diff --git a/src/services/UtilService.ts b/src/services/UtilService.ts index 68980b17..be01b6df 100644 --- a/src/services/UtilService.ts +++ b/src/services/UtilService.ts @@ -86,7 +86,7 @@ const findShipmentPackages = async(shipmentIds: Array): Promise => "shipmentId_op": "in" }, "fieldList": ["shipmentId", "shipmentPackageSeqId", "shipmentRouteSegmentId", "shipmentMethodTypeId", "shipmentBoxTypeId", "packageName", "primaryOrderId", "carrierPartyId", "picklistBinId", "isTrackingRequired", "trackingCode", "internationalInvoiceUrl", "labelImageUrl", "carrierServiceStatusId"], - "viewSize": shipmentIds.length, + "viewSize": 250, //max size perform find support, need to update this logic to fetch the paginated detail "distinct": "Y" } @@ -126,6 +126,53 @@ const findShipmentPackages = async(shipmentIds: Array): Promise => return shipmentPackages; } +const findShipmentPackageContents = async (shipmentIds: Array): Promise => { + let viewIndex = 0; + let shipmentPackageContents: any[] = []; + let shipmentPackageContentInfo: { [key: string]: any[] } = {}; + let resp; + + try { + do { + resp = await api({ + url: "performFind", + method: "get", + params: { + "entityName": "ShipmentPackageAndContent", + "inputFields": { + "shipmentId": shipmentIds, + "shipmentId_op": "in" + }, + "fieldList": ["shipmentId", "shipmentItemSeqId", "shipmentPackageSeqId", "packageName", "quantity"], + viewIndex, + "viewSize": 250, + "distinct": "Y" + } + }) as any; + + if (!hasError(resp) && resp.data.count) { + shipmentPackageContents = shipmentPackageContents.concat(resp.data.docs); + viewIndex++; + } else { + throw resp; + } + } while (resp.data.docs.length >= 250); + } catch (error) { + logger.error(error); + } + + shipmentPackageContentInfo = shipmentPackageContents.reduce((contents: any, shipmentPackageContent: any) => { + if (contents[shipmentPackageContent.shipmentId]) { + contents[shipmentPackageContent.shipmentId].push(shipmentPackageContent); + } else { + contents[shipmentPackageContent.shipmentId] = [shipmentPackageContent]; + } + return contents; + }, {}); + + return shipmentPackageContentInfo; +}; + const findCarrierPartyIdsForShipment = async(shipmentIds: Array): Promise => { let carrierPartyIdsByShipment = {}; @@ -578,6 +625,7 @@ export const UtilService = { findShipmentIdsForOrders, findShipmentItemInformation, findShipmentPackages, + findShipmentPackageContents, fetchTransferOrderFacets, getAvailablePickers, getProductStoreSetting, diff --git a/src/store/modules/order/actions.ts b/src/store/modules/order/actions.ts index 41848f93..281b3d85 100644 --- a/src/store/modules/order/actions.ts +++ b/src/store/modules/order/actions.ts @@ -38,7 +38,7 @@ const actions: ActionTree = { // TODO: handle case when shipmentIds is empty // https://stackoverflow.com/questions/28066429/promise-all-order-of-resolved-values - const [shipmentPackagesByOrderInformationAndPicklistBin, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)]) + const [shipmentPackagesByOrderInformationAndPicklistBin, shipmentPackageContents, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentPackageContents(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)]) // TODO: try fetching the carrierPartyIds when fetching packages information, as ShipmentPackageRouteSegDetail entity contain carrierPartyIds as well const carrierPartyIds = [...new Set(Object.values(carrierPartyIdsByShipmentInformation).map((carrierPartyIds: any) => carrierPartyIds.map((carrier: any) => carrier.carrierPartyId)).flat())] @@ -88,8 +88,8 @@ const actions: ActionTree = { item.shipmentId = shipment.shipmentId item.shipmentItemSeqId = shipment.shipmentItemSeqId } - - item.selectedBox = shipmentPackagesByOrderAndPicklistBin[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName + + item.selectedBox = shipmentPackageContents[`${item.shipmentId}`].find((shipmentPackageContent: any) => shipmentPackageContent.shipmentItemSeqId === item.shipmentItemSeqId)?.packageName }) const orderItem = order.items[0]; @@ -647,17 +647,26 @@ const actions: ActionTree = { const missingLabelImage = this.state.util.productStoreShipmentMethCount > 0 ? shipmentPackageValues.some((shipmentPackage:any) => !shipmentPackage.trackingCode) : false; const updateShipmentPackages = (order:any) => { - order.shipmentPackages.forEach((shipmentPackage:any) => { + + const updatedShipmentPackages = order.shipmentPackages.reduce((updatedShipmentPackages: any[], shipmentPackage: any) => { const key = `${shipmentPackage.shipmentId}-${shipmentPackage.shipmentPackageSeqId}`; const updatedShipmentPackage = shipmentPackagesMap[key]; + + // Only add the shipment package if updatedShipmentPackage exists if (updatedShipmentPackage) { - shipmentPackage.trackingCode = updatedShipmentPackage.trackingCode; - shipmentPackage.labelPdfUrl = updatedShipmentPackage.labelPdfUrl; - shipmentPackage.shipmentMethodTypeId = updatedShipmentPackage.shipmentMethodTypeId; - shipmentPackage.carrierPartyId = updatedShipmentPackage.carrierPartyId; - shipmentPackage.missingLabelImage = missingLabelImage; + const newShipmentPackage = { ...shipmentPackage }; + newShipmentPackage.trackingCode = updatedShipmentPackage.trackingCode; + newShipmentPackage.labelPdfUrl = updatedShipmentPackage.labelPdfUrl; + newShipmentPackage.shipmentMethodTypeId = updatedShipmentPackage.shipmentMethodTypeId; + newShipmentPackage.carrierPartyId = updatedShipmentPackage.carrierPartyId; + newShipmentPackage.missingLabelImage = missingLabelImage; + updatedShipmentPackages.push(newShipmentPackage); } - }); + + return updatedShipmentPackages; + }, []); + + order.shipmentPackages = updatedShipmentPackages order.trackingCode = order.shipmentPackages?.[0]?.trackingCode order.missingLabelImage = missingLabelImage }; @@ -1083,7 +1092,7 @@ const actions: ActionTree = { // TODO: handle case when shipmentIds is empty // https://stackoverflow.com/questions/28066429/promise-all-order-of-resolved-values - const [shipmentPackagesByOrderInformationAndPicklistBin, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)]) + const [shipmentPackagesByOrderInformationAndPicklistBin, shipmentPackageContents, itemInformationByOrderInformation, carrierPartyIdsByShipmentInformation] = await Promise.all([UtilService.findShipmentPackages(orderShipmentIds), UtilService.findShipmentPackageContents(orderShipmentIds), UtilService.findShipmentItemInformation(orderShipmentIds), UtilService.findCarrierPartyIdsForShipment(orderShipmentIds)]) // TODO: try fetching the carrierPartyIds when fetching packages information, as ShipmentPackageRouteSegDetail entity contain carrierPartyIds as well const carrierPartyIds = [...new Set(Object.values(carrierPartyIdsByShipmentInformation).map((carrierPartyIds: any) => carrierPartyIds.map((carrier: any) => carrier.carrierPartyId)).flat())] @@ -1133,7 +1142,7 @@ const actions: ActionTree = { item.shipmentItemSeqId = shipment.shipmentItemSeqId } - item.selectedBox = shipmentPackagesByOrderAndPicklistBin[`${item.orderId}_${item.picklistBinId}`]?.find((shipmentPackage: any) => shipmentPackage.shipmentId === item.shipmentId)?.packageName + item.selectedBox = shipmentPackageContents[`${item.shipmentId}`].find((shipmentPackageContent: any) => shipmentPackageContent.shipmentItemSeqId === item.shipmentItemSeqId)?.packageName }) const orderItem = current.items[0]; diff --git a/src/views/InProgress.vue b/src/views/InProgress.vue index 461d7cff..03535795 100644 --- a/src/views/InProgress.vue +++ b/src/views/InProgress.vue @@ -779,7 +779,7 @@ export default defineComponent({ } } else { prefix = 'rtp' - form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId) + form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId + "-" + shipmentPackage.shipmentPackageSeqId) form.append(`${prefix}_shipmentId_${index}`, item.shipmentId) form.append(`${prefix}_shipmentItemSeqId_${index}`, item.shipmentItemSeqId) form.append(`${index}_${prefix}_rowSubmit_`, ''+index) @@ -848,6 +848,7 @@ export default defineComponent({ order.items = items await this.store.dispatch('order/updateInProgressOrder', order) + await this.store.dispatch('order/updateShipmentPackageDetail', order) } showToast(translate('Order updated successfully')) } else { diff --git a/src/views/OrderDetail.vue b/src/views/OrderDetail.vue index 189acee0..d8c9c5df 100644 --- a/src/views/OrderDetail.vue +++ b/src/views/OrderDetail.vue @@ -1270,7 +1270,7 @@ export default defineComponent({ } } else { prefix = 'rtp' - form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId) + form.append(`${prefix}_newShipmentId_${index}`, shipmentPackage.shipmentId + "-" + shipmentPackage.shipmentPackageSeqId) form.append(`${prefix}_shipmentId_${index}`, item.shipmentId) form.append(`${prefix}_shipmentItemSeqId_${index}`, item.shipmentItemSeqId) form.append(`${index}_${prefix}_rowSubmit_`, ''+index) @@ -1319,6 +1319,7 @@ export default defineComponent({ order.isModified = false; await this.store.dispatch('order/updateInProgressOrder', order) + await this.store.dispatch('order/updateShipmentPackageDetail', order) showToast(translate('Order updated successfully')) return Promise.resolve(order); } else {