1.1.68 销售合同订单台账采购信息采购物料清单

优化。
dev
yinq 3 weeks ago
parent 13202d8ff4
commit 582b2d38b8

@ -100,14 +100,14 @@ public class ErpContractOrderController extends BaseController {
}
/**
* vs
*
*
* @param projectId erp_project_purchase.project_id erp_project_contracts
* @param contractId ID
*/
@GetMapping("/purchaseMaterialList/{projectId}")
public R<List<ErpContractOrderPurchaseMaterialVo>> getPurchaseMaterialList(@NotNull(message = "主键不能为空")
@PathVariable("projectId") Long projectId) {
return R.ok(erpContractOrderService.queryPurchaseMaterialList(projectId));
@GetMapping("/purchaseMaterialList/{contractId}")
public R<List<ErpContractOrderPurchaseMaterialVo>> getPurchaseMaterialList(@NotNull(message = "合同ID不能为空")
@PathVariable("contractId") Long contractId) {
return R.ok(erpContractOrderService.queryPurchaseMaterialList(contractId));
}
/**

@ -36,11 +36,11 @@ public interface ErpContractMaterialMapper extends BaseMapperPlus<ErpContractMat
public List<ErpContractMaterialVo> selectCustomErpContractMaterialVoList(@Param(Constants.WRAPPER) MPJLambdaWrapper<ErpContractMaterial> queryWrapper);
/**
* ID
*
*
* @param projectId ID
* @param contractId ID
* @return
*/
List<ErpContractOrderPurchaseMaterialVo> selectPurchaseMatchListByProjectId(@Param("projectId") Long projectId);
List<ErpContractOrderPurchaseMaterialVo> selectPurchaseMatchListByContractId(@Param("contractId") Long contractId);
}

