| | |
| | | T1.is_production, |
| | | T1.create_user, |
| | | T1.dept_id, |
| | | p.product_name as product_category, |
| | | pm.model as specification_model, |
| | | pm.unit as unit, |
| | | COALESCE(NULLIF(T1.product_category, ''), p.product_name) as product_category, |
| | | T1.material, |
| | | COALESCE(NULLIF(T1.specification_model, ''), pm.model) as specification_model, |
| | | COALESCE(NULLIF(T1.unit, ''), pm.unit) as unit, |
| | | CASE |
| | | WHEN (IFNULL(t2.qualitity, 0) - IFNULL(t2.locked_quantity, 0)) >0 THEN 1 |
| | | ELSE 0 |
| | |
| | | LEFT JOIN purchase_return_orders pro |
| | | ON pro.id = prop.purchase_return_order_id |
| | | GROUP BY prop.sales_ledger_product_id |
| | | |
| | | UNION ALL |
| | | |
| | | SELECT |
| | | si.sales_ledger_product_id, |
| | | IFNULL(SUM(rsp.num), 0) AS return_quantity |
| | | FROM return_sale_product rsp |
| | | INNER JOIN return_management rm ON rm.id = rsp.return_management_id |
| | | INNER JOIN shipping_info si ON si.id = rm.shipping_id |
| | | INNER JOIN stock_in_record sir ON sir.record_id = rsp.id |
| | | AND TRIM(sir.record_type) IN ('14','15') |
| | | AND sir.approval_status = 1 |
| | | WHERE si.sales_ledger_product_id IS NOT NULL |
| | | GROUP BY si.sales_ledger_product_id |
| | | ) t6 ON t6.sales_ledger_product_id = T1.id |
| | | left join product_model pm ON T1.product_model_id = pm.id |
| | | left join product p ON pm.product_id = p.id |