|
|
@@ -19,6 +19,7 @@ import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
|
|
|
public class stockbill extends Controller {
|
|
|
/**
|
|
|
@@ -77,7 +78,7 @@ public class stockbill extends Controller {
|
|
|
// 是否删除
|
|
|
String isdelete = content.getString("isdelete");
|
|
|
|
|
|
- siteid="lsa";
|
|
|
+ siteid="lsa1986";
|
|
|
|
|
|
|
|
|
Rows stockbillRows = dbConnect.runSqlQuery("select * from st_stockbill where siteid='lsa1986' and status='审核' and billno='"+fbillnum+"'");
|
|
|
@@ -87,7 +88,7 @@ public class stockbill extends Controller {
|
|
|
*/
|
|
|
SQLFactory sqlFactory =new SQLFactory(this,"销售出库单新增");
|
|
|
long st_stockbillid=createTableID("st_stockbill");
|
|
|
- sqlFactory.addParameter("siteid","lsa");
|
|
|
+ sqlFactory.addParameter("siteid","lsa1986");
|
|
|
sqlFactory.addParameter("st_stockbillid",st_stockbillid);
|
|
|
sqlFactory.addParameter("sys_enterpriseid",sys_enterpriseid);
|
|
|
sqlFactory.addParameter("billno",fbillnum);
|
|
|
@@ -104,9 +105,18 @@ public class stockbill extends Controller {
|
|
|
sqlList.add(sqlFactory.getSQL());
|
|
|
|
|
|
JSONArray detailarray = content.getJSONArray("icstockbilldetails");
|
|
|
- Rows rows = dbConnect.runSqlQuery("select * from plm_item where siteid='lsa1986' ");
|
|
|
+ List<String> itemnos=new ArrayList<>();
|
|
|
+ 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"));
|
|
|
+ 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("]", ")"));
|
|
|
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' ");
|
|
|
+ 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");
|
|
|
BigDecimal amountTotal=BigDecimal.ZERO;
|
|
|
for (Object object:detailarray) {
|
|
|
@@ -120,7 +130,7 @@ public class stockbill extends Controller {
|
|
|
//String fbatchno = jsonObject.getString("fbatchno");
|
|
|
String fdetailnotes = jsonObject.getString("fnotes");
|
|
|
SQLFactory sqlFactorydetail =new SQLFactory(this,"销售出库单明细新增");
|
|
|
- sqlFactorydetail.addParameter("siteid","lsa");
|
|
|
+ sqlFactorydetail.addParameter("siteid","lsa1986");
|
|
|
sqlFactorydetail.addParameter("st_stockbill_itemsid", createTableID("st_stockbill_items"));
|
|
|
sqlFactorydetail.addParameter("st_stockbillid", st_stockbillid);
|
|
|
sqlFactorydetail.addParameter("rowno", frownum);
|
|
|
@@ -167,6 +177,8 @@ public class stockbill extends Controller {
|
|
|
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'");
|
|
|
+
|
|
|
+
|
|
|
}else if (!stockbillRows.isEmpty() && "0".equals(isdelete) && "审核".equals(fstatus)) {
|
|
|
/**
|
|
|
* DRP存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需将当前销售出库单先反审核,修改内容后再进行审核
|
|
|
@@ -223,8 +235,7 @@ public class stockbill extends Controller {
|
|
|
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='',checkdate=null where st_stockbillid = "+stockbillRows.get(0).getLong("st_stockbillid")+" and siteid='lsa1986'");
|
|
|
|
|
|
}
|
|
|
@@ -236,10 +247,30 @@ public class stockbill extends Controller {
|
|
|
}
|
|
|
code = 0;
|
|
|
}
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ /**
|
|
|
+ * 更新发货单数量
|
|
|
+ */
|
|
|
+ Rows stockbillrows =dbConnect.runSqlQuery("select st_stockbillid,status from st_stockbill where fbillnum='"+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");
|
|
|
+ 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"));
|
|
|
+ }
|
|
|
+ }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"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqldispatchitems);
|
|
|
+
|
|
|
/**
|
|
|
* 如单据为新建状态,则,先把单据强行删除掉
|
|
|
*/
|
|
|
- dbConnect.runSqlUpdate(sqlList);
|
|
|
dbConnect.runSqlUpdate("delete from st_stockbill where status='新建'");
|
|
|
JSONObject returnObject =new JSONObject();
|
|
|
returnObject.put("msg", msg);
|