diff --git a/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java b/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java index 8aa4b8d..8ebabd9 100644 --- a/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java +++ b/main/java/shkd/repc/recon/formplugin/ReconPayreqFormPlugin.java @@ -15,6 +15,7 @@ import kd.bos.cache.CacheFactory; import kd.bos.cache.TempFileCache; import kd.bos.coderule.api.CodeRuleInfo; import kd.bos.context.RequestContext; +import kd.bos.dataentity.OperateOption; import kd.bos.dataentity.entity.DynamicObject; import kd.bos.dataentity.entity.DynamicObjectCollection; import kd.bos.dataentity.resource.ResManager; @@ -165,822 +166,831 @@ public class ReconPayreqFormPlugin extends AbstractFormPlugin implements BeforeF @Override public void clientCallBack(ClientCallBackEvent e) { - super.clientCallBack(e); - String name = e.getName(); - if ("auto_save".equals(name)){ - this.getView().invokeOperation("save"); + super.clientCallBack(e); + String name = e.getName(); + if ("auto_save".equals(name)){ + this.getView().invokeOperation("save"); + } + } - } + @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){ + //发票识别test + 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> attachments = AttachmentServiceHelper.getAttachments(billtype, + dataEntity.getPkValue(), "qeug_attachmentpanelap"); + if (attachments.size() <= 0) { + this.getView().showTipNotification("请先上传发票附件"); + return; + } + // ToDo: 获取token;重新识别无需对现存的发票的数据操作,直接提示接口信息 - @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){ - //发票识别test - 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> 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(!Strings.isEmpty(oaToken)){//判断是否获取到token + for (int i = 0; i < attachments.size(); i++) { + Map attachment = attachments.get(i); + String type = attachment.get("type").toString(); + String name = attachment.get("name").toString(); + if (fileExtendList.contains(type)){//规范附件类型,超出范围外不调用接口 + // TODO: 根据发票路径转换出图像数据 + String fileBase64 = getFileBase64StrByUrl(attachment);//转换为Base64数据 + // TODO: 调取OA发票识别接口 + JSONObject ocr_jsonObject = parseOCRData(companyTaxNo, type, fileBase64, oaToken); + String ocr_success = ocr_jsonObject.getString("success"); + if ("true".equals(ocr_success)) { + //TODO: 发票识别成功调用OA发票保存接口 + JSONArray ocrDatas = ocr_jsonObject.getJSONArray("data"); + String fileId = ocr_jsonObject.getString("fileId"); + JSONObject saveCheckJson = saveCheck(companyTaxNo, fileId, ocrDatas,oaToken);//返回数据 + DobeDWUtils.saveLog("FPLOG", + "OA发票","", saveCheckJson.toJSONString(), + true,"调用OA发票保存接口"); + logger.info("发票传OA保存接口:"+saveCheckJson.toJSONString()); + String save_success = saveCheckJson.getString("success"); + logger.info("发票传OA保存接口2:"+save_success); + if ("true".equals(save_success)){ + //TODO: 生成发票登记 - String oaToken = getOaToken(); - //发票信息分录 - DynamicObjectCollection invoiceentry = this.getView().getModel().getEntryEntity("invoiceentry"); - if(!Strings.isEmpty(oaToken)){//判断是否获取到token - for (int i = 0; i < attachments.size(); i++) { - Map attachment = attachments.get(i); - String type = attachment.get("type").toString(); - String name = attachment.get("name").toString(); - if (fileExtendList.contains(type)){//规范附件类型,超出范围外不调用接口 - // TODO: 根据发票路径转换出图像数据 - String fileBase64 = getFileBase64StrByUrl(attachment);//转换为Base64数据 - // TODO: 调取OA发票识别接口 - JSONObject ocr_jsonObject = parseOCRData(companyTaxNo, type, fileBase64, oaToken); - String ocr_success = ocr_jsonObject.getString("success"); - if ("true".equals(ocr_success)) { - //TODO: 发票识别成功调用OA发票保存接口 - JSONArray ocrDatas = ocr_jsonObject.getJSONArray("data"); - String fileId = ocr_jsonObject.getString("fileId"); - JSONObject saveCheckJson = saveCheck(companyTaxNo, fileId, ocrDatas,oaToken);//返回数据 - DobeDWUtils.saveLog("FPLOG", - "OA发票","", saveCheckJson.toJSONString(), - true,"调用OA发票保存接口"); - logger.info("发票传OA保存接口:"+saveCheckJson.toJSONString()); - String save_success = saveCheckJson.getString("success"); - logger.info("发票传OA保存接口2:"+save_success); - if ("true".equals(save_success)){ - //TODO: 生成发票登记 - - JSONArray dataList = ocr_jsonObject.getJSONArray("data");//data数据类型为集合表示 - JSONObject data = dataList.getJSONObject(0);//data数据 - String invoiceType = data.getString("type"); //票据类型 - JSONObject details = data.getJSONObject("details");//票据数据内容 - String description = data.getString("description");//发票名称 - String qeug_invoicecode = "";//发票代码初始定义 - String qeug_invoiceno = "";//发票号码 - BigDecimal qeug_notaxamt = BigDecimal.ZERO;//不含税金额 - BigDecimal qeug_tax = BigDecimal.ZERO;//税额 - BigDecimal qeug_amount = BigDecimal.ZERO;//价税合计 - Date qeug_bizdate = null;//开票日期 - String qeug_saleorg = "";//开票单位,只有文字;该字段不用从oa携带和还原 - JSONArray items = null; - boolean parseFlag = true; - if ("10100".equals(invoiceType) || "10101".equals(invoiceType) || "10102".equals(invoiceType) ){ - //当票据类型为10100【增值税专用发票】、10101【增值税普通发票】、10102【增值税电子普通发票】 - qeug_invoicecode = details.getString("code");//印刷发票代码 - qeug_invoiceno = details.getString("number");//印刷发票号码 - qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 - qeug_tax = details.getBigDecimal("tax");//税额 - qeug_amount = details.getBigDecimal("total");////价税合计 - qeug_bizdate = details.getDate("date");//开票日期 - qeug_saleorg = details.getString("seller");//开票单位 - items = details.getJSONArray("items");//增值税发票购买项明细 - }else if ("10103".equals(invoiceType)){ - //当票据类型为10100【增值税普通发票(卷票)】 - qeug_invoicecode = details.getString("code");//印刷发票代码 - qeug_invoiceno = details.getString("number");//印刷发票号码 - qeug_amount = details.getBigDecimal("total");////价税合计 - qeug_bizdate = details.getDate("date");//开票日期 - qeug_saleorg = details.getString("seller");//开票单位 - items = details.getJSONArray("items");//增值税发票卷票购买项 - }else if ("10108".equals(invoiceType) || "10107".equals(invoiceType)){ - //当票据类型为10107【电子发票(增值税专用发票)】、10108【电子发票(普通发票)】 - qeug_invoiceno = details.getString("number");//印刷发票号码 - qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 - qeug_tax = details.getBigDecimal("tax");//税额 - qeug_amount = details.getBigDecimal("total");////价税合计 - qeug_bizdate = details.getDate("date");//开票日期 - qeug_saleorg = details.getString("seller");//开票单位 - items = details.getJSONArray("items");//电子发票购买项 - } else if ("10200".equals(invoiceType)){ - //当票据类型为10200【定额发票】 - qeug_invoicecode = details.getString("code");//印刷发票代码 - qeug_invoiceno = details.getString("number");//印刷发票号码 - qeug_amount = details.getBigDecimal("total");////价税合计 - }else if ("10400".equals(invoiceType)){ - //当票据类型为10400【定额发票】 - qeug_invoicecode = details.getString("code");//印刷发票代码 - qeug_invoiceno = details.getString("number");//印刷发票号码 - qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 - qeug_amount = details.getBigDecimal("total");////价税合计 - qeug_bizdate = details.getDate("date");//开票日期 - qeug_saleorg = details.getString("seller");//开票单位 - items = details.getJSONArray("items");//机打发票购买项明细 - }else if ("10500".equals(invoiceType)){ - //当票据类型为10500【出租车发票】 - qeug_invoicecode = details.getString("code");//发票代码 - qeug_invoiceno = details.getString("number");//发票号码 - qeug_amount = details.getBigDecimal("total");////总金额 - qeug_bizdate = details.getDate("date");//开票日期 - }else if ("10503".equals(invoiceType)){ - //当票据类型为10503【火车票】 - qeug_invoiceno = details.getString("number");//火车票号码 - qeug_amount = details.getBigDecimal("total");////总金额 - qeug_bizdate = details.getDate("date");//开票日期 - }else if ("10505".equals(invoiceType)){ - //当票据类型为10505【客运汽车】 - qeug_invoicecode = details.getString("code");//发票代码 - qeug_invoiceno = details.getString("number");//发票号码 - qeug_amount = details.getBigDecimal("total");////总金额 - qeug_bizdate = details.getDate("date");//开票日期 - }else if ("10506".equals(invoiceType)){ - //当票据类型为10506【航空运输电子客票行程单】 - qeug_invoiceno = details.getString("number");//发票号码 - qeug_tax = details.getBigDecimal("tax");//税额 - qeug_amount = details.getBigDecimal("total");////总额 - qeug_bizdate = details.getDate("date");//填开日期 - qeug_saleorg = details.getString("issue_by");//填开单位 - }else if ("10507".equals(invoiceType)){ - //当票据类型为10507【过路费发票】 - qeug_invoicecode = details.getString("code");//发票代码 - qeug_invoiceno = details.getString("number");//发票号码 - qeug_amount = details.getBigDecimal("total");//总金额 - qeug_bizdate = details.getDate("date");//填开日期 - }else{ - parseFlag = false; - this.getView().showTipNotification(name +":发票识别失败:请上传有效发票"); - } - boolean saveResultFlag = false; - JSONObject save_data = saveCheckJson.getJSONObject("data"); - JSONArray billDatas = save_data.getJSONArray("billDatas"); - JSONObject billData = billDatas.getJSONObject(0); - String invoiceState = billData.getString("invoiceState"); - if ("0".equals(invoiceState)||"3".equals(invoiceState)){ - saveResultFlag = true; - }else { - this.getView().showTipNotification(name +":发票保存校验失败:发票状态异常"); - return; - } - - //todo:若为有效发票则生成发票等级,并构建发票信息分录数据 - if (parseFlag && saveResultFlag){ - JSONArray resultList = saveCheckJson.getJSONArray("resultList"); - 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","A");//单据状态 - //所属组织 - //DynamicObject org = BusinessDataServiceHelper.loadSingle("bos_org", new QFilter[]{new QFilter("number", QCP.equals, "dobe")}); - long rootOrgId = OrgUnitServiceHelper.getRootOrgId(); - DynamicObject org = BusinessDataServiceHelper.loadSingle(rootOrgId, "bos_org"); - if (null != org) { - recon_invoicebill.set("org",org); + JSONArray dataList = ocr_jsonObject.getJSONArray("data");//data数据类型为集合表示 + JSONObject data = dataList.getJSONObject(0);//data数据 + String invoiceType = data.getString("type"); //票据类型 + JSONObject details = data.getJSONObject("details");//票据数据内容 + String description = data.getString("description");//发票名称 + String qeug_invoicecode = "";//发票代码初始定义 + String qeug_invoiceno = "";//发票号码 + BigDecimal qeug_notaxamt = BigDecimal.ZERO;//不含税金额 + BigDecimal qeug_tax = BigDecimal.ZERO;//税额 + BigDecimal qeug_amount = BigDecimal.ZERO;//价税合计 + Date qeug_bizdate = null;//开票日期 + String qeug_saleorg = "";//开票单位,只有文字;该字段不用从oa携带和还原 + JSONArray items = null; + boolean parseFlag = true; + if ("10100".equals(invoiceType) || "10101".equals(invoiceType) || "10102".equals(invoiceType) ){ + //当票据类型为10100【增值税专用发票】、10101【增值税普通发票】、10102【增值税电子普通发票】 + qeug_invoicecode = details.getString("code");//印刷发票代码 + qeug_invoiceno = details.getString("number");//印刷发票号码 + qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 + qeug_tax = details.getBigDecimal("tax");//税额 + qeug_amount = details.getBigDecimal("total");////价税合计 + qeug_bizdate = details.getDate("date");//开票日期 + qeug_saleorg = details.getString("seller");//开票单位 + items = details.getJSONArray("items");//增值税发票购买项明细 + }else if ("10103".equals(invoiceType)){ + //当票据类型为10100【增值税普通发票(卷票)】 + qeug_invoicecode = details.getString("code");//印刷发票代码 + qeug_invoiceno = details.getString("number");//印刷发票号码 + qeug_amount = details.getBigDecimal("total");////价税合计 + qeug_bizdate = details.getDate("date");//开票日期 + qeug_saleorg = details.getString("seller");//开票单位 + items = details.getJSONArray("items");//增值税发票卷票购买项 + }else if ("10108".equals(invoiceType) || "10107".equals(invoiceType)){ + //当票据类型为10107【电子发票(增值税专用发票)】、10108【电子发票(普通发票)】 + qeug_invoiceno = details.getString("number");//印刷发票号码 + qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 + qeug_tax = details.getBigDecimal("tax");//税额 + qeug_amount = details.getBigDecimal("total");////价税合计 + qeug_bizdate = details.getDate("date");//开票日期 + qeug_saleorg = details.getString("seller");//开票单位 + items = details.getJSONArray("items");//电子发票购买项 + } else if ("10200".equals(invoiceType)){ + //当票据类型为10200【定额发票】 + qeug_invoicecode = details.getString("code");//印刷发票代码 + qeug_invoiceno = details.getString("number");//印刷发票号码 + qeug_amount = details.getBigDecimal("total");////价税合计 + }else if ("10400".equals(invoiceType)){ + //当票据类型为10400【定额发票】 + qeug_invoicecode = details.getString("code");//印刷发票代码 + qeug_invoiceno = details.getString("number");//印刷发票号码 + qeug_notaxamt = details.getBigDecimal("pretax_amount");//不含税金额 + qeug_amount = details.getBigDecimal("total");////价税合计 + qeug_bizdate = details.getDate("date");//开票日期 + qeug_saleorg = details.getString("seller");//开票单位 + items = details.getJSONArray("items");//机打发票购买项明细 + }else if ("10500".equals(invoiceType)){ + //当票据类型为10500【出租车发票】 + qeug_invoicecode = details.getString("code");//发票代码 + qeug_invoiceno = details.getString("number");//发票号码 + qeug_amount = details.getBigDecimal("total");////总金额 + qeug_bizdate = details.getDate("date");//开票日期 + }else if ("10503".equals(invoiceType)){ + //当票据类型为10503【火车票】 + qeug_invoiceno = details.getString("number");//火车票号码 + qeug_amount = details.getBigDecimal("total");////总金额 + qeug_bizdate = details.getDate("date");//开票日期 + }else if ("10505".equals(invoiceType)){ + //当票据类型为10505【客运汽车】 + qeug_invoicecode = details.getString("code");//发票代码 + qeug_invoiceno = details.getString("number");//发票号码 + qeug_amount = details.getBigDecimal("total");////总金额 + qeug_bizdate = details.getDate("date");//开票日期 + }else if ("10506".equals(invoiceType)){ + //当票据类型为10506【航空运输电子客票行程单】 + qeug_invoiceno = details.getString("number");//发票号码 + qeug_tax = details.getBigDecimal("tax");//税额 + qeug_amount = details.getBigDecimal("total");////总额 + qeug_bizdate = details.getDate("date");//填开日期 + qeug_saleorg = details.getString("issue_by");//填开单位 + }else if ("10507".equals(invoiceType)){ + //当票据类型为10507【过路费发票】 + qeug_invoicecode = details.getString("code");//发票代码 + qeug_invoiceno = details.getString("number");//发票号码 + qeug_amount = details.getBigDecimal("total");//总金额 + qeug_bizdate = details.getDate("date");//填开日期 + }else{ + parseFlag = false; + this.getView().showTipNotification(name +":发票识别失败:请上传有效发票"); } - DynamicObject project = dataEntity.getDynamicObject("project"); - recon_invoicebill.set("project",project);//设置项目名称 - switch (billtype){ - case "recon_payreqbill"://付款申请 - recon_invoicebill.set("biztype","CONTRACT");//发票所属业务为合同 - recon_invoicebill.set("contractbill",dataEntity.getDynamicObject("contractbill"));//合同 - break; - case "recon_connotextbill": - recon_invoicebill.set("biztype","CONNOTEXT");//发票所属业务为费用 - recon_invoicebill.set("connotextbill",this.getModel().getDataEntity());//发票登记 - break; - } - recon_invoicebill.set("collectionway","NORMAL");//设置征收方式为默认普通征税 - if ("0".equals(invoiceState)){ - recon_invoicebill.set("invoicetype","posinvoice"); //设置为正数发票 + boolean saveResultFlag = false; + JSONObject save_data = saveCheckJson.getJSONObject("data"); + JSONArray billDatas = save_data.getJSONArray("billDatas"); + JSONObject billData = billDatas.getJSONObject(0); + String invoiceState = billData.getString("invoiceState"); + if ("0".equals(invoiceState)||"3".equals(invoiceState)){ + saveResultFlag = true; }else { - recon_invoicebill.set("invoicetype","roffinvoice"); //设置为红冲发票 + this.getView().showTipNotification(name +":发票保存校验失败:发票状态异常"); + return; } - 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()); + //todo:若为有效发票则生成发票等级,并构建发票信息分录数据 + if (parseFlag && saveResultFlag){ + JSONArray resultList = saveCheckJson.getJSONArray("resultList"); + JSONObject result = resultList.getJSONObject(0);//保存返回结果 + String pi_key = result.getString("pi_key");//发票结果key - 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",qeug_invoiceno);//----编码规则待维护,目前与发票号码一致 - - //付款申请单 payreqentrys - DynamicObjectCollection payreqentrys = recon_invoicebill.getDynamicObjectCollection("payreqentrys"); - payreqentrys.clear(); - DynamicObject payreqentry = payreqentrys.addNew(); - payreqentry.set("fbasedataid", this.getView().getModel().getDataEntity()); - - //todo:若接口返回汇总 - //发票_明细 - //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"));//税额 - } - } + //生成发票登记表单 + DynamicObject recon_invoicebill = BusinessDataServiceHelper.newDynamicObject("recon_invoicebill"); + recon_invoicebill.set("billstatus","A");//单据状态 + //所属组织 + //long rootOrgId = OrgUnitServiceHelper.getRootOrgId(); + long rootOrgId = dataEntity.getLong("org.id"); + DynamicObject org = BusinessDataServiceHelper.loadSingle(rootOrgId, "bos_org"); + if (null != org) { + recon_invoicebill.set("org",org); + } + DynamicObject project = dataEntity.getDynamicObject("project"); + recon_invoicebill.set("project",project);//设置项目名称 + switch (billtype){ + case "recon_payreqbill"://付款申请 + recon_invoicebill.set("biztype","CONTRACT");//发票所属业务为合同 + recon_invoicebill.set("contractbill",dataEntity.getDynamicObject("contractbill"));//合同 + break; + case "recon_connotextbill": + recon_invoicebill.set("biztype","CONNOTEXT");//发票所属业务为费用 + recon_invoicebill.set("connotextbill",this.getModel().getDataEntity());//发票登记 + break; + } + recon_invoicebill.set("collectionway","NORMAL");//设置征收方式为默认普通征税 + if ("0".equals(invoiceState)){ + recon_invoicebill.set("invoicetype","posinvoice"); //设置为正数发票 + }else { + recon_invoicebill.set("invoicetype","roffinvoice"); //设置为红冲发票 } - }else { - DynamicObject invoiceentr = invoiceentrs.addNew(); - invoiceentr.set("entry_content",description);//项目名称 - invoiceentr.set("entry_notaxamt",qeug_amount); + 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",qeug_invoiceno);//----编码规则待维护,目前与发票号码一致 + + //付款申请单 payreqentrys + DynamicObjectCollection payreqentrys = recon_invoicebill.getDynamicObjectCollection("payreqentrys"); + payreqentrys.clear(); + DynamicObject payreqentry = payreqentrys.addNew(); + payreqentry.set("fbasedataid", this.getView().getModel().getDataEntity()); + + //todo:若接口返回汇总 + //发票_明细 + //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); + } + + //保存 + OperateOption operateOption1 = OperateOption.create(); + OperationResult operationResult1 = OperationServiceHelper.executeOperate("save", "recon_invoicebill", new DynamicObject[]{recon_invoicebill}, operateOption1); + if (!operationResult1.isSuccess()){ + logger.error(operationResult1.getMessage()); + } + //提交 + OperateOption operateOption2 = OperateOption.create(); + OperationResult operationResult2 = OperationServiceHelper.executeOperate("submit", "recon_invoicebill", new DynamicObject[]{recon_invoicebill}, operateOption2); + if (!operationResult2.isSuccess()){ + logger.error(operationResult2.getMessage()); + } + //审核 + OperateOption operateOption3 = OperateOption.create(); + OperationResult operationResult3 = OperationServiceHelper.executeOperate("audit", "recon_invoicebill", new DynamicObject[]{recon_invoicebill}, operateOption3); + if (!operationResult3.isSuccess()){ + logger.error(operationResult3.getMessage()); + } + + //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("发票识别成功"); + refreshInvoiceEntry(); + SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()}); } - OperationResult operationResult = OperationServiceHelper.executeOperate("save", "recon_invoicebill", new DynamicObject[]{recon_invoicebill}); - if (!operationResult.isSuccess()){ - logger.error(operationResult.getMessage()); - } - OperationResult operationResult1 = OperationServiceHelper.executeOperate("submit", "recon_invoicebill", new DynamicObject[]{recon_invoicebill}); - if (!operationResult1.isSuccess()){ - logger.error(operationResult1.getMessage()); - } - OperationResult operationResult2 = OperationServiceHelper.executeOperate("audit", "recon_invoicebill", new DynamicObject[]{recon_invoicebill}); - if (!operationResult2.isSuccess()){ - logger.error(operationResult2.getMessage()); - } - //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("发票识别成功"); - refreshInvoiceEntry(); - SaveServiceHelper.save(new DynamicObject[]{this.getView().getModel().getDataEntity()}); + }else {// + //验真保存失败--提示失败信息 + this.getView().showTipNotification(name +":发票保存验真:请上传有效发票"+saveCheckJson.getString("message")); } - }else {// - //验真保存失败--提示失败信息 - this.getView().showTipNotification(name +":发票保存验真:请上传有效发票"+saveCheckJson.getString("message")); + }else { + //发票识别失败--提示失败信息 + this.getView().showTipNotification(name +":发票识别失败:请上传有效发票"+ocr_jsonObject.getString("message")); } - }else { - //发票识别失败--提示失败信息 - this.getView().showTipNotification(name +":发票识别失败:请上传有效发票"+ocr_jsonObject.getString("message")); + }else {//附件类型不符合规范 + this.getView().showTipNotification("文件:"+name+",不符合规范请重新上传"); } - }else {//附件类型不符合规范 - this.getView().showTipNotification("文件:"+name+",不符合规范请重新上传"); } } + this.getView().updateView(); + }else { + this.getView().showTipNotification("请先选择用款单位!"); } - this.getView().updateView(); - }else { - this.getView().showTipNotification("请先选择用款单位!"); - } - break; - //发票验真验重 - case "qeug_refinvoice": - //todo: 关联发票二开接口 - switch (billtype){ - case "recon_payreqbill"://当单据为付款申请时 - DynamicObject contractbill = this.getModel().getDataEntity().getDynamicObject("contractbill"); - if (contractbill != null){ - ListShowParameter listShowParameter = ShowFormHelper.createShowListForm("recon_invoicebill_f7", true); - listShowParameter.setFormId("bos_listf7"); - listShowParameter.setCaption(ResManager.loadKDString("请选择关联发票", "RePayReqBillFormPlugin_4", "repc-recon-formplugin")); - DynamicObjectCollection invoiceEntries = dataEntity.getDynamicObjectCollection("invoiceentry"); - List selectInvoiceIds = invoiceEntries.stream().filter(invoiceEntry -> null != invoiceEntry.get("inventry_invoicebill")).map(invoiceEntry -> { - DynamicObject invoiceF7 = invoiceEntry.getDynamicObject("inventry_invoicebill"); - return invoiceF7.getPkValue(); - }).collect(Collectors.toList()); - listShowParameter.setSelectedRows(selectInvoiceIds.toArray()); - StyleCss inlineStyleCss = new StyleCss(); - inlineStyleCss.setHeight("600"); - inlineStyleCss.setWidth("800"); - List qFilters = listShowParameter.getListFilterParameter().getQFilters(); - qFilters.add(new QFilter("org", QCP.equals, this.getModel().getDataEntity().getDynamicObject("org").getPkValue())); - qFilters.add(new QFilter("hasredoff", QCP.equals, false)); - qFilters.add(new QFilter("invoicetype", QCP.not_equals, "roffinvoice")); - qFilters.add(new QFilter("billstatus", QCP.equals, "C")); - qFilters.add(new QFilter("writeoffamount",QCP.large_than,BigDecimal.ZERO)); - qFilters.add(new QFilter("contractbill.id",QCP.equals,contractbill.getPkValue())); - listShowParameter.getOpenStyle().setInlineStyleCss(inlineStyleCss); - listShowParameter.getOpenStyle().setShowType(ShowType.Modal); - listShowParameter.setCloseCallBack(new CloseCallBack(this, "recon_invoicebill_f7")); - getView().showForm(listShowParameter); - }else { - this.getView().showTipNotification("请先选择合同"); - } - break; - case "recon_connotextbill"://费用登记 - DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); - if (project != null){ - ListShowParameter listShowParameter = ShowFormHelper.createShowListForm("recon_invoicebill_f7", true); - listShowParameter.setFormId("bos_listf7"); - listShowParameter.setCaption(ResManager.loadKDString("请选择关联发票", "RePayReqBillFormPlugin_4", "repc-recon-formplugin")); - DynamicObjectCollection invoiceEntries = dataEntity.getDynamicObjectCollection("invoiceentry"); - List selectInvoiceIds = invoiceEntries.stream().filter(invoiceEntry -> null != invoiceEntry.get("inventry_invoicebill")).map(invoiceEntry -> { - DynamicObject invoiceF7 = invoiceEntry.getDynamicObject("inventry_invoicebill"); - return invoiceF7.getPkValue(); - }).collect(Collectors.toList()); - listShowParameter.setSelectedRows(selectInvoiceIds.toArray()); - StyleCss inlineStyleCss = new StyleCss(); - inlineStyleCss.setHeight("600"); - inlineStyleCss.setWidth("800"); - List qFilters = listShowParameter.getListFilterParameter().getQFilters(); - qFilters.add(new QFilter("org", QCP.equals, this.getModel().getDataEntity().getDynamicObject("org").getPkValue())); - qFilters.add(new QFilter("hasredoff", QCP.equals, false)); - qFilters.add(new QFilter("invoicetype", QCP.not_equals, "roffinvoice")); - qFilters.add(new QFilter("billstatus", QCP.equals, "C")); - qFilters.add(new QFilter("writeoffamount",QCP.large_than,BigDecimal.ZERO)); - qFilters.add(new QFilter("project.id",QCP.equals,project.getPkValue())); - listShowParameter.getOpenStyle().setInlineStyleCss(inlineStyleCss); - listShowParameter.getOpenStyle().setShowType(ShowType.Modal); - listShowParameter.setCloseCallBack(new CloseCallBack(this, "recon_invoicebill_f7")); - getView().showForm(listShowParameter); - }else { - this.getView().showTipNotification("请先选择项目"); - } - break; - } - break; - case "deleteinvoiceentry"://删行后自动保存 + break; + //关联发票 + case "qeug_refinvoice": + //todo: 关联发票二开接口 + switch (billtype){ + case "recon_payreqbill"://当单据为付款申请时 + DynamicObject contractbill = this.getModel().getDataEntity().getDynamicObject("contractbill"); + if (contractbill != null){ + ListShowParameter listShowParameter = ShowFormHelper.createShowListForm("recon_invoicebill_f7", true); + listShowParameter.setFormId("bos_listf7"); + listShowParameter.setCaption(ResManager.loadKDString("请选择关联发票", "RePayReqBillFormPlugin_4", "repc-recon-formplugin")); + DynamicObjectCollection invoiceEntries = dataEntity.getDynamicObjectCollection("invoiceentry"); + List selectInvoiceIds = invoiceEntries.stream().filter(invoiceEntry -> null != invoiceEntry.get("inventry_invoicebill")).map(invoiceEntry -> { + DynamicObject invoiceF7 = invoiceEntry.getDynamicObject("inventry_invoicebill"); + return invoiceF7.getPkValue(); + }).collect(Collectors.toList()); + listShowParameter.setSelectedRows(selectInvoiceIds.toArray()); + StyleCss inlineStyleCss = new StyleCss(); + inlineStyleCss.setHeight("600"); + inlineStyleCss.setWidth("800"); + List qFilters = listShowParameter.getListFilterParameter().getQFilters(); + qFilters.add(new QFilter("org", QCP.equals, this.getModel().getDataEntity().getDynamicObject("org").getPkValue())); + qFilters.add(new QFilter("hasredoff", QCP.equals, false)); + qFilters.add(new QFilter("invoicetype", QCP.not_equals, "roffinvoice")); + qFilters.add(new QFilter("billstatus", QCP.equals, "C")); + qFilters.add(new QFilter("writeoffamount",QCP.large_than,BigDecimal.ZERO)); + qFilters.add(new QFilter("contractbill.id",QCP.equals,contractbill.getPkValue())); + listShowParameter.getOpenStyle().setInlineStyleCss(inlineStyleCss); + listShowParameter.getOpenStyle().setShowType(ShowType.Modal); + listShowParameter.setCloseCallBack(new CloseCallBack(this, "recon_invoicebill_f7")); + getView().showForm(listShowParameter); + }else { + this.getView().showTipNotification("请先选择合同"); + } + break; + case "recon_connotextbill"://费用登记 + DynamicObject project = this.getModel().getDataEntity().getDynamicObject("project"); + if (project != null){ + ListShowParameter listShowParameter = ShowFormHelper.createShowListForm("recon_invoicebill_f7", true); + listShowParameter.setFormId("bos_listf7"); + listShowParameter.setCaption(ResManager.loadKDString("请选择关联发票", "RePayReqBillFormPlugin_4", "repc-recon-formplugin")); + DynamicObjectCollection invoiceEntries = dataEntity.getDynamicObjectCollection("invoiceentry"); + List selectInvoiceIds = invoiceEntries.stream().filter(invoiceEntry -> null != invoiceEntry.get("inventry_invoicebill")).map(invoiceEntry -> { + DynamicObject invoiceF7 = invoiceEntry.getDynamicObject("inventry_invoicebill"); + return invoiceF7.getPkValue(); + }).collect(Collectors.toList()); + listShowParameter.setSelectedRows(selectInvoiceIds.toArray()); + StyleCss inlineStyleCss = new StyleCss(); + inlineStyleCss.setHeight("600"); + inlineStyleCss.setWidth("800"); + List qFilters = listShowParameter.getListFilterParameter().getQFilters(); + qFilters.add(new QFilter("org", QCP.equals, this.getModel().getDataEntity().getDynamicObject("org").getPkValue())); + qFilters.add(new QFilter("hasredoff", QCP.equals, false)); + qFilters.add(new QFilter("invoicetype", QCP.not_equals, "roffinvoice")); + qFilters.add(new QFilter("billstatus", QCP.equals, "C")); + qFilters.add(new QFilter("writeoffamount",QCP.large_than,BigDecimal.ZERO)); + qFilters.add(new QFilter("project.id",QCP.equals,project.getPkValue())); + listShowParameter.getOpenStyle().setInlineStyleCss(inlineStyleCss); + listShowParameter.getOpenStyle().setShowType(ShowType.Modal); + listShowParameter.setCloseCallBack(new CloseCallBack(this, "recon_invoicebill_f7")); + getView().showForm(listShowParameter); + }else { + this.getView().showTipNotification("请先选择项目"); + } + break; + } + break; + case "deleteinvoiceentry"://删行后自动保存 // refreshInvoiceEntry(); - SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)}); - break; + SaveServiceHelper.save(new DynamicObject[]{this.getModel().getDataEntity(true)}); + break; + } + } - } + @Override + public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { + super.closedCallBack(closedCallBackEvent); + DynamicObject model = getModel().getDataEntity(true); + String actionId = closedCallBackEvent.getActionId(); - @Override - public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { - super.closedCallBack(closedCallBackEvent); - DynamicObject model = getModel().getDataEntity(true); - String actionId = closedCallBackEvent.getActionId(); - - // 关联发票 - if ("recon_invoicebill_f7".equals(actionId)) { - ListSelectedRowCollection returnData = (ListSelectedRowCollection) closedCallBackEvent.getReturnData(); - if (returnData == null || returnData.isEmpty()) { - return; - } - Object[] primaryKeyValues = returnData.getPrimaryKeyValues(); - DynamicObjectCollection invoiceEntries = model.getDynamicObjectCollection("invoiceentry"); - List invoiceIdList = invoiceEntries.stream() - .filter(e -> null != e.get("inventry_invoicebill")) - .map(e -> e.getDynamicObject("inventry_invoicebill").getLong("id")) - .collect(Collectors.toList()); - - DynamicObject[] invoiceF7s = BusinessDataServiceHelper.load(primaryKeyValues, - EntityMetadataCache.getDataEntityType("recon_invoicebill_f7")); - - BigDecimal invoiceAmt = BigDecimal.ZERO; - for (int i = 0; i < invoiceF7s.length; i++) { - DynamicObject invoiceBill = invoiceF7s[i]; - if (invoiceIdList.contains(invoiceBill.getLong("id"))) { - continue; + // 关联发票 + if ("recon_invoicebill_f7".equals(actionId)) { + ListSelectedRowCollection returnData = (ListSelectedRowCollection) closedCallBackEvent.getReturnData(); + if (returnData == null || returnData.isEmpty()) { + return; } - DynamicObject invoiceEntry = invoiceEntries.addNew(); - invoiceEntry.getDataEntityState().setFromDatabase(true); - 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")); - } + Object[] primaryKeyValues = returnData.getPrimaryKeyValues(); + DynamicObjectCollection invoiceEntries = model.getDynamicObjectCollection("invoiceentry"); + List invoiceIdList = invoiceEntries.stream() + .filter(e -> null != e.get("inventry_invoicebill")) + .map(e -> e.getDynamicObject("inventry_invoicebill").getLong("id")) + .collect(Collectors.toList()); - getModel().updateCache(); - getView().updateView("invoiceentry"); + DynamicObject[] invoiceF7s = BusinessDataServiceHelper.load(primaryKeyValues, + EntityMetadataCache.getDataEntityType("recon_invoicebill_f7")); - refreshInvoiceEntry(); - } - } - - @Override - public void beforeDoOperation(BeforeDoOperationEventArgs args) { - super.beforeDoOperation(args); - FormOperate source = (FormOperate) args.getSource(); - String operateKey = source.getOperateKey(); - DynamicObject dataEntity = this.getModel().getDataEntity();//单据数据 - Object pk = this.getModel().getDataEntity().getPkValue();//当前单据主键 - switch (operateKey) { - //删行 - case "deleteinvoiceentry": - //用户在删除发票明细时,如果当前发票已经生成发票登记单,一并删除掉 - //删除后--未保存前,遍历发票信息分录 删除满足(明细"发票号码" == 发票登记单头"发票号码")的发票登记单 - //获得"发票信息明细"选中行 - EntryGrid assetsentry = (EntryGrid)this.getView().getControl("invoiceentry"); - int[] selectRows = assetsentry.getSelectRows(); - if (selectRows.length > 0) { - Map map = new HashMap<>(); - List noList = new ArrayList<>(); - for (int i = 0; i < selectRows.length; i++) { - int selectRow = selectRows[i]; - String qeug_invoicekey = (String)this.getModel().getValue("qeug_invoicekey",selectRow);//分录中的发票保存key - if(!Strings.isEmpty(qeug_invoicekey)){//key不为空或者不为""时 - noList.add(qeug_invoicekey); - } + BigDecimal invoiceAmt = BigDecimal.ZERO; + for (int i = 0; i < invoiceF7s.length; i++) { + DynamicObject invoiceBill = invoiceF7s[i]; + if (invoiceIdList.contains(invoiceBill.getLong("id"))) { + continue; } - if (noList.size() > 0){ - map.put("pi_keys", noList); - String keys_str = ""; - ObjectMapper objectMapper = new ObjectMapper(); - try { - keys_str = objectMapper.writeValueAsString(map); - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } + DynamicObject invoiceEntry = invoiceEntries.addNew(); + invoiceEntry.getDataEntityState().setFromDatabase(true); + 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")); + } - 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}); - } + getModel().updateCache(); + getView().updateView("invoiceentry"); + + refreshInvoiceEntry(); + } + } + + @Override + public void beforeDoOperation(BeforeDoOperationEventArgs args) { + super.beforeDoOperation(args); + FormOperate source = (FormOperate) args.getSource(); + String operateKey = source.getOperateKey(); + DynamicObject dataEntity = this.getModel().getDataEntity();//单据数据 + Object pk = this.getModel().getDataEntity().getPkValue();//当前单据主键 + switch (operateKey) { + //删行 + case "deleteinvoiceentry": + //用户在删除发票明细时,如果当前发票已经生成发票登记单,一并删除掉 + //删除后--未保存前,遍历发票信息分录 删除满足(明细"发票号码" == 发票登记单头"发票号码")的发票登记单 + //获得"发票信息明细"选中行 + EntryGrid assetsentry = (EntryGrid)this.getView().getControl("invoiceentry"); + int[] selectRows = assetsentry.getSelectRows(); + if (selectRows.length > 0) { + Map map = new HashMap<>(); + List noList = new ArrayList<>(); + for (int i = 0; i < selectRows.length; i++) { + int selectRow = selectRows[i]; + String qeug_invoicekey = (String)this.getModel().getValue("qeug_invoicekey",selectRow);//分录中的发票保存key + if(!Strings.isEmpty(qeug_invoicekey)){//key不为空或者不为""时 + noList.add(qeug_invoicekey); + } + } + if (noList.size() > 0){ + map.put("pi_keys", noList); + String keys_str = ""; + ObjectMapper objectMapper = new ObjectMapper(); + try { + keys_str = objectMapper.writeValueAsString(map); + } catch (JsonProcessingException e) { + 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}); + } + } + }else { + args.setCancel(true);//取消操作 + this.getView().showTipNotification("oa删除接口调用失败"+deleteResult.getString("message")); } - }else { - args.setCancel(true);//取消操作 - this.getView().showTipNotification("oa删除接口调用失败"+deleteResult.getString("message")); } - } - } - break; - case "confirmchange": - //确认核销付款申请/费用登记关联发票 - String billtype =this.getModel().getDataEntityType().getName();//单据标识 - //todo:若单据为费用登记单 - boolean billFlag = true; - if ("recon_connotextbill".equals(billtype)){ - Map> tarBills = BFTrackerServiceHelper.findTargetBills("recon_connotextbill", new Long[]{(Long) pk});//查询费用登记的下游单据 - HashSet 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)){ + break; + case "confirmchange": + //确认核销付款申请/费用登记关联发票 + String billtype =this.getModel().getDataEntityType().getName();//单据标识 + //todo:若单据为费用登记单 + boolean billFlag = true; + if ("recon_connotextbill".equals(billtype)){ + Map> tarBills = BFTrackerServiceHelper.findTargetBills("recon_connotextbill", new Long[]{(Long) pk});//查询费用登记的下游单据 + HashSet 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("下游关联付款申请单据状态异常,无法核销"); + 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("本次申请金额大于发票核销金额之和,请修改补录发票"); + 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("总发票核销金额大于本次申请金额,请修改补录发票"); } - } else { - args.setCancel(true);//取消操作 - this.getView().showTipNotification("总发票核销金额大于本次申请金额,请修改补录发票"); } - } - break; - case "submit": - boolean qeug_isticket = dataEntity.getBoolean("qeug_isticket");//查看是否补单状态 - DynamicObjectCollection invoiceEntrys = getModel().getEntryEntity("invoiceentry");//获取发票分录 - if (qeug_isticket){//若需要补单,则不允许发票分录存在数据 - if (invoiceEntrys.size() > 0){ - args.setCancel(true);//取消操作 - this.getView().showTipNotification("补票单据禁止关联发票,请删除后重新提交"); + break; + case "submit": + boolean qeug_isticket = dataEntity.getBoolean("qeug_isticket");//查看是否补单状态 + DynamicObjectCollection invoiceEntrys = getModel().getEntryEntity("invoiceentry");//获取发票分录 + if (qeug_isticket){//若需要补单,则不允许发票分录存在数据 + if (invoiceEntrys.size() > 0){ + args.setCancel(true);//取消操作 + this.getView().showTipNotification("补票单据禁止关联发票,请删除后重新提交"); + } + }else {//无需补票的时候必须提交等额申请核销的发票 + BigDecimal applyamt = dataEntity.getBigDecimal("applyamt");//本期申请金额 + BigDecimal invoiceApplyAmt = BigDecimal.ZERO;//初始化申请核销金额之和 + for (DynamicObject invoiceEntry : invoiceEntrys) { + BigDecimal inventry_haswriteoffamt = invoiceEntry.getBigDecimal("inventry_haswriteoffamt");//发票申请核销金额 + invoiceApplyAmt = invoiceApplyAmt.add(inventry_haswriteoffamt);//汇总发票申请核销金额 + } + if (applyamt.compareTo(invoiceApplyAmt) != 0){ + args.setCancel(true);//取消操作 + this.getView().showTipNotification("本期申请金额须等于发票申请核销金额之和,请修改关联发票后重新提交"); + } } - }else {//无需补票的时候必须提交等额申请核销的发票 - BigDecimal applyamt = dataEntity.getBigDecimal("applyamt");//本期申请金额 - BigDecimal invoiceApplyAmt = BigDecimal.ZERO;//初始化申请核销金额之和 - for (DynamicObject invoiceEntry : invoiceEntrys) { - BigDecimal inventry_haswriteoffamt = invoiceEntry.getBigDecimal("inventry_haswriteoffamt");//发票申请核销金额 - invoiceApplyAmt = invoiceApplyAmt.add(inventry_haswriteoffamt);//汇总发票申请核销金额 - } - if (applyamt.compareTo(invoiceApplyAmt) != 0){ - args.setCancel(true);//取消操作 - this.getView().showTipNotification("本期申请金额须等于发票申请核销金额之和,请修改关联发票后重新提交"); - } - } - break; - default: - break; - } - } - - public void refreshInvoiceEntry() { - String billtype =this.getModel().getDataEntityType().getName(); - if ("recon_payreqbill".equals(billtype)){ - DynamicObjectCollection invoiceEntrys = getModel().getEntryEntity("invoiceentry"); - // 记录累计发票金额 - BigDecimal invoiceAmt = BigDecimal.ZERO; - // 获取数据 - for(DynamicObject invoiceEntry : invoiceEntrys) { - DynamicObject invoiceBill = invoiceEntry.getDynamicObject("inventry_invoicebill"); - if(null == invoiceBill) { - continue; - } - invoiceAmt = invoiceAmt.add(invoiceBill.getBigDecimal("invoiceamount")); + break; + default: + break; } - getModel().setValue("invoiceamt", invoiceAmt);//本次发票金额赋值 } - } - public String getOaToken(){ - String userName = System.getProperty("oaFPUserName"); - String password = System.getProperty("oaFPPassword"); - String loginName = "test";//测试使用test用户 - //正式环境使用 + public void refreshInvoiceEntry() { + String billtype =this.getModel().getDataEntityType().getName(); + if ("recon_payreqbill".equals(billtype)){ + DynamicObjectCollection invoiceEntrys = getModel().getEntryEntity("invoiceentry"); + // 记录累计发票金额 + BigDecimal invoiceAmt = BigDecimal.ZERO; + // 获取数据 + for(DynamicObject invoiceEntry : invoiceEntrys) { + DynamicObject invoiceBill = invoiceEntry.getDynamicObject("inventry_invoicebill"); + if(null == invoiceBill) { + continue; + } + invoiceAmt = invoiceAmt.add(invoiceBill.getBigDecimal("invoiceamount")); + } + getModel().setValue("invoiceamt", invoiceAmt);//本次发票金额赋值 + } + } + + public String getOaToken(){ + String userName = System.getProperty("oaFPUserName"); + String password = System.getProperty("oaFPPassword"); + 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 oaUrl = System.getProperty("oaurl"); - logger.info("密钥接口:mc获取的oaUrl:\n{}", oaUrl); - String linkUrl =oaUrl+ "/seeyon/rest/token"; - //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token"; - //接口请求体 - JSONObject linkBody = new JSONObject(); - linkBody.put("userName", userName); - linkBody.put("password", password); - linkBody.put("loginName",loginName); - String token = ""; - try { - String linkPostjson = HttpClientUtils.postjson(linkUrl, null, linkBody.toJSONString(),3*60*1000,3*60*1000); - logger.info("获取OaToken接口返回结果:\n{}", linkPostjson); + String oaUrl = System.getProperty("oaurl"); + logger.info("密钥接口:mc获取的oaUrl:\n{}", oaUrl); + String linkUrl =oaUrl+ "/seeyon/rest/token"; + //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/token"; + //接口请求体 + JSONObject linkBody = new JSONObject(); + linkBody.put("userName", userName); + linkBody.put("password", password); + linkBody.put("loginName",loginName); + String token = ""; + try { + String linkPostjson = HttpClientUtils.postjson(linkUrl, null, linkBody.toJSONString(),3*60*1000,3*60*1000); + logger.info("获取OaToken接口返回结果:\n{}", linkPostjson); - if (StringUtils.isNotEmpty(linkPostjson)) { - JSONObject jsonObject = JSONObject.parseObject(linkPostjson); - token = jsonObject.getString("id"); - logger.info("获取OaToken接口返回id"+token); - }else { - this.getView().showTipNotification("OaToken接口数据异常,请联系系统管理员!"); - } - return token; - } catch (Exception e) { - logger.info(String.format("获取OaToken接口异常:%s", e.getMessage())+"接口地址:"+linkUrl); - throw new RuntimeException(e); - } - } - - - public JSONObject parseOCRData(String taxno,String fileExtend,String base64File,String token){ - String oaUrl = System.getProperty("oaurl"); - logger.info("解析图片接口:mc获取的oaUrl:\n{}", oaUrl); - String linkUrl = oaUrl+"/seeyon/rest/lexmisciv/kekai/parseOCRData"; - System.out.println("test"); - //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/lexmisciv/kekai/parseOCRData"; - //接口请求体 - JSONObject linkBody = new JSONObject(); - linkBody.put("taxno", taxno); - linkBody.put("fileExtend", fileExtend); - linkBody.put("base64File", base64File); - String strJson = linkBody.toJSONString(); - Map base64Header = new HashMap<>(); - base64Header.put("Content-Type", "application/json"); - base64Header.put("token", token); - try { - 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); - return jsonObject; - }else { - this.getView().showTipNotification("parseOCRData接口数据异常,请联系系统管理员!"); - } - } catch (Exception e) { - logger.info(String.format("获取parseOCRData接口异常:%s", e.getMessage())); - throw new RuntimeException(e); - } - return null; - } - - public JSONObject saveCheck(String taxno,String fileId,JSONArray ocrDatas,String token) { - String oaUrl = System.getProperty("oaurl"); - logger.info("保存验真接口:mc获取的oaUrl:\n{}", oaUrl); - String linkUrl = oaUrl+"/seeyon/rest/lexmisciv/kekai/saveOutInvoice"; - //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/lexmisciv/kekai/saveOutInvoice"; - //接口请求体 - JSONObject linkBody = new JSONObject(); - linkBody.put("taxno", taxno); - linkBody.put("fileId", fileId); - linkBody.put("ocrDatas", ocrDatas); - String strJson = linkBody.toJSONString(); - Map saveCheckHeader = new HashMap<>(); - saveCheckHeader.put("Content-Type", "application/json"); - saveCheckHeader.put("token", token); - - try { - 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); - return jsonObject; - }else { - this.getView().showTipNotification("saveOutInvoice接口数据异常,请联系系统管理员!"); - } - }catch (Exception e){ - logger.info(String.format("saveOutInvoice接口异常:%s", e.getMessage())); - throw new RuntimeException(e); - } - - return null; - } - public JSONObject deleteInvoice(String pi_keys,String token) { - String oaUrl = System.getProperty("oaurl"); - logger.info("删除接口:mc获取的oaUrl:\n{}", oaUrl); - String linkUrl = oaUrl+"/seeyon/rest/lexmisciv/kekai/delInvoice"; - //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/lexmisciv/kekai/delInvoice"; - //接口请求体 - Map 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; - }else { - this.getView().showTipNotification("delInvoice接口数据异常,请联系系统管理员!"); - } - }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 attachment){ - Object attPKId = attachment.get("attPkId"); - AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(attPKId); - String resourcePath = attachmentDto.getResourcePath(); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - FileServiceFactory.getAttachmentFileService().download(resourcePath,out,null); - byte[] bytes = out.toByteArray(); - 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 allUsersOfOrg = UserServiceHelper.getAllUsersOfOrg(departId);//得到当前组织的全部人员,包括直属员工和下属组织的员工 - QFilter qFilter = new QFilter("id", QCP.in, allUsersOfOrg); - DynamicObject[] bos_users = BusinessDataServiceHelper.load("bos_user", "id,number", qFilter.toArray()); - List userNumbers = new ArrayList();//构建人员工号容器 - for (DynamicObject bos_user : bos_users) { - String number = bos_user.getString("number"); - userNumbers.add(number); + if (StringUtils.isNotEmpty(linkPostjson)) { + JSONObject jsonObject = JSONObject.parseObject(linkPostjson); + token = jsonObject.getString("id"); + logger.info("获取OaToken接口返回id"+token); + }else { + this.getView().showTipNotification("OaToken接口数据异常,请联系系统管理员!"); } - QFilter qfByNumber = new QFilter("number", QCP.in, userNumbers); - ListShowParameter formShowParameter = (ListShowParameter) beforeF7SelectEvent.getFormShowParameter(); - formShowParameter.getListFilterParameter().setFilter(qfByNumber); - }else { - beforeF7SelectEvent.setCancel(true); - this.getView().showTipNotification("请先选择用款部门"); + return token; + } catch (Exception e) { + logger.info(String.format("获取OaToken接口异常:%s", e.getMessage())+"接口地址:"+linkUrl); + throw new RuntimeException(e); } } - } - /** - * 校验发票分录金额是否存在差异,之前已经核销的发票需要返回已核销金额后再进行比较 - * @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 alreadyInvoices = new ArrayList<>(); - for (DynamicObject invoiceBill : invoiceBills) {//添加该申请单已核销的发票号码 - alreadyInvoices.add(invoiceBill.getString("invoiceno")); + + public JSONObject parseOCRData(String taxno,String fileExtend,String base64File,String token){ + String oaUrl = System.getProperty("oaurl"); + logger.info("解析图片接口:mc获取的oaUrl:\n{}", oaUrl); + String linkUrl = oaUrl+"/seeyon/rest/lexmisciv/kekai/parseOCRData"; + System.out.println("test"); + //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/lexmisciv/kekai/parseOCRData"; + //接口请求体 + JSONObject linkBody = new JSONObject(); + linkBody.put("taxno", taxno); + linkBody.put("fileExtend", fileExtend); + linkBody.put("base64File", base64File); + String strJson = linkBody.toJSONString(); + Map base64Header = new HashMap<>(); + base64Header.put("Content-Type", "application/json"); + base64Header.put("token", token); + try { + 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); + return jsonObject; + }else { + this.getView().showTipNotification("parseOCRData接口数据异常,请联系系统管理员!"); + } + } catch (Exception e) { + logger.info(String.format("获取parseOCRData接口异常:%s", e.getMessage())); + throw new RuntimeException(e); + } + return null; } - 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);//还原未核销金额 + + public JSONObject saveCheck(String taxno,String fileId,JSONArray ocrDatas,String token) { + String oaUrl = System.getProperty("oaurl"); + logger.info("保存验真接口:mc获取的oaUrl:\n{}", oaUrl); + String linkUrl = oaUrl+"/seeyon/rest/lexmisciv/kekai/saveOutInvoice"; + //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/lexmisciv/kekai/saveOutInvoice"; + //接口请求体 + JSONObject linkBody = new JSONObject(); + linkBody.put("taxno", taxno); + linkBody.put("fileId", fileId); + linkBody.put("ocrDatas", ocrDatas); + String strJson = linkBody.toJSONString(); + Map saveCheckHeader = new HashMap<>(); + saveCheckHeader.put("Content-Type", "application/json"); + saveCheckHeader.put("token", token); + + try { + 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); + return jsonObject; + }else { + this.getView().showTipNotification("saveOutInvoice接口数据异常,请联系系统管理员!"); + } + }catch (Exception e){ + logger.info(String.format("saveOutInvoice接口异常:%s", e.getMessage())); + throw new RuntimeException(e); + } + + return null; + } + public JSONObject deleteInvoice(String pi_keys,String token) { + String oaUrl = System.getProperty("oaurl"); + logger.info("删除接口:mc获取的oaUrl:\n{}", oaUrl); + String linkUrl = oaUrl+"/seeyon/rest/lexmisciv/kekai/delInvoice"; + //String linkUrl = "http://172.31.254.240:9090/seeyon/rest/lexmisciv/kekai/delInvoice"; + //接口请求体 + Map 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; + }else { + this.getView().showTipNotification("delInvoice接口数据异常,请联系系统管理员!"); + } + }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 attachment){ + Object attPKId = attachment.get("attPkId"); + AttachmentDto attachmentDto = AttachmentServiceHelper.getAttachmentInfoByAttPk(attPKId); + String resourcePath = attachmentDto.getResourcePath(); + ByteArrayOutputStream out = new ByteArrayOutputStream(); + FileServiceFactory.getAttachmentFileService().download(resourcePath,out,null); + byte[] bytes = out.toByteArray(); + 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 allUsersOfOrg = UserServiceHelper.getAllUsersOfOrg(departId);//得到当前组织的全部人员,包括直属员工和下属组织的员工 + QFilter qFilter = new QFilter("id", QCP.in, allUsersOfOrg); + DynamicObject[] bos_users = BusinessDataServiceHelper.load("bos_user", "id,number", qFilter.toArray()); + List userNumbers = new ArrayList();//构建人员工号容器 + 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 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)+"发票未核销金额不足,请重新关联发票"); + 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; } - }else { - this.getView().showTipNotification("第"+(i+1)+"发票行数据异常,请重新关联发票"); - flag = false; } + return flag; } - return flag; - } - /** - * 发票金额核销数据更新,根据校验未核销金额结果返回判断值,正确则更新发票核销数据 - * @param dataEntity - * @param pk - * @return - */ - public boolean VerificationInvoice(DynamicObject dataEntity,Object pk){ + /** + * 发票金额核销数据更新,根据校验未核销金额结果返回判断值,正确则更新发票核销数据 + * @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");//本期申请金额