Skip to content

Commit

Permalink
Merge pull request #160 from hotwax/159_inventory_group_card
Browse files Browse the repository at this point in the history
Improved: facility detail page to display dedicated card for inventory groups (#159).
  • Loading branch information
ravilodhi authored Jan 2, 2024
2 parents d43e205 + 744f73c commit 0cde687
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 71 deletions.
6 changes: 5 additions & 1 deletion src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@
"Failed to update fulfillment setting": "Failed to update fulfillment setting",
"Failed to update group description.": "Failed to update group description.",
"Failed to update primary product store": "Failed to update primary product store",
"Failed to update sell inventory online setting": "Failed to update sell inventory online setting",
"Failed to update shopify mapping": "Failed to update shopify mapping",
"Failed to update some fulfillment settings.": "Failed to update some fulfillment settings.",
"Failed to update some product stores": "Failed to update some product stores",
Expand All @@ -171,6 +172,7 @@
"Internal ID": "Internal ID",
"Internal ID cannot be more than 20 characters.": "Internal ID cannot be more than 20 characters.",
"Internal locations": "Internal locations",
"is now selling on": "{facilityName} is now selling on {facilityGroupId}.",
"Instance Url": "Instance Url",
"Language": "Language",
"Latitude": "Latitude",
Expand Down Expand Up @@ -207,6 +209,7 @@
"No facilities found": "No facilities found",
"No fulfillment capacity": "No fulfillment capacity",
"No groups found": "No groups found",
"no longer sells on": "{facilityName} no longer sells on {facilityGroupId}.",
"No party found": "No party found",
"No records found": "No records found",
"No time zone found": "No time zone found",
Expand Down Expand Up @@ -289,9 +292,10 @@
"Search time zones": "Search time zones",
"Select time zone": "Select time zone",
"Select product stores": "Select product stores",
"Select which channels this facility publishes inventory too.": "Select which channels this facility publishes inventory too.",
"Select your preferred language.": "Select your preferred language.",
"Sell Online": "Sell Online",
"Sell Inventory Online": "Sell Inventory Online",
"Sell inventory online": "Sell inventory online",
"Sequence": "Sequence",
"sequence": "sequence",
"Settings": "Settings",
Expand Down
9 changes: 9 additions & 0 deletions src/services/UtilService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,13 +113,22 @@ const fetchShopifyShop = async (payload: any): Promise<any> => {
})
}

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

export const UtilService = {
fetchCalendars,
fetchCalendarWeekTimings,
fetchCountries,
fetchExternalMappingTypes,
fetchFacilityGroupTypes,
fetchFacilityTypes,
fetchInventoryGroups,
fetchLocationTypes,
fetchProductStores,
fetchShopifyShop,
Expand Down
38 changes: 11 additions & 27 deletions src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ const actions: ActionTree<FacilityState, RootState> = {
commit(types.FACILITY_LIST_UPDATED, { facilities, total: facilities.length })
},

async fetchFacilityAdditionalInformation({ commit, state }) {
async fetchFacilityAdditionalInformation({ commit, state, rootGetters }) {
const facility = JSON.parse(JSON.stringify(state.current))

const inventoryGroups = rootGetters['util/getInventoryGroups'];

const [facilityGroupInformation, facilityOrderCount] = await Promise.all([FacilityService.fetchFacilityGroupInformation([facility.facilityId]), FacilityService.fetchFacilitiesOrderCount([facility.facilityId])])

const fulfillmentOrderLimit = facility.maximumOrderLimit
Expand All @@ -156,7 +157,6 @@ const actions: ActionTree<FacilityState, RootState> = {
const facilityGroupInfo = facilityGroupInformation[facility.facilityId]
if (facilityGroupInfo?.length) {
facility.groupInformation = facilityGroupInfo
facility.sellOnline = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'FAC_GRP'))
facility.useOMSFulfillment = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'OMS_FULFILLMENT'))
facility.generateShippingLabel = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'AUTO_SHIPPING_LABEL'))
facility.allowPickup = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'PICKUP'))
Expand All @@ -168,10 +168,16 @@ const actions: ActionTree<FacilityState, RootState> = {
facility.allowPickup = false
}

