|
|
@@ -0,0 +1,558 @@
|
|
|
+package restcontroller.webmanage.sale.dbstockbill;
|
|
|
+
|
|
|
+import beans.data.BatchDeleteErr;
|
|
|
+import beans.datacontrllog.DataContrlLog;
|
|
|
+import beans.invbal.Invbal;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.annotation.CACHEING;
|
|
|
+import common.annotation.CACHEING_CLEAN;
|
|
|
+import common.data.*;
|
|
|
+import restcontroller.R;
|
|
|
+import restcontroller.webmanage.sale.stockbill.stockbill;
|
|
|
+import restcontroller.webmanage.sale.stockbill.stockbillitems;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+public class dbstockbill extends Controller {
|
|
|
+ public dbstockbill(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "新增更新调拨单", apiversion = R.ID2025061914261403.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {dbstockbill.class,dbstockbilldetail.class})
|
|
|
+ public String insertormodify_dbstockbill() throws YosException {
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ // 表名
|
|
|
+
|
|
|
+ String tableName = "st_dbstockbill";
|
|
|
+ Long st_dbstockbillid = content.getLong("st_dbstockbillid");
|
|
|
+ Long departmentid = content.getLongValue("departmentid");
|
|
|
+ boolean isnotimmediately = content.getBooleanValue("isnotimmediately");
|
|
|
+ String remarks = content.getStringValue("remarks");
|
|
|
+ String billdate = content.getStringValue("billdate");
|
|
|
+ long instockid = content.getLong("instockid");
|
|
|
+ long outstockid = content.getLong("outstockid");
|
|
|
+ if (st_dbstockbillid <= 0) {
|
|
|
+
|
|
|
+ st_dbstockbillid = createTableID(tableName);
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, tableName);
|
|
|
+ insertSQL.setUniqueid(st_dbstockbillid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("isnotimmediately", isnotimmediately);
|
|
|
+ insertSQL.setValue("departmentid", departmentid);
|
|
|
+ insertSQL.setValue("remarks", remarks);
|
|
|
+ insertSQL.setValue("billdate", billdate);
|
|
|
+ insertSQL.setValue("billno", createBillCode("stockbill"));
|
|
|
+ insertSQL.setValue("instockid", instockid);
|
|
|
+ insertSQL.setValue("outstockid", outstockid);
|
|
|
+
|
|
|
+ insertSQL.setValue("createby", username);
|
|
|
+ insertSQL.setDateValue("createdate");
|
|
|
+ insertSQL.setValue("changeby", username);
|
|
|
+ insertSQL.setDateValue("changedate");
|
|
|
+ insertSQL.setValue("status", "新建");
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "st_dbstockbill", st_dbstockbillid, "新增", "调拨单新增成功").getSQL());
|
|
|
+ } else {
|
|
|
+ Rows rows = dbConnect.runSqlQuery(
|
|
|
+ "SELECT status from st_dbstockbill WHERE st_dbstockbillid = "
|
|
|
+ + st_dbstockbillid);
|
|
|
+ if (rows.isNotEmpty()) {
|
|
|
+ if (rows.get(0).getString("status").equals("新建")) {
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, tableName);
|
|
|
+ updateSQL.setUniqueid(st_dbstockbillid);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("departmentid", departmentid);
|
|
|
+ updateSQL.setValue("remarks", remarks);
|
|
|
+ updateSQL.setValue("billdate", billdate);
|
|
|
+// updateSQL.setValue("instockid", instockid);
|
|
|
+// updateSQL.setValue("outstockid", outstockid);
|
|
|
+ updateSQL.setValue("isnotimmediately", isnotimmediately);
|
|
|
+
|
|
|
+ updateSQL.setValue("changeby", username);
|
|
|
+ updateSQL.setDateValue("changedate");
|
|
|
+ sqlList.add(updateSQL.getSQL());
|
|
|
+
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "st_dbstockbill", st_dbstockbillid, "更新", "调拨单更新成功").getSQL());
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return getErrReturnObject().setErrMsg("该调拨单不存在").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ content.put("st_dbstockbillid", st_dbstockbillid);
|
|
|
+
|
|
|
+ return queryDbStockbillMain();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "调拨单详情", apiversion = R.ID2025061914271503.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryDbStockbillMain() throws YosException {
|
|
|
+ long st_dbstockbillid = content.getLong("st_dbstockbillid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_dbstockbill","*");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t2", "t1.instockid = t2.stockid AND t1.siteid = t2.siteid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t3", "t1.outstockid = t3.stockid AND t1.siteid = t3.siteid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t4", "t1.departmentid=t4.departmentid and t1.siteid = t4.siteid","depname");
|
|
|
+
|
|
|
+ querySQL.addQueryFields("outstockno", "t3.stockno");
|
|
|
+ querySQL.addQueryFields("outstockname", "t3.stockname");
|
|
|
+ querySQL.addQueryFields("instockno", "t2.stockno");
|
|
|
+ querySQL.addQueryFields("instockname", "t2.stockname");
|
|
|
+ querySQL.setWhere("t1.siteid", siteid);
|
|
|
+ querySQL.setWhere("t1.st_dbstockbillid",st_dbstockbillid);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
|
|
|
+ return getSucReturnObject().setData(row).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "调拨单列表", apiversion = R.ID2025061914273303.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryDbStockbillList() throws YosException {
|
|
|
+ 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("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.stockname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.stockno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t3.stockname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t3.stockno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t4.depname like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
|
|
|
+ where.append(" and t1.status ='").append(whereObject.getString("status")).append("' ");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
|
|
|
+ where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
|
|
|
+ }
|
|
|
+ }
|
|
|
+// SQLFactory sqlFactory = new SQLFactory(this, "出入库单列表查询", pageSize, pageNumber, pageSorting);
|
|
|
+// sqlFactory.addParameter("siteid", siteid);
|
|
|
+// sqlFactory.addParameter_SQL("where", where);
|
|
|
+// Rows rows = dbConnect.runSqlQuery(sqlFactory);
|
|
|
+ QuerySQL querySQL = queryStockbillList(where.toString());
|
|
|
+ querySQL.setPage(pageSize, pageNumber);
|
|
|
+ querySQL.setOrderBy(pageSorting);
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "删除", apiversion = R.ID2025061914455503.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {dbstockbill.class,dbstockbilldetail.class})
|
|
|
+ public String delete() throws YosException {
|
|
|
+ JSONArray st_dbstockbillids = content.getJSONArray("st_dbstockbillids");
|
|
|
+ BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, st_dbstockbillids.size());
|
|
|
+ for (Object o : st_dbstockbillids) {
|
|
|
+ long st_dbstockbillid = Long.parseLong(o.toString());
|
|
|
+ Rows RowsStatus = dbConnect.runSqlQuery("select st_dbstockbillid,status from st_dbstockbill where siteid='"
|
|
|
+ + siteid + "' and st_dbstockbillid='" + st_dbstockbillid + "'");
|
|
|
+
|
|
|
+ if (RowsStatus.isNotEmpty()) {
|
|
|
+ if (!RowsStatus.get(0).getString("status").equals("新建")) {
|
|
|
+ batchDeleteErr.addErr(st_dbstockbillid, "非新建状态的调拨单无法删除");
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(
|
|
|
+ "delete from st_dbstockbill where siteid='" + siteid + "' and st_dbstockbillid=" + st_dbstockbillid);
|
|
|
+ }
|
|
|
+ return batchDeleteErr.getReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "审核", apiversion = R.ID2025061914484803.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {dbstockbill.class,dbstockbilldetail.class})
|
|
|
+ public String check() throws YosException {
|
|
|
+ long st_dbstockbillid = content.getLong("st_dbstockbillid");
|
|
|
+ Rows dbstockbillrows =dbConnect.runSqlQuery("select * from st_dbstockbill where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"'");
|
|
|
+ Rows dbstockbilldetailrows =dbConnect.runSqlQuery("select t1.*,t2.itemname,t2.itemno,t2.model from st_dbstockbilldetail t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_dbstockbillid='"+st_dbstockbillid+"' and t1.siteid='"+siteid+"'");
|
|
|
+ Rows dbstockbilldetailskurows =dbConnect.runSqlQuery("select st_dbstockbilldetailid,count(1) qty from st_dbstockbilldetailsku where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"' group by st_dbstockbilldetailid");
|
|
|
+ Rows dbstockbilldetailskus =dbConnect.runSqlQuery("select st_dbstockbilldetailid,sku,outstockid from st_dbstockbilldetailsku where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"'");
|
|
|
+ RowsMap dbstockbilldetailskurowsMap =dbstockbilldetailskurows.toRowsMap("st_dbstockbilldetailid");
|
|
|
+ RowsMap dbstockbilldetailrowsMap =dbstockbilldetailrows.toRowsMap("st_dbstockbilldetailid");
|
|
|
+ RowsMap dbstockbilldetailskusRowsMap=dbstockbilldetailskus.toRowsMap("st_dbstockbilldetailid");
|
|
|
+ for(Row row :dbstockbilldetailrows){
|
|
|
+ if(row.getBigDecimal("qty").compareTo(BigDecimal.ZERO)<=0){
|
|
|
+ return getErrReturnObject().setErrMsg("调拨数量不能小于等于0").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for(Row row :dbstockbilldetailrows){
|
|
|
+ if(row.getLong("instockid")!=dbstockbillrows.get(0).getLong("instockid")){
|
|
|
+ return getErrReturnObject().setErrMsg("表体调入仓库必须与表头调入仓库一致").toString();
|
|
|
+ }
|
|
|
+ if(row.getLong("outstockid")!=dbstockbillrows.get(0).getLong("outstockid")){
|
|
|
+ return getErrReturnObject().setErrMsg("表体调出仓库必须与表头调出仓库一致").toString();
|
|
|
+ }
|
|
|
+ if(row.getLong("instockid")==row.getLong("outstockid")){
|
|
|
+ return getErrReturnObject().setErrMsg("调入仓库与调出仓库一致,不可审核").toString();
|
|
|
+ }
|
|
|
+ if(dbstockbilldetailskurowsMap.containsKey(row.getString("st_dbstockbilldetailid"))){
|
|
|
+ if(row.getInteger("qty")!=dbstockbilldetailskurowsMap.get(row.getString("st_dbstockbilldetailid")).get(0).getInteger("qty")){
|
|
|
+ return getErrReturnObject().setErrMsg("货品"+row.getString("itemname")+"调拨数量和序列号数量不符").toString();
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ return getErrReturnObject().setErrMsg("货品"+row.getString("itemname")+"序列号不存在").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /******************* 检查序列号是否有效 ********************/
|
|
|
+ Rows skurows =dbConnect.runSqlQuery("select * from sa_itemsku where siteid='"+siteid+"'");
|
|
|
+ RowsMap skurowsmap =skurows.toRowsMap("sku");
|
|
|
+ for(Row row :dbstockbilldetailskus){
|
|
|
+ if(!skurowsmap.containsKey(row.getString("sku"))){
|
|
|
+ return getErrReturnObject().setErrMsg("序列号" + row.getString("sku")+"不存在于序列号表中").toString();
|
|
|
+ }
|
|
|
+ if(skurowsmap.get(row.getString("sku")).get(0).getLong("stockid")<=0){
|
|
|
+ return getErrReturnObject().setErrMsg("序列号" + row.getString("sku") + "不在仓库中,无法进行调拨").toString();
|
|
|
+ }
|
|
|
+ if(skurowsmap.get(row.getString("sku")).get(0).getLong("stockid")!=row.getLong("outstockid")){
|
|
|
+ return getErrReturnObject().setErrMsg("序列号" + row.getString("sku")+ "所在仓库已变动").toString();
|
|
|
+ }
|
|
|
+ if(!dbstockbilldetailrowsMap.containsKey(row.getString("st_dbstockbilldetailid"))){
|
|
|
+ return getErrReturnObject().setErrMsg("关联表体不存在").toString();
|
|
|
+ }
|
|
|
+ if(dbstockbilldetailrowsMap.get(row.getString("st_dbstockbilldetailid")).get(0).getLong("outstockid")
|
|
|
+ !=row.getLong("outstockid")){
|
|
|
+ return getErrReturnObject().setErrMsg("货品" + dbstockbilldetailrowsMap.get(row.getString("st_dbstockbilldetailid")).get(0).getString("itemno") + "的调出仓库与其序列号" + row.getString("sku") + "所在仓库不一致").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Rows stockbill=dbConnect.runSqlQuery("select * from st_stockbill where sourceid="+st_dbstockbillid +" and sourceobject='st_dbstockbill' and siteid='"+siteid+"'");
|
|
|
+ if (!stockbill.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("该调拨单存在对应的出入库单单据,不可审核").toString();
|
|
|
+ }
|
|
|
+ ArrayList<String> sqllist=new ArrayList<>();
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
|
|
|
+ long st_stockbillid = createTableID("st_stockbill");
|
|
|
+ insertSQL.setUniqueid(st_stockbillid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("billno", createBillCode("stockbill"));
|
|
|
+ insertSQL.setValue("type", "其他出库");
|
|
|
+ insertSQL.setValue("typemx", "调拨出库");
|
|
|
+ insertSQL.setValue("sys_enterpriseid",0);
|
|
|
+ insertSQL.setValue("rb", 1);
|
|
|
+ insertSQL.setValue("sourceobject", "st_dbstockbill");
|
|
|
+ insertSQL.setValue("sourceid", st_dbstockbillid);
|
|
|
+ insertSQL.setValue("stockid", dbstockbillrows.get(0).getLong("outstockid"));
|
|
|
+ insertSQL.setValue("remarks", "调拨出库"+dbstockbillrows.get(0).getString("remarks"));
|
|
|
+ insertSQL.setValue("status", "审核");
|
|
|
+ insertSQL.setValue("createby",username);
|
|
|
+ insertSQL.setDateValue("createdate");
|
|
|
+ insertSQL.setValue("checkby",username);
|
|
|
+ insertSQL.setDateValue("checkdate");
|
|
|
+ insertSQL.setDateValue("billdate");
|
|
|
+ sqllist.add(insertSQL.getSQL());
|
|
|
+
|
|
|
+ int i=1;
|
|
|
+ for(Row row :dbstockbilldetailrows){
|
|
|
+ insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
|
|
|
+ long st_stockbill_itemsid = createTableID("st_stockbill_items");
|
|
|
+ insertSQL.setUniqueid(st_stockbill_itemsid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("rowno",i);
|
|
|
+ insertSQL.setValue("sa_dispatch_itemsid",0);
|
|
|
+ insertSQL.setValue("sourceobject", "st_dbstockbilldetail");
|
|
|
+ insertSQL.setValue("sourceid", row.getLong("st_dbstockbilldetailid"));
|
|
|
+ insertSQL.setValue("stockid", row.getLong("outstockid"));
|
|
|
+ insertSQL.setValue("itemid",row.getLong("itemid"));
|
|
|
+ insertSQL.setValue("itemno",row.getString("itemno"));
|
|
|
+ insertSQL.setValue("itemname",row.getString("itemname"));
|
|
|
+ insertSQL.setValue("model",row.getString("model"));
|
|
|
+ insertSQL.setValue("qty",row.getBigDecimal("qty"));
|
|
|
+ insertSQL.setValue("st_stockbillid",st_stockbillid);
|
|
|
+ i++;
|
|
|
+ sqllist.add(insertSQL.getSQL());
|
|
|
+ for(Row rowdetail:dbstockbilldetailskusRowsMap.get(row.getString("st_dbstockbilldetailid"))){
|
|
|
+ insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
|
|
|
+ long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
|
|
|
+ insertSQL.setUniqueid(st_stockbill_items_skuid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("stockid", rowdetail.getLong("outstockid"));
|
|
|
+ insertSQL.setValue("itemid",row.getLong("itemid"));
|
|
|
+ insertSQL.setValue("sku",rowdetail.getString("sku"));
|
|
|
+ insertSQL.setValue("st_stockbillid",st_stockbillid);
|
|
|
+ insertSQL.setValue("st_stockbill_itemsid",st_stockbill_itemsid);
|
|
|
+ sqllist.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sqllist.addAll(updateIcinvbal(true,false,st_dbstockbillid));
|
|
|
+ if(!dbstockbillrows.get(0).getBoolean("isnotimmediately")){
|
|
|
+ insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
|
|
|
+ st_stockbillid = createTableID("st_stockbill");
|
|
|
+ insertSQL.setUniqueid(st_stockbillid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("billno", createBillCode("stockbill"));
|
|
|
+ insertSQL.setValue("type", "其他入库");
|
|
|
+ insertSQL.setValue("typemx", "调拨入库");
|
|
|
+ insertSQL.setValue("rb", 1);
|
|
|
+ insertSQL.setValue("sys_enterpriseid",0);
|
|
|
+ insertSQL.setValue("sourceobject", "st_dbstockbill");
|
|
|
+ insertSQL.setValue("sourceid", st_dbstockbillid);
|
|
|
+ insertSQL.setValue("stockid", dbstockbillrows.get(0).getLong("instockid"));
|
|
|
+ insertSQL.setValue("remarks", "调拨入库");
|
|
|
+ insertSQL.setValue("status", "审核");
|
|
|
+ insertSQL.setValue("createby",username);
|
|
|
+ insertSQL.setDateValue("createdate");
|
|
|
+ insertSQL.setValue("checkby",username);
|
|
|
+ insertSQL.setDateValue("checkdate");
|
|
|
+ insertSQL.setDateValue("billdate");
|
|
|
+ sqllist.add(insertSQL.getSQL());
|
|
|
+ int j=1;
|
|
|
+ for(Row row :dbstockbilldetailrows){
|
|
|
+ insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items");
|
|
|
+ long st_stockbill_itemsid = createTableID("st_stockbill_items");
|
|
|
+ insertSQL.setUniqueid(st_stockbill_itemsid);
|
|
|
+ insertSQL.setValue("rowno",j);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_dispatch_itemsid",0);
|
|
|
+ insertSQL.setValue("sourceobject", "st_dbstockbilldetail");
|
|
|
+ insertSQL.setValue("sourceid", row.getLong("st_dbstockbilldetailid"));
|
|
|
+ insertSQL.setValue("stockid", row.getLong("instockid"));
|
|
|
+ insertSQL.setValue("itemid",row.getLong("itemid"));
|
|
|
+ insertSQL.setValue("itemno",row.getString("itemno"));
|
|
|
+ insertSQL.setValue("itemname",row.getString("itemname"));
|
|
|
+ insertSQL.setValue("model",row.getString("model"));
|
|
|
+ insertSQL.setValue("qty",row.getBigDecimal("qty"));
|
|
|
+ insertSQL.setValue("st_stockbillid",st_stockbillid);
|
|
|
+ sqllist.add(insertSQL.getSQL());
|
|
|
+ j++;
|
|
|
+ for(Row rowdetail:dbstockbilldetailskusRowsMap.get(row.getString("st_dbstockbilldetailid"))){
|
|
|
+ insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill_items_sku");
|
|
|
+ long st_stockbill_items_skuid = createTableID("st_stockbill_items_sku");
|
|
|
+ insertSQL.setUniqueid(st_stockbill_items_skuid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("stockid", row.getLong("instockid"));
|
|
|
+ insertSQL.setValue("itemid",row.getLong("itemid"));
|
|
|
+ insertSQL.setValue("sku",rowdetail.getString("sku"));
|
|
|
+ insertSQL.setValue("st_stockbillid",st_stockbillid);
|
|
|
+ insertSQL.setValue("st_stockbill_itemsid",st_stockbill_itemsid);
|
|
|
+ sqllist.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sqllist.addAll(updateIcinvbal(true,true,st_dbstockbillid));
|
|
|
+ sqllist.addAll(updateUnInQty(true,dbstockbilldetailrows));
|
|
|
+
|
|
|
+ }
|
|
|
+ sqllist.addAll(updatesku(dbstockbillrows.get(0).getLong("instockid"),dbstockbillrows.get(0).getLong("outstockid"),dbstockbilldetailskus,true,!dbstockbillrows.get(0).getBoolean("isnotimmediately")));
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_dbstockbill");
|
|
|
+ updateSQL.setUniqueid(st_dbstockbillid);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("status", "审核");
|
|
|
+ updateSQL.setValue("checkby", username);
|
|
|
+ updateSQL.setDateValue("checkdate");
|
|
|
+ sqllist.add(updateSQL.getSQL());
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqllist);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "反审核", apiversion = R.ID2025061914490803.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {dbstockbill.class,dbstockbilldetail.class})
|
|
|
+ public String uncheck() throws YosException {
|
|
|
+ long st_dbstockbillid = content.getLong("st_dbstockbillid");
|
|
|
+ Rows dbstockbillrows =dbConnect.runSqlQuery("select * from st_dbstockbill where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"'");
|
|
|
+ Rows dbstockbilldetailrows =dbConnect.runSqlQuery("select t1.*,t2.itemname,t2.itemno,t2.model from st_dbstockbilldetail t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_dbstockbillid='"+st_dbstockbillid+"' and t1.siteid='"+siteid+"'");
|
|
|
+ Rows dbstockbilldetailskus =dbConnect.runSqlQuery("select st_dbstockbilldetailid,sku,outstockid from st_dbstockbilldetailsku where st_dbstockbillid='"+st_dbstockbillid+"' and siteid='"+siteid+"'");
|
|
|
+ RowsMap dbstockbilldetailrowsMap =dbstockbilldetailrows.toRowsMap("st_dbstockbilldetailid");
|
|
|
+
|
|
|
+ /******************* 检查序列号是否有效 ********************/
|
|
|
+ Rows skurows =dbConnect.runSqlQuery("select * from sa_itemsku where siteid='"+siteid+"'");
|
|
|
+ RowsMap skurowsmap =skurows.toRowsMap("sku");
|
|
|
+ for(Row row :dbstockbilldetailskus){
|
|
|
+ if(!skurowsmap.containsKey(row.getString("sku"))){
|
|
|
+ return getErrReturnObject().setErrMsg("序列号" + row.getString("sku")+"不存在于序列号表中").toString();
|
|
|
+ }
|
|
|
+
|
|
|
+// if(skurowsmap.get(row.getString("sku")).get(0).getLong("stockid")!=row.getLong("instockid")){
|
|
|
+// return getErrReturnObject().setErrMsg("序列号" + row.getString("sku")+ "所在仓库已变动").toString();
|
|
|
+// }
|
|
|
+ if(!dbstockbilldetailrowsMap.containsKey(row.getString("st_dbstockbilldetailid"))){
|
|
|
+ return getErrReturnObject().setErrMsg("关联表体不存在").toString();
|
|
|
+ }
|
|
|
+ if(dbstockbilldetailrowsMap.get(row.getString("st_dbstockbilldetailid")).get(0).getLong("instockid")
|
|
|
+ !=skurowsmap.get(row.getString("sku")).get(0).getLong("stockid")){
|
|
|
+ return getErrReturnObject().setErrMsg("序列号" + row.getString("sku")+ "所在仓库已变动").toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Rows stockbill=dbConnect.runSqlQuery("select * from st_stockbill where sourceid="+st_dbstockbillid +" and sourceobject='st_dbstockbill' and siteid='"+siteid+"'");
|
|
|
+ RowsMap stockbillrowmap =stockbill.toRowsMap("typemx");
|
|
|
+ if (!stockbillrowmap.containsKey("调拨出库")) {
|
|
|
+ return getErrReturnObject().setErrMsg("找不到该调拨单对应的出库单,不可反审核").toString();
|
|
|
+ }
|
|
|
+ if (!stockbillrowmap.containsKey("调拨入库")) {
|
|
|
+ return getErrReturnObject().setErrMsg("找不到该调拨单对应的入库单,不可反审核").toString();
|
|
|
+ }
|
|
|
+ ArrayList<String> sqllist=new ArrayList<>();
|
|
|
+ if (!dbstockbillrows.get(0).getBoolean("isnotimmediately")) {// 如果不需要收货确认,则反审核原入库单,并删除
|
|
|
+ sqllist.addAll(updateIcinvbal(false, false,st_dbstockbillid));
|
|
|
+ }
|
|
|
+
|
|
|
+ sqllist.addAll(updateIcinvbal(false,true,st_dbstockbillid));
|
|
|
+ sqllist.addAll(updateUnInQty(false,dbstockbilldetailrows));
|
|
|
+ sqllist.addAll(updatesku(dbstockbillrows.get(0).getLong("instockid"),dbstockbillrows.get(0).getLong("outstockid"),dbstockbilldetailskus,false,true));
|
|
|
+ Rows glstockbillRows = dbConnect.runSqlQuery("select st_stockbillid from st_stockbill where sourceid="+st_dbstockbillid+" and sourceobject='st_dbstockbill' and siteid='"+siteid+"'");
|
|
|
+ for(Row row :glstockbillRows){
|
|
|
+ sqllist.add("delete from st_stockbill where siteid='"+siteid+"' and st_stockbillid="+row.getLong("st_stockbillid"));
|
|
|
+ sqllist.add("delete from st_stockbill_items where siteid='"+siteid+"' and st_stockbillid="+row.getLong("st_stockbillid"));
|
|
|
+ sqllist.add("delete from st_stockbill_items_sku where siteid='"+siteid+"' and st_stockbillid="+row.getLong("st_stockbillid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "st_dbstockbill");
|
|
|
+ updateSQL.setUniqueid(st_dbstockbillid);
|
|
|
+ updateSQL.setSiteid(siteid);
|
|
|
+ updateSQL.setValue("status", "新建");
|
|
|
+ updateSQL.setValue("checkby", "");
|
|
|
+ updateSQL.setValue("checkdate","null");
|
|
|
+ sqllist.add(updateSQL.getSQL());
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate(sqllist);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ //查询调拨单列表
|
|
|
+ public QuerySQL queryStockbillList(String where) throws YosException {
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_dbstockbill","*");
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t2", "t1.instockid = t2.stockid AND t1.siteid = t2.siteid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "st_stock", "t3", "t1.outstockid = t3.stockid AND t1.siteid = t3.siteid");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_department", "t4", "t1.departmentid=t4.departmentid and t1.siteid = t4.siteid","depname");
|
|
|
+
|
|
|
+ querySQL.addQueryFields("outstockno", "t3.stockno");
|
|
|
+ querySQL.addQueryFields("outstockname", "t3.stockname");
|
|
|
+ querySQL.addQueryFields("instockno", "t2.stockno");
|
|
|
+ querySQL.addQueryFields("instockname", "t2.stockname");
|
|
|
+ querySQL.setWhere("t1.siteid", siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ return querySQL;
|
|
|
+ }
|
|
|
+
|
|
|
+ public ArrayList<String> updateIcinvbal(boolean ischeck,boolean isinstock,Long st_dbstockbillid) throws YosException {
|
|
|
+ ArrayList<String> sqlList =new ArrayList();
|
|
|
+ Rows dbstockbilldetail =dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_dbstockbilldetail t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_dbstockbillid ='"
|
|
|
+ + st_dbstockbillid + "' and t1.siteid='" + siteid + "'");// 出入库表体
|
|
|
+ ArrayList<Long> itemids = new ArrayList<Long>();
|
|
|
+ itemids = dbstockbilldetail.toArrayList("itemid",new ArrayList<>());
|
|
|
+ itemids.add((long) 0);
|
|
|
+ int i = 0;
|
|
|
+ String sql="select * from st_invbal where itemid in"+itemids;
|
|
|
+ sql = sql.replace("[", "(").replace("]", ")");
|
|
|
+ Rows invbals = dbConnect.runSqlQuery(sql);
|
|
|
+ RowsMap invbalsRowsMap=invbals.toRowsMap("itemid");
|
|
|
+ for(Row row : dbstockbilldetail){
|
|
|
+ String itemid = row.getString("itemid");
|
|
|
+ //String batchno = row.getString("batchno");
|
|
|
+ //String fdcspno = row.getString("fdcspno");
|
|
|
+ long stockid;
|
|
|
+
|
|
|
+ if ((ischeck && isinstock) || (!ischeck && !isinstock)) {
|
|
|
+ stockid = row.getLong("instockid");
|
|
|
+ }else{
|
|
|
+ stockid = row.getLong("outstockid");
|
|
|
+ }
|
|
|
+
|
|
|
+// if (type == 1 && !getSysVars().getBoolean("FISBATCHFORXC")) {
|
|
|
+// fdcspno = "**********";
|
|
|
+// fbatchno = "**********";
|
|
|
+// fstockno = getPaoSet("TDEPARTMENT").getPao(0)
|
|
|
+// .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
|
|
|
+// icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
|
|
|
+// "fitemno='" + fitemno + "' and fstockno='" + fstockno
|
|
|
+// + "' and fdcspno='" + fdcspno
|
|
|
+// + "' and fbatchno='" + fbatchno + "'");
|
|
|
+// } else if (type == 2 && !getSysVars().getBoolean("FISBATCHFORXC")) {
|
|
|
+// fdcspno = "**********";
|
|
|
+// fbatchno = "**********";
|
|
|
+// fstockno = getPaoSet("TSUPPLIER").getPao(0)
|
|
|
+// .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
|
|
|
+// icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
|
|
|
+// "fitemno='" + fitemno + "' and fstockno='" + fstockno
|
|
|
+// + "' and fdcspno='" + fdcspno
|
|
|
+// + "' and fbatchno='" + fbatchno + "'");
|
|
|
+// }
|
|
|
+ BigDecimal qty = isinstock ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
|
|
|
+ if(!invbalsRowsMap.containsKey(itemid)){
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "即时库存新增");
|
|
|
+ sqlFactory.addParameter("st_invbalid", createTableID("st_invbal"));
|
|
|
+ sqlFactory.addParameter("qty", qty);
|
|
|
+ sqlFactory.addParameter("itemid", itemid);
|
|
|
+ sqlFactory.addParameter("stockid", stockid);
|
|
|
+ sqlFactory.addParameter("siteid",siteid);
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ sqlFactory.addParameter("username", username);
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ }else{
|
|
|
+ if(invbalsRowsMap.get(itemid).toRowsMap("stockid").containsKey(stockid)){
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "即时库存更新");
|
|
|
+ sqlFactory.addParameter("st_invbalid", createTableID("st_invbal"));
|
|
|
+ sqlFactory.addParameter("qty", invbalsRowsMap.get(itemid).toRowsMap("stockid").get(stockid).get(0).getBigDecimal("qty").add(qty));
|
|
|
+ sqlFactory.addParameter("itemid", itemid);
|
|
|
+ sqlFactory.addParameter("stockid", stockid);
|
|
|
+ sqlFactory.addParameter("siteid",siteid);
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ sqlFactory.addParameter("username", username);
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ }else{
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(new Invbal(), "即时库存新增");
|
|
|
+ sqlFactory.addParameter("st_invbalid", createTableID("st_invbal"));
|
|
|
+ sqlFactory.addParameter("qty", qty);
|
|
|
+ sqlFactory.addParameter("itemid", itemid);
|
|
|
+ sqlFactory.addParameter("stockid", stockid);
|
|
|
+ System.err.println(stockid);
|
|
|
+ sqlFactory.addParameter("siteid",siteid);
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ sqlFactory.addParameter("username", username);
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sqlList;
|
|
|
+ }
|
|
|
+ public ArrayList<String> updatesku(long instockid,long outstockid,Rows dbstockbilldetailskus, boolean ischeck, boolean isinbillneedcheck) {
|
|
|
+ ArrayList<String> sqllist =new ArrayList<>();
|
|
|
+ for(Row row : dbstockbilldetailskus){
|
|
|
+ if (ischeck) {// 审核
|
|
|
+ if (isinbillneedcheck) {
|
|
|
+ sqllist.add("update sa_itemsku set stockid="+instockid+" where sku='"+row.getString("sku")+"'");
|
|
|
+ } else {
|
|
|
+ sqllist.add("update sa_itemsku set stockid=0 where sku='"+row.getString("sku")+"'");
|
|
|
+ }
|
|
|
+ } else {// 反审核
|
|
|
+ sqllist.add("update sa_itemsku set stockid="+outstockid+" where sku='"+row.getString("sku")+"'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sqllist;
|
|
|
+ }
|
|
|
+ public ArrayList<String> updateUnInQty( boolean ischeck, Rows dbstockbilldetail) {
|
|
|
+ ArrayList<String> sqllist =new ArrayList<>();
|
|
|
+ for(Row row : dbstockbilldetail){
|
|
|
+ if (ischeck) {// 审核
|
|
|
+ sqllist.add("update st_dbstockbilldetail set undeliqty=0 where st_dbstockbilldetailid='"+row.getString("st_dbstockbilldetailid")+"'");
|
|
|
+ } else {// 反审核
|
|
|
+ sqllist.add("update st_dbstockbilldetail set undeliqty="+row.getBigDecimal("qty")+" where st_dbstockbilldetailid='"+row.getString("st_dbstockbilldetailid")+"'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sqllist;
|
|
|
+ }
|
|
|
+}
|