diff --git a/src/services/StockService.ts b/src/services/StockService.ts index 8941484ac..e22be78fd 100644 --- a/src/services/StockService.ts +++ b/src/services/StockService.ts @@ -1,4 +1,4 @@ -import { api } from '@/adapter'; +import { api, hasError } from '@/adapter'; const checkInventory = async (query: any): Promise => { return api({ @@ -16,7 +16,16 @@ const getInventoryAvailableByFacility = async (query: any): Promise => { }); } +const getInventoryComputation = async (payload: any ): Promise => { + return api({ + url: 'performFind', + method: 'post', + data: payload + }); +} + export const StockService = { checkInventory, - getInventoryAvailableByFacility + getInventoryAvailableByFacility, + getInventoryComputation } \ No newline at end of file diff --git a/src/store/modules/stock/StockState.ts b/src/store/modules/stock/StockState.ts index 128855bc6..80416cb19 100644 --- a/src/store/modules/stock/StockState.ts +++ b/src/store/modules/stock/StockState.ts @@ -1,3 +1,4 @@ export default interface StockState { products: any; + count: any; } \ No newline at end of file diff --git a/src/store/modules/stock/actions.ts b/src/store/modules/stock/actions.ts index b8d36d70d..605a20634 100644 --- a/src/store/modules/stock/actions.ts +++ b/src/store/modules/stock/actions.ts @@ -26,6 +26,30 @@ const actions: ActionTree = { logger.error(err) showToast(translate('No data available!')) } + }, + + async fetchInvCount({ commit }, { productId }) { + try { + + const params = { + "entityName": "ProductFacility", + "inputFields": { + productId, + "facilityId": this.state.user.currentFacility.facilityId + }, + "fieldList": ["minimumStock", "lastInventoryCount"], + "viewSize": 1 + } as any + + const resp: any = await StockService.getInventoryComputation(params); + if(!hasError(resp)) { + commit(types.INVENTORY_COMPUTATIONS, { productId: productId, facilityId: this.state.user.currentFacility.facilityId, minimumStock: resp.minimumStock, lastInventoryCount: resp.lastInventoryCount}) + } + } + catch (err) { + logger.error(err) + showToast(translate('No data available!')) + } } } export default actions; \ No newline at end of file diff --git a/src/store/modules/stock/getters.ts b/src/store/modules/stock/getters.ts index 59ebd8f02..77f3b2332 100644 --- a/src/store/modules/stock/getters.ts +++ b/src/store/modules/stock/getters.ts @@ -7,6 +7,9 @@ const getters: GetterTree = { getProductStock: (state, RootState) => (productId: any) => { const facilityId = store.state.user?.currentFacility?.facilityId return state.products[productId] ? state.products[productId][facilityId] ? state.products[productId][facilityId] : {} : {} + }, + getInventoryCount: (state) => { + return state.count; } } export default getters; \ No newline at end of file diff --git a/src/store/modules/stock/index.ts b/src/store/modules/stock/index.ts index a4bbc14b8..1e1a4c252 100644 --- a/src/store/modules/stock/index.ts +++ b/src/store/modules/stock/index.ts @@ -8,7 +8,8 @@ import RootState from '../../RootState' const stockModule: Module = { namespaced: true, state: { - products: {} + products: {}, + count: {}, }, getters, actions, diff --git a/src/store/modules/stock/mutation-types.ts b/src/store/modules/stock/mutation-types.ts index 3937ac90e..7bd23a022 100644 --- a/src/store/modules/stock/mutation-types.ts +++ b/src/store/modules/stock/mutation-types.ts @@ -1,2 +1,3 @@ export const SN_STOCK = 'stock' -export const STOCK_ADD_PRODUCT = SN_STOCK + '/ADD_PRODUCT' \ No newline at end of file +export const STOCK_ADD_PRODUCT = SN_STOCK + '/ADD_PRODUCT' +export const INVENTORY_COMPUTATIONS = SN_STOCK + '/INVENTORY_COMPUTATIONS' \ No newline at end of file diff --git a/src/store/modules/stock/mutations.ts b/src/store/modules/stock/mutations.ts index cc2f3329d..5ab73c122 100644 --- a/src/store/modules/stock/mutations.ts +++ b/src/store/modules/stock/mutations.ts @@ -11,6 +11,16 @@ const mutations: MutationTree = { [payload.facilityId]: payload.stock } } + }, + [types.INVENTORY_COMPUTATIONS] (state, { productId, facilityId, minimumStock, lastInventoryCount }) { + if (!state.count[productId]) { + state.count[productId] = {}; + } + + state.count[productId][facilityId] = { + minimumStock, + lastInventoryCount + }; } } export default mutations; \ No newline at end of file diff --git a/src/views/ProductDetail.vue b/src/views/ProductDetail.vue index 24870c04c..301920588 100644 --- a/src/views/ProductDetail.vue +++ b/src/views/ProductDetail.vue @@ -60,7 +60,7 @@ Quantity on hand - 10 + {{ getProductStock(product)?.quantityOnHandTotal ?? '0' }} Safety Stock @@ -72,18 +72,18 @@ Available to promise - 70 + {{ }} Other Stores - 100 ATP + {{ otherStoresInventory }} Warehouse - 100 ATP + {{ warehouseInventory }} @@ -228,11 +228,15 @@ export default defineComponent({ ...mapGetters({ product: "product/getCurrent", currentFacility: 'user/getCurrentFacility', - currency: 'user/getCurrency' + currency: 'user/getCurrency', + getProductStock: 'stock/getProductStock', + getInventoryCount: 'stock/getInventoryCount', }) }, async beforeMount() { await this.store.dispatch('product/setCurrent', { productId: this.$route.params.productId }) + await this.store.dispatch('stock/fetchStock', { productId: this.$route.params.productId }) + await this.store.dispatch('stock/fetchInvCount', { productId: this.$route.params.productId }); if (this.product.variants) { this.getFeatures() await this.updateVariant() @@ -245,6 +249,7 @@ export default defineComponent({ await this.updateVariant(); }, getFeatures() { + console.log(this.getInventoryCount); const features = {} as any this.product.variants.map((variant: any) => { const size = getFeature(variant.featureHierarchy, '1/SIZE/');