Skip to content

Commit

Permalink
Merge branch 'main' into #84
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Feb 14, 2024
2 parents 970e796 + 7e73f4a commit 9cca11e
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 71 deletions.
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"Order Rule Filters": "Order Rule Filters",
"Order Rule Sort": "Order Rule Sort",
"operator": "operator",
"Partial allocation cannot be disabled. Orders are filtered by item when filtering by promise date.": "Partial allocation cannot be disabled. Orders are filtered by item when filtering by promise date.",
"Partially available": "Partially available",
"Passed duration": "Passed duration",
"Password": "Password",
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/orderRouting/OrderRoutingState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export default interface OrderRoutingState {
rules: any;
currentGroup: any;
currentRoute: any;
routingHistory: any;
}
38 changes: 38 additions & 0 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,44 @@ const actions: ActionTree<OrderRoutingState, RootState> = {
commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, payload)
},

async fetchRoutingHistory({ commit, state }, routingGroupId) {
const history = Object.values(state.routingHistory)[0] as any

// If the routing history for the current group is already available then don't fetch the history again
if(history?.length && history[0].routingGroupId === routingGroupId) {
return;
}

let routingHistory = {}

try {
const resp = await OrderRoutingService.fetchRoutingHistory(routingGroupId)

if(!hasError(resp)) {
// Sorting the history based on startTime, as we does not get the records in sorted order from api
const sortedRoutingHistory = resp.data.sort((a: any, b: any) => b.startDate - a.startDate)

routingHistory = sortedRoutingHistory.reduce((routings: any, routing: any) => {
if(routings[routing.orderRoutingId]) {
routings[routing.orderRoutingId].push(routing)
} else {
routings = {
...routings,
[routing.orderRoutingId]: [routing]
}
}
return routings
}, {})
} else {
throw resp.data;
}
} catch(err) {
logger.error(err)
}

commit(types.ORDER_ROUTING_HISTORY_UPDATED, routingHistory)
},

