发票名识别校验
This commit is contained in:
		
							parent
							
								
									99d37d2ec4
								
							
						
					
					
						commit
						5447c0109c
					
				|  | @ -0,0 +1,169 @@ | ||||||
|  | // | ||||||
|  | // Source code recreated from a .class file by IntelliJ IDEA | ||||||
|  | // (powered by FernFlower decompiler) | ||||||
|  | // | ||||||
|  | 
 | ||||||
|  | package zcgj.zcdev.zcdev.pr.plugin.form; | ||||||
|  | 
 | ||||||
|  | import java.util.Date; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Set; | ||||||
|  | import kd.bos.context.RequestContext; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.dataentity.resource.ResManager; | ||||||
|  | import kd.bos.dataentity.utils.StringUtils; | ||||||
|  | import kd.bos.form.ConfirmCallBackListener; | ||||||
|  | import kd.bos.form.ConfirmTypes; | ||||||
|  | import kd.bos.form.MessageBoxOptions; | ||||||
|  | import kd.bos.form.MessageBoxResult; | ||||||
|  | import kd.bos.form.events.ClosedCallBackEvent; | ||||||
|  | import kd.bos.form.events.MessageBoxClosedEvent; | ||||||
|  | import kd.bos.list.IListView; | ||||||
|  | import kd.bos.list.ListShowParameter; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.bos.orm.query.QFilter; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.operation.SaveServiceHelper; | ||||||
|  | import kd.ec.basedata.common.invoicecloud.InvoiceDataHandleHelper; | ||||||
|  | import kd.ec.basedata.common.invoicecloud.bean.InvoiceVO; | ||||||
|  | import kd.ec.basedata.common.utils.EcSerializeHelper; | ||||||
|  | import kd.ec.basedata.common.utils.SystemParamHelper; | ||||||
|  | import kd.ec.ecpf.formplugin.invoicecloud.InvoiceCloudImportListPlugin; | ||||||
|  | 
 | ||||||
