Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/hotwax/facilities into faci…
Browse files Browse the repository at this point in the history
…lities/#10
  • Loading branch information
amansinghbais committed Nov 17, 2023
2 parents aada1d4 + 631c07c commit 6a35e72
Show file tree
Hide file tree
Showing 5 changed files with 214 additions and 11 deletions.
93 changes: 93 additions & 0 deletions src/components/ViewFacilityOrderCountModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<template>
<ion-header>
<ion-toolbar>
<ion-buttons slot="start">
<ion-button @click="closeModal()">
<ion-icon slot="icon-only" :icon="closeOutline" />
</ion-button>
</ion-buttons>
<ion-title>{{ translate("Consumed Order Limit") }}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
<ion-grid v-if="facilityOrderCounts.length && !isLoading">
<ion-row class="ion-justify-content-center">
<ion-col>{{ translate('Entry Date') }}</ion-col>
<ion-col>{{ translate('Consumed Order Limit') }}</ion-col>
</ion-row>
<ion-row class="ion-justify-content-center" v-for="facilityOrderCount in facilityOrderCounts" :key="facilityOrderCount.facilityId">
<ion-col>{{ facilityOrderCount.entryDate }}</ion-col>
<ion-col>{{ facilityOrderCount.lastOrderCount }}</ion-col>
</ion-row>
</ion-grid>
<div v-else-if="!isLoading" class="ion-text-center ion-padding-top">
{{ translate('No records found') }}
</div>
</ion-content>
</template>

<script lang="ts">
import {
IonButton,
IonButtons,
IonCol,
IonContent,
IonGrid,
IonHeader,
IonIcon,
IonRow,
IonTitle,
IonToolbar,
modalController
} from "@ionic/vue";
import { defineComponent } from "vue";
import { closeOutline, saveOutline } from "ionicons/icons";
import { translate } from '@hotwax/dxp-components'
import { FacilityService } from "@/services/FacilityService";
export default defineComponent({
name: "ViewFacilityOrderCountModal",
components: {
IonButton,
IonButtons,
IonCol,
IonContent,
IonGrid,
IonHeader,
IonIcon,
IonRow,
IonTitle,
IonToolbar
},
props: ["facilityId"],
data() {
return {
facilityOrderCounts: [] as Array<any>,
isLoading: true
}
},
async mounted() {
this.facilityOrderCounts = await FacilityService.fetchFacilityOrderCounts(this.facilityId)
this.isLoading = false;
},
methods: {
closeModal() {
modalController.dismiss()
}
},
setup() {
return {
closeOutline,
saveOutline,
translate
};
},
});
</script>

<style>
ion-col {
text-align: center;
}
</style>
4 changes: 4 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
40 changes: 36 additions & 4 deletions src/services/FacilityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,7 @@ const fetchFacilitiesOrderCount = async(facilityIds: Array<string>): Promise<any
data: params
})

if (!hasError(resp) && resp.data.count) {
// using index 0 as we will only get a single record
// this.currentFacilityDetails.orderCount = resp.data.docs[0].lastOrderCount

if (!hasError(resp) && resp.data.count > 0) {
facilitiesOrderCount = resp.data.docs.reduce((facilitiesCount: any, facilityCount: any) => {
facilitiesCount[facilityCount.facilityId] = facilityCount.lastOrderCount
return facilitiesCount
Expand All @@ -85,6 +82,40 @@ const fetchFacilitiesOrderCount = async(facilityIds: Array<string>): Promise<any
return facilitiesOrderCount;
}

const fetchFacilityOrderCounts = async(facilityId: string): Promise<any> => {
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<any> => {
return api({
url: "service/updateFacility",
Expand Down Expand Up @@ -120,6 +151,7 @@ const updateProductStoreFacility = async (payload: any): Promise <any> => {
export const FacilityService = {
createProductStoreFacility,
fetchFacilityOnlineGroupInformation,
fetchFacilityOrderCounts,
fetchFacilitiesOrderCount,
fetchFacilities,
getFacilityProductStores,
Expand Down
21 changes: 20 additions & 1 deletion src/store/modules/facility/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,13 +112,32 @@ const actions: ActionTree<FacilityState, RootState> = {
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
}
Expand Down
67 changes: 61 additions & 6 deletions src/views/FacilityDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,20 @@
<br/><br/>
{{ 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.") }}
</ion-card-content>
<ion-item lines="none">
<ion-text>{{ 10 }}</ion-text>
<ion-progress-bar class="ion-margin" :value="10/20"></ion-progress-bar>
<ion-chip :outline="true">{{ 20 }}</ion-chip>
<ion-item lines="none" v-if="current.orderLimitType === 'custom'">
<ion-text>{{ current.orderCount }}</ion-text>
<ion-progress-bar class="ion-margin" :value="current.orderCount / current.maximumOrderLimit" />
<ion-chip outline @click="changeOrderLimitPopover">{{ current.maximumOrderLimit }}</ion-chip>
</ion-item>
<ion-item lines="none" v-else-if="current.orderLimitType === 'unlimited'">
<ion-label>{{ translate("orders allocated today", { orderCount: current.orderCount }) }}</ion-label>
<ion-chip outline @click="changeOrderLimitPopover">{{ translate("Unlimited") }}</ion-chip>
</ion-item>
<ion-item lines="none" v-else>
<ion-label>{{ translate("orders in fulfillment queue", { orderCount: current.orderCount }) }}</ion-label>
<ion-chip outline @click="changeOrderLimitPopover" color="danger" fill="outline">{{ current.maximumOrderLimit }}</ion-chip>
</ion-item>
<ion-item lines="none" class="ion-margin-horizontal" detail button>
<ion-item lines="none" detail button @click="openFacilityOrderCountModal">
<ion-label>{{ translate("View order count history") }}</ion-label>
</ion-item>
</ion-card>
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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() {
Expand Down

0 comments on commit 6a35e72

Please sign in to comment.