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