|  | public class CustomInvoiceCloudImportListPlugin extends InvoiceCloudImportListPlugin { | ||||||
|  |     private static final Log log = LogFactory.getLog(CustomInvoiceCloudImportListPlugin.class); | ||||||
|  |     public CustomInvoiceCloudImportListPlugin() { | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void closedCallBack(ClosedCallBackEvent closedCallBackEvent) { | ||||||
|  |         super.closedCallBack(closedCallBackEvent); | ||||||
|  |         String actionId = closedCallBackEvent.getActionId();//获取回调标识 | ||||||
|  |         log.info("获取回调标识:" + actionId); | ||||||
|  |         Object returnData = closedCallBackEvent.getReturnData();//获取回调数据 | ||||||
|  |         if (StringUtils.equals(actionId, "importinvoice") && returnData != null) { | ||||||
|  |             log.info("导入发票"); | ||||||
|  |             this.importInvoiceCallBack(returnData); | ||||||
|  |         } else if (StringUtils.equals(actionId, "xhSelectInvoice") && !StringUtils.isBlank(returnData)) { | ||||||
|  |             log.info("选择发票"); | ||||||
|  |             this.xhSelectInvoiceCallBack(returnData);//解析返回的发票数据 | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected void xhSelectInvoiceCallBack(Object returnData) { | ||||||
|  |         Map<String, Object> data = (Map)returnData; | ||||||
|  |         log.info("获取发票助手返回的数据"+data); | ||||||
|  |         DynamicObject org = (DynamicObject)data.get("org"); | ||||||
|  |         if (org != null) { | ||||||
|  |             long currUserId = RequestContext.get().getCurrUserId();//获取当前用户ID | ||||||
|  |             log.info("获取当前用户ID"); | ||||||
|  |             Object selectInvoice = data.get("selectInvoice"); | ||||||
|  |             log.info("获取发票对象"+selectInvoice); | ||||||
|  |             log.info("将selectInvoice解析为发票列表"); | ||||||
|  |             //将selectInvoice解析为发票列表 | ||||||
|  |             List<InvoiceVO> invoiceVOList = InvoiceDataHandleHelper.parseXhInvoiceCloudReturnData(selectInvoice); | ||||||
|  |             ListShowParameter listShowParameter = (ListShowParameter)this.getView().getFormShowParameter();//获取表单显示参数 | ||||||
|  |             log.info("获取表单显示参数"); | ||||||
|  |             String billFormId = listShowParameter.getBillFormId();//获取发票ID | ||||||
|  |             log.info("获取发票ID:"+billFormId); | ||||||
|  |             //处理发票列表,返回map,ture对应值表示Set 包含新生成的发票对象,false对应Set 包含已存在的发票对象。 | ||||||
|  |             log.info("处理发票列表,返回map,ture对应值表示Set 包含新生成的发票对象,false对应Set 包含已存在的发票对象。"); | ||||||
|  |             Map<Boolean, Set<DynamicObject>> invoiceMap = CustomInvoiceDataHandleHelper.processInvoiceVO(invoiceVOList, currUserId, org.getLong("id"), new Date(), billFormId, this.getCurrency(), true); | ||||||
|  |             if (invoiceMap.isEmpty()) { | ||||||
|  |                 this.getView().showTipNotification(ResManager.loadKDString("导入发票为空。", "InvoiceCloudImportListPlugin_4", "ec-ecpf-formplugin", new Object[0])); | ||||||
|  |             } else { | ||||||
|  |                 Set<DynamicObject> newInvoices = (Set)invoiceMap.getOrDefault(Boolean.TRUE, new HashSet(0));//新生成的发票对象 | ||||||
|  |                 Set<DynamicObject> updateInvoices = (Set)invoiceMap.getOrDefault(Boolean.FALSE, new HashSet(0));//已存在的发票对象。 | ||||||
|  |                 this.saveInvoiceAndGiveTips(newInvoices, updateInvoices, true);//保存发票数据并给出相应的提示 | ||||||
|  |                 log.info("保存发票数据并给出相应的提示"); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected void importInvoiceCallBack(Object returnData) { | ||||||
|  |         long orgId = RequestContext.get().getOrgId(); | ||||||
|  |         DynamicObject org = BusinessDataServiceHelper.loadSingle(orgId, "bos_org"); | ||||||
|  |         List<InvoiceVO> invoiceVOList = InvoiceDataHandleHelper.parseInvoiceCloudReturnData(returnData, org); | ||||||
|  |         ListShowParameter listShowParameter = (ListShowParameter)this.getView().getFormShowParameter(); | ||||||
|  |         String billFormId = listShowParameter.getBillFormId(); | ||||||
|  |         Map<Boolean, Set<DynamicObject>> invoiceMap = InvoiceDataHandleHelper.processInvoiceVO(invoiceVOList, RequestContext.get().getCurrUserId(), orgId, new Date(), billFormId, this.getCurrency()); | ||||||
|  |         if (!invoiceMap.isEmpty()) { | ||||||
|  |             if (invoiceMap.get(Boolean.TRUE) != null && !((Set)invoiceMap.get(Boolean.TRUE)).isEmpty()) { | ||||||
|  |                 Set<DynamicObject> newInvoices = (Set)invoiceMap.get(Boolean.TRUE); | ||||||
|  | 
 | ||||||
|  |                 for(DynamicObject newInvoice : newInvoices) { | ||||||
|  |                     DynamicObject invoiceOrg = StringUtils.equals(billFormId, "ec_in_invoice") ? newInvoice.getDynamicObject("buyer") : newInvoice.getDynamicObject("seller"); | ||||||
|  |                     String name = StringUtils.equals(billFormId, "ec_in_invoice") ? ResManager.loadKDString("购买方", "InvoiceCloudImportListPlugin_1", "ec-ecpf-formplugin", new Object[0]) : ResManager.loadKDString("销售方", "InvoiceCloudImportListPlugin_2", "ec-ecpf-formplugin", new Object[0]); | ||||||
|  |                     if (invoiceOrg != null && invoiceOrg.getLong("id") != orgId) { | ||||||
|  |                         this.getPageCache().put("importInvoiceCache", EcSerializeHelper.serialize(invoiceMap)); | ||||||
|  |                         this.getView().showConfirm(String.format(ResManager.loadKDString("当前发票%s不为当前组织,是否需要继续导入?", "InvoiceCloudImportListPlugin_3", "ec-ecpf-formplugin", new Object[0]), name), MessageBoxOptions.OKCancel, ConfirmTypes.Default, new ConfirmCallBackListener("importinvoiceconfirm")); | ||||||
|  |                         return; | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 Set<DynamicObject> existInvoices = (Set)invoiceMap.getOrDefault(Boolean.FALSE, new HashSet(0)); | ||||||
|  |                 this.saveInvoiceAndGiveTips(newInvoices, existInvoices, false); | ||||||
|  |             } else { | ||||||
|  |                 this.getView().showTipNotification(ResManager.loadKDString("发票已经在发票池中,无需重复导入。", "InvoiceCloudImportListPlugin_0", "ec-ecpf-formplugin", new Object[0])); | ||||||
|  |             } | ||||||
|  |         } else { | ||||||
|  |             this.getView().showTipNotification(ResManager.loadKDString("导入发票为空。", "InvoiceCloudImportListPlugin_4", "ec-ecpf-formplugin", new Object[0])); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected DynamicObject getCurrency() { | ||||||
|  |         QFilter numberFilter = new QFilter("number", "=", "CNY"); | ||||||
|  |         return BusinessDataServiceHelper.loadSingle("bd_currency", "", new QFilter[]{numberFilter}); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public void confirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) { | ||||||
|  |         super.confirmCallBack(messageBoxClosedEvent); | ||||||
|  |         String callBackId = messageBoxClosedEvent.getCallBackId(); | ||||||
|  |         if (StringUtils.equals(callBackId, "importinvoiceconfirm")) { | ||||||
|  |             this.importInvoiceConfirmCallBack(messageBoxClosedEvent); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected boolean isXhInvoiceCloud() { | ||||||
|  |         Object linkSystem = SystemParamHelper.getSystemParameter("linksystem", "eced"); | ||||||
|  |         return StringUtils.equals("cosmic", linkSystem == null ? "" : linkSystem.toString()); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected void importInvoiceConfirmCallBack(MessageBoxClosedEvent messageBoxClosedEvent) { | ||||||
|  |         Map<Boolean, Set<DynamicObject>> invoiceMap = (Map)EcSerializeHelper.unserialize(this.getPageCache().get("importInvoiceCache")); | ||||||
|  |         if (MessageBoxResult.Yes.getValue() == messageBoxClosedEvent.getResult().getValue()) { | ||||||
|  |             Set<DynamicObject> newInvoices = (Set)invoiceMap.getOrDefault(Boolean.TRUE, new HashSet(0)); | ||||||
|  |             Set<DynamicObject> existInvoices = (Set)invoiceMap.getOrDefault(Boolean.FALSE, new HashSet(0)); | ||||||
|  |             this.saveInvoiceAndGiveTips(newInvoices, existInvoices, false); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         this.getPageCache().remove("importInvoiceCache"); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected void saveInvoiceAndGiveTips(Set<DynamicObject> newInvoices, Set<DynamicObject> existInvoices, boolean isUpdate) { | ||||||
|  |         if (!newInvoices.isEmpty()) { | ||||||
|  |             SaveServiceHelper.save((DynamicObject[])newInvoices.toArray(new DynamicObject[0])); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (!existInvoices.isEmpty() && isUpdate) { | ||||||
|  |             SaveServiceHelper.save((DynamicObject[])existInvoices.toArray(new DynamicObject[0])); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         if (isUpdate) { | ||||||
|  |             this.getView().showSuccessNotification(String.format(ResManager.loadKDString("成功导入发票%1$s条;%2$s条发票已更新。", "InvoiceCloudImportListPlugin_8", "ec-ecpf-formplugin", new Object[0]), newInvoices.size(), existInvoices.size())); | ||||||
|  |         } else if (existInvoices != null && !existInvoices.isEmpty()) { | ||||||
|  |             this.getView().showSuccessNotification(String.format(ResManager.loadKDString("成功导入发票%1$s条;%2$s条发票已存在,不重复导入。", "InvoiceCloudImportListPlugin_7", "ec-ecpf-formplugin", new Object[0]), newInvoices.size(), existInvoices.size())); | ||||||
|  |         } else { | ||||||
|  |             this.getView().showSuccessNotification(String.format(ResManager.loadKDString("成功导入发票%s条。", "InvoiceCloudImportListPlugin_5", "ec-ecpf-formplugin", new Object[0]), newInvoices.size())); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         IListView view = (IListView)this.getView(); | ||||||
|  |         view.refresh(); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | @ -0,0 +1,271 @@ | ||||||
|  | // | ||||||
|  | // Source code recreated from a .class file by IntelliJ IDEA | ||||||
|  | // (powered by FernFlower decompiler) | ||||||
|  | // | ||||||
|  | 
 | ||||||
|  | package zcgj.zcdev.zcdev.pr.plugin.form; | ||||||
|  | 
 | ||||||
|  | import java.math.BigDecimal; | ||||||
|  | import java.text.ParseException; | ||||||
|  | import java.text.SimpleDateFormat; | ||||||
|  | import java.util.ArrayList; | ||||||
|  | import java.util.Date; | ||||||
|  | import java.util.HashMap; | ||||||
|  | import java.util.HashSet; | ||||||
|  | import java.util.List; | ||||||
|  | import java.util.Map; | ||||||
|  | import java.util.Set; | ||||||
|  | import kd.bos.coderule.api.CodeRuleInfo; | ||||||
|  | import kd.bos.context.RequestContext; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObject; | ||||||
|  | import kd.bos.dataentity.entity.DynamicObjectCollection; | ||||||
|  | import kd.bos.dataentity.metadata.dynamicobject.DynamicObjectType; | ||||||
|  | import kd.bos.dataentity.resource.ResManager; | ||||||
|  | import kd.bos.dataentity.utils.StringUtils; | ||||||
|  | import kd.bos.entity.EntityMetadataCache; | ||||||
|  | import kd.bos.entity.MainEntityType; | ||||||
|  | import kd.bos.exception.KDBizException; | ||||||
|  | import kd.bos.form.CloseCallBack; | ||||||
|  | import kd.bos.form.FormShowParameter; | ||||||
|  | import kd.bos.form.ShowType; | ||||||
|  | import kd.bos.form.StyleCss; | ||||||
|  | import kd.bos.form.plugin.AbstractFormPlugin; | ||||||
|  | import kd.bos.logging.Log; | ||||||
|  | import kd.bos.logging.LogFactory; | ||||||
|  | import kd.bos.orm.ORM; | ||||||
|  | import kd.bos.orm.query.QFilter; | ||||||
|  | import kd.bos.servicehelper.BusinessDataServiceHelper; | ||||||
|  | import kd.bos.servicehelper.QueryServiceHelper; | ||||||
|  | import kd.bos.servicehelper.coderule.CodeRuleServiceHelper; | ||||||
|  | import kd.ec.basedata.common.enums.BillStatusEnum; | ||||||
|  | import kd.ec.basedata.common.enums.DefaultEnum; | ||||||
|  | import kd.ec.basedata.common.invoicecloud.InvoiceCloudConfigHelper; | ||||||
|  | import kd.ec.basedata.common.invoicecloud.InvoiceDataHandleHelper; | ||||||
|  | import kd.ec.basedata.common.invoicecloud.bean.InvoiceItemVO; | ||||||
|  | import kd.ec.basedata.common.invoicecloud.bean.InvoiceVO; | ||||||
|  | import kd.ec.basedata.common.invoicecloud.enumeration.InvoiceTypeEnum; | ||||||
|  | import kd.ec.basedata.common.utils.HttpURLConnectionHelper; | ||||||
|  | import kd.ec.basedata.common.utils.MD5; | ||||||
|  | import kd.ec.basedata.common.utils.TextHelper; | ||||||
|  | import net.sf.ezmorph.object.DateMorpher; | ||||||
|  | import net.sf.json.JSONArray; | ||||||
|  | import net.sf.json.JSONObject; | ||||||
|  | import net.sf.json.JsonConfig; | ||||||
|  | import net.sf.json.util.JSONUtils; | ||||||
|  | import net.sf.json.util.PropertySetStrategy; | ||||||
|  | 
 | ||||||
|  | public class CustomInvoiceDataHandleHelper extends InvoiceDataHandleHelper { | ||||||
|  |     private static final Log log = LogFactory.getLog(CustomInvoiceDataHandleHelper.class); | ||||||
|  | 
 | ||||||
|  |     private CustomInvoiceDataHandleHelper() {} | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  |     public static Map<Boolean, Set<DynamicObject>> processInvoiceVO(List<InvoiceVO> list, long userID, long orgID, Date date, String invoiceFormId, DynamicObject currency) { | ||||||
|  |         return processInvoiceVO(list, userID, orgID, date, invoiceFormId, currency, false); | ||||||
|  |     } | ||||||
|  |     //将发票对象分为两类 true新发票 false已存在发票 | ||||||
|  |     public static Map<Boolean, Set<DynamicObject>> processInvoiceVO(List<InvoiceVO> list, long userID, long orgID, Date date, String invoiceFormId, DynamicObject currency, boolean isUpdate) { | ||||||
|  |         Map<Boolean, Set<DynamicObject>> result = new HashMap(16); | ||||||
|  |         if (list != null && !list.isEmpty()) { | ||||||
|  |             log.info("根据发票ID获取数据实体类型"); | ||||||
|  |             MainEntityType dt = EntityMetadataCache.getDataEntityType(invoiceFormId);//根据发票ID获取数据实体类型 | ||||||
|  |             ORM orm = ORM.create();//用于生成新的发票ID | ||||||
|  |             long[] ids = orm.genLongIds(dt, list.size()); | ||||||
|  |             int index = 0; | ||||||
|  |             log.info("遍历发票列表"); | ||||||
|  |             for(InvoiceVO invoiceVO : list) { | ||||||
|  |                 log.info("根据 invoiceVO 和 invoiceFormId,从数据库中获取对应的发票对象。"); | ||||||
|  |                 DynamicObject invoiceFromDB = getInvoiceByVO(invoiceVO, invoiceFormId);//根据 invoiceVO 和 invoiceFormId,从数据库中获取对应的发票对象。 | ||||||
|  |                 if (invoiceFromDB != null) { | ||||||
|  |                     if (isUpdate) { | ||||||
|  |                         log.info("发票已存在,更新发票数据"); | ||||||
|  |                         updateInvoiceData(invoiceFromDB, invoiceVO);//如果发票已存在,更新发票数据 | ||||||
|  |                     } | ||||||
|  |                     //获取 Map 中键为 Boolean.FALSE 的 Set(表示已存在的发票),如果不存在则创建一个新的 HashSet | ||||||
|  |                     log.info("获取 Map 中键为 Boolean.FALSE 的 Set(表示已存在的发票),如果不存在则创建一个新的 HashSet"); | ||||||
|  |                     Set<DynamicObject> dbInvoices = (Set)result.getOrDefault(Boolean.FALSE, new HashSet(16)); | ||||||
|  |                     dbInvoices.add(invoiceFromDB);//将已存在的发票对象添加到该 Set 中 | ||||||
|  |                     result.put(Boolean.FALSE, dbInvoices);//将更新后的 Set 放回 Map 中 | ||||||
|  |                 } else { | ||||||
|  |                     //发票不存在,generateInvoiceByVO方法生成一个新的发票对象 | ||||||
|  |                     log.info("发票不存在,generateInvoiceByVO方法生成一个新的发票对象"); | ||||||
|  |                     DynamicObject newInvoice = generateInvoiceByVO(invoiceVO, dt, ids[index++], userID, orgID, date, currency); | ||||||
|  |                     Set<DynamicObject> newInvoices = (Set)result.getOrDefault(Boolean.TRUE, new HashSet(16)); | ||||||
|  |                     newInvoices.add(newInvoice);//将新生成的发票对象添加到该 Set 中 | ||||||
|  |                     result.put(Boolean.TRUE, newInvoices);//将更新后的 Set 放回 Map 中 | ||||||
|  |                 } | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         return result; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     protected static void updateInvoiceData(DynamicObject invoiceFromDB, InvoiceVO invoiceVO) { | ||||||
|  |         invoiceFromDB.set("invoicestatus", invoiceVO.getInvoiceStatus()); | ||||||
|  |     } | ||||||
|  |     //根据一个 InvoiceVO 对象生成一个 DynamicObject 类型的发票对象 | ||||||
|  |     public static DynamicObject generateInvoiceByVO(InvoiceVO invoiceVO, MainEntityType dt, long id, long userID, long orgID, Date date, DynamicObject currency) { | ||||||
|  |         DynamicObject invoice = new DynamicObject(dt); | ||||||
|  |         invoice.set("id", id);//设置发票的唯一 ID | ||||||
|  |         log.info("设置发票的唯一 ID:"+id); | ||||||
|  |         invoice.set("serialno", invoiceVO.getSerialNo());//设置发票序列号 | ||||||
|  |         log.info("设置发票序列号 serialno:"+invoiceVO.getSerialNo()); | ||||||
|  |         InvoiceTypeEnum invoiceTypeEnum = InvoiceTypeEnum.getEnumByValue(invoiceVO.getInvoiceType()); | ||||||
|  |         if (invoiceTypeEnum != null) { | ||||||
|  |             QFilter invoiceTypeFilter = new QFilter("name", "=", invoiceTypeEnum.getName()); | ||||||
|  |             DynamicObject invoiceType = BusinessDataServiceHelper.loadSingle("ec_invoice_type", "id", new QFilter[]{invoiceTypeFilter}); | ||||||
|  |             invoice.set("invoicetypeid", invoiceType);//设置发票类型 | ||||||
|  |             log.info("设置发票类型:"+invoiceType); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         invoice.set("invoicecode", invoiceVO.getInvoiceCode());//设置发票代码 | ||||||
|  |         invoice.set("invoiceno", invoiceVO.getInvoiceNo());//发票号码 | ||||||
|  |         SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); | ||||||
|  | 
 | ||||||
|  |         try { | ||||||
|  |             Date invoiceDate = format.parse(invoiceVO.getInvoiceDate()); | ||||||
|  |             invoice.set("invoicedate", invoiceDate);//设置发票日期 | ||||||
|  |         } catch (ParseException var32) { | ||||||
|  |             log.info("parse invoice date error."); | ||||||
|  |         } | ||||||
|  |         //设置发票的货币类型和各种金额字段 | ||||||
|  |         log.info("设置发票的货币类型和各种金额字段"); | ||||||
|  |         invoice.set("currency", currency);//设置币别 | ||||||
|  |         invoice.set("totaloftaxamount", invoiceVO.getTotalAmount()); | ||||||
|  |         invoice.set("unapplyamount", invoiceVO.getTotalAmount()); | ||||||
|  |         invoice.set("totaltax", invoiceVO.getTaxAmount()); | ||||||
|  |         invoice.set("unapplyinvtax", invoiceVO.getTaxAmount()); | ||||||
|  |         invoice.set("totalamount", invoiceVO.getAmount()); | ||||||
|  |         //设置购买方的税务编号、银行信息、账号、电话和地址 | ||||||
|  |         log.info("设置购买方的税务编号、银行信息、账号、电话和地址"); | ||||||
|  |         invoice.set("buyertaxno", invoiceVO.getBuyerTaxNo()); | ||||||
|  |         invoice.set("buyerbank", TextHelper.getBankName(invoiceVO.getBuyerAccount())); | ||||||
|  |         invoice.set("buyeraccount", TextHelper.getBankNum(invoiceVO.getBuyerAccount())); | ||||||
|  |         invoice.set("buyerphone", TextHelper.getPhoneNum(invoiceVO.getBuyerAddressPhone())); | ||||||
|  |         invoice.set("buyeraddress", TextHelper.getAddress(invoiceVO.getBuyerAddressPhone())); | ||||||
|  |         if (StringUtils.equals(dt.getName(), "ec_in_invoice")) { | ||||||
|  |             invoice.set("isreceived", "1"); | ||||||
|  |         } | ||||||
|  | 
 | ||||||
|  |         invoice.set("source", "03"); | ||||||
|  |         invoice.set("buyername", invoiceVO.getBuyerName()); | ||||||
|  |         //如果是进项发票,从业务单元中检索买方信息name 不是就从顾客中检索 | ||||||
|  |         log.info("发票名:"+dt.getName()); | ||||||
|  |         QFilter buyerFilter = new QFilter("ffirmname", "=", invoiceVO.getBuyerName());//原本查询的是name | ||||||
|  |         DynamicObject buyer = StringUtils.equals(dt.getName(), "ec_in_invoice") ? BusinessDataServiceHelper.loadSingle("bos_org", "", new QFilter[]{buyerFilter}) : BusinessDataServiceHelper.loadSingle("bd_customer", "", new QFilter[]{new QFilter("name", "=", invoiceVO.getBuyerName())}); | ||||||
|  |         if (buyer == null) { | ||||||
|  |             throw new KDBizException(String.format(ResManager.loadKDString("发票【%1$s】:购买方【%2$s】不存在。", "InvoiceDataHandleHelper_5", "ec-ecbd-common", new Object[0]), invoiceVO.getInvoiceCode(), invoiceVO.getBuyerName())); | ||||||
|  |         } else { | ||||||
|  |             invoice.set("buyer", buyer); | ||||||
|  |             invoice.set("sellertaxno", invoiceVO.getSalerTaxNo()); | ||||||
|  |             invoice.set("sellerbank", TextHelper.getBankName(invoiceVO.getSalerAccount())); | ||||||
|  |             invoice.set("selleraccount", TextHelper.getBankNum(invoiceVO.getSalerAccount())); | ||||||
|  |             invoice.set("sellerphone", TextHelper.getPhoneNum(invoiceVO.getSalerAddressPhone())); | ||||||
|  |             invoice.set("selleraddress", TextHelper.getAddress(invoiceVO.getSalerAddressPhone())); | ||||||
|  |             String sellerName = invoiceVO.getSalerName(); | ||||||
|  |             invoice.set("sellername", sellerName); | ||||||
|  |             QFilter sellerFilter = new QFilter("name", "=", sellerName); | ||||||
|  |             if (!sellerName.contains("(") && !sellerName.contains(")")) { | ||||||
|  |                 if (sellerName.contains("(") || sellerName.contains(")")) { | ||||||
|  |                     sellerName.replace('(', '('); | ||||||
|  |                     sellerName.replace(')', ')'); | ||||||
|  |                     sellerFilter.or("name", "=", sellerName); | ||||||
|  |                 } | ||||||
|  |             } else { | ||||||
|  |                 sellerName.replace('(', '('); | ||||||
|  |                 sellerName.replace(')', ')'); | ||||||
|  |                 sellerFilter.or("name", "=", sellerName); | ||||||
|  |             } | ||||||
|  | 
 | ||||||
|  |             DynamicObject seller = StringUtils.equals(dt.getName(), "ec_in_invoice") ? BusinessDataServiceHelper.loadSingle("bd_supplier", "", new QFilter[]{sellerFilter}) : BusinessDataServiceHelper.loadSingle("bos_org", "", new QFilter[]{sellerFilter}); | ||||||
|  |             if (seller == null) { | ||||||
|  |                 throw new KDBizException(String.format(ResManager.loadKDString("发票【%1$s】:销售方【%2$s】不存在。", "InvoiceDataHandleHelper_6", "ec-ecbd-common", new Object[0]), invoiceVO.getInvoiceCode(), sellerName)); | ||||||
|  |             } else { | ||||||
|  |                 invoice.set("seller", seller); | ||||||
|  |                 invoice.set("invoicestatus", invoiceVO.getInvoiceStatus()); | ||||||
|  |                 invoice.set("billstatus", BillStatusEnum.AUDIT.getValue()); | ||||||
|  |                 invoice.set("org_id", orgID); | ||||||
|  |                 List<InvoiceItemVO> detailEntries = invoiceVO.getItems(); | ||||||
|  |                 if (detailEntries != null && !detailEntries.isEmpty()) { | ||||||
|  |                     DynamicObjectCollection invoiceEntries = invoice.getDynamicObjectCollection("entryentity"); | ||||||
|  |                     DynamicObjectType entryDt = (new DynamicObject(dt)).getDynamicObjectCollection("entryentity").getDynamicObjectType(); | ||||||
|  | 
 | ||||||
|  |                     for(InvoiceItemVO item : detailEntries) { | ||||||
|  |                         DynamicObject entry = new DynamicObject(entryDt); | ||||||
|  |                         entry.set("name", item.getGoodsName()); | ||||||
|  |                         entry.set("model", item.getSpecModel()); | ||||||
|  |                         String unitName = item.getUnit(); | ||||||
|  |                         if (unitName != null && !unitName.isEmpty()) { | ||||||
|  |                             QFilter unitFilter = (new QFilter("name", "=", unitName)).or("number", "=", unitName).or("number", "=", unitName.toLowerCase()).or("number", "=", unitName.toUpperCase()); | ||||||
|  |                             QFilter validFilter = (new QFilter("enable", "=", DefaultEnum.YES.getValue().charAt(0))).and("status", "=", BillStatusEnum.AUDIT.getValue().charAt(0)); | ||||||
|  |                             DynamicObject unit = BusinessDataServiceHelper.loadSingle("bd_measureunits", "name", new QFilter[]{unitFilter, validFilter}); | ||||||
|  |                             if (unit != null) { | ||||||
|  |                                 entry.set("unit", unit); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         entry.set("qty", item.getNum()); | ||||||
|  |                         BigDecimal price = item.getUnitPrice(); | ||||||
|  |                         entry.set("price", item.getUnitPrice()); | ||||||
|  |                         entry.set("amount", item.getDetailAmount()); | ||||||
|  |                         BigDecimal ofTaxPrice = price; | ||||||
|  |                         BigDecimal tax = item.getTaxRate(); | ||||||
|  |                         if (tax != null) { | ||||||
|  |                             BigDecimal taxRateHundred = tax.multiply(BigDecimal.TEN.multiply(BigDecimal.TEN)); | ||||||
|  |                             QFilter taxFilter = new QFilter("taxrate", "=", taxRateHundred); | ||||||
|  |                             DynamicObject[] taxRate = BusinessDataServiceHelper.load("bd_taxrate", "name", new QFilter[]{taxFilter}); | ||||||
|  |                             if (taxRate != null && taxRate.length > 0) { | ||||||
|  |                                 entry.set("taxrate", taxRate[0]); | ||||||
|  |                             } | ||||||
|  | 
 | ||||||
|  |                             if (price != null) { | ||||||
|  |                                 ofTaxPrice = price.multiply(BigDecimal.ONE.add(tax)); | ||||||
|  |                             } | ||||||
|  |                         } | ||||||
|  | 
 | ||||||
|  |                         entry.set("oftaxprice", ofTaxPrice); | ||||||
|  |                         entry.set("tax", item.getTaxAmount()); | ||||||
|  |                         entry.set("oftaxamount", item.getDetailAmount().add(item.getTaxAmount() == null ? BigDecimal.ZERO : item.getTaxAmount())); | ||||||
|  |                         invoiceEntries.add(entry); | ||||||
|  |                     } | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 String snapshotUrl = invoiceVO.getSnapshotUrl(); | ||||||
|  |                 if (!StringUtils.isBlank(snapshotUrl)) { | ||||||
|  |                     DynamicObjectCollection pictureEntries = invoice.getDynamicObjectCollection("pictureentry"); | ||||||
|  |                     DynamicObjectType pictureEntryDt = (new DynamicObject(dt)).getDynamicObjectCollection("pictureentry").getDynamicObjectType(); | ||||||
|  |                     DynamicObject item = new DynamicObject(pictureEntryDt); | ||||||
|  |                     item.set("filename", invoiceVO.getInvoiceNo()); | ||||||
|  |                     item.set("imageurl", snapshotUrl); | ||||||
|  |                     item.set("uploaddate", date); | ||||||
|  |                     pictureEntries.add(item); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 invoice.set("creator_id", userID); | ||||||
|  |                 invoice.set("modifier_id", userID); | ||||||
|  |                 invoice.set("auditor_id", userID); | ||||||
|  |                 invoice.set("createtime", date); | ||||||
|  |                 invoice.set("modifytime", date); | ||||||
|  |                 invoice.set("auditdate", date); | ||||||
|  |                 CodeRuleInfo codeRuleInfo = CodeRuleServiceHelper.getCodeRule(dt.getName(), invoice, String.valueOf(RequestContext.get().getOrgId())); | ||||||
|  |                 if (null != codeRuleInfo) { | ||||||
|  |                     invoice.set("billno", CodeRuleServiceHelper.getNumber(codeRuleInfo, invoice)); | ||||||
|  |                 } else { | ||||||
|  |                     invoice.set("billno", invoiceVO.getSerialNo()); | ||||||
|  |                 } | ||||||
|  | 
 | ||||||
|  |                 return invoice; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     public static DynamicObject getInvoiceByVO(InvoiceVO invoiceVO, String invoiceFormId) { | ||||||
|  |         if (invoiceVO != null && !StringUtils.isBlank(invoiceFormId)) { | ||||||
|  |             QFilter filter = new QFilter("serialno", "=", invoiceVO.getSerialNo()); | ||||||
|  |             List<Object> primaryKeys = QueryServiceHelper.queryPrimaryKeys(invoiceFormId, new QFilter[]{filter}, (String)null, 1); | ||||||
|  |             return primaryKeys != null && !primaryKeys.isEmpty() ? BusinessDataServiceHelper.loadSingle(primaryKeys.get(0), invoiceFormId) : null; | ||||||
|  |         } else { | ||||||
|  |             return null; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
		Loading…
	
		Reference in New Issue