|
@@ -6,6 +6,7 @@ import common.Controller;
|
|
|
import common.YosException;
|
|
import common.YosException;
|
|
|
import common.data.Rows;
|
|
import common.data.Rows;
|
|
|
import common.data.SQLFactory;
|
|
import common.data.SQLFactory;
|
|
|
|
|
+import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
@@ -138,6 +139,90 @@ public class Accountbalance extends BaseClass {
|
|
|
return sqlList;
|
|
return sqlList;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 创建收入凭证(返回SQL)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param controller
|
|
|
|
|
+ * @param sys_enterpriseid 企业id
|
|
|
|
|
+ * @param sa_accountclassid 账户id
|
|
|
|
|
+ * @param cashbillEntity 收支凭证实体
|
|
|
|
|
+ * @param ischeck 是否审核
|
|
|
|
|
+ * @param period 归属日期
|
|
|
|
|
+ * @return
|
|
|
|
|
+ * @throws YosException
|
|
|
|
|
+ */
|
|
|
|
|
+ public static ArrayList<String> createCashbillIncome(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck,String period) 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", 1);
|
|
|
|
|
+ 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("sa_cashbillid_rebate", "null");
|
|
|
|
|
+ sqlFactory.addParameter("class", cashbillEntity.getType());
|
|
|
|
|
+ sqlFactory.addParameter("subclass", cashbillEntity.getTypemx());
|
|
|
|
|
+ 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 accountbalanceaddSqlFactory = new SQLFactory(new Accountbalance(), "营销账户余额新增");
|
|
|
|
|
+ accountbalanceaddSqlFactory.addParameter("sa_accountbalanceid",
|
|
|
|
|
+ controller.createTableID("sa_accountbalance"));
|
|
|
|
|
+ accountbalanceaddSqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
|
|
|
|
|
+ accountbalanceaddSqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
|
|
|
|
|
+ accountbalanceaddSqlFactory.addParameter("siteid", controller.siteid);
|
|
|
|
|
+ accountbalanceaddSqlFactory.addParameter("balance", cashbillEntity.getAmount());
|
|
|
|
|
+ accountbalanceaddSqlFactory.addParameter("userid", controller.userid);
|
|
|
|
|
+ accountbalanceaddSqlFactory.addParameter("username", controller.username);
|
|
|
|
|
+ balance = cashbillEntity.getAmount();
|
|
|
|
|
+ sqlList.add(accountbalanceaddSqlFactory.getSQL());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ BigDecimal newbalance = cashbillEntity.getAmount().add(rowsaccountbalance.get(0).getBigDecimal("balance"));
|
|
|
|
|
+ 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);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sqlFactory.addParameter("status", "新建");
|
|
|
|
|
+ sqlFactory.addParameter("checkby", "null");
|
|
|
|
|
+ sqlFactory.addParameter("checkdate", "null");
|
|
|
|
|
+ sqlFactory.addParameter("balance", 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
|
|
+ if(!StringUtils.isBlank(period)){
|
|
|
|
|
+ sqlList.add("update sa_cashbill set period='"+period+"' where sa_cashbillid="+sa_cashbillid +" and siteid='"+controller.siteid+"'");
|
|
|
|
|
+ }
|
|
|
|
|
+ String content = "您有一项来自【" + cashbillEntity.getSource() + "】金额为" + cashbillEntity.getAmount() + "的【收入】凭证";
|
|
|
|
|
+ new Accountbalance().sendMsg(controller, content, cashbillEntity.getOwnerid(), sys_enterpriseid);
|
|
|
|
|
+ return sqlList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 创建支出凭证(返回SQL)
|
|
* 创建支出凭证(返回SQL)
|
|
|
*
|
|
*
|
|
@@ -218,6 +303,79 @@ public class Accountbalance extends BaseClass {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ public static ArrayList<String> createCashbillPay(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck,String period) 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");
|
|
|
|
|
+ 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("该营销账户不存在,支出凭证无法审核");
|
|
|
|
|
+ } else {
|
|
|
|
|
+ BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
|
|
|
|
|
+ if (cashbillEntity.getAmount().compareTo(new BigDecimal("0")) == 1) {
|
|
|
|
|
+ if (cashbillEntity.getAmount().compareTo(canuseamount) == 1) {
|
|
|
|
|
+ throw new YosException("该营销账户可用余额不足,支出凭证无法审核");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ 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);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ sqlFactory.addParameter("status", "新建");
|
|
|
|
|
+ sqlFactory.addParameter("checkby", "");
|
|
|
|
|
+ sqlFactory.addParameter("checkdate", "");
|
|
|
|
|
+ sqlFactory.addParameter("balance", 0);
|
|
|
|
|
+ }
|
|
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
|
|
+ if(!StringUtils.isBlank(period)){
|
|
|
|
|
+ sqlList.add("update sa_cashbill set period='"+period+"' where sa_cashbillid="+sa_cashbillid +" and siteid='"+controller.siteid+"'");
|
|
|
|
|
+ }
|
|
|
|
|
+ String content = "您有一项来自【" + cashbillEntity.getSource() + "】金额为" + cashbillEntity.getAmount() + "的【支出】凭证";
|
|
|
|
|
+ new Accountbalance().sendMsg(controller, content, cashbillEntity.getOwnerid(), sys_enterpriseid);
|
|
|
|
|
+ return sqlList;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
public static ArrayList<String> createCashbillPay(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck, Long sa_cashbillid_rebate) throws YosException {
|
|
public static ArrayList<String> createCashbillPay(Controller controller, long sys_enterpriseid, long sa_accountclassid, CashbillEntity cashbillEntity, boolean ischeck, Long sa_cashbillid_rebate) throws YosException {
|
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
|
long sa_cashbillid = controller.createTableID("sa_cashbill");
|
|
long sa_cashbillid = controller.createTableID("sa_cashbill");
|