1、修改double类型为BigDecimal

2、修复sql中大于小于少&出错的问题
This commit is contained in:
cjl
2019-01-17 15:56:25 +08:00
61 changed files with 24893 additions and 24820 deletions

View File

@@ -1,141 +1,142 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.Account;
import com.jsh.erp.datasource.vo.AccountVo4InOutList;
import com.jsh.erp.service.account.AccountService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author jishenghua 75271*8920
*/
@RestController
@RequestMapping(value = "/account")
public class AccountController {
private Logger logger = LoggerFactory.getLogger(AccountController.class);
@Resource
private AccountService accountService;
/**
* 查找结算账户信息-下拉框
* @param request
* @return
*/
@GetMapping(value = "/findBySelect")
public String findBySelect(HttpServletRequest request) {
String res = null;
try {
List<Account> dataList = accountService.findBySelect();
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (Account account : dataList) {
JSONObject item = new JSONObject();
item.put("Id", account.getId());
//结算账户名称
item.put("AccountName", account.getName());
dataArray.add(item);
}
}
res = dataArray.toJSONString();
} catch(Exception e){
e.printStackTrace();
res = "获取数据失败";
}
return res;
}
/**
* 获取所有结算账户
* @param request
* @return
*/
@GetMapping(value = "/getAccount")
public BaseResponseInfo getAccount(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<Account> accountList = accountService.getAccount();
map.put("accountList", accountList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 账户流水信息
* @param currentPage
* @param pageSize
* @param accountId
* @param initialAmount
* @param request
* @return
*/
@GetMapping(value = "/findAccountInOutList")
public BaseResponseInfo findAccountInOutList(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("accountId") Long accountId,
@RequestParam("initialAmount") Double initialAmount,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<AccountVo4InOutList> dataList = accountService.findAccountInOutList(accountId, (currentPage-1)*pageSize, pageSize);
int total = accountService.findAccountInOutListCount(accountId);
map.put("total", total);
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (AccountVo4InOutList aEx : dataList) {
String timeStr = aEx.getOperTime().toString();
Double balance = accountService.getAccountSum(accountId, timeStr, "date") + accountService.getAccountSumByHead(accountId, timeStr, "date")
+ accountService.getAccountSumByDetail(accountId, timeStr, "date") + accountService.getManyAccountSum(accountId, timeStr, "date") + initialAmount;
aEx.setBalance(balance);
dataArray.add(aEx);
}
}
map.put("rows", dataArray);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
@PostMapping(value = "/updateAmountIsDefault")
public String updateAmountIsDefault(@RequestParam("isDefault") Boolean isDefault,
@RequestParam("accountId") Long accountId,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = accountService.updateAmountIsDefault(isDefault, accountId);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
}
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.Account;
import com.jsh.erp.datasource.vo.AccountVo4InOutList;
import com.jsh.erp.service.account.AccountService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author jishenghua 75271*8920
*/
@RestController
@RequestMapping(value = "/account")
public class AccountController {
private Logger logger = LoggerFactory.getLogger(AccountController.class);
@Resource
private AccountService accountService;
/**
* 查找结算账户信息-下拉框
* @param request
* @return
*/
@GetMapping(value = "/findBySelect")
public String findBySelect(HttpServletRequest request) {
String res = null;
try {
List<Account> dataList = accountService.findBySelect();
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (Account account : dataList) {
JSONObject item = new JSONObject();
item.put("Id", account.getId());
//结算账户名称
item.put("AccountName", account.getName());
dataArray.add(item);
}
}
res = dataArray.toJSONString();
} catch(Exception e){
e.printStackTrace();
res = "获取数据失败";
}
return res;
}
/**
* 获取所有结算账户
* @param request
* @return
*/
@GetMapping(value = "/getAccount")
public BaseResponseInfo getAccount(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<Account> accountList = accountService.getAccount();
map.put("accountList", accountList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 账户流水信息
* @param currentPage
* @param pageSize
* @param accountId
* @param initialAmount
* @param request
* @return
*/
@GetMapping(value = "/findAccountInOutList")
public BaseResponseInfo findAccountInOutList(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("accountId") Long accountId,
@RequestParam("initialAmount") BigDecimal initialAmount,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<AccountVo4InOutList> dataList = accountService.findAccountInOutList(accountId, (currentPage-1)*pageSize, pageSize);
int total = accountService.findAccountInOutListCount(accountId);
map.put("total", total);
//存放数据json数组
JSONArray dataArray = new JSONArray();
if (null != dataList) {
for (AccountVo4InOutList aEx : dataList) {
String timeStr = aEx.getOperTime().toString();
BigDecimal balance = accountService.getAccountSum(accountId, timeStr, "date").add(accountService.getAccountSumByHead(accountId, timeStr, "date"))
.add(accountService.getAccountSumByDetail(accountId, timeStr, "date")).add(accountService.getManyAccountSum(accountId, timeStr, "date")).add(initialAmount);
aEx.setBalance(balance);
dataArray.add(aEx);
}
}
map.put("rows", dataArray);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
@PostMapping(value = "/updateAmountIsDefault")
public String updateAmountIsDefault(@RequestParam("isDefault") Boolean isDefault,
@RequestParam("accountId") Long accountId,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = accountService.updateAmountIsDefault(isDefault, accountId);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
}

View File

@@ -12,6 +12,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -69,7 +70,7 @@ public class AccountHeadController {
Map<String, Object> map = new HashMap<String, Object>();
try {
JSONObject outer = new JSONObject();
Double sum = 0.0;
BigDecimal sum = BigDecimal.ZERO;
String getS = supplierId.toString();
int i = 1;
if (supType.equals("customer")) { //客户
@@ -78,10 +79,14 @@ public class AccountHeadController {
i = -1;
}
//收付款部分
sum = sum + (allMoney(getS, "付款", "合计",endTime) + allMoney(getS, "付款", "实际",endTime)) * i;
sum = sum - (allMoney(getS, "", "合计",endTime) + allMoney(getS, "", "实际",endTime)) * i;
sum = sum + (allMoney(getS, "收入", "合计",endTime) - allMoney(getS, "收入", "实际",endTime)) * i;
sum = sum - (allMoney(getS, "支出", "合计",endTime) - allMoney(getS, "支出", "实际",endTime)) * i;
// sum = sum + (allMoney(getS, "付款", "合计",endTime) + allMoney(getS, "付款", "实际",endTime)) * i;
sum = sum.add((allMoney(getS, "", "合计",endTime).add(allMoney(getS, "", "实际",endTime))).multiply(new BigDecimal(i)));
// sum = sum - (allMoney(getS, "收款", "合计",endTime) + allMoney(getS, "收款", "实际",endTime)) * i;
sum = sum.subtract((allMoney(getS, "收款", "合计",endTime).add(allMoney(getS, "收款", "实际",endTime))).multiply(new BigDecimal(i)));
// sum = sum + (allMoney(getS, "收入", "合计",endTime) - allMoney(getS, "收入", "实际",endTime)) * i;
sum = sum.add((allMoney(getS, "收入", "合计",endTime).subtract(allMoney(getS, "收入", "实际",endTime))).multiply(new BigDecimal(i)));
// sum = sum - (allMoney(getS, "支出", "合计",endTime) - allMoney(getS, "支出", "实际",endTime)) * i;
sum = sum.subtract((allMoney(getS, "支出", "合计",endTime).subtract(allMoney(getS, "支出", "实际",endTime))).multiply(new BigDecimal(i)));
outer.put("getAllMoney", sum);
map.put("rows", outer);
res.code = 200;
@@ -128,11 +133,11 @@ public class AccountHeadController {
* @param endTime
* @return
*/
public Double allMoney(String getS, String type, String mode, String endTime) {
Double allMoney = 0.0;
public BigDecimal allMoney(String getS, String type, String mode, String endTime) {
BigDecimal allMoney = BigDecimal.ZERO;
try {
Integer supplierId = Integer.valueOf(getS);
Double sum = accountHeadService.findAllMoney(supplierId, type, mode, endTime);
BigDecimal sum = accountHeadService.findAllMoney(supplierId, type, mode, endTime);
if(sum != null) {
allMoney = sum;
}
@@ -140,8 +145,8 @@ public class AccountHeadController {
e.printStackTrace();
}
//返回正数,如果负数也转为正数
if (allMoney < 0) {
allMoney = -allMoney;
if ((allMoney.compareTo(BigDecimal.ZERO))==-1) {
allMoney = allMoney.abs();
}
return allMoney;
}

View File

@@ -15,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -86,8 +87,8 @@ public class AccountItemController {
item.put("AccountName", ai.getAccountName());
item.put("InOutItemId", ai.getInoutitemid());
item.put("InOutItemName", ai.getInOutItemName());
Double eachAmount = ai.getEachamount();
item.put("EachAmount", eachAmount < 0 ? 0 - eachAmount : eachAmount);
BigDecimal eachAmount = ai.getEachamount();
item.put("EachAmount", (eachAmount.compareTo(BigDecimal.ZERO))==-1 ? BigDecimal.ZERO.subtract(eachAmount): eachAmount);
item.put("Remark", ai.getRemark());
dataArray.add(item);
}

View File

@@ -1,461 +1,468 @@
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.DepotHead;
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.service.depotHead.DepotHeadService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji-sheng-hua 752*718*920
*/
@RestController
@RequestMapping(value = "/depotHead")
public class DepotHeadController {
private Logger logger = LoggerFactory.getLogger(DepotHeadController.class);
@Resource
private DepotHeadService depotHeadService;
/**
* 批量设置状态-审核或者反审核
* @param status
* @param depotHeadIDs
* @param request
* @return
*/
@PostMapping(value = "/batchSetStatus")
public String batchSetStatus(@RequestParam("status") Boolean status,
@RequestParam("depotHeadIDs") String depotHeadIDs,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = depotHeadService.batchSetStatus(status, depotHeadIDs);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 单据编号生成接口规则查找当前类型单据下的当天最大的单据号并加1
* @param type
* @param subType
* @param beginTime
* @param endTime
* @param request
* @return
*/
@GetMapping(value = "/buildNumber")
public BaseResponseInfo buildNumber(@RequestParam("type") String type,
@RequestParam("subType") String subType,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
String number = depotHeadService.buildNumber(type, subType, beginTime, endTime);
map.put("DefaultNumber", number);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 获取最大的id
* @param request
* @return
*/
@GetMapping(value = "/getMaxId")
public BaseResponseInfo getMaxId(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
Long maxId = depotHeadService.getMaxId();
map.put("maxId", maxId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查找单据_根据月份(报表)
* @param monthTime
* @param request
* @return
*/
@GetMapping(value = "/findByMonth")
public BaseResponseInfo findByMonth(@RequestParam("monthTime") String monthTime,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHead> dataList = depotHeadService.findByMonth(monthTime);
String headId = "";
if (null != dataList) {
for (DepotHead depotHead : dataList) {
headId = headId + depotHead.getId() + ",";
}
}
if (headId != "") {
headId = headId.substring(0, headId.lastIndexOf(","));
}
map.put("HeadIds", headId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查找统计信息_根据礼品卡(报表)
* @param projectId
* @param request
* @return
*/
@GetMapping(value = "/findGiftReport")
public BaseResponseInfo findGiftReport(@RequestParam("projectId") String projectId,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHead> dataList_in = depotHeadService.getDepotHead();
String headId = "";
if (null != dataList_in) {
for (DepotHead depotHead : dataList_in) {
headId = headId + depotHead.getId() + ",";
}
List<DepotHead> dataList_out = depotHeadService.getDepotHeadGiftOut(projectId);
if (null != dataList_out) {
for (DepotHead depotHead : dataList_out) {
headId = headId + depotHead.getId() + ",";
}
}
}
if (headId != "") {
headId = headId.substring(0, headId.lastIndexOf(","));
}
map.put("HeadIds", headId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 入库出库明细接口
* @param currentPage
* @param pageSize
* @param oId
* @param pid
* @param dids
* @param beginTime
* @param endTime
* @param type
* @param request
* @return
*/
@GetMapping(value = "/findInDetail")
public BaseResponseInfo findInDetail(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("organId") Integer oId,
@RequestParam("projectId") Integer pid,
@RequestParam("depotIds") String dids,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
@RequestParam("type") String type,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHeadVo4InDetail> resList = new ArrayList<DepotHeadVo4InDetail>();
List<DepotHeadVo4InDetail> list = depotHeadService.findByAll(beginTime, endTime, type, pid, dids, oId, currentPage, pageSize);
int total = depotHeadService.findByAllCount(beginTime, endTime, type, pid, dids, oId);
map.put("total", total);
//存放数据json数组
if (null != list) {
for (DepotHeadVo4InDetail dhd : list) {
resList.add(dhd);
}
}
map.put("rows", resList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 入库出库统计接口
* @param currentPage
* @param pageSize
* @param oId
* @param pid
* @param dids
* @param beginTime
* @param endTime
* @param type
* @param request
* @return
*/
@GetMapping(value = "/findInOutMaterialCount")
public BaseResponseInfo findInOutMaterialCount(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("organId") Integer oId,
@RequestParam("projectId") Integer pid,
@RequestParam("depotIds") String dids,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
@RequestParam("type") String type,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHeadVo4InOutMCount> resList = new ArrayList<DepotHeadVo4InOutMCount>();
List<DepotHeadVo4InOutMCount> list = depotHeadService.findInOutMaterialCount(beginTime, endTime, type, pid, dids, oId, currentPage, pageSize);
int total = depotHeadService.findInOutMaterialCountTotal(beginTime, endTime, type, pid, dids, oId);
map.put("total", total);
//存放数据json数组
if (null != list) {
for (DepotHeadVo4InOutMCount dhc : list) {
resList.add(dhc);
}
}
map.put("rows", resList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 对账单接口
* @param currentPage
* @param pageSize
* @param beginTime
* @param endTime
* @param organId
* @param supType
* @param request
* @return
*/
@GetMapping(value = "/findStatementAccount")
public BaseResponseInfo findStatementAccount(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
@RequestParam("organId") Integer organId,
@RequestParam("supType") String supType,
HttpServletRequest request) {
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;
}
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("total", total);
//存放数据json数组
if (null != list) {
for (DepotHeadVo4StatementAccount dha : list) {
dha.setNumber(dha.getNumber()); //单据编号
dha.setType(dha.getType()); //类型
String type = dha.getType();
Double p1 = 0.0;
Double p2 = 0.0;
if (dha.getDiscountLastMoney() != null) {
p1 = dha.getDiscountLastMoney();
}
if (dha.getChangeAmount() != null) {
p2 = dha.getChangeAmount();
}
Double allPrice = 0.0;
if (p1 < 0) {
p1 = -p1;
}
if (p2 < 0) {
p2 = -p2;
}
if (type.equals("采购入库")) {
allPrice = -(p1 - p2);
} else if (type.equals("销售退货入库")) {
allPrice = -(p1 - p2);
} else if (type.equals("销售")) {
allPrice = p1 - p2;
} else if (type.equals("采购退货出库")) {
allPrice = p1 - p2;
} else if (type.equals("付款")) {
allPrice = p1 + p2;
} else if (type.equals("")) {
allPrice = -(p1 + p2);
} else if (type.equals("")) {
allPrice = p1 - p2;
} else if (type.equals("支出")) {
allPrice = -(p1 - p2);
}
dha.setDiscountLastMoney(p1); //金额
dha.setChangeAmount(p2); //金额
dha.setAllPrice(Double.parseDouble(String.format("%.2f", allPrice * j))); //计算后的金额
dha.setSupplierName(dha.getSupplierName()); //供应商
dha.setoTime(dha.getoTime()); //入库出库日期
resList.add(dha);
}
}
map.put("rows", resList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
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) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
JSONObject outer = new JSONObject();
Double sum = 0.0;
String getS = supplierId.toString();
int i = 1;
if (supType.equals("customer")) { //客户
i = 1;
} else if (supType.equals("vendor")) { //供应商
i = -1;
}
//进销部分
sum = sum - (allMoney(getS, "入库", "采购", "合计",endTime) - allMoney(getS, "入库", "采购", "实际",endTime)) * i;
sum = sum - (allMoney(getS, "入库", "销售退货", "合计",endTime) - allMoney(getS, "入库", "销售退货", "实际",endTime)) * i;
sum = sum + (allMoney(getS, "出库", "销售", "合计",endTime) - allMoney(getS, "出库", "销售", "实际",endTime)) * i;
sum = sum + (allMoney(getS, "出库", "采购退货", "合计",endTime) - allMoney(getS, "出库", "采购退货", "实际",endTime)) * i;
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
* @param request
* @return
*/
@GetMapping(value = "/getDetailByNumber")
public BaseResponseInfo getDetailByNumber(@RequestParam("number") String number,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
DepotHeadVo4List dhl = new DepotHeadVo4List();
try {
List<DepotHeadVo4List> list = depotHeadService.getDetailByNumber(number);
if(list.size() == 1) {
dhl = list.get(0);
}
res.code = 200;
res.data = dhl;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 统计总金额
* @param getS
* @param type
* @param subType
* @param mode 合计或者金额
* @return
*/
public Double allMoney(String getS, String type, String subType, String mode, String endTime) {
Double allMoney = 0.0;
try {
Integer supplierId = Integer.valueOf(getS);
Double sum = depotHeadService.findAllMoney(supplierId, type, subType, mode, endTime);
if(sum != null) {
allMoney = sum;
}
} catch (Exception e) {
e.printStackTrace();
}
//返回正数,如果负数也转为正数
if (allMoney < 0) {
allMoney = -allMoney;
}
return allMoney;
}
}
package com.jsh.erp.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jsh.erp.datasource.entities.DepotHead;
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.service.depotHead.DepotHeadService;
import com.jsh.erp.utils.BaseResponseInfo;
import com.jsh.erp.utils.ErpInfo;
import com.jsh.erp.utils.StringUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.sql.Date;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static com.jsh.erp.utils.ResponseJsonUtil.returnJson;
/**
* @author ji-sheng-hua 752*718*920
*/
@RestController
@RequestMapping(value = "/depotHead")
public class DepotHeadController {
private Logger logger = LoggerFactory.getLogger(DepotHeadController.class);
@Resource
private DepotHeadService depotHeadService;
/**
* 批量设置状态-审核或者反审核
* @param status
* @param depotHeadIDs
* @param request
* @return
*/
@PostMapping(value = "/batchSetStatus")
public String batchSetStatus(@RequestParam("status") Boolean status,
@RequestParam("depotHeadIDs") String depotHeadIDs,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = depotHeadService.batchSetStatus(status, depotHeadIDs);
if(res > 0) {
return returnJson(objectMap, ErpInfo.OK.name, ErpInfo.OK.code);
} else {
return returnJson(objectMap, ErpInfo.ERROR.name, ErpInfo.ERROR.code);
}
}
/**
* 单据编号生成接口规则查找当前类型单据下的当天最大的单据号并加1
* @param type
* @param subType
* @param beginTime
* @param endTime
* @param request
* @return
*/
@GetMapping(value = "/buildNumber")
public BaseResponseInfo buildNumber(@RequestParam("type") String type,
@RequestParam("subType") String subType,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
String number = depotHeadService.buildNumber(type, subType, beginTime, endTime);
map.put("DefaultNumber", number);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 获取最大的id
* @param request
* @return
*/
@GetMapping(value = "/getMaxId")
public BaseResponseInfo getMaxId(HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
Long maxId = depotHeadService.getMaxId();
map.put("maxId", maxId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查找单据_根据月份(报表)
* @param monthTime
* @param request
* @return
*/
@GetMapping(value = "/findByMonth")
public BaseResponseInfo findByMonth(@RequestParam("monthTime") String monthTime,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHead> dataList = depotHeadService.findByMonth(monthTime);
String headId = "";
if (null != dataList) {
for (DepotHead depotHead : dataList) {
headId = headId + depotHead.getId() + ",";
}
}
if (headId != "") {
headId = headId.substring(0, headId.lastIndexOf(","));
}
map.put("HeadIds", headId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 查找统计信息_根据礼品卡(报表)
* @param projectId
* @param request
* @return
*/
@GetMapping(value = "/findGiftReport")
public BaseResponseInfo findGiftReport(@RequestParam("projectId") String projectId,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHead> dataList_in = depotHeadService.getDepotHead();
String headId = "";
if (null != dataList_in) {
for (DepotHead depotHead : dataList_in) {
headId = headId + depotHead.getId() + ",";
}
List<DepotHead> dataList_out = depotHeadService.getDepotHeadGiftOut(projectId);
if (null != dataList_out) {
for (DepotHead depotHead : dataList_out) {
headId = headId + depotHead.getId() + ",";
}
}
}
if (headId != "") {
headId = headId.substring(0, headId.lastIndexOf(","));
}
map.put("HeadIds", headId);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 入库出库明细接口
* @param currentPage
* @param pageSize
* @param oId
* @param pid
* @param dids
* @param beginTime
* @param endTime
* @param type
* @param request
* @return
*/
@GetMapping(value = "/findInDetail")
public BaseResponseInfo findInDetail(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("organId") Integer oId,
@RequestParam("projectId") Integer pid,
@RequestParam("depotIds") String dids,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
@RequestParam("type") String type,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHeadVo4InDetail> resList = new ArrayList<DepotHeadVo4InDetail>();
List<DepotHeadVo4InDetail> list = depotHeadService.findByAll(beginTime, endTime, type, pid, dids, oId, currentPage, pageSize);
int total = depotHeadService.findByAllCount(beginTime, endTime, type, pid, dids, oId);
map.put("total", total);
//存放数据json数组
if (null != list) {
for (DepotHeadVo4InDetail dhd : list) {
resList.add(dhd);
}
}
map.put("rows", resList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 入库出库统计接口
* @param currentPage
* @param pageSize
* @param oId
* @param pid
* @param dids
* @param beginTime
* @param endTime
* @param type
* @param request
* @return
*/
@GetMapping(value = "/findInOutMaterialCount")
public BaseResponseInfo findInOutMaterialCount(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("organId") Integer oId,
@RequestParam("projectId") Integer pid,
@RequestParam("depotIds") String dids,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
@RequestParam("type") String type,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotHeadVo4InOutMCount> resList = new ArrayList<DepotHeadVo4InOutMCount>();
List<DepotHeadVo4InOutMCount> list = depotHeadService.findInOutMaterialCount(beginTime, endTime, type, pid, dids, oId, currentPage, pageSize);
int total = depotHeadService.findInOutMaterialCountTotal(beginTime, endTime, type, pid, dids, oId);
map.put("total", total);
//存放数据json数组
if (null != list) {
for (DepotHeadVo4InOutMCount dhc : list) {
resList.add(dhc);
}
}
map.put("rows", resList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 对账单接口
* @param currentPage
* @param pageSize
* @param beginTime
* @param endTime
* @param organId
* @param supType
* @param request
* @return
*/
@GetMapping(value = "/findStatementAccount")
public BaseResponseInfo findStatementAccount(@RequestParam("currentPage") Integer currentPage,
@RequestParam("pageSize") Integer pageSize,
@RequestParam("beginTime") String beginTime,
@RequestParam("endTime") String endTime,
@RequestParam("organId") Integer organId,
@RequestParam("supType") String supType,
HttpServletRequest request) {
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;
}
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("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 ((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 = p1.add(p2);
} else if (type.equals("")) {
allPrice = BigDecimal.ZERO.subtract(p1.add(p2));
} else if (type.equals("收入")) {
allPrice = p1 .subtract(p2);
} else if (type.equals("支出")) {
allPrice = p2 .subtract(p1);
}
dha.setDiscountLastMoney(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);
}
}
map.put("rows", resList);
res.code = 200;
res.data = map;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
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) {
BaseResponseInfo res = new BaseResponseInfo();
Map<String, Object> map = new HashMap<String, Object>();
try {
JSONObject outer = new JSONObject();
BigDecimal sum = BigDecimal.ZERO;
String getS = supplierId.toString();
int i = 1;
if (supType.equals("customer")) { //客户
i = 1;
} else if (supType.equals("vendor")) { //供应商
i = -1;
}
//进销部分
// sum = sum - (allMoney(getS, "入库", "采购", "合计",endTime) - allMoney(getS, "入库", "采购", "实际",endTime)) * i;
sum = sum.subtract((allMoney(getS, "入库", "采购", "合计",endTime).subtract(allMoney(getS, "入库", "采购", "实际",endTime))).multiply(new BigDecimal(i)));
// sum = sum - (allMoney(getS, "入库", "销售退货", "合计",endTime) - allMoney(getS, "入库", "销售退货", "实际",endTime)) * i;
sum = sum.subtract((allMoney(getS, "入库", "销售退货", "合计",endTime).subtract(allMoney(getS, "入库", "销售退货", "实际",endTime))).multiply(new BigDecimal(i)));
// sum = sum + (allMoney(getS, "出库", "销售", "合计",endTime) - allMoney(getS, "出库", "销售", "实际",endTime)) * i;
sum = sum.add((allMoney(getS, "出库", "销售", "合计",endTime).subtract(allMoney(getS, "出库", "销售", "实际",endTime))).multiply(new BigDecimal(i)));
// sum = sum + (allMoney(getS, "出库", "采购退货", "合计",endTime) - allMoney(getS, "出库", "采购退货", "实际",endTime)) * i;
sum = sum.add((allMoney(getS, "出库", "采购退货", "合计",endTime).subtract(allMoney(getS, "出库", "采购退货", "实际",endTime))).multiply(new BigDecimal(i)));
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
* @param request
* @return
*/
@GetMapping(value = "/getDetailByNumber")
public BaseResponseInfo getDetailByNumber(@RequestParam("number") String number,
HttpServletRequest request) {
BaseResponseInfo res = new BaseResponseInfo();
DepotHeadVo4List dhl = new DepotHeadVo4List();
try {
List<DepotHeadVo4List> list = depotHeadService.getDetailByNumber(number);
if(list.size() == 1) {
dhl = list.get(0);
}
res.code = 200;
res.data = dhl;
} catch(Exception e){
e.printStackTrace();
res.code = 500;
res.data = "获取数据失败";
}
return res;
}
/**
* 统计总金额
* @param getS
* @param type
* @param subType
* @param mode 合计或者金额
* @return
*/
public BigDecimal allMoney(String getS, String type, String subType, String mode, String endTime) {
BigDecimal allMoney = BigDecimal.ZERO;
try {
Integer supplierId = Integer.valueOf(getS);
BigDecimal sum = depotHeadService.findAllMoney(supplierId, type, subType, mode, endTime);
if(sum != null) {
allMoney = sum;
}
} catch (Exception e) {
e.printStackTrace();
}
//返回正数,如果负数也转为正数
if ((allMoney.compareTo(BigDecimal.ZERO))==-1) {
allMoney = allMoney.abs();
}
return allMoney;
}
}

View File

@@ -15,6 +15,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
@@ -152,13 +153,13 @@ public class DepotItemController {
if (null != list) {
for (DepotItemVo4Material di : list) {
JSONObject item = new JSONObject();
double prevSum = sumNumber("入库", pid, materialId, monthTime, true) - sumNumber("出库", pid, materialId, monthTime, true);
double InSum = sumNumber("入库", pid, materialId, monthTime, false);
double OutSum = sumNumber("出库", pid, materialId, monthTime, false);
BigDecimal prevSum = sumNumber("入库", pid, materialId, monthTime, true).subtract(sumNumber("出库", pid, materialId, monthTime, true));
BigDecimal InSum = sumNumber("入库", pid, materialId, monthTime, false);
BigDecimal OutSum = sumNumber("出库", pid, materialId, monthTime, false);
item.put("MaterialId", di.getMaterialid() == null ? "" : di.getMaterialid());
item.put("MaterialName", di.getMname());
item.put("MaterialModel", di.getMmodel());
item.put("thisSum", prevSum + InSum - OutSum);
item.put("thisSum", prevSum.add(InSum).subtract(OutSum));
dataArray.add(item);
}
}
@@ -425,12 +426,12 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
Double prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true) - sumNumber("出库", pid, diEx.getMId(), monthTime, true);
Double InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
Double OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
BigDecimal prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true).subtract(sumNumber("出库", pid, diEx.getMId(), monthTime, true));
BigDecimal InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
BigDecimal OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
BigDecimal prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true).subtract(sumPrice("出库", pid, diEx.getMId(), monthTime, true));
BigDecimal InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
BigDecimal OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMColor());
//扩展信息
@@ -438,21 +439,21 @@ public class DepotItemController {
item.put("MaterialOther", materialOther);
item.put("MaterialColor", diEx.getMColor());
item.put("MaterialUnit", diEx.getMaterialUnit());
Double unitPrice = 0.0;
if (prevSum + InSum - OutSum != 0.0) {
unitPrice = (prevPrice + InPrice - OutPrice) / (prevSum + InSum - OutSum);
BigDecimal unitPrice = BigDecimal.ZERO;
if ((prevSum .add(InSum).subtract(OutSum)).compareTo(BigDecimal.ZERO)!= 0) {
unitPrice = (prevPrice.add(InPrice).subtract(OutPrice)).divide(prevSum.add(InSum).subtract(OutSum),2, BigDecimal.ROUND_HALF_UP);
/**
* 2019-01-15通过除法算出金额后保留两位小数
* */
DecimalFormat df = new DecimalFormat("#.00");
unitPrice= Double.parseDouble(df.format(unitPrice));
unitPrice= new BigDecimal(df.format(unitPrice));
}
item.put("UnitPrice", unitPrice);
item.put("prevSum", prevSum);
item.put("InSum", InSum);
item.put("OutSum", OutSum);
item.put("thisSum", prevSum + InSum - OutSum);
item.put("thisAllPrice", prevPrice + InPrice - OutPrice);
item.put("thisSum", prevSum.add(InSum).subtract(OutSum));
item.put("thisAllPrice", prevPrice.add(InPrice).subtract(OutPrice));
dataArray.add(item);
}
}
@@ -486,13 +487,13 @@ public class DepotItemController {
Map<String, Object> map = new HashMap<String, Object>();
try {
List<DepotItemVo4WithInfoEx> dataList = depotItemService.findByAll(headIds, materialIds, null, null);
Double thisAllPrice = 0.0;
BigDecimal thisAllPrice = BigDecimal.ZERO;
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
thisAllPrice = thisAllPrice + (prevPrice + InPrice - OutPrice);
BigDecimal prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true).subtract(sumPrice("出库", pid, diEx.getMId(), monthTime, true));
BigDecimal InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
BigDecimal OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
thisAllPrice = thisAllPrice .add(prevPrice.add(InPrice).subtract(OutPrice));
}
}
map.put("totalCount", thisAllPrice);
@@ -537,10 +538,10 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
Double InSum = sumNumberBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
BigDecimal InSum = sumNumberBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
BigDecimal OutSum = sumNumberBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
BigDecimal InSumPrice = sumPriceBuyOrSale("入库", "采购", diEx.getMId(), monthTime);
BigDecimal OutSumPrice = sumPriceBuyOrSale("出库", "采购退货", diEx.getMId(), monthTime);
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel());
//扩展信息
@@ -597,14 +598,14 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
Double OutSumRetail = sumNumberBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
Double OutSum = sumNumberBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
Double InSumRetail = sumNumberBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
Double InSum = sumNumberBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
Double OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
Double OutSumPrice = sumPriceBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
Double InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
Double InSumPrice = sumPriceBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
BigDecimal OutSumRetail = sumNumberBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
BigDecimal OutSum = sumNumberBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
BigDecimal InSumRetail = sumNumberBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
BigDecimal InSum = sumNumberBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
BigDecimal OutSumRetailPrice = sumPriceBuyOrSale("出库", "零售", diEx.getMId(), monthTime);
BigDecimal OutSumPrice = sumPriceBuyOrSale("出库", "销售", diEx.getMId(), monthTime);
BigDecimal InSumRetailPrice = sumPriceBuyOrSale("入库", "零售退货", diEx.getMId(), monthTime);
BigDecimal InSumPrice = sumPriceBuyOrSale("入库", "销售退货", diEx.getMId(), monthTime);
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel());
//扩展信息
@@ -612,10 +613,10 @@ public class DepotItemController {
item.put("MaterialOther", materialOther);
item.put("MaterialColor", diEx.getMColor());
item.put("MaterialUnit", diEx.getMaterialUnit());
item.put("OutSum", OutSumRetail + OutSum);
item.put("InSum", InSumRetail + InSum);
item.put("OutSumPrice", OutSumRetailPrice + OutSumPrice);
item.put("InSumPrice", InSumRetailPrice + InSumPrice);
item.put("OutSum", OutSumRetail.add(OutSum));
item.put("InSum", InSumRetail.add(InSum));
item.put("OutSumPrice", OutSumRetailPrice.add(OutSumPrice));
item.put("InSumPrice", InSumRetailPrice.add(InSumPrice));
dataArray.add(item);
}
}
@@ -661,8 +662,8 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
JSONObject item = new JSONObject();
Double InSum = sumNumberGift("礼品充值", pid, diEx.getMId(), "in");
Double OutSum = sumNumberGift("礼品销售", pid, diEx.getMId(), "out");
BigDecimal InSum = sumNumberGift("礼品充值", pid, diEx.getMId(), "in");
BigDecimal OutSum = sumNumberGift("礼品销售", pid, diEx.getMId(), "out");
item.put("MaterialName", diEx.getMName());
item.put("MaterialModel", diEx.getMModel());
//扩展信息
@@ -670,7 +671,7 @@ public class DepotItemController {
item.put("MaterialOther", materialOther);
item.put("MaterialColor", diEx.getMColor());
item.put("MaterialUnit", diEx.getMaterialUnit());
item.put("thisSum", InSum - OutSum);
item.put("thisSum", InSum.subtract(OutSum));
dataArray.add(item);
}
}
@@ -718,23 +719,23 @@ public class DepotItemController {
if (null != dataList) {
for (DepotItemVo4WithInfoEx diEx : dataList) {
String[] objs = new String[9];
Double prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true) - sumNumber("出库", pid, diEx.getMId(), monthTime, true);
Double InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
Double OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
Double prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true) - sumPrice("出库", pid, diEx.getMId(), monthTime, true);
Double InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
Double OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
Double unitPrice = 0.0;
if (prevSum + InSum - OutSum != 0.0) {
unitPrice = (prevPrice + InPrice - OutPrice) / (prevSum + InSum - OutSum);
BigDecimal prevSum = sumNumber("入库", pid, diEx.getMId(), monthTime, true).subtract(sumNumber("出库", pid, diEx.getMId(), monthTime, true));
BigDecimal InSum = sumNumber("入库", pid, diEx.getMId(), monthTime, false);
BigDecimal OutSum = sumNumber("出库", pid, diEx.getMId(), monthTime, false);
BigDecimal prevPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, true).subtract(sumPrice("出库", pid, diEx.getMId(), monthTime, true));
BigDecimal InPrice = sumPrice("入库", pid, diEx.getMId(), monthTime, false);
BigDecimal OutPrice = sumPrice("出库", pid, diEx.getMId(), monthTime, false);
BigDecimal unitPrice = BigDecimal.ZERO;
if ((prevSum.add(InSum).subtract(OutSum)).compareTo(BigDecimal.ZERO) != 0) {
unitPrice = (prevPrice.add(InPrice).subtract(OutPrice)).divide(prevSum.add(InSum).subtract(OutSum),2, BigDecimal.ROUND_HALF_UP);
/**
* 2019-01-15通过除法算出金额后保留两位小数
* */
DecimalFormat df = new DecimalFormat("#.00");
unitPrice= Double.parseDouble(df.format(unitPrice));
unitPrice= new BigDecimal(df.format(unitPrice));
}
Double thisSum = prevSum + InSum - OutSum;
Double thisAllPrice = prevPrice + InPrice - OutPrice;
BigDecimal thisSum = prevSum.add(InSum).subtract(OutSum);
BigDecimal thisAllPrice = prevPrice.add(InPrice).subtract(OutPrice);
objs[0] = diEx.getMName().toString();
objs[1] = diEx.getMModel().toString();
objs[2] = diEx.getMaterialUnit().toString();
@@ -770,10 +771,10 @@ public class DepotItemController {
* @param isPrev
* @return
*/
public Double sumNumber(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
Double sumNumber = 0.0;
public BigDecimal sumNumber(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
BigDecimal sumNumber = BigDecimal.ZERO;
try {
Double sum = depotItemService.findByType(type, ProjectId, MId, MonthTime, isPrev);
BigDecimal sum = depotItemService.findByType(type, ProjectId, MId, MonthTime, isPrev);
if(sum != null) {
sumNumber = sum;
}
@@ -792,10 +793,10 @@ public class DepotItemController {
* @param isPrev
* @return
*/
public Double sumPrice(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
Double sumPrice = 0.0;
public BigDecimal sumPrice(String type, Integer ProjectId, Long MId, String MonthTime, Boolean isPrev) {
BigDecimal sumPrice = BigDecimal.ZERO;
try {
Double sum = depotItemService.findPriceByType(type, ProjectId, MId, MonthTime, isPrev);
BigDecimal sum = depotItemService.findPriceByType(type, ProjectId, MId, MonthTime, isPrev);
if(sum != null) {
sumPrice = sum;
}
@@ -805,11 +806,11 @@ public class DepotItemController {
return sumPrice;
}
public Double sumNumberBuyOrSale(String type, String subType, Long MId, String MonthTime) {
Double sumNumber = 0.0;
public BigDecimal sumNumberBuyOrSale(String type, String subType, Long MId, String MonthTime) {
BigDecimal sumNumber = BigDecimal.ZERO;
String sumType = "Number";
try {
Double sum = depotItemService.buyOrSale(type, subType, MId, MonthTime, sumType);
BigDecimal sum = depotItemService.buyOrSale(type, subType, MId, MonthTime, sumType);
if(sum != null) {
sumNumber = sum;
}
@@ -819,11 +820,11 @@ public class DepotItemController {
return sumNumber;
}
public Double sumPriceBuyOrSale(String type, String subType, Long MId, String MonthTime) {
Double sumPrice = 0.0;
public BigDecimal sumPriceBuyOrSale(String type, String subType, Long MId, String MonthTime) {
BigDecimal sumPrice = BigDecimal.ZERO;
String sumType = "Price";
try {
Double sum = depotItemService.buyOrSale(type, subType, MId, MonthTime, sumType);
BigDecimal sum = depotItemService.buyOrSale(type, subType, MId, MonthTime, sumType);
if(sum != null) {
sumPrice = sum;
}
@@ -841,12 +842,12 @@ public class DepotItemController {
* @param type
* @return
*/
public Double sumNumberGift(String subType, Integer ProjectId, Long MId, String type) {
Double sumNumber = 0.0;
public BigDecimal sumNumberGift(String subType, Integer ProjectId, Long MId, String type) {
BigDecimal sumNumber = BigDecimal.ZERO;
String allNumber = "";
try {
if (ProjectId != null) {
Double sum = depotItemService.findGiftByType(subType, ProjectId, MId, type);
BigDecimal sum = depotItemService.findGiftByType(subType, ProjectId, MId, type);
if(sum != null) {
sumNumber = sum;
}

View File

@@ -18,6 +18,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -270,19 +271,19 @@ public class MaterialController {
for (int i = 1; i < src.getRows(); i++) {
Material m = new Material();
m.setName(ExcelUtils.getContent(src, i, 0));
m.setCategoryid(1l); //根目录
m.setCategoryid(1L); //根目录
m.setModel(ExcelUtils.getContent(src, i, 2));
String safetyStock = ExcelUtils.getContent(src, i, 3);
m.setSafetystock(parseDoubleEx(safetyStock));
m.setSafetystock(parseBigDecimalEx(safetyStock));
m.setUnit(ExcelUtils.getContent(src, i, 4));
String retailprice = ExcelUtils.getContent(src, i, 5);
m.setRetailprice(parseDoubleEx(retailprice));
m.setRetailprice(parseBigDecimalEx(retailprice));
String lowPrice = ExcelUtils.getContent(src, i, 6);
m.setLowprice(parseDoubleEx(lowPrice));
m.setLowprice(parseBigDecimalEx(lowPrice));
String presetpriceone = ExcelUtils.getContent(src, i, 7);
m.setPresetpriceone(parseDoubleEx(presetpriceone));
m.setPresetpriceone(parseBigDecimalEx(presetpriceone));
String presetpricetwo = ExcelUtils.getContent(src, i, 8);
m.setPresetpricetwo(parseDoubleEx(presetpricetwo));
m.setPresetpricetwo(parseBigDecimalEx(presetpricetwo));
m.setRemark(ExcelUtils.getContent(src, i, 9));
String enabled = ExcelUtils.getContent(src, i, 10);
m.setEnabled(enabled.equals("启用")? true: false);
@@ -299,9 +300,9 @@ public class MaterialController {
response.sendRedirect("../pages/materials/material.html");
}
public Double parseDoubleEx(String str){
public BigDecimal parseBigDecimalEx(String str){
if(!StringUtil.isEmpty(str)) {
return Double.parseDouble(str);
return new BigDecimal(str);
} else {
return null;
}

View File

@@ -18,6 +18,7 @@ import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -48,7 +49,7 @@ public class SupplierController {
*/
@PostMapping(value = "/updateAdvanceIn")
public String updateAdvanceIn(@RequestParam("supplierId") Long supplierId,
@RequestParam("advanceIn") Double advanceIn,
@RequestParam("advanceIn") BigDecimal advanceIn,
HttpServletRequest request) {
Map<String, Object> objectMap = new HashMap<String, Object>();
int res = supplierService.updateAdvanceIn(supplierId, advanceIn);
@@ -396,9 +397,9 @@ public class SupplierController {
s.setContacts(ExcelUtils.getContent(src, i, 2));
s.setPhonenum(ExcelUtils.getContent(src, i, 3));
s.setEmail(ExcelUtils.getContent(src, i, 4));
s.setAdvancein(parseDoubleEx(ExcelUtils.getContent(src, i, 5)));
s.setBeginneedget(parseDoubleEx(ExcelUtils.getContent(src, i, 6)));
s.setBeginneedpay(parseDoubleEx(ExcelUtils.getContent(src, i, 7)));
s.setAdvancein(parseBigDecimalEx(ExcelUtils.getContent(src, i, 5)));
s.setBeginneedget(parseBigDecimalEx(ExcelUtils.getContent(src, i, 6)));
s.setBeginneedpay(parseBigDecimalEx(ExcelUtils.getContent(src, i, 7)));
s.setDescription(ExcelUtils.getContent(src, i, 8));
s.setFax(ExcelUtils.getContent(src, i, 9));
s.setTelephone(ExcelUtils.getContent(src, i, 10));
@@ -406,7 +407,7 @@ public class SupplierController {
s.setTaxnum(ExcelUtils.getContent(src, i, 12));
s.setBankname(ExcelUtils.getContent(src, i, 13));
s.setAccountnumber(ExcelUtils.getContent(src, i, 14));
s.setTaxrate(parseDoubleEx(ExcelUtils.getContent(src, i, 15)));
s.setTaxrate(parseBigDecimalEx(ExcelUtils.getContent(src, i, 15)));
String enabled = ExcelUtils.getContent(src, i, 16);
s.setEnabled(enabled.equals("启用")? true: false);
s.setIsystem(Byte.parseByte("1"));
@@ -423,9 +424,9 @@ public class SupplierController {
return null;
}
public Double parseDoubleEx(String str){
public BigDecimal parseBigDecimalEx(String str){
if(!StringUtil.isEmpty(str)) {
return Double.parseDouble(str);
return new BigDecimal(str);
} else {
return null;
}