//inventory groups
inventoryGroups.forEach((group: any) => {
const isChecked = (facilityGroupInfo?.some((facilityGroup: any) => facilityGroup?.facilityGroupId === group.facilityGroupId))
group.isChecked = isChecked ? isChecked : false;
});
facility.inventoryGroups = inventoryGroups;
commit(types.FACILITY_CURRENT_UPDATED, facility)
},

async fetchCurrentFacility({ commit, state }, payload) {
async fetchCurrentFacility({ commit, dispatch, state }, payload) {
// checking that if the list contains basic information for facility then not fetching the same information again
const cachedFacilities = JSON.parse(JSON.stringify(state.facilities.list))
const current = cachedFacilities.find((facility: any) => facility.facilityId === payload.facilityId)
Expand All @@ -198,29 +204,6 @@ const actions: ActionTree<FacilityState, RootState> = {

if(!hasError(resp) && resp.data.count > 0) {
facility = resp.data.docs[0]

const [facilityGroupInformation, facilityOrderCount] = await Promise.all([FacilityService.fetchFacilityGroupInformation([facility.facilityId]), FacilityService.fetchFacilitiesOrderCount([facility.facilityId])])

const fulfillmentOrderLimit = facility.maximumOrderLimit
if (fulfillmentOrderLimit === 0) {
facility.orderLimitType = 'no-capacity'
} else if (fulfillmentOrderLimit) {
facility.orderLimitType = 'custom'
} else {
facility.orderLimitType = 'unlimited'
}

facility.orderCount = facilityOrderCount[facility.facilityId] ? facilityOrderCount[facility.facilityId] : 0;

const facilityGroupInfo = facilityGroupInformation[facility.facilityId]

if(facilityGroupInfo.length) {
facility.groupInformation = facilityGroupInfo
facility.sellOnline = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'FAC_GRP'))
facility.useOMSFulfillment = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'OMS_FULFILLMENT'))
facility.generateShippingLabel = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'AUTO_SHIPPING_LABEL'))
facility.allowPickup = (facilityGroupInfo.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'PICKUP'))
}
} else {
throw resp.data
}
Expand All @@ -229,6 +212,7 @@ const actions: ActionTree<FacilityState, RootState> = {
}

commit(types.FACILITY_CURRENT_UPDATED, { ...state.current, ...facility });
await dispatch('fetchFacilityAdditionalInformation', payload);
},

