| | |
| | | import com.by4cloud.platformx.admin.api.feign.RemoteDeptService; |
| | | import com.by4cloud.platformx.business.api.feign.RemoteFlowProcessService; |
| | | import com.by4cloud.platformx.business.constant.FlowNameEnum; |
| | | import com.by4cloud.platformx.business.dto.ContractInvoiceQueryDTO; |
| | | import com.by4cloud.platformx.business.dto.ContractQueryDTO; |
| | | import com.by4cloud.platformx.business.dto.GenInvoiceInfoDTO; |
| | | import com.by4cloud.platformx.business.entity.*; |
| | | import com.by4cloud.platformx.business.mapper.*; |
| | | import com.by4cloud.platformx.business.service.ContractInvoiceService; |
| | | import com.by4cloud.platformx.business.service.PaymentConfirmService; |
| | | import com.by4cloud.platformx.business.vo.ContractInvoiceOutBoundVo; |
| | | import com.by4cloud.platformx.business.vo.ContractOutBoundMergeVo; |
| | | import com.by4cloud.platformx.business.vo.GenInvoiceInfoVo; |
| | | import com.by4cloud.platformx.business.vo.InvoiceItemVo; |
| | | import com.by4cloud.platformx.business.vo.*; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.common.data.datascope.DataScope; |
| | | import com.by4cloud.platformx.common.data.mybatis.BaseModel; |
| | | import com.by4cloud.platformx.common.security.util.SecurityUtils; |
| | | import com.by4cloud.platformx.flow.task.dto.ProcessInstanceParamDto; |
| | |
| | | private final ContractMapper contractMapper; |
| | | private final BusinessCustomerMapper businessCustomerMapper; |
| | | private final ContractOutBoundMapper contractOutBoundMapper; |
| | | private final PaymentConfirmMapper paymentConfirmMapper; |
| | | private final ContractExecDateMapper contractExecDateMapper; |
| | | private final ContractPaymentScheduleMapper contractPaymentScheduleMapper; |
| | | private final MeterReadRecordMapper meterReadRecordMapper; |
| | | private final ContractSubjectMatterMapper subjectMatterMapper; |
| | | private final ProductMapper productMapper; |
| | | private final BwRequestRecordMapper bwRequestRecordMapper; |
| | |
| | | .selectAll(ContractOutBound.class) |
| | | .eq(ContractOutBound::getContractId, contractId); |
| | | List<ContractInvoiceOutBoundVo> invoiceOutBoundVoList = contractOutBoundMapper.selectJoinList(ContractInvoiceOutBoundVo.class, wrapper); |
| | | if (ArrayUtil.isNotEmpty(invoiceOutBoundVoList.toArray())) { |
| | | invoiceOutBoundVoList.stream().forEach(contractInvoiceOutBoundVo -> { |
| | | contractInvoiceOutBoundVo.setInvoiceNum(contractInvoiceOutBoundVo.getOutBoundNum().subtract(contractInvoiceOutBoundVo.getInvoiceNum())); |
| | | contractInvoiceOutBoundVo.setToInvoiceNum(contractInvoiceOutBoundVo.getInvoiceNum()); |
| | | }); |
| | | } |
| | | return R.ok(invoiceOutBoundVoList); |
| | | } |
| | | |
| | | @Override |
| | | public R getContractHouseWater(Long contractId) { |
| | | MPJLambdaWrapper<ContractPaymentSchedule> wrapper = new MPJLambdaWrapper<ContractPaymentSchedule>() |
| | | .selectAll(ContractPaymentSchedule.class) |
| | | .eq(ContractPaymentSchedule::getContractId, contractId) |
| | | .orderByAsc(ContractPaymentSchedule::getCreateTime); |
| | | List<ContractHouseWaterVo> invoiceOutBoundVoList = contractPaymentScheduleMapper.selectJoinList(ContractHouseWaterVo.class, wrapper); |
| | | return R.ok(invoiceOutBoundVoList); |
| | | } |
| | | |
| | | @Override |
| | | public R genInvoiceInfo(GenInvoiceInfoDTO genInvoiceInfoDTO) { |
| | | if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getContractOutBoundIds())) { |
| | | if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | return R.failed("请选择开票出库单后再操作"); |
| | | } |
| | | ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getContractOutBoundIds().get(0)); |
| | | Contract contract = contractMapper.selectById(outBound.getContractId()); |
| | | Long contractId = null; |
| | | if (!StrUtil.equals(genInvoiceInfoDTO.getContractCategory(),"water_house")) { |
| | | ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId()); |
| | | contractId = outBound.getContractId(); |
| | | }else { |
| | | ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId()); |
| | | contractId = schedule.getContractId(); |
| | | } |
| | | Contract contract = contractMapper.selectById(contractId); |
| | | if (ObjUtil.isNull(contract)) { |
| | | return R.failed("合同信息异常,请联系技术人员"); |
| | | } |
| | |
| | | private GenInvoiceInfoVo genInvoiceInfoVo(GenInvoiceInfoDTO genInvoiceInfoDTO, Contract contract, SysDept b) { |
| | | GenInvoiceInfoVo vo = new GenInvoiceInfoVo(); |
| | | BusinessCustomer a = businessCustomerMapper.selectById(contract.getPartyAId()); |
| | | vo.setPartyA(a.getCompanyName()); |
| | | vo.setPartyA(a.getRegisterName()); |
| | | vo.setPartyAOrgCode(a.getCreditCode()); |
| | | vo.setPartyAOpenBank(a.getBankName()); |
| | | vo.setPartyABankAccount(a.getBankAccount()); |
| | |
| | | List<InvoiceItemVo> invoiceItemVoList = new ArrayList<>(); |
| | | List<String> erpCode = new ArrayList<>(); |
| | | List<ContractOutBoundMergeVo> mergeOutBounds = new ArrayList<>(); |
| | | List<ContractOutBound> outBounds = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery() |
| | | .in(ContractOutBound::getId, genInvoiceInfoDTO.getContractOutBoundIds())); |
| | | if (ArrayUtil.isNotEmpty(outBounds.toArray())) { |
| | | outBounds.stream().forEach(contractOutBound -> { |
| | | if (!ArrayUtil.contains(erpCode.toArray(), contractOutBound.getSubjectMatterCode())) { |
| | | erpCode.add(contractOutBound.getSubjectMatterCode()); |
| | | ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo(); |
| | | mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode()); |
| | | mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName()); |
| | | mergeVo.setQuantity(contractOutBound.getOutBoundNum()); |
| | | Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode()) |
| | | .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(product)) { |
| | | mergeVo.setTaxClass(product.getTaxClass()); |
| | | mergeVo.setSpecification(product.getProductType()); |
| | | mergeVo.setTaxRate(new BigDecimal(product.getTaxRate())); |
| | | mergeVo.setTaxCode(product.getTaxCode()); |
| | | Product productClass = productMapper.selectById(product.getParentId()); |
| | | // List<ContractOutBound> outBounds = contractOutBoundMapper.selectList(Wrappers.<ContractOutBound>lambdaQuery() |
| | | // .in(ContractOutBound::getId, genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getContractOutBoundId()).collect(Collectors.toList()))); |
| | | if (!StrUtil.equals(contract.getContractCategory(), "water_house")){ |
| | | if (ArrayUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) { |
| | | genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | |
| | | if (!ArrayUtil.contains(erpCode.toArray(), contractOutBound.getSubjectMatterCode())) { |
| | | erpCode.add(contractOutBound.getSubjectMatterCode()); |
| | | ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo(); |
| | | mergeVo.setMaterialCode(contractOutBound.getSubjectMatterCode()); |
| | | mergeVo.setMaterialInternalName(contractOutBound.getSubjectMatterName()); |
| | | mergeVo.setQuantity(contractOutBoundInvoiceVo.getInvoiceNum()); |
| | | Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, contractOutBound.getSubjectMatterCode()) |
| | | .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(product)) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*" + productClass.getProductName()); |
| | | mergeVo.setTaxClass(product.getTaxClass()); |
| | | 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() + "*水费"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*电费"); |
| | | } 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, 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())) // 防止空指针,建议常量在前 |
| | | .collect(Collectors.toList()); |
| | | if (ArrayUtil.isNotEmpty(filteredList.toArray())) { |
| | | filteredList.get(0).setQuantity(filteredList.get(0).getQuantity().add(contractOutBound.getOutBoundNum())); |
| | | } |
| | | } |
| | | 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())) // 防止空指针,建议常量在前 |
| | | .collect(Collectors.toList()); |
| | | if (ArrayUtil.isNotEmpty(filteredList.toArray())) { |
| | | filteredList.get(0).setQuantity(filteredList.get(0).getQuantity().add(contractOutBound.getOutBoundNum())); |
| | | } |
| | | } |
| | | }); |
| | | if (ArrayUtil.isNotEmpty(mergeOutBounds.toArray())) { |
| | | invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class); |
| | | invoiceItemVoList.stream().forEach(invoiceItemVo -> { |
| | | // for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) { |
| | | BigDecimal itemPrice = invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()); |
| | | BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate()); |
| | | invoiceItemVo.setPriceTax(itemPriceTax); |
| | | invoiceItemVo.setPriceNoTax(itemPrice.subtract(itemPriceTax)); |
| | | }); |
| | | vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceTax().add(item.getPriceNoTax())).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setInvoiceItemList(invoiceItemVoList); |
| | | vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice())); |
| | | if (ArrayUtil.isNotEmpty(mergeOutBounds.toArray())) { |
| | | invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class); |
| | | invoiceItemVoList.stream().forEach(invoiceItemVo -> { |
| | | // for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) { |
| | | BigDecimal itemPrice = invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity()); |
| | | BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate()); |
| | | invoiceItemVo.setPriceTax(itemPriceTax); |
| | | invoiceItemVo.setPriceNoTax(itemPrice.subtract(itemPriceTax)); |
| | | }); |
| | | vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceTax().add(item.getPriceNoTax())).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setInvoiceItemList(invoiceItemVoList); |
| | | vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice())); |
| | | } |
| | | } |
| | | }else { |
| | | if (ArrayUtil.isNotEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) { |
| | | genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | |
| | | if (!ArrayUtil.contains(erpCode.toArray(), schedule.getSubjectMatterCode())) { |
| | | erpCode.add(schedule.getSubjectMatterCode()); |
| | | ContractOutBoundMergeVo mergeVo = new ContractOutBoundMergeVo(); |
| | | mergeVo.setMaterialCode(schedule.getSubjectMatterCode()); |
| | | mergeVo.setMaterialInternalName(schedule.getSubjectMatterName()); |
| | | mergeVo.setPriceAndTax(schedule.getPlannedAmount()); |
| | | Product product = productMapper.selectOne(Wrappers.<Product>lambdaQuery().eq(Product::getErpCode, schedule.getSubjectMatterCode()) |
| | | .eq(Product::getCompId, SecurityUtils.getUser().getCompId()).last("limit 1")); |
| | | if (ObjUtil.isNotNull(product)) { |
| | | mergeVo.setTaxClass(product.getTaxClass()); |
| | | 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() + "*水费"); |
| | | } else if (StrUtil.equals(product.getErpCode(), "electricity_bill")) { |
| | | mergeVo.setItemName("*" + product.getTaxClass() + "*电费"); |
| | | } 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()); |
| | | } |
| | | mergeOutBounds.add(mergeVo); |
| | | }else { |
| | | List<ContractOutBoundMergeVo> filterMergeVo = mergeOutBounds.stream().filter(item->item.getMaterialCode() |
| | | .equals(schedule.getSubjectMatterCode())).collect(Collectors.toList()); |
| | | if (ArrayUtil.isNotEmpty(filterMergeVo.toArray())){ |
| | | filterMergeVo.get(0).setPriceAndTax(schedule.getPlannedAmount().add(filterMergeVo.get(0).getPriceAndTax())); |
| | | } |
| | | } |
| | | }); |
| | | if (ArrayUtil.isNotEmpty(mergeOutBounds.toArray())) { |
| | | invoiceItemVoList = BeanUtil.copyToList(mergeOutBounds, InvoiceItemVo.class); |
| | | invoiceItemVoList.stream().forEach(invoiceItemVo -> { |
| | | // for (InvoiceItemVo invoiceItemVo:invoiceItemVoList) { |
| | | BigDecimal itemPrice = invoiceItemVo.getPriceAndTax(); |
| | | BigDecimal itemPriceTax = itemPrice.divide(new BigDecimal("100").add(invoiceItemVo.getTaxRate()), 2, RoundingMode.HALF_UP).multiply(invoiceItemVo.getTaxRate()); |
| | | invoiceItemVo.setPriceTax(itemPriceTax); |
| | | invoiceItemVo.setPriceNoTax(itemPrice.subtract(itemPriceTax)); |
| | | }); |
| | | vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceAndTax()).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setInvoiceItemList(invoiceItemVoList); |
| | | vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice())); |
| | | } |
| | | } |
| | | } |
| | | return vo; |
| | |
| | | |
| | | @Override |
| | | public R toInvoice(GenInvoiceInfoDTO genInvoiceInfoDTO) { |
| | | if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getContractOutBoundIds().toArray())) { |
| | | if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList().toArray())) { |
| | | return R.failed("请选择开票出库单后再操作"); |
| | | } |
| | | ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getContractOutBoundIds().get(0)); |
| | | Contract contract = contractMapper.selectById(outBound.getContractId()); |
| | | Long contractId = null; |
| | | if (!StrUtil.equals(genInvoiceInfoDTO.getContractCategory(),"water_house")) { |
| | | ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId()); |
| | | contractId = outBound.getContractId(); |
| | | }else { |
| | | ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId()); |
| | | contractId = schedule.getContractId(); |
| | | } |
| | | Contract contract = contractMapper.selectById(contractId); |
| | | if (ObjUtil.isNull(contract)) { |
| | | return R.failed("合同信息异常,请联系技术人员"); |
| | | } |
| | |
| | | SysDept b = r.getData(); |
| | | GenInvoiceInfoVo vo = genInvoiceInfoVo(genInvoiceInfoDTO, contract, b); |
| | | //发票保存 |
| | | ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getContractOutBoundIds(), DateUtil.current() + ""); |
| | | ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + ""); |
| | | //启动流程 |
| | | ProcessInstanceParamDto dto = new ProcessInstanceParamDto(); |
| | | Map<String, Object> map = BeanUtil.beanToMap(invoice); |
| | | if (StrUtil.equals(genInvoiceInfoDTO.getContractCategory(),"water_house")) { |
| | | map.put("contractCategory","water_house"); |
| | | } |
| | | dto.setParamMap(map); |
| | | dto.setFlowName(FlowNameEnum.销售挂账审批.name()); |
| | | R r1 = remoteFlowProcessService.startProcessInstance(dto); |
| | | if (r1.getCode() == 1) { |
| | | return R.failed("流程启动失败"); |
| | | } |
| | | //更新合同出库单状态 |
| | | genInvoiceInfoDTO.getContractOutBoundIds().stream().forEach(outBoundId -> { |
| | | ContractOutBound bound = contractOutBoundMapper.selectById(outBoundId); |
| | | bound.setInvoiceStatus("1"); |
| | | contractOutBoundMapper.updateById(bound); |
| | | }); |
| | | if (!StrUtil.equals(contract.getContractCategory(),"water_house")) { |
| | | //更新合同出库单状态 |
| | | genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound bound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | bound.setInvoiceStatus("1"); |
| | | bound.setInvoiceNum(bound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(bound); |
| | | }); |
| | | }else { |
| | | //更新合同房租 水电 费开票状态 |
| | | genInvoiceInfoDTO.getOutBoundInvoiceList().stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | schedule.setInvoiceFlag("1"); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | }); |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | |
| | | invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit()); |
| | | invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity()); |
| | | invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity())); |
| | | if (!StrUtil.equals(vo.getContractCategory(),"water_house")) { |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity())); |
| | | }else { |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceAndTax()); |
| | | } |
| | | invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax()); |
| | | |
| | | invoiceDetailsList.add(invoiceDetail); |
| | |
| | | return jsonObject; |
| | | } |
| | | |
| | | private ContractInvoice saveContractInvoice(GenInvoiceInfoVo genInvoiceInfoVo, Contract contract, List<Long> outBoundIds, String serialNo) { |
| | | private ContractInvoice saveContractInvoice(GenInvoiceInfoVo genInvoiceInfoVo, Contract contract, List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList, String serialNo) { |
| | | ContractInvoice invoice = new ContractInvoice(); |
| | | invoice.setContractId(contract.getId()); |
| | | invoice.setInvoiceCategory("1"); |
| | |
| | | invoice.setInvoicePreview(JSONObject.toJSONString(genInvoiceInfoVo)); |
| | | invoice.setInvoiceStatus("1"); |
| | | invoice.setApprovalStatus("0"); |
| | | invoice.setOutBoundId(outBoundIds.stream() |
| | | .map(String::valueOf) // 或者 .map(Object::toString) |
| | | invoice.setOutBoundId(outBoundInvoiceVoList.stream() |
| | | .map(item-> String.valueOf(item.getContractOutBoundId())) // 或者 .map(Object::toString) |
| | | .collect(Collectors.joining(","))); |
| | | invoice.setInvoicePreviewParam(JSONObject.toJSONString(outBoundInvoiceVoList)); |
| | | baseMapper.insert(invoice); |
| | | return invoice; |
| | | } |
| | |
| | | ContractInvoice blueInvoice = baseMapper.selectById(invoiceId); |
| | | blueInvoice.setRedReversal("2"); |
| | | baseMapper.updateById(blueInvoice); |
| | | Contract contract = contractMapper.selectById(blueInvoice.getContractId()); |
| | | ContractInvoice invoice = new ContractInvoice(); |
| | | invoice.setContractId(blueInvoice.getContractId()); |
| | | invoice.setTexNo(blueInvoice.getTexNo()); |
| | |
| | | invoice.setSerialNo(DateUtil.current() + ""); |
| | | invoice.setBlueInvoiceId(invoiceId); |
| | | invoice.setApprovalStatus("0"); |
| | | invoice.setInvoicePreviewParam(blueInvoice.getInvoicePreviewParam()); |
| | | baseMapper.insert(invoice); |
| | | //启动流程 |
| | | ProcessInstanceParamDto dto = new ProcessInstanceParamDto(); |
| | | Map<String, Object> map = BeanUtil.beanToMap(invoice); |
| | | dto.setParamMap(map); |
| | | if (StrUtil.equals(contract.getContractCategory(),"water_house")) { |
| | | map.put("contractCategory","water_house"); |
| | | } |
| | | dto.setParamMap(map); |
| | | dto.setFlowName(FlowNameEnum.销售挂账审批.name()); |
| | | R r1 = remoteFlowProcessService.startProcessInstance(dto); |
| | |
| | | return R.ok(); |
| | | } |
| | | |
| | | private JSONObject genRedInvoice(ContractInvoice blueInvoice, String redConfirmSerialNo) { |
| | | private JSONObject genRedInvoice(Contract contract,ContractInvoice blueInvoice, String redConfirmSerialNo) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("taxNo", blueInvoice.getTexNo()); |
| | | jsonObject.put("redConfirmSerialNo", redConfirmSerialNo); |
| | |
| | | invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit()); |
| | | invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity()); |
| | | invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity())); |
| | | if (!StrUtil.equals(contract.getContractCategory(),"water_house")) { |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getUnitPrice().multiply(invoiceItemVo.getQuantity())); |
| | | }else { |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceAndTax()); |
| | | } |
| | | invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax()); |
| | | |
| | | invoiceDetailsList.add(invoiceDetail); |
| | |
| | | ContractInvoice invoice = baseMapper.selectById(id); |
| | | Contract contract = contractMapper.selectById(invoice.getContractId()); |
| | | GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(invoice.getInvoicePreview()), GenInvoiceInfoVo.class); |
| | | |
| | | vo.setContractCategory(contract.getContractCategory()); |
| | | //蓝票 |
| | | if (invoice.getInvoiceCategory().equals("1")) { |
| | | // TODO 开蓝票接口 |
| | |
| | | invoice.setInvoiceNo(model.getString("invoiceNo")); |
| | | } |
| | | } |
| | | if (!StrUtil.equals(contract.getContractCategory(),"water_house")) { |
| | | //合同状态 |
| | | if (StrUtil.equals(contract.getBillingStatus(), "2")) { |
| | | if (ObjUtil.isNull(contract.getBillingAmout())) { |
| | | contract.setBillingAmout(vo.getTotalPrice()); |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | } |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) < 0) { |
| | | contract.setBillingStatus("1"); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | } else { |
| | | 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.setBillingStatus("1"); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | } |
| | | } else { |
| | | if (ObjUtil.isNull(contract.getBillingAmout())) { |
| | | contract.setBillingAmout(vo.getTotalPrice()); |
| | | contractMapper.updateById(contract); |
| | | } else { |
| | | contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout())); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | } |
| | | }else { |
| | | //判断 循环是否完成 |
| | | List<ContractExecDate> execDateList = contractExecDateMapper.selectList(Wrappers.<ContractExecDate>lambdaQuery().eq(ContractExecDate::getContractId,contract.getId()) |
| | | .eq(ContractExecDate::getGenFlag,"0")); |
| | | List<MeterReadRecord> recordList = meterReadRecordMapper.selectList(Wrappers.<MeterReadRecord>lambdaQuery() |
| | | .eq(MeterReadRecord::getContractId,contract.getId()) |
| | | .isNull(MeterReadRecord::getMeterReadNum)); |
| | | if (ArrayUtil.isEmpty(execDateList.toArray())&&ArrayUtil.isEmpty(recordList.toArray())) { |
| | | //判断是否有可开票记录 |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId,contract.getId()).eq(ContractPaymentSchedule::getInvoiceFlag,"0")); |
| | | if (ArrayUtil.isEmpty(scheduleList.toArray())){ |
| | | contract.setBillingStatus("3"); |
| | | }else { |
| | | contract.setBillingStatus("2"); |
| | | } |
| | | |
| | | //合同状态 |
| | | if (StrUtil.equals(contract.getBillingStatus(), "2")) { |
| | | }else { |
| | | //判断是否有可开票记录 |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId,contract.getId())); |
| | | if (ArrayUtil.isEmpty(scheduleList.toArray())){ |
| | | contract.setBillingStatus("1"); |
| | | }else { |
| | | contract.setBillingStatus("2"); |
| | | } |
| | | } |
| | | if (ObjUtil.isNull(contract.getBillingAmout())) { |
| | | contract.setBillingAmout(vo.getTotalPrice()); |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | } else { |
| | | contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout())); |
| | | if (contract.getBillingAmout().compareTo(contract.getAmount()) == 0) { |
| | | contract.setBillingStatus("3"); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | } |
| | | } else { |
| | | if (ObjUtil.isNull(contract.getBillingAmout())) { |
| | | contract.setBillingAmout(vo.getTotalPrice()); |
| | | contractMapper.updateById(contract); |
| | | } else { |
| | | contract.setBillingAmout(vo.getTotalPrice().add(contract.getBillingAmout())); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | contractMapper.updateById(contract); |
| | | } |
| | | } |
| | | //红票 |
| | | if (invoice.getInvoiceCategory().equals("2")) { |
| | | // TODO 开红票接口 |
| | | ContractInvoice blueInvoice = baseMapper.selectById(invoice.getBlueInvoiceId()); |
| | | JSONObject request = genRedInvoice(blueInvoice, invoice.getSerialNo()); |
| | | JSONObject request = genRedInvoice(contract,blueInvoice, invoice.getSerialNo()); |
| | | String requestId = IdUtil.fastUUID(); |
| | | if (bwFlag) { |
| | | log.info("红字确认单请求接口入参", request.toJSONString()); |
| | |
| | | } |
| | | } |
| | | } |
| | | //更新合同开票状态 |
| | | contract.setBillingAmout(contract.getBillingAmout().subtract(invoice.getInvoiceTotalPriceTax())); |
| | | //更新合同开票状态 前提出库完成 |
| | | contract.setBillingStatus("2"); |
| | | contract.setBillingAmout(contract.getAmount().subtract(invoice.getInvoiceTotalPriceTax())); |
| | | contractMapper.updateById(contract); |
| | | |
| | | //更新合同出库单状态 |
| | | String[] outBoundIds = blueInvoice.getOutBoundId().split(","); |
| | | Arrays.stream(outBoundIds).forEach(outBoundId -> { |
| | | ContractOutBound bound = contractOutBoundMapper.selectById(outBoundId); |
| | | bound.setInvoiceStatus("0"); |
| | | contractOutBoundMapper.updateById(bound); |
| | | }); |
| | | blueInvoice.setRedReversal("1"); |
| | | baseMapper.updateById(blueInvoice); |
| | | if (!StrUtil.equals(contract.getContractCategory(),"water_house")) { |
| | | //更新合同出库单状态 |
| | | List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); |
| | | if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) { |
| | | outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | }); |
| | | } |
| | | }else { |
| | | //更新合同房租 水电 费开票状态 |
| | | List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(blueInvoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); |
| | | if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) { |
| | | outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | schedule.setInvoiceFlag("0"); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | invoice.setApprovalStatus("1"); |
| | | baseMapper.updateById(invoice); |
| | |
| | | @Override |
| | | public void refuseApproval(Long id) { |
| | | ContractInvoice invoice = baseMapper.selectById(id); |
| | | //更新合同出库单状态 |
| | | String[] outBoundIds = invoice.getOutBoundId().split(","); |
| | | Arrays.stream(outBoundIds).forEach(outBoundId -> { |
| | | ContractOutBound bound = contractOutBoundMapper.selectById(outBoundId); |
| | | bound.setInvoiceStatus("0"); |
| | | contractOutBoundMapper.updateById(bound); |
| | | }); |
| | | invoice.setApprovalStatus("2"); |
| | | baseMapper.updateById(invoice); |
| | | Contract contract = contractMapper.selectById(invoice.getContractId()); |
| | | //蓝票 |
| | | if (invoice.getInvoiceCategory().equals("1")) { |
| | | if (!StrUtil.equals(contract.getContractCategory(),"water_house")) { |
| | | //更新合同出库单状态 |
| | | List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(invoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); |
| | | if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) { |
| | | outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | }); |
| | | } |
| | | }else { |
| | | //更新合同房租 水电 费开票状态 |
| | | List<ContractOutBoundInvoiceVo> outBoundInvoiceVoList = BeanUtil.copyToList(JSONArray.parseArray(invoice.getInvoicePreviewParam()), ContractOutBoundInvoiceVo.class); |
| | | if (ArrayUtil.isNotEmpty(outBoundInvoiceVoList.toArray())) { |
| | | outBoundInvoiceVoList.stream().forEach(contractOutBoundInvoiceVo -> { |
| | | ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | schedule.setInvoiceFlag("0"); |
| | | contractPaymentScheduleMapper.updateById(schedule); |
| | | }); |
| | | } |
| | | contract.setBillingStatus("2"); |
| | | contractMapper.updateById(contract); |
| | | } |
| | | } |
| | | //红票 |
| | | if (invoice.getInvoiceCategory().equals("2")) { |
| | | ContractInvoice blueInvoice = baseMapper.selectById(invoice.getBlueInvoiceId()); |
| | | blueInvoice.setRedReversal("0"); |
| | | baseMapper.updateById(blueInvoice); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public Page pageInvoice(Page page, ContractInvoiceQueryDTO queryDTO) { |
| | | return baseMapper.pageInvoice(page,queryDTO, DataScope.of("comp_id")); |
| | | } |
| | | |
| | | @Override |
| | | public Page pageScope(Page page, ContractQueryDTO queryDTO) { |
| | | return baseMapper.pageScope(page,queryDTO, DataScope.of("comp_id")); |
| | | } |
| | | } |