cashbill.java 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068
  1. package restcontroller.sale.cashbill;
  2. import beans.clear.ClearData;
  3. import beans.data.BatchDeleteErr;
  4. import beans.datacontrllog.DataContrlLog;
  5. import beans.datateam.DataTeam;
  6. import com.alibaba.fastjson.JSONArray;
  7. import com.alibaba.fastjson.JSONObject;
  8. import com.sun.xml.internal.xsom.impl.Ref;
  9. import common.Controller;
  10. import common.YosException;
  11. import common.annotation.API;
  12. import common.annotation.CACHEING;
  13. import common.annotation.CACHEING_CLEAN;
  14. import common.annotation.cm;
  15. import common.data.*;
  16. import common.data.Row;
  17. import org.apache.commons.lang.StringUtils;
  18. import org.apache.poi.ss.usermodel.*;
  19. import org.apache.poi.xssf.usermodel.*;
  20. import restcontroller.R;
  21. import restcontroller.system.attachment.Attachment;
  22. import java.io.IOException;
  23. import java.math.BigDecimal;
  24. import java.text.SimpleDateFormat;
  25. import java.util.ArrayList;
  26. import java.util.Arrays;
  27. import java.util.HashMap;
  28. import java.util.Map;
  29. import static restcontroller.webmanage.saletool.orderclue.orderclue.isBigDecimal;
  30. public class cashbill extends Controller {
  31. public cashbill(JSONObject arg0) throws YosException {
  32. super(arg0);
  33. // TODO Auto-generated constructor stub
  34. }
  35. /**
  36. * 下载凭证导入单模板
  37. *
  38. * @return
  39. */
  40. @API(title = "下载凭证导入单模板", apiversion = R.ID20230506162603.v1.class)
  41. public String downloadCashbillExcel() throws YosException {
  42. ExcelFactory excelFactory = new ExcelFactory("ImportTemplateForCashbill");
  43. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
  44. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  45. CellStyle style = xssfFWorkbook.createCellStyle();
  46. // 设置为文本格式,防止身份证号变成科学计数法
  47. DataFormat format = xssfFWorkbook.createDataFormat();
  48. style.setDataFormat(format.getFormat("@"));
  49. // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
  50. for (int i = 0; i <= 10; i++) {
  51. sheet.setDefaultColumnStyle(i, style);
  52. }
  53. if (content.getString("type").equals("收入")) {
  54. IncomeExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  55. XSSFCellStyle titleCellStyle1 = IncomeExportExcel.createTitleCellStyle1(xssfFWorkbook);
  56. XSSFCellStyle titleCellStyle2 = IncomeExportExcel.createTitleCellStyle2(xssfFWorkbook);
  57. XSSFCellStyle titleCellStyle3 = IncomeExportExcel.createBodyCellStyle(xssfFWorkbook);
  58. XSSFCellStyle titleCellStyle4 = IncomeExportExcel.createTitleCellStyle3(xssfFWorkbook);
  59. IncomeExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, titleCellStyle4,
  60. xssfFWorkbook);// 写入标题
  61. } else if (content.getString("type").equals("支出")) {
  62. PayExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  63. XSSFCellStyle titleCellStyle1 = PayExportExcel.createTitleCellStyle1(xssfFWorkbook);
  64. XSSFCellStyle titleCellStyle2 = PayExportExcel.createTitleCellStyle2(xssfFWorkbook);
  65. XSSFCellStyle titleCellStyle3 = PayExportExcel.createBodyCellStyle(xssfFWorkbook);
  66. XSSFCellStyle titleCellStyle4 = PayExportExcel.createTitleCellStyle3(xssfFWorkbook);
  67. PayExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, titleCellStyle4,
  68. xssfFWorkbook);// 写入标题
  69. } else {
  70. return getErrReturnObject().setErrMsg("凭证类型不匹配,无法下载导入文件").toString();
  71. }
  72. Rows aa = uploadExcelToObs(excelFactory);
  73. String url = "";
  74. if (!aa.isEmpty()) {
  75. url = aa.get(0).getString("url");
  76. }
  77. return getSucReturnObject().setData(url).toString();
  78. }
  79. /**
  80. * 导入凭证
  81. *
  82. * @return
  83. */
  84. @API(title = "导入凭证", apiversion = R.ID20230506162703.v1.class)
  85. @CACHEING_CLEAN(apiClass = cashbill.class)
  86. public String uploadCashbillByExcel() throws YosException {
  87. ExcelFactory e;
  88. try {
  89. // 华为云
  90. e = getPostExcelFactory(content.getLong("attachmentid"));
  91. // 本地
  92. //e = getPostExcelFactory();
  93. // Rows keyRow = dbConnect.runSqlQuery("select fagentnum,faddress from tagents
  94. // where 1=2");
  95. // Rows row1 = e.getSheetRows(1, keyRow, 1);
  96. ArrayList<String> keys = new ArrayList<>();
  97. ArrayList<String> sqllist = new ArrayList<>();
  98. keys.add("agentnum");
  99. keys.add("accountname");
  100. keys.add("amount");
  101. keys.add("type");
  102. keys.add("typemx");
  103. keys.add("remarks");
  104. Rows accountclassRows = dbConnect.runSqlQuery("select sa_accountclassid,accountname from sa_accountclass where siteid='" + siteid + "' and isused=1");
  105. RowsMap accountclassRowsMap = accountclassRows.toRowsMap("accountname");
  106. Rows agentRows = dbConnect.runSqlQuery("select agentnum,sys_enterpriseid from sa_agents where siteid='" + siteid + "'");
  107. RowsMap agentRowsMap = agentRows.toRowsMap("agentnum");
  108. if (!(content.getString("type") + "凭证导入")
  109. .equals(((String) getCellFormatValue(e.getSheet(0).getRow(0).getCell(0))).replace(" ", ""))) {
  110. return getErrReturnObject().setErrMsg("导入失败,不符合" + content.getString("type") + "凭证导入要求").toString();
  111. }
  112. Rows rows = e.getSheetRows(0, keys, 3);
  113. int a = 1;
  114. int i = 0;
  115. // String msg = "";
  116. boolean iserr = false;
  117. Rows rowserr = new Rows();
  118. Rows rowssuc = new Rows();
  119. for (Row row : rows) {
  120. String msg = "";
  121. if (StringUtils.isEmpty(row.getString("agentnum"))) {
  122. iserr = true;
  123. msg = msg + "【经销商编码为空】";
  124. }
  125. if (StringUtils.isEmpty(row.getString("accountname"))) {
  126. iserr = true;
  127. msg = msg + "【账户名称为空】";
  128. }
  129. if (!isBigDecimal(row.getString("amount"))) {
  130. iserr = true;
  131. msg = msg + "【金额错误:" + row.getString("amount") + "】";
  132. }
  133. if (StringUtils.isEmpty(row.getString("type"))) {
  134. iserr = true;
  135. msg = msg + "【分类为空】";
  136. }
  137. if (!agentRowsMap.containsKey(row.getString("agentnum"))) {
  138. iserr = true;
  139. msg = msg + "【该经销商编码找不到匹配的经销商】";
  140. } else {
  141. if (agentRowsMap.get(row.getString("agentnum")).isEmpty()) {
  142. iserr = true;
  143. msg = msg + "【该经销商编码找不到匹配的经销商】";
  144. }
  145. }
  146. if (!accountclassRowsMap.containsKey(row.getString("accountname"))) {
  147. iserr = true;
  148. msg = msg + "【该账户名称找不到匹配的账户】";
  149. } else {
  150. if (accountclassRowsMap.get(row.getString("accountname")).isEmpty()) {
  151. iserr = true;
  152. msg = msg + "【该账户名称找不到匹配的账户】";
  153. }
  154. }
  155. if (iserr) {
  156. row.put("msg", "错误信息:" + msg);
  157. rowserr.add(row);
  158. } else {
  159. rowssuc.add(row);
  160. }
  161. // if (!msg.equals("111")) {
  162. // XSSFWorkbook xssfFWorkbook = e.getXssfWorkbook();
  163. // XSSFCellStyle cellStyle = xssfFWorkbook.createCellStyle();
  164. //
  165. // XSSFFont font = xssfFWorkbook.createFont();
  166. //
  167. // font.setColor((short) 0xa);
  168. // font.setFontHeightInPoints((short) 8);
  169. // font.setBold(true);
  170. // cellStyle.setFont(font);
  171. // datarow.createCell(8).setCellValue("错误信息:" + msg);
  172. // datarow.getCell(8).setCellStyle(cellStyle);
  173. //
  174. // }
  175. }
  176. long[] sa_cashbillid = createTableID("sa_cashbill",
  177. rowssuc.size());
  178. if (!rowssuc.isEmpty()) {
  179. for (Row row : rowssuc) {
  180. SQLFactory sqlFactoryupload = new SQLFactory(this, "收支凭证新增");
  181. sqlFactoryupload.addParameter("sa_cashbillid", sa_cashbillid[i]);
  182. sqlFactoryupload.addParameter("billno", createBillCode("cashbill"));
  183. if (agentRowsMap.containsKey(row.getString("agentnum"))) {
  184. sqlFactoryupload.addParameter("sys_enterpriseid", agentRowsMap.get(row.getString("agentnum")).get(0).getLong("sys_enterpriseid"));
  185. } else {
  186. continue;
  187. }
  188. if (accountclassRowsMap.containsKey(row.getString("accountname"))) {
  189. sqlFactoryupload.addParameter("sa_accountclassid", accountclassRowsMap.get(row.getString("accountname")).get(0).getLong("sa_accountclassid"));
  190. } else {
  191. continue;
  192. }
  193. if (content.getString("type").equals("收入")) {
  194. sqlFactoryupload.addParameter("type", 1);
  195. } else {
  196. sqlFactoryupload.addParameter("type", 0);
  197. }
  198. sqlFactoryupload.addParameter("siteid", siteid);
  199. sqlFactoryupload.addParameter("remarks", row.getString("remarks"));
  200. sqlFactoryupload.addParameter("amount", row.getDouble("amount"));
  201. sqlFactoryupload.addParameter("subclass", row.getString("typemx"));
  202. sqlFactoryupload.addParameter("class", row.getString("type"));
  203. sqlFactoryupload.addParameter("userid", userid);
  204. sqlFactoryupload.addParameter("username", username);
  205. sqlFactoryupload.addParameter("ownertable", "");
  206. sqlFactoryupload.addParameter("ownerid", 0);
  207. sqlFactoryupload.addParameter("source", "");
  208. sqlFactoryupload.addParameter("sourcenote", "");
  209. sqllist.add(sqlFactoryupload.getSQL());
  210. i++;
  211. }
  212. }
  213. System.out.println(sqllist.size());
  214. dbConnect.runSqlUpdate(sqllist);
  215. if (iserr) {
  216. ExcelFactory excelFactory = new ExcelFactory("sa_cashbillerr");
  217. HashMap<String, String> map = new HashMap<String, String>();
  218. map.put("agentnum", "经销商编码");
  219. map.put("accountname", "账户名称");
  220. map.put("amount", "金额");
  221. map.put("type", "分类");
  222. map.put("typemx", "分类明细");
  223. map.put("remarks", "备注");
  224. map.put("msg", "错误信息");
  225. ArrayList<String> colNameList = new ArrayList<String>();
  226. HashMap<String, Class> keytypemap = new HashMap<String, Class>();
  227. colNameList.add("agentnum");
  228. colNameList.add("accountname");
  229. colNameList.add("amount");
  230. colNameList.add("type");
  231. colNameList.add("typemx");
  232. colNameList.add("remarks");
  233. colNameList.add("msg");
  234. keytypemap.put("agentnum", String.class);
  235. keytypemap.put("accountname", String.class);
  236. keytypemap.put("amount", String.class);
  237. keytypemap.put("type", String.class);
  238. keytypemap.put("typemx", String.class);
  239. keytypemap.put("remarks", String.class);
  240. keytypemap.put("msg", String.class);
  241. rowserr.setFieldList(colNameList);
  242. rowserr.setFieldTypeMap(keytypemap);
  243. if (content.getString("type").equals("收入")) {
  244. addSheetIncome(excelFactory, "Sheet1", rowserr, map);
  245. } else {
  246. addSheetPay(excelFactory, "Sheet1", rowserr, map);
  247. }
  248. Rows aa = uploadExcelToObs(excelFactory);
  249. String url = "";
  250. if (!aa.isEmpty()) {
  251. url = aa.get(0).getString("url");
  252. }
  253. return getSucReturnObject().setData(url).toString();
  254. }
  255. } catch (Exception e1) {
  256. // TODO Auto-generated catch block
  257. e1.printStackTrace();
  258. return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
  259. }
  260. return getSucReturnObject().toString();
  261. }
  262. @API(title = "收支凭证新建更新", apiversion = R.ID20221009102803.v1.class,intervaltime = 200)
  263. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  264. public String insertormodify_creditbill() throws YosException {
  265. Long sa_cashbillid = content.getLong("sa_cashbillid");
  266. Long type = content.getLong("type"); //收支类型(1:收;0:支)
  267. Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  268. Long sa_accountclassid = content.getLong("sa_accountclassid");
  269. String billcode = createBillCode("cashbill");
  270. String subclass = content.getString("subclass");
  271. String class1 = content.getString("class");
  272. String period = content.getStringValue("period");
  273. if (StringUtils.isEmpty(period)) {
  274. if (type == 1) {
  275. return getErrReturnObject().setErrMsg("未填写归属日期").toString();
  276. } else if (type == 0 && subclass.equals("拨款")) {
  277. period = getDate_Str();
  278. }
  279. }
  280. //String billcode = "123456789";
  281. BigDecimal amount = content.getBigDecimal("amount");
  282. String remarks = content.getString("remarks");
  283. // String source = content.getString("source");
  284. // String sourcenote = content.getString("sourcenote");
  285. ArrayList<String> sqlList = new ArrayList<>();
  286. if (sa_cashbillid <= 0 || dbConnect
  287. .runSqlQuery("select sa_cashbillid from sa_cashbill where sa_cashbillid="
  288. + sa_cashbillid)
  289. .isEmpty()) {
  290. sa_cashbillid = createTableID("sa_cashbill");
  291. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证新增");
  292. sqlFactory.addParameter("billno", billcode);
  293. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  294. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  295. sqlFactory.addParameter("type", type);
  296. sqlFactory.addParameter("siteid", siteid);
  297. sqlFactory.addParameter("remarks", remarks);
  298. sqlFactory.addParameter("amount", amount);
  299. sqlFactory.addParameter("subclass", subclass);
  300. sqlFactory.addParameter("class", class1);
  301. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  302. sqlFactory.addParameter("userid", userid);
  303. sqlFactory.addParameter("username", username);
  304. sqlFactory.addParameter("ownertable", "");
  305. sqlFactory.addParameter("ownerid", 0);
  306. sqlFactory.addParameter("source", "");
  307. sqlFactory.addParameter("sourcenote", "");
  308. sqlFactory.addParameter("period", period);
  309. content.put("sa_cashbillid", sa_cashbillid);
  310. sqlList.add(sqlFactory.getSQL());
  311. } else {
  312. Rows rowscount = dbConnect.runSqlQuery(
  313. "select status from sa_cashbill where sa_cashbillid=" + sa_cashbillid);
  314. if (rowscount.isEmpty()) {
  315. return getErrReturnObject().setErrMsg("此收支凭证不存在").toString();
  316. } else {
  317. if (!rowscount.get(0).getString("status").equals("新建")) {
  318. return getErrReturnObject().setErrMsg("非新建状态的收支凭证无法更新").toString();
  319. }
  320. }
  321. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证更新");
  322. sqlFactory.addParameter("siteid", siteid);
  323. sqlFactory.addParameter("remarks", remarks);
  324. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  325. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  326. sqlFactory.addParameter("amount", amount);
  327. sqlFactory.addParameter("subclass", subclass);
  328. sqlFactory.addParameter("class", class1);
  329. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  330. sqlFactory.addParameter("userid", userid);
  331. sqlFactory.addParameter("username", username);
  332. sqlFactory.addParameter("source", "");
  333. sqlFactory.addParameter("sourcenote", "");
  334. sqlFactory.addParameter("period", period);
  335. sqlList.add(sqlFactory.getSQL());
  336. }
  337. dbConnect.runSqlUpdate(sqlList);
  338. return queryCashbillMain();
  339. }
  340. // @API(title = "合作企业档案列表",apiversion = R.ID20221008164103.v1.class)
  341. // @CACHEING
  342. // public String queryEnterpriseList() throws YosException {
  343. //
  344. // /*
  345. // * 过滤条件设置
  346. // */
  347. // String where = " 1=1 ";
  348. // if (content.containsKey("where")) {
  349. // JSONObject whereObject = content.getJSONObject("where");
  350. // if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  351. // where = where + " and(t1.enterprisename like'%" + whereObject.getString("condition")
  352. // + "%' or t1.phonenumber like '%" + whereObject.getString("condition") + "%')";
  353. // }
  354. // }
  355. // SQLFactory sqlFactory = new SQLFactory(this, "合作企业档案列表查询", pageSize, pageNumber, pageSorting);
  356. // sqlFactory.addParameter_SQL("where", where);
  357. // sqlFactory.addParameter("siteid", siteid);
  358. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  359. // return getSucReturnObject().setData(rows).toString();
  360. // }
  361. //
  362. // @API(title = "营销账户类别列表",apiversion = R.ID20221008164203.v1.class)
  363. // @CACHEING
  364. // public String queryAccountclassList() throws YosException {
  365. // long sys_enterpriseid=content.getLong("sys_enterpriseid");
  366. //
  367. // SQLFactory sqlFactory = new SQLFactory(this, "营销账户类别列表查询");
  368. // sqlFactory.addParameter("siteid", siteid);
  369. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  370. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  371. // return getSucReturnObject().setData(rows).toString();
  372. // }
  373. @API(title = "收入凭证列表", apiversion = R.ID20221009102903.v1.class)
  374. @CACHEING
  375. public String queryIncomeCashbillList() throws YosException {
  376. /*
  377. * 过滤条件设置
  378. */
  379. String where = " 1=1 and t1.type=1 ";
  380. if (content.containsKey("where")) {
  381. JSONObject whereObject = content.getJSONObject("where");
  382. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  383. where = where + " and(t2.enterprisename like'%" + whereObject.getString("condition")
  384. + "%' or t3.accountname like '%" + whereObject.getString("condition") + "%'"
  385. + " or t2.abbreviation like '%" + whereObject.getString("condition") + "%'"
  386. + " or t1.billno like '%" + whereObject.getString("condition") + "%'"
  387. + " or t1.remarks like '%" + whereObject.getString("condition") + "%'"
  388. + " or t4.agentnum like '%" + whereObject.getString("condition") + "%'"
  389. + " or t1.class like '%" + whereObject.getString("condition") + "%'"
  390. + " or t1.subclass like '%" + whereObject.getString("condition") + "%'"
  391. + " or t1.amount like '%" + whereObject.getString("condition") + "%'"
  392. + ")";
  393. }
  394. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  395. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  396. }
  397. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  398. where = where + " and t3.accountname ='" + whereObject.getString("accountname") + "' ";
  399. }
  400. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  401. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') >='" + whereObject.getString("begindate") + "'";
  402. }
  403. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  404. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') <='" + whereObject.getString("enddate") + "'";
  405. }
  406. if (whereObject.containsKey("billno") && !"".equals(whereObject.getString("billno"))) {
  407. where = where + " and t1.billno ='" + whereObject.getString("billno") + "'";
  408. }
  409. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  410. where = where + " and ifnull(t3.isrebate,0) ='" + whereObject.getLongValue("isrebate") + "'";
  411. }
  412. if (whereObject.containsKey("remarks") && !"".equals(whereObject.getString("remarks"))) {
  413. where = where+" and t1.remarks like'%"+whereObject.getString("remarks") + "%' ";
  414. }
  415. if (whereObject.containsKey("agentinfo") && !"".equals(whereObject.getString("agentinfo"))) {
  416. where = where + " and(t2.enterprisename like'%" + whereObject.getString("agentinfo") + "%'"
  417. + " or t4.agentnum like '%" + whereObject.getString("agentinfo") + "%'"
  418. + ")";
  419. }
  420. }
  421. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证列表查询", pageSize, pageNumber, pageSorting);
  422. sqlFactory.addParameter_SQL("where", where);
  423. sqlFactory.addParameter("siteid", siteid);
  424. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  425. ArrayList sa_cashbillids = rows.toArrayList("sa_cashbillid", new ArrayList<>());
  426. sa_cashbillids.add(0L);
  427. String sql = "select t1.sa_cashbillid,t2.billno from sa_cashbill t1 inner join sa_cashbill t2 on t1.siteid=t2.siteid and t1.ownerid=t2.sa_cashbillid and t1.ownertable='sa_cashbill' where t1.siteid='" + siteid + "' and t1.ownerid in " + sa_cashbillids;
  428. sql = sql.replace("[", "(").replace("]", ")");
  429. RowsMap offsettingRowsMap = dbConnect.runSqlQuery(sql).toRowsMap("sa_cashbillid");
  430. for (Row row : rows) {
  431. if (row.getString("ownertable").equals("sa_cashbill") && offsettingRowsMap.containsKey(row.getString("sa_cashbillid"))) {
  432. row.put("offsettingbillno", offsettingRowsMap.get(row.getString("sa_cashbillid")).get(0).getString("billno"));
  433. }
  434. row.put("amount", row.getBigDecimal("amount"));
  435. }
  436. return getSucReturnObject().setData(rows).toString();
  437. }
  438. @API(title = "支出收入凭证列表", apiversion = R.ID20221010102903.v1.class)
  439. @CACHEING
  440. public String queryPayCashbillList() throws YosException {
  441. /*
  442. * 过滤条件设置
  443. */
  444. String where = " 1=1 and t1.type=0 ";
  445. if (content.containsKey("where")) {
  446. JSONObject whereObject = content.getJSONObject("where");
  447. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  448. where = where + " and(t2.enterprisename like'%" + whereObject.getString("condition")
  449. + "%' or t3.accountname like '%" + whereObject.getString("condition") + "%'"
  450. + " or t2.abbreviation like '%" + whereObject.getString("condition") + "%'"
  451. + " or t1.billno like '%" + whereObject.getString("condition") + "%'"
  452. + " or t4.agentnum like '%" + whereObject.getString("condition") + "%'"
  453. + " or t1.remarks like '%" + whereObject.getString("condition") + "%'"
  454. + " or t1.class like '%" + whereObject.getString("condition") + "%'"
  455. + " or t1.subclass like '%" + whereObject.getString("condition") + "%'"
  456. + " or t1.amount like '%" + whereObject.getString("condition") + "%'"
  457. + ")";
  458. }
  459. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  460. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  461. }
  462. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  463. where = where + " and t3.accountname ='" + whereObject.getString("accountname") + "' ";
  464. }
  465. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  466. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') >='" + whereObject.getString("begindate") + "'";
  467. }
  468. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  469. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') <='" + whereObject.getString("enddate") + "'";
  470. }
  471. if (whereObject.containsKey("billno") && !"".equals(whereObject.getString("billno"))) {
  472. where = where + " and t1.billno ='" + whereObject.getString("billno") + "'";
  473. }
  474. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  475. where = where + " and ifnull(t3.isrebate,0) ='" + whereObject.getLongValue("isrebate") + "'";
  476. }
  477. if (whereObject.containsKey("remarks") && !"".equals(whereObject.getString("remarks"))) {
  478. where = where+" and t1.remarks like'%"+whereObject.getString("remarks") + "%' ";
  479. }
  480. if (whereObject.containsKey("agentinfo") && !"".equals(whereObject.getString("agentinfo"))) {
  481. where = where + " and(t2.enterprisename like'%" + whereObject.getString("agentinfo") + "%'"
  482. + " or t4.agentnum like '%" + whereObject.getString("agentinfo") + "%'"
  483. + ")";
  484. }
  485. }
  486. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证列表查询", pageSize, pageNumber, pageSorting);
  487. sqlFactory.addParameter_SQL("where", where);
  488. sqlFactory.addParameter("siteid", siteid);
  489. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  490. for (Row row : rows) {
  491. row.put("amount", row.getBigDecimal("amount"));
  492. }
  493. return getSucReturnObject().setData(rows).toString();
  494. }
  495. @API(title = "收支凭证详情", apiversion = R.ID20221009103003.v1.class)
  496. public String queryCashbillMain() throws YosException {
  497. Long sa_cashbillid = content.getLong("sa_cashbillid");
  498. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证详情查询");
  499. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  500. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  501. if (rows.size() > 0) {
  502. Rows offsetting = dbConnect.runSqlQuery("select billno from sa_cashbill where siteid='" + siteid + "' and '" + rows.get(0).getString("ownertable") + "'='sa_cashbill' and sa_cashbillid=" + rows.get(0).getLong("ownerid"));
  503. if (offsetting.isNotEmpty()) {
  504. rows.get(0).put("offsettingbillno", offsetting.get(0).getString("billno"));
  505. }
  506. rows.get(0).put("amount", rows.get(0).getBigDecimal("amount"));
  507. }
  508. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  509. }
  510. /**
  511. * 收支凭证审核
  512. *
  513. * @return
  514. */
  515. @API(title = "收支凭证审核", apiversion = R.ID20221009103103.v1.class)
  516. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20221008145903.v1.class, R.ID20221009160003.v1.class, R.ID20230111103403.v1.class})
  517. public String release() throws YosException {
  518. long sa_cashbillid = content.getLong("sa_cashbillid");
  519. String[] s = {"sa_cashbillid"};
  520. for (String s1 : s) {
  521. if (!content.containsKey(s1))
  522. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  523. }
  524. //List<String> list = sa_creditbillids.toJavaList(String.class);
  525. //String[] stringArray = list.toArray(new String[0]);
  526. //SQLFactory sqlFactoryquery = new SQLFactory(this, "信用额度调整单状态查询");
  527. //sqlFactoryquery.addParameter("siteid", siteid);
  528. //sqlFactoryquery.addParameter_in("sa_creditbillids", stringArray);
  529. Rows rows = dbConnect.runSqlQuery("select sa_cashbillid,sys_enterpriseid,sa_accountclassid,status,billno,amount,type,ownerid from sa_cashbill where sa_cashbillid ='" + sa_cashbillid + "' and siteid='" + siteid + "'");
  530. for (Row row : rows) {
  531. if (row.getString("status").equals("审核")) {
  532. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证已审核,无法再次审核")
  533. .toString();
  534. }
  535. if (!row.getString("status").equals("新建")) {
  536. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证为非新建状态,无法审核")
  537. .toString();
  538. }
  539. }
  540. ArrayList<String> sqlList = new ArrayList<>();
  541. BigDecimal balance = BigDecimal.ZERO; //当前账户余额
  542. if (!rows.isEmpty()) {
  543. long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
  544. long sa_accountclassid = rows.get(0).getLong("sa_accountclassid");
  545. long type = rows.get(0).getLong("type");
  546. Rows rowsaccountbalance = dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  547. if (type == 1) {
  548. Rows offsettingRows = dbConnect.runSqlQuery("select amount from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + rows.get(0).getLong("ownerid"));
  549. if (offsettingRows.isNotEmpty()) {
  550. sqlList.add("update sa_cashbill set writeoffamount=writeoffamount+" + offsettingRows.get(0).getBigDecimal("amount").abs() + " where siteid='" + siteid + "' and sa_cashbillid=" + rows.get(0).getLong("ownerid"));
  551. }
  552. if (rowsaccountbalance.isEmpty()) {
  553. balance = rows.get(0).getBigDecimal("amount");
  554. SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  555. sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  556. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  557. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  558. sqlFactory.addParameter("siteid", siteid);
  559. sqlFactory.addParameter("balance", rows.get(0).getBigDecimal("amount"));
  560. sqlFactory.addParameter("userid", userid);
  561. sqlFactory.addParameter("username", username);
  562. sqlList.add(sqlFactory.getSQL());
  563. } else {
  564. balance = rows.get(0).getBigDecimal("amount").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
  565. sqlList.add("update sa_accountbalance set balance='" + rows.get(0).getBigDecimal("amount").add(rowsaccountbalance.get(0).getBigDecimal("balance")) + "',changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  566. }
  567. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "审核", "收入凭证审核成功").getSQL());
  568. } else {
  569. if (rowsaccountbalance.isEmpty()) {
  570. // SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  571. // sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  572. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  573. // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  574. // sqlFactory.addParameter("siteid", siteid);
  575. // sqlFactory.addParameter("balance", -rows.get(0).getLong("amount"));
  576. // sqlFactory.addParameter("userid", userid);
  577. // sqlFactory.addParameter("username", username);
  578. // sqlList.add(sqlFactory.getSQL());
  579. return getErrReturnObject().setErrMsg("该营销账户不存在,支出凭证无法审核")
  580. .toString();
  581. } else {
  582. BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
  583. if (rows.get(0).getBigDecimal("amount").compareTo(canuseamount) == 1) {
  584. return getErrReturnObject().setErrMsg("该营销账户可用余额不足,支出凭证无法审核")
  585. .toString();
  586. }
  587. BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(rows.get(0).getBigDecimal("amount"));
  588. balance = newbalance;
  589. sqlList.add("update sa_accountbalance set balance='" + newbalance + "',changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  590. }
  591. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "审核", "支出凭证审核成功").getSQL());
  592. }
  593. }
  594. SQLFactory sqlFactoryupdate = new SQLFactory(this, "收支凭证审核");
  595. sqlFactoryupdate.addParameter("siteid", siteid);
  596. sqlFactoryupdate.addParameter("sa_cashbillid", sa_cashbillid);
  597. sqlFactoryupdate.addParameter("balance", balance);
  598. sqlFactoryupdate.addParameter("checkby", username);
  599. sqlList.add(sqlFactoryupdate.getSQL());
  600. dbConnect.runSqlUpdate(sqlList);
  601. return getSucReturnObject().toString();
  602. }
  603. /**
  604. * 收支凭证反审核
  605. *
  606. * @return
  607. */
  608. @API(title = "收入凭证反审核", apiversion = R.ID20230509085703.v1.class)
  609. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20221008145903.v1.class, R.ID20221009160003.v1.class, R.ID20230111103403.v1.class})
  610. public String unrelease() throws YosException {
  611. long sa_cashbillid = content.getLong("sa_cashbillid");
  612. //List<String> list = sa_creditbillids.toJavaList(String.class);
  613. //String[] stringArray = list.toArray(new String[0]);
  614. //SQLFactory sqlFactoryquery = new SQLFactory(this, "信用额度调整单状态查询");
  615. //sqlFactoryquery.addParameter("siteid", siteid);
  616. //sqlFactoryquery.addParameter_in("sa_creditbillids", stringArray);
  617. Rows rows = dbConnect.runSqlQuery("select sa_cashbillid,sys_enterpriseid,sa_accountclassid,status,billno,amount,type,ownerid from sa_cashbill where sa_cashbillid ='" + sa_cashbillid + "' and siteid='" + siteid + "'");
  618. for (Row row : rows) {
  619. if (!row.getString("status").equals("审核")) {
  620. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证为非审核状态,无法反审核")
  621. .toString();
  622. }
  623. if (rows.get(0).getLong("type") != 1) {
  624. return getErrReturnObject().setErrMsg("非收入凭证无法反审核")
  625. .toString();
  626. }
  627. }
  628. ArrayList<String> sqlList = new ArrayList<>();
  629. BigDecimal balance = BigDecimal.ZERO; //当前账户余额
  630. if (!rows.isEmpty()) {
  631. long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
  632. long sa_accountclassid = rows.get(0).getLong("sa_accountclassid");
  633. long type = rows.get(0).getLong("type");
  634. Rows rowsaccountbalance = dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  635. System.out.println("select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  636. if (type == 1) {
  637. Rows offsettingRows = dbConnect.runSqlQuery("select amount from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + rows.get(0).getLong("ownerid"));
  638. if (offsettingRows.isNotEmpty()) {
  639. sqlList.add("update sa_cashbill set writeoffamount=writeoffamount+" + offsettingRows.get(0).getBigDecimal("amount").abs() + " where siteid='" + siteid + "' and sa_cashbillid=" + rows.get(0).getLong("ownerid"));
  640. }
  641. if (rowsaccountbalance.isEmpty()) {
  642. return getErrReturnObject().setErrMsg("该营销账户不存在,收入凭证无法反审核")
  643. .toString();
  644. } else {
  645. BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
  646. if (rows.get(0).getBigDecimal("amount").compareTo(canuseamount) == 1) {
  647. return getErrReturnObject().setErrMsg("该营销账户可用余额不足,收入凭证无法反审核")
  648. .toString();
  649. }
  650. BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(rows.get(0).getBigDecimal("amount"));
  651. balance = newbalance;
  652. sqlList.add("update sa_accountbalance set balance='" + newbalance + "',changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  653. }
  654. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "反审核", "收入凭证反审核成功").getSQL());
  655. }
  656. }
  657. SQLFactory sqlFactoryupdate = new SQLFactory(this, "收支凭证反审核");
  658. sqlFactoryupdate.addParameter("siteid", siteid);
  659. sqlFactoryupdate.addParameter("sa_cashbillid", sa_cashbillid);
  660. sqlFactoryupdate.addParameter("balance", balance);
  661. sqlList.add(sqlFactoryupdate.getSQL());
  662. dbConnect.runSqlUpdate(sqlList);
  663. return getSucReturnObject().toString();
  664. }
  665. @API(title = "删除", apiversion = R.ID20221009103203.v1.class)
  666. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  667. public String delete() throws YosException {
  668. JSONArray sa_cashbillids = content.getJSONArray("sa_cashbillids");
  669. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_cashbillids.size());
  670. for (Object o : sa_cashbillids) {
  671. long sa_cashbillid = Long.parseLong(o.toString());
  672. Rows RowsStatus = dbConnect.runSqlQuery("select sa_cashbillid,status from sa_cashbill where siteid='"
  673. + siteid + "' and sa_cashbillid='" + sa_cashbillid + "'");
  674. if (RowsStatus.isNotEmpty()) {
  675. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  676. batchDeleteErr.addErr(sa_cashbillid, "非新建状态的凭证无法删除");
  677. continue;
  678. }
  679. }
  680. ArrayList<String> list = new ArrayList<>();
  681. SQLFactory deletesql = new SQLFactory("sql:delete from sa_cashbill where siteid='" + siteid
  682. + "' and sa_cashbillid=" + sa_cashbillid);
  683. list.add(deletesql.getSQL());
  684. dbConnect.runSqlUpdate(list);
  685. }
  686. ClearData.clearCashbill(this);
  687. return batchDeleteErr.getReturnObject().toString();
  688. }
  689. @API(title = "审核状态的收支凭证详情列表", apiversion = R.ID20221022161304.v1.class)
  690. @CACHEING
  691. public String query_cashnill_audit() throws YosException {
  692. /*
  693. 过滤条件
  694. */
  695. StringBuffer where = new StringBuffer(" 1=1 ");
  696. Long sa_accountclassid = content.getLong("sa_accountclassid");
  697. Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  698. if (content.containsKey("where")) {
  699. JSONObject whereObject = content.getJSONObject("where");
  700. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  701. where.append(" and (t1.billno like '%").append(whereObject.getString("condition")).append("%'");
  702. where.append(" or t3.enterprisename like '%").append(whereObject.getString("condition")).append("%'");
  703. where.append(" or t1.remarks like '%").append(whereObject.getString("condition")).append("%'");
  704. where.append(" or t1.source like '%").append(whereObject.getString("condition")).append("%')");
  705. }
  706. if (whereObject.containsKey("minAmount") && whereObject.getBigDecimal("minAmount").compareTo(new BigDecimal("0")) == 1) {
  707. BigDecimal minAmount = whereObject.getBigDecimal("minAmount");
  708. if (whereObject.containsKey("maxAmount") && whereObject.getBigDecimal("maxAmount").compareTo(new BigDecimal("0")) == 1) {
  709. BigDecimal maxAmount = whereObject.getBigDecimal("maxAmount");
  710. where.append(" and t1.amount between ").append(minAmount).append(" and ").append(maxAmount);
  711. } else {
  712. where.append(" and t1.amount > ").append(minAmount);
  713. }
  714. } else if (whereObject.containsKey("maxAmount") && whereObject.getBigDecimal("maxAmount").compareTo(new BigDecimal("0")) == 1) {
  715. BigDecimal maxAmount = whereObject.getBigDecimal("maxAmount");
  716. where.append(" and t1.amount < ").append(maxAmount);
  717. }
  718. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  719. where.append(" and t1.type = ").append(whereObject.getLong("type"));
  720. }
  721. }
  722. SQLFactory sqlFactory = new SQLFactory(this, "审核状态的收支凭证详情列表", pageSize, pageNumber, pageSorting);
  723. sqlFactory.addParameter_SQL("where", where);
  724. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  725. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  726. sqlFactory.addParameter("siteid", siteid);
  727. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  728. return getSucReturnObject().setData(rows).toString();
  729. }
  730. @API(title = "资金流水账列表查询", apiversion = R.ID20230111103403.v1.class)
  731. @CACHEING
  732. public String query_cashBill() throws YosException, IOException {
  733. /*
  734. 过滤条件
  735. */
  736. Long sa_accountclassid = content.getLong("sa_accountclassid");
  737. if (content.containsKey("sys_enterpriseid")) {
  738. sys_enterpriseid = content.getLong("sys_enterpriseid");
  739. }
  740. Map<String, Rows> map = new HashMap<String, Rows>();
  741. /**
  742. * 过滤条件设置
  743. */
  744. String where = " 1=1 ";
  745. if (content.containsKey("where")) {
  746. JSONObject whereObject = content.getJSONObject("where");
  747. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  748. where = where + " and (t1.billno like '%" + whereObject.getString("condition") + "%') ";
  749. }
  750. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  751. where = where + " and DATE_FORMAT(t1.checkdate,'%Y-%m-%d') >=DATE_FORMAT('" + whereObject.getString("begindate") + "','%Y-%m-%d')";
  752. }
  753. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  754. where = where + " and DATE_FORMAT(t1.checkdate,'%Y-%m-%d') <=DATE_FORMAT('" + whereObject.getString("enddate") + "','%Y-%m-%d')";
  755. }
  756. }
  757. /**
  758. * SQL资金流水账查询参数设置并查询
  759. */
  760. boolean isExport = content.getBooleanValue("isExport");
  761. SQLFactory factory = new SQLFactory(this, "资金流水账查询", pageSize, pageNumber, pageSorting);
  762. if (isExport) {
  763. factory = new SQLFactory(this, "资金流水账查询导出");
  764. }
  765. factory.addParameter("sys_enterpriseid", sys_enterpriseid);
  766. factory.addParameter("sa_accountclassid", sa_accountclassid);
  767. factory.addParameter("siteid", siteid);
  768. factory.addParameter_SQL("where", where);
  769. Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  770. if (isExport) {
  771. //去除不需要导出项
  772. rows.getFieldList().remove("sa_accountclassid");
  773. rows.getFieldList().remove("balance");
  774. rows.getFieldList().remove("createby");
  775. rows.getFieldList().remove("createdate");
  776. Rows uploadRows = uploadExcelToObs("cashBill", "资金流水账列表", rows, getTitleMap());
  777. return getSucReturnObject().setData(uploadRows).toString();
  778. }
  779. /**
  780. * SQL资金流水账汇总信息查询参数设置并查询
  781. */
  782. SQLFactory factoryhz = new SQLFactory(this, "资金流水账查询汇总");
  783. factoryhz.addParameter("sys_enterpriseid", sys_enterpriseid);
  784. factoryhz.addParameter("sa_accountclassid", sa_accountclassid);
  785. factoryhz.addParameter("siteid", siteid);
  786. factoryhz.addParameter_SQL("where", where);
  787. Rows rowszh = dbConnect.runSqlQuery(factoryhz.getSQL());
  788. if (!rows.isEmpty()) {
  789. rows.get(0).put("total", rowszh);
  790. }
  791. return getSucReturnObject().setData(rows).toString();
  792. }
  793. @API(title = "核销单关联查询", apiversion = R.ID20230224185904.v1.class)
  794. @CACHEING
  795. public String querywriteoffamount() throws YosException {
  796. Long sa_cashbillid = content.getLong("sa_cashbillid");
  797. SQLFactory sqlFactory = new SQLFactory(this, "核销单关联查询", pageSize, pageNumber, pageSorting);
  798. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  799. sqlFactory.addParameter("siteid", siteid);
  800. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  801. return getSucReturnObject().setData(rows).toString();
  802. }
  803. @API(title = "收入凭证对冲生成", apiversion = R.ID20230306102904.v1.class)
  804. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  805. public String cashbilloffsetting() throws YosException {
  806. Long sa_cashbillid = content.getLong("sa_cashbillid");
  807. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证详情查询");
  808. sqlFactory.addParameter("siteid", siteid);
  809. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  810. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  811. if (rows.isEmpty()) {
  812. return getErrReturnObject().setErrMsg("无效收入凭证").toString();
  813. }
  814. if (rows.get(0).getLong("type") == 0) {
  815. return getErrReturnObject().setErrMsg("支出凭证不能生成对冲").toString();
  816. }
  817. if (!rows.get(0).getString("status").equals("审核")) {
  818. return getErrReturnObject().setErrMsg("非审核状态不能生成对冲").toString();
  819. }
  820. if (rows.get(0).getBigDecimal("unwriteoffamount").compareTo(new BigDecimal(0)) < 1) {
  821. return getErrReturnObject().setErrMsg("未核销金额必须大于0").toString();
  822. }
  823. if (dbConnect.runSqlQuery("select 1 from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and sa_cashbillid=" + sa_cashbillid).isNotEmpty()) {
  824. return getErrReturnObject().setErrMsg("该凭证已生成对冲凭证").toString();
  825. }
  826. if (dbConnect.runSqlQuery("select 1 from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + sa_cashbillid).isNotEmpty()) {
  827. return getErrReturnObject().setErrMsg("该凭证已生成对冲凭证").toString();
  828. }
  829. Long offsettingCashbillid = createTableID("sa_cashbill");
  830. sqlFactory = new SQLFactory(this, "收支凭证新增");
  831. sqlFactory.addParameter("siteid", siteid);
  832. sqlFactory.addParameter("userid", userid);
  833. sqlFactory.addParameter("username", username);
  834. sqlFactory.addParameter("sa_cashbillid", offsettingCashbillid);
  835. sqlFactory.addParameter("billno", createBillCode("cashbill"));
  836. sqlFactory.addParameter("sys_enterpriseid", rows.get(0).getLong("sys_enterpriseid"));
  837. sqlFactory.addParameter("sa_accountclassid", rows.get(0).getLong("sa_accountclassid"));
  838. sqlFactory.addParameter("type", rows.get(0).getLong("type"));
  839. sqlFactory.addParameter("remarks", "凭证对冲");
  840. sqlFactory.addParameter("amount", rows.get(0).getBigDecimal("unwriteoffamount").negate());
  841. sqlFactory.addParameter("source", rows.get(0).getString("amount"));
  842. sqlFactory.addParameter("sourcenote", rows.get(0).getString("sourcenote"));
  843. sqlFactory.addParameter("subclass", rows.get(0).getString("subclass"));
  844. sqlFactory.addParameter("class", rows.get(0).getString("class"));
  845. sqlFactory.addParameter("ownertable", "sa_cashbill");
  846. sqlFactory.addParameter("ownerid", sa_cashbillid);
  847. dbConnect.runSqlUpdate(sqlFactory.getSQL());
  848. content.put("sa_cashbillid", offsettingCashbillid);
  849. return queryCashbillMain();
  850. }
  851. public Object getCellFormatValue(Cell cell) {
  852. Object cellValue = null;
  853. if (cell != null) {
  854. // 判断cell类型
  855. CellType cellType = cell.getCellType();
  856. switch (cellType) {
  857. case NUMERIC: {
  858. if (DateUtil.isCellDateFormatted(cell)) {
  859. short num = cell.getCellStyle().getDataFormat();
  860. String format = "YYYY-mm-dd";
  861. SimpleDateFormat df = new SimpleDateFormat(format);
  862. cellValue = df.format(cell.getDateCellValue());
  863. } else {
  864. cell.setCellType(CellType.STRING); // 将数值型cell设置为string型
  865. cellValue = cell.getStringCellValue();
  866. }
  867. break;
  868. }
  869. case FORMULA: {
  870. // 判断cell是否为日期格式
  871. if (DateUtil.isCellDateFormatted(cell)) {
  872. // 转换为日期格式YYYY-mm-dd
  873. cellValue = cell.getDateCellValue();
  874. } else {
  875. // 数字
  876. cellValue = String.valueOf(cell.getNumericCellValue());
  877. }
  878. break;
  879. }
  880. case STRING: {
  881. cellValue = cell.getRichStringCellValue().getString();
  882. break;
  883. }
  884. default:
  885. cellValue = cell.getRichStringCellValue().getString();
  886. break;
  887. }
  888. } else {
  889. cellValue = "";
  890. }
  891. return cellValue;
  892. }
  893. public XSSFSheet addSheetIncome(ExcelFactory excelFactory, String sheetname, Rows datarows,
  894. HashMap<String, String> titlemap) {
  895. ArrayList<String> keylist = datarows.getFieldList();
  896. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  897. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  898. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  899. XSSFFont font = xssfFWorkbook.createFont();
  900. font.setColor((short) 0xa);
  901. font.setFontHeightInPoints((short) 12);
  902. font.setBold(true);
  903. xssfCellStyle1.setFont(font);
  904. IncomeExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  905. XSSFCellStyle titleCellStyle1 = IncomeExportExcel.createTitleCellStyle1(xssfFWorkbook);
  906. XSSFCellStyle titleCellStyle2 = IncomeExportExcel.createTitleCellStyle2(xssfFWorkbook);
  907. XSSFCellStyle titleCellStyle3 = IncomeExportExcel.createTitleCellStyle3(xssfFWorkbook);
  908. IncomeExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  909. for (int n = 0; n < datarows.size(); n++) {
  910. Row row = datarows.get(n);
  911. XSSFRow datarow = sheet.createRow(n + 3);
  912. for (int i1 = 0; i1 < keylist.size(); i1++) {
  913. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  914. if (fieldclazztype == Integer.class) {
  915. datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)).intValue());
  916. } else if (fieldclazztype == Long.class) {
  917. datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
  918. } else if (fieldclazztype == Float.class) {
  919. datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
  920. } else if (fieldclazztype == Double.class) {
  921. datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
  922. } else {
  923. datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
  924. }
  925. if (i1 == 6) {
  926. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  927. }
  928. }
  929. }
  930. return sheet;
  931. }
  932. public XSSFSheet addSheetPay(ExcelFactory excelFactory, String sheetname, Rows datarows,
  933. HashMap<String, String> titlemap) {
  934. ArrayList<String> keylist = datarows.getFieldList();
  935. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  936. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  937. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  938. XSSFFont font = xssfFWorkbook.createFont();
  939. font.setColor((short) 0xa);
  940. font.setFontHeightInPoints((short) 12);
  941. font.setBold(true);
  942. xssfCellStyle1.setFont(font);
  943. PayExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  944. XSSFCellStyle titleCellStyle1 = PayExportExcel.createTitleCellStyle1(xssfFWorkbook);
  945. XSSFCellStyle titleCellStyle2 = PayExportExcel.createTitleCellStyle2(xssfFWorkbook);
  946. XSSFCellStyle titleCellStyle3 = PayExportExcel.createTitleCellStyle3(xssfFWorkbook);
  947. PayExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  948. for (int n = 0; n < datarows.size(); n++) {
  949. Row row = datarows.get(n);
  950. XSSFRow datarow = sheet.createRow(n + 3);
  951. for (int i1 = 0; i1 < keylist.size(); i1++) {
  952. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  953. if (fieldclazztype == Integer.class) {
  954. datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)).intValue());
  955. } else if (fieldclazztype == Long.class) {
  956. datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
  957. } else if (fieldclazztype == Float.class) {
  958. datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
  959. } else if (fieldclazztype == Double.class) {
  960. datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
  961. } else {
  962. datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
  963. }
  964. if (i1 == 6) {
  965. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  966. }
  967. }
  968. }
  969. return sheet;
  970. }
  971. //返回导出的标题
  972. public HashMap<String, String> getTitleMap() {
  973. HashMap<String, String> titleMap = new HashMap<>();
  974. titleMap.put("billno", "凭证编号");
  975. titleMap.put("type", "收支类型");
  976. titleMap.put("accountname", "账户名称");
  977. titleMap.put("amount", "收支金额");
  978. titleMap.put("source", "凭证来源");
  979. titleMap.put("checkby", "审核人");
  980. titleMap.put("checkdate", "审核时间");
  981. titleMap.put("remarks", "备注");
  982. return titleMap;
  983. }
  984. }