|
|
@@ -0,0 +1,160 @@
|
|
|
+package restcontroller.webmanage.sale.transferbill;
|
|
|
+
|
|
|
+import beans.accountbalance.Accountbalance;
|
|
|
+import beans.accountbalance.AccountbalanceEntity;
|
|
|
+import beans.accountbalance.CashbillEntity;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.annotation.CACHEING;
|
|
|
+import common.annotation.CACHEING_CLEAN;
|
|
|
+import common.data.Rows;
|
|
|
+import common.data.SQLFactory;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.ArrayList;
|
|
|
+
|
|
|
+@API(title = "转账单")
|
|
|
+public class Transferbill extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public Transferbill(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "列表", apiversion = R.ID20230511144904.v1.class)
|
|
|
+ @CACHEING
|
|
|
+ public String queryList() throws YosException {
|
|
|
+ StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
+ if (content.containsKey("where")) {
|
|
|
+ JSONObject whereObject = content.getJSONObject("where");
|
|
|
+ if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
+ where.append(" and(");
|
|
|
+ where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append("or t3.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
+ where.append(")");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
|
|
|
+ where.append(" and t1.billdate >='").append(whereObject.getString("begindate")).append("'");
|
|
|
+ }
|
|
|
+ if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
+ where.append(" and t1.enddate <='").append(whereObject.getString("enddate")).append("'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "转账单列表查询", pageSize, pageNumber, pageSorting);
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter_SQL("where", where);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "新增或更新", apiversion = R.ID20230511144804.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiversions = {R.ID20230511144904.v1.class})
|
|
|
+ public String insertOrUpdate() throws YosException {
|
|
|
+ Long sa_transferbillid = content.getLong("sa_transferbillid");
|
|
|
+ Long sys_enterpriseid = content.getLong("sys_enterpriseid");
|
|
|
+ Long inaccountclassid = content.getLong("inaccountclassid");
|
|
|
+ Long sa_accountclassid = content.getLong("sa_accountclassid");
|
|
|
+ String billdate = content.getString("billdate");
|
|
|
+ BigDecimal amount = content.getBigDecimal("amount");
|
|
|
+ String remarks = content.getStringValue("remarks");
|
|
|
+ if (inaccountclassid.equals(sa_accountclassid)) {
|
|
|
+ return getErrReturnObject().setErrMsg("转出账户和转入账户不能一致").toString();
|
|
|
+ }
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select status from sa_transferbill where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "转账单新增");
|
|
|
+ if (sa_transferbillid <= 0 || rows.isEmpty()) {
|
|
|
+ sa_transferbillid = createTableID("sa_transferbill");
|
|
|
+ String billno = createBillCode("transferbill");
|
|
|
+ sqlFactory.addParameter("billno", billno);
|
|
|
+ } else {
|
|
|
+ if (!rows.get(0).getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建状态转账单不能修改").toString();
|
|
|
+ }
|
|
|
+ sqlFactory = new SQLFactory(this, "转账单更新");
|
|
|
+ }
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("userid", userid);
|
|
|
+ sqlFactory.addParameter("username", username);
|
|
|
+ sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ sqlFactory.addParameter("inaccountclassid", inaccountclassid);
|
|
|
+ sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
|
|
|
+ sqlFactory.addParameter("billdate", billdate);
|
|
|
+ sqlFactory.addParameter("amount", amount);
|
|
|
+ sqlFactory.addParameter("remarks", remarks);
|
|
|
+ sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
|
|
|
+ dbConnect.runSqlUpdate(sqlFactory.getSQL());
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "审核", apiversion = R.ID20230511144704.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiversions = {R.ID20230511144904.v1.class, R.ID20221009102903.v1.class, R.ID20230111103403.v1.class, R.ID20221008145903.v1.class, R.ID20221009160003.v1.class})
|
|
|
+ public String check() throws YosException {
|
|
|
+ Long sa_transferbillid = content.getLong("sa_transferbillid");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "转账单详情");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("无效转账单").toString();
|
|
|
+ }
|
|
|
+ if (!rows.get(0).getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建状态转账单不能审核").toString();
|
|
|
+ }
|
|
|
+ long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
|
|
|
+ long sa_accountclassid = rows.get(0).getLong("sa_accountclassid");
|
|
|
+ long inaccountclassid = rows.get(0).getLong("inaccountclassid");
|
|
|
+ BigDecimal amount = rows.get(0).getBigDecimal("amount");
|
|
|
+ if (!Accountbalance.judgeBalance(this, sys_enterpriseid, sa_accountclassid, amount)) {
|
|
|
+ return getErrReturnObject().setErrMsg("账户余额不足").toString();
|
|
|
+ }
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ sqlList.add("update sa_transferbill set checkby='" + username + "',checkdate=current_date,status='审核' where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
|
|
|
+ CashbillEntity cashbillEntity = new CashbillEntity(amount.negate(), "", "转账单", rows.get(0).getString("billno"), "sa_transferbill", sa_transferbillid);
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillIncome(this, sys_enterpriseid, sa_accountclassid, cashbillEntity, true));
|
|
|
+ cashbillEntity.setAmount(amount);
|
|
|
+ sqlList.addAll(Accountbalance.createCashbillIncome(this, sys_enterpriseid, inaccountclassid, cashbillEntity, true));
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "删除", apiversion = R.ID20230511144604.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiversions = {R.ID20230511144904.v1.class})
|
|
|
+ public String delete() throws YosException {
|
|
|
+ Long sa_transferbillid = content.getLong("sa_transferbillid");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select * from sa_transferbill where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
|
|
|
+ if (rows.isNotEmpty() && !rows.get(0).getString("status").equals("新建")) {
|
|
|
+ return getErrReturnObject().setErrMsg("非新建转账单无法删除").toString();
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_transferbill where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "详情", apiversion = R.ID20230511144504.v1.class)
|
|
|
+ public String queryById() throws YosException {
|
|
|
+ Long sa_transferbillid = content.getLong("sa_transferbillid");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "转账单详情");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+ return getSucReturnObject().setData(rows.get(0)).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ @API(title = "关联收入凭证查询", apiversion = R.ID20230511144404.v1.class)
|
|
|
+ public String queryCashbill() throws YosException {
|
|
|
+ Long sa_transferbillid = content.getLong("sa_transferbillid");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(this, "关联收入凭证查询");
|
|
|
+ sqlFactory.addParameter("siteid", siteid);
|
|
|
+ sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
|
|
|
+ Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
|
|
|
+ return getSucReturnObject().setData(rows).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+}
|