ToolBill.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  1. package restcontroller.webmanage.sale.toolbill;
  2. import beans.accountbalance.Accountbalance;
  3. import beans.accountbalance.CashbillEntity;
  4. import beans.datacontrllog.DataContrlLog;
  5. import beans.dataextend.DataExtend;
  6. import beans.datateam.DataTeam;
  7. import beans.hr.Hr;
  8. import beans.parameter.Parameter;
  9. import beans.remind.Remind;
  10. import beans.uploaderpdata.UploadDataToERP;
  11. import com.alibaba.fastjson.JSONArray;
  12. import com.alibaba.fastjson.JSONObject;
  13. import common.Controller;
  14. import common.YosException;
  15. import common.annotation.API;
  16. import common.annotation.CACHEING;
  17. import common.annotation.CACHEING_CLEAN;
  18. import common.data.Row;
  19. import common.data.Rows;
  20. import common.data.RowsMap;
  21. import common.data.SQLFactory;
  22. import restcontroller.R;
  23. import restcontroller.webmanage.sale.order.Order;
  24. import java.io.IOException;
  25. import java.math.BigDecimal;
  26. import java.util.ArrayList;
  27. import java.util.HashMap;
  28. import static beans.order.Order.getOrderRows;
  29. /**
  30. * 工具借用单
  31. */
  32. public class ToolBill extends Controller {
  33. /**
  34. * 构造函数
  35. *
  36. * @param content
  37. */
  38. public ToolBill(JSONObject content) throws YosException {
  39. super(content);
  40. }
  41. @API(title = "查询企业的工具合同", apiversion = R.ID20230114092502.v1.class)
  42. public String queryEnterpriseToolContract() throws YosException {
  43. StringBuffer where = new StringBuffer(" 1=1 ");
  44. if (content.containsKey("where")) {
  45. JSONObject whereObject = content.getJSONObject("where");
  46. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  47. where.append(" and(");
  48. where.append("t1.billno like'%").append(whereObject.getString("condition")).append("%' ");
  49. where.append("or t1.title like'%").append(whereObject.getString("condition")).append("%' ");
  50. where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
  51. where.append(")");
  52. }
  53. }
  54. if (content.containsKey("sys_enterpriseid")) {
  55. sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  56. }
  57. SQLFactory sqlFactory = new SQLFactory(this, "查询企业的工具合同", pageSize, pageNumber, pageSorting);
  58. sqlFactory.addParameter("siteid", siteid);
  59. sqlFactory.addParameter_SQL("where", where);
  60. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  61. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  62. return getSucReturnObject().setData(rows).toString();
  63. }
  64. @API(title = "新增或更新", apiversion = R.ID20230116092702.v1.class, intervaltime = 200)
  65. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  66. public String insertOrUpdate() throws YosException {
  67. //表名
  68. String tableName = "sa_order";
  69. Long sa_orderid = content.getLong("sa_orderid");
  70. if (content.getLongValue("sys_enterpriseid") > 0) {
  71. sys_enterpriseid = content.getLongValue("sys_enterpriseid");
  72. }
  73. Long sa_brandid = content.getLongValue("sa_brandid");
  74. Long sa_contractid = content.getLongValue("sa_contractid");
  75. Long sa_projectid = content.getLongValue("sa_projectid");
  76. boolean isAdd;
  77. SQLFactory sqlFactory = new SQLFactory(this, "工具借用单新增");
  78. if (sa_orderid <= 0) {
  79. isAdd = true;
  80. sa_orderid = createTableID(tableName);
  81. //默认当前用户为负责人
  82. DataTeam.createTeam(this, "sa_order", sa_orderid, userid);
  83. dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_order", sa_orderid, "新增", "工具借用单新增成功").getSQL());
  84. } else {
  85. Rows rows = dbConnect.runSqlQuery("SELECT status from sa_order WHERE sa_orderid = " + sa_orderid);
  86. if (rows.isNotEmpty()) {
  87. sqlFactory = new SQLFactory(this, "工具借用单更新");
  88. isAdd = false;
  89. dbConnect.runSqlUpdate(DataContrlLog.createLog(this, "sa_order", sa_orderid, "更新", "订单更新成功").getSQL());
  90. } else {
  91. return getErrReturnObject().setErrMsg("未找到数据").toString();
  92. }
  93. }
  94. sqlFactory.addParameter("siteid", siteid);
  95. sqlFactory.addParameter("userid", userid);
  96. sqlFactory.addParameter("username", username);
  97. sqlFactory.addParameter("sa_orderid", sa_orderid);
  98. //订单编号
  99. sqlFactory.addParameter("sonum", createBillCode("orderbill"));
  100. //订单类型
  101. sqlFactory.addParameter("type", "工具借用单");
  102. //明细分类
  103. sqlFactory.addParameter("typemx", content.getStringValue("typemx"));
  104. //订货企业id
  105. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  106. //营销账户类型ID
  107. sqlFactory.addParameter("sa_accountclassid", beans.order.Order.getDefaultAccount(siteid, "工具借用单"));
  108. //品牌ID
  109. sqlFactory.addParameter("sa_brandid", sa_brandid);
  110. //合同ID
  111. sqlFactory.addParameter("sa_contractid", sa_contractid);
  112. //工程项目表ID
  113. sqlFactory.addParameter("sa_projectid", sa_projectid);
  114. //合作企业财务信息ID(开票信息)
  115. Long sys_enterprise_financeid = content.getLongValue("sys_enterprise_financeid");
  116. if (sys_enterprise_financeid <= 0 && isAdd) {
  117. sys_enterprise_financeid = new Order(content).getDefaultEnterpriseFinanceid(sys_enterpriseid);
  118. }
  119. sqlFactory.addParameter("sys_enterprise_financeid", sys_enterprise_financeid);
  120. //物流公司档案ID
  121. //sqlFactory.addParameter("sa_logiscompid", content.getLongValue("sa_logiscompid"));
  122. //合作企业联系人表ID(收货信息)
  123. //合作企业联系人表ID(收货信息),设置默认
  124. Long rec_contactsid = content.getLongValue("rec_contactsid");
  125. if (rec_contactsid <= 0 && isAdd) {
  126. rec_contactsid = new Order(content).getDefaultContactsid(sys_enterpriseid);
  127. }
  128. sqlFactory.addParameter("rec_contactsid", rec_contactsid);
  129. //备注说明
  130. sqlFactory.addParameter("remarks", content.getStringValue("remarks"));
  131. //销售人员hrid,业务员hrid
  132. sqlFactory.addParameter("saler_hrid", new Order(content).getSaleHrid(sys_enterpriseid));
  133. //制单方 1表示工厂方,0表示客户方
  134. if (usertype == 21 || usertype == 22) {
  135. sqlFactory.addParameter("createflag", 0);
  136. } else {
  137. sqlFactory.addParameter("createflag", 1);
  138. }
  139. // 领域
  140. sqlFactory.addParameter("tradefield", content.getStringValue("tradefield"));
  141. //结算单位
  142. Long pay_enterpriseid = content.getLongValue("pay_enterpriseid");
  143. if (isAdd) {
  144. pay_enterpriseid = sys_enterpriseid;
  145. }
  146. sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid);
  147. //单据日期
  148. String billdate = content.getStringValue("billdate");
  149. //订单新增时
  150. if (isAdd) {
  151. if (billdate.equals("")) {
  152. sqlFactory.addParameter_SQL("billdate", "current_time");
  153. } else {
  154. sqlFactory.addParameter("billdate", billdate);
  155. }
  156. } else {
  157. //订单更新时
  158. if (billdate.equals("")) {
  159. sqlFactory.addParameter_SQL("billdate", "createdate");
  160. } else {
  161. sqlFactory.addParameter("billdate", billdate);
  162. }
  163. }
  164. sqlFactory.addParameter("rebate_used", content.getBooleanValue("rebate_used"));
  165. sqlFactory.addParameter("signbacknum", content.getStringValue("signbacknum"));
  166. sqlFactory.addParameter("tradefieldmx", content.getStringValue("tradefieldmx"));
  167. sqlFactory.addParameter("sa_promotionid", "null");
  168. sqlFactory.addParameter("freightstatus", content.getStringValue("freightstatus"));
  169. //套
  170. Long toolcount = content.getLongValue("toolcount", 1L);
  171. sqlFactory.addParameter("toolcount", toolcount);
  172. String sql = sqlFactory.getSQL();
  173. dbConnect.runSqlUpdate(sql);
  174. content.put("sa_orderid", sa_orderid);
  175. return selectDetail();
  176. }
  177. @API(title = "更改套数", apiversion = R.ID20230202135502.v1.class)
  178. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  179. public String changeToolCount() throws YosException {
  180. //表名
  181. Long sa_orderid = content.getLong("sa_orderid");
  182. Long toolcount = content.getLongValue("toolcount", 1L);
  183. SQLFactory sqlFactory = new SQLFactory(this, "工具借用单更新套数");
  184. sqlFactory.addParameter("siteid", siteid);
  185. sqlFactory.addParameter("userid", userid);
  186. sqlFactory.addParameter("username", username);
  187. sqlFactory.addParameter("sa_orderid", sa_orderid);
  188. sqlFactory.addParameter("toolcount", toolcount);
  189. String sql = sqlFactory.getSQL();
  190. dbConnect.runSqlUpdate(sql);
  191. content.put("sa_orderid", sa_orderid);
  192. return selectDetail();
  193. }
  194. @API(title = "工具借用单列表", apiversion = R.ID20230114105002.v1.class)
  195. @CACHEING
  196. public String queryToolList() throws YosException, IOException {
  197. StringBuffer where = new StringBuffer(" 1=1 ");
  198. if (content.containsKey("where")) {
  199. JSONObject whereObject = content.getJSONObject("where");
  200. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  201. where.append(" and(");
  202. where.append("t1.sonum like'%").append(whereObject.getString("condition")).append("%' ");
  203. where.append("or t5.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
  204. where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
  205. where.append(")");
  206. }
  207. //状态
  208. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  209. where.append(" and(");
  210. where.append("t1.status like'%").append(whereObject.getString("status")).append("%' ");
  211. where.append(")");
  212. }
  213. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  214. where.append(" and t1.billdate >='").append(whereObject.getString("begindate")).append("' ");
  215. }
  216. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  217. where.append(" and t1.billdate <='").append(whereObject.getString("enddate")).append("' ");
  218. }
  219. }
  220. //是否管理端
  221. Long isManage = content.getLongValue("isManage", 2L);
  222. //经销商
  223. if (isManage == 1 && (usertype == 21 || usertype == 22)) {
  224. where.append(" and t1.sys_enterpriseid = " + sys_enterpriseid + " ");
  225. }
  226. //业务员
  227. if (isManage == 0 && usertype == 1) {
  228. ArrayList<Long> sys_enterpriseids = new ArrayList<>();
  229. sys_enterpriseids.addAll(Hr.getAgents(this, hrid));
  230. sys_enterpriseids.addAll(Hr.getCustomers(this, hrid));
  231. String sql = " and t1.sys_enterpriseid IN " + sys_enterpriseids;
  232. sql = sql.replace("[", "(").replace("]", ")");
  233. where.append(sql);
  234. }
  235. boolean isExport = content.getBooleanValue("isExport");
  236. SQLFactory sqlFactory = new SQLFactory(this, "工具借用单列表", pageSize, pageNumber, pageSorting);
  237. if (isExport) {
  238. sqlFactory = new SQLFactory(this, "工具借用单列表");
  239. }
  240. sqlFactory.addParameter("siteid", siteid);
  241. sqlFactory.addParameter_SQL("where", where);
  242. String sql = sqlFactory.getSQL();
  243. Rows rows = dbConnect.runSqlQuery(sql);
  244. //查询数据:amount,defaultamount,qty
  245. ArrayList<Long> sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>());
  246. sqlFactory = new SQLFactory(this, "查询工具数据");
  247. sqlFactory.addParameter("siteid", siteid);
  248. sqlFactory.addParameter_in("sa_orderid", sa_orderids);
  249. RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid");
  250. for (Row row : rows) {
  251. Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows());
  252. if (dataRows.isNotEmpty()) {
  253. row.putAll(dataRows.get(0));
  254. } else {
  255. row.put("amount", 0);
  256. row.put("qty", 0);
  257. }
  258. }
  259. // if (isExport) {
  260. // Rows uploadRows = uploadExcelToObs("order", "工具借用单列表", rows, new HashMap<>());
  261. // return getSucReturnObject().setData(uploadRows).toString();
  262. // }
  263. return getSucReturnObject().setData(rows).toString();
  264. }
  265. @API(title = "工具借用单详情", apiversion = R.ID20230114140402.v1.class)
  266. @CACHEING
  267. public String selectDetail() throws YosException {
  268. Long sa_orderid = content.getLong("sa_orderid");
  269. //查询详情
  270. SQLFactory sqlFactory = new SQLFactory(this, "工具借用单详情");
  271. sqlFactory.addParameter("sa_orderid", sa_orderid);
  272. sqlFactory.addParameter("siteid", siteid);
  273. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  274. //查询数据
  275. ArrayList<Long> sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>());
  276. sqlFactory = new SQLFactory(this, "查询工具数据");
  277. sqlFactory.addParameter("siteid", siteid);
  278. sqlFactory.addParameter_in("sa_orderid", sa_orderids);
  279. RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid");
  280. ArrayList<Long> sys_enterpriseids = rows.toArrayList("pay_enterpriseid", new ArrayList<>());
  281. //查询开票信息
  282. sqlFactory = new SQLFactory(this, "查询经销商默认开票信息");
  283. sqlFactory.addParameter("siteid", siteid);
  284. sqlFactory.addParameter_in("sys_enterpriseid", sys_enterpriseids);
  285. RowsMap financeRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sys_enterpriseid");
  286. for (Row row : rows) {
  287. row.put("pay_finance", financeRowsMap.getOrDefault(row.getString("sys_enterpriseid"), new Rows()));
  288. Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows());
  289. if (dataRows.isNotEmpty()) {
  290. row.putAll(dataRows.get(0));
  291. } else {
  292. row.put("amount", 0);
  293. row.put("qty", 0);
  294. }
  295. }
  296. Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
  297. Long pay_enterpriseid = row.getLong("pay_enterpriseid");
  298. Long sa_accountclassid = row.getLong("sa_accountclassid");
  299. //开票信息
  300. sqlFactory = new SQLFactory(this, "工具_开票信息");
  301. sqlFactory.addParameter("siteid", siteid);
  302. sqlFactory.addParameter("sa_orderid", sa_orderid);
  303. Rows financeRows = dbConnect.runSqlQuery(sqlFactory);
  304. row.put("finance", financeRows.isNotEmpty() ? financeRows.get(0) : new Row());
  305. //物流
  306. // sqlFactory = new SQLFactory(this, "工具-查询物流信息");
  307. // sqlFactory.addParameter("siteid", siteid);
  308. // sqlFactory.addParameter("sa_orderid", sa_orderid);
  309. // Rows logiscompRows = dbConnect.runSqlQuery(sqlFactory);
  310. // row.put("logiscomp", logiscompRows.isNotEmpty() ? logiscompRows.get(0) : new Row());
  311. //营销账户类型
  312. sqlFactory = new SQLFactory(this, "工具-查询营销账号");
  313. sqlFactory.addParameter("siteid", siteid);
  314. sqlFactory.addParameter("sa_orderid", sa_orderid);
  315. sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid);
  316. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  317. String sql = sqlFactory.getSQL();
  318. Rows accountclassRows = dbConnect.runSqlQuery(sql);
  319. if (accountclassRows.isNotEmpty()) {
  320. accountclassRows.get(0).put("amount", row.getBigDecimal("amount"));
  321. accountclassRows.get(0).put("rebate_used", row.getBigDecimal("rebate_used"));
  322. accountclassRows.get(0).put("rebate_userate", row.getBigDecimal("rebate_userate"));
  323. accountclassRows.get(0).put("rebate_amount", row.getBigDecimal("amount").multiply(row.getBigDecimal("rebate_userate")));
  324. }
  325. row.put("accountclass", accountclassRows.isNotEmpty() ? accountclassRows.get(0) : new Row());
  326. //收货信息
  327. row.put("contacts", beans.order.Order.getContactsRow(this, row.getLong("rec_contactsid")));
  328. Rows deliveryRows = dbConnect.runSqlQuery("SELECT count(0) count from plm_item WHERE itemid in (SELECT itemid from sa_orderitems WHERE sa_orderid = " + sa_orderid + " and siteid = '" + siteid + "') and delivery >0 and siteid = '" + siteid + "'");
  329. if (deliveryRows.get(0).getLong("count") > 0) {
  330. row.put("isdelivery", 1);
  331. } else {
  332. row.put("isdelivery", 0);
  333. }
  334. Rows contractrow = dbConnect.runSqlQuery("SELECT * from sa_contract WHERE sa_contractid in (SELECT sa_contractid FROM sa_order WHERE sa_orderid=" + sa_orderid + ")");
  335. if (contractrow.isNotEmpty()) {
  336. row.put("contract", contractrow.get(0));
  337. } else {
  338. row.put("contract", new Row());
  339. }
  340. row.put("rebatebalance", Accountbalance.getRebateBalance(this, pay_enterpriseid));
  341. return getSucReturnObject().setData(row).toString();
  342. }
  343. @API(title = "删除", apiversion = R.ID20230116100002.v1.class)
  344. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  345. public String delete() throws YosException {
  346. JSONArray sa_orderids = content.getJSONArray("sa_orderids");
  347. if (sa_orderids.size() <= 0) {
  348. return getErrReturnObject().setErrMsg("请选择要执行删除操作的数据。").toString();
  349. }
  350. String sql = "SELECT 1 from sa_order WHERE sa_orderid in " + sa_orderids + " and `status` !='新建' and siteid = '" + siteid + "'";
  351. sql = sql.replace("[", "(").replace("]", ")");
  352. if (dbConnect.runSqlQuery(sql).isNotEmpty()) {
  353. return getErrReturnObject().setErrMsg("存在非新建状态数据,无法执行删除操作。").toString();
  354. }
  355. ArrayList<String> sqlList = new ArrayList<>();
  356. SQLFactory sqlFactory = new SQLFactory(this, "删除");
  357. sqlFactory.addParameter("siteid", siteid);
  358. sqlFactory.addParameter_in("sa_orderid", sa_orderids.toArray());
  359. sqlList.add(sqlFactory.getSQL());
  360. //订单删除原因
  361. DataExtend.createDeleteReasonSql(this, "sa_order", sa_orderids.toJavaList(Long.class), content.getStringValue("deletereason"));
  362. //操作记录
  363. for (Object obj : sa_orderids) {
  364. Long sa_orderid = Long.valueOf(obj.toString());
  365. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "删除", "工具借用单删除").getSQL());
  366. }
  367. dbConnect.runSqlUpdate(sqlList);
  368. return getSucReturnObject().toString();
  369. }
  370. @API(title = "交期回复", apiversion = R.ID20230114152602.v1.class)
  371. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  372. public String delivery() throws YosException {
  373. Long sa_orderid = content.getLong("sa_orderid");
  374. Rows rows = getOrderRows(this, sa_orderid);
  375. if (rows.isEmpty()) {
  376. return getErrReturnObject().setErrMsg("数据不存在").toString();
  377. }
  378. // if (!rows.get(0).getString("status").equals("新建")) {
  379. // return getErrReturnObject().setErrMsg("非新建状态无法交期回复").toString();
  380. // }
  381. ArrayList<String> sqlList = new ArrayList<>();
  382. SQLFactory sqlFactory = new SQLFactory(this, "交期回复");
  383. sqlFactory.addParameter("siteid", siteid);
  384. sqlFactory.addParameter("userid", userid);
  385. sqlFactory.addParameter("username", username);
  386. sqlFactory.addParameter("sa_orderid", sa_orderid);
  387. sqlList.add(sqlFactory.getSQL());
  388. //操作记录
  389. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期回复", "工具借用单:交期回复" + sa_orderid).getSQL());
  390. dbConnect.runSqlUpdate(sqlList);
  391. return getSucReturnObject().toString();
  392. }
  393. @API(title = "确认交期,操作交期待确认的", apiversion = R.ID20230129154102.v1.class)
  394. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  395. public String confirmDeliveryDate() throws YosException {
  396. Long sa_orderid = content.getLong("sa_orderid");
  397. Rows rows = getOrderRows(this, sa_orderid);
  398. if (rows.isEmpty()) {
  399. return getErrReturnObject().setErrMsg("订单不存在").toString();
  400. }
  401. //交期待确认
  402. String status = rows.get(0).getString("status");
  403. if (!status.equals("交期待确认")) {
  404. return getErrReturnObject().setErrMsg("只能操作交期待确认的订单").toString();
  405. }
  406. ArrayList<String> sqlList = new ArrayList<>();
  407. SQLFactory sqlFactory = new SQLFactory(this, "确认交期");
  408. sqlFactory.addParameter("siteid", siteid);
  409. sqlFactory.addParameter("userid", userid);
  410. sqlFactory.addParameter("username", username);
  411. sqlFactory.addParameter("sa_orderid", sa_orderid);
  412. sqlList.add(sqlFactory.getSQL());
  413. //操作记录
  414. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期确认", "工具借用单交期确认").getSQL());
  415. dbConnect.runSqlUpdate(sqlList);
  416. return getSucReturnObject().toString();
  417. }
  418. @API(title = "撤回交期回复", apiversion = R.ID20230114152702.v1.class)
  419. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  420. public String unDelivery() throws YosException {
  421. Long sa_orderid = content.getLong("sa_orderid");
  422. Rows rows = getOrderRows(this, sa_orderid);
  423. ArrayList<String> sqlList = new ArrayList<>();
  424. if (rows.isEmpty()) {
  425. return getErrReturnObject().setErrMsg("数据不存在").toString();
  426. }
  427. if (!rows.get(0).getString("status").equals("交期回复")) {
  428. return getErrReturnObject().setErrMsg("非交期回复状态无法撤回").toString();
  429. }
  430. SQLFactory sqlFactory = new SQLFactory(this, "撤回交期回复");
  431. sqlFactory.addParameter("siteid", siteid);
  432. sqlFactory.addParameter("userid", userid);
  433. sqlFactory.addParameter("username", username);
  434. sqlFactory.addParameter("sa_orderid", sa_orderid);
  435. sqlList.add(sqlFactory.getSQL());
  436. //操作记录
  437. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "撤回交期回复", "工具借用单:撤回交期回复" + sa_orderid).getSQL());
  438. dbConnect.runSqlUpdate(sqlList);
  439. return getSucReturnObject().toString();
  440. }
  441. @API(title = "提交", apiversion = R.ID20230114160002.v1.class)
  442. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  443. public String submit() throws YosException {
  444. Long sa_orderid = content.getLong("sa_orderid");
  445. Rows rows = getOrderRows(this, sa_orderid);
  446. ArrayList<String> sqlList = new ArrayList<>();
  447. if (rows.isEmpty()) {
  448. return getErrReturnObject().setErrMsg("数据不存在").toString();
  449. }
  450. Row row = rows.get(0);
  451. BigDecimal amount = getAmount(sa_orderid);
  452. Rows freefreightamountRows = dbConnect.runSqlQuery("SELECT ifnull(freefreightamount,0) freefreightamount from sys_enterprise WHERE sys_enterpriseid= 1 and siteid ='yostest2'");
  453. BigDecimal freefreightamount = freefreightamountRows.get(0).getBigDecimal("freefreightamount");
  454. String freightstatus = row.getString("freightstatus");
  455. if (freightstatus.isEmpty()) {
  456. if (freefreightamount.compareTo(BigDecimal.ZERO) == -1) {
  457. freightstatus = "到付";
  458. }
  459. if (freefreightamount.compareTo(BigDecimal.ZERO) == 0) {
  460. freightstatus = "预付";
  461. }
  462. if (freefreightamount.compareTo(BigDecimal.ZERO) == 1) {
  463. if (amount.compareTo(freefreightamount) == 1) {
  464. freightstatus = "预付";
  465. } else {
  466. freightstatus = "到付";
  467. }
  468. }
  469. }
  470. SQLFactory sqlFactory = new SQLFactory(this, "提交");
  471. sqlFactory.addParameter("siteid", siteid);
  472. sqlFactory.addParameter("userid", userid);
  473. sqlFactory.addParameter("username", username);
  474. sqlFactory.addParameter("freightstatus", freightstatus);
  475. sqlFactory.addParameter("sa_orderid", sa_orderid);
  476. sqlList.add(sqlFactory.getSQL());
  477. //操作记录
  478. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "提交", "工具借用单:提交" + sa_orderid).getSQL());
  479. dbConnect.runSqlUpdate(sqlList);
  480. return getSucReturnObject().toString();
  481. }
  482. @API(title = "审核", apiversion = R.ID20230114161402.v1.class)
  483. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  484. public String check() throws YosException {
  485. Long sa_orderid = content.getLong("sa_orderid");
  486. String reviewtype = content.getString("reviewtype");
  487. Rows rows = getOrderRows(this, sa_orderid);
  488. ArrayList<String> sqlList = new ArrayList<>();
  489. if (rows.isEmpty()) {
  490. return getErrReturnObject().setErrMsg("数据不存在").toString();
  491. }
  492. if (!rows.get(0).getString("status").equals("提交") && !rows.get(0).getString("status").equals("交期确认")) {
  493. return getErrReturnObject().setErrMsg("非提交,交期确认状态无法审核").toString();
  494. }
  495. Row row = rows.get(0);
  496. Long sa_accountclassid = row.getLong("sa_accountclassid");
  497. if (sa_accountclassid <= 0) {
  498. return getErrReturnObject().setErrMsg("请选择支付账号").toString();
  499. }
  500. //验证结算企业
  501. Long pay_enterpriseid = row.getLong("pay_enterpriseid");
  502. if (pay_enterpriseid <= 0) {
  503. return getErrReturnObject().setErrMsg("请选择结算企业").toString();
  504. }
  505. String sonum = row.getString("sonum");
  506. SQLFactory sqlFactory = new SQLFactory(this, "审核");
  507. sqlFactory.addParameter("siteid", siteid);
  508. sqlFactory.addParameter("userid", userid);
  509. sqlFactory.addParameter("username", username);
  510. sqlFactory.addParameter("reviewtype", reviewtype);
  511. sqlFactory.addParameter("sa_orderid", sa_orderid);
  512. sqlList.add(sqlFactory.getSQL());
  513. BigDecimal amount = getAmount(sa_orderid);
  514. CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "押金收入凭证", "由" + sonum + "工具借用单审核时自动产生");
  515. JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true, false);
  516. sqlList.addAll(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
  517. Long sa_cashbillid = cashbillIncome.getLong("sa_cashbillid");
  518. //操作记录
  519. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "审核", "工具借用单:审核" + sa_orderid).getSQL());
  520. dbConnect.runSqlUpdate(sqlList);
  521. Accountbalance.remindSend(this, pay_enterpriseid, sa_cashbillid);
  522. if (Parameter.get("system.erp_dockswitch").equalsIgnoreCase("true")) {
  523. UploadDataToERP uploadDataToERP = new UploadDataToERP(this, sa_orderid, "");
  524. boolean issuccess = uploadDataToERP.upload();
  525. if (!issuccess) {
  526. unCheck();
  527. return getErrReturnObject().setErrMsg("上传ERP失败,当前单据将自动反审核,请检查!").toString();
  528. } else {
  529. Long sys_enterpriseid = row.getLong("sys_enterpriseid");
  530. sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid);
  531. sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid);
  532. }
  533. } else {
  534. Long sys_enterpriseid = row.getLong("sys_enterpriseid");
  535. sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid);
  536. sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid);
  537. }
  538. return getSucReturnObject().toString();
  539. }
  540. public void sendMsg(String content, Long sa_orderid, Long sys_enterpriseid) throws YosException {
  541. ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid).toArrayList("userid", new ArrayList<>());
  542. Remind remind = new Remind(this);
  543. remind.setTitle("工具借用单");
  544. remind.setContent(content);
  545. remind.setType("应用");
  546. remind.setObjectid(sa_orderid);
  547. remind.setObjectname("sa_order");
  548. remind.setTouserid(userList);
  549. remind.createSys_message();
  550. }
  551. @API(title = "反审核", apiversion = R.ID20230114161502.v1.class)
  552. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  553. public String unCheck() throws YosException {
  554. Long sa_orderid = content.getLong("sa_orderid");
  555. Rows rows = getOrderRows(this, sa_orderid);
  556. ArrayList<String> sqlList = new ArrayList<>();
  557. if (rows.isEmpty()) {
  558. return getErrReturnObject().setErrMsg("数据不存在").toString();
  559. }
  560. if (!rows.get(0).getString("status").equals("审核")) {
  561. return getErrReturnObject().setErrMsg("非审核状态无法反审核").toString();
  562. }
  563. Row row = rows.get(0);
  564. Long sa_accountclassid = row.getLong("sa_accountclassid");
  565. if (sa_accountclassid <= 0) {
  566. return getErrReturnObject().setErrMsg("请选择支付账号").toString();
  567. }
  568. //验证结算企业
  569. Long pay_enterpriseid = row.getLong("pay_enterpriseid");
  570. if (pay_enterpriseid <= 0) {
  571. return getErrReturnObject().setErrMsg("请选择结算企业").toString();
  572. }
  573. String sonum = row.getString("sonum");
  574. SQLFactory sqlFactory = new SQLFactory(this, "反审核");
  575. sqlFactory.addParameter("siteid", siteid);
  576. sqlFactory.addParameter("userid", userid);
  577. sqlFactory.addParameter("username", username);
  578. sqlFactory.addParameter("sa_orderid", sa_orderid);
  579. sqlList.add(sqlFactory.getSQL());
  580. BigDecimal amount = getAmount(sa_orderid);
  581. CashbillEntity entity = getCashbillEntity(amount.negate(), sa_orderid, "押金收入凭证", "由" + sonum + "工具借用反单审核时自动产生");
  582. JSONObject cashbillIncome = Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true, false);
  583. sqlList.addAll(cashbillIncome.getJSONArray("sqlList").toJavaList(String.class));
  584. Long sa_cashbillid = cashbillIncome.getLong("sa_cashbillid");
  585. //操作记录
  586. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反审核", "工具借用单:反审核" + sa_orderid).getSQL());
  587. dbConnect.runSqlUpdate(sqlList);
  588. Accountbalance.remindSend(this, pay_enterpriseid, sa_cashbillid);
  589. return getSucReturnObject().toString();
  590. }
  591. @API(title = "退回", apiversion = R.ID20230116085902.v1.class)
  592. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  593. public String back() throws YosException {
  594. Long sa_orderid = content.getLong("sa_orderid");
  595. Rows rows = getOrderRows(this, sa_orderid);
  596. ArrayList<String> sqlList = new ArrayList<>();
  597. if (rows.isEmpty()) {
  598. return getErrReturnObject().setErrMsg("数据不存在").toString();
  599. }
  600. SQLFactory sqlFactory = new SQLFactory(this, "退回");
  601. sqlFactory.addParameter("siteid", siteid);
  602. sqlFactory.addParameter("userid", userid);
  603. sqlFactory.addParameter("username", username);
  604. sqlFactory.addParameter("sa_orderid", sa_orderid);
  605. sqlList.add(sqlFactory.getSQL());
  606. //操作记录
  607. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "退回", "工具借用单:退回" + sa_orderid).getSQL());
  608. //订单退回原因
  609. ArrayList<Long> sa_orderids = new ArrayList<>();
  610. sa_orderids.add(sa_orderid);
  611. DataExtend.createBackReasonSql(this, "sa_order", sa_orderids, content.getStringValue("backreason"));
  612. dbConnect.runSqlUpdate(sqlList);
  613. return getSucReturnObject().toString();
  614. }
  615. public CashbillEntity getCashbillEntity(BigDecimal amount, Long ownerid, String source, String remarks) throws YosException {
  616. CashbillEntity entity = new CashbillEntity();
  617. entity.setAmount(amount);
  618. entity.setOwnerid(ownerid);
  619. entity.setOwnertable("sa_order");
  620. entity.setSource(source);
  621. entity.setRemarks(remarks);
  622. return entity;
  623. }
  624. /**
  625. * 获取价格(折扣)
  626. *
  627. * @param sa_orderid
  628. * @return
  629. * @throws YosException
  630. */
  631. public BigDecimal getAmount(Long sa_orderid) throws YosException {
  632. Rows rows = dbConnect.runSqlQuery("SELECT ifnull(sum(amount),0) amount from sa_orderitems WHERE sa_orderid=" + sa_orderid + " AND siteid = '" + siteid + "'");
  633. return rows.get(0).getBigDecimal("amount");
  634. }
  635. }