Skip to content

Commit

Permalink
Merge pull request #73 from hotwax/72-brokering-fails-for-single-assi…
Browse files Browse the repository at this point in the history
…gnment-when-queue-contains-completedcancelled-items

Fix: SQL now checks facility and threshold conditions for eligible ship group items only
  • Loading branch information
dixitdeepak committed Dec 10, 2024
1 parent b406688 commit 2a608be
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions sql/InventorySourceSelector.sql.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ x.*
(select sum(QUANTITY-ifnull(CANCEL_QUANTITY,0)) from order_item where order_id=oh.ORDER_ID and status_id = 'ITEM_APPROVED' and ship_group_seq_id = oisg.ship_group_seq_id group by order_id) as ship_group_total_qty,
oi.quantity-ifnull(oi.cancel_quantity,0) as item_qty,oisg.carrier_party_id,
fpa.postal_code as origin_postal_code,opa.postal_code as destination_postal_code,f.maximum_order_limit,foc.entry_date,foc.last_order_count, inv_count.inventoryForAllocation,
ifnull((select distinct 'N' from order_item oi1 LEFT join product_facility pf1 on oi1.product_id=pf1.product_id and pf1.facility_id=pf.FACILITY_ID where oi1.order_id=oh.ORDER_ID and oi1.ship_group_seq_id=oisg.ship_group_seq_id and ((ifnull(pf1.last_inventory_count,0)-ifnull(pf1.MINIMUM_STOCK,0)) < oi1.quantity-ifnull(oi1.cancel_quantity,0) or pf1.FACILITY_ID is null) AND ifnull(pf.ALLOW_BROKERING,'Y') = 'Y' group by oi1.ORDER_ID,pf1.FACILITY_ID),'Y') as rank_by_order_at_facility,<#-- revised -->
ifnull((select distinct 'N' from order_item oi1 LEFT join product_facility pf1 on oi1.product_id=pf1.product_id and pf1.facility_id=pf.FACILITY_ID where oi1.order_id=oh.ORDER_ID and oi1.ship_group_seq_id=oisg.ship_group_seq_id and ((ifnull(pf1.last_inventory_count,0)-ifnull(pf1.MINIMUM_STOCK,0)) < oi1.quantity-ifnull(oi1.cancel_quantity,0) or pf1.FACILITY_ID is null) AND ifnull(pf.ALLOW_BROKERING,'Y') = 'Y' and oi1.status_id = 'ITEM_APPROVED' group by oi1.ORDER_ID,pf1.FACILITY_ID),'Y') as rank_by_order_at_facility,<#-- revised -->
<#if !splitGroupItem>
ifnull((select distinct 'N' from order_item_group_assoc oiga1 inner join order_item_group oig1 on oiga1.order_id = oig1.order_id and oig1.order_item_group_type_id = "BROKERING_ITEM_GRP" inner join order_item oi1 on oiga1.ORDER_ID = oi1.ORDER_ID and oiga1.ORDER_ITEM_SEQ_ID = oi1.ORDER_ITEM_SEQ_ID left join product_facility pf1 on oi1.product_id=pf1.product_id and pf1.facility_id=pf.FACILITY_ID
where oiga1.order_id=oiga.ORDER_ID and oi1.order_id=oi.ORDER_ID and oiga1.ORDER_ITEM_GROUP_SEQ_ID=oiga.ORDER_ITEM_GROUP_SEQ_ID and ((ifnull(pf1.last_inventory_count, 0)-ifnull(pf1.MINIMUM_STOCK,0)) < oi1.quantity-ifnull(oi1.cancel_quantity,0) <#if brokeringSafetyStock?has_content> or case when (ifnull(pf1.last_inventory_count, 0)-ifnull(pf1.MINIMUM_STOCK,0)) >= oi1.quantity-ifnull(oi1.cancel_quantity,0) then (ifnull(pf1.last_inventory_count, 0)-ifnull(pf1.MINIMUM_STOCK,0)) < ${(brokeringSafetyStock.fieldValue)!0} end </#if> or pf1.FACILITY_ID is null) and ifnull(pf.ALLOW_BROKERING,'Y') = 'Y' group by oi1.ORDER_ID,oiga1.ORDER_ITEM_GROUP_SEQ_ID),'Y') as rank_by_order_item_grp_at_facility_threshold,
where oiga1.order_id=oiga.ORDER_ID and oi1.order_id=oi.ORDER_ID and oiga1.ORDER_ITEM_GROUP_SEQ_ID=oiga.ORDER_ITEM_GROUP_SEQ_ID and oi1.status_id='ITEM_APPROVED' and ((ifnull(pf1.last_inventory_count, 0)-ifnull(pf1.MINIMUM_STOCK,0)) < oi1.quantity-ifnull(oi1.cancel_quantity,0) <#if brokeringSafetyStock?has_content> or case when (ifnull(pf1.last_inventory_count, 0)-ifnull(pf1.MINIMUM_STOCK,0)) >= oi1.quantity-ifnull(oi1.cancel_quantity,0) then (ifnull(pf1.last_inventory_count, 0)-ifnull(pf1.MINIMUM_STOCK,0)) < ${(brokeringSafetyStock.fieldValue)!0} end </#if> or pf1.FACILITY_ID is null) and ifnull(pf.ALLOW_BROKERING,'Y') = 'Y' group by oi1.ORDER_ID,oiga1.ORDER_ITEM_GROUP_SEQ_ID),'Y') as rank_by_order_item_grp_at_facility_threshold,
</#if> <#-- NEW Rank order item if its order item group's all items are available at facility above threshold -->
ifnull((select distinct 'N' from order_item oi1 LEFT join product_facility pf1 on oi1.product_id=pf1.product_id and pf1.facility_id=pf.FACILITY_ID where oi1.order_id=oh.ORDER_ID and oi1.ship_group_seq_id=oisg.ship_group_seq_id <#if brokeringSafetyStock?has_content> and ((ifnull(pf1.last_inventory_count,0)-ifnull(pf1.MINIMUM_STOCK,0)) < ${(brokeringSafetyStock.fieldValue)!0} OR pf1.FACILITY_ID is null) </#if> AND ifnull(pf.ALLOW_BROKERING,'Y') = 'Y' group by oi1.ORDER_ID,pf1.FACILITY_ID),'Y') as rank_by_order_above_facility_threshold, <#-- revised -->
ifnull((select distinct 'N' from order_item oi1 LEFT join product_facility pf1 on oi1.product_id=pf1.product_id and pf1.facility_id=pf.FACILITY_ID where oi1.order_id=oh.ORDER_ID and oi1.ship_group_seq_id=oisg.ship_group_seq_id <#if brokeringSafetyStock?has_content> and ((ifnull(pf1.last_inventory_count,0)-ifnull(pf1.MINIMUM_STOCK,0)) < ${(brokeringSafetyStock.fieldValue)!0} OR pf1.FACILITY_ID is null) </#if> AND ifnull(pf.ALLOW_BROKERING,'Y') = 'Y' and oi1.status_id ='ITEM_APPROVED' group by oi1.ORDER_ID,pf1.FACILITY_ID),'Y') as rank_by_order_above_facility_threshold, <#-- revised -->
ifnull((select count(oi2.order_item_seq_id) from order_item oi2 inner join product_facility pf2 on oi2.product_id=pf2.product_id and (ifnull(pf2.LAST_INVENTORY_COUNT,0)-ifnull(pf2.MINIMUM_STOCK,0)) > 0 and ifnull(pf2.ALLOW_BROKERING,'Y') = 'Y' where oi2.order_id=oh.ORDER_ID and oi2.ship_group_seq_id=oisg.ship_group_seq_id and pf2.facility_id=pf.facility_id and (ifnull(pf2.last_inventory_count,0)-ifnull(pf2.MINIMUM_STOCK,0)) >= oi2.quantity-ifnull(oi2.cancel_quantity,0) and oi2.STATUS_ID = 'ITEM_APPROVED' group by oi2.ORDER_ID,pf2.FACILITY_ID),0) as rank_by_item_cnt,
ifnull((select count(oi2.order_item_seq_id) from order_item oi2 inner join product_facility pf2 on oi2.product_id=pf2.product_id <#if brokeringSafetyStock?has_content> and (ifnull(pf2.LAST_INVENTORY_COUNT,0)-ifnull(pf2.MINIMUM_STOCK,0)) <@buildSqlCondition value=brokeringSafetyStock /> </#if> and ifnull(pf2.ALLOW_BROKERING,'Y') = 'Y' where oi2.order_id=oh.ORDER_ID and oi2.ship_group_seq_id=oisg.ship_group_seq_id and pf2.facility_id=pf.facility_id and (ifnull(pf2.last_inventory_count,0)-ifnull(pf2.MINIMUM_STOCK,0)) >= oi2.quantity-ifnull(oi2.cancel_quantity,0) and oi2.STATUS_ID = 'ITEM_APPROVED' group by oi2.ORDER_ID,pf2.FACILITY_ID),0) as rank_by_item_cnt_above_threshold,
ifnull((select 'Y' from order_item oi3 where oi3.order_id=oi.ORDER_ID and oi3.order_item_seq_id=oi.order_item_seq_id <#if brokeringSafetyStock?has_content> and (ifnull(pf.last_inventory_count,0)-ifnull(pf.MINIMUM_STOCK,0)) <@buildSqlCondition value=brokeringSafetyStock /> </#if> and (ifnull(pf.last_inventory_count,0)-ifnull(pf.MINIMUM_STOCK,0)) >= oi3.quantity-ifnull(oi3.cancel_quantity,0) and oi3.STATUS_ID = 'ITEM_APPROVED'),'N') as item_at_facility_above_threshold
Expand Down

0 comments on commit 2a608be

Please sign in to comment.