发票问题修改
This commit is contained in:
parent
4a2828c944
commit
26d54d61a3
|
@ -1,15 +1,22 @@
|
|||
package shkd.fi.fi.formplugin;
|
||||
|
||||
import kd.bos.bill.AbstractBillPlugIn;
|
||||
import kd.bos.dataentity.OperateOption;
|
||||
import kd.bos.dataentity.entity.DynamicObject;
|
||||
import kd.bos.entity.datamodel.events.AfterDeleteRowEventArgs;
|
||||
import kd.bos.entity.datamodel.events.BeforeDeleteRowEventArgs;
|
||||
import kd.bos.entity.operate.OperateOptionConst;
|
||||
import kd.bos.entity.property.EntryProp;
|
||||
import kd.bos.form.CloseCallBack;
|
||||
import kd.bos.form.FormShowParameter;
|
||||
import kd.bos.form.ShowType;
|
||||
import kd.bos.form.control.events.ItemClickEvent;
|
||||
import kd.bos.form.events.AfterDoOperationEventArgs;
|
||||
import kd.bos.form.events.ClosedCallBackEvent;
|
||||
import kd.bos.servicehelper.BusinessDataServiceHelper;
|
||||
import kd.bos.servicehelper.operation.OperationServiceHelper;
|
||||
|
||||
import java.util.EventObject;
|
||||
import java.util.List;
|
||||
|
||||
public class ApFinapbillFormPlugin extends AbstractBillPlugIn {
|
||||
@Override
|
||||
|
@ -22,15 +29,33 @@ public class ApFinapbillFormPlugin extends AbstractBillPlugIn {
|
|||
public void itemClick(ItemClickEvent evt) {
|
||||
super.itemClick(evt);
|
||||
String itemKey = evt.getItemKey();
|
||||
|
||||
//发票采集按钮
|
||||
if ("shkd_fpocr".equals(itemKey)) {
|
||||
FormShowParameter parameter = new FormShowParameter();
|
||||
parameter.setCustomParam("billno", this.getModel().getValue("billno"));//应付单单据编号
|
||||
DynamicObject asstact = (DynamicObject) this.getModel().getValue("asstact");//往来户
|
||||
DynamicObject org = (DynamicObject) this.getModel().getValue("org");//结算组织
|
||||
String asstactName = "";
|
||||
if (asstact == null) {
|
||||
this.getView().showMessage("请选择结算供应商");
|
||||
return;
|
||||
}
|
||||
asstactName = asstact.getLocaleString("name").getLocaleValue_zh_CN();
|
||||
parameter.setCustomParam("asstactName", asstactName);//往来户
|
||||
String orgName = "";
|
||||
if (org == null) {
|
||||
this.getView().showMessage("请选择结算组织");
|
||||
return;
|
||||
}
|
||||
orgName = org.getString("name");
|
||||
parameter.setCustomParam("orgName", orgName);//结算组织 org
|
||||
Object id = this.getModel().getValue("id");
|
||||
if (id.equals(0L)) {
|
||||
this.getView().showMessage("请先保存单据");
|
||||
return;
|
||||
}
|
||||
parameter.setCustomParam("id", id);
|
||||
parameter.setCustomParam("billno", this.getModel().getValue("billno"));
|
||||
parameter.setCustomParam("id", id);//应付单id
|
||||
parameter.setFormId("shkd_uploadattachments");
|
||||
parameter.setCloseCallBack(new CloseCallBack(this, "shkd_fpocr"));
|
||||
parameter.getOpenStyle().setShowType(ShowType.Modal);
|
||||
|
@ -42,7 +67,42 @@ public class ApFinapbillFormPlugin extends AbstractBillPlugIn {
|
|||
@Override
|
||||
public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) {
|
||||
super.closedCallBack(closedCallBackEvent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeDeleteRow(BeforeDeleteRowEventArgs e) {
|
||||
super.beforeDeleteRow(e);
|
||||
EntryProp entryProp = e.getEntryProp();
|
||||
String entryPropName = entryProp.getName();
|
||||
OperateOption option = OperateOption.create();
|
||||
option.setVariableValue(OperateOptionConst.ISHASRIGHT, "true");
|
||||
option.setVariableValue(OperateOptionConst.IGNOREWARN, "true");
|
||||
if ("inventry".equals(entryPropName)) {
|
||||
int[] rowIndexs = e.getRowIndexs();
|
||||
if (rowIndexs.length > 0) {
|
||||
int row = rowIndexs[0];
|
||||
DynamicObject shkd_invoicereceipt = (DynamicObject) this.getModel().getValue("shkd_invoicereceipt", row);
|
||||
if (shkd_invoicereceipt != null) {
|
||||
DynamicObject invoicereceipt = BusinessDataServiceHelper.loadSingle(shkd_invoicereceipt.get("id"), "shkd_invoicereceipt");
|
||||
OperationServiceHelper.executeOperate("unaudit", "shkd_invoicereceipt", new DynamicObject[]{invoicereceipt}, option);
|
||||
OperationServiceHelper.executeOperate("delete", "shkd_invoicereceipt", new DynamicObject[]{invoicereceipt}, option);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterDeleteRow(AfterDeleteRowEventArgs e) {
|
||||
super.afterDeleteRow(e);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterDoOperation(AfterDoOperationEventArgs afterDoOperationEventArgs) {
|
||||
super.afterDoOperation(afterDoOperationEventArgs);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package shkd.fi.fi.formplugin;
|
|||
import com.alibaba.druid.support.logging.Log;
|
||||
import com.alibaba.druid.support.logging.LogFactory;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import dm.jdbc.util.StringUtil;
|
||||
import kd.bos.cache.CacheFactory;
|
||||
import kd.bos.cache.DistributeSessionlessCache;
|
||||
import kd.bos.cache.TempFileCache;
|
||||
|
@ -53,11 +54,11 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
* OCR发票识别接口url
|
||||
*/
|
||||
// public static final String OCR_INVOICESCANNER_URL = "https://apigw.coscoshipping.com/tax/ocr/v1/invoiceScanner";
|
||||
|
||||
/**
|
||||
* 发票验证接口url
|
||||
*/
|
||||
// public static final String COMPLIANCECOLLECTZY_URL = "https://apigw.coscoshipping.com/tax/input/v1/compliancecollectZY";
|
||||
|
||||
@Override
|
||||
public void registerListener(EventObject e) {
|
||||
super.registerListener(e);
|
||||
|
@ -88,6 +89,10 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
Object id = formShowParameter.getCustomParam("id");
|
||||
//财务应付单号
|
||||
String billno = formShowParameter.getCustomParam("billno");
|
||||
//往来户
|
||||
String asstactName = formShowParameter.getCustomParam("asstactName");
|
||||
//结算组织
|
||||
String orgName = formShowParameter.getCustomParam("orgName");
|
||||
//财务应付单
|
||||
DynamicObject ap_finapbill = BusinessDataServiceHelper.loadSingle(id, "ap_finapbill");
|
||||
|
||||
|
@ -118,7 +123,7 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
tokenBody.put("grant_type", "client_credentials");
|
||||
//1.3.通过接口调用获取token
|
||||
String postjson = HttpClientUtils.post(tokenUrl, tokenHeader, tokenBody);
|
||||
LogBillUtils.SaveLogBill(tokenUrl, postjson,"获取token", tokenBody.toString());
|
||||
LogBillUtils.SaveLogBill(tokenUrl, postjson, "获取token", tokenBody.toString());
|
||||
if (StringUtils.isEmpty(postjson)) {
|
||||
|
||||
this.getView().showMessage("获取token失败");
|
||||
|
@ -183,7 +188,7 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
//1.4.调用OCR接口
|
||||
String ocr_invoicescanner_url = System.getProperty("OCR_INVOICESCANNER_URL");
|
||||
String postjson = HttpClientUtils.postjson(ocr_invoicescanner_url, ocrScannerHeader, ocrScannerBody.toJSONString());
|
||||
LogBillUtils.SaveLogBill(ocr_invoicescanner_url, postjson,"OCR识别接口", ocrScannerBody.toString());
|
||||
LogBillUtils.SaveLogBill(ocr_invoicescanner_url, postjson, "OCR识别接口", ocrScannerBody.toString());
|
||||
if (StringUtils.isEmpty(postjson)) {
|
||||
this.getView().showMessage("OCR接口识别失败");
|
||||
}
|
||||
|
@ -198,6 +203,16 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
}
|
||||
List<Response> responseList = ocrRetureData.getResponse();
|
||||
Response response = responseList.get(0);
|
||||
String saleName = response.getSaleName();//开票公司
|
||||
if (StringUtils.isNotEmpty(saleName) && !StringUtil.equals(asstactName, saleName)) {
|
||||
this.getView().showMessage("发票开票单位和当前单据上结算供应商不一致");
|
||||
return;
|
||||
}
|
||||
String purchaserName = response.getPurchaserName();//收票公司
|
||||
if (StringUtils.isNotEmpty(purchaserName) && !StringUtil.equals(orgName, purchaserName)) {
|
||||
this.getView().showMessage("发票收票公司和当前应付单结算组织不匹配");
|
||||
return;
|
||||
}
|
||||
List<DetailList> detailList = response.getDetailList();
|
||||
BigDecimal shkd_tax = BigDecimal.ZERO;//税额
|
||||
BigDecimal shkd_amount = BigDecimal.ZERO;//金额
|
||||
|
@ -217,7 +232,7 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
compliancecollectBody.put("InvoiceCode", response.getInvoiceCode());
|
||||
compliancecollectBody.put("InvoiceNumber", response.getInvoiceNo());
|
||||
String checkCode = response.getCheckCode();
|
||||
if (StringUtils.isNotEmpty(checkCode)&&checkCode.length() > 6) {
|
||||
if (StringUtils.isNotEmpty(checkCode) && checkCode.length() > 6) {
|
||||
checkCode = checkCode.substring(checkCode.length() - 6);
|
||||
}
|
||||
compliancecollectBody.put("CheckCode_6", checkCode);// checkCode后6位数
|
||||
|
@ -232,7 +247,7 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
//2.3.调用发票合规查验接口
|
||||
String compliancecollectzy_url = System.getProperty("COMPLIANCECOLLECTZY_URL");
|
||||
String compliancecollectPostjson = HttpClientUtils.postjson(compliancecollectzy_url, compliancecollectHeader, compliancecollectBody.toJSONString());
|
||||
LogBillUtils.SaveLogBill(compliancecollectzy_url, compliancecollectPostjson,"发票合规查验接口", compliancecollectBody.toString());
|
||||
LogBillUtils.SaveLogBill(compliancecollectzy_url, compliancecollectPostjson, "发票合规查验接口", compliancecollectBody.toString());
|
||||
//
|
||||
if (compliancecollectPostjson == null || compliancecollectPostjson.isEmpty()) {
|
||||
// 使用自定义异常类型和更详细的异常信息
|
||||
|
@ -246,6 +261,7 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
if (!success) {
|
||||
this.getView().showMessage(message);
|
||||
}
|
||||
this.getView().showMessage("发票已识别验真通过,生成发票明细成功");
|
||||
//2.5.发票合规查验接口调用成功 生成发票识别单据
|
||||
DynamicObject shkd_invoicereceipt = BusinessDataServiceHelper.newDynamicObject("shkd_invoicereceipt");
|
||||
shkd_invoicereceipt.set("billno", String.valueOf(System.currentTimeMillis()));
|
||||
|
@ -286,8 +302,8 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
shkd_invoicereceipt.set("shkd_invid", null);//发票id 隐藏字段
|
||||
shkd_invoicereceipt.set("shkd_serialno", null);//发票流水号 隐藏字段
|
||||
shkd_invoicereceipt.set("shkd_refbill", ap_finapbill);//财务应付单
|
||||
shkd_invoicereceipt.set("billstatus", "A");
|
||||
shkd_invoicereceipt.set("creator",RequestContext.get().getCurrUserId());
|
||||
shkd_invoicereceipt.set("billstatus", "C");
|
||||
shkd_invoicereceipt.set("creator", RequestContext.get().getCurrUserId());
|
||||
|
||||
// option.setVariableValue(OperateOptionConst.ORM_SAVEOP_REMOVECACHE, "true");
|
||||
//保存发票识别单据并上传发票附件到发票识别单据
|
||||
|
@ -307,9 +323,9 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
|
||||
//回写发票信息到财务应付单发票明细
|
||||
if (!returnDataList.isEmpty()) {
|
||||
|
||||
ap_finapbill.set("istaxdeduction", false);//进项税抵扣
|
||||
DynamicObjectCollection inventry = ap_finapbill.getDynamicObjectCollection("inventry");
|
||||
inventry.clear();
|
||||
// inventry.clear();
|
||||
|
||||
IFormView parentView = this.getView().getParentView();
|
||||
for (DynamicObject dynamicObject : returnDataList) {
|
||||
|
@ -347,7 +363,8 @@ public class UploadAttachmentsFormPlugin extends AbstractFormPlugin {
|
|||
try {
|
||||
//current transaction is aborted, commands ignored until end of transaction block
|
||||
//保存财务应付单
|
||||
SaveServiceHelper.save(new DynamicObject[]{ap_finapbill}, option);
|
||||
// SaveServiceHelper.save(new DynamicObject[]{ap_finapbill}, option);
|
||||
SaveServiceHelper.save(new DynamicObject[]{ap_finapbill});
|
||||
} catch (Throwable e) {
|
||||
h.markRollback();
|
||||
log.info(e.getMessage());
|
||||
|
|
Loading…
Reference in New Issue