where l.is_deleted =0 AND l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid is null and ldsi.incoming_batch = l.incoming_batch )
ELSE (select sum(l.quantity_stock)
where l.is_deleted =0 AND l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid is null
and ldsi.incoming_batch = l.incoming_batch )
ELSE (select sum(l.quantity_stock)
from logpm_distribution_stock_list l
where l.is_deleted =0 AND l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not null and ldsi.incoming_batch = l.incoming_batch )
where l.is_deleted =0 AND l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid
and l.pid is not null and ldsi.incoming_batch = l.incoming_batch )
END 'quantityStock',
CASE WHEN ldsi.pid is null THEN
(select sum(l.outbound_quantity)
CASE WHEN ldsi.pid is null THEN
(select sum(l.outbound_quantity)
from logpm_distribution_stock_list l
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id AND l.pid is null and ldsi.incoming_batch = l.incoming_batch)
else (select sum(l.outbound_quantity)
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id AND l.pid is null and
ldsi.incoming_batch = l.incoming_batch)
else (select sum(l.outbound_quantity)
from logpm_distribution_stock_list l
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not null and ldsi.incoming_batch = l.incoming_batch)
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not
where l.market_id =ldsi.market_id and l.material_id = ldsi.material_id and l.pid is null and ldsi.incoming_batch = l.incoming_batch ))
ELSE (select count(*)
where l.market_id =ldsi.market_id and l.material_id = ldsi.material_id and l.pid is null and ldsi.incoming_batch
= l.incoming_batch ))
ELSE (select count(*)
from logpm_distribution_stock_list lds
where lds.pid in (select l.id
where lds.pid in (select l.id
from logpm_distribution_stock_list l
where l.market_id =ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not null and ldsi.incoming_batch = l.incoming_batch ))
where l.market_id =ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not
null and ldsi.incoming_batch = l.incoming_batch ))
END 'unpack',
CASE WHEN ldsi.pid is null THEN
CASE WHEN ldsi.pid is null THEN
(select sum(l.quantity_occupied)
from logpm_distribution_stock_list l
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id AND l.pid is null and ldsi.incoming_batch = l.incoming_batch)
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id AND l.pid is null and
ldsi.incoming_batch = l.incoming_batch)
else (select sum(l.quantity_occupied)
from logpm_distribution_stock_list l
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not null and ldsi.incoming_batch = l.incoming_batch)
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not
null and ldsi.incoming_batch = l.incoming_batch)
END 'quantityOccupied',
CASE WHEN ldsi.pid is null THEN
CASE WHEN ldsi.pid is null THEN
(select sum(l.unpacking_quantity)
from logpm_distribution_stock_list l
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id AND l.pid is null and ldsi.incoming_batch = l.incoming_batch)
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id AND l.pid is null and
ldsi.incoming_batch = l.incoming_batch)
else (select sum(l.unpacking_quantity)
from logpm_distribution_stock_list l
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not null and ldsi.incoming_batch = l.incoming_batch)
where l.market_id = ldsi.market_id and l.material_id = ldsi.material_id and l.pid = ldsi.pid and l.pid is not
left join logpm_distribution_reservation_stocklist ldrs on ldrs.reservation_id = ldr.id and ldrs.is_deleted = 0 and ldrs.stock_list_status in (1,3)
left join logpm_distribution_stock_list ldsl on ldsl.id = ldrs.stocklist_id and ldsl.is_deleted = 0
left join logpm_distribution_stock s on s.stock_list_id = ldsl.id and s.is_deleted = 0 and s.stock_list_id = #{stockListId} and s.reservation_id = #{reservationId}
left join logpm_distribution_reservation_stocklist ldrs on ldrs.reservation_id = ldr.id and ldrs.is_deleted = 0
and ldrs.stock_list_status in (1,3)
left join logpm_distribution_stock_list ldsl on ldsl.id = ldrs.stocklist_id and ldsl.is_deleted = 0
left join logpm_distribution_stock s on s.stock_list_id = ldsl.id and s.is_deleted = 0 and s.stock_list_id =
#{stockListId} and s.reservation_id = #{reservationId}
(SELECT GROUP_CONCAT(position_code) from logpm_warehouse_updown_goods lwug where lwug.association_id =ldsl.material_id and market_name=ldsl.market_name) as position_code
(SELECT GROUP_CONCAT(position_code) from logpm_warehouse_updown_goods lwug where lwug.association_id
=ldsl.material_id and market_name=ldsl.market_name) as position_code
<!-- lwug.position_code-->
FROM
logpm_distribution_stock_list ldsl
FROM
logpm_distribution_stock_list ldsl
<where>
ldsl.service_type = #{par.serviceType} and ldsl.warehouse_id = #{par.warehouseId} and ldsl.is_deleted = 0 and (ldsl.quantity_stock - ldsl.quantity_occupied) > 0
ldsl.service_type = #{par.serviceType} and ldsl.warehouse_id = #{par.warehouseId} and ldsl.is_deleted = 0
and (ldsl.quantity_stock - ldsl.quantity_occupied) > 0
<iftest="par.incomingBatch != null and par.incomingBatch != ''">
and ldsl.incoming_batch like concat('%',#{par.incomingBatch},'%')
and ldsl.incoming_batch like concat('%',#{par.incomingBatch},'%')
</if>
<iftest="par.orderCode != null and par.orderCode != ''">
and ldsl.order_code like concat('%',#{par.orderCode},'%')
and ldsl.order_code like concat('%',#{par.orderCode},'%')
</if>
<iftest="par.serviceNumber != null and par.serviceNumber != ''">
and ldsl.service_number like concat('%',#{par.serviceNumber},'%')
and ldsl.service_number like concat('%',#{par.serviceNumber},'%')
</if>
<iftest="par.marketCode != null and par.marketCode != ''">
and ldsl.market_code like concat('%',#{par.marketCode},'%')
and ldsl.market_code like concat('%',#{par.marketCode},'%')
</if>
<iftest="par.marketName != null and par.marketName != ''">
and ldsl.market_name like concat('%',#{par.marketName},'%')
and ldsl.market_name like concat('%',#{par.marketName},'%')
</if>
<iftest="par.storeName != null and par.storeName != ''">
and ldsl.store_name like concat('%',#{par.storeName},'%')
and ldsl.store_name like concat('%',#{par.storeName},'%')
</if>
<iftest="par.storeCode != null and par.storeCode != ''">
and ldsl.store_code like concat('%',#{par.storeCode},'%')
and ldsl.store_code like concat('%',#{par.storeCode},'%')
</if>
<iftest="par.storeCode != null and par.storeCode != ''">
and ldsl.store_code like concat('%',#{par.storeCode},'%')
and ldsl.store_code like concat('%',#{par.storeCode},'%')
</if>
<iftest="par.cargoNumber != null and par.cargoNumber != ''">
and ldsl.cargo_number like concat('%',#{par.cargoNumber},'%')
and ldsl.cargo_number like concat('%',#{par.cargoNumber},'%')
</if>
<iftest="par.descriptionGoods != null and par.descriptionGoods != ''">
and ldsl.description_goods like concat('%',#{par.descriptionGoods},'%')
and ldsl.description_goods like concat('%',#{par.descriptionGoods},'%')
</if>
<iftest="par.brandName != null and par.brandName != ''">
and ldsl.brand_name like concat('%',#{par.brandName},'%')
and ldsl.brand_name like concat('%',#{par.brandName},'%')
LEFT JOIN logpm_distribution_parcel_list AS ldpl ON ldsl.incoming_batch = ldpl.order_code
AND ldpl.conditions = 2
LEFT JOIN logpm_warehouse_tray_goods AS lwtg ON ldpl.order_package_code = lwtg.association_value AND lwtg.association_type = 3
LEFT JOIN logpm_warehouse_updown_goods AS lwug ON ldpl.order_package_code = lwug.association_value AND lwug.association_type = 3
LEFT JOIN logpm_warehouse_tray_goods AS lwtg ON ldpl.order_package_code = lwtg.association_value AND
lwtg.association_type = 3
LEFT JOIN logpm_warehouse_updown_goods AS lwug ON ldpl.order_package_code = lwug.association_value AND
lwug.association_type = 3
LEFT JOIN logpm_warehouse_tray AS lwt ON lwt.id = lwtg.tray_id
LEFT JOIN logpm_warehouse_goods_allocation AS lwga ON lwug.allocation_id = lwga.id
WHERE
@ -595,15 +628,17 @@
lwga.qr_code AS allocation,
lwt.pallet_name AS trayName,
CASE
WHEN lwug.id is not null THEN lwug.num
WHEN lwtg.id is not null THEN lwtg.num
WHEN lwug.id is not null THEN lwug.num
WHEN lwtg.id is not null THEN lwtg.num
ELSE
ldsl.quantity_stock
END num
FROM
logpm_distribution_stock_list AS ldsl
LEFT JOIN logpm_warehouse_tray_goods AS lwtg ON ldsl.cargo_number = lwtg.association_value AND lwtg.association_type = 4 AND lwtg.incoming_batch = ldsl.incoming_batch
LEFT JOIN logpm_warehouse_updown_goods AS lwug ON ldsl.cargo_number = lwug.association_value AND lwug.association_type = 4 AND lwug.incoming_batch = ldsl.incoming_batch
LEFT JOIN logpm_warehouse_tray_goods AS lwtg ON ldsl.cargo_number = lwtg.association_value AND
lwtg.association_type = 4 AND lwtg.incoming_batch = ldsl.incoming_batch
LEFT JOIN logpm_warehouse_updown_goods AS lwug ON ldsl.cargo_number = lwug.association_value AND
lwug.association_type = 4 AND lwug.incoming_batch = ldsl.incoming_batch
LEFT JOIN logpm_warehouse_tray AS lwt ON lwt.id = lwtg.tray_id
LEFT JOIN logpm_warehouse_goods_allocation AS lwga ON lwug.allocation_id = lwga.id
WHERE
@ -613,29 +648,31 @@
lwtg.tray_id
</select>
<updateid="updeteSourceTypeById">
<updateid="updeteSourceTypeById">
update logpm_distribution_stock_list
set source_type = #{sourceType}
where id = #{stockListId}
</update>
<updateid="updateInventoryQuantityOccupied">
UPDATE logpm_distribution_stock_list SET quantity_occupied = (quantity_occupied + #{reservationNum}) WHERE id = #{stockListId}
UPDATE logpm_distribution_stock_list SET quantity_occupied = (quantity_occupied + #{reservationNum}) WHERE id =
#{stockListId}
</update>
<updateid="decreaseStockListQuantityOccupied">
UPDATE logpm_distribution_stock_list SET quantity_occupied = (quantity_occupied - #{num}) WHERE id = #{stockListId}
UPDATE logpm_distribution_stock_list SET quantity_occupied = (quantity_occupied - #{num}) WHERE id =