فهرست منبع

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

# Conflicts:
#	src/custom/restcontroller/R.java
#	src/custom/restcontroller/webmanage/sale/invbal/invbal.java
eganwu 1 سال پیش
والد
کامیت
0b3e6a3866

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

@@ -5425,6 +5425,11 @@ public class R {
         }
     }
 
+    public static class ID20231228102402 {
+        public static class v1 {
+        }
+    }
+
     public static class ID20231225141902 {
         public static class v1 {
         }

+ 49 - 45
src/custom/restcontroller/sale/favorites/favorites.java

@@ -13,6 +13,7 @@ import common.data.Rows;
 import common.data.RowsMap;
 import common.data.SQLFactory;
 
+import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 import restcontroller.webmanage.sale.itemgroup.itemgroup;
 
@@ -34,24 +35,24 @@ public class favorites extends Controller {
      *
      * @return
      */
-    @API(title = "商品收藏", apiversion = R.ID20231121143403.v1.class,intervaltime = 200)
-    @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class,favorites.class})
+    @API(title = "商品收藏", apiversion = R.ID20231121143403.v1.class, intervaltime = 200)
+    @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class, favorites.class})
     public String insertormodify_item() throws YosException {
         long itemid = content.getLongValue("itemid");
-        boolean iscollection=content.getBooleanValue("iscollection");
-        BigDecimal qty =content.getBigDecimalValue("qty");
-        BigDecimal width =content.getBigDecimalValue("width");
-        BigDecimal length =content.getBigDecimalValue("length");
-        Rows favoritesRows = dbConnect.runSqlQuery("select * from sa_favorites where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "' and itemid='"+itemid+"'");
+        boolean iscollection = content.getBooleanValue("iscollection");
+        BigDecimal qty = content.getBigDecimalValue("qty");
+        BigDecimal width = content.getBigDecimalValue("width");
+        BigDecimal length = content.getBigDecimalValue("length");
+        Rows favoritesRows = dbConnect.runSqlQuery("select * from sa_favorites where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "' and itemid='" + itemid + "'");
         ArrayList<String> sqllist = new ArrayList<>();
         SQLFactory sqlAddFactory = new SQLFactory(this, "商品收藏记录新增");
-        if(favoritesRows.isEmpty()){
+        if (favoritesRows.isEmpty()) {
             sqlAddFactory.addParameter("itemid", itemid);
             sqlAddFactory.addParameter("sa_favoritesid", createTableID("sa_favorites"));
             sqlAddFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
             sqlAddFactory.addParameter("iscollection", iscollection);
             sqlAddFactory.addParameter("siteid", siteid);
-        }else{
+        } else {
             sqlAddFactory = new SQLFactory(this, "商品收藏记录更新");
             sqlAddFactory.addParameter("sa_favoritesid", favoritesRows.get(0).getLong("sa_favoritesid"));
             sqlAddFactory.addParameter("iscollection", iscollection);
@@ -71,11 +72,11 @@ public class favorites extends Controller {
      *
      * @return
      */
-    @API(title = "商品批量收藏", apiversion = R.ID20231122102803.v1.class,intervaltime = 200)
-    @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class,favorites.class})
+    @API(title = "商品批量收藏", apiversion = R.ID20231122102803.v1.class, intervaltime = 200)
+    @CACHEING_CLEAN(apiClass = {itemgroup.class, restcontroller.sale.itemgroup.itemgroup.class, favorites.class})
     public String items_collect() throws YosException {
         JSONArray itemids = content.getJSONArray("itemids");
-        boolean iscollection=content.getBooleanValue("iscollection");
+        boolean iscollection = content.getBooleanValue("iscollection");
         ArrayList<String> sqllist = new ArrayList<>();
         SQLFactory sqlFactory = new SQLFactory(this, "商品收藏记录批量更新");
         sqlFactory.addParameter_in("itemids", itemids.toArray());
@@ -116,15 +117,15 @@ public class favorites extends Controller {
         RowsMap pricerowsMap = pricerows.toRowsMap("itemid");
 
         SQLFactory sqlFactory = new SQLFactory(this, "查询收藏商品列表", pageSize, pageNumber, pageSorting);
-        sqlFactory.addParameter_SQL("where",where);
+        sqlFactory.addParameter_SQL("where", where);
         sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
         sqlFactory.addParameter("siteid", siteid);
         Rows itemrows = dbConnect.runSqlQuery(sqlFactory.getSQL());
 
-        Rows sizecustomizedschemes=dbConnect.runSqlQuery("select * from sa_sizecustomizedscheme where siteid='"+siteid+"' ");
-        RowsMap sizecustomizedschemesRowsMap=sizecustomizedschemes.toRowsMap("sa_sizecustomizedschemeid");
-        Rows sizeschemedetails=dbConnect.runSqlQuery("select * from sa_sizeschemedetail where siteid='"+siteid+"' ");
-        RowsMap sizeschemedetailsRowsMap=sizeschemedetails.toRowsMap("sa_sizecustomizedschemeid");
+        Rows sizecustomizedschemes = dbConnect.runSqlQuery("select * from sa_sizecustomizedscheme where siteid='" + siteid + "' ");
+        RowsMap sizecustomizedschemesRowsMap = sizecustomizedschemes.toRowsMap("sa_sizecustomizedschemeid");
+        Rows sizeschemedetails = dbConnect.runSqlQuery("select * from sa_sizeschemedetail where siteid='" + siteid + "' ");
+        RowsMap sizeschemedetailsRowsMap = sizeschemedetails.toRowsMap("sa_sizecustomizedschemeid");
 
         for (Row row : itemrows) {
             ItemPrice itemPrice = ItemPrice.getItemPrice(this, sys_enterpriseid, row.getLong("itemid"));
@@ -132,45 +133,45 @@ public class favorites extends Controller {
             if (sys_enterpriseid > 0 || (usertype == 21 || usertype == 22)) {
                 row.put("gradeprice", itemPrice.getContractprice());
             } else {
-                if(pricerowsMap.containsKey(row.getString("itemid"))){
-                    if(pricerowsMap.get(row.getString("itemid")).isNotEmpty()){
+                if (pricerowsMap.containsKey(row.getString("itemid"))) {
+                    if (pricerowsMap.get(row.getString("itemid")).isNotEmpty()) {
                         row.put("gradeprice", pricerowsMap.get(row.getString("itemid")).get(0).getBigDecimal("price"));
-                    }else{
-                        row.put("gradeprice",0);
+                    } else {
+                        row.put("gradeprice", 0);
                     }
-                }else {
+                } else {
                     row.put("gradeprice", 0);
                 }
             }
 
-            if(row.getLong("widthschemeid")!=0){
-                if(sizecustomizedschemesRowsMap.containsKey(row.getString("widthschemeid"))){
-                    if(sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).isNotEmpty()){
-                        row.put("widthtype",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getString("type"));
-                        row.put("widthmin",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("min"));
-                        row.put("widthmax",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("max"));
-                        row.put("widthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("decimalplaces"));
-                        if(sizeschemedetailsRowsMap.containsKey(row.getString("widthschemeid"))){
-                            row.put("widthschemedetails",sizeschemedetailsRowsMap.get(row.getString("widthschemeid")));
-                        }else{
-                            row.put("widthschemedetails",new JSONArray());
+            if (row.getLong("widthschemeid") != 0) {
+                if (sizecustomizedschemesRowsMap.containsKey(row.getString("widthschemeid"))) {
+                    if (sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).isNotEmpty()) {
+                        row.put("widthtype", sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getString("type"));
+                        row.put("widthmin", sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("min"));
+                        row.put("widthmax", sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("max"));
+                        row.put("widthdecimalplaces", sizecustomizedschemesRowsMap.get(row.getString("widthschemeid")).get(0).getBigDecimal("decimalplaces"));
+                        if (sizeschemedetailsRowsMap.containsKey(row.getString("widthschemeid"))) {
+                            row.put("widthschemedetails", sizeschemedetailsRowsMap.get(row.getString("widthschemeid")));
+                        } else {
+                            row.put("widthschemedetails", new JSONArray());
                         }
 
                     }
 
                 }
             }
-            if(row.getLong("lengthschemeid")!=0){
-                if(sizecustomizedschemesRowsMap.containsKey(row.getString("lengthschemeid"))){
-                    if(sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).isNotEmpty()){
-                        row.put("lengthtype",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getString("type"));
-                        row.put("lengthmin",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("min"));
-                        row.put("lengthmax",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("max"));
-                        row.put("lengthdecimalplaces",sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("decimalplaces"));
-                        if(sizeschemedetailsRowsMap.containsKey(row.getString("lengthschemeid"))){
-                            row.put("lengthschemedetails",sizeschemedetailsRowsMap.get(row.getString("lengthschemeid")));
-                        }else{
-                            row.put("lengthschemedetails",new JSONArray());
+            if (row.getLong("lengthschemeid") != 0) {
+                if (sizecustomizedschemesRowsMap.containsKey(row.getString("lengthschemeid"))) {
+                    if (sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).isNotEmpty()) {
+                        row.put("lengthtype", sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getString("type"));
+                        row.put("lengthmin", sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("min"));
+                        row.put("lengthmax", sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("max"));
+                        row.put("lengthdecimalplaces", sizecustomizedschemesRowsMap.get(row.getString("lengthschemeid")).get(0).getBigDecimal("decimalplaces"));
+                        if (sizeschemedetailsRowsMap.containsKey(row.getString("lengthschemeid"))) {
+                            row.put("lengthschemedetails", sizeschemedetailsRowsMap.get(row.getString("lengthschemeid")));
+                        } else {
+                            row.put("lengthschemedetails", new JSONArray());
                         }
                     }
 
@@ -215,7 +216,10 @@ public class favorites extends Controller {
                 row.put("attinfos", attRowsMap.getOrDefault(row.getString("itemid"), new Rows()));
             }
             row.put("itemclass", itemclassRowsMap.get(row.getString("itemid")));
-            row.put("tradefield", tradefieldRowsMap.get(row.getString("itemid")));
+            Rows tradefieldRows = tradefieldRowsMap.getOrDefault(row.getString("itemid"), new Rows());
+            row.put("tradefield", tradefieldRows);
+
+            row.put("tradefield_shoppingcart", StringUtils.join(tradefieldRows.toArray("tradefield"), ","));
             row.put("brand", brandRowsMap.get(row.getString("itemid")));
         }
 

+ 11 - 0
src/custom/restcontroller/webmanage/sale/invbal/SQL/查询手工关闭统计.sql

@@ -0,0 +1,11 @@
+SELECT DATE_FORMAT(t2.closedate, '%m') AS month, t1.itemid,sum((t1.qty-ifnull(t3.outwarehouseqty,0))) qty
+FROM sa_orderitems t1
+    INNER JOIN sa_order t2 ON t2.sa_orderid = t1.sa_orderid and t2.siteid=t1.siteid and t2.status in ('手工关闭')
+    LEFT JOIN (
+    SELECT itemid,sa_orderid,sum(outwarehouseqty) outwarehouseqty from sa_dispatch_items a
+    INNER JOIN sa_dispatch b ON b.sa_dispatchid=a.sa_dispatchid and b.siteid=a.siteid
+    GROUP BY itemid,sa_orderid
+    ) t3 ON t3.sa_orderid=t2.sa_orderid and t3.itemid=t1.itemid
+WHERE t2.closedate >= $begindate$ and t2.closedate <= $enddate$ and t1.siteid=$siteid$ and t1.itemid in $itemid$
+GROUP BY month,t1.itemid
+ORDER BY month DESC;

+ 7 - 0
src/custom/restcontroller/webmanage/sale/invbal/SQL/查询统计商品月销量销.sql

@@ -0,0 +1,7 @@
+SELECT DATE_FORMAT(t2.submitdate, '%m') AS month, sum(qty) AS qty,itemid
+FROM sa_orderitems t1
+    INNER JOIN sa_order t2
+ON t2.sa_orderid = t1.sa_orderid and t2.siteid=t1.siteid and t2.status in ('提交','审核','关闭','手工关闭')
+WHERE t2.submitdate >= $begindate$ and t2.submitdate <= $enddate$ and t1.siteid=$siteid$ and itemid in $itemid$
+GROUP BY month, itemid
+ORDER BY month DESC;

+ 7 - 0
src/custom/restcontroller/webmanage/sale/invbal/SQL/查询退货统计.sql

@@ -0,0 +1,7 @@
+SELECT DATE_FORMAT(t2.checkdate, '%m') AS month, sum(qty) AS qty,itemid
+from sa_aftersalesmag_items t1
+    INNER JOIN sa_aftersalesmag t2
+ON t2.sa_aftersalesmagid=t1.sa_aftersalesmagid and t2.siteid=t1.siteid and t2.`status`='审核'
+WHERE t2.checkdate >= $begindate$ and t2.checkdate <= $enddate$ and t1.siteid=$siteid$ and itemid in $itemid$
+GROUP BY month, itemid
+ORDER BY month DESC;

+ 496 - 260
src/custom/restcontroller/webmanage/sale/invbal/invbal.java

@@ -24,70 +24,71 @@ import common.data.RowsMap;
 import common.data.SQLFactory;
 import common.data.db.DBConnect;
 import org.apache.commons.lang.StringUtils;
+import org.apache.poi.hslf.dev.UserEditAndPersistListing;
 import restcontroller.R;
 import utility.ERPDocking;
 
 @API(title = "库存管理")
 public class invbal extends Controller {
 
-	public invbal(JSONObject content) throws YosException {
-		super(content);
-		// TODO Auto-generated constructor stub
-	}
+    public invbal(JSONObject content) throws YosException {
+        super(content);
+        // TODO Auto-generated constructor stub
+    }
+
+    public static HashMap<String, Long> itemhashmap = new HashMap<>(16);
+    public static HashMap<Long, String> itemnomap = new HashMap<>(16);
+
 
-	public static HashMap<String, Long> itemhashmap = new HashMap<>(16);
-	public static HashMap<Long, String> itemnomap = new HashMap<>(16);
-	
-	
     @API(title = "从erp新增更新库存", apiversion = R.ID20230222203603.v1.class)
     @CACHEING_CLEAN(apiversions = {R.ID20230222203803.class})
-	public String caculate() throws YosException {
-		JSONArray itemids = content.getJSONArray("itemids");
-		boolean rightnow = content.getBooleanValue("rightnow");
-		JSONArray erpitemnos = new JSONArray();
-		if (itemnomap.isEmpty()) {
-			Rows rows = dbConnect
-					.runSqlQuery("select itemid,erpitemno from plm_itemextend where siteid='" + siteid + "'");
-			for (Row row : rows) {
-				itemnomap.put(row.getLong("itemid"), row.getString("erpitemno"));
-			}
-		}
-
-		for (Object object : itemids) {
-			long itemid =((Integer)object).longValue();
-			if (itemnomap.containsKey(itemid)) {
-				erpitemnos.add(itemnomap.get(itemid));
-			} else {
-				Rows rows = dbConnect.runSqlQuery("select erpitemno from plm_itemextend where itemid='" + itemid
-						+ "' and siteid='" + siteid + "'");
-				if (!rows.isEmpty()) {
-					erpitemnos.add(rows.get(0).getString("erpitemno"));
-					itemnomap.put(itemid, rows.get(0).getString("erpitemno"));
-				}
-			}
-		}
-		 Invbal.caculate_erpitemno(this, erpitemnos, rightnow);
-		 return getSucReturnObject().toString();
-	}
-    
+    public String caculate() throws YosException {
+        JSONArray itemids = content.getJSONArray("itemids");
+        boolean rightnow = content.getBooleanValue("rightnow");
+        JSONArray erpitemnos = new JSONArray();
+        if (itemnomap.isEmpty()) {
+            Rows rows = dbConnect
+                    .runSqlQuery("select itemid,erpitemno from plm_itemextend where siteid='" + siteid + "'");
+            for (Row row : rows) {
+                itemnomap.put(row.getLong("itemid"), row.getString("erpitemno"));
+            }
+        }
+
+        for (Object object : itemids) {
+            long itemid = ((Integer) object).longValue();
+            if (itemnomap.containsKey(itemid)) {
+                erpitemnos.add(itemnomap.get(itemid));
+            } else {
+                Rows rows = dbConnect.runSqlQuery("select erpitemno from plm_itemextend where itemid='" + itemid
+                        + "' and siteid='" + siteid + "'");
+                if (!rows.isEmpty()) {
+                    erpitemnos.add(rows.get(0).getString("erpitemno"));
+                    itemnomap.put(itemid, rows.get(0).getString("erpitemno"));
+                }
+            }
+        }
+        Invbal.caculate_erpitemno(this, erpitemnos, rightnow);
+        return getSucReturnObject().toString();
+    }
+
     @API(title = "从erp新增更新库存(站点全部)", apiversion = R.ID20230222203703.v1.class)
     @CACHEING_CLEAN(apiversions = {R.ID20230222203803.class})
-    public  String caculateAll() throws YosException {
-		if (itemnomap.isEmpty()) {
-			Rows rows = dbConnect
-					.runSqlQuery("select itemid,erpitemno from plm_itemextend where siteid='" + siteid + "'");
-			for (Row row : rows) {
-				itemnomap.put(row.getLong("itemid"), row.getString("erpitemno"));
-			}
-		}
-		Invbal.caculate_erpitemno(this);
-		 return getSucReturnObject().toString();
-	}
-    
-    
+    public String caculateAll() throws YosException {
+        if (itemnomap.isEmpty()) {
+            Rows rows = dbConnect
+                    .runSqlQuery("select itemid,erpitemno from plm_itemextend where siteid='" + siteid + "'");
+            for (Row row : rows) {
+                itemnomap.put(row.getLong("itemid"), row.getString("erpitemno"));
+            }
+        }
+        Invbal.caculate_erpitemno(this);
+        return getSucReturnObject().toString();
+    }
+
+
     @API(title = "查询库存列表", apiversion = R.ID20230222203803.v1.class)
     public String queryInvbalList() throws YosException {
-    	boolean istotal = content.getBooleanValue("istotal");
+        boolean istotal = content.getBooleanValue("istotal");
         StringBuffer where = new StringBuffer(" 1=1 ");
         if (content.containsKey("where")) {
             JSONObject whereObject = content.getJSONObject("where");
@@ -101,116 +102,116 @@ public class invbal extends Controller {
             }
         }
         SQLFactory sqlFactory;
-        if(istotal) {
-        	 sqlFactory = new SQLFactory(this, "销售库存列表查询", pageSize, pageNumber, pageSorting);
-        }else {
-        	 sqlFactory = new SQLFactory(this, "即时库存列表查询", pageSize, pageNumber, pageSorting);
-		}
-        
+        if (istotal) {
+            sqlFactory = new SQLFactory(this, "销售库存列表查询", pageSize, pageNumber, pageSorting);
+        } else {
+            sqlFactory = new SQLFactory(this, "即时库存列表查询", pageSize, pageNumber, pageSorting);
+        }
+
         sqlFactory.addParameter("siteid", siteid);
         sqlFactory.addParameter_SQL("where", where);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
         return getSucReturnObject().setData(rows).toString();
     }
 
-	@API(title = "查询Erp库存列表", apiversion = R.ID20230408091703.v1.class)
-	public String queryErpInvbalList() throws YosException, IOException {
-		boolean isExport = content.getBooleanValue("isExport");
-		//String iteminfo = content.getStringValue("iteminfo");
-		//String agentinfo = content.getStringValue("agentinfo");
-		//boolean all = content.getBooleanValue("all");
-		//JSONArray itemclassids = content.getJSONArray("itemclassids");
-		String where =" 1=1 ";
-		SQLFactory sqlFactory =new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
-		if (isExport) {
-			sqlFactory = new SQLFactory(this,"商品列表");
-		}
-		if (content.containsKey("where")) {
-			JSONObject whereObject = content.getJSONObject("where");
-			if(whereObject.containsKey("iteminfo")){
-				if(!StringUtils.isBlank(whereObject.getStringValue("iteminfo"))){
-					where=where+" and (t2.itemno like '%"+whereObject.getStringValue("iteminfo")+"%' or t2.itemname like '%"+whereObject.getStringValue("iteminfo")+"%') ";
-				}
-			}
-			if(whereObject.containsKey("itemclassids")){
-				if (whereObject.getLong("itemclassids")!=0) {
-					ArrayList<Long> itemclassList = new ArrayList<Long>();
-					//System.out.println(row.getLong("itemclassid"));
-					long itemclassid = whereObject.getLong("itemclassids");
-					itemclassList.add(itemclassid);
-					itemclassList.addAll(ItemClass.getSubItemClassIds(this,itemclassid));
-					String sql = " and t2.itemid in ( SELECT itemid from sa_itemsaleclass WHERE itemclassid IN " + itemclassList + "  and siteid='" + siteid + "')";
-					sql = sql.replace("[", "(").replace("]", ")");
-					where=where+sql;
-				}
-			}
+    @API(title = "查询Erp库存列表", apiversion = R.ID20230408091703.v1.class)
+    public String queryErpInvbalList() throws YosException, IOException {
+        boolean isExport = content.getBooleanValue("isExport");
+        //String iteminfo = content.getStringValue("iteminfo");
+        //String agentinfo = content.getStringValue("agentinfo");
+        //boolean all = content.getBooleanValue("all");
+        //JSONArray itemclassids = content.getJSONArray("itemclassids");
+        String where = " 1=1 ";
+        SQLFactory sqlFactory = new SQLFactory(this, "商品列表", pageSize, pageNumber, pageSorting);
+        if (isExport) {
+            sqlFactory = new SQLFactory(this, "商品列表");
+        }
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("iteminfo")) {
+                if (!StringUtils.isBlank(whereObject.getStringValue("iteminfo"))) {
+                    where = where + " and (t2.itemno like '%" + whereObject.getStringValue("iteminfo") + "%' or t2.itemname like '%" + whereObject.getStringValue("iteminfo") + "%') ";
+                }
+            }
+            if (whereObject.containsKey("itemclassids")) {
+                if (whereObject.getLong("itemclassids") != 0) {
+                    ArrayList<Long> itemclassList = new ArrayList<Long>();
+                    //System.out.println(row.getLong("itemclassid"));
+                    long itemclassid = whereObject.getLong("itemclassids");
+                    itemclassList.add(itemclassid);
+                    itemclassList.addAll(ItemClass.getSubItemClassIds(this, itemclassid));
+                    String sql = " and t2.itemid in ( SELECT itemid from sa_itemsaleclass WHERE itemclassid IN " + itemclassList + "  and siteid='" + siteid + "')";
+                    sql = sql.replace("[", "(").replace("]", ")");
+                    where = where + sql;
+                }
+            }
 
-			if (whereObject.containsKey("all") && !"".equals(whereObject.getString("all"))) {
-				if(!whereObject.getBooleanValue("all")){
-					where = where+" and 1=2 ";
-				}
-			}
-			if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
-				where = where+" and t2.isonsale ='"+whereObject.getString("isonsale") + "' ";
-			}
-			if(whereObject.containsKey("agentinfo")){
-				if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
-					sqlFactory =new SQLFactory(this,"订单明细未发商品列表", pageSize, pageNumber, pageSorting);
-					if (isExport) {
-						sqlFactory = new SQLFactory(this,"订单明细未发商品列表");
-					}
-					//System.out.println(StringUtils.isBlank(itemname) && StringUtils.isBlank(itemno) && itemclassids.size()==0);
-					if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
-						where=where+" and (t6.agentnum like '%"+whereObject.getStringValue("agentinfo")+"%' or t5.enterprisename like '%"+whereObject.getStringValue("agentinfo")+"%') ";
-					}
-				}
-			}
-
-		}
-
-		sqlFactory.addParameter("siteid", siteid);
-		sqlFactory.addParameter_SQL("where", where);
-		//System.out.println(sqlFactory.getSQL());
-		Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
-		Rows rowsitemclass = dbConnect.runSqlQuery(" select  t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 LEFT JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='" + siteid + "'");
-		RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
-
-		RowsMap rowsMap =rows.toRowsMap("itemno");
-
-
-		SQLFactory sqlFactory1 =new SQLFactory(this,"商品发货数量汇总");
-		sqlFactory1.addParameter("siteid", siteid);
-		where=" 1=1 ";
-		sqlFactory1.addParameter_SQL("where", where);
-		Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
-		RowsMap sumAllQtyRowsMap= sumQtyRows.toRowsMap("itemno");
-		if (content.containsKey("where")) {
-			JSONObject whereObject = content.getJSONObject("where");
-			if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
-				where=where+" and (t6.agentnum like '%"+whereObject.getStringValue("agentinfo")+"%' or t5.enterprisename like '%"+whereObject.getStringValue("agentinfo")+"%') ";
-			}
-		}
-
-		sqlFactory1.addParameter_SQL("where", where);
-		sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
-		RowsMap sumQtyRowsMap= sumQtyRows.toRowsMap("itemno");
-
-		SQLFactory sqlFactory2 =new SQLFactory(this,"商品未发货数量汇总");
-		sqlFactory2.addParameter("siteid", siteid);
-		where=" 1=1 ";
-		sqlFactory2.addParameter_SQL("where", where);
-		Rows sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
-		RowsMap sumUnAllQtyRowsMap= sumUnQtyRows.toRowsMap("itemno");
-		if (content.containsKey("where")) {
-			JSONObject whereObject = content.getJSONObject("where");
-			if(!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))){
-				where=where+" and (t6.agentnum like '%"+whereObject.getStringValue("agentinfo")+"%' or t5.enterprisename like '%"+whereObject.getStringValue("agentinfo")+"%') ";
-			}
-		}
-
-		sqlFactory2.addParameter_SQL("where", where);
-		sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
-		RowsMap sumUnQtyRowsMap= sumUnQtyRows.toRowsMap("itemno");
+            if (whereObject.containsKey("all") && !"".equals(whereObject.getString("all"))) {
+                if (!whereObject.getBooleanValue("all")) {
+                    where = where + " and 1=2 ";
+                }
+            }
+            if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
+                where = where + " and t2.isonsale ='" + whereObject.getString("isonsale") + "' ";
+            }
+            if (whereObject.containsKey("agentinfo")) {
+                if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                    sqlFactory = new SQLFactory(this, "订单明细未发商品列表", pageSize, pageNumber, pageSorting);
+                    if (isExport) {
+                        sqlFactory = new SQLFactory(this, "订单明细未发商品列表");
+                    }
+                    //System.out.println(StringUtils.isBlank(itemname) && StringUtils.isBlank(itemno) && itemclassids.size()==0);
+                    if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                        where = where + " and (t6.agentnum like '%" + whereObject.getStringValue("agentinfo") + "%' or t5.enterprisename like '%" + whereObject.getStringValue("agentinfo") + "%') ";
+                    }
+                }
+            }
+
+        }
+
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter_SQL("where", where);
+        //System.out.println(sqlFactory.getSQL());
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+        Rows rowsitemclass = dbConnect.runSqlQuery(" select  t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 LEFT JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='" + siteid + "'");
+        RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
+
+        RowsMap rowsMap = rows.toRowsMap("itemno");
+
+
+        SQLFactory sqlFactory1 = new SQLFactory(this, "商品发货数量汇总");
+        sqlFactory1.addParameter("siteid", siteid);
+        where = " 1=1 ";
+        sqlFactory1.addParameter_SQL("where", where);
+        Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
+        RowsMap sumAllQtyRowsMap = sumQtyRows.toRowsMap("itemno");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                where = where + " and (t6.agentnum like '%" + whereObject.getStringValue("agentinfo") + "%' or t5.enterprisename like '%" + whereObject.getStringValue("agentinfo") + "%') ";
+            }
+        }
+
+        sqlFactory1.addParameter_SQL("where", where);
+        sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
+        RowsMap sumQtyRowsMap = sumQtyRows.toRowsMap("itemno");
+
+        SQLFactory sqlFactory2 = new SQLFactory(this, "商品未发货数量汇总");
+        sqlFactory2.addParameter("siteid", siteid);
+        where = " 1=1 ";
+        sqlFactory2.addParameter_SQL("where", where);
+        Rows sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
+        RowsMap sumUnAllQtyRowsMap = sumUnQtyRows.toRowsMap("itemno");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                where = where + " and (t6.agentnum like '%" + whereObject.getStringValue("agentinfo") + "%' or t5.enterprisename like '%" + whereObject.getStringValue("agentinfo") + "%') ";
+            }
+        }
+
+        sqlFactory2.addParameter_SQL("where", where);
+        sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
+        RowsMap sumUnQtyRowsMap = sumUnQtyRows.toRowsMap("itemno");
 
 
 		ERPDocking erpDocking =new ERPDocking(siteid);
@@ -223,114 +224,349 @@ public class invbal extends Controller {
 					jsonArray=erpDocking.getErpIcinvbalRows(200000, 1,new JSONArray());
 				}
 
-			}
-		}
+            }
+        }
 
