Compare commits

...

2 Commits

2 changed files with 131 additions and 9 deletions

View File

@ -4,6 +4,7 @@ import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.operate.FormOperate;
import kd.bos.orm.query.QCP;
@ -51,38 +52,40 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
filter.and(new QFilter("zcgj_isnew", QCP.equals, true));//是否最新
DynamicObjectCollection rptAssistBalanceGxCollection = QueryServiceHelper.query("zcgj_rpt_assistbalancegx",
"id,zcgj_account,zcgj_processname",
new QFilter[]{filter});//核算维度余额取数表(矿山工序维度)
new QFilter[]{filter});//"核算维度余额取数表(矿山工序维度)"
for (DynamicObject rptAssistBalanceGx : rptAssistBalanceGxCollection) {
QFilter[] qFilter = new QFilter[]{new QFilter("id", QCP.equals, rptAssistBalanceGx.get("zcgj_account"))};
DynamicObject bd_accountview = BusinessDataServiceHelper.loadSingle("bd_accountview",
"id,number,name", qFilter);//会计科目
"id,number,name", qFilter);//"会计科目"
if (bd_accountview == null) {
continue;
}
QFilter filter1 = new QFilter("zcgj_acccostentry.zcgj_accountname", QCP.equals, bd_accountview.getString("name"));//科目名称
filter1.and(new QFilter("zcgj_acccostentry.zcgj_accountnumber", QCP.equals, bd_accountview.getString("number")));//科目编码
// filter1.and(new QFilter("zcgj_org", QCP.equals, org1.getPkValue()));//组织
QFilter filter1 = new QFilter("zcgj_acccostentry.zcgj_accountnumber", QCP.equals, bd_accountview.getString("number"));//科目编码
DynamicObject zcgj_accountcost = QueryServiceHelper.queryOne("zcgj_accountcost",
"id,zcgj_acccostentry.zcgj_costtype,zcgj_acccostentry.zcgj_sectype",
new QFilter[]{filter1});//会计科目与成本项目
new QFilter[]{filter1});//"会计科目与成本项目"
QFilter[] qFilters = new QFilter[]{new QFilter("name", QCP.equals, rptAssistBalanceGx.get("zcgj_processname"))};//工序名称
DynamicObject ec_ecbd_pro_cbs = BusinessDataServiceHelper.loadSingle("ec_ecbd_pro_cbs", "id", qFilters);//项目工序
DynamicObject ec_ecbd_pro_cbs = BusinessDataServiceHelper.loadSingle("ec_ecbd_pro_cbs", "id", qFilters);//"项目工序"
QFilter filter2 = new QFilter("fiaccountorg", QCP.equals, org1.getPkValue());//财务记账组织
filter2.and(new QFilter("billstatus", QCP.equals, "C"));//单据状态
DynamicObject[] ec_projects = BusinessDataServiceHelper.load("ec_project", "id,zcgj_init", new QFilter[]{filter2});// 项目
DynamicObject[] ec_projects = BusinessDataServiceHelper.load("ec_project", "id,zcgj_init", new QFilter[]{filter2});// "项目"
if (ec_ecbd_pro_cbs == null && zcgj_accountcost == null && ec_projects.length == 0) {
continue;
}
DynamicObject newEntry = new DynamicObject(entryType);
DynamicObjectCollection subEntryEntityCollection = newEntry.getDynamicObjectCollection("zcgj_subentryentity");//成本核算维度明细
DynamicObjectType subEntryEntityType = subEntryEntityCollection.getDynamicObjectType();
DynamicObject newEntrySubEntryEntity = new DynamicObject(subEntryEntityType);
if (ec_projects.length != 0) {
for (DynamicObject ec_project : ec_projects) {
boolean zcgj_init = ec_project.getBoolean("zcgj_init");//默认项目
if (zcgj_init) {
DynamicObject ec_project_f7 = BusinessDataServiceHelper.loadSingle("ec_project_f7", "id",
new QFilter[]{new QFilter("id", QCP.equals, ec_project.getPkValue())});//项目
newEntry.set("project", ec_project_f7);//项目
newEntry.set("project", ec_project_f7);//"项目"
newEntrySubEntryEntity.set("zcgj_project", ec_project_f7);
break;
}
}
@ -91,19 +94,42 @@ public class EntCostSplitBillPlugin extends AbstractBillPlugIn {
DynamicObject ec_project_f7 = BusinessDataServiceHelper.loadSingle("ec_project_f7", "id",
new QFilter[]{new QFilter("id", QCP.equals, ec_projects[0].getPkValue())});//项目
newEntry.set("project", ec_project_f7);//项目
newEntrySubEntryEntity.set("zcgj_project", ec_project_f7);
}
}
if (ec_ecbd_pro_cbs != null) {
newEntry.set("cbs", ec_ecbd_pro_cbs);//成本分解结构
newEntrySubEntryEntity.set("zcgj_cbs", ec_ecbd_pro_cbs);
}
if (zcgj_accountcost != null) {
newEntry.set("costtype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype"));//成本项
newEntry.set("zcgj_sectype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype"));//二级分类
newEntrySubEntryEntity.set("zcgj_costtype", zcgj_accountcost.get("zcgj_acccostentry.zcgj_costtype"));
newEntrySubEntryEntity.set("zcgj_sectype1", zcgj_accountcost.get("zcgj_acccostentry.zcgj_sectype"));
}
entryCollection.add(newEntry);
subEntryEntityCollection.add(newEntrySubEntryEntity);
}
this.getView().updateView("entryentity");//刷新分录
this.getView().updateView("zcgj_subentryentity");//刷新分录
this.getModel().endInit();
this.getView().invokeOperation("save");
this.getView().invokeOperation("refresh");
} else if ("newentry1".equals(formOperate.getOperateKey())) {
//成本核算维度明细子分录增行按钮
int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity");//企业费用成本分摊明细分录行索引
int rowCount = this.getModel().getEntryRowCount("entryentity");//企业费用成本分摊明细分录总行数
if (rowCount > 0 && rowIndex >= 0) {
int subInd = this.getModel().createNewEntryRow("zcgj_subentryentity");//新增子分录行数
this.getModel().setValue("zcgj_project", this.getModel().getValue("project", rowIndex), subInd);
this.getModel().setValue("zcgj_cbs", this.getModel().getValue("cbs", rowIndex), subInd);
this.getModel().setValue("zcgj_costtype", this.getModel().getValue("costtype", rowIndex), subInd);
this.getModel().setValue("zcgj_sectype1", this.getModel().getValue("zcgj_sectype", rowIndex), subInd);
args.setCancel(true);
} else {
this.getView().showTipNotification(ResManager.loadKDString("请先选中1行企业费用成本分摊明细分录行数据", "MaterialCostBillPlugin_1", "ec-ecco-formplugin", new Object[0]));
args.setCancel(true);
}
}
}
}

View File

@ -0,0 +1,96 @@
package zcgj.zcdev.zcdev.pr.plugin.operate;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.plugin.AbstractOperationServicePlugIn;
import kd.bos.entity.plugin.AddValidatorsEventArgs;
import kd.bos.entity.plugin.PreparePropertysEventArgs;
import kd.bos.entity.validate.AbstractValidator;
import java.math.BigDecimal;
/**
* 入库单提交操作校验插件
* 说明校验存在发票时发票分录中的金额税额和价税合计与入库单明细中的金额税额和价税合计是否一致
*/
public class MaterialInBillSubmitValidatorOp extends AbstractOperationServicePlugIn {
public void onPreparePropertys(PreparePropertysEventArgs e) {
super.onPreparePropertys(e);
e.getFieldKeys().add("zcgj_entryentity");
e.getFieldKeys().add("entryentity");
e.getFieldKeys().add("zcgj_invoiceamount");
e.getFieldKeys().add("zcgj_invoicetax");
e.getFieldKeys().add("zcgj_oftaxinvoiceamount");
e.getFieldKeys().add("notaxamount");
e.getFieldKeys().add("taxamount");
e.getFieldKeys().add("oftaxamount");
}
@Override
public void onAddValidators(AddValidatorsEventArgs e) {
super.onAddValidators(e);
e.getValidators().add(new ValidatorExt());
}
class ValidatorExt extends AbstractValidator {
@Override
public void validate() {
ExtendedDataEntity[] extendedDataEntities = this.getDataEntities();
for (ExtendedDataEntity extendedDataEntity : extendedDataEntities) {
DynamicObject ecma_MaterialInBill = extendedDataEntity.getDataEntity();
DynamicObjectCollection entryEntityCollection = ecma_MaterialInBill.getDynamicObjectCollection("zcgj_entryentity");//合同进项发票信息
DynamicObjectCollection entryEntity2Collection = ecma_MaterialInBill.getDynamicObjectCollection("entryentity");//入库单分录
if (entryEntityCollection != null && entryEntityCollection.size() > 0 && entryEntity2Collection != null && entryEntity2Collection.size() > 0) {
BigDecimal totalInvoiceAmount = BigDecimal.ZERO; // 发票总金额
BigDecimal totalInvoiceTax = BigDecimal.ZERO; // 发票总税额
BigDecimal totalInvoiceTotal = BigDecimal.ZERO; // 发票总价税合计
BigDecimal totalEntryAmount = BigDecimal.ZERO; // 入库单总金额
BigDecimal totalEntryTax = BigDecimal.ZERO; // 入库单总税额
BigDecimal totalEntryTotal = BigDecimal.ZERO; // 入库单总价税合计
for (DynamicObject entryEntity : entryEntityCollection) {
BigDecimal invoiceAmount = entryEntity.getBigDecimal("zcgj_invoiceamount"); // 合同进项发票信息-金额
BigDecimal invoiceTax = entryEntity.getBigDecimal("zcgj_invoicetax"); // 合同进项发票信息-税额
BigDecimal invoiceTotal = entryEntity.getBigDecimal("zcgj_oftaxinvoiceamount"); // 合同进项发票信息-价税合计
if (invoiceAmount != null) {
totalInvoiceAmount = totalInvoiceAmount.add(invoiceAmount);
}
if (invoiceTax != null) {
totalInvoiceTax = totalInvoiceTax.add(invoiceTax);
}
if (invoiceTotal != null) {
totalInvoiceTotal = totalInvoiceTotal.add(invoiceTotal);
}
}
for (DynamicObject entryEntity2 : entryEntity2Collection) {
BigDecimal notaxAmount = entryEntity2.getBigDecimal("notaxamount"); // 入库单-金额
BigDecimal taxAmount = entryEntity2.getBigDecimal("taxamount"); // 入库单-税额
BigDecimal oftaxAmount = entryEntity2.getBigDecimal("oftaxamount"); // 入库单-含税金额
if (notaxAmount != null) {
totalEntryAmount = totalEntryAmount.add(notaxAmount);
}
if (taxAmount != null) {
totalEntryTax = totalEntryTax.add(taxAmount);
}
if (oftaxAmount != null) {
totalEntryTotal = totalEntryTotal.add(oftaxAmount);
}
}
if (totalInvoiceAmount.compareTo(totalEntryAmount) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库单明细金额汇总与合同进项发票信息金额汇总不匹配!");
}
if (totalInvoiceTax.compareTo(totalEntryTax) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库单明细税额汇总与合同进项发票信息税额汇总不匹配!");
}
if (totalInvoiceTotal.compareTo(totalEntryTotal) != 0) {
this.addFatalErrorMessage(extendedDataEntity, "入库单明细含税金额汇总与合同进项发票信息价税合计汇总不匹配!");
}
}
}
}
}
}