Skip to content

Commit

Permalink
Merge pull request #175 from ymaheshwari1/#159
Browse files Browse the repository at this point in the history
Implemented: support to clone inventory rule(#159)
  • Loading branch information
ymaheshwari1 authored Apr 10, 2024
2 parents 3fd74fb + 7e4032f commit 2c1c0ba
Show file tree
Hide file tree
Showing 3 changed files with 220 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"Change": "Change",
"Clear auto cancel days": "Clear auto cancel days",
"Click the backdrop to dismiss.": "Click the backdrop to dismiss.",
"Clone": "Clone",
"Cloning route": "Cloning route",
"Close": "Close",
"Connection configuration is missing for oms.": "Connection configuration is missing for oms.",
"Created at": "Created at",
Expand All @@ -33,6 +35,7 @@
"duration": "duration",
"Edit": "Edit",
"Error getting user profile": "Error getting user profile",
"Failed to clone the rule": "Failed to clone the rule",
"Failed to create brokering run": "Failed to create brokering run",
"Failed to create inventory rule": "Failed to create inventory rule",
"Failed to create order routing": "Failed to create order routing",
Expand Down
74 changes: 73 additions & 1 deletion src/views/BrokeringQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
</ion-item>
<ion-item>
<ion-button slot="end" size="small" @click="isRuleNameUpdating = !isRuleNameUpdating; updateRuleName(selectedRoutingRule.routingRuleId)" fill="outline">{{ isRuleNameUpdating ? translate("Save") : translate("Rename") }}</ion-button>
<ion-button slot="end" size="small" @click="cloneRule" fill="outline">
<ion-icon slot="start" :icon="copyOutline"/>
{{ translate("Clone") }}
</ion-button>
</ion-item>
</div>
</ion-card>
Expand Down Expand Up @@ -242,7 +246,7 @@

<script setup lang="ts">
import { IonButton, IonCard, IonCardContent, IonCardHeader, IonCardTitle, IonChip, IonContent, IonIcon, IonInput, IonItem, IonItemDivider, IonItemGroup, IonLabel, IonList, IonNote, IonPage, IonReorder, IonReorderGroup, IonSelect, IonSelectOption, IonToggle, alertController, modalController, onIonViewWillEnter, popoverController } from "@ionic/vue";
import { addCircleOutline, bookmarkOutline, chevronUpOutline, filterOutline, golfOutline, optionsOutline, playForwardOutline, pulseOutline, swapVerticalOutline, timeOutline } from "ionicons/icons"
import { addCircleOutline, bookmarkOutline, chevronUpOutline, copyOutline, 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";
Expand Down Expand Up @@ -773,6 +777,74 @@ function updateRuleName(routingRuleId: string) {
})
}
async function cloneRule() {
emitter.emit("presentLoader", { message: `Cloning rule ${selectedRoutingRule.value.ruleName}`, backdropDismiss: false })
const payload = {
routingRuleId: "",
orderRoutingId: props.orderRoutingId,
ruleName: selectedRoutingRule.value.ruleName + ' copy',
statusId: "RULE_DRAFT", // by default when cloning the rule the new rule will be in draft status
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: selectedRoutingRule.value.assignmentEnumId,
createdDate: DateTime.now().toMillis()
}
const routingRuleId = await store.dispatch("orderRouting/createRoutingRule", payload)
if(!routingRuleId) {
showToast(translate("Failed to clone the rule"))
emitter.emit("dismissLoader")
return;
}
const sortOptions = rulesInformation.value[selectedRoutingRule.value.routingRuleId]["inventoryFilters"]?.["ENTCT_SORT_BY"] ? rulesInformation.value[selectedRoutingRule.value.routingRuleId]["inventoryFilters"]["ENTCT_SORT_BY"] : {}
const filterOptions = rulesInformation.value[selectedRoutingRule.value.routingRuleId]["inventoryFilters"]?.["ENTCT_FILTER"] ? rulesInformation.value[selectedRoutingRule.value.routingRuleId]["inventoryFilters"]["ENTCT_FILTER"] : {}
const actionOptions = rulesInformation.value[selectedRoutingRule.value.routingRuleId]["actions"] ? rulesInformation.value[selectedRoutingRule.value.routingRuleId]["actions"] : {}
let inventoryFilters = [] as any, actions = [] as any
Object.values(sortOptions).map((option: any) => {
inventoryFilters.push({
createdDate: DateTime.now().toMillis(),
conditionTypeEnumId: option.conditionTypeEnumId,
fieldName: option.fieldName,
sequenceNum: option.sequenceNum
})
})
Object.values(filterOptions).map((option: any) => {
inventoryFilters.push({
createdDate: DateTime.now().toMillis(),
conditionTypeEnumId: option.conditionTypeEnumId,
fieldName: option.fieldName,
fieldValue: option.fieldValue,
operator: option.operator,
sequenceNum: option.sequenceNum
})
})
Object.values(actionOptions).map((option: any) => {
actions.push({
actionTypeEnumId: option.actionTypeEnumId,
actionValue: option.actionValue,
createdDate: DateTime.now().toMillis(),
})
})
await store.dispatch("orderRouting/updateRule", {
routingRuleId,
orderRoutingId: props.orderRoutingId,
inventoryFilters,
actions
})
inventoryRules.value = JSON.parse(JSON.stringify(currentRouting.value["rules"]))
fetchRuleInformation(routingRuleId)
emitter.emit("dismissLoader")
}
function doRouteSortReorder(event: CustomEvent) {
const previousSeq = JSON.parse(JSON.stringify(Object.values(orderRoutingSortOptions.value)))
Expand Down
149 changes: 144 additions & 5 deletions src/views/BrokeringRoute.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@
</ion-item>
<ion-item lines="none">
<ion-badge class="pointer" :color="routing.statusId === 'ROUTING_ACTIVE' ? 'success' : ''" @click.stop="updateOrderRouting(routing, 'statusId', `${routing.statusId === 'ROUTING_DRAFT' ? 'ROUTING_ACTIVE' : 'ROUTING_DRAFT'}`)">{{ getStatusDesc(routing.statusId) }}</ion-badge>
<ion-button fill="clear" color="medium" slot="end" @click.stop="updateOrderRouting(routing, 'statusId', 'ROUTING_ARCHIVED')">
{{ translate("Archive") }}
<ion-icon slot="end" :icon="archiveOutline" />
</ion-button>
<div slot="end">
<ion-button fill="clear" color="medium" @click.stop="cloneRouting(routing)">
<ion-icon slot="icon-only" :icon="copyOutline" />
</ion-button>
<ion-button fill="clear" color="medium" @click.stop="updateOrderRouting(routing, 'statusId', 'ROUTING_ARCHIVED')">
<ion-icon slot="icon-only" :icon="archiveOutline" />
</ion-button>
</div>
</ion-item>
</ion-card>
</ion-reorder-group>
Expand Down Expand Up @@ -148,7 +152,7 @@

<script setup lang="ts">
import { IonBackButton, IonBadge, IonButtons, IonButton, IonCard, IonChip, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonListHeader, IonPage, IonReorder, IonReorderGroup, IonSelect, IonSelectOption, IonTextarea, IonTitle, IonToolbar, alertController, modalController, onIonViewWillEnter } from "@ionic/vue";
import { addCircleOutline, archiveOutline, refreshOutline, reorderTwoOutline, saveOutline, timeOutline, timerOutline } from "ionicons/icons"
import { addCircleOutline, archiveOutline, copyOutline, refreshOutline, reorderTwoOutline, saveOutline, timeOutline, timerOutline } from "ionicons/icons"
import { onBeforeRouteLeave, useRouter } from "vue-router";
import { useStore } from "vuex";
import { computed, defineProps, nextTick, ref } from "vue";
Expand Down Expand Up @@ -623,6 +627,141 @@ async function editGroupDescription() {
await nextTick()
descRef.value.$el.setFocus();
}
async function cloneRouting(routing: any) {
emitter.emit("presentLoader", { message: "Cloning route", backdropDismiss: false })
// payload for creating the cloned copy of current routing
const payload = {
orderRoutingId: "",
routingGroupId: props.routingGroupId,
statusId: "ROUTING_DRAFT", // when cloning a routing, the new routing will be in draft status
routingName: routing.routingName + " copy",
sequenceNum: orderRoutings.value.length && orderRoutings.value[orderRoutings.value.length - 1].sequenceNum >= 0 ? orderRoutings.value[orderRoutings.value.length - 1].sequenceNum + 5 : 0, // added check for `>= 0` as sequenceNum can be 0 which will result in again setting the new route seqNum to 0, also considering archivedRouting when calculating new seqNum
description: "",
createdDate: DateTime.now().toMillis()
}
const orderRoutingId = await store.dispatch("orderRouting/createOrderRouting", payload)
// No need to perform any action if we do not get routingId in return after routing creation
if(!orderRoutingId) {
showToast(translate("Failed to clone order routing"))
emitter.emit("dismissLoader")
return;
}
let parentRouting = {} as any;
// Fetch rules and order filters for the parent routing, as we need to create copy of the rules and filters
try {
const resp = await OrderRoutingService.fetchOrderRouting(routing.orderRoutingId);
if(!hasError(resp) && resp.data) {
parentRouting = resp.data
} else {
throw resp.data
}
} catch(err) {
showToast(translate("Failed to clone the routing filters and rules"))
logger.error(err);
emitter.emit("dismissLoader");
return;
}
if(parentRouting?.rules?.length) {
const parentRoutingRules = await Promise.all(parentRouting.rules.map((rule: any) => OrderRoutingService.fetchRule(rule.routingRuleId)))
parentRouting["rulesInformation"] = parentRoutingRules.reduce((rulesInformation: any, rule: any) => {
rulesInformation[rule.data.ruleName] = rule.data
return rulesInformation
}, {})
}
// Payload for applying routing filters and rules in the cloned routing
const routingPayload = {
orderRoutingId,
routingGroupId: parentRouting.routingGroupId,
orderFilters: parentRouting.orderFilters?.length ? parentRouting.orderFilters.reduce((filters: any, filter: any) => {
filters.push({
conditionTypeEnumId: filter.conditionTypeEnumId,
fieldName: filter.fieldName,
fieldValue: filter.fieldValue,
operator: filter.operator,
sequenceNum: filter.sequenceNum,
createdDate: DateTime.now().toMillis(),
orderRoutingId
})
return filters
}, []) : [],
rules: parentRouting.rules?.length ? parentRouting.rules.reduce((rules: any, rule: any) => {
rules.push({
assignmentEnumId: rule.assignmentEnumId,
createdDate: DateTime.now().toMillis(),
ruleName: rule.ruleName,
sequenceNum: rule.sequenceNum,
statusId: "RULE_DRAFT",
orderRoutingId
})
return rules
}, []) : []
}
if(!routingPayload.orderFilters.length && !routingPayload.rules.length) {
emitter.emit("dismissLoader")
return;
}
await store.dispatch("orderRouting/updateRouting", routingPayload)
let clonedRoutingRules = {} as any;
// As we do not have routingRuleId's for the rules created inside the cloned routing, hence fetching the rule ids
if(Object.keys(parentRouting["rulesInformation"])?.length) {
try {
const resp = await OrderRoutingService.fetchOrderRouting(orderRoutingId);
if(!hasError(resp) && resp.data?.rules?.length) {
clonedRoutingRules = resp.data.rules.reduce((rules: any, rule: any) => {
rules[rule.ruleName] = rule.routingRuleId
return rules
}, {})
} else {
throw resp.data
}
} catch(err) {
logger.error(err)
}
}
if(Object.keys(clonedRoutingRules).length) {
await Promise.all(Object.values(parentRouting["rulesInformation"]).map((rule: any) => {
store.dispatch("orderRouting/updateRule", {
routingRuleId: clonedRoutingRules[rule.ruleName],
orderRoutingId,
inventoryFilters: rule.inventoryFilters?.length ? rule.inventoryFilters.map((filter: any) => ({
createdDate: DateTime.now().toMillis(),
conditionTypeEnumId: filter.conditionTypeEnumId,
fieldName: filter.fieldName,
fieldValue: filter.fieldValue,
operator: filter.operator,
sequenceNum: filter.sequenceNum,
})) : [],
actions: rule.actions?.length ? rule.actions.map((filter: any) => ({
actionTypeEnumId: filter.actionTypeEnumId,
actionValue: filter.actionValue,
createdDate: DateTime.now().toMillis(),
})) : []
})
}))
}
// update the routing order for reordering and the cloned updated routings again
if(orderRoutingId) {
orderRoutings.value = JSON.parse(JSON.stringify(currentRoutingGroup.value))["routings"]
initializeOrderRoutings();
}
emitter.emit("dismissLoader")
}
</script>

<style scoped>
Expand Down

0 comments on commit 2c1c0ba

Please sign in to comment.