优化客户和供应商的对账单

This commit is contained in:
季圣华
2021-07-08 00:11:56 +08:00
parent a4cf56d631
commit 1149ada422
8 changed files with 91 additions and 186 deletions

View File

@@ -6,14 +6,17 @@ import com.jsh.erp.constants.BusinessConstants;
import com.jsh.erp.constants.ExceptionConstants;
import com.jsh.erp.datasource.entities.DepotHead;
import com.jsh.erp.datasource.entities.DepotHeadVo4Body;
import com.jsh.erp.datasource.entities.Supplier;
import com.jsh.erp.datasource.vo.DepotHeadVo4InDetail;
import com.jsh.erp.datasource.vo.DepotHeadVo4InOutMCount;
import com.jsh.erp.datasource.vo.DepotHeadVo4List;
import com.jsh.erp.datasource.vo.DepotHeadVo4StatementAccount;
import com.jsh.erp.exception.BusinessParamCheckingException;
import com.jsh.erp.service.accountHead.AccountHeadService;
import com.jsh.erp.service.depotHead.DepotHeadService;
import com.jsh.erp.service.log.LogService;
import com.jsh.erp.service.redis.RedisService;
import com.jsh.erp.service.supplier.SupplierService;
import com.jsh.erp.utils.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,6 +47,12 @@ public class DepotHeadController {
@Resource
private DepotHeadService depotHeadService;
@Resource
private AccountHeadService accountHeadService;
@Resource
private SupplierService supplierService;
@Resource
private RedisService redisService;
@@ -187,69 +196,27 @@ public class DepotHeadController {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
int j = 1;
if (supType.equals("客户")) { //客户
j = 1;
} else if (supType.equals("供应商")) { //供应商
j = -1;
}
beginTime = Tools.parseDayToTime(beginTime,BusinessConstants.DAY_FIRST_TIME);
endTime = Tools.parseDayToTime(endTime,BusinessConstants.DAY_LAST_TIME);
List<DepotHeadVo4StatementAccount> resList = new ArrayList<DepotHeadVo4StatementAccount>();
List<DepotHeadVo4StatementAccount> list = depotHeadService.findStatementAccount(beginTime, endTime, organId, supType, (currentPage-1)*pageSize, pageSize);
int total = depotHeadService.findStatementAccountCount(beginTime, endTime, organId, supType);
map.put("rows", list);
map.put("total", total);
//存放数据json数组
if (null != list) {
for (DepotHeadVo4StatementAccount dha : list) {
dha.setNumber(dha.getNumber()); //单据编号
dha.setType(dha.getType()); //类型
String type = dha.getType();
BigDecimal p1 = BigDecimal.ZERO ;
BigDecimal p2 = BigDecimal.ZERO;
if (dha.getDiscountLastMoney() != null) {
p1 = dha.getDiscountLastMoney();
}
if (dha.getChangeAmount() != null) {
p2 = dha.getChangeAmount();
}
BigDecimal allPrice = BigDecimal.ZERO;
if ((p1.compareTo(BigDecimal.ZERO))==-1) {
p1 = p1.abs();
}
if(dha.getOtherMoney()!=null) {
p1 = p1.add(dha.getOtherMoney()); //与其它费用相加
}
if ((p2 .compareTo(BigDecimal.ZERO))==-1) {
p2 = p2.abs();
}
if (type.equals("采购入库")) {
allPrice = p2.subtract(p1);
} else if (type.equals("销售退货入库")) {
allPrice = p2.subtract(p1);
} else if (type.equals("销售出库")) {
allPrice = p1.subtract(p2);
} else if (type.equals("采购退货出库")) {
allPrice = p1.subtract(p2);
} else if (type.equals("收款")) {
allPrice = BigDecimal.ZERO.subtract(p1);
} else if (type.equals("付款")) {
allPrice = p1;
} else if (type.equals("收入")) {
allPrice = p1.subtract(p2);
} else if (type.equals("支出")) {
allPrice = p2.subtract(p1);
}
dha.setBillMoney(p1); //单据金额
dha.setChangeAmount(p2); //实际支付
DecimalFormat df = new DecimalFormat(".##");
dha.setAllPrice(new BigDecimal(df.format(allPrice.multiply(new BigDecimal(j))))); //本期变化
dha.setSupplierName(dha.getSupplierName()); //单位名称
dha.setoTime(dha.getoTime()); //单据日期
resList.add(dha);
if(null!=organId) {
Supplier supplier = supplierService.getSupplier(organId);
BigDecimal beginNeed = BigDecimal.ZERO;
if (("客户").equals(supType)) {
beginNeed = supplier.getBeginNeedGet();
} else if (("供应商").equals(supType)) {
beginNeed = supplier.getBeginNeedPay();
}
BigDecimal firstMoney = depotHeadService.findTotalPay(organId, beginTime, supType)
.add(accountHeadService.findTotalPay(organId, beginTime, supType)).add(beginNeed);
BigDecimal lastMoney = depotHeadService.findTotalPay(organId, endTime, supType)
.add(accountHeadService.findTotalPay(organId, endTime, supType)).add(beginNeed);
map.put("firstMoney", firstMoney); //期初
map.put("lastMoney", lastMoney); //期末
}
map.put("rows", resList);
res.code = 200;
res.data = map;
} catch(Exception e){
@@ -260,37 +227,6 @@ public class DepotHeadController {
return res;
}
/**
* 查询单位的累计应收和累计应付,零售不能计入
* @param supplierId
* @param endTime
* @param supType
* @param request
* @return
*/
@GetMapping(value = "/findTotalPay")
public BaseResponseInfo findTotalPay(@RequestParam("supplierId") Integer supplierId,
@RequestParam("endTime") String endTime,
@RequestParam("supType") String supType,
HttpServletRequest request)throws Exception {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
JSONObject outer = new JSONObject();
endTime = endTime + BusinessConstants.DAY_LAST_TIME;
BigDecimal sum = depotHeadService.findTotalPay(supplierId, endTime, supType);
outer.put("getAllMoney", sum);
map.put("rows", outer);
res.code = 200;
res.data = map;
} catch (Exception e) {
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 根据编号查询单据信息
* @param number