Prechádzať zdrojové kódy

账户资金冻结功能

hu 2 mesiacov pred
rodič
commit
bf4825ac7c

+ 2 - 1
src/custom/beans/accountbalance/Accountbalance.java

@@ -34,7 +34,8 @@ public class Accountbalance extends BaseClass {
             accountbalanceEntity.setBalance(rows.get(0).getBigDecimal("balance"));
             accountbalanceEntity.setCreditquota(rows.get(0).getBigDecimal("creditquota"));
             accountbalanceEntity.setDiscountamount(rows.get(0).getBigDecimal("discountamount"));
-            accountbalanceEntity.setCanuseamount(rows.get(0).getBigDecimal("balance").add(rows.get(0).getBigDecimal("creditquota")).add(rows.get(0).getBigDecimal("discountamount")));
+            accountbalanceEntity.setFreezamount(rows.get(0).getBigDecimal("freezamount"));
+            accountbalanceEntity.setCanuseamount(rows.get(0).getBigDecimal("balance").add(rows.get(0).getBigDecimal("creditquota")).add(rows.get(0).getBigDecimal("discountamount")).subtract(rows.get(0).getBigDecimal("freezamount")));
         }
         return accountbalanceEntity;
     }

+ 5 - 0
src/custom/beans/accountbalance/AccountbalanceEntity.java

