Browse Source

Sales Report

wfg 1 year ago
parent
commit
e583b79f3c

+ 48 - 0
blade-service-api/blade-los-api/src/main/java/org/springblade/los/business/sea/entity/Bills.java

@@ -1666,6 +1666,54 @@ public class Bills implements Serializable {
 	private String sharingRatio;
 
 	/**
+	 * 销售报告利润状态
+	 */
+	@TableField(exist = false)
+	private String profitStatus;
+
+	/**
+	 * 销售报告利润状态
+	 */
+	@TableField(exist = false)
+	private String profitStatusText;
+
+	/**
+	 * 销售报告利润状态
+	 */
+	@TableField(exist = false)
+	private String profitStatusEnText;
+
+	/**
+	 * 是否国内直接客户, 0 = 否 1 = 是
+	 */
+	@TableField(exist = false)
+	private Integer corpIsDC;
+
+	/**
+	 * 销售报告利润状态
+	 */
+	@TableField(exist = false)
+	private BigDecimal overFeeLimit;
+
+	/**
+	 * 销售报告利润状态
+	 */
+	@TableField(exist = false)
+	private String ifDCCorp;
+
+	/**
+	 * 销售报告利润状态
+	 */
+	@TableField(exist = false)
+	private String profitRemarks;
+
+	/**
+	 * 销售报告利润状态
+	 */
+	@TableField(exist = false)
+	private String profitSpec;
+
+	/**
 	 * 是否存在RMB海运费
 	 */
 	@TableField(exist = false)

+ 1 - 0
blade-service/blade-los/src/main/java/org/springblade/los/Util/MagicValues.java

@@ -71,6 +71,7 @@ public class MagicValues {
 	public static final String MM = "MM";
 	public static final String DD = "DD";
 	public static final String PROFIT_MARGIN = "profit.margin";
+	public static final String SALESREPORT_OVERLIMIT = "salesReport.overlimit";
 	public static final String FM = "JMS";
 	public static final String DATA = "data";
 

+ 362 - 0
blade-service/blade-los/src/main/java/org/springblade/los/basic/reports/service/impl/ReportsServiceImpl.java

@@ -78,6 +78,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.math.MathContext;
 import java.math.RoundingMode;
 import java.util.*;
@@ -85,6 +86,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import java.util.function.Function;
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * 基础资料-报表管理 服务实现类
@@ -5979,6 +5981,10 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 		if (ObjectUtils.isNull(billId)) {
 			throw new RuntimeException("缺少比要参数");
 		}
+
+		// String debug = System.getProperty("java.debug");
+		boolean isDebug = true; // (debug != null && debug.toLowerCase().startsWith("true"));
+
 		R<Dept> res = sysClient.getDept(deptUtils.getDeptPid());
 		Dept dept;
 		if (res.isSuccess() && res.getData() != null) {
@@ -6000,6 +6006,7 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 			.eq(BCurrency::getTenantId, AuthUtil.getTenantId())
 			.eq(BCurrency::getIsDeleted, 0)
 			.eq(BCurrency::getCode, MagicValues.USD));
+		// 销售报告 SALES REPORT
 		if (MagicValues.BUSINESS.equals(reportCode) && MagicValues.SALES_REPORT.equals(groupCode) && (MagicValues.HYCK.equals(type) || MagicValues.HYJK.equals(type))) {
 			List<Bills> list = new ArrayList<>();
 			String profitMargin = sysClient.getParamServiceNew(MagicValues.PROFIT_MARGIN);
@@ -6009,6 +6016,7 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 				if (biz.isSuccess()) {
 					bills.setSrcType(biz.getData());
 				}
+				// 提取分表
 				SeaBillsDetail seaBillsDetail = seaBillsDetailService.getOne(new LambdaQueryWrapper<SeaBillsDetail>()
 					.eq(SeaBillsDetail::getTenantId, AuthUtil.getTenantId())
 					.eq(SeaBillsDetail::getPid, bills.getId()));
@@ -6063,11 +6071,13 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 					bills.setMnotify2Details(seaBillsDetail.getMnotify2Details());
 					bills.setMforwarderDetails(seaBillsDetail.getMforwarderDetails());
 				}
+				// 提取 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) {
@@ -6078,6 +6088,14 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 				} 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())
@@ -6086,6 +6104,7 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 					if (!billsList.isEmpty()) {
 						List<Long> ids = billsList.stream().map(Bills::getId).filter(Objects::nonNull).collect(Collectors.toList());
 						if (!ids.isEmpty()) {
+							// 所有分单的费用
 							List<FeeCenter> feeCenterListMh = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
 								.in(FeeCenter::getPid, ids)
 								.eq(FeeCenter::getTenantId, AuthUtil.getTenantId())
@@ -6093,6 +6112,7 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 							if (feeCenterListMh.isEmpty()) {
 								throw new RuntimeException("请先维护费用信息");
 							}
+							allFeeCenter.addAll(feeCenterListMh);
 							for (FeeCenter item : feeCenterListMh) {
 								if (ObjectUtils.isNotNull(item.getShortName())) {
 									item.setCorpCnName(item.getShortName());
@@ -6106,6 +6126,10 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 								}
 							}
 							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));
@@ -6171,10 +6195,18 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 							}
 						}
 					}
+					// 当前单据的费用信息
 					List<FeeCenter> feeCenterList = feeCenterService.list(new LambdaQueryWrapper<FeeCenter>()
 						.eq(FeeCenter::getPid, bills.getId())
 						.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());
@@ -6254,6 +6286,7 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 					}
 					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())
@@ -6266,6 +6299,11 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 						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())) {
@@ -6346,6 +6384,13 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 							.eq(FeeCenter::getPid, details.getId())
 							.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());
@@ -6425,16 +6470,20 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 				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());
@@ -6457,6 +6506,7 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 							}
 							feeCenterReports.add(feeCenterReports1);
 						}
+						// 如果存在未对应的应付,添加应付费用
 						if (countC < feeCenterReportsC.size()) {
 							List<FeeCenterReports> feeCe = feeCenterReportsC.stream()
 								.filter(e -> !"1".equals(e.getMark())).collect(Collectors.toList());
@@ -6482,6 +6532,317 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 						} 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);
+
+						//   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);
+
+							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 "F":
+									item.setProfitStatusText("利润正常");
+									item.setProfitStatusEnText("");
+									break;
+								case "M":
+									item.setProfitStatusText("利润为负");
+									item.setProfitStatusEnText("");
+									break;
+								case "U":
+									item.setProfitStatusText("不成比例");
+									item.setProfitStatusEnText("");
+									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) {
@@ -6524,6 +6885,7 @@ public class ReportsServiceImpl extends ServiceImpl<ReportsMapper, Reports> impl
 						} else {
 							item.setProfitMargin("");
 						}
+						*/
 						item.setFeeCenterList(feeCenterReports);
 						item.setDept(dept);
 					}