Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: functionality which allows users to manually close purchase order items when they receive them. (#212) #258

Merged
merged 16 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
9df9dfc
Implemented: functionality which allows users to manually close purch…
amansinghbais Aug 29, 2023
50a4221
Improved: code for closePO's modal (#212)
amansinghbais Sep 11, 2023
556f7d1
Improved: code for close PO items (#212)
amansinghbais Sep 11, 2023
076243a
Merge branch 'main' of https://github.com/hotwax/receiving into recei…
amansinghbais Sep 18, 2023
9770a27
Improved: indentation, casing, conditions (#212)
amansinghbais Sep 18, 2023
75398ef
Improved: conditions which are not required and if syntax (#212)
amansinghbais Sep 20, 2023
3c07e28
Improved: used emitter to call parent component function from modal (…
amansinghbais Oct 9, 2023
09dd51b
Improved: logic to call changeOrderItemStatus api and show Toast acco…
amansinghbais Oct 11, 2023
57fc6b2
Improved: better alternative for statusUpdated Variable (#212)
amansinghbais Oct 12, 2023
59f1e69
Merge branch 'main' of https://github.com/hotwax/receiving into recei…
amansinghbais Oct 16, 2023
f6ea9d5
Improved: code to handle newly added items (#212)
amansinghbais Oct 17, 2023
9571d70
Improved: promise.allsettled response handling (#212)
amansinghbais Oct 17, 2023
75c5c83
Improved: code for handling item selection for status update (#212)
amansinghbais Oct 18, 2023
878850c
Fixed: removed comments from the api parameters (#212)
amansinghbais Oct 18, 2023
ac43b04
Improved: optimized way of writing conditions (#212)
amansinghbais Oct 18, 2023
6cd37f6
Improved: variable name and comments (#212)
amansinghbais Oct 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
}
}]
});
return alert.present();
},
async updatePOItemStatus() {
const eligibleItems = this.order.items.filter((item: any) => item.isChecked)
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved
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
ymaheshwari1 marked this conversation as resolved.
Show resolved Hide resolved

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