diff --git a/src/components/ViewFacilityOrderCountModal.vue b/src/components/ViewFacilityOrderCountModal.vue new file mode 100644 index 00000000..599d10eb --- /dev/null +++ b/src/components/ViewFacilityOrderCountModal.vue @@ -0,0 +1,93 @@ + + + + + + + + + {{ translate("Consumed Order Limit") }} + + + + + + + {{ translate('Entry Date') }} + {{ translate('Consumed Order Limit') }} + + + {{ facilityOrderCount.entryDate }} + {{ facilityOrderCount.lastOrderCount }} + + + + {{ translate('No records found') }} + + + + + + + \ No newline at end of file diff --git a/src/locales/en.json b/src/locales/en.json index 6682229d..aef34439 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -66,6 +66,7 @@ "Location": "Location", "Location details": "Location details", "Locations": "Locations", + "Logging in": "Logging in", "Logging out": "Logging out", "Login": "Login", "Login failed": "Login failed", @@ -89,6 +90,8 @@ "Opening Time": "Opening Time", "Operating hours": "Operating hours", "Order fulfillment capacity": "Order fulfillment capacity", + "orders allocated today": "{orderCount} orders allocated today", + "orders in fulfillment queue": "{orderCount} orders in fulfillment queue", "Parking": "Parking", "party id": "party id", "Party Id": "Party Id", @@ -144,6 +147,7 @@ "Timezone": "Timezone", "Tuesday": "Tuesday", "Type": "Type", + "Unlimited": "Unlimited", "Unlimited Capacity": "Unlimited Capacity", "Unlimited capacity removes the fulfillment capacity limit entirely. To add a fulfillment capacity to this facility, use the custom option.": "Unlimited capacity removes the fulfillment capacity limit entirely. To add a fulfillment capacity to this facility, use the custom option.", "Unlimited fulfillment capacity": "Unlimited fulfillment capacity", diff --git a/src/services/FacilityService.ts b/src/services/FacilityService.ts index c37192cf..e4cb775d 100644 --- a/src/services/FacilityService.ts +++ b/src/services/FacilityService.ts @@ -67,10 +67,7 @@ const fetchFacilitiesOrderCount = async(facilityIds: Array): Promise 0) { facilitiesOrderCount = resp.data.docs.reduce((facilitiesCount: any, facilityCount: any) => { facilitiesCount[facilityCount.facilityId] = facilityCount.lastOrderCount return facilitiesCount @@ -85,6 +82,40 @@ const fetchFacilitiesOrderCount = async(facilityIds: Array): Promise => { + let facilityOrderCounts = {}, resp: any; + try { + const params = { + entityName: "FacilityOrderCount", + inputFields: { + facilityId: facilityId + }, + viewSize: 10, // only fetching last 10 order consumed information for facility + fieldList: ["entryDate", "facilityId", "lastOrderCount"], + orderBy: "entryDate DESC" + } + + resp = await api({ + url: "performFind", + method: "post", + data: params + }) + + if (!hasError(resp) && resp.data.count > 0) { + facilityOrderCounts = resp.data.docs.map((facilityOrderCount: any) => { + facilityOrderCount.entryDate = DateTime.fromMillis(facilityOrderCount.entryDate).toFormat('MMM dd yyyy') + return facilityOrderCount + }) + } else { + throw resp.data + } + } catch(err) { + logger.error("Failed to fetch order consumed history for this facility", err); + } + + return facilityOrderCounts; +} + const updateFacility = async (payload: any): Promise => { return api({ url: "service/updateFacility", @@ -120,6 +151,7 @@ const updateProductStoreFacility = async (payload: any): Promise => { export const FacilityService = { createProductStoreFacility, fetchFacilityOnlineGroupInformation, + fetchFacilityOrderCounts, fetchFacilitiesOrderCount, fetchFacilities, getFacilityProductStores, diff --git a/src/store/modules/facility/actions.ts b/src/store/modules/facility/actions.ts index e3d8b517..fdcd43ab 100644 --- a/src/store/modules/facility/actions.ts +++ b/src/store/modules/facility/actions.ts @@ -112,13 +112,32 @@ const actions: ActionTree = { viewSize: 1 } - let facility = {}; + let facility = {} as any; try { const resp = await FacilityService.fetchFacilities(params) 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 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; + + if(facilityOnlineGroupInformation.includes(facility.facilityId)) { + facility.sellOnline = true + } else { + facility.sellOnline = false + } } else { throw resp.data } diff --git a/src/views/FacilityDetails.vue b/src/views/FacilityDetails.vue index 4d93979b..3a5fd6fd 100644 --- a/src/views/FacilityDetails.vue +++ b/src/views/FacilityDetails.vue @@ -201,12 +201,20 @@ {{ translate("Setting fulfillment capacity to 0 disables new order from being allocated to this facility. Leave this empty if this facility's fulfillment capacity is unrestricted.") }} - - {{ 10 }} - - {{ 20 }} + + {{ current.orderCount }} + + {{ current.maximumOrderLimit }} + + + {{ translate("orders allocated today", { orderCount: current.orderCount }) }} + {{ translate("Unlimited") }} + + + {{ translate("orders in fulfillment queue", { orderCount: current.orderCount }) }} + {{ current.maximumOrderLimit }} - + {{ translate("View order count history") }} @@ -409,9 +417,13 @@ import SelectOperatingTimeModal from '@/components/SelectOperatingTimeModal.vue' import AddLocationModal from '@/components/AddLocationModal.vue'; import AddStaffMemberModal from '@/components/AddStaffMemberModal.vue'; import { mapGetters, useStore } from 'vuex'; -import { showToast } from '@/utils'; +import OrderLimitPopover from '@/components/OrderLimitPopover.vue' import { FacilityService } from '@/services/FacilityService'; +import { hasError } from '@/adapter'; +import { showToast } from '@/utils'; import { DateTime } from 'luxon'; +import logger from '@/logger'; +import ViewFacilityOrderCountModal from '@/components/ViewFacilityOrderCountModal.vue' export default defineComponent({ name: 'FacilityDetails', @@ -569,6 +581,49 @@ export default defineComponent({ }, getStoreDetail(productStoreId: any) { return this.productStores.find((store: any) => store.productStoreId === productStoreId) + }, + async changeOrderLimitPopover(ev: Event) { + const popover = await popoverController.create({ + component: OrderLimitPopover, + event: ev, + showBackdrop: false, + componentProps: { fulfillmentOrderLimit: this.current.maximumOrderLimit } + }); + popover.present(); + + const result = await popover.onDidDismiss(); + // Note: here result.data returns 0 in some cases that's why it is compared with 'undefined'. + if(result.data != undefined && result.data !== this.current.maximumOrderLimit) { + await this.updateFacility(result.data, this.current) + } + }, + async updateFacility(maximumOrderLimit: number | string, facility: any) { + let resp; + + try { + resp = await FacilityService.updateFacility({ + "facilityId": facility.facilityId, + maximumOrderLimit + }) + + if(!hasError(resp)) { + facility.maximumOrderLimit = maximumOrderLimit === "" ? null : maximumOrderLimit + showToast(translate('Fulfillment capacity updated successfully for ', { facilityName: facility.facilityName })) + } else { + throw resp.data + } + } catch(err) { + showToast(translate('Failed to update fulfillment capacity for ', { facilityName: facility.facilityName })) + logger.error('Failed to update facility', err) + } + }, + async openFacilityOrderCountModal() { + const facilityOrderCountModal = await modalController.create({ + component: ViewFacilityOrderCountModal, + componentProps: { facilityId: this.facilityId } + }) + + facilityOrderCountModal.present() } }, setup() {