Skip to content

Commit

Permalink
Implemented: support for multi channel inventory in sell inventory ca…
Browse files Browse the repository at this point in the history
…rd (hotwax#382)
  • Loading branch information
amansinghbais committed Jan 10, 2024
1 parent ed17aa5 commit 9748ae0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 62 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"Click the backdrop to dismiss.": "Click the backdrop to dismiss.",
"Change": "Change",
"Changes to the CSV mapping has been saved.": "Changes to the CSV mapping has been saved.",
"Channels": "Channels",
"Check stock": "Check stock",
"Choose language": "Choose language",
"City": "City",
Expand Down
113 changes: 51 additions & 62 deletions src/views/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,20 @@
</ion-card-content>
<ion-item lines="none">
<ion-label>{{ translate("Sell online") }}</ion-label>
<ion-toggle :disabled="!hasPermission(Actions.APP_UPDT_ECOM_INV_CONFIG) || !facilityGroupDetails?.facilityGroupId" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
<ion-toggle :disabled="!hasPermission(Actions.APP_UPDT_ECOM_INV_CONFIG) || !isEComInvEnabled" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
</ion-item>
<ion-list v-if="isEComInvEnabled">
<ion-item-divider color="light">
<ion-label>{{ translate("Channels") }}</ion-label>
</ion-item-divider>
<ion-item lines="none">
<ion-row>
<ion-chip v-for="group in facilityInventoryGroups" :key="group.facilityId">
{{ group.facilityGroupName }}
</ion-chip>
</ion-row>
</ion-item>
</ion-list>
</ion-card>
</section>

Expand Down Expand Up @@ -252,7 +264,7 @@ export default defineComponent({
currentFacilityDetails: {} as any,
orderLimitType: 'unlimited',
fulfillmentOrderLimit: "" as number | string,
facilityGroupDetails: {} as any,
facilityInventoryGroups: [] as any,
isEComInvEnabled: false
};
},
Expand Down Expand Up @@ -336,39 +348,23 @@ export default defineComponent({
let resp: any;
try {
this.isEComInvEnabled = false
this.facilityGroupDetails = {}
this.facilityInventoryGroups = []
resp = await UserService.getFacilityGroupDetails({
"entityName": "FacilityGroup",
resp = await UserService.getFacilityGroupAndMemberDetails({
"entityName": "FacilityGroupAndMember",
"inputFields": {
"facilityGroupTypeId": 'SHOPIFY_GROUP_FAC'
"facilityId": this.currentFacility.facilityId,
"facilityGroupTypeId": 'CHANNEL_FAC_GROUP'
},
"fieldList": ["facilityGroupId", "facilityGroupTypeId"],
"viewSize": 1,
"filterByDate": 'Y',
"fieldList": ["facilityGroupId", "facilityGroupName", "fromDate"]
})
if (!hasError(resp)) {
// using facilityGroupId as a flag for getting data from getFacilityGroupDetails
this.facilityGroupDetails.facilityGroupId = resp.data.docs[0].facilityGroupId
resp = await UserService.getFacilityGroupAndMemberDetails({
"entityName": "FacilityGroupAndMember",
"inputFields": {
"facilityId": this.currentFacility.facilityId,
"facilityGroupId": this.facilityGroupDetails.facilityGroupId
},
"fieldList": ["facilityId", "fromDate"],
"viewSize": 1,
"filterByDate": 'Y'
})
if (!hasError(resp)) {
this.facilityGroupDetails = { ...this.facilityGroupDetails, ...resp.data.docs[0] }
// When getting data from group member enabling the eCom inventory
this.isEComInvEnabled = true
} else {
throw resp.data
}
if (!hasError(resp) && resp.data.docs.length) {
this.facilityInventoryGroups = resp.data.docs
// When getting data from group member enabling the eCom inventory
this.isEComInvEnabled = true
} else {
throw resp.data
}
Expand Down Expand Up @@ -449,44 +445,37 @@ export default defineComponent({
logger.error('Failed to update facility', err)
}
},
async updateFacilityToGroup() {
let resp;
try {
resp = await UserService.updateFacilityToGroup({
async removeFacilityInvGroups() {
const updateResponses = await Promise.allSettled(this.facilityInventoryGroups
.map(async (payload: any) => await UserService.updateFacilityToGroup({
"facilityId": this.currentFacility.facilityId,
"facilityGroupId": this.facilityGroupDetails.facilityGroupId,
"fromDate": this.facilityGroupDetails.fromDate,
"facilityGroupId": payload.facilityGroupId,
"fromDate": payload.fromDate,
"thruDate": DateTime.now().toMillis()
})
}))
)
if (!hasError(resp)) {
this.isEComInvEnabled = false
showToast(translate('ECom inventory status updated successfully'))
} else {
throw resp.data
}
} catch (err) {
showToast(translate('Failed to update eCom inventory status'))
logger.error('Failed to update eCom inventory status', err)
const hasFailedResponse = updateResponses.some((response: any) => response.status === 'rejected')
if (hasFailedResponse) {
showToast(translate('Failed to update some eCom inventory status'))
} else {
showToast(translate('ECom inventory status updated successfully'))
}
await this.getEcomInvStatus()
},
async addFacilityToGroup() {
let resp;
try {
resp = await UserService.addFacilityToGroup({
async addFacilityInvGroups() {
const addResponses = await Promise.allSettled(this.facilityInventoryGroups
.map(async (payload: any) => await UserService.addFacilityToGroup({
"facilityId": this.currentFacility.facilityId,
"facilityGroupId": this.facilityGroupDetails.facilityGroupId
})
"facilityGroupId": payload.facilityGroupId
}))
)
if (!hasError(resp)) {
this.isEComInvEnabled = true
showToast(translate('ECom inventory status updated successfully'))
} else {
throw resp.data
}
} catch (err) {
showToast(translate('Failed to update eCom inventory status'))
logger.error('Failed to update eCom inventory status', err)
const hasFailedResponse = addResponses.some((response: any) => response.status === 'rejected')
if (hasFailedResponse) {
showToast(translate('Failed to update some eCom inventory status'))
} else {
showToast(translate('ECom inventory status updated successfully'))
}
},
async updateEComInvStatus(event: any) {
Expand Down Expand Up @@ -514,7 +503,7 @@ export default defineComponent({
const { role } = await alert.onDidDismiss();
if(role) {
isChecked ? await this.addFacilityToGroup() : await this.updateFacilityToGroup()
isChecked ? await this.addFacilityInvGroups() : await this.removeFacilityInvGroups()
}
},
Expand Down

0 comments on commit 9748ae0

Please sign in to comment.