updateCurrentFacility({ commit }, facility) {
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/util/UtilState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export default interface UtilState {
countries: any[];
states: any;
shopifyShopForProductStore: any;
inventoryGroups: [];
}
27 changes: 27 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,32 @@ const actions: ActionTree<UtilState, RootState> = {
return shopifyShops[0].shopifyShopId
},

async fetchInventoryGroups({ commit }) {
let inventoryGroups = []
const params = {
entityName: "FacilityGroup",
inputFields: {
facilityGroupTypeId: 'CHANNEL_FAC_GROUP'
},
noConditionFind: 'Y',
orderBy: "facilityGroupName ASC",
fieldList: ["facilityGroupId", "facilityGroupTypeId", "facilityGroupName", "description"],
viewSize: 50
}

try {
const resp = await UtilService.fetchInventoryGroups(params)
if (!hasError(resp)) {
inventoryGroups = resp.data.docs
} else {
throw resp.data
}
} catch (error) {
logger.error(error)
}
commit(types.UTIL_INVENTORY_GROUP_UPDATED, inventoryGroups)
},

clearUtilState({ commit }) {
commit(types.UTIL_PRODUCT_STORES_UPDATED, [])
commit(types.UTIL_FACILITY_TYPES_UPDATED, [])
Expand All @@ -339,6 +365,7 @@ const actions: ActionTree<UtilState, RootState> = {
commit(types.UTIL_LOCATION_TYPES_UPDATED, {})
commit(types.UTIL_EXTERNAL_MAPPING_TYPES_UPDATED, {})
commit(types.UTIL_SHOPIFY_SHOP_UPDATED, [])
commit(types.UTIL_INVENTORY_GROUP_UPDATED, [])
},
}

Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/util/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ const getters: GetterTree<UtilState, RootState> = {
},
getShopifyShopIdForProductStore: (state) => (productStoreId: string) => {
return state.shopifyShopForProductStore[productStoreId] ? state.shopifyShopForProductStore[productStoreId] : ''
},
getInventoryGroups(state) {
return state.inventoryGroups;
}
}
export default getters;
3 changes: 2 additions & 1 deletion src/store/modules/util/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ const utilModule: Module<UtilState, RootState> = {
externalMappingTypes: {},
countries: [],
states: {},
shopifyShopForProductStore: {}
shopifyShopForProductStore: {},
inventoryGroups: []
},
getters,
actions,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/util/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export const UTIL_EXTERNAL_MAPPING_TYPES_UPDATED = SN_UTIL + '/EXTERNAL_MAPPING_
export const UTIL_PARTY_ROLES_UPDATED = SN_UTIL + '/PARTY_ROLES_UPDATED'
export const UTIL_STATES_UPDATED = SN_UTIL + '/STATES_UPDATED'
export const UTIL_SHOPIFY_SHOP_UPDATED = SN_UTIL + '/SHOPIFY_SHOP_UPDATED'
export const UTIL_INVENTORY_GROUP_UPDATED = SN_UTIL + '/INVENTORY_GROUP_UPDATED'
3 changes: 3 additions & 0 deletions src/store/modules/util/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ const mutations: MutationTree<UtilState> = {
payload.map((shopifyShop: any) => {
state.shopifyShopForProductStore[shopifyShop.productStoreId] = shopifyShop.shopifyShopId
})
},
[types.UTIL_INVENTORY_GROUP_UPDATED](state, payload) {
state.inventoryGroups = payload
}
}
export default mutations;
104 changes: 62 additions & 42 deletions src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -190,10 +190,6 @@
{{ translate("Fulfillment Settings") }}
</ion-card-title>
</ion-card-header>
<ion-item>
<ion-label>{{ translate("Sell Inventory Online") }}</ion-label>
<ion-toggle :checked="current.sellOnline" slot="end" @click="updateFulfillmentSetting($event, 'FAC_GRP')"/>
</ion-item>
<ion-item>
<ion-label>{{ translate("Allow pickup") }}</ion-label>
<ion-toggle :checked="current.allowPickup" slot="end" @click="updateFulfillmentSetting($event, 'PICKUP')"/>
Expand All @@ -214,6 +210,20 @@
{{ translate("Update days to ship") }}
</ion-button>
</ion-card>
<ion-card>
<ion-card-header>
<ion-card-title>
{{ translate("Sell inventory online") }}
</ion-card-title>
</ion-card-header>
<ion-card-content>
{{ translate("Select which channels this facility publishes inventory too.") }}
</ion-card-content>
<ion-item v-for="inventoryGroup in current.inventoryGroups" :key="inventoryGroup.facilityGroupId">
<ion-label>{{ inventoryGroup?.facilityGroupName }}</ion-label>
<ion-toggle :checked="inventoryGroup.isChecked" slot="end" @click="updateSellInventoryOnlineSetting($event, inventoryGroup)"/>
</ion-item>
</ion-card>

