|
|
@@ -4,6 +4,7 @@ import beans.accountbalance.Accountbalance;
|
|
|
import beans.accountbalance.CashbillEntity;
|
|
|
import beans.data.BatchDeleteErr;
|
|
|
import beans.datacontrllog.DataContrlLog;
|
|
|
+import beans.stockbill.Stockbill;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import common.Controller;
|
|
|
@@ -337,7 +338,7 @@ public class tpartreimbursement extends Controller {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "sa_tpartreimbursementdetailid", "remarks","qty", "sa_orderitemsid", "sa_tpartreimbursementid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "sa_tpartreimbursementdetailid", "remarks","qty","checkqty", "sa_orderitemsid", "sa_tpartreimbursementid");
|
|
|
querySQL.setTableAlias("t1");
|
|
|
querySQL.addJoinTable(JOINTYPE.inner, "sa_orderitems", "t2", "t1.sa_orderitemsid = t2.sa_orderitemsid AND t1.siteid = t2.siteid","price", "amount", "rowno", "cardno", "offstatus", "billingstatus");
|
|
|
querySQL.addJoinTable(JOINTYPE.left, "plm_item", "t3", "t2.itemid = t3.itemid AND t2.siteid = t3.siteid", "itemid","itemno", "itemname", "spec", "model");
|
|
|
@@ -381,11 +382,11 @@ public class tpartreimbursement extends Controller {
|
|
|
@CACHEING
|
|
|
public String queryCheckAmount() throws YosException {
|
|
|
JSONArray sa_tpartreimbursementdetailids = content.getJSONArray("sa_tpartreimbursementdetailids");
|
|
|
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "qty");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "checkqty");
|
|
|
querySQL.setTableAlias("t1");
|
|
|
querySQL.addJoinTable(JOINTYPE.left, "sa_orderitems", "t2", "t1.sa_orderitemsid = t2.sa_orderitemsid AND t1.siteid = t2.siteid","price");
|
|
|
querySQL.setSiteid(siteid);
|
|
|
- querySQL.addQueryFields("amount","ROUND(t1.qty*t2.price, 2)");
|
|
|
+ querySQL.addQueryFields("amount","ROUND(t1.checkqty*t2.price, 2)");
|
|
|
querySQL.setWhere("t1.sa_tpartreimbursementdetailid", sa_tpartreimbursementdetailids);
|
|
|
Rows rows = querySQL.query();
|
|
|
return getSucReturnObject().setData(rows.sum("amount")).toString();
|
|
|
@@ -399,33 +400,49 @@ public class tpartreimbursement extends Controller {
|
|
|
long sys_enterpriseid = content.getLong("sys_enterpriseid");
|
|
|
JSONArray sa_tpartreimbursementdetailids = content.getJSONArray("sa_tpartreimbursementdetailids");
|
|
|
JSONArray iteminfos = content.getJSONArray("iteminfos");
|
|
|
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "sa_tpartreimbursementdetailid","isverified","qty","sa_orderitemsid");
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "sa_tpartreimbursementdetailid","isverified","qty","sa_orderitemsid","hongbillno");
|
|
|
querySQL.setTableAlias("t1");
|
|
|
querySQL.addJoinTable(JOINTYPE.left, "sa_orderitems", "t2", "t1.sa_orderitemsid = t2.sa_orderitemsid AND t1.siteid = t2.siteid");
|
|
|
querySQL.addJoinTable(JOINTYPE.left, "sa_tpartreimbursement", "t3", "t1.sa_tpartreimbursementid = t3.sa_tpartreimbursementid AND t1.siteid = t2.siteid","billno");
|
|
|
querySQL.setSiteid(siteid);
|
|
|
querySQL.setWhere("t1.sa_tpartreimbursementdetailid", sa_tpartreimbursementdetailids);
|
|
|
Rows rows = querySQL.query();
|
|
|
-
|
|
|
- QuerySQL querySQLgroup = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "sa_orderitemsid");
|
|
|
- querySQLgroup.setTableAlias("t1");
|
|
|
- querySQLgroup.addJoinTable(JOINTYPE.left, "sa_orderitems", "t2", "t1.sa_orderitemsid = t2.sa_orderitemsid AND t1.siteid = t2.siteid");
|
|
|
- querySQLgroup.setSiteid(siteid);
|
|
|
- querySQLgroup.addQueryFields("sumqty", "sum(t1.qty)");
|
|
|
- querySQLgroup.setWhere("t1.sa_tpartreimbursementdetailid", sa_tpartreimbursementdetailids);
|
|
|
- querySQLgroup.addGroupBy("sa_orderitemsid");
|
|
|
- Rows rowsgroup = querySQLgroup.query();
|
|
|
-
|
|
|
+ ArrayList<String> billnolist = rows.toArrayList("hongbillno");
|
|
|
+ billnolist.add("111");
|
|
|
+ QuerySQL stockbillquerySQL = SQLFactory.createQuerySQL(this, "st_stockbill", "billno");
|
|
|
+ stockbillquerySQL.setTableAlias("t1");
|
|
|
+ stockbillquerySQL.setSiteid(siteid);
|
|
|
+ stockbillquerySQL.setWhere("t1.billno",billnolist);
|
|
|
+ Rows stockbillrows =stockbillquerySQL.query();
|
|
|
+ RowsMap stockbillrowsMap = stockbillrows.toRowsMap("billno");
|
|
|
for (Row row : rows) {
|
|
|
- if (row.getBoolean("isverified")) {
|
|
|
- return getErrReturnObject().setErrMsg("存在记录已核销,请检查").toString();
|
|
|
+ if (StringUtils.isNotBlank(row.getString("hongbillno"))) {
|
|
|
+ if(stockbillrowsMap.containsKey(row.getString("hongbillno"))){
|
|
|
+ return getErrReturnObject().setErrMsg("存在核销生成的红字出库单,无法核销").toString();
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
- sqllist.add("update sa_tpartreimbursementdetail set isverified=1 where sa_tpartreimbursementdetailid=" + row.getLong("sa_tpartreimbursementdetailid"));
|
|
|
- }
|
|
|
- for (Row row : rowsgroup) {
|
|
|
- sqllist.add("update sa_orderitems set verifiedqty=ifnull(verifiedqty,0)+"+row.getBigDecimal("sumqty")+" where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
}
|
|
|
|
|
|
+// QuerySQL querySQLgroup = SQLFactory.createQuerySQL(this, "sa_tpartreimbursementdetail", "sa_orderitemsid");
|
|
|
+// querySQLgroup.setTableAlias("t1");
|
|
|
+// querySQLgroup.addJoinTable(JOINTYPE.left, "sa_orderitems", "t2", "t1.sa_orderitemsid = t2.sa_orderitemsid AND t1.siteid = t2.siteid");
|
|
|
+// querySQLgroup.setSiteid(siteid);
|
|
|
+// querySQLgroup.addQueryFields("sumqty", "sum(t1.qty)");
|
|
|
+// querySQLgroup.setWhere("t1.sa_tpartreimbursementdetailid", sa_tpartreimbursementdetailids);
|
|
|
+// querySQLgroup.addGroupBy("sa_orderitemsid");
|
|
|
+// Rows rowsgroup = querySQLgroup.query();
|
|
|
+
|
|
|
+// for (Row row : rows) {
|
|
|
+// if (row.getBoolean("isverified")) {
|
|
|
+// return getErrReturnObject().setErrMsg("存在记录已核销,请检查").toString();
|
|
|
+// }
|
|
|
+// sqllist.add("update sa_tpartreimbursementdetail set isverified=1 where sa_tpartreimbursementdetailid=" + row.getLong("sa_tpartreimbursementdetailid"));
|
|
|
+// }
|
|
|
+// for (Row row : rowsgroup) {
|
|
|
+// sqllist.add("update sa_orderitems set verifiedqty=ifnull(verifiedqty,0)+"+row.getBigDecimal("sumqty")+" where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
+// }
|
|
|
+
|
|
|
String tableName = "st_stockbill";
|
|
|
Rows stocks = dbConnect.runSqlQuery("select stockid from st_stock where stockname='配件仓库' and siteid='" + siteid + "'");
|
|
|
Rows department = dbConnect.runSqlQuery("select departmentid from sys_department where depname='售后部' and siteid='" + siteid + "'");
|
|
|
@@ -478,9 +495,9 @@ public class tpartreimbursement extends Controller {
|
|
|
insertSQL.setDateValue("createdate");
|
|
|
insertSQL.setValue("changeby", username);
|
|
|
insertSQL.setDateValue("changedate");
|
|
|
- insertSQL.setValue("checkby", username);
|
|
|
- insertSQL.setDateValue("checkdate");
|
|
|
- insertSQL.setValue("status", "审核");
|
|
|
+// insertSQL.setValue("checkby", username);
|
|
|
+// insertSQL.setDateValue("checkdate");
|
|
|
+ insertSQL.setValue("status", "新建");
|
|
|
|
|
|
int i = 0;
|
|
|
long maxid = 0;
|
|
|
@@ -523,18 +540,39 @@ public class tpartreimbursement extends Controller {
|
|
|
totalamount = totalamount.add(iteminfo.getBigDecimal("qty").multiply(iteminfo.getBigDecimal("price")));
|
|
|
}
|
|
|
}
|
|
|
+ for(Object object:sa_tpartreimbursementdetailids){
|
|
|
+ Integer sa_tpartreimbursementdetailid = (Integer) object;
|
|
|
+ sqllist.add("update sa_tpartreimbursementdetail set hongbillno='"+billno+"' where sa_tpartreimbursementdetailid="+sa_tpartreimbursementdetailid);
|
|
|
+ }
|
|
|
+
|
|
|
insertSQL.setValue("payamount", totalamount);
|
|
|
insertSQL.setValue("paydiscountamount", 0);
|
|
|
|
|
|
sqllist.add(insertSQL.getSQL());
|
|
|
sqllist.add(DataContrlLog.createLog(this, "st_stockbill", st_stockbillid, "新增", "销售出库单新增成功,来源配件核销"+rows.toJsonArray("billno").toJSONString()).getSQL());
|
|
|
- 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=" + sys_enterpriseid);
|
|
|
-
|
|
|
- CashbillEntity entity = getCashbillEntity(totalamount.negate(), BigDecimal.ZERO, st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成");
|
|
|
- JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
- sqllist.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
+ //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=" + sys_enterpriseid);
|
|
|
|
|
|
+ //CashbillEntity entity = getCashbillEntity(totalamount.negate(), BigDecimal.ZERO, st_stockbillid, "销售出库单审核", billno, "由销售出库单" + billno + "审核时生成");
|
|
|
+ //JSONObject createCashbillPay = Accountbalance.createCashbillPay(dbConnect, userInfo, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
+ //sqllist.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
dbConnect.runSqlUpdate(sqllist);
|
|
|
+ try {
|
|
|
+ Stockbill.check(this, st_stockbillid, true);
|
|
|
+ } catch (YosException e) {
|
|
|
+ // Code to handle the exception
|
|
|
+ dbConnect.runSqlUpdate("delete from st_stockbill where st_stockbillid="+st_stockbillid);
|
|
|
+ dbConnect.runSqlUpdate("delete from st_stockbill_items where st_stockbillid="+st_stockbillid);
|
|
|
+ dbConnect.runSqlUpdate("delete from sys_contrllog where ownerid="+st_stockbillid+" and ownertable='st_stockbill'");
|
|
|
+ for(Object object:sa_tpartreimbursementdetailids){
|
|
|
+ Integer sa_tpartreimbursementdetailid = (Integer) object;
|
|
|
+ dbConnect.runSqlUpdate("update sa_tpartreimbursementdetail set hongbillno='' where sa_tpartreimbursementdetailid="+sa_tpartreimbursementdetailid);
|
|
|
+ }
|
|
|
+ return getErrReturnObject().setErrMsg(e.getMessage())
|
|
|
+ .toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|