diff --git a/oms_web/oms_vue/src/api/finance/receivable.js b/oms_web/oms_vue/src/api/finance/receivable.js index 126b4112..08a1968e 100644 --- a/oms_web/oms_vue/src/api/finance/receivable.js +++ b/oms_web/oms_vue/src/api/finance/receivable.js @@ -5,6 +5,7 @@ export function listReceivable(query) { return request({ url: '/finance/receivable/list', method: 'post', + headers: { 'Content-Type': 'multipart/form-data' }, data: query }) } diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/DataProcessController.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/DataProcessController.java index 9ba0556d..d6d772e3 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/DataProcessController.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/DataProcessController.java @@ -3,6 +3,7 @@ package com.ruoyi.sip.controller; import com.ruoyi.common.annotation.Anonymous; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.exception.ServiceException; +import com.ruoyi.common.utils.StringUtils; import com.ruoyi.sip.dto.ProjectTransferRequest; import com.ruoyi.sip.service.IDataProcessService; import org.springframework.beans.factory.annotation.Autowired; @@ -26,10 +27,7 @@ public class DataProcessController { //入库单生成应付单 @Anonymous @GetMapping("/inventoryInnerGeneratePayableBill") - void inventoryInnerGeneratePayableBill(@RequestParam("innerId") Long innerId) { - if (innerId == null) { - throw new ServiceException("innerId不能为空"); - } + public void inventoryInnerGeneratePayableBill(@RequestParam("innerId") Long innerId) { dataProcessService.inventoryInnerGeneratePayableBill(innerId); } @@ -38,4 +36,11 @@ public class DataProcessController { return dataProcessService.projectTransfer(request); } + //生成服务产品的应收单、应付单 + @Anonymous + @GetMapping("/generateServiceBillsWhenAllDelivered") + public void generateServiceBillsWhenAllDelivered(@RequestParam("orderCode") String orderCode) { + dataProcessService.generateServiceBillsWhenAllDelivered(orderCode); + } + } diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/OmsReceivableBillController.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/OmsReceivableBillController.java index 046d891c..3e24f3b9 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/OmsReceivableBillController.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/controller/OmsReceivableBillController.java @@ -47,7 +47,7 @@ public class OmsReceivableBillController extends BaseController @RequiresPermissions("finance:receivable:list") @PostMapping("/list") @ResponseBody - public TableDataInfo list(@RequestBody OmsReceivableBill omsReceivableBill) + public TableDataInfo list(OmsReceivableBill omsReceivableBill) { startPage(); List list = omsReceivableBillService.selectOmsReceivableBillList(omsReceivableBill); @@ -128,4 +128,4 @@ public class OmsReceivableBillController extends BaseController } -} \ No newline at end of file +} diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IDataProcessService.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IDataProcessService.java index 34b33189..eefdd88a 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IDataProcessService.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IDataProcessService.java @@ -9,4 +9,6 @@ public interface IDataProcessService { AjaxResult projectTransfer(ProjectTransferRequest request); + void generateServiceBillsWhenAllDelivered(String orderCode); + } diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IInventoryDeliveryService.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IInventoryDeliveryService.java index 2881b399..3f6b668f 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IInventoryDeliveryService.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/IInventoryDeliveryService.java @@ -71,4 +71,7 @@ public interface IInventoryDeliveryService void recall(Long id); List detailExport(InventoryDelivery inventoryDelivery); + + void generateServiceBillsWhenAllDelivered(String orderCode); + } diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/DataProcessServiceImpl.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/DataProcessServiceImpl.java index 0bc744f3..ce9e7c98 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/DataProcessServiceImpl.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/DataProcessServiceImpl.java @@ -16,17 +16,14 @@ import com.ruoyi.sip.mapper.OmsInventoryInnerMapper; import com.ruoyi.sip.mapper.ProjectInfoMapper; import com.ruoyi.sip.mapper.ProjectOrderInfoMapper; import com.ruoyi.sip.mapper.ProjectUserCollectInfoMapper; -import com.ruoyi.sip.service.IDataProcessService; -import com.ruoyi.sip.service.IOmsPayableBillService; -import com.ruoyi.sip.service.IOmsPurchaseOrderService; -import com.ruoyi.sip.service.IProductInfoService; -import com.ruoyi.sip.service.IVendorInfoService; +import com.ruoyi.sip.service.*; import org.apache.shiro.SecurityUtils; import org.apache.shiro.mgt.DefaultSecurityManager; import org.apache.shiro.mgt.SecurityManager; import org.apache.shiro.subject.SimplePrincipalCollection; import org.apache.shiro.subject.Subject; import org.apache.shiro.util.ThreadContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; @@ -65,9 +62,13 @@ public class DataProcessServiceImpl implements IDataProcessService { @Resource private ProjectInfoMapper projectInfoMapper; + @Resource private ProjectOrderInfoMapper projectOrderInfoMapper; + @Autowired + private IInventoryDeliveryService inventoryDeliveryService; + @Value("${oms.inventory.innerTax:0.13}") private String defaultTax; @@ -155,5 +156,14 @@ public class DataProcessServiceImpl implements IDataProcessService { projectUserCollectInfoMapper.deleteProjectUserCollectInfoByProjectIds(request.getProjectIdList(), request.getOriginalHzSupportUser()); return AjaxResult.success("项目转移成功"); } + + @Override + public void generateServiceBillsWhenAllDelivered(String orderCode) { + if (StringUtils.isEmpty(orderCode)) { + throw new ServiceException("orderCode不能为空"); + } + bindShiroUser(1L, "admin", "平台管理员"); + inventoryDeliveryService.generateServiceBillsWhenAllDelivered(orderCode); + } } diff --git a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java index 1d4632b4..47062bbb 100644 --- a/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java +++ b/ruoyi-sip/src/main/java/com/ruoyi/sip/service/impl/InventoryDeliveryServiceImpl.java @@ -27,6 +27,7 @@ import org.springframework.stereotype.Service; import com.ruoyi.sip.mapper.InventoryDeliveryMapper; import com.ruoyi.common.core.text.Convert; import org.springframework.transaction.annotation.Transactional; +import org.springframework.util.ObjectUtils; import javax.annotation.Resource; @@ -316,7 +317,86 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService { billService.insertOmsReceivableBill(receivableBill); } + //生成服务应收单、应付单 + generateServiceBillsWhenAllDelivered(inventoryDelivery.getOrderCode()); + } + /** + 生成服务应收单、应付单 + */ + @Override + public void generateServiceBillsWhenAllDelivered(String orderCode) { + ProjectOrderInfo orderInfo = projectOrderInfoService.selectProjectOrderInfoByOrderCode(orderCode); + if (ObjectUtils.isEmpty(orderInfo)) { + throw new ServiceException("无对应订单信息"); + } + if (!ProjectOrderInfo.DeliveryStatusEnum.ALL_DELIVERY.getCode().equals(orderInfo.getDeliveryStatus())) { + throw new ServiceException("当前订单未全部发货"); + } + List serviceProductInfos = CollUtil.isEmpty(orderInfo.getMaintenanceProjectProductInfoList()) + ? Collections.emptyList() + : orderInfo.getMaintenanceProjectProductInfoList(); + if (CollUtil.isEmpty(serviceProductInfos)) { + return; + } + OmsPayableBill payableQuery = new OmsPayableBill(); + payableQuery.setOrderCode(orderInfo.getOrderCode()); + Set existsPayableProductCodeSet = payableBillService.selectOmsPayableBillList(payableQuery).stream() + .filter(item -> StringUtils.isEmpty(item.getInventoryCode())) + .map(OmsPayableBill::getProductCode) + .filter(StringUtils::isNotEmpty) + .collect(Collectors.toSet()); + + OmsReceivableBill receivableQuery = new OmsReceivableBill(); + receivableQuery.setOrderCode(orderInfo.getOrderCode()); + Set existsReceivableProductCodeSet = billService.selectOmsReceivableBillList(receivableQuery).stream() + .filter(item -> StringUtils.isEmpty(item.getInventoryCode())) + .map(OmsReceivableBill::getProductCode) + .filter(StringUtils::isNotEmpty) + .collect(Collectors.toSet()); + + for (ProjectProductInfo serviceProductInfo : serviceProductInfos) { + BigDecimal totalPriceWithTax = Optional.ofNullable(serviceProductInfo.getAllPrice()) + .orElse(Optional.ofNullable(serviceProductInfo.getPrice()).orElse(BigDecimal.ZERO) + .multiply(new BigDecimal(Optional.ofNullable(serviceProductInfo.getQuantity()).orElse(0L)))); + BigDecimal taxRate = serviceProductInfo.getTaxRate() == null + ? new BigDecimal(defaultTax) + : serviceProductInfo.getTaxRate().divide(new BigDecimal("100")); + BigDecimal totalPriceWithoutTax = totalPriceWithTax.divide(BigDecimal.ONE.add(taxRate), 2, RoundingMode.HALF_UP); + + String productCode = serviceProductInfo.getProductBomCode(); + if (!existsPayableProductCodeSet.contains(productCode)) { + OmsPayableBill servicePayableBill = new OmsPayableBill(); + servicePayableBill.setProductCode(productCode); + servicePayableBill.setProductType(serviceProductInfo.getType()); + servicePayableBill.setProductLevel2Type(serviceProductInfo.getLevel2Type()); + servicePayableBill.setVendorCode(serviceProductInfo.getVendorCode()); + servicePayableBill.setTotalPriceWithTax(totalPriceWithTax); + servicePayableBill.setTaxRate(taxRate); + servicePayableBill.setTotalPriceWithoutTax(totalPriceWithoutTax); + servicePayableBill.setTaxAmount(totalPriceWithTax.subtract(totalPriceWithoutTax)); + servicePayableBill.setOrderCode(orderInfo.getOrderCode()); + payableBillService.insertOmsPayableBill(servicePayableBill, 0); + existsPayableProductCodeSet.add(productCode); + } + + if (!existsReceivableProductCodeSet.contains(productCode)) { + OmsReceivableBill serviceReceivableBill = new OmsReceivableBill(); + serviceReceivableBill.setProductCode(productCode); + serviceReceivableBill.setProductType(serviceProductInfo.getType()); + serviceReceivableBill.setPartnerCode(orderInfo.getPartnerCode()); + serviceReceivableBill.setPartnerName(orderInfo.getPartnerName()); + serviceReceivableBill.setOrderCode(orderInfo.getOrderCode()); + serviceReceivableBill.setTotalPriceWithTax(totalPriceWithTax); + serviceReceivableBill.setTaxRate(taxRate); + serviceReceivableBill.setTotalPriceWithoutTax(totalPriceWithoutTax); + serviceReceivableBill.setTaxAmount(totalPriceWithTax.subtract(totalPriceWithoutTax)); + serviceReceivableBill.setUninvoicedAmount(totalPriceWithTax); + serviceReceivableBill.setUnreceivedAmount(totalPriceWithTax); + billService.insertOmsReceivableBill(serviceReceivableBill); + existsReceivableProductCodeSet.add(productCode); + } + } } @Override @@ -416,6 +496,29 @@ public class InventoryDeliveryServiceImpl implements IInventoryDeliveryService { projectOrderInfoService.updateProjectOrderInfoByCode(updateOrder); //修改累计发货数量 productInfoService.updateCumulativeCount(-inventoryDelivery.getQuantity(), inventoryDelivery.getProductCode()); + //撤回时删除当前出库单对应的应付、应收数据(仅删除软件和硬件类型:1、2) + Set deleteProductTypeSet = new HashSet<>(Arrays.asList( + ProductInfo.ProductTypeEnum.SOFTWARE.getType(), + ProductInfo.ProductTypeEnum.HARDWARE.getType() + )); + OmsPayableBill queryPayable = new OmsPayableBill(); + queryPayable.setInventoryCode(inventoryDelivery.getOuterCode()); + List payableBills = payableBillService.selectOmsPayableBillList(queryPayable).stream() + .filter(item -> deleteProductTypeSet.contains(item.getProductType())) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(payableBills)) { + String ids = payableBills.stream().map(item -> String.valueOf(item.getId())).collect(Collectors.joining(",")); + payableBillService.deleteOmsPayableBillByIds(ids); + } + OmsReceivableBill queryReceivable = new OmsReceivableBill(); + queryReceivable.setInventoryCode(inventoryDelivery.getOuterCode()); + List receivableBills = billService.selectOmsReceivableBillList(queryReceivable).stream() + .filter(item -> deleteProductTypeSet.contains(item.getProductType())) + .collect(Collectors.toList()); + if (CollUtil.isNotEmpty(receivableBills)) { + String ids = receivableBills.stream().map(item -> String.valueOf(item.getId())).collect(Collectors.joining(",")); + billService.deleteOmsReceivableBillByIds(ids); + } } diff --git a/ruoyi-sip/src/main/resources/mapper/finance/OmsPayableBillMapper.xml b/ruoyi-sip/src/main/resources/mapper/finance/OmsPayableBillMapper.xml index 75022eee..6214f648 100644 --- a/ruoyi-sip/src/main/resources/mapper/finance/OmsPayableBillMapper.xml +++ b/ruoyi-sip/src/main/resources/mapper/finance/OmsPayableBillMapper.xml @@ -11,6 +11,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -39,6 +40,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" t1.order_code, t1.inventory_code, t1.product_type, + t1.product_code, t1.total_price_with_tax, t1.total_price_without_tax, t1.tax_amount, @@ -80,6 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" t1.tax_rate, t1.remark, t1.del_flag , + t1.product_code, t3.project_code, t3.project_name, t4.vendor_name, @@ -119,6 +122,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{inventoryCode},'%') and t1.product_type = #{productType} + and t1.product_code = #{productCode} and t1.total_price_with_tax = #{totalPriceWithTax} and t1.total_price_without_tax = #{totalPriceWithoutTax} and t1.tax_amount = #{taxAmount} @@ -286,6 +290,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order_code = #{orderCode}, inventory_code = #{inventoryCode}, product_type = #{productType}, + product_code = #{productCode}, total_price_with_tax = #{totalPriceWithTax}, total_price_without_tax = #{totalPriceWithoutTax}, tax_amount = #{taxAmount}, diff --git a/ruoyi-sip/src/main/resources/mapper/sip/OmsReceivableBillMapper.xml b/ruoyi-sip/src/main/resources/mapper/sip/OmsReceivableBillMapper.xml index 915aa434..606890d1 100644 --- a/ruoyi-sip/src/main/resources/mapper/sip/OmsReceivableBillMapper.xml +++ b/ruoyi-sip/src/main/resources/mapper/sip/OmsReceivableBillMapper.xml @@ -14,6 +14,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" + @@ -31,7 +32,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - select t1.id, t1.receivable_bill_code, t1.last_receipt_plan_id, t1.last_invoice_plan_id, t1.partner_code, t1.partner_name, t1.order_code, t1.inventory_code, t1.product_type, + select t1.id, t1.receivable_bill_code, t1.last_receipt_plan_id, t1.last_invoice_plan_id, t1.partner_code, t1.partner_name, t1.order_code, t1.inventory_code, t1.product_type, t1.product_code, t1.total_price_with_tax, t1.total_price_without_tax, t1.tax_rate, t1.tax_amount, t1.received_amount, t1.unreceived_amount, t1.invoiced_amount, t1.uninvoiced_amount, t1.create_by, t1.create_time, t1.update_by, t1.update_time, t1.remark, t1.del_flag ,t3.project_name, t3.project_code @@ -68,6 +69,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" and t1.order_code = #{orderCode} and t1.inventory_code = #{inventoryCode} and t1.product_type = #{productType} + and t1.product_code = #{productCode} and t1.create_by = #{createBy} and t3.project_code = #{projectCode} and t3.project_name like concat('%', #{projectName}, '%') @@ -100,6 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order_code, inventory_code, product_type, + product_code, total_price_with_tax, total_price_without_tax, tax_rate, @@ -124,6 +127,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" #{orderCode}, #{inventoryCode}, #{productType}, + #{productCode}, #{totalPriceWithTax}, #{totalPriceWithoutTax}, #{taxRate}, @@ -152,6 +156,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" order_code = #{orderCode}, inventory_code = #{inventoryCode}, product_type = #{productType}, + product_code = #{productCode}, total_price_with_tax = #{totalPriceWithTax}, total_price_without_tax = #{totalPriceWithoutTax}, tax_rate = #{taxRate}, @@ -168,11 +173,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" - update oms_receivable_bill set del_flag = '2' where id = #{id} + delete from oms_receivable_bill where id = #{id} - update oms_receivable_bill set del_flag = '2' where id in + delete from oms_receivable_bill where id in #{id} @@ -185,7 +190,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" AND receivable_bill_code REGEXP CONCAT('^', #{codePrefix}, '[0-9]+$')