@@ -1792,31 +1793,32 @@ open class ProductionScheduleService(
"fromDate" to fromDate,
"fromDate" to fromDate,
)
)
// Aggregate-only SELECT: MySQL 8 ONLY_FULL_GROUP_BY rejects the old `group by matCode` + psl.*.
val sql = """
val sql = """
select
select
group_concat(distinct it.code) as itemCode,
group_concat(distinct it.code) as itemCode,
group_concat(distinct it.name) as itemName,
group_concat(distinct it.name) as itemName,
itm.code as matCode,
itm.code as matCode,
itm.name as matName,
MAX(itm.name) as matName,
sum(bm.qty * psl.batchNeed) as totalMatQtyNeed,
sum(bm.qty * psl.batchNeed) as totalMatQtyNeed,
iv.onHandQty,
iv.unavailableQty,
MAX(iv.onHandQty) as onHandQty,
MAX(iv.unavailableQty) as unavailableQty,
(select sum(qty) from purchase_order_line
(select sum(qty) from purchase_order_line
left join purchase_order on purchase_order_line.purchaseOrderId = purchase_order.id
left join purchase_order on purchase_order_line.purchaseOrderId = purchase_order.id
where purchase_order_line.itemId = itm.id and date(purchase_order.estimatedArrivalDate) >= date(now()) and purchase_order.completeDate is null) as purchasedQty,
where purchase_order_line.itemId = itm.id and date(purchase_order.estimatedArrivalDate) >= date(now()) and purchase_order.completeDate is null) as purchasedQty,
bm.uomName,
(select ratioD/ratioN from item_uom where purchaseUnit = 1 and itemId = it.id and item_uom.deleted = 0
) as purchaseRatio,
(select ceil(ratioD/ratioN*sum(bm.qty * psl.batchNeed)) from item_uom where purchaseUnit = 1 and itemId = it.id and item_uom.deleted = 0
) as purchaseQtyNeed,
MAX(bm.uomName) as uomName,
(select ratioD/ratioN from item_uom where purchaseUnit = 1 and itemId = itm.id and item_uom.deleted = 0
LIMIT 1) as purchaseRatio,
ceil(sum(bm.qty * psl.batchNeed) * COALESCE((
select ratioD/ratioN from item_uom where purchaseUnit = 1 and itemId = itm.id and item_uom.deleted = 0 LIMIT 1
), 0)) as purchaseQtyNeed,
(select code from item_uom
(select code from item_uom
left join uom_conversion on item_uom.uomId = uom_conversion.id
left join uom_conversion on item_uom.uomId = uom_conversion.id
where item_uom.purchaseUnit = 1 and item_uom.itemId = it.id and item_uom.deleted = 0
) as purchaseUnit,
where item_uom.purchaseUnit = 1 and item_uom.itemId = itm.id and item_uom.deleted = 0
LIMIT 1) as purchaseUnit,
min(ps.produceAt) as toProdcueFrom,
min(ps.produceAt) as toProdcueFrom,
max(ps.produceAt) as toProdcueAt,
max(ps.produceAt) as toProdcueAt,
ucs.udfudesc as stockUnit,
psl.*
MAX(ucs.udfudesc) as stockUnit
from production_schedule_line psl
from production_schedule_line psl
left join production_schedule ps on psl.prodScheduleId = ps.id
left join production_schedule ps on psl.prodScheduleId = ps.id
@@ -1825,15 +1827,15 @@ open class ProductionScheduleService(
left join bom_material bm on bom.id = bm.bomId
left join bom_material bm on bom.id = bm.bomId
left join items itm on bm.itemId = itm.id
left join items itm on bm.itemId = itm.id
left join inventory iv on itm.id = iv.itemId
left join inventory iv on itm.id = iv.itemId
left join item_uom ius on itm.id = ius.itemId and ius.stockUnit = 1
left join item_uom ius on itm.id = ius.itemId and ius.stockUnit = 1 and ius.deleted = 0
left join uom_conversion ucs on ius.uomId = ucs.id
left join uom_conversion ucs on ius.uomId = ucs.id
where ps.produceAt >= :fromDate
where ps.produceAt >= :fromDate
and ps.id = (select id from production_schedule where produceAt = ps.produceAt order by id desc limit 1)
and ps.id = (select id from production_schedule where produceAt = ps.produceAt order by id desc limit 1)
-- This is water
-- This is water
AND it.code != 'GI3236'
AND it.code != 'GI3236'
-- order by ps.produceAt asc, psl.itemPriority desc, itemCode asc
group by matCode
AND itm.id IS NOT NULL
group by itm.id, itm.code
""";
""";
@@ -1869,33 +1871,33 @@ open class ProductionScheduleService(