async deleteRoutingFilters({ dispatch }, payload) {

Check warning on line 203 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (18.x)

'dispatch' is defined but never used

Check warning on line 203 in src/store/modules/orderRouting/actions.ts

View workflow job for this annotation

GitHub Actions / call-workflow-in-another-repo / reusable_workflow_job (20.x)

'dispatch' is defined but never used
let hasAllFiltersDeletedSuccessfully = true;
try {
Expand Down
3 changes: 3 additions & 0 deletions src/store/modules/orderRouting/getters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const getters: GetterTree<OrderRoutingState, RootState> = {
},
getCurrentOrderRouting(state) {
return JSON.parse(JSON.stringify(state.currentRoute))
},
getRoutingHistory(state) {
return JSON.parse(JSON.stringify(state.routingHistory))
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/store/modules/orderRouting/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ const orderRoutingModule: Module<OrderRoutingState, RootState> = {
groups: [],
rules: {},
currentGroup: {},
currentRoute: {}
currentRoute: {},
routingHistory: {}
},
getters,
actions,
Expand Down
1 change: 1 addition & 0 deletions src/store/modules/orderRouting/mutation-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export const ORDER_ROUTING_GROUPS_UPDATED = SN_ORDER_ROUTING + "/GROUPS_UPDATED"
export const ORDER_ROUTING_RULES_UPDATED = SN_ORDER_ROUTING + "/RULE_UPDATED"
export const ORDER_ROUTING_CURRENT_GROUP_UPDATED = SN_ORDER_ROUTING + "/CURRENT_GROUP_UPDATED"
export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED"
export const ORDER_ROUTING_HISTORY_UPDATED = SN_ORDER_ROUTING + "/ROUTING_HISTORY_UPDATED"
export const ORDER_ROUTING_CLEARED = SN_ORDER_ROUTING + "/CLEARED"
4 changes: 4 additions & 0 deletions src/store/modules/orderRouting/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@ const mutations: MutationTree<OrderRoutingState> = {
[types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED](state, payload) {
state.currentRoute = payload
},
[types.ORDER_ROUTING_HISTORY_UPDATED](state, payload) {
state.routingHistory = payload
},
[types.ORDER_ROUTING_CLEARED](state) {
state.groups = []
state.rules = {}
state.currentGroup = {}
state.currentRoute = {}
state.routingHistory = {}
},
}
export default mutations;
7 changes: 6 additions & 1 deletion src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,9 @@ function getDateAndTime(time: any) {
return time ? DateTime.fromMillis(time).toLocaleString(DateTime.DATETIME_MED) : "-";
}

export { getDate, getDateAndTime, getTime, getTimeFromSeconds, showToast, hasError, sortSequence }
function getDateAndTimeShort(time: any) {
// format: hh:mm(localized 24-hour time) date/month
return time ? DateTime.fromMillis(time).toFormat("T dd/LL") : "-";
}

export { getDate, getDateAndTime, getDateAndTimeShort, getTime, getTimeFromSeconds, showToast, hasError, sortSequence }
91 changes: 71 additions & 20 deletions src/views/BrokeringQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,32 @@
<div class="menu">
<ion-item lines="none">
<ion-label>{{ currentRouting.routingName }}</ion-label>
<ion-chip slot="end" outline @click="router.push(`/tabs/brokering/${currentRouting.routingGroupId}/routes`)">
<ion-chip slot="end" outline @click="router.go(-1)">
{{ getRouteIndex() }}
<ion-icon :icon="chevronUpOutline" />
</ion-chip>
</ion-item>
<ion-button class="ion-margin" expand="block" :disabled="!hasUnsavedChanges" @click="saveChanges">{{ translate("Save changes") }}</ion-button>
<ion-item>
<ion-icon slot="start" :icon="pulseOutline" />
<ion-select :label="translate('Status')" interface="popover" :value="routingStatus" @ionChange="updateOrderRouting($event.detail.value)">
<ion-select-option value="ROUTING_DRAFT">{{ translate("Draft") }}</ion-select-option>
<ion-select-option value="ROUTING_ACTIVE">{{ translate("Active") }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item lines="full">
<ion-icon :icon="timeOutline" slot="start" />
<ion-label>{{ translate("Last run") }}</ion-label>
<ion-chip outline @click.stop="openRoutingHistoryModal()">
<ion-label>{{ routingHistory[currentRouting.orderRoutingId] ? getDateAndTimeShort(routingHistory[currentRouting.orderRoutingId][0].startDate) : "-" }}</ion-label>
</ion-chip>
</ion-item>
<ion-item lines="full">
<ion-icon :icon="archiveOutline" slot="start" />
<ion-toggle color="danger" :checked="currentRouting.statusId === 'ROUTING_ARCHIVED'" @ionChange="toggleRoutingStatus($event)">
{{ translate("Archive") }}
</ion-toggle>
</ion-item>
<ion-item-group>
<ion-item-divider color="light">
<ion-label>{{ translate("Filters") }}</ion-label>
Expand All @@ -27,7 +47,7 @@
</ion-item>
<ion-item v-if="getFilterValue(orderRoutingFilterOptions, ruleEnums, 'SHIPPING_METHOD')">
<ion-select multiple :placeholder="translate('shipping method')" interface="popover" :label="translate('Shipping method')" :selected-text="getSelectedValue(orderRoutingFilterOptions, ruleEnums, 'SHIPPING_METHOD')" :value="getFilterValue(orderRoutingFilterOptions, ruleEnums, 'SHIPPING_METHOD').fieldValue?.split(',')" @ionChange="updateOrderFilterValue($event, 'SHIPPING_METHOD', true)">
<ion-select-option v-for="(shippingMethod, shippingMethodId) in shippingMethods" :key="shippingMethodId" :value="shippingMethodId">{{ shippingMethod.shippingMethodId || shippingMethodId }}</ion-select-option>
<ion-select-option v-for="(shippingMethod, shippingMethodId) in shippingMethods" :key="shippingMethodId" :value="shippingMethodId">{{ shippingMethod.description || shippingMethodId }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item v-if="getFilterValue(orderRoutingFilterOptions, ruleEnums, 'PRIORITY')">
Expand Down Expand Up @@ -183,7 +203,13 @@
{{ translate("Select if partial allocation should be allowed in this inventory rule") }}
</ion-card-content>
<ion-item lines="none">
<ion-toggle :disabled="isPromiseDateFilterApplied()" :checked="selectedRoutingRule.assignmentEnumId === 'ORA_MULTI'" @ionChange="updatePartialAllocation($event.detail.checked)">{{ translate("Allow partial allocation") }}</ion-toggle>
<!-- When selecting promiseDate route filter we will show the partial allocation option as checked on UI, but will not update its value on backend. Discussed with Aditya Sir -->
<ion-toggle :disabled="isPromiseDateFilterApplied()" :checked="selectedRoutingRule.assignmentEnumId === 'ORA_MULTI' || isPromiseDateFilterApplied()" @ionChange="updatePartialAllocation($event.detail.checked)">{{ translate("Allow partial allocation") }}</ion-toggle>
</ion-item>
<ion-item v-show="isPromiseDateFilterApplied()" lines="none">
<ion-label class="ion-text-wrap">
<p>{{ translate("Partial allocation cannot be disabled. Orders are filtered by item when filtering by promise date.") }}</p>
</ion-label>
</ion-item>
</ion-card>
<ion-card>
Expand Down Expand Up @@ -225,19 +251,20 @@

<script setup lang="ts">
import { IonButton, IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonChip, IonContent, IonIcon, IonInput, IonItem, IonItemDivider, IonItemGroup, IonLabel, IonList, IonPage, IonReorder, IonReorderGroup, IonSelect, IonSelectOption, IonToggle, alertController, modalController, onIonViewWillEnter, popoverController } from "@ionic/vue";
import { addCircleOutline, bookmarkOutline, chevronUpOutline, filterOutline, golfOutline, optionsOutline, playForwardOutline, swapVerticalOutline } from "ionicons/icons"
import { addCircleOutline, archiveOutline, bookmarkOutline, chevronUpOutline, filterOutline, golfOutline, optionsOutline, playForwardOutline, pulseOutline, swapVerticalOutline, timeOutline } from "ionicons/icons"
import { onBeforeRouteLeave, useRouter } from "vue-router";
import { computed, defineProps, ref } from "vue";
import store from "@/store";
import AddInventoryFilterOptionsModal from "@/components/AddInventoryFilterOptionsModal.vue";
import { sortSequence } from "@/utils";
import { getDateAndTimeShort, sortSequence } from "@/utils";
import { Rule } from "@/types";
import AddOrderRouteFilterOptions from "@/components/AddOrderRouteFilterOptions.vue"
import PromiseFilterPopover from "@/components/PromiseFilterPopover.vue"
import logger from "@/logger";
import { DateTime } from "luxon";
import emitter from "@/event-bus";
import { translate } from "@/i18n";
import RoutingHistoryModal from "@/components/RoutingHistoryModal.vue"
const router = useRouter();
const props = defineProps({
Expand All @@ -258,6 +285,7 @@ const facilities = computed(() => store.getters["util/getFacilities"])
const enums = computed(() => store.getters["util/getEnums"])
const shippingMethods = computed(() => store.getters["util/getShippingMethods"])
const facilityGroups = computed(() => store.getters["util/getFacilityGroups"])
const routingHistory = computed(() => store.getters["orderRouting/getRoutingHistory"])
let ruleActionType = ref("")
let selectedRoutingRule = ref({}) as any
Expand All @@ -270,10 +298,12 @@ let inventoryRuleActions = ref({}) as any
let rulesInformation = ref({}) as any
let hasUnsavedChanges = ref(false)
let isRuleNameUpdating = ref(false)
let routingStatus = ref("")
onIonViewWillEnter(async () => {
emitter.emit("presentLoader", { message: "Fetching filters and inventory rules", backdropDismiss: false })
await Promise.all([store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId), store.dispatch("util/fetchFacilities"), store.dispatch("util/fetchEnums", { enumTypeId: "ORDER_SALES_CHANNEL" }), store.dispatch("util/fetchShippingMethods"), store.dispatch("util/fetchFacilityGroups")])
store.dispatch("orderRouting/fetchRoutingHistory", router.currentRoute.value.params.routingGroupId)
// Fetching the group information again if the group stored in the state and the groupId in the route params are not same. This case occurs when we are on the route details page of a group and then directly hit the route details for a different group.
if(currentRoutingGroup.value.routingGroupId !== router.currentRoute.value.params.routingGroupId) {
Expand All @@ -289,6 +319,8 @@ onIonViewWillEnter(async () => {
inventoryRules.value = sortSequence(JSON.parse(JSON.stringify(currentRouting.value["rules"])))
await fetchRuleInformation(inventoryRules.value[0].routingRuleId);
}
routingStatus.value = currentRouting.value.statusId
emitter.emit("dismissLoader")
})
Expand Down Expand Up @@ -437,6 +469,15 @@ async function addOrderRouteFilterOptions(parentEnumId: string, conditionTypeEnu
await orderRouteFilterOptions.present();
}
async function openRoutingHistoryModal() {
const routingHistoryModal = await modalController.create({
component: RoutingHistoryModal,
componentProps: { routingHistory: routingHistory.value[currentRouting.value.orderRoutingId], routingName: currentRouting.value.routingName, groupName: currentRoutingGroup.value.groupName }
})
routingHistoryModal.present();
}
async function addInventoryRule() {
const newRuleAlert = await alertController.create({
header: translate("New Inventory Rule"),
Expand Down Expand Up @@ -486,6 +527,21 @@ function updateRule() {
hasUnsavedChanges.value = true
}
function updateOrderRouting(value: string) {
routingStatus.value = value
hasUnsavedChanges.value = true
}
function toggleRoutingStatus(event: CustomEvent) {
if(event.detail.checked) {
routingStatus.value = "ROUTING_ARCHIVED"
} else {
routingStatus.value = "ROUTING_DRAFT"
}
hasUnsavedChanges.value = true
}
function updateUnfillableActionType(value: string) {
const actionType = ruleActionType.value
ruleActionType.value = value
Expand Down Expand Up @@ -568,18 +624,8 @@ function isPromiseDateFilterApplied() {
return;
}
// When user updates partial allocation and then selects promiseDate filter then we will assume that the user wants to change the value for partialAllocation on server and thus we will not revert any change made in the partial allocation action and update its value on server
const filter = getFilterValue(orderRoutingFilterOptions.value, ruleEnums, "PROMISE_DATE")
// When promise date range is selected for order filter, we will revert any change made to the partialAllocation enum and will change it to its initial value and will disable the partial allocation feature
if(filter?.fieldValue || filter?.fieldValue == 0) {
const assignmentEnumId = JSON.parse(JSON.stringify(currentRouting.value["rules"])).find((rule: any) => rule.routingRuleId === selectedRoutingRule.value.routingRuleId)?.assignmentEnumId
inventoryRules.value.find((inventoryRule: any) => {
if(inventoryRule.routingRuleId === selectedRoutingRule.value.routingRuleId) {
inventoryRule.assignmentEnumId = assignmentEnumId
return true;
}
})
}
return filter?.fieldValue || filter?.fieldValue == 0
}
Expand Down Expand Up @@ -765,7 +811,7 @@ function doConditionSortReorder(event: CustomEvent) {
updateRule()
}
function findRoutingsDiff(previousSeq: any, updatedSeq: any) {
function findRulesDiff(previousSeq: any, updatedSeq: any) {
const diffSeq: any = Object.keys(previousSeq).reduce((diff, key) => {
if (updatedSeq[key].routingRuleId === previousSeq[key].routingRuleId && updatedSeq[key].statusId === previousSeq[key].statusId && updatedSeq[key].assignmentEnumId === previousSeq[key].assignmentEnumId && updatedSeq[key].ruleName === previousSeq[key].ruleName) return diff
return {
Expand Down Expand Up @@ -878,7 +924,7 @@ function doReorder(event: CustomEvent) {
// returns the updated sequence after reordering
const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(inventoryRules.value)));
let diffSeq = findRoutingsDiff(previousSeq, updatedSeq)
let diffSeq = findRulesDiff(previousSeq, updatedSeq)
const updatedSeqenceNum = previousSeq.map((rule: Rule) => rule.sequenceNum)
Object.keys(diffSeq).map((key: any) => {
Expand Down Expand Up @@ -920,9 +966,14 @@ async function save() {
routingGroupId: currentRouting.value.routingGroupId
} as any
// Check if the status of currentRouting is changed, if yes then update the status for routing
if(currentRouting.value.statusId !== routingStatus.value) {
orderRouting["statusId"] = routingStatus.value
}
// Find diff for inventory rules
if(currentRouting.value["rules"]) {
let diffSeq = findRoutingsDiff(currentRouting.value["rules"], inventoryRules.value)
let diffSeq = findRulesDiff(currentRouting.value["rules"], inventoryRules.value)
const updatedSeqenceNum = currentRouting.value["rules"].map((rule: Rule) => rule.sequenceNum)
Object.keys(diffSeq).map((key: any) => {
Expand Down Expand Up @@ -965,7 +1016,7 @@ async function save() {
// }
}
if(filtersToUpdate?.length || orderRouting["rules"]?.length) {
if(filtersToUpdate?.length || orderRouting["rules"]?.length || orderRouting.statusId) {
orderRouting["orderFilters"] = filtersToUpdate
const orderRoutingId = await store.dispatch("orderRouting/updateRouting", orderRouting)
Expand Down
Loading

0 comments on commit 9cca11e

Please sign in to comment.