更新供应商和客户的累计应收应付的算法

This commit is contained in:
季圣华 2017-04-09 16:52:02 +08:00
parent bd5deee8ba
commit 33bb4e06ef
29 changed files with 293 additions and 25 deletions

View File

@ -5,15 +5,19 @@ import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.po.Logdetails;
import com.jsh.model.po.Supplier;
import com.jsh.model.vo.basic.SupplierModel;
import com.jsh.service.basic.SupplierIService;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
/*
* 单位管理
@ -242,8 +246,6 @@ public class SupplierAction extends BaseAction<SupplierModel>
item.put("email", supplier.getEmail());
item.put("BeginNeedGet",supplier.getBeginNeedGet());
item.put("BeginNeedPay",supplier.getBeginNeedPay());
item.put("AllNeedGet",supplier.getAllNeedGet());
item.put("AllNeedPay",supplier.getAllNeedPay());
item.put("isystem", supplier.getIsystem() == (short)0?"":"");
item.put("description", supplier.getDescription());
item.put("enabled", supplier.getEnabled());

View File

@ -7,9 +7,12 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.po.Account;
@ -19,6 +22,8 @@ import com.jsh.model.po.Person;
import com.jsh.model.po.Supplier;
import com.jsh.model.vo.materials.AccountHeadModel;
import com.jsh.service.materials.AccountHeadIService;
import com.jsh.service.materials.DepotHeadIService;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
import com.jsh.util.Tools;
/*
@ -276,6 +281,70 @@ public class AccountHeadAction extends BaseAction<AccountHeadModel>
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询财务信息结果异常", e);
}
}
/**
* 查询单位的累计应收和累计应付
* @return
*/
public void findTotalPay() {
try
{
JSONObject outer = new JSONObject();
Double sum = 0.0;
String getS = model.getSupplierId();
//进销部分
sum = sum - (allMoney(getS, "付款", "合计") + allMoney(getS, "付款", "实际"));
sum = sum + (allMoney(getS, "收款", "合计") + allMoney(getS, "收款", "实际"));
sum = sum - (allMoney(getS, "收入", "合计") - allMoney(getS, "收入", "实际"));
sum = sum + (allMoney(getS, "支出", "合计") - allMoney(getS, "支出", "实际"));
//收付款部分
outer.put("getAllMoney", sum);
toClient(outer.toString());
}
catch (DataAccessException e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找异常", e);
}
catch (IOException e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询结果异常", e);
}
}
/**
* 统计总金额
* @param type
* @param mode 合计或者金额
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Double allMoney(String getS, String type, String mode) {
Log.infoFileSync("getS:" + getS);
Double allMoney = 0.0;
String allReturn = "";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try {
Integer supplierId = Integer.valueOf(getS);
accountHeadService.findAllMoney(pageUtil, supplierId, type, mode);
allReturn = pageUtil.getPageList().toString();
allReturn = allReturn.substring(1,allReturn.length()-1);
if(allReturn.equals("null")){
allReturn = "0";
}
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
allMoney = Double.parseDouble(allReturn);
//返回正数如果负数也转为正数
if(allMoney<0){
allMoney = -allMoney;
}
return allMoney;
}
/**
* 拼接搜索条件
@ -296,7 +365,6 @@ public class AccountHeadAction extends BaseAction<AccountHeadModel>
}
//=============以下spring注入以及Model驱动公共方法与Action处理无关==================
@Override
public AccountHeadModel getModel()
{
return model;

View File

@ -7,9 +7,12 @@ import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.dao.DataAccessException;
import com.jsh.base.BaseAction;
import com.jsh.base.Log;
import com.jsh.model.po.Account;
@ -20,8 +23,11 @@ import com.jsh.model.po.Person;
import com.jsh.model.po.Supplier;
import com.jsh.model.vo.materials.DepotHeadModel;
import com.jsh.service.materials.DepotHeadIService;
import com.jsh.util.JshException;
import com.jsh.util.PageUtil;
import com.jsh.util.Tools;
/*
* 单据表头管理
* @author jishenghua qq:752718920
@ -331,6 +337,72 @@ public class DepotHeadAction extends BaseAction<DepotHeadModel>
}
}
/**
* 查询单位的累计应收和累计应付
* @return
*/
public void findTotalPay() {
try
{
JSONObject outer = new JSONObject();
Double sum = 0.0;
String getS = model.getSupplierId();
//进销部分
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, "出库", "其他", "实际"));
outer.put("getAllMoney", sum);
toClient(outer.toString());
}
catch (DataAccessException e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>查找异常", e);
}
catch (IOException e)
{
Log.errorFileSync(">>>>>>>>>>>>>>>>>>>回写查询结果异常", e);
}
}
/**
* 统计总金额
* @param type
* @param subType
* @param mode 合计或者金额
* @return
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public Double allMoney(String getS, String type, String subType, String mode) {
Log.infoFileSync("getS:" + getS);
Double allMoney = 0.0;
String allReturn = "";
PageUtil pageUtil = new PageUtil();
pageUtil.setPageSize(0);
pageUtil.setCurPage(0);
try {
Integer supplierId = Integer.valueOf(getS);
depotHeadService.findAllMoney(pageUtil, supplierId, type, subType, mode);
allReturn = pageUtil.getPageList().toString();
allReturn = allReturn.substring(1,allReturn.length()-1);
if(allReturn.equals("null")){
allReturn = "0";
}
} catch (JshException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
allMoney = Double.parseDouble(allReturn);
//返回正数如果负数也转为正数
if(allMoney<0){
allMoney = -allMoney;
}
return allMoney;
}
/**
* 拼接搜索条件
* @return
@ -362,7 +434,6 @@ public class DepotHeadAction extends BaseAction<DepotHeadModel>
}
//=============以下spring注入以及Model驱动公共方法与Action处理无关==================
@Override
public DepotHeadModel getModel()
{
return model;

View File

@ -5,6 +5,7 @@ import org.hibernate.Query;
import com.jsh.base.BaseDAO;
import com.jsh.util.JshException;
import com.jsh.model.po.AccountHead;
import com.jsh.model.po.DepotHead;
import com.jsh.model.po.UserBusiness;
import com.jsh.util.PageUtil;
import com.jsh.util.SearchConditionUtil;
@ -22,11 +23,26 @@ public class AccountHeadDAO extends BaseDAO<AccountHead> implements AccountHeadI
}
@SuppressWarnings("unchecked")
@Override
public void find(PageUtil<AccountHead> pageUtil,String maxid) throws JshException
{
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select max(Id) as Id from AccountHead accountHead where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list());
}
@SuppressWarnings("unchecked")
public void findAllMoney(PageUtil<AccountHead> pageUtil, Integer supplierId, String type, String mode) throws JshException
{
Query query;
String modeName = "";
if(mode.equals("实际")){
modeName = "ChangeAmount";
}
else if(mode.equals("合计")){
modeName = "TotalPrice";
}
query= this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select sum(" + modeName + ") as allMoney from AccountHead accountHead where Type='" + type + "' and OrganId =" + supplierId + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list());
}
}

View File

@ -3,6 +3,7 @@ package com.jsh.dao.materials;
import com.jsh.base.BaseIDAO;
import com.jsh.util.JshException;
import com.jsh.model.po.AccountHead;
import com.jsh.model.po.DepotHead;
import com.jsh.model.po.UserBusiness;
import com.jsh.util.PageUtil;
@ -12,4 +13,6 @@ public interface AccountHeadIDAO extends BaseIDAO<AccountHead>
* 获取MaxId
*/
void find(PageUtil<AccountHead> pageUtil,String maxid) throws JshException;
void findAllMoney(PageUtil<AccountHead> pageUtil, Integer supplierId, String type, String mode) throws JshException;
}

