Skip to content

Commit

Permalink
Merge branch 'main' into #dxp/288-facility-selector
Browse files Browse the repository at this point in the history
  • Loading branch information
R-Sourabh committed Nov 18, 2024
2 parents ae76142 + 8ce5e7d commit e5f615b
Show file tree
Hide file tree
Showing 14 changed files with 363 additions and 49 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "receiving",
"version": "2.27.5",
"version": "2.28.1",
"private": true,
"description": "HotWax Commerce Receiving App",
"scripts": {
Expand Down
59 changes: 49 additions & 10 deletions src/components/ClosePurchaseOrderModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import { mapGetters, useStore } from 'vuex'
import { OrderService } from "@/services/OrderService";
import { DxpShopifyImg, translate, getProductIdentificationValue, useProductIdentificationStore } from '@hotwax/dxp-components';
import { useRouter } from 'vue-router';
import { hasError } from '@/utils';
export default defineComponent({
name: "ClosePurchaseOrderModal",
Expand Down Expand Up @@ -130,20 +131,58 @@ export default defineComponent({
}
const eligibleItems = this.order.items.filter((item: any) => item.isChecked && this.isPOItemStatusPending(item))
const responses = await Promise.allSettled(eligibleItems.map(async (item: any) => {
await OrderService.updatePOItemStatus({
orderId: item.orderId,
orderItemSeqId: item.orderItemSeqId,
let hasFailedItems = false;
let completedItems = [] as any;
let lastItem = {} as any;
if(eligibleItems.length > 1) {
const itemsToBatchUpdate = eligibleItems.slice(0, -1);
lastItem = eligibleItems[eligibleItems.length - 1];
const batchSize = 10;
while(itemsToBatchUpdate.length) {
const itemsToUpdate = itemsToBatchUpdate.splice(0, batchSize)
const responses = await Promise.allSettled(itemsToUpdate.map(async(item: any) => {
await OrderService.updatePOItemStatus({
orderId: item.orderId,
orderItemSeqId: item.orderItemSeqId,
statusId: "ITEM_COMPLETED"
})
return item.orderItemSeqId
}))
responses.map((response: any) => {
if(response.status === "fulfilled") {
completedItems.push(response.value)
} else {
hasFailedItems = true
}
})
}
} else {
lastItem = eligibleItems[0]
}
try{
const resp = await OrderService.updatePOItemStatus({
orderId: lastItem.orderId,
orderItemSeqId: lastItem.orderItemSeqId,
statusId: "ITEM_COMPLETED"
})
return item.orderItemSeqId
}))
const failedItemsCount = responses.filter((response) => response.status === 'rejected').length
if(failedItemsCount){
console.error('Failed to update the status of purchase order items.')
if(!hasError(resp)) {
completedItems.push(lastItem.orderItemSeqId)
} else {
throw resp.data;
}
} catch(error: any) {
hasFailedItems = true;
}
const completedItems = responses.filter((response) => response.status === 'fulfilled')?.map((response: any) => response.value)
if(hasFailedItems){
console.error('Failed to update the status of purchase order items.')
}
if(!completedItems.length) return;
Expand Down
4 changes: 3 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"No shipments have been received against this purchase order yet": "No shipments have been received against {lineBreak} this purchase order yet",
"OMS": "OMS",
"OMS instance": "OMS instance",
"on hand": "{ qoh } on hand",
"Only allow received quantity to be incremented by scanning the barcode of products. If the identifier is not found, the scan will default to using the internal name.": "Only allow received quantity to be incremented by scanning the barcode of products. {space} If the identifier is not found, the scan will default to using the internal name.",
"Open": "Open",
"ordered": "ordered",
Expand All @@ -83,6 +84,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 All @@ -108,7 +110,7 @@
"Scanned item is not present within the shipment:": "Scanned item is not present within the shipment: {itemName}",
"Scanned successfully.": "Scanned {itemName} successfully.",
"Search items": "Search items",
"Searched item is not present within the shipment:": "Scanned item is not present within the shipment: {itemName}",
"Searched item is not present within the shipment:": "Searched item is not present within the shipment: {itemName}",
"secondary identifier": "secondary identifier",
"Search": "Search",
"Search facilities": "Search facilities",
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
30 changes: 28 additions & 2 deletions src/services/ProductService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { api } from '@/adapter';
import { api, hasError } from '@/adapter';
import store from '@/store';

const fetchProducts = async (query: any): Promise <any> => {
return api({
Expand All @@ -9,6 +10,31 @@ const fetchProducts = async (query: any): Promise <any> => {
})
}

const getInventoryAvailableByFacility = async (productId: any): Promise<any> => {
let productQoh = ''
const payload = {
productId: productId,
facilityId: store.getters['user/getCurrentFacility']?.facilityId
}

try {
const resp: any = await api({
url: "service/getInventoryAvailableByFacility",
method: "post",
data: payload
})
if (!hasError(resp)) {
productQoh = resp?.data.quantityOnHandTotal;
} else {
throw resp.data;
}
} catch (err) {
console.error(err)
}
return productQoh;
}

export const ProductService = {
fetchProducts
fetchProducts,
getInventoryAvailableByFacility
}
42 changes: 42 additions & 0 deletions src/services/UploadService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { api } from '@/adapter';
import { UploadRequest } from '@/types'

const uploadJsonFile = async (payload: any): Promise <any> => {
return api({
url: "uploadAndImportFile",
method: "post",
...payload
});
}

const prepareUploadJsonPayload = (request: UploadRequest) => {
const blob = new Blob([JSON.stringify(request.uploadData)], { type: 'application/json'});
const formData = new FormData();
const fileName = request.fileName ? request.fileName : Date.now() + ".json" ;
formData.append("uploadedFile", blob, fileName);
if (request.params) {
for (const key in request.params) {
formData.append(key, request.params[key]);
}
}
return {
data: formData,
headers: {
'Content-Type': 'multipart/form-data;'
}
}
}

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

export const UploadService = {
fetchDataManagerLog,
prepareUploadJsonPayload,
uploadJsonFile
}
47 changes: 46 additions & 1 deletion src/store/modules/order/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,50 @@ const actions: ActionTree<OrderState, RootState> = {
return resp;
},

async createAndReceiveIncomingShipment({ commit }, payload) {

Check warning on line 154 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 154 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 @@ -162,7 +206,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 currentFacilityId = getCurrentFacilityId()
const facilityLocations = await this.dispatch('user/getFacilityLocations', currentFacilityId);
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
72 changes: 72 additions & 0 deletions src/store/modules/shipment/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ import { hasError, showToast, getCurrentFacilityId } from '@/utils'
import { getProductIdentificationValue, translate, useUserStore } from '@hotwax/dxp-components'

Check warning on line 7 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'useUserStore' is defined but never used

Check warning on line 7 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'useUserStore' is defined but never used
import emitter from '@/event-bus'
import store from "@/store";
import { DateTime } from 'luxon';
import { UploadService } from "@/services/UploadService";
import { toHandlerKey } from "vue";

Check warning on line 12 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'toHandlerKey' is defined but never used

Check warning on line 12 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'toHandlerKey' is defined but never used

const actions: ActionTree<ShipmentState, RootState> = {
async findShipment ({ commit, state }, payload) {
Expand Down Expand Up @@ -139,6 +142,75 @@ const actions: ActionTree<ShipmentState, RootState> = {

return areAllSuccess;
},
async receiveShipmentJson ({ dispatch }, payload) {

Check warning on line 145 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'dispatch' is defined but never used

Check warning on line 145 in src/store/modules/shipment/actions.ts

View workflow job for this annotation

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

'dispatch' is defined but never used
emitter.emit("presentLoader");
const fileName = `ReceiveShipment_${payload.shipmentId}_${DateTime.now().toLocaleString(DateTime.DATETIME_MED_WITH_SECONDS)}.json`;
const params = {
"configId": "RECEIVE_SHIP_ITEMS"
}
if(!payload.isMultiReceivingEnabled) {
payload.items = payload.items.filter((item: any) => item.quantityReceived === 0)
}
const uploadData = payload.items.map((item: any) => {
return {
shipmentId: payload.shipmentId,
facilityId: this.state.user.currentFacility.facilityId,
shipmentItemSeqId: item.itemSeqId,
productId: item.productId,
quantityAccepted: item.quantityAccepted,
orderId: item.orderId,
orderItemSeqId: item.orderItemSeqId,
unitCost: 0.00,
locationSeqId: item.locationSeqId
};
})

try {
const uploadPayload = UploadService.prepareUploadJsonPayload({
uploadData,
fileName,
params
});
let resp = await UploadService.uploadJsonFile(uploadPayload);
if (resp.status == 200 && !hasError(resp)) {
const uploadFileContentId = resp.data.uploadFileContentId;
if (uploadFileContentId) {
resp = await UploadService.fetchDataManagerLog({
"inputFields": {
"configId": "RECEIVE_SHIP_ITEMS",
"uploadFileContentId": uploadFileContentId,
"errorRecordContentId_op": "empty",
"statusI": "SERVICE_FINISHED",
},
"fieldList": ["logId", "configId", "uploadFileContentId", "errorRecordContentId", "statusId"],
"entityName": "DataManagerLog",
"viewSize": 1
});
if (!hasError(resp) && resp.data.docs.length) {
//If there is no error and file is processed then mark the shipment as received
resp = await ShipmentService.receiveShipment({
"shipmentId": payload.shipmentId,
"statusId": "PURCH_SHIP_RECEIVED"
})
if (resp.status == 200 && !hasError(resp)) {
return true;
} else {
throw resp.data;
}
} else {
throw resp.data;
}
}
} else {
throw resp.data;
}
} catch (err) {
showToast(translate("Something went wrong, please try again"));
}
emitter.emit("dismissLoader");
return false;
},

async receiveShipment ({ dispatch }, payload) {
emitter.emit("presentLoader", {message: 'Receiving in-progress.', backdropDismiss: false});
const areAllSuccess = await dispatch("receiveShipmentItem", payload);
Expand Down
5 changes: 5 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export interface UploadRequest {
params?: any;
fileName?: string;
uploadData: any;
}
Loading

0 comments on commit e5f615b

Please sign in to comment.