ToolBill.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728
  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. if (content.containsKey("saler_hrid")) {
  133. hrid = content.getLongValue("saler_hrid");
  134. }
  135. if (isAdd) {
  136. hrid = new Order(content).getSaleHrid(sys_enterpriseid);
  137. }
  138. sqlFactory.addParameter("saler_hrid", hrid);
  139. //制单方 1表示工厂方,0表示客户方
  140. if (usertype == 21 || usertype == 22) {
  141. sqlFactory.addParameter("createflag", 0);
  142. } else {
  143. sqlFactory.addParameter("createflag", 1);
  144. }
  145. // 领域
  146. sqlFactory.addParameter("tradefield", content.getStringValue("tradefield"));
  147. //结算单位
  148. Long pay_enterpriseid = content.getLongValue("pay_enterpriseid");
  149. if (isAdd) {
  150. pay_enterpriseid = sys_enterpriseid;
  151. }
  152. sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid);
  153. //单据日期
  154. String billdate = content.getStringValue("billdate");
  155. //订单新增时
  156. if (isAdd) {
  157. if (billdate.equals("")) {
  158. sqlFactory.addParameter_SQL("billdate", "current_time");
  159. } else {
  160. sqlFactory.addParameter("billdate", billdate);
  161. }
  162. } else {
  163. //订单更新时
  164. if (billdate.equals("")) {
  165. sqlFactory.addParameter_SQL("billdate", "createdate");
  166. } else {
  167. sqlFactory.addParameter("billdate", billdate);
  168. }
  169. }
  170. sqlFactory.addParameter("rebate_used", content.getBooleanValue("rebate_used"));
  171. sqlFactory.addParameter("signbacknum", content.getStringValue("signbacknum"));
  172. sqlFactory.addParameter("tradefieldmx", content.getStringValue("tradefieldmx"));
  173. sqlFactory.addParameter("sa_promotionid", "null");
  174. sqlFactory.addParameter("freightstatus", content.getStringValue("freightstatus"));
  175. //套
  176. Long toolcount = content.getLongValue("toolcount", 1L);
  177. sqlFactory.addParameter("toolcount", toolcount);
  178. String sql = sqlFactory.getSQL();
  179. dbConnect.runSqlUpdate(sql);
  180. content.put("sa_orderid", sa_orderid);
  181. return selectDetail();
  182. }
  183. @API(title = "更改套数", apiversion = R.ID20230202135502.v1.class)
  184. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  185. public String changeToolCount() throws YosException {
  186. //表名
  187. Long sa_orderid = content.getLong("sa_orderid");
  188. Long toolcount = content.getLongValue("toolcount", 1L);
  189. SQLFactory sqlFactory = new SQLFactory(this, "工具借用单更新套数");
  190. sqlFactory.addParameter("siteid", siteid);
  191. sqlFactory.addParameter("userid", userid);
  192. sqlFactory.addParameter("username", username);
  193. sqlFactory.addParameter("sa_orderid", sa_orderid);
  194. sqlFactory.addParameter("toolcount", toolcount);
  195. String sql = sqlFactory.getSQL();
  196. dbConnect.runSqlUpdate(sql);
  197. content.put("sa_orderid", sa_orderid);
  198. return selectDetail();
  199. }
  200. @API(title = "工具借用单列表", apiversion = R.ID20230114105002.v1.class)
  201. @CACHEING
  202. public String queryToolList() throws YosException, IOException {
  203. StringBuffer where = new StringBuffer(" 1=1 ");
  204. if (content.containsKey("where")) {
  205. JSONObject whereObject = content.getJSONObject("where");
  206. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  207. where.append(" and(");
  208. where.append("t1.sonum like'%").append(whereObject.getString("condition")).append("%' ");
  209. where.append("or t5.agentnum like'%").append(whereObject.getString("condition")).append("%' ");
  210. where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
  211. where.append(")");
  212. }
  213. //状态
  214. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  215. where.append(" and(");
  216. where.append("t1.status like'%").append(whereObject.getString("status")).append("%' ");
  217. where.append(")");
  218. }
  219. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  220. where.append(" and t1.billdate >='").append(whereObject.getString("begindate")).append("' ");
  221. }
  222. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  223. where.append(" and t1.billdate <='").append(whereObject.getString("enddate")).append("' ");
  224. }
  225. }
  226. //是否管理端
  227. Long isManage = content.getLongValue("isManage", 2L);
  228. //经销商
  229. if (isManage == 1 && (usertype == 21 || usertype == 22)) {
  230. where.append(" and t1.sys_enterpriseid = " + sys_enterpriseid + " ");
  231. }
  232. //业务员
  233. if (isManage == 0 && usertype == 1) {
  234. ArrayList<Long> sys_enterpriseids = new ArrayList<>();
  235. sys_enterpriseids.addAll(Hr.getAgents(this, hrid));
  236. sys_enterpriseids.addAll(Hr.getCustomers(this, hrid));
  237. String sql = " and t1.sys_enterpriseid IN " + sys_enterpriseids;
  238. sql = sql.replace("[", "(").replace("]", ")");
  239. where.append(sql);
  240. }
  241. boolean isExport = content.getBooleanValue("isExport");
  242. SQLFactory sqlFactory = new SQLFactory(this, "工具借用单列表", pageSize, pageNumber, pageSorting);
  243. if (isExport) {
  244. sqlFactory = new SQLFactory(this, "工具借用单列表");
  245. }
  246. sqlFactory.addParameter("siteid", siteid);
  247. sqlFactory.addParameter_SQL("where", where);
  248. String sql = sqlFactory.getSQL();
  249. Rows rows = dbConnect.runSqlQuery(sql);
  250. //查询数据:amount,defaultamount,qty
  251. ArrayList<Long> sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>());
  252. sqlFactory = new SQLFactory(this, "查询工具数据");
  253. sqlFactory.addParameter("siteid", siteid);
  254. sqlFactory.addParameter_in("sa_orderid", sa_orderids);
  255. RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid");
  256. for (Row row : rows) {
  257. Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows());
  258. if (dataRows.isNotEmpty()) {
  259. row.putAll(dataRows.get(0));
  260. } else {
  261. row.put("amount", 0);
  262. row.put("qty", 0);
  263. }
  264. }
  265. // if (isExport) {
  266. // Rows uploadRows = uploadExcelToObs("order", "工具借用单列表", rows, new HashMap<>());
  267. // return getSucReturnObject().setData(uploadRows).toString();
  268. // }
  269. return getSucReturnObject().setData(rows).toString();
  270. }
  271. @API(title = "工具借用单详情", apiversion = R.ID20230114140402.v1.class)
  272. @CACHEING
  273. public String selectDetail() throws YosException {
  274. Long sa_orderid = content.getLong("sa_orderid");
  275. //查询详情
  276. SQLFactory sqlFactory = new SQLFactory(this, "工具借用单详情");
  277. sqlFactory.addParameter("sa_orderid", sa_orderid);
  278. sqlFactory.addParameter("siteid", siteid);
  279. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  280. //查询数据
  281. ArrayList<Long> sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>());
  282. sqlFactory = new SQLFactory(this, "查询工具数据");
  283. sqlFactory.addParameter("siteid", siteid);
  284. sqlFactory.addParameter_in("sa_orderid", sa_orderids);
  285. RowsMap dataRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sa_orderid");
  286. ArrayList<Long> sys_enterpriseids = rows.toArrayList("pay_enterpriseid", new ArrayList<>());
  287. //查询开票信息
  288. sqlFactory = new SQLFactory(this, "查询经销商默认开票信息");
  289. sqlFactory.addParameter("siteid", siteid);
  290. sqlFactory.addParameter_in("sys_enterpriseid", sys_enterpriseids);
  291. RowsMap financeRowsMap = dbConnect.runSqlQuery(sqlFactory).toRowsMap("sys_enterpriseid");
  292. for (Row row : rows) {
  293. row.put("pay_finance", financeRowsMap.getOrDefault(row.getString("sys_enterpriseid"), new Rows()));
  294. Rows dataRows = dataRowsMap.getOrDefault(row.getString("sa_orderid"), new Rows());
  295. if (dataRows.isNotEmpty()) {
  296. row.putAll(dataRows.get(0));
  297. } else {
  298. row.put("amount", 0);
  299. row.put("qty", 0);
  300. }
  301. }
  302. Row row = rows.isNotEmpty() ? rows.get(0) : new Row();
  303. Long pay_enterpriseid = row.getLong("pay_enterpriseid");
  304. Long sa_accountclassid = row.getLong("sa_accountclassid");
  305. //开票信息
  306. sqlFactory = new SQLFactory(this, "工具_开票信息");
  307. sqlFactory.addParameter("siteid", siteid);
  308. sqlFactory.addParameter("sa_orderid", sa_orderid);
  309. Rows financeRows = dbConnect.runSqlQuery(sqlFactory);
  310. row.put("finance", financeRows.isNotEmpty() ? financeRows.get(0) : new Row());
  311. //物流
  312. // sqlFactory = new SQLFactory(this, "工具-查询物流信息");
  313. // sqlFactory.addParameter("siteid", siteid);
  314. // sqlFactory.addParameter("sa_orderid", sa_orderid);
  315. // Rows logiscompRows = dbConnect.runSqlQuery(sqlFactory);
  316. // row.put("logiscomp", logiscompRows.isNotEmpty() ? logiscompRows.get(0) : new Row());
  317. //营销账户类型
  318. sqlFactory = new SQLFactory(this, "工具-查询营销账号");
  319. sqlFactory.addParameter("siteid", siteid);
  320. sqlFactory.addParameter("sa_orderid", sa_orderid);
  321. sqlFactory.addParameter("pay_enterpriseid", pay_enterpriseid);
  322. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  323. String sql = sqlFactory.getSQL();
  324. Rows accountclassRows = dbConnect.runSqlQuery(sql);
  325. if (accountclassRows.isNotEmpty()) {
  326. accountclassRows.get(0).put("amount", row.getBigDecimal("amount"));
  327. accountclassRows.get(0).put("rebate_used", row.getBigDecimal("rebate_used"));
  328. accountclassRows.get(0).put("rebate_userate", row.getBigDecimal("rebate_userate"));
  329. accountclassRows.get(0).put("rebate_amount", row.getBigDecimal("amount").multiply(row.getBigDecimal("rebate_userate")));
  330. }
  331. row.put("accountclass", accountclassRows.isNotEmpty() ? accountclassRows.get(0) : new Row());
  332. //收货信息
  333. row.put("contacts", beans.order.Order.getContactsRow(this, row.getLong("rec_contactsid")));
  334. 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 + "'");
  335. if (deliveryRows.get(0).getLong("count") > 0) {
  336. row.put("isdelivery", 1);
  337. } else {
  338. row.put("isdelivery", 0);
  339. }
  340. Rows contractrow = dbConnect.runSqlQuery("SELECT * from sa_contract WHERE sa_contractid in (SELECT sa_contractid FROM sa_order WHERE sa_orderid=" + sa_orderid + ")");
  341. if (contractrow.isNotEmpty()) {
  342. row.put("contract", contractrow.get(0));
  343. } else {
  344. row.put("contract", new Row());
  345. }
  346. row.put("rebatebalance", Accountbalance.getRebateBalance(this, pay_enterpriseid));
  347. return getSucReturnObject().setData(row).toString();
  348. }
  349. @API(title = "删除", apiversion = R.ID20230116100002.v1.class)
  350. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  351. public String delete() throws YosException {
  352. JSONArray sa_orderids = content.getJSONArray("sa_orderids");
  353. if (sa_orderids.size() <= 0) {
  354. return getErrReturnObject().setErrMsg("请选择要执行删除操作的数据。").toString();
  355. }
  356. String sql = "SELECT 1 from sa_order WHERE sa_orderid in " + sa_orderids + " and `status` !='新建' and siteid = '" + siteid + "'";
  357. sql = sql.replace("[", "(").replace("]", ")");
  358. if (dbConnect.runSqlQuery(sql).isNotEmpty()) {
  359. return getErrReturnObject().setErrMsg("存在非新建状态数据,无法执行删除操作。").toString();
  360. }
  361. ArrayList<String> sqlList = new ArrayList<>();
  362. SQLFactory sqlFactory = new SQLFactory(this, "删除");
  363. sqlFactory.addParameter("siteid", siteid);
  364. sqlFactory.addParameter_in("sa_orderid", sa_orderids.toArray());
  365. sqlList.add(sqlFactory.getSQL());
  366. //订单删除原因
  367. DataExtend.createDeleteReasonSql(this, "sa_order", sa_orderids.toJavaList(Long.class), content.getStringValue("deletereason"));
  368. //操作记录
  369. for (Object obj : sa_orderids) {
  370. Long sa_orderid = Long.valueOf(obj.toString());
  371. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "删除", "工具借用单删除").getSQL());
  372. }
  373. dbConnect.runSqlUpdate(sqlList);
  374. return getSucReturnObject().toString();
  375. }
  376. @API(title = "交期回复", apiversion = R.ID20230114152602.v1.class)
  377. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  378. public String delivery() throws YosException {
  379. Long sa_orderid = content.getLong("sa_orderid");
  380. Rows rows = getOrderRows(this, sa_orderid);
  381. if (rows.isEmpty()) {
  382. return getErrReturnObject().setErrMsg("数据不存在").toString();
  383. }
  384. // if (!rows.get(0).getString("status").equals("新建")) {
  385. // return getErrReturnObject().setErrMsg("非新建状态无法交期回复").toString();
  386. // }
  387. ArrayList<String> sqlList = new ArrayList<>();
  388. SQLFactory sqlFactory = new SQLFactory(this, "交期回复");
  389. sqlFactory.addParameter("siteid", siteid);
  390. sqlFactory.addParameter("userid", userid);
  391. sqlFactory.addParameter("username", username);
  392. sqlFactory.addParameter("sa_orderid", sa_orderid);
  393. sqlList.add(sqlFactory.getSQL());
  394. //操作记录
  395. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期回复", "工具借用单:交期回复" + sa_orderid).getSQL());
  396. dbConnect.runSqlUpdate(sqlList);
  397. return getSucReturnObject().toString();
  398. }
  399. @API(title = "确认交期,操作交期待确认的", apiversion = R.ID20230129154102.v1.class)
  400. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  401. public String confirmDeliveryDate() throws YosException {
  402. Long sa_orderid = content.getLong("sa_orderid");
  403. Rows rows = getOrderRows(this, sa_orderid);
  404. if (rows.isEmpty()) {
  405. return getErrReturnObject().setErrMsg("订单不存在").toString();
  406. }
  407. //交期待确认
  408. String status = rows.get(0).getString("status");
  409. if (!status.equals("交期待确认")) {
  410. return getErrReturnObject().setErrMsg("只能操作交期待确认的订单").toString();
  411. }
  412. ArrayList<String> sqlList = new ArrayList<>();
  413. SQLFactory sqlFactory = new SQLFactory(this, "确认交期");
  414. sqlFactory.addParameter("siteid", siteid);
  415. sqlFactory.addParameter("userid", userid);
  416. sqlFactory.addParameter("username", username);
  417. sqlFactory.addParameter("sa_orderid", sa_orderid);
  418. sqlList.add(sqlFactory.getSQL());
  419. //操作记录
  420. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "交期确认", "工具借用单交期确认").getSQL());
  421. dbConnect.runSqlUpdate(sqlList);
  422. return getSucReturnObject().toString();
  423. }
  424. @API(title = "撤回交期回复", apiversion = R.ID20230114152702.v1.class)
  425. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  426. public String unDelivery() throws YosException {
  427. Long sa_orderid = content.getLong("sa_orderid");
  428. Rows rows = getOrderRows(this, sa_orderid);
  429. ArrayList<String> sqlList = new ArrayList<>();
  430. if (rows.isEmpty()) {
  431. return getErrReturnObject().setErrMsg("数据不存在").toString();
  432. }
  433. if (!rows.get(0).getString("status").equals("交期回复")) {
  434. return getErrReturnObject().setErrMsg("非交期回复状态无法撤回").toString();
  435. }
  436. SQLFactory sqlFactory = new SQLFactory(this, "撤回交期回复");
  437. sqlFactory.addParameter("siteid", siteid);
  438. sqlFactory.addParameter("userid", userid);
  439. sqlFactory.addParameter("username", username);
  440. sqlFactory.addParameter("sa_orderid", sa_orderid);
  441. sqlList.add(sqlFactory.getSQL());
  442. //操作记录
  443. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "撤回交期回复", "工具借用单:撤回交期回复" + sa_orderid).getSQL());
  444. dbConnect.runSqlUpdate(sqlList);
  445. return getSucReturnObject().toString();
  446. }
  447. @API(title = "提交", apiversion = R.ID20230114160002.v1.class)
  448. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  449. public String submit() throws YosException {
  450. Long sa_orderid = content.getLong("sa_orderid");
  451. Rows rows = getOrderRows(this, sa_orderid);
  452. ArrayList<String> sqlList = new ArrayList<>();
  453. if (rows.isEmpty()) {
  454. return getErrReturnObject().setErrMsg("数据不存在").toString();
  455. }
  456. Row row = rows.get(0);
  457. BigDecimal amount = getAmount(sa_orderid);
  458. Rows freefreightamountRows = dbConnect.runSqlQuery("SELECT ifnull(freefreightamount,0) freefreightamount from sys_enterprise WHERE sys_enterpriseid= 1 and siteid ='yostest2'");
  459. BigDecimal freefreightamount = freefreightamountRows.get(0).getBigDecimal("freefreightamount");
  460. String freightstatus = row.getString("freightstatus");
  461. if (freightstatus.isEmpty()) {
  462. if (freefreightamount.compareTo(BigDecimal.ZERO) == -1) {
  463. freightstatus = "到付";
  464. }
  465. if (freefreightamount.compareTo(BigDecimal.ZERO) == 0) {
  466. freightstatus = "预付";
  467. }
  468. if (freefreightamount.compareTo(BigDecimal.ZERO) == 1) {
  469. if (amount.compareTo(freefreightamount) == 1) {
  470. freightstatus = "预付";
  471. } else {
  472. freightstatus = "到付";
  473. }
  474. }
  475. }
  476. SQLFactory sqlFactory = new SQLFactory(this, "提交");
  477. sqlFactory.addParameter("siteid", siteid);
  478. sqlFactory.addParameter("userid", userid);
  479. sqlFactory.addParameter("username", username);
  480. sqlFactory.addParameter("freightstatus", freightstatus);
  481. sqlFactory.addParameter("sa_orderid", sa_orderid);
  482. sqlList.add(sqlFactory.getSQL());
  483. //操作记录
  484. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "提交", "工具借用单:提交" + sa_orderid).getSQL());
  485. dbConnect.runSqlUpdate(sqlList);
  486. return getSucReturnObject().toString();
  487. }
  488. @API(title = "审核", apiversion = R.ID20230114161402.v1.class)
  489. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  490. public String check() throws YosException {
  491. Long sa_orderid = content.getLong("sa_orderid");
  492. String reviewtype = content.getString("reviewtype");
  493. Rows rows = getOrderRows(this, sa_orderid);
  494. ArrayList<String> sqlList = new ArrayList<>();
  495. if (rows.isEmpty()) {
  496. return getErrReturnObject().setErrMsg("数据不存在").toString();
  497. }
  498. if (!rows.get(0).getString("status").equals("提交") && !rows.get(0).getString("status").equals("交期确认")) {
  499. return getErrReturnObject().setErrMsg("非提交,交期确认状态无法审核").toString();
  500. }
  501. Row row = rows.get(0);
  502. Long sa_accountclassid = row.getLong("sa_accountclassid");
  503. if (sa_accountclassid <= 0) {
  504. return getErrReturnObject().setErrMsg("请选择支付账号").toString();
  505. }
  506. //验证结算企业
  507. Long pay_enterpriseid = row.getLong("pay_enterpriseid");
  508. if (pay_enterpriseid <= 0) {
  509. return getErrReturnObject().setErrMsg("请选择结算企业").toString();
  510. }
  511. String sonum = row.getString("sonum");
  512. SQLFactory sqlFactory = new SQLFactory(this, "审核");
  513. sqlFactory.addParameter("siteid", siteid);
  514. sqlFactory.addParameter("userid", userid);
  515. sqlFactory.addParameter("username", username);
  516. sqlFactory.addParameter("reviewtype", reviewtype);
  517. sqlFactory.addParameter("sa_orderid", sa_orderid);
  518. sqlList.add(sqlFactory.getSQL());
  519. BigDecimal amount = getAmount(sa_orderid);
  520. CashbillEntity entity = getCashbillEntity(amount, sa_orderid, "押金收入凭证", "由" + sonum + "工具借用单审核时自动产生");
  521. sqlList.addAll(Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true,false));
  522. //操作记录
  523. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "审核", "工具借用单:审核" + sa_orderid).getSQL());
  524. dbConnect.runSqlUpdate(sqlList);
  525. if (Parameter.get("system.erp_dockswitch").equalsIgnoreCase("true")) {
  526. UploadDataToERP uploadDataToERP = new UploadDataToERP(this, sa_orderid, "");
  527. boolean issuccess = uploadDataToERP.upload();
  528. if (!issuccess) {
  529. unCheck();
  530. return getErrReturnObject().setErrMsg("上传ERP失败,当前单据将自动反审核,请检查!").toString();
  531. } else {
  532. Long sys_enterpriseid = row.getLong("sys_enterpriseid");
  533. sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid);
  534. sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid);
  535. }
  536. } else {
  537. Long sys_enterpriseid = row.getLong("sys_enterpriseid");
  538. sendMsg("工具借用单审核", sa_orderid, sys_enterpriseid);
  539. sendMsg("生成押金收入凭证", sa_orderid, sys_enterpriseid);
  540. }
  541. return getSucReturnObject().toString();
  542. }
  543. public void sendMsg(String content, Long sa_orderid, Long sys_enterpriseid) throws YosException {
  544. ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid).toArrayList("userid", new ArrayList<>());
  545. Remind remind = new Remind(this);
  546. remind.setTitle("工具借用单");
  547. remind.setContent(content);
  548. remind.setType("应用");
  549. remind.setObjectid(sa_orderid);
  550. remind.setObjectname("sa_order");
  551. remind.setTouserid(userList);
  552. remind.createSys_message();
  553. }
  554. @API(title = "反审核", apiversion = R.ID20230114161502.v1.class)
  555. @CACHEING_CLEAN(apiClass = {ToolBill.class, ToolBilItem.class})
  556. public String unCheck() throws YosException {
  557. Long sa_orderid = content.getLong("sa_orderid");
  558. Rows rows = getOrderRows(this, sa_orderid);
  559. ArrayList<String> sqlList = new ArrayList<>();
  560. if (rows.isEmpty()) {
  561. return getErrReturnObject().setErrMsg("数据不存在").toString();
  562. }
  563. if (!rows.get(0).getString("status").equals("审核")) {
  564. return getErrReturnObject().setErrMsg("非审核状态无法反审核").toString();
  565. }
  566. Row row = rows.get(0);
  567. Long sa_accountclassid = row.getLong("sa_accountclassid");
  568. if (sa_accountclassid <= 0) {
  569. return getErrReturnObject().setErrMsg("请选择支付账号").toString();
  570. }
  571. //验证结算企业
  572. Long pay_enterpriseid = row.getLong("pay_enterpriseid");
  573. if (pay_enterpriseid <= 0) {
  574. return getErrReturnObject().setErrMsg("请选择结算企业").toString();
  575. }
  576. String sonum = row.getString("sonum");
  577. SQLFactory sqlFactory = new SQLFactory(this, "反审核");
  578. sqlFactory.addParameter("siteid", siteid);
  579. sqlFactory.addParameter("userid", userid);
  580. sqlFactory.addParameter("username", username);
  581. sqlFactory.addParameter("sa_orderid", sa_orderid);
  582. sqlList.add(sqlFactory.getSQL());
  583. BigDecimal amount = getAmount(sa_orderid);
  584. CashbillEntity entity = getCashbillEntity(amount.negate(), sa_orderid, "押金收入凭证", "由" + sonum + "工具借用反单审核时自动产生");
  585. sqlList.addAll(Accountbalance.createCashbillIncome(this, pay_enterpriseid, sa_accountclassid, entity, true,false));
  586. //操作记录
  587. sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反审核", "工具借用单:反审核" + sa_orderid).getSQL());
  588. dbConnect.runSqlUpdate(sqlList);
  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. }