优化账户余额的计算方法,将财务单据统计进去
This commit is contained in:
parent
12ab93ae55
commit
bfb1fe531f
@ -5,6 +5,10 @@ import java.sql.Timestamp;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.text.*;
|
||||
|
||||
import com.jsh.model.po.AccountHead;
|
||||
import com.jsh.model.po.AccountItem;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONObject;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
@ -16,6 +20,8 @@ import com.jsh.model.po.Account;
|
||||
import com.jsh.model.vo.basic.AccountModel;
|
||||
import com.jsh.service.basic.AccountIService;
|
||||
import com.jsh.service.materials.DepotHeadIService;
|
||||
import com.jsh.service.materials.AccountHeadIService;
|
||||
import com.jsh.service.materials.AccountItemIService;
|
||||
import com.jsh.util.PageUtil;
|
||||
import com.jsh.util.Tools;
|
||||
/**
|
||||
@ -27,6 +33,8 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
{
|
||||
private AccountIService accountService;
|
||||
private DepotHeadIService depotHeadService;
|
||||
private AccountHeadIService accountHeadService;
|
||||
private AccountItemIService accountItemService;
|
||||
private AccountModel model = new AccountModel();
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@ -288,6 +296,7 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
{
|
||||
for(Account account:dataList)
|
||||
{
|
||||
DecimalFormat df =new DecimalFormat(".##");
|
||||
JSONObject item = new JSONObject();
|
||||
item.put("id", account.getId());
|
||||
//结算账户名称
|
||||
@ -295,8 +304,12 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
item.put("serialNo", account.getSerialNo());
|
||||
item.put("initialAmount", account.getInitialAmount());
|
||||
String monthTime = Tools.getCurrentMonth();
|
||||
item.put("thisMonthAmount", getAccountSum(account.getId(),monthTime)); //本月发生额
|
||||
item.put("currentAmount", getAccountSum(account.getId(),"") + account.getInitialAmount()); //当前余额
|
||||
Double thisMonthAmount = getAccountSum(account.getId(), monthTime) + getAccountSumByHead(account.getId(), monthTime) +getAccountSumByDetail(account.getId(), monthTime);
|
||||
String thisMonthAmountFmt=df.format(thisMonthAmount);
|
||||
item.put("thisMonthAmount", thisMonthAmountFmt); //本月发生额
|
||||
Double currentAmount = getAccountSum(account.getId(),"") + getAccountSumByHead(account.getId(), "") + getAccountSumByDetail(account.getId(), "") + account.getInitialAmount();
|
||||
String currentAmountFmt=df.format(currentAmount);
|
||||
item.put("currentAmount", currentAmountFmt); //当前余额
|
||||
item.put("remark", account.getRemark());
|
||||
item.put("op", 1);
|
||||
dataArray.add(item);
|
||||
@ -316,7 +329,7 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 单个账户的金额求和
|
||||
* 单个账户的金额求和-入库和出库
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
@ -341,6 +354,79 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
return accountSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个账户的金额求和-收入、支出、转账的单据表头的合计
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Double getAccountSumByHead(Long id,String monthTime){
|
||||
Double accountSum = 0.0;
|
||||
try{
|
||||
PageUtil<AccountHead> pageUtil = new PageUtil<AccountHead>();
|
||||
pageUtil.setPageSize(0);
|
||||
pageUtil.setCurPage(0);
|
||||
pageUtil.setAdvSearch(getCondition_getSumByHead(id, monthTime));
|
||||
accountHeadService.find(pageUtil);
|
||||
List<AccountHead> dataList = pageUtil.getPageList();
|
||||
if(dataList!= null){
|
||||
for(AccountHead accountHead:dataList){
|
||||
accountSum = accountSum + accountHead.getChangeAmount();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (DataAccessException e){
|
||||
Log.errorFileSync(">>>>>>>>>查找进销存信息异常", e);
|
||||
}
|
||||
return accountSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单个账户的金额求和-收款、付款、转账、收预付款的单据明细的合计
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
public Double getAccountSumByDetail(Long id,String monthTime){
|
||||
Double accountSum = 0.0;
|
||||
try{
|
||||
PageUtil<AccountHead> pageUtil = new PageUtil<AccountHead>();
|
||||
pageUtil.setPageSize(0);
|
||||
pageUtil.setCurPage(0);
|
||||
pageUtil.setAdvSearch(getCondition_getSumByHead(monthTime));
|
||||
accountHeadService.find(pageUtil);
|
||||
List<AccountHead> dataList = pageUtil.getPageList();
|
||||
if(dataList!= null){
|
||||
String ids = "";
|
||||
for(AccountHead accountHead:dataList){
|
||||
ids = ids + accountHead.getId() +",";
|
||||
}
|
||||
ids = ids.substring(0,ids.length() -1);
|
||||
|
||||
System.out.println(">>>>>>>>>>>>>>>>>" + ids);
|
||||
|
||||
PageUtil<AccountItem> pageUtilOne = new PageUtil<AccountItem>();
|
||||
pageUtilOne.setPageSize(0);
|
||||
pageUtilOne.setCurPage(0);
|
||||
pageUtilOne.setAdvSearch(getCondition_getSumByDetail(id, ids));
|
||||
accountItemService.find(pageUtilOne);
|
||||
List<AccountItem> dataListOne = pageUtilOne.getPageList();
|
||||
if(dataListOne!= null){
|
||||
for(AccountItem accountItem:dataListOne){
|
||||
accountSum = accountSum + accountItem.getEachAmount();
|
||||
}
|
||||
}
|
||||
|
||||
System.out.println(">>>>>>>>>>>>>>>>>accountSum:" + accountSum);
|
||||
}
|
||||
}
|
||||
catch (DataAccessException e){
|
||||
Log.errorFileSync(">>>>>>>>>查找进销存信息异常", e);
|
||||
}
|
||||
catch (Exception e){
|
||||
Log.errorFileSync(">>>>>>>>>异常信息:", e);
|
||||
}
|
||||
return accountSum;
|
||||
}
|
||||
|
||||
/**
|
||||
* 查找结算账户信息-下拉框
|
||||
* @return
|
||||
@ -413,7 +499,7 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接搜索条件-结算账户当前余额求和
|
||||
* 拼接搜索条件
|
||||
* @return
|
||||
*/
|
||||
private Map<String,Object> getCondition_getSum(Long id,String monthTime)
|
||||
@ -431,6 +517,58 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
* @return
|
||||
*/
|
||||
private Map<String,Object> getCondition_getSumByHead(Long id,String monthTime)
|
||||
{
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
*/
|
||||
Map<String,Object> condition = new HashMap<String,Object>();
|
||||
condition.put("AccountId_n_eq", id);
|
||||
if(!monthTime.equals("")){
|
||||
condition.put("BillTime_s_gteq", monthTime + "-01 00:00:00");
|
||||
condition.put("BillTime_s_lteq", monthTime + "-31 00:00:00");
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
* @return
|
||||
*/
|
||||
private Map<String,Object> getCondition_getSumByHead(String monthTime)
|
||||
{
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
*/
|
||||
Map<String,Object> condition = new HashMap<String,Object>();
|
||||
if(!monthTime.equals("")){
|
||||
condition.put("BillTime_s_gteq", monthTime + "-01 00:00:00");
|
||||
condition.put("BillTime_s_lteq", monthTime + "-31 00:00:00");
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
* @return
|
||||
*/
|
||||
private Map<String,Object> getCondition_getSumByDetail(Long id, String ids)
|
||||
{
|
||||
/**
|
||||
* 拼接搜索条件
|
||||
*/
|
||||
Map<String,Object> condition = new HashMap<String,Object>();
|
||||
condition.put("AccountId_n_eq", id);
|
||||
if(!ids.equals("")){
|
||||
condition.put("HeaderId_s_in", ids);
|
||||
}
|
||||
return condition;
|
||||
}
|
||||
|
||||
//=============以下spring注入以及Model驱动公共方法,与Action处理无关==================
|
||||
@Override
|
||||
public AccountModel getModel()
|
||||
@ -444,4 +582,10 @@ public class AccountAction extends BaseAction<AccountModel>
|
||||
public void setDepotHeadService(DepotHeadIService depotHeadService) {
|
||||
this.depotHeadService = depotHeadService;
|
||||
}
|
||||
public void setAccountHeadService(AccountHeadIService accountHeadService) {
|
||||
this.accountHeadService = accountHeadService;
|
||||
}
|
||||
public void setAccountItemService(AccountItemIService accountItemService) {
|
||||
this.accountItemService = accountItemService;
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@ public class AccountItemAction extends BaseAction<AccountItemModel>
|
||||
try
|
||||
{
|
||||
Long headerId=model.getHeaderId();
|
||||
String listType = model.getListType(); //单据类型
|
||||
String inserted=model.getInserted();
|
||||
String deleted=model.getDeleted();
|
||||
String updated=model.getUpdated();
|
||||
@ -55,7 +56,13 @@ public class AccountItemAction extends BaseAction<AccountItemModel>
|
||||
accountItem.setHeaderId(new AccountHead(headerId));
|
||||
if(tempInsertedJson.get("AccountId")!=null&&!tempInsertedJson.get("AccountId").equals("")){accountItem.setAccountId(new Account(tempInsertedJson.getLong("AccountId")));}
|
||||
if(tempInsertedJson.get("InOutItemId")!=null&&!tempInsertedJson.get("InOutItemId").equals("")){accountItem.setInOutItemId(new InOutItem(tempInsertedJson.getLong("InOutItemId")));}
|
||||
if(tempInsertedJson.get("EachAmount")!=null){accountItem.setEachAmount(tempInsertedJson.getDouble("EachAmount"));}
|
||||
if(tempInsertedJson.get("EachAmount")!=null){
|
||||
Double eachAmount = tempInsertedJson.getDouble("EachAmount");
|
||||
if(listType.equals("付款")) {
|
||||
eachAmount = 0 - eachAmount;
|
||||
}
|
||||
accountItem.setEachAmount(eachAmount);
|
||||
}
|
||||
accountItem.setRemark(tempInsertedJson.getString("Remark"));
|
||||
accountItemService.create(accountItem);
|
||||
}
|
||||
@ -77,7 +84,13 @@ public class AccountItemAction extends BaseAction<AccountItemModel>
|
||||
accountItem.setHeaderId(new AccountHead(headerId));
|
||||
if(tempUpdatedJson.get("AccountId")!=null&&!tempUpdatedJson.get("AccountId").equals("")){accountItem.setAccountId(new Account(tempUpdatedJson.getLong("AccountId")));}
|
||||
if(tempUpdatedJson.get("InOutItemId")!=null&&!tempUpdatedJson.get("InOutItemId").equals("")){accountItem.setInOutItemId(new InOutItem(tempUpdatedJson.getLong("InOutItemId")));}
|
||||
if(tempUpdatedJson.get("EachAmount")!=null){accountItem.setEachAmount(tempUpdatedJson.getDouble("EachAmount"));}
|
||||
if(tempUpdatedJson.get("EachAmount")!=null){
|
||||
Double eachAmount = tempUpdatedJson.getDouble("EachAmount");
|
||||
if(listType.equals("付款")) {
|
||||
eachAmount = 0 - eachAmount;
|
||||
}
|
||||
accountItem.setEachAmount(eachAmount);
|
||||
}
|
||||
accountItem.setRemark(tempUpdatedJson.getString("Remark"));
|
||||
accountItemService.create(accountItem);
|
||||
}
|
||||
@ -144,7 +157,8 @@ public class AccountItemAction extends BaseAction<AccountItemModel>
|
||||
item.put("AccountName", accountItem.getAccountId()==null?"":accountItem.getAccountId().getName());
|
||||
item.put("InOutItemId", accountItem.getInOutItemId()==null?"":accountItem.getInOutItemId().getId());
|
||||
item.put("InOutItemName", accountItem.getInOutItemId()==null?"":accountItem.getInOutItemId().getName());
|
||||
item.put("EachAmount", accountItem.getEachAmount());
|
||||
Double eachAmount = accountItem.getEachAmount();
|
||||
item.put("EachAmount", eachAmount < 0 ? 0-eachAmount : eachAmount);
|
||||
item.put("Remark", accountItem.getRemark());
|
||||
item.put("op", 1);
|
||||
dataArray.add(item);
|
||||
|
||||
@ -20,6 +20,7 @@ public class AccountItemModel implements Serializable
|
||||
private String Updated = ""; //json修改记录
|
||||
|
||||
private String HeadIds = ""; //表头集合列表
|
||||
private String ListType = ""; //单据类型
|
||||
private String MonthTime = ""; //月份
|
||||
private String browserType = "";
|
||||
/**
|
||||
@ -157,6 +158,14 @@ public class AccountItemModel implements Serializable
|
||||
return HeadIds;
|
||||
}
|
||||
|
||||
public String getListType() {
|
||||
return ListType;
|
||||
}
|
||||
|
||||
public void setListType(String listType) {
|
||||
ListType = listType;
|
||||
}
|
||||
|
||||
public void setMonthTime(String monthTime)
|
||||
{
|
||||
MonthTime = monthTime;
|
||||
|
||||
@ -307,6 +307,8 @@
|
||||
<bean id="accountAction" class="com.jsh.action.basic.AccountAction" scope="prototype">
|
||||
<property name="accountService" ref="accountService"/>
|
||||
<property name="depotHeadService" ref="depotHeadService"/>
|
||||
<property name="accountHeadService" ref="accountHeadService"/>
|
||||
<property name="accountItemService" ref="accountItemService"/>
|
||||
<property name="logService" ref="logService"/>
|
||||
</bean>
|
||||
<!--结算账户配置结束 -->
|
||||
|
||||
@ -235,9 +235,10 @@
|
||||
+ 'AaBb' + rec.HandsPersonId + 'AaBb' + rec.HandsPersonName + 'AaBb' + rec.ChangeAmount + 'AaBb' + rec.TotalPrice;
|
||||
if(1 == value)
|
||||
{
|
||||
var orgId = rec.OrganId ? rec.OrganId : 0;
|
||||
str += '<img src="' + path + '/js/easyui-1.3.5/themes/icons/list.png" style="cursor: pointer;" onclick="showAccountHead(\'' + rowInfo + '\');"/> <a onclick="showAccountHead(\'' + rowInfo + '\');" style="text-decoration:none;color:black;" href="javascript:void(0)">查看</a> ';
|
||||
str += '<img src="' + path + '/js/easyui-1.3.5/themes/icons/pencil.png" style="cursor: pointer;" onclick="editAccountHead(\'' + rowInfo + '\');"/> <a onclick="editAccountHead(\'' + rowInfo + '\');" style="text-decoration:none;color:black;" href="javascript:void(0)">编辑</a> ';
|
||||
str += '<img src="' + path + '/js/easyui-1.3.5/themes/icons/edit_remove.png" style="cursor: pointer;" onclick="deleteAccountHead('+ rec.Id +',' + rec.OrganId +',' + rec.TotalPrice+ ');"/> <a onclick="deleteAccountHead('+ rec.Id +',' + rec.OrganId +',' + rec.TotalPrice +');" style="text-decoration:none;color:black;" href="javascript:void(0)">删除</a>';
|
||||
str += '<img src="' + path + '/js/easyui-1.3.5/themes/icons/edit_remove.png" style="cursor: pointer;" onclick="deleteAccountHead('+ rec.Id +',' + orgId +',' + rec.TotalPrice+ ');"/> <a onclick="deleteAccountHead('+ rec.Id +',' + orgId +',' + rec.TotalPrice +');" style="text-decoration:none;color:black;" href="javascript:void(0)">删除</a>';
|
||||
}
|
||||
return str;
|
||||
}
|
||||
@ -787,11 +788,11 @@
|
||||
if(listType !=="转账"){
|
||||
OrganId = $('#OrganId').combobox('getValue');
|
||||
}
|
||||
if(listType === "支出"){
|
||||
if(listType === "支出" || listType === "转账"){
|
||||
//支出为负数
|
||||
ChangeAmount = 0 - ChangeAmount;
|
||||
}
|
||||
if(listType === "支出" || listType === "付款"){
|
||||
if(listType === "支出" || listType === "付款" || listType === "转账"){
|
||||
//支出和付款为负数
|
||||
TotalPrice = 0 - TotalPrice;
|
||||
}
|
||||
@ -850,11 +851,11 @@
|
||||
if(accountHeadID ==0)
|
||||
{
|
||||
getMaxId(); //查找最大的Id
|
||||
accept(accountHeadMaxId); //新增
|
||||
accept(accountHeadMaxId,listType); //新增
|
||||
}
|
||||
else
|
||||
{
|
||||
accept(accountHeadID); //修改
|
||||
accept(accountHeadID,listType); //修改
|
||||
}
|
||||
|
||||
$('#accountHeadDlg').dialog('close');
|
||||
@ -1030,7 +1031,7 @@
|
||||
return true;
|
||||
}
|
||||
//保存
|
||||
function accept(accepId) {
|
||||
function accept(accepId,listType) {
|
||||
append();
|
||||
removeit();
|
||||
if ($("#accountData").datagrid('getChanges').length) {
|
||||
@ -1047,6 +1048,7 @@
|
||||
Deleted: JSON.stringify(deleted),
|
||||
Updated: JSON.stringify(updated),
|
||||
HeaderId: accepId,
|
||||
ListType: listType,
|
||||
clientIp: clientIp
|
||||
},
|
||||
success: function (tipInfo)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user