| | |
| | | |
| | | import cn.hutool.core.bean.BeanUtil; |
| | | import cn.hutool.core.collection.CollUtil; |
| | | import cn.hutool.core.date.DateTime; |
| | | import cn.hutool.core.util.ArrayUtil; |
| | | import cn.hutool.core.util.StrUtil; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | |
| | | import com.by4cloud.platformx.admin.api.entity.SysDept; |
| | | import com.by4cloud.platformx.admin.api.feign.RemoteDeptService; |
| | | import com.by4cloud.platformx.business.entity.*; |
| | | import com.by4cloud.platformx.business.entity.invoice.vo.BipResVo; |
| | | import com.by4cloud.platformx.business.entity.invoice.vo.InvoicingVo; |
| | | import com.by4cloud.platformx.business.invoice.service.BIPYsService; |
| | | import com.by4cloud.platformx.business.service.*; |
| | | import com.by4cloud.platformx.business.vo.ContractOutBoundVo; |
| | | import com.by4cloud.platformx.common.core.util.R; |
| | | import com.by4cloud.platformx.common.data.mybatis.BaseModel; |
| | | import com.by4cloud.platformx.common.excel.annotation.ResponseExcel; |
| | | import com.by4cloud.platformx.common.log.annotation.SysLog; |
| | | import com.by4cloud.platformx.common.security.annotation.Inner; |
| | |
| | | import org.springframework.security.access.prepost.PreAuthorize; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.math.BigDecimal; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * 销售挂账 |
| | |
| | | private final ContractSubjectMatterService contractSubjectMatterService; |
| | | private final RemoteDeptService remoteDeptService; |
| | | |
| | | |
| | | private final InvoiceService invoiceService; |
| | | private final BIPYsService bipYsService; |
| | | |
| | | |
| | | /** |
| | |
| | | if(contractOutBoundList.size()==0){ |
| | | return R.failed("请选择出库单!"); |
| | | } |
| | | //开票之前,先记录开票信息 |
| | | //1.出库单进行标记,将出库单发票记录id填入。将InvoiceSatus=1开票中。 |
| | | String outBoundIds = ""; |
| | | for(ContractOutBoundVo vo : contractOutBoundList){ |
| | | if(StrUtil.isEmpty(outBoundIds)){ |
| | |
| | | outBound.setInvoiceSatus(1); |
| | | contractOutBoundService.updateById(outBound); |
| | | } |
| | | //结算中记录出库单ids. |
| | | saleCredit.setOutBoundIds(outBoundIds); |
| | | saleCreditService.save(saleCredit); |
| | | //生成结算单号 |
| | | saleCredit.setEntrustCode("JsNo"+System.currentTimeMillis()); |
| | | saleCreditService.updateById(saleCredit); |
| | | |
| | | return R.ok("销售挂账生成!"); |
| | | //生成vo |
| | | /* InvoicingVo invoicingVo = invoiceService.toGetByCompareByVo(saleCredit,contractOutBoundList); |
| | | try { |
| | | Map<String, Object> objectMap = invoiceService.toKaipiao(invoicingVo); |
| | | Boolean success = (Boolean) objectMap.get("success"); |
| | | String message = (String) objectMap.get("message"); |
| | | //System.out.println(saleCredit.getEntrustCode() + "的railwayEntrust蓝字开票结果为:" + success + "------" + message); |
| | | if(success){ |
| | | saleCredit.setBlueResultStatus(1); |
| | | saleCreditService.updateById(saleCredit); |
| | | //StringBuffer errMsg = new StringBuffer(); |
| | | BipResVo bipResVo = bipYsService.sendBIPYs(saleCredit); |
| | | if (!bipResVo.getCode().equals("200")) { |
| | | *//*if (StrUtil.isNotEmpty(errMsg)) { |
| | | errMsg.append(","); |
| | | } |
| | | errMsg.append(saleCredit.getCreditCodeB()+ "应收发票推送失败:" + bipResVo.getMessage());*//* |
| | | return R.failed("开票成功,推送bip失败,err:" + bipResVo.getMessage()); |
| | | }else{ |
| | | return R.ok("开票成功,推送big成功!"); |
| | | } |
| | | }else{ |
| | | saleCredit.setStatus(2); |
| | | saleCreditService.updateById(saleCredit); |
| | | return R.failed("开票失败!原因:" + message); |
| | | } |
| | | |
| | | }catch (Exception e){ |
| | | saleCredit.setStatus(3); |
| | | saleCreditService.updateById(saleCredit); |
| | | return R.failed("开票失败!"); |
| | | }*/ |
| | | //return R.ok("销售挂账生成!"); |
| | | |
| | | |
| | | //出库单已开票 |
| | | List<ContractOutBound> contractOutBounds = contractOutBoundService.list(new LambdaQueryWrapper<ContractOutBound>() |
| | | .eq(ContractOutBound::getSaleCreditId,saleCredit.getId()) |
| | | ); |
| | | for(ContractOutBound contractOutBound : contractOutBounds){ |
| | | contractOutBound.setInvoiceSatus(2); |
| | | } |
| | | contractOutBoundService.updateBatchById(contractOutBounds); |
| | | |
| | | //开票成功 |
| | | //开票记录单蓝票信息存储 |
| | | saleCredit.setBlueResultStatus(1); |
| | | saleCredit.setInvoiceRemark("开票成功!"); |
| | | saleCredit.setBlueInvoiceTime(DateTime.now()); |
| | | saleCreditService.updateById(saleCredit); |
| | | |
| | | //相关合同金额和开票状态进行修改。 |
| | | Contract contract = contractService.getById(saleCredit.getContractId()); |
| | | String billingStatus = contract.getBillingStatus(); |
| | | |
| | | if(contract.getBillingAmout()==null){ |
| | | contract.setBillingAmout(saleCredit.getTotalAmount()); |
| | | }else{ |
| | | contract.setBillingAmout(contract.getBillingAmout().add(saleCredit.getTotalAmount())); |
| | | } |
| | | |
| | | int res = contract.getAmount().compareTo(contract.getBillingAmout()); |
| | | |
| | | if("2".equals(billingStatus)) { |
| | | if (res == 0) { |
| | | contract.setBillingStatus("3"); |
| | | } else if (res > 0) { |
| | | contract.setBillingStatus("2"); |
| | | } else { |
| | | return R.failed("已付金额不能大于总金额!"); |
| | | } |
| | | } |
| | | |
| | | contractService.updateById(contract); |
| | | return R.ok("开票成功,推送bip成功!"); |
| | | } |
| | | |
| | | /** |
| | | * 拼接销售挂账 |
| | | * @param contract1 销售挂账 |
| | | * @return R |
| | | */ |
| | | @Operation(summary = "获取发票列表" , description = "获取发票列表" ) |
| | | @SysLog("获取发票列表" ) |
| | | @GetMapping("/getInvoices") |
| | | @PreAuthorize("@pms.hasPermission('business_saleCredit_view')" ) |
| | | public R getInvoices(@ParameterObject Contract contract1) { |
| | | Contract contract = contractService.getById(contract1.getId()); |
| | | if(contract==null){ |
| | | return R.failed("合同id错误"); |
| | | } |
| | | List<SaleCredit> saleCredits = saleCreditService.list(new LambdaQueryWrapper<SaleCredit>() |
| | | .eq(SaleCredit::getContractId,contract1.getId()) |
| | | .orderByAsc(BaseModel::getCreateTime) |
| | | ); |
| | | for(SaleCredit saleCredit : saleCredits){ |
| | | if(saleCredit.getRedResultStatus()!=null && saleCredit.getRedResultStatus()>0){//说明已开红票 |
| | | saleCredit.setBlueResultStatus(0); |
| | | if(saleCredit.getRedResultStatus()==1){ |
| | | saleCredit.setInvoiceRemark("开红票成功!"); |
| | | saleCredit.setInvoicRedUrl("红票url"); |
| | | }else{ |
| | | //显示 saleCredit.getInvoiceRemark(); |
| | | } |
| | | }else{ |
| | | if(saleCredit.getBlueResultStatus()==1){ |
| | | saleCredit.setInvoiceRemark("开蓝票成功!"); |
| | | saleCredit.setInvoicUrl("蓝票url"); |
| | | }else if(saleCredit.getBlueResultStatus()==2){ |
| | | //显示 saleCredit.getInvoiceRemark(); |
| | | } |
| | | } |
| | | } |
| | | return R.ok(saleCredits); |
| | | } |
| | | |
| | | /** |
| | | * 拼接销售挂账 |
| | | * @param saleCredit1 销售挂账 |
| | | * @return R |
| | | */ |
| | | @Operation(summary = "红冲发票" , description = "红冲发票" ) |
| | | @SysLog("红冲发票" ) |
| | | @PostMapping("/toRedStamp") |
| | | @PreAuthorize("@pms.hasPermission('business_saleCredit_edit')" ) |
| | | public R toRedStamp(@RequestBody SaleCredit saleCredit1) { |
| | | if(saleCredit1.getId()==null){ |
| | | return R.failed("销售挂账id不能为空!"); |
| | | } |
| | | SaleCredit saleCredit = saleCreditService.getById(saleCredit1.getId()); |
| | | if(saleCredit==null){ |
| | | return R.failed("销售挂账id不能为空!"); |
| | | } |
| | | |
| | | /*try { |
| | | Map<String, Object> map = invoiceService.toRedTicket(saleCredit); |
| | | Boolean success = (Boolean) map.get("success"); |
| | | if(success){ |
| | | return R.ok("红字开票成功"); |
| | | }else { |
| | | return R.failed((String) map.get("message")); |
| | | } |
| | | }catch (Exception e){ |
| | | e.printStackTrace(); |
| | | return R.failed("红字开票失败"); |
| | | }*/ |
| | | |
| | | |
| | | //出库单恢复到未开票状态 |
| | | List<ContractOutBound> outBoundList = contractOutBoundService.list(new LambdaQueryWrapper<ContractOutBound>() |
| | | .eq(ContractOutBound::getSaleCreditId,saleCredit.getId()) |
| | | ); |
| | | for(ContractOutBound outBound : outBoundList){ |
| | | outBound.setInvoiceSatus(0); |
| | | outBound.setSaleCreditId(0l); |
| | | } |
| | | contractOutBoundService.updateBatchById(outBoundList); |
| | | |
| | | saleCredit.setRedInvoiceTime(DateTime.now()); |
| | | saleCredit.setRedResultStatus(1); |
| | | saleCredit.setInvoiceRemark("开红票成功!"); |
| | | saleCreditService.updateById(saleCredit); |
| | | |
| | | |
| | | //合同已开票金额和状态还原 |
| | | Contract contract = contractService.getById(saleCredit.getContractId()); |
| | | String billingStatus = contract.getBillingStatus(); |
| | | BigDecimal bill = contract.getBillingAmout() == null ? BigDecimal.ZERO : contract.getBillingAmout(); |
| | | BigDecimal credit = saleCredit.getTotalAmount() == null ? BigDecimal.ZERO : saleCredit.getTotalAmount(); |
| | | BigDecimal diff = bill.subtract(credit); |
| | | int res = diff.compareTo(BigDecimal.ZERO); |
| | | |
| | | if("3".equals(billingStatus)){ |
| | | if(res>=0){ |
| | | contract.setBillingStatus("2"); |
| | | contract.setBillingAmout(BigDecimal.ZERO); |
| | | }else{ |
| | | return R.failed("已开票金额负数报错!"); |
| | | } |
| | | } |
| | | contractService.updateById(contract); |
| | | return R.ok("红冲开票成功!"); |
| | | } |
| | | |
| | | |
| | | |
| | |
| | | @SysLog("拼接销售挂账" ) |
| | | @GetMapping("/generatorInvoice") |
| | | @PreAuthorize("@pms.hasPermission('business_saleCredit_view')" ) |
| | | @Inner(value = false) |
| | | public R generatorInvoice(@ParameterObject SaleCredit saleCredit) { |
| | | if(saleCredit.getContractId()==null){ |
| | | return R.failed("合同id不能为空"); |
| | |
| | | ContractOutBoundVo vo = new ContractOutBoundVo(); |
| | | BeanUtil.copyProperties(outBound,vo); |
| | | Product product = productService.getOne(new LambdaQueryWrapper<Product>().eq(Product::getErpCode,outBound.getSubjectMatterCode()).last("limit 1")); |
| | | Product productP = productService.getOne(new LambdaQueryWrapper<Product>().eq(Product::getId,product.getParentId()).last("limit 1")); |
| | | |
| | | if(product!=null){ |
| | | vo.setProductId(product.getId()); |
| | | vo.setInvoiceName("*"+product.getTaxClass()+"*" + (productP!=null?productP.getProductName():"") + "*"); |
| | | vo.setTaxClass(product.getTaxClass()); |
| | | vo.setTaxCode(product.getTaxCode()); |
| | | vo.setTaxRate(product.getTaxRate()); |
| | | } |
| | | |
| | | ContractSubjectMatter matter = contractSubjectMatterService.getOne(new LambdaQueryWrapper<ContractSubjectMatter>() |
| | | .eq(ContractSubjectMatter::getContractId,contract.getId()) |
| | | .eq(ContractSubjectMatter::getMaterialCode,outBound.getSubjectMatterCode()) |
| | | .last("limit 1") |
| | | ); |
| | | |
| | | if(matter!=null){ |
| | | vo.setSpecification(matter.getSpecification()); |
| | | vo.setUnit(matter.getUnit()); |
| | | vo.setUnitPrice(matter.getUnitPrice()); |
| | | } |
| | | |
| | | list.add(vo); |
| | | } |
| | | saleCredit.setContractOutBoundList(list); |