无合同付款添加发票功能

This commit is contained in:
zhangzhiguo 2025-10-23 11:18:38 +08:00
parent 5af3b351a0
commit 72e5464e3d
1 changed files with 205 additions and 6 deletions

View File

@ -7,18 +7,18 @@ import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.entity.LocaleString; import kd.bos.dataentity.entity.LocaleString;
import kd.bos.dataentity.metadata.IDataEntityProperty; import kd.bos.dataentity.metadata.IDataEntityProperty;
import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType;
import kd.bos.dataentity.resource.ResManager; import kd.bos.dataentity.resource.ResManager;
import kd.bos.entity.datamodel.IDataModel; import kd.bos.entity.datamodel.IDataModel;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.entity.datamodel.events.ChangeData; import kd.bos.entity.datamodel.events.ChangeData;
import kd.bos.entity.datamodel.events.PropertyChangedArgs; import kd.bos.entity.datamodel.events.PropertyChangedArgs;
import kd.bos.form.ClientProperties; import kd.bos.form.*;
import kd.bos.form.FormShowParameter;
import kd.bos.form.control.AttachmentPanel; import kd.bos.form.control.AttachmentPanel;
import kd.bos.form.control.EntryGrid; import kd.bos.form.control.EntryGrid;
import kd.bos.form.control.events.ItemClickEvent; import kd.bos.form.control.events.ItemClickEvent;
import kd.bos.form.events.AfterDoOperationEventArgs; import kd.bos.form.events.*;
import kd.bos.form.events.PreOpenFormEventArgs;
import kd.bos.form.events.SetFilterEvent;
import kd.bos.form.field.BasedataEdit; import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.ComboEdit; import kd.bos.form.field.ComboEdit;
import kd.bos.form.field.ComboItem; import kd.bos.form.field.ComboItem;
@ -32,8 +32,11 @@ import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter; import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper; import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.QueryServiceHelper; import kd.bos.servicehelper.QueryServiceHelper;
import org.apache.commons.lang.StringUtils; import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.util.*; import java.util.*;
/** /**
@ -113,6 +116,202 @@ public class PublicreimbursebillNoContractPlugin extends AbstractBillPlugIn impl
} }
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
super.beforeDoOperation(args);
FormOperate operate = (FormOperate)args.getSource();
String key = operate.getOperateKey();
if (org.apache.commons.lang3.StringUtils.equals(key, "newsubentryinvoice")) { //选择发票
this.beforeNewsubentryinvoice(args);
}/* else if (StringUtils.equals(key, "selectinvoice")) { //导入发票
this.showInvoiceImport(args);
}*/else if (key.equals("deletesubentryinvoice")) {
this.beforeDeleteSubEntry(args);
}
}
//选择发票 开始
protected void beforeNewsubentryinvoice(BeforeDoOperationEventArgs args) {
String billId = this.getModel().getDataEntity().getPkValue().toString();
if (!billId.equals("0") && "A".equals(this.getModel().getValue("billstatus"))) {
this.showInvoice("invoiceentry");
} 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("currency")).getLong("id");
DynamicObject costcompany = (DynamicObject) this.getModel().getValue("costcompany");
if (costcompany == null){
this.getView().showErrorNotification("清先填写发票企业名称!");
return;
}
DynamicObject project = (DynamicObject) this.getModel().getValue("zcgj_ec_project");
if (project == null){
this.getView().showErrorNotification("请先选择工程项目!");
return;
}
long orgId = costcompany.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));
filter.and(new QFilter("project", "=", project.getLong("id")));
//QFilter filter1 = new QFilter("isclaimed", "=", true);
//filter1.and(new QFilter("billstatus", "=", "C"));
//filter1.and(new QFilter("unapplyamount", ">", BigDecimal.ZERO));
DynamicObjectCollection contInvEntryCol = this.getModel().getEntryEntity("invoiceentry");
if (contInvEntryCol.size() > 0) {
List<Long> selectedInvIds = new ArrayList(8);
for(DynamicObject contInvEntryObj : contInvEntryCol) {
Long ecinvoiceid = contInvEntryObj.getLong("zcgj_ecinvoiceid");
selectedInvIds.add(ecinvoiceid);
}
filter.and(new QFilter("id", "not in", selectedInvIds));
}
DynamicObject[] invoices = BusinessDataServiceHelper.load("ec_in_invoice", "id", new QFilter[]{filter});
ListShowParameter param = ShowFormHelper.createShowListForm("ec_in_invoice_f7", true);
if(invoices.length > 0){
List<Long> ids = new ArrayList<>(invoices.length);
for (DynamicObject invoice : invoices) {
ids.add(invoice.getLong("id"));
}
param.getListFilterParameter().setFilter(new QFilter("id", "in", ids));
}else{
param.getListFilterParameter().setFilter(new QFilter("id", "in", new ArrayList<Long>()));
}
param.setMultiSelect(true);
param.setCloseCallBack(new CloseCallBack(this, entryType));
param.getOpenStyle().setShowType(ShowType.Modal);
this.getView().showForm(param);
}
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("invoiceentry") && returnData != null) {
this.invoiceCloseCallBack(event);
}
}
protected void invoiceCloseCallBack(ClosedCallBackEvent event) {
ListSelectedRowCollection rows = (ListSelectedRowCollection)event.getReturnData();
DynamicObject[] invArr = new DynamicObject[rows.size()];
int index = 0;
DynamicObject project = (DynamicObject)this.getModel().getValue("zcgj_ec_project");
for(ListSelectedRow row : rows) {
Object invoicePk = row.getPrimaryKeyValue().toString();
int rowIndex = this.getModel().createNewEntryRow("invoiceentry");
this.getModel().setValue("zcgj_ecinvoiceid", Long.valueOf(invoicePk.toString()), rowIndex);//发票id
DynamicObject invoice = BusinessDataServiceHelper.loadSingle(invoicePk, "ec_in_invoice",
"invoicecode,invoiceno,invoicedate,invoicetypeid,unapplyinvtax,unapplyamount,entryentity,entryentity.taxrate,isClaimed,contract,project,connecttype,currency,totalamount,totaltax,totaloftaxamount,seller");
DynamicObject invoicetypeid = invoice.getDynamicObject("invoicetypeid");
if(invoicetypeid != null) {
this.getModel().setValue("invoicetype", invoicetypeid.getString("number"), rowIndex);
}
this.getModel().setValue("invoicecode", invoice.getString("invoicecode"), rowIndex); //发票代码 invoicecode
this.getModel().setValue("invoiceno", invoice.getString("invoiceno"), rowIndex); //发票号码 invoiceno
this.getModel().setValue("invoicedate", invoice.getDate("invoicedate"), rowIndex); //开票日期 invoicedate
this.getModel().setValue("invoicecurrency", invoice.getDynamicObject("currency") == null ? Long.valueOf("0") : invoice.getDynamicObject("currency").getPkValue(), rowIndex); //发票币别
this.getModel().setValue("totalamount", invoice.getBigDecimal("totaloftaxamount"), rowIndex); //价税合计 totaloftaxamount
this.getModel().setValue("taxamount_invoice", invoice.getBigDecimal("totaltax"), rowIndex); //税额 totaltax
this.getModel().setValue("invoicenotaxamount", invoice.getBigDecimal("totalamount"), rowIndex); //不含税金额 totalamount
DynamicObject seller = invoice.getDynamicObject("seller");
if(seller != null) {
this.getModel().setValue("makeoutcompname", seller.getString("name"), rowIndex); //开票公司 seller.name
}
DynamicObjectCollection dynamicObjectCollection = invoice.getDynamicObjectCollection("entryentity");
if(dynamicObjectCollection != null && !dynamicObjectCollection.isEmpty()) {
if(dynamicObjectCollection.size() == 1) {
DynamicObject taxrate = dynamicObjectCollection.get(0).getDynamicObject("taxrate");
BigDecimal taxrate1 = taxrate.getBigDecimal("taxrate");
this.getModel().setValue("alltaxrate", taxrate1.multiply(new BigDecimal(100)), rowIndex); //税率
}else{
//税率 = 税额/不含税金额
BigDecimal totaltax = invoice.getBigDecimal("totaltax");
BigDecimal totalamount = invoice.getBigDecimal("totalamount");
if(totaltax !=null && totalamount != null && totalamount.compareTo(BigDecimal.ZERO) != 0) {
BigDecimal divide = totaltax.divide(totalamount, 2, BigDecimal.ROUND_HALF_UP);
this.getModel().setValue("alltaxrate", divide.multiply(new BigDecimal(100)), rowIndex); //税率
}
}
}
invArr[index++] = invoice;
invoice.set("isclaimed", true);
invoice.set("project", project);
// invoice.set("project", (DynamicObject)this.getModel().getValue("zcgj_project"));
//invoice.set("connecttype", "contract");
}
SaveServiceHelper.save(invArr);
this.getView().invokeOperation("invoicesave");
this.getView().updateView("invoiceentry");
}
protected void beforeDeleteSubEntry(BeforeDoOperationEventArgs args) {
EntryGrid subGrid = (EntryGrid)this.getControl("invoiceentry");
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("invoiceentry");
for(int i = selRows.length - 1; i >= 0; --i) {
int rowIndex = selRows[i];
Long ecinvoiceid = (Long)this.getModel().getValue("zcgj_ecinvoiceid", rowIndex);
if(ecinvoiceid!=null){
updateInvoicePks.add(ecinvoiceid);
delPks[i] = ((DynamicObject)subEntryEntityCol.get(selRows[i])).getPkValue();
}
this.getModel().deleteEntryRow("invoiceentry", rowIndex);
}
DynamicObjectType subDT = this.getModel().getDataEntity().getDynamicObjectCollection("invoiceentry").getDynamicObjectType();
QFilter filter = new QFilter("invoiceentry.zcgj_ecinvoiceid", "in", updateInvoicePks);
filter.and("id", "!=", this.getModel().getDataEntity().getPkValue());
DynamicObjectCollection invoiceApplyEntries = QueryServiceHelper.query("er_publicreimbursebill", "invoiceentry.zcgj_ecinvoiceid", new QFilter[]{filter});
if (invoiceApplyEntries != null && !invoiceApplyEntries.isEmpty()) {
for(DynamicObject subEntry : invoiceApplyEntries) {
updateInvoicePks.remove(subEntry.get("invoiceentry.zcgj_ecinvoiceid"));
}
}
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("project", (Object)null);
invoice.set("connecttype", "null");
}
}
//SaveServiceHelper.save(invoices);
}
DeleteServiceHelper.delete(subDT, delPks);
this.getView().showSuccessNotification("发票删除成功!");
//this.setEnableByInvoice();
}
}
@Override @Override
public void preOpenForm(PreOpenFormEventArgs e) { public void preOpenForm(PreOpenFormEventArgs e) {
super.preOpenForm(e); super.preOpenForm(e);