Преглед изворни кода

经销商及业务员开票申请

沈静伟 пре 4 година
родитељ
комит
7825508332
17 измењених фајлова са 632 додато и 26 уклоњено
  1. 1 9
      src/apps/tinvoiceapply/tinvoiceapply.java
  2. 4 4
      src/apps/tinvoiceapplyorder/tinvoiceapplyOrderDataBean.java
  3. 1 1
      src/apps/tinvoiceapplyorder/tinvoiceapplyorder.java
  4. 7 4
      src/apps/tinvoicebill/tinvoiceapplyBillDataBean.java
  5. 3 3
      src/apps/tinvoicebill/tinvoicebill.java
  6. 4 4
      src/apps/tinvoicebillitem/tinvoiceItemDataBean.java
  7. 1 1
      src/apps/tinvoicebillitem/tinvoicebillitem.java
  8. 14 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/下级业务员查询.sql
  9. 5 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/开票经销商选择查询_业务员.sql
  10. 15 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/开票订单行选择查询.sql
  11. 19 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票列表查询.sql
  12. 20 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票列表查询_业务员.sql
  13. 20 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票详情查询.sql
  14. 8 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票详情查询_发票.sql
  15. 17 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票详情查询_订单行.sql
  16. 231 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/Tinvoiceapply.java
  17. 262 0
      src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/Tinvoiceapply_saler.java

+ 1 - 9
src/apps/tinvoiceapply/tinvoiceapply.java

