diff --git a/src/locales/en.json b/src/locales/en.json index ddf814e9..41070341 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -31,6 +31,7 @@ "Custom mapping": "Custom mapping", "Country": "Country", "Days to ship": "Days to ship", + "days to ship": "days to ship", "Dismiss": "Dismiss", "Edit": "Edit", "Edit location": "Edit location", diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index d5a5a083..368f177a 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -10,21 +10,19 @@ const fetchFacilities = async(query: any): Promise => { }); } -const fetchFacilityOnlineGroupInformation = async(facilityIds: Array): Promise => { - let facilitiesWithSellOnlineEnabled = [] +const fetchFacilityGroupInformation = async(facilityIds: Array): Promise => { + let facilitiesGroupInformation = [] const params = { inputFields: { facilityId: facilityIds, - facilityId_op: "in", - facilityGroupTypeId: 'SHOPIFY_GROUP_FAC', - facilityGroupTypeId_op: 'equals' + facilityId_op: "in" }, - fieldList: ['facilityId', 'facilityGroupTypeId'], + fieldList: ['facilityId', 'facilityGroupId', 'facilityGroupTypeId', "fromDate"], entityName: "FacilityGroupAndMember", distinct: 'Y', filterByDate: 'Y', - viewSize: facilityIds.length + viewSize: facilityIds.length * 10 // multiplying the id by 10, as one facility at max will be in 10 groups } try { @@ -35,7 +33,20 @@ const fetchFacilityOnlineGroupInformation = async(facilityIds: Array): P }) as any; if(!hasError(resp) && resp.data.count > 0) { - facilitiesWithSellOnlineEnabled = resp.data.docs.map((facility: any) => facility.facilityId) + facilitiesGroupInformation = resp.data.docs.reduce((facilityGroups: any, facilityGroup: any) => { + + if(facilityGroups[facilityGroup.facilityId]) { + facilityGroups[facilityGroup.facilityId].push({ + ...facilityGroup + }) + } else { + facilityGroups[facilityGroup.facilityId] = [{ + ...facilityGroup + }] + } + + return facilityGroups + }, {}) } else { throw resp.data; } @@ -43,7 +54,7 @@ const fetchFacilityOnlineGroupInformation = async(facilityIds: Array): P logger.error(err) } - return facilitiesWithSellOnlineEnabled; + return facilitiesGroupInformation; } const fetchFacilitiesOrderCount = async(facilityIds: Array): Promise => { @@ -123,10 +134,28 @@ const updateFacility = async (payload: any): Promise => { }) } +const addFacilityToGroup = async (payload: any): Promise => { + return api({ + url: "service/addFacilityToGroup", + method: "post", + data: payload + }) +} + +const updateFacilityToGroup = async (payload: any): Promise => { + return api({ + url: "service/updateFacilityToGroup", + method: "post", + data: payload + }) +} + export const FacilityService = { - fetchFacilityOnlineGroupInformation, + addFacilityToGroup, + fetchFacilityGroupInformation, fetchFacilityOrderCounts, fetchFacilitiesOrderCount, fetchFacilities, - updateFacility + updateFacility, + updateFacilityToGroup } \ No newline at end of file diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index 26d197b3..c543654b 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -54,11 +54,10 @@ const actions: ActionTree = { if(!hasError(resp) && resp.data.count) { facilities = resp.data.docs - if(payload.viewIndex && payload.viewIndex > 0) facilities = JSON.parse(JSON.stringify(state.facilities.list)).concat(resp.data.docs) total = resp.data.count // make api calls in parallel - const facilityOnlineGroupInformation = await FacilityService.fetchFacilityOnlineGroupInformation(facilities.map((facility: any) => facility.facilityId)) + const facilitiesGroupInformation = await FacilityService.fetchFacilityGroupInformation(facilities.map((facility: any) => facility.facilityId)) const facilitiesOrderCount = await FacilityService.fetchFacilitiesOrderCount(facilities.map((facility: any) => facility.facilityId)) facilities.map((facility: any) => { @@ -73,12 +72,18 @@ const actions: ActionTree = { facility.orderCount = facilitiesOrderCount[facility.facilityId] ? facilitiesOrderCount[facility.facilityId] : 0; - if(facilityOnlineGroupInformation.includes(facility.facilityId)) { - facility.sellOnline = true - } else { - facility.sellOnline = false + const facilityGroupInformation = facilitiesGroupInformation[facility.facilityId] + + if(facilityGroupInformation.length) { + facility.groupInformation = facilityGroupInformation + facility.sellOnline = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'FAC_GRP')) + facility.useOMSFulfillment = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'OMS_FULFILLMENT')) + facility.generateShippingLabel = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'AUTO_SHIPPING_LABEL')) + facility.allowPickup = (facilityGroupInformation.some((facilityGroup: any) => facilityGroup.facilityGroupId === 'PICKUP')) } }) + + if(payload.viewIndex && payload.viewIndex > 0) facilities = JSON.parse(JSON.stringify(state.facilities.list)).concat(facilities) } else { throw resp.data } @@ -120,7 +125,7 @@ const actions: ActionTree = { if(!hasError(resp) && resp.data.count > 0) { facility = resp.data.docs[0] - const [facilityOnlineGroupInformation, facilityOrderCount] = await Promise.all([FacilityService.fetchFacilityOnlineGroupInformation(facility.facilityId), FacilityService.fetchFacilitiesOrderCount(facility.facilityId)]) + const [facilityGroupInformation, facilityOrderCount] = await Promise.all([FacilityService.fetchFacilityGroupInformation([facility.facilityId]), FacilityService.fetchFacilitiesOrderCount([facility.facilityId])]) const fulfillmentOrderLimit = facility.maximumOrderLimit if (fulfillmentOrderLimit === 0) { @@ -133,10 +138,14 @@ const actions: ActionTree = { facility.orderCount = facilityOrderCount[facility.facilityId] ? facilityOrderCount[facility.facilityId] : 0; - if(facilityOnlineGroupInformation.includes(facility.facilityId)) { - facility.sellOnline = true - } else { - facility.sellOnline = false + 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 diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 574b0573..21377cea 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -176,25 +176,25 @@ {{ translate("Sell Inventory Online") }} - + {{ translate("Uses native fulfillment app") }} - + {{ translate("Generate shipping labels") }} - + {{ translate("Allow pickup") }} - + {{ translate("Days to ship") }} - + - + {{ translate("Update days to ship") }} @@ -432,6 +432,7 @@ import { hasError } from '@/adapter'; import { showToast } from '@/utils'; import logger from '@/logger'; import ViewFacilityOrderCountModal from '@/components/ViewFacilityOrderCountModal.vue' +import { DateTime } from 'luxon'; export default defineComponent({ name: 'FacilityDetails', @@ -465,7 +466,8 @@ export default defineComponent({ return { isTimeModalOpen: false as boolean, isLoading: true, // shows whether the facility information fetching is completed or not - segment: 'external-mappings' + segment: 'external-mappings', + defaultDaysToShip: '' // not assinging 0 by default as it will convey the user that the facility can ship same day, but actually defaultDays are not setup on the facility } }, computed: { @@ -476,6 +478,7 @@ export default defineComponent({ props: ["facilityId"], async ionViewWillEnter() { await this.store.dispatch('facility/fetchCurrentFacility', { facilityId: this.facilityId }) + this.defaultDaysToShip = this.current.defaultDaysToShip this.isLoading = false }, methods: { @@ -587,6 +590,78 @@ export default defineComponent({ }) facilityOrderCountModal.present() + }, + async addFacilityToGroup(facilityGroupId: string) { + let resp; + try { + resp = await FacilityService.addFacilityToGroup({ + "facilityId": this.current.facilityId, + "facilityGroupId": facilityGroupId + }) + + if(!hasError(resp)) { + showToast(translate('Fulfillment setting updated successfully')) + } else { + throw resp.data + } + } catch (err) { + showToast(translate('Failed to update fulfillment setting')) + logger.error('Failed to update fulfillment setting', err) + } + }, + async updateFulfillmentSetting(event: any, facilityGroupId: string) { + event.stopImmediatePropagation(); + + // 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) { + 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() + }) + + if (!hasError(resp)) { + showToast(translate('Fulfillment setting updated successfully')) + } else { + throw resp.data + } + } catch (err) { + showToast(translate('Failed to update fulfillment setting')) + logger.error('Failed to update fulfillment setting', err) + } + }, + async updateDefaultDaysToShip() { + try { + const payload = { + facilityId: this.current.facilityId, + defaultDaysToShip: this.defaultDaysToShip + } + + const resp = await FacilityService.updateFacility(payload) + + if(!hasError(resp)) { + showToast(translate('Updated default days to ship')) + } else { + throw resp.data + } + } catch(err) { + logger.error('Failed to update default days to ship', err) + showToast(translate('Failed to update default days to ship')) + } } }, setup() {