diff --git a/src/main/java/com/jsh/action/materials/AccountHeadAction.java b/src/main/java/com/jsh/action/materials/AccountHeadAction.java index 621fda81..dc1fb60c 100644 --- a/src/main/java/com/jsh/action/materials/AccountHeadAction.java +++ b/src/main/java/com/jsh/action/materials/AccountHeadAction.java @@ -292,11 +292,19 @@ public class AccountHeadAction extends BaseAction JSONObject outer = new JSONObject(); Double sum = 0.0; String getS = model.getSupplierId(); + String supType = model.getSupType(); //单位类型:客户、供应商 + int i = 1; + if(supType.equals("customer")){ //客户 + i = 1; + } + else if(supType.equals("vendor")){ //供应商 + i = -1; + } //收付款部分 - sum = sum - (allMoney(getS, "付款", "合计") + allMoney(getS, "付款", "实际")); - sum = sum + (allMoney(getS, "收款", "合计") + allMoney(getS, "收款", "实际")); - sum = sum - (allMoney(getS, "收入", "合计") - allMoney(getS, "收入", "实际")); - sum = sum + (allMoney(getS, "支出", "合计") - allMoney(getS, "支出", "实际")); + sum = sum + (allMoney(getS, "付款", "合计") + allMoney(getS, "付款", "实际"))*i; + sum = sum - (allMoney(getS, "收款", "合计") + allMoney(getS, "收款", "实际"))*i; + sum = sum + (allMoney(getS, "收入", "合计") - allMoney(getS, "收入", "实际"))*i; + sum = sum - (allMoney(getS, "支出", "合计") - allMoney(getS, "支出", "实际"))*i; outer.put("getAllMoney", sum); toClient(outer.toString()); } @@ -321,9 +329,10 @@ public class AccountHeadAction extends BaseAction Log.infoFileSync("getS:" + getS); Double allMoney = 0.0; String allReturn = ""; - PageUtil pageUtil = new PageUtil(); + PageUtil pageUtil = new PageUtil(); pageUtil.setPageSize(0); pageUtil.setCurPage(0); + pageUtil.setAdvSearch(getConditionHead_byEndTime()); try { Integer supplierId = Integer.valueOf(getS); accountHeadService.findAllMoney(pageUtil, supplierId, type, mode); @@ -362,6 +371,13 @@ public class AccountHeadAction extends BaseAction return condition; } + private Map getConditionHead_byEndTime() + { + Map condition = new HashMap(); + condition.put("BillTime_s_lteq", model.getEndTime()); + return condition; + } + //=============以下spring注入以及Model驱动公共方法,与Action处理无关================== public AccountHeadModel getModel() { diff --git a/src/main/java/com/jsh/action/materials/DepotHeadAction.java b/src/main/java/com/jsh/action/materials/DepotHeadAction.java index 80f1677d..dfa28845 100644 --- a/src/main/java/com/jsh/action/materials/DepotHeadAction.java +++ b/src/main/java/com/jsh/action/materials/DepotHeadAction.java @@ -565,13 +565,21 @@ public class DepotHeadAction extends BaseAction JSONObject outer = new JSONObject(); Double sum = 0.0; String getS = model.getSupplierId(); + String supType = model.getSupType(); //单位类型:客户、供应商 + int i = 1; + if(supType.equals("customer")){ //客户 + i = 1; + } + else if(supType.equals("vendor")){ //供应商 + i = -1; + } //进销部分 - sum = sum + (allMoney(getS, "入库", "采购", "合计") - allMoney(getS, "入库", "采购", "实际")); - sum = sum + (allMoney(getS, "入库", "销售退货", "合计") - allMoney(getS, "入库", "销售退货", "实际")); - sum = sum + (allMoney(getS, "入库", "其他", "合计") - allMoney(getS, "入库", "其他", "实际")); - sum = sum - (allMoney(getS, "出库", "销售", "合计") - allMoney(getS, "出库", "销售", "实际")); - sum = sum - (allMoney(getS, "出库", "采购退货", "合计") - allMoney(getS, "出库", "采购退货", "实际")); - sum = sum - (allMoney(getS, "出库", "其他", "合计") - allMoney(getS, "出库", "其他", "实际")); + sum = sum - (allMoney(getS, "入库", "采购", "合计") - allMoney(getS, "入库", "采购", "实际"))*i; + sum = sum - (allMoney(getS, "入库", "销售退货", "合计") - allMoney(getS, "入库", "销售退货", "实际"))*i; + sum = sum - (allMoney(getS, "入库", "其他", "合计") - allMoney(getS, "入库", "其他", "实际"))*i; + sum = sum + (allMoney(getS, "出库", "销售", "合计") - allMoney(getS, "出库", "销售", "实际"))*i; + sum = sum + (allMoney(getS, "出库", "采购退货", "合计") - allMoney(getS, "出库", "采购退货", "实际"))*i; + sum = sum + (allMoney(getS, "出库", "其他", "合计") - allMoney(getS, "出库", "其他", "实际"))*i; outer.put("getAllMoney", sum); toClient(outer.toString()); } @@ -598,9 +606,10 @@ public class DepotHeadAction extends BaseAction Log.infoFileSync("getS:" + getS); Double allMoney = 0.0; String allReturn = ""; - PageUtil pageUtil = new PageUtil(); + PageUtil pageUtil = new PageUtil(); pageUtil.setPageSize(0); pageUtil.setCurPage(0); + pageUtil.setAdvSearch(getConditionHead_byEndTime()); try { Integer supplierId = Integer.valueOf(getS); depotHeadService.findAllMoney(pageUtil, supplierId, type, subType, mode); @@ -755,10 +764,58 @@ public class DepotHeadAction extends BaseAction Object dl = dataList.get(i); //获取对象 Object[] arr = (Object[]) dl; //转为数组 item.put("number", arr[0]); //单据编号 - item.put("changeAmount", arr[1]); //金额 - item.put("totalPrice", arr[2]); //金额 - item.put("supplierName", arr[3]); //供应商 - item.put("operTime", arr[4]); //入库出库日期 + item.put("type", arr[1]); //类型 + item.put("changeAmount", arr[2]); //金额 + item.put("totalPrice", arr[3]); //金额 + String type = arr[1].toString(); + Double p1 = 0.0; + Double p2 = 0.0; + if(arr[3]!=null){ + p1 = Double.parseDouble(arr[3].toString()); + } + if(arr[2]!=null){ + p2 = Double.parseDouble(arr[2].toString()); + } + 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); + } + else if(type.equals("收入")) { + allPrice = p1-p2; + } + else if(type.equals("支出")) { + allPrice = -(p1-p2); + } + item.put("allPrice", String .format("%.2f",allPrice)); //计算后的金额 + item.put("supplierName", arr[4]); //供应商 + item.put("operTime", arr[5]); //入库出库日期 dataArray.add(item); } } @@ -823,6 +880,13 @@ public class DepotHeadAction extends BaseAction } return condition; } + + private Map getConditionHead_byEndTime() + { + Map condition = new HashMap(); + condition.put("OperTime_s_lteq", model.getEndTime()); + return condition; + } //=============以下spring注入以及Model驱动公共方法,与Action处理无关================== public DepotHeadModel getModel() diff --git a/src/main/java/com/jsh/dao/materials/DepotHeadDAO.java b/src/main/java/com/jsh/dao/materials/DepotHeadDAO.java index 0ce51887..e7f374f5 100644 --- a/src/main/java/com/jsh/dao/materials/DepotHeadDAO.java +++ b/src/main/java/com/jsh/dao/materials/DepotHeadDAO.java @@ -131,14 +131,14 @@ public class DepotHeadDAO extends BaseDAO implements DepotHeadIDAO { @SuppressWarnings("unchecked") public void findStatementAccount(PageUtil pageUtil,String beginTime,String endTime,Long organId) throws JshException { StringBuffer queryString = new StringBuffer(); - queryString.append("select dh.Number,dh.ChangeAmount,dh.TotalPrice,s.supplier,date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime from jsh_depothead dh " + + queryString.append("select dh.Number,concat(dh.SubType,dh.Type) as newType,dh.ChangeAmount,dh.TotalPrice,s.supplier,date_format(dh.OperTime,'%Y-%m-%d %H:%i:%S') as oTime from jsh_depothead dh " + "inner join jsh_supplier s on s.id=dh.OrganId where s.type!='会员' " + "and dh.OperTime >='"+ beginTime +"' and dh.OperTime<='"+ endTime +"' "); if(organId!=null && !organId.equals("")) { queryString.append(" and dh.OrganId='"+ organId +"' "); } queryString.append("UNION ALL " + - "select ah.BillNo,ah.ChangeAmount,ah.TotalPrice,s.supplier,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime from jsh_accounthead ah " + + "select ah.BillNo,ah.Type as newType,ah.ChangeAmount,ah.TotalPrice,s.supplier,date_format(ah.BillTime,'%Y-%m-%d %H:%i:%S') as oTime from jsh_accounthead ah " + "inner join jsh_supplier s on s.id=ah.OrganId where s.type!='会员' " + "and ah.BillTime >='"+ beginTime +"' and ah.BillTime<='"+ endTime +"' "); if(organId!=null && !organId.equals("")) { diff --git a/src/main/java/com/jsh/model/vo/materials/AccountHeadModel.java b/src/main/java/com/jsh/model/vo/materials/AccountHeadModel.java index 386dae88..4fc9fae7 100644 --- a/src/main/java/com/jsh/model/vo/materials/AccountHeadModel.java +++ b/src/main/java/com/jsh/model/vo/materials/AccountHeadModel.java @@ -22,6 +22,8 @@ public class AccountHeadModel implements Serializable private String MonthTime; //查询月份 private String supplierId; //单位Id,用于查询单位的收付款 + + private String supType; //单位类型,客户、供应商 /** * 分类ID */ @@ -233,5 +235,12 @@ public class AccountHeadModel implements Serializable public void setSupplierId(String supplierId) { this.supplierId = supplierId; } - + + public String getSupType() { + return supType; + } + + public void setSupType(String supType) { + this.supType = supType; + } } diff --git a/src/main/java/com/jsh/model/vo/materials/DepotHeadModel.java b/src/main/java/com/jsh/model/vo/materials/DepotHeadModel.java index c9f70186..54c7a577 100644 --- a/src/main/java/com/jsh/model/vo/materials/DepotHeadModel.java +++ b/src/main/java/com/jsh/model/vo/materials/DepotHeadModel.java @@ -44,6 +44,7 @@ public class DepotHeadModel implements Serializable private String supplierId; //单位Id,用于查询单位的应收应付 private String MaterialParam; //商品参数 private String dhIds; //单据id列表 + private String supType; //单位类型,客户、供应商 /** * 分类ID @@ -381,4 +382,12 @@ public class DepotHeadModel implements Serializable public void setDhIds(String dhIds) { this.dhIds = dhIds; } + + public String getSupType() { + return supType; + } + + public void setSupType(String supType) { + this.supType = supType; + } } diff --git a/src/main/webapp/js/pages/manage/supplier.js b/src/main/webapp/js/pages/manage/supplier.js index 5033d04f..19665842 100644 --- a/src/main/webapp/js/pages/manage/supplier.js +++ b/src/main/webapp/js/pages/manage/supplier.js @@ -631,13 +631,23 @@ url = path + '/supplier/update.action?supplierID=' + supplierInfo[0]; //显示累计应收和累计应付 + var thisDateTime = getNowFormatDateTime(); //当前时间 + var supType = "customer"; + if(listType === "客户"){ + supType = "customer" + } + else if(listType === "供应商"){ + supType = "vendor" + } $.ajax({ type:"post", url: path + "/depotHead/findTotalPay.action", dataType: "json", async: false, data: ({ - supplierId: supplierInfo[0] + supplierId: supplierInfo[0], + EndTime:thisDateTime, + supType: supType }), success: function(res){ if(res) { @@ -648,7 +658,9 @@ dataType: "json", async: false, data: ({ - supplierId: supplierInfo[0] + supplierId: supplierInfo[0], + EndTime:thisDateTime, + supType: supType }), success: function(res){ if(res) { @@ -656,14 +668,13 @@ var money = moneyA+moneyB; var moneyBeginNeedGet = $("#BeginNeedGet").val()-0; //期初应收 var moneyBeginNeedPay = $("#BeginNeedPay").val()-0; //期初应付 - money = (money + moneyBeginNeedPay - moneyBeginNeedGet).toFixed(2); - if(money>0) { - $("#AllNeedGet").val(""); //累计应收-置空 - $("#AllNeedPay").val(money); //累计应付 + if(listType === "客户"){ + money = (money + moneyBeginNeedGet - moneyBeginNeedPay).toFixed(2); + $("#AllNeedGet").val(money); //累计应收 } - else { - $("#AllNeedGet").val(-money); //累计应收 - $("#AllNeedPay").val(""); //累计应付-置空 + else if(listType === "供应商"){ + money = (money + moneyBeginNeedPay - moneyBeginNeedGet).toFixed(2); + $("#AllNeedPay").val(money); //累计应付 } } }, diff --git a/src/main/webapp/pages/reports/statement_of_account.jsp b/src/main/webapp/pages/reports/statement_of_account.jsp index 980528da..8c49202d 100644 --- a/src/main/webapp/pages/reports/statement_of_account.jsp +++ b/src/main/webapp/pages/reports/statement_of_account.jsp @@ -7,7 +7,7 @@ - 对账单 + 客户对账 @@ -49,12 +49,17 @@    打印 +   + + 期初应收:0   + 期末应收:0 + -
+
@@ -76,7 +81,7 @@ }); - //初始化供应商、客户 + //初始化客户 function initSupplier(){ $('#OrganId').combobox({ url: cusUrl, @@ -107,10 +112,11 @@ pageList: [10,50,100], columns:[[ { title: '单据编号',field: 'number',width:140}, + { title: '类型',field: 'type',width:100}, { title: '单位名称',field: 'supplierName',width:200}, - { title: '金额',field: 'allPrice',width:60,formatter: function(value,rec){ - return (rec.changeAmount-rec.totalPrice).toFixed(2); - }}, + { title: '单据金额',field: 'totalPrice',width:80}, + { title: '实际支付',field: 'changeAmount',width:80}, + { title: '本期变化',field: 'allPrice',width:80}, { title: '单据日期',field: 'operTime',width:140} ]], onLoadError:function() @@ -209,6 +215,131 @@ success: function (res) { if(res){ $("#tableData").datagrid('loadData',res); + //如果选择了单位信息,就进行计算期初和期末 + var supplierId = $('#OrganId').combobox('getValue'); + if(supplierId) { + //先查找期初信息 + var beginNeedGet = 0; + var beginNeedPay = 0; + $.ajax({ + type:"post", + url: "<%=path %>/supplier/findById.action", + dataType: "json", + async: false, + data: ({ + supplierID: supplierId + }), + success: function(res){ + if(res && res.rows && res.rows[0]) { + if(res.rows[0].BeginNeedGet) { + beginNeedGet = res.rows[0].BeginNeedGet; + } + if(res.rows[0].BeginNeedPay) { + beginNeedPay = res.rows[0].BeginNeedPay; + } + //显示期初结存 + var searchBeginTime = $("#searchBeginTime").val(); //开始时间 + $.ajax({ + type:"post", + url: "<%=path %>/depotHead/findTotalPay.action", + dataType: "json", + async: false, + data: ({ + supplierId: supplierId, + EndTime:searchBeginTime, + supType: "customer" + }), + success: function(res){ + if(res) { + var moneyA = res.getAllMoney.toFixed(2)-0; + $.ajax({ + type:"post", + url: "<%=path %>/accountHead/findTotalPay.action", + dataType: "json", + async: false, + data: ({ + supplierId: supplierId, + EndTime:searchBeginTime, + supType: "customer" + }), + success: function(res){ + if(res) { + var moneyB = res.getAllMoney.toFixed(2)-0; + var money = moneyA+moneyB; + var moneyBeginNeedGet = beginNeedGet-0; //期初应收 + var moneyBeginNeedPay = beginNeedPay-0; //期初应付 + money = (money + moneyBeginNeedGet - moneyBeginNeedPay).toFixed(2); + $(".first-total").text(money); //期初结存 + } + }, + error: function(){ + $.messager.alert('提示','网络异常请稍后再试!','error'); + return; + } + }); + } + }, + error: function(){ + $.messager.alert('提示','网络异常请稍后再试!','error'); + return; + } + }) + + //显示期末合计 + var searchEndTime = $("#searchEndTime").val(); //结束时间 + $.ajax({ + type:"post", + url: "<%=path %>/depotHead/findTotalPay.action", + dataType: "json", + async: false, + data: ({ + supplierId: supplierId, + EndTime:searchEndTime, + supType: "customer" + }), + success: function(res){ + if(res) { + var moneyA = res.getAllMoney.toFixed(2)-0; + $.ajax({ + type:"post", + url: "<%=path %>/accountHead/findTotalPay.action", + dataType: "json", + async: false, + data: ({ + supplierId: supplierId, + EndTime:searchEndTime, + supType: "customer" + }), + success: function(res){ + if(res) { + var moneyB = res.getAllMoney.toFixed(2)-0; + var money = moneyA+moneyB; + var moneyBeginNeedGet = beginNeedGet-0; //期初应收 + var moneyBeginNeedPay = beginNeedPay-0; //期初应付 + money = (money + moneyBeginNeedGet - moneyBeginNeedPay).toFixed(2); + $(".last-total").text(money); //期末合计 + } + }, + error: function(){ + $.messager.alert('提示','网络异常请稍后再试!','error'); + return; + } + }); + } + }, + error: function(){ + $.messager.alert('提示','网络异常请稍后再试!','error'); + return; + } + }) + } + }, + error: function(){ + $.messager.alert('提示','网络异常请稍后再试!','error'); + return; + } + }); + } } }, //此处添加错误处理