IF(a.warehousing_outbound_type = 1,LPAD(n.ord_ln,3,0),LPAD(o.ord_ln,3,0)) as SAL_LINE,
IF(a.warehousing_outbound_type = 1,LPAD(n.ord_ln,3,0),LPAD(o.ord_ln,3,0)) as SAL_LINE,
aa.batch_number as BATCH_ID,
aa.batch_number as BATCH_ID,
concat(ab.code,'-',LPAD(ab.ord_ln,3,0)) as PUR_ORDER
IF(ad.code,concat(ad.code,'-',LPAD(ad.ord_ln,3,0)),concat(ac.business_order_no,'-',LPAD(ab.ord_ln,3,0))) as PUR_ORDER
FROM
jg_warehousing_outbound a
RIGHT JOIN jg_warehousing_outbound_product aa ON a.id = aa.warehousing_outbound_id AND aa.f_delete_mark is null
-- LEFT JOIN jg_warehousing_storage_product ab ON aa.batch_number = ab.batch_number AND ab.f_delete_mark is null
-- LEFT JOIN jg_warehousing_storage ac ON ab.warehousing_storage_id = ac.id AND ac.f_delete_mark is null
LEFT JOIN jg_business_batch ab ON aa.batch_number = ab.batch_number AND ab.f_delete_mark is null
LEFT JOIN jg_warehousing_notification b ON a.warehousing_id = b.id AND b.f_delete_mark IS NULL
LEFT JOIN jg_business_order c ON b.business_id = c.id AND c.f_delete_mark IS NULL
LEFT JOIN jg_subject_basic d ON c.first_subject_basic_id = d.id AND d.f_delete_mark IS NULL
LEFT JOIN base_organize e ON a.company_id = e.f_id AND e.f_delete_mark IS NULL
LEFT JOIN base_organize f ON a.department_id = f.f_id AND f.f_delete_mark IS NULL
LEFT JOIN base_user g ON a.f_creator_user_id = g.f_id AND g.f_delete_mark IS NULL
LEFT JOIN jg_contract h ON c.contract_id = h.id AND h.f_delete_mark IS NULL
LEFT JOIN jg_business_cargo i ON aa.outbound_area_id = i.id AND i.f_delete_mark IS NULL
LEFT JOIN jg_product j ON aa.product_id = j.id AND j.f_delete_mark is null
LEFT JOIN base_user k ON a.f_last_modify_user_id = k.f_id AND k.f_delete_mark IS NULL
LEFT JOIN jg_delivery_order l on a.warehousing_id = l.id and l.f_delete_mark is null
LEFT JOIN jg_business_order m on l.business_id = m.id and m.f_delete_mark is null
LEFT JOIN jg_business_order_product_relational n on c.id = n.business_order_id and n.f_delete_mark is null and aa.product_id = n.product_id and aa.outbound_unit = n.sales_main_unit_id and aa.ord_ln = n.ord_ln
LEFT JOIN jg_business_order_product_relational o on m.id = o.business_order_id and o.f_delete_mark is null and aa.product_id = o.product_id and aa.outbound_unit = o.sales_main_unit_id and aa.ord_ln = o.ord_ln
LEFT JOIN jg_contract p ON m.contract_id = p.id AND p.f_delete_mark IS NULL
LEFT JOIN jg_subject_basic q ON m.first_subject_basic_id = q.id AND q.f_delete_mark IS NULL
LEFT JOIN jg_business_order r ON a.business_order_no = r.code AND r.f_delete_mark is null
LEFT JOIN jg_contract s ON r.contract_id = s.id AND s.f_delete_mark is null