|
|
|
|
@ -59,15 +59,31 @@
|
|
|
|
|
t.unit_id,
|
|
|
|
|
u.unit_name,
|
|
|
|
|
t.amount as need_purchase_amount,
|
|
|
|
|
t.amount as purchase_amount,
|
|
|
|
|
case
|
|
|
|
|
when coalesce(pm.purchased_amount, 0) >= t.amount then 0
|
|
|
|
|
else t.amount - coalesce(pm.purchased_amount, 0)
|
|
|
|
|
end as purchase_amount,
|
|
|
|
|
m.material_code as relation_material_code,
|
|
|
|
|
COALESCE(m.material_name, t.product_name) as relation_material_name
|
|
|
|
|
from erp_contract_material t
|
|
|
|
|
left join erp_project_contracts pc on pc.contract_id = t.contract_id and pc.del_flag = '0'
|
|
|
|
|
left join base_material_info m on m.material_id = t.material_id
|
|
|
|
|
left join base_unit_info u on u.unit_id = t.unit_id
|
|
|
|
|
left join (select ppm.relation_details_id,
|
|
|
|
|
pp.relation_id,
|
|
|
|
|
sum(coalesce(ppm.purchase_amount, 0)) as purchased_amount
|
|
|
|
|
from erp_project_purchase_material ppm
|
|
|
|
|
inner join erp_project_purchase pp on pp.project_purchase_id = ppm.project_purchase_id
|
|
|
|
|
and pp.del_flag = '0'
|
|
|
|
|
and pp.spare_flag = '1'
|
|
|
|
|
where ppm.del_flag = '0'
|
|
|
|
|
and ppm.spare_flag = '1'
|
|
|
|
|
group by ppm.relation_details_id, pp.relation_id) pm
|
|
|
|
|
on pm.relation_details_id = t.contract_material_id
|
|
|
|
|
and pm.relation_id = t.contract_id
|
|
|
|
|
where t.del_flag = '0'
|
|
|
|
|
and pc.project_id = #{projectId}
|
|
|
|
|
order by t.contract_material_id asc
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="selectBudgetMaterialsByProjectId"
|
|
|
|
|
@ -84,11 +100,26 @@
|
|
|
|
|
t.unit_id,
|
|
|
|
|
u.unit_name,
|
|
|
|
|
t.amount as need_purchase_amount,
|
|
|
|
|
t.amount as purchase_amount,
|
|
|
|
|
case
|
|
|
|
|
when coalesce(pm.purchased_amount, 0) >= t.amount then 0
|
|
|
|
|
else t.amount - coalesce(pm.purchased_amount, 0)
|
|
|
|
|
end as purchase_amount,
|
|
|
|
|
t.material_code as relation_material_code,
|
|
|
|
|
t.material_name as relation_material_name
|
|
|
|
|
from erp_budget_material_cost t
|
|
|
|
|
left join base_unit_info u on u.unit_id = t.unit_id
|
|
|
|
|
left join (select ppm.relation_details_id,
|
|
|
|
|
pp.relation_id,
|
|
|
|
|
sum(coalesce(ppm.purchase_amount, 0)) as purchased_amount
|
|
|
|
|
from erp_project_purchase_material ppm
|
|
|
|
|
inner join erp_project_purchase pp on pp.project_purchase_id = ppm.project_purchase_id
|
|
|
|
|
and pp.del_flag = '0'
|
|
|
|
|
and pp.spare_flag = '0'
|
|
|
|
|
where ppm.del_flag = '0'
|
|
|
|
|
and ppm.spare_flag = '0'
|
|
|
|
|
group by ppm.relation_details_id, pp.relation_id) pm
|
|
|
|
|
on pm.relation_details_id = t.material_cost_id
|
|
|
|
|
and pm.relation_id = t.budget_id
|
|
|
|
|
where t.del_flag = '0'
|
|
|
|
|
and t.project_id = #{projectId}
|
|
|
|
|
order by t.material_cost_id asc
|
|
|
|
|
|