| | |
| | | import com.ruoyi.stock.execl.StockInRecordExportData; |
| | | import com.ruoyi.production.mapper.ProductionOrderPickMapper; |
| | | import com.ruoyi.production.pojo.ProductionOrderPick; |
| | | import com.ruoyi.procurementrecord.mapper.ReturnManagementMapper; |
| | | import com.ruoyi.procurementrecord.mapper.ReturnSaleProductMapper; |
| | | import com.ruoyi.procurementrecord.pojo.ReturnManagement; |
| | | import com.ruoyi.procurementrecord.pojo.ReturnSaleProduct; |
| | | import com.ruoyi.sales.mapper.SalesLedgerMapper; |
| | | import com.ruoyi.sales.mapper.ShippingInfoMapper; |
| | | import com.ruoyi.sales.pojo.SalesLedger; |
| | | import com.ruoyi.sales.pojo.ShippingInfo; |
| | | import com.ruoyi.stock.mapper.StockInRecordMapper; |
| | | import com.ruoyi.stock.mapper.StockInventoryMapper; |
| | | import com.ruoyi.stock.mapper.StockUninventoryMapper; |
| | |
| | | private StockInventoryMapper stockInventoryMapper; |
| | | private StockUninventoryMapper stockUninventoryMapper; |
| | | private ProductionOrderPickMapper productionOrderPickMapper; |
| | | private ReturnSaleProductMapper returnSaleProductMapper; |
| | | private ReturnManagementMapper returnManagementMapper; |
| | | private ShippingInfoMapper shippingInfoMapper; |
| | | private SalesLedgerMapper salesLedgerMapper; |
| | | |
| | | @Override |
| | | public IPage<StockInRecordDto> listPage(Page page, StockInRecordDto stockInRecordDto) { |
| | |
| | | stockUninventoryMapper.updateAddStockUnInventory(stockUninventoryDto); |
| | | } |
| | | } |
| | | // 销售退货入库:扣减销售台账实际合同金额(退货生效) |
| | | handleSalesReturnRefund(stockInRecord); |
| | | } |
| | | } |
| | | return ids.size(); |
| | |
| | | |
| | | return ids.size(); |
| | | } |
| | | |
| | | /** |
| | | * 销售退货入库审批通过时,扣减对应销售台账的实际合同金额。 |
| | | * 关联链:stock_in_record.record_id = return_sale_product.id |
| | | * → return_management.shipping_id = shipping_info.id |
| | | * → shipping_info.sales_ledger_id = sales_ledger.id |
| | | * 只处理 record_type 为 14(合格)或 15(不合格)的销售退货入库。 |
| | | */ |
| | | private void handleSalesReturnRefund(StockInRecord stockInRecord) { |
| | | String recordType = stockInRecord.getRecordType(); |
| | | if (!StockInQualifiedRecordTypeEnum.RETURN_HE_IN.getCode().equals(recordType) |
| | | && !StockInQualifiedRecordTypeEnum.RETURN_UNSTOCK_IN.getCode().equals(recordType)) { |
| | | return; |
| | | } |
| | | if (stockInRecord.getRecordId() == null) { |
| | | return; |
| | | } |
| | | ReturnSaleProduct rsp = returnSaleProductMapper.selectById(stockInRecord.getRecordId()); |
| | | if (rsp == null || rsp.getReturnManagementId() == null) { |
| | | return; |
| | | } |
| | | ReturnManagement rm = returnManagementMapper.selectById(rsp.getReturnManagementId()); |
| | | if (rm == null || rm.getShippingId() == null) { |
| | | return; |
| | | } |
| | | ShippingInfo shippingInfo = shippingInfoMapper.selectById(rm.getShippingId()); |
| | | if (shippingInfo == null || shippingInfo.getSalesLedgerId() == null) { |
| | | return; |
| | | } |
| | | SalesLedger salesLedger = salesLedgerMapper.selectById(shippingInfo.getSalesLedgerId()); |
| | | if (salesLedger == null || salesLedger.getContractAmount() == null) { |
| | | return; |
| | | } |
| | | BigDecimal refund = rsp.getAmount() != null ? rsp.getAmount() : BigDecimal.ZERO; |
| | | if (refund.compareTo(BigDecimal.ZERO) == 0) { |
| | | return; |
| | | } |
| | | BigDecimal baseAmount = salesLedger.getNetContractAmount() != null |
| | | ? salesLedger.getNetContractAmount() |
| | | : salesLedger.getContractAmount(); |
| | | salesLedger.setNetContractAmount(baseAmount.subtract(refund)); |
| | | salesLedgerMapper.updateById(salesLedger); |
| | | } |
| | | } |