浏览代码

经销商端发货单和发货明细查询调整及增加欠货库存导出功能

hu 2 年之前
父节点
当前提交
c8c25682fe

+ 1 - 1
src/custom/beans/dispatch/SQL/查询发货单数量金额.sql

@@ -1,4 +1,4 @@
-select t1.sa_dispatchid,sum(t1.qty * t2.price) sumamount, sum(t1.qty) sumqty from sa_dispatch_items t1
+select t1.sa_dispatchid,sum(t1.qty * t2.price) sumamount, sum(t1.qty) sumqty,sum(t1.outwarehouseqty) sumoutwarehouseqty,max(t1.outwarehousedate) outwarehousedaterecently from sa_dispatch_items t1
                              inner join sa_orderitems t2 on t1.sa_orderitemsid = t2.sa_orderitemsid and t1.siteid = t2.siteid
                             WHERE t1.siteid = $siteid$ and t1.sa_dispatchid in $sa_dispatchid$
                     group by t1.sa_dispatchid

+ 4 - 0
src/custom/restcontroller/sale/dispatch/dispatch.java

@@ -65,9 +65,13 @@ public class dispatch extends Controller {
             if (dispatchAmountRowsMap.get(id.toString()).isNotEmpty()) {
                 row.put("sumamount", dispatchAmountRowsMap.get(id.toString()).get(0).getBigDecimal("sumamount"));
                 row.put("sumqty", dispatchAmountRowsMap.get(id.toString()).get(0).getBigDecimal("sumqty"));
+                row.put("sumoutwarehouseqty", dispatchAmountRowsMap.get(id.toString()).get(0).getBigDecimal("sumoutwarehouseqty"));
+                row.put("outwarehousedaterecently", dispatchAmountRowsMap.get(id.toString()).get(0).getString("outwarehousedaterecently"));
             } else {
                 row.put("sumamount", 0);
                 row.put("sumqty", 0);
+                row.put("sumoutwarehouseqty", 0);
+                row.put("outwarehousedaterecently", "");
             }
 
         }

+ 1 - 0
src/custom/restcontroller/webmanage/sale/dispatch/SQL/发货单明细所有列表查询.sql

@@ -18,6 +18,7 @@ SELECT t1.sa_dispatch_itemsid,
        ifnull(t1.qty, 0) qty,
        t1.remarks,
        ifnull(t1.outwarehouseqty, 0) outwarehouseqty,
+       t1.outwarehousedate,
        t1.batchno,
        t5.price,
        (ifnull(t1.qty, 0) * t5.price) amount,

+ 19 - 22
src/custom/restcontroller/webmanage/sale/dispatch/dispatchItems.java

