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

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

shenjingwei 3 месяцев назад
Родитель
Сommit
81621a77e8

+ 15 - 0
src/custom/restcontroller/R.java

@@ -6796,6 +6796,21 @@ public class R {
         public static class v1 {
         }
     }
+
+    public static class ID2025102409585903 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025102413280503 {
+        public static class v1 {
+        }
+    }
+
+    public static class ID2025102509532403 {
+        public static class v1 {
+        }
+    }
 }
 
 

+ 907 - 1
src/custom/restcontroller/webmanage/sale/sendrepair/sendrepair.java

@@ -1,5 +1,7 @@
 package restcontroller.webmanage.sale.sendrepair;
 
+import beans.accountbalance.Accountbalance;
+import beans.accountbalance.CashbillEntity;
 import beans.data.BatchDeleteErr;
 import beans.datacontrllog.DataContrlLog;
 import com.alibaba.fastjson2.JSONArray;
@@ -10,8 +12,10 @@ import common.annotation.API;
 import common.annotation.CACHEING;
 import common.annotation.CACHEING_CLEAN;
 import common.data.*;
+import org.apache.commons.lang.StringUtils;
 import restcontroller.R;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
 
 @API(title = "送修单")
@@ -56,7 +60,7 @@ public class sendrepair extends Controller {
                     sqlList.add(DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "更新", "送修单更新成功")
                             .getSQL());
                 } else {
-                    return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
+                   // return getErrReturnObject().setErrMsg("非新建状态下无法编辑").toString();
                 }
 
             } else {
@@ -78,6 +82,12 @@ public class sendrepair extends Controller {
         UpdateSQLdetail.setValue("disposition", content.getStringValue("disposition"));
         UpdateSQLdetail.setValue("idearemarks", content.getStringValue("idearemarks"));
         UpdateSQLdetail.setValue("agentcost", content.getBigDecimal("agentcost"));
+
+        UpdateSQLdetail.setValue("newitemid", content.getStringValue("newitemid"));
+        UpdateSQLdetail.setValue("newitenmno", content.getStringValue("newitenmno"));
+        UpdateSQLdetail.setValue("newitemname", content.getStringValue("newitemname"));
+        UpdateSQLdetail.setValue("newspec", content.getStringValue("newspec"));
+        UpdateSQLdetail.setValue("newsku", content.getStringValue("newsku"));
         sqlList.add(UpdateSQLdetail.getSQL());
 
         dbConnect.runSqlUpdate(sqlList);
@@ -207,4 +217,900 @@ public class sendrepair extends Controller {
         return batchDeleteErr.getReturnObject().toString();
 
     }
+
+    @API(title = "确认", apiversion = R.ID2025102409585903.v1.class)
+    public String confirm() throws YosException {
+        Long sa_sendrepairid = content.getLong("sa_sendrepairid");
+        boolean isconfirm = content.getBooleanValue("isconfirm");
+
+        Rows rows = dbConnect.runSqlQuery("select t1.billno,t1.status,t2.reason,t2.disposition from sa_sendrepair t1 inner join sa_sendrepair_detail t2  on t1.sa_sendrepairid=t2.sa_sendrepairid where t1.sa_sendrepairid ='"
+                + sa_sendrepairid + "' and  t1.siteid='" + siteid + "'");
+
+        for (Row row : rows) {
+            if (isconfirm) {
+                if (!row.getString("status").equals("新建")) {
+                    return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非新建状态,无法确认")
+                            .toString();
+                }
+                if (StringUtils.isBlank(row.getString("reason")) || StringUtils.isBlank(row.getString("disposition")) ) {
+                    return getErrReturnObject().setErrMsg("原因分析,处理意见必填")
+                            .toString();
+                }
+
+            } else {
+                if (!row.getString("status").equals("确认")) {
+                    return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非确认状态,无法反确认")
+                            .toString();
+                }
+            }
+
+        }
+        ArrayList<String> sqlList = new ArrayList<>();
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair");
+        updateSQL.setUniqueid(sa_sendrepairid);
+        updateSQL.setSiteid(siteid);
+
+
+        if (isconfirm) {
+            updateSQL.setValue("status","确认");
+            updateSQL.setValue("confirmby",username);
+            updateSQL.setDateValue("confirmdate");
+            sqlList.add(
+                    DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "确认", "送修单确认成功").getSQL());
+        } else {
+            updateSQL.setValue("status","新建");
+            updateSQL.setValue("confirmby","");
+            updateSQL.setValue("confirmdate","null");
+            sqlList.add(
+                    DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "反确认", "送修单反确认成功").getSQL());
+        }
+        sqlList.add(updateSQL.getSQL());
+        dbConnect.runSqlUpdate(sqlList);
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "进仓", apiversion = R.ID2025102413280503.v1.class)
+    public String instock() throws YosException {
+        Long sa_sendrepairid = content.getLong("sa_sendrepairid");
+        boolean isinstock = content.getBooleanValue("isinstock");
+
+        Rows rows = dbConnect.runSqlQuery("select t1.sys_enterpriseid,t1.remarks,t1.billno,t1.status,t2.qty,t2.sa_sendrepair_detailid,t2.reason,t2.disposition,t2.newitemno,t2.newsku,t2.newitemid,t2.sku,t2.name,t2.phonenumber,t2.address,t3.itemno,t2.itemid,t3.itemname,t3.model,t4.model newmodel,t4.skucontrol from sa_sendrepair t1 " +
+                "inner join sa_sendrepair_detail t2  on t1.sa_sendrepairid=t2.sa_sendrepairid" +
+                "left join plm_item t3 on t3.itemid=t2.itemid" +
+                "left join plm_item t4 on t4.itemid=t2.newitemid" +
+                " where t1.sa_sendrepairid ='"
+                + sa_sendrepairid + "' and  t1.siteid='" + siteid + "'");
+        if(rows.isEmpty()){
+            return getErrReturnObject().setErrMsg("送修单不存在")
+                    .toString();
+        }
+        Row row =rows.get(0);
+        if (isinstock) {
+            if (!row.getString("status").equals("确认")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非确认状态,无法进仓")
+                        .toString();
+            }
+            if (row.getString("disposition").equals("待修")) {
+                return getErrReturnObject().setErrMsg("待修不可进仓")
+                        .toString();
+            }
+
+        } else {
+            if (!row.getString("status").equals("进仓")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非进仓状态,无法反进仓")
+                        .toString();
+            }
+            Rows stockbillRows = dbConnect.runSqlQuery("select type,typemx from st_stockbill where sourceid="+sa_sendrepairid+" and sourceobject='sa_sendrepair' and status='审核'");
+            RowsMap stockbillRowsMap =stockbillRows.toRowsMap("type");
+            if (stockbillRowsMap.containsKey("返修出库")) {
+                return getErrReturnObject().setErrMsg("已生成的出库单已审核不可反进仓").toString();
+            }
+            if (stockbillRowsMap.containsKey("其他入库")) {
+                for(Row stockbillRow :stockbillRowsMap.get("其他入库")){
+                    if(stockbillRow.getString("typemx").equals("正品入库")){
+                        return getErrReturnObject().setErrMsg("已生成的正品入库单已审核不可反进仓").toString();
+                    }
+
+                }
+
+            }
+        }
+
+        ArrayList<String> sqlList = new ArrayList<>();
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair");
+        updateSQL.setUniqueid(sa_sendrepairid);
+        updateSQL.setSiteid(siteid);
+        Rows dispositionRows  =dbConnect.runSqlQuery("select * from sa_aftersalesmag_disposition where disposition='"+row.getString("disposition")+"'");
+        Rows stockRows  =dbConnect.runSqlQuery("select * from st_stock");
+        RowsMap stockRowsMap = stockRows.toRowsMap("stockno");
+        if(dispositionRows.isEmpty()){
+            return getErrReturnObject().setErrMsg("返修处理意见不存在")
+                    .toString();
+        }
+        if (isinstock) {
+            updateSQL.setValue("status","进仓");
+            updateSQL.setValue("instockby",username);
+            updateSQL.setDateValue("instockdate");
+            sqlList.add(
+                    DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "确认", "送修单确认成功").getSQL());
+        } else {
+            updateSQL.setValue("status","确认");
+            updateSQL.setValue("instockby","");
+            updateSQL.setValue("instockdate","null");
+            sqlList.add(
+                    DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "反确认", "送修单反确认成功").getSQL());
+        }
+        if(row.getString("disposition").equals("返修") || row.getString("disposition").equals("翻新")){
+            if(isinstock){
+                if(StringUtils.isBlank(row.getString("newitemno")) && StringUtils.isBlank(row.getString("newsku"))){
+                    InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+                    long st_stockbillid = createTableID("st_stockbill");
+                    insertSQL.setUniqueid(st_stockbillid);
+                    insertSQL.setSiteid(siteid);
+                    insertSQL.setValue("billno", createBillCode("stockbilla"));
+                    insertSQL.setValue("type", "返修出库");
+                    insertSQL.setValue("typemx", "");
+                    insertSQL.setValue("sys_enterpriseid",row.getLong("sys_enterpriseid"));
+                    insertSQL.setValue("rb", 1);
+                    insertSQL.setValue("sourceobject", "sa_sendrepair");
+                    insertSQL.setValue("sourceid", sa_sendrepairid);
+                    insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    insertSQL.setValue("remarks",  row.getString("remarks"));
+                    insertSQL.setValue("status", "新建");
+                    insertSQL.setValue("createby", username);
+                    insertSQL.setDateValue("createdate");
+                    insertSQL.setDateValue("billdate");
+                    sqlList.add(insertSQL.getSQL());
+
+                    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", 1);
+                    insertSQL.setValue("sa_dispatch_itemsid", 0);
+                    insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
+                    insertSQL.setValue("sourceid", row.getLong("sa_sendrepair_detailid"));
+                    insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    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());
+                    if(StringUtils.isNotBlank(row.getString("sku"))){
+                        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", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                        insertSQL.setValue("itemid", row.getLong("itemid"));
+                        insertSQL.setValue("sku", row.getString("sku"));
+                        insertSQL.setValue("st_stockbillid", st_stockbillid);
+                        insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                        sqlList.add(insertSQL.getSQL());
+                    }
+                }else if(!row.getString("newsku").equals(row.getString("sku"))){
+
+                    sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
+                    sqlList.addAll(updatefnewmachinecode(isinstock,row,stockRowsMap));
+
+                    InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+                    long st_stockbillid = createTableID("st_stockbill");
+                    insertSQL.setUniqueid(st_stockbillid);
+                    insertSQL.setSiteid(siteid);
+                    insertSQL.setValue("billno", createBillCode("stockbilla"));
+                    insertSQL.setValue("type", "返修出库");
+                    insertSQL.setValue("typemx", "");
+                    insertSQL.setValue("sys_enterpriseid",row.getLong("sys_enterpriseid"));
+                    insertSQL.setValue("rb", 1);
+                    insertSQL.setValue("sourceobject", "sa_sendrepair");
+                    insertSQL.setValue("sourceid", sa_sendrepairid);
+                    insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    insertSQL.setValue("remarks",  row.getString("remarks"));
+                    insertSQL.setValue("status", "新建");
+                    insertSQL.setValue("createby", username);
+                    insertSQL.setDateValue("createdate");
+                    insertSQL.setDateValue("billdate");
+                    sqlList.add(insertSQL.getSQL());
+
+                    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", 1);
+                    insertSQL.setValue("sa_dispatch_itemsid", 0);
+                    insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
+                    insertSQL.setValue("sourceid", row.getLong("sa_sendrepair_detailid"));
+                    insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    insertSQL.setValue("itemid", row.getLong("newitemid"));
+                    insertSQL.setValue("itemno", row.getString("newitemno"));
+                    insertSQL.setValue("itemname", row.getString("newitemname"));
+                    insertSQL.setValue("model", row.getString("newmodel"));
+                    insertSQL.setValue("qty", row.getBigDecimal("qty"));
+                    insertSQL.setValue("st_stockbillid", st_stockbillid);
+                    sqlList.add(insertSQL.getSQL());
+                    if(StringUtils.isNotBlank(row.getString("newsku"))){
+                        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", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                        insertSQL.setValue("itemid", row.getLong("newitemid"));
+                        insertSQL.setValue("sku", row.getString("newsku"));
+                        insertSQL.setValue("st_stockbillid", st_stockbillid);
+                        insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                        sqlList.add(insertSQL.getSQL());
+                    }
+                }else if(!row.getString("itemid").equals(row.getString("newitemid"))){
+
+                    sqlList.addAll(updatefitemno(isinstock,row));
+
+                    InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+                    long st_stockbillid = createTableID("st_stockbill");
+                    insertSQL.setUniqueid(st_stockbillid);
+                    insertSQL.setSiteid(siteid);
+                    insertSQL.setValue("billno", createBillCode("stockbilla"));
+                    insertSQL.setValue("type", "返修出库");
+                    insertSQL.setValue("typemx", "");
+                    insertSQL.setValue("sys_enterpriseid",row.getLong("sys_enterpriseid"));
+                    insertSQL.setValue("rb", 1);
+                    insertSQL.setValue("sourceobject", "sa_sendrepair");
+                    insertSQL.setValue("sourceid", sa_sendrepairid);
+                    insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    insertSQL.setValue("remarks",  row.getString("remarks"));
+                    insertSQL.setValue("status", "新建");
+                    insertSQL.setValue("createby", username);
+                    insertSQL.setDateValue("createdate");
+                    insertSQL.setDateValue("billdate");
+                    sqlList.add(insertSQL.getSQL());
+
+                    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", 1);
+                    insertSQL.setValue("sa_dispatch_itemsid", 0);
+                    insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
+                    insertSQL.setValue("sourceid", row.getLong("sa_sendrepair_detailid"));
+                    insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    insertSQL.setValue("itemid", row.getLong("newitemid"));
+                    insertSQL.setValue("itemno", row.getString("newitemno"));
+                    insertSQL.setValue("itemname", row.getString("newitemname"));
+                    insertSQL.setValue("model", row.getString("newmodel"));
+                    insertSQL.setValue("qty", row.getBigDecimal("qty"));
+                    insertSQL.setValue("st_stockbillid", st_stockbillid);
+                    sqlList.add(insertSQL.getSQL());
+                    if(StringUtils.isNotBlank(row.getString("sku"))){
+                        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", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                        insertSQL.setValue("itemid", row.getLong("newitemid"));
+                        insertSQL.setValue("sku", row.getString("sku"));
+                        insertSQL.setValue("st_stockbillid", st_stockbillid);
+                        insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                        sqlList.add(insertSQL.getSQL());
+                    }
+                }
+            }else{
+                if(StringUtils.isBlank(row.getString("newitemno")) && StringUtils.isBlank(row.getString("newsku"))){
+
+                } else if(!row.getString("newsku").equals(row.getString("sku"))){
+                    sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
+                    sqlList.addAll(updatefnewmachinecode(isinstock,row,stockRowsMap));
+                } else if(!row.getString("itemid").equals(row.getString("newitemid"))){
+                    sqlList.addAll(updatefitemno(isinstock,row));
+                }
+            }
+        }
+        // 是否进成品仓
+        if(dispositionRows.get(0).getBoolean("inishedstock")){
+            if (isinstock) {
+                sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
+                sqlList.addAll(infinishedstock(isinstock,row));
+            } else {
+                sqlList.addAll(infinishedstock(isinstock,row));
+                sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
+            }
+        }
+        // 是否进报废仓
+        if(dispositionRows.get(0).getBoolean("scrapstock")){
+            if (isinstock) {
+                sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
+                sqlList.addAll(inscrapstock(isinstock,row,stockRowsMap));
+            } else {
+                sqlList.addAll(inscrapstock(isinstock,row,stockRowsMap));
+                sqlList.addAll(updatefmachinecode(isinstock,row,stockRowsMap));
+            }
+        }
+        if(!isinstock){
+            sqlList.add("delete from st_stockbill_items where st_stockbillid in (select st_stockbillid from st_stockbill where sourceobject='sa_sendrepair' and sourceid="+sa_sendrepairid+")");
+            sqlList.add("delete from st_stockbill_items_sku where st_stockbillid in (select st_stockbillid from st_stockbill where sourceobject='sa_sendrepair' and sourceid="+sa_sendrepairid+")");
+            sqlList.add("delete from st_stockbill where sourceobject='sa_sendrepair' and sourceid="+sa_sendrepairid);
+        }
+
+        sqlList.add(updateSQL.getSQL());
+        dbConnect.runSqlUpdate(sqlList);
+
+        return getSucReturnObject().toString();
+    }
+
+    @API(title = "审核", apiversion = R.ID2025102509532403.v1.class)
+    public String check() throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        Long sa_sendrepairid = content.getLong("sa_sendrepairid");
+        boolean ischeck = content.getBooleanValue("ischeck");
+        long sa_accountclassid=0;
+        Rows accountclassrows = dbConnect.runSqlQuery("select * from sa_accountclass where accountno='01'");
+        if(accountclassrows.isNotEmpty()){
+            sa_accountclassid=accountclassrows.get(0).getLong("sa_accountclassid");
+        }
+        Rows rows = dbConnect.runSqlQuery("select t1.sys_enterpriseid,t1.remarks,t1.billno,t1.status,t2.qty,t2.sa_sendrepair_detailid,t2.amount,t2.agentcost,t2.disposition from sa_sendrepair t1 " +
+                "inner join sa_sendrepair_detail t2  on t1.sa_sendrepairid=t2.sa_sendrepairid" +
+                " where t1.sa_sendrepairid ='"
+                + sa_sendrepairid + "' and  t1.siteid='" + siteid + "'");
+        if(rows.isEmpty()){
+            return getErrReturnObject().setErrMsg("送修单不存在")
+                    .toString();
+        }
+        Row row =rows.get(0);
+
+        Rows dispositionRows  =dbConnect.runSqlQuery("select * from sa_aftersalesmag_disposition where disposition='"+row.getString("disposition")+"'");
+        if(dispositionRows.isEmpty()){
+            return getErrReturnObject().setErrMsg("返修处理意见不存在")
+                    .toString();
+        }
+
+        if (ischeck) {
+            if (!row.getString("status").equals("进仓")) {
+                return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的送修单为非进仓状态,无法审核")
+                        .toString();
+            }
+        } else {
+            if (!dispositionRows.get(0).getBoolean("isrefund")) {
+                if (!row.getString("status").equals("审核")) {
+                    return getErrReturnObject().setErrMsg("非审核状态下不可反审核").toString();
+                }
+            } else {
+                if (!row.getString("status").equals("退款确认")) {
+                    return getErrReturnObject().setErrMsg("非退款确认状态下不可反审核").toString();
+                }
+            }
+
+        }
+        // 是否维修
+        if (dispositionRows.get(0).getBoolean("ismaintain")) {
+            /******** 账户余额扣减 ********/
+            BigDecimal totalamount = rows.sum("agentcost");// 经销商维修支付费用总额
+            // 如果经销商维修费用大于0
+            if (totalamount.compareTo(BigDecimal.ZERO)>0) {
+                if (ischeck) {
+                    CashbillEntity cashbillEntity = new CashbillEntity();
+                    cashbillEntity.setAmount(totalamount);
+                    cashbillEntity.setDiscountamountamount(BigDecimal.ZERO);
+                    cashbillEntity.setOwnerid(sa_sendrepairid);
+                    cashbillEntity.setOwnertable("sa_sendrepair");
+                    cashbillEntity.setRemarks("该单由送修单" + row.getString("billno") + "审核时自动生成");
+                    cashbillEntity.setSource("送修单审核");
+                    cashbillEntity.setTypemx("维修费");
+                    JSONObject cashbillPay = Accountbalance.createCashbillPay(this, row.getLong("sys_enterpriseid"), sa_accountclassid, cashbillEntity, true);
+                    sqlList.addAll(cashbillPay.getJSONArray("sqlList").toJavaList(String.class));
+                } else {
+                    CashbillEntity cashbillEntity = new CashbillEntity();
+                    cashbillEntity.setAmount(totalamount.negate());
+                    cashbillEntity.setDiscountamountamount(BigDecimal.ZERO);
+                    cashbillEntity.setOwnerid(sa_sendrepairid);
+                    cashbillEntity.setOwnertable("sa_sendrepair");
+                    cashbillEntity.setRemarks("该单由送修单" + row.getString("billno") + "反审核时自动生成");
+                    cashbillEntity.setSource("送修单反审核");
+                    cashbillEntity.setTypemx("维修费");
+                    JSONObject cashbillPay = Accountbalance.createCashbillPay(this, row.getLong("sys_enterpriseid"), sa_accountclassid, cashbillEntity, true);
+                    sqlList.addAll(cashbillPay.getJSONArray("sqlList").toJavaList(String.class));
+                }
+            }
+        }
+
+        UpdateSQL updateSQL = SQLFactory.createUpdateSQL(this, "sa_sendrepair");
+        updateSQL.setUniqueid(sa_sendrepairid);
+        updateSQL.setSiteid(siteid);
+        if (ischeck) {
+            if (!dispositionRows.get(0).getBoolean("isrefund")) {
+                updateSQL.setValue("status","审核");
+            }else{
+                updateSQL.setValue("status","退款确认");
+            }
+            updateSQL.setValue("checkby",username);
+            updateSQL.setDateValue("checkdate");
+            sqlList.add(
+                    DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "审核", "送修单审核成功").getSQL());
+        } else {
+            updateSQL.setValue("status","进仓");
+            updateSQL.setValue("checkby","");
+            updateSQL.setValue("checkdate","null");
+            sqlList.add(
+                    DataContrlLog.createLog(this, "sa_sendrepair", sa_sendrepairid, "反审核", "送修单反审核成功").getSQL());
+        }
+        sqlList.add(updateSQL.getSQL());
+        dbConnect.runSqlUpdate(sqlList);
+        return getSucReturnObject().toString();
+    }
+
+
+    /**
+     * 翻新序列号不变 品号改变
+     *
+     */
+    public ArrayList<String> updatefitemno(boolean istrue,Row sendrepairdetail) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows skurows =dbConnect.runSqlQuery("select * from sa_itemsku where sku='"+sendrepairdetail.getString("sku")+"' and status!='报废'");
+        if(skurows.isEmpty()){
+            throw new YosException("序列号不存在或已作废");
+        }
+        long newitemid = sendrepairdetail.getLong("newitemid");
+        String remarks = "由送修单号为" + sendrepairdetail.getString("billno") + "更改品号";
+        if (skurows.size() == 1) {
+            Row skurow =skurows.get(0);
+            if (istrue) {
+                if (newitemid==sendrepairdetail.getLong("itemid")) {
+                    throw new YosException( "调整品号不可与原品号相同");
+                }
+                if (newitemid==0) {
+                    throw new YosException( "调整品号不可为空");
+                }
+                if (!sendrepairdetail.getBoolean("skucontrol")) {
+                    throw new YosException("调整品号不是单品管理");
+                }
+                if (skurow.getLong("wmsuploadflag") == 2) {
+                    sqlList.add("update sa_itemsku set itemid="+newitemid+",changenotes='"+remarks+"',wmsuploadflag=1 where sa_itemskuid="+skurow.getLong("sa_itemskuid"));
+                }else{
+                    sqlList.add("update sa_itemsku set itemid="+newitemid+",changenotes='"+remarks+"' where sa_itemskuid="+skurow.getLong("sa_itemskuid"));
+                }
+
+
+                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_itemsku_change");
+                insertSQL.setValue("siteid", siteid);
+                insertSQL.setValue("sa_itemsku_changeid", createTableID("sa_itemsku_change"));
+                insertSQL.setValue("sa_itemskuid", skurow.getLong("sa_itemskuid"));
+                insertSQL.setValue("sa_agentsid", skurow.getLong("sa_agentsid"));
+                insertSQL.setValue("sa_agentsidnew",  skurow.getLong("sa_agentsid"));
+
+                insertSQL.setValue("itemid", skurow.getLong("itemid"));
+                insertSQL.setValue("itemidnew", newitemid);
+
+                insertSQL.setValue("stockid", skurow.getLong("stockid"));
+                insertSQL.setValue("stockidnew", skurow.getLong("stockid"));
+                insertSQL.setValue("changenotes", remarks);
+
+                insertSQL.setDateValue("changedate");
+                insertSQL.setValue("changeby", username);
+                sqlList.add(insertSQL.getSQL());
+            }
+            if (!istrue) {
+                sqlList.add("update sa_itemsku set itemid="+sendrepairdetail.getLong("itemid")+",changenotes='' where sa_itemskuid="+skurow.getLong("sa_itemskuid"));
+                sqlList.add("delete from sa_itemsku_change where changenotes like '%"+sendrepairdetail.getString("billno")+"%'");
+            }
+        }
+        return  sqlList;
+    }
+
+    /**
+     * 翻新新序列号入库
+     *
+     */
+    public ArrayList<String> updatefnewmachinecode(boolean istrue,Row sendrepairdetail,RowsMap stockRowsMap) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows departmentRows  =dbConnect.runSqlQuery("select * from sys_department");
+        RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
+        String sku = sendrepairdetail.getString("sku");
+        String newsku = sendrepairdetail.getString("newsku");
+        if (istrue) {
+            if (!sku.equals(newsku)) {
+                InsertSQL saItemsku = SQLFactory.createInsertSQL(this,"sa_itemsku");
+                saItemsku.setValue("sku", newsku);
+                saItemsku.setValue("itemid", sendrepairdetail.getLong("newitemid"));
+                saItemsku.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                saItemsku.setValue("createby", username);
+                saItemsku.setDateValue("createdate");
+                saItemsku.setValue("changeby", username);
+                saItemsku.setDateValue("changedate");
+                saItemsku.setWhere("sa_itemskuid", createTableID("sa_itemsku"));
+                saItemsku.setSiteid(siteid);
+                sqlList.add(saItemsku.getSQL());
+
+                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+                long st_stockbillid = createTableID("st_stockbill");
+                insertSQL.setUniqueid(st_stockbillid);
+                insertSQL.setSiteid(siteid);
+                insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
+                insertSQL.setValue("type", "其他入库");
+                insertSQL.setValue("typemx", "翻新/返修入库");
+                insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
+                insertSQL.setValue("rb", 1);
+                insertSQL.setValue("sourceobject", "sa_sendrepair");
+                insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
+                insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
+                insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                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());
+
+                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", 1);
+                insertSQL.setValue("sa_dispatch_itemsid", 0);
+                insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
+                insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
+                insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                insertSQL.setValue("itemid", sendrepairdetail.getLong("newitemid"));
+                insertSQL.setValue("itemno", sendrepairdetail.getString("newitemno"));
+                insertSQL.setValue("itemname", sendrepairdetail.getString("newitemname"));
+                insertSQL.setValue("model", sendrepairdetail.getString("newmodel"));
+                insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
+                insertSQL.setValue("st_stockbillid", st_stockbillid);
+                sqlList.add(insertSQL.getSQL());
+                if(StringUtils.isNotBlank(sendrepairdetail.getString("newsku"))){
+                    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", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    insertSQL.setValue("itemid", sendrepairdetail.getLong("newitemid"));
+                    insertSQL.setValue("sku", sendrepairdetail.getString("newsku"));
+                    insertSQL.setValue("st_stockbillid", st_stockbillid);
+                    insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                    sqlList.add(insertSQL.getSQL());
+                }
+                sqlList.addAll(sendrepairIcinvbal_new(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
+            }
+        }
+        if (!istrue) {
+            sqlList.addAll(sendrepairIcinvbal_new(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
+            //sqlList.add("delete from st_stockbill where type='其他入库' and sourceobject='sa_sendrepair' and sourceid="+sendrepairdetail.getLong("sendrepairid"));
+            sqlList.add("delete from sa_itemsku where sku='"+sendrepairdetail.getString("newsku")+"'");
+        }
+        return  sqlList;
+    }
+
+    /**
+     * 翻新 老序列号出库
+     *
+     */
+    public ArrayList<String> updatefmachinecode(boolean istrue,Row sendrepairdetail,RowsMap stockRowsMap) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows departmentRows  =dbConnect.runSqlQuery("select * from sys_department");
+        RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
+        String sku = sendrepairdetail.getString("sku");
+        String newsku = sendrepairdetail.getString("newsku");
+        if (istrue) {
+            if (!sku.equals(newsku)) {
+                InsertSQL saItemsku = SQLFactory.createInsertSQL(this,"sa_itemsku");
+                saItemsku.setValue("sku", newsku);
+                saItemsku.setValue("itemid", sendrepairdetail.getLong("newitemid"));
+                saItemsku.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                saItemsku.setValue("createby", username);
+                saItemsku.setDateValue("createdate");
+                saItemsku.setValue("changeby", username);
+                saItemsku.setDateValue("changedate");
+                saItemsku.setWhere("sa_itemskuid", createTableID("sa_itemsku"));
+                saItemsku.setSiteid(siteid);
+                sqlList.add(saItemsku.getSQL());
+
+                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+                long st_stockbillid = createTableID("st_stockbill");
+                insertSQL.setUniqueid(st_stockbillid);
+                insertSQL.setSiteid(siteid);
+                insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
+                insertSQL.setValue("type", "其他出库");
+                if (sendrepairdetail.getString("disposition").equalsIgnoreCase("返修")) {
+                    insertSQL.setValue("typemx", "返修出库");
+                } else if (sendrepairdetail.getString("disposition").equalsIgnoreCase("翻新")) {
+                    insertSQL.setValue("typemx", "翻新出库");
+                } else if (sendrepairdetail.getString("disposition").contains("报废")) {
+                    insertSQL.setValue("typemx", "报废出库");
+                } else if (sendrepairdetail.getString("disposition").equalsIgnoreCase("退钱做正品")) {
+                    insertSQL.setValue("typemx", "退钱做正品出库");
+                } else if (sendrepairdetail.getString("disposition").equalsIgnoreCase("退钱做试验机")) {
+                    insertSQL.setValue("typemx", "退钱做试验机出库");
+
+                }
+                insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
+                insertSQL.setValue("rb", 1);
+                insertSQL.setValue("sourceobject", "sa_sendrepair");
+                insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
+                insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
+                insertSQL.setValue("stockid", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                insertSQL.setValue("remarks",  "送修单出库");
+                insertSQL.setValue("status", "审核");
+                insertSQL.setValue("createby", username);
+                insertSQL.setDateValue("createdate");
+                insertSQL.setDateValue("billdate");
+                insertSQL.setValue("checkby", username);
+                insertSQL.setDateValue("checkdate");
+                sqlList.add(insertSQL.getSQL());
+
+                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", 1);
+                insertSQL.setValue("sa_dispatch_itemsid", 0);
+                insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
+                insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
+                insertSQL.setValue("stockid",stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
+                insertSQL.setValue("itemno", sendrepairdetail.getString("itemno"));
+                insertSQL.setValue("itemname", sendrepairdetail.getString("itemname"));
+                insertSQL.setValue("model", sendrepairdetail.getString("model"));
+                insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
+                insertSQL.setValue("st_stockbillid", st_stockbillid);
+                sqlList.add(insertSQL.getSQL());
+                if(StringUtils.isNotBlank(sendrepairdetail.getString("sku"))){
+                    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", stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0);
+                    insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
+                    insertSQL.setValue("sku", sendrepairdetail.getString("sku"));
+                    insertSQL.setValue("st_stockbillid", st_stockbillid);
+                    insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                    sqlList.add(insertSQL.getSQL());
+                }
+                sqlList.addAll(sendrepairIcinvbal(isinstock("其他出库","1",istrue),sendrepairdetail, stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
+                sqlList.add("update sa_itemsku set stockid=0 where sku='"+sendrepairdetail.getString("sku")+"'");
+                if(sendrepairdetail.getString("disposition").equalsIgnoreCase("翻新")  || sendrepairdetail.getString("disposition").equalsIgnoreCase("返修")){
+                    sqlList.add("update sa_itemsku set status='报废' where sku='"+sendrepairdetail.getString("sku")+"'");
+                }
+
+            }
+        }
+        if (!istrue) {
+            sqlList.addAll(sendrepairIcinvbal(isinstock("其他出库","1",istrue),sendrepairdetail, stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0));
+            sqlList.add("update sa_itemsku set status='在库',stockid='"+(stockRowsMap.containsKey("104")?stockRowsMap.get("104").get(0).getLong("stockid"):0)+"' where sku='"+sendrepairdetail.getString("sku")+"'");
+        }
+        return  sqlList;
+    }
+    /**
+     * 正品入库
+     *
+     */
+    public ArrayList<String> infinishedstock(boolean istrue,Row sendrepairdetail) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows departmentRows  =dbConnect.runSqlQuery("select * from sys_department");
+        RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
+        if (istrue) {
+            /*************** 售后开始 ****************/
+            long stockid = 0;
+            long itemid = sendrepairdetail.getLong("itemid");
+            Rows itemrows = dbConnect.runSqlQuery("select t2.stockid from plm_item t1 left join st_stock t2 on t1.stockno=t2.stockno where t1.itemid="+itemid);
+            if (itemrows.isNotEmpty()) {
+                stockid = itemrows.get(0).getLong("stockid");
+                if (stockid==0) {
+                    throw new YosException("货品档案中该商品没有默认仓库,请先补齐信息");
+                }
+            } else {
+                throw new YosException("系统货品档案中不存在该品号");
+            }
+            /*************** 售后结束 ****************/
+            /*************** 电商出库开始 ****************/
+            String name = sendrepairdetail.getString("name");
+            String phonenumber = sendrepairdetail.getString("phonenumber");
+            String address = sendrepairdetail.getString("address");
+            String fnotes = "";
+            if (!name.equals("")) {
+                fnotes = "姓名:" + name + ",电话:" + phonenumber + ".地址:" + address;
+            }
+            /*************** 电商出库结束 ****************/
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+            long st_stockbillid = createTableID("st_stockbill");
+            insertSQL.setUniqueid(st_stockbillid);
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
+            insertSQL.setValue("type", "其他入库");
+            insertSQL.setValue("typemx", "正品入库");
+            insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
+            insertSQL.setValue("rb", 1);
+            insertSQL.setValue("sourceobject", "sa_sendrepair");
+            insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
+            insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
+            insertSQL.setValue("stockid", stockid);
+            insertSQL.setValue("remarks",  fnotes);
+            insertSQL.setValue("status", "新建");
+            insertSQL.setValue("createby", username);
+            insertSQL.setDateValue("createdate");
+            insertSQL.setDateValue("billdate");
+            sqlList.add(insertSQL.getSQL());
+
+            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", 1);
+            insertSQL.setValue("sa_dispatch_itemsid", 0);
+            insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
+            insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
+            insertSQL.setValue("stockid",stockid);
+            insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
+            insertSQL.setValue("itemno", sendrepairdetail.getString("itemno"));
+            insertSQL.setValue("itemname", sendrepairdetail.getString("itemname"));
+            insertSQL.setValue("model", sendrepairdetail.getString("model"));
+            insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
+            insertSQL.setValue("st_stockbillid", st_stockbillid);
+            sqlList.add(insertSQL.getSQL());
+            if(StringUtils.isNotBlank(sendrepairdetail.getString("sku"))){
+                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", stockid);
+                insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
+                insertSQL.setValue("sku", sendrepairdetail.getString("sku"));
+                insertSQL.setValue("st_stockbillid", st_stockbillid);
+                insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                sqlList.add(insertSQL.getSQL());
+            }
+        }
+        if (!istrue) {
+            sqlList.add("update sa_itemsku set stockid=0 where sku='"+sendrepairdetail.getString("sku")+"'");
+        }
+        return  sqlList;
+    }
+
+    /**
+     * 报废入库报废仓
+     *
+     */
+    public ArrayList<String> inscrapstock(boolean istrue,Row sendrepairdetail,RowsMap stockRowsMap) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        Rows departmentRows  =dbConnect.runSqlQuery("select * from sys_department");
+        RowsMap departmentRowsMap = departmentRows.toRowsMap("depno");
+        if (istrue) {
+            String name = sendrepairdetail.getString("name");
+            String phonenumber = sendrepairdetail.getString("phonenumber");
+            String address = sendrepairdetail.getString("address");
+            String fnotes = "";
+            if (!name.equals("")) {
+                fnotes = "姓名:" + name + ",电话:" + phonenumber + ".地址:" + address;
+            }
+            /*************** 电商出库结束 ****************/
+            InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_stockbill");
+            long st_stockbillid = createTableID("st_stockbill");
+            insertSQL.setUniqueid(st_stockbillid);
+            insertSQL.setSiteid(siteid);
+            insertSQL.setValue("billno", createBillCode("STOCKBILL1"));
+            insertSQL.setValue("type", "其他入库");
+            insertSQL.setValue("typemx", "报废入库");
+            insertSQL.setValue("sys_enterpriseid",sendrepairdetail.getLong("sys_enterpriseid"));
+            insertSQL.setValue("rb", 1);
+            insertSQL.setValue("sourceobject", "sa_sendrepair");
+            insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepairid"));
+            insertSQL.setValue("departmentid", departmentRowsMap.containsKey("10106")?departmentRowsMap.get("10106").get(0).getLong("departmentid"):0);
+            insertSQL.setValue("stockid", stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0);
+            insertSQL.setValue("remarks",  "送修单入库");
+            insertSQL.setValue("status", "新建");
+            insertSQL.setValue("createby", username);
+            insertSQL.setDateValue("createdate");
+            insertSQL.setDateValue("billdate");
+            sqlList.add(insertSQL.getSQL());
+
+            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", 1);
+            insertSQL.setValue("sa_dispatch_itemsid", 0);
+            insertSQL.setValue("sourceobject", "sa_sendrepair_detail");
+            insertSQL.setValue("sourceid", sendrepairdetail.getLong("sa_sendrepair_detailid"));
+            insertSQL.setValue("stockid",stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0);
+            insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
+            insertSQL.setValue("itemno", sendrepairdetail.getString("itemno"));
+            insertSQL.setValue("itemname", sendrepairdetail.getString("itemname"));
+            insertSQL.setValue("model", sendrepairdetail.getString("model"));
+            insertSQL.setValue("qty", sendrepairdetail.getBigDecimal("qty"));
+            insertSQL.setValue("st_stockbillid", st_stockbillid);
+            sqlList.add(insertSQL.getSQL());
+            if(StringUtils.isNotBlank(sendrepairdetail.getString("sku"))){
+                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", stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0);
+                insertSQL.setValue("itemid", sendrepairdetail.getLong("itemid"));
+                insertSQL.setValue("sku", sendrepairdetail.getString("sku"));
+                insertSQL.setValue("st_stockbillid", st_stockbillid);
+                insertSQL.setValue("st_stockbill_itemsid", st_stockbill_itemsid);
+                sqlList.add(insertSQL.getSQL());
+            }
+            sqlList.addAll(sendrepairIcinvbal(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0));
+            sqlList.add("update sa_itemsku set stockid="+(stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0)+" where sku='"+sendrepairdetail.getString("sku")+"'");
+        }
+        if (!istrue) {
+            sqlList.addAll(sendrepairIcinvbal(isinstock("其他入库","1",istrue),sendrepairdetail,stockRowsMap.containsKey("106")?stockRowsMap.get("106").get(0).getLong("stockid"):0));
+            sqlList.add("update sa_itemsku set stockid=0 where sku='"+sendrepairdetail.getString("sku")+"'");
+        }
+        return  sqlList;
+    }
+
+    public ArrayList<String> sendrepairIcinvbal_new(boolean isinstock,Row sendrepairdetail,long stockid) throws YosException {// 云链
+        ArrayList<String> sqlList =new ArrayList<>();
+        long newitemid = sendrepairdetail.getLong("newitemid");
+        String newitemno = sendrepairdetail.getString("newitemno");
+        ArrayList<Long> itemList= new ArrayList<>();
+        itemList.add(newitemid);
+        RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal").setWhere("siteid", siteid).setWhere("itemid",itemList).query().toRowsMap("itemid");
+        BigDecimal qty =isinstock ? sendrepairdetail.getBigDecimal("qty") : sendrepairdetail.getBigDecimal("qty").negate();
+        if (!invbalsRowsMap.containsKey(String.valueOf(newitemid)) || !invbalsRowsMap.get(String.valueOf(newitemid)).toRowsMap("stockid").containsKey(String.valueOf(stockid))) {
+            InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal");
+            invbalInsert.setValue("siteid", siteid);
+            invbalInsert.setValue("stockid", stockid);
+            invbalInsert.setValue("itemid", newitemid);
+            invbalInsert.setValue("qty", qty.doubleValue());
+            sqlList.add(invbalInsert.getSQL());
+        } else {
+            UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal");
+            invbalUpdate.addValue("qty", invbalsRowsMap.get(String.valueOf(newitemid)).get(0).getBigDecimal("qty").add(qty));
+            invbalUpdate.setWhere("itemid", newitemid);
+            invbalUpdate.setWhere("stockid", stockid);
+            invbalUpdate.setWhere("siteid", siteid);
+            sqlList.add(invbalUpdate.getSQL());
+        }
+        return sqlList;
+    }
+
+
+
+    public ArrayList<String> sendrepairIcinvbal(boolean isinstock,Row sendrepairdetail,long stockid) throws YosException {// 云链
+        ArrayList<String> sqlList =new ArrayList<>();
+        long itemid = sendrepairdetail.getLong("itemid");
+        ArrayList<Long> itemList= new ArrayList<>();
+        itemList.add(itemid);
+        RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "st_invbal").setWhere("siteid", siteid).setWhere("itemid",itemList).query().toRowsMap("itemid");
+        BigDecimal qty =isinstock ? sendrepairdetail.getBigDecimal("qty") : sendrepairdetail.getBigDecimal("qty").negate();
+        if (!invbalsRowsMap.containsKey(String.valueOf(itemid)) || !invbalsRowsMap.get(String.valueOf(itemid)).toRowsMap("stockid").containsKey(String.valueOf(stockid))) {
+            InsertSQL invbalInsert = SQLFactory.createInsertSQL(this, "st_invbal");
+            invbalInsert.setValue("siteid", siteid);
+            invbalInsert.setValue("stockid", stockid);
+            invbalInsert.setValue("itemid", itemid);
+            invbalInsert.setValue("qty", qty.doubleValue());
+            sqlList.add(invbalInsert.getSQL());
+        } else {
+            UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(this, "st_invbal");
+            invbalUpdate.addValue("qty", invbalsRowsMap.get(String.valueOf(itemid)).get(0).getBigDecimal("qty").add(qty));
+            invbalUpdate.setWhere("itemid", itemid);
+            invbalUpdate.setWhere("stockid", stockid);
+            invbalUpdate.setWhere("siteid", siteid);
+            sqlList.add(invbalUpdate.getSQL());
+        }
+        return sqlList;
+    }
+    public boolean isinstock(String type, String rb, boolean fischeck) {
+        if (type.equals("其他出库") || type.equals("销售出库")
+                || type.equals("生产领料出库") || type.equals("委外领料出库")
+                || type.equals("返修出库")) {
+            if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
+                return false;
+            } else {
+                return true;
+            }
+
+        } else if (type.equals("其他入库") || type.equals("外购入库")
+                || type.equals("生产入库") || type.equals("委外入库")
+                || type.equals("返修入库")) {
+            if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
+                return true;
+            } else {
+                return false;
+            }
+        }
+        return false;
+    }
 }

