Skip to content

Commit

Permalink
Improved: logic to call changeOrderItemStatus api and show Toast acco…
Browse files Browse the repository at this point in the history
…rdingly (#212)
  • Loading branch information
amansinghbais committed Oct 11, 2023
1 parent 3c07e28 commit 09dd51b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"Something went wrong": "Something went wrong",
"Something went wrong while login. Please contact administrator": "Something went wrong while login. Please contact administrator.",
"Sorry, your username or password is incorrect. Please try again.": "Sorry, your username or password is incorrect. Please try again.",
"Some purchase order items were not successfully updated, Please retry.": "Some purchase order items were not successfully updated, Please retry.",
"Specify which facility you want to operate from. Order, inventory and other configuration data will be specific to the facility you select.": "Specify which facility you want to operate from. Order, inventory and other configuration data will be specific to the facility you select.",
"store name": "store name",
"Store": "Store",
Expand Down
49 changes: 28 additions & 21 deletions src/views/ClosePurchaseOrderModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ import { productHelpers, showToast } from '@/utils';
import { ShopifyImg } from '@hotwax/dxp-components';
import { translate } from '@/i18n'
import emitter from "@/event-bus"
import { useRouter } from 'vue-router';
export default defineComponent({
name: "ClosePurchaseOrder",
name: "ClosePurchaseOrderModal",
components: {
IonBadge,
IonButton,
Expand Down Expand Up @@ -122,38 +123,42 @@ export default defineComponent({
emitter.emit('create-shipment')
}
await this.updatePOItemStatus()
modalController.dismiss()
this.router.push('/purchase-orders')
}
}]
});
return alert.present();
},
async updatePOItemStatus() {
const eligibleItems = this.order.items.filter((item: any) => item.isChecked)
const areAllItemsSelected = this.areAllItemsSelected(eligibleItems)
eligibleItems.forEach(async (item:any) => {
const selectedItem = {
orderId: item.orderId,
orderItemSeqId: item.orderItemSeqId
} as any
if(!areAllItemsSelected) {
selectedItem.statusId = "ITEM_COMPLETED"
await Promise.allSettled(eligibleItems.map(async (item:any) => {
const selectedItemDetails = {
orderId: item.orderId,
orderItemSeqId: item.orderItemSeqId,
statusId: "ITEM_COMPLETED"
}
try{
await OrderService.updatePOItemStatus({orderId: item.orderId, orderItemSeqId: item.orderItemSeqId})
.then(() => {
showToast(translate('Purchase order updated successfully.'))
})
try {
await OrderService.updatePOItemStatus(selectedItemDetails)
item.statusUpdated = true
} catch(err) {
item.statusUpdated = false
console.error(err);
showToast(translate("Purchase order update failed."))
}
});
},
areAllItemsSelected(eligibleItems: any) {
return eligibleItems.length === this.order.items.filter((item:any) => item.orderItemStatusId != "ITEM_COMPLETED" || item.orderItemStatusId != "ITEM_REJECTED").length
}))
const failedItemsCount = eligibleItems.filter((item: any) => item.statusUpdated === false).length
if(failedItemsCount === 0){
showToast(translate('Purchase order updated successfully.'))
} else if(failedItemsCount === eligibleItems.length){
showToast(translate("Purchase order update failed."))
} else {
showToast(translate("Some purchase order items were not successfully updated, Please retry."))
}
},
isEligibleToClosePOItems() {
return this.order.items.some((item: any) => item.isChecked)
Expand All @@ -167,6 +172,7 @@ export default defineComponent({
}
},
setup() {
const router = useRouter()
return {
arrowBackOutline,
Actions,
Expand All @@ -175,6 +181,7 @@ export default defineComponent({
hasPermission,
OrderService,
productHelpers,
router,
saveOutline
};
}
Expand Down
9 changes: 6 additions & 3 deletions src/views/PurchaseOrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ export default defineComponent({
productIdentificationPref: 'user/getProductIdentificationPref'
})
},
mounted() {
emitter.on('create-shipment', this.createShipment)
},
methods: {
getRcvdToOrderedFraction(item: any){
return (parseInt(item.quantityAccepted) + this.getPOItemAccepted(item.productId))/(item.quantity)
Expand Down Expand Up @@ -313,8 +316,6 @@ export default defineComponent({
}
})
emitter.on('create-shipment', this.createShipment)
return modal.present();
},
async createShipment() {
Expand All @@ -323,7 +324,6 @@ export default defineComponent({
if (resp.status === 200 && !hasError(resp)) {
this.router.push('/purchase-orders')
}
emitter.off('create-shipment', this.createShipment)
},
isEligibileForCreatingShipment() {
return this.order.items.some((item: any) => item.quantityAccepted > 0)
Expand All @@ -344,6 +344,9 @@ export default defineComponent({
this.store.dispatch('order/getPOHistory', { orderId: this.order.orderId })
})
},
unmounted() {
emitter.off('create-shipment', this.createShipment)
},
setup() {
const store = useStore();
const router = useRouter();
Expand Down

0 comments on commit 09dd51b

Please sign in to comment.