付款申请单已审核 重新添加发票

This commit is contained in:
程小伟 2025-05-08 11:17:06 +08:00
parent 113f2a4e47
commit d303624622
1 changed files with 235 additions and 0 deletions

View File

@ -0,0 +1,235 @@
package zcgj.zcdev.zcdev.pr.plugin.form;
import dm.jdbc.util.StringUtil;
import kd.bos.bill.AbstractBillPlugIn;
import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.dataentity.resource.ResManager;
import kd.bos.entity.datamodel.ListSelectedRow;
import kd.bos.entity.datamodel.ListSelectedRowCollection;
import kd.bos.entity.datamodel.events.PropertyChangedArgs;
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.operation.SaveServiceHelper;
import kd.ec.contract.formplugin.PaymentApplyEditUI;
import kd.sdk.plugin.Plugin;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
public class SupplementInvoiceBillPlugin1 extends AbstractBillPlugIn implements Plugin {
private static final Log log = LogFactory.getLog(SupplementInvoiceBillPlugin1.class);
@Override
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
if ("C".equals(this.getModel().getValue("billstatus"))){
log.info("SupplementInvoiceBillPlugin:单据已审核,走子类方法");
FormOperate operate = (FormOperate)args.getSource();
String key = operate.getOperateKey();//获取操作码
log.info("SupplementInvoiceBillPlugin:操作码:"+key);
if(StringUtil.equals("supplementinvoice", key)) {//候补发票
log.info("SupplementInvoiceBillPlugin:点击候补发票");
this.beforeNewSubEntry1(args);
}
}
}
@Override
public void propertyChanged(PropertyChangedArgs e) {
log.info("SupplementInvoiceBillPlugin:发生变动的字段:"+e.getProperty().getName());
String billId = this.getModel().getDataEntity().getPkValue().toString();
log.info("SupplementInvoiceBillPlugin:主键值:"+billId);
if (!billId.equals("0") && "A".equals(this.getModel().getValue("billstatus"))){
super.propertyChanged(e);
} else if (!billId.equals("0") &&"C".equals(this.getModel().getValue("billstatus"))){
String key = e.getProperty().getName();
// int rowIndex = e.getChangeSet()[0].getRowIndex();
log.info("SupplementInvoiceBillPlugin:发生变动的字段:"+key);
if(StringUtil.equals("applyinvoftaxamt", key)) {
log.info("SupplementInvoiceBillPlugin:发票申请金额发生变动,与合同的申请金额进行比较");
this.compareApplyInvoftaxamt1();
}
}
}
private void compareApplyInvoftaxamt1() {
int rowIndex = this.getModel().getEntryCurrentRowIndex("entryentity");
DynamicObject rowEntity = this.getModel().getEntryRowEntity("entryentity", rowIndex);//获取对应行的单据体
BigDecimal applyoftaxamount = rowEntity.getBigDecimal("applyoftaxamount");//获取单据体对应的 本次应付金额字段
BigDecimal totalAmount = this.getSum1("subentryentity", "applyinvoftaxamt");//算出子单据申请金额总和
if(applyoftaxamount.compareTo(totalAmount)!=0){
this.getView().showTipNotification(
"合同付款信息 第"+(rowIndex+1)+"行的 本次申请金额\n" +
" 不等于 合同进项发票的 本次申请金额总和 ,请重写填写合同进项发票的申请金额",5000);
}
}
protected void beforeNewSubEntry1(BeforeDoOperationEventArgs args) {
String billId = this.getModel().getDataEntity().getPkValue().toString();
log.info("SupplementInvoiceBillPlugin:主键值:"+billId);
if (!billId.equals("0") && "C".equals(this.getModel().getValue("billstatus"))) {//单据状态是否为审核
log.info("SupplementInvoiceBillPlugin:单据已审核");
EntryGrid grid = (EntryGrid)this.getView().getControl("entryentity");//获取单据体控件-合同付款信息
int[] rows = grid.getEntryState().getSelectedRows();//获取选择行号
log.info("SupplementInvoiceBillPlugin:导入的进项发票数量:"+rows.length);
if (rows.length != 1) {//只能选择一条
this.getView().showMessage(ResManager.loadKDString("必须选中一条合同付款信息记录。", "PaymentApplyEditUI_2", "ec-contract-formplugin", new Object[0]));
args.setCancel(true);
}else if(this.hasInvoice1(rows[0])){
this.getView().showMessage(ResManager.loadKDString("发票已导入,无需候补。", "PaymentApplyEditUI_2", "ec-contract-formplugin", new Object[0]));
args.setCancel(true);
}else if(!this.hasInvoice1(rows[0])) {//没有对应的发票进项发票候补
log.info("SupplementInvoiceBillPlugin:单据已审核,已选择一条合同付款信息记录,没有对应的发票,可以进项发票候补");
this.showInvoice1("subentryentity");
}
} else {
this.getView().showMessage(ResManager.loadKDString("单据不是审核状态,请先审核单据。", "PaymentApplyEditUI_1", "ec-contract-formplugin", new Object[0]));
args.setCancel(true);
}
}
private void showInvoice1(String entryType) {
log.info("SupplementInvoiceBillPlugin:在进项发票基础资料中进项筛选");
Object currencyId = this.getModel().getValue("currency_id");
long orgId = ((DynamicObject)this.getModel().getValue("org")).getLong("id");
log.info("SupplementInvoiceBillPlugin:orgId"+orgId);
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"));
int contEntryIndex = this.getModel().getEntryCurrentRowIndex("entryentity");
DynamicObject contract = (DynamicObject)this.getModel().getValue("contract", contEntryIndex);
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("subentryentity");
if (contInvEntryCol.size() > 0) {
List<Long> selectedInvIds = new ArrayList(8);
for(DynamicObject contInvEntryObj : contInvEntryCol) {
DynamicObject invoice = contInvEntryObj.getDynamicObject("invoice");
selectedInvIds.add(invoice.getLong("id"));
}
filter1.and(new QFilter("id", "not in", selectedInvIds));//已选发票不再出现
}
ListShowParameter param = ShowFormHelper.createShowListForm("ec_in_invoice_f7", true);
param.getListFilterParameter().setFilter(filter.or(filter1));
param.setMultiSelect(true);
param.setCloseCallBack(new CloseCallBack(this, entryType));
log.info("SupplementInvoiceBillPlugin:返回关闭标识:"+entryType);
param.getOpenStyle().setShowType(ShowType.Modal);
this.getView().showForm(param);
}
}
@Override
public void closedCallBack(ClosedCallBackEvent event) {
if ("C".equals(this.getModel().getValue("billstatus"))){
String actionId = event.getActionId();//获取回调标识
Object returnData = event.getReturnData();//获取子页面返回的数据
log.info("SupplementInvoiceBillPlugin:获取回调标识:"+actionId);
if (actionId.equals("subentryentity") && returnData != null) {
this.invoiceCloseCallBack1(event);
}
}
}
protected void invoiceCloseCallBack1(ClosedCallBackEvent event) {
ListSelectedRowCollection rows = (ListSelectedRowCollection)event.getReturnData();
DynamicObject[] invArr = new DynamicObject[rows.size()];
int index = 0;
log.info("SupplementInvoiceBillPlugin:进项发票资料带下来");
for(ListSelectedRow row : rows) {
Object invoicePk = row.getPrimaryKeyValue().toString();
int rowIndex = this.getModel().createNewEntryRow("subentryentity");
this.getModel().setValue("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("invoicecurrency", invoice.getDynamicObject("currency") == null ? Long.valueOf("0") : invoice.getDynamicObject("currency").getPkValue(), rowIndex);
this.getModel().setValue("invoiceamount", invoice.getBigDecimal("totalamount"), rowIndex);
this.getModel().setValue("invoicetax", invoice.getBigDecimal("totaltax"), rowIndex);
this.getModel().setValue("oftaxinvoiceamount", invoice.getBigDecimal("totaloftaxamount"), rowIndex);
this.getModel().setValue("unapplyinvoftaxamt", invoice.getBigDecimal("unapplyamount"), rowIndex);
this.getModel().setValue("unapplyinvtax", invoice.getBigDecimal("unapplyinvtax"), rowIndex);
this.getModel().setValue("applyinvoftaxamt", invoice.getBigDecimal("unapplyamount"), rowIndex);
invArr[index++] = invoice;
invoice.set("isclaimed", true);
int upCurIndex = this.getModel().getEntryCurrentRowIndex("entryentity");
DynamicObject upContract = (DynamicObject)this.getModel().getValue("contract", upCurIndex);
invoice.set("contract", upContract);
invoice.set("project", upContract.getDynamicObject("project"));
invoice.set("connecttype", "contract");
}
// this.setApplyAmtByInvoice(this.getModel().getEntryCurrentRowIndex("entryentity"));
log.info("SupplementInvoiceBillPlugin:发票保存");
SaveServiceHelper.save(invArr);//发票保存
this.getView().invokeOperation("invoicesave");
this.setEnableByInvoice1();
}
protected void setEnableByInvoice1() {
int entryRowCount = this.getModel().getEntryRowCount("entryentity");
log.info("SupplementInvoiceBillPlugin:有发票,合同记录锁定 thisapplyoftax thisapplyamout 字段");
for(int i = 0; i < entryRowCount; ++i) {//有发票锁定 "thisapplyoftax", "thisapplyamount" 字段
this.getView().setEnable(!this.hasInvoice1(i), i, new String[]{"thisapplyoftax", "thisapplyamount"});
}
}
protected boolean hasInvoice1(int rowIndex) {
DynamicObject rowEntity = this.getModel().getEntryRowEntity("entryentity", rowIndex);//获取对应的单据体
DynamicObjectCollection subEntries = rowEntity.getDynamicObjectCollection("subentryentity");//获取单据体对应的子单据体
return subEntries != null && !subEntries.isEmpty();//子单据体不为null且有数据
}
// protected void setApplyAmtByInvoice(String subColumnId, String contractColumnId, int rowIndex) {
// BigDecimal totalAmount = this.getSum("subentryentity", subColumnId);
//// this.getModel().setValue(contractColumnId, totalAmount, rowIndex);
// }
// protected void setApplyAmtByInvoice(int rowIndex) {
// this.setApplyAmtByInvoice("applyinvoftaxamt", "applyoftaxamount", rowIndex);
//// this.setApplyAmtByInvoice("applyinvamt", "applyamount", rowIndex);
//// this.setApplyAmtByInvoice("applyinvtax", "applytaxamount", rowIndex);
// }
protected BigDecimal getSum1(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);
}
log.info("SupplementInvoiceBillPlugin:发票申请总金额"+totalAmount);
return totalAmount;
}
}