收入合同结算单功能开发

This commit is contained in:
zhangzhiguo 2025-05-30 08:49:35 +08:00
parent c32235fe53
commit 06ffd9292d
6 changed files with 773 additions and 1 deletions

View File

@ -0,0 +1,322 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.context.RequestContext;
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.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.CloseCallBack;
import kd.bos.form.ShowFormHelper;
import kd.bos.form.ShowType;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.operate.FormOperate;
import kd.bos.list.ListShowParameter;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.ec.basedata.common.invoicecloud.InvoiceDataHandleHelper;
import kd.ec.basedata.common.invoicecloud.bean.InvoiceVO;
import kd.ec.contract.utils.ImportInvoiceUtils;
import kd.fi.ap.piaozone.InvoiceCollectHelper;
import kd.sdk.plugin.Plugin;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;
/**
* 收入合同确认单发票导入插件
*/
public class InContractFinaceConfirmeInvoicePlugin extends AbstractBillPlugIn implements Plugin {
private static final Log log = LogFactory.getLog(InContractFinaceConfirmeInvoicePlugin.class);
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate operate = (FormOperate)args.getSource();
String key = operate.getOperateKey();
if (StringUtils.equals(key, "newsubentry")) { //选择发票
this.beforeNewSubEntry(args);
} else if (StringUtils.equals(key, "selectinvoice")) { //导入发票
this.showInvoiceImport(args);
}else if (key.equals("deletesubentry")) {
this.beforeDeleteSubEntry(args);
}
}
public void closedCallBack(ClosedCallBackEvent event) {
super.closedCallBack(event);//selectInvoice_2220454955754478592
String actionId = event.getActionId();
Object returnData = event.getReturnData();
//returnData = "{\"invoiceData\":[{\"xbrlName\":\"\",\"fileName\":\"\",\"specialTypeMark\":\"\",\"downloadUrl\":\"/dev/2170355234897924096/202505/5b96f486f0de44d4a437a482e830cf95/扬尚发票103417.6.pdf\",\"invoiceAmount\":\"91520\",\"needCheck\":\"1\",\"personFlag\":false,\"type\":\"0\",\"authenticateFlag\":1,\"isElectricInvoice\":\"1\",\"payee\":\"\",\"taxOfdUrl\":\"\",\"salerTaxNo\":\"91320117MADRMAMU8L\",\"invoiceType\":\"27\",\"orgNumber\":\"10006834\",\"invoiceNo\":\"25322000000224247311\",\"salerType\":\"\",\"area\":\"\",\"orgName\":\"南京矿山江苏溧水分公司\",\"buyerTaxNo\":\"913201176867400458\",\"resource\":\"发票助手\",\"selectTime\":\"\",\"originalState\":\"0\",\"companySeal\":\"0\",\"originalInvoiceNo\":\"\",\"xbrlType\":\"\",\"serialNo\":\"c2108f40b42046a986c5891cb59d65cc0\",\"xmlUrl\":\"\",\"checkFlag\":1,\"errorLevel\":\"3\",\"totalAmount\":\"103417.6\",\"xbrlUrl\":\"\",\"salerAddressPhone\":\"江苏省南京市溧水区溧水区晶桥镇枫香岭村配件小区16号 13305141166\",\"checkTime\":\"\",\"authenticateTime\":\"\",\"recordedPurpose\":\"\",\"salelistSum\":0,\"isRevise\":\"1\",\"region\":\"\",\"totalTaxAmount\":\"11897.6\",\"taxAmount\":\"11897.6\",\"recordedTime\":\"\",\"items\":[{\"unitPrice\":\"400\",\"num\":\"228.8\",\"preferentialPolicy\":\"\",\"zeroTaxRateFlag\":\"\",\"taxRate\":\"0.13\",\"unit\":\"\",\"vatException\":\"\",\"versionNo\":\"\",\"detailAmount\":\"91520\",\"specModel\":\"\",\"discountType\":\"0\",\"goodsCode\":\"3040502019900000000\",\"taxAmount\":\"11897.6\",\"goodsName\":\"*经营租赁*挖机租赁费\",\"seq\":\"0\"}],\"originalInvoiceCode\":\"\",\"deductionFlag\":\"1\",\"salerName\":\"南京扬尚机械租赁有限公司\",\"taxPeriod\":\"\",\"uploadSeq\":1747898704052000000,\"destArea\":\"\",\"proxyMark\":\"0\",\"remark\":\"购方开户银行:中国农业银行股份有限公司南京晶桥支行 银行账号10127901040003185销方开户银行中国工商银行股份有限公司南京珍珠南路支行 银行账号4301031809100080341\",\"delete\":\"1\",\"billCreateTime\":\"2025-05-22 10:45:53\",\"invoice_info\":\"ty_27,st_0,ex_1,ch_1,or_0,au_0,\",\"checkStatus\":\"1\",\"availableAmount\":\"103417.6\",\"imageUrl\":\"/dev/2170355234897924096/202505/rim/22/snap/f4f68a6c6cb84255a3a4e6b35fe710d60.jpg\",\"taxPdfUrl\":\"\",\"pixel\":\"\",\"recordedPeriod\":\"\",\"effectiveTaxAmount\":\"11897.6\",\"invoiceRiskLevel\":\"\",\"buyerAddressPhone\":\"南京市溧水区晶桥镇 18551696115\",\"originalFileName\":\"扬尚发票103417.6.pdf\",\"originalGraphUrl\":\"/dev/2170355234897924096/202505/5b96f486f0de44d4a437a482e830cf95/扬尚发票103417.6.pdf\",\"salerAccount\":\"销方开户银行:中国工商银行股份有限公司南京珍珠南路支行 银行账号4301031809100080341\",\"amount\":\"91520\",\"fileIndex\":\"\",\"validateMessage\":\"合规性校验通过\",\"drawer\":\"\",\"verifyResult\":[],\"updateTime\":\"2025-05-22 15:24:42\",\"reviewer\":\"\",\"invoiceDate\":\"2025-05-19\",\"buyerName\":\"中国非金属材料南京矿山工程有限公司溧水分公司\",\"invalidDate\":\"\",\"invoiceSource\":\"\",\"pdfurl\":\"/dev/2170355234897924096/202505/5b96f486f0de44d4a437a482e830cf95/扬尚发票103417.6.pdf\",\"sourceArea\":\"\",\"salelistComplete\":\"1\",\"buyerAccount\":\"购方开户银行:中国农业银行股份有限公司南京晶桥支行 银行账号10127901040003185\",\"rotationAngle\":\"0\",\"recordedStatus\":\"01\",\"snapshotUrl\":\"/dev/2170355234897924096/202505/rim/22/snap/f4f68a6c6cb84255a3a4e6b35fe710d60.jpg\",\"invoiceStatus\":\"0\",\"isModify\":\"0\",\"deductionPurpose\":\"\",\"expendStatus\":\"1\",\"fileType\":\"1\",\"expenseStatus\":\"1\",\"taxXmlUrl\":\"\"}],\"attachData\":[]}";
if (actionId.toLowerCase().startsWith("zcgj_entryentity") && returnData != null) {
this.invoiceCloseCallBack(event);
} else if (actionId.toLowerCase().startsWith("selectinvoice") && returnData != null) {
this.importInvoiceCallBack(returnData);
}
}
//选择发票 开始
protected void beforeNewSubEntry(BeforeDoOperationEventArgs args) {
String billId = this.getModel().getDataEntity().getPkValue().toString();
if (!billId.equals("0") && "A".equals(this.getModel().getValue("billstatus"))) {
this.showInvoice("zcgj_entryentity");
} else {
this.getView().showMessage(ResManager.loadKDString("单据不是暂存状态,请先保存单据。", "PaymentApplyEditUI_1", "ec-contract-formplugin", new Object[0]));
args.setCancel(true);
}
}
private void showInvoice(String entryType) {
long currencyId = ((DynamicObject)this.getModel().getValue("zcgj_currency")).getLong("id");
long orgId = ((DynamicObject)this.getModel().getValue("zcgj_invoice_org")).getLong("id");
QFilter filter = new QFilter("org", "=", orgId);
filter.and(new QFilter("isclaimed", "=", false));
filter.and(new QFilter("billstatus", "=", "C"));
filter.and(new QFilter("currency", "=", currencyId));
filter.and(new QFilter("invoicestatus", "!=", "2"));
filter.and(new QFilter("unapplyamount", ">", BigDecimal.ZERO));
QFilter filter1 = new QFilter("isclaimed", "=", true);
filter1.and(new QFilter("billstatus", "=", "C"));
DynamicObject contract = (DynamicObject)this.getModel().getValue("zcgj_contract");
if (contract != null) {
long contractId = contract.getLong("id");
filter1.and(new QFilter("contract", "=", contractId));
filter1.and(new QFilter("unapplyamount", ">", BigDecimal.ZERO));
DynamicObjectCollection contInvEntryCol = this.getModel().getEntryEntity("zcgj_entryentity");
if (contInvEntryCol.size() > 0) {
List<Long> selectedInvIds = new ArrayList(8);
for(DynamicObject contInvEntryObj : contInvEntryCol) {
DynamicObject invoice = contInvEntryObj.getDynamicObject("zcgj_invoice");
selectedInvIds.add(invoice.getLong("id"));
}
filter1.and(new QFilter("id", "not in", selectedInvIds));
}
ListShowParameter param = ShowFormHelper.createShowListForm("ec_out_invoice_f7", true);
param.getListFilterParameter().setFilter(filter.or(filter1));
param.setMultiSelect(true);
param.setCloseCallBack(new CloseCallBack(this, entryType));
param.getOpenStyle().setShowType(ShowType.Modal);
this.getView().showForm(param);
}
}
protected void invoiceCloseCallBack(ClosedCallBackEvent event) {
ListSelectedRowCollection rows = (ListSelectedRowCollection)event.getReturnData();
DynamicObject[] invArr = new DynamicObject[rows.size()];
int index = 0;
DynamicObject upContract = (DynamicObject)this.getModel().getValue("zcgj_contract");
for(ListSelectedRow row : rows) {
Object invoicePk = row.getPrimaryKeyValue().toString();
int rowIndex = this.getModel().createNewEntryRow("zcgj_entryentity");
this.getModel().setValue("zcgj_invoice", invoicePk.toString(), rowIndex);
DynamicObject invoice = BusinessDataServiceHelper.loadSingle(invoicePk, "ec_in_invoice", "unapplyinvtax,unapplyamount,isClaimed,contract,project,connecttype,currency,totalamount,totaltax,totaloftaxamount");
this.getModel().setValue("zcgj_invoicecurrency", invoice.getDynamicObject("currency") == null ? Long.valueOf("0") : invoice.getDynamicObject("currency").getPkValue(), rowIndex);
this.getModel().setValue("zcgj_invoiceamount", invoice.getBigDecimal("totalamount"), rowIndex);
this.getModel().setValue("zcgj_invoicetax", invoice.getBigDecimal("totaltax"), rowIndex);
this.getModel().setValue("zcgj_oftaxinvoiceamount", invoice.getBigDecimal("totaloftaxamount"), rowIndex);
this.getModel().setValue("zcgj_unapplyinvoftaxamt", invoice.getBigDecimal("unapplyamount"), rowIndex);
this.getModel().setValue("zcgj_unapplyinvtax", invoice.getBigDecimal("unapplyinvtax"), rowIndex);
this.getModel().setValue("zcgj_applyinvoftaxamt", invoice.getBigDecimal("unapplyamount"), rowIndex);
invArr[index++] = invoice;
invoice.set("isclaimed", true);
invoice.set("contract", upContract);
invoice.set("project", (DynamicObject)this.getModel().getValue("zcgj_project"));
invoice.set("connecttype", "contract");
}
SaveServiceHelper.save(invArr);
this.getView().invokeOperation("invoicesave");
}
protected BigDecimal getSum(String entryId, String columnId) {
int rowCount = this.getModel().getEntryRowCount(entryId);
BigDecimal totalAmount = BigDecimal.ZERO;
for(int i = 0; i < rowCount; ++i) {
BigDecimal amount = (BigDecimal)this.getModel().getValue(columnId, i);
amount = amount == null ? BigDecimal.ZERO : amount;
totalAmount = totalAmount.add(amount);
}
return totalAmount;
}
//选择发票 结束
//导入发票 开始
protected void showInvoiceImport(BeforeDoOperationEventArgs args) {
String billId = this.getModel().getDataEntity().getPkValue().toString();
if (!billId.equals("0") && "A".equals(this.getModel().getValue("billstatus"))) {
if (this.getModel().getValue("zcgj_invoice_org") == null) {
this.getView().showTipNotification(ResManager.loadKDString("发票企业名称不能为空", "PaymentApplyEditUI_18", "ec-contract-formplugin", new Object[0]));
args.setCancel(true);
} else {
if (!ImportInvoiceUtils.isXhInvoiceCloud()) {
args.setCancel(true);
ImportInvoiceUtils.showImportView(this);
}else{
args.setCancel(true);
DynamicObject org = (DynamicObject) this.getModel().getValue("zcgj_invoice_org");
InvoiceCollectHelper.showSelectInvoice(this, org);
}
}
} else {
this.getView().showMessage(ResManager.loadKDString("单据不是暂存状态,请先保存单据。", "PaymentApplyEditUI_1", "ec-contract-formplugin", new Object[0]));
args.setCancel(true);
}
}
protected void importInvoiceCallBack(Object returnData) {
DynamicObject org = (DynamicObject)this.getModel().getValue("zcgj_invoice_org");
//List<InvoiceVO> invoiceVOList = InvoiceDataHandleHelper.parseXhInvoiceCloudReturnData(returnData);
List<InvoiceVO> invoiceVOList = CustomInvoiceDataHandleHelper.parseXhInvoiceCloudReturnData(returnData);
Map<Boolean, Set<DynamicObject>> invoiceMap = InvoiceDataHandleHelper.processInvoiceVO(invoiceVOList, RequestContext.get().getCurrUserId(),
org.getLong("id"), new Date(), "ec_in_invoice", (DynamicObject)this.getModel().getValue("zcgj_currency"), true);
ImportInvoiceUtils invoiceUtils = new ImportInvoiceUtils(this.getView(), this.getPageCache());
this.addInvoiceToEntry(invoiceUtils, invoiceMap);
}
protected void addInvoiceToEntry(ImportInvoiceUtils invoiceUtils, Map<Boolean, Set<DynamicObject>> invoiceMap) {
if (invoiceMap.isEmpty()) {
this.getView().showTipNotification(ResManager.loadKDString("导入发票为空。", "PaymentApplyEditUI_19", "ec-contract-formplugin", new Object[0]));
} else {
long orgId = (Long)((DynamicObject)this.getModel().getValue("zcgj_invoice_org")).getPkValue();
Set<DynamicObject> newInvoices = (Set)invoiceMap.get(Boolean.TRUE);
Set<DynamicObject> existInvoices = (Set)invoiceMap.get(Boolean.FALSE);
if (newInvoices != null && !newInvoices.isEmpty()) {
for(DynamicObject newInvoice : newInvoices) {
DynamicObject buyerOrg = newInvoice.getDynamicObject("buyer");
if (buyerOrg != null && buyerOrg.getLong("id") != orgId) {
this.getView().showErrorNotification(ResManager.loadKDString("导入失败:当前发票购买方不为当前财务记账组织,请确认信息。", "PaymentApplyEditUI_20", "ec-contract-formplugin", new Object[0]));
return;
}
}
this.saveInvoiceData(invoiceUtils, newInvoices, existInvoices);
} else if (existInvoices != null) {
DynamicObjectCollection contInvEntryCol = this.getModel().getEntryEntity("zcgj_entryentity");
Map<Object, Object> entryMap = (Map)contInvEntryCol.stream().collect(Collectors.toMap(this::getInvoicePK, this::getInvoicePK));
this.initSubEntryEntity(existInvoices, entryMap);
}
}
}
protected void saveInvoiceData(ImportInvoiceUtils invoiceUtils, Set<DynamicObject> newInvoices, Set<DynamicObject> existInvoices) {
invoiceUtils.saveInvoiceAndGiveTips(newInvoices, existInvoices);
if (newInvoices != null && existInvoices != null) {
newInvoices.addAll(existInvoices);
}
this.initSubEntryEntity(newInvoices, (Map)null);
}
protected void initSubEntryEntity(Set<DynamicObject> invoices, Map<Object, Object> entryMap) {
if (invoices != null) {
List<DynamicObject> invArr = new ArrayList(invoices.size());
for(DynamicObject invoice : invoices) {
if (entryMap != null && entryMap.get(invoice.getPkValue()) != null) {
this.getView().showTipNotification(String.format(ResManager.loadKDString("发票号码%s已存在分录行", "PaymentApplyEditUI_22", "ec-contract-formplugin", new Object[0]), invoice.getString("invoiceno")));
} else {
BigDecimal unApplyAmount = invoice.getBigDecimal("unapplyamount");
if (unApplyAmount != null && unApplyAmount.doubleValue() <= (double)0.0F) {
this.getView().showTipNotification(String.format(ResManager.loadKDString("发票号码%s金额已经被关联完毕不可重复使用", "PaymentApplyEditUI_23", "ec-contract-formplugin", new Object[0]), invoice.getString("invoiceno")));
} else {
DynamicObject upContract = (DynamicObject)this.getModel().getValue("zcgj_contract");
int rowIndex = this.getModel().createNewEntryRow("zcgj_entryentity");
this.getModel().setValue("zcgj_invoice", invoice.getPkValue(), rowIndex);
this.getModel().setValue("zcgj_invoicecurrency", invoice.getDynamicObject("currency") == null ? Long.valueOf("0") : invoice.getDynamicObject("currency").getPkValue(), rowIndex);
this.getModel().setValue("zcgj_invoiceamount", invoice.getBigDecimal("totalamount"), rowIndex);
this.getModel().setValue("zcgj_invoicetax", invoice.getBigDecimal("totaltax"), rowIndex);
this.getModel().setValue("zcgj_oftaxinvoiceamount", invoice.getBigDecimal("totaloftaxamount"), rowIndex);
this.getModel().setValue("zcgj_unapplyinvoftaxamt", invoice.getBigDecimal("unapplyamount"), rowIndex);
this.getModel().setValue("zcgj_unapplyinvtax", invoice.getBigDecimal("unapplyinvtax"), rowIndex);
this.getModel().setValue("zcgj_applyinvoftaxamt", invoice.getBigDecimal("unapplyamount"), rowIndex);
invoice.set("isclaimed", true);
invoice.set("contract", upContract);
invoice.set("project", (DynamicObject)this.getModel().getValue("zcgj_project"));
invoice.set("connecttype", "contract");
invArr.add(invoice);
}
}
}
if (invArr.size() > 0) {
SaveServiceHelper.save((DynamicObject[])invArr.toArray(new DynamicObject[invoices.size()]));
}
this.getView().invokeOperation("invoicesave");
}
}
protected Object getInvoicePK(DynamicObject object) {
return object.getDynamicObject("invoice").getPkValue();
}
//导入发票 结束
//删除发票 开始
protected void beforeDeleteSubEntry(BeforeDoOperationEventArgs args) {
EntryGrid subGrid = (EntryGrid)this.getControl("zcgj_entryentity");
int[] selRows = subGrid.getEntryState().getSelectedRows();
if (selRows.length == 0) {
this.getView().showMessage(ResManager.loadKDString("请选择发票。", "PaymentApplyEditUI_3", "ec-contract-formplugin", new Object[0]));
args.setCancel(true);
} else {
Object[] delPks = new Object[selRows.length];
Set<Object> updateInvoicePks = new HashSet(selRows.length);
DynamicObjectCollection subEntryEntityCol = this.getModel().getEntryEntity("zcgj_entryentity");
for(int i = selRows.length - 1; i >= 0; --i) {
int rowIndex = selRows[i];
DynamicObject invoice = (DynamicObject)this.getModel().getValue("zcgj_invoice", rowIndex);
updateInvoicePks.add(invoice.getPkValue());
delPks[i] = ((DynamicObject)subEntryEntityCol.get(selRows[i])).getPkValue();
this.getModel().deleteEntryRow("zcgj_entryentity", rowIndex);
}
// this.setApplyAmtByInvoice(this.getModel().getEntryCurrentRowIndex("entryentity"));
// DynamicObjectType entryentityDT = DynamicObjectTypeUtils.getEntryDynamicObjectType("ec_paymentapply", "entryentity");
DynamicObjectType subDT = this.getModel().getDataEntity().getDynamicObjectCollection("zcgj_entryentity").getDynamicObjectType();
// DynamicObjectType subDT = this.getModel().getDynamicObjectCollection("zcgj_entryentity").getDynamicObjectType();
QFilter filter = new QFilter("zcgj_entryentity.zcgj_invoice", "in", updateInvoicePks);
filter.and("id", "!=", this.getModel().getDataEntity().getPkValue());
DynamicObjectCollection invoiceApplyEntries = QueryServiceHelper.query("zcgj_ec_in_finaceconfirm", "zcgj_entryentity.zcgj_invoice", new QFilter[]{filter});
if (invoiceApplyEntries != null && !invoiceApplyEntries.isEmpty()) {
for(DynamicObject subEntry : invoiceApplyEntries) {
updateInvoicePks.remove(subEntry.get("zcgj_entryentity.zcgj_invoice"));
}
}
if (!updateInvoicePks.isEmpty()) {
DynamicObject[] invoices = BusinessDataServiceHelper.load("ec_in_invoice", "isinvoiceclaim,isclaimed,contract,project,connecttype",
new QFilter[]{new QFilter("id", "in", updateInvoicePks)});
for(DynamicObject invoice : invoices) {
if (!invoice.getBoolean("isinvoiceclaim")) {
invoice.set("isclaimed", false);
invoice.set("contract", (Object)null);
invoice.set("project", (Object)null);
invoice.set("connecttype", "null");
}
}
SaveServiceHelper.save(invoices);
}
DeleteServiceHelper.delete(subDT, delPks);
this.getView().showSuccessNotification("发票删除成功!");
//this.setEnableByInvoice();
}
}
//删除发票 结束
}

