|
@@ -60,6 +60,8 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
|
|
|
private final IInventoryFormMaterialService formMaterialService;
|
|
|
|
|
|
+ private final IMeterPeriodService meterPeriodService;
|
|
|
+
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public void add(ContractMaterialAdjustAddDTO dto) {
|
|
@@ -69,6 +71,21 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
ContractMaterialAdjust adjust = new ContractMaterialAdjust();
|
|
|
BeanUtils.copyProperties(dto,adjust);
|
|
|
adjust.setId(SnowFlakeUtil.getId());
|
|
|
+ /*保存材料明细*/
|
|
|
+ List<ContractMaterialAdjustDetail> details = dto.getDetails();
|
|
|
+ BigDecimal adjustTotal = BigDecimal.ZERO;
|
|
|
+ if (details.size() != 0){
|
|
|
+ for (ContractMaterialAdjustDetail detail : details) {
|
|
|
+ detail.setMaterialAdjustId(adjust.getId());
|
|
|
+ if (detail.getChangeTotal() == null){
|
|
|
+ throw new ServiceException("请填写["+detail.getFormName()+"]可调量");
|
|
|
+ }
|
|
|
+ detail.setAdjustTotal(detail.getChangeTotal().multiply(detail.getAdjustFactor()).setScale(3,RoundingMode.HALF_UP));
|
|
|
+ adjustTotal = adjustTotal.add(detail.getAdjustTotal());
|
|
|
+ }
|
|
|
+ adjustDetailService.saveBatch(details);
|
|
|
+ }
|
|
|
+
|
|
|
//计算调差金额,生成计算式
|
|
|
StringBuilder str = new StringBuilder("调差价格依据于:"+dto.getMaterialName()+
|
|
|
"("+validity.getStartDate().format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"至"+
|
|
@@ -78,32 +95,27 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
BigDecimal currentPrice = dto.getCurrentPrice();
|
|
|
if (price.compareTo(currentPrice) == 1){
|
|
|
//市场价低于基准价
|
|
|
- adjustMoney = dto.getMaterialTotal().multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().abs().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
+ adjustMoney = adjustTotal.multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().abs().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
str.append("调差公式(标准):调增金额=调差数量×[市场价-基准价×(1-风险幅度差%)]×(1+合同增值税税率)\n");
|
|
|
- str.append("调差公式(计算):"+adjustMoney+"="+dto.getMaterialTotal()+"*["+currentPrice+"-"+price+"*(1+"+dto.getRangePriceRatio().abs()+"%)]*(1+9.0/100)");
|
|
|
+ str.append("调差公式(计算):"+adjustMoney+"="+adjustTotal+"*["+currentPrice+"-"+price+"*(1+"+dto.getRangePriceRatio().abs()+"%)]*(1+9.0/100)");
|
|
|
}else {
|
|
|
//市场价高于基准价
|
|
|
- adjustMoney = dto.getMaterialTotal().multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
+ adjustMoney = adjustTotal.multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
str.append("调差公式(标准):调增金额=调差数量×[市场价-基准价×(1+风险幅度差%)]×(1+合同增值税税率)\n");
|
|
|
- str.append("调差公式(计算):"+adjustMoney+"="+dto.getMaterialTotal()+"*["+currentPrice+"-"+price+"*(1-"+dto.getRangePriceRatio()+"%)]*(1+9.0/100)");
|
|
|
+ str.append("调差公式(计算):"+adjustMoney+"="+adjustTotal+"*["+currentPrice+"-"+price+"*(1-"+dto.getRangePriceRatio()+"%)]*(1+9.0/100)");
|
|
|
}
|
|
|
+ adjust.setAdjustTotal(adjustTotal);
|
|
|
adjust.setAdjustMoney(adjustMoney);
|
|
|
adjust.setAdjustCalculation(str.toString());
|
|
|
this.save(adjust);
|
|
|
|
|
|
- /*保存材料明细*/
|
|
|
- List<ContractMaterialAdjustDetail> details = dto.getDetails();
|
|
|
- if (details.size() != 0){
|
|
|
- for (ContractMaterialAdjustDetail detail : details) {
|
|
|
- detail.setMaterialAdjustId(adjust.getId());
|
|
|
- }
|
|
|
- adjustDetailService.saveBatch(details);
|
|
|
- }
|
|
|
/*保存附件信息*/
|
|
|
List<AttachmentForm> files = dto.getFiles();
|
|
|
if (files.size() != 0){
|
|
|
for (AttachmentForm file : files) {
|
|
|
file.setMasterId(adjust.getId());
|
|
|
+ file.setProjectId(dto.getProjectId());
|
|
|
+ file.setContractId(dto.getContractId());
|
|
|
}
|
|
|
attachmentFormService.saveBatch(files);
|
|
|
}
|
|
@@ -122,6 +134,8 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
List<ContractMaterialAdjustDetail> list = baseMapper.getMaterialDetail(dto,formIds);
|
|
|
for (ContractMaterialAdjustDetail detail : list) {
|
|
|
detail.setContractMaterialId(dto.getContractMaterialId());
|
|
|
+ detail.setChangeTotal(detail.getMeterTotal());
|
|
|
+ detail.setAdjustTotal(detail.getChangeTotal().multiply(detail.getAdjustFactor()).setScale(3,RoundingMode.HALF_UP));
|
|
|
}
|
|
|
return list;
|
|
|
}
|
|
@@ -160,6 +174,24 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
/*保存材料调差单*/
|
|
|
ContractMaterialAdjust adjust = new ContractMaterialAdjust();
|
|
|
BeanUtils.copyProperties(dto,adjust);
|
|
|
+ BigDecimal adjustTotal = BigDecimal.ZERO;
|
|
|
+ /*保存材料明细*/
|
|
|
+ //先删除再清空id
|
|
|
+ adjustDetailService.remove(new LambdaQueryWrapper<ContractMaterialAdjustDetail>()
|
|
|
+ .eq(ContractMaterialAdjustDetail::getMaterialAdjustId,adjust.getId()));
|
|
|
+ List<ContractMaterialAdjustDetail> details = dto.getDetails();
|
|
|
+ if (details.size() != 0){
|
|
|
+ for (ContractMaterialAdjustDetail detail : details) {
|
|
|
+ detail.setId(null);
|
|
|
+ detail.setMaterialAdjustId(adjust.getId());
|
|
|
+ if (detail.getChangeTotal() == null){
|
|
|
+ throw new ServiceException("请填写["+detail.getFormName()+"]可调量");
|
|
|
+ }
|
|
|
+ detail.setAdjustTotal(detail.getChangeTotal().multiply(detail.getAdjustFactor()).setScale(3,RoundingMode.HALF_UP));
|
|
|
+ adjustTotal = adjustTotal.add(detail.getAdjustTotal());
|
|
|
+ }
|
|
|
+ adjustDetailService.saveBatch(details);
|
|
|
+ }
|
|
|
//计算调差金额,生成计算式
|
|
|
StringBuilder str = new StringBuilder("调差价格依据于:"+dto.getMaterialName()+
|
|
|
"("+validity.getStartDate().format(DateTimeFormatter.ofPattern("yyyyMMdd"))+"至"+
|
|
@@ -169,31 +201,21 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
BigDecimal currentPrice = dto.getCurrentPrice();
|
|
|
if (price.compareTo(currentPrice) == 1){
|
|
|
//市场价低于基准价
|
|
|
- adjustMoney = dto.getMaterialTotal().multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().abs().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
+ adjustMoney = adjustTotal.multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().abs().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
str.append("调差公式(标准):调增金额=调差数量×[市场价-基准价×(1-风险幅度差%)]×(1+合同增值税税率)\n");
|
|
|
- str.append("调差公式(计算):"+adjustMoney+"="+dto.getMaterialTotal()+"*["+currentPrice+"-"+price+"*(1+"+dto.getRangePriceRatio().abs()+"%)]*(1+9.0/100)");
|
|
|
+ str.append("调差公式(计算):"+adjustMoney+"="+adjustTotal+"*["+currentPrice+"-"+price+"*(1+"+dto.getRangePriceRatio().abs()+"%)]*(1+9.0/100)");
|
|
|
}else {
|
|
|
//市场价高于基准价
|
|
|
- adjustMoney = dto.getMaterialTotal().multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
+ adjustMoney = adjustTotal.multiply(currentPrice.subtract((price.multiply(new BigDecimal(1).add(dto.getRangePriceRatio().divide(new BigDecimal(100))))))).multiply(new BigDecimal(1.09)).setScale(2, RoundingMode.DOWN);
|
|
|
str.append("调差公式(标准):调增金额=调差数量×[市场价-基准价×(1+风险幅度差%)]×(1+合同增值税税率)\n");
|
|
|
- str.append("调差公式(计算):"+adjustMoney+"="+dto.getMaterialTotal()+"*["+currentPrice+"-"+price+"*(1-"+dto.getRangePriceRatio()+"%)]*(1+9.0/100)");
|
|
|
+ str.append("调差公式(计算):"+adjustMoney+"="+adjustTotal+"*["+currentPrice+"-"+price+"*(1-"+dto.getRangePriceRatio()+"%)]*(1+9.0/100)");
|
|
|
}
|
|
|
adjust.setAdjustMoney(adjustMoney);
|
|
|
+ adjust.setAdjustTotal(adjustTotal);
|
|
|
adjust.setAdjustCalculation(str.toString());
|
|
|
this.updateById(adjust);
|
|
|
|
|
|
- /*保存材料明细*/
|
|
|
- //先删除再清空id
|
|
|
- adjustDetailService.remove(new LambdaQueryWrapper<ContractMaterialAdjustDetail>()
|
|
|
- .eq(ContractMaterialAdjustDetail::getMaterialAdjustId,adjust.getId()));
|
|
|
- List<ContractMaterialAdjustDetail> details = dto.getDetails();
|
|
|
- if (details.size() != 0){
|
|
|
- for (ContractMaterialAdjustDetail detail : details) {
|
|
|
- detail.setId(null);
|
|
|
- detail.setMaterialAdjustId(adjust.getId());
|
|
|
- }
|
|
|
- adjustDetailService.saveBatch(details);
|
|
|
- }
|
|
|
+
|
|
|
/*保存附件信息*/
|
|
|
//先删除再清空id
|
|
|
attachmentFormService.remove(new LambdaQueryWrapper<AttachmentForm>()
|
|
@@ -203,8 +225,26 @@ public class ContractMaterialAdjustServiceImpl extends BaseServiceImpl<ContractM
|
|
|
for (AttachmentForm file : files) {
|
|
|
file.setId(null);
|
|
|
file.setMasterId(adjust.getId());
|
|
|
+ file.setProjectId(dto.getProjectId());
|
|
|
+ file.setContractId(dto.getContractId());
|
|
|
}
|
|
|
attachmentFormService.saveBatch(files);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void delete(Long id) {
|
|
|
+ //获取调差信息,判断是否已经审批
|
|
|
+ ContractMaterialAdjust adjust = this.getById(id);
|
|
|
+ if (adjust.getApproveStatus() == 1){
|
|
|
+ throw new ServiceException("当前材料调差单已经上报,删除失败");
|
|
|
+ }
|
|
|
+ //获取材料计量期,判断是否已经审批
|
|
|
+ MeterPeriod period = meterPeriodService.getById(adjust.getMeterPeriodId());
|
|
|
+ if (period.getApproveStatus() != 0){
|
|
|
+ throw new ServiceException("删除失败,当前计量期不是未上报状态");
|
|
|
+ }
|
|
|
+ this.removeById(id);
|
|
|
+
|
|
|
+ }
|
|
|
}
|