| | |
| | | pl.purchase_contract_number as purchase_contract_no |
| | | </when> |
| | | <otherwise> |
| | | pwo.work_order_no, |
| | | sl.sales_contract_no |
| | | pot.work_order_no, |
| | | po_sales.sales_contract_no |
| | | </otherwise> |
| | | </choose> |
| | | FROM |
| | |
| | | </when> |
| | | <otherwise> |
| | | LEFT JOIN production_product_main ppm ON qi.product_main_id = ppm.id |
| | | LEFT JOIN product_work_order pwo ON ppm.work_order_id = pwo.id |
| | | left join product_order po ON po.id = pwo.product_order_id |
| | | left join sales_ledger sl ON sl.id = po.sales_ledger_id |
| | | LEFT JOIN production_operation_task pot ON ppm.production_operation_task_id = pot.id |
| | | left join production_order po ON po.id = pot.production_order_id |
| | | left join ( |
| | | select po2.id as order_id, |
| | | group_concat(distinct sl2.sales_contract_no order by sl2.sales_contract_no separator ',') as sales_contract_no |
| | | from production_order po2 |
| | | left join production_plan pp2 |
| | | on find_in_set(pp2.id, replace(replace(replace(po2.production_plan_ids, '[', ''), ']', ''), ' ', '')) > 0 |
| | | left join sales_ledger sl2 on sl2.id = pp2.sales_ledger_id |
| | | group by po2.id |
| | | ) po_sales ON po_sales.order_id = po.id |
| | | </otherwise> |
| | | </choose> |
| | | WHERE |