diff --git a/.env.example b/.env.example index 750230b..1d264a0 100644 --- a/.env.example +++ b/.env.example @@ -7,6 +7,6 @@ VUE_APP_DEFAULT_LOG_LEVEL="error" VUE_APP_RULE_ENUMS={"QUEUE":{"id":"OIP_QUEUE","code":"facilityId"},"SHIPPING_METHOD":{"id":"OIP_SHIP_METH_TYPE","code":"shipmentMethodTypeId"},"PRIORITY":{"id":"OIP_PRIORITY","code":"priority"},"PROMISE_DATE":{"id":"OIP_PROMISE_DATE","code":"promiseDaysCutoff"},"SALES_CHANNEL":{"id":"OIP_SALES_CHANNEL","code":"salesChannelEnumId"},"SHIP_BY":{"id":"OSP_SHIP_BY","code":"shipBeforeDate"},"SHIP_AFTER":{"id":"OSP_SHIP_AFTER","code":"shipAfterDate"},"ORDER_DATE":{"id":"OSP_ORDER_DATE","code":"orderDate"},"SHIPPING_METHOD_SORT":{"id":"OSP_SHIP_METH","code":"deliveryDays"}} VUE_APP_RULE_FILTER_ENUMS={"FACILITY_GROUP":{"id":"IIP_FACILITY_GROUP","code":"facilityGroupId"},"PROXIMITY":{"id":"IIP_PROXIMITY","code":"distance"},"BRK_SAFETY_STOCK":{"id":"IIP_BRK_SFTY_STOCK","code":"brokeringSafetyStock"},"MEASUREMENT_SYSTEM":{"id":"IIP_MSMNT_SYSTEM","code":"measurementSystem"}} VUE_APP_RULE_SORT_ENUMS={"PROXIMITY":{"id":"ISP_PROXIMITY","code":"distance"},"INV_BALANCE":{"id":"ISP_INV_BAL","code":"inventoryForAllocation"},"CUSTOMER_SEQ":{"id":"ISP_CUST_SEQ","code":"facilitySequence"}} -VUE_APP_RULE_ACTION_ENUMS={"AUTO_CANCEL_DAYS":{"id":"ORA_AUTO_CANCEL_DAYS","code":"ADD_AUTO_CANCEL_DATE"},"NEXT_RULE":{"id":"ORA_NEXT_RULE","code":"NEXT_RULE"},"MOVE_TO_QUEUE":{"id":"ORA_MV_TO_QUEUE","code":"MOVE_TO_QUEUE"}} -VUE_APP_ROUTE_STATUS_ENUMS={"ROUTING_DRAFT":{"id":"ROUTING_DRAFT","desc":"Draft","code":"DRAFT","color":"medium"},"ROUTING_ACTIVE":{"id":"ROUTING_ACTIVE","desc":"Active","code":"ACTIVE","color":"success"},"ROUTING_ARCHIVED":{"id":"ROUTING_ARCHIVED","desc":"Archived","code":"ARCHIVED","color":"warning"}} -VUE_APP_CRON_EXPRESSIONS={"Every 30 minutes":"0 */30 * ? * *","Hourly":"0 0 * ? * *","Every six hours":"0 0 */6 ? * *","Every day at midnight":"0 0 0 * * ?"} \ No newline at end of file +VUE_APP_RULE_ACTION_ENUMS={"RM_AUTO_CANCEL_DATE":{"id":"ORA_RM_CANCEL_DATE","code":"RM_AUTO_CANCEL_DATE"},"AUTO_CANCEL_DAYS":{"id":"ORA_AUTO_CANCEL_DAYS","code":"ADD_AUTO_CANCEL_DATE"},"NEXT_RULE":{"id":"ORA_NEXT_RULE","code":"NEXT_RULE"},"MOVE_TO_QUEUE":{"id":"ORA_MV_TO_QUEUE","code":"MOVE_TO_QUEUE"}} +VUE_APP_STATUS_ENUMS={"ROUTING_DRAFT":{"id":"ROUTING_DRAFT","desc":"Draft","code":"DRAFT","color":"medium"},"ROUTING_ACTIVE":{"id":"ROUTING_ACTIVE","desc":"Active","code":"ACTIVE","color":"success"},"ROUTING_ARCHIVED":{"id":"ROUTING_ARCHIVED","desc":"Archived","code":"ARCHIVED","color":"warning"},"RULE_DRAFT":{"id":"RULE_DRAFT","desc":"Draft","code":"DRAFT","color":"medium"},"RULE_ACTIVE":{"id":"RULE_ACTIVE","desc":"Active","code":"ACTIVE","color":"success"},"RULE_ARCHIVED":{"id":"RULE_ARCHIVED","desc":"Acrhived","code":"ARCHIVED","color":"warning"}} +VUE_APP_CRON_EXPRESSIONS={"Every 30 minutes":"0 */30 * ? * *","Hourly":"0 0 * ? * *","Every six hours":"0 0 */6 ? * *","Every day at midnight":"0 0 0 * * ?"} diff --git a/src/components/AddInventoryFilterOptionsModal.vue b/src/components/AddInventoryFilterOptionsModal.vue index e13ca4c..56d5f8e 100644 --- a/src/components/AddInventoryFilterOptionsModal.vue +++ b/src/components/AddInventoryFilterOptionsModal.vue @@ -29,6 +29,7 @@ import { IonButton, IonButtons, IonCheckbox, IonContent, IonFab, IonFabButton, I import { useStore } from "vuex"; import { computed, defineProps, onMounted, ref } from "vue"; import { saveOutline } from "ionicons/icons"; +import { DateTime } from "luxon"; const store = useStore(); const enums = computed(() => store.getters["util/getEnums"]) @@ -70,54 +71,46 @@ function addConditionOption(condition: any) { const associatedEnum = enums.value[props.parentEnumId][associatedOptions[condition.enumId]] if(isConditionOptionAlreadyApplied) { - delete inventoryRuleConditions.value[props.conditionTypeEnumId][condition.enumCode] + delete inventoryRuleConditions.value[condition.enumCode] // When removing a condition, also remove its associated option if available - associatedEnum && delete inventoryRuleConditions.value[props.conditionTypeEnumId][associatedEnum.enumCode] + associatedEnum && delete inventoryRuleConditions.value[associatedEnum.enumCode] } else { // checking unchecking an option and then checking it again, we need to use the same values - if(props.ruleConditions[props.conditionTypeEnumId]?.[condition.enumCode]) { - inventoryRuleConditions.value[props.conditionTypeEnumId][condition.enumCode] = props.ruleConditions[props.conditionTypeEnumId][condition.enumCode] - associatedEnum && (inventoryRuleConditions.value[props.conditionTypeEnumId][associatedEnum.enumCode] = props.ruleConditions[props.conditionTypeEnumId][associatedEnum.enumCode]) + if(props.ruleConditions?.[condition.enumCode]) { + inventoryRuleConditions.value[condition.enumCode] = props.ruleConditions[condition.enumCode] + associatedEnum && (inventoryRuleConditions.value[associatedEnum.enumCode] = props.ruleConditions[associatedEnum.enumCode]) } else { // when adding a new value, we don't need to pass conditionSeqId // Added check that whether the filters for the conditionType exists or not, if not then create a new value for conditionType - inventoryRuleConditions.value[props.conditionTypeEnumId] ? inventoryRuleConditions.value[props.conditionTypeEnumId][condition.enumCode] = { + inventoryRuleConditions.value[condition.enumCode] = { routingRuleId: props.routingRuleId, conditionTypeEnumId: props.conditionTypeEnumId, fieldName: condition.enumCode, - sequenceNum: Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length && inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 - } : inventoryRuleConditions.value = { - ...inventoryRuleConditions.value, - [props.conditionTypeEnumId]: { - [condition.enumCode]: { - routingRuleId: props.routingRuleId, - conditionTypeEnumId: props.conditionTypeEnumId, - fieldName: condition.enumCode, - sequenceNum: 0 - } - } + sequenceNum: Object.keys(inventoryRuleConditions.value).length && inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + createdDate: DateTime.now().toMillis() } // Adding associatedEnum out of ternary, as we will always get the conditionTypeEnumId, as the filter will already handle that - associatedEnum && (inventoryRuleConditions.value[props.conditionTypeEnumId][associatedEnum.enumCode] = { + associatedEnum && (inventoryRuleConditions.value[associatedEnum.enumCode] = { routingRuleId: props.routingRuleId, conditionTypeEnumId: props.conditionTypeEnumId, fieldName: associatedEnum.enumCode, - sequenceNum: Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length && inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[props.conditionTypeEnumId][Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId])[Object.keys(inventoryRuleConditions.value[props.conditionTypeEnumId]).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + sequenceNum: Object.keys(inventoryRuleConditions.value).length && inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]]?.sequenceNum >= 0 ? inventoryRuleConditions.value[Object.keys(inventoryRuleConditions.value)[Object.keys(inventoryRuleConditions.value).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + createdDate: DateTime.now().toMillis() }) } } } function saveConditionOptions() { - closeModal(inventoryRuleConditions.value, 'save'); + closeModal('save'); } function isConditionOptionSelected(code: string) { - return inventoryRuleConditions.value[props.conditionTypeEnumId]?.[code] + return inventoryRuleConditions.value?.[code] } -function closeModal(filters = {}, action = 'close') { - modalController.dismiss({ dismissed: true, filters }, action) +function closeModal(action = 'close') { + modalController.dismiss({ dismissed: true, filters: inventoryRuleConditions.value }, action) } diff --git a/src/components/AddOrderRouteFilterOptions.vue b/src/components/AddOrderRouteFilterOptions.vue index 849a195..988315d 100644 --- a/src/components/AddOrderRouteFilterOptions.vue +++ b/src/components/AddOrderRouteFilterOptions.vue @@ -29,6 +29,7 @@ import { IonButton, IonButtons, IonCheckbox, IonContent, IonFab, IonFabButton, I import { useStore } from "vuex"; import { computed, defineProps, onMounted, ref } from "vue"; import { saveOutline } from "ionicons/icons"; +import { DateTime } from "luxon"; const store = useStore(); const enums = computed(() => store.getters["util/getEnums"]) @@ -64,43 +65,34 @@ function addSortOption(sort: any) { const isSortOptionAlreadyApplied = isSortOptionSelected(sort.enumCode)?.fieldName if(isSortOptionAlreadyApplied) { - delete routingFilters.value[props.conditionTypeEnumId][sort.enumCode] + delete routingFilters.value[sort.enumCode] } else { // checking unchecking an option and then checking it again, we need to use the same values - if(props.orderRoutingFilters[props.conditionTypeEnumId]?.[sort.enumCode]) { - routingFilters.value[props.conditionTypeEnumId][sort.enumCode] = props.orderRoutingFilters[props.conditionTypeEnumId][sort.enumCode] + // TODO: check for a unique case that what if we add a new option, reorder the filters and then remove the old option and then add it again, this case result in duplicate seqNum which should not happen + if(props.orderRoutingFilters?.[sort.enumCode]) { + routingFilters.value[sort.enumCode] = props.orderRoutingFilters[sort.enumCode] } else { // when adding a new value, we don't need to pass conditionSeqId - // Added check that whether the filters for the conditionType exists or not, if not then create a new value for conditionType - routingFilters.value[props.conditionTypeEnumId] ? routingFilters.value[props.conditionTypeEnumId][sort.enumCode] = { + routingFilters.value[sort.enumCode] = { orderRoutingId: props.orderRoutingId, conditionTypeEnumId: props.conditionTypeEnumId, fieldName: sort.enumCode, - sequenceNum: Object.keys(routingFilters.value[props.conditionTypeEnumId]).length && routingFilters.value[props.conditionTypeEnumId][Object.keys(routingFilters.value[props.conditionTypeEnumId])[Object.keys(routingFilters.value[props.conditionTypeEnumId]).length - 1]]?.sequenceNum >= 0 ? routingFilters.value[props.conditionTypeEnumId][Object.keys(routingFilters.value[props.conditionTypeEnumId])[Object.keys(routingFilters.value[props.conditionTypeEnumId]).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 - } : routingFilters.value = { - ...routingFilters.value, - [props.conditionTypeEnumId]: { - [sort.enumCode]: { - orderRoutingId: props.orderRoutingId, - conditionTypeEnumId: props.conditionTypeEnumId, - fieldName: sort.enumCode, - sequenceNum: 0 - } - } + sequenceNum: Object.keys(routingFilters.value).length && routingFilters.value[Object.keys(routingFilters.value)[Object.keys(routingFilters.value).length - 1]]?.sequenceNum >= 0 ? routingFilters.value[Object.keys(routingFilters.value)[Object.keys(routingFilters.value).length - 1]].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new seqNum to 0 + createdDate: DateTime.now().toMillis() // TODO: need to create createdDate object when clicking save button, as adding it here will have difference between creation time when having multiple filters to create } } } } function saveSortOptions() { - closeModal(routingFilters.value, 'save'); + closeModal('save'); } function isSortOptionSelected(code: string) { - return routingFilters.value[props.conditionTypeEnumId]?.[code] + return routingFilters.value?.[code] } -function closeModal(filters = {}, action = 'close') { - modalController.dismiss({ dismissed: true, filters }, action) +function closeModal(action = 'close') { + modalController.dismiss({ dismissed: true, filters: routingFilters.value }, action) } diff --git a/src/services/RoutingService.ts b/src/services/RoutingService.ts index db4998e..3e55e66 100644 --- a/src/services/RoutingService.ts +++ b/src/services/RoutingService.ts @@ -70,17 +70,9 @@ const fetchRoutingRules = async (payload: any): Promise => { }); } -const fetchRoutingFilters = async (payload: any): Promise => { +const updateRouting = async (payload: any): Promise => { return api({ - url: `routings/${payload.orderRoutingId}/orderFilters`, - method: "GET", - query: payload - }); -} - -const updateRoutingFilter = async (payload: any): Promise => { - return api({ - url: `routings/${payload.orderRoutingId}/orderFilters`, + url: `routings/${payload.orderRoutingId}`, method: "POST", data: payload }); @@ -94,14 +86,6 @@ const deleteRoutingFilter = async (payload: any): Promise => { }); } -const fetchRuleConditions = async (payload: any): Promise => { - return api({ - url: `rules/${payload.routingRuleId}/inventoryFilters`, - method: "GET", - query: payload - }); -} - const createRuleCondition = async (payload: any): Promise => { return api({ url: `rules/${payload.routingRuleId}/inventoryFilters`, @@ -118,11 +102,26 @@ const deleteRuleCondition = async (payload: any): Promise => { }); } -const fetchRuleActions = async (payload: any): Promise => { +const deleteRuleAction = async (payload: any): Promise => { return api({ url: `rules/${payload.routingRuleId}/actions`, - method: "GET", - query: payload + method: "DELETE", + data: payload + }); +} + +const fetchRule = async (routingRuleId: string): Promise => { + return api({ + url: `rules/${routingRuleId}`, + method: "GET" + }); +} + +const updateRule = async (payload: any): Promise => { + return api({ + url: `rules/${payload.routingRuleId}`, + method: "POST", + data: payload }); } @@ -140,16 +139,16 @@ export const OrderRoutingService = { createRoutingRule, createRuleCondition, deleteRoutingFilter, + deleteRuleAction, deleteRuleCondition, fetchOrderRouting, - fetchRoutingFilters, fetchRoutingGroupInformation, fetchRoutingGroups, fetchRoutingRules, - fetchRuleActions, - fetchRuleConditions, + fetchRule, scheduleBrokering, updateOrderRouting, - updateRoutingFilter, - updateRoutingGroup + updateRouting, + updateRoutingGroup, + updateRule } \ No newline at end of file diff --git a/src/store/modules/orderRouting/OrderRoutingState.ts b/src/store/modules/orderRouting/OrderRoutingState.ts index 12c66b0..4cc7024 100644 --- a/src/store/modules/orderRouting/OrderRoutingState.ts +++ b/src/store/modules/orderRouting/OrderRoutingState.ts @@ -1,16 +1,6 @@ -import { Group, RouteFilter } from "@/types"; - export default interface OrderRoutingState { groups: Array; // runs - routes: Array; - rules: Array; + rules: any; currentGroup: any; currentRoute: any; - currentRouteFilters: { - [key: string]: { // conditionTypeEnumId as key - [key: string]: RouteFilter // enumCode/fieldName as key - } - }; - ruleConditions: {}; - ruleActions: {} } \ No newline at end of file diff --git a/src/store/modules/orderRouting/actions.ts b/src/store/modules/orderRouting/actions.ts index 3128138..816f102 100644 --- a/src/store/modules/orderRouting/actions.ts +++ b/src/store/modules/orderRouting/actions.ts @@ -5,7 +5,6 @@ import { OrderRoutingService } from "@/services/RoutingService" import { hasError, showToast, sortSequence } from "@/utils" import * as types from './mutation-types' import logger from "@/logger" -import { RouteFilter } from "@/types" import { DateTime } from "luxon" const actions: ActionTree = { @@ -74,6 +73,10 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, currentGroup) }, + async setCurrentGroup({ commit }, currentGroup) { + commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, currentGroup) + }, + async createOrderRouting({ dispatch, state }, payload) { const currentGroup = JSON.parse(JSON.stringify(state.currentGroup)) let orderRoutingId = '' @@ -111,17 +114,7 @@ const actions: ActionTree = { return orderRoutingId; }, - async setCurrentGroup({ commit }, currentGroup) { - commit(types.ORDER_ROUTING_CURRENT_GROUP_UPDATED, currentGroup) - }, - - async fetchCurrentOrderRouting({ dispatch, state }, orderRoutingId) { - const current = state.currentRoute - if(current.orderRoutingId && current.orderRoutingId === orderRoutingId) { - dispatch("setCurrentOrderRouting", current) - return; - } - + async fetchCurrentOrderRouting({ dispatch }, orderRoutingId) { let currentRoute = {} try { @@ -143,34 +136,43 @@ const actions: ActionTree = { commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, payload) }, - async fetchRoutingRules({ commit }, orderRoutingId) { - let routingRules = [] as any; - // filter groups on the basis of productStoreId - const payload = { - orderRoutingId - } - + async deleteRoutingFilters({ dispatch }, payload) { + let hasAllFiltersDeletedSuccessfully = true; try { - const resp = await OrderRoutingService.fetchRoutingRules(payload); - - if(!hasError(resp) && resp.data.length) { - routingRules = resp.data - } else { - throw resp.data + // As discussed, we can't make parallel api calls, hence using for loop to make api calls + for(const filter of payload.filters) { + const resp = await OrderRoutingService.deleteRoutingFilter({ + orderRoutingId: payload.orderRoutingId, + conditionSeqId: filter.conditionSeqId + }); + if(hasError(resp) || !resp.data.orderRoutingId) { + hasAllFiltersDeletedSuccessfully = false + } } } catch(err) { logger.error(err); } - if(routingRules.length) { - routingRules = sortSequence(routingRules) + return hasAllFiltersDeletedSuccessfully + }, + + async updateRouting({ dispatch }, payload) { + let orderRoutingId = '' + try { + const resp = await OrderRoutingService.updateRouting(payload) + if(!hasError(resp) && resp.data?.orderRoutingId) { + orderRoutingId = resp.data.orderRoutingId + } + } catch(err) { + logger.error(err); } - commit(types.ORDER_ROUTING_RULES_UPDATED, routingRules) + return orderRoutingId }, async createRoutingRule({ commit, state }, payload) { - let routingRules = JSON.parse(JSON.stringify(state.rules)) + const currentRoute = JSON.parse(JSON.stringify(state.currentRoute)) + let routingRules = currentRoute.rules?.length ? currentRoute.rules : [] let routingRuleId = '' try { @@ -190,7 +192,7 @@ const actions: ActionTree = { routingRules = sortSequence(routingRules) } - commit(types.ORDER_ROUTINGS_UPDATED, routingRules) + commit(types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED, currentRoute) } } catch(err) { showToast("Failed to create rule") @@ -200,193 +202,102 @@ const actions: ActionTree = { return routingRuleId; }, - async fetchRoutingFilters({ commit }, orderRoutingId) { - let routingFilters = {} as any; - // filter groups on the basis of productStoreId - const payload = { - orderRoutingId - } - - try { - const resp = await OrderRoutingService.fetchRoutingFilters(payload); - - if(!hasError(resp) && resp.data.length) { - routingFilters = resp.data.reduce((filters: any, filter: RouteFilter) => { - if(filters[filter.conditionTypeEnumId]) { - filters[filter.conditionTypeEnumId][filter.fieldName] = filter - } else { - filters[filter.conditionTypeEnumId] = { - [filter.fieldName]: filter - } - } - return filters - }, {}) - } else { - throw resp.data - } - } catch(err) { - logger.error(err); - } - - const sortEnum = "ENTCT_SORT_BY" - - // As we only need to add support of reordering for sortBy filter - if(routingFilters[sortEnum]?.length) { - routingFilters[sortEnum] = sortSequence(routingFilters[sortEnum]) - } - - commit(types.ORDER_ROUTING_FILTERS_UPDATED, routingFilters) - }, - - async deleteRoutingFilters({ dispatch }, payload) { - // TODO: check if we can call request in parallel for delete operation - let hasAllFiltersDeletedSuccessfully = true; - try { - await payload.filters.forEach(async (filter: any) => { - const resp = await OrderRoutingService.deleteRoutingFilter({ - orderRoutingId: payload.orderRoutingId, - conditionSeqId: filter.conditionSeqId - }); - if(hasError(resp) || !resp.data.orderRoutingId) { - hasAllFiltersDeletedSuccessfully = false - } - }); - } catch(err) { - logger.error(err); - } - - dispatch("fetchRoutingFilters", payload.orderRoutingId) - - return hasAllFiltersDeletedSuccessfully - }, - - async createRoutingFilters({ dispatch }, payload) { - // TODO: check if we can call request in parallel for create operation - let hasAllFiltersCreatedSuccessfully = true; - try { - await payload.filters.forEach(async (filter: any) => { - const resp = await OrderRoutingService.updateRoutingFilter({ - orderRoutingId: payload.orderRoutingId, - ...filter - }); - if(hasError(resp) || !resp.data.orderRoutingId) { - hasAllFiltersCreatedSuccessfully = false - } - }); - } catch(err) { - logger.error(err); - } - - dispatch("fetchRoutingFilters", payload.orderRoutingId) - return hasAllFiltersCreatedSuccessfully - }, - - async fetchRuleConditions({ commit }, routingRuleId) { - let ruleConditions = {} as any; - // filter groups on the basis of productStoreId - const payload = { - routingRuleId - } - - try { - const resp = await OrderRoutingService.fetchRuleConditions(payload); - - if(!hasError(resp) && resp.data.length) { - ruleConditions = resp.data.reduce((conditions: any, condition: any) => { - if(conditions[condition.conditionTypeEnumId]) { - conditions[condition.conditionTypeEnumId][condition.fieldName] = condition - } else { - conditions[condition.conditionTypeEnumId] = { - [condition.fieldName]: condition - } - } - return conditions - }, {}) - } else { - throw resp.data - } - } catch(err) { - logger.error(err); - } - - const sortEnum = "ENTCT_SORT_BY" - - // As we only need to add support of reordering for sortBy filter - if(ruleConditions[sortEnum]?.length) { - ruleConditions[sortEnum] = sortSequence(ruleConditions[sortEnum]) - } - - commit(types.ORDER_ROUTING_RULE_CONDITIONS_UPDATED, ruleConditions) - }, - async deleteRuleConditions({ dispatch }, payload) { // TODO: check if we can call request in parallel for delete operation let hasAllConditionsDeletedSuccessfully = true; try { - await payload.conditions.forEach(async (condition: any) => { + for(const condition of payload.conditions) { const resp = await OrderRoutingService.deleteRuleCondition({ routingRuleId: payload.routingRuleId, conditionSeqId: condition.conditionSeqId - }); + }) if(hasError(resp) || !resp.data.conditionSeqId) { hasAllConditionsDeletedSuccessfully = false } - }); + } } catch(err) { logger.error(err); } - dispatch("fetchRuleConditions", payload.routingRuleId) - return hasAllConditionsDeletedSuccessfully }, - async createRuleConditions({ dispatch }, payload) { - let hasAllConditionsCreatedSuccessfully = true; + async deleteRuleActions({ dispatch }, payload) { + // TODO: check if we can call request in parallel for delete operation + let hasAllActionsDeletedSuccessfully = true; try { - await payload.conditions.forEach(async (condition: any) => { - const resp = await OrderRoutingService.createRuleCondition({ + for(const action of payload.actions) { + const resp = await OrderRoutingService.deleteRuleAction({ routingRuleId: payload.routingRuleId, - ...condition - }); - if(!hasError(resp) || !resp.data.conditionSeqId) { - hasAllConditionsCreatedSuccessfully = false + actionSeqId: action.actionSeqId + }) + if(hasError(resp) || !resp.data.actionSeqId) { + hasAllActionsDeletedSuccessfully = false } - }); + } } catch(err) { - logger.error(err); + logger.error(err) } - // TODO: check if we can call the action only once after all the operations are success - dispatch("fetchRuleConditions", payload.routingRuleId) - return hasAllConditionsCreatedSuccessfully + return hasAllActionsDeletedSuccessfully }, - async fetchRuleActions({ commit }, routingRuleId) { - let ruleActions = {} as any; - const payload = { - routingRuleId + async fetchInventoryRuleInformation({ commit, state }, routingRuleId) { + const rulesInformation = JSON.parse(JSON.stringify(state.rules)) + + // Do not fetch the rule information if its already available in state. This condition will be false on refresh as state will be cleared so automatically updated information will be fetched + if(rulesInformation[routingRuleId]) { + return rulesInformation[routingRuleId]; } try { - const resp = await OrderRoutingService.fetchRuleActions(payload); + const resp = await OrderRoutingService.fetchRule(routingRuleId) + + if(!hasError(resp) && resp.data.routingRuleId) { + rulesInformation[routingRuleId] = resp.data + + if(rulesInformation[routingRuleId]["inventoryFilters"]?.length) { + rulesInformation[routingRuleId]["inventoryFilters"] = sortSequence(rulesInformation[routingRuleId]["inventoryFilters"]).reduce((filters: any, filter: any) => { + if(filters[filter.conditionTypeEnumId]) { + filters[filter.conditionTypeEnumId][filter.fieldName] = filter + } else { + filters[filter.conditionTypeEnumId] = { + [filter.fieldName]: filter + } + } + return filters + }, {}) + } - if(!hasError(resp) && resp.data.length) { - ruleActions = resp.data.reduce((actions: any, action: any) => { - // considering that only one value for an action is available - actions[action.actionTypeEnumId] = action - return actions - }, {}) - } else { - throw resp.data + if(rulesInformation[routingRuleId]["actions"]?.length) { + rulesInformation[routingRuleId]["actions"] = rulesInformation[routingRuleId]["actions"].reduce((actions: any, action: any) => { + actions[action.actionTypeEnumId] = action + return actions + }, {}) + } } } catch(err) { - logger.error(err); + logger.error(err) } - commit(types.ORDER_ROUTING_RULE_ACTIONS_UPDATED, ruleActions) + commit(types.ORDER_ROUTING_RULES_UPDATED, rulesInformation) + return JSON.parse(JSON.stringify(rulesInformation[routingRuleId])) }, + async updateRule({ dispatch }, payload) { + let routingRuleId = '' + try { + const resp = await OrderRoutingService.updateRule(payload) + + if(!hasError(resp) && resp.data.routingRuleId) { + routingRuleId = resp.data.routingRuleId + } + } catch(err) { + logger.error("Failed to update rule conditions and actions") + } + + return routingRuleId; + } } export default actions; \ No newline at end of file diff --git a/src/store/modules/orderRouting/getters.ts b/src/store/modules/orderRouting/getters.ts index b38bfd2..6b6e181 100644 --- a/src/store/modules/orderRouting/getters.ts +++ b/src/store/modules/orderRouting/getters.ts @@ -6,23 +6,14 @@ const getters: GetterTree = { getRoutingGroups(state) { return state.groups }, - getRoutingRules(state) { - return JSON.parse(JSON.stringify(state.rules)) + getRulesInformation(state) { + return state.rules }, getCurrentRoutingGroup(state) { return JSON.parse(JSON.stringify(state.currentGroup)) }, getCurrentOrderRouting(state) { return JSON.parse(JSON.stringify(state.currentRoute)) - }, - getCurrentRouteFilters(state) { - return state.currentRouteFilters - }, - getRuleConditions(state) { - return JSON.parse(JSON.stringify(state.ruleConditions)) - }, - getRuleActions(state) { - return JSON.parse(JSON.stringify(state.ruleActions)) } } diff --git a/src/store/modules/orderRouting/index.ts b/src/store/modules/orderRouting/index.ts index ae5b873..efa0196 100644 --- a/src/store/modules/orderRouting/index.ts +++ b/src/store/modules/orderRouting/index.ts @@ -10,13 +10,9 @@ const orderRoutingModule: Module = { namespaced: true, state: { groups: [], - routes: [], - rules: [], + rules: {}, currentGroup: {}, - currentRoute: {}, - currentRouteFilters: {}, - ruleConditions: {}, - ruleActions: {} + currentRoute: {} }, getters, actions, diff --git a/src/store/modules/orderRouting/mutation-types.ts b/src/store/modules/orderRouting/mutation-types.ts index 447da3d..9674d94 100644 --- a/src/store/modules/orderRouting/mutation-types.ts +++ b/src/store/modules/orderRouting/mutation-types.ts @@ -1,9 +1,5 @@ export const SN_ORDER_ROUTING = "orderRouting" export const ORDER_ROUTING_GROUPS_UPDATED = SN_ORDER_ROUTING + "/GROUPS_UPDATED" -export const ORDER_ROUTINGS_UPDATED = SN_ORDER_ROUTING + "/ROUTES_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_FILTERS_UPDATED = SN_ORDER_ROUTING + "/FILTERS_UPDATED" -export const ORDER_ROUTING_RULE_CONDITIONS_UPDATED = SN_ORDER_ROUTING + "/RULE_CONDITIONS_UPDATED" -export const ORDER_ROUTING_RULE_ACTIONS_UPDATED = SN_ORDER_ROUTING + "/RULE_ACTIONS_UPDATED" \ No newline at end of file +export const ORDER_ROUTING_CURRENT_ROUTE_UPDATED = SN_ORDER_ROUTING + "/CURRENT_ROUTE_UPDATED" \ No newline at end of file diff --git a/src/store/modules/orderRouting/mutations.ts b/src/store/modules/orderRouting/mutations.ts index d0d58eb..cef33f3 100644 --- a/src/store/modules/orderRouting/mutations.ts +++ b/src/store/modules/orderRouting/mutations.ts @@ -6,9 +6,6 @@ const mutations: MutationTree = { [types.ORDER_ROUTING_GROUPS_UPDATED](state, payload) { state.groups = payload }, - [types.ORDER_ROUTINGS_UPDATED](state, payload) { - state.routes = payload - }, [types.ORDER_ROUTING_RULES_UPDATED](state, payload) { state.rules = payload }, @@ -18,14 +15,5 @@ const mutations: MutationTree = { [types.ORDER_ROUTING_CURRENT_ROUTE_UPDATED](state, payload) { state.currentRoute = payload }, - [types.ORDER_ROUTING_FILTERS_UPDATED](state, payload) { - state.currentRouteFilters = payload - }, - [types.ORDER_ROUTING_RULE_CONDITIONS_UPDATED](state, payload) { - state.ruleConditions = payload - }, - [types.ORDER_ROUTING_RULE_ACTIONS_UPDATED](state, payload) { - state.ruleActions = payload - } } export default mutations; \ No newline at end of file diff --git a/src/views/BrokeringQuery.vue b/src/views/BrokeringQuery.vue index b56bd76..d654640 100644 --- a/src/views/BrokeringQuery.vue +++ b/src/views/BrokeringQuery.vue @@ -19,34 +19,34 @@ -

{{ "Select filter to apply" }}

+

{{ "Select filter to apply" }}

- - + + {{ facility.facilityName || facilityId }} - - + + {{ shippingMethod.shippingMethodId || shippingMethodId }} - - + + {{ "High" }} {{ "Medium" }} {{ "Low" }} - + {{ "Promise date" }} - {{ getFilterValue(orderRoutingFilters, ruleEnums, 'PROMISE_DATE').fieldValue || getFilterValue(orderRoutingFilters, ruleEnums, 'PROMISE_DATE').fieldValue == 0 ? getFilterValue(orderRoutingFilters, ruleEnums, 'PROMISE_DATE').fieldValue : '-' }} + {{ getFilterValue(orderRoutingFilterOptions, ruleEnums, 'PROMISE_DATE').fieldValue || getFilterValue(orderRoutingFilterOptions, ruleEnums, 'PROMISE_DATE').fieldValue == 0 ? getFilterValue(orderRoutingFilterOptions, ruleEnums, 'PROMISE_DATE').fieldValue : '-' }} - - + + {{ enumInfo.description || enumInfo.enumId }} @@ -59,9 +59,9 @@ -

{{ "Select sorting to apply" }}

+

{{ "Select sorting to apply" }}

- + {{ getLabel("ORD_SORT_PARAM_TYPE", code) || code }} @@ -87,8 +87,8 @@ {{ "Rule Status" }} - {{ selectedRoutingRule.statusId }} - {{ selectedRoutingRule.statusId }} + {{ statusEnums[selectedRoutingRule.statusId]?.desc }} + {{ statusEnums[selectedRoutingRule.statusId]?.desc }}
@@ -99,31 +99,31 @@ -

{{ "Select filter to apply" }}

- - +

{{ "Select filter to apply" }}

+ + {{ facilityGroup.description || facilityGroupId }} - + {{ "Proximity" }} - + {{ "kms" }} {{ "miles" }} - {{ getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'PROXIMITY').fieldValue || getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'PROXIMITY').fieldValue == 0 ? getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'PROXIMITY').fieldValue : '-' }} + {{ getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'PROXIMITY').fieldValue || getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'PROXIMITY').fieldValue == 0 ? getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'PROXIMITY').fieldValue : '-' }} - + {{ "Brokering safety stock" }} - + {{ enumeration.description || enumeration.enumCode }} - {{ getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue || getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue == 0 ? getFilterValue(inventoryRuleConditions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue : '-' }} + {{ getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue || getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue == 0 ? getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'BRK_SAFETY_STOCK').fieldValue : '-' }}
@@ -134,9 +134,9 @@ -