View File

@ -22,11 +22,26 @@ public class DepotHeadDAO extends BaseDAO<DepotHead> implements DepotHeadIDAO
}
@SuppressWarnings("unchecked")
@Override
public void find(PageUtil<DepotHead> pageUtil,String maxid) throws JshException
public void find(PageUtil<DepotHead> pageUtil,String maxid) throws JshException
{
Query query = this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select max(Id) as Id from DepotHead depotHead where 1=1 " + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list());
}
@SuppressWarnings("unchecked")
public void findAllMoney(PageUtil<DepotHead> pageUtil, Integer supplierId, String type, String subType, String mode) throws JshException
{
Query query;
String modeName = "";
if(mode.equals("实际")){
modeName = "ChangeAmount";
}
else if(mode.equals("合计")){
modeName = "TotalPrice";
}
query= this.getHibernateTemplate().getSessionFactory().getCurrentSession().createQuery("select sum(" + modeName + ") as allMoney from DepotHead depotHead where Type='" + type + "' and SubType = '" + subType + "' and OrganId =" + supplierId + SearchConditionUtil.getCondition(pageUtil.getAdvSearch()));
pageUtil.setTotalCount(query.list().size());
pageUtil.setPageList(query.list());
}
}

View File

@ -12,4 +12,7 @@ public interface DepotHeadIDAO extends BaseIDAO<DepotHead>
* 获取MaxId
*/
void find(PageUtil<DepotHead> pageUtil,String maxid) throws JshException;
void findAllMoney(PageUtil<DepotHead> pageUtil, Integer supplierId, String type, String subType, String mode) throws JshException;
}

View File

@ -8,7 +8,7 @@ import com.jsh.util.PageUtil;
public interface DepotItemIDAO extends BaseIDAO<DepotItem>
{
void findByType(PageUtil<DepotItem> pageUtil,String type,Long MId, String MonthTime,Boolean isPrev) throws JshException;
public void findByType(PageUtil<DepotItem> pageUtil,String type,Long MId, String MonthTime,Boolean isPrev) throws JshException;
void buyOrSale(PageUtil<DepotItem> pageUtil,String type, String subType,Long MId, String MonthTime, String sumType) throws JshException;
public void buyOrSale(PageUtil<DepotItem> pageUtil,String type, String subType,Long MId, String MonthTime, String sumType) throws JshException;
}

View File

@ -20,6 +20,8 @@ public class AccountHeadModel implements Serializable
private String BeginTime; //查询开始时间
private String EndTime; //查询结束时间
private String MonthTime; //查询月份
private String supplierId; //单位Id用于查询单位的收付款
/**
* 分类ID
*/
@ -222,4 +224,14 @@ public class AccountHeadModel implements Serializable
public String getClientIp()
{
return clientIp;
}}
}
public String getSupplierId() {
return supplierId;
}
public void setSupplierId(String supplierId) {
this.supplierId = supplierId;
}
}

View File

@ -25,7 +25,10 @@ public class DepotHeadModel implements Serializable
private String BeginTime; //查询开始时间
private String EndTime; //查询结束时间
private String MonthTime; //查询月份
/**
private String supplierId; //单位Id用于查询单位的应收应付
/**
* 分类ID
*/
private Long depotHeadID = 0l;
@ -225,5 +228,14 @@ public class DepotHeadModel implements Serializable
public void setMonthTime(String monthTime) {
MonthTime = monthTime;
}
public String getSupplierId() {
return supplierId;
}
public void setSupplierId(String supplierId) {
this.supplierId = supplierId;
}
}

View File

@ -3,6 +3,7 @@ package com.jsh.service.materials;
import com.jsh.base.BaseIService;
import com.jsh.util.JshException;
import com.jsh.model.po.AccountHead;
import com.jsh.model.po.DepotHead;
import com.jsh.model.po.UserBusiness;
import com.jsh.util.PageUtil;
@ -12,4 +13,6 @@ public interface AccountHeadIService extends BaseIService<AccountHead>
* 获取MaxId
*/
void find(PageUtil<AccountHead> accountHead,String maxid)throws JshException;
void findAllMoney(PageUtil<AccountHead> accountHead, Integer supplierId, String type, String mode)throws JshException;
}

View File

@ -4,6 +4,7 @@ import com.jsh.base.BaseService;
import com.jsh.dao.materials.AccountHeadIDAO;
import com.jsh.util.JshException;
import com.jsh.model.po.AccountHead;
import com.jsh.model.po.DepotHead;
import com.jsh.model.po.UserBusiness;
import com.jsh.util.PageUtil;
@ -24,9 +25,13 @@ public class AccountHeadService extends BaseService<AccountHead> implements Acco
return AccountHead.class;
}
@Override
public void find(PageUtil<AccountHead> pageUtil, String maxid) throws JshException
{
accountHeadDao.find(pageUtil, maxid);
}
public void findAllMoney(PageUtil<AccountHead> pageUtil, Integer supplierId, String type, String mode) throws JshException
{
accountHeadDao.findAllMoney(pageUtil, supplierId, type, mode);
}
}

View File

@ -12,4 +12,6 @@ public interface DepotHeadIService extends BaseIService<DepotHead>
* 获取MaxId
*/
void find(PageUtil<DepotHead> depotHead,String maxid)throws JshException;
void findAllMoney(PageUtil<DepotHead> depotHead, Integer supplierId, String type, String subType, String mode)throws JshException;
}

View File

@ -24,9 +24,13 @@ public class DepotHeadService extends BaseService<DepotHead> implements DepotHea
return DepotHead.class;
}
@Override
public void find(PageUtil<DepotHead> pageUtil, String maxid) throws JshException
{
depotHeadDao.find(pageUtil, maxid);
}
public void findAllMoney(PageUtil<DepotHead> pageUtil, Integer supplierId, String type, String subType, String mode) throws JshException
{
depotHeadDao.findAllMoney(pageUtil, supplierId, type, subType, mode);
}
}

View File

