"LEFT JOIN project_sale_order a ON (a.id = o.project_order_id) "+
"LEFT JOIN project_plan b ON (b.project_id = a.id) "+
"LEFT JOIN base_customer c ON (c.id = a.customer_id) "+
"LEFT JOIN base_material d ON (d.id = o.material_id) "+
"LEFT JOIN pro_task_dispatch e ON (e.project_sub_id = o.id) "+
"LEFT JOIN pro_task_dispatch_detail f ON (f.dispatch_id = e.id) "+
"LEFT JOIN base_procedure g ON (g.id = f.procedure_id AND g.is_final = 1) "+
"LEFT JOIN pro_task_report h ON (h.dispatch_detail_id = f.id AND h.has_report = 1) "+
"WHERE o.deleted=0 AND (a.order_status = 8 AND a.is_snapshot = 0) and g.name='成品包装' and o.id=t.id "+
") reportAmount1")
.select("ifnull((select amount from ( "+
"select a.material_id,a.project_id,sum(a.amount) as amount from "+
" (select distinct assemble_code,material_id,procedure_id,amount,SUBSTRING_INDEX(assemble_code,'-',1) as project_id from pro_task_report where isnull(assemble_code)=0) as a "+
"group by a.material_id,a.project_id) as b where b.material_id=t.material_id and b.project_id=t.project_order_id "+