{{ "Select sorting to apply" }}

+

{{ "Select sorting to apply" }}

- + {{ getLabel("INV_SORT_PARAM_TYPE", code) || code }} @@ -153,7 +153,7 @@ - {{ "Clear auto cancel days" }} + {{ "Clear auto cancel days" }}
@@ -176,7 +176,7 @@ - + {{ "Next rule" }} @@ -188,13 +188,13 @@ - + {{ facility.facilityName || facilityId }} {{ "Auto cancel days" }} - {{ autoCancelDays ? `${autoCancelDays} days` : '-' }} + {{ inventoryRuleActions[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue ? `${inventoryRuleActions[actionEnums['AUTO_CANCEL_DAYS'].id].actionValue} days` : '-' }} @@ -212,11 +212,12 @@ import { useRouter } from "vue-router"; import { computed, defineProps, ref } from "vue"; import store from "@/store"; import AddInventoryFilterOptionsModal from "@/components/AddInventoryFilterOptionsModal.vue"; -import { showToast } from "@/utils"; +import { showToast, 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"; const router = useRouter(); const props = defineProps({ @@ -229,38 +230,67 @@ const props = defineProps({ const ruleEnums = JSON.parse(process.env?.VUE_APP_RULE_ENUMS as string) const actionEnums = JSON.parse(process.env?.VUE_APP_RULE_ACTION_ENUMS as string) const conditionFilterEnums = JSON.parse(process.env?.VUE_APP_RULE_FILTER_ENUMS as string) -const autoCancelDays = ref(0) -const ruleActionType = ref('') -let orderRoutingFilters = ref({}) as any -let selectedRoutingRule = ref({}) as any -let inventoryRuleConditions = ref({}) as any -let inventoryRules = ref([]) as any -let rulesToUpdate = ref([]) as any +const statusEnums = JSON.parse(process.env?.VUE_APP_STATUS_ENUMS as string) const currentRouting = computed(() => store.getters["orderRouting/getCurrentOrderRouting"]) -const routingRules = computed(() => store.getters["orderRouting/getRoutingRules"]) -const routingFilters = computed(() => store.getters["orderRouting/getCurrentRouteFilters"]) -const ruleActions = computed(() => store.getters["orderRouting/getRuleActions"]) -const ruleConditions = computed(() => store.getters["orderRouting/getRuleConditions"]) +const routingRules = computed(() => store.getters["orderRouting/getRulesInformation"]) 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"]) +let ruleActionType = ref('') +let selectedRoutingRule = ref({}) as any +let inventoryRules = ref([]) as any +let orderRoutingFilterOptions = ref({}) as any +let orderRoutingSortOptions = ref({}) as any +let inventoryRuleFilterOptions = ref({}) as any +let inventoryRuleSortOptions = ref({}) as any +let inventoryRuleActions = ref({}) as any +let rulesInformation = ref({}) as any + onIonViewWillEnter(async () => { - await Promise.all([store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingRules", props.orderRoutingId), store.dispatch("orderRouting/fetchRoutingFilters", props.orderRoutingId), store.dispatch("util/fetchFacilities"), store.dispatch("util/fetchEnums", { enumTypeId: "ORDER_SALES_CHANNEL" }), store.dispatch("util/fetchShippingMethods"), store.dispatch("util/fetchFacilityGroups")]) + 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")]) - orderRoutingFilters.value = JSON.parse(JSON.stringify(routingFilters.value)) + if(currentRouting.value["orderFilters"]?.length) { + initializeOrderRoutingOptions() + } // Added check to not fetch any rule related information as when a new route will be created no rule will be available thus no need to fetch any other information - if(!routingRules.value.length) { - return; + if(currentRouting.value["rules"]?.length) { + inventoryRules.value = JSON.parse(JSON.stringify(currentRouting.value["rules"])) + await fetchRuleInformation(inventoryRules.value[0].routingRuleId); } +}) - inventoryRules.value = JSON.parse(JSON.stringify(routingRules.value)) +function initializeOrderRoutingOptions() { + const orderRouteFilters = sortSequence(JSON.parse(JSON.stringify(currentRouting.value["orderFilters"]))).reduce((filters: any, filter: any) => { + if(filters[filter.conditionTypeEnumId]) { + filters[filter.conditionTypeEnumId][filter.fieldName] = filter + } else { + filters[filter.conditionTypeEnumId] = { + [filter.fieldName]: filter + } + } + return filters + }, {}) - await fetchRuleInformation(inventoryRules.value[0].routingRuleId); -}) + orderRoutingFilterOptions.value = orderRouteFilters["ENTCT_FILTER"] ? orderRouteFilters["ENTCT_FILTER"] : {} + orderRoutingSortOptions.value = orderRouteFilters["ENTCT_SORT_BY"] ? orderRouteFilters["ENTCT_SORT_BY"] : {} +} + +async function initializeInventoryRules(rule: any) { + const inventoryRuleFilters = rule["inventoryFilters"] ? rule["inventoryFilters"] : {} + + inventoryRuleActions.value = rule["actions"] || {} + inventoryRuleFilterOptions.value = inventoryRuleFilters["ENTCT_FILTER"] ? inventoryRuleFilters["ENTCT_FILTER"] : {} + inventoryRuleSortOptions.value = inventoryRuleFilters["ENTCT_SORT_BY"] ? inventoryRuleFilters["ENTCT_SORT_BY"] : {} + + const actionTypes = ["ORA_NEXT_RULE", "ORA_MV_TO_QUEUE"] + ruleActionType.value = Object.keys(inventoryRuleActions.value).find((actionId: string) => { + return actionTypes.includes(actionId) + }) || '' +} async function fetchRuleInformation(routingRuleId: string) { // When clicking the same enum again do not fetch its information @@ -269,35 +299,41 @@ async function fetchRuleInformation(routingRuleId: string) { return; } - selectedRoutingRule.value = inventoryRules.value.find((rule: Rule) => rule.routingRuleId === routingRuleId) - await Promise.all([store.dispatch("orderRouting/fetchRuleConditions", routingRuleId), store.dispatch("orderRouting/fetchRuleActions", routingRuleId)]) + // Only fetch the rules information, if already not present, as we are updating rule values + if(!rulesInformation.value[routingRuleId]) { + rulesInformation.value[routingRuleId] = await store.dispatch("orderRouting/fetchInventoryRuleInformation", routingRuleId) + } - inventoryRuleConditions.value = JSON.parse(JSON.stringify(ruleConditions.value)) - autoCancelDays.value = ruleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue + // TODO: check on this condition, remove if not required + // If there is not an already selected rule, deep clone it for usage. This condition can occur when we does not have any inventory rules for the route and we have created a new rule + if(!selectedRoutingRule.value.routingRuleId) { + rulesInformation.value = JSON.parse(JSON.stringify(routingRules.value)) + } - const actionTypes = ["ORA_NEXT_RULE", "ORA_MV_TO_QUEUE"] - ruleActionType.value = Object.keys(ruleActions.value).find((actionId: string) => { - return actionTypes.includes(actionId) - }) || '' + // Using currentRouting["rules"] deep-cloned object here, as we will update the change in rules with route changes and not with rules filter changes + selectedRoutingRule.value = inventoryRules.value.find((rule: Rule) => rule.routingRuleId === routingRuleId) + + initializeInventoryRules(JSON.parse(JSON.stringify(rulesInformation.value[routingRuleId]))); } async function addInventoryFilterOptions(parentEnumId: string, conditionTypeEnumId: string, label = "") { if(!selectedRoutingRule.value.routingRuleId) { - // TODO: check if we can show a toast here - logger.error('Failed to identify selected inventory rule, please select a rule or refresh') + showToast("Failed to identify selected inventory rule, please select a rule or refresh") + logger.error("Failed to identify selected inventory rule, please select a rule or refresh") return; } const inventoryFilterOptionsModal = await modalController.create({ component: AddInventoryFilterOptionsModal, - componentProps: { ruleConditions: inventoryRuleConditions.value, routingRuleId: selectedRoutingRule.value.routingRuleId, parentEnumId, conditionTypeEnumId, label } + componentProps: { ruleConditions: conditionTypeEnumId === 'ENTCT_FILTER' ? inventoryRuleFilterOptions.value : inventoryRuleSortOptions.value, routingRuleId: selectedRoutingRule.value.routingRuleId, parentEnumId, conditionTypeEnumId, label } }) inventoryFilterOptionsModal.onDidDismiss().then((result: any) => { // Using role to determine when to update the filters // When closing the modal without save and when unselecting all the filter, in both the cases we get filters object as empty thus passing a role from the modal to update the filter only when save action is performed - if(result.data?.filters && result.role === 'save') { - inventoryRuleConditions.value = result.data.filters + if(result.role === 'save') { + conditionTypeEnumId === 'ENTCT_FILTER' ? ( inventoryRuleFilterOptions.value = result.data.filters ) : ( inventoryRuleSortOptions.value = result.data.filters ) + updateRule() } }) @@ -307,14 +343,14 @@ async function addInventoryFilterOptions(parentEnumId: string, conditionTypeEnum async function addOrderRouteFilterOptions(parentEnumId: string, conditionTypeEnumId: string, label = "") { const orderRouteFilterOptions = await modalController.create({ component: AddOrderRouteFilterOptions, - componentProps: { orderRoutingFilters: orderRoutingFilters.value, orderRoutingId: props.orderRoutingId, parentEnumId, conditionTypeEnumId, label } + componentProps: { orderRoutingFilters: conditionTypeEnumId === 'ENTCT_FILTER' ? orderRoutingFilterOptions.value : orderRoutingSortOptions.value, orderRoutingId: props.orderRoutingId, parentEnumId, conditionTypeEnumId, label } }) orderRouteFilterOptions.onDidDismiss().then((result: any) => { // Using role to determine when to update the filters // When closing the modal without save and when unselecting all the filter, in both the cases we get filters object as empty thus passing a role from the modal to update the filter only when save action is performed - if(result.data?.filters && result.role === 'save') { - orderRoutingFilters.value = result.data.filters + if(result.role === 'save') { + conditionTypeEnumId === 'ENTCT_FILTER' ? ( orderRoutingFilterOptions.value = result.data.filters ) : ( orderRoutingSortOptions.value = result.data.filters ) } }) @@ -348,12 +384,14 @@ async function addInventoryRule() { statusId: "RULE_DRAFT", // by default considering the rule to be in draft sequenceNum: inventoryRules.value.length && inventoryRules.value[inventoryRules.value.length - 1].sequenceNum >= 0 ? inventoryRules.value[inventoryRules.value.length - 1].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0, that will result in again setting the new route seqNum to 0, assignmentEnumId: "ORA_SINGLE", // by default, considering partial fulfillment to be inactive - fulfillEntireShipGroup: "N", // TODO: check for default value + createdDate: DateTime.now().toMillis() } - const resp = await store.dispatch("orderRouting/createRoutingRule", payload) - if(resp.routingRuleId) { - fetchRuleInformation(resp.routingRuleId) + const routingRuleId = await store.dispatch("orderRouting/createRoutingRule", payload) + if(routingRuleId) { + // TODO: Fix warning of duplicate keys when creating a new rule + inventoryRules.value = JSON.parse(JSON.stringify(currentRouting.value["rules"])) + fetchRuleInformation(routingRuleId) } } }) @@ -361,24 +399,41 @@ async function addInventoryRule() { return newRuleAlert.present(); } -function updateRuleActionType(value: string) { +// When changing the selected rule, updating any changes made in filter, sort and actions of the current rule +function updateRule() { + rulesInformation.value[selectedRoutingRule.value.routingRuleId]["inventoryFilters"] = { "ENTCT_FILTER": inventoryRuleFilterOptions.value, "ENTCT_SORT_BY": inventoryRuleSortOptions.value } + rulesInformation.value[selectedRoutingRule.value.routingRuleId]["actions"] = inventoryRuleActions.value +} + +function updateUnfillableActionType(value: string) { const actionType = ruleActionType.value ruleActionType.value = value - ruleActions.value[ruleActionType.value] = { - ...ruleActions.value[actionType], + inventoryRuleActions.value[ruleActionType.value] = { actionTypeEnumId: value, - actionValue: '' // after changing action type, as next_rule action does not need to have a value, so in all cases making intially the value as empty and will update if required from some other function + actionValue: "", // after changing action type, as next_rule action does not need to have a value, so in all cases making intially the value as empty and will update if required from some other function + createdDate: DateTime.now().toMillis() } // deleting previous action type, but using the data of previous action, as we will not call delete action on server for actionTypes - delete ruleActions.value[actionType] + delete inventoryRuleActions.value[actionType] + updateRule() } function updateRuleActionValue(value: string) { - ruleActions.value[ruleActionType.value]["actionValue"] = value + if(inventoryRuleActions.value[ruleActionType.value]) { + inventoryRuleActions.value[ruleActionType.value]["actionValue"] = value + } else { + inventoryRuleActions.value = { + ...inventoryRuleActions.value, + [ruleActionType.value]: { + actionValue: value + } + } + } + updateRule() } -async function updateAutoCancelDays(cancelDays: any) { +async function updateAutoCancelDays() { const alert = await alertController.create({ header: "Auto Cancel Days", inputs: [{ @@ -386,7 +441,7 @@ async function updateAutoCancelDays(cancelDays: any) { placeholder: "auto cancel days", type: "number", min: 0, - value: cancelDays + value: inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue }], buttons: [{ text: "Cancel", @@ -395,18 +450,23 @@ async function updateAutoCancelDays(cancelDays: any) { { text: "Save", handler: (data) => { - if(data) { - if(data.autoCancelDays === '') { - showToast("Please provide a value") - return false; - } else if(data.autoCancelDays < 0) { - showToast("Provide a value greater than or equal to 0") - return false; + if(data?.autoCancelDays || data.autoCancelDays === 0) { + if(inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue) { + inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id].actionValue = data.autoCancelDays } else { - autoCancelDays.value = data.autoCancelDays - ruleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id].actionValue = data.autoCancelDays + inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id] = { + actionTypeEnumId: actionEnums['AUTO_CANCEL_DAYS'].id, + actionValue: data.autoCancelDays, + createdDate: DateTime.now().toMillis(), + } + } + } else { + // If we have received an empty/undefined value for autoCancelDays then considered that it needs to be removed + if(inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id]?.actionValue) { + delete inventoryRuleActions.value[actionEnums['AUTO_CANCEL_DAYS'].id] } } + updateRule() } }] }) @@ -414,11 +474,15 @@ async function updateAutoCancelDays(cancelDays: any) { } function updatePartialAllocation(checked: any) { - selectedRoutingRule.value.assignmentEnumId = checked ? "ORA_MULTI" : "ORA_SINGLE" + inventoryRules.value.map((inventoryRule: any) => { + if(inventoryRule.routingRuleId === selectedRoutingRule.value.routingRuleId) { + inventoryRule.assignmentEnumId = checked ? "ORA_MULTI" : "ORA_SINGLE" + } + }) } function getFilterValue(options: any, enums: any, parameter: string) { - return options["ENTCT_FILTER"]?.[enums[parameter].code] + return options?.[enums[parameter].code] } function getLabel(parentType: string, code: string) { @@ -438,14 +502,15 @@ async function selectPromiseFilterValue(ev: CustomEvent) { }) popover.onDidDismiss().then((result: any) => { - getFilterValue(orderRoutingFilters.value, ruleEnums, "PROMISE_DATE").fieldValue = result.data?.isPastDuration ? `-${result.data?.duration}` : result.data?.duration - getFilterValue(orderRoutingFilters.value, ruleEnums, "PROMISE_DATE").operator = "less-equals" + getFilterValue(orderRoutingFilterOptions.value, ruleEnums, "PROMISE_DATE").fieldValue = result.data?.isPastDuration ? `-${result.data?.duration}` : result.data?.duration + getFilterValue(orderRoutingFilterOptions.value, ruleEnums, "PROMISE_DATE").operator = "less-equals" }) return popover.present(); } async function selectValue(id: string, header: string) { + const filter = getFilterValue(inventoryRuleFilterOptions.value, conditionFilterEnums, id) const valueAlert = await alertController.create({ header, buttons: [{ @@ -457,7 +522,7 @@ async function selectValue(id: string, header: string) { inputs: [{ name: "value", placeholder: "value", - value: getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, id).fieldValue + value: filter.fieldValue }] }) @@ -465,9 +530,10 @@ async function selectValue(id: string, header: string) { const value = result.data?.values?.value; // Considering that when having role in result, its negative action and not need to do anything if(!result.role && value) { - getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, id).fieldValue = value - // When selecting a filter value making the operator to default `equals` - getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, id).operator = "equals" + filter.fieldValue = value + // When selecting a filter value making the operator to default `equals` if not present already + filter.operator = filter.operator || "equals" + updateRule() } }) @@ -475,17 +541,37 @@ async function selectValue(id: string, header: string) { } function updateOperator(event: CustomEvent) { - getFilterValue(inventoryRuleConditions.value, conditionFilterEnums, "BRK_SAFETY_STOCK").operator = event.detail.value + getFilterValue(inventoryRuleFilterOptions.value, conditionFilterEnums, "BRK_SAFETY_STOCK").operator = event.detail.value + updateRule() } -function updateOrderFilterValue(event: CustomEvent, conditionTypeEnumId: string, id: string) { - orderRoutingFilters.value[conditionTypeEnumId][ruleEnums[id].code].fieldValue = event.detail.value +function updateOrderFilterValue(event: CustomEvent, id: string) { + orderRoutingFilterOptions.value[ruleEnums[id].code].fieldValue = event.detail.value } -function updateRuleFilterValue(event: CustomEvent, conditionTypeEnumId: string, id: string) { - inventoryRuleConditions.value[conditionTypeEnumId][conditionFilterEnums[id].code].fieldValue = event.detail.value +function updateRuleFilterValue(event: CustomEvent, id: string) { + inventoryRuleFilterOptions.value[conditionFilterEnums[id].code].fieldValue = event.detail.value + updateRule() } +function updateClearAutoCancelDays(checked: any) { + if(inventoryRuleActions.value[actionEnums["RM_AUTO_CANCEL_DATE"].id]) { + inventoryRuleActions.value[actionEnums["RM_AUTO_CANCEL_DATE"].id].actionValue = checked + } else { + inventoryRuleActions.value = { + ...inventoryRuleActions.value, + [actionEnums["RM_AUTO_CANCEL_DATE"].id]: { + actionValue: checked, + actionTypeEnumId: actionEnums["RM_AUTO_CANCEL_DATE"].id, + createdDate: DateTime.now().toMillis() + } + } + } + + updateRule() +} + +// Updating rule status function updateRuleStatus(routingRuleId: string, statusId: string) { inventoryRules.value.map((inventoryRule: any) => { if(inventoryRule.routingRuleId === routingRuleId) { @@ -495,42 +581,44 @@ function updateRuleStatus(routingRuleId: string, statusId: string) { } function doRouteSortReorder(event: CustomEvent) { - const previousSeq = JSON.parse(JSON.stringify(Object.values(orderRoutingFilters.value["ENTCT_SORT_BY"]))) + const previousSeq = JSON.parse(JSON.stringify(Object.values(orderRoutingSortOptions.value))) // returns the updated sequence after reordering - const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(orderRoutingFilters.value["ENTCT_SORT_BY"])))); + const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(orderRoutingSortOptions.value)))); const updatedSeqenceNum = Object.keys(previousSeq).map((filter: any) => previousSeq[filter].sequenceNum) Object.keys(updatedSeq).map((key: any, index: number) => { updatedSeq[key].sequenceNum = updatedSeqenceNum[index] }) - orderRoutingFilters.value["ENTCT_SORT_BY"] = updatedSeq.reduce((filters: any, filter: any) => { + orderRoutingSortOptions.value = updatedSeq.reduce((filters: any, filter: any) => { filters[filter.fieldName] = filter return filters }, {}) } function doConditionSortReorder(event: CustomEvent) { - const previousSeq = JSON.parse(JSON.stringify(Object.values(inventoryRuleConditions.value["ENTCT_SORT_BY"]))) + const previousSeq = JSON.parse(JSON.stringify(Object.values(inventoryRuleSortOptions.value))) // returns the updated sequence after reordering - const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(inventoryRuleConditions.value["ENTCT_SORT_BY"])))); + const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(Object.values(inventoryRuleSortOptions.value)))); const updatedSeqenceNum = Object.keys(previousSeq).map((filter: any) => previousSeq[filter].sequenceNum) Object.keys(updatedSeq).map((key: any, index: number) => { updatedSeq[key].sequenceNum = updatedSeqenceNum[index] }) - inventoryRuleConditions.value["ENTCT_SORT_BY"] = updatedSeq.reduce((filters: any, filter: any) => { + inventoryRuleSortOptions.value = updatedSeq.reduce((filters: any, filter: any) => { filters[filter.fieldName] = filter return filters }, {}) + + updateRule() } function findRoutingsDiff(previousSeq: any, updatedSeq: any) { const diffSeq: any = Object.keys(previousSeq).reduce((diff, key) => { - if (updatedSeq[key].routingRuleId === previousSeq[key].routingRuleId) return diff + if (updatedSeq[key].routingRuleId === previousSeq[key].routingRuleId && updatedSeq[key].statusId === previousSeq[key].statusId && updatedSeq[key].assignmentEnumId === previousSeq[key].assignmentEnumId) return diff return { ...diff, [key]: updatedSeq[key] @@ -539,8 +627,102 @@ function findRoutingsDiff(previousSeq: any, updatedSeq: any) { return diffSeq; } +function findSortDiff(previousSeq: any, updatedSeq: any) { + let seqToUpdate = {} + let seqToRemove = {} as any + + seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => { + if(!updatedSeq[key]) { + seqToRemove[key] = previousSeq[key] + return diff + } + + if (updatedSeq[key].fieldName === previousSeq[key].fieldName && updatedSeq[key].sequenceNum === previousSeq[key].sequenceNum) return diff + return { + ...diff, + [key]: updatedSeq[key] + } + }, seqToUpdate) + + seqToUpdate = Object.keys(updatedSeq).reduce((diff, key) => { + if(!previousSeq[key]) { + diff = { + ...diff, + [key]: updatedSeq[key] + } + } + + return diff + }, seqToUpdate) + + return { seqToUpdate, seqToRemove }; +} + +function findFilterDiff(previousSeq: any, updatedSeq: any) { + let seqToUpdate = {} + let seqToRemove = {} as any + + seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => { + if(!updatedSeq[key]) { + seqToRemove[key] = previousSeq[key] + return diff + } + + if (updatedSeq[key].fieldName === previousSeq[key].fieldName && updatedSeq[key].fieldValue === previousSeq[key].fieldValue && updatedSeq[key].operator === previousSeq[key].operator) return diff + return { + ...diff, + [key]: updatedSeq[key] + } + }, seqToUpdate) + + seqToUpdate = Object.keys(updatedSeq).reduce((diff, key) => { + // Added fieldValue check as we have considered that when adding a filter option, it should always have a value + if(!previousSeq[key] && updatedSeq[key].fieldValue) { + diff = { + ...diff, + [key]: updatedSeq[key] + } + } + + return diff + }, seqToUpdate) + + return { seqToUpdate, seqToRemove }; +} + +function findActionDiff(previousSeq: any, updatedSeq: any) { + let seqToUpdate = {} + let seqToRemove = {} as any + + seqToUpdate = Object.keys(previousSeq).reduce((diff, key) => { + if(!updatedSeq[key]) { + seqToRemove[key] = previousSeq[key] + return diff + } + + if (updatedSeq[key].actionTypeEnumId === previousSeq[key].actionTypeEnumId && updatedSeq[key].actionValue === previousSeq[key].actionValue) return diff + return { + ...diff, + [key]: updatedSeq[key] + } + }, seqToUpdate) + + seqToUpdate = Object.keys(updatedSeq).reduce((diff, key) => { + if(!previousSeq[key]) { + diff = { + ...diff, + [key]: updatedSeq[key] + } + } + + return diff + }, seqToUpdate) + + return { seqToUpdate, seqToRemove }; +} + function doReorder(event: CustomEvent) { - const previousSeq = JSON.parse(JSON.stringify(routingRules.value)) + const previousSeq = JSON.parse(JSON.stringify(inventoryRules.value)) // returns the updated sequence after reordering const updatedSeq = event.detail.complete(JSON.parse(JSON.stringify(inventoryRules.value))); @@ -555,104 +737,116 @@ function doReorder(event: CustomEvent) { diffSeq = Object.keys(diffSeq).map((key) => diffSeq[key]) inventoryRules.value = updatedSeq - rulesToUpdate.value = diffSeq -} - -// checks whether values for all the properties of two objects are same -function isObjectUpdated(initialObj: any, finalObj: any) { - return !Object.keys(initialObj).every((key: string) => finalObj[key] === initialObj[key]) || Object.keys(initialObj).length !== Object.keys(finalObj).length } async function save() { - const valueRequiredForRouteFilter = "ENTCT_FILTER" - const filtersToUpdate = [] as any, filtersToRemove = [] as any, filtersToCreate = [] as any - const conditionTypes = Object.keys(enums.value["CONDITION_TYPE"]) - - conditionTypes.map((filterType: string) => { - if(orderRoutingFilters.value[filterType]) { - Object.keys(orderRoutingFilters.value[filterType]).map((key: string) => { - if(routingFilters.value[filterType]?.[key]) { - const isSeqChanged = isObjectUpdated(routingFilters.value[filterType][key], orderRoutingFilters.value[filterType]?.[key]) - if(isSeqChanged) { - // Expanding object, as when the filter which is updated needs to use the values from original object, but if there is some change in the latest object(like seqNum due to reordering) then needs to override it - filtersToUpdate.push({ - ...routingFilters.value[filterType][key], - ...orderRoutingFilters.value[filterType][key] - }) - } - } else { - // Added check for 0, as when applying promiseDate filter the value can be zero - if(filterType === valueRequiredForRouteFilter && (orderRoutingFilters.value[filterType][key]?.["fieldValue"] || orderRoutingFilters.value[filterType][key]?.["fieldValue"] == 0)) { - filtersToCreate.push(orderRoutingFilters.value[filterType][key]) - } else if(filterType !== valueRequiredForRouteFilter) { - filtersToCreate.push(orderRoutingFilters.value[filterType][key]) - } - } - }) - } + const orderRouting = { + orderRoutingId: props.orderRoutingId, + routingGroupId: currentRouting.value.routingGroupId + } as any - if(routingFilters.value[filterType]) { - Object.keys(routingFilters.value[filterType]).map((key: string) => { - if(!orderRoutingFilters.value[filterType]?.[key]) { - filtersToRemove.push(routingFilters.value[filterType][key]) - } - }) - } + // Find diff for inventory rules + let diffSeq = findRoutingsDiff(currentRouting.value["rules"], inventoryRules.value) + + const updatedSeqenceNum = currentRouting.value["rules"].map((rule: Rule) => rule.sequenceNum) + Object.keys(diffSeq).map((key: any) => { + diffSeq[key].sequenceNum = updatedSeqenceNum[key] }) - const conditionsToUpdate = [] as any, conditionsToRemove = [] as any, conditionsToCreate = [] as any - - conditionTypes.map((filterType: string) => { - if(inventoryRuleConditions.value[filterType]) { - Object.keys(inventoryRuleConditions.value[filterType]).map((key: string) => { - if(ruleConditions.value[filterType]?.[key]) { - const isSeqChanged = isObjectUpdated(ruleConditions.value[filterType][key], inventoryRuleConditions.value[filterType]?.[key]) - if(isSeqChanged) { - // Expanding object, as when the filter which is updated needs to use the values from original object, but if there is some change in the latest object(like seqNum due to reordering) then needs to override it - conditionsToUpdate.push({ - ...ruleConditions.value[filterType][key], - ...inventoryRuleConditions.value[filterType][key] - }) - } - } else { - // Added check for 0, as when applying safetyStock filter the value can be zero - if(filterType === valueRequiredForRouteFilter && (inventoryRuleConditions.value[filterType][key]?.["fieldValue"] || inventoryRuleConditions.value[filterType][key]?.["fieldValue"] == 0)) { - conditionsToCreate.push(inventoryRuleConditions.value[filterType][key]) - } else if(filterType !== valueRequiredForRouteFilter) { - conditionsToCreate.push(inventoryRuleConditions.value[filterType][key]) - } - } - }) - } + diffSeq = Object.keys(diffSeq).map((key) => diffSeq[key]) - if(ruleConditions.value[filterType]) { - Object.keys(ruleConditions.value[filterType]).map((key: string) => { - if(!inventoryRuleConditions.value[filterType]?.[key]) { - conditionsToRemove.push(ruleConditions.value[filterType][key]) - } - }) + if(diffSeq.length) { + orderRouting["rules"] = diffSeq + } + // Inventory rules diff calculated + + // Find order filters diff + const routeSortOptionsDiff = findSortDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { + if(filter.conditionTypeEnumId === "ENTCT_SORT_BY") { + filters[filter.fieldName] = filter } - }) + return filters + }, {}), orderRoutingSortOptions.value) - // TODO: add support to update rules - // TODO: add support to update filters - // TODO: add support to update conditions + const routeFilterOptionsDiff = findFilterDiff(currentRouting.value["orderFilters"].reduce((filters: any, filter: any) => { + if(filter.conditionTypeEnumId === "ENTCT_FILTER") { + filters[filter.fieldName] = filter + } + return filters + }, {}), orderRoutingFilterOptions.value) - if(filtersToCreate.length) { - await store.dispatch("orderRouting/createRoutingFilters", { filters: filtersToCreate, orderRoutingId: props.orderRoutingId }) - } + const filtersToRemove = Object.values({ ...routeFilterOptionsDiff.seqToRemove, ...routeSortOptionsDiff.seqToRemove }) + const filtersToUpdate = Object.values({ ...routeFilterOptionsDiff.seqToUpdate, ...routeSortOptionsDiff.seqToUpdate }) + // Diff found for removing and updating filters - if(filtersToRemove.length) { + if(filtersToRemove?.length) { await store.dispatch("orderRouting/deleteRoutingFilters", { filters: filtersToRemove, orderRoutingId: props.orderRoutingId }) + + // TODO: check when to update the filters in state, currently not updating and fetching the records again, as when creating new filter we get conditionSeqId from response, but we can't add it in the state + // if(isSuccess) { + // await store.dispatch("orderRouting/setCurrentOrderRouting", { ...currentRouting.value, orderFilters: Object.values({ ...orderRoutingFilterOptions.value, ...orderRoutingSortOptions.value }) }) + // } } - if(conditionsToCreate.length) { - await store.dispatch("orderRouting/createRuleConditions", { conditions: conditionsToCreate, routingRuleId: selectedRoutingRule.value.routingRuleId }) + if(filtersToUpdate?.length || orderRouting["rules"]?.length) { + orderRouting["orderFilters"] = filtersToUpdate + const orderRoutingId = await store.dispatch("orderRouting/updateRouting", orderRouting) + + if(orderRoutingId) { + await store.dispatch("orderRouting/setCurrentOrderRouting", { ...currentRouting.value, orderFilters: Object.values({ ...orderRoutingFilterOptions.value, ...orderRoutingSortOptions.value }) }) + } } - if(conditionsToRemove.length) { - await store.dispatch("orderRouting/deleteRuleConditions", { conditions: conditionsToRemove, routingRuleId: selectedRoutingRule.value.routingRuleId }) + const initialInventoryRulesInformation = JSON.parse(JSON.stringify(routingRules.value)) + + // Whenever we will be having a feature to delete a rule then this logic needs updation + const rulesDiff = Object.keys(initialInventoryRulesInformation).map((ruleId: string) => { + const previousRuleSortOptions = initialInventoryRulesInformation[ruleId]["inventoryFilters"]?.["ENTCT_SORT_BY"] ? initialInventoryRulesInformation[ruleId]["inventoryFilters"]["ENTCT_SORT_BY"] : {} + const updatedRuleSortOptions = rulesInformation.value[ruleId]["inventoryFilters"]?.["ENTCT_SORT_BY"] ? rulesInformation.value[ruleId]["inventoryFilters"]["ENTCT_SORT_BY"] : {} + const sortOptionsDiff = findSortDiff(previousRuleSortOptions, updatedRuleSortOptions) + + const previousRuleFilterOptions = initialInventoryRulesInformation[ruleId]["inventoryFilters"]?.["ENTCT_FILTER"] ? initialInventoryRulesInformation[ruleId]["inventoryFilters"]["ENTCT_FILTER"] : {} + const updatedRuleFilterOptions = rulesInformation.value[ruleId]["inventoryFilters"]?.["ENTCT_FILTER"] ? rulesInformation.value[ruleId]["inventoryFilters"]["ENTCT_FILTER"] : {} + const filterOptionsDiff = findFilterDiff(previousRuleFilterOptions, updatedRuleFilterOptions) + + const previousRuleActionOptions = initialInventoryRulesInformation[ruleId]["actions"] ? initialInventoryRulesInformation[ruleId]["actions"] : {} + const updatedRuleActionOptions = rulesInformation.value[ruleId]["actions"] ? rulesInformation.value[ruleId]["actions"] : {} + const ruleActionsDiff = findActionDiff(previousRuleActionOptions, updatedRuleActionOptions) + + return { + routingRuleId: ruleId, + orderRoutingId: props.orderRoutingId, + filtersToRemove: Object.values({ ...filterOptionsDiff.seqToRemove, ...sortOptionsDiff.seqToRemove }), + filtersToUpdate: Object.values({ ...filterOptionsDiff.seqToUpdate, ...sortOptionsDiff.seqToUpdate }), + actionsToRemove: Object.values(ruleActionsDiff.seqToRemove), + actionsToUpdate: Object.values(ruleActionsDiff.seqToUpdate) + } + }) + + for(const key in rulesDiff) { + const rule = rulesDiff[key] + + if(rule.filtersToRemove?.length) { + await store.dispatch("orderRouting/deleteRuleConditions", rule.filtersToRemove) + } + + if(rule.actionsToRemove?.length) { + await store.dispatch("orderRouting/deleteRuleActions", rule.actionsToRemove) + } + + if(rule.filtersToUpdate?.length || rule.actionsToUpdate?.length) { + await store.dispatch("orderRouting/updateRule", { + routingRuleId: rule.routingRuleId, + orderRoutingId: rule.orderRoutingId, + inventoryFilters: rule.filtersToUpdate, + actions: rule.actionsToUpdate + }) + } } + + // TODO: call this action only if there is some change in the orderRoutings + // await store.dispatch("orderRouting/fetchCurrentOrderRouting", props.orderRoutingId) + // initializeOrderRoutingOptions(); } diff --git a/src/views/BrokeringRoute.vue b/src/views/BrokeringRoute.vue index 64aaeab..a7d6b9e 100644 --- a/src/views/BrokeringRoute.vue +++ b/src/views/BrokeringRoute.vue @@ -126,7 +126,7 @@ const props = defineProps({ } }) -const routingStatus = JSON.parse(process.env?.VUE_APP_ROUTE_STATUS_ENUMS as string) +const routingStatus = JSON.parse(process.env?.VUE_APP_STATUS_ENUMS as string) const cronExpressions = JSON.parse(process.env?.VUE_APP_CRON_EXPRESSIONS as string) let routingsForReorder = ref([]) let description = ref("")