Jelajahi Sumber

Merge remote-tracking branch 'origin/develop' into develop

shenjingwei 3 bulan lalu
induk
melakukan
fdb4553b7e

+ 15 - 0
src/custom/restcontroller/R.java

@@ -6691,6 +6691,21 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025090313530203 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025090314003303 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025090316070203 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 162 - 0
src/custom/restcontroller/webmanage/sale/accessoryorder/accessoryorder.java

@@ -11,6 +11,7 @@ import common.annotation.CACHEING;
 import common.data.*;
 import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
+import utility.ERPDocking;
 
 import java.io.IOException;
 import java.math.BigDecimal;
@@ -184,6 +185,167 @@ public class accessoryorder extends Controller {
     }
 
 
+    @API(title = "查询配件订单所有明细列表", apiversion = R.ID2025090316070203.v1.class)
+    public String selectAllList() throws YosException, IOException {
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (sys_enterpriseid > 0) {
+            where.append(" and t5.sys_enterpriseid ='").append(sys_enterpriseid).append("' ");
+        }
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append(" t5.sonum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t1.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t6.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t7.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t3.spec like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+
+            if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
+                where.append(" and DATE_FORMAT(t5.billdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
+            }
+            if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
+                where.append(" and DATE_FORMAT(t5.billdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
+            }
+            if (whereObject.containsKey("begindate1") && !"".equals(whereObject.getString("begindate1"))) {
+                where.append(" and DATE_FORMAT(t5.submitdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate1")).append("' ");
+            }
+            if (whereObject.containsKey("enddate1") && !"".equals(whereObject.getString("enddate1"))) {
+                where.append(" and DATE_FORMAT(t5.submitdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate1")).append("' ");
+            }
+
+            if (whereObject.containsKey("begindate2") && !"".equals(whereObject.getString("begindate2"))) {
+                where.append(" and DATE_FORMAT(t5.checkdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate2")).append("' ");
+            }
+
+            if (whereObject.containsKey("enddate2") && !"".equals(whereObject.getString("enddate2"))) {
+                where.append(" and DATE_FORMAT(t5.checkdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate2")).append("' ");
+            }
+            if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
+                where.append(" and t5.status ='").append(whereObject.getString("status")).append("' ");
+            }
+            if (whereObject.containsKey("isfreeze") && !"".equals(whereObject.getString("isfreeze"))) {
+                where.append(" and t1.isfreeze ='").append(whereObject.getString("isfreeze")).append("' ");
+            }
+            if (whereObject.containsKey("typemx") && !"".equals(whereObject.getString("typemx"))) {
+                where.append(" and t5.typemx ='").append(whereObject.getString("typemx")).append("' ");
+            }
+
+            if (whereObject.containsKey("isuncheckout") && !"".equals(whereObject.getString("isuncheckout"))) {
+                String begindate = "";
+                String enddate = "";
+                if (whereObject.containsKey("datetype") && !"".equals(whereObject.getString("datetype"))) {
+                    String datetype = whereObject.getStringValue("datetype");
+                    switch (datetype) {
+                        case "7":
+                            begindate = getDate_Str(-7);
+                            enddate = getDate_Str();
+                            break;
+                        case "30":
+                            begindate = getDate_Str(-30);
+                            enddate = getDate_Str();
+                            break;
+                        case "90":
+                            begindate = getDate_Str(-90);
+                            enddate = getDate_Str();
+                            break;
+                        default:
+                            break;
+                    }
+                }
+                if (!begindate.equals("")) {
+                    where.append(" and DATE_FORMAT(t5.submitdate, '%Y-%m-%d') >='").append(begindate).append("' ");
+                }
+                if (!enddate.equals("")) {
+                    where.append(" and DATE_FORMAT(t5.submitdate, '%Y-%m-%d') <='").append(enddate).append("' ");
+                }
+
+                String isuncheckout = whereObject.getStringValue("isuncheckout");
+                if (isuncheckout.equals("1")) {
+                    where.append(" and t1.sa_orderitemsid in (select t1.sa_orderitemsid from sa_orderitems t1 inner join (select t2.sa_orderitemsid,t2.siteid,sum(outwarehouseqty) sumoutwarehouseqty from sa_dispatch_items t2 inner join sa_dispatch t3 on t2.sa_dispatchid=t3.sa_dispatchid and t2.siteid=t3.siteid GROUP BY sa_orderitemsid,siteid) t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.qty>ifnull(t2.sumoutwarehouseqty,0) or t1.undeliqty>0)");
+                } else {
+                    where.append(" and t1.sa_orderitemsid not in (select t1.sa_orderitemsid from sa_orderitems t1 inner join (select t2.sa_orderitemsid,t2.siteid,sum(outwarehouseqty) sumoutwarehouseqty from sa_dispatch_items t2 inner join sa_dispatch t3 on t2.sa_dispatchid=t3.sa_dispatchid and t2.siteid=t3.siteid GROUP BY sa_orderitemsid,siteid) t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.qty>ifnull(t2.sumoutwarehouseqty,0) or t1.undeliqty>0)");
+                }
+            }
+            if (whereObject.containsKey("iscancel") && !"".equals(whereObject.getString("iscancel"))) {
+                String iscancel = whereObject.getStringValue("iscancel");
+                if (iscancel.equals("1")) {
+                    where.append(" and t5.status ='手工关闭' and not exists(select 1 from st_stockbill_items s1 inner join st_stockbill s2 on s1.st_stockbillid=s2.st_stockbillid and s1.siteid=s2.siteid where s2.status='审核' and s2.rb=1 and s1.sa_orderitemsid=t1.sa_orderitemsid)");
+                }
+            }
+            if (whereObject.containsKey("convenient") && !"".equals(whereObject.getString("convenient"))) {
+                String convenient = whereObject.getStringValue("convenient");
+                if (convenient.equals("待确认")) {
+                    where.append(" and t5.status ='预提交' ");
+                } else if (convenient.equals("待审核")) {
+                    where.append(" and t5.status ='提交' ");
+                } else if (convenient.equals("待发货")) {
+                    where.append(" and t5.status in ('审核') and not exists(select 1 from st_stockbill_items s1 inner join st_stockbill s2 on s1.st_stockbillid=s2.st_stockbillid and s1.siteid=s2.siteid where s2.status='审核' and s2.rb=1 and s1.sa_orderitemsid=t1.sa_orderitemsid)");
+                } else if (convenient.equals("已发货")) {
+                    where.append(" and exists(select 1 from st_stockbill_items s1 inner join st_stockbill s2 on s1.st_stockbillid=s2.st_stockbillid and s1.siteid=s2.siteid where s2.status='审核' and s2.rb=1 and s1.sa_orderitemsid=t1.sa_orderitemsid)");
+                } else if (convenient.equals("已取消")) {
+                    where.append(" and t5.status ='手工关闭' and  exists(select 1 from (\n" +
+                            "select  s1.sa_orderitemsid,s1.siteid,sum(s1.qty) qty from st_stockbill_items s1 inner join st_stockbill s2 on s1.st_stockbillid=s2.st_stockbillid and s1.siteid=s2.siteid where s2.status='审核' and s2.rb=1 group by s1.sa_orderitemsid,s1.siteid) s right join sa_orderitems s1  on s.sa_orderitemsid=s1.sa_orderitemsid and s.siteid=s1.siteid where s1.qty>ifnull(s.qty,0) and s1.sa_orderitemsid=t1.sa_orderitemsid)");
+                }
+            }
+
+
+        }
+
+        boolean isExport = content.getBooleanValue("isExport");
+        QuerySQL querySQL = queryAllListManage(where.toString());
+        querySQL.setOrderBy(pageSorting);
+        querySQL.setPage(pageSize, pageNumber);
+        Rows rows = querySQL.query();
+        ArrayList<Long> ids = rows.toArrayList("itemid", new ArrayList<>());
+        //查询附件
+        RowsMap attinfoRowsMap = getAttachmentUrl("plm_item", ids);
+        for (Row row : rows) {
+            row.put("attinfos", attinfoRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
+            row.put("contractprice", 0);
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    //查询配件订单明细列表(管理端)
+    public QuerySQL queryAllListManage(String where) throws YosException {
+
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_orderitems",
+                "sa_orderitemsid", "itemid", "rowno", "itemno", "itemname", "unit", "qty", "undeliqty", "saleprice", "defaultprice", "price", "amount", "remarks", "customproperties", "batchcontrol", "model",
+                "conversionrate", "marketprice", "defaultprice", "defaultamount", "auxqty", "needdate", "deliedqty", "rebateamount", "invoiceamount", "writeoffamount", "auxunit", "sa_orderid",
+                "deliverydate", "returnqty", "stockno", "position", "batchno", "isfreeze", "decorationrebateflag");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t3", "t3.itemid = t1.itemid and t3.siteid = t1.siteid",
+                "orderminqty_auxunit", "orderminqty", "orderaddqty_auxunit", "orderaddqty", "spec", "standards", "packageqty", "delivery", "k3outcode");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_order", "t5", "t5.sa_orderid = t1.sa_orderid and t5.siteid = t1.siteid",
+                "sonum", "type", "typemx", "status", "billdate", "submitdate", "checkdate", "tradefield", "closedate");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sys_enterpriseid = t5.sys_enterpriseid and t6.siteid = t5.siteid",
+                "agentnum");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t7", "t7.sys_enterpriseid = t5.sys_enterpriseid and t7.siteid = t5.siteid",
+                "enterprisename");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_itemclass", "t8", "t8.itemclassid = t3.marketingcategory and t8.siteid = t3.siteid",
+                "itemclassname");
+        querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise_tradefield", "t9", "t9.sys_enterpriseid = t5.sys_enterpriseid and t9.tradefield=t5.tradefield and t9.siteid = t5.siteid",
+                "sys_enterprise_tradefieldid");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_salearea", "t10", "t10.sa_saleareaid = t9.sa_saleareaid and t10.siteid = t9.siteid",
+                "areaname");
+//        querySQL.addJoinTable(JOINTYPE.left, t11, "t11", "t11.sa_orderitemsid = t1.sa_orderitemsid and t11.siteid = t1.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_accountclass", "t12", "t12.sa_accountclassid=t5.sa_accountclassid and t12.siteid=t5.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "sa_promotion", "t13", "t13.sa_promotionid=t5.sa_promotionid and t13.siteid=t5.siteid","promnum","promname");
+        querySQL.addQueryFields("accountnames", "if(ifnull(replace(replace(replace(JSON_EXTRACT (t5.sa_accountclassinfos, '$**.accountname' ),'[',''),']',''),'\\\"',''),'')='',t12.accountname,replace(replace(replace(JSON_EXTRACT (t5.sa_accountclassinfos, '$**.accountname' ),'[',''),']',''),'\\\"',''))");
+        querySQL.addQueryFields("orderremarks", "t5.remarks");
+//        querySQL.addQueryFields("outwarehouseqty", "ifnull(t11.outwarehouseqty,0)");
+        //querySQL.addQueryFields("accountclassinfos", "REPLACE(SUBSTRING(JSON_EXTRACT(t5.sa_accountclassinfos, '$[*].accountname'), 2, CHAR_LENGTH(JSON_EXTRACT(t5.sa_accountclassinfos, '$[*].accountname'))-2),'\"','')");
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere(where);
+        querySQL.setWhere("t5.status!='新建' and t5.type='配件订单'");
+        return querySQL;
+    }
+
     //查询配件订单列表(管理端)
     public QuerySQL queryListManage(String where) throws YosException {
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_order",

+ 4 - 4
src/custom/restcontroller/webmanage/sale/dbstockbill/dbstockbill.java

@@ -195,7 +195,7 @@ public class dbstockbill extends Controller {
         Rows dbstockbillrows =dbConnect.runSqlQuery("select * from st_dbstockbill where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"'");
         Rows dbstockbilldetailrows =dbConnect.runSqlQuery("select t1.*,t2.itemname,t2.itemno,t2.model from st_dbstockbilldetail t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_dbstockbillid='"+st_dbstockbillid+"' and t1.siteid='"+siteid+"'");
         Rows dbstockbilldetailskurows =dbConnect.runSqlQuery("select st_dbstockbilldetailid,count(1) qty from st_dbstockbilldetailsku where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"' group by st_dbstockbilldetailid");
-        Rows dbstockbilldetailskus =dbConnect.runSqlQuery("select st_dbstockbilldetailid,sku,outstockid from st_dbstockbilldetailsku where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"'");
+        Rows dbstockbilldetailskus =dbConnect.runSqlQuery("select st_dbstockbillid,st_dbstockbilldetailid,sku,outstockid from st_dbstockbilldetailsku where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"'");
         RowsMap dbstockbilldetailskurowsMap =dbstockbilldetailskurows.toRowsMap("st_dbstockbilldetailid");
         RowsMap dbstockbilldetailrowsMap =dbstockbilldetailrows.toRowsMap("st_dbstockbilldetailid");
         RowsMap dbstockbilldetailskusRowsMap=dbstockbilldetailskus.toRowsMap("st_dbstockbilldetailid");
@@ -413,7 +413,7 @@ public class dbstockbill extends Controller {
         if (!stockbillrowmap.containsKey("调拨出库")) {
             return getErrReturnObject().setErrMsg("找不到该调拨单对应的出库单,不可反审核").toString();
         }
-        if (!stockbillrowmap.containsKey("调拨入库")) {
+        if (!stockbillrowmap.containsKey("调拨入库") && !dbstockbillrows.get(0).getBoolean("isnotimmediately")) {
             return getErrReturnObject().setErrMsg("找不到该调拨单对应的入库单,不可反审核").toString();
         }
         ArrayList<String> sqllist=new ArrayList<>();
@@ -570,10 +570,10 @@ public class dbstockbill extends Controller {
                 if (isinbillneedcheck) {
                     sqllist.add("update sa_itemsku set stockid="+instockid+" where sku='"+row.getString("sku")+"'");
                 } else {
-                    sqllist.add("update sa_itemsku set stockid=0 where sku='"+row.getString("sku")+"'");
+                    sqllist.add("update sa_itemsku set stockid=0,st_dbstockbillid="+row.getLong("st_dbstockbillid")+",st_dbstockbilldetailid="+row.getLong("st_dbstockbilldetailid")+" where sku='"+row.getString("sku")+"'");
                 }
             } else {// 反审核
-                sqllist.add("update sa_itemsku set stockid="+outstockid+" where sku='"+row.getString("sku")+"'");
+                sqllist.add("update sa_itemsku set stockid="+outstockid+",st_dbstockbillid=0,st_dbstockbilldetailid=0 where sku='"+row.getString("sku")+"'");
             }
         }
         return sqllist;

+ 281 - 0
src/custom/restcontroller/webmanage/sale/dbstockbill/dbstockbillreceive.java

@@ -0,0 +1,281 @@
+package restcontroller.webmanage.sale.dbstockbill;
+
+import beans.invbal.Invbal;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import common.Controller;
+import common.YosException;
+import common.annotation.API;
+import common.data.*;
+import restcontroller.R;
+
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Date;
+
+public class dbstockbillreceive extends Controller {
+    public dbstockbillreceive(JSONObject content) throws YosException {
+        super(content);
+    }
+
+    @API(title = "查询需要收货确认的审核调拨单", apiversion = R.ID2025090313530203.v1.class)
+    public String queryDbstockbills_Receive() throws YosException {
+
+        /*
+         * 过滤条件设置
+         */
+        StringBuffer where = new StringBuffer(" 1=1 ");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
+                where.append(" and(");
+                where.append("t4.itemname like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t4.model like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t4.spec like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t4.itemno like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_dbstockbilldetail","*");
+        querySQL.setTableAlias("t1");
+        querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t2", "t1.instockid = t2.stockid AND t1.siteid = t2.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t3", "t1.outstockid = t3.stockid AND t1.siteid = t3.siteid");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t4", "t1.itemid=t4.itemid and t1.siteid = t4.siteid","itemno","itemname"
+                ,"spec","model");
+        querySQL.addJoinTable(JOINTYPE.left, "plm_unit", "t5", "t4.unitid=t5.unitid and t4.siteid = t5.siteid","unitname");
+        querySQL.addJoinTable(JOINTYPE.inner, "st_dbstockbill", "t6", "t1.st_dbstockbillid=t6.st_dbstockbillid and t1.siteid = t6.siteid","billno","checkdate");
+
+        querySQL.addQueryFields("outstockno", "t3.stockno");
+        querySQL.addQueryFields("outstockname", "t3.stockname");
+        querySQL.addQueryFields("instockno", "t2.stockno");
+        querySQL.addQueryFields("instockname", "t2.stockname");
+        querySQL.setWhere("t1.siteid", siteid);
+        querySQL.setWhere(where);
+        querySQL.setWhere("t6.status='审核' and t1.undeliqty>0");
+        querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy(pageSorting);
+        Rows rows = querySQL.query();
+
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "生成入库单", apiversion = R.ID2025090314003303.v1.class)
+    public String received() throws YosException {
+        JSONArray st_dbstockbilldetails=content.getJSONArray("st_dbstockbilldetails");
+        if(st_dbstockbilldetails.isEmpty()){
+            return getErrReturnObject().setErrMsg("未选择调拨单明细").toString();
+        }
+        Rows dbstockbilldetail=new Rows();
+        Rows rows = dbConnect.runSqlQuery("select t1.*,t2.instockid from st_dbstockbilldetail t1 inner join st_dbstockbill t2 on t1.siteid=t2.siteid and t1.st_dbstockbillid=t2.st_dbstockbillid  where t1.siteid='"+siteid+"' and t1.undeliqty>0 and t2.status='审核'");
+        RowsMap rowsMap =rows.toRowsMap("st_dbstockbilldetailid");
+        long st_dbstockbillid =0;
+        for(Object object :st_dbstockbilldetails){
+            JSONObject jsonObject = (JSONObject)object;
+            Row st_dbstockbilldetail;
+            if(rowsMap.containsKey(jsonObject.getLong("st_dbstockbilldetailid"))){
+                st_dbstockbilldetail=rowsMap.get(jsonObject.getLong("st_dbstockbilldetailid")).get(0);
+            }else{
+                return getErrReturnObject().setErrMsg("调拨单明细不存在").toString();
+            }
+            if (st_dbstockbillid!=0 && st_dbstockbillid!=st_dbstockbilldetail.getLong("st_dbstockbillid")) {
+                return getErrReturnObject().setErrMsg("不能同时选择两个调拨单进行收货确认").toString();
+            } else {
+                st_dbstockbillid = st_dbstockbilldetail.getLong("st_dbstockbillid");
+            }
+            int recqty =jsonObject.getIntValue("recqty");// 收货确认数量
+            int undeliqty = st_dbstockbilldetail.getInteger("undeliqty");// 未入库数量
+            if (recqty>undeliqty) {
+                return getErrReturnObject().setErrMsg("收货确认数量不能大于未入库数量").toString();
+            }
+            if(jsonObject.getJSONArray("skuinfos").size()>0){
+                if (recqty!=jsonObject.getJSONArray("skuinfos").size()) {
+                    return getErrReturnObject().setErrMsg("机器码数量与收货确认数量不匹配").toString();
+                }
+            }
+            Rows skurows = dbConnect.runSqlQuery("select * from sa_itemsku where siteid='"+siteid+"' and ifnull(st_dbstockbillid,0)>0 ");
+            RowsMap skuRowsMap =skurows.toRowsMap("sku");
+            for(Object skuinfo : jsonObject.getJSONArray("skuinfos")){
+               if(!skuRowsMap.containsKey(((JSONObject)skuinfo).getString("sku"))){
+                   return getErrReturnObject().setErrMsg("序列号" + ((JSONObject)skuinfo).getString("sku") + "不存在或者已经确认收货").toString();
+               }
+            }
+
+            st_dbstockbilldetail.put("qty",recqty);
+            st_dbstockbilldetail.put("skuinfos",jsonObject.getJSONArray("skuinfos"));
+            dbstockbilldetail.add(st_dbstockbilldetail);
+
+        }
+        ArrayList<String> sqllist=new ArrayList<>();
+        InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+        long st_stockbillid =  createTableID("st_stockbill");
+        insertSQL.setUniqueid(st_stockbillid);
+        insertSQL.setSiteid(siteid);
+        insertSQL.setValue("billno", createBillCode("stockbill"));
+        insertSQL.setValue("type", "其他入库");
+        insertSQL.setValue("typemx", "调拨入库");
+        insertSQL.setValue("rb", 1);
+        insertSQL.setValue("sys_enterpriseid",0);
+        insertSQL.setValue("sourceobject", "st_dbstockbill");
+        insertSQL.setValue("sourceid", st_dbstockbillid);
+        insertSQL.setValue("stockid", rows.get(0).getLong("instockid"));
+        insertSQL.setValue("remarks", "收货确认入库");
+        insertSQL.setValue("status", "审核");
+        insertSQL.setValue("createby",username);
+        insertSQL.setDateValue("createdate");
+        insertSQL.setValue("checkby",username);
+        insertSQL.setDateValue("checkdate");
+        insertSQL.setDateValue("billdate");
+        sqllist.add(insertSQL.getSQL());
+        int j=1;
+        for(Row row:dbstockbilldetail){
+            insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
+            long st_stockbill_itemsid =  createTableID("st_stockbill_items");
+            insertSQL.setUniqueid(st_stockbill_itemsid);
+            insertSQL.setValue("rowno",j);
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("sa_dispatch_itemsid",0);
+            insertSQL.setValue("sourceobject", "st_dbstockbilldetail");
+            insertSQL.setValue("sourceid", row.getLong("st_dbstockbilldetailid"));
+            insertSQL.setValue("stockid", row.getLong("instockid"));
+            insertSQL.setValue("itemid",row.getLong("itemid"));
+            insertSQL.setValue("itemno",row.getString("itemno"));
+            insertSQL.setValue("itemname",row.getString("itemname"));
+            insertSQL.setValue("model",row.getString("model"));
+            insertSQL.setValue("qty",row.getBigDecimal("qty"));
+            insertSQL.setValue("st_stockbillid",st_stockbillid);
+            sqllist.add(insertSQL.getSQL());
+            j++;
+            for(Object objectdetail:row.getJSONArray("skuinfos")){
+                JSONObject rowdetail = (JSONObject)objectdetail;
+                insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
+                long st_stockbill_items_skuid =  createTableID("st_stockbill_items_sku");
+                insertSQL.setUniqueid(st_stockbill_items_skuid);
+                insertSQL.setSiteid(siteid);
+                insertSQL.setValue("stockid", row.getLong("instockid"));
+                insertSQL.setValue("itemid",row.getLong("itemid"));
+                insertSQL.setValue("sku",rowdetail.getString("sku"));
+                insertSQL.setValue("st_stockbillid",st_stockbillid);
+                insertSQL.setValue("st_stockbill_itemsid",st_stockbill_itemsid);
+                sqllist.add(insertSQL.getSQL());
+                sqllist.add("update sa_itemsku set stockid="+row.getLong("instockid")+",st_dbstockbillid=0,st_dbstockbilldetailid=0 where sku='"+rowdetail.getString("sku")+"'");
+            }
+        }
+        sqllist.addAll(updateIcinvbal(true,true,dbstockbilldetail));
+        sqllist.addAll(updateUnInQty(true,dbstockbilldetail));
+        dbConnect.runSqlUpdate(sqllist);
+        return getSucReturnObject().toString();
+    }
+
+    public  ArrayList<String> updateIcinvbal(boolean ischeck,boolean isinstock,Rows dbstockbilldetail) throws YosException {
+        ArrayList<String> sqlList =new ArrayList();
+        ArrayList<Long> itemids = new ArrayList<Long>();
+        itemids = dbstockbilldetail.toArrayList("itemid",new ArrayList<>());
+        itemids.add((long) 0);
+        int i = 0;
+        String sql="select * from st_invbal where itemid in"+itemids;
+        sql = sql.replace("[", "(").replace("]", ")");
+        Rows invbals =  dbConnect.runSqlQuery(sql);
+        RowsMap invbalsRowsMap=invbals.toRowsMap("itemid");
+        RowsMap invbalsSaleRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal_sale").setWhere("siteid", siteid).setWhere("itemid", itemids).query().toRowsMap("itemid");
+        for(Row row : dbstockbilldetail){
+            String itemid = row.getString("itemid");
+            //String batchno = row.getString("batchno");
+            //String fdcspno = row.getString("fdcspno");
+            long stockid;
+
+            if ((ischeck && isinstock) || (!ischeck && !isinstock)) {
+                stockid = row.getLong("instockid");
+            }else{
+                stockid = row.getLong("outstockid");
+            }
+
+//             if (type == 1 && !getSysVars().getBoolean("FISBATCHFORXC")) {
+//                 fdcspno = "**********";
+//                 fbatchno = "**********";
+//                 fstockno = getPaoSet("TDEPARTMENT").getPao(0)
+//                         .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
+//                 icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
+//                         "fitemno='" + fitemno + "' and fstockno='" + fstockno
+//                                 + "' and fdcspno='" + fdcspno
+//                                 + "' and fbatchno='" + fbatchno + "'");
+//             } else if (type == 2 && !getSysVars().getBoolean("FISBATCHFORXC")) {
+//                 fdcspno = "**********";
+//                 fbatchno = "**********";
+//                 fstockno = getPaoSet("TSUPPLIER").getPao(0)
+//                         .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
+//                 icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
+//                         "fitemno='" + fitemno + "' and fstockno='" + fstockno
+//                                 + "' and fdcspno='" + fdcspno
+//                                 + "' and fbatchno='" + fbatchno + "'");
+//             }
+            BigDecimal qty = isinstock ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
+            if(!invbalsRowsMap.containsKey(itemid)){
+                SQLFactory sqlFactory = new SQLFactory(this, "即时库存新增");
+                sqlFactory.addParameter("st_invbalid", createTableID("st_invbal"));
+                sqlFactory.addParameter("qty", qty);
+                sqlFactory.addParameter("itemid", itemid);
+                sqlFactory.addParameter("stockid", stockid);
+                sqlFactory.addParameter("siteid",siteid);
+                sqlFactory.addParameter("userid", userid);
+                sqlFactory.addParameter("username", username);
+                sqlList.add(sqlFactory.getSQL());
+            }else{
+                if(invbalsRowsMap.get(itemid).toRowsMap("stockid").containsKey(stockid)){
+                    SQLFactory sqlFactory = new SQLFactory(this, "即时库存更新");
+                    sqlFactory.addParameter("st_invbalid", createTableID("st_invbal"));
+                    sqlFactory.addParameter("qty", invbalsRowsMap.get(itemid).toRowsMap("stockid").get(stockid).get(0).getBigDecimal("qty").add(qty));
+                    sqlFactory.addParameter("itemid", itemid);
+                    sqlFactory.addParameter("stockid", stockid);
+                    sqlFactory.addParameter("siteid",siteid);
+                    sqlFactory.addParameter("userid", userid);
+                    sqlFactory.addParameter("username", username);
+                    sqlList.add(sqlFactory.getSQL());
+                }else{
+                    SQLFactory sqlFactory = new SQLFactory(new Invbal(), "即时库存新增");
+                    sqlFactory.addParameter("st_invbalid", createTableID("st_invbal"));
+                    sqlFactory.addParameter("qty", qty);
+                    sqlFactory.addParameter("itemid", itemid);
+                    sqlFactory.addParameter("stockid", stockid);
+                    System.err.println(stockid);
+                    sqlFactory.addParameter("siteid",siteid);
+                    sqlFactory.addParameter("userid", userid);
+                    sqlFactory.addParameter("username", username);
+                    sqlList.add(sqlFactory.getSQL());
+                }
+            }
+
+            //是否为销售仓库
+            if (SQLFactory.getRow(this, "st_stock", stockid).getBoolean("issalestock")) {
+                if (!invbalsSaleRowsMap.containsKey(String.valueOf(itemid))) {
+                    InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal_sale");
+                    invbalInsert.setValue("siteid", siteid);
+                    invbalInsert.setValue("itemid", itemid);
+                    invbalInsert.setValue("cansaleqty", qty.doubleValue());//可销售数量
+                    invbalInsert.setValue("candispatchqty", qty.doubleValue());//可发货数量
+                    invbalInsert.setValue("qty", qty.doubleValue());//库存数量
+                    sqlList.add(invbalInsert.getSQL());
+                } else {
+                    UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal_sale");
+                    invbalUpdate.addValue("qty", invbalsSaleRowsMap.get(String.valueOf(itemid)).get(0).getBigDecimal("qty").add(qty));//库存数量
+                    invbalUpdate.setWhere("itemid", itemid);
+                    invbalUpdate.setWhere("siteid", siteid);
+                    sqlList.add(invbalUpdate.getSQL());
+                }
+
+            }
+        }
+        return sqlList;
+    }
+
+    public ArrayList<String> updateUnInQty( boolean ischeck, Rows dbstockbilldetail) {
+        ArrayList<String> sqllist =new ArrayList<>();
+        for(Row row : dbstockbilldetail){
+            if (ischeck) {// 审核
+                sqllist.add("update st_dbstockbilldetail  set undeliqty=undeliqty-"+row.getInteger("recqty")+" where st_dbstockbilldetailid='"+row.getString("st_dbstockbilldetailid")+"'");
+            } else {// 反审核
+                sqllist.add("update st_dbstockbilldetail set undeliqty="+row.getBigDecimal("qty")+" where st_dbstockbilldetailid='"+row.getString("st_dbstockbilldetailid")+"'");
+            }
+        }
+        return sqllist;
+    }
+}