@@ -8,6 +8,11 @@ public class AccountbalanceEntity {
 	private BigDecimal balance;
 	private BigDecimal canuseamount;
 	private BigDecimal discountamount;
+	private BigDecimal freezamount;
+
+	public BigDecimal getFreezamount() {return freezamount;}
+
+	public void setFreezamount(BigDecimal freezamount) {this.freezamount = freezamount;}
 
 	public BigDecimal getDiscountamount() {
 		return discountamount;

+ 1 - 0
src/custom/beans/accountbalance/SQL/账户余额查询.sql

@@ -3,6 +3,7 @@ SELECT t1.accountno,
        ifnull(t2.balance, 0)     balance,
        ifnull(t2.creditquota, 0) creditquota,
        ifnull(t2.discountamount, 0) discountamount,
+       ifnull(t2.freezamount, 0) freezamount,
        t2.changeuserid,
        t2.changeby,
        t2.changedate

+ 58 - 2
src/custom/restcontroller/webmanage/sale/order/Order.java

@@ -2109,7 +2109,7 @@ public class Order extends Controller {
         Long sa_cashbillid1 = cashbillPay.getLong("sa_cashbillid");
 
         //创建返利金支出凭证
-        Rows cashbillRows = dbConnect.runSqlQuery("SELECT * from sa_cashbill WHERE class='返利金' and STATUS ='审核' and rebate_enddate>=CURRENT_TIME and rebate_balance>0 and sys_enterpriseid= " + pay_enterpriseid + " and siteid = '" + siteid + "'  ORDER BY  rebate_enddate ");
+        Rows cashbillRows = dbConnect.runSqlQuery("SELECT * from sa_cashbill WHERE class='返利金' and STATUS ='' and rebate_enddate>=CURRENT_TIME and rebate_balance>0 and sys_enterpriseid= " + pay_enterpriseid + " and siteid = '" + siteid + "'  ORDER BY  rebate_enddate ");
         int count = 0;
         while (rebateamount.compareTo(BigDecimal.ZERO) == 1) {
             Row cashbillRow = cashbillRows.get(count);
@@ -2258,6 +2258,10 @@ public class Order extends Controller {
         }
         String message = "您的订单【" + sonum + "】已审核!";
 
+
+
+        sqlList.addAll(updateAccountbalance_freez(amount,true, "由销售订单" + sonum + "审核时冻结",sys_enterpriseid, sa_accountclassid, sa_orderid));
+
         sqlList.add(getOrderCheckSql(sa_orderid, reviewtype));
 
 
@@ -2313,7 +2317,7 @@ public class Order extends Controller {
 
         //验证结算企业
         Long sys_enterpriseid = row.getLong("sys_enterpriseid");
-
+        Long sa_accountclassid= row.getLong("sa_accountclassid");
         String sonum = row.getString("sonum");
 
         BigDecimal amount = beans.order.Order.getAmount(this, sa_orderid);
@@ -2337,6 +2341,8 @@ public class Order extends Controller {
 
         String message = "您的订单【" + sonum + "】已反审核,请注意查看!";
 
+        sqlList.addAll(updateAccountbalance_freez(amount,false, "由销售订单" + sonum + "审核时冻结",sys_enterpriseid, sa_accountclassid, sa_orderid));
+
         sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "订单反审核", "订单反审核成功,金额:" + amount).getSQL());
 
         dbConnect.runSqlUpdate(sqlList);
@@ -4185,4 +4191,54 @@ public class Order extends Controller {
 //        return getSucReturnObject().toString();
 //    }
 
+
+    /**
+     * 账户余额冻结
+     * @param totalamount
+     * @param addorsub
+     * @param remarks
+     */
+    public ArrayList<String> updateAccountbalance_freez(BigDecimal totalamount, boolean addorsub,
+                                    String remarks,long sys_enterpriseid,long sa_accountclassid,long sa_orderid) throws YosException {
+        ArrayList<String> sqllist= new ArrayList<>();
+        /******** 冻结数据 ********/
+        if (addorsub) {
+            long sa_accountbalanceid=0;
+            totalamount = addorsub ? totalamount : totalamount.negate();
+            Rows accountbalancerows =dbConnect.runSqlQuery("select * from sa_accountbalance where sa_accountclassid="+sa_accountclassid+" and sys_enterpriseid="+sys_enterpriseid+" and siteid='"+siteid+"'");
+            if(accountbalancerows.isNotEmpty()){
+                sa_accountbalanceid=accountbalancerows.get(0).getLong("sa_accountbalanceid");
+                sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)+"+totalamount+" where sa_accountbalanceid="+sa_accountbalanceid);
+            }else{
+                sa_accountbalanceid= createTableID("sa_accountbalance");
+                InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "sa_accountbalance");
+                insertSQL.setUniqueid(sa_accountbalanceid);
+                insertSQL.setSiteid(siteid);
+                insertSQL.setValue("sys_enterpriseid", sys_enterpriseid);
+                insertSQL.setValue("freezamount", totalamount);
+                insertSQL.setValue("sa_accountclassid", sa_accountclassid);
+                sqllist.add(insertSQL.getSQL());
+            }
+            InsertSQL frezzInsertSQL = SQLFactory.createInsertSQL(this, "sa_accountbalance_freez");
+            frezzInsertSQL.setUniqueid(createTableID("sa_accountbalance_freez"));
+            frezzInsertSQL.setSiteid(siteid);
+            frezzInsertSQL.setValue("sa_accountbalanceid", sa_accountbalanceid);
+            frezzInsertSQL.setValue("sourcetable", "sa_order");
+            frezzInsertSQL.setValue("sourceid", sa_orderid);
+            frezzInsertSQL.setValue("amount", totalamount);
+            frezzInsertSQL.setValue("remarks", remarks);
+            frezzInsertSQL.setValue("createby", username);
+            frezzInsertSQL.setDateValue("createdate");
+            sqllist.add(frezzInsertSQL.getSQL());
+        } else {
+            Rows accountbalancerows =dbConnect.runSqlQuery("select * from sa_accountbalance_freez where sourceid="+sa_orderid+" and sourcetable='sa_order' and siteid='"+siteid+"'");
+            BigDecimal freezamount =accountbalancerows.sum("amount");
+            if(accountbalancerows.isNotEmpty()){
+                sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-"+freezamount+" where sa_accountbalanceid="+accountbalancerows.get(0).getLong("sa_accountbalanceid"));
+            }
+            sqllist.add("delete from sa_accountbalance_freez where sourceid="+sa_orderid+" and sourcetable='sa_order' and siteid='"+siteid+"'");
+        }
+        return sqllist;
+    }
+
 }

+ 62 - 4
src/custom/restcontroller/webmanage/sale/stockbill/stockbill.java

@@ -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;
+    }
 }