Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented: support for multi channel inventory in sell inventory card (#382) #386

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 10 additions & 1 deletion src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ const getFieldMappings = async (payload: any): Promise <any> => {
});
}

const fetchFacilityPreferredInvGroups = async (payload: any): Promise <any> => {
return api({
url: "/service/fetchFacilityPreferredInvGroups",
method: "POST",
data: payload
});
}

export const UserService = {
addFacilityToGroup,
createFieldMapping,
Expand All @@ -330,5 +338,6 @@ export const UserService = {
getUserPermissions,
updateFacility,
updateFacilityToGroup,
updateFieldMapping
updateFieldMapping,
fetchFacilityPreferredInvGroups
}
146 changes: 80 additions & 66 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 && !facilityPreferredInvGroups)" v-model="isEComInvEnabled" @click="updateEComInvStatus($event)" slot="end" />
</ion-item>
<ion-list v-if="isEComInvEnabled || facilityPreferredInvGroups.length">
<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.length ? facilityInventoryGroups : facilityPreferredInvGroups" :key="group.facilityId">
{{ group.facilityGroupName }}
</ion-chip>
</ion-row>
</ion-item>
</ion-list>
</ion-card>
</section>

Expand Down Expand Up @@ -186,11 +198,14 @@ import {
IonContent,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonItem,
IonItemDivider,
IonLabel,
IonList,
IonMenuButton,
IonPage,
IonProgressBar,
IonRow,
IonSelect,
IonSelectOption,
IonTitle,
Expand Down Expand Up @@ -230,11 +245,14 @@ export default defineComponent({
IonContent,
IonHeader,
IonIcon,
IonItem,
IonLabel,
IonItem,
IonItemDivider,
IonLabel,
IonList,
IonMenuButton,
IonPage,
IonProgressBar,
IonRow,
IonSelect,
IonSelectOption,
IonTitle,
Expand All @@ -252,8 +270,9 @@ export default defineComponent({
currentFacilityDetails: {} as any,
orderLimitType: 'unlimited',
fulfillmentOrderLimit: "" as number | string,
facilityGroupDetails: {} as any,
isEComInvEnabled: false
facilityInventoryGroups: [] as any,
isEComInvEnabled: false,
facilityPreferredInvGroups: [] as any
};
},
computed: {
Expand Down Expand Up @@ -336,45 +355,47 @@ 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) && resp.data.docs.length) {
this.facilityInventoryGroups = resp.data.docs

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
}
// When getting data from group member enabling the eCom inventory
this.isEComInvEnabled = true
} else {
throw resp.data
}
} catch (err) {
logger.error('Failed to fetch eCom inventory config', err)
}

try {
if(!this.isEComInvEnabled) {
resp = await UserService.fetchFacilityPreferredInvGroups({
facilityId: this.currentFacility.facilityId,
oms: this.instanceUrl,
collection: 'FACILITY_PREFERENCE'
})

if(!hasError(resp)) {
this.facilityPreferredInvGroups = resp.data.docs
} else {
throw resp.data
}
}
} catch(err) {
logger.error(err)
}
},
logout () {
this.store.dispatch('user/logout', { isUserUnauthorised: false }).then((redirectionUrl) => {
Expand Down Expand Up @@ -449,44 +470,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.facilityPreferredInvGroups
.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 +528,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
Loading