This commit is contained in:
Jonathan Chevalier
2023-01-18 17:56:18 +01:00
parent 25034216a6
commit c68f6e963f
4 changed files with 100 additions and 15 deletions

View File

@@ -1,22 +1,39 @@
<template> <template>
<div class="search-form d-flex align-items-center"> <div class="search-form d-flex align-items-center">
<input type="text" name="query" placeholder="Scanner un bon de livraison" v-model="query" @input="searchDeliveries" autofocus> <input type="text" placeholder="Scanner un bon de livraison" v-model="query" @input="searchDeliveries"
ref="orderScan">
<button type="submit" title="Valider"><i class="fa-solid fa-barcode fa-fw"></i></button> <button type="submit" title="Valider"><i class="fa-solid fa-barcode fa-fw"></i></button>
</div> </div>
</template> </template>
<script> <script>
import {ref} from 'vue'; import {nextTick, onMounted, ref, watch} from 'vue';
import {useShipmentStore} from '@/stores/shipment.js' import {useShipmentStore} from '@/stores/shipment.js'
import ShipmentApi from '@/services/ShipmentApi.js' import ShipmentApi from '@/services/ShipmentApi.js'
import {storeToRefs} from "pinia";
export default { export default {
name: "Search", name: "Search",
setup() { setup() {
const query = ref(); const query = ref();
const shipmentStore = useShipmentStore() const store = useShipmentStore()
const {refresh} = storeToRefs(store)
const orderScan = ref(null)
onMounted(() => {
orderScan.value.focus()
})
watch(refresh, async (to, from) => {
if (!from && to) {
await nextTick()
orderScan.value.focus()
}
});
return { return {
shipmentStore, store,
orderScan,
query query
} }
}, },
@@ -29,8 +46,10 @@ export default {
const apiResult = await ShipmentApi.getDeliveriesByOrder(this.query) const apiResult = await ShipmentApi.getDeliveriesByOrder(this.query)
this.shipmentStore.setIdOrder(this.query) this.store.setIdOrder(this.query)
this.shipmentStore.setDeliveryLines(apiResult.data) this.store.setIdCustomer(apiResult.id_customer)
this.store.setDeliveryLines(apiResult.data)
this.store.refreshAfterUpdate(false);
this.query = null this.query = null
}, },
} }

View File

@@ -4,10 +4,10 @@ export default {
getApiUrl(exec, param = null) { getApiUrl(exec, param = null) {
const store = useGlobalStore() const store = useGlobalStore()
return '/php/api/v3/?controller=ShipmentController&NUMC=' + store.idSession + '&EXEC=' + exec + ((param !== null) ? param : null) return '/php/api/v3/?controller=ShipmentController&NUMC=' + store.idSession + '&EXEC=' + exec + ((param !== null) ? param : '')
}, },
async getDeliveriesByOrder(idOrder) { async getDeliveriesByOrder(idOrder) {
const apiUrl = this.getApiUrl('getDeliveriesByOrder', '&query=' + idOrder) const apiUrl = this.getApiUrl('getDeliveriesByOrder', '&id_order=' + idOrder)
if (import.meta.env.DEV) { if (import.meta.env.DEV) {
console.log(apiUrl) console.log(apiUrl)
@@ -21,6 +21,36 @@ export default {
return false return false
} }
}) })
},
async updateDeliveriesByOrder(idOrder, list) {
const apiUrl = this.getApiUrl('updateDeliveriesByOrder')
const formData = new FormData();
formData.append('id_order', idOrder);
formData.append('data', JSON.stringify(list));
return new Promise(function (resolve, reject) {
let xhr = new XMLHttpRequest();
xhr.open('POST', apiUrl);
xhr.onload = function () {
if (this.status >= 200 && this.status < 300) {
resolve(JSON.parse(xhr.response));
} else {
reject({
status: this.status,
statusText: xhr.statusText
});
}
};
xhr.onerror = function () {
reject({
status: this.status,
statusText: xhr.statusText
});
};
xhr.send(formData);
});
} }
} }

View File