View File

@ -0,0 +1,100 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.bill.BillShowParameter;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.ShowType;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.events.HyperLinkClickArgs;
import kd.bos.list.BillList;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
/**
* 收入合同结算财务确认单
*/
public class InContractFinaceConfirmeListPlugin extends AbstractListPlugin implements Plugin {
private static final Log log = LogFactory.getLog(InContractFinaceConfirmeListPlugin.class);
@Override
public void billListHyperLinkClick(HyperLinkClickArgs args) {
String fieldName = args.getFieldName();
if ("zcgj_ec_in_contract_sett_billno".equals(fieldName)) {
// 超链接点击为编码时取消原逻辑 跳转至自定义页面
showOutContractSettleForm();
args.setCancel(true);
}
}
private void showOutContractSettleForm() {
BillList billList = this.getView().getControl(AbstractListPlugin.BILLLISTID);
// 获取表单选中行
ListSelectedRowCollection selectedRows = billList.getSelectedRows();
Object[] primaryKeyValues = selectedRows.getPrimaryKeyValues();
DynamicObject dynamicObject = BusinessDataServiceHelper.loadSingle(primaryKeyValues[0], "zcgj_ec_in_finaceconfirm"); // 替换为实际表单标识
if (dynamicObject != null) {
// 获取业务单据编号值
Long billId = dynamicObject.getLong("zcgj_ec_in_contractid"); // 替换为实际字段标识
BillShowParameter showParameter = new BillShowParameter();
showParameter.setPkId(billId);
showParameter.setFormId("ec_in_contract_settle");
showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage); //打开方式
getView().showForm(showParameter);
}
}
@Override
public void itemClick(ItemClickEvent evt) {
super.itemClick(evt);
String itemKey = evt.getItemKey();
/*if("zcgj_deletevoucher".equals(itemKey)){
BillList billList = this.getView().getControl(AbstractListPlugin.BILLLISTID);
//获取到选中行的数据
ListSelectedRowCollection selectedRows = billList.getSelectedRows();
if(selectedRows.isEmpty()){
this.getView().showTipNotification(String.format("请选择需要删除凭证的数据。"));
return;
}
List<Long> voucherIds = new ArrayList<>();
int errorCount =0;
int allCount =0;
int successCount =0;
for (ListSelectedRow selectedRow : selectedRows) {
Long pk = (Long) selectedRow.getPrimaryKeyValue();
log.info("OutContractFinaceConfirmeListPlugin-delete:billid:"+pk);
DynamicObject voucherObject = BusinessDataServiceHelper.loadSingle("gl_voucher", "id",
new QFilter[]{new QFilter("sourcebill", QCP.equals, pk)
.and(new QFilter("sourcebilltype.number", QCP.equals, "zcgj_ec_out_finaceconfirm"))
//.and(new QFilter("billno", QCP.equals, vouchernum))
});
long voucherId = voucherObject.getLong("id");
log.info("TaskListBuildVoucherPlugin-delete:voucherId:"+voucherId);
Map<String,Object> params = new HashMap<String,Object>();
Map<String,Long> idMap = new HashMap<>();
idMap.put("id", voucherId);
params.put("data",idMap);
OpenApiResult invoke = OpenApiSdkUtil.invoke("/v2/gl/gl_voucher/delete", params);
Map<String, Object> map = invoke.toMap();
if(map.get("status").toString().equals("true")){
successCount++;
}else{
errorCount++;
log.info("OutContractFinaceConfirmeListPlugin-delete:error:"+invoke.getMessage());
}
allCount++;
}
if(errorCount == 0){//没有失败的使用成功弹框提醒
this.getView().showSuccessNotification(String.format("删除凭证完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount));
}else{//有失败的使用警告弹框提醒
this.getView().showTipNotification(String.format("删除凭证完成,一共%d条成功%d条失败%d条。",allCount,successCount,errorCount));
}
this.getView().invokeOperation("refresh");//调用表单的刷新操作
}*/
}
}

