Просмотр исходного кода

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

沈静伟 2 лет назад
Родитель
Сommit
9642e1988a
1 измененных файлов с 50 добавлено и 20 удалено
  1. 50 20
      src/custom/restcontroller/webmanage/lsak3/stockbill/stockbill.java

+ 50 - 20
src/custom/restcontroller/webmanage/lsak3/stockbill/stockbill.java

@@ -2,6 +2,7 @@ package restcontroller.webmanage.lsak3.stockbill;
 
 import beans.accountbalance.Accountbalance;
 import beans.accountbalance.CashbillEntity;
+import beans.datacontrllog.DataContrlLog;
 import beans.parameter.Parameter;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
@@ -12,6 +13,7 @@ import common.data.Row;
 import common.data.Rows;
 import common.data.RowsMap;
 import common.data.SQLFactory;
+import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 
 import javax.swing.text.StyledEditorKit;
@@ -105,16 +107,25 @@ public class stockbill extends Controller {
                 sqlList.add(sqlFactory.getSQL());
 
                 JSONArray detailarray = content.getJSONArray("icstockbilldetails");
-                List<String> itemnos=new ArrayList<>();
+                StringBuffer str = new StringBuffer();
+
                 List<Long> sa_dispatch_itemsids=new ArrayList<>();
-                itemnos.add("0");
                 sa_dispatch_itemsids.add(0l);
                 for (Object object:detailarray) {
                     JSONObject jsonObject = (JSONObject)object;
-                    itemnos.add(jsonObject.getString("fitemno"));
+                    if (str.toString().equals("")) {
+                        str.append("'" +jsonObject.getString("fitemno") + "'");
+                    } else {
+                        str.append(",'" + jsonObject.getString("fitemno") + "'");
+                    }
                     sa_dispatch_itemsids.add(jsonObject.getLong("sainvoicedetailid"));
                 }
-                Rows rows = dbConnect.runSqlQuery("select * from plm_item  where siteid='lsa1986' and itemno in "+itemnos.toString().replace("[", "(").replace("]", ")"));
+                Rows rows;
+                if (!str.toString().equals("")) {
+                     rows = dbConnect.runSqlQuery("select * from plm_item  where siteid='lsa1986' and itemno in "+"(" + str.toString() + ")");
+                } else {
+                     rows = dbConnect.runSqlQuery("select * from plm_item  where siteid='lsa1986' and itemno in('')");
+                }
                 RowsMap itemRowsMap =rows.toRowsMap("itemno");
                 Rows distiptchRows = dbConnect.runSqlQuery("select t2.price,t1.sa_dispatch_itemsid from sa_dispatch_items t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid inner join sa_dispatch t3 on t1.sa_dispatchid=t3.sa_dispatchid and t1.siteid=t3.siteid  where t3.status in('审核','复核','关闭') and  t1.siteid='lsa1986' and  t1.sa_dispatch_itemsid in "+sa_dispatch_itemsids.toString().replace("[", "(").replace("]", ")"));
                 RowsMap distiptchRowsMap =distiptchRows.toRowsMap("sa_dispatch_itemsid");
@@ -123,6 +134,7 @@ public class stockbill extends Controller {
                     JSONObject jsonObject = (JSONObject)object;
                     String frownum = jsonObject.getString("frownum");
                     String fitemno = jsonObject.getString("fitemno");
+                     System.err.println(frownum+":"+fitemno);
                     BigDecimal fqty = new BigDecimal(jsonObject.getString("fqty"));
                     fqty=fqty.compareTo(BigDecimal.ZERO)<0?fqty.negate():fqty;
                     //String fdetailstockno = jsonObject.getString("fstockno");
@@ -164,18 +176,19 @@ public class stockbill extends Controller {
                 //返利比例
                 String icstockbillrebateaccount = Parameter.get(siteid,"icstockbillrebateaccount"); //经销商销售出库单返利账户
                 String icstockbillrebaterate1 = Parameter.get(siteid,"icstockbillrebaterate"); //销售出库单返利比例
-                BigDecimal icstockbillrebaterate =new BigDecimal(icstockbillrebaterate1);
-                //经销商返利
-                BigDecimal rebateamount = icstockbillrebaterate.multiply(amountTotal);
-                 System.out.println(rebateamount);
-                CashbillEntity entity = new CashbillEntity();
-                entity.setAmount(rebateamount);
-                entity.setOwnerid(st_stockbillid);
-                entity.setOwnertable("st_stockbill");
-                entity.setSource("");
-                entity.setRemarks("销售出库单" + fbillnum + "返利");
-                sqlList.addAll(Accountbalance.createCashbillIncome(this,sys_enterpriseid,Long.valueOf(icstockbillrebateaccount).longValue(),entity,true));
-
+                if(!StringUtils.isBlank(icstockbillrebateaccount) && !StringUtils.isBlank(icstockbillrebaterate1)){
+                    BigDecimal icstockbillrebaterate =new BigDecimal(icstockbillrebaterate1);
+                    //经销商返利
+                    BigDecimal rebateamount = icstockbillrebaterate.multiply(amountTotal);
+                    System.out.println(rebateamount);
+                    CashbillEntity entity = new CashbillEntity();
+                    entity.setAmount(rebateamount);
+                    entity.setOwnerid(st_stockbillid);
+                    entity.setOwnertable("st_stockbill");
+                    entity.setSource("");
+                    entity.setRemarks("销售出库单" + fbillnum + "返利");
+                    sqlList.addAll(Accountbalance.createCashbillIncome(this,sys_enterpriseid,Long.valueOf(icstockbillrebateaccount).longValue(),entity,true));
+                }
                 sqlList.add("update st_stockbill set status='审核',checkby='"+checkby+"',checkdate=CURRENT_TIMESTAMP where st_stockbillid = "+st_stockbillid+" and siteid='lsa1986'");
 
 
@@ -252,21 +265,38 @@ public class stockbill extends Controller {
         /**
          * 更新发货单数量
          */
-        Rows stockbillrows =dbConnect.runSqlQuery("select st_stockbillid,status from st_stockbill where fbillnum='"+fbillnum+"' and siteid='lsa1986'");
+        Rows stockbillrows =dbConnect.runSqlQuery("select st_stockbillid,status from st_stockbill where billno='"+fbillnum+"' and siteid='lsa1986'");
         ArrayList<String> sqldispatchitems =new ArrayList<>();
         if(stockbillrows.isNotEmpty()){
-            Rows stockbilldetailrows =dbConnect.runSqlQuery("select sa_dispatch_itemsid,sum(qty) qty from st_stockbill_items where st_stockbillid = "+stockbillrows.get(0).getLong("st_stockbillid")+" and siteid='lsa1986' group by sa_dispatch_itemsid");
+            Rows stockbilldetailrows =dbConnect.runSqlQuery("select t1.sa_dispatch_itemsid,sum(t1.qty) qty,t2.sa_dispatchid from st_stockbill_items t1 inner join  sa_dispatch_items t2 on t1.sa_dispatch_itemsid=t2.sa_dispatch_itemsid and t1.siteid=t2.siteid where t1.st_stockbillid = "+stockbillrows.get(0).getLong("st_stockbillid")+" and t1.siteid='lsa1986' group by t1.sa_dispatch_itemsid");
             if(stockbillrows.get(0).getString("status").equals("审核")){
                 for (Row row :stockbilldetailrows) {
-                    sqldispatchitems.add("update sa_dispatch_items set outwarehouseqty=outwarehouseqty+"+row.getBigDecimal("qty")+" where siteid='lsa1986' sa_dispatch_itemsid="+row.getLong("sa_dispatch_itemsid"));
+                    sqldispatchitems.add("update sa_dispatch_items set outwarehousedate=CURRENT_TIME,outwarehouseqty=outwarehouseqty+"+row.getBigDecimal("qty")+" where siteid='lsa1986' and sa_dispatch_itemsid="+row.getLong("sa_dispatch_itemsid"));
                 }
             }else{
                 for (Row row :stockbilldetailrows) {
-                    sqldispatchitems.add("update sa_dispatch_items set outwarehouseqty=outwarehouseqty-"+row.getBigDecimal("qty")+" where siteid='lsa1986' sa_dispatch_itemsid="+row.getLong("sa_dispatch_itemsid"));
+                    sqldispatchitems.add("update sa_dispatch_items set outwarehousedate=CURRENT_TIME,outwarehouseqty=outwarehouseqty-"+row.getBigDecimal("qty")+" where siteid='lsa1986' and sa_dispatch_itemsid="+row.getLong("sa_dispatch_itemsid"));
+                    sqldispatchitems.add("update sa_dispatch set closedate=null,closeby='',status='复核' where siteid='lsa1986' and sa_dispatchid="+row.getLong("sa_dispatch_itemsid"));
                 }
             }
         }
         dbConnect.runSqlUpdate(sqldispatchitems);
+        //查询可关闭的发货单
+        Rows dispatchrows =dbConnect.runSqlQuery( "select t.sa_dispatchid from (select t2.sa_dispatchid,sum(t2.qty) sumqty,sum(outwarehouseqty) sumoutwarehouseqty from st_stockbill_items t1 inner join  sa_dispatch_items t2 on t1.sa_dispatch_itemsid=t2.sa_dispatch_itemsid and t1.siteid=t2.siteid where t1.st_stockbillid = "+stockbillrows.get(0).getLong("st_stockbillid")+" and t1.siteid='lsa1986' group by t2.sa_dispatchid) t where t.sumqty=t.sumoutwarehouseqty");
+        ArrayList<String>  sqldispatch =new ArrayList<>();
+        for (Row row:dispatchrows) {
+            sqldispatch.add("update sa_dispatch set status='关闭',closedate=current_time,closeby='admin' where sa_dispatchid='" + row.getLong("sa_dispatchid") + "' and siteid='lsa1986'");
+            SQLFactory sqlFactory = new SQLFactory(new DataContrlLog(), "数据操作日志新增");
+            sqlFactory.addParameter("ownertable", "sa_dispatch");
+            sqlFactory.addParameter("ownerid", row.getLong("sa_dispatchid"));
+            sqlFactory.addParameter("action", "自动关闭");
+            sqlFactory.addParameter("remarks", "发货单自动关闭成功");
+            sqlFactory.addParameter("actionuserid", "1");
+            sqlFactory.addParameter("actionby", "admin");
+            sqlFactory.addParameter("siteid", "lsa1986");
+            sqldispatch.add(sqlFactory.getSQL());
+        }
+        dbConnect.runSqlUpdate(sqldispatch);
 
         /**
          * 如单据为新建状态,则,先把单据强行删除掉