@@ -272,6 +272,7 @@ public class dispatchItems extends Controller {
         StringBuffer where = new StringBuffer(" 1=1 ");
         if (sys_enterpriseid > 0) {
             where.append(" and t4.sys_enterpriseid ='").append(sys_enterpriseid).append("' ");
+            where.append(" and  ifnull(t1.outwarehouseqty, 0)>0' ");
         }
 
         if (content.containsKey("where")) {
@@ -342,6 +343,7 @@ public class dispatchItems extends Controller {
                 JSONObject jsonObject = (JSONObject) object;
 
                 if (rowsMap.containsKey(jsonObject.getString("fitemno"))) {
+
                     if (rowsMap.get(jsonObject.getString("fitemno")).isNotEmpty()) {
                         if (sumQtyRowsMap.containsKey(jsonObject.getString("fitemno"))) {
                             rowsMap.get(jsonObject.getString("fitemno")).get(0).put("delinvbalqty", jsonObject.getBigDecimalValue("fqty").subtract(sumQtyRowsMap.get(jsonObject.getString("fitemno")).get(0).getBigDecimal("qty")));
@@ -362,28 +364,22 @@ public class dispatchItems extends Controller {
         }
 
         if (isExport) {
-            ExcelFactory excelFactory = new ExcelFactory("发货单明细所有列表");
-
-            XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
-            XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
-
-            CellStyle style = xssfFWorkbook.createCellStyle();
-            // 设置为文本格式,防止身份证号变成科学计数法
-            DataFormat format = xssfFWorkbook.createDataFormat();
-            style.setDataFormat(format.getFormat("@"));
-            // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
-            sheet.setDefaultColumnStyle(0, style);
-            ExportDown.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
-            XSSFCellStyle titleCellStyle2 = ExportDown.createTitleCellStyle2(xssfFWorkbook);
-            XSSFCellStyle titleCellStyle3 = ExportDown.createBodyCellStyle(xssfFWorkbook);
-            ExportDown.batchDetail(sheet, titleCellStyle2, titleCellStyle3, rows);// 写入标题
-
-            Rows uploadRows = uploadExcelToObs(excelFactory);
-            String url = "";
-            if (!uploadRows.isEmpty()) {
-                url = uploadRows.get(0).getString("url");
-            }
-            return getSucReturnObject().setData(url).toString();
+            //去除不需要导出项
+            rows.getFieldList().remove("sa_dispatch_itemsid");
+            rows.getFieldList().remove("sa_dispatchid");
+            rows.getFieldList().remove("sa_orderitemsid");
+            rows.getFieldList().remove("sa_orderid");
+            rows.getFieldList().remove("sys_enterpriseid");
+            rows.getFieldList().remove("isclose");
+            rows.getFieldList().remove("rowno");
+            rows.getFieldList().remove("itemid");
+            rows.getFieldList().remove("batchno");
+            rows.getFieldList().remove("price");
+            rows.getFieldList().remove("amount");
+            rows.getFieldList().remove("undeliqty");
+            rows.getFieldList().remove("deliedqty");
+            Rows uploadRows = uploadExcelToObs("dispatch", "发货单明细列表", rows, getTitleMap());
+            return getSucReturnObject().setData(uploadRows).toString();
         }
         return getSucReturnObject().setData(rows).toString();
     }
@@ -403,6 +399,7 @@ public class dispatchItems extends Controller {
         titleMap.put("unitname", "单位");
         titleMap.put("qty", "发货数量");
         titleMap.put("remarks", "发货行备注");
+        titleMap.put("outwarehouseqty", "已出库数量");
 
         return titleMap;
     }

+ 5 - 1
src/custom/restcontroller/webmanage/sale/invbal/SQL/商品列表.sql

@@ -3,7 +3,11 @@ SELECT t2.itemno,
        t2.itemname,
        t2.isonsale,
        t4.unitname,
-       t2.packageqty
+       t2.packageqty,
+        '0' canbesent,
+        '0' canbesale,
+        '0' invbalqty,
+        '0' undelqty
 FROM plm_item t2
          left join plm_unit t4 on t2.unitid=t4.unitid and t2.siteid=t4.siteid
 	where t2.siteid = $siteid$

+ 5 - 1
src/custom/restcontroller/webmanage/sale/invbal/SQL/订单明细未发商品列表.sql

@@ -3,7 +3,11 @@ SELECT t2.itemno,
        t2.itemname,
        t2.isonsale,
        t4.unitname,
-       t2.packageqty
+       t2.packageqty,
+        '0' canbesent,
+        '0' canbesale,
+        '0' invbalqty,
+        '0' undelqty
 FROM sa_orderitems t1
          inner join plm_item t2 on t1.siteid = t2.siteid and t1.itemid = t2.itemid
          inner join sa_order t3 on t1.siteid=t3.siteid and t1.sa_orderid=t3.sa_orderid

+ 58 - 1
src/custom/restcontroller/webmanage/sale/invbal/invbal.java

@@ -1,5 +1,6 @@
 package restcontroller.webmanage.sale.invbal;
 
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -113,7 +114,8 @@ public class invbal extends Controller {
     }
 
 	@API(title = "查询Erp库存列表", apiversion = R.ID20230408091703.v1.class)
-	public String queryErpInvbalList() throws YosException {
+	public String queryErpInvbalList() throws YosException, IOException {
+		boolean isExport = content.getBooleanValue("isExport");
 		String itemno = content.getStringValue("itemno");
 		String itemname = content.getStringValue("itemname");
 		String agentinfo = content.getStringValue("agentinfo");
@@ -121,16 +123,28 @@ public class invbal extends Controller {
 		JSONArray itemclassids = content.getJSONArray("itemclassids");
 		String where ="1=2";
 		SQLFactory sqlFactory =new SQLFactory(this,"订单明细未发商品列表", pageSize, pageNumber, pageSorting);
+		if (isExport) {
+			sqlFactory = new SQLFactory(this,"订单明细未发商品列表");
+		}
 		if(!StringUtils.isBlank(itemno)){
 			sqlFactory=new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
+			if (isExport) {
+				sqlFactory = new SQLFactory(this,"商品列表");
+			}
 			where=where+" or t2.itemno like '%"+itemno+"%'";
 		}
 		if(!StringUtils.isBlank(itemname)){
 			sqlFactory=new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
+			if (isExport) {
+				sqlFactory = new SQLFactory(this,"商品列表");
+			}
 			where=where+" or t2.itemname like '%"+itemname+"%' ";
 		}
 		if (itemclassids.size() > 0) {
 			sqlFactory=new SQLFactory(this,"商品列表", pageSize, pageNumber, pageSorting);
+			if (isExport) {
+				sqlFactory = new SQLFactory(this,"商品列表");
+			}
 			ArrayList<Long> itemclassList = new ArrayList<Long>();
 			for (Object object : itemclassids) {
 				//System.out.println(row.getLong("itemclassid"));
@@ -148,6 +162,9 @@ public class invbal extends Controller {
 		}
 		if(!StringUtils.isBlank(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(itemname) && StringUtils.isBlank(itemno) && itemclassids.size()==0){
 				where=where+" or 1=1 and (t6.agentnum like '%"+agentinfo+"%' or t5.enterprisename like '%"+agentinfo+"%') ";
@@ -225,8 +242,48 @@ public class invbal extends Controller {
 			}
 
 		}
+		for (Row row:rows) {
+			row.put("canbesent", row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty")));
+			row.put("canbesale", (row.getBigDecimal("invbalqty").subtract(row.getBigDecimal("unsoldqty"))).subtract(row.getBigDecimal("undelqty")));
+		}
+		if(isExport){
+			//去除不需要导出项
+			rows.getFieldList().remove("itemid");
+			rows.getFieldList().remove("packageqty");
+			rows.getFieldList().remove("qty");
+			//添加
+//			rows.getFieldList().add("canbesent");
+//			rows.getFieldList().add("canbesale");
+			rows.getFieldList().add("invbalqty");
+			rows.getFieldList().add("undelqty");
+			ArrayList<String> keylist = rows.getFieldList();
+			for (String str:
+			keylist) {
+				Class fieldclazztype = rows.getFieldMeta(str).getFieldtype();
+			}
+			System.out.println(rows.get(0).toString());
+
+			Rows uploadRows = uploadExcelToObs("invbal", "Erp欠货库存列表", 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");

+ 2 - 2
src/custom/service/DispatchAutoCloseService.java

@@ -73,7 +73,7 @@ public class DispatchAutoCloseService extends ServiceController {
                     Rows erpupdatelogRows = dbConnect.runSqlQuery(
                             "select * from sys_erpupdatelog where ownertable='sa_dispatch' and type='关闭发货单' and ownerid=" + sa_dispatchid);
                     SQLFactory sqlFactory;
-                    if (!rows.isEmpty()) {
+                    if (!erpupdatelogRows.isEmpty()) {
                         sqlFactory = new SQLFactory(new UploadDataToERP_HY(), "erp上传日志更新");
                         sqlFactory.addParameter("sys_erpupdatelogid", erpupdatelogRows.get(0).getLong("sys_erpupdatelogid"));
                     } else {
@@ -119,7 +119,7 @@ public class DispatchAutoCloseService extends ServiceController {
                 if(!jsonArray.isEmpty()){
                     for (Object object1:jsonArray) {
                         JSONObject jsonObject = (JSONObject)object1;
-                        sqlList.add("update sa_dispatch_items set outwarehouseqty="+jsonObject.getBigDecimalValue("fqty1")+" where rowno ="+jsonObject.getIntValue("frownum")+" and sa_dispatchid='"+sa_dispatchid+"' and siteid='CCYOSG'");
+                        sqlList.add("update sa_dispatch_items set outwarehousedate=current_time,outwarehouseqty="+jsonObject.getBigDecimalValue("fqty1")+" where rowno ="+jsonObject.getIntValue("frownum")+" and sa_dispatchid='"+sa_dispatchid+"' and siteid='CCYOSG'");
                     }
                 }