Ver Fonte

采购发票保存校验

yaoyu há 2 anos atrás
pai
commit
3345915e15
1 ficheiros alterados com 97 adições e 42 exclusões
  1. 97 42
      pu/pu/src/private/nc/bs/ic/base/InvoiceAfterCheckEvent.java

+ 97 - 42
pu/pu/src/private/nc/bs/ic/base/InvoiceAfterCheckEvent.java

@@ -1,6 +1,5 @@
 package nc.bs.ic.base;
 
-import java.math.BigDecimal;
 import java.util.List;
 import java.util.Map;
 
@@ -9,18 +8,30 @@ import nc.bs.businessevent.IBusinessListener;
 import nc.bs.framework.common.NCLocator;
 import nc.bs.pu.event.PUBusinessEvent;
 import nc.itf.uap.IUAPQueryBS;
+import nc.jdbc.framework.processor.ColumnProcessor;
 import nc.jdbc.framework.processor.MapListProcessor;
+import nc.md.persist.framework.IMDPersistenceQueryService;
+import nc.vo.bd.defdoc.DefdocVO;
 import nc.vo.pu.m25.entity.InvoiceItemVO;
 import nc.vo.pu.m25.entity.InvoiceVO;
 import nc.vo.pub.BusinessException;
-import nc.vo.pub.lang.UFDateTime;
+import nc.vo.pub.lang.UFDate;
 import nc.vo.pub.lang.UFDouble;
 import nc.vo.pubapp.pattern.exception.ExceptionUtils;
 
+
+/**
+ * 采购发票保存后校验
+ * @author yaoy
+ * 2023-05-25
+ *
+ */
 public class InvoiceAfterCheckEvent implements IBusinessListener{
 	
 	
-	IUAPQueryBS bs = NCLocator.getInstance().lookup(IUAPQueryBS.class);
+	private IUAPQueryBS bs = NCLocator.getInstance().lookup(IUAPQueryBS.class);
+	private IMDPersistenceQueryService service = NCLocator.getInstance().lookup(IMDPersistenceQueryService.class);
+
 
 
 	@Override
@@ -33,55 +44,99 @@ public class InvoiceAfterCheckEvent implements IBusinessListener{
 			}
 			if (obj instanceof InvoiceVO[]) {
 				InvoiceVO InvoiceVO = (InvoiceVO) obj[0];
-				InvoiceItemVO[] invoiceItemListVO = (InvoiceItemVO[]) InvoiceVO.getChildren(InvoiceItemVO.class);
-				UFDateTime date = new UFDateTime(System.currentTimeMillis());
-				UFDateTime date2 = new UFDateTime("2023-01-01 00:00:01");
-				//当年只能报销当年的控制
-				if(date.getYear() != date2.getYear()) {
-					ExceptionUtils.wrappBusinessException("不能跨年报销发票!");
-				}
+				InvoiceItemVO[] arrInvoiceItemVO = (InvoiceItemVO[]) InvoiceVO.getChildren(InvoiceItemVO.class);
 				//参照上游单据的信息和发票信息一致性校验(抬头、税率)
 				//发票金额不可超过采购合同/订单金额
 				//购买方发票抬头、税号准确性
 				//来源单据类型
-				String csourcetypecode = invoiceItemListVO[0].getCsourcetypecode();
+				String csourcetypecode = arrInvoiceItemVO[0].getCsourcetypecode();
 				//来源单据主键
-				String csourceid = invoiceItemListVO[0].getCsourceid();
+				String csourceid = arrInvoiceItemVO[0].getCsourceid();
+				
+				List<Map<Object, Object>> listMap = null;
 				//来源单据是采购订单
+				
 				if("21".equals(csourcetypecode)) {
-					String sql = "select po_order_b.pk_order_b,po_order_b.norigtaxmny,po_order_b.ntaxrate from po_order po_order" + 
-							" left join po_order_b po_order_b on po_order_b.pk_order = po_order.pk_order" + 
-							" where po_order.pk_order='"+csourceid+"'";
-					 List<Map<Object, Object>> listMap = (List<Map<Object, Object>>) bs.executeQuery(sql, new MapListProcessor());                
-					 for (InvoiceItemVO invoiceItemVO : invoiceItemListVO) { 
-						 for (Map<Object, Object> map : listMap) { 
-							 if (invoiceItemVO.getCsourcebid().equals(map.get("pk_order_b"))) { 
-								 UFDouble norigtaxmny1 = invoiceItemVO.getNorigtaxmny();
-								 UFDouble norigtaxmny2 = new UFDouble(map.get("norigtaxmny").toString());
-								 //比较价税合计							 
-								 if(norigtaxmny1.compareTo(norigtaxmny2) == 1) {
-									 ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"不可超过采购订单价税合计金额!");
-								 }
-								 //比较税率
-								 UFDouble ntaxrate1 = invoiceItemVO.getNtaxrate();
-								 UFDouble ntaxrate2 = new UFDouble(map.get("ntaxrate").toString());
-								 if(ntaxrate1.compareTo(ntaxrate2) != 0) {
-									 ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"与采购订单税率不同!");
-								 }
-								 //比较抬头
-								 
-								 //比较纳税人识别号
-								 break;
-							 }
-						 }
-					 }
+					StringBuffer sql = new StringBuffer();
+					sql.append("SELECT");
+					sql.append(" po_order_b.pk_order_b,");
+					sql.append(" po_order_b.norigtaxmny,");
+					sql.append(" po_order_b.ntaxrate ");
+					sql.append(" FROM");
+					sql.append(" po_order po_order");
+					sql.append(" LEFT JOIN po_order_b po_order_b ON po_order.pk_order = po_order_b.pk_order");
+					sql.append(" WHERE");
+					sql.append(" po_order.pk_order = '"+csourceid+"'");
+					listMap = (List<Map<Object, Object>>) bs.executeQuery(sql.toString(), new MapListProcessor());                
 				}
 				
 				//来源单据是入库单