View File

@ -0,0 +1,159 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.bill.BillShowParameter;
import kd.bos.bill.OperationStatus;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.utils.StringUtils;
import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.FormShowParameter;
import kd.bos.form.ShowType;
import kd.bos.form.control.EntryGrid;
import kd.bos.form.events.HyperLinkClickEvent;
import kd.bos.form.events.HyperLinkClickListener;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.ec.contract.common.enums.DirectionEnum;
import kd.sdk.plugin.Plugin;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.EventObject;
/**
* 收入合同确认单插件
*/
public class InContractFinaceConfirmePlugin extends AbstractBillPlugIn implements Plugin, HyperLinkClickListener {
@Override
public void afterBindData(EventObject e) {
super.afterBindData(e);
//如果是新增时
BillShowParameter bsp=(BillShowParameter)this.getView().getFormShowParameter();
if(bsp.getStatus()== OperationStatus.ADDNEW ){
// 获取当前页面的FormShowParameter对象
FormShowParameter formShowParameter = this.getView().getFormShowParameter();
if(formShowParameter.getCustomParam("newBill")!=null){
// 获取自定义参数
Object contractSettleIdObj = formShowParameter.getCustomParam("contractSettleId");
boolean newBill = (boolean)formShowParameter.getCustomParam("newBill");
if (contractSettleIdObj != null && newBill) {
initData(contractSettleIdObj);
this.getView().invokeOperation("save");
}
}
}
}
public void initData(Object contractSettleIdObj){
QFilter accountTableFilter = new QFilter("id", QCP.equals,(Long)contractSettleIdObj);
DynamicObject ecincontractsettle = BusinessDataServiceHelper.loadSingle("ec_in_contract_settle", new QFilter[]{accountTableFilter});
getModel().setValue("zcgj_ec_in_contract_sett",ecincontractsettle.getLong("id"));
getModel().setValue("zcgj_ec_in_contract_name",ecincontractsettle.getString("billname"));
getModel().setValue("zcgj_ec_in_contractid", ecincontractsettle.getLong("id")); //id文本冗余
getModel().setValue("zcgj_billname",ecincontractsettle.getString("billname"));
getModel().setValue("zcgj_contract",ecincontractsettle.getDynamicObject("contract"));
getModel().setValue("zcgj_contattr",ecincontractsettle.getDynamicObject("contattr"));
getModel().setValue("zcgj_project",ecincontractsettle.getDynamicObject("project"));
getModel().setValue("zcgj_period",ecincontractsettle.getDynamicObject("period"));
getModel().setValue("zcgj_begindate",ecincontractsettle.getDate("begindate"));
getModel().setValue("zcgj_enddate",ecincontractsettle.getDate("enddate"));
getModel().setValue("zcgj_conttotaloftaxamount",ecincontractsettle.getBigDecimal("conttotaloftaxamount"));
getModel().setValue("zcgj_description",ecincontractsettle.getString("description"));
getModel().setValue("zcgj_currency",ecincontractsettle.getDynamicObject("currency"));
getModel().setValue("zcgj_invoice_org",ecincontractsettle.getDynamicObject("project").getDynamicObject("projectorg"));
// getModel().setValue("zcgj_jscustomer",ecincontractsettle.getDynamicObject("zcgj_jscustomer"));
DynamicObjectCollection itementry = ecincontractsettle.getDynamicObjectCollection("itementry");
//DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("zcgj_itementry");
DynamicObjectCollection entryEntity1 = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_itementry");
entryEntity1.clear();
for (DynamicObject dynamicObject : itementry) {
DynamicObject item = entryEntity1.addNew();
item.set("zcgj_payitem",dynamicObject.getDynamicObject("payitem"));
item.set("zcgj_oftaxamount",dynamicObject.getBigDecimal("oftaxamount"));
item.set("zcgj_amount",dynamicObject.getBigDecimal("amount"));
item.set("zcgj_rate",dynamicObject.getBigDecimal("rate"));
item.set("zcgj_taxamt",dynamicObject.getBigDecimal("taxamt"));
item.set("zcgj_remark",dynamicObject.getString("remark"));
}
this.getView().updateView("zcgj_itementry");
}
public void propertyChanged(PropertyChangedArgs e) {
String name = e.getProperty().getName();
ChangeData changeData = e.getChangeSet()[0];
if (StringUtils.equals(name, "zcgj_oftaxamount")) {
this.ofTaxAmountChanged(changeData); //计算税额和不含税金额
}else if(StringUtils.equals(name, "zcgj_ec_in_contract_sett")){
DynamicObject newValue = (DynamicObject)changeData.getNewValue();
initData(newValue.getLong("id"));
}
}
protected void ofTaxAmountChanged(ChangeData changeData) {
int rowIndex = changeData.getRowIndex();
if (this.isNotNonDirection(rowIndex)) {
BigDecimal ofTaxAmount = (BigDecimal)this.getModel().getValue("zcgj_oftaxamount", rowIndex);
BigDecimal rate = (BigDecimal)this.getModel().getValue("zcgj_rate", rowIndex);
BigDecimal amount = ofTaxAmount.divide(BigDecimal.ONE.add(rate.divide(BigDecimal.valueOf(100L), 10, RoundingMode.HALF_UP)), 10, 4);
BigDecimal taxAmount = ofTaxAmount.subtract(amount);
this.getModel().setValue("zcgj_taxamt", taxAmount, rowIndex);
this.getModel().setValue("zcgj_amount", amount, rowIndex);
}
}
protected boolean isNotNonDirection(int rowIndex) {
DynamicObject itemEntry = this.getModel().getEntryRowEntity("zcgj_itementry", rowIndex);
if (itemEntry == null) {
return false;
} else {
DynamicObject payItem = itemEntry.getDynamicObject("zcgj_payitem");
if (payItem == null) {
return false;
} else {
String direction = payItem.getString("direction");
return !StringUtils.equals(direction, DirectionEnum.NON.getValue());
}
}
}
/**
* 发票分录超链接跳转到详情
*/
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
EntryGrid control = this.getControl("zcgj_entryentity");
control.addHyperClickListener(this);
}
@Override
public void hyperLinkClick(HyperLinkClickEvent hyperLinkClickEvent) {
String fieldName = hyperLinkClickEvent.getFieldName();
EntryGrid entryGrid = getView().getControl("zcgj_entryentity");
int[] selectRows = entryGrid.getSelectRows();
if(selectRows != null && selectRows.length == 1){
DynamicObjectCollection dynamicObjectCollection = this.getModel().getDataEntity(true).getDynamicObjectCollection("zcgj_entryentity");
DynamicObject dynamicObject = dynamicObjectCollection.get(selectRows[0]);
DynamicObject zcgjInvoice = dynamicObject.getDynamicObject("zcgj_invoice");
long invoiceId = zcgjInvoice.getLong("id");
if(invoiceId != 0){
//弹出发票详情
BillShowParameter showParameter = new BillShowParameter();
showParameter.setPkId(invoiceId);
showParameter.setFormId("ec_in_invoice");
showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage); //打开方式
getView().showForm(showParameter);
}
}else{
this.getView().showTipNotification("请选择一条发票数据。");
}
}
}

