| | |
| | | ContractOutBound contractOutBound = contractOutBoundMapper.selectById(contractOutBoundInvoiceVo.getContractOutBoundId()); |
| | | contractOutBound.setInvoiceStatus("1"); |
| | | if (contractOutBoundInvoiceVo.getInvoiceNum().compareTo(contractOutBound.getOutBoundNum().subtract(contractOutBound.getInvoiceNum())) <= 0) { |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().subtract(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | contractOutBound.setInvoiceNum(contractOutBound.getInvoiceNum().add(contractOutBoundInvoiceVo.getInvoiceNum())); |
| | | } |
| | | contractOutBoundMapper.updateById(contractOutBound); |
| | | }); |
| | |
| | | JSONObject invoiceDetail = new JSONObject(); |
| | | |
| | | invoiceDetail.put("goodsLineNo", lineNo); |
| | | invoiceDetail.put("goodsName", invoiceItemVo.getItemName()); |
| | | invoiceDetail.put("projectName", invoiceItemVo.getItemName()); |
| | | invoiceDetail.put("goodsCode", invoiceItemVo.getTaxCode()); |
| | | invoiceDetail.put("goodsTaxRate", invoiceItemVo.getTaxRate().divide(new BigDecimal("100"))); |
| | | invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit()); |
| | | invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity()); |
| | | invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); |
| | | // invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); |
| | | if (!StrUtil.equals(vo.getContractCategory(), "water_house")) { |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceNoTax()); |
| | | } else { |
| | |
| | | invoiceDetailsList.add(invoiceDetail); |
| | | lineNo++; |
| | | } |
| | | jsonObject.put("invoiceDetailsList", invoiceDetailsList); |
| | | data.put("invoiceDetailsList", invoiceDetailsList); |
| | | //购方 |
| | | data.put("buyerTaxNo", vo.getPartyAOrgCode()); |
| | | data.put("buyerName", vo.getPartyA()); |
| | |
| | | invoiceDetail.put("goodsTaxRate", invoiceItemVo.getTaxRate().divide(new BigDecimal("100"))); |
| | | invoiceDetail.put("goodsUnit", invoiceItemVo.getUnit()); |
| | | invoiceDetail.put("goodsQuantity", invoiceItemVo.getQuantity()); |
| | | invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); |
| | | // invoiceDetail.put("goodsPrice", invoiceItemVo.getUnitPrice()); |
| | | invoiceDetail.put("goodsTotalPrice", invoiceItemVo.getPriceNoTax().multiply(new BigDecimal("-1"))); |
| | | invoiceDetail.put("goodsTotalTax", invoiceItemVo.getPriceTax().multiply(new BigDecimal("-1"))); |
| | | invoiceDetailsList.add(invoiceDetail); |
| | |
| | | public R queryBlueInvoice() { |
| | | if (bwFlag) { |
| | | List<ContractInvoice> contractInvoices = baseMapper.selectList(Wrappers.<ContractInvoice>lambdaQuery() |
| | | .eq(ContractInvoice::getInvoiceCategory, "1").eq(ContractInvoice::getInvoiceStatus, "1")); |
| | | .eq(ContractInvoice::getApprovalStatus, "1") |
| | | .eq(ContractInvoice::getBwRequestResult,"1") |
| | | .isNull(ContractInvoice::getInvoicePath)); |
| | | if (ArrayUtil.isNotEmpty(contractInvoices)) { |
| | | contractInvoices.stream().forEach(contractInvoice -> { |
| | | JSONObject request = new JSONObject(); |
| | | request.put("taxNo", contractInvoice.getTaxNo()); |
| | | JSONObject data = new JSONObject(); |
| | | data.put("taxNo", contractInvoice.getSerialNo()); |
| | | data.put("serialNo", contractInvoice.getSerialNo()); |
| | | data.put("returnType", "3"); |
| | | data.put("invoiceIssueMode", "1"); |
| | | request.put("data",data); |
| | | String requestId = IdUtil.fastUUID(); |
| | | |
| | | log.info("serial_no:{},发票查询入参:{},", contractInvoice.getSerialNo(), request.toJSONString()); |
| | | String result = HttpUtil.post("method=baiwang.output.format.query&version=1.0&request_id=" + requestId, request.toJSONString()); |
| | | String result = HttpUtil.post(bwUrl+"method=baiwang.output.format.query&version=1.0&request_id=" + requestId, request.toJSONString()); |
| | | log.info("serial_no:{},发票查询回参:{},", contractInvoice.getSerialNo(), result); |
| | | saveBwRequestRecord("baiwang.output.format.query", requestId, request.toJSONString(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | |
| | | contractInvoice.setInvoiceStatus("2"); |
| | | baseMapper.updateById(contractInvoice); |
| | | } |
| | | //推送BIP |
| | | pushBipInvoice(contractInvoice); |
| | | }); |
| | | } |
| | | } |
| | |
| | | JSONObject params = genBlueReceiveParams(contractInvoice, contract, customer, dept); |
| | | String finalAccessToken = accessToken; |
| | | |
| | | log.info("XSJZ_YS_DJ_INSERT Request:{}", params.toJSONString()); |
| | | log.info("应收发票集成入参:{}", params.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/receivable/save?access_token=" + finalAccessToken, params.toJSONString()); |
| | | log.info("XSJZ_YS_DJ_INSERT Response:{}", result); |
| | | log.info("应收发票集成回参:{}", result); |
| | | //保存请求记录 |
| | | paymentConfirmService.saveBipRequestRecord(params, "< XSJZ_YS_DJ_001>-应收发票保存接口", result); |
| | | paymentConfirmService.saveBipRequestRecord(params, "应收发票集成接口", result); |
| | | JSONObject resultJson = JSONObject.parseObject(result); |
| | | if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) { |
| | | JSONObject data = resultJson.getJSONObject("data"); |
| | |
| | | JSONObject params = genRedReceiveParams(contractInvoice); |
| | | String finalAccessToken = accessToken; |
| | | |
| | | log.info("XSJZ_YS_DJ_DELETE Request:", params.toJSONString()); |
| | | log.info("应收发票删除入参:{}", params.toJSONString()); |
| | | String result = HttpUtil.post(url + "/yonbip/EFI/receivable/delete?access_token=" + finalAccessToken, params.toJSONString()); |
| | | log.info("XSJZ_YS_DJ_DELETE Response:{}", result); |
| | | log.info("应收发票删除回参:{}", result); |
| | | //保存请求记录 |
| | | paymentConfirmService.saveBipRequestRecord(params, "< XSJZ_YS_DJ_002>-应收发票删除接口", result); |
| | | paymentConfirmService.saveBipRequestRecord(params, "应收发票删除接口", result); |
| | | JSONObject resultJson = JSONObject.parseObject(result); |
| | | if (resultJson.containsKey("code") && resultJson.getString("code").equals("200")) { |
| | | contractInvoice.setBipPush("1"); |
| | |
| | | vo.setContractCategory(contract.getContractCategory()); |
| | | invoice.setApprovalStatus("1"); |
| | | baseMapper.updateById(invoice); |
| | | invoice.setBwRequestResult("0"); |
| | | //蓝票 |
| | | if (invoice.getInvoiceCategory().equals("1")) { |
| | | // TODO 开蓝票接口 |
| | |
| | | if (bwFlag) { |
| | | String requestId = IdUtil.fastUUID(); |
| | | invoice.setBwRequestId(requestId); |
| | | log.info("蓝票请求接口入参", request.toJSONString()); |
| | | 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()); |
| | | log.info("蓝票请求接口回参", result); |
| | | log.info("蓝票请求接口回参:{}", result); |
| | | saveBwRequestRecord("baiwang.output.invoice.issue", requestId, request.toJSONString(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | !resultObj.getBoolean("success")) { |
| | | log.error("开票失败!!!"); |
| | | return; |
| | | resultObj.getBoolean("success")) { |
| | | log.info("开票成功!!!"); |
| | | invoice.setBwRequestResult("1"); |
| | | } |
| | | JSONObject modelJson = resultObj.getJSONObject("model"); |
| | | if (ObjUtil.isNotNull(modelJson)) { |
| | | JSONArray models = modelJson.getJSONArray("success"); |
| | | if (ArrayUtil.isNotEmpty(models)) { |
| | | if (CollUtil.isNotEmpty(models)) { |
| | | JSONObject model = (JSONObject) models.get(0); |
| | | Date invoiceDate = DateUtil.parse(model.getString("invoiceDate"), DatePattern.PURE_DATETIME_PATTERN); |
| | | invoice.setInvoiceTime(invoiceDate); |
| | | invoice.setInvoiceNo(model.getString("invoiceNo")); |
| | | //推送BIP |
| | | pushBipInvoice(invoice); |
| | | } |
| | | } |
| | | } |
| | | if (StrUtil.isNotBlank(vo.getAdvanceInvoice())){ |
| | |
| | | } |
| | | 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) { |
| | |
| | | } |
| | | contractMapper.updateById(contract); |
| | | } |
| | | baseMapper.updateById(invoice); |
| | | } |
| | | //红票 |
| | | if (invoice.getInvoiceCategory().equals("2")) { |
| | |
| | | JSONObject request = genRedInvoice(contract, blueInvoice, invoice.getSerialNo()); |
| | | String requestId = IdUtil.fastUUID(); |
| | | invoice.setBwRequestId(requestId); |
| | | invoice.setBwRequestParam(request.toJSONString()); |
| | | if (bwFlag) { |
| | | log.info("红字确认单请求接口入参:{}", request.toJSONString()); |
| | | String result = HttpUtil.post(bwUrl + "method=baiwang.output.redinvoice.add&version=1.0&requestId=" + requestId, request.toJSONString()); |
| | |
| | | saveBwRequestRecord("baiwang.output.redinvoice.add", requestId, request.toJSONString(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | !resultObj.getBoolean("success")) { |
| | | log.error("红字确认单失败!!!"); |
| | | return; |
| | | resultObj.getBoolean("success")) { |
| | | log.info("红字确认单成功!!!"); |
| | | invoice.setBwRequestResult("1"); |
| | | |
| | | } |
| | | JSONArray models = resultObj.getJSONArray("model"); |
| | | if (ArrayUtil.isNotEmpty(models)) { |
| | | if (CollUtil.isNotEmpty(models)) { |
| | | JSONObject model = (JSONObject) models.get(0); |
| | | |
| | | if (StrUtil.isEmpty(model.getString("confirmBillingMark")) || StrUtil.equals(model.getString("confirmBillingMark"), "N")) { |
| | |
| | | } |
| | | } |
| | | } |
| | | baseMapper.updateById(invoice); |
| | | contract.setBillingAmout(contract.getBillingAmout().subtract(invoice.getInvoiceTotalPriceTax())); |
| | | //防止重复审开票审核通过后 开票金额为负 |
| | | if (contract.getBillingAmout().compareTo(new BigDecimal("0")) < 0) { |
| | |
| | | public Page pageScope(Page page, ContractQueryDTO queryDTO) { |
| | | return baseMapper.pageScope(page, queryDTO, DataScope.of("comp_id")); |
| | | } |
| | | |
| | | @Override |
| | | public R refresh(Long invoiceId) { |
| | | ContractInvoice invoice = baseMapper.selectById(invoiceId); |
| | | //蓝票 |
| | | if (invoice.getInvoiceCategory().equals("1")) { |
| | | // TODO 开蓝票接口 |
| | | if (bwFlag) { |
| | | String requestId = IdUtil.fastUUID(); |
| | | invoice.setBwRequestId(requestId); |
| | | invoice.setBwRequestResult("1"); |
| | | invoice.setBwRequestParam(invoice.getBwRequestParam()); |
| | | log.info("蓝票请求接口入参:{}", invoice.getBwRequestParam()); |
| | | String result = HttpUtil.post(bwUrl + "method=baiwang.output.invoice.issue&version=1.0&requestId=" + requestId, invoice.getBwRequestParam()); |
| | | log.info("蓝票请求接口回参:{}", result); |
| | | saveBwRequestRecord("baiwang.output.invoice.issue", requestId, invoice.getBwRequestParam(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | !resultObj.getBoolean("success")) { |
| | | log.error("开票失败!!!"); |
| | | return R.failed(resultObj.getString("message")); |
| | | } |
| | | invoice.setBwRequestResult("1"); |
| | | JSONObject modelJson = resultObj.getJSONObject("model"); |
| | | JSONArray models = modelJson.getJSONArray("success"); |
| | | if (CollUtil.isNotEmpty(models)) { |
| | | JSONObject model = (JSONObject) models.get(0); |
| | | Date invoiceDate = DateUtil.parse(model.getString("invoiceDate"), DatePattern.PURE_DATETIME_PATTERN); |
| | | invoice.setInvoiceTime(invoiceDate); |
| | | invoice.setInvoiceNo(model.getString("invoiceNo")); |
| | | //推送BIP |
| | | pushBipInvoice(invoice); |
| | | } |
| | | } |
| | | } |
| | | //红票 |
| | | if (invoice.getInvoiceCategory().equals("2")) { |
| | | // TODO 开红票接口 |
| | | String requestId = IdUtil.fastUUID(); |
| | | invoice.setBwRequestId(requestId); |
| | | invoice.setBwRequestParam(invoice.getBwRequestParam()); |
| | | if (bwFlag) { |
| | | log.info("红字确认单请求接口入参:{}", invoice.getBwRequestParam()); |
| | | String result = HttpUtil.post(bwUrl + "method=baiwang.output.redinvoice.add&version=1.0&requestId=" + requestId, invoice.getBwRequestParam()); |
| | | log.info("红字确认单请求接口回参:{}", result); |
| | | saveBwRequestRecord("baiwang.output.redinvoice.add", requestId, invoice.getBwRequestParam(), result); |
| | | JSONObject resultObj = JSONObject.parseObject(result); |
| | | if (resultObj.containsKey("requestId") && StrUtil.equals(resultObj.getString("requestId"), requestId) && |
| | | !resultObj.getBoolean("success")) { |
| | | log.error("红字确认单成功!!!"); |
| | | |
| | | return R.failed(resultObj.getString("message")); |
| | | } |
| | | invoice.setBwRequestResult("1"); |
| | | JSONArray models = resultObj.getJSONArray("model"); |
| | | if (ArrayUtil.isNotEmpty(models)) { |
| | | JSONObject model = (JSONObject) models.get(0); |
| | | if (StrUtil.isEmpty(model.getString("confirmBillingMark")) || StrUtil.equals(model.getString("confirmBillingMark"), "N")) { |
| | | //等待确认 |
| | | invoice.setRedReversal("3"); |
| | | } else if (StrUtil.equals(model.getString("confirmBillingMark"), "Y")) { |
| | | //确认即开 |
| | | invoice.setInvoiceNo(model.getString("redInvoiceNo")); |
| | | invoice.setRedReversal("1"); |
| | | //推送BIP |
| | | pushBipInvoice(invoice); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | baseMapper.updateById(invoice); |
| | | return R.ok(); |
| | | } |
| | | } |