+ 1 - 0
src/custom/restcontroller/webmanage/sale/stockbill/SQL/出入库单详情.sql

@@ -13,6 +13,7 @@ SELECT t1.*,
        t7.suppno,
        t7.suppname,
        t7.suppshortname,
+       t8.stockno,
        t8.stockname
 FROM st_stockbill t1
          LEFT JOIN sys_enterprise t2 ON t1.sys_enterpriseid = t2.sys_enterpriseid AND t1.siteid = t2.siteid

+ 17 - 5
src/custom/restcontroller/webmanage/sale/stockbill/stockbill.java

@@ -22,8 +22,11 @@ import restcontroller.webmanage.sale.order.OrderItems;
 import restcontroller.webmanage.sale.sendrepair.sendrepair;
 import restcontroller.webmanage.sale.sendrepair.sendrepair_pj;
 
+import javax.sql.RowSetReader;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Date;
 import java.util.HashMap;
 
 /**
@@ -92,8 +95,10 @@ public class stockbill extends Controller {
             insertSQL.setValue("remarks", remarks);
             if (StringUtils.isBlank(billdate)) {
                 insertSQL.setDateValue("billdate");
+                insertSQL.setValue("period",getPeriod(new Date()));
             } else {
                 insertSQL.setValue("billdate", billdate);
+                insertSQL.setValue("period",getPeriod(content.getDate("billdate")));
             }
             if (type.equals("销售出库")) {
                 insertSQL.setValue("billno", createBillCode("stockbill"));
@@ -112,9 +117,6 @@ public class stockbill extends Controller {
             insertSQL.setValue("invoice_taxno", invoice_taxno);
             insertSQL.setValue("tracknumber", tracknumber);
             insertSQL.setValue("isconfirm", isconfirm);
-
-            insertSQL.setValue("period", content.getStringValue("period"));
-
             insertSQL.setValue("createby", username);
             insertSQL.setDateValue("createdate");
             insertSQL.setValue("changeby", username);
@@ -215,7 +217,7 @@ public class stockbill extends Controller {
         sqlFactory.addParameter("siteid", siteid);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
         Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
-        Rows rowsdetail = dbConnect.runSqlQuery("select amount from st_stockbill_items where st_stockbillid=" + st_stockbillid);
+        Rows rowsdetail = dbConnect.runSqlQuery("select amount,qty from st_stockbill_items where st_stockbillid=" + st_stockbillid);
         row.put("receivableamount", rowsdetail.sum("amount"));
         Rows accountbalancerows = dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + row.getLong("sys_enterpriseid"));
         if(accountbalancerows.isNotEmpty()){
@@ -223,7 +225,7 @@ public class stockbill extends Controller {
         }else{
             row.put("discountamount_xjzh", 0);
         }
-
+        row.put("qty",rowsdetail.sum("qty"));
         return getSucReturnObject().setData(row).toString();
 
     }
@@ -1203,4 +1205,14 @@ public class stockbill extends Controller {
         int size = a.size();
         return (String[]) a.toArray(new String[size]);
     }
+    public String getPeriod(Date date) throws YosException {
+
+        String preioddate = new SimpleDateFormat("yyyy-MM-dd").format(date);
+        Rows rows =dbConnect.runSqlQuery("select CONCAT_WS('-', year, LPAD(month, 2, '0')) period from st_period where begdate<='"+preioddate+"' and enddate>='"+preioddate+"'");
+        if (rows.size() != 1) {
+            throw new YosException("该单据日期不存在对应的会计期间");
+        } else {
+            return rows.get(0).getString("period");
+        }
+    }
 }