Compare commits

...

3 Commits

Author SHA1 Message Date
zengweihai 67537c5b52 发票优化 2024-10-29 14:41:32 +08:00
zengweihai 6976568dbb Merge remote-tracking branch 'origin/master' 2024-10-29 14:39:47 +08:00
zengweihai 4a98296374 用款部门过滤报销人 2024-10-24 15:33:48 +08:00
2 changed files with 418 additions and 106 deletions

View File

@ -36,6 +36,9 @@ import kd.bos.form.events.AfterDoOperationEventArgs;
import kd.bos.form.events.BeforeDoOperationEventArgs;
import kd.bos.form.events.ClientCallBackEvent;
import kd.bos.form.events.ClosedCallBackEvent;
import kd.bos.form.field.BasedataEdit;
import kd.bos.form.field.events.BeforeF7SelectEvent;
import kd.bos.form.field.events.BeforeF7SelectListener;
import kd.bos.form.operate.FormOperate;
import kd.bos.form.plugin.AbstractFormPlugin;
import kd.bos.imageplatform.axis.IScanWebServiceImplServiceStub;
@ -47,6 +50,7 @@ import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.AttachmentDto;
import kd.bos.servicehelper.AttachmentServiceHelper;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.botp.BFTrackerServiceHelper;
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.OperationServiceHelper;
@ -71,6 +75,7 @@ import javax.xml.bind.DatatypeConverter;
import java.io.*;
import java.math.BigDecimal;
import java.net.URL;
import java.sql.Timestamp;
import java.util.*;
import java.util.stream.Collectors;
/**
@ -78,16 +83,22 @@ import java.util.stream.Collectors;
* 发票识别,发票验真验重
* qeug_recon_payreqbill_ext && qeug_recon_connotextb_ext
*/
public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadListener {
public class ReconPayreqFormPlugin extends AbstractFormPlugin implements BeforeF7SelectListener {
private static final Log logger = LogFactory.getLog(OAUtils.class);
List<String> fileExtendList = new ArrayList<String>(Arrays.asList("png","jpg","jpeg","ofd","pdf","xml"));//发票文件后缀集合
@Override
public void registerListener(EventObject e) {
super.registerListener(e);
AttachmentPanel attachmentPanel = getControl("qeug_attachmentpanelap");
attachmentPanel.addUploadListener(this);
String billtype = this.getModel().getDataEntity().getDynamicObjectType().getName();//获取单据标识
if ("recon_connotextbill".equals(billtype)){//当单据为费用登记单时对该控件进行过滤监听
BasedataEdit edit = this.getView().getControl("qeug_personbank");//获取报销人控件
edit.addBeforeF7SelectListener(this);
}
}
/**
@ -419,8 +430,6 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
}else {
this.getView().showTipNotification("请先选择用款单位!");
}
break;
//发票验真验重
case "qeug_refinvoice":
@ -529,7 +538,6 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
invoiceEntry.set("inventry_invoicebill", invoiceBill);
invoiceEntry.set("qeug_invoiceno",invoiceBill.getString("invoiceno"));
invoiceEntry.set("inventry_haswriteoffamt", invoiceBill.getBigDecimal("writeoffamount"));
invoiceAmt = invoiceAmt.add(invoiceBill.getBigDecimal("invoiceamount"));
}
@ -546,6 +554,8 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
FormOperate source = (FormOperate) args.getSource();
String operateKey = source.getOperateKey();
DynamicObject dataEntity = this.getModel().getDataEntity();//单据数据
Object pk = this.getModel().getDataEntity().getPkValue();//当前单据主键
switch (operateKey) {
//删行
case "deleteinvoiceentry":
@ -595,6 +605,66 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
}
break;
case "confirmchange":
//确认核销付款申请/费用登记关联发票
String billtype =this.getModel().getDataEntityType().getName();//单据标识
//todo:若单据为费用登记单
boolean billFlag = true;
if ("recon_connotextbill".equals(billtype)){
Map<String, HashSet<Long>> tarBills = BFTrackerServiceHelper.findTargetBills("recon_connotextbill", new Long[]{(Long) pk});//查询费用登记的下游单据
HashSet<Long> longs = new HashSet<>();
if (tarBills.containsKey("recon_payreqbill")){
longs = tarBills.get("recon_payreqbill");
}
if (longs.size() > 0){//当下游付款申请单存在时
Object[] objects = longs.toArray();
Object payPk= objects[0];//更新主键为付款申请单据
DynamicObject recon_payreqbill = BusinessDataServiceHelper.loadSingle(payPk, "recon_payreqbill");
if (recon_payreqbill != null){
String billstatus = recon_payreqbill.getString("billstatus");
if (!"C".equals(billstatus)){
billFlag = false;
args.setCancel(true);//取消操作
this.getView().showTipNotification("下游关联付款申请单据状态异常,无法核销");
}
}else {
billFlag = false;
args.setCancel(true);//取消操作
this.getView().showTipNotification("该费用登记单据无下游关联付款申请单据,无法核销");
}
}else {
billFlag = false;
args.setCancel(true);//取消操作
this.getView().showTipNotification("该费用登记单据无下游关联付款申请单据,无法核销");
}
}
if (dataEntity.getBoolean("qeug_isticket") && billFlag){//确定付款是否需要补票且当单据为费用登记时需要判断关联的付款申请是否异常
BigDecimal applyamt = dataEntity.getBigDecimal("applyamt");//本期申请金额
BigDecimal totalAmount = BigDecimal.ZERO;
DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");//发票信息分录
for (DynamicObject invoice : invoiceentry) {
totalAmount = totalAmount.add(invoice.getBigDecimal("inventry_haswriteoffamt"));//遍历计算总发票核销金额
}
if (applyamt.compareTo(totalAmount) >= 0){
if (applyamt.compareTo(totalAmount) == 0){//完全核销付款申请金额等于发票金额
boolean bool = VerificationInvoice(dataEntity, pk);
if(bool){
//todo:4根据当前付款申请的发票分录所有数据修改数据后取消补单状态
this.getModel().setValue("qeug_isticket",false);
}else {
args.setCancel(true);//取消操作
}
}else if(applyamt.compareTo(totalAmount) > 0){//付款申请金额大于发票金额,此时不允许核销
args.setCancel(true);//取消操作
this.getView().showTipNotification("本次申请金额大于发票核销金额之和,请修改补录发票");
}
} else {
args.setCancel(true);//取消操作
this.getView().showTipNotification("总发票核销金额大于本次申请金额,请修改补录发票");
}
}
break;
default:
break;
}
@ -637,7 +707,7 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
linkBody.put("loginName",loginName);
String token = "";
try {
String linkPostjson = HttpClientUtils.postjson(linkUrl, null, linkBody.toJSONString());
String linkPostjson = HttpClientUtils.postjson(linkUrl, null, linkBody.toJSONString(),3*60*1000,3*60*1000);
logger.info("获取OaToken接口返回结果\n{}", linkPostjson);
if (StringUtils.isNotEmpty(linkPostjson)) {
@ -665,7 +735,7 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
base64Header.put("Content-Type", "application/json");
base64Header.put("token", token);
try {
String linkPostjson = HttpClientUtils.postjson(linkUrl, base64Header,strJson);
String linkPostjson = HttpClientUtils.postjson(linkUrl, base64Header,strJson,3*60*1000,3*60*1000);
logger.info("获取parseOCRData接口返回结果\n{}", linkPostjson);
if (StringUtils.isNotEmpty(linkPostjson)) {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
@ -691,7 +761,7 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
saveCheckHeader.put("token", token);
try {
String linkPostjson = HttpClientUtils.postjson(linkUrl, saveCheckHeader,strJson);
String linkPostjson = HttpClientUtils.postjson(linkUrl, saveCheckHeader,strJson,3*60*1000,3*60*1000);
logger.info("获取saveOutInvoice接口返回结果\n{}", linkPostjson);
if (StringUtils.isNotEmpty(linkPostjson)) {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
@ -749,5 +819,221 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements UploadL
String baseStr = new String(Base64.getEncoder().encode(bytes));
return baseStr;
}
/**
* 报销人根据用款部门过滤
* @param beforeF7SelectEvent
*/
@Override
public void beforeF7Select(BeforeF7SelectEvent beforeF7SelectEvent) {
String name = beforeF7SelectEvent.getProperty().getName();
if ("qeug_personbank".equals(name)){
DynamicObject dataEntity = this.getModel().getDataEntity();
DynamicObject usedepart = dataEntity.getDynamicObject("usedepart");//获取用款部门数据
if (usedepart != null){
Long departId = usedepart.getLong("id");//用款部门id
List<Long> allUsersOfOrg = UserServiceHelper.getAllUsersOfOrg(departId);//得到当前组织的全部人员包括直属员工和下属组织的员工
QFilter qFilter = new QFilter("id", QCP.in, allUsersOfOrg);
DynamicObject[] bos_users = BusinessDataServiceHelper.load("bos_user", "id,number", qFilter.toArray());
List<String> userNumbers = new ArrayList<String>();//构建人员工号容器
for (DynamicObject bos_user : bos_users) {
String number = bos_user.getString("number");
userNumbers.add(number);
}
QFilter qfByNumber = new QFilter("number", QCP.in, userNumbers);
ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter();
formShowParameter.getListFilterParameter().setFilter(qfByNumber);
}else {
beforeF7SelectEvent.setCancel(true);
this.getView().showTipNotification("请先选择用款部门");
}
}
}
/**
* 校验发票分录金额是否存在差异之前已经核销的发票需要返回已核销金额后再进行比较
* @param invoiceentry 付款申请发票分录数据
* @param pk 付款申请单主键
*/
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;
}
/**
* 发票金额核销数据更新根据校验未核销金额结果返回判断值正确则更新发票核销数据
* @param dataEntity
* @param pk
* @return
*/
public boolean VerificationInvoice(DynamicObject dataEntity,Object pk){
String billtype =this.getModel().getDataEntityType().getName();//单据标识
DynamicObjectCollection invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");//发票信息分录
BigDecimal applyamt = dataEntity.getBigDecimal("applyamt");//本期申请金额
if ("recon_connotextbill".equals(billtype)) {//当单据为费用登记时
Map<String, HashSet<Long>> tarBills = BFTrackerServiceHelper.findTargetBills("recon_connotextbill", new Long[]{(Long) pk});//查询费用登记的下游单据
HashSet<Long> longs = new HashSet<>();
if (tarBills.containsKey("recon_payreqbill")){
longs = tarBills.get("recon_payreqbill");
}
if (longs.size() > 0){//当下游付款申请单存在时
Object[] objects = longs.toArray();
pk= objects[0];//更新主键为付款申请单据
}
}
boolean flag = checkInvoiceAmount(invoiceentry,pk);
if (flag){//校验发票未核销金额是否足额
//todo:0,若单据类型为费用登记则同步费用登记发票分录数据到付款申请上
if ("recon_connotextbill".equals(billtype)) {//当单据为费用登记时
DynamicObject recon_payreqbill = BusinessDataServiceHelper.loadSingle(pk, "recon_payreqbill");//获取下游付款申请单完整数据
DynamicObjectCollection text_invoiceentry = dataEntity.getDynamicObjectCollection("invoiceentry");
DynamicObjectCollection pay_invoiceentry = recon_payreqbill.getDynamicObjectCollection("invoiceentry");
if (text_invoiceentry.size() > 0){
pay_invoiceentry.clear();
for (DynamicObject dynamicObject : text_invoiceentry) {
DynamicObject addNew = pay_invoiceentry.addNew();
addNew.set("inventry_invoicebill",dynamicObject.getDynamicObject("inventry_invoicebill").getPkValue());
addNew.set("qeug_invoiceno",dynamicObject.getString("qeug_invoiceno"));
addNew.set("inventry_haswriteoffamt",dynamicObject.getBigDecimal("inventry_haswriteoffamt"));
}
SaveServiceHelper.save(new DynamicObject[]{recon_payreqbill});//保存同步发票分录后的付款申请
}
}
//todo:1使用pk付款申请单id查询当前申请的是否存在已经核销的发票
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;
}
}
}
}
}
return true;
}else {
this.getView().showTipNotification("发票未核销金额异常,请检查后重新补录发票");
return false;
}
}
}
// CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule("recon_invoicebill", recon_invoicebill, null);