View File

@ -0,0 +1,118 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.db.DB;
import kd.bos.db.DBRoute;
import kd.bos.entity.EntityMetadataCache;
import kd.bos.entity.MainEntityType;
import kd.bos.ext.fi.ai.AbstractDapWriteBackImpl;
import kd.bos.ext.fi.ai.Voucher;
import kd.bos.ext.fi.ai.VoucherOperation;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
* 收入合同财务确认凭证反写插件
*/
public class InContractFinaceConfirmeVoucherPlugin extends AbstractDapWriteBackImpl {
public static final Log log = LogFactory.getLog(InContractFinaceConfirmeVoucherPlugin.class);
//目标单据需要反写的凭证号字段名
public static final String voucherNoFile="fk_zcgj_voucherbillno";
@Override
protected DBRoute getDBRoute() {
// 扩展开发库的分库标识实际值可以查看mc分库标识
DBRoute DBR = DBRoute.of("scm");
return DBR;
}
// 删除凭证写入的值这里是复选框- 布尔false
@Override
protected Object getVchDisableStatus() {
Boolean disRchValue = false;
return disRchValue;
}
// 生成凭证时写入的值这里是复选框- 布尔 true
@Override
protected Object getVchEnableStatus() {
Boolean rchValue = true;
return rchValue;
}
// 要反写的字段,反写的是常量值反写凭证的一些其他信息回单据只能重写writeBack方法
@Override
protected String getVchStatusField() {
String vchField = "fk_zcgj_isvoucher";
return vchField;
}
@Override
public void writeBack(VoucherOperation operation, String billEntityNumber, Map<Long, Voucher> billToVch) {
MainEntityType mt = EntityMetadataCache.getDataEntityType(billEntityNumber);
Set<Long> keySet = billToVch.keySet();
log.info("AbstractDapWriteBackImpl#keySet:" + keySet);
if (VoucherOperation.Create.equals(operation)) {
log.info("AbstractDapWriteBackImpl#开始执行生成凭证反写:" + operation);
Object vchStatusField = getVchEnableStatus();
List<Object[]> params = new ArrayList<>();
for (Long me : keySet) {
log.info("AbstractDapWriteBackImpl#生成凭证的单据ID" + me);
Voucher voucher=billToVch.get(me);//凭证
String voucherNo = voucher.getVoucherNo();
//这里处理的是一个单据只有一个凭证的时候如果是多个凭证可以先获取已经生成的凭证号再拼接上字符串
Object[] param = new Object[] { vchStatusField,voucherNo, me };//
params.add(param);
if (params.size() >= 10000) {
log.info("AbstractDapWriteBackImpl#开始执行生成凭证反写SQL");
log.info("AbstractDapWriteBackImpl#mt.getAlias()" + mt.getAlias());
log.info("AbstractDapWriteBackImpl#mt.getVchStatusField()" + getVchStatusField());
DB.executeBatch(getDBRoute(),
"update " + mt.getAlias() + " set " + getVchStatusField() + " = ? , "+voucherNoFile+" = ? where fid = ?", params);
log.info("AbstractDapWriteBackImpl#结束执行生成凭证反写SQL");
params.clear();
}
}
log.info("AbstractDapWriteBackImpl#最后#开始执行生成凭证反写SQL");
log.info("AbstractDapWriteBackImpl#最后#mt.getAlias()" + mt.getAlias());
log.info("AbstractDapWriteBackImpl#最后#mt.getVchStatusField()" + getVchStatusField());
if (params.size() > 0) {
DB.executeBatch(getDBRoute(),
"update " + mt.getAlias() + " set " + getVchStatusField() + " = ? , "+voucherNoFile+" = ? where fid = ?", params);
}
log.info("AbstractDapWriteBackImpl#最后#结束执行生成凭证反写SQL");
} else if (VoucherOperation.Delete.equals(operation)) {
log.info("AbstractDapWriteBackImpl#开始执行删除凭证反写:" + operation);
Object vchDisableStatus = getVchDisableStatus();
List<Object[]> params = new ArrayList<>();
for (Long me : keySet) {
log.info("AbstractDapWriteBackImpl#删除凭证的单据ID" + me);
//这里处理的是一个单据只有一个凭证的时候如果是多个凭证可以先获取已经生成的凭证号再去掉本凭证之后的凭证号
Object[] param = new Object[] {vchDisableStatus, "",me };// getVchDisableStatus
params.add(param);
if (params.size() >= 10000) {
log.info("AbstractDapWriteBackImpl#开始执行删除凭证反写SQL");
log.info("AbstractDapWriteBackImpl#mt.getAlias()" + mt.getAlias());
log.info("AbstractDapWriteBackImpl#mt.getVchStatusField()" + getVchStatusField());
DB.executeBatch(getDBRoute(),
"update " + mt.getAlias() + " set " + getVchStatusField() + " = ? , "+voucherNoFile+" = ? where fid = ?", params);
params.clear();
log.info("AbstractDapWriteBackImpl#结束执行删除凭证反写SQL");
}
}
log.info("AbstractDapWriteBackImpl#最后#开始执行删除凭证反写SQL");
log.info("AbstractDapWriteBackImpl#最后#mt.getAlias()" + mt.getAlias());
log.info("AbstractDapWriteBackImpl#最后#mt.getVchStatusField()" + getVchStatusField());
if (params.size() > 0) {
DB.executeBatch(getDBRoute(),
"update " + mt.getAlias() + " set " + getVchStatusField() + " = ? , "+voucherNoFile+" = ? where fid = ?", params);
}
log.info("AbstractDapWriteBackImpl#最后#结束执行删除凭证反写SQL");
}
}
}

