(SELECT GROUP_CONCAT(material_name) FROM logpm_distribution_parcel_list WHERE is_deleted = 0 AND stock_article_id = ldsa.id GROUP BY stock_article_id) AS materialName,
CASE ldsa.is_zero
WHEN 0 THEN
(select COUNT(id) from logpm_distrilbution_bill_package
where stock_article_id = ldsa.id and packet_bar_status in (1,3) and bill_lading_id = #{param.billLadingId} ) + (SELECT IFNULL(SUM(quantity),0) FROM logpm_distribution_reservation_zero_package WHERE stock_article_id = ldsa.id AND zero_package_status IN ( 1, 3 ) AND reservation_id = #{param.billLadingId}) handQuantity,
(select IFNULL(SUM(quantity),0) from logpm_distribution_bill_lading_scan
where stock_article_id = ldsa.id ) pick_up_quantity,
where stock_article_id = ldsa.id and packet_bar_status in (1,3) and bill_lading_id = #{param.billLadingId} AND is_deleted = 0 )
ELSE
(select sum(quantity) from logpm_distribution_reservation_zero_package
where stock_article_id = ldsa.id and zero_package_status in (1,3) AND type =3 and reservation_id = #{param.billLadingId} AND is_deleted = 0 )
END handQuantity,
(select IFNULL(sum(quantity) ,0) from logpm_distribution_bill_lading_scan
where stock_article_id = ldsa.id AND bill_lading_id = #{param.billLadingId} AND is_deleted = 0 ) pick_up_quantity,
CASE
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id ) = 0 THEN 10
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id ) - ( SELECT count( id ) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN ( 1, 3 ) ) < 0 THEN 20
WHEN ( SELECT count( id ) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id ) - ( SELECT count( id ) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN ( 1, 3 ) ) = 0 THEN 30
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id AND is_deleted = 0) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3) AND is_deleted = 0) = 0 THEN '20'
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id AND is_deleted = 0) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3) AND is_deleted = 0) > 0 THEN '10'
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id AND is_deleted = 0) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3) AND is_deleted = 0) < 0 THEN '30'
LEFT JOIN logpm_distrilbution_bill_stock ldbs ON ldbs.bill_lading_id = ldbl.id
LEFT JOIN logpm_distribution_stock_article ldsa on ldbs.stock_article_id = ldsa.id
LEFT JOIN logpm_distribution_stock lds on lds.stock_article = ldbs.stock_article_id
LEFT JOIN logpm_distrilbution_bill_lading ldbl ON lds.stock_article = ldbl.stock_article_id
LEFT JOIN (SELECT ldbs.stock_article_id,GROUP_CONCAT(DISTINCT ldbls.scan_user) AS scan_user,MAX(ldbls.create_time) AS aaa FROM logpm_distrilbution_bill_stock AS ldbs LEFT JOIN logpm_distribution_bill_lading_scan AS ldbls ON ldbs.stock_article_id = ldbls.stock_article_id WHERE ldbs.order_status IN (
1,
3) AND ldbs.is_deleted = 0 AND ldbls.is_deleted = 0 GROUP BY ldbs.stock_article_id) AS t ON ldbs.stock_article_id = t.stock_article_id
<where>
ldbs.is_deleted = 0 and ldbs.bill_lading_id = #{param.billLadingId} and ldbs.order_status in (1,3)
</where>
@ -254,22 +260,33 @@
where ldbp.bill_lading_id = #{reservationId} and ldsa.is_zero = #{isZero} and ldbp.packet_bar_status in (1,3)
(SELECT GROUP_CONCAT(material_name) FROM logpm_distribution_parcel_list WHERE is_deleted = 0 AND stock_article_id = ldsa.id GROUP BY stock_article_id) AS materialName,
CASE ldsa.is_zero
WHEN 0 THEN
(select COUNT(id) from logpm_distrilbution_bill_package
where stock_article_id = ldsa.id and packet_bar_status in (1,3) and bill_lading_id = #{param.billLadingId} ) handQuantity,
(select COUNT(id) from logpm_distribution_bill_lading_scan
where stock_article_id = ldsa.id ) pick_up_quantity,
where stock_article_id = ldsa.id and packet_bar_status in (1,3) and bill_lading_id = #{param.billLadingId} AND is_deleted = 0 )
ELSE
(select sum(quantity) from logpm_distribution_reservation_zero_package
where stock_article_id = ldsa.id and zero_package_status in (1,3) AND type =3 and reservation_id = #{param.billLadingId} AND is_deleted = 0 )
END handQuantity,
(select IFNULL(sum(quantity) ,0) from logpm_distribution_bill_lading_scan
where stock_article_id = ldsa.id AND bill_lading_id = #{param.billLadingId} AND is_deleted = 0 ) pick_up_quantity,
CASE
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3)) = 0 THEN 20
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3)) > 0 THEN 10
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3)) < 0 THEN 30
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id AND is_deleted = 0) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3) AND is_deleted = 0) = 0 THEN '20'
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id AND is_deleted = 0) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3) AND is_deleted = 0) > 0 THEN '10'
WHEN (SELECT COUNT(id) FROM logpm_distribution_bill_lading_scan WHERE stock_article_id = ldsa.id AND is_deleted = 0) - (SELECT COUNT(id) FROM logpm_distrilbution_bill_package WHERE stock_article_id = ldsa.id AND packet_bar_status IN (1,3) AND is_deleted = 0) < 0 THEN '30'