Skip to content

Commit

Permalink
Improved: the alert to display the tracking code and facility name of…
Browse files Browse the repository at this point in the history
… shipment which handled the order adjustments(hotwax#862)
  • Loading branch information
ymaheshwari1 committed Jan 7, 2025
1 parent 835ae57 commit 517ff74
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
26 changes: 17 additions & 9 deletions src/components/OrderAdjustmentModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ export default defineComponent({
orderAdjustmentTypeDesc: {} as any,
otherShipmentTotal: 0,
shipmentSubtotal: 0,
shipmentTotal: 0
shipmentTotal: 0,
orderItemSeqIds: [] as Array<string>
}
},
props: ["order", "orderId", "orderAdjustments", "orderHeaderAdjustmentTotal", "adjustmentsByGroup"],
Expand All @@ -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
Expand All @@ -119,7 +123,6 @@ export default defineComponent({
},
entityName: "OrderHeaderItemAndShipGroup",
viewSize: 50,
distinct: "Y",
fieldList: ["orderId", "grandTotal", "currencyUom", "unitPrice", "shipGroupSeqId"]
})
Expand All @@ -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) {
Expand Down
50 changes: 34 additions & 16 deletions src/views/OrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ export default defineComponent({
isOrderAdjustmentPending: false,
orderAdjustments: [],
orderHeaderAdjustmentTotal: 0,
adjustmentsByGroup: {} as any
adjustmentsByGroup: {} as any,
orderAdjustmentShipmentId: ""
}
},
async ionViewDidEnter() {
Expand Down Expand Up @@ -1734,37 +1735,54 @@ 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);
}
},
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 += "<br/><br/>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.<br/><br/>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();
Expand Down

0 comments on commit 517ff74

Please sign in to comment.