| | |
| | | import cn.hutool.core.convert.Convert; |
| | | import cn.hutool.core.date.DatePattern; |
| | | import cn.hutool.core.date.DateUtil; |
| | | import cn.hutool.core.io.StreamProgress; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.IdUtil; |
| | | import cn.hutool.core.util.ObjUtil; |
| | |
| | | .eq(ContractSubjectMatter::getMaterialCode, contractInvoiceOutBoundVo.getSubjectMatterCode()) |
| | | .eq(StrUtil.isNotBlank(contractInvoiceOutBoundVo.getLineNo()), ContractSubjectMatter::getLineNo, contractInvoiceOutBoundVo.getLineNo()) |
| | | .last("limit 1")); |
| | | if (ObjUtil.isNotNull(subjectMatter) && subjectMatter.getAdvanceNum().compareTo(new BigDecimal("0")) > 0) { |
| | | contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(subjectMatter.getAdvanceNum())); |
| | | if (ObjUtil.isNotNull(subjectMatter)) { |
| | | contractInvoiceOutBoundVo.setUnitPrice(subjectMatter.getUnitPrice()); |
| | | if (subjectMatter.getAdvanceNum().compareTo(new BigDecimal("0")) > 0) { |
| | | contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(subjectMatter.getAdvanceNum())); |
| | | } |
| | | } |
| | | contractInvoiceOutBoundVo.setToInvoiceNum(contractInvoiceOutBoundVo.getInvoiceNum()); |
| | | }); |
| | |
| | | public R genInvoiceInfo(GenInvoiceInfoDTO genInvoiceInfoDTO) { |
| | | if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | return R.failed("请选择开票出库单后再操作"); |
| | | } |
| | | genInvoiceInfoDTO.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList().stream().filter(item-> |
| | | item.getInvoiceNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList())); |
| | | if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | return R.failed("请选择开票出库单后或调整开票数量再操作"); |
| | | } |
| | | Long contractId = null; |
| | | //预收款开票 |
| | |
| | | if (CollUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | |
| | | if (!CollUtil.contains(erpCode, contractOutBound.getSubjectMatterCode())) { |
| | | erpCode.add(contractOutBound.getSubjectMatterCode()); |
| | | ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode()) |
| | | .eq(StrUtil.isNotBlank(contractOutBound.getLineNo()),ContractSubjectMatter::getLineNo,contractOutBound.getLineNo()) |
| | | .eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1")); |
| | | if (!CollUtil.contains(erpCode, contractOutBound.getSubjectMatterCode()+subjectMatter.getUnitPrice())) { |
| | | erpCode.add(contractOutBound.getSubjectMatterCode()+subjectMatter.getUnitPrice()); |
| | | ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo(); |
| | | mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode()); |
| | | mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode()+subjectMatter.getUnitPrice()); |
| | | mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName()); |
| | | mergeVo.setQuantity(contractOutBoundInvoiceVo.getInvoiceNum()); |
| | | Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode()) |
| | |
| | | mergeVo.setTaxRate(new BigDecimal(product.getTaxRate())); |
| | | mergeVo.setTaxCode(product.getTaxCode()); |
| | | } |
| | | ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getMaterialCode, contractOutBound.getSubjectMatterCode()) |
| | | .eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(subjectMatter)) { |
| | | mergeVo.setUnitPrice(subjectMatter.getUnitPrice()); |
| | | mergeVo.setUnit(subjectMatter.getUnit()); |
| | |
| | | mergeOutBounds.add(mergeVo); |
| | | } else { |
| | | List<ContractOutBoundMergeVo> filteredList = mergeOutBounds.stream() |
| | | .filter(item -> contractOutBound.getSubjectMatterCode().equals(item.getMaterialCode())) // 防止空指针,建议常量在前 |
| | | .filter(item -> item.getMaterialCode().equals(subjectMatter.getMaterialCode()+subjectMatter.getUnitPrice())) // 防止空指针,建议常量在前 |
| | | .collect(Collectors.toList()); |
| | | if (ArrayUtil.isNotEmpty(filteredList)) { |
| | | filteredList.get(0).setQuantity(filteredList.get(0).getQuantity().add(contractOutBound.getOutBoundNum())); |
| | |
| | | mergeVo.setSpecification(product.getProductType()); |
| | | mergeVo.setTaxRate(new BigDecimal(product.getTaxRate())); |
| | | mergeVo.setTaxCode(product.getTaxCode()); |
| | | Product productClass = productMapper.selectById(product.getParentId()); |
| | | if (ObjUtil.isNotNull(product)) { |
| | | if (StrUtil.equals(product.getErpCode(), "water_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*水费"); |
| | | mergeVo.setUnit("吨"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*电费"); |
| | | mergeVo.setUnit("度"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "house_rental")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*房屋租赁"); |
| | | } else { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*" + productClass.getProductName()); |
| | | } |
| | | |
| | | } |
| | | } |
| | | ContractSubjectMatter subjectMatter = subjectMatterMapper.selectOne(Wrappers.<ContractSubjectMatter>lambdaQuery() |
| | | .eq(ContractSubjectMatter::getMaterialCode, schedule.getSubjectMatterCode()) |
| | | .eq(ContractSubjectMatter::getContractId, contract.getId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(subjectMatter)) { |
| | | mergeVo.setUnitPrice(subjectMatter.getUnitPrice()); |
| | | if (StrUtil.equals(product.getErpCode(), "water_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*水费"); |
| | | mergeVo.setUnit("吨"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*电费"); |
| | | mergeVo.setUnit("度"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "house_rental")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*房屋租赁"); |
| | | } else { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*" + subjectMatter.getMaterialName()); |
| | | } |
| | | |
| | | } |
| | | mergeOutBounds.add(mergeVo); |
| | | } else { |
| | |
| | | genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractSubjectMatter subjectMatter = contractSubjectMatterMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | if (ObjUtil.isNotNull(subjectMatter)) { |
| | | if (!CollUtil.contains(erpCode, subjectMatter.getMaterialCode())) { |
| | | if (!CollUtil.contains(erpCode, subjectMatter.getMaterialCode()+subjectMatter.getUnitPrice())) { |
| | | erpCode.add(subjectMatter.getMaterialCode()); |
| | | ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo(); |
| | | mergeVo.setMaterialCode(subjectMatter.getMaterialCode()); |
| | |
| | | mergeVo.setSpecification(product.getProductType()); |
| | | mergeVo.setTaxRate(new BigDecimal(product.getTaxRate())); |
| | | mergeVo.setTaxCode(product.getTaxCode()); |
| | | Product productClass = productMapper.selectById(product.getParentId()); |
| | | if (ObjUtil.isNotNull(product)) { |
| | | if (StrUtil.equals(product.getErpCode(), "water_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*水费"); |
| | | mergeVo.setUnit("吨"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*电费"); |
| | | mergeVo.setUnit("度"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "house_rental")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*房屋租赁"); |
| | | } else { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*" + productClass.getProductName()); |
| | | } |
| | | |
| | | } |
| | | if (ObjUtil.isNotNull(product)) { |
| | | if (StrUtil.equals(product.getErpCode(), "water_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*水费"); |
| | | mergeVo.setUnit("吨"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*电费"); |
| | | mergeVo.setUnit("度"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "house_rental")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*房屋租赁"); |
| | | } else { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*" + subjectMatter.getMaterialName()); |
| | | } |
| | | |
| | | } |
| | | mergeVo.setUnitPrice(subjectMatter.getUnitPrice()); |
| | | mergeVo.setUnit(subjectMatter.getUnit()); |
| | |
| | | |
| | | @Override |
| | | public R toInvoice(GenInvoiceInfoDTO genInvoiceInfoDTO) { |
| | | if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | return R.failed("请选择开票出库单后再操作"); |
| | | } |
| | | genInvoiceInfoDTO.setOutBoundInvoiceList(genInvoiceInfoDTO.getOutBoundInvoiceList().stream().filter(item-> |
| | | item.getInvoiceNum().compareTo(new BigDecimal("0"))>0).collect(Collectors.toList())); |
| | | if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | return R.failed("请选择开票出库单后或调整开票数量再操作"); |
| | | } |
| | | if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "3") || StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(), "4")) { |
| | | if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())) { |
| | |
| | | genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | contractOutBound.setInvoiceStatus("1"); |
| | | if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum())) <= 0) { |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | } |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | }); |
| | | } else { |
| | |
| | | } |
| | | if (!StrUtil.equals(contract.getContractCategory(), "water_house")) { |
| | | //合同状态 |
| | | if (StrUtil.equals(contract.getBillingStatus(), "2")) { |
| | | contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout())); |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0 && |
| | | contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | contract.setContractStatus(3); |
| | | } |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) { |
| | | contract.setBillingStatus("1"); |
| | | List<ContractOutBound> outBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery() |
| | | .eq(ContractOutBound::getContractId, contract.getId()) |
| | | .apply("invoice_num < out_bound_num")); |
| | | if (CollUtil.isNotEmpty(outBoundList)) { |
| | | contract.setBillingStatus("2"); |
| | | } |
| | | |
| | | } |
| | | //防止重复审开票审核通过后 开票金额超出合同金额 |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) > 0) { |
| | | contract.setBillingAmout(contract.getAmount()); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout())); |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | } |
| | | if (contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0&& |
| | | contract.getBillingAmout().compareTo(contract.getAmount()) == 0){ |
| | | contract.setContractStatus(3); |
| | | } |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) { |
| | | contract.setBillingStatus("1"); |
| | | List<ContractOutBound> outBoundList = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery() |
| | | .eq(ContractOutBound::getContractId, contract.getId()) |
| | | .apply("invoice_num < out_bound_num")); |
| | | if (CollUtil.isNotEmpty(outBoundList)) { |
| | | contract.setBillingStatus("2"); |
| | | } |
| | | |
| | | } |
| | | //防止重复审开票审核通过后 开票金额超出合同金额 |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) > 0) { |
| | | contract.setBillingAmout(contract.getAmount()); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | |
| | | } else { |
| | | //判断 循环是否完成 |
| | | List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId, contract.getId()) |
| | |
| | | contract.setBillingStatus("2"); |
| | | } |
| | | contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout())); |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | } |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0 && |
| | | contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) == 0) { |
| | | contract.getPaidAmount().compareTo(contract.getAmount().subtract(contract.getDropAmount())) >= 0) { |
| | | contract.setBillingStatus("3"); |
| | | contract.setContractStatus(3); |
| | | } |
| | |
| | | if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) { |
| | | outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum())) <= 0) { |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | } |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | }); |
| | | } |
| | | } else { |
| | |
| | | if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList)) { |
| | | outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum())) <= 0) { |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | } |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | }); |
| | | } |
| | | } else { |