|
@@ -1,5 +1,6 @@
|
|
|
package nc.bs.ic.base;
|
|
|
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -14,7 +15,6 @@ 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.UFDate;
|
|
|
import nc.vo.pub.lang.UFDouble;
|
|
|
import nc.vo.pubapp.pattern.exception.ExceptionUtils;
|
|
@@ -35,87 +35,90 @@ public class InvoiceAfterCheckEvent implements IBusinessListener{
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void doAction(IBusinessEvent event) throws BusinessException {
|
|
|
- if (event instanceof PUBusinessEvent) {
|
|
|
- PUBusinessEvent busiEvent = (PUBusinessEvent)event;
|
|
|
- Object[] obj = busiEvent.getObjs();
|
|
|
- if (obj == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (obj instanceof InvoiceVO[]) {
|
|
|
- InvoiceVO InvoiceVO = (InvoiceVO) obj[0];
|
|
|
- InvoiceItemVO[] arrInvoiceItemVO = (InvoiceItemVO[]) InvoiceVO.getChildren(InvoiceItemVO.class);
|
|
|
- //参照上游单据的信息和发票信息一致性校验(抬头、税率)
|
|
|
- //发票金额不可超过采购合同/订单金额
|
|
|
- //购买方发票抬头、税号准确性
|
|
|
- //来源单据类型
|
|
|
- String csourcetypecode = arrInvoiceItemVO[0].getCsourcetypecode();
|
|
|
- //来源单据主键
|
|
|
- String csourceid = arrInvoiceItemVO[0].getCsourceid();
|
|
|
-
|
|
|
- List<Map<Object, Object>> listMap = null;
|
|
|
- //来源单据是采购订单
|
|
|
-
|
|
|
- if("21".equals(csourcetypecode)) {
|
|
|
- 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());
|
|
|
+ public void doAction(IBusinessEvent event){
|
|
|
+ try {
|
|
|
+ if (event instanceof PUBusinessEvent) {
|
|
|
+ PUBusinessEvent busiEvent = (PUBusinessEvent)event;
|
|
|
+ Object[] obj = busiEvent.getObjs();
|
|
|
+ if (obj == null) {
|
|
|
+ return;
|
|
|
}
|
|
|
|
|
|
- //来源单据是入库单
|
|
|
- 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()+"纳税人识别号不正确!");
|
|
|
+ if (obj instanceof InvoiceVO[]) {
|
|
|
+ InvoiceVO InvoiceVO = (InvoiceVO) obj[0];
|
|
|
+ InvoiceItemVO[] arrInvoiceItemVO = (InvoiceItemVO[]) InvoiceVO.getChildren(InvoiceItemVO.class);
|
|
|
+ //参照上游单据的信息和发票信息一致性校验(抬头、税率)
|
|
|
+ //发票金额不可超过采购合同/订单金额
|
|
|
+ //购买方发票抬头、税号准确性
|
|
|
+ //来源单据类型
|
|
|
+ String csourcetypecode = arrInvoiceItemVO[0].getCsourcetypecode();
|
|
|
+ //来源单据主键
|
|
|
+ String csourceid = arrInvoiceItemVO[0].getCsourceid();
|
|
|
+
|
|
|
+ List<Map<Object, Object>> listMap = new ArrayList<Map<Object, Object>>();
|
|
|
+ //来源单据是采购订单
|
|
|
+ if("21".equals(csourcetypecode)) {
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ //来源单据是入库单
|
|
|
+ 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) {
|
|
|
+ //没传发票不比较日期、抬头、纳税人识别号
|
|
|
+ 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();
|
|
|
+ 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) {
|
|
|
//来源可能是采购订单,采购入库单
|
|
@@ -136,8 +139,10 @@ public class InvoiceAfterCheckEvent implements IBusinessListener{
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
}
|
|
|
+ } catch (Exception e) {
|
|
|
+ ExceptionUtils.wrappBusinessException(""+e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
}
|