资金日报

This commit is contained in:
“wyx12345678” 2024-08-07 09:30:09 +08:00
parent 48f4a4ccae
commit 1981f693b6
1 changed files with 134 additions and 8 deletions

View File

@ -12,6 +12,7 @@ import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.org.OrgUnitServiceHelper;
import kd.sdk.plugin.Plugin;
import java.math.BigDecimal;
@ -27,7 +28,7 @@ import java.util.*;
public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin implements Plugin {
private static final Log logger = LogFactory.getLog(CapitalDayDataListShkdPlugin.class);
private static final Log logger = LogFactory.getLog(CapitalDayListDataPlugin.class);
@Override
public DataSet query(ReportQueryParam reportQueryParam, Object o) throws Throwable {
@ -35,10 +36,25 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
//获取过滤条件集合
Map<String, Object> paramMap = this.transQueryParam(reportQueryParam);
DynamicObjectCollection companys = (DynamicObjectCollection)paramMap.get("shkd_filter_company");//使用组织集合
DynamicObjectCollection groups = (DynamicObjectCollection)paramMap.get("shkd_filter_group");//使用组织集合
String shkd_queryorgtype = paramMap.get("shkd_queryorgtype").toString();//使用组织集合
ArrayList<Long> longs = new ArrayList<>();
String groupName = null;
//如果查询是查的集团然后想要查询需查询下级及下级所有公司的id
if("group".equals(shkd_queryorgtype)){
ArrayList<Long> grouplongs = new ArrayList<>();
for (DynamicObject group : groups) {
groupName = group.getString("name");
grouplongs.add(group.getLong("id"));
}
List<Long> allSubordinateOrgs = OrgUnitServiceHelper.getAllSubordinateOrgs(8L, grouplongs, true);
longs.addAll(allSubordinateOrgs);
}else{
for (DynamicObject company : companys) {
longs.add(company.getLong("id"));
}
}
Date firstDate = (Date)paramMap.get("shkd_firstdate");//开始时间
Date endDate = (Date)paramMap.get("shkd_enddate");//结束时间
DynamicObject orgcurrency = (DynamicObject) paramMap.get("shkd_orgcurrency");
@ -67,7 +83,18 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
Collection<Object[]> firmParams = null;
if (cas_cashmgtinits != null){
firmParams = new ArrayList<Object[]>(cas_cashmgtinits.length);//多公司数据集合
BigDecimal payTotal = BigDecimal.ZERO; //总计 期间支出合计
BigDecimal recTotal = BigDecimal.ZERO; //总计 期间收入合计
BigDecimal payLB = BigDecimal.ZERO; //内部往来,支出合计
BigDecimal recLB = BigDecimal.ZERO; //内部往来 期间收入合计
for (int i = 0; i < cas_cashmgtinits.length; i++) {
//若是集团需要在第一行拼接第一行的数据
if("group".equals(shkd_queryorgtype)&&i == 0){
Object[] firmParam = new Object[7];//存放公司数据
firmParam[0] = i;//存放序号
firmParam[1] = groupName;//存放集团名称,先优先考虑单集团的凭借
firmParams.add(firmParam);
}
DynamicObject startperiod = cas_cashmgtinits[i].getDynamicObject("startperiod");
if (startperiod != null){
Object pkValue = startperiod.getPkValue();
@ -151,9 +178,13 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
if (orgcurrency != null){
per_recQF.and("currency.id",QCP.equals,orgcurrencyId);
}
per_recQF.and("payeedate",QCP.large_equals,startDate);
per_recQF.and("payeedate",QCP.less_equals,overDate);
DynamicObject[] per_cas_recbills = BusinessDataServiceHelper.load("cas_recbill", "id,org,org.id,org.number,actrecamt,currency", per_recQF.toArray());
per_recQF.and("bizdate",QCP.large_equals,startDate);
per_recQF.and("bizdate",QCP.less_equals,overDate);
DynamicObject[] per_cas_recbills = BusinessDataServiceHelper.load("cas_recbill", "id,org,org.id,org.number,actrecamt,currency,payertype,customerf7,customerf7", per_recQF.toArray());
BigDecimal transactions = this.getTransactions(per_cas_recbills);
recLB =recLB.add(transactions); //内部往来收入合计
for (DynamicObject per_cas_recbill : per_cas_recbills) {
BigDecimal actrecamt = per_cas_recbill.getBigDecimal("actrecamt");
perRecAmountTotal = perRecAmountTotal.add(actrecamt);//添加收入金额
@ -170,7 +201,10 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
per_payQF.and("org.id",QCP.equals,orgPkValue);
per_payQF.and("paydate",QCP.large_equals,startDate);
per_payQF.and("paydate",QCP.less_equals,overDate);
DynamicObject[] per_cas_paybills = BusinessDataServiceHelper.load("cas_paybill", "id,org,org.id,org.number,payeenumber,actpayamt,currency", per_payQF.toArray());
DynamicObject[] per_cas_paybills = BusinessDataServiceHelper.load("cas_paybill", "id,org,org.id,org.number,payeenumber,actpayamt,currency,payeetype,payee", per_payQF.toArray());
BigDecimal transactionsByfk = this.getTransactionsByfk(per_cas_paybills);
payLB =payLB.add(transactionsByfk); //内部往来收入合计
for (DynamicObject per_cas_paybill : per_cas_paybills) {
String payNumber = per_cas_paybill.getDynamicObject("org").getString("number");
String recNumber = per_cas_paybill.getString("payeenumber");
@ -186,10 +220,27 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
BigDecimal endAmount = startAmount.add(perRecAmountTotal).subtract(perPayAmountTotal);
firmParam[5] = endAmount;
firmParams.add(firmParam);
}
payTotal = payTotal.add(perPayAmountTotal);
recTotal = recTotal.add(perRecAmountTotal);
}
}
}
//总计行的组装
Object[] firmParam = new Object[7];//存放公司数据
firmParam[1] = "总计";
firmParam[3] = recTotal; //今日收入合计
firmParam[4] = payTotal; //今日收入合计
firmParams.add(firmParam);
Object[] firmParam2 = new Object[7];//存放公司数据
firmParam2[1] = "内部往来";
firmParam2[3] = recLB; //今日收入合计
firmParam2[4] = payLB; //今日收入合计
firmParams.add(firmParam2);
//内部收支净额的组装
}
@ -276,4 +327,79 @@ public class CapitalDayListDataPlugin extends AbstractReportListDataPlugin imple
Date endOfDay = Date.from(startOfDay.atZone(ZoneId.systemDefault()).toInstant());
return endOfDay;
}
//内部往来收款单组装
public BigDecimal getTransactions(DynamicObject[] per_cas_recbills){
BigDecimal recAmountTotal = BigDecimal.ZERO;
for (DynamicObject per_cas_recbill : per_cas_recbills) {
//查询收款单为内部往来的公司
String payertype = per_cas_recbill.getString("payertype");//付款人类型
if("bd_customer".equals(payertype)||"bd_supplier".equals(payertype)||"bos_org".equals(payertype)){
if("bd_supplier".equals(payertype)){
DynamicObject f7_payer = per_cas_recbill.getDynamicObject("f7_payer");//供应商
long id = f7_payer.getLong("id");
QFilter per_recQF = new QFilter("billstatus", QCP.equals, "D");
per_recQF.and("org.id",QCP.equals,id);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
} else if ("bd_customer".equals(payertype)) {
DynamicObject customerf7 = per_cas_recbill.getDynamicObject("customerf7");//供应商
long id = customerf7.getLong("id");
QFilter per_recQF = new QFilter("billstatus", QCP.equals, "D");
per_recQF.and("org.id",QCP.equals,id);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
}
BigDecimal actrecamt = per_cas_recbill.getBigDecimal("actrecamt");
recAmountTotal = recAmountTotal.add(actrecamt);//添加收入金额
}
}
return recAmountTotal;
}
//内部往来付款合计
public BigDecimal getTransactionsByfk(DynamicObject[] per_cas_paybills){
BigDecimal perPayAmountTotal = BigDecimal.ZERO;
for (DynamicObject per_cas_paybill : per_cas_paybills) {
//查询收款单为内部往来的公司
String payertype = per_cas_paybill.getString("payeetype");//收款人款人类型
Long payerid = per_cas_paybill.getLong("payee");//供应商
if("bd_customer".equals(payertype)||"bd_supplier".equals(payertype)||"bos_org".equals(payertype)){
if("bd_supplier".equals(payertype)){
QFilter per_recQF = new QFilter("id",QCP.equals,payerid);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
} else if ("bd_customer".equals(payertype)) {
QFilter per_recQF = new QFilter("org.id",QCP.equals,payerid);
DynamicObject bd_supplier = BusinessDataServiceHelper.loadSingle("bd_supplier", "id,number,internal_company", per_recQF.toArray());
DynamicObject internal_company = bd_supplier.getDynamicObject("internal_company");
if(internal_company==null){
continue;
}
}
String payNumber = per_cas_paybill.getDynamicObject("org").getString("number");
String recNumber = per_cas_paybill.getString("payeenumber");
BigDecimal actpayamt = per_cas_paybill.getBigDecimal("actpayamt");
perPayAmountTotal = perPayAmountTotal.add(actpayamt);
if (payNumber.equals(recNumber)){//当付款编码同收款编码时
perPayAmountTotal = perPayAmountTotal.add(actpayamt);//补充收款数据
}
}
}
return perPayAmountTotal;
}
}