|
|
@@ -33,6 +33,7 @@ import org.springblade.los.business.sea.entity.Bills;
|
|
|
import org.springblade.los.business.sea.entity.PreContainers;
|
|
|
import org.springblade.los.business.sea.mapper.BillsMapper;
|
|
|
import org.springblade.los.business.sea.mapper.PreContainersMapper;
|
|
|
+import org.springblade.los.excel.InventoryAlertExcel;
|
|
|
import org.springblade.los.finance.fee.entity.FeeCenter;
|
|
|
import org.springblade.los.finance.fee.mapper.FeeCenterMapper;
|
|
|
import org.springblade.los.trade.entity.*;
|
|
|
@@ -40,6 +41,7 @@ import org.springblade.los.trade.mapper.AgentItemsMapper;
|
|
|
import org.springblade.los.trade.mapper.DispatchVehiclesMapper;
|
|
|
import org.springblade.los.trade.mapper.InOutStorageMapper;
|
|
|
import org.springblade.los.trade.service.IInOutStorageService;
|
|
|
+import org.springblade.los.trade.service.IPayableStorageFeesItemsService;
|
|
|
import org.springblade.los.trade.service.IStorageService;
|
|
|
import org.springblade.los.trade.vo.InOutStorageVO;
|
|
|
import org.springblade.system.entity.Dept;
|
|
|
@@ -84,6 +86,8 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
|
|
|
|
|
|
private final DispatchVehiclesMapper dispatchVehiclesMapper;
|
|
|
|
|
|
+ private final IPayableStorageFeesItemsService payableStorageFeesItemsService;
|
|
|
+
|
|
|
@Override
|
|
|
public IPage<InOutStorageVO> selectInOutStoragePage(IPage<InOutStorageVO> page, InOutStorageVO inOutStorage) {
|
|
|
return page.setRecords(baseMapper.selectInOutStoragePage(page, inOutStorage));
|
|
|
@@ -667,7 +671,6 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
|
|
|
if ("1".equals(inOutStorage.getWhetherInOutStorage())) {
|
|
|
throw new RuntimeException("已生成出库信息,撤销失败");
|
|
|
}
|
|
|
- inOutStorage.setChargingDate(null);
|
|
|
Bills bills = billsMapper.selectById(inOutStorage.getPid());
|
|
|
if (ObjectUtils.isNotNull(bills.getMconsigneeCntyName())) {
|
|
|
List<FeeCenter> feeCenterTradeList = feeCenterMapper.selectList(new LambdaQueryWrapper<FeeCenter>()
|
|
|
@@ -706,7 +709,13 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
|
|
|
if ("1".equals(storage.getBillingRules())) {
|
|
|
billingRules = false;
|
|
|
}
|
|
|
- inOutStorage.setOutStorageDate(null);
|
|
|
+ List<PayableStorageFeesItems> payableStorageFees = payableStorageFeesItemsService.list(new LambdaQueryWrapper<PayableStorageFeesItems>()
|
|
|
+ .eq(PayableStorageFeesItems::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(PayableStorageFeesItems::getIsDeleted, 0)
|
|
|
+ .eq(PayableStorageFeesItems::getItemId, inOutStorage.getId()));
|
|
|
+ if (!payableStorageFees.isEmpty()) {
|
|
|
+ throw new RuntimeException("改出库记录已计算过仓储费,撤销失败");
|
|
|
+ }
|
|
|
InOutStorage inStorage = baseMapper.selectById(inOutStorage.getSrcId());
|
|
|
BigDecimal quantity = inStorage.getSurplusQuantity();
|
|
|
BigDecimal grossWeight = inStorage.getSurplusWeight();
|
|
|
@@ -811,4 +820,152 @@ public class InOutStorageServiceImpl extends ServiceImpl<InOutStorageMapper, InO
|
|
|
return baseMapper.inventoryAccountStatisticsList(outStorageStatistics);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public R inventoryAlert(InOutStorage inOutStorage) {
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ Storage storage = storageService.getById(inOutStorage.getWarehouseId());
|
|
|
+ if (storage == null) {
|
|
|
+ throw new RuntimeException("未查到仓库信息");
|
|
|
+ }
|
|
|
+ boolean billingRules = true;
|
|
|
+ if ("1".equals(storage.getBillingRules())) {
|
|
|
+ billingRules = false;
|
|
|
+ }
|
|
|
+ InOutStorage inStorage = baseMapper.selectById(inOutStorage.getSrcId());
|
|
|
+ BigDecimal quantity = inStorage.getSurplusQuantity();
|
|
|
+ if (quantity.compareTo(inOutStorage.getOutQuantity()) < 0) {
|
|
|
+ throw new RuntimeException("剩余数量:" + quantity + "小于出库数量:" + inOutStorage.getOutQuantity());
|
|
|
+ }
|
|
|
+ BigDecimal grossWeight = inStorage.getSurplusWeight();
|
|
|
+ if (grossWeight.compareTo(inOutStorage.getOutWeight()) < 0) {
|
|
|
+ throw new RuntimeException("剩余毛重:" + grossWeight + "小于出库毛重:" + inOutStorage.getOutWeight());
|
|
|
+ }
|
|
|
+ BigDecimal netWeight = inStorage.getSurplusNetWeight();
|
|
|
+ if (netWeight.compareTo(inOutStorage.getOutNetWeight()) < 0) {
|
|
|
+ throw new RuntimeException("剩余净重:" + netWeight + "小于出库净重:" + inOutStorage.getOutWeight());
|
|
|
+ }
|
|
|
+ BigDecimal outGoodsAmount;
|
|
|
+ if (billingRules) {
|
|
|
+ outGoodsAmount = inOutStorage.getOutWeight().multiply(inOutStorage.getPrice());
|
|
|
+ } else {
|
|
|
+ outGoodsAmount = inOutStorage.getOutNetWeight().multiply(inOutStorage.getPrice());
|
|
|
+ }
|
|
|
+ Bills bills = billsMapper.selectById(inStorage.getPid());
|
|
|
+ if (bills == null) {
|
|
|
+ throw new RuntimeException("未查到该条出库对应总单据信息");
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsMapper.selectList(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(Bills::getCorpId, bills.getCorpId()));
|
|
|
+ if (billsList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到客户:" + bills.getCorpCnName() + "单据信息");
|
|
|
+ }
|
|
|
+ List<Long> pidList = billsList.stream().map(Bills::getId).distinct().collect(Collectors.toList());
|
|
|
+ List<InOutStorage> inOutStorageList = baseMapper.selectList(new LambdaQueryWrapper<InOutStorage>()
|
|
|
+ .eq(InOutStorage::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(InOutStorage::getIsDeleted, 0)
|
|
|
+ .eq(InOutStorage::getBillType, "RK")
|
|
|
+ .eq(InOutStorage::getPid, pidList));
|
|
|
+ List<FeeCenter> feeCenterList = feeCenterMapper.selectList(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .in(FeeCenter::getPid, pidList)
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .eq(FeeCenter::getDc, "D")
|
|
|
+ .orderByDesc(FeeCenter::getCorpId)
|
|
|
+ .orderByAsc(FeeCenter::getBillNo));
|
|
|
+ BigDecimal amount = new BigDecimal("0.00");
|
|
|
+ BigDecimal surplusGoodsAmount = new BigDecimal("0.00");
|
|
|
+ if (!feeCenterList.isEmpty()) {
|
|
|
+ amount = feeCenterList.stream().map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ if (!feeCenterList.isEmpty()) {
|
|
|
+ surplusGoodsAmount = inOutStorageList.stream().map(InOutStorage::getSurplusGoodsAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ BigDecimal thisGoodsAmount = outGoodsAmount.multiply(inStorage.getPrice());
|
|
|
+ if (amount.compareTo(surplusGoodsAmount.subtract(thisGoodsAmount)) >= 0) {
|
|
|
+ map.put("status", true);
|
|
|
+ map.put("content", "客户未收金额:" + amount + "大于剩余货值:" + surplusGoodsAmount.subtract(thisGoodsAmount) + "(" +
|
|
|
+ (surplusGoodsAmount.subtract(thisGoodsAmount)).divide(surplusGoodsAmount, 2, RoundingMode.HALF_UP) + "%)" +
|
|
|
+ ",本次出库货值:" + thisGoodsAmount + "(" + thisGoodsAmount.divide(surplusGoodsAmount, 2, RoundingMode.HALF_UP) + ")");
|
|
|
+ map.put("feeCenterList", feeCenterList);
|
|
|
+ } else {
|
|
|
+ map.put("status", false);
|
|
|
+ }
|
|
|
+ return R.data(map);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public List<InventoryAlertExcel> inventoryAlertExport(InOutStorage detail) {
|
|
|
+ InOutStorage inOutStorage = baseMapper.selectById(detail.getId());
|
|
|
+ Storage storage = storageService.getById(inOutStorage.getWarehouseId());
|
|
|
+ if (storage == null) {
|
|
|
+ throw new RuntimeException("未查到仓库信息");
|
|
|
+ }
|
|
|
+ boolean billingRules = true;
|
|
|
+ if ("1".equals(storage.getBillingRules())) {
|
|
|
+ billingRules = false;
|
|
|
+ }
|
|
|
+ InOutStorage inStorage = baseMapper.selectById(inOutStorage.getSrcId());
|
|
|
+ BigDecimal outGoodsAmount;
|
|
|
+ if (billingRules) {
|
|
|
+ outGoodsAmount = inOutStorage.getOutWeight().multiply(inOutStorage.getPrice());
|
|
|
+ } else {
|
|
|
+ outGoodsAmount = inOutStorage.getOutNetWeight().multiply(inOutStorage.getPrice());
|
|
|
+ }
|
|
|
+ Bills bills = billsMapper.selectById(inStorage.getPid());
|
|
|
+ if (bills == null) {
|
|
|
+ throw new RuntimeException("未查到该条出库对应总单据信息");
|
|
|
+ }
|
|
|
+ List<Bills> billsList = billsMapper.selectList(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0)
|
|
|
+ .eq(Bills::getCorpId, bills.getCorpId()));
|
|
|
+ if (billsList.isEmpty()) {
|
|
|
+ throw new RuntimeException("未查到客户:" + bills.getCorpCnName() + "单据信息");
|
|
|
+ }
|
|
|
+ List<Long> pidList = billsList.stream().map(Bills::getId).distinct().collect(Collectors.toList());
|
|
|
+ List<InOutStorage> inOutStorageList = baseMapper.selectList(new LambdaQueryWrapper<InOutStorage>()
|
|
|
+ .eq(InOutStorage::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(InOutStorage::getIsDeleted, 0)
|
|
|
+ .eq(InOutStorage::getBillType, "RK")
|
|
|
+ .eq(InOutStorage::getPid, pidList));
|
|
|
+ List<FeeCenter> feeCenterList = feeCenterMapper.selectList(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .in(FeeCenter::getPid, pidList)
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0)
|
|
|
+ .eq(FeeCenter::getDc, "D")
|
|
|
+ .orderByDesc(FeeCenter::getCorpId)
|
|
|
+ .orderByAsc(FeeCenter::getBillNo));
|
|
|
+ BigDecimal amount = new BigDecimal("0.00");
|
|
|
+ BigDecimal surplusGoodsAmount = new BigDecimal("0.00");
|
|
|
+ if (!feeCenterList.isEmpty()) {
|
|
|
+ amount = feeCenterList.stream().map(FeeCenter::getAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ if (!feeCenterList.isEmpty()) {
|
|
|
+ surplusGoodsAmount = inOutStorageList.stream().map(InOutStorage::getSurplusGoodsAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ }
|
|
|
+ BigDecimal thisGoodsAmount = outGoodsAmount.multiply(inStorage.getPrice());
|
|
|
+ List<InventoryAlertExcel> inventoryAlertExcelList = new ArrayList<>();
|
|
|
+ if (amount.compareTo(surplusGoodsAmount.subtract(thisGoodsAmount)) >= 0) {
|
|
|
+ for (FeeCenter item : feeCenterList) {
|
|
|
+ InventoryAlertExcel excel = new InventoryAlertExcel();
|
|
|
+ excel.setBusinessType(item.getBusinessType());
|
|
|
+ excel.setBookingNo(item.getBookingNo());
|
|
|
+ excel.setMblno(item.getMblno());
|
|
|
+ excel.setCorpCnName(item.getCorpCnName());
|
|
|
+ excel.setFeeCnName(item.getFeeCnName());
|
|
|
+ excel.setUnsettledAmount(item.getUnsettledAmount());
|
|
|
+ excel.setBillDate(item.getBillDate());
|
|
|
+ if (0 == item.getAccStatus()) {
|
|
|
+ excel.setAccStatus("否");
|
|
|
+ } else {
|
|
|
+ excel.setAccStatus("是");
|
|
|
+ }
|
|
|
+ inventoryAlertExcelList.add(excel);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return inventoryAlertExcelList;
|
|
|
+ }
|
|
|
+
|
|
|
}
|