View File

@ -0,0 +1,73 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import kd.bos.bill.BillShowParameter;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.form.ShowType;
import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.list.BillList;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;
/**
* 收入合同结算-财务确认单插件
*/
public class InContractSettleFiConfirmeListPlugin extends AbstractListPlugin implements Plugin {
private static final Log log = LogFactory.getLog(InContractSettleFiConfirmeListPlugin.class);
@Override
public void itemClick(ItemClickEvent evt) {
super.itemClick(evt);
String itemKey = evt.getItemKey();
if("zcgj_finaceconfirme".equals(itemKey)) {
BillList billList = this.getView().getControl(AbstractListPlugin.BILLLISTID);
//获取到选中行的数据
ListSelectedRowCollection selectedRows = billList.getSelectedRows();
if(selectedRows.isEmpty()){
this.getView().showTipNotification(String.format("请选择要确认的数据。"));
return;
}
if(selectedRows.size() > 1){
this.getView().showTipNotification(String.format("请选择单个数据进行确认操作。。"));
return;
}
for (ListSelectedRow selectedRow : selectedRows) {
BillShowParameter showParameter = new BillShowParameter();
String billStatus = selectedRow.getBillStatus();
if("C".equals(billStatus)){
Long contractSettleId = (Long)selectedRow.getPrimaryKeyValue();//支出合同结算id
// DynamicObject taskobj = BusinessDataServiceHelper.loadSingle(pk, "task_task");
String billNo = selectedRow.getBillNo();
QFilter accountTableFilter = new QFilter("zcgj_ec_in_contractid", QCP.equals,String.valueOf(contractSettleId));
DynamicObject data = BusinessDataServiceHelper.loadSingle("zcgj_ec_in_finaceconfirm", "id,number", new QFilter[]{accountTableFilter});
if(data != null){ //财务确认单
long id = data.getLong("id");
showParameter.setPkId(id);
showParameter.setCustomParam("newBill", false);//如果不是第一次则设置标识false
}else{
showParameter.setCustomParam("contractSettleId", contractSettleId);
showParameter.setCustomParam("newBill", true);//如果是第一次设置标识为true
}
showParameter.setFormId("zcgj_ec_in_finaceconfirm");
showParameter.getOpenStyle().setShowType(ShowType.MainNewTabPage); //打开方式
getView().showForm(showParameter);
}else{
this.getView().showTipNotification(String.format("只有已审核通过的数据才可进行财务确认操作。"));
return;
}
}
}
}
}

View File

@ -70,7 +70,7 @@ public class OutContractFinaceConfirmePlugin extends AbstractBillPlugIn impleme
getModel().setValue("zcgj_description",ecoutcontractsettle.getString("description"));
getModel().setValue("zcgj_currency",ecoutcontractsettle.getDynamicObject("currency"));
getModel().setValue("zcgj_invoice_org",ecoutcontractsettle.getDynamicObject("project").getDynamicObject("projectorg"));
getModel().setValue("zcgj_jscustomer",ecoutcontractsettle.getDynamicObject("contract").getDynamicObject("partb"));
getModel().setValue("zcgj_jscustomer",ecoutcontractsettle.getDynamicObject("zcgj_jscustomer"));
DynamicObjectCollection itementry = ecoutcontractsettle.getDynamicObjectCollection("itementry");
//DynamicObjectCollection entryEntity = this.getModel().getEntryEntity("zcgj_itementry");