发票识别验真
This commit is contained in:
parent
b8d9311ba4
commit
d8247aeab1
|
@ -110,16 +110,15 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
|
||||||
//发票类工具栏按钮隐藏
|
//发票类工具栏按钮隐藏
|
||||||
this.getView().setVisible(false,"advcontoolbarap2");
|
this.getView().setVisible(false,"advcontoolbarap2");
|
||||||
//分录申请核销金额锁定
|
//分录申请核销金额锁定
|
||||||
this.getView().setVisible(false,"inventry_haswriteoffamt");
|
this.getView().setEnable(false,"invoiceentry");
|
||||||
//设置置顶按钮隐藏
|
//设置置顶按钮隐藏
|
||||||
this.getView().setVisible(false,"qeug_confirmchange");
|
this.getView().setVisible(false,"qeug_confirmchange");
|
||||||
|
// this.getView().updateView("invoiceentry");
|
||||||
}else {
|
}else {
|
||||||
//设置置顶按钮隐藏
|
//设置置顶按钮隐藏
|
||||||
this.getView().setVisible(false,"bar_audit","bar_print","viewflowchart","payreqsplit","qeug_syncbip","payreqsplitsave");
|
this.getView().setVisible(false,"bar_audit","bar_print","viewflowchart","payreqsplit","qeug_syncbip","payreqsplitsave");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -528,6 +527,7 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
|
||||||
DynamicObject invoiceEntry = invoiceEntries.addNew();
|
DynamicObject invoiceEntry = invoiceEntries.addNew();
|
||||||
invoiceEntry.getDataEntityState().setFromDatabase(true);
|
invoiceEntry.getDataEntityState().setFromDatabase(true);
|
||||||
invoiceEntry.set("inventry_invoicebill", invoiceBill);
|
invoiceEntry.set("inventry_invoicebill", invoiceBill);
|
||||||
|
invoiceEntry.set("qeug_invoiceno",invoiceBill.getString("invoiceno"));
|
||||||
invoiceEntry.set("inventry_haswriteoffamt", invoiceBill.getBigDecimal("writeoffamount"));
|
invoiceEntry.set("inventry_haswriteoffamt", invoiceBill.getBigDecimal("writeoffamount"));
|
||||||
|
|
||||||
invoiceAmt = invoiceAmt.add(invoiceBill.getBigDecimal("invoiceamount"));
|
invoiceAmt = invoiceAmt.add(invoiceBill.getBigDecimal("invoiceamount"));
|
||||||
|
|
|
@ -0,0 +1,227 @@
|
||||||
|
package shkd.repc.recon.listplugin;
|
||||||
|
|
||||||
|
import kd.bos.bill.BillShowParameter;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.entity.datamodel.ListSelectedRow;
|
||||||
|
import kd.bos.entity.datamodel.ListSelectedRowCollection;
|
||||||
|
import kd.bos.entity.operate.Save;
|
||||||
|
import kd.bos.form.FormShowParameter;
|
||||||
|
import kd.bos.form.ShowType;
|
||||||
|
import kd.bos.form.control.Toolbar;
|
||||||
|
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||||
|
import kd.bos.list.plugin.AbstractListPlugin;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
import kd.bos.orm.query.QFilter;
|
||||||
|
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import kd.sdk.plugin.Plugin;
|
||||||
|
import org.agrona.Strings;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 标准单据列表插件
|
||||||
|
*/
|
||||||
|
public class PeconPayreqBillListPlugin extends AbstractListPlugin implements Plugin {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
|
||||||
|
super.afterDoOperation(afterDoOperationEventArgs);
|
||||||
|
String operateKey = afterDoOperationEventArgs.getOperateKey();
|
||||||
|
if ("addinvoice".equals(operateKey)){
|
||||||
|
ListSelectedRowCollection rows = this.getSelectedRows();
|
||||||
|
for (ListSelectedRow row : rows) {
|
||||||
|
Object pk = row.getPrimaryKeyValue();
|
||||||
|
if (checkAddInvoice(pk)){
|
||||||
|
BillShowParameter showParameter = new BillShowParameter();
|
||||||
|
showParameter.setFormId("recon_payreqbill");
|
||||||
|
showParameter.setPkId(pk);//设置单据主键
|
||||||
|
showParameter.setCustomParam("isticket","true");
|
||||||
|
showParameter.getOpenStyle().setShowType(ShowType.Modal);//打开方式
|
||||||
|
this.getView().showForm(showParameter);
|
||||||
|
}else {
|
||||||
|
this.getView().showTipNotification("此付款申请单据不符合补录条件");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if ("re_addinvoice".equals(operateKey)) {//补录完毕,同步发票数据
|
||||||
|
ListSelectedRowCollection rows = this.getSelectedRows();
|
||||||
|
for (ListSelectedRow row : rows) {
|
||||||
|
Object pk = row.getPrimaryKeyValue();
|
||||||
|
DynamicObject payreqbill = BusinessDataServiceHelper.loadSingle(pk, "recon_payreqbill");//付款申请完整数据
|
||||||
|
if (payreqbill.getBoolean("qeug_isticket")){//确定付款是否需要补票
|
||||||
|
BigDecimal applyamt = payreqbill.getBigDecimal("applyamt");//本期申请金额
|
||||||
|
BigDecimal totalAmount = BigDecimal.ZERO;
|
||||||
|
DynamicObjectCollection invoiceentry = payreqbill.getDynamicObjectCollection("invoiceentry");//发票信息分录
|
||||||
|
for (DynamicObject invoice : invoiceentry) {
|
||||||
|
totalAmount = totalAmount.add(invoice.getBigDecimal("inventry_haswriteoffamt"));//遍历计算总发票核销金额
|
||||||
|
}
|
||||||
|
if (applyamt.compareTo(totalAmount) > 0){
|
||||||
|
this.getView().showTipNotification("本次申请金额大于总发票核销金额,请继续补录发票");
|
||||||
|
return;
|
||||||
|
} else if (applyamt.compareTo(totalAmount) < 0) {
|
||||||
|
this.getView().showTipNotification("总发票核销金额大于本次申请金额,请修改补录发票");
|
||||||
|
return;
|
||||||
|
}else if (applyamt.compareTo(totalAmount) == 0){//当本次申请金额等于总发票核销金额
|
||||||
|
|
||||||
|
boolean flag = checkInvoiceAmount(invoiceentry,pk);
|
||||||
|
if (flag){//校验发票未核销金额是否足额
|
||||||
|
//todo:1、查询当前申请的是否存在已经核销的发票
|
||||||
|
QFilter qFilter = new QFilter("writeoffinfoentry.wentry_paybill.id", QCP.equals,pk);
|
||||||
|
DynamicObject[] invoiceBills = BusinessDataServiceHelper.load("recon_invoicebill", "id,invoiceno,invoiceamount,haswriteoffamount,writeoffamount,writeoffinfoentry.wentry_paybill.number,writeoffinfoentry.wentry_writroffamount,writeoffinfoentry.wentry_bizdate", new QFilter[]{qFilter});
|
||||||
|
ArrayList<String> alreadyInvoices = new ArrayList<>();
|
||||||
|
for (DynamicObject invoiceBill : invoiceBills) {//添加该申请单已核销的发票号码
|
||||||
|
alreadyInvoices.add(invoiceBill.getString("invoiceno"));
|
||||||
|
}
|
||||||
|
//todo:2、遍历当前付款申请的发票分录数据,比较已关联发票数据,修改数据
|
||||||
|
for (DynamicObject invoice : invoiceentry) {
|
||||||
|
String qeug_invoiceno = invoice.getString("qeug_invoiceno");
|
||||||
|
QFilter no_qf = new QFilter("invoiceno", QCP.equals, qeug_invoiceno);
|
||||||
|
DynamicObject invoiceBill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", no_qf.toArray());
|
||||||
|
BigDecimal inventry_haswriteoffamt = invoice.getBigDecimal("inventry_haswriteoffamt");//发票申请核销金额
|
||||||
|
if (invoiceBill != null){
|
||||||
|
Object invoicePk = invoiceBill.getPkValue();//获取发票主键
|
||||||
|
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle(invoicePk, "recon_invoicebill");//查询实际发票数据
|
||||||
|
if (recon_invoicebill != null){
|
||||||
|
String invoiceno = recon_invoicebill.getString("invoiceno");//发票号码
|
||||||
|
if (!Strings.isEmpty(invoiceno)){
|
||||||
|
boolean isContains = alreadyInvoices.contains(invoiceno);//判断当前行发票是否已经被关联核销
|
||||||
|
if (isContains){//当此时关联发票已经被核销的情况
|
||||||
|
DynamicObjectCollection writeoffinfoentry = recon_invoicebill.getDynamicObjectCollection("writeoffinfoentry");//获取核销信息分录
|
||||||
|
for (DynamicObject dynamicObject : writeoffinfoentry) {
|
||||||
|
Object payBillPk = dynamicObject.getDynamicObject("wentry_paybill").getPkValue();//核销付款单id
|
||||||
|
if (pk.equals(payBillPk)){
|
||||||
|
BigDecimal wentry_writroffamount = dynamicObject.getBigDecimal("wentry_writroffamount");//获取分录核销金额
|
||||||
|
if (wentry_writroffamount.compareTo(inventry_haswriteoffamt) != 0){//当付款单发票核销金额同已核销数据不一致时
|
||||||
|
BigDecimal haswriteoffamount = recon_invoicebill.getBigDecimal("haswriteoffamount");//目前已核销金额
|
||||||
|
haswriteoffamount = haswriteoffamount.subtract(wentry_writroffamount);//还原已核销金额
|
||||||
|
haswriteoffamount = haswriteoffamount.add(inventry_haswriteoffamt);//重新添加出已核销金额
|
||||||
|
recon_invoicebill.set("haswriteoffamount",haswriteoffamount);//赋值已核销金额
|
||||||
|
BigDecimal writeoffamount = recon_invoicebill.getBigDecimal("writeoffamount");//目前未核销金额
|
||||||
|
writeoffamount = writeoffamount.add(wentry_writroffamount);//还原未核销金额
|
||||||
|
writeoffamount = writeoffamount.subtract(inventry_haswriteoffamt);
|
||||||
|
recon_invoicebill.set("writeoffamount",writeoffamount);//赋值未核销金额
|
||||||
|
dynamicObject.set("wentry_writroffamount",inventry_haswriteoffamt);//更新核销金额
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});//更新发票数据
|
||||||
|
alreadyInvoices.remove(invoiceno);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
DynamicObjectCollection writeoffinfoentry = recon_invoicebill.getDynamicObjectCollection("writeoffinfoentry");//获取核销信息分录
|
||||||
|
DynamicObject dynamicObject = writeoffinfoentry.addNew();
|
||||||
|
dynamicObject.set("wentry_paybill",pk);//付款申请单编号
|
||||||
|
dynamicObject.set("wentry_payamount",applyamt);//付款金额
|
||||||
|
dynamicObject.set("wentry_writroffamount",inventry_haswriteoffamt);//核销金额
|
||||||
|
BigDecimal haswriteoffamount = recon_invoicebill.getBigDecimal("haswriteoffamount");//目前已核销金额
|
||||||
|
haswriteoffamount = haswriteoffamount.add(inventry_haswriteoffamt);//增加已核销金额
|
||||||
|
recon_invoicebill.set("haswriteoffamount",haswriteoffamount);//赋值已核销金额
|
||||||
|
BigDecimal writeoffamount = recon_invoicebill.getBigDecimal("writeoffamount");//目前未核销金额
|
||||||
|
writeoffamount = writeoffamount.subtract(inventry_haswriteoffamt);
|
||||||
|
recon_invoicebill.set("writeoffamount",writeoffamount);//赋值未核销金额
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});//更新发票数据
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//todo:3、根据当前付款申请的发票分录数据修改数据后,剩下的发票为废弃关联,需返回核销金额
|
||||||
|
if(alreadyInvoices.size()>0){//当已核销发票存在时,返还核销金额
|
||||||
|
for (String alreadyInvoice : alreadyInvoices) {
|
||||||
|
QFilter alreadyInvoice_qf = new QFilter("invoiceno", QCP.equals, alreadyInvoice);//设置发票登记过滤条件
|
||||||
|
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", alreadyInvoice_qf.toArray());//查询发票数据
|
||||||
|
if (recon_invoicebill != null){//当发票不为空时
|
||||||
|
DynamicObjectCollection writeoffinfoentry = recon_invoicebill.getDynamicObjectCollection("writeoffinfoentry");//获取核销信息分录
|
||||||
|
for (int i = 0; i < writeoffinfoentry.size();i++) {
|
||||||
|
DynamicObject dynamicObject = writeoffinfoentry.get(i);
|
||||||
|
Object payBillPk = dynamicObject.getDynamicObject("wentry_paybill").getPkValue();//核销付款单id
|
||||||
|
if (pk.equals(payBillPk)){
|
||||||
|
BigDecimal wentry_writroffamount = dynamicObject.getBigDecimal("wentry_writroffamount");//获取分录核销金额
|
||||||
|
BigDecimal haswriteoffamount = recon_invoicebill.getBigDecimal("haswriteoffamount");//目前已核销金额
|
||||||
|
haswriteoffamount = haswriteoffamount.subtract(wentry_writroffamount);//还原已核销金额
|
||||||
|
recon_invoicebill.set("haswriteoffamount",haswriteoffamount);//赋值已核销金额
|
||||||
|
BigDecimal writeoffamount = recon_invoicebill.getBigDecimal("writeoffamount");//目前未核销金额
|
||||||
|
writeoffamount = writeoffamount.add(wentry_writroffamount);//还原未核销金额
|
||||||
|
recon_invoicebill.set("writeoffamount",writeoffamount);//赋值未核销金额
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});//
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//todo:4、根据当前付款申请的发票分录所有数据修改数据后,取消补单状态
|
||||||
|
payreqbill.set("qeug_isticket",false);
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{payreqbill});//保存付款申请单
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验
|
||||||
|
* @param pk
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean checkAddInvoice(Object pk){
|
||||||
|
DynamicObject payreqbill = BusinessDataServiceHelper.loadSingle(pk, "recon_payreqbill");//付款申请完整数据
|
||||||
|
return payreqbill.getBoolean("qeug_isticket");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 校验发票分录金额是否存在差异,之前已经核销的发票需要返回已核销金额后再进行比较
|
||||||
|
* @param invoiceentry
|
||||||
|
*/
|
||||||
|
public boolean checkInvoiceAmount(DynamicObjectCollection invoiceentry,Object pk){
|
||||||
|
boolean flag = true;
|
||||||
|
//todo:1、查询当前申请的是否存在已经核销的发票
|
||||||
|
QFilter qFilter = new QFilter("writeoffinfoentry.wentry_paybill.id", QCP.equals,pk);
|
||||||
|
DynamicObject[] invoiceBills = BusinessDataServiceHelper.load("recon_invoicebill", "id,invoiceno,invoiceamount,haswriteoffamount,writeoffamount,writeoffinfoentry.wentry_paybill.number,writeoffinfoentry.wentry_writroffamount,writeoffinfoentry.wentry_bizdate", new QFilter[]{qFilter});
|
||||||
|
ArrayList<String> alreadyInvoices = new ArrayList<>();
|
||||||
|
for (DynamicObject invoiceBill : invoiceBills) {//添加该申请单已核销的发票号码
|
||||||
|
alreadyInvoices.add(invoiceBill.getString("invoiceno"));
|
||||||
|
}
|
||||||
|
for (int i = 0; i < invoiceentry.size();i++){
|
||||||
|
DynamicObject invoice = invoiceentry.get(i);
|
||||||
|
String qeug_invoiceno = invoice.getString("qeug_invoiceno");
|
||||||
|
QFilter no_qf = new QFilter("invoiceno", QCP.equals, qeug_invoiceno);
|
||||||
|
DynamicObject invoiceBill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", no_qf.toArray());
|
||||||
|
BigDecimal inventry_haswriteoffamt = invoice.getBigDecimal("inventry_haswriteoffamt");//发票申请核销金额
|
||||||
|
if (invoiceBill != null){
|
||||||
|
Object invoicePk = invoiceBill.getPkValue();
|
||||||
|
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle(invoicePk, "recon_invoicebill");//查询实际发票数据
|
||||||
|
if (recon_invoicebill != null){
|
||||||
|
String invoiceno = recon_invoicebill.getString("invoiceno");
|
||||||
|
DynamicObjectCollection writeoffinfoentry = recon_invoicebill.getDynamicObjectCollection("writeoffinfoentry");//获取核销信息分录
|
||||||
|
BigDecimal writeoffamount = recon_invoicebill.getBigDecimal("writeoffamount");//获取未核销金额
|
||||||
|
if (alreadyInvoices.contains(invoiceno)){
|
||||||
|
for (DynamicObject dynamicObject : writeoffinfoentry) {
|
||||||
|
Object payBillPk = dynamicObject.getDynamicObject("wentry_paybill").getPkValue();//核销付款单id
|
||||||
|
if (pk.equals(payBillPk)){
|
||||||
|
BigDecimal wentry_writroffamount = dynamicObject.getBigDecimal("wentry_writroffamount");//获取分录核销金额
|
||||||
|
writeoffamount = writeoffamount.add(wentry_writroffamount);//还原未核销金额
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (writeoffamount.compareTo(inventry_haswriteoffamt) < 0){
|
||||||
|
this.getView().showTipNotification("第"+(i+1)+"发票未核销金额不足,请重新关联发票");
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
this.getView().showTipNotification("第"+(i+1)+"发票行数据异常,请重新关联发票");
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
this.getView().showTipNotification("第"+(i+1)+"发票行数据异常,请重新关联发票");
|
||||||
|
flag = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return flag;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue