Skip to content

Commit

Permalink
Implemented: support to exclude specific inventory filter from the rule(
Browse files Browse the repository at this point in the history
  • Loading branch information
ymaheshwari1 committed Aug 22, 2024
1 parent 51d2d14 commit dcab823
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ VUE_APP_VIEW_SIZE=10
VUE_APP_PERMISSION_ID=
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"},"ORIGIN_FACILITY_GROUP":{"id":"OIP_ORIGIN_FAC_GRP","code":"originFacilityGroupId"},"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"},"SORT_PRIORITY":{"id":"OSP_PRIORITY","code":"priority"}}
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"},"SPLIT_ITEM_GROUP":{"id":"IIP_SPLIT_ITEM_GROUP","code":"splitOrderItemGroup"}}
VUE_APP_RULE_FILTER_ENUMS={"FACILITY_GROUP":{"id":"IIP_FACILITY_GROUP","code":"facilityGroupId"},"FACILITY_GROUP_EXCLUDED":{"id":"IIP_FACILITY_GROUP_EXCLUDED","code":"facilityGroupId_excluded"},"PROXIMITY":{"id":"IIP_PROXIMITY","code":"distance"},"BRK_SAFETY_STOCK":{"id":"IIP_BRK_SFTY_STOCK","code":"brokeringSafetyStock"},"MEASUREMENT_SYSTEM":{"id":"IIP_MSMNT_SYSTEM","code":"measurementSystem"},"SPLIT_ITEM_GROUP":{"id":"IIP_SPLIT_ITEM_GROUP","code":"splitOrderItemGroup"}}
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={"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_CRON_EXPRESSIONS={"Every 5 minutes":"0 */5 * ? * *","Every 15 minutes":"0 */15 * ? * *","Every 30 minutes":"0 */30 * ? * *","Hourly":"0 0 * ? * *","Every six hours":"0 0 */6 ? * *","Every day at midnight":"0 0 0 * * ?"}
Expand Down
12 changes: 9 additions & 3 deletions src/components/AddInventoryFilterOptionsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,18 @@
<div v-if="!enumerations.length" class="empty-state">
<p>{{ translate(`Failed to fetch ${props.label?.toLowerCase()} options`) }}</p>
</div>

<ion-list v-else>
<ion-item v-for="condition in enumerations" :key="condition.enumId">
<ion-checkbox :disabled="isConditionDisabled(condition.enumId)" :checked="isConditionOptionSelected(condition.enumCode)" @ionChange="addConditionOption(condition)">
<template v-if="isConditionDisabled(condition.enumId)">
{{ condition.description || condition.enumCode }}<br/>
<ion-label>{{ condition.description || condition.enumCode }}</ion-label>
<ion-note>{{ `Only applicable when ${dependentOptions[condition.enumId].label} is selected` }}</ion-note>
</template>
<template v-else-if="condition.enumCode.includes('_excluded')">
<ion-label>{{ condition.description || condition.enumCode }}</ion-label>
<ion-note color="danger">{{ translate("Excluded") }}</ion-note>
</template>
<template v-else>
{{ condition.description || condition.enumCode }}
</template>
Expand All @@ -36,7 +41,7 @@
</template>

<script setup lang="ts">
import { IonButton, IonButtons, IonCheckbox, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonItem, IonList, IonNote, IonPage, IonTitle, IonToolbar, modalController } from "@ionic/vue";
import { IonButton, IonButtons, IonCheckbox, IonContent, IonFab, IonFabButton, IonHeader, IonIcon, IonItem, IonLabel, IonList, IonNote, IonPage, IonTitle, IonToolbar, modalController } from "@ionic/vue";
import { useStore } from "vuex";
import { computed, defineProps, onMounted, ref } from "vue";
import { saveOutline } from "ionicons/icons";
Expand Down Expand Up @@ -118,7 +123,8 @@ function addConditionOption(condition: any) {
conditionTypeEnumId: props.conditionTypeEnumId,
fieldName: condition.enumCode,
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()
createdDate: DateTime.now().toMillis(),
operator: condition.enumCode.includes("_excluded") ? "not-equals" : ""
}
// Adding associatedEnum out of ternary, as we will always get the conditionTypeEnumId, as the filter will already handle that
Expand Down
5 changes: 5 additions & 0 deletions src/store/modules/orderRouting/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ const actions: ActionTree<OrderRoutingState, RootState> = {

if(rulesInformation[routingRuleId]["inventoryFilters"]?.length) {
rulesInformation[routingRuleId]["inventoryFilters"] = sortSequence(rulesInformation[routingRuleId]["inventoryFilters"]).reduce((filters: any, filter: any) => {

if(filter.operator === "not-equals") {
filter.fieldName += "_excluded"
}

if(filters[filter.conditionTypeEnumId]) {
filters[filter.conditionTypeEnumId][filter.fieldName] = filter
} else {
Expand Down
10 changes: 10 additions & 0 deletions src/store/modules/util/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ const actions: ActionTree<UtilState, RootState> = {
}
return enumerations
}, enums)

if(enums["INV_FILTER_PRM_TYPE"] && enums["INV_FILTER_PRM_TYPE"]["IIP_FACILITY_GROUP"]) {
enums["INV_FILTER_PRM_TYPE"]["IIP_FACILITY_GROUP_EXCLUDED"] = {
"enumId": "IIP_FACILITY_GROUP_EXCLUDED",
"enumTypeId": "INV_FILTER_PRM_TYPE",
"enumCode": "facilityGroupId_excluded",
"sequenceNum": 5,
"description": "Facility group"
} as any
}
}
} catch(err) {
logger.error(err)
Expand Down
32 changes: 31 additions & 1 deletion src/views/BrokeringQuery.vue
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,16 @@
</p>
<ion-item v-if="getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'FACILITY_GROUP')">
<ion-select :placeholder="translate('facility group')" interface="popover" :label="translate('Group')" :value="getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'FACILITY_GROUP').fieldValue" @ionChange="updateRuleFilterValue($event, 'FACILITY_GROUP')">
<ion-select-option v-for="(facilityGroup, facilityGroupId) in getFacilityGroupsForBrokering()" :key="facilityGroupId" :value="facilityGroupId">{{ facilityGroup.facilityGroupName || facilityGroupId }}</ion-select-option>
<ion-select-option v-for="(facilityGroup, facilityGroupId) in getFacilityGroupsForBrokering()" :key="facilityGroupId" :value="facilityGroupId" :disabled="isFacilityGroupSelected(facilityGroupId, 'included')">{{ facilityGroup.facilityGroupName || facilityGroupId }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item v-if="getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'FACILITY_GROUP_EXCLUDED')">
<ion-select :placeholder="translate('facility group')" interface="popover" :value="getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'FACILITY_GROUP_EXCLUDED').fieldValue" @ionChange="updateRuleFilterValue($event, 'FACILITY_GROUP_EXCLUDED')">
<div slot="label">
<ion-label>{{ translate("Group") }}</ion-label>
<ion-note color="danger">{{ translate("Excluded") }}</ion-note>
</div>
<ion-select-option v-for="(facilityGroup, facilityGroupId) in getFacilityGroupsForBrokering()" :key="facilityGroupId" :value="facilityGroupId" :disabled="isFacilityGroupSelected(facilityGroupId, 'excluded')">{{ facilityGroup.facilityGroupName || facilityGroupId }}</ion-select-option>
</ion-select>
</ion-item>
<ion-item v-if="getFilterValue(inventoryRuleFilterOptions, conditionFilterEnums, 'PROXIMITY')">
Expand Down Expand Up @@ -716,6 +725,14 @@ async function addInventoryRule() {
return newRuleAlert.present();
}
function isFacilityGroupSelected(facilityGroupId: string, type: string) {
if(type === "excluded") {
return facilityGroupId == getFilterValue(inventoryRuleFilterOptions.value, conditionFilterEnums, 'FACILITY_GROUP').fieldValue
} else {
return facilityGroupId == getFilterValue(inventoryRuleFilterOptions.value, conditionFilterEnums, 'FACILITY_GROUP_EXCLUDED').fieldValue
}
}
// 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 }
Expand Down Expand Up @@ -1288,6 +1305,19 @@ async function save() {
const updatedRuleActionOptions = rulesInformation.value[ruleId]["actions"] ? rulesInformation.value[ruleId]["actions"] : {}
const ruleActionsDiff = findActionDiff(previousRuleActionOptions, updatedRuleActionOptions)
// As we have explicitely added the options for exclude filter for inventory rules, we will remove the _excluded from the fieldName parameter before updating the same
Object.entries(filterOptionsDiff.seqToRemove).map(([key, value]: any) => {
if(key.includes("_excluded")) {
value["fieldName"] = value["fieldName"].split("_")[0]
}
})
Object.entries(filterOptionsDiff.seqToUpdate).map(([key, value]: any) => {
if(key.includes("_excluded")) {
value["fieldName"] = value["fieldName"].split("_")[0]
}
})
return {
routingRuleId: ruleId,
orderRoutingId: props.orderRoutingId,
Expand Down

0 comments on commit dcab823

Please sign in to comment.