Pārlūkot izejas kodu

手工关闭订单时无需判断账户余额。

eganwu 1 gadu atpakaļ
vecāks
revīzija
572dc57b68

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

@@ -240,7 +240,7 @@ public class Accountbalance extends BaseClass {
                 throw new YosException(false, "该营销账户不存在,支出凭证无法审核");
             } else {
                 BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
-                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1|| canuseamount.compareTo(BigDecimal.ZERO) <= 0) {
+                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1) {
                     throw new YosException(false, "该营销账户可用余额不足,支出凭证无法审核");
                 }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
@@ -268,6 +268,83 @@ public class Accountbalance extends BaseClass {
         return jsonObject;
     }
 
+    //订单手动关闭专用
+    public static JSONObject createCashbillPay2(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck) throws YosException {
+        ArrayList<String> sqlList = new ArrayList<>();
+        long sa_cashbillid = controller.createTableID("sa_cashbill");
+        String billcode = controller.createBillCode("cashbill");
+        SQLFactory sqlFactory = new SQLFactory(new Accountbalance(), "收支凭证新增");
+        sqlFactory.addParameter("billno", billcode);
+        sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+        sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
+        sqlFactory.addParameter("type", 0);
+        sqlFactory.addParameter("siteid", controller.siteid);
+        sqlFactory.addParameter("remarks", cashbillEntity.getRemarks());
+        sqlFactory.addParameter("amount", cashbillEntity.getAmount());
+        sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
+        sqlFactory.addParameter("userid", controller.userid);
+        sqlFactory.addParameter("username", controller.username);
+        sqlFactory.addParameter("ownertable", cashbillEntity.getOwnertable());
+        sqlFactory.addParameter("ownerid", cashbillEntity.getOwnerid());
+        sqlFactory.addParameter("source", cashbillEntity.getSource());
+        sqlFactory.addParameter("sourcenote", cashbillEntity.getSourcenote());
+        sqlFactory.addParameter("class", cashbillEntity.getType());
+        sqlFactory.addParameter("subclass", cashbillEntity.getTypemx());
+        sqlFactory.addParameter("sa_cashbillid_rebate", "null");
+        sqlFactory.addParameter("updatek3flag", "");
+        if (ischeck) {
+            BigDecimal balance = BigDecimal.ZERO;  //当前账户余额
+            sqlFactory.addParameter("status", "审核");
+            sqlFactory.addParameter("checkby", controller.username);
+            sqlFactory.addParameter_SQL("checkdate", "CURRENT_TIME");
+
+            // 审核逻辑判断
+            Rows rowsaccountbalance = controller.dbConnect.runSqlQuery(
+                    "select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='"
+                            + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='"
+                            + controller.siteid + "'");
+            if (rowsaccountbalance.isEmpty()) {
+//				SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
+//				sqlFactory.addParameter("sa_accountbalanceid",  createTableID("sa_accountbalance"));
+//				sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
+//				sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
+//				sqlFactory.addParameter("siteid", siteid);
+//				sqlFactory.addParameter("balance",  -rows.get(0).getLong("amount"));
+//				sqlFactory.addParameter("userid", userid);
+//				sqlFactory.addParameter("username", username);
+//				sqlList.add(sqlFactory.getSQL());
+                throw new YosException(false, "该营销账户不存在,支出凭证无法审核");
+            } else {
+//                BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
+//                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1) {
+//                    throw new YosException(false, "该营销账户可用余额不足,支出凭证无法审核");
+//                }
+                BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());
+                sqlList.add("update sa_accountbalance set balance='" + newbalance + "',changedate=CURRENT_TIME,changeby ='" + controller.username + "',changeuserid='" + controller.userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and  sa_accountclassid='" + sa_accountclassid + "' and siteid='" + controller.siteid + "'");
+                balance = newbalance;
+            }
+            sqlFactory.addParameter("balance", balance);
+            Rows accountclassrows = controller.dbConnect.runSqlQuery("select * from sa_accountclass where siteid='" + controller.siteid + "' and  sa_accountclassid=" + sa_accountclassid);
+            if (!accountclassrows.isEmpty()) {
+                String content = "您的" + accountclassrows.get(0).getString("accountname") + "已支出【" + cashbillEntity.getAmount() + "】元";
+                new Accountbalance().sendMsg(controller, content, cashbillEntity.getOwnerid(), sys_enterpriseid);
+            }
+        } else {
+            sqlFactory.addParameter("status", "新建");
+            sqlFactory.addParameter("checkby", "");
+            sqlFactory.addParameter("checkdate", "");
+            sqlFactory.addParameter("balance", 0);
+            sqlFactory.addParameter("updatek3flag", "");
+        }
+        sqlList.add(sqlFactory.getSQL());
+
+        JSONObject jsonObject = new JSONObject();
+        jsonObject.put("sa_cashbillid", sa_cashbillid);
+        jsonObject.put("sqlList", sqlList);
+        return jsonObject;
+    }
+
+
 
     public static JSONObject createCashbillPay(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck, Long sa_cashbillid_rebate) throws YosException {
         ArrayList<String> sqlList = new ArrayList<>();
@@ -306,7 +383,7 @@ public class Accountbalance extends BaseClass {
                 throw new YosException(false, "该营销账户不存在,支出凭证无法审核");
             } else {
                 BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
-                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1 || canuseamount.compareTo(BigDecimal.ZERO) <= 0) {
+                if (cashbillEntity.getAmount().compareTo(canuseamount) == 1 ) {
                     throw new YosException(false, "该营销账户可用余额不足,支出凭证无法审核");
                 }
                 BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(cashbillEntity.getAmount());

+ 1 - 1
src/custom/restcontroller/sale/cashbill/cashbill.java

@@ -774,7 +774,7 @@ public class cashbill extends Controller {
                             .toString();
                 } else {
                     BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
-                    if (rows.get(0).getBigDecimal("amount").compareTo(canuseamount) == 1 || canuseamount.compareTo(BigDecimal.ZERO) <= 0) {
+                    if (rows.get(0).getBigDecimal("amount").compareTo(canuseamount) == 1 ) {
                         return getErrReturnObject().setErrMsg("该营销账户可用余额不足,支出凭证无法审核")
                                 .toString();
                     }

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

@@ -3463,7 +3463,7 @@ public class Order extends Controller {
                 entity.setRemarks("由订单号" + orderRow.get(0).getString("sonum") + "手工关闭时生成");
                 entity.setType("普通费用");
                 entity.setTypemx("订单关闭退款");
-                JSONObject cashbillPay = Accountbalance.createCashbillPay(this, sys_enterpriseid, orderaccountclassinfo.getLongValue("sa_accountclassid"), entity, true);
+                JSONObject cashbillPay = Accountbalance.createCashbillPay2(this, sys_enterpriseid, orderaccountclassinfo.getLongValue("sa_accountclassid"), entity, true);
                 sqlList.addAll(cashbillPay.getJSONArray("sqlList").toJavaList(String.class));
                 sa_cashbillidList.add(cashbillPay.getLong("sa_cashbillid"));
                 sqlList.add("update sa_promotion_auth set saledamount=saledamount-" + totalprice + " where sa_promotion_authid=" + sa_promotion_authid);
@@ -3478,7 +3478,7 @@ public class Order extends Controller {
                 entity.setRemarks("由" + orderRow.get(0).getString("sonum") + "订单手工关闭时自动产生");
                 entity.setType("普通费用");
                 entity.setTypemx("订单关闭退款");
-                JSONObject cashbillPay = Accountbalance.createCashbillPay(this, sys_enterpriseid, orderaccountclassinfo.getLongValue("sa_accountclassid"), entity, true);
+                JSONObject cashbillPay = Accountbalance.createCashbillPay2(this, sys_enterpriseid, orderaccountclassinfo.getLongValue("sa_accountclassid"), entity, true);
                 sqlList.addAll(cashbillPay.getJSONArray("sqlList").toJavaList(String.class));
                 sa_cashbillidList.add(cashbillPay.getLong("sa_cashbillid"));
 
@@ -3493,7 +3493,7 @@ public class Order extends Controller {
                 promotionentity.setRemarks("由" + orderRow.get(0).getString("sonum") + "订单手工关闭时自动产生");
                 promotionentity.setType("普通费用");
                 promotionentity.setTypemx("订单关闭退款");
-                JSONObject cashbillPay1 = Accountbalance.createCashbillPay(this, sys_enterpriseid, promotionaccountclassinfo.getLongValue("sa_accountclassid"), promotionentity, true);
+                JSONObject cashbillPay1 = Accountbalance.createCashbillPay2(this, sys_enterpriseid, promotionaccountclassinfo.getLongValue("sa_accountclassid"), promotionentity, true);
                 sqlList.addAll(cashbillPay1.getJSONArray("sqlList").toJavaList(String.class));
                 sa_cashbillidList.add(cashbillPay1.getLong("sa_cashbillid"));
             }