View File

@ -6,10 +6,12 @@ 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.CloseCallBack;
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.form.events.ClosedCallBackEvent;
import kd.bos.list.plugin.AbstractListPlugin;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
@ -26,6 +28,7 @@ import java.util.*;
*/
public class PeconPayreqBillListPlugin extends AbstractListPlugin implements Plugin {
String billname;
@Override
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
@ -37,13 +40,14 @@ public class PeconPayreqBillListPlugin extends AbstractListPlugin implements Plu
Object pk = row.getPrimaryKeyValue();
if (checkAddInvoice(pk)){
BillShowParameter showParameter = new BillShowParameter();
showParameter.setFormId("recon_payreqbill");
showParameter.setFormId(billname);
showParameter.setPkId(pk);//设置单据主键
showParameter.setCustomParam("isticket","true");
showParameter.getOpenStyle().setShowType(ShowType.Modal);//打开方式
showParameter.setCloseCallBack(new CloseCallBack(this,"ticket"));
this.getView().showForm(showParameter);
}else {
this.getView().showTipNotification("付款申请单据不符合补录条件");
this.getView().showTipNotification("单据不符合补录条件");
}
}
@ -51,127 +55,149 @@ public class PeconPayreqBillListPlugin extends AbstractListPlugin implements Plu
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){//当本次申请金额等于总发票核销金额
if (checkAddInvoice(pk)){
DynamicObject payreqbill = BusinessDataServiceHelper.loadSingle(pk, billname);//付款申请完整数据
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;
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});//更新发票数据
}
}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: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});//保存付款申请单
}
//todo:4根据当前付款申请的发票分录所有数据修改数据后取消补单状态
payreqbill.set("qeug_isticket",false);
SaveServiceHelper.save(new DynamicObject[]{payreqbill});//保存付款申请单
}
}
}
}
}
}
@Override
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
super.closedCallBack(closedCallBackEvent);
String actionId = closedCallBackEvent.getActionId();
if ("ticket".equals(actionId)) {
this.getView().invokeOperation("refresh");
}
}
/**
* 校验
* @param pk
* @return
*/
public boolean checkAddInvoice(Object pk){
DynamicObject payreqbill = BusinessDataServiceHelper.loadSingle(pk, "recon_payreqbill");//付款申请完整数据
return payreqbill.getBoolean("qeug_isticket");
DynamicObject bill;
QFilter qFilter = new QFilter("id", QCP.equals, pk);
DynamicObject payreqbill = BusinessDataServiceHelper.loadSingle("recon_payreqbill",qFilter.toArray());//付款申请完整数据
if (payreqbill != null){
billname = "recon_payreqbill";
bill = payreqbill;
}else {
DynamicObject connotextbill = BusinessDataServiceHelper.loadSingle("recon_connotextbill",qFilter.toArray());//付款申请完整数据
billname = "recon_connotextbill";
bill = connotextbill;
}
return bill.getBoolean("qeug_isticket");
}
/**