@ -42,7 +42,7 @@
moneyType = true; //隐藏当前列
payTypeTitle = "收入项目";
inOrOut = "in";
organUrl = supUrl;
organUrl = cusUrl;
}
else if(listTitle === "支出单列表"){
listType = "支出";
@ -50,7 +50,7 @@
moneyType = true; //隐藏当前列
payTypeTitle = "支出项目";
inOrOut = "out";
organUrl = cusUrl;
organUrl = supUrl;
}
else if(listTitle === "收款单列表"){
listType = "收款";
@ -58,7 +58,7 @@
moneyType = false; //显示当前列
payTypeTitle = "无标题";
inOrOut = "";
organUrl = supUrl;
organUrl = cusUrl;
}
else if(listTitle === "付款单列表"){
listType = "付款";
@ -66,7 +66,7 @@
moneyType = false; //显示当前列
payTypeTitle = "无标题";
inOrOut = "";
organUrl = cusUrl;
organUrl = supUrl;
}
else if(listTitle === "转账单列表"){
listType = "转账";

View File

@ -201,14 +201,14 @@
{ title: '联系人', field: 'contacts',width:50,align:"center"},
{ title: '联系电话', field: 'phonenum',width:60,align:"center"},
{ title: '电子邮箱',field: 'email',width:80,align:"center"},
{ title: '累计应收',field: 'AllNeedGet',width:70,align:"center"},
{ title: '累计应付',field: 'AllNeedPay',width:70,align:"center"},
{ title: '期初应收',field: 'BeginNeedGet',width:70,align:"center"},
{ title: '期初应付',field: 'BeginNeedPay',width:70,align:"center"},
{ title: '类型',field: 'type',width:50},
{ title: '启动',field: 'enabled',width:40},
{ title: '操作',field: 'op',align:"center",width:130,formatter:function(value,rec)
{
var str = '';
var rowInfo = rec.id + 'AaBb' + rec.supplier +'AaBb' + rec.contacts + 'AaBb'+ rec.phonenum + 'AaBb'+ rec.email + 'AaBb'+ rec.BeginNeedGet + 'AaBb'+ rec.BeginNeedPay + 'AaBb'+ rec.AllNeedGet + 'AaBb'+ rec.AllNeedPay + 'AaBb' + rec.isystem + 'AaBb' + rec.description+ 'AaBb' + rec.type+ 'AaBb' + rec.enabled;
var rowInfo = rec.id + 'AaBb' + rec.supplier +'AaBb' + rec.contacts + 'AaBb'+ rec.phonenum + 'AaBb'+ rec.email + 'AaBb'+ rec.BeginNeedGet + 'AaBb'+ rec.BeginNeedPay + 'AaBb' + rec.isystem + 'AaBb' + rec.description+ 'AaBb' + rec.type+ 'AaBb' + rec.enabled;
if(1 == value)
{
str += '<img src="<%=path%>/js/easyui-1.3.5/themes/icons/pencil.png" style="cursor: pointer;" onclick="editSupplier(\'' + rowInfo + '\');"/>&nbsp;<a onclick="editSupplier(\'' + rowInfo + '\');" style="text-decoration:none;color:black;" href="javascript:void(0)">编辑</a>&nbsp;&nbsp;';
@ -428,6 +428,12 @@
$("#phonenum").val("").focus();
return;
}
var beginNeedGet = $.trim($("#BeginNeedGet").val());
var beginNeedPay = $.trim($("#BeginNeedPay").val());
if(beginNeedGet && beginNeedPay) {
$.messager.alert('提示','期初应收和期初应付不能同时输入','info');
return;
}
$('#supplierFM').form('submit',{
url: url,
@ -467,11 +473,9 @@
email : supplierInfo[4],
BeginNeedGet : supplierInfo[5],
BeginNeedPay : supplierInfo[6],
AllNeedGet : supplierInfo[7],
AllNeedPay : supplierInfo[8],
description : supplierInfo[10],
type : supplierInfo[11],
enabled : supplierInfo[12],
description : supplierInfo[8],
type : supplierInfo[9],
enabled : supplierInfo[10],
clientIp:'<%=clientIp %>'
};
orgSupplier = supplierInfo[1];
@ -482,6 +486,54 @@
//焦点在名称输入框==定焦在输入文字后面
$("#supplier").val("").focus().val(supplierInfo[1]);
url = '<%=path %>/supplier/update.action?supplierID=' + supplierInfo[0];
//显示累计应收和累计应付
$.ajax({
type:"post",
url: "<%=path %>/depotHead/findTotalPay.action",
dataType: "json",
async: false,
data: ({
supplierId: supplierInfo[0]
}),
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: supplierInfo[0]
}),
success: function(res){
if(res) {
var moneyB = res.getAllMoney.toFixed(2)-0;
var money = moneyA+moneyB;
var moneyBeginNeedGet = $("#BeginNeedGet").val()-0; //期初应收
var moneyBeginNeedPay = $("#BeginNeedPay").val()-0; //期初应付
money = money + moneyBeginNeedPay - moneyBeginNeedGet;
if(money>0) {
$("#AllNeedPay").val(money); //累计应付
}
else {
$("#AllNeedGet").val(-money); //累计应收
}
}
},
error: function(){
$.messager.alert('提示','网络异常请稍后再试!','error');
return;
}
});
}
},
error: function(){
$.messager.alert('提示','网络异常请稍后再试!','error');
return;
}
})
}