Kaynağa Gözat

保存从行金额校验改成行合计金额校验

yaoyu 1 yıl önce
ebeveyn
işleme
f899856288

+ 82 - 52
pu/pu/src/private/nc/bs/ic/base/InvoiceAfterCheckEvent.java

@@ -55,7 +55,9 @@ public class InvoiceAfterCheckEvent implements IRule<InvoiceVO>{
 					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(" po_order_b.ntaxrate,");
+					sql.append(" po_order_b.nmny,");
+					sql.append(" po_order_b.ntax");
 					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");
@@ -70,7 +72,9 @@ public class InvoiceAfterCheckEvent implements IRule<InvoiceVO>{
 					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(" po_order_b.ntaxrate,");
+					sql.append(" po_order_b.nmny,");
+					sql.append(" po_order_b.ntax");
 					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");
@@ -79,49 +83,55 @@ public class InvoiceAfterCheckEvent implements IRule<InvoiceVO>{
 					sql.append(" ic_purchasein_h.cgeneralhid = '"+csourceid+"'");
 					listMap = (List<Map<Object, Object>>) bs.executeQuery(sql.toString(), new MapListProcessor());
 				}
-//				else {
-//					//只有来源是采购订单或者采购入库单的才进行保存校验
-//					return;
-//				}
-					for (InvoiceItemVO invoiceItemVO : arrInvoiceItemVO) {
-					//没传发票不比较日期、抬头、纳税人识别号
-					if(invoiceItemVO.getVbdef20() != null && !"".equals(invoiceItemVO.getVbdef20())) {
-						String[] arrVbdef20 = invoiceItemVO.getVbdef20().split(",");
-						for(String Vbdef20 : arrVbdef20) {
-							DefdocVO defdocVO = (DefdocVO) service.queryBillOfNCObjectByPKWithDR(DefdocVO.class, Vbdef20, true).getContainmentObject();
-							if(defdocVO.getPid() != null) {
-								UFDate date = new UFDate(System.currentTimeMillis());
-								UFDate date2 = new UFDate(defdocVO.getPid());
-								//当年只能报销当年的控制
-								if(date.getYear() != date2.getYear()) {
-									ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"不能跨年报销发票!");
-								}
-							}
-							//特殊发票不存在抬头与纳税人识别号可不做校验
-							if(defdocVO.getName2() != null && !"".equals(defdocVO.getName2())) {
-								//比较抬头
-								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(!defdocVO.getMnecode().equals(tcode)) {
-									ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"纳税人识别号不正确!请检查自定义档案是否维护正确!");
-								}
-							}
-						}
-					}
+				//金额
+				UFDouble nmny1 = new UFDouble();
+				UFDouble nmny2 = new UFDouble();
+				//税额
+				UFDouble ntax1 = new UFDouble();
+				UFDouble ntax2 = new UFDouble();
+				//价税合计
+				UFDouble norigtaxmny1 = new UFDouble();
+				UFDouble norigtaxmny2 = new UFDouble();
+					
+				for (InvoiceItemVO invoiceItemVO : arrInvoiceItemVO) {
+				//没传发票不比较日期、抬头、纳税人识别号
+//					if(invoiceItemVO.getVbdef20() != null && !"".equals(invoiceItemVO.getVbdef20())) {
+//						String[] arrVbdef20 = invoiceItemVO.getVbdef20().split(",");
+//						for(String Vbdef20 : arrVbdef20) {
+//							DefdocVO defdocVO = (DefdocVO) service.queryBillOfNCObjectByPKWithDR(DefdocVO.class, Vbdef20, true).getContainmentObject();
+//							if(defdocVO.getPid() != null) {
+//								UFDate date = new UFDate(System.currentTimeMillis());
+//								UFDate date2 = new UFDate(defdocVO.getPid());
+//								//当年只能报销当年的控制
+//								if(date.getYear() != date2.getYear()) {
+//									ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"不能跨年报销发票!");
+//								}
+//							}
+//							//特殊发票不存在抬头与纳税人识别号可不做校验
+//							if(defdocVO.getName2() != null && !"".equals(defdocVO.getName2())) {
+//								//比较抬头
+//								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(!defdocVO.getMnecode().equals(tcode)) {
+//									ExceptionUtils.wrappBusinessException("行:"+invoiceItemVO.getCrowno()+"纳税人识别号不正确!请检查自定义档案是否维护正确!");
+//								}
+//							}
+//						}
+//					}
 					for (Map<Object, Object> map : listMap) {//
 						//自增没有来源不比较
 						if(invoiceItemVO.getCsourcebid() == null) {
@@ -129,22 +139,42 @@ public class InvoiceAfterCheckEvent implements IRule<InvoiceVO>{
 						}
 						//来源可能是采购订单,采购入库单
 						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 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;
+							
+							 norigtaxmny1 = norigtaxmny1.add(invoiceItemVO.getNorigtaxmny());
+							 norigtaxmny2 = norigtaxmny2.add(new UFDouble(map.get("norigtaxmny").toString()));
+							 
+							 nmny1 = nmny1.add(invoiceItemVO.getNmny());
+							 nmny2 = nmny2.add(new UFDouble(map.get("nmny").toString()));
+							 
+							 ntax1 = ntax1.add(invoiceItemVO.getNtax());
+							 ntax2 = ntax2.add(new UFDouble(map.get("ntax").toString()));
 						}
 					}
 				}
+				//比较金额
+				if(nmny1.compareTo(nmny2) == 1) {
+					ExceptionUtils.wrappBusinessException("不可超过采购订单金额!");
+				}
+				//比较税额
+				if(ntax1.compareTo(ntax2) == 1) {
+					ExceptionUtils.wrappBusinessException("不可超过采购订单税额!");
+				}
+				//比较价税合计							 
+				if(norigtaxmny1.compareTo(norigtaxmny2) == 1) {
+					ExceptionUtils.wrappBusinessException("不可超过采购订单价税合计金额!");
+				}
 			}
 			
 		} catch (Exception e) {