@ -53,10 +53,10 @@ public interface IErpContractOrderService {
/**
* vs
*
* @param projectId erp_project_purchase.project_id
* @return
* @param contractId ID
* @return
*/
List<ErpContractOrderPurchaseMaterialVo> queryPurchaseMaterialList(Long projectId);
List<ErpContractOrderPurchaseMaterialVo> queryPurchaseMaterialList(Long contractId);
/**
*

@ -252,11 +252,11 @@ public class ErpContractOrderServiceImpl implements IErpContractOrderService {
}
@Override
public List<ErpContractOrderPurchaseMaterialVo> queryPurchaseMaterialList(Long projectId) {
if (projectId == null) {
public List<ErpContractOrderPurchaseMaterialVo> queryPurchaseMaterialList(Long contractId) {
if (contractId == null) {
return Collections.emptyList();
}
return contractMaterialMapper.selectPurchaseMatchListByProjectId(projectId);
return contractMaterialMapper.selectPurchaseMatchListByContractId(contractId);
}
/**
@ -896,15 +896,15 @@ public class ErpContractOrderServiceImpl implements IErpContractOrderService {
*
*/
private String resolvePurchaseStatus(ErpProjectInfo contractOrder) {
Long bizProjectId = resolvePurchaseBizProjectId(contractOrder);
if (bizProjectId == null) {
Long contractId = contractOrder.getContractId();
if (contractId == null) {
return OrderPurchaseStatusConstant.NOT_PURCHASED;
}
Long contractId = contractOrder.getContractId();
if (hasPurchasingInProgress(bizProjectId, contractId)) {
Long bizProjectId = resolvePurchaseBizProjectId(contractOrder);
if (bizProjectId != null && hasPurchasingInProgress(bizProjectId, contractId)) {
return OrderPurchaseStatusConstant.PURCHASING;
}
List<ErpContractOrderPurchaseMaterialVo> materials = queryPurchaseMaterialList(bizProjectId);
List<ErpContractOrderPurchaseMaterialVo> materials = queryPurchaseMaterialList(contractId);
if (CollUtil.isEmpty(materials)) {
return OrderPurchaseStatusConstant.NOT_PURCHASED;
}

@ -5,8 +5,6 @@
<mapper namespace="org.dromara.oa.erp.mapper.ErpContractMaterialMapper">
<resultMap type="org.dromara.oa.erp.domain.vo.ErpContractMaterialVo" id="ErpContractMaterialResult">
</resultMap>
<resultMap type="org.dromara.oa.erp.domain.vo.ErpContractOrderPurchaseMaterialVo" id="ErpContractOrderPurchaseMaterialResult">
</resultMap>
<select id="selectCustomErpContractMaterialVoList" resultMap="ErpContractMaterialResult">
select t.contract_material_id,
@ -43,12 +41,11 @@
</select>
<!--
projectId 与前端台账 getContractOrderPurchaseMaterialList(bizProjectId) 一致:实施项目 project_id。
合同物料范围erp_project_contracts 或 erp_project_info 上挂的本项目合同。
已采数量 = 备件类relation_details_id=合同物料ID与项目采购编辑页 selectContractMaterialsByProjectId 一致按合同ID 关联)
+ 非备件预算类relation_details_id=预算材料费IDpp.relation_id=bmc.budget_id预算行与本项目、采购头 project_id 均为传入 projectId再按合同行 material_id / relation_material_id 与预算行对齐)。
按 erp_contract_material 合同物料行展示。
已采数量仅统计备件类采购relation_details_id=合同物料IDrelation_id=合同ID与项目采购编辑页一致
-->
<select id="selectPurchaseMatchListByProjectId" resultMap="ErpContractOrderPurchaseMaterialResult">
<select id="selectPurchaseMatchListByContractId"
resultType="org.dromara.oa.erp.domain.vo.ErpContractOrderPurchaseMaterialVo">
select cm.contract_material_id,
cm.contract_id,
m.material_code,
@ -57,10 +54,10 @@
cm.specification_description,
u.unit_name,
cm.amount as contract_amount,
(coalesce(pm_spare.purchased_amount, 0) + coalesce(pm_budget.purchased_amount, 0)) as purchased_amount,
coalesce(pm.purchased_amount, 0) as purchased_amount,
case
when (coalesce(pm_spare.purchased_amount, 0) + coalesce(pm_budget.purchased_amount, 0)) &gt;= cm.amount then 0
else cm.amount - (coalesce(pm_spare.purchased_amount, 0) + coalesce(pm_budget.purchased_amount, 0))
when coalesce(pm.purchased_amount, 0) &gt;= cm.amount then 0
else cm.amount - coalesce(pm.purchased_amount, 0)
end as unpurchased_amount
from erp_contract_material cm
left join base_material_info m on m.material_id = cm.material_id
@ -75,53 +72,11 @@
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_spare
on pm_spare.relation_details_id = cm.contract_material_id
and pm_spare.relation_id = cm.contract_id
left join (select cm_line.contract_material_id,
sum(coalesce(ppm.purchase_amount, 0)) as purchased_amount
from erp_contract_material cm_line
inner join erp_budget_material_cost bmc on bmc.project_id = #{projectId}
and bmc.del_flag = '0'
and (
(cm_line.material_id is not null and bmc.material_id = cm_line.material_id)
or (cm_line.material_id is null and cm_line.relation_material_id is not null
and bmc.relation_material_id = cm_line.relation_material_id)
)
inner join erp_project_purchase_material ppm on ppm.relation_details_id = bmc.material_cost_id
and ppm.del_flag = '0'
and ppm.spare_flag = '0'
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'
and pp.project_id = #{projectId}
and pp.relation_id = bmc.budget_id
where cm_line.del_flag = '0'
and (
exists (select 1 from erp_project_contracts pc2
where pc2.project_id = #{projectId}
and pc2.contract_id = cm_line.contract_id
and pc2.del_flag = '0')
or exists (select 1 from erp_project_info pi2
where pi2.project_id = #{projectId}
and pi2.del_flag = '0'
and pi2.contract_id is not null
and pi2.contract_id = cm_line.contract_id)
)
group by cm_line.contract_material_id) pm_budget
on pm_budget.contract_material_id = cm.contract_material_id
group by ppm.relation_details_id, pp.relation_id) pm
on pm.relation_details_id = cm.contract_material_id
and pm.relation_id = cm.contract_id
where cm.del_flag = '0'
and (
exists (select 1 from erp_project_contracts pc
where pc.project_id = #{projectId}
and pc.contract_id = cm.contract_id
and pc.del_flag = '0')
or exists (select 1 from erp_project_info pi
where pi.project_id = #{projectId}
and pi.del_flag = '0'
and pi.contract_id is not null
and pi.contract_id = cm.contract_id)
)
and cm.contract_id = #{contractId}
order by cm.contract_material_id asc
</select>

Loading…
Cancel
Save