123
This commit is contained in:
parent
7ddd611bcc
commit
114a9e83bd
|
@ -0,0 +1,218 @@
|
||||||
|
package shkd.repc.recon.formplugin;
|
||||||
|
|
||||||
|
import com.grapecity.documents.excel.D;
|
||||||
|
import kd.bos.bill.BillShowParameter;
|
||||||
|
import kd.bos.bill.OperationStatus;
|
||||||
|
import kd.bos.cache.CacheFactory;
|
||||||
|
import kd.bos.cache.TempFileCache;
|
||||||
|
import kd.bos.coderule.api.CodeRuleInfo;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObject;
|
||||||
|
import kd.bos.dataentity.entity.DynamicObjectCollection;
|
||||||
|
import kd.bos.fileservice.FileServiceFactory;
|
||||||
|
import kd.bos.form.CloseCallBack;
|
||||||
|
import kd.bos.form.ShowType;
|
||||||
|
import kd.bos.form.control.AttachmentPanel;
|
||||||
|
import kd.bos.form.control.Control;
|
||||||
|
import kd.bos.form.control.EntryGrid;
|
||||||
|
import kd.bos.form.control.events.UploadEvent;
|
||||||
|
import kd.bos.form.control.events.UploadListener;
|
||||||
|
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||||
|
import kd.bos.form.events.BeforeDoOperationEventArgs;
|
||||||
|
import kd.bos.form.operate.FormOperate;
|
||||||
|
import kd.bos.form.plugin.AbstractFormPlugin;
|
||||||
|
import kd.bos.orm.query.QCP;
|
||||||
|
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.coderule.CodeRuleServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.DeleteServiceHelper;
|
||||||
|
import kd.bos.servicehelper.operation.SaveServiceHelper;
|
||||||
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
||||||
|
import org.apache.poi.ss.usermodel.Row;
|
||||||
|
import org.apache.poi.ss.usermodel.Sheet;
|
||||||
|
import org.apache.poi.ss.usermodel.Workbook;
|
||||||
|
import org.apache.poi.ss.usermodel.WorkbookFactory;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 付款申请单 || 费用登记单 插件
|
||||||
|
* 发票识别,发票验真验重
|
||||||
|
* qeug_recon_payreqbill_ext && qeug_recon_connotextb_ext
|
||||||
|
*/
|
||||||
|
public class ReconPayreqFormPlugin extends AbstractFormPlugin {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterDoOperation(AfterDoOperationEventArgs args) {
|
||||||
|
super.afterDoOperation(args);
|
||||||
|
|
||||||
|
DynamicObject dataEntity = this.getView().getModel().getDataEntity();
|
||||||
|
String billtype = dataEntity.getDynamicObjectType().getName();
|
||||||
|
String operateKey = args.getOperateKey();
|
||||||
|
switch (operateKey){
|
||||||
|
//发票识别123
|
||||||
|
case "qeug_invoicedistinguish":
|
||||||
|
|
||||||
|
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(billtype,
|
||||||
|
dataEntity.getPkValue(), "qeug_attachmentpanelap");
|
||||||
|
if (attachments.size() <= 0) {
|
||||||
|
this.getView().showTipNotification("请先上传发票附件");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//发票信息分录
|
||||||
|
DynamicObjectCollection invoiceentry = this.getView().getModel().getEntryEntity("invoiceentry");
|
||||||
|
if (invoiceentry.size() > 0) {
|
||||||
|
this.getView().showTipNotification("请先删除发票信息数据后,再进行发票识别");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// TODO: 调取OA发票识别接口
|
||||||
|
boolean b = true;
|
||||||
|
//成功--新增分录行
|
||||||
|
if (b) {
|
||||||
|
|
||||||
|
//发票信息分录
|
||||||
|
for (int i = 0; i < attachments.size(); i++) {
|
||||||
|
|
||||||
|
invoiceentry.addNew();
|
||||||
|
//todo:模仿标品新增字段,为接口返回数据反写分录做准备
|
||||||
|
this.getModel().setValue("qeug_invoicecode", "FKHM-0904-0001",i);//发票代码
|
||||||
|
this.getModel().setValue("qeug_invoiceno", "FKHM-0904-0001",i);//发票号码
|
||||||
|
this.getModel().setValue("qeug_amount", 10000,i);//价税合计
|
||||||
|
this.getModel().setValue("qeug_attainformation", "发票识别:"+attachments.get(i).get("name"),i);
|
||||||
|
this.getModel().setValue("qeug_invoicestatus", 0,i);//发票验真/重状态
|
||||||
|
}
|
||||||
|
this.getView().updateView("invoiceentry");
|
||||||
|
this.getView().showSuccessNotification("发票识别成功");
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
|
||||||
|
}else {
|
||||||
|
//失败--提示失败信息
|
||||||
|
this.getView().showTipNotification("发票识别失败:请上传有效发票");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
//发票验真验重
|
||||||
|
case "qeug_invoicecheck":
|
||||||
|
//todo: 发票验真验重接口
|
||||||
|
// 根据接口情况打包分录数据去OA验真验重---遍历调取接口还是汇总集合调取接口
|
||||||
|
//发票信息分录
|
||||||
|
DynamicObjectCollection invoiceens = this.getView().getModel().getEntryEntity("invoiceentry");
|
||||||
|
if (invoiceens.size() == 0) {
|
||||||
|
this.getView().showTipNotification("请先进行发票识别后,再进行验真验重");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
boolean bb = true;
|
||||||
|
//成功--新增分录行
|
||||||
|
if (bb) {
|
||||||
|
this.getView().showSuccessNotification("发票验真验重接口");
|
||||||
|
//验真验重接口调通--生成发票登记单据(recon_invoicebill)
|
||||||
|
//todo 遍历发票信息明细,批量生成发票登记单(再次点击发票验真验重,只选择未完成验真验重的数据)
|
||||||
|
for (DynamicObject invoiceen : invoiceens) {
|
||||||
|
String qeug_invoicestatus = invoiceen.getString("qeug_invoicestatus");//验真/重--状态
|
||||||
|
//未完成
|
||||||
|
if ("0".equals(qeug_invoicestatus)) {
|
||||||
|
|
||||||
|
DynamicObject recon_invoicebill = BusinessDataServiceHelper.newDynamicObject("recon_invoicebill");
|
||||||
|
// DynamicObject recon_invoicebill1 = BusinessDataServiceHelper.loadSingle("2031274535679975424", "recon_invoicebill");
|
||||||
|
recon_invoicebill.set("billstatus","A");//单据状态
|
||||||
|
//所属组织
|
||||||
|
DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, "DOBE")});
|
||||||
|
if (null != org) {
|
||||||
|
recon_invoicebill.set("org",org);
|
||||||
|
}
|
||||||
|
//发票号码 invoiceno
|
||||||
|
// recon_invoicebill.set("invoiceno",System.currentTimeMillis());
|
||||||
|
recon_invoicebill.set("invoiceno",invoiceen.getString("qeug_invoiceno"));//分录中的发票号码//todo----编码规则待维护
|
||||||
|
//发票编码
|
||||||
|
recon_invoicebill.set("billno","测试数据勿删!!");//----编码规则待维护
|
||||||
|
|
||||||
|
//付款申请单 payreqentrys
|
||||||
|
DynamicObjectCollection payreqentrys = recon_invoicebill.getDynamicObjectCollection("payreqentrys");
|
||||||
|
payreqentrys.clear();
|
||||||
|
DynamicObject payreqentry = payreqentrys.addNew();
|
||||||
|
payreqentry.set("fbasedataid", this.getView().getModel().getDataEntity());
|
||||||
|
|
||||||
|
//todo:若接口返回汇总
|
||||||
|
//发票_明细
|
||||||
|
DynamicObjectCollection invoiceentrs = recon_invoicebill.getDynamicObjectCollection("invoiceentry");
|
||||||
|
invoiceentrs.clear();
|
||||||
|
DynamicObject invoiceentr = invoiceentrs.addNew();
|
||||||
|
invoiceentr.set("entry_notaxamt",100000);
|
||||||
|
//todo:若接口返回明细--遍历新增发票明细分录
|
||||||
|
|
||||||
|
Object[] save = SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});
|
||||||
|
//如果 成功生成发票登记的单子,反写分录状态为完成
|
||||||
|
if (save.length > 0) {
|
||||||
|
//发票信息分录
|
||||||
|
DynamicObjectCollection invoiceentrys = this.getView().getModel().getEntryEntity("invoiceentry");
|
||||||
|
if (invoiceentrys.size() > 0) {
|
||||||
|
for (DynamicObject invoiceent : invoiceentrys) {
|
||||||
|
//根据发票号码进行过滤
|
||||||
|
String qeug_invoiceno = invoiceent.getString("qeug_invoiceno");//分录中的发票号码
|
||||||
|
//todo:付款申请单发票信息分录行的发票号码 == 发票登记单头发票号码
|
||||||
|
if (qeug_invoiceno.equals(recon_invoicebill.getString("invoiceno"))) {
|
||||||
|
System.out.println();
|
||||||
|
invoiceent.set("qeug_invoicestatus",1);//发票状态(验真/重)--------已完成
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.getView().updateView("invoiceentry");
|
||||||
|
// SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else {
|
||||||
|
//失败--提示失败信息
|
||||||
|
this.getView().showTipNotification("发票验真验重失败:请检查发票明细信息是否正确");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "deleteinvoiceentry":
|
||||||
|
//付款申请单发票信息明细删除行后进行保存
|
||||||
|
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
|
||||||
|
this.getView().showSuccessNotification("同步删除发票登记成功");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void beforeDoOperation(BeforeDoOperationEventArgs args) {
|
||||||
|
super.beforeDoOperation(args);
|
||||||
|
|
||||||
|
FormOperate source = (FormOperate) args.getSource();
|
||||||
|
String operateKey = source.getOperateKey();
|
||||||
|
switch (operateKey) {
|
||||||
|
//发票识别
|
||||||
|
case "deleteinvoiceentry":
|
||||||
|
//用户在删除发票明细时,如果当前发票已经生成发票登记单,一并删除掉
|
||||||
|
//删除后--未保存前,遍历发票信息分录 删除满足(明细"发票号码" == 发票登记单头"发票号码")的发票登记单
|
||||||
|
//获得"发票信息明细"选中行
|
||||||
|
EntryGrid assetsentry = (EntryGrid)this.getView().getControl("invoiceentry");
|
||||||
|
int[] selectRows = assetsentry.getSelectRows();
|
||||||
|
if (selectRows.length > 0) {
|
||||||
|
for (int i = 0; i < selectRows.length; i++) {
|
||||||
|
int selectRow = selectRows[i];
|
||||||
|
String qeug_invoiceno = (String)this.getModel().getValue("qeug_invoiceno",selectRow);//分录中的发票号码
|
||||||
|
QFilter q = new QFilter("invoiceno", QCP.equals, qeug_invoiceno);
|
||||||
|
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", new QFilter[]{q});
|
||||||
|
if (null != recon_invoicebill) {
|
||||||
|
int recon_invoicebill1 = DeleteServiceHelper.delete("recon_invoicebill", new QFilter[]{q});
|
||||||
|
//失败
|
||||||
|
if (1 != recon_invoicebill1) {
|
||||||
|
this.getView().showTipNotification("删除失败:请检查发票登记单的单据状态");
|
||||||
|
args.setCancel(true);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// CodeRuleInfo codeRule = CodeRuleServiceHelper.getCodeRule("recon_invoicebill", recon_invoicebill, null);
|
Loading…
Reference in New Issue