|
|
@@ -0,0 +1,262 @@
|
|
|
+package openapi.restcontroller.wechatapp.tinvoiceapply;
|
|
|
+
|
|
|
+import net.sf.json.JSONArray;
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+import openapi.base.Controller;
|
|
|
+import openapi.base.SQLFactory;
|
|
|
+import openapi.base.data.Row;
|
|
|
+import openapi.base.data.Rows;
|
|
|
+import openapi.base.data.db.DBConnect;
|
|
|
+import p2.pao.PaoRemote;
|
|
|
+import p2.pao.PaoSetRemote;
|
|
|
+import tinvoiceapply.tinvoiceapply;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Arrays;
|
|
|
+import java.util.HashMap;
|
|
|
+
|
|
|
+public class Tinvoiceapply_saler extends Controller {
|
|
|
+
|
|
|
+ public Tinvoiceapply_saler(JSONObject content) {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ public String queryInvoiceApplyList() {
|
|
|
+ String[] sortmsg = {"t1.tinvoiceapplyid desc"};
|
|
|
+
|
|
|
+ String sort = "t1.tinvoiceapplyid desc";
|
|
|
+ if (content.containsKey("sort") && Arrays.asList(sortmsg).contains(content.getString("sort"))) {
|
|
|
+ sort = content.getString("sort");
|
|
|
+ }
|
|
|
+ String where = " 1=1 ";
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where = where + " and t1.finvoicename like'%" + whereObject.getString("condition") + "%'";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+
|
|
|
+ SQLFactory a = new SQLFactory(this, "下级业务员查询");
|
|
|
+ a.addParameter("hrid", hrid);
|
|
|
+ a.addParameter("siteid", siteid);
|
|
|
+ Rows hridRows = connect.runSqlQuery(a.getSQL());
|
|
|
+ String hridinwhere = hridRows.getInWhere("hrid");
|
|
|
+
|
|
|
+ SQLFactory factory = new SQLFactory(this, "经销商发票列表查询_业务员", pageSize, pageNumber, sort);
|
|
|
+ factory.addParameter("siteid", siteid);
|
|
|
+ factory.addParameter_SQL("hrid", hridinwhere);
|
|
|
+ factory.addParameter_SQL("where", where);
|
|
|
+
|
|
|
+ Rows rows = connect.runSqlQuery(factory.getSQL());
|
|
|
+
|
|
|
+ return getReturnObject_suc_page(rows, true, 1, sortmsg).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发票详情查询
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String queryInvoiceApplyMain() {
|
|
|
+ long tinvoiceapplyid = content.getLong("tinvoiceapplyid");
|
|
|
+
|
|
|
+ SQLFactory factory = new SQLFactory(this, "经销商发票详情查询");
|
|
|
+ factory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
|
|
|
+ factory.addParameter("siteid", siteid);
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+ Rows rows = connect.runSqlQuery(factory.getSQL());
|
|
|
+
|
|
|
+ for (Row row : rows) {
|
|
|
+ SQLFactory orderFactory = new SQLFactory(this, "经销商发票详情查询_订单行");
|
|
|
+ orderFactory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
|
|
|
+ orderFactory.addParameter("siteid", siteid);
|
|
|
+ row.put("orderdetails", connect.runSqlQuery(orderFactory.getSQL()));
|
|
|
+
|
|
|
+ SQLFactory invoiceFactory = new SQLFactory(this, "经销商发票详情查询_订单行");
|
|
|
+ invoiceFactory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
|
|
|
+ invoiceFactory.addParameter("siteid", siteid);
|
|
|
+ row.put("invoices", connect.runSqlQuery(invoiceFactory.getSQL()));
|
|
|
+ }
|
|
|
+ return getReturnObject_suc(rows, false).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发票新增修改
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String insertorModify() {
|
|
|
+ long tinvoiceapplyid = content.getLong("tinvoiceapplyid");//新建为0
|
|
|
+ String fagentnum = content.getString("fagentnum");//新建为0
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+ Rows rows = connect.runSqlQuery("select * from tinvoiceapply where tinvoiceapplyid='" + tinvoiceapplyid + "'");
|
|
|
+ if (!rows.isEmpty() && !"新建".equals(rows.get(0).getString("fstatus"))) {
|
|
|
+ return getReturnObject_err("当前状态不可修改").toString();
|
|
|
+ }
|
|
|
+ String finvoicename = content.getString("finvoicename");//开票单位
|
|
|
+ String finvoiceaddress = content.getString("finvoiceaddress");//开票单位地址
|
|
|
+ String finvoicetaxnumber = content.getString("finvoicetaxnumber");//开票单位税号
|
|
|
+ String fnotes = content.getString("fnotes");//备注
|
|
|
+ JSONArray orderdetailsArray = content.getJSONArray("orderdetails");
|
|
|
+ PaoSetRemote tinvoiceapplySet = null;
|
|
|
+ try {
|
|
|
+ tinvoiceapplySet = getP2ServerPaoSet("tinvoiceapply", hrid, "siteid='" + siteid + "' and tinvoiceapplyid='" + tinvoiceapplyid + "'");
|
|
|
+ tinvoiceapplySet.setApp("INVOICEAPP");
|
|
|
+ PaoRemote tinvoiceapply = null;
|
|
|
+ if (tinvoiceapplyid <= 0 || tinvoiceapplySet.isEmpty()) {
|
|
|
+ tinvoiceapply = tinvoiceapplySet.addAtEnd();
|
|
|
+ tinvoiceapply.setValue("fagentnum", fagentnum, 11L);
|
|
|
+ content.put("tinvoiceapplyid", tinvoiceapply.getUniqueIDValue());
|
|
|
+ } else {
|
|
|
+ tinvoiceapply = tinvoiceapplySet.getPao(0);
|
|
|
+ }
|
|
|
+ tinvoiceapply.setValue("finvoicename", finvoicename, 11L);
|
|
|
+ tinvoiceapply.setValue("finvoiceaddress", finvoiceaddress, 11L);
|
|
|
+ tinvoiceapply.setValue("finvoicetaxnumber", finvoicetaxnumber, 11L);
|
|
|
+ tinvoiceapply.setValue("fnotes", fnotes, 11L);
|
|
|
+
|
|
|
+ PaoSetRemote tinvoiceapplyorderset = tinvoiceapply.getPaoSet("tinvoiceapplyorder");
|
|
|
+ HashMap<String, PaoRemote> tinvoiceapplyordermap = getPaoMap(tinvoiceapplyorderset, "saorderdetailid");
|
|
|
+
|
|
|
+ ArrayList<String> donotdeleteid = new ArrayList<>();
|
|
|
+
|
|
|
+ for (Object o : orderdetailsArray) {
|
|
|
+ JSONObject orderdetailObject = (JSONObject) o;
|
|
|
+ String saorderid = orderdetailObject.getString("saorderid");
|
|
|
+ String saorderdetailid = orderdetailObject.getString("saorderdetailid");
|
|
|
+ double finvoiceqty = orderdetailObject.getDouble("finvoiceqty");//开票数量
|
|
|
+ double finvoiceamount = orderdetailObject.getDouble("finvoiceamount");//开票金额
|
|
|
+
|
|
|
+ PaoRemote detailPao = null;
|
|
|
+ if (tinvoiceapplyordermap.containsKey(saorderdetailid)) {
|
|
|
+ detailPao = tinvoiceapplyordermap.get(saorderdetailid);
|
|
|
+ } else {
|
|
|
+ /**
|
|
|
+ * 如果id不为0表示该订单行本身不存在,需要增加行
|
|
|
+ */
|
|
|
+ detailPao = tinvoiceapplyorderset.addAtEnd();
|
|
|
+ detailPao.setValue("siteid", siteid, 11L);
|
|
|
+ detailPao.setValue("tinvoiceapplyid", tinvoiceapplyid, 11L);
|
|
|
+ detailPao.setValue("saorderid", saorderid, 2L);
|
|
|
+ detailPao.setValue("saorderdetailid", saorderdetailid, 2L);
|
|
|
+ }
|
|
|
+ if (detailPao != null) {
|
|
|
+ detailPao.setValue("finvoiceqty", finvoiceqty, 2L);
|
|
|
+ detailPao.setValue("finvoiceamount", finvoiceamount, 2L);
|
|
|
+ }
|
|
|
+ donotdeleteid.add(saorderdetailid);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 删除多余的行
|
|
|
+ */
|
|
|
+ for (String id : tinvoiceapplyordermap.keySet()) {
|
|
|
+ if (!donotdeleteid.contains(id)) {
|
|
|
+ if (!tinvoiceapplyordermap.get(id).isModified()) {
|
|
|
+ tinvoiceapplyordermap.get(id).delete();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ tinvoiceapplySet.save();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ tinvoiceapplySet.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return queryInvoiceApplyMain();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String invoiceApplysubmit() {
|
|
|
+ long tinvoiceapplyid = content.getLong("tinvoiceapplyid");//新建为0
|
|
|
+ PaoSetRemote tinvoiceapplySet = null;
|
|
|
+ try {
|
|
|
+ tinvoiceapplySet = getP2ServerPaoSet("tinvoiceapply", hrid, "siteid='" + siteid + "' and tinvoiceapplyid='" + tinvoiceapplyid + "'");
|
|
|
+ tinvoiceapplySet.setApp("INVOICEAPP");
|
|
|
+ tinvoiceapply tinvoiceapply = (tinvoiceapply) tinvoiceapplySet.getPao(0);
|
|
|
+ tinvoiceapply.submitvalidate(true);
|
|
|
+ tinvoiceapply.submit(true);
|
|
|
+ } catch (Exception e) {
|
|
|
+ return getReturnObject_err(e.getMessage()).toString();
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ tinvoiceapplySet.close();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return getReturnObject_suc().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public String invoiceApplydelete() {
|
|
|
+ long tinvoiceapplyid = content.getLong("tinvoiceapplyid");//新建为0
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+ Rows rows = connect.runSqlQuery("select * from tinvoiceapply where tinvoiceapplyid='" + tinvoiceapplyid + "'");
|
|
|
+ if (rows.isEmpty() || !"新建".equals(rows.get(0).getString("fstatus"))) {
|
|
|
+ return getReturnObject_err("非新建状态下不可删除").toString();
|
|
|
+ }
|
|
|
+ String status = connect.runSqlUpdate("delete from tinvoiceapply where tinvoiceapplyid='" + tinvoiceapplyid + "'");
|
|
|
+ if ("true".equals(status)) {
|
|
|
+ return getReturnObject_suc().toString();
|
|
|
+ } else {
|
|
|
+ return getReturnObject_err("删除失败!").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开票经销商选择
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String queryInvoiceAgent() {
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+ SQLFactory a = new SQLFactory(this, "下级业务员查询");
|
|
|
+ a.addParameter("hrid", hrid);
|
|
|
+ a.addParameter("siteid", siteid);
|
|
|
+ Rows hridRows = connect.runSqlQuery(a.getSQL());
|
|
|
+ String hridinwhere = hridRows.getInWhere("hrid");
|
|
|
+
|
|
|
+ SQLFactory factory = new SQLFactory(this, "开票经销商选择查询_业务员");
|
|
|
+ factory.addParameter("siteid", siteid);
|
|
|
+ factory.addParameter_SQL("hrid", hridinwhere);
|
|
|
+
|
|
|
+ Rows rows = connect.runSqlQuery(factory.getSQL());
|
|
|
+ return getReturnObject_suc(rows, false).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开票单位选择
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String queryInvoiceName() {
|
|
|
+ String fagentnum = content.getString("fagentnum");
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+ Rows rows = connect.runSqlQuery("select * from tinvoiceapply_taxview where siteid='" + siteid + "' and fpayagentnum='" + fagentnum + "'");
|
|
|
+ return getReturnObject_suc(rows, false).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 开票订单行选择
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String querySaorderDetail() {
|
|
|
+ String fagentnum = content.getString("fagentnum");
|
|
|
+ String finvoicetaxnumber = content.getString("finvoicetaxnumber");
|
|
|
+ long tinvoiceapplyid = content.getLong("tinvoiceapplyid");
|
|
|
+ SQLFactory factory = new SQLFactory(this, "开票订单行选择查询");
|
|
|
+ factory.addParameter("siteid", siteid);
|
|
|
+ factory.addParameter("fagentnum", fagentnum);
|
|
|
+ factory.addParameter("finvoicetaxnumber", finvoicetaxnumber);
|
|
|
+ factory.addParameter("tinvoiceapplyid", tinvoiceapplyid);
|
|
|
+
|
|
|
+ DBConnect connect = new DBConnect();
|
|
|
+ Rows rows = connect.runSqlQuery(factory.getSQL());
|
|
|
+ return getReturnObject_suc(rows, false).toString();
|
|
|
+ }
|
|
|
+}
|