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

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);
}
}