|
|
@@ -252,90 +252,122 @@ public class stockbill extends Controller {
|
|
|
sqlList.add("update st_stockbill set status='新建',checkby='',checkdate=null where st_stockbillid = "+stockbillRows.get(0).getLong("st_stockbillid")+" and siteid='lsa1986'");
|
|
|
|
|
|
}
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- msg = e.getMessage();
|
|
|
- if(msg==null) {
|
|
|
- msg = "";
|
|
|
- }
|
|
|
- code = 0;
|
|
|
- }
|
|
|
|
|
|
- dbConnect.runSqlUpdate(sqlList);
|
|
|
- /**
|
|
|
- * 更新发货单数量
|
|
|
- */
|
|
|
- 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 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 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 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_dispatchid"));
|
|
|
+
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ /**
|
|
|
+ * 更新发货单数量
|
|
|
+ */
|
|
|
+ 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 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("审核")){
|
|
|
+ if(stockbillrows.get(0).getString("rb").equals("1")){
|
|
|
+ for (Row row :stockbilldetailrows) {
|
|
|
+ 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 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_dispatchid"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }else{
|
|
|
+ if(stockbillrows.get(0).getString("rb").equals("1")){
|
|
|
+ for (Row row :stockbilldetailrows) {
|
|
|
+ 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_dispatchid"));
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ for (Row row :stockbilldetailrows) {
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
- 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);
|
|
|
+ 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");
|
|
|
+ Rows undispatchrows =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(this, "数据操作日志新增");
|
|
|
+ sqlFactory.addParameter("sys_contrllogid", createTableID("sys_contrllog"));
|
|
|
+ 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());
|
|
|
+ }
|
|
|
+ for (Row row:undispatchrows) {
|
|
|
+ sqldispatch.add("update sa_dispatch set status='复核',closedate=null,closeby='' where sa_dispatchid='" + row.getLong("sa_dispatchid") + "' and siteid='lsa1986'");
|
|
|
+ sqldispatch.add("delete from sys_contrllog where ownertable='sa_dispatch' and action='自动关闭' and ownerid='" + row.getLong("sa_dispatchid") + "' and siteid='lsa1986'");
|
|
|
+ }
|
|
|
|
|
|
+ dbConnect.runSqlUpdate(sqldispatch);
|
|
|
|
|
|
- //查询可关闭的订单
|
|
|
- //订单出库总数量
|
|
|
- Rows orderinstockrows =dbConnect.runSqlQuery( "select t1.sa_orderid,t1.siteid,sum(ifnull(t2.outwarehouseqty,0)) sumoutwarehouseqty from sa_orderitems t1 left join sa_dispatch_items t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.sa_orderid in(select t3.sa_orderid 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 inner join sa_orderitems t3 on t2.sa_orderitemsid=t3.sa_orderitemsid and t2.siteid=t3.siteid where t1.st_stockbillid ="+stockbillrows.get(0).getLong("st_stockbillid")+" and t1.siteid='lsa1986') group by t1.sa_orderid,t1.siteid");
|
|
|
- //订单总数量
|
|
|
- Rows ordersumrows =dbConnect.runSqlQuery( "select t1.sa_orderid,t1.siteid,sum(qty) sumqty from sa_orderitems t1 where t1.sa_orderid in(select t3.sa_orderid 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 inner join sa_orderitems t3 on t2.sa_orderitemsid=t3.sa_orderitemsid and t2.siteid=t3.siteid where t1.st_stockbillid ="+stockbillrows.get(0).getLong("st_stockbillid")+" and t1.siteid='lsa1986') group by t1.sa_orderid,t1.siteid");
|
|
|
- RowsMap orderinstockRowsMap = orderinstockrows.toRowsMap("sa_orderid");
|
|
|
|
|
|
+ //查询可关闭的订单
|
|
|
+ //订单出库总数量
|
|
|
+ Rows orderinstockrows =dbConnect.runSqlQuery( "select t1.sa_orderid,t1.siteid,sum(ifnull(t2.outwarehouseqty,0)) sumoutwarehouseqty from sa_orderitems t1 left join sa_dispatch_items t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.sa_orderid in(select t3.sa_orderid 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 inner join sa_orderitems t3 on t2.sa_orderitemsid=t3.sa_orderitemsid and t2.siteid=t3.siteid where t1.st_stockbillid ="+stockbillrows.get(0).getLong("st_stockbillid")+" and t1.siteid='lsa1986') group by t1.sa_orderid,t1.siteid");
|
|
|
+ //订单总数量
|
|
|
+ Rows ordersumrows =dbConnect.runSqlQuery( "select t1.sa_orderid,t1.siteid,sum(qty) sumqty from sa_orderitems t1 where t1.sa_orderid in(select t3.sa_orderid 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 inner join sa_orderitems t3 on t2.sa_orderitemsid=t3.sa_orderitemsid and t2.siteid=t3.siteid where t1.st_stockbillid ="+stockbillrows.get(0).getLong("st_stockbillid")+" and t1.siteid='lsa1986') group by t1.sa_orderid,t1.siteid");
|
|
|
+ RowsMap orderinstockRowsMap = orderinstockrows.toRowsMap("sa_orderid");
|
|
|
|
|
|
- ArrayList<String> sqlorder =new ArrayList<>();
|
|
|
- for (Row row:ordersumrows) {
|
|
|
- if(orderinstockRowsMap.containsKey(row.getString("sa_orderid"))){
|
|
|
- if(orderinstockRowsMap.get(row.getString("sa_orderid")).get(0).getBigDecimal("sumoutwarehouseqty").compareTo(row.getBigDecimal("sumqty"))==0){
|
|
|
- sqlorder.add("update sa_order set status='关闭',closedate=current_time,closeby='admin' where sa_orderid='" + row.getLong("sa_orderid") + "' and siteid='lsa1986'");
|
|
|
+
|
|
|
+ ArrayList<String> sqlorder =new ArrayList<>();
|
|
|
+ for (Row row:ordersumrows) {
|
|
|
+ if(orderinstockRowsMap.containsKey(row.getString("sa_orderid"))){
|
|
|
+ if(orderinstockRowsMap.get(row.getString("sa_orderid")).get(0).getBigDecimal("sumoutwarehouseqty").compareTo(row.getBigDecimal("sumqty"))==0){
|
|
|
+ sqlorder.add("update sa_order set status='关闭',closedate=current_time,closeby='admin' where sa_orderid='" + row.getLong("sa_orderid") + "' and siteid='lsa1986'");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "数据操作日志新增");
|
|
|
+ sqlFactory.addParameter("sys_contrllogid", createTableID("sys_contrllog"));
|
|
|
+ sqlFactory.addParameter("ownertable", "sa_order");
|
|
|
+ sqlFactory.addParameter("ownerid", row.getLong("sa_orderid"));
|
|
|
+ sqlFactory.addParameter("action", "自动关闭");
|
|
|
+ sqlFactory.addParameter("remarks", "订单自动关闭成功");
|
|
|
+ sqlFactory.addParameter("actionuserid", "1");
|
|
|
+ sqlFactory.addParameter("actionby", "admin");
|
|
|
+ sqlFactory.addParameter("siteid", "lsa1986");
|
|
|
+ sqlorder.add(sqlFactory.getSQL());
|
|
|
+ }else {
|
|
|
+ sqlorder.add("update sa_order set status='审核',closedate=null,closeby='' where sa_orderid='" + row.getLong("sa_orderid") + "' and siteid='lsa1986'");
|
|
|
+ sqlorder.add("delete from sys_contrllog where ownertable='sa_order' and action='自动关闭' and ownerid='" + row.getLong("sa_orderid") + "' and siteid='lsa1986'");
|
|
|
+ }
|
|
|
}else {
|
|
|
sqlorder.add("update sa_order set status='审核',closedate=null,closeby='' where sa_orderid='" + row.getLong("sa_orderid") + "' and siteid='lsa1986'");
|
|
|
+ sqlorder.add("delete from sys_contrllog where ownertable='sa_order' and action='自动关闭' and ownerid='" + row.getLong("sa_orderid") + "' and siteid='lsa1986'");
|
|
|
}
|
|
|
- }else {
|
|
|
- sqlorder.add("update sa_order set status='审核',closedate=null,closeby='' where sa_orderid='" + row.getLong("sa_orderid") + "' and siteid='lsa1986'");
|
|
|
+
|
|
|
}
|
|
|
- SQLFactory sqlFactory = new SQLFactory(new DataContrlLog(), "数据操作日志新增");
|
|
|
- sqlFactory.addParameter("ownertable", "sa_order");
|
|
|
- sqlFactory.addParameter("ownerid", row.getLong("sa_orderid"));
|
|
|
- sqlFactory.addParameter("action", "自动关闭");
|
|
|
- sqlFactory.addParameter("remarks", "订单自动关闭成功");
|
|
|
- sqlFactory.addParameter("actionuserid", "1");
|
|
|
- sqlFactory.addParameter("actionby", "admin");
|
|
|
- sqlFactory.addParameter("siteid", "lsa1986");
|
|
|
- sqlorder.add(sqlFactory.getSQL());
|
|
|
- }
|
|
|
- dbConnect.runSqlUpdate(sqlorder);
|
|
|
+ dbConnect.runSqlUpdate(sqlorder);
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 如单据为新建状态,则,先把单据强行删除掉
|
|
|
+ */
|
|
|
+ dbConnect.runSqlUpdate("delete from st_stockbill where status='新建'");
|
|
|
|
|
|
- /**
|
|
|
- * 如单据为新建状态,则,先把单据强行删除掉
|
|
|
- */
|
|
|
- dbConnect.runSqlUpdate("delete from st_stockbill where status='新建'");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg = e.getMessage();
|
|
|
+ if(msg==null) {
|
|
|
+ msg = "";
|
|
|
+ }
|
|
|
+ code = 0;
|
|
|
+ dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid in(select st_stockbillid from st_stockbill where siteid='lsa1986' and billno='"+fbillnum+"')");
|
|
|
+ dbConnect.runSqlUpdate("delete from st_stockbill where billno='"+fbillnum+"' and siteid='lsa1986'");
|
|
|
+
|
|
|
+ }
|
|
|
JSONObject returnObject =new JSONObject();
|
|
|
returnObject.put("msg", msg);
|
|
|
returnObject.put("code", code);
|