| | |
| | | CASE |
| | | WHEN t2.id IS NOT NULL THEN 1 |
| | | ELSE 0 |
| | | END as has_stock_inventory |
| | | END as has_stock_inventory, |
| | | (SELECT IFNULL(SUM(si.quantity), 0) |
| | | FROM shipping_info si |
| | | WHERE si.sales_ledger_product_id = T1.id |
| | | AND si.status IN ('审核通过', '已发货')) AS already_shipped_quantity, |
| | | (IFNULL(T1.quantity, 0) - (SELECT IFNULL(SUM(si.quantity), 0) |
| | | FROM shipping_info si |
| | | WHERE si.sales_ledger_product_id = T1.id |
| | | AND si.status IN ('审核通过', '已发货'))) AS unshipped_quantity |
| | | FROM |
| | | sales_ledger_product T1 |
| | | LEFT JOIN stock_inventory t2 ON T1.product_model_id = t2.product_model_id |