| | |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | @Slf4j |
| | |
| | | |
| | | @Override |
| | | public R genInvoiceInfo(GenInvoiceInfoDTO genInvoiceInfoDTO) { |
| | | if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | if (CollUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | return R.failed("请选择开票出库单后再操作"); |
| | | } |
| | | Long contractId = null; |
| | | //预收款开票 |
| | | if (StrUtil.isNotBlank(genInvoiceInfoDTO.getContractId())) { |
| | | ContractPaymentSchedule schedule = contractPaymentScheduleMapper.selectOne(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getStageName, "合同签订").eq(ContractPaymentSchedule::getContractId,genInvoiceInfoDTO.getContractId()) |
| | |
| | | return R.ok(vo); |
| | | } |
| | | |
| | | //正常产品开票 |
| | | if (!StrUtil.equals(genInvoiceInfoDTO.getContractCategory(), "water_house")) { |
| | | ContractOutBound outBound = contractOutBoundMapper.selectById(genInvoiceInfoDTO.getOutBoundInvoiceList().get(0).getContractOutBoundId()); |
| | | contractId = outBound.getContractId(); |
| | |
| | | return R.failed("获取开票单位异常"); |
| | | } |
| | | SysDept b = r.getData(); |
| | | //机动车开票 |
| | | if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"3")||StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"4")){ |
| | | if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())){ |
| | | return R.failed("机动车开票请输入车架号"); |
| | | } |
| | | BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getInvoiceNum()).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | if (invoiceNumSum.compareTo(new BigDecimal("1"))>0){ |
| | | return R.failed("机动车开票只能1次开1辆"); |
| | | } |
| | | JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(),b); |
| | | R r1 = requestQueryVehicleNo(request); |
| | | if (!r1.isOk()){ |
| | | return r1; |
| | | } |
| | | JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(),b); |
| | | R r2 = requestQueryVehicleDetail(request1); |
| | | if (!r2.isOk()){ |
| | | return r2; |
| | | } |
| | | genInvoiceInfoDTO.setVehicleData(r2.getData().toString()); |
| | | } |
| | | |
| | | GenInvoiceInfoVo vo = genInvoiceInfoVo(genInvoiceInfoDTO, contract, b); |
| | | |
| | | return R.ok(vo); |
| | | } |
| | | |
| | | private R requestQueryVehicleDetail(JSONObject request) { |
| | | String requestId = IdUtil.fastUUID(); |
| | | |
| | | log.info("机动车合格证查询接口入参:{},", request.toJSONString()); |
| | | String result = HttpUtil.post(bwUrl+"method=baiwang.output.invoice.queryVinDetail&version=1.0&request_id=" + requestId, request.toJSONString()); |
| | | log.info("机动车合格证查询接口回参:{},", result); |
| | | saveBwRequestRecord("baiwang.output.invoice.queryVinDetail", requestId, request.toJSONString(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | !resultObj.getBoolean("success")) { |
| | | return R.failed("机动车合格证查询失败",result); |
| | | } |
| | | JSONArray models = resultObj.getJSONArray("model"); |
| | | if (CollUtil.isNotEmpty(models)){ |
| | | JSONObject model = (JSONObject) models.get(0); |
| | | return R.ok(model); |
| | | } |
| | | return R.failed("机动车合格证查询异常"); |
| | | } |
| | | |
| | | private JSONObject genQueryVehDetailParam(String vehicleNo, SysDept b) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("taxNo",b.getOrgCode()); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("vehicleNo", vehicleNo); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | private R requestQueryVehicleNo(JSONObject request) { |
| | | String requestId = IdUtil.fastUUID(); |
| | | |
| | | log.info("查询税局车架号码入参:{},", request.toJSONString()); |
| | | String result = HttpUtil.post(bwUrl+"method=baiwang.output.einvoice.queryvinlist&version=1.0&request_id=" + requestId, request.toJSONString()); |
| | | log.info("查询税局车架号码回参:{},", result); |
| | | saveBwRequestRecord("baiwang.output.einvoice.queryvinlist", requestId, request.toJSONString(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | !resultObj.getBoolean("success")) { |
| | | return R.failed("查询税局车架号码失败",result); |
| | | } |
| | | JSONArray models = resultObj.getJSONArray("model"); |
| | | if (CollUtil.isNotEmpty(models)){ |
| | | JSONObject model = (JSONObject) models.get(0); |
| | | if (!model.getBoolean("isOpenInvoice")){ |
| | | return R.failed(model.getString("isNotOpenInvReason")); |
| | | } |
| | | } |
| | | return R.ok(); |
| | | } |
| | | |
| | | private JSONObject genQueryVinParam(String vehicleNo,SysDept b) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | jsonObject.put("taxNo",b.getOrgCode()); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("vinList", new ArrayList<String>(Arrays.asList(vehicleNo))); |
| | | jsonObject.put("data",data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | private GenInvoiceInfoVo genInvoiceInfoVo(GenInvoiceInfoDTO genInvoiceInfoDTO, Contract contract, SysDept b) { |
| | |
| | | vo.setPartyBOrgCode(b.getOrgCode()); |
| | | vo.setPartyBOpenBank(b.getOrgBank()); |
| | | vo.setPartyBBankAccount(b.getOrgBankAccount()); |
| | | vo.setInvoiceType(a.getInvoiceType()); |
| | | if (StrUtil.isNotBlank(genInvoiceInfoDTO.getInvoiceType())) { |
| | | vo.setInvoiceVehicleType(genInvoiceInfoDTO.getInvoiceType()); |
| | | } |
| | | if (StrUtil.isNotBlank(genInvoiceInfoDTO.getVehicleNo())) { |
| | | vo.setVehicleNo(genInvoiceInfoDTO.getVehicleNo()); |
| | | } |
| | | if (StrUtil.isNotBlank(genInvoiceInfoDTO.getCertificateNo())) { |
| | | vo.setCertificateNo(genInvoiceInfoDTO.getCertificateNo()); |
| | | } |
| | | if (StrUtil.isNotBlank(genInvoiceInfoDTO.getVehicleData())) { |
| | | vo.setVehicleData(genInvoiceInfoDTO.getVehicleData()); |
| | | } |
| | | List<InvoiceItemVo> invoiceItemVoList = new ArrayList<>(); |
| | | List<String> erpCode = new ArrayList<>(); |
| | | List<ContractOutBoundMergeVo> mergeOutBounds = new ArrayList<>(); |
| | |
| | | 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()) |
| | |
| | | if (ObjUtil.isNotNull(subjectMatter)) { |
| | | mergeVo.setUnitPrice(subjectMatter.getUnitPrice()); |
| | | mergeVo.setUnit(subjectMatter.getUnit()); |
| | | 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() + "*" + subjectMatter.getMaterialName()); |
| | | } |
| | | } |
| | | mergeOutBounds.add(mergeVo); |
| | | } else { |
| | |
| | | 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)); |
| | | invoiceItemVo.setPriceAndTax(itemPrice); |
| | | }); |
| | | vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceTax().add(item.getPriceNoTax())).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceAndTax()).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setTotalTax(invoiceItemVoList.stream().map(item -> item.getPriceTax()).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setInvoiceItemList(invoiceItemVoList); |
| | | vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice())); |
| | | } |
| | |
| | | mergeVo.setMaterialCode(schedule.getSubjectMatterCode()); |
| | | mergeVo.setMaterialInternalName(schedule.getSubjectMatterName()); |
| | | mergeVo.setPriceAndTax(schedule.getPlannedAmount()); |
| | | mergeVo.setQuantity(schedule.getInvoiceNum()); |
| | | 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)) { |
| | |
| | | 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 { |
| | |
| | | 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.setTotalTax(invoiceItemVoList.stream().map(item -> item.getPriceTax()).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setInvoiceItemList(invoiceItemVoList); |
| | | vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice())); |
| | | } |
| | |
| | | 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 { |
| | |
| | | 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)); |
| | | invoiceItemVo.setPriceAndTax(itemPrice); |
| | | }); |
| | | vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceTax().add(item.getPriceNoTax())).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setTotalPrice(invoiceItemVoList.stream().map(item -> item.getPriceAndTax()).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setTotalTax(invoiceItemVoList.stream().map(item -> item.getPriceTax()).reduce(BigDecimal.ZERO, BigDecimal::add)); |
| | | vo.setInvoiceItemList(invoiceItemVoList); |
| | | vo.setPriceWords(Convert.digitToChinese(vo.getTotalPrice())); |
| | | } |
| | |
| | | public R toInvoice(GenInvoiceInfoDTO genInvoiceInfoDTO) { |
| | | if (ArrayUtil.isEmpty(genInvoiceInfoDTO.getOutBoundInvoiceList())) { |
| | | return R.failed("请选择开票出库单后再操作"); |
| | | } |
| | | if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"3")||StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"4")){ |
| | | if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())){ |
| | | return R.failed("机动车开票请输入车架号"); |
| | | } |
| | | BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getInvoiceNum()).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | if (invoiceNumSum.compareTo(new BigDecimal("1"))>0){ |
| | | return R.failed("机动车开票只能1次开1辆"); |
| | | } |
| | | } |
| | | Long contractId = null; |
| | | if (StrUtil.isNotBlank(genInvoiceInfoDTO.getContractId())) { |
| | |
| | | return R.failed("获取开票单位异常"); |
| | | } |
| | | SysDept b = r.getData(); |
| | | //机动车开票 |
| | | if (StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"3")||StrUtil.equals(genInvoiceInfoDTO.getInvoiceType(),"4")){ |
| | | if (StrUtil.isBlank(genInvoiceInfoDTO.getVehicleNo())){ |
| | | return R.failed("机动车开票请输入车架号"); |
| | | } |
| | | BigDecimal invoiceNumSum = genInvoiceInfoDTO.getOutBoundInvoiceList().stream().map(item->item.getInvoiceNum()).reduce(BigDecimal.ZERO,BigDecimal::add); |
| | | if (invoiceNumSum.compareTo(new BigDecimal("1"))>0){ |
| | | return R.failed("机动车开票只能1次开1辆"); |
| | | } |
| | | JSONObject request = genQueryVinParam(genInvoiceInfoDTO.getVehicleNo(),b); |
| | | R r1 = requestQueryVehicleNo(request); |
| | | if (!r1.isOk()){ |
| | | return r1; |
| | | } |
| | | JSONObject request1 = genQueryVehDetailParam(genInvoiceInfoDTO.getVehicleNo(),b); |
| | | R r2 = requestQueryVehicleDetail(request1); |
| | | if (!r2.isOk()){ |
| | | return r2; |
| | | } |
| | | genInvoiceInfoDTO.setVehicleData(r2.getData().toString()); |
| | | } |
| | | GenInvoiceInfoVo vo = genInvoiceInfoVo(genInvoiceInfoDTO, contract, b); |
| | | //发票保存 |
| | | ContractInvoice invoice = saveContractInvoice(vo, contract, genInvoiceInfoDTO.getOutBoundInvoiceList(), DateUtil.current() + "","0"); |
| | |
| | | bwRequestRecordMapper.insert(bwRequestRecord); |
| | | } |
| | | |
| | | private JSONObject genBlueInvoice(GenInvoiceInfoVo vo, String serialNo) { |
| | | private JSONObject genBlueInvoice(GenInvoiceInfoVo vo, String serialNo,SysDept dept) { |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //销方 |
| | | jsonObject.put("taxNo", vo.getPartyBOrgCode());//税号 |
| | |
| | | jsonObject.put("formatPushType", false);//版式生成是否推送(true / false) |
| | | //data |
| | | JSONObject data = new JSONObject(); |
| | | data.put("invoiceTypeCode", "01"); |
| | | data.put("invoiceTypeCode", vo.getInvoiceType()); |
| | | data.put("serialNo", serialNo); |
| | | //data.invoiceDetailsList |
| | | JSONArray invoiceDetailsList = new JSONArray(); |
| | |
| | | invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit()); |
| | | invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity()); |
| | | // invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); |
| | | if (StrUtil.equals(vo.getInvoiceVehicleType(),"3")){ |
| | | invoiceDetail.put("goodsSpecification", vo.getVehicleNo()); |
| | | }else { |
| | | invoiceDetail.put("goodsSpecification", invoiceItemVo.getSpecification()); |
| | | } |
| | | |
| | | if (!StrUtil.equals(vo.getContractCategory(), "water_house")) { |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceNoTax()); |
| | | } else { |
| | |
| | | //购方 |
| | | data.put("buyerTaxNo", vo.getPartyAOrgCode()); |
| | | data.put("buyerName", vo.getPartyA()); |
| | | data.put("drawer", SecurityUtils.getUser().getPhone());// TODO 税务总局系统登陆人手机号 |
| | | data.put("drawer", dept.getInvoiceContact());// TODO 税务总局系统登陆人手机号 |
| | | data.put("invoiceTotalPriceTax", vo.getTotalPrice()); |
| | | data.put("buyerBankName", vo.getPartyAOpenBank()); |
| | | data.put("buyerBankNumber", vo.getPartyABankAccount()); |
| | |
| | | jsonObject.put("sellerTaxName", blueInvoice.getSellerTaxName()); |
| | | jsonObject.put("buyerTaxName", blueInvoice.getBuyerTaxName()); |
| | | jsonObject.put("buyerTaxNo", blueInvoice.getBuyerTaxNo()); |
| | | jsonObject.put("originInvoiceDate", blueInvoice.getInvoiceTime()); |
| | | jsonObject.put("originInvoiceDate", DateUtil.formatDateTime(blueInvoice.getInvoiceTime())); |
| | | jsonObject.put("originInvoiceTotalPrice", blueInvoice.getInvoiceTotalPrice()); |
| | | jsonObject.put("originInvoiceTotalTax", blueInvoice.getInvoiceTotalTax()); |
| | | jsonObject.put("invoiceTotalPrice", blueInvoice.getInvoiceTotalPrice().multiply(new BigDecimal("-1"))); |
| | |
| | | @Override |
| | | public void takeEffect(Long id) { |
| | | ContractInvoice invoice = baseMapper.selectById(id); |
| | | R<SysDept> r = remoteDeptService.getById(SecurityUtils.getUser().getCompId()); |
| | | if (!r.isOk()){ |
| | | log.error("单位信息查询异常"); |
| | | return; |
| | | } |
| | | SysDept dept = r.getData(); |
| | | Contract contract = contractMapper.selectById(invoice.getContractId()); |
| | | GenInvoiceInfoVo vo = BeanUtil.copyProperties(JSONObject.parseObject(invoice.getInvoicePreview()), GenInvoiceInfoVo.class); |
| | | vo.setContractCategory(contract.getContractCategory()); |
| | | invoice.setApprovalStatus("1"); |
| | | baseMapper.updateById(invoice); |
| | | invoice.setBwRequestResult("0"); |
| | | |
| | | //蓝票 |
| | | if (invoice.getInvoiceCategory().equals("1")) { |
| | | // TODO 开蓝票接口 |
| | | JSONObject request = genBlueInvoice(vo, invoice.getSerialNo()); |
| | | // TODO 开蓝票接口机动车 |
| | | if (StrUtil.equals(vo.getInvoiceVehicleType(),"3")){ |
| | | JSONObject request = genBlueInvoiceVehicle(vo, invoice.getSerialNo(),dept); |
| | | String requestId = IdUtil.fastUUID(); |
| | | invoice.setBwRequestId(requestId); |
| | | invoice.setBwRequestParam(request.toJSONString()); |
| | | log.info("机动车发票开具请求接口入参:{}", request.toJSONString()); |
| | | String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.vehicleissue&version=1.0&requestId=" + requestId, request.toJSONString()); |
| | | log.info("机动车发票开具请求接口回参:{}", result); |
| | | saveBwRequestRecord("baiwang.output.invoice.vehicleissue", requestId, request.toJSONString(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | resultObj.getBoolean("success")) { |
| | | log.info("开票成功!!!"); |
| | | invoice.setBwRequestResult("1"); |
| | | } |
| | | JSONObject modelJson = resultObj.getJSONObject("model"); |
| | | if (ObjUtil.isNotNull(modelJson)) { |
| | | Date invoiceDate = DateUtil.parse(modelJson.getString("invoiceDate"), DatePattern.PURE_DATETIME_PATTERN); |
| | | invoice.setInvoiceTime(invoiceDate); |
| | | invoice.setInvoiceNo(modelJson.getString("invoiceNo")); |
| | | //推送BIP |
| | | pushBipInvoice(invoice); |
| | | } |
| | | } |
| | | |
| | | // TODO 开蓝票接口 非机动车 |
| | | JSONObject request = genBlueInvoice(vo, invoice.getSerialNo(),dept); |
| | | if (bwFlag) { |
| | | String requestId = IdUtil.fastUUID(); |
| | | invoice.setBwRequestId(requestId); |
| | | invoice.setBwRequestResult("1"); |
| | | invoice.setBwRequestParam(request.toJSONString()); |
| | | log.info("蓝票请求接口入参:{}", request.toJSONString()); |
| | | String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.issue&version=1.0&requestId=" + requestId, request.toJSONString()); |
| | |
| | | //判断 循环是否完成 |
| | | 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) && ArrayUtil.isEmpty(recordList)) { |
| | | if (CollUtil.isEmpty(execDateList)) { |
| | | //判断是否有可开票记录 |
| | | List<ContractPaymentSchedule> scheduleList = contractPaymentScheduleMapper.selectList(Wrappers.<ContractPaymentSchedule>lambdaQuery() |
| | | .eq(ContractPaymentSchedule::getContractId, contract.getId()).eq(ContractPaymentSchedule::getInvoiceFlag, "0")); |
| | |
| | | |
| | | } |
| | | |
| | | private JSONObject genBlueInvoiceVehicle(GenInvoiceInfoVo vo, String serialNo,SysDept dept) { |
| | | JSONObject vechicleData = JSONObject.parseObject(vo.getVehicleData()); |
| | | JSONObject jsonObject = new JSONObject(); |
| | | //销方 |
| | | jsonObject.put("taxNo", vo.getPartyBOrgCode());//税号 |
| | | jsonObject.put("invoiceTerminalCode", "JDCwxj");//超过发票单张限额是否需要拆分开具,默认不拆分(拆分只支持发票类型代码为 专票 004 普票 007 电子票 026的 |
| | | jsonObject.put("formatGenerate", false);//是否需要生成版式返回版式链接(true / false) |
| | | jsonObject.put("formatPushType", false);//版式生成是否推送(true / false) |
| | | jsonObject.put("taxUserName", dept.getInvoiceContact()); |
| | | //data |
| | | JSONObject data = new JSONObject(); |
| | | data.put("invoiceTypeCode", "03"); |
| | | data.put("invoiceType", "0"); |
| | | data.put("serialNo", serialNo); |
| | | //data.invoiceDetailsList |
| | | Integer lineNo = 1; |
| | | JSONObject invoiceDetail = new JSONObject(); |
| | | |
| | | invoiceDetail.put("vehicleNo", vo.getVehicleNo()); |
| | | invoiceDetail.put("manufacturingEnterprise","03"); |
| | | invoiceDetail.put("originPlace", vechicleData.getString("originPlace")); |
| | | invoiceDetail.put("certificateNo",vo.getCertificateNo()); |
| | | invoiceDetail.put("engineNo",vechicleData.getString("engineNo")); |
| | | invoiceDetail.put("tonnage",vechicleData.getString("tonnage")); |
| | | invoiceDetail.put("passengersLimited",vechicleData.getString("passengersLimited")); |
| | | invoiceDetail.put("brandModel",vechicleData.getString("brandModel")); |
| | | |
| | | invoiceDetail.put("goodsCode", vo.getInvoiceItemList().get(0).getTaxCode()); |
| | | invoiceDetail.put("goodsTaxRate", vo.getInvoiceItemList().get(0).getTaxRate().divide(new BigDecimal("100"))); |
| | | if (!StrUtil.equals(vo.getContractCategory(), "water_house")) { |
| | | invoiceDetail.put("goodsTotalPrice", vo.getInvoiceItemList().get(0).getPriceNoTax()); |
| | | } else { |
| | | invoiceDetail.put("goodsTotalPrice", vo.getInvoiceItemList().get(0).getPriceNoTax()); |
| | | } |
| | | invoiceDetail.put("goodsTotalTax", vo.getInvoiceItemList().get(0).getPriceTax()); |
| | | data.put("invoiceVehicleInfo", invoiceDetail); |
| | | //购方 |
| | | data.put("buyerTaxNo", vo.getPartyAOrgCode()); |
| | | data.put("buyerName", vo.getPartyA()); |
| | | data.put("sellerTaxNo", vo.getPartyBOrgCode());// TODO 税务总局系统登陆人手机号 |
| | | data.put("invoiceTotalPrice", vo.getTotalPrice().subtract(vo.getTotalTax())); |
| | | data.put("invoiceTotalPriceTax", vo.getTotalPrice()); |
| | | data.put("invoiceTotalTax", vo.getTotalTax()); |
| | | data.put("buyerBankName", vo.getPartyAOpenBank()); |
| | | data.put("buyerBankNumber", vo.getPartyABankAccount()); |
| | | |
| | | jsonObject.put("data", data); |
| | | return jsonObject; |
| | | } |
| | | |
| | | @Override |
| | | public void refuseApproval(Long id) { |
| | | ContractInvoice invoice = baseMapper.selectById(id); |
| | |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | !resultObj.getBoolean("success")) { |
| | | log.error("红字确认单成功!!!"); |
| | | log.error("红字确认单失败!!!"); |
| | | |
| | | return R.failed(resultObj.getString("message")); |
| | | } |