diff --git a/src/components/OrderAdjustmentModal.vue b/src/components/OrderAdjustmentModal.vue index a67f464d..d395fb5c 100644 --- a/src/components/OrderAdjustmentModal.vue +++ b/src/components/OrderAdjustmentModal.vue @@ -94,7 +94,8 @@ export default defineComponent({ orderAdjustmentTypeDesc: {} as any, otherShipmentTotal: 0, shipmentSubtotal: 0, - shipmentTotal: 0 + shipmentTotal: 0, + orderItemSeqIds: [] as Array } }, props: ["order", "orderId", "orderAdjustments", "orderHeaderAdjustmentTotal", "adjustmentsByGroup"], @@ -106,6 +107,9 @@ export default defineComponent({ this.orderAdjustmentTypeIds.push(adjustment.orderAdjustmentTypeId) }) + // Getting seqIds as need to add item level adjustment to specific shipment total + this.orderItemSeqIds = this.order.items.map((item: any) => item.orderItemSeqId) + await this.fetchOrderPayment(); await this.fetchAdjustmentTypeDescription(); this.shipmentTotal = this.shipmentSubtotal + this.orderHeaderAdjustmentTotal @@ -119,7 +123,6 @@ export default defineComponent({ }, entityName: "OrderHeaderItemAndShipGroup", viewSize: 50, - distinct: "Y", fieldList: ["orderId", "grandTotal", "currencyUom", "unitPrice", "shipGroupSeqId"] }) @@ -134,13 +137,18 @@ export default defineComponent({ } }) - Object.entries(this.adjustmentsByGroup).map(([seqId, adjustmentAmount]: any) => { - // If we have adjustment with _NA_ group then adding them in the current shipment total - if(seqId !== this.order.shipGroupSeqId && seqId !== "_NA_") { - this.otherShipmentTotal += adjustmentAmount - } else { - this.shipmentSubtotal += adjustmentAmount - } + Object.entries(this.adjustmentsByGroup).map(([seqId, adjustments]: any) => { + adjustments.map((adjustment: any) => { + if(seqId === this.order.shipGroupSeqId) { + this.shipmentSubtotal += adjustment.amount + } else if(seqId !== "_NA_") { + this.otherShipmentTotal += adjustment.amount + } else if(this.orderItemSeqIds.includes(adjustment.orderItemSeqId)) { + this.shipmentSubtotal += adjustment.amount + } else { + this.otherShipmentTotal += adjustment.amount + } + }) }) } } catch(err) { diff --git a/src/views/OrderDetail.vue b/src/views/OrderDetail.vue index 20e50474..92f61d57 100644 --- a/src/views/OrderDetail.vue +++ b/src/views/OrderDetail.vue @@ -543,7 +543,8 @@ export default defineComponent({ isOrderAdjustmentPending: false, orderAdjustments: [], orderHeaderAdjustmentTotal: 0, - adjustmentsByGroup: {} as any + adjustmentsByGroup: {} as any, + orderAdjustmentShipmentId: "" } }, async ionViewDidEnter() { @@ -1734,15 +1735,20 @@ export default defineComponent({ if(!hasError(resp) && resp.data?.count) { this.orderHeaderAdjustmentTotal = 0 this.orderAdjustments = resp.data.docs.filter((adjustment: any) => { - if(adjustment.orderItemSeqId === "_NA_" || !adjustment.orderItemSeqId) { + if((adjustment.orderItemSeqId === "_NA_" || !adjustment.orderItemSeqId) && !adjustment.billingShipmentId) { this.orderHeaderAdjustmentTotal += adjustment.amount return true; } else { - this.adjustmentsByGroup[adjustment.shipGroupSeqId] ? (this.adjustmentsByGroup[adjustment.shipGroupSeqId] += adjustment.amount) : (this.adjustmentsByGroup[adjustment.shipGroupSeqId] = adjustment.amount) + this.adjustmentsByGroup[adjustment.shipGroupSeqId] ? (this.adjustmentsByGroup[adjustment.shipGroupSeqId].push(adjustment)) : (this.adjustmentsByGroup[adjustment.shipGroupSeqId] = [adjustment]) return false; } }) this.isOrderAdjustmentPending = resp.data.docs.some((adjustment: any) => !adjustment.billingShipmentId) + + if(!this.isOrderAdjustmentPending) { + const adjustment = resp.data.docs.find((adjustment: any) => adjustment.billingShipmentId) + this.orderAdjustmentShipmentId = adjustment.billingShipmentId + } } } catch(err) { logger.error(err); @@ -1750,21 +1756,33 @@ export default defineComponent({ }, async openOrderAdjustmentInfo() { if(this.isCODPaymentPending && !this.isOrderAdjustmentPending) { + let message = "Order level charges like shipping fees and taxes were already charged to the customer on the first label generated for this order." + let facilityName = "" + let trackingCode = "" + let buttons = [ + { + text: translate("Dismiss"), + role: "cancel" + } + ] as any + + if(this.orderAdjustmentShipmentId) { + const shipGroup = this.order.shipGroups.find((group: any) => group.shipmentId == this.orderAdjustmentShipmentId) + facilityName = shipGroup.facilityName || shipGroup.facilityId + trackingCode = shipGroup.trackingCode + message += "

Label was generated by facility with tracking code at" + buttons.push({ + text: translate("Copy tracking code"), + handler: () => { + copyToClipboard(trackingCode, "Copied to clipboard") + } + }) + } + const alert = await alertController.create({ - message: translate("Order level charges like shipping fees and taxes were already charged to the customer on the first label generated for this order.

Label was generated by facility with tracking code at"), + message: translate(message, { facilityName, trackingCode }), header: translate("COD calculation"), - buttons: [ - { - text: translate("Copy tracking code"), - handler: () => { - console.log('copy tracking code') - } - }, - { - text: translate("Dismiss"), - role: 'cancel' - }, - ], + buttons }) return alert.present();