Skip to content

Commit

Permalink
Improved: Used createIncomingShipment service to create shipment with…
Browse files Browse the repository at this point in the history
… items instead of doing multiple calls for creating/adding shipment and items. Also used the common flow for shipment, return and po to import the json file and processing the item receiving at backend. (#402)
  • Loading branch information
ravilodhi committed Oct 22, 2024
1 parent 63d344b commit b201629
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
"Purchase Order": "Purchase Order",
"Purchase Order Details": "Purchase Order Details",
"Purchase Orders": "Purchase Orders",
"Purchase order received successfully" : "Purchase order received successfully {orderId}",
"Qty": "Qty",
"Receive": "Receive",
"Receive All": "Receive All",
Expand Down
9 changes: 9 additions & 0 deletions src/services/OrderService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ const createPurchaseShipment = async (payload: any): Promise<any> => {
})
}

const createIncomingShipment = async (payload: any): Promise<any> => {
return api({
url: "/service/createIncomingShipment",
method: "POST",
data: payload
})
}

const fetchPOHistory = async (payload: any): Promise<any> => {
return api({
url: "/performFind",
Expand All @@ -43,6 +51,7 @@ const updatePOItemStatus = async (payload: any): Promise<any> => {
export const OrderService = {
fetchPurchaseOrders,
fetchPODetail,
createIncomingShipment,
createPurchaseShipment,
fetchPOHistory,
updatePOItemStatus
Expand Down
47 changes: 46 additions & 1 deletion src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,50 @@ const actions: ActionTree<OrderState, RootState> = {
return resp;
},

async createAndReceiveIncomingShipment({ commit }, payload) {

Check warning on line 167 in src/store/modules/order/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'commit' is defined but never used

Check warning on line 167 in src/store/modules/order/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'commit' is defined but never used
let resp;
try {
payload.items.map((item: any, index: number) => {
item.itemSeqId = `1000${index+1}`
item.quantity = item.quantityAccepted
})

const params = {
orderId: payload.orderId,
destinationFacilityId: this.state.user.currentFacility.facilityId,
"type": "PURCHASE_SHIPMENT",
"status": "PURCH_SHIP_CREATED",
"items": payload.items
}
resp = await OrderService.createIncomingShipment({"payload": params})

if (resp.status === 200 && !hasError(resp) && resp.data.shipmentId) {
const facilityLocations = await this.dispatch('user/getFacilityLocations', this.state.user.currentFacility.facilityId);
if (facilityLocations.length){
const locationSeqId = facilityLocations[0].locationSeqId
payload.items.map((item: any) => {
item.locationSeqId = locationSeqId
item.quantityReceived = item.quantityAccepted ? Number(item.quantityAccepted) : 0
})
} else {
showToast(translate("Facility locations were not found corresponding to destination facility of PO. Please add facility locations to avoid receive PO failure."))
}
const poShipment = {
shipmentId : resp.data.shipmentId,
items: payload.items,
isMultiReceivingEnabled: true
}
return await this.dispatch('shipment/receiveShipmentJson', poShipment).catch((err) => console.error(err))
} else {
showToast(translate("Something went wrong"));
}
} catch(error){
console.error(error)
showToast(translate("Something went wrong"));
}
return false;
},

async getPOHistory({ commit, state }, payload) {
let resp;
const current = state.current as any;
Expand All @@ -175,7 +219,8 @@ const actions: ActionTree<OrderState, RootState> = {
},
"entityName": "ShipmentReceiptAndItem",
"fieldList": ["datetimeReceived", "productId", "quantityAccepted", "quantityRejected", "receivedByUserLoginId", "shipmentId", 'locationSeqId'],
"orderBy": 'datetimeReceived DESC'
"orderBy": 'datetimeReceived DESC',
"viewSize": "250"
}
const facilityLocations = await this.dispatch('user/getFacilityLocations', this.state.user.currentFacility.facilityId);
const locationSeqId = facilityLocations.length > 0 ? facilityLocations[0].locationSeqId : "";
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/return/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const actions: ActionTree<ReturnState, RootState> = {
const locationSeqId = facilityLocations[0].locationSeqId
resp.data.items.map((item: any) => {
item.locationSeqId = locationSeqId;
item.quantityReceived = item.quantityAccepted ? Number(item.quantityAccepted) : 0
});
} else {
showToast(translate("Facility locations were not found corresponding to destination facility of return shipment. Please add facility locations to avoid receive return shipment failure."))
Expand Down
2 changes: 0 additions & 2 deletions src/store/modules/shipment/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ const actions: ActionTree<ShipmentState, RootState> = {
"statusId": "PURCH_SHIP_RECEIVED"
})
if (resp.status == 200 && !hasError(resp)) {
showToast(translate("Shipment received successfully", { shipmentId: payload.shipmentId }))
return true;
} else {
throw resp.data;
Expand All @@ -205,7 +204,6 @@ const actions: ActionTree<ShipmentState, RootState> = {
throw resp.data;
}
} catch (err) {
await dispatch('setCurrent', { shipmentId: payload.shipmentId })
showToast(translate("Something went wrong, please try again"));
}
emitter.emit("dismissLoader");
Expand Down
9 changes: 7 additions & 2 deletions src/views/PurchaseOrderDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,14 @@ export default defineComponent({
},
async createShipment() {
const eligibleItems = this.order.items.filter((item: any) => item.quantityAccepted > 0)
const resp = await this.store.dispatch('order/createPurchaseShipment', { items: eligibleItems, orderId: this.order.orderId })
if (resp.status === 200 && !hasError(resp)) {
const isShipmentReceived = await this.store.dispatch('order/createAndReceiveIncomingShipment', { items: eligibleItems, orderId: this.order.orderId })
if (isShipmentReceived) {
showToast(translate("Purchase order received successfully", { orderId: this.order.orderId }))
this.router.push('/purchase-orders')
} else {
this.store.dispatch("order/getOrderDetail", { orderId: this.$route.params.slug }).then(() => {
this.store.dispatch('order/getPOHistory', { orderId: this.order.orderId })
})
}
},
isEligibileForCreatingShipment() {
Expand Down
14 changes: 9 additions & 5 deletions src/views/ReturnDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
</div>

<div class="product-count">
<ion-item v-if="isReturnReceivable(current.statusId)">
<ion-item v-if="isReturnReceivable(current.statusId) && item.quantityReceived === 0">
<ion-input :label="translate('Qty')" :disabled="isForceScanEnabled" label-placement="floating" type="number" min="0" v-model="item.quantityAccepted" />
</ion-item>
<ion-item v-if="!isReturnReceivable(current.statusId)" lines="none">
<ion-item v-else lines="none">
<ion-label>{{ item.quantityAccepted }} {{ translate("received") }}</ion-label>
</ion-item>
</div>
</div>

<ion-item lines="none" class="border-top" v-if="item.quantityOrdered > 0">
<ion-button v-if="isReturnReceivable(current.statusId)" :disabled="isForceScanEnabled" @click="receiveAll(item)" slot="start" fill="outline">
<ion-button v-if="isReturnReceivable(current.statusId) && item.quantityReceived === 0" :disabled="isForceScanEnabled" @click="receiveAll(item)" slot="start" fill="outline">
{{ translate("Receive All") }}
</ion-button>
<ion-progress-bar :color="getRcvdToOrdrdFraction(item) === 1 ? 'success' : getRcvdToOrdrdFraction(item) > 1 ? 'danger' : 'primary'" :value="getRcvdToOrdrdFraction(item)" />
Expand Down Expand Up @@ -228,9 +228,13 @@ export default defineComponent({
async receiveReturn() {
const eligibleItems = this.current.items.filter((item: any) => item.quantityAccepted > 0)
const shipmentId = this.current.shipment ? this.current.shipment.shipmentId : this.current.shipmentId
let resp = await this.store.dispatch('return/receiveReturn', { items: eligibleItems, shipmentId });
if(resp.status === 200 && !hasError(resp)) {
let isReturnReceived = await this.store.dispatch('shipment/receiveShipmentJson', { items: eligibleItems, shipmentId });
if (isReturnReceived) {
showToast(translate("Return received successfully", { shipmentId: shipmentId }))
this.router.push('/returns');
} else {
showToast(translate('Something went wrong'));
await this.store.dispatch('return/setCurrent', { shipmentId: this.$route.params.id })
}
},
isEligibleForReceivingReturns() {
Expand Down
1 change: 1 addition & 0 deletions src/views/ShipmentDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export default defineComponent({
const shipmentId = this.current.shipment ? this.current.shipment.shipmentId : this.current.shipmentId
const isShipmentReceived = await this.store.dispatch('shipment/receiveShipmentJson', { items: eligibleItems, shipmentId })
if (isShipmentReceived) {
showToast(translate("Shipment received successfully", { shipmentId: shipmentId }))
this.router.push('/shipments');
} else {
showToast(translate("Failed to receive shipment"))
Expand Down

0 comments on commit b201629

Please sign in to comment.