<ion-card>
<ion-card-header>
Expand Down Expand Up @@ -625,7 +635,7 @@ export default defineComponent({
},
props: ["facilityId"],
async ionViewWillEnter() {
this.store.dispatch('util/fetchFacilityGroupTypes')
await Promise.all([this.store.dispatch('util/fetchFacilityGroupTypes'), this.store.dispatch('util/fetchInventoryGroups')])
await Promise.all([this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId }), this.store.dispatch('util/fetchExternalMappingTypes'), this.store.dispatch('util/fetchLocationTypes'), this.store.dispatch('util/fetchPartyRoles'), this.store.dispatch('util/fetchFacilityTypes', {
parentTypeId: 'VIRTUAL_FACILITY',
parentTypeId_op: 'notEqual',
Expand Down Expand Up @@ -936,17 +946,31 @@ export default defineComponent({
facilityOrderCountModal.present()
},
async addFacilityToGroup(facilityGroupId: string) {
async updateFulfillmentSetting(event: any, facilityGroupId: string) {
event.stopImmediatePropagation();
emitter.emit("presentLoader");
let resp;
try {
resp = await FacilityService.addFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroupId
})
// Using `not` as the click event returns the current status of toggle, but on click we want to change the toggle status
const isChecked = !event.target.checked;
if(!hasError(resp)) {
try {
let resp;
if (isChecked) {
resp = await FacilityService.addFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroupId
});
} else {
const groupInformation = this.current.groupInformation.find((group: any) => group.facilityGroupId === facilityGroupId)
resp = await await FacilityService.updateFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroupId,
"fromDate": groupInformation.fromDate,
"thruDate": DateTime.now().toMillis()
})
}
if (!hasError(resp)) {
showToast(translate('Fulfillment setting updated successfully'))
await this.store.dispatch('facility/fetchFacilityAdditionalInformation')
} else {
Expand All @@ -956,49 +980,45 @@ export default defineComponent({
showToast(translate('Failed to update fulfillment setting'))
logger.error('Failed to update fulfillment setting', err)
}
emitter.emit("dismissLoader");
},
async updateFulfillmentSetting(event: any, facilityGroupId: string) {
async updateSellInventoryOnlineSetting(event: any, facilityGroup: any) {
event.stopImmediatePropagation();
emitter.emit("presentLoader");
// Using `not` as the click event returns the current status of toggle, but on click we want to change the toggle status
const isChecked = !event.target.checked;
if(isChecked) {
this.addFacilityToGroup(facilityGroupId)
} else {
this.updateFacilityToGroup(facilityGroupId)
}
},
async updateFacilityToGroup(facilityGroupId: string) {
emitter.emit("presentLoader");
let resp;
const groupInformation = this.current.groupInformation.find((group: any) => group.facilityGroupId === facilityGroupId)
try {
resp = await FacilityService.updateFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroupId,
"fromDate": groupInformation.fromDate,
"thruDate": DateTime.now().toMillis()
})
let resp;
let successMessage;
if (isChecked) {
resp = await FacilityService.addFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroup.facilityGroupId
});
successMessage = translate('is now selling on', { "facilityName": this.current.facilityName, "facilityGroupId": facilityGroup.facilityGroupName });
} else {
const groupInformation = this.current.groupInformation.find((group: any) => group.facilityGroupId === facilityGroup.facilityGroupId)
resp = await await FacilityService.updateFacilityToGroup({
"facilityId": this.current.facilityId,
"facilityGroupId": facilityGroup.facilityGroupId,
"fromDate": groupInformation.fromDate,
"thruDate": DateTime.now().toMillis()
})
successMessage = translate('no longer sells on', { "facilityName": this.current.facilityName, "facilityGroupId": facilityGroup.facilityGroupName })
}
if (!hasError(resp)) {
showToast(translate('Fulfillment setting updated successfully'))
showToast(successMessage)
await this.store.dispatch('facility/fetchFacilityAdditionalInformation')
} else {
throw resp.data
}
} catch (err) {
showToast(translate('Failed to update fulfillment setting'))
logger.error('Failed to update fulfillment setting', err)
} catch(err) {
showToast(translate('Failed to update sell inventory online setting'))
logger.error('Failed to update sell inventory online setting', err)
}
emitter.emit("dismissLoader");
},
async removeFacilityFromGroup(facilityGroupId: string) {
Expand Down

0 comments on commit 0cde687

Please sign in to comment.