发票识别验真

This commit is contained in:
zengweihai 2024-10-14 10:03:45 +08:00
parent 8af813c869
commit eb3636588b
1 changed files with 350 additions and 251 deletions

View File

@ -3,6 +3,8 @@ package shkd.repc.recon.formplugin;
import cfca.svs.api.util.IOUtil; import cfca.svs.api.util.IOUtil;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.grapecity.documents.excel.B; import com.grapecity.documents.excel.B;
import com.grapecity.documents.excel.D; import com.grapecity.documents.excel.D;
import com.huawei.shade.org.apache.http.protocol.RequestContent; import com.huawei.shade.org.apache.http.protocol.RequestContent;
@ -40,6 +42,7 @@ import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.bos.servicehelper.coderule.CodeRuleServiceHelper; import kd.bos.servicehelper.coderule.CodeRuleServiceHelper;
import kd.bos.servicehelper.operation.DeleteServiceHelper; import kd.bos.servicehelper.operation.DeleteServiceHelper;
import kd.bos.servicehelper.operation.SaveServiceHelper; import kd.bos.servicehelper.operation.SaveServiceHelper;
import kd.bos.servicehelper.user.UserServiceHelper;
import kd.bos.url.UrlService; import kd.bos.url.UrlService;
import kd.bos.util.FileNameUtils; import kd.bos.util.FileNameUtils;
import kd.bos.util.HttpClientUtils; import kd.bos.util.HttpClientUtils;
@ -73,263 +76,296 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
@Override @Override
public void afterDoOperation(AfterDoOperationEventArgs args) { public void afterDoOperation(AfterDoOperationEventArgs args) {
super.afterDoOperation(args); super.afterDoOperation(args);
DynamicObject dataEntity = this.getView().getModel().getDataEntity(); DynamicObject dataEntity = this.getView().getModel().getDataEntity();//单据对象
String billtype = dataEntity.getDynamicObjectType().getName(); String billtype = dataEntity.getDynamicObjectType().getName();
String operateKey = args.getOperateKey(); String operateKey = args.getOperateKey();
switch (operateKey){ switch (operateKey){
//发票识别test //发票识别test
case "qeug_invoicedistinguish": case "qeug_invoicedistinguish":
DynamicObject usedepart = dataEntity.getDynamicObject("usedepart");//获取用款单位
if (usedepart != null){//用款单位不为空
String usedepart_number = usedepart.getString("number");//获取用款单位编码
String companyTaxNo = getCompanyTaxNo(usedepart_number);
if (Strings.isEmpty(companyTaxNo)){
this.getView().showTipNotification("请维护财务公司税务登记号");
return;
}
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(billtype,
dataEntity.getPkValue(), "qeug_attachmentpanelap");
if (attachments.size() <= 0) {
this.getView().showTipNotification("请先上传发票附件");
return;
}
// ToDo: 获取token
String oaToken = getOaToken();
//发票信息分录
DynamicObjectCollection invoiceentry = this.getView().getModel().getEntryEntity("invoiceentry");
if (invoiceentry.size() > 0) {
for (DynamicObject invoice : invoiceentry) {
String qeug_invoiceno = invoice.getString("qeug_invoiceno");//分录中的发票号码
String qeug_invoicekey = invoice.getString("qeug_invoicekey");//分录中的发票保存key
Map<String, Object> map = new HashMap<>();
// 创建一个数组并将其作为值放入Map中
map.put("pi_keys", Arrays.asList(qeug_invoicekey));
ObjectMapper objectMapper = new ObjectMapper();
try {
String jsonString = objectMapper.writeValueAsString(map);
deleteInvoice(jsonString,oaToken);
} catch (JsonProcessingException e) {
throw new RuntimeException(e);
}
List<Map<String, Object>> attachments = AttachmentServiceHelper.getAttachments(billtype, QFilter q = new QFilter("invoiceno", QCP.equals, qeug_invoiceno);
dataEntity.getPkValue(), "qeug_attachmentpanelap"); DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", new QFilter[]{q});
if (attachments.size() <= 0) { if (null != recon_invoicebill) {
this.getView().showTipNotification("请先上传发票附件"); int recon_invoicebill1 = DeleteServiceHelper.delete("recon_invoicebill", new QFilter[]{q});
return; //失败
} if (1 != recon_invoicebill1) {
//发票信息分录 this.getView().showTipNotification("删除失败:请检查发票登记单的单据状态");
DynamicObjectCollection invoiceentry = this.getView().getModel().getEntryEntity("invoiceentry"); }
if (invoiceentry.size() > 0) {
for (DynamicObject invoice : invoiceentry) {
String qeug_invoiceno = invoice.getString("qeug_invoiceno");//分录中的发票号码
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("删除失败:请检查发票登记单的单据状态");
} }
} }
invoiceentry.clear();
} }
invoiceentry.clear(); if(!Strings.isEmpty(oaToken)){//判断是否获取到token
} for (int i = 0; i < attachments.size(); i++) {
// ToDo: 获取token Map<String, Object> attachment = attachments.get(i);
String oaToken = getOaToken(); String type = attachment.get("type").toString();
if(!Strings.isEmpty(oaToken)){//判断是否获取到token String name = attachment.get("name").toString();
for (int i = 0; i < attachments.size(); i++) { if (fileExtendList.contains(type)){//规范附件类型超出范围外不调用接口
Map<String, Object> attachment = attachments.get(i); // TODO: 根据发票路径转换出图像数据
String type = attachment.get("type").toString(); String fileBase64 = getFileBase64StrByUrl(attachment);//转换为Base64数据
String name = attachment.get("name").toString(); // TODO: 调取OA发票识别接口
if (fileExtendList.contains(type)){//规范附件类型超出范围外不调用接口 JSONObject ocr_jsonObject = parseOCRData(companyTaxNo, type, fileBase64, oaToken);
// TODO: 根据发票路径转换出图像数据 String ocr_success = ocr_jsonObject.getString("success");
String fileBase64 = getFileBase64StrByUrl(attachment);//转换为Base64数据 if ("true".equals(ocr_success)) {
// TODO: 调取OA发票识别接口 //TODO: 发票识别成功调用OA发票识别接口
JSONObject ocr_jsonObject = parseOCRData("91310106054599952W", type, fileBase64, oaToken); JSONArray ocrDatas = ocr_jsonObject.getJSONArray("data");
String ocr_success = ocr_jsonObject.getString("success"); String fileId = ocr_jsonObject.getString("fileId");
if ("true".equals(ocr_success)) { JSONObject saveCheckJson = saveCheck(companyTaxNo, fileId, ocrDatas,oaToken);//返回数据
//TODO: 发票识别成功调用OA发票识别接口 String save_success = saveCheckJson.getString("success");
JSONArray ocrDatas = ocr_jsonObject.getJSONArray("data"); if ("true".equals(save_success)){
String fileId = ocr_jsonObject.getString("fileId"); //TODO: 生成发票登记
JSONObject saveCheckJson = saveCheck("91310106054599952W", fileId, ocrDatas,oaToken);//返回数据
String save_success = saveCheckJson.getString("success");
if ("true".equals(save_success) || "false".equals(save_success)){
//TODO: 生成发票登记
JSONArray dataList = ocr_jsonObject.getJSONArray("data");//data数据类型为集合表示 JSONArray dataList = ocr_jsonObject.getJSONArray("data");//data数据类型为集合表示
JSONObject data = dataList.getJSONObject(0);//data数据 JSONObject data = dataList.getJSONObject(0);//data数据
String invoiceType = data.getString("type"); //票据类型 String invoiceType = data.getString("type"); //票据类型
JSONObject details = data.getJSONObject("details");//票据数据内容 JSONObject details = data.getJSONObject("details");//票据数据内容
String description = data.getString("description");//发票名称 String description = data.getString("description");//发票名称
String qeug_invoicecode = "";//发票代码初始定义 String qeug_invoicecode = "";//发票代码初始定义
String qeug_invoiceno = "";//发票号码 String qeug_invoiceno = "";//发票号码
BigDecimal qeug_notaxamt = BigDecimal.ZERO;//不含税金额 BigDecimal qeug_notaxamt = BigDecimal.ZERO;//不含税金额
BigDecimal qeug_tax = BigDecimal.ZERO;//税额 BigDecimal qeug_tax = BigDecimal.ZERO;//税额
BigDecimal qeug_amount = BigDecimal.ZERO;//价税合计 BigDecimal qeug_amount = BigDecimal.ZERO;//价税合计
Date qeug_bizdate = null;//开票日期 Date qeug_bizdate = null;//开票日期
String qeug_saleorg = "";//开票单位,只有文字该字段不用从oa携带和还原 String qeug_saleorg = "";//开票单位,只有文字该字段不用从oa携带和还原
JSONArray items = null; JSONArray items = null;
boolean parseFlag = true; boolean parseFlag = true;
if ("10100".equals(invoiceType) || "10101".equals(invoiceType) || "10102".equals(invoiceType) ){ if ("10100".equals(invoiceType) || "10101".equals(invoiceType) || "10102".equals(invoiceType) ){
//当票据类型为10100增值税专用发票10101增值税普通发票10102增值税电子普通发票 //当票据类型为10100增值税专用发票10101增值税普通发票10102增值税电子普通发票
qeug_invoicecode = details.getString("code");//印刷发票代码 qeug_invoicecode = details.getString("code");//印刷发票代码
qeug_invoiceno = details.getString("number");//印刷发票号码 qeug_invoiceno = details.getString("number");//印刷发票号码
qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额
qeug_tax = details.getBigDecimal("tax");//税额 qeug_tax = details.getBigDecimal("tax");//税额
qeug_amount = details.getBigDecimal("total");////价税合计 qeug_amount = details.getBigDecimal("total");////价税合计
qeug_bizdate = details.getDate("date");//开票日期 qeug_bizdate = details.getDate("date");//开票日期
qeug_saleorg = details.getString("seller");//开票单位 qeug_saleorg = details.getString("seller");//开票单位
items = details.getJSONArray("items");//增值税发票购买项明细 items = details.getJSONArray("items");//增值税发票购买项明细
}else if ("10103".equals(invoiceType)){ }else if ("10103".equals(invoiceType)){
//当票据类型为10100增值税普通发票(卷票) //当票据类型为10100增值税普通发票(卷票)
qeug_invoicecode = details.getString("code");//印刷发票代码 qeug_invoicecode = details.getString("code");//印刷发票代码
qeug_invoiceno = details.getString("number");//印刷发票号码 qeug_invoiceno = details.getString("number");//印刷发票号码
qeug_amount = details.getBigDecimal("total");////价税合计 qeug_amount = details.getBigDecimal("total");////价税合计
qeug_bizdate = details.getDate("date");//开票日期 qeug_bizdate = details.getDate("date");//开票日期
qeug_saleorg = details.getString("seller");//开票单位 qeug_saleorg = details.getString("seller");//开票单位
items = details.getJSONArray("items");//增值税发票卷票购买项 items = details.getJSONArray("items");//增值税发票卷票购买项
}else if ("10108".equals(invoiceType) || "10107".equals(invoiceType)){ }else if ("10108".equals(invoiceType) || "10107".equals(invoiceType)){
//当票据类型为10107电子发票(增值税专用发票)10108电子发票(普通发票) //当票据类型为10107电子发票(增值税专用发票)10108电子发票(普通发票)
qeug_invoiceno = details.getString("number");//印刷发票号码 qeug_invoiceno = details.getString("number");//印刷发票号码
qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额
qeug_tax = details.getBigDecimal("tax");//税额 qeug_tax = details.getBigDecimal("tax");//税额
qeug_amount = details.getBigDecimal("total");////价税合计 qeug_amount = details.getBigDecimal("total");////价税合计
qeug_bizdate = details.getDate("date");//开票日期 qeug_bizdate = details.getDate("date");//开票日期
qeug_saleorg = details.getString("seller");//开票单位 qeug_saleorg = details.getString("seller");//开票单位
items = details.getJSONArray("items");//电子发票购买项 items = details.getJSONArray("items");//电子发票购买项
} else if ("10200".equals(invoiceType)){ } else if ("10200".equals(invoiceType)){
//当票据类型为10200定额发票 //当票据类型为10200定额发票
qeug_invoicecode = details.getString("code");//印刷发票代码 qeug_invoicecode = details.getString("code");//印刷发票代码
qeug_invoiceno = details.getString("number");//印刷发票号码 qeug_invoiceno = details.getString("number");//印刷发票号码
qeug_amount = details.getBigDecimal("total");////价税合计 qeug_amount = details.getBigDecimal("total");////价税合计
}else if ("10400".equals(invoiceType)){ }else if ("10400".equals(invoiceType)){
//当票据类型为10400定额发票 //当票据类型为10400定额发票
qeug_invoicecode = details.getString("code");//印刷发票代码 qeug_invoicecode = details.getString("code");//印刷发票代码
qeug_invoiceno = details.getString("number");//印刷发票号码 qeug_invoiceno = details.getString("number");//印刷发票号码
qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额
qeug_amount = details.getBigDecimal("total");////价税合计 qeug_amount = details.getBigDecimal("total");////价税合计
qeug_bizdate = details.getDate("date");//开票日期 qeug_bizdate = details.getDate("date");//开票日期
qeug_saleorg = details.getString("seller");//开票单位 qeug_saleorg = details.getString("seller");//开票单位
items = details.getJSONArray("items");//机打发票购买项明细 items = details.getJSONArray("items");//机打发票购买项明细
}else if ("10500".equals(invoiceType)){ }else if ("10500".equals(invoiceType)){
//当票据类型为10500出租车发票 //当票据类型为10500出租车发票
qeug_invoicecode = details.getString("code");//发票代码 qeug_invoicecode = details.getString("code");//发票代码
qeug_invoiceno = details.getString("number");//发票号码 qeug_invoiceno = details.getString("number");//发票号码
qeug_amount = details.getBigDecimal("total");////总金额 qeug_amount = details.getBigDecimal("total");////总金额
qeug_bizdate = details.getDate("date");//开票日期 qeug_bizdate = details.getDate("date");//开票日期
}else if ("10503".equals(invoiceType)){ }else if ("10503".equals(invoiceType)){
//当票据类型为10503火车票 //当票据类型为10503火车票
qeug_invoiceno = details.getString("number");//火车票号码 qeug_invoiceno = details.getString("number");//火车票号码
qeug_amount = details.getBigDecimal("total");////总金额 qeug_amount = details.getBigDecimal("total");////总金额
qeug_bizdate = details.getDate("date");//开票日期 qeug_bizdate = details.getDate("date");//开票日期
}else if ("10505".equals(invoiceType)){ }else if ("10505".equals(invoiceType)){
//当票据类型为10505客运汽车 //当票据类型为10505客运汽车
qeug_invoicecode = details.getString("code");//发票代码 qeug_invoicecode = details.getString("code");//发票代码
qeug_invoiceno = details.getString("number");//发票号码 qeug_invoiceno = details.getString("number");//发票号码
qeug_amount = details.getBigDecimal("total");////总金额 qeug_amount = details.getBigDecimal("total");////总金额
qeug_bizdate = details.getDate("date");//开票日期 qeug_bizdate = details.getDate("date");//开票日期
}else if ("10506".equals(invoiceType)){ }else if ("10506".equals(invoiceType)){
//当票据类型为10506航空运输电子客票行程单 //当票据类型为10506航空运输电子客票行程单
qeug_invoiceno = details.getString("number");//发票号码 qeug_invoiceno = details.getString("number");//发票号码
qeug_tax = details.getBigDecimal("tax");//税额 qeug_tax = details.getBigDecimal("tax");//税额
qeug_amount = details.getBigDecimal("total");////总额 qeug_amount = details.getBigDecimal("total");////总额
qeug_bizdate = details.getDate("date");//填开日期 qeug_bizdate = details.getDate("date");//填开日期
qeug_saleorg = details.getString("issue_by");//填开单位 qeug_saleorg = details.getString("issue_by");//填开单位
}else if ("10507".equals(invoiceType)){ }else if ("10507".equals(invoiceType)){
//当票据类型为10507过路费发票 //当票据类型为10507过路费发票
qeug_invoicecode = details.getString("code");//发票代码 qeug_invoicecode = details.getString("code");//发票代码
qeug_invoiceno = details.getString("number");//发票号码 qeug_invoiceno = details.getString("number");//发票号码
qeug_amount = details.getBigDecimal("total");//总金额 qeug_amount = details.getBigDecimal("total");//总金额
qeug_bizdate = details.getDate("date");//填开日期 qeug_bizdate = details.getDate("date");//填开日期
}else{ }else{
parseFlag = false; parseFlag = false;
this.getView().showTipNotification(name +":发票识别失败:请上传有效发票"); this.getView().showTipNotification(name +":发票识别失败:请上传有效发票");
} }
boolean saveResultFlag = false; boolean saveResultFlag = false;
JSONObject save_data = saveCheckJson.getJSONObject("data"); JSONObject save_data = saveCheckJson.getJSONObject("data");
JSONArray billDatas = save_data.getJSONArray("billDatas"); JSONArray billDatas = save_data.getJSONArray("billDatas");
JSONObject billData = billDatas.getJSONObject(0); JSONObject billData = billDatas.getJSONObject(0);
String invoiceState = billData.getString("invoiceState"); String invoiceState = billData.getString("invoiceState");
if ("0".equals(invoiceState)||"3".equals(invoiceState)){ if ("0".equals(invoiceState)||"3".equals(invoiceState)){
saveResultFlag = true; saveResultFlag = true;
}else { }else {
this.getView().showTipNotification(name +":发票保存校验失败:发票状态异常"); this.getView().showTipNotification(name +":发票保存校验失败:发票状态异常");
return; return;
}
//todo若为有效发票则生成发票等级并构建发票信息分录数据
if (parseFlag && saveResultFlag){
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);
}
DynamicObject project = dataEntity.getDynamicObject("project");
recon_invoicebill.set("project",project);//设置项目名称
recon_invoicebill.set("collectionway","NORMAL");//设置征收方式为默认普通征税
if ("0".equals(invoiceState)){
recon_invoicebill.set("invoicetype","posinvoice"); //设置为正数发票
}else {
recon_invoicebill.set("invoicetype","roffinvoice"); //设置为红冲发票
}
QFilter invoicetype_qf = new QFilter("number",QCP.equals,type);
DynamicObject bd_invoicetype = BusinessDataServiceHelper.loadSingle("bd_invoicetype", invoicetype_qf.toArray());
recon_invoicebill.set("invoice",bd_invoicetype);//设置发票类型
//发票号码 invoiceno
// recon_invoicebill.set("invoiceno",System.currentTimeMillis());
recon_invoicebill.set("invoicecode",qeug_invoicecode);//发票代码
recon_invoicebill.set("invoiceno",qeug_invoiceno);//分录中的发票号码
recon_invoicebill.set("notaxamt",qeug_notaxamt);//不含税金额
recon_invoicebill.set("tax",qeug_tax);//税额
recon_invoicebill.set("amount",qeug_amount);//价税合计
recon_invoicebill.set("bizdate",qeug_bizdate);//开票日期
// 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();
if (items != null){
for (int x = 0; x < items.size(); x++ ){
JSONObject item = items.getJSONObject(x);
if (item != null){
DynamicObject invoiceentr = invoiceentrs.addNew();
invoiceentr.set("entry_content",item.getString("name"));//项目名称
invoiceentr.set("entry_qty",item.getString("quantity"));//数量
invoiceentr.set("entry_price",item.getString("price"));//单价
invoiceentr.set("entry_notaxamt",item.getString("total"));//金额
if (item.containsKey("tax_rate")){
String tax_rate = item.getString("tax_rate");
String substring = tax_rate.substring(0, tax_rate.length() - 1);
int value = Integer.parseInt(substring);
QFilter bd_taxrate_qf = new QFilter("taxrate",QCP.equals,value);
DynamicObject bd_taxrate = BusinessDataServiceHelper.loadSingle("bd_taxrate", bd_taxrate_qf.toArray());
invoiceentr.set("entry_taxrate",bd_taxrate);//税率
}
if (item.containsKey("tax")){
invoiceentr.set("entry_tax",item.getString("tax"));//税额
}
}
} }
}else { //todo若为有效发票则生成发票等级并构建发票信息分录数据
DynamicObject invoiceentr = invoiceentrs.addNew(); if (parseFlag && saveResultFlag){
invoiceentr.set("entry_content",description);//项目名称 JSONArray resultList = saveCheckJson.getJSONArray("resultList");
invoiceentr.set("entry_notaxamt",qeug_amount); JSONObject result = resultList.getJSONObject(0);//保存返回结果
String pi_key = result.getString("pi_key");//发票结果key
DynamicObject recon_invoicebill = BusinessDataServiceHelper.newDynamicObject("recon_invoicebill");
// DynamicObject recon_invoicebill1 = BusinessDataServiceHelper.loadSingle("2031274535679975424", "recon_invoicebill");
recon_invoicebill.set("billstatus","C");//单据状态
//所属组织
DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, "DOBE")});
if (null != org) {
recon_invoicebill.set("org",org);
}
recon_invoicebill.set("contractbill",dataEntity.getDynamicObject("contractbill"));
recon_invoicebill.set("biztype","CONTRACT");//发票所属业务
DynamicObject project = dataEntity.getDynamicObject("project");
recon_invoicebill.set("project",project);//设置项目名称
recon_invoicebill.set("collectionway","NORMAL");//设置征收方式为默认普通征税
if ("0".equals(invoiceState)){
recon_invoicebill.set("invoicetype","posinvoice"); //设置为正数发票
}else {
recon_invoicebill.set("invoicetype","roffinvoice"); //设置为红冲发票
}
QFilter invoicetype_qf = new QFilter("number",QCP.equals,invoiceType);
DynamicObject bd_invoicetype = BusinessDataServiceHelper.loadSingle("bd_invoicetype", invoicetype_qf.toArray());
recon_invoicebill.set("invoice",bd_invoicetype);//设置发票类型
//发票号码 invoiceno
// recon_invoicebill.set("invoiceno",System.currentTimeMillis());
recon_invoicebill.set("invoicecode",qeug_invoicecode == ""?"0":qeug_invoicecode);//发票代码
recon_invoicebill.set("invoiceno",qeug_invoiceno);//分录中的发票号码
recon_invoicebill.set("invoiceamount",qeug_amount);//发票金额
recon_invoicebill.set("haswriteoffamount",BigDecimal.ZERO);//已核销金额
recon_invoicebill.set("writeoffamount",qeug_amount);//未核销金额
recon_invoicebill.set("notaxamt",qeug_notaxamt);//不含税金额
recon_invoicebill.set("tax",qeug_tax);//税额
recon_invoicebill.set("amount",qeug_amount);//价税合计
recon_invoicebill.set("bizdate",qeug_bizdate);//开票日期
// 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();
if (items != null){
for (int x = 0; x < items.size(); x++ ){
JSONObject item = items.getJSONObject(x);
if (item != null){
DynamicObject invoiceentr = invoiceentrs.addNew();
invoiceentr.set("entry_content",item.getString("name"));//项目名称
invoiceentr.set("entry_qty",item.getString("quantity"));//数量
invoiceentr.set("entry_price",item.getString("price"));//单价
invoiceentr.set("entry_notaxamt",item.getString("total"));//金额
if (item.containsKey("tax_rate")){
String tax_rate = item.getString("tax_rate");
String substring = tax_rate.substring(0, tax_rate.length() - 1);
int value = Integer.parseInt(substring);
QFilter bd_taxrate_qf = new QFilter("taxrate",QCP.equals,value);
DynamicObject bd_taxrate = BusinessDataServiceHelper.loadSingle("bd_taxrate", bd_taxrate_qf.toArray());
invoiceentr.set("entry_taxrate",bd_taxrate);//税率
}
if (item.containsKey("tax")){
invoiceentr.set("entry_tax",item.getString("tax"));//税额
}
}
}
}else {
DynamicObject invoiceentr = invoiceentrs.addNew();
invoiceentr.set("entry_content",description);//项目名称
invoiceentr.set("entry_notaxamt",qeug_amount);
}
//todo:若接口返回明细--遍历新增发票明细分录
Object[] save = SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});
//todo:添加发票信息分录
DynamicObject dynamicObject = invoiceentry.addNew();//新增分录行
//todo:模仿标品新增字段,为接口返回数据反写分录做准备
DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle(recon_invoicebill.getLong("id"), "recon_invoicebill_f7");
dynamicObject.set("qeug_invoiceno",qeug_invoiceno);
dynamicObject.set("inventry_invoicebill",dynamicObject1);
dynamicObject.set("qeug_invoicekey",pi_key);
dynamicObject.set("qeug_textfield", "发票识别:"+name);
this.getView().updateView("invoiceentry");
this.getView().showSuccessNotification("发票识别成功");
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
}
}else {//
//验真保存失败--提示失败信息
this.getView().showTipNotification(name +":发票保存验真:请上传有效发票"+saveCheckJson.getString("message"));
} }
}else {
//todo:若接口返回明细--遍历新增发票明细分录 //发票识别失败--提示失败信息
this.getView().showTipNotification(name +":发票识别失败:请上传有效发票"+ocr_jsonObject.getString("message"));
Object[] save = SaveServiceHelper.save(new DynamicObject[]{recon_invoicebill});
//todo:添加发票信息分录
DynamicObject dynamicObject = invoiceentry.addNew();//新增分录行
//todo:模仿标品新增字段,为接口返回数据反写分录做准备
DynamicObject dynamicObject1 = BusinessDataServiceHelper.loadSingle(recon_invoicebill.getLong("id"), "recon_invoicebill_f7");
dynamicObject.set("qeug_invoiceno",qeug_invoiceno);
dynamicObject.set("inventry_invoicebill",dynamicObject1);
dynamicObject.set("qeug_textfield", "发票识别:"+name);
this.getView().updateView("invoiceentry");
this.getView().showSuccessNotification("发票识别成功");
SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()});
} }
}else {// }else {//附件类型不符合规范
//验真保存失败--提示失败信息 this.getView().showTipNotification("文件:"+name+",不符合规范请重新上传");
this.getView().showTipNotification(name +":发票保存验真:请上传有效发票"+saveCheckJson.getString("message"));
} }
}else {
//发票识别失败--提示失败信息
this.getView().showTipNotification(name +":发票识别失败:请上传有效发票"+ocr_jsonObject.getString("message"));
} }
}else {//附件类型不符合规范
this.getView().showTipNotification("文件:"+name+",不符合规范请重新上传");
} }
this.getView().updateView("invoiceentry");
}else {
this.getView().showTipNotification("请先选择用款单位!");
} }
}
break; break;
//发票验真验重 //发票验真验重
case "qeug_invoicecheck": case "qeug_invoicecheck":
@ -379,20 +415,44 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
EntryGrid assetsentry = (EntryGrid)this.getView().getControl("invoiceentry"); EntryGrid assetsentry = (EntryGrid)this.getView().getControl("invoiceentry");
int[] selectRows = assetsentry.getSelectRows(); int[] selectRows = assetsentry.getSelectRows();
if (selectRows.length > 0) { if (selectRows.length > 0) {
Map<String, Object> map = new HashMap<>();
List<String> noList = new ArrayList<>();
for (int i = 0; i < selectRows.length; i++) { for (int i = 0; i < selectRows.length; i++) {
int selectRow = selectRows[i]; int selectRow = selectRows[i];
String qeug_invoiceno = (String)this.getModel().getValue("qeug_invoiceno",selectRow);//分录中的发票号码 String qeug_invoicekey = (String)this.getModel().getValue("qeug_invoicekey",selectRow);//分录中的发票保存key
QFilter q = new QFilter("invoiceno", QCP.equals, qeug_invoiceno); noList.add(qeug_invoicekey);
DynamicObject recon_invoicebill = BusinessDataServiceHelper.loadSingle("recon_invoicebill", new QFilter[]{q}); }
if (null != recon_invoicebill) { map.put("pi_keys", noList);
int recon_invoicebill1 = DeleteServiceHelper.delete("recon_invoicebill", new QFilter[]{q}); String keys_str = "";
//失败 ObjectMapper objectMapper = new ObjectMapper();
if (1 != recon_invoicebill1) { try {
this.getView().showTipNotification("删除失败:请检查发票登记单的单据状态"); keys_str = objectMapper.writeValueAsString(map);
args.setCancel(true); } catch (JsonProcessingException e) {
return; throw new RuntimeException(e);
}
String oaToken = this.getOaToken();
JSONObject deleteResult = deleteInvoice(keys_str, oaToken);
String del_result = deleteResult.getString("success");
if ("true".equals(del_result)){
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;
}
} }
} }
}else {
args.setCancel(true);//取消操作
this.getView().showTipNotification("oa删除接口调用失败"+deleteResult.getString("message"));
} }
} }
break; break;
@ -404,7 +464,13 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
public String getOaToken(){ public String getOaToken(){
String userName = "lexmiscivrest"; String userName = "lexmiscivrest";
String password = "lexmisciv2019"; String password = "lexmisciv2019";
String loginName = "test"; String loginName = "test";//测试使用test用户
//正式环境使用
// Long userId = UserServiceHelper.getCurrentUserId();
// DynamicObject bos_user = BusinessDataServiceHelper.loadSingle(userId, "bos_user");
// if (bos_user != null){
// loginName = bos_user.getString("number");
// }
String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token"; String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token";
//接口请求体 //接口请求体
@ -469,7 +535,7 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
try { try {
String linkPostjson = HttpClientUtils.postjson(linkUrl, saveCheckHeader,strJson); String linkPostjson = HttpClientUtils.postjson(linkUrl, saveCheckHeader,strJson);
logger.info("获取parseOCRData接口返回结果:\n{}", linkPostjson); logger.info("获取saveOutInvoice接口返回结果:\n{}", linkPostjson);
if (StringUtils.isNotEmpty(linkPostjson)) { if (StringUtils.isNotEmpty(linkPostjson)) {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson); JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
return jsonObject; return jsonObject;
@ -481,6 +547,39 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin {
return null; return null;
} }
public JSONObject deleteInvoice(String pi_keys,String token) {
String linkUrl = "http://172.31.254.240:9090/seeyon/rest/lexmisciv/kekai/delInvoice";
//接口请求体
Map<String, String> saveCheckHeader = new HashMap<>();
saveCheckHeader.put("Content-Type", "application/json");
saveCheckHeader.put("token", token);
try {
String linkPostjson = HttpClientUtils.postjson(linkUrl, saveCheckHeader,pi_keys);
logger.info("获取delInvoice接口返回结果\n{}", linkPostjson);
if (StringUtils.isNotEmpty(linkPostjson)) {
JSONObject jsonObject = JSONObject.parseObject(linkPostjson);
return jsonObject;
}
}catch (Exception e){
logger.info(String.format("delInvoice接口异常%s", e.getMessage()));
throw new RuntimeException(e);
}
return null;
}
public String getCompanyTaxNo(String bizDept){
//根据用款部门的编号获得对应关系表中的财务公司编号和部门编号
DynamicObject orginfo = BusinessDataServiceHelper.loadSingle("qeug_recon_orgrelation",new QFilter[]{new QFilter("number","=",bizDept)});
String qeug_taxno = "";
if(orginfo != null){
qeug_taxno = orginfo.getString("qeug_taxno");//财务公司税务登记号
}
return qeug_taxno;
}
public String getFileBase64StrByUrl(Map<String, Object> attachment){ public String getFileBase64StrByUrl(Map<String, Object> attachment){