@@ -21,7 +21,7 @@ public class tinvoiceapply extends PaoCust {
     public void init() throws P2Exception {
         super.init();
         if (!toBeAdded()) {
-            if (!"新建".equals(getString("fstatus"))) {
+            if ("审核".equals(getString("fstatus"))) {
                 GetFieldsName fieldsName = new GetFieldsName(getName());
                 setFieldFlag(fieldsName.getFields(), READONLY, true);
             }
@@ -72,7 +72,6 @@ public class tinvoiceapply extends PaoCust {
         super.submitvalidate(issubmit);
 
         PaoSetRemote tinvoiceapplyorderSet = getPaoSet("tinvoiceapplyorder");
-        PaoSetRemote tinvoicebillSet = getPaoSet("tinvoicebill");
         /****************** 单据检验 *********************/
         if (issubmit) {
             if (!"新建".equals(getString("fstatus"))) {
@@ -81,16 +80,9 @@ public class tinvoiceapply extends PaoCust {
             if (tinvoiceapplyorderSet.isEmpty()) {
                 throw new P2AppException("", "订单信息为空不可提交");
             }
-            if (tinvoicebillSet.isEmpty()) {
-                throw new P2AppException("", "开票信息为空不可提交");
-            }
             if (tinvoiceapplyorderSet.min("finvoiceamount") <= 0) {
                 throw new P2AppException("", "订单行开票金额必须大于0");
             }
-            PaoSetRemote tinvoiceapply_totalview = getPaoSet("tinvoiceapply_totalview");
-            if (tinvoiceapply_totalview.getPao(0).getDouble("forderamount") != tinvoiceapply_totalview.getPao(0).getDouble("fbillamount")) {
-                throw new P2AppException("", "订单金额和开票金额不一致");
-            }
 
             int i = 0;
             PaoRemote detailpao = null;

+ 4 - 4
src/apps/tinvoiceapplyorder/tinvoiceapplyOrderDataBean.java

@@ -8,16 +8,16 @@ public class tinvoiceapplyOrderDataBean extends DataBeanCust {
 
     @Override
     public int TOGGLEDELETEROW() throws P2Exception {
-        if (!"新建".equals(parent.getString("fstatus"))) {
-            throw new P2AppException("", "非新建状态下不可删除");
+        if ("审核".equals(parent.getString("fstatus"))) {
+            throw new P2AppException("", "审核状态下不可删除");
         }
         return super.TOGGLEDELETEROW();
     }
 
     public int ADDORDERS() throws P2Exception {
         parent.save();
-        if (!"新建".equals(parent.getString("fstatus"))) {
-            throw new P2AppException("", "非新建状态下不可添加");
+        if ("审核".equals(parent.getString("fstatus"))) {
+            throw new P2AppException("", "审核状态下不可添加");
         }
         return 2;
     }

+ 1 - 1
src/apps/tinvoiceapplyorder/tinvoiceapplyorder.java

@@ -18,7 +18,7 @@ public class tinvoiceapplyorder extends PaoCust {
     public void init() throws P2Exception {
         super.init();
         if (!toBeAdded() && getOwner() instanceof tinvoiceapply) {
-            if (!"н¨".equals(getOwner().getString("fstatus"))) {
+            if ("ÉóºË".equals(getOwner().getString("fstatus"))) {
                 setFieldFlag(new String[]{"finvoiceamount", "finvoiceqty"}, READONLY, true);
             }
             PaoRemote saorderdetail = getPaoSet("saorderdetail").getPao(0);

+ 7 - 4
src/apps/tinvoicebill/tinvoiceapplyBillDataBean.java

@@ -16,8 +16,8 @@ public class tinvoiceapplyBillDataBean extends DataBeanCust {
      */
     public int ADDINVOICES() throws P2Exception {
         parent.save();
-        if (!"新建".equals(parent.getString("fstatus"))) {
-            throw new P2AppException("", "非新建状态下不可添加");
+        if ("审核".equals(parent.getString("fstatus"))) {
+            throw new P2AppException("", "审核状态下不可添加");
         }
         tinvoiceapply tinvoiceapply = (tinvoiceapply) parent.getPao();
         tinvoiceapply.addBills();
@@ -28,14 +28,17 @@ public class tinvoiceapplyBillDataBean extends DataBeanCust {
 
     public int ADDROW() throws P2Exception {
         parent.save();
-        if (!"新建".equals(parent.getString("fstatus"))) {
-            throw new P2AppException("", "非新建状态下不可添加");
+        if ("审核".equals(parent.getString("fstatus"))) {
+            throw new P2AppException("", "审核状态下不可添加");
         }
         return super.ADDROW();
     }
 
     @Override
     public int TOGGLEDELETEROW() throws P2Exception {
+        if ("审核".equals(parent.getString("fstatus"))) {
+            throw new P2AppException("", "审核状态下不可删除");
+        }
         return super.TOGGLEDELETEROW();
     }
 

+ 3 - 3
src/apps/tinvoicebill/tinvoicebill.java

@@ -48,7 +48,7 @@ public class tinvoicebill extends PaoCust {
     public void init() throws P2Exception {
         super.init();
         if (!toBeAdded()) {
-            if (getOwner() instanceof tinvoiceapply && !"新建".equals(getOwner().getString("fstatus"))) {
+            if (getOwner() instanceof tinvoiceapply && "审核".equals(getOwner().getString("fstatus"))) {
                 if ("2".equals(getString("status"))) {
                     setFieldFlag(new String[]{"fnotes", "billInfoNo"}, READONLY, true);
                 }
@@ -67,9 +67,9 @@ public class tinvoicebill extends PaoCust {
     @Override
     public void canDelete() throws P2Exception {
         super.canDelete();
-        if (getOwner() instanceof tinvoiceapply && !"新建".equals(getOwner().getString("fstatus"))) {
+        if (getOwner() instanceof tinvoiceapply && "审核".equals(getOwner().getString("fstatus"))) {
             if ("蓝".equals(getString("frb"))) {
-                throw new P2AppException("", "非新建状态下蓝票不可删除");
+                throw new P2AppException("", "审核状态下蓝票不可删除");
             }
             if ("2".equals(getString("status"))) {
                 throw new P2AppException("", "已完成开票,不可删除");

+ 4 - 4
src/apps/tinvoicebillitem/tinvoiceItemDataBean.java

@@ -8,16 +8,16 @@ public class tinvoiceItemDataBean extends DataBeanCust {
 
     @Override
     public int TOGGLEDELETEROW() throws P2Exception {
-        if (!"新建".equals(parent.getPao().getOwner().getString("fstatus"))) {
-            throw new P2AppException("", "非新建状态下不可删除");
+        if ("审核".equals(parent.getPao().getOwner().getString("fstatus"))) {
+            throw new P2AppException("", "审核状态下不可删除");
         }
         return super.TOGGLEDELETEROW();
     }
 
     public int ADDBILLITEMROW() throws P2Exception {
         parent.save();
-        if (!"新建".equals(parent.getPao().getOwner().getString("fstatus"))) {
-            throw new P2AppException("", "非新建状态下不可添加");
+        if ("审核".equals(parent.getPao().getOwner().getString("fstatus"))) {
+            throw new P2AppException("", "审核状态下不可添加");
         }
         return 2;
     }

+ 1 - 1
src/apps/tinvoicebillitem/tinvoicebillitem.java

@@ -17,7 +17,7 @@ public class tinvoicebillitem extends PaoCust {
     public void init() throws P2Exception {
         super.init();
         if (!toBeAdded()) {
-            if (getOwner() instanceof tinvoicebill && getOwner().getOwner() instanceof tinvoiceapply && !"н¨".equals(getOwner().getOwner().getString("fstatus"))) {
+            if (getOwner() instanceof tinvoicebill && getOwner().getOwner() instanceof tinvoiceapply && "ÉóºË".equals(getOwner().getOwner().getString("fstatus"))) {
                 if ("2".equals(getOwner().getString("status"))) {
                     GetFieldsName fieldsName = new GetFieldsName(getName());
                     setFieldFlag(fieldsName.getFields(), READONLY, true);

+ 14 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/下级业务员查询.sql

@@ -0,0 +1,14 @@
+with cte(fdepno,issub) AS (
+	SELECT t1.fdepno,0 FROM tdepartment t1
+	inner join pp_hr t2 on t1.fdepno=t2.fdepno and t1.siteid=t2.siteid
+	WHERE t2.hrid=$hrid$ and t1.siteid=$siteid$
+	UNION ALL
+	SELECT t1.fdepno,1 FROM tdepartment t1
+	inner join cte t2 on t1.fleaddepno=t2.fdepno
+	where t1.siteid=$siteid$
+)
+select t2.hrid from cte t1
+inner join pp_hr t2 on t1.fdepno=t2.fdepno
+where t1.issub=1
+union
+select $hrid$

+ 5 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/开票经销商选择查询_业务员.sql

@@ -0,0 +1,5 @@
+
+select fagentnum,fagentname from tagents
+where siteid=$siteid$ and
+exists(select distinct t1.fpayagentnum from saorder t1 inner join saorderdetail t2 on t1.siteid=t2.siteid and t1.saorderid=t2.fparentid inner join SAORDER_RECEIVEDVIEW t3 on t2.fparentid=t3.saorderid and t2.saorderdetailid=t3.saorderdetailid where isnull(t3.freceivedamount,0)>isnull(t2.finvoiceamount,0) and t1.fpayagentnum=tagents.fagentnum)
+and exists (select fagentnum from tagents_field where hrid in $hrid$ and siteid=tagents.siteid and fagentnum=tagents.fagentnum )

+ 15 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/开票订单行选择查询.sql

@@ -0,0 +1,15 @@
+select *from saorderdetail where
+siteid=$siteid$ and
+exists(
+        select *from saorder_receivedview
+        where siteid=saorderdetail.siteid and saorderid=saorderdetail.fparentid and saorderdetailid=saorderdetail.saorderdetailid
+        and isnull(freceivedamount,0)>isnull(saorderdetail.finvoiceamount,0)
+)
+and exists(
+        select * from saorder
+        where fstatus in('ÉóºË','¹Ø±Õ') and siteid=saorderdetail.siteid
+        and saorderid=saorderdetail.fparentid and fpayagentnum=$fagentnum$ and finvoicetaxnumber=$finvoicetaxnumber$
+)
+and not exists(
+    select *from tinvoiceapplyorder where siteid=$siteid and tinvoiceapplyid=$tinvoiceapplyid$ and saorderdetailid=saorderdetail.saorderdetailid
+)

+ 19 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票列表查询.sql

@@ -0,0 +1,19 @@
+select t1.tinvoiceapplyid,
+       t1.fbillnum,
+       t1.fagentnum,
+       t3.fagentname,
+       convert(varchar(19), t1.createdate, 120) as createdate,
+       convert(varchar(19), t1.submitdate, 120) as submitdate,
+       convert(varchar(19), t1.checkdate, 120)  as checkdate,
+       t1.finvoicetaxnumber,
+       t1.finvoicename,
+       t1.finvoiceaddress,
+       t1.fstatus,
+       sum(t2.finvoiceamount)                   as finvoiceamount
+from tinvoiceapply t1
+         left join tinvoiceapplyorder t2 on t1.siteid = t2.siteid and t1.tinvoiceapplyid = t2.tinvoiceapplyid
+         left join tagents t3 on t1.siteid=t3.siteid and t1.fagentnum=t3.fagentnum
+         where t1.siteid=$siteid$ and t1.fagentnum=$fagentnum$ and $where$
+group by t1.tinvoiceapplyid, t1.fbillnum, t1.createdate, t1.submitdate, t1.checkdate, t1.finvoicetaxnumber,
+         t1.finvoicename,
+         t1.finvoiceaddress, t1.fstatus

+ 20 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票列表查询_业务员.sql

@@ -0,0 +1,20 @@
+select t1.tinvoiceapplyid,
+       t1.fbillnum,
+       t1.fagentnum,
+       t3.fagentname,
+       convert(varchar(19), t1.createdate, 120) as createdate,
+       convert(varchar(19), t1.submitdate, 120) as submitdate,
+       convert(varchar(19), t1.checkdate, 120)  as checkdate,
+       t1.finvoicetaxnumber,
+       t1.finvoicename,
+       t1.finvoiceaddress,
+       t1.fstatus,
+       sum(t2.finvoiceamount)                   as finvoiceamount
+from tinvoiceapply t1
+         left join tinvoiceapplyorder t2 on t1.siteid = t2.siteid and t1.tinvoiceapplyid = t2.tinvoiceapplyid
+         left join tagents t3 on t1.siteid=t3.siteid and t1.fagentnum=t3.fagentnum
+         where t1.siteid=$siteid$ and $where$
+         and exists (select fagentnum from tagents_field where hrid in $hrid$ and siteid=t1.siteid and fagentnum=t1.fagentnum )
+group by t1.tinvoiceapplyid, t1.fbillnum, t1.createdate, t1.submitdate, t1.checkdate, t1.finvoicetaxnumber,
+         t1.finvoicename,
+         t1.finvoiceaddress, t1.fstatus

+ 20 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票详情查询.sql

@@ -0,0 +1,20 @@
+select t1.tinvoiceapplyid,
+       t1.fbillnum,
+       t1.fagentnum,
+       t3.fagentname,
+       convert(varchar(19), t1.createdate, 120) as createdate,
+       convert(varchar(19), t1.submitdate, 120) as submitdate,
+       convert(varchar(19), t1.checkdate, 120)  as checkdate,
+       t1.finvoicetaxnumber,
+       t1.finvoicename,
+       t1.finvoiceaddress,
+       t1.fstatus,
+       t1.fnotes,
+       sum(t2.finvoiceamount)                   as finvoiceamount
+from tinvoiceapply t1
+         left join tinvoiceapplyorder t2 on t1.siteid = t2.siteid and t1.tinvoiceapplyid = t2.tinvoiceapplyid
+          left join tagents t3 on t1.siteid=t3.siteid and t1.fagentnum=t3.fagentnum
+         where t1.siteid=$siteid$ and t1.tinvoiceapplyid=$tinvoiceapplyid$
+group by t1.tinvoiceapplyid, t1.fbillnum, t1.createdate, t1.submitdate, t1.checkdate, t1.finvoicetaxnumber,
+         t1.finvoicename,
+         t1.finvoiceaddress, t1.fstatus,t1.fnotes

+ 8 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票详情查询_发票.sql

@@ -0,0 +1,8 @@
+select
+t1.frb,
+t1.fnotes,
+t1.invoicecode,
+t1.invoiceno,
+case when t1.paperpdfurl is null then t1.pdfurl else t1.paperpdfurl end as pdfurl
+from tinvoicebill t1
+where t1.status = 2 and t1.siteid =$siteid$ and t1.tinvoiceapplyid=$tinvoiceapplyid$

+ 17 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/SQL/经销商发票详情查询_订单行.sql

@@ -0,0 +1,17 @@
+select tinvoiceapplyordid,
+       finvoiceamount,
+       finvoiceqty,
+       fprice,
+       funinvoiceamount,
+       saorderdetailid,
+       saorderid,
+       t2.frownum,
+       t2.fsonum,
+       t2.fitemno,
+       t2.fitemname,
+       t2.fmodel,
+       t2.fspec
+from tinvoiceapplyorder t1
+         inner join saorderdetail t2
+                    on t1.siteid = t2.siteid and t1.saorderid = t2.fparentid and t1.saorderdetailid = t2.saorderdetailid
+ where t1.siteid=$siteid$ and t1.tinvoiceapplyid=$tinvoiceapplyid$

+ 231 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/Tinvoiceapply.java

@@ -0,0 +1,231 @@
+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 extends Controller {
+
+    public Tinvoiceapply(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") + "%'";
+            }
+        }
+        SQLFactory factory = new SQLFactory(this, "经销商发票列表查询", pageSize, pageNumber, sort);
+        factory.addParameter("fagentnum", fagentnum);
+        factory.addParameter("siteid", siteid);
+        factory.addParameter_SQL("where", where);
+
+        DBConnect connect = new DBConnect();
+        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
+        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 queryInvoiceName() {
+        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 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();
+    }
+}

+ 262 - 0
src/rest/openapi/restcontroller/wechatapp/tinvoiceapply/Tinvoiceapply_saler.java

@@ -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();
+    }
+}