|
@@ -325,7 +325,7 @@ public class stockbill extends Controller {
|
|
|
String type=rows.get(0).getString("type");
|
|
|
boolean isinstock = isinstock(type,rows.get(0).getString("rb"),true);
|
|
|
if(type.equals("销售出库")){
|
|
|
- String str = xsckcheck(st_stockbillid);
|
|
|
+ String str = xsckcheck(st_stockbillid,isinstock);
|
|
|
if(!str.equals("success")){
|
|
|
return getErrReturnObject().setErrMsg(str)
|
|
|
.toString();
|
|
@@ -371,7 +371,7 @@ public class stockbill extends Controller {
|
|
|
String type=rows.get(0).getString("type");
|
|
|
boolean isinstock = isinstock(rows.get(0).getString("type"),rows.get(0).getString("rb"),false);
|
|
|
if(type.equals("销售出库")){
|
|
|
- String str = unxsckcheck(st_stockbillid);
|
|
|
+ String str = unxsckcheck(st_stockbillid,isinstock);
|
|
|
if(!str.equals("success")){
|
|
|
return getErrReturnObject().setErrMsg(str)
|
|
|
.toString();
|
|
@@ -403,7 +403,7 @@ public class stockbill extends Controller {
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
- public String xsckcheck(Long st_stockbillid) throws YosException {
|
|
|
+ public String xsckcheck(Long st_stockbillid,boolean isinstock) throws YosException {
|
|
|
Rows rows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
|
|
|
+ st_stockbillid + "' and siteid='" + siteid + "'");
|
|
|
Rows rowsdetail = dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
|
|
@@ -503,13 +503,15 @@ public class stockbill extends Controller {
|
|
|
// Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
|
|
|
// RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
|
|
|
|
|
|
+ sqlList.addAll(updateAccountbalance_freez(st_stockbillid,isinstock));
|
|
|
+
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
// Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
|
|
|
return "success";
|
|
|
|
|
|
}
|
|
|
|
|
|
- public String unxsckcheck(Long st_stockbillid) throws YosException {
|
|
|
+ public String unxsckcheck(Long st_stockbillid,boolean isinstock) throws YosException {
|
|
|
|
|
|
|
|
|
Rows rows = dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
|
|
@@ -607,6 +609,7 @@ public class stockbill extends Controller {
|
|
|
// Rows stockbillitems = dbConnect.runSqlQuery("select t2.sa_orderid,sum(t2.price*t1.qty) amount from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='"+siteid+"'and t1.st_stockbillid="+st_stockbillid+" group by t2.sa_orderid");
|
|
|
// Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
|
|
|
// RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
|
|
|
+ sqlList.addAll(updateAccountbalance_freez(st_stockbillid,isinstock));
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
|
|
|
// Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
|
|
@@ -778,4 +781,59 @@ public class stockbill extends Controller {
|
|
|
}
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 账户余额冻结
|
|
|
+ * @param addorsub
|
|
|
+ */
|
|
|
+ public ArrayList<String> updateAccountbalance_freez(long st_stockbillid,boolean addorsub) throws YosException {
|
|
|
+ ArrayList<String> sqllist= new ArrayList<>();
|
|
|
+ /******** 冻结数据 ********/
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum,ROUND(sum(t1.qty*t2.price*ifnull(t2.pricerate,1)*ifnull(t2.rwpricerate,1)), 2) amount from st_stockbill_items t1 \n" +
|
|
|
+ " inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid\n" +
|
|
|
+ " inner join sa_order t3 on t2.sa_orderid=t3.sa_orderid and t2.siteid=t3.siteid\n" +
|
|
|
+ "\t\t\t\t\t\t\t\t\tleft join sa_accountbalance t4 on t4.sa_accountclassid=t3.sa_accountclassid and t4.sys_enterpriseid=t3.sys_enterpriseid and t4.siteid=t3.siteid\n" +
|
|
|
+ " where t1.st_stockbillid="+st_stockbillid+" group by t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum");
|
|
|
+ if (addorsub) {
|
|
|
+ for(Row row :rows) {
|
|
|
+ String sonum = row.getString("sonum");
|
|
|
+ long sa_orderid = row.getLong("sa_orderid");
|
|
|
+ long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
|
|
|
+ BigDecimal amount = row.getBigDecimal("amount");
|
|
|
+ Rows accountbalancefreezrows = dbConnect.runSqlQuery("select sa_accountbalance_freezid from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + siteid + "'");
|
|
|
+
|
|
|
+ sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)+" + amount + " where sa_accountbalanceid=" + sa_accountbalanceid + " and siteid='" + siteid + "'");
|
|
|
+
|
|
|
+ if (accountbalancefreezrows.isNotEmpty()) {
|
|
|
+ sqllist.add("update sa_accountbalance_freez set amount=amount+" + amount + " where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
|
|
|
+ } else {
|
|
|
+ long sa_accountbalance_freezid = createTableID("sa_accountbalance_freez");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_accountbalance_freez");
|
|
|
+ insertSQL.setUniqueid(sa_accountbalance_freezid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("sa_accountbalanceid", sa_accountbalanceid);
|
|
|
+ insertSQL.setValue("sourcetable", "sa_order");
|
|
|
+ insertSQL.setValue("sourceid", sa_orderid);
|
|
|
+ insertSQL.setValue("amount", amount);
|
|
|
+ insertSQL.setValue("remarks", "由销售订单" + sonum + "审核时冻结");
|
|
|
+ insertSQL.setValue("createby", username);
|
|
|
+ insertSQL.setDateValue("createdate");
|
|
|
+ sqllist.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ for(Row row : rows){
|
|
|
+ long sa_orderid = row.getLong("sa_orderid");
|
|
|
+ long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
|
|
|
+ BigDecimal amount = row.getBigDecimal("amount");
|
|
|
+ Rows accountbalancefreezrows = dbConnect.runSqlQuery("select sa_accountbalance_freezid,amount from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + siteid + "'");
|
|
|
+ if (accountbalancefreezrows.size() > 0) {
|
|
|
+ sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-"+amount+" where sa_accountbalanceid="+sa_accountbalanceid);
|
|
|
+ sqllist.add("update sa_accountbalance_freez set amount=amount-"+amount+" where sa_accountbalance_freezid="+accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return sqllist;
|
|
|
+ }
|
|
|
}
|