diff --git a/src/services/ProductService.ts b/src/services/ProductService.ts index 45fb9448..502fd298 100644 --- a/src/services/ProductService.ts +++ b/src/services/ProductService.ts @@ -69,11 +69,45 @@ const addProductToFacility = async (payload: any): Promise => { }); } +const getCurrentFacilityLocation = async (facilityId: string): Promise => { + let locationSeqId; + + try { + const params = { + "inputFields": { + facilityId + }, + "viewSize": 1, + "entityName": "FacilityLocation", + "fieldList": ["areaId", "aisleId", "sectionId", "levelId", "positionId", "locationSeqId"] + } + + const resp = await ProductService.getFacilityLocations(params); + if (!hasError(resp) && resp.data.docs.length) { + locationSeqId = resp.data.docs[0].locationSeqId + } + } catch (err) { + console.error(err); + } + + return locationSeqId; +} + +const createProductFacilityLocation = async (payload: any): Promise => { + return api({ + url: "service/createProductFacilityLocation", + method: "post", + data: payload + }); +} + export const ProductService = { addProductToFacility, + createProductFacilityLocation, fetchProducts, importInventoryCount, isProductFacilityAssocExists, + getCurrentFacilityLocation, getFacilityLocations, updateVariance } \ No newline at end of file diff --git a/src/views/count.vue b/src/views/count.vue index 72baf8c1..27256c47 100644 --- a/src/views/count.vue +++ b/src/views/count.vue @@ -212,12 +212,12 @@ }); await picker.present(); }, - updateProductInventoryCount() { + async updateProductInventoryCount() { if (this.quantity) { this.product.quantity = this.quantity; this.product.availableQOH = this.availableQOH; //Create the ProductFacility record if it does not exist. - this.checkAndCreateProductFacilityAssoc(); + await this.checkAndCreateProductFacilityAssoc(); this.store.dispatch('product/updateInventoryCount', { ...this.product, locationId: this.product.locationId }); showToast(translate("Item added to upload list"), [{ text: translate('View'), @@ -232,15 +232,30 @@ } }, async checkAndCreateProductFacilityAssoc() { + let resp; try { if (!await ProductService.isProductFacilityAssocExists(this.product.productId, this.facility.facilityId)) { - const resp = await ProductService.addProductToFacility({ + resp = await ProductService.addProductToFacility({ productId: this.product.productId, facilityId: this.facility.facilityId }); if (hasError(resp)) { throw resp.data; } + + const locationSeqId = await ProductService.getCurrentFacilityLocation(this.facility.facilityId) + + resp = await ProductService.createProductFacilityLocation({ + productId: this.product.productId, + facilityId: this.facility.facilityId, + locationSeqId + }); + + if (!hasError(resp)) { + await this.getFacilityLocations() + } else { + throw resp.data; + } } } catch (err) { console.error(err); @@ -339,6 +354,9 @@ }, async updateProductVarianceCount() { emitter.emit("presentLoader"); + + await this.checkAndCreateProductFacilityAssoc(); + let resp; try { const params = {