@@ -3,7 +3,9 @@ import {defineStore} from 'pinia'
export const useShipmentStore = defineStore('shipment', { export const useShipmentStore = defineStore('shipment', {
state: () => ({ state: () => ({
idOrder: null, idOrder: null,
deliveryLines: [] idCustomer : null,
deliveryLines: [],
refresh : false,
}), }),
getters: { getters: {
deliveriesCounter: (state) => state.deliveryLines.length, deliveriesCounter: (state) => state.deliveryLines.length,
@@ -18,5 +20,11 @@ export const useShipmentStore = defineStore('shipment', {
setIdOrder(idOrder) { setIdOrder(idOrder) {
this.idOrder = idOrder this.idOrder = idOrder
}, },
setIdCustomer(idCustomer) {
this.idCustomer = idCustomer
},
refreshAfterUpdate(bool){
this.refresh = bool
}
}, },
}) })

View File

@@ -26,7 +26,7 @@
</div> </div>
<div class="ps-4" v-if="store.deliveriesCounter === deliveryLines.filter(line=>line.scan).length"> <div class="ps-4" v-if="store.deliveriesCounter === deliveryLines.filter(line=>line.scan).length">
<button class="btn btn-primary ms-10">Valider</button> <button class="btn btn-primary ms-10" @click="sendNewStatus">Valider</button>
</div> </div>
</div> </div>
@@ -60,7 +60,8 @@
</tr> </tr>
<tr v-for="line in store.deliveryLines.filter(obj => obj.physical_location === location)" <tr v-for="line in store.deliveryLines.filter(obj => obj.physical_location === location)"
:class="(line.scan) ? 'table-primary' : null"> :class="(line.scan) ? 'table-primary' : null">
<td class="text-center"><input class="form-check-input" type="checkbox" role="switch" :checked="line.scan"> <td class="text-center"><input class="form-check-input" type="checkbox" role="switch" :checked="line.scan"
@click="updateLine(line)">
</td> </td>
<td>{{ line.product_name }}</td> <td>{{ line.product_name }}</td>
<td>{{ line.ean }}</td> <td>{{ line.ean }}</td>
@@ -72,7 +73,9 @@
<input class="form-control to_edit" type="text" name="line_1_ean_winpharma" value="" disabled="" <input class="form-control to_edit" type="text" name="line_1_ean_winpharma" value="" disabled=""
required="required"></div> required="required"></div>
</td> </td>
<td><span :class="getStatusInfo(line.status).hasOwnProperty('color') ? 'bg-'+getStatusInfo(line.status).color : 'bg-info'" class="text-nowrap badge label_status_initial">{{ getStatusInfo(line.status).label }}</span> <td><span
:class="getStatusInfo(line.status).hasOwnProperty('color') ? 'bg-'+getStatusInfo(line.status).color : 'bg-info'"
class="text-nowrap badge label_status_initial">{{ getStatusInfo(line.status).label }}</span>
<select <select
class="form-select form-select-sm to_edit d-none" name="line_1_new_status" required="required" disabled="" class="form-select form-select-sm to_edit d-none" name="line_1_new_status" required="required" disabled=""
@@ -105,13 +108,14 @@ import {useShipmentStore} from '@/stores/shipment.js'
import {nextTick, onMounted, reactive, ref, watch} from "vue"; import {nextTick, onMounted, reactive, ref, watch} from "vue";
import {storeToRefs} from "pinia"; import {storeToRefs} from "pinia";
import {Modal} from 'bootstrap' import {Modal} from 'bootstrap'
import ShipmentApi from '@/services/ShipmentApi.js'
const shipmentStatus = [ const shipmentStatus = [
{ {
code: "0", code: "0",
label: 'En attente', label: 'En attente',
allowStatus: [3, 80, 39, 37], allowStatus: [3, 80, 39, 37],
color: 'danger' color: 'warning'
}, },
{ {
@@ -123,21 +127,25 @@ const shipmentStatus = [
{ {
code: "3", code: "3",
label: 'A livrer', label: 'A livrer',
color: 'success',
allowStatus: [] allowStatus: []
}, },
{ {
code: "31", code: "31",
label: 'A livrer Dépôt', label: 'A livrer Dépôt',
color: 'success',
allowStatus: [3, 80, 39, 37] allowStatus: [3, 80, 39, 37]
}, },
{ {
code: "80", code: "80",
label: 'Manquant à rembourser', label: 'Manquant à rembourser',
color: 'danger',
allowStatus: [] allowStatus: []
}, },
{ {
code: "39", code: "39",
label: 'Produit en commande', label: 'Produit en commande',
color: 'warning',
allowStatus: [30, 3, 80, 39, 37] allowStatus: [30, 3, 80, 39, 37]
}, },
] ]
@@ -154,7 +162,7 @@ export default {
const productScan = ref(null) const productScan = ref(null)
watch(idOrder, async (to, from) => { watch(idOrder, async (to, from) => {
if (from === null && to !== null) { if (from !== to) {
await nextTick() await nextTick()
productScan.value.focus() productScan.value.focus()
} }
@@ -163,6 +171,7 @@ export default {
return { return {
store, store,
idOrder,
locationGroup, locationGroup,
deliveryLines, deliveryLines,
productScan, productScan,
@@ -180,19 +189,38 @@ export default {
if (this.eanScan.length === 13) { if (this.eanScan.length === 13) {
const findLine = this.deliveryLines.filter(line => line.ean === this.eanScan) const findLine = this.deliveryLines.filter(line => line.ean === this.eanScan)
if (findLine.length > 0) { if (findLine.length > 0) {
findLine[0].rollBackStatus = findLine[0].status
findLine[0].scan = true findLine[0].scan = true
findLine[0].status = "3" findLine[0].status = "3"
findLine[0].labelStatus = "A livrer"
this.eanScan = null this.eanScan = null
} else { } else {
this.modal.show() this.modal.show()
} }
} }
},
updateLine(line) {
if (!line.scan) {
line.rollBackStatus = line.status
line.scan = true
line.status = "3"
} else {
line.scan = false
line.status = line.rollBackStatus
line.rollBackStatus = null
}
}, },
getStatusInfo(code) { getStatusInfo(code) {
let labelFinder = shipmentStatus.filter(status => status.code === code) let labelFinder = shipmentStatus.filter(status => status.code === code)
return (labelFinder.length > 0) ? labelFinder[0] : {label: 'unknow'} return (labelFinder.length > 0) ? labelFinder[0] : {label: 'unknow'}
},
async sendNewStatus() {
const newList = await ShipmentApi.updateDeliveriesByOrder(this.idOrder, this.deliveryLines)
this.store.setDeliveryLines(newList.data);
this.store.setDeliveryLines(newList.data);
this.store.refreshAfterUpdate(true);
} }
}, },
mounted() { mounted() {