Transferbill.java 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package restcontroller.webmanage.sale.transferbill;
  2. import beans.accountbalance.Accountbalance;
  3. import beans.accountbalance.CashbillEntity;
  4. import com.alibaba.fastjson2.JSONObject;
  5. import common.Controller;
  6. import common.YosException;
  7. import common.annotation.API;
  8. import common.annotation.CACHEING;
  9. import common.annotation.CACHEING_CLEAN;
  10. import common.data.QuerySQL;
  11. import common.data.Rows;
  12. import common.data.db.SQLList;
  13. import common.data.SQLFactory;
  14. import restcontroller.R;
  15. import java.math.BigDecimal;
  16. import java.util.ArrayList;
  17. @API(title = "转账单")
  18. public class Transferbill extends Controller {
  19. /**
  20. * 构造函数
  21. *
  22. * @param content
  23. */
  24. public Transferbill(JSONObject content) throws YosException {
  25. super(content);
  26. }
  27. @API(title = "列表", apiversion = R.ID20230511144904.v1.class)
  28. @CACHEING
  29. public String queryList() throws YosException {
  30. StringBuffer where = new StringBuffer(" 1=1 ");
  31. if (content.containsKey("where")) {
  32. JSONObject whereObject = content.getJSONObject("where");
  33. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  34. where.append(" and(");
  35. where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
  36. where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
  37. where.append("or t3.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
  38. where.append(")");
  39. }
  40. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  41. where.append(" and t1.billdate >='").append(whereObject.getString("begindate")).append("'");
  42. }
  43. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  44. where.append(" and t1.enddate <='").append(whereObject.getString("enddate")).append("'");
  45. }
  46. }
  47. SQLFactory sqlFactory = new SQLFactory(this, "转账单列表查询");
  48. sqlFactory.addParameter("siteid", siteid);
  49. sqlFactory.addParameter_SQL("where", where);
  50. // Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  51. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sys_site_parameter", "sys_site_parameterid");
  52. querySQL.setTableAlias("t0");
  53. querySQL.addJoinTable(JOINTYPE.right, sqlFactory, "t1", "t0.siteid='111'","*");
  54. querySQL.setPage(pageSize, pageNumber);
  55. Rows rows = querySQL.query();
  56. return getSucReturnObject().setData(rows).toString();
  57. }
  58. @API(title = "新增或更新", apiversion = R.ID20230511144804.v1.class)
  59. @CACHEING_CLEAN(apiversions = {R.ID20230511144904.v1.class})
  60. public String insertOrUpdate() throws YosException {
  61. Long sa_transferbillid = content.getLong("sa_transferbillid");
  62. Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  63. Long inaccountclassid = content.getLong("inaccountclassid");
  64. Long sa_accountclassid = content.getLong("sa_accountclassid");
  65. String billdate = content.getString("billdate");
  66. BigDecimal amount = content.getBigDecimal("amount");
  67. String remarks = content.getStringValue("remarks");
  68. if (inaccountclassid.equals(sa_accountclassid)) {
  69. return getErrReturnObject().setErrMsg("转出账户和转入账户不能一致").toString();
  70. }
  71. Rows rows = dbConnect.runSqlQuery("select status from sa_transferbill where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
  72. SQLFactory sqlFactory = new SQLFactory(this, "转账单新增");
  73. if (sa_transferbillid <= 0 || rows.isEmpty()) {
  74. sa_transferbillid = createTableID("sa_transferbill");
  75. String billno = createBillCode("transferbill");
  76. sqlFactory.addParameter("billno", billno);
  77. } else {
  78. if (!rows.get(0).getString("status").equals("新建")) {
  79. return getErrReturnObject().setErrMsg("非新建状态转账单不能修改").toString();
  80. }
  81. sqlFactory = new SQLFactory(this, "转账单更新");
  82. }
  83. sqlFactory.addParameter("siteid", siteid);
  84. sqlFactory.addParameter("userid", userid);
  85. sqlFactory.addParameter("username", username);
  86. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  87. sqlFactory.addParameter("inaccountclassid", inaccountclassid);
  88. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  89. sqlFactory.addParameter("billdate", billdate);
  90. sqlFactory.addParameter("amount", amount);
  91. sqlFactory.addParameter("remarks", remarks);
  92. sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
  93. dbConnect.runSqlUpdate(sqlFactory.getSQL());
  94. content.put("sa_transferbillid", sa_transferbillid);
  95. return queryById();
  96. }
  97. @API(title = "审核", apiversion = R.ID20230511144704.v1.class)
  98. @CACHEING_CLEAN(apiversions = {R.ID20230511144904.v1.class, R.ID20221009102903.v1.class, R.ID20230111103403.v1.class, R.ID20221008145903.v1.class, R.ID20221009160003.v1.class})
  99. public String check() throws YosException {
  100. Long sa_transferbillid = content.getLong("sa_transferbillid");
  101. SQLFactory sqlFactory = new SQLFactory(this, "转账单详情");
  102. sqlFactory.addParameter("siteid", siteid);
  103. sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
  104. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  105. if (rows.isEmpty()) {
  106. return getErrReturnObject().setErrMsg("无效转账单").toString();
  107. }
  108. if (!rows.get(0).getString("status").equals("新建")) {
  109. return getErrReturnObject().setErrMsg("非新建状态转账单不能审核").toString();
  110. }
  111. long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
  112. long sa_accountclassid = rows.get(0).getLong("sa_accountclassid");
  113. long inaccountclassid = rows.get(0).getLong("inaccountclassid");
  114. BigDecimal amount = rows.get(0).getBigDecimal("amount");
  115. if (!Accountbalance.judgeBalance(this, sys_enterpriseid, sa_accountclassid, amount)) {
  116. return getErrReturnObject().setErrMsg("账户余额不足").toString();
  117. }
  118. SQLList sqlList = new SQLList();
  119. ArrayList<Long> sa_cashbillidList = new ArrayList<>();
  120. sqlList.add("update sa_transferbill set checkby='" + username + "',checkdate=current_date,status='审核' where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
  121. CashbillEntity cashbillEntity = new CashbillEntity(amount.negate(),BigDecimal.ZERO, "", "转账单", rows.get(0).getString("billno"), "sa_transferbill", sa_transferbillid, "货款", "");
  122. cashbillEntity.setPeriod(rows.get(0).getString("billno"));
  123. SQLList cashbillIncome = Accountbalance.createCashbillIncome(this, sys_enterpriseid, sa_accountclassid, cashbillEntity, true, false);
  124. sqlList.addAll(cashbillIncome);
  125. sa_cashbillidList.add((Long) cashbillIncome.getLong("sa_cashbillid"));
  126. cashbillEntity.setAmount(amount);
  127. cashbillEntity.setDiscountamountamount(BigDecimal.ZERO);
  128. SQLList cashbillIncome1 = Accountbalance.createCashbillIncome(this, sys_enterpriseid, inaccountclassid, cashbillEntity, true, false);
  129. sqlList.addAll(cashbillIncome1);
  130. sa_cashbillidList.add((Long) cashbillIncome1.getLong("sa_cashbillid"));
  131. dbConnect.runSqlUpdate(sqlList);
  132. String billdate = rows.get(0).getString("billdate");
  133. if (!billdate.isEmpty()) {
  134. dbConnect.runSqlUpdate("update sa_cashbill set period= '" + billdate + "' WHERE ownertable='sa_transferbill' and ownerid='" + sa_transferbillid + "'");
  135. }
  136. for (Long sa_cashbillid : sa_cashbillidList) {
  137. Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
  138. }
  139. return getSucReturnObject().toString();
  140. }
  141. @API(title = "删除", apiversion = R.ID20230511144604.v1.class)
  142. @CACHEING_CLEAN(apiversions = {R.ID20230511144904.v1.class})
  143. public String delete() throws YosException {
  144. Long sa_transferbillid = content.getLong("sa_transferbillid");
  145. Rows rows = dbConnect.runSqlQuery("select * from sa_transferbill where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
  146. if (rows.isNotEmpty() && !rows.get(0).getString("status").equals("新建")) {
  147. return getErrReturnObject().setErrMsg("非新建转账单无法删除").toString();
  148. }
  149. dbConnect.runSqlUpdate("delete from sa_transferbill where siteid='" + siteid + "' and sa_transferbillid=" + sa_transferbillid);
  150. return getSucReturnObject().toString();
  151. }
  152. @API(title = "详情", apiversion = R.ID20230511144504.v1.class)
  153. public String queryById() throws YosException {
  154. Long sa_transferbillid = content.getLong("sa_transferbillid");
  155. SQLFactory sqlFactory = new SQLFactory(this, "转账单详情");
  156. sqlFactory.addParameter("siteid", siteid);
  157. sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
  158. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  159. return getSucReturnObject().setData(rows.get(0)).toString();
  160. }
  161. @API(title = "关联收入凭证查询", apiversion = R.ID20230511144404.v1.class)
  162. public String queryCashbill() throws YosException {
  163. Long sa_transferbillid = content.getLong("sa_transferbillid");
  164. SQLFactory sqlFactory = new SQLFactory(this, "关联收入凭证查询");
  165. sqlFactory.addParameter("siteid", siteid);
  166. sqlFactory.addParameter("sa_transferbillid", sa_transferbillid);
  167. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  168. return getSucReturnObject().setData(rows).toString();
  169. }
  170. }