|
|
@@ -2794,6 +2794,904 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
|
|
|
} else {
|
|
|
map.put(MagicValues.DATA, null);
|
|
|
}
|
|
|
+ } else if (MagicValues.BUSINESS.equals(reportCode) && MagicValues.SALES_REPORT_AMEND.equals(groupCode) && (MagicValues.HYCK.equals(type) || MagicValues.HYJK.equals(type))) {
|
|
|
+ List<Bills> list = new ArrayList<>();
|
|
|
+ Bills bills = billsService.getById(billId);
|
|
|
+ if (bills != null) {
|
|
|
+ R<String> biz = dictBizClient.getOneValue("src_type_los", bills.getSrcType(), AuthUtil.getTenantId());
|
|
|
+ if (biz.isSuccess()) {
|
|
|
+ bills.setSrcType(biz.getData());
|
|
|
+ }
|
|
|
+ // 提取分表
|
|
|
+ SeaBillsDetail seaBillsDetail = seaBillsDetailService.getOne(new LambdaQueryWrapper<SeaBillsDetail>()
|
|
|
+ .eq(SeaBillsDetail::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(SeaBillsDetail::getPid, bills.getId()));
|
|
|
+ if (seaBillsDetail != null) {
|
|
|
+ bills.setInttraToDoorCorpName(seaBillsDetail.getInttraToDoorCorpName());
|
|
|
+ bills.setInttraToDoorCorpAddr(seaBillsDetail.getInttraToDoorCorpAddr());
|
|
|
+ bills.setInttraToDoorCorpContacts(seaBillsDetail.getInttraToDoorCorpContacts());
|
|
|
+ bills.setInttraToDoorCorpTel(seaBillsDetail.getInttraToDoorCorpTel());
|
|
|
+ bills.setInttraDoorToCorpName(seaBillsDetail.getInttraDoorToCorpName());
|
|
|
+ bills.setInttraDoorToCorpAddr(seaBillsDetail.getInttraDoorToCorpAddr());
|
|
|
+ bills.setInttraDoorToCorpContacts(seaBillsDetail.getInttraDoorToCorpContacts());
|
|
|
+ bills.setInttraDoorToCorpTel(seaBillsDetail.getInttraDoorToCorpTel());
|
|
|
+ bills.setHshipperId(seaBillsDetail.getHshipperId());
|
|
|
+ bills.setHshipperCode(seaBillsDetail.getHshipperCode());
|
|
|
+ bills.setHshipperCnName(seaBillsDetail.getHshipperCnName());
|
|
|
+ bills.setHshipperEnName(seaBillsDetail.getHshipperEnName());
|
|
|
+ bills.setHshipperDetails(seaBillsDetail.getHshipperDetails());
|
|
|
+ bills.setHconsigneeId(seaBillsDetail.getHconsigneeId());
|
|
|
+ bills.setHconsigneeCode(seaBillsDetail.getHconsigneeCode());
|
|
|
+ bills.setHconsigneeCnName(seaBillsDetail.getHconsigneeCnName());
|
|
|
+ bills.setHconsigneeEnName(seaBillsDetail.getHconsigneeEnName());
|
|
|
+ bills.setHconsigneeDetails(seaBillsDetail.getHconsigneeDetails());
|
|
|
+ bills.setHnotifyId(seaBillsDetail.getHnotifyId());
|
|
|
+ bills.setHnotifyCode(seaBillsDetail.getHnotifyCode());
|
|
|
+ bills.setHnotifyCnName(seaBillsDetail.getHnotifyCnName());
|
|
|
+ bills.setHnotifyEnName(seaBillsDetail.getHnotifyEnName());
|
|
|
+ bills.setHnotifyDetails(seaBillsDetail.getHnotifyDetails());
|
|
|
+ bills.setHnotify2Id(seaBillsDetail.getHnotify2Id());
|
|
|
+ bills.setHnotify2Code(seaBillsDetail.getHnotify2Code());
|
|
|
+ bills.setHnotify2CnName(seaBillsDetail.getHnotify2CnName());
|
|
|
+ bills.setHnotify2EnName(seaBillsDetail.getHnotify2EnName());
|
|
|
+ bills.setHnotify2Details(seaBillsDetail.getHnotify2Details());
|
|
|
+ bills.setMshipperId(seaBillsDetail.getMshipperId());
|
|
|
+ bills.setMshipperCode(seaBillsDetail.getMshipperCode());
|
|
|
+ bills.setMshipperCnName(seaBillsDetail.getMshipperCnName());
|
|
|
+ bills.setMshipperEnName(seaBillsDetail.getMshipperEnName());
|
|
|
+ bills.setMshipperDetails(seaBillsDetail.getMshipperDetails());
|
|
|
+ bills.setMconsigneeId(seaBillsDetail.getMconsigneeId());
|
|
|
+ bills.setMconsigneeCode(seaBillsDetail.getMconsigneeCode());
|
|
|
+ bills.setMconsigneeCnName(seaBillsDetail.getMconsigneeCnName());
|
|
|
+ bills.setMconsigneeEnName(seaBillsDetail.getMconsigneeEnName());
|
|
|
+ bills.setMconsigneeDetails(seaBillsDetail.getMconsigneeDetails());
|
|
|
+ bills.setMnotifyId(seaBillsDetail.getMnotifyId());
|
|
|
+ bills.setMnotifyCode(seaBillsDetail.getMnotifyCode());
|
|
|
+ bills.setMnotifyCnName(seaBillsDetail.getMnotifyCnName());
|
|
|
+ bills.setMnotifyEnName(seaBillsDetail.getMnotifyEnName());
|
|
|
+ bills.setMnotifyDetails(seaBillsDetail.getMnotifyDetails());
|
|
|
+ bills.setMnotify2Id(seaBillsDetail.getMnotify2Id());
|
|
|
+ bills.setMnotify2Code(seaBillsDetail.getMnotify2Code());
|
|
|
+ bills.setMnotify2CnName(seaBillsDetail.getMnotify2CnName());
|
|
|
+ bills.setMnotify2EnName(seaBillsDetail.getMnotify2EnName());
|
|
|
+ bills.setMnotify2Details(seaBillsDetail.getMnotify2Details());
|
|
|
+ bills.setMforwarderDetails(seaBillsDetail.getMforwarderDetails());
|
|
|
+ }
|
|
|
+ HmmEdi hmmEdi = hmmEdiService.getOne(new LambdaQueryWrapper<HmmEdi>()
|
|
|
+ .eq(HmmEdi::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(HmmEdi::getPid, bills.getId()));
|
|
|
+ bills.setHmmEdi(hmmEdi != null ? hmmEdi : new HmmEdi());
|
|
|
+ // 提取 USD 汇率
|
|
|
+ if (bCurrency != null) {
|
|
|
+ bills.setRate(bCurrency.getExrate());
|
|
|
+ } else {
|
|
|
+ bills.setRate(new BigDecimal(MagicValues.ZERO));
|
|
|
+ }
|
|
|
+ //
|
|
|
+ if (ObjectUtils.isNotNull(bills.getAmountProfitLoc()) && ObjectUtils.isNotNull(bills.getAmountDrLoc())) {
|
|
|
+ if (bills.getAmountProfitLoc().compareTo(new BigDecimal(MagicValues.ZERO)) == 0 ||
|
|
|
+ bills.getAmountDrLoc().compareTo(new BigDecimal(MagicValues.ZERO)) == 0) {
|
|
|
+ bills.setGrossMargin(new BigDecimal(MagicValues.ZERO));
|
|
|
+ } else {
|
|
|
+ bills.setGrossMargin(bills.getAmountProfitLoc().divide(bills.getAmountDrLoc(), 4, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ bills.setGrossMargin(new BigDecimal(MagicValues.ZERO));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isDebug) {
|
|
|
+ System.out.println("GrossMargin: " + bills.getGrossMargin().toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ List<FeeCenter> allFeeCenter = new ArrayList<>();
|
|
|
+
|
|
|
+ // 直单或主单
|
|
|
+ if (MagicValues.MM.equals(bills.getBillType()) || MagicValues.DD.equals(bills.getBillType())) {
|
|
|
+ List<Bills> billsList = billsService.list(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getMasterId, bills.getId())
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0));
|
|
|
+ if (!billsList.isEmpty()) {
|
|
|
+ String mblNo = billsList.stream().map(Bills::getMblno).filter(Objects::nonNull).collect(Collectors.joining(","));
|
|
|
+ if (ObjectUtils.isNotNull(mblNo)) {
|
|
|
+ // 所有分单的费用
|
|
|
+ List<FeeCenter> feeCenterListMh = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .apply("find_in_set(mblno,'" + mblNo + "')")
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0));
|
|
|
+ if (feeCenterListMh.isEmpty()) {
|
|
|
+ throw new RuntimeException("请先维护费用信息");
|
|
|
+ }
|
|
|
+ allFeeCenter.addAll(feeCenterListMh);
|
|
|
+ for (FeeCenter item : feeCenterListMh) {
|
|
|
+ if (ObjectUtils.isNotNull(item.getShortName())) {
|
|
|
+ item.setCorpCnName(item.getShortName());
|
|
|
+ } else {
|
|
|
+ item.setCorpCnName("无");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getBillShortName())) {
|
|
|
+ item.setBillCorpCnName(item.getBillShortName());
|
|
|
+ } else {
|
|
|
+ item.setBillCorpCnName("无");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ for (Bills item : billsList) {
|
|
|
+ List<FeeCenter> feeD = feeCenterListMh.stream().filter(e -> MagicValues.D.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ item.setFeeCenterListD(feeD);
|
|
|
+ List<FeeCenter> feeC = feeCenterListMh.stream().filter(e -> MagicValues.C.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ item.setFeeCenterListC(feeC);
|
|
|
+ List<FeeCenter> feeCenterList = feeCenterListMh.stream()
|
|
|
+ .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
+ Comparator.comparing(f -> f.getFeeId() + f.getCorpId() + f.getCurCode() + f.getDc()))), ArrayList::new));
|
|
|
+ List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
+ for (FeeCenter fee : feeCenterList) {
|
|
|
+ FeeCenterReports feeCenterReports = new FeeCenterReports();
|
|
|
+ feeCenterReports.setRemarks(fee.getRemarks());
|
|
|
+ feeCenterReports.setPid(item.getId());
|
|
|
+ feeCenterReports.setFeeCnName(fee.getFeeCnName());
|
|
|
+ feeCenterReports.setDc(fee.getDc());
|
|
|
+ List<FeeCenter> feeCenterListD = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(item.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountD(feeCenterListD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdD = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(item.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdD(feeCenterListUsdD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListUsdD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListC = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(item.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountC(feeCenterListC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdC = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(item.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdC(feeCenterListUsdC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListUsdC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ feeCenterReportList.add(feeCenterReports);
|
|
|
+ }
|
|
|
+ item.setFeeCenterList(feeCenterReportList);
|
|
|
+ list.add(item);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 当前单据的费用信息
|
|
|
+ List<FeeCenter> feeCenterList = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getMblno, bills.getMblno())
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0));
|
|
|
+ allFeeCenter.addAll(feeCenterList);
|
|
|
+
|
|
|
+ List<FeeCenter> feeD = feeCenterList.stream().filter(e -> MagicValues.D.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ bills.setFeeCenterListD(feeD);
|
|
|
+ List<FeeCenter> feeC = feeCenterList.stream().filter(e -> MagicValues.C.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ bills.setFeeCenterListC(feeC);
|
|
|
+
|
|
|
+ for (FeeCenter item : feeCenterList) {
|
|
|
+ if (ObjectUtils.isNotNull(item.getShortName())) {
|
|
|
+ item.setCorpCnName(item.getShortName());
|
|
|
+ } else {
|
|
|
+ item.setCorpCnName("无");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getBillShortName())) {
|
|
|
+ item.setBillCorpCnName(item.getBillShortName());
|
|
|
+ } else {
|
|
|
+ item.setBillCorpCnName("无");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!feeCenterList.isEmpty()) {
|
|
|
+ List<FeeCenter> feeCenters = feeCenterList.stream()
|
|
|
+ .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
+ Comparator.comparing(f -> f.getFeeId() + f.getCorpId() + f.getCurCode() + f.getDc()))), ArrayList::new));
|
|
|
+ List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
+ for (FeeCenter fee : feeCenters) {
|
|
|
+ FeeCenterReports feeCenterReports = new FeeCenterReports();
|
|
|
+ feeCenterReports.setRemarks(fee.getRemarks());
|
|
|
+ feeCenterReports.setPid(bills.getId());
|
|
|
+ feeCenterReports.setFeeCnName(fee.getFeeCnName());
|
|
|
+ feeCenterReports.setDc(fee.getDc());
|
|
|
+ List<FeeCenter> feeCenterListD = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountD(feeCenterListD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdD = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdD(feeCenterListUsdD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListUsdD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListC = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountC(feeCenterListC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdC = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdC(feeCenterListUsdC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListUsdC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ feeCenterReportList.add(feeCenterReports);
|
|
|
+ }
|
|
|
+ bills.setFeeCenterList(feeCenterReportList);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("请先维护费用");
|
|
|
+ }
|
|
|
+ list.add(0, bills);
|
|
|
+ }
|
|
|
+ else if (MagicValues.MH.equals(bills.getBillType())) {
|
|
|
+ // 分单
|
|
|
+ Bills details = billsService.getOne(new LambdaQueryWrapper<Bills>()
|
|
|
+ .eq(Bills::getId, bills.getMasterId())
|
|
|
+ .eq(Bills::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(Bills::getIsDeleted, 0));
|
|
|
+ if (details != null) {
|
|
|
+ List<FeeCenter> feeCenterList = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getMblno, bills.getMblno())
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0));
|
|
|
+ if (feeCenterList.isEmpty()) {
|
|
|
+ throw new RuntimeException("请先维护费用信息");
|
|
|
+ }
|
|
|
+ allFeeCenter.addAll(feeCenterList);
|
|
|
+ List<FeeCenter> feeD = feeCenterList.stream().filter(e -> MagicValues.D.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ bills.setFeeCenterListD(feeD);
|
|
|
+ List<FeeCenter> feeC = feeCenterList.stream().filter(e -> MagicValues.C.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ bills.setFeeCenterListC(feeC);
|
|
|
+ if (!feeCenterList.isEmpty()) {
|
|
|
+ for (FeeCenter item : feeCenterList) {
|
|
|
+ if (ObjectUtils.isNotNull(item.getShortName())) {
|
|
|
+ item.setCorpCnName(item.getShortName());
|
|
|
+ } else {
|
|
|
+ item.setCorpCnName("无");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getBillShortName())) {
|
|
|
+ item.setBillCorpCnName(item.getBillShortName());
|
|
|
+ } else {
|
|
|
+ item.setBillCorpCnName("无");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenters = feeCenterList.stream()
|
|
|
+ .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
+ Comparator.comparing(f -> f.getFeeId() + f.getCorpId() + f.getCurCode() + f.getDc()))), ArrayList::new));
|
|
|
+ List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
+ for (FeeCenter fee : feeCenters) {
|
|
|
+ FeeCenterReports feeCenterReports = new FeeCenterReports();
|
|
|
+ feeCenterReports.setRemarks(fee.getRemarks());
|
|
|
+ feeCenterReports.setPid(bills.getId());
|
|
|
+ feeCenterReports.setFeeCnName(fee.getFeeCnName());
|
|
|
+ feeCenterReports.setDc(fee.getDc());
|
|
|
+ List<FeeCenter> feeCenterListD = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountD(feeCenterListD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdD = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdD(feeCenterListUsdD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListUsdD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListC = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountC(feeCenterListC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdC = feeCenterList.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(bills.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdC(feeCenterListUsdC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListUsdC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ feeCenterReportList.add(feeCenterReports);
|
|
|
+ }
|
|
|
+ bills.setFeeCenterList(feeCenterReportList);
|
|
|
+ }
|
|
|
+ list.add(bills);
|
|
|
+ List<FeeCenter> feeCenterListMh = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
|
|
|
+ .eq(FeeCenter::getMblno, details.getMblno())
|
|
|
+ .eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
|
|
|
+ .eq(FeeCenter::getIsDeleted, 0));
|
|
|
+
|
|
|
+ allFeeCenter.addAll(feeCenterListMh);
|
|
|
+
|
|
|
+ List<FeeCenter> feeD2 = feeCenterListMh.stream().filter(e -> MagicValues.D.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ details.setFeeCenterListD(feeD2);
|
|
|
+ List<FeeCenter> feeC2 = feeCenterListMh.stream().filter(e -> MagicValues.C.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ details.setFeeCenterListC(feeC2);
|
|
|
+ for (FeeCenter item : feeCenterListMh) {
|
|
|
+ if (ObjectUtils.isNotNull(item.getShortName())) {
|
|
|
+ item.setCorpCnName(item.getShortName());
|
|
|
+ } else {
|
|
|
+ item.setCorpCnName("无");
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getBillShortName())) {
|
|
|
+ item.setBillCorpCnName(item.getBillShortName());
|
|
|
+ } else {
|
|
|
+ item.setBillCorpCnName("无");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterList1 = feeCenterListMh.stream()
|
|
|
+ .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
+ Comparator.comparing(f -> f.getFeeId() + f.getCorpId() + f.getCurCode() + f.getDc()))), ArrayList::new));
|
|
|
+ List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
+ for (FeeCenter fee : feeCenterList1) {
|
|
|
+ FeeCenterReports feeCenterReports = new FeeCenterReports();
|
|
|
+ feeCenterReports.setRemarks(fee.getRemarks());
|
|
|
+ feeCenterReports.setPid(details.getId());
|
|
|
+ feeCenterReports.setFeeCnName(fee.getFeeCnName());
|
|
|
+ feeCenterReports.setDc(fee.getDc());
|
|
|
+ List<FeeCenter> feeCenterListD = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(details.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountD(feeCenterListD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdD = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc()) && e.getMblno().equals(details.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdD.isEmpty()) {
|
|
|
+ feeCenterReports.setBillCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdD(feeCenterListUsdD.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocD(feeCenterListUsdD.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListC = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(details.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.CNY.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountC(feeCenterListC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ List<FeeCenter> feeCenterListUsdC = feeCenterListMh.stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc()) && e.getMblno().equals(details.getMblno()) &&
|
|
|
+ e.getFeeId().equals(fee.getFeeId()) && MagicValues.USD.equals(e.getCurCode()) && fee.getCurCode().equals(e.getCurCode()) &&
|
|
|
+ e.getCorpId().equals(fee.getCorpId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (!feeCenterListUsdC.isEmpty()) {
|
|
|
+ feeCenterReports.setCorpCnName(fee.getCorpCnName());
|
|
|
+ feeCenterReports.setAmountUsdC(feeCenterListUsdC.stream().map(FeeCenter::getAmount)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ feeCenterReports.setAmountLocC(feeCenterListUsdC.stream().map(FeeCenter::getAmountLoc)
|
|
|
+ .filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add));
|
|
|
+ }
|
|
|
+ feeCenterReportList.add(feeCenterReports);
|
|
|
+ }
|
|
|
+ details.setFeeCenterList(feeCenterReportList);
|
|
|
+ list.add(0, details);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!list.isEmpty()) {
|
|
|
+ for (Bills item : list) {
|
|
|
+ List<FeeCenterReports> feeCenterReports = new ArrayList<>();
|
|
|
+ // 应收
|
|
|
+ List<FeeCenterReports> feeCenterReportsD = item.getFeeCenterList().stream()
|
|
|
+ .filter(e -> MagicValues.D.equals(e.getDc())).collect(Collectors.toList()) == null ? new ArrayList<>() :
|
|
|
+ item.getFeeCenterList().stream().filter(e -> MagicValues.D.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ // 应付
|
|
|
+ List<FeeCenterReports> feeCenterReportsC = item.getFeeCenterList().stream()
|
|
|
+ .filter(e -> MagicValues.C.equals(e.getDc())).collect(Collectors.toList()) == null ? new ArrayList<>() :
|
|
|
+ item.getFeeCenterList().stream().filter(e -> MagicValues.C.equals(e.getDc())).collect(Collectors.toList());
|
|
|
+ // 排序
|
|
|
+ List<FeeCenterReports> feeCentersD = feeCenterReportsD.stream()
|
|
|
+ .collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
+ Comparator.comparing(e -> e.getFeeCnName() + e.getBillCorpCnName()))), ArrayList::new));
|
|
|
+ int countC = 0;
|
|
|
+ // 遍历应收,并与应付对应
|
|
|
+ for (int i = 0; i < feeCentersD.size(); i++) {
|
|
|
+ FeeCenterReports feeCenterReports1 = new FeeCenterReports();
|
|
|
+ feeCenterReports1.setFeeCnName(feeCentersD.get(i).getFeeCnName());
|
|
|
+ feeCenterReports1.setHblno(feeCentersD.get(i).getHblno());
|
|
|
+ feeCenterReports1.setPid(feeCentersD.get(i).getPid());
|
|
|
+ int finalI = i;
|
|
|
+ FeeCenterReports feeCenterC = feeCenterReportsC.stream()
|
|
|
+ .filter(e -> e.getFeeCnName().equals(feeCentersD.get(finalI).getFeeCnName()) && !"1".equals(e.getMark())).findFirst().orElse(null);
|
|
|
+ feeCenterReports1.setBillCorpCnName(feeCentersD.get(i).getBillCorpCnName());
|
|
|
+ feeCenterReports1.setAmountD(feeCentersD.get(i).getAmountD());
|
|
|
+ feeCenterReports1.setAmountLocD(feeCentersD.get(i).getAmountLocD());
|
|
|
+ feeCenterReports1.setAmountUsdD(feeCentersD.get(i).getAmountUsdD());
|
|
|
+ if (feeCenterC != null) {
|
|
|
+ feeCenterC.setMark("1");
|
|
|
+ feeCenterReports1.setCorpCnName(feeCenterC.getCorpCnName());
|
|
|
+ feeCenterReports1.setAmountC(feeCenterC.getAmountC());
|
|
|
+ feeCenterReports1.setAmountLocC(feeCenterC.getAmountLocC());
|
|
|
+ feeCenterReports1.setAmountUsdC(feeCenterC.getAmountUsdC());
|
|
|
+ countC++;
|
|
|
+ }
|
|
|
+ feeCenterReports.add(feeCenterReports1);
|
|
|
+ }
|
|
|
+ // 如果存在未对应的应付,添加应付费用
|
|
|
+ if (countC < feeCenterReportsC.size()) {
|
|
|
+ List<FeeCenterReports> feeCe = feeCenterReportsC.stream()
|
|
|
+ .filter(e -> !"1".equals(e.getMark())).collect(Collectors.toList());
|
|
|
+ for (FeeCenterReports i : feeCe) {
|
|
|
+ FeeCenterReports feeCenterReports1 = new FeeCenterReports();
|
|
|
+ feeCenterReports1.setCorpCnName(i.getCorpCnName());
|
|
|
+ feeCenterReports1.setFeeCnName(i.getFeeCnName());
|
|
|
+ feeCenterReports1.setHblno(i.getHblno());
|
|
|
+ feeCenterReports1.setPid(i.getPid());
|
|
|
+ feeCenterReports1.setAmountC(i.getAmountC());
|
|
|
+ feeCenterReports1.setAmountLocC(i.getAmountLocC());
|
|
|
+ feeCenterReports1.setAmountUsdC(i.getAmountUsdC());
|
|
|
+ feeCenterReports.add(feeCenterReports1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (ObjectUtils.isNotNull(item.getAmountProfitLoc()) && ObjectUtils.isNotNull(item.getAmountDrLoc())) {
|
|
|
+ if (item.getAmountProfitLoc().compareTo(new BigDecimal(MagicValues.ZERO)) == 0 ||
|
|
|
+ item.getAmountDrLoc().compareTo(new BigDecimal(MagicValues.ZERO)) == 0) {
|
|
|
+ item.setGrossMargin(new BigDecimal(MagicValues.ZERO));
|
|
|
+ } else {
|
|
|
+ item.setGrossMargin(item.getAmountProfitLoc().divide(item.getAmountDrLoc(), 4, RoundingMode.HALF_UP));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item.setGrossMargin(new BigDecimal(MagicValues.ZERO));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isDebug) {
|
|
|
+ System.out.println(item.getId().toString() + ", " + item.getBillNo() + ", GrossMargin: " + bills.getGrossMargin().toString());
|
|
|
+ }
|
|
|
+ // 费用名称
|
|
|
+ // 1722822288795000833 O/F 海运费 145
|
|
|
+ // 1722823384343011329 P/S P/S 220
|
|
|
+ // 1746015648988901393 HP/S HP/S 623
|
|
|
+ // 特殊 PS 客户名称
|
|
|
+ // 1425 W0077 W0077
|
|
|
+ // 1561 W0091 W0091
|
|
|
+ // 3415 W0256 W0256
|
|
|
+ // 5110 W0312 W0312
|
|
|
+ // 6363 W0380 W0380
|
|
|
+ // 10120 W0582 W0582
|
|
|
+ // 11794 W0643 W0643
|
|
|
+ // 12247 W0661 W0661
|
|
|
+ // 12431 W0675 W0675
|
|
|
+ // 12731 W0689 W0689
|
|
|
+ String specPScorpIds = ",1425,1561,3415,5110,6363,10120,11794,12247,12431,12731,";
|
|
|
+
|
|
|
+ List<FeeCenter> feeList = Stream.concat(item.getFeeCenterListD().stream(), item.getFeeCenterListC().stream()).collect(Collectors.toList());
|
|
|
+
|
|
|
+ BigDecimal usdOFProfit = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal ofInAmtProfit = new BigDecimal(BigInteger.ZERO);
|
|
|
+ Integer ofCNYCount = 0;
|
|
|
+
|
|
|
+ BigDecimal HPSProfit = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal specProfit = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal specInAmtProfit = new BigDecimal(BigInteger.ZERO);
|
|
|
+
|
|
|
+ BigDecimal psProfit = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal psInAmtProfit = new BigDecimal(BigInteger.ZERO);
|
|
|
+
|
|
|
+ // 特殊ps客户 Id
|
|
|
+ Long specPSCorpId = 0L;
|
|
|
+ // 高收退费客户 Id
|
|
|
+ Long hpsCorpId = 0L;
|
|
|
+
|
|
|
+ if (ObjectUtils.isNotNull(feeList)) {
|
|
|
+ for (FeeCenter fee : feeList) {
|
|
|
+ if (specPSCorpId == 0 && ObjectUtils.isNotNull(fee.getCorpId())) {
|
|
|
+ if (specPScorpIds.indexOf("," + fee.getCorpId().toString() + ",") >= 0) {
|
|
|
+ specPSCorpId = fee.getCorpId();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal amt = fee.getAmount();
|
|
|
+ if (MagicValues.C.equals(fee.getDc())) {
|
|
|
+ amt = amt.multiply(new BigDecimal(-1));
|
|
|
+ }
|
|
|
+ if (MagicValues.USD.equals(fee.getCurCode())) {
|
|
|
+ if ("O/F".equals(fee.getFeeCode())) {
|
|
|
+ // 145
|
|
|
+ usdOFProfit = usdOFProfit.add(amt);
|
|
|
+ }
|
|
|
+ if ("P/S".equals(fee.getFeeCode())) {
|
|
|
+ // 220
|
|
|
+ psProfit = psProfit.subtract(amt);
|
|
|
+ }
|
|
|
+ if ("HP/S".equals(fee.getFeeCode())) {
|
|
|
+ if (hpsCorpId == 0 && ObjectUtils.isNotNull(fee.getCorpId())) {
|
|
|
+ hpsCorpId = fee.getCorpId();
|
|
|
+ }
|
|
|
+ // 623
|
|
|
+ HPSProfit = HPSProfit.add(amt);
|
|
|
+ specProfit = specProfit.subtract(amt);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if ("O/F".equals(fee.getFeeCode())) {
|
|
|
+ // 145
|
|
|
+ ofInAmtProfit = ofInAmtProfit.add(amt.divide(new BigDecimal("6.8"), 2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ ofCNYCount += 1;
|
|
|
+ }
|
|
|
+ if ("P/S".equals(fee.getFeeCode())) {
|
|
|
+ // 220
|
|
|
+ psInAmtProfit = psInAmtProfit.add(amt);
|
|
|
+ }
|
|
|
+ if ("HP/S".equals(fee.getFeeCode())) {
|
|
|
+ if (hpsCorpId == 0 && ObjectUtils.isNotNull(fee.getCorpId())) {
|
|
|
+ hpsCorpId = fee.getCorpId();
|
|
|
+ }
|
|
|
+ // 623
|
|
|
+ specInAmtProfit = specInAmtProfit.subtract(amt);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取客户 PsRate
|
|
|
+ BCorps bCorps11 = bCorpsService.getById(item.getCorpId());
|
|
|
+ BigDecimal PsRate = new BigDecimal(BigInteger.ZERO);
|
|
|
+ Integer corpIsDC = 0;
|
|
|
+ if (ObjectUtils.isNotNull(bCorps11)) {
|
|
|
+ PsRate = new BigDecimal(bCorps11.getPsRate());
|
|
|
+ if (ObjectUtils.isNotNull(bCorps11.getCorpTypeName()) && bCorps11.getCorpTypeName().indexOf("国内直接客户") >= 0) {
|
|
|
+ corpIsDC = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ BigDecimal specPsRate = new BigDecimal(BigInteger.ZERO);
|
|
|
+ Boolean isPS = false;
|
|
|
+
|
|
|
+ if (specPSCorpId > 0) {
|
|
|
+ BCorps bCorps12 = bCorpsService.getById(specPSCorpId);
|
|
|
+ if (ObjectUtils.isNotNull(bCorps12)) {
|
|
|
+ specPsRate = new BigDecimal(bCorps12.getPsRate());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (hpsCorpId > 0) {
|
|
|
+ BCorps bCorps13 = bCorpsService.getById(hpsCorpId);
|
|
|
+ if (ObjectUtils.isNotNull(bCorps13)) {
|
|
|
+ Long ownerCorpId = ObjectUtils.isNotNull(bCorps13.getCorpId()) ? bCorps13.getCorpId() : 0L;
|
|
|
+ if (ownerCorpId > 0 && (ownerCorpId.equals(item.getCorpId()) || ownerCorpId.equals(item.getCarrierId()) || ownerCorpId.equals(hpsCorpId))) {
|
|
|
+ isPS = ObjectUtils.isNotNull(bCorps13.getIsPs()) && bCorps13.getIsPs() == 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String ps_text = ofCNYCount > 0 ? "(应收/应付)存在RMB海运费" : "";
|
|
|
+ String ps_remarks = "";
|
|
|
+ String ps_ps = "";
|
|
|
+ String ps_spec = "";
|
|
|
+
|
|
|
+ usdOFProfit = usdOFProfit.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ ofInAmtProfit = ofInAmtProfit.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ psInAmtProfit = psInAmtProfit.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ psProfit = psProfit.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ HPSProfit = HPSProfit.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ PsRate = PsRate.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ specPsRate = specPsRate.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ specProfit = specProfit.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ specInAmtProfit = specInAmtProfit.setScale(2, RoundingMode.HALF_UP);
|
|
|
+ if (psInAmtProfit.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ ps_remarks += " PS不能出现 RMB 费用\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ if ("CC".equals(item.getMpaymode()) && psProfit.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ ps_remarks += " 主单付费方式为CC 不能出现PS\r\n";
|
|
|
+ }
|
|
|
+
|
|
|
+ if (("PP".equals(item.getMpaymode()) && (MagicValues.DD.equals(item.getBillType()) || MagicValues.MM.equals(item.getBillType())))
|
|
|
+ || ("PP".equals(item.getMpaymode()) && ObjectUtils.isNotNull(item.getHblno()))) {
|
|
|
+ if (specPScorpIds.indexOf("," + specPSCorpId.toString() + ",") >= 0) {
|
|
|
+ if (usdOFProfit.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ BigDecimal tt1 = usdOFProfit.add(ofInAmtProfit).add(HPSProfit).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (tt1.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ BigDecimal pt1 = psProfit.divide(tt1, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (pt1.compareTo(specPsRate) > 0) {
|
|
|
+ BigDecimal psr1 = new BigDecimal(1).subtract(pt1).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ ps_remarks += " PS比例高,公司比例: " + psr1.toString() + " 系统比例为:" + specPsRate.toString() + "\r\n";
|
|
|
+ BigDecimal psr2 = new BigDecimal(1).subtract(specPsRate).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ ps_ps += "公司比例:" + psr1.toString() + " (" + psr2.toString() + ")\r\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (usdOFProfit.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ BigDecimal tt1 = usdOFProfit.add(ofInAmtProfit).add(HPSProfit).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (tt1.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ BigDecimal pt1 = psProfit.divide(tt1, 4, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (pt1.compareTo(PsRate) > 0) {
|
|
|
+ BigDecimal psr1 = new BigDecimal(1).subtract(pt1).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ ps_remarks += " PS比例高,公司比例: " + psr1.toString() + " 系统比例为:" + specPsRate.toString() + "\r\n";
|
|
|
+ BigDecimal psr2 = new BigDecimal(1).subtract(PsRate).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ ps_ps += "公司比例:" + psr1.toString() + " (" + psr2.toString() + ")\r\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (psProfit.compareTo(BigDecimal.ZERO) != 0) {
|
|
|
+ ps_remarks += "只有预付、直单和主单,或分单和到付才可以输入PS\r\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal tt2 = specProfit.add(specInAmtProfit).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ if (tt2.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ if (isPS == true) {
|
|
|
+ ps_spec += "存在高收退费\r\n";
|
|
|
+ } else {
|
|
|
+ ps_remarks += "不应该存在高收退费\r\n";
|
|
|
+ ps_spec += "不应该存在高收退费\r\n";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ ps_remarks = ps_remarks.trim();
|
|
|
+ ps_ps = ps_ps.trim();
|
|
|
+ item.setProfitStatus("");
|
|
|
+ item.setProfitRemarks(ps_remarks.trim());
|
|
|
+ item.setProfitSpec(ps_ps.trim() + "\r\n" + ps_spec.trim());
|
|
|
+ item.setText(ps_text);
|
|
|
+ item.setCorpIsDC(corpIsDC);
|
|
|
+ item.setIfDCCorp(corpIsDC == 1 ? "DC" : "");
|
|
|
+
|
|
|
+ // FOverFeeLimit:=Trim(GetSysConst('SEA_ISSUEBILL_OVERFEE_LIMIT', '100000'));
|
|
|
+ // 判断是否国内直客
|
|
|
+
|
|
|
+ BigDecimal sumUSDDr = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal sumCNYDr = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal sumLocDr = new BigDecimal(BigInteger.ZERO);
|
|
|
+
|
|
|
+ BigDecimal sumUSDCr = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal sumCNYCr = new BigDecimal(BigInteger.ZERO);
|
|
|
+ BigDecimal sumLocCr = new BigDecimal(BigInteger.ZERO);
|
|
|
+
|
|
|
+ BigDecimal sumOFPS = new BigDecimal(BigInteger.ZERO);
|
|
|
+ if (item.equals(bills)) {
|
|
|
+ // 当前单据,计算 ProfitStatus
|
|
|
+ for (FeeCenter fee : allFeeCenter) {
|
|
|
+ if (MagicValues.C.equals(fee.getDc()) && "P/S".equals(fee.getFeeCode())) {
|
|
|
+ // if("USD".equals(fee.getCurCode())){
|
|
|
+ sumOFPS = sumOFPS.add(fee.getAmountLoc()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (MagicValues.D.equals(fee.getDc())) {
|
|
|
+ if ("USD".equals(fee.getCurCode())) {
|
|
|
+ sumUSDDr = sumUSDDr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ } else {
|
|
|
+ sumCNYDr = sumCNYDr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ sumLocDr = sumLocDr.add(fee.getAmountLoc()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (MagicValues.C.equals(fee.getDc())) {
|
|
|
+ if ("USD".equals(fee.getCurCode())) {
|
|
|
+ sumUSDCr = sumUSDCr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ } else {
|
|
|
+ sumCNYCr = sumCNYCr.add(fee.getAmount()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ sumLocCr = sumLocCr.add(fee.getAmountLoc()).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ BigDecimal sumProfitUSD = sumUSDDr.subtract(sumUSDCr).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal sumProfitCNY = sumCNYDr.subtract(sumCNYCr).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal sumProfitLoc = sumLocDr.subtract(sumLocCr).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+
|
|
|
+ BigDecimal profitRate = new BigDecimal(BigInteger.ZERO);
|
|
|
+ if (sumLocDr.compareTo(BigDecimal.ZERO) == 1) {
|
|
|
+ profitRate = sumProfitLoc.divide(sumLocDr, 4, BigDecimal.ROUND_HALF_UP).setScale(4, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+
|
|
|
+ String profitStatus = "";
|
|
|
+ if (!ps_ps.isEmpty()) {
|
|
|
+ profitStatus = "U";
|
|
|
+ }
|
|
|
+ if (sumProfitLoc.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ profitStatus = "Z";
|
|
|
+ } else if (sumProfitLoc.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ profitStatus = "M";
|
|
|
+ } else if (sumLocDr.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (profitRate.compareTo(new BigDecimal("0.4")) >= 0) {
|
|
|
+ profitStatus = "H";
|
|
|
+ } else if (profitRate.compareTo(new BigDecimal("0.02")) < 0) {
|
|
|
+ profitStatus = "U".equals(profitStatus) ? "D" : "L";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ item.setProfitStatus(profitStatus);
|
|
|
+ //[IF([WFPK_ProfitStatus]='Z', 'Profit was zero!',
|
|
|
+ // IF([WFPK_ProfitStatus]='D', 'Profit was unfair and low !',
|
|
|
+ // IF([WFPK_ProfitStatus]='H', 'Profit was high!',
|
|
|
+ // if([WFPK_ProfitStatus]='L','Profit was low!',''))))]
|
|
|
+ //[IF([WFPK_ProfitStatus]='M', 'Profit was minus!',
|
|
|
+ // IF([WFPK_ProfitStatus]='U', 'P/S was unfair!', ''))]
|
|
|
+ switch (profitStatus) {
|
|
|
+ case "Z":
|
|
|
+ item.setProfitStatusText("利润为零");
|
|
|
+ item.setProfitStatusEnText("Profit was zero!");
|
|
|
+ break;
|
|
|
+ case "D":
|
|
|
+ item.setProfitStatusText("利润不成比例且过低");
|
|
|
+ item.setProfitStatusEnText("Profit was unfair and low!");
|
|
|
+ break;
|
|
|
+ case "H":
|
|
|
+ item.setProfitStatusText("利润过高");
|
|
|
+ item.setProfitStatusEnText("Profit was high!");
|
|
|
+ break;
|
|
|
+ case "L":
|
|
|
+ item.setProfitStatusText("利润过低");
|
|
|
+ item.setProfitStatusEnText("Profit was low!");
|
|
|
+ break;
|
|
|
+ case "F":
|
|
|
+ item.setProfitStatusText("利润正常");
|
|
|
+ item.setProfitStatusEnText("");
|
|
|
+ break;
|
|
|
+ case "M":
|
|
|
+ item.setProfitStatusText("利润为负");
|
|
|
+ item.setProfitStatusEnText("Profit was minus!");
|
|
|
+ break;
|
|
|
+ case "U":
|
|
|
+ item.setProfitStatusText("不成比例");
|
|
|
+ item.setProfitStatusEnText("P/S was unfair!");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ item.setProfitStatusText("");
|
|
|
+ item.setProfitStatusEnText("");
|
|
|
+ }
|
|
|
+ }
|
|
|
+// 'F':aAuditItem.RefNo2:='正常';
|
|
|
+// 'M':aAuditItem.RefNo2:='为负';
|
|
|
+// 'H':aAuditItem.RefNo2:='过高';
|
|
|
+// 'L':aAuditItem.RefNo2:='过低';
|
|
|
+// 'U':aAuditItem.RefNo2:='不成比例';
|
|
|
+// 'D':aAuditItem.RefNo2:='不成比例且过低';
|
|
|
+
|
|
|
+ String salesReportOverlimit = sysClient.getParamServiceNew(MagicValues.SALESREPORT_OVERLIMIT);
|
|
|
+ BigDecimal ro;
|
|
|
+ if (ObjectUtils.isNotNull(salesReportOverlimit)) {
|
|
|
+ try {
|
|
|
+ ro = new BigDecimal(salesReportOverlimit);
|
|
|
+ } catch (Exception e) {
|
|
|
+ ro = new BigDecimal(BigInteger.ZERO);
|
|
|
+ }
|
|
|
+ } else
|
|
|
+ ro = new BigDecimal(BigInteger.ZERO);
|
|
|
+ item.setOverFeeLimit(ro.setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+
|
|
|
+ /*
|
|
|
+ if (ObjectUtils.isNotNull(profitMargin)) {
|
|
|
+ BigDecimal margin = new BigDecimal(profitMargin).divide(new BigDecimal(MagicValues.HUNDRED), 2, RoundingMode.HALF_UP);
|
|
|
+ if (margin.compareTo(item.getGrossMargin()) > 0) {
|
|
|
+ item.setProfitMargin("Profit was low and unfair(DC)!");
|
|
|
+ BigDecimal amountD = feeCenterReports.stream().filter(e -> e.getFeeCnName().equals("海运费"))
|
|
|
+ .map(FeeCenterReports::getAmountD).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountC = feeCenterReports.stream().filter(e -> e.getFeeCnName().equals("海运费"))
|
|
|
+ .map(FeeCenterReports::getAmountC).filter(Objects::nonNull).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ if (new BigDecimal("0.00").compareTo((amountD.add(amountC))) == 0) {
|
|
|
+ item.setText("(应收/应付)存在RMB海运费");
|
|
|
+ }
|
|
|
+ String status = sysClient.getParamServiceNew("is.profit.margin");
|
|
|
+ if ("1".equals(status)) {
|
|
|
+ BigDecimal amountHYD = item.getFeeCenterList().stream()
|
|
|
+ .filter(e -> e.getFeeCnName().equals("海运费") && "D".equals(e.getDc()))
|
|
|
+ .map(FeeCenterReports::getAmountUsdD).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountHYC = item.getFeeCenterList().stream()
|
|
|
+ .filter(e -> e.getFeeCnName().equals("海运费") && "C".equals(e.getDc()))
|
|
|
+ .map(FeeCenterReports::getAmountUsdC).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountPSD = item.getFeeCenterList().stream()
|
|
|
+ .filter(e -> e.getFeeCnName().equals("PS") && "D".equals(e.getDc()))
|
|
|
+ .map(FeeCenterReports::getAmountUsdD).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BigDecimal amountPSC = item.getFeeCenterList().stream()
|
|
|
+ .filter(e -> e.getFeeCnName().equals("PS") && "C".equals(e.getDc()))
|
|
|
+ .map(FeeCenterReports::getAmountUsdC).reduce(BigDecimal.ZERO, BigDecimal::add);
|
|
|
+ BCorps bCorps = bCorpsService.getById(item.getCorpId());
|
|
|
+ BigDecimal PSAmount = amountPSC.subtract(amountPSD);
|
|
|
+ BigDecimal HYAmount = amountHYD.subtract(amountHYC);
|
|
|
+ BigDecimal rate = new BigDecimal("0.00");
|
|
|
+ if (PSAmount.compareTo(new BigDecimal("0.00")) != 0 && HYAmount.compareTo(new BigDecimal("0.00")) != 0) {
|
|
|
+ rate = PSAmount.divide(HYAmount, MathContext.DECIMAL32).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ if (new BigDecimal(bCorps.getPsRate()).compareTo(rate) > 0) {
|
|
|
+ item.setSharingRatio("公司实际分成比例:" + rate + "(" + bCorps.getPsRate() + ")");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item.setProfitMargin("");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ item.setProfitMargin("");
|
|
|
+ }
|
|
|
+ */
|
|
|
+ item.setFeeCenterList(feeCenterReports);
|
|
|
+ item.setDept(dept);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ map.put(MagicValues.DATA, list);
|
|
|
+ }
|
|
|
} else {
|
|
|
// 默认取单据数据,包括主表、预配箱、配箱、费用
|
|
|
Bills bills = billsService.getById(billId);
|
|
|
@@ -4662,7 +5560,8 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
|
|
|
/*List<FeeCenter> feeCenters = feeCenterList.stream()
|
|
|
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
Comparator.comparing(f -> f.getFeeId() + f.getCorpId() + f.getCurCode() + f.getReportType()))), ArrayList::new));
|
|
|
- */List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
+ */
|
|
|
+ List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
for (FeeCenter fee : feeCenterList) {
|
|
|
FeeCenterReports feeCenterReports = new FeeCenterReports();
|
|
|
feeCenterReports.setRemarks(fee.getRemarks());
|
|
|
@@ -4827,7 +5726,8 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
|
|
|
/*List<FeeCenter> feeCenters = feeCenterList.stream()
|
|
|
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
Comparator.comparing(f -> f.getFeeId() + f.getCorpId() + f.getCurCode() + f.getReportType()))), ArrayList::new));
|
|
|
- */List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
+ */
|
|
|
+ List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
for (FeeCenter fee : feeCenterList) {
|
|
|
FeeCenterReports feeCenterReports = new FeeCenterReports();
|
|
|
feeCenterReports.setRemarks(fee.getRemarks());
|
|
|
@@ -4988,7 +5888,8 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
|
|
|
/*List<FeeCenter> feeCenterList1 = feeCenterListMh.stream()
|
|
|
.collect(Collectors.collectingAndThen(Collectors.toCollection(() -> new TreeSet<>(
|
|
|
Comparator.comparing(f -> f.getFeeId() + f.getCorpId() + f.getCurCode() + f.getReportType()))), ArrayList::new));
|
|
|
- */List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
+ */
|
|
|
+ List<FeeCenterReports> feeCenterReportList = new ArrayList<>();
|
|
|
for (FeeCenter fee : feeCenterListMh) {
|
|
|
FeeCenterReports feeCenterReports = new FeeCenterReports();
|
|
|
feeCenterReports.setRemarks(fee.getRemarks());
|