|
@@ -0,0 +1,236 @@
|
|
|
|
+package nc.impl.th;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.io.PrintWriter;
|
|
|
|
+import java.io.StringWriter;
|
|
|
|
+
|
|
|
|
+import javax.servlet.ServletException;
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
|
+
|
|
|
|
+import nc.bs.framework.adaptor.IHttpServletAdaptor;
|
|
|
|
+import nc.bs.framework.common.InvocationInfoProxy;
|
|
|
|
+import nc.bs.framework.common.NCLocator;
|
|
|
|
+import nc.bs.framework.server.ISecurityTokenCallback;
|
|
|
|
+import nc.bs.servlet.service.BaseServlet;
|
|
|
|
+import nc.itf.pu.m25.IInvoiceMaintain;
|
|
|
|
+import nc.itf.uap.IUAPQueryBS;
|
|
|
|
+import nc.jdbc.framework.processor.ColumnProcessor;
|
|
|
|
+import nc.vo.pu.m25.entity.InvoiceHeaderVO;
|
|
|
|
+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.UFDateTime;
|
|
|
|
+import nc.vo.pub.lang.UFDouble;
|
|
|
|
+import net.sf.json.JSONArray;
|
|
|
|
+import net.sf.json.JSONObject;
|
|
|
|
+
|
|
|
|
+public class InvoiceAddImpl extends BaseServlet implements IHttpServletAdaptor {
|
|
|
|
+ IUAPQueryBS iuap = (IUAPQueryBS) NCLocator.getInstance().lookup(IUAPQueryBS.class.getName());
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void doAction(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {
|
|
|
|
+ try {
|
|
|
|
+ InvocationInfoProxy.getInstance().setUserDataSource("NC20230301");
|
|
|
|
+ NCLocator.getInstance().lookup(ISecurityTokenCallback.class).token("NCSystem".getBytes(),"pfxx".getBytes());
|
|
|
|
+ String createStr = buildJson(req, resp, this.getClass().getName());
|
|
|
|
+ JSONObject json = JSONObject.fromObject(createStr);
|
|
|
|
+ String vbillcode = "";
|
|
|
|
+ vbillcode = json.getString("vbillcode");
|
|
|
|
+ checkJson(json);
|
|
|
|
+ InvocationInfoProxy.getInstance().setGroupId(SqlexecuteQuery("pk_group", "org_group", "code", "00"));
|
|
|
|
+ InvocationInfoProxy.getInstance().setUserId(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("billmaker")));
|
|
|
|
+ PrintWriter out = resp.getWriter();
|
|
|
|
+ InvoiceVO[] aggvos = new InvoiceVO[1];
|
|
|
|
+ InvoiceVO aggvo = new InvoiceVO();
|
|
|
|
+ aggvos[0] = aggvo;
|
|
|
|
+
|
|
|
|
+ InvoiceHeaderVO parentVO=new InvoiceHeaderVO();
|
|
|
|
+
|
|
|
|
+ InvoiceItemVO[] childrenVO = new InvoiceItemVO[json.getJSONArray("childrenVO").size()];
|
|
|
|
+
|
|
|
|
+ parentVO.setPk_group(SqlexecuteQuery("pk_group", "org_group", "code", "00"));
|
|
|
|
+ parentVO.setPk_org(json.getString("pk_org"));
|
|
|
|
+ parentVO.setPk_org_v(SqlexecuteQuery2("pk_vid", "org_stockorg_v", "pk_stockorg", json.getString("pk_org")));
|
|
|
|
+ parentVO.setCreator(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("billmaker")));
|
|
|
|
+ parentVO.setCreationtime(new UFDateTime(json.getString("dbilldate")));
|
|
|
|
+ parentVO.setBillmaker(SqlexecuteQuery("cuserid", "sm_user", "user_code", json.getString("billmaker")));
|
|
|
|
+ parentVO.setDmakedate(new UFDate(json.getString("dbilldate")));
|
|
|
|
+ parentVO.setVtrantypecode(json.getString("vtrantypecode"));
|
|
|
|
+ parentVO.setCtrantypeid(SqlexecuteQuery("pk_billtypeid", "bd_billtype", "pk_billtypecode", json.getString("ctrantypeid")));
|
|
|
|
+ parentVO.setFinvoiceclass(json.getInt("finvoiceclass"));
|
|
|
|
+ parentVO.setVbillcode(vbillcode);
|
|
|
|
+ parentVO.setDbilldate(new UFDate(json.getString("dbilldate")));
|
|
|
|
+ parentVO.setPk_supplier(SqlexecuteQuery("pk_supplier", "bd_supplier", "code", json.getString("pk_supplier")));
|
|
|
|
+ parentVO.setPk_bankaccbas(SqlexecuteQuery("pk_bankaccsub", "bd_bankaccsub", "accnum", json.getString("pk_bankaccbas")));
|
|
|
|
+ parentVO.setPk_bizpsn(SqlexecuteQuery("pk_psndoc", "bd_psndoc", "code", json.getString("pk_bizpsn")));
|
|
|
|
+ parentVO.setPk_dept_v(SqlexecuteQuery("pk_vid", "org_dept_v", "code", json.getString("pk_dept_v")));
|
|
|
|
+ parentVO.setPk_busitype(SqlexecuteQuery("pk_busitype", "bd_busitype", "busicode", json.getString("pk_busitype")));
|
|
|
|
+ parentVO.setPk_stockorg_v(SqlexecuteQuery("pk_vid", "org_stockorg_v", "code", json.getString("pk_stockorg_v")));
|
|
|
|
+ parentVO.setPk_paytosupplier(SqlexecuteQuery("pk_supplier", "bd_supplier", "code", json.getString("pk_paytosupplier")));
|
|
|
|
+ parentVO.setNtotalastnum(new UFDouble(json.getString("ntotalastnum")));
|
|
|
|
+ parentVO.setNtotalorigmny(new UFDouble(json.getString("ntotalorigmny")));
|
|
|
|
+ parentVO.setFtaxtypeflagh(0);
|
|
|
|
+ parentVO.setVmemo(json.getString("vmemo"));
|
|
|
|
+ parentVO.setDarrivedate(new UFDate(json.getString("darrivedate")));
|
|
|
|
+ parentVO.setCcurrencyid(SqlexecuteQuery("pk_currtype", "bd_currtype", "code", json.getString("ccurrencyid")));
|
|
|
|
+ parentVO.setCorigcurrencyid(SqlexecuteQuery("pk_currtype", "bd_currtype", "code", json.getString("corigcurrencyid")));
|
|
|
|
+ parentVO.setNexchangerate(new UFDouble(json.getString("nexchangerate")));
|
|
|
|
+ parentVO.setCrececountryid(SqlexecuteQuery("pk_country", "bd_countryzone", "code","CN"));
|
|
|
|
+ parentVO.setCsendcountryid(SqlexecuteQuery("pk_country", "bd_countryzone", "code","CN"));
|
|
|
|
+ parentVO.setCtaxcountryid(SqlexecuteQuery("pk_country", "bd_countryzone", "code","CN"));
|
|
|
|
+ parentVO.setFbuysellflag(2);
|
|
|
|
+ parentVO.setVdef18(json.getString("vdef18"));
|
|
|
|
+
|
|
|
|
+ aggvo.setParentVO(parentVO);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JSONArray bodyArray = json.getJSONArray("childrenVO");
|
|
|
|
+ int i=0;
|
|
|
|
+ for (Object Object : bodyArray) {
|
|
|
|
+ JSONObject bodyObject = JSONObject.fromObject(Object);
|
|
|
|
+ InvoiceItemVO invoiceItemVO = new InvoiceItemVO();
|
|
|
|
+ invoiceItemVO.setPk_group(SqlexecuteQuery("pk_group", "org_group", "code", "00"));
|
|
|
|
+ invoiceItemVO.setPk_org(json.getString("pk_org"));
|
|
|
|
+ invoiceItemVO.setPk_org_v(SqlexecuteQuery2("pk_vid", "org_stockorg_v", "pk_stockorg", json.getString("pk_org")));
|
|
|
|
+ invoiceItemVO.setDbilldate(new UFDate(json.getString("dbilldate")));
|
|
|
|
+ invoiceItemVO.setCrowno(bodyObject.getString("crowno"));
|
|
|
|
+ invoiceItemVO.setVbdef13(bodyObject.getString("vbdef13"));
|
|
|
|
+ invoiceItemVO.setVbdef11(bodyObject.getString("vbdef11"));
|
|
|
|
+ invoiceItemVO.setVbdef12(vbillcode);
|
|
|
|
+ invoiceItemVO.setPk_material(SqlexecuteQuery("pk_material", "bd_material", "code", bodyObject.getString("pk_material")));
|
|
|
|
+ invoiceItemVO.setPk_srcmaterial(SqlexecuteQuery("pk_source", "bd_material_v", "code", bodyObject.getString("pk_srcmaterial")));
|
|
|
|
+ invoiceItemVO.setCtaxcodeid(SqlexecuteQuery("pk_taxcode", "bd_taxcode", "code", bodyObject.getString("ctaxcodeid")));
|
|
|
|
+ invoiceItemVO.setNtaxrate(new UFDouble(bodyObject.getString("ntaxrate")));
|
|
|
|
+ invoiceItemVO.setNastorigprice(new UFDouble(bodyObject.getString("nastorigprice")));
|
|
|
|
+ invoiceItemVO.setNorigmny(new UFDouble(bodyObject.getString("norigmny")));
|
|
|
|
+ invoiceItemVO.setNtax(new UFDouble(bodyObject.getString("ntax")));
|
|
|
|
+ invoiceItemVO.setNastorigtaxprice(new UFDouble(bodyObject.getString("nastorigtaxprice")));
|
|
|
|
+ invoiceItemVO.setNorigtaxmny(new UFDouble(bodyObject.getString("norigtaxmny")));
|
|
|
|
+ invoiceItemVO.setVbdef17(json.getString("finvoiceclass"));
|
|
|
|
+ invoiceItemVO.setVbdef15(bodyObject.getString("vbdef15"));
|
|
|
|
+ invoiceItemVO.setVbdef14(bodyObject.getString("vbdef14"));
|
|
|
|
+ invoiceItemVO.setPk_apfinanceorg_v(SqlexecuteQuery("pk_vid", "org_financeorg_v", "code", bodyObject.getString("pk_apfinanceorg_v")));
|
|
|
|
+ invoiceItemVO.setVmemob(bodyObject.getString("vmemob"));
|
|
|
|
+ invoiceItemVO.setFrowtype(0);
|
|
|
|
+ invoiceItemVO.setFtaxtypeflag(1);
|
|
|
|
+ invoiceItemVO.setVchangerate("1/1");
|
|
|
|
+ invoiceItemVO.setVbdef16(bodyObject.getString("vbdef16"));
|
|
|
|
+
|
|
|
|
+ if(bodyObject.opt("vbatchcode")!=null){
|
|
|
|
+ invoiceItemVO.setVbatchcode(bodyObject.getString("vbatchcode"));
|
|
|
|
+ }
|
|
|
|
+ childrenVO[i] = invoiceItemVO;
|
|
|
|
+ i++;
|
|
|
|
+ }
|
|
|
|
+ aggvo.setChildrenVO(childrenVO);
|
|
|
|
+
|
|
|
|
+ IInvoiceMaintain iInvoiceMaintain=(IInvoiceMaintain)NCLocator.getInstance().lookup(IInvoiceMaintain.class);
|
|
|
|
+ iInvoiceMaintain.insert(aggvos, null);
|
|
|
|
+
|
|
|
|
+ out.print(formatRSJsonData("成功","",vbillcode));
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ resp.getWriter().write(formatRSJsonData("失败", e.getMessage().toString(), "").toString());
|
|
|
|
+ StringWriter stringWriter = new StringWriter();
|
|
|
|
+ e.printStackTrace(new PrintWriter(stringWriter));
|
|
|
|
+
|
|
|
|
+ String msg = stringWriter.getBuffer().toString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * 非空判断
|
|
|
|
+ */
|
|
|
|
+ private void checkJson(JSONObject json) throws Exception {
|
|
|
|
+
|
|
|
|
+ StringBuffer mags = new StringBuffer();
|
|
|
|
+ Boolean empty = true;
|
|
|
|
+
|
|
|
|
+ String vbillcode = "vbillcode";
|
|
|
|
+ String pk_org = "pk_org";
|
|
|
|
+ String billmaker = "billmaker";
|
|
|
|
+ String vdef18 = "vdef18";
|
|
|
|
+
|
|
|
|
+ String body = "childrenVO";
|
|
|
|
+
|
|
|
|
+ String[] HeadKey = {vbillcode,pk_org,billmaker,body,vdef18};
|
|
|
|
+
|
|
|
|
+ for (String as : HeadKey) {
|
|
|
|
+ if (json.getString(as).isEmpty()) {
|
|
|
|
+ empty = false;
|
|
|
|
+ mags.append("'" + as + "'");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (json.getJSONArray(body)==null) {
|
|
|
|
+ empty = false;
|
|
|
|
+ mags.append("表体不存在! ");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ JSONArray oprepObjectBs = json.getJSONArray("childrenVO");
|
|
|
|
+
|
|
|
|
+ if (oprepObjectBs == null || oprepObjectBs.size() == 0) {
|
|
|
|
+ throw new Exception("表体内容不可为空!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String crowno = "crowno";
|
|
|
|
+
|
|
|
|
+ for(int i = 0; i < oprepObjectBs.size(); i++) {
|
|
|
|
+
|
|
|
|
+ JSONObject oprepJsonObjectB = oprepObjectBs.getJSONObject(i);
|
|
|
|
+ String[] BodyKey = {crowno};
|
|
|
|
+ int num = i+1;
|
|
|
|
+
|
|
|
|
+ mags.append("第"+num+"块表体:{");
|
|
|
|
+ for (String as : BodyKey) {
|
|
|
|
+ if (oprepJsonObjectB.getString(as).isEmpty()) {
|
|
|
|
+ empty = false;
|
|
|
|
+ mags.append("'" + as + "' ");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ mags.append("}");
|
|
|
|
+ }
|
|
|
|
+ if (!empty) {
|
|
|
|
+ throw new Exception("以下字段不可为空:"+mags);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ * 数据库查询
|
|
|
|
+ */
|
|
|
|
+ private String SqlexecuteQuery(String out,String table,String key,String value) throws Exception {
|
|
|
|
+ String sql = "select "+out+" from "+table+" where "+key+" = '"+value+"' and nvl(dr,0)=0";
|
|
|
|
+ Object object;
|
|
|
|
+ try {
|
|
|
|
+ object = iuap.executeQuery(sql, new ColumnProcessor());
|
|
|
|
+ if (object==null) {
|
|
|
|
+ throw new Exception("未查询到数据!请检查编码"+value+"是否正确!");
|
|
|
|
+ }
|
|
|
|
+ return object.toString();
|
|
|
|
+ } catch (BusinessException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return e.getMessage();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private String SqlexecuteQuery2(String out,String table,String key,String value) throws Exception {
|
|
|
|
+ String sql = "select "+out+" from "+table+" where "+key+" = '"+value+"' and nvl(dr,0)=0 and enablestate = '2'";
|
|
|
|
+ Object object;
|
|
|
|
+ try {
|
|
|
|
+ object = iuap.executeQuery(sql, new ColumnProcessor());
|
|
|
|
+ if (object==null) {
|
|
|
|
+ throw new Exception("未查询到数据!请检查编码"+value+"是否正确!");
|
|
|
|
+ }
|
|
|
|
+ return object.toString();
|
|
|
|
+ } catch (BusinessException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return e.getMessage();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|