-				
-				String str = null;
-				System.out.println(str.toString());
-				
+				if("45".equals(csourcetypecode)) {
+					StringBuffer sql = new StringBuffer();
+					sql.append("SELECT");
+					sql.append(" ic_purchasein_b.cgeneralbid,");
+					sql.append(" po_order_b.pk_order_b,");
+					sql.append(" po_order_b.norigtaxmny,");
+					sql.append(" po_order_b.ntaxrate");
+					sql.append(" FROM");
+					sql.append(" ic_purchasein_h ic_purchasein_h");
+					sql.append(" LEFT JOIN ic_purchasein_b ic_purchasein_b ON ic_purchasein_h.cgeneralhid = ic_purchasein_b.cgeneralhid");
+					sql.append(" LEFT JOIN po_order_b po_order_b ON ic_purchasein_b.csourcebillbid = po_order_b.pk_order_b");
+					sql.append(" WHERE");
+					sql.append(" ic_purchasein_h.cgeneralhid = '"+csourceid+"'");
+					listMap = (List<Map<Object, Object>>) bs.executeQuery(sql.toString(), new MapListProcessor());
+				}
+				for (InvoiceItemVO invoiceItemVO : arrInvoiceItemVO) {
+					invoiceItemVO.setVbdef20("1001ZZ1000000097E319,1001ZZ10000000979E29");
+					String[] arrVbdef20 = invoiceItemVO.getVbdef20().split(",");
+					for(String Vbdef20 : arrVbdef20) {
+						DefdocVO defdocVO = (DefdocVO) service.queryBillOfNCObjectByPKWithDR(DefdocVO.class, Vbdef20, true).getContainmentObject();
+						UFDate date = new UFDate(System.currentTimeMillis());
+						UFDate date2 = new UFDate(defdocVO.getShortname4());
+						//当年只能报销当年的控制
+						if(date.getYear() != date2.getYear()) {
+							ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"不能跨年报销发票!");
+						}
+						//比较抬头
+						String sql1 = "select name from org_financeorg_v where pk_vid ='"+InvoiceVO.getParent().getAttributeValue("pk_org_v")+"'";
+						String orgname = (String) bs.executeQuery(sql1, new ColumnProcessor());
+						if(!orgname.equals(defdocVO.getName2())) {
+							ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"发票抬头不正确!");
+						}
+						//比较纳税人识别号
+						StringBuffer sql2 = new StringBuffer();
+						sql2.append("SELECT");
+						sql2.append(" name");
+						sql2.append(" FROM");
+						sql2.append(" bd_defdoc ");
+						sql2.append(" WHERE");
+						sql2.append(" pk_defdoclist = ( SELECT pk_defdoclist FROM bd_defdoclist WHERE code = 'CORPYS04' ) ");
+						sql2.append(" AND memo = '"+orgname+"' ");
+						sql2.append(" AND enablestate = 2");
+						String tcode = (String) bs.executeQuery(sql2.toString(), new ColumnProcessor());
+						if(!tcode.equals(defdocVO.getMnecode())) {
+							ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"纳税人识别号不正确!");
+						}
+						for (Map<Object, Object> map : listMap) { 
+							//来源可能是采购订单,采购入库单
+							if (invoiceItemVO.getCsourcebid().equals(map.get("pk_order_b")) || invoiceItemVO.getCsourcebid().equals(map.get("cgeneralbid"))) { 
+								UFDouble norigtaxmny1 = invoiceItemVO.getNorigtaxmny();
+								UFDouble norigtaxmny2 = new UFDouble(map.get("norigtaxmny").toString());
+								 //比较价税合计							 
+								if(norigtaxmny1.compareTo(norigtaxmny2) == 1) {
+									ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"不可超过采购订单价税合计金额!");
+								}
+								 //比较税率
+								UFDouble ntaxrate1 = invoiceItemVO.getNtaxrate();
+								UFDouble ntaxrate2 = new UFDouble(map.get("ntaxrate").toString());
+								if(ntaxrate1.compareTo(ntaxrate2) != 0) {
+									ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"与采购订单税率不同!");
+								}
+								break;
+							}
+						}
+					}
+				 }
 			}
 		}
 	}