Skip to content

Commit

Permalink
Implemented: API for fetcting the minimumStock & lastInventoryCount(#386
Browse files Browse the repository at this point in the history
)
  • Loading branch information
R-Sourabh committed May 13, 2024
1 parent 02f00ed commit bcc09ee
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 9 deletions.
13 changes: 11 additions & 2 deletions src/services/StockService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { api } from '@/adapter';
import { api, hasError } from '@/adapter';

const checkInventory = async (query: any): Promise <any> => {
return api({
Expand All @@ -16,7 +16,16 @@ const getInventoryAvailableByFacility = async (query: any): Promise <any> => {
});
}

const getInventoryComputation = async (payload: any ): Promise<any> => {
return api({
url: 'performFind',
method: 'post',
data: payload
});
}

export const StockService = {
checkInventory,
getInventoryAvailableByFacility
getInventoryAvailableByFacility,
getInventoryComputation
}
1 change: 1 addition & 0 deletions src/store/modules/stock/StockState.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export default interface StockState {
products: any;
count: any;
}
24 changes: 24 additions & 0 deletions src/store/modules/stock/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,30 @@ const actions: ActionTree<StockState, RootState> = {
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;
3 changes: 3 additions & 0 deletions src/store/modules/stock/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const getters: GetterTree <StockState, RootState> = {
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;
3 changes: 2 additions & 1 deletion src/store/modules/stock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import RootState from '../../RootState'
const stockModule: Module<StockState, RootState> = {
namespaced: true,
state: {
products: {}
products: {},
count: {},
},
getters,
actions,
Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/stock/mutation-types.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const SN_STOCK = 'stock'
export const STOCK_ADD_PRODUCT = SN_STOCK + '/ADD_PRODUCT'
export const STOCK_ADD_PRODUCT = SN_STOCK + '/ADD_PRODUCT'
export const INVENTORY_COMPUTATIONS = SN_STOCK + '/INVENTORY_COMPUTATIONS'
10 changes: 10 additions & 0 deletions src/store/modules/stock/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ const mutations: MutationTree <StockState> = {
[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;
15 changes: 10 additions & 5 deletions src/views/ProductDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<ion-list v-if="selectedSegment === 'inStore'">
<ion-item>
<ion-label class="ion-text-wrap">Quantity on hand</ion-label>
<ion-note slot="end">10</ion-note>
<ion-note slot="end">{{ getProductStock(product)?.quantityOnHandTotal ?? '0' }}</ion-note>
</ion-item>
<ion-item>
<ion-label class="ion-text-wrap">Safety Stock</ion-label>
Expand All @@ -72,18 +72,18 @@
</ion-item>
<ion-item lines="none">
<ion-label class="ion-text-wrap">Available to promise</ion-label>
<ion-badge color="success" slot="end">70</ion-badge>
<ion-badge color="success" slot="end">{{ }}</ion-badge>
</ion-item>
</ion-list>

<ion-list v-if="selectedSegment === 'otherLocations'">
<ion-item>
<ion-label class="ion-text-wrap">Other Stores</ion-label>
<ion-button @click="getOtherStoresInventoryDetails()" fill="outline">100 ATP</ion-button>
<ion-button @click="getOtherStoresInventoryDetails()" fill="outline">{{ otherStoresInventory }}</ion-button>
</ion-item>
<ion-item lines="none">
<ion-label class="ion-text-wrap">Warehouse</ion-label>
<ion-note slot="end">100 ATP</ion-note>
<ion-note slot="end">{{ warehouseInventory }}</ion-note>
</ion-item>
</ion-list>
</div>
Expand Down Expand Up @@ -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()
Expand All @@ -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/');
Expand Down

0 comments on commit bcc09ee

Please sign in to comment.