-		if(!jsonArray.isEmpty()){
+        if (!jsonArray.isEmpty()) {
 
-			for (Object object:jsonArray) {
-				JSONObject jsonObject =(JSONObject)object;
-				if(rowsMap.containsKey(jsonObject.getString("fitemno"))){
-					if(rowsMap.get(jsonObject.getString("fitemno")).isNotEmpty()){
-						rowsMap.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
-					}
-				}
-			}
-		}
-		for (Row row:rows) {
-			String itemclass=itemclassRowsMap.get(row.getString("itemid")).toJsonArray("itemclassname").toString().substring(1,itemclassRowsMap.get(row.getString("itemid")).toJsonArray("itemclassname").toString().length()-1);
-			row.put("itemclass", itemclass.replaceAll("\"", ""));
-			if(sumQtyRowsMap.get(row.getString("itemno")).isNotEmpty()){
-				row.put("unsoldqty", sumQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
-			}else {
-				row.put("unsoldqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
-			}
-			if(sumUnQtyRowsMap.get(row.getString("itemno")).isNotEmpty()){
-				row.put("undelqty", sumUnQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
-				row.put("qty", sumUnQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
-			}else {
-				row.put("undelqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
-				row.put("qty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
-			}
-			if(sumUnAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()){
-				row.put("undelqtysum", sumUnAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
-			}else {
-				row.put("undelqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
-			}
-			if(sumAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()){
-				row.put("unsoldqtysum", sumAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
-			}else {
-				row.put("unsoldqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
-			}
-
-			if(!row.containsKey("invbalqty")){
-				row.put("invbalqty",BigDecimal.ZERO.stripTrailingZeros().toPlainString());
-			}
-
-		}
-		for (Row row:rows) {
-
-			row.put("canbesent", (row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).stripTrailingZeros().toPlainString());
-			row.put("canbesale", ((row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).subtract(row.getBigDecimal("undelqtysum"))).stripTrailingZeros().toPlainString());
-			if(row.getString("itemno").equals("10901371")){
-				System.out.println(row.getString("canbesent"));
-				System.out.println(row.getString("canbesale"));
-				System.out.println(row.toJsonObject().toJSONString());
-			}
-		}
-		if(isExport){
-			//去除不需要导出项
-			rows.getFieldList().remove("itemid");
-			rows.getFieldList().remove("packageqty");
-			rows.getFieldList().remove("qty");
-			for (Row row:rows) {
-				if(row.getString("itemno").equals("10901371")){
-					System.out.println(row.getString("canbesent"));
-					System.out.println(row.getString("canbesale"));
-					System.out.println(row.toJsonObject().toJSONString());
-				}
+            for (Object object : jsonArray) {
+                JSONObject jsonObject = (JSONObject) object;
+                if (rowsMap.containsKey(jsonObject.getString("fitemno"))) {
+                    if (rowsMap.get(jsonObject.getString("fitemno")).isNotEmpty()) {
+                        rowsMap.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
+                    }
+                }
+            }
+        }
+        for (Row row : rows) {
+            String itemclass = itemclassRowsMap.get(row.getString("itemid")).toJsonArray("itemclassname").toString().substring(1, itemclassRowsMap.get(row.getString("itemid")).toJsonArray("itemclassname").toString().length() - 1);
+            row.put("itemclass", itemclass.replaceAll("\"", ""));
+            if (sumQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("unsoldqty", sumQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("unsoldqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+            if (sumUnQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("undelqty", sumUnQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
+                row.put("qty", sumUnQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("undelqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+                row.put("qty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+            if (sumUnAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("undelqtysum", sumUnAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("undelqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+            if (sumAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("unsoldqtysum", sumAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("unsoldqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+
+            if (!row.containsKey("invbalqty")) {
+                row.put("invbalqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+
+        }
+        for (Row row : rows) {
+
+            row.put("canbesent", (row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).stripTrailingZeros().toPlainString());
+            row.put("canbesale", ((row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).subtract(row.getBigDecimal("undelqtysum"))).stripTrailingZeros().toPlainString());
+//            if (row.getString("itemno").equals("10901371")) {
+//                System.out.println(row.getString("canbesent"));
+//                System.out.println(row.getString("canbesale"));
+//                System.out.println(row.toJsonObject().toJSONString());
+//            }
+        }
+        if (isExport) {
+            //去除不需要导出项
+            rows.getFieldList().remove("itemid");
+            rows.getFieldList().remove("packageqty");
+            rows.getFieldList().remove("qty");
+//            for (Row row : rows) {
+//                if (row.getString("itemno").equals("10901371")) {
+//                    System.out.println(row.getString("canbesent"));
+//                    System.out.println(row.getString("canbesale"));
+//                    System.out.println(row.toJsonObject().toJSONString());
+//                }
+//
+//            }
+            Rows uploadRows = uploadExcelToObs("invbal", "库存列表", rows, getTitleMap());
+            return getSucReturnObject().setData(uploadRows).toString();
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
 
-			}
-			Rows uploadRows = uploadExcelToObs("invbal", "库存列表", rows, getTitleMap());
-			return getSucReturnObject().setData(uploadRows).toString();
-		}
-		return getSucReturnObject().setData(rows).toString();
-	}
-
-	//返回导出的标题
-	public HashMap<String, String> getTitleMap() {
-		HashMap<String, String> titleMap = new HashMap<>();
-		titleMap.put("itemname", "产品名称");
-		titleMap.put("itemno", "产品编号");
-		titleMap.put("undelqty", "未发数量");
-		titleMap.put("invbalqty", "库存数");
-		titleMap.put("canbesent", "预计可发量");
-		titleMap.put("canbesale", "预计可售量");
-		titleMap.put("unitname", "单位");
-		titleMap.put("itemclass", "营销分类");
-		titleMap.put("isonsale", "是否上架");
-		return titleMap;
-	}
-
-	@API(title = "查询指定商品对应的未发货订单明细", apiversion = R.ID20230408101803.v1.class)
-	public String queryOrderDetailList() throws YosException {
-		String itemno = content.getString("itemno");
-		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("t5.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
-				where.append("or t6.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
-				where.append(")");
-			}
-		}
-		SQLFactory sqlFactory =new SQLFactory(this,"未发货订单明细列表", pageSize, pageNumber, pageSorting);
-		sqlFactory.addParameter("siteid", siteid);
-		sqlFactory.addParameter("itemno", itemno);
-		sqlFactory.addParameter_SQL("where", where);
-		Rows rows = dbConnect.runSqlQuery(sqlFactory);
-		return getSucReturnObject().setData(rows).toString();
-	}
+    //返回导出的标题
+    public HashMap<String, String> getTitleMap() {
+        HashMap<String, String> titleMap = new HashMap<>();
+        titleMap.put("itemname", "产品名称");
+        titleMap.put("itemno", "产品编号");
+        titleMap.put("undelqty", "未发数量");
+        titleMap.put("invbalqty", "库存数");
+        titleMap.put("canbesent", "预计可发量");
+        titleMap.put("canbesale", "预计可售量");
+        titleMap.put("unitname", "单位");
+        titleMap.put("itemclass", "营销分类");
+        titleMap.put("isonsale", "是否上架");
+        return titleMap;
+    }
+
+    @API(title = "查询指定商品对应的未发货订单明细", apiversion = R.ID20230408101803.v1.class)
+    public String queryOrderDetailList() throws YosException {
+        String itemno = content.getString("itemno");
+        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("t5.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append("or t6.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
+                where.append(")");
+            }
+        }
+        SQLFactory sqlFactory = new SQLFactory(this, "未发货订单明细列表", pageSize, pageNumber, pageSorting);
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter("itemno", itemno);
+        sqlFactory.addParameter_SQL("where", where);
+        Rows rows = dbConnect.runSqlQuery(sqlFactory);
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    @API(title = "商品补货分析", apiversion = R.ID20231228102402.v1.class)
+    public String queryItemSalesList() throws YosException, IOException {
+        boolean isExport = content.getBooleanValue("isExport");
+        int year = content.getIntValue("year");
+        if (year <= 0) {
+            Calendar calendar = Calendar.getInstance();
+            year = calendar.get(Calendar.YEAR);
+        }
+
+        String begindate = year+"-01-01";
+        String enddate = (year+1)+"-01-01";
+
+        String where = " 1=1 ";
+        SQLFactory sqlFactory = new SQLFactory(this, "商品列表", pageSize, pageNumber, pageSorting);
+        if (isExport) {
+            sqlFactory = new SQLFactory(this, "商品列表");
+        }
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (whereObject.containsKey("iteminfo")) {
+                if (!StringUtils.isBlank(whereObject.getStringValue("iteminfo"))) {
+                    where = where + " and (t2.itemno like '%" + whereObject.getStringValue("iteminfo") + "%' or t2.itemname like '%" + whereObject.getStringValue("iteminfo") + "%') ";
+                }
+            }
+            if (whereObject.containsKey("itemclassids")) {
+                if (whereObject.getLong("itemclassids") != 0) {
+                    ArrayList<Long> itemclassList = new ArrayList<Long>();
+                    long itemclassid = whereObject.getLong("itemclassids");
+                    itemclassList.add(itemclassid);
+                    itemclassList.addAll(ItemClass.getSubItemClassIds(this, itemclassid));
+                    String sql = " and t2.itemid in ( SELECT itemid from sa_itemsaleclass WHERE itemclassid IN " + itemclassList + "  and siteid='" + siteid + "')";
+                    sql = sql.replace("[", "(").replace("]", ")");
+                    where = where + sql;
+                }
+            }
+
+            if (whereObject.containsKey("all") && !"".equals(whereObject.getString("all"))) {
+                if (!whereObject.getBooleanValue("all")) {
+                    where = where + " and 1=2 ";
+                }
+            }
+            if (whereObject.containsKey("isonsale") && !"".equals(whereObject.getString("isonsale"))) {
+                where = where + " and t2.isonsale ='" + whereObject.getString("isonsale") + "' ";
+            }
+            if (whereObject.containsKey("agentinfo")) {
+                if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                    sqlFactory = new SQLFactory(this, "订单明细未发商品列表", pageSize, pageNumber, pageSorting);
+                    if (isExport) {
+                        sqlFactory = new SQLFactory(this, "订单明细未发商品列表");
+                    }
+                    //System.out.println(StringUtils.isBlank(itemname) && StringUtils.isBlank(itemno) && itemclassids.size()==0);
+                    if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                        where = where + " and (t6.agentnum like '%" + whereObject.getStringValue("agentinfo") + "%' or t5.enterprisename like '%" + whereObject.getStringValue("agentinfo") + "%') ";
+                    }
+                }
+            }
+
+        }
+
+        sqlFactory.addParameter("siteid", siteid);
+        sqlFactory.addParameter_SQL("where", where);
+        //System.out.println(sqlFactory.getSQL());
+        Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
+        Rows rowsitemclass = dbConnect.runSqlQuery(" select  t7.itemclassname,t6.itemid,t8.brandname from sa_itemsaleclass t6 LEFT JOIN plm_itemclass t7 ON t7.itemclassid = t6.itemclassid AND t7.siteid = t6.siteid LEFT JOIN sa_brand t8 ON t8.sa_brandid = t7.sa_brandid AND t8.siteid = t7.siteid where t6.siteid='" + siteid + "'");
+        RowsMap itemclassRowsMap = rowsitemclass.toRowsMap("itemid");
+
+        RowsMap rowsMap = rows.toRowsMap("itemno");
+
+
+        SQLFactory sqlFactory1 = new SQLFactory(this, "商品发货数量汇总");
+        sqlFactory1.addParameter("siteid", siteid);
+        where = " 1=1 ";
+        sqlFactory1.addParameter_SQL("where", where);
+        Rows sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
+        RowsMap sumAllQtyRowsMap = sumQtyRows.toRowsMap("itemno");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                where = where + " and (t6.agentnum like '%" + whereObject.getStringValue("agentinfo") + "%' or t5.enterprisename like '%" + whereObject.getStringValue("agentinfo") + "%') ";
+            }
+        }
+
+        sqlFactory1.addParameter_SQL("where", where);
+        sumQtyRows = dbConnect.runSqlQuery(sqlFactory1);
+        RowsMap sumQtyRowsMap = sumQtyRows.toRowsMap("itemno");
+
+        SQLFactory sqlFactory2 = new SQLFactory(this, "商品未发货数量汇总");
+        sqlFactory2.addParameter("siteid", siteid);
+        where = " 1=1 ";
+        sqlFactory2.addParameter_SQL("where", where);
+        Rows sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
+        RowsMap sumUnAllQtyRowsMap = sumUnQtyRows.toRowsMap("itemno");
+        if (content.containsKey("where")) {
+            JSONObject whereObject = content.getJSONObject("where");
+            if (!StringUtils.isBlank(whereObject.getStringValue("agentinfo"))) {
+                where = where + " and (t6.agentnum like '%" + whereObject.getStringValue("agentinfo") + "%' or t5.enterprisename like '%" + whereObject.getStringValue("agentinfo") + "%') ";
+            }
+        }
+
+        sqlFactory2.addParameter_SQL("where", where);
+        sumUnQtyRows = dbConnect.runSqlQuery(sqlFactory2);
+        RowsMap sumUnQtyRowsMap = sumUnQtyRows.toRowsMap("itemno");
+
+
+        ERPDocking erpDocking = new ERPDocking();
+        JSONArray jsonArray = new JSONArray();
+        if (rows.toJsonArray("itemno").size() != 0) {
+            if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true") && siteid.equalsIgnoreCase("ccyosg")) {
+                if (rows.toJsonArray("itemno").size() <= 2000) {
+                    jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, rows.toJsonArray("itemno"));
+                } else {
+                    jsonArray = erpDocking.getErpIcinvbalRows(200000, 1, new JSONArray());
+                }
+
+            }
+        }
+
+        if (!jsonArray.isEmpty()) {
+
+            for (Object object : jsonArray) {
+                JSONObject jsonObject = (JSONObject) object;
+                if (rowsMap.containsKey(jsonObject.getString("fitemno"))) {
+                    if (rowsMap.get(jsonObject.getString("fitemno")).isNotEmpty()) {
+                        rowsMap.get(jsonObject.getString("fitemno")).get(0).put("invbalqty", jsonObject.getBigDecimalValue("fqty"));
+                    }
+                }
+            }
+        }
+        for (Row row : rows) {
+            String itemclass = itemclassRowsMap.get(row.getString("itemid")).toJsonArray("itemclassname").toString().substring(1, itemclassRowsMap.get(row.getString("itemid")).toJsonArray("itemclassname").toString().length() - 1);
+            row.put("itemclass", itemclass.replaceAll("\"", ""));
+            if (sumQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("unsoldqty", sumQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("unsoldqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+            if (sumUnQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("undelqty", sumUnQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
+                row.put("qty", sumUnQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("undelqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+                row.put("qty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+            if (sumUnAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("undelqtysum", sumUnAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("undeliqty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("undelqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+            if (sumAllQtyRowsMap.get(row.getString("itemno")).isNotEmpty()) {
+                row.put("unsoldqtysum", sumAllQtyRowsMap.get(row.getString("itemno")).get(0).getBigDecimal("qty").stripTrailingZeros().toPlainString());
+            } else {
+                row.put("unsoldqtysum", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+
+            if (!row.containsKey("invbalqty")) {
+                row.put("invbalqty", BigDecimal.ZERO.stripTrailingZeros().toPlainString());
+            }
+
+        }
+
+
+        //查询统计商品月销量销
+        SQLFactory sqlFactory3 = new SQLFactory(this, "查询统计商品月销量销");
+        sqlFactory3.addParameter("siteid", siteid);
+        sqlFactory3.addParameter("begindate", begindate);
+        sqlFactory3.addParameter("enddate", enddate);
+        sqlFactory3.addParameter_in("itemid", rows.toArray("itemid"));
+        RowsMap monthRowsMap = dbConnect.runSqlQuery(sqlFactory3).toRowsMap("itemid");
+
+        SQLFactory sqlFactory4 = new SQLFactory(this, "查询退货统计");
+        sqlFactory4.addParameter("siteid", siteid);
+        sqlFactory4.addParameter("begindate", begindate);
+        sqlFactory4.addParameter("enddate", enddate);
+        sqlFactory4.addParameter_in("itemid", rows.toArray("itemid"));
+        RowsMap returnRowsMap = dbConnect.runSqlQuery(sqlFactory4).toRowsMap("itemid");
+
+
+        SQLFactory sqlFactory5 = new SQLFactory(this, "查询手工关闭统计");
+        sqlFactory5.addParameter("siteid", siteid);
+        sqlFactory5.addParameter("begindate", begindate);
+        sqlFactory5.addParameter("enddate", enddate);
+        sqlFactory5.addParameter_in("itemid", rows.toArray("itemid"));
+        RowsMap closeRowsMap = dbConnect.runSqlQuery(sqlFactory5).toRowsMap("itemid");
+
+
+        for (Row row : rows) {
+
+            row.put("canbesent", (row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).stripTrailingZeros().toPlainString());
+            row.put("canbesale", ((row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).subtract(row.getBigDecimal("undelqtysum"))).stripTrailingZeros().toPlainString());
+            Rows monthRows = monthRowsMap.getOrDefault(row.getString("itemid"), new Rows());
+            for (Row month : monthRows) {
+                row.put("month_" + month.getString("month"), month.getBigDecimal("qty"));
+            }
+            //补足月份
+            row = initMonthRow(row);
+            //处理退货
+            Rows returnRows = returnRowsMap.getOrDefault(row.getString("itemid"), new Rows());
+            for (Row returnRow : returnRows) {
+                String key = "month_" + returnRow.getString("month");
+                row.replace(key, row.getBigDecimal(key).subtract(returnRow.getBigDecimal("qty")));
+            }
+            //
+            Rows closeRows = closeRowsMap.getOrDefault(row.getString("itemid"), new Rows());
+            for (Row closeRow : closeRows) {
+                String key = "month_" + closeRow.getString("month");
+                row.replace(key, row.getBigDecimal(key).subtract(closeRow.getBigDecimal("qty")));
+            }
+        }
+        if (isExport) {
+            //去除不需要导出项
+            rows.getFieldList().remove("itemid");
+            rows.getFieldList().remove("packageqty");
+            rows.getFieldList().remove("qty");
+            Rows uploadRows = uploadExcelToObs("invbal", "商品补货分析", rows, getTitleMap());
+            return getSucReturnObject().setData(uploadRows).toString();
+        }
+        return getSucReturnObject().setData(rows).toString();
+    }
+
+    public Row initMonthRow(Row row) {
+        row.putIfAbsent("month_01", 0);
+        row.putIfAbsent("month_02", 0);
+        row.putIfAbsent("month_03", 0);
+        row.putIfAbsent("month_04", 0);
+        row.putIfAbsent("month_05", 0);
+        row.putIfAbsent("month_06", 0);
+        row.putIfAbsent("month_07", 0);
+        row.putIfAbsent("month_08", 0);
+        row.putIfAbsent("month_09", 0);
+        row.putIfAbsent("month_10", 0);
+        row.putIfAbsent("month_11", 0);
+        row.putIfAbsent("month_12", 0);
+        return row;
+    }
 
 }

+ 11 - 6
src/custom/restcontroller/webmanage/sale/order/Order.java

@@ -117,6 +117,9 @@ public class Order extends Controller {
         if (sa_accountclassid <= 0) {
             return getErrReturnObject().setErrMsg("未找到扣款账户信息").toString();
         }
+
+        orderItemsHelper.isAccountCanUsed(sa_accountclassid);
+
         sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
         sqlList.addAll(updateAccountclassinfos(sa_orderid, sa_accountclassid, sys_enterpriseid));
 
@@ -184,7 +187,7 @@ public class Order extends Controller {
             } else {
                 sqlFactory.addParameter("billdate", billdate);
             }
-            if (content.containsKey("sa_accountclassid")) {
+            if (content.containsKey("sa_accountclassid") && !content.getString("sa_accountclassid").equals("")) {
                 sa_accountclassid = content.getLongValue("sa_accountclassid");
                 if (sa_accountclassid <= 0) {
                     return getErrReturnObject().setErrMsg("账户不存在").toString();
@@ -349,6 +352,7 @@ public class Order extends Controller {
         if (sa_accountclassid <= 0) {
             return getErrReturnObject().setErrMsg("未找到扣款账户信息").toString();
         }
+        orderItemsHelper.isAccountCanUsed(sa_accountclassid);
         sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
 
 
@@ -1400,10 +1404,15 @@ public class Order extends Controller {
         if (sa_accountclassid <= 0) {
             return getErrReturnObject().setErrMsg("请选择支付账号").toString();
         }
+        Long sys_enterpriseid = row.getLong("sys_enterpriseid");
+        if (sys_enterpriseid <= 0) {
+            return getErrReturnObject().setErrMsg("请选择订货企业信息").toString();
+        }
         //验证结算企业
         Long pay_enterpriseid = row.getLong("pay_enterpriseid");
         if (pay_enterpriseid <= 0) {
-            return getErrReturnObject().setErrMsg("请选择结算企业").toString();
+            dbConnect.runSqlQuery("UPDATE sa_order set pay_enterpriseid=sys_enterpriseid  WHERE sa_orderid=" + sa_orderid);
+//            return getErrReturnObject().setErrMsg("请选择结算企业").toString();
         }
         Long sys_enterprise_financeid = row.getLong("sys_enterprise_financeid");
         if (sys_enterprise_financeid <= 0) {
@@ -1414,10 +1423,6 @@ public class Order extends Controller {
 //        if (rec_contactsid <= 0) {
 //            return getErrReturnObject().setErrMsg("请选择物收货人信息").toString();
 //        }
-        Long sys_enterpriseid = row.getLong("sys_enterpriseid");
-        if (sys_enterpriseid <= 0) {
-            return getErrReturnObject().setErrMsg("请选择订货企业信息").toString();
-        }
         if (dbConnect.runSqlQuery("SELECT 1 FROM sa_agents WHERE siteid='" + siteid + "' AND `status`='启用' AND sys_enterpriseid=" + sys_enterpriseid).isEmpty()) {
             return getErrReturnObject().setErrMsg("当前企业不存在或已禁用,无法下单").toString();
         }

+ 13 - 2
src/custom/restcontroller/webmanage/sale/order/OrderItemsHelper.java

@@ -32,12 +32,23 @@ public class OrderItemsHelper extends BaseClass {
         this.content = controller.content;
     }
 
+    public void isAccountCanUsed(Long sa_accountclassid) throws YosException {
+        if (dbConnect.runSqlQuery("select * from sa_accountclass  WHERE isused=1 and isorder=1 and sa_accountclassid=" + sa_accountclassid).isEmpty()) {
+            throw new YosException(false, "当资金账户未启用或者不支持订货");
+        }
+
+    }
+
     public long getAccountClassId(String type) throws YosException {
 
         Long sa_accountclassid = content.getLong("sa_accountclassid");
 
-        if ((type.equals("标准订单") || type.equals("特殊订单")) && sa_accountclassid > 0) {
-            return sa_accountclassid;
+        //if ((type.equals("标准订单") || type.equals("特殊订单")) && sa_accountclassid > 0) {
+        if ((type.equals("标准订单") || type.equals("特殊订单")) && content.getString("tradefield").equals("GC工程")) {
+            return 69L;
+        }
+        if ((type.equals("标准订单") || type.equals("特殊订单")) && content.getString("tradefield").equals("整装工程")) {
+            return 96L;
         }
         if (type.equals("促销订单")) {
             Rows accountclassRows = dbConnect.runSqlQuery("select sa_accountclassid from sa_promotion where siteid='" + controller.siteid + "' and sa_promotionid=" + content.getLongValue("sa_promotionid"));

+ 7 - 1
src/custom/restcontroller/webmanage/sale/rebateaccount/rebateaccounthead.java

@@ -41,6 +41,12 @@ public class rebateaccounthead extends Controller {
     @API(title = "返利结算单新增更新", apiversion = R.ID20230627091003.v1.class)
     @CACHEING_CLEAN(apiClass = {rebateaccounthead.class})
     public String insertormodify_rebateaccounthead() throws YosException, IOException {
+
+        Rows rebateschemes = dbConnect.runSqlQuery("select * from sa_rebatescheme where siteid='"+siteid+"' and isused=1");
+        if (rebateschemes.isEmpty()) {
+            return getErrReturnObject().setErrMsg("不存在装修返利方案,无法结算").toString();
+        }
+
         ArrayList<String> sqlList = new ArrayList<>();
         // 表名
         String tableName = "sa_rebateaccounthead";
@@ -251,7 +257,7 @@ public class rebateaccounthead extends Controller {
             return getErrReturnObject().setErrMsg("返利结算单表体为空,无法结算").toString();
         } else {
             long sa_rebateschemeid = 0;
-            Rows rebateschemes = dbConnect.runSqlQuery("select * from sa_rebatescheme");
+            Rows rebateschemes = dbConnect.runSqlQuery("select * from sa_rebatescheme where siteid='"+siteid+"'");
             if (rebateschemes.isEmpty()) {
                 return getErrReturnObject().setErrMsg("不存在装修返利方案,无法结算").toString();
             } else {

+ 3 - 0
src/custom/restcontroller/webmanage/sale/rebatescheme/rebatescheme.java

@@ -32,6 +32,7 @@ public class rebatescheme extends Controller {
 
         Long sa_rebateschemeid = content.getLongValue("sa_rebateschemeid");
         Long sa_accountclassid = content.getLongValue("sa_accountclassid");
+        Long isused = content.getLongValue("isused");
         if (sa_accountclassid <= 0) {
             return getErrReturnObject().setErrMsg("请选择账户").toString();
         }
@@ -41,6 +42,7 @@ public class rebatescheme extends Controller {
             insertSQL.setUniqueid(sa_rebateschemeid).setSiteid(siteid);
             insertSQL.setValue("billno", createBillCode("rebateschemebill"));
             insertSQL.setValue("sa_accountclassid", sa_accountclassid);
+            insertSQL.setValue("isused", isused);
             sqlList.add(insertSQL.getSQL());
             sqlList.add(DataContrlLog.createLog(this, tableName, sa_rebateschemeid, "新增", "装修返利方案新增成功").getSQL());
         }
@@ -48,6 +50,7 @@ public class rebatescheme extends Controller {
             UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
             updateSQL.setUniqueid(sa_rebateschemeid).setSiteid(siteid);
             updateSQL.setValue("sa_accountclassid", sa_accountclassid);
+            updateSQL.setValue("isused", isused);
             sqlList.add(updateSQL.getSQL());
             sqlList.add(DataContrlLog.createLog(this, tableName, sa_rebateschemeid, "编辑", "装修返利方案编辑成功").getSQL());
         }

+ 6 - 0
src/custom/restcontroller/webmanage/site/site.java

@@ -96,6 +96,12 @@ public class site extends Controller {
         tableColumnsMap.remove("changedate");
         tableColumnsMap.remove("siteid");
 
+        if (content.containsKey("isrebate") && content.getString("isrebate").equals("1")) {
+            if (dbConnect.runSqlQuery("SELECT 1 from sa_rebatescheme WHERE isused=1 and siteid='" + siteid + "'").isEmpty()) {
+                return getErrReturnObject().setErrMsg("未找到启用状态的返利方案").toString();
+            }
+        }
+
 
         StringBuffer updateSQl = new StringBuffer();
         updateSQl.append("update sys_site_parameter set changeuserid=" + userid + ",changeby='" + username + "',changedate=now()");