cashbill.java 75 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  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 beans.remind.Remind;
  7. import com.alibaba.fastjson.JSONArray;
  8. import com.alibaba.fastjson.JSONObject;
  9. import common.Controller;
  10. import common.YosException;
  11. import common.annotation.*;
  12. import common.data.*;
  13. import common.data.Row;
  14. import org.apache.commons.lang.StringUtils;
  15. import org.apache.poi.ss.usermodel.*;
  16. import org.apache.poi.xssf.usermodel.*;
  17. import restcontroller.R;
  18. import restcontroller.system.attachment.Attachment;
  19. import java.io.IOException;
  20. import java.math.BigDecimal;
  21. import java.text.ParseException;
  22. import java.text.SimpleDateFormat;
  23. import java.util.*;
  24. import static beans.order.Order.getOrderRows;
  25. import static restcontroller.webmanage.saletool.orderclue.orderclue.isBigDecimal;
  26. public class cashbill extends Controller {
  27. public cashbill(JSONObject arg0) throws YosException {
  28. super(arg0);
  29. // TODO Auto-generated constructor stub
  30. }
  31. /**
  32. * 下载凭证导入单模板
  33. *
  34. * @return
  35. */
  36. @API(title = "下载凭证导入单模板", apiversion = R.ID20230506162603.v1.class)
  37. public String downloadCashbillExcel() throws YosException {
  38. ExcelFactory excelFactory = new ExcelFactory("ImportTemplateForCashbill");
  39. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet("Sheet1");
  40. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  41. CellStyle style = xssfFWorkbook.createCellStyle();
  42. // 设置为文本格式,防止身份证号变成科学计数法
  43. DataFormat format = xssfFWorkbook.createDataFormat();
  44. style.setDataFormat(format.getFormat("@"));
  45. // 对单独某一列进行样式赋值,第一个参数为列数,第二个参数为样式
  46. for (int i = 0; i <= 10; i++) {
  47. sheet.setDefaultColumnStyle(i, style);
  48. }
  49. if (content.getString("type").equals("收入")) {
  50. IncomeExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  51. XSSFCellStyle titleCellStyle1 = IncomeExportExcel.createTitleCellStyle1(xssfFWorkbook);
  52. XSSFCellStyle titleCellStyle2 = IncomeExportExcel.createTitleCellStyle2(xssfFWorkbook);
  53. XSSFCellStyle titleCellStyle3 = IncomeExportExcel.createBodyCellStyle(xssfFWorkbook);
  54. XSSFCellStyle titleCellStyle4 = IncomeExportExcel.createTitleCellStyle3(xssfFWorkbook);
  55. IncomeExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, titleCellStyle4,
  56. xssfFWorkbook);// 写入标题
  57. } else if (content.getString("type").equals("支出")) {
  58. PayExportExcel.setBatchDetailSheetColumn1(sheet);// 设置工作薄列宽
  59. XSSFCellStyle titleCellStyle1 = PayExportExcel.createTitleCellStyle1(xssfFWorkbook);
  60. XSSFCellStyle titleCellStyle2 = PayExportExcel.createTitleCellStyle2(xssfFWorkbook);
  61. XSSFCellStyle titleCellStyle3 = PayExportExcel.createBodyCellStyle(xssfFWorkbook);
  62. XSSFCellStyle titleCellStyle4 = PayExportExcel.createTitleCellStyle3(xssfFWorkbook);
  63. PayExportExcel.batchDetail(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, titleCellStyle4,
  64. xssfFWorkbook);// 写入标题
  65. } else {
  66. return getErrReturnObject().setErrMsg("凭证类型不匹配,无法下载导入文件").toString();
  67. }
  68. Rows aa = uploadExcelToObs(excelFactory);
  69. String url = "";
  70. if (!aa.isEmpty()) {
  71. url = aa.get(0).getString("url");
  72. }
  73. return getSucReturnObject().setData(url).toString();
  74. }
  75. /**
  76. * 导入凭证
  77. *
  78. * @return
  79. */
  80. @API(title = "导入凭证", apiversion = R.ID20230506162703.v1.class)
  81. @CACHEING_CLEAN(apiClass = cashbill.class)
  82. public String uploadCashbillByExcel() throws YosException {
  83. ExcelFactory e;
  84. try {
  85. // 华为云
  86. e = getPostExcelFactory(content.getLong("attachmentid"));
  87. // 本地
  88. //e = getPostExcelFactory();
  89. // Rows keyRow = dbConnect.runSqlQuery("select fagentnum,faddress from tagents
  90. // where 1=2");
  91. // Rows row1 = e.getSheetRows(1, keyRow, 1);
  92. ArrayList<String> keys = new ArrayList<>();
  93. ArrayList<String> sqllist = new ArrayList<>();
  94. keys.add("agentnum");
  95. keys.add("accountname");
  96. keys.add("amount");
  97. keys.add("type");
  98. keys.add("typemx");
  99. keys.add("period");
  100. keys.add("remarks");
  101. Rows accountclassRows = dbConnect.runSqlQuery("select sa_accountclassid,accountname from sa_accountclass where siteid='" + siteid + "' and isused=1");
  102. RowsMap accountclassRowsMap = accountclassRows.toRowsMap("accountname");
  103. Rows agentRows = dbConnect.runSqlQuery("select agentnum,sys_enterpriseid from sa_agents where siteid='" + siteid + "'");
  104. RowsMap agentRowsMap = agentRows.toRowsMap("agentnum");
  105. if (!(content.getString("type") + "凭证导入")
  106. .equals(((String) getCellFormatValue(e.getSheet(0).getRow(0).getCell(0))).replace(" ", ""))) {
  107. return getErrReturnObject().setErrMsg("导入失败,不符合" + content.getString("type") + "凭证导入要求").toString();
  108. }
  109. Rows rows = e.getSheetRows(0, keys, 3);
  110. int a = 1;
  111. int i = 0;
  112. // String msg = "";
  113. boolean iserr = false;
  114. Rows rowserr = new Rows();
  115. Rows rowssuc = new Rows();
  116. for (Row row : rows) {
  117. String msg = "";
  118. if (StringUtils.isEmpty(row.getString("agentnum"))) {
  119. iserr = true;
  120. msg = msg + "【经销商编码为空】";
  121. }
  122. if (StringUtils.isEmpty(row.getString("accountname"))) {
  123. iserr = true;
  124. msg = msg + "【账户名称为空】";
  125. }
  126. if (!isValidFormat(row.getString("period"))) {
  127. iserr = true;
  128. msg = msg + "【归属日期格式错误】";
  129. }
  130. if (!isBigDecimal(row.getString("amount"))) {
  131. iserr = true;
  132. msg = msg + "【金额错误:" + row.getString("amount") + "】";
  133. }
  134. if (StringUtils.isEmpty(row.getString("type"))) {
  135. iserr = true;
  136. msg = msg + "【分类为空】";
  137. }
  138. if (!agentRowsMap.containsKey(row.getString("agentnum"))) {
  139. iserr = true;
  140. msg = msg + "【该经销商编码找不到匹配的经销商】";
  141. } else {
  142. if (agentRowsMap.get(row.getString("agentnum")).isEmpty()) {
  143. iserr = true;
  144. msg = msg + "【该经销商编码找不到匹配的经销商】";
  145. }
  146. }
  147. if (!accountclassRowsMap.containsKey(row.getString("accountname"))) {
  148. iserr = true;
  149. msg = msg + "【该账户名称找不到匹配的账户】";
  150. } else {
  151. if (accountclassRowsMap.get(row.getString("accountname")).isEmpty()) {
  152. iserr = true;
  153. msg = msg + "【该账户名称找不到匹配的账户】";
  154. }
  155. }
  156. if (iserr) {
  157. row.put("msg", "错误信息:" + msg);
  158. rowserr.add(row);
  159. } else {
  160. rowssuc.add(row);
  161. }
  162. // if (!msg.equals("111")) {
  163. // XSSFWorkbook xssfFWorkbook = e.getXssfWorkbook();
  164. // XSSFCellStyle cellStyle = xssfFWorkbook.createCellStyle();
  165. //
  166. // XSSFFont font = xssfFWorkbook.createFont();
  167. //
  168. // font.setColor((short) 0xa);
  169. // font.setFontHeightInPoints((short) 8);
  170. // font.setBold(true);
  171. // cellStyle.setFont(font);
  172. // datarow.createCell(8).setCellValue("错误信息:" + msg);
  173. // datarow.getCell(8).setCellStyle(cellStyle);
  174. //
  175. // }
  176. }
  177. long[] sa_cashbillid = createTableID("sa_cashbill",
  178. rowssuc.size());
  179. if (!rowssuc.isEmpty()) {
  180. for (Row row : rowssuc) {
  181. SQLFactory sqlFactoryupload = new SQLFactory(this, "收支凭证新增");
  182. sqlFactoryupload.addParameter("sa_cashbillid", sa_cashbillid[i]);
  183. sqlFactoryupload.addParameter("billno", createBillCode("cashbill"));
  184. if (agentRowsMap.containsKey(row.getString("agentnum"))) {
  185. sqlFactoryupload.addParameter("sys_enterpriseid", agentRowsMap.get(row.getString("agentnum")).get(0).getLong("sys_enterpriseid"));
  186. } else {
  187. continue;
  188. }
  189. if (accountclassRowsMap.containsKey(row.getString("accountname"))) {
  190. sqlFactoryupload.addParameter("sa_accountclassid", accountclassRowsMap.get(row.getString("accountname")).get(0).getLong("sa_accountclassid"));
  191. } else {
  192. continue;
  193. }
  194. if (content.getString("type").equals("收入")) {
  195. sqlFactoryupload.addParameter("type", 1);
  196. } else {
  197. sqlFactoryupload.addParameter("type", 0);
  198. }
  199. sqlFactoryupload.addParameter("siteid", siteid);
  200. sqlFactoryupload.addParameter("remarks", row.getString("remarks"));
  201. sqlFactoryupload.addParameter("amount", row.getDouble("amount"));
  202. sqlFactoryupload.addParameter("subclass", row.getString("typemx"));
  203. sqlFactoryupload.addParameter("class", row.getString("type"));
  204. sqlFactoryupload.addParameter("userid", userid);
  205. sqlFactoryupload.addParameter("username", username);
  206. sqlFactoryupload.addParameter("ownertable", "");
  207. sqlFactoryupload.addParameter("ownerid", 0);
  208. sqlFactoryupload.addParameter("source", "");
  209. sqlFactoryupload.addParameter("sourcenote", "");
  210. sqlFactoryupload.addParameter("discountamount", 0);
  211. if (StringUtils.isBlank(row.getString("period"))) {
  212. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
  213. sqlFactoryupload.addParameter("period", sdf.format(new Date()));
  214. } else {
  215. sqlFactoryupload.addParameter("period", row.getString("period"));
  216. }
  217. sqllist.add(sqlFactoryupload.getSQL());
  218. i++;
  219. }
  220. }
  221. //System.out.println(sqllist.size());
  222. dbConnect.runSqlUpdate(sqllist);
  223. if (iserr) {
  224. ExcelFactory excelFactory = new ExcelFactory("sa_cashbillerr");
  225. HashMap<String, String> map = new HashMap<String, String>();
  226. map.put("agentnum", "经销商编码");
  227. map.put("accountname", "账户名称");
  228. map.put("amount", "金额");
  229. map.put("type", "分类");
  230. map.put("typemx", "分类明细");
  231. map.put("period", "归属日期");
  232. map.put("remarks", "备注");
  233. map.put("msg", "错误信息");
  234. ArrayList<String> colNameList = new ArrayList<String>();
  235. HashMap<String, Class> keytypemap = new HashMap<String, Class>();
  236. colNameList.add("agentnum");
  237. colNameList.add("accountname");
  238. colNameList.add("amount");
  239. colNameList.add("type");
  240. colNameList.add("typemx");
  241. colNameList.add("period");
  242. colNameList.add("remarks");
  243. colNameList.add("msg");
  244. keytypemap.put("agentnum", String.class);
  245. keytypemap.put("accountname", String.class);
  246. keytypemap.put("amount", String.class);
  247. keytypemap.put("type", String.class);
  248. keytypemap.put("typemx", String.class);
  249. keytypemap.put("period", String.class);
  250. keytypemap.put("remarks", String.class);
  251. keytypemap.put("msg", String.class);
  252. rowserr.setFieldList(colNameList);
  253. rowserr.setFieldTypeMap(keytypemap);
  254. if (content.getString("type").equals("收入")) {
  255. addSheetIncome(excelFactory, "Sheet1", rowserr, map);
  256. } else {
  257. addSheetPay(excelFactory, "Sheet1", rowserr, map);
  258. }
  259. Rows aa = uploadExcelToObs(excelFactory);
  260. String url = "";
  261. if (!aa.isEmpty()) {
  262. url = aa.get(0).getString("url");
  263. }
  264. return getSucReturnObject().setData(url).toString();
  265. }
  266. } catch (Exception e1) {
  267. // TODO Auto-generated catch block
  268. e1.printStackTrace();
  269. return getErrReturnObject().setErrMsg(e1.getMessage()).toString();
  270. }
  271. return getSucReturnObject().toString();
  272. }
  273. @API(title = "收支凭证新建更新", apiversion = R.ID20221009102803.v1.class, intervaltime = 200)
  274. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  275. public String insertormodify_creditbill() throws YosException {
  276. Long sa_cashbillid = content.getLong("sa_cashbillid");
  277. Long type = content.getLong("type"); //收支类型(1:收;0:支)
  278. Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  279. Long sa_accountclassid = content.getLong("sa_accountclassid");
  280. String billcode = createBillCode("cashbill");
  281. String subclass = content.getStringValue("subclass");
  282. String class1 = content.getStringValue("class");
  283. String period = content.getStringValue("period");
  284. if (StringUtils.isEmpty(period)) {
  285. if (type == 1) {
  286. return getErrReturnObject().setErrMsg("未填写归属日期").toString();
  287. } else if (type == 0 && subclass.equals("拨款")) {
  288. period = getDate_Str();
  289. }
  290. }
  291. BigDecimal amount = content.getBigDecimal("amount");
  292. BigDecimal discountamount = content.getBigDecimal("discountamount");
  293. String remarks = content.getString("remarks");
  294. ArrayList<String> sqlList = new ArrayList<>();
  295. if (sa_cashbillid <= 0 || dbConnect
  296. .runSqlQuery("select sa_cashbillid from sa_cashbill where sa_cashbillid="
  297. + sa_cashbillid)
  298. .isEmpty()) {
  299. if (sa_cashbillid <= 0) {
  300. sa_cashbillid = createTableID("sa_cashbill");
  301. }
  302. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证新增");
  303. sqlFactory.addParameter("billno", billcode);
  304. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  305. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  306. sqlFactory.addParameter("type", type);
  307. sqlFactory.addParameter("siteid", siteid);
  308. sqlFactory.addParameter("remarks", remarks);
  309. sqlFactory.addParameter("amount", amount);
  310. sqlFactory.addParameter("subclass", subclass);
  311. sqlFactory.addParameter("class", class1);
  312. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  313. sqlFactory.addParameter("userid", userid);
  314. sqlFactory.addParameter("username", username);
  315. sqlFactory.addParameter("ownertable", "");
  316. sqlFactory.addParameter("ownerid", 0);
  317. sqlFactory.addParameter("source", "");
  318. sqlFactory.addParameter("sourcenote", "");
  319. sqlFactory.addParameter("period", period);
  320. sqlFactory.addParameter("discountamount", discountamount);
  321. content.put("sa_cashbillid", sa_cashbillid);
  322. sqlList.add(sqlFactory.getSQL());
  323. if (type == 1) {
  324. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "新增", "收入凭证新增成功").getSQL());
  325. } else {
  326. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "新增", "支出凭证新增成功").getSQL());
  327. }
  328. } else {
  329. Rows rowscount = dbConnect.runSqlQuery(
  330. "select status from sa_cashbill where sa_cashbillid=" + sa_cashbillid);
  331. if (rowscount.isNotEmpty()) {
  332. if (!rowscount.get(0).getString("status").equals("新建")) {
  333. return getErrReturnObject().setErrMsg("非新建状态的收支凭证无法更新").toString();
  334. }
  335. }
  336. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证更新");
  337. sqlFactory.addParameter("siteid", siteid);
  338. sqlFactory.addParameter("remarks", remarks);
  339. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  340. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  341. sqlFactory.addParameter("amount", amount);
  342. sqlFactory.addParameter("subclass", subclass);
  343. sqlFactory.addParameter("class", class1);
  344. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  345. sqlFactory.addParameter("userid", userid);
  346. sqlFactory.addParameter("username", username);
  347. sqlFactory.addParameter("source", "");
  348. sqlFactory.addParameter("sourcenote", "");
  349. sqlFactory.addParameter("period", period);
  350. sqlFactory.addParameter("discountamount", discountamount);
  351. sqlList.add(sqlFactory.getSQL());
  352. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "更新", "收支凭证更新成功").getSQL());
  353. }
  354. dbConnect.runSqlUpdate(sqlList);
  355. return queryCashbillMain();
  356. }
  357. // @API(title = "合作企业档案列表",apiversion = R.ID20221008164103.v1.class)
  358. // @CACHEING
  359. // public String queryEnterpriseList() throws YosException {
  360. //
  361. // /*
  362. // * 过滤条件设置
  363. // */
  364. // String where = " 1=1 ";
  365. // if (content.containsKey("where")) {
  366. // JSONObject whereObject = content.getJSONObject("where");
  367. // if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  368. // where = where + " and(t1.enterprisename like'%" + whereObject.getString("condition")
  369. // + "%' or t1.phonenumber like '%" + whereObject.getString("condition") + "%')";
  370. // }
  371. // }
  372. // SQLFactory sqlFactory = new SQLFactory(this, "合作企业档案列表查询", pageSize, pageNumber, pageSorting);
  373. // sqlFactory.addParameter_SQL("where", where);
  374. // sqlFactory.addParameter("siteid", siteid);
  375. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  376. // return getSucReturnObject().setData(rows).toString();
  377. // }
  378. //
  379. // @API(title = "营销账户类别列表",apiversion = R.ID20221008164203.v1.class)
  380. // @CACHEING
  381. // public String queryAccountclassList() throws YosException {
  382. // long sys_enterpriseid=content.getLong("sys_enterpriseid");
  383. //
  384. // SQLFactory sqlFactory = new SQLFactory(this, "营销账户类别列表查询");
  385. // sqlFactory.addParameter("siteid", siteid);
  386. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  387. // Rows rows = dbConnect.runSqlQuery(sqlFactory);
  388. // return getSucReturnObject().setData(rows).toString();
  389. // }
  390. @API(title = "更新收支凭证明细分类", apiversion = R.ID20231205134103.v1.class)
  391. public String updateTypemx() throws YosException {
  392. Long sa_cashbillid = content.getLong("sa_cashbillid");
  393. String subclass = content.getStringValue("subclass");
  394. String class1 = content.getStringValue("class");
  395. Rows cashbillRows = dbConnect.runSqlQuery("select * from sa_cashbill where siteid='" + siteid + "' and sa_cashbillid=" + sa_cashbillid);
  396. if (cashbillRows.isEmpty()) {
  397. return getErrReturnObject().setErrMsg("收支凭证不存在").toString();
  398. }
  399. dbConnect.runSqlUpdate("update sa_cashbill set subclass='" + subclass + "',class='" + class1 + "' where sa_cashbillid=" + sa_cashbillid);
  400. return queryCashbillMain();
  401. }
  402. @API(title = "收入凭证列表", apiversion = R.ID20221009102903.v1.class)
  403. @CACHEING
  404. public String queryIncomeCashbillList() throws YosException, IOException {
  405. /*
  406. * 过滤条件设置
  407. */
  408. boolean isExport = content.getBooleanValue("isExport");
  409. String where = " 1=1 and t1.type=1 ";
  410. if (content.containsKey("where")) {
  411. JSONObject whereObject = content.getJSONObject("where");
  412. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  413. where = where + " and(t2.enterprisename like'%" + whereObject.getString("condition")
  414. + "%' or t3.accountname like '%" + whereObject.getString("condition") + "%'"
  415. + " or t2.abbreviation like '%" + whereObject.getString("condition") + "%'"
  416. + " or t1.billno like '%" + whereObject.getString("condition") + "%'"
  417. + " or t1.remarks like '%" + whereObject.getString("condition") + "%'"
  418. + " or t4.agentnum like '%" + whereObject.getString("condition") + "%'"
  419. + " or t1.class like '%" + whereObject.getString("condition") + "%'"
  420. + " or t1.subclass like '%" + whereObject.getString("condition") + "%'"
  421. + " or t1.amount like '%" + whereObject.getString("condition") + "%'"
  422. + ")";
  423. }
  424. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  425. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  426. }
  427. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  428. where = where + " and t3.accountname ='" + whereObject.getString("accountname") + "' ";
  429. }
  430. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  431. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') >='" + whereObject.getString("begindate") + "'";
  432. }
  433. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  434. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') <='" + whereObject.getString("enddate") + "'";
  435. }
  436. if (whereObject.containsKey("beginperiod") && !"".equals(whereObject.getString("beginperiod"))) {
  437. where = where + " and t1.period >='" + whereObject.getString("beginperiod") + "' ";
  438. }
  439. if (whereObject.containsKey("endperiod") && !"".equals(whereObject.getString("endperiod"))) {
  440. where = where + " and t1.period <='" + whereObject.getString("endperiod") + "' ";
  441. }
  442. if (whereObject.containsKey("billno") && !"".equals(whereObject.getString("billno"))) {
  443. where = where + " and t1.billno ='" + whereObject.getString("billno") + "'";
  444. }
  445. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  446. where = where + " and ifnull(t3.isrebate,0) ='" + whereObject.getLongValue("isrebate") + "'";
  447. }
  448. if (whereObject.containsKey("remarks") && !"".equals(whereObject.getString("remarks"))) {
  449. where = where + " and t1.remarks like'%" + whereObject.getString("remarks") + "%' ";
  450. }
  451. if (whereObject.containsKey("period") && !"".equals(whereObject.getString("period"))) {
  452. where = where + " and t1.period like'%" + whereObject.getString("period") + "%' ";
  453. }
  454. if (whereObject.containsKey("agentinfo") && !"".equals(whereObject.getString("agentinfo"))) {
  455. where = where + " and(t2.enterprisename like'%" + whereObject.getString("agentinfo") + "%'"
  456. + " or t4.agentnum like '%" + whereObject.getString("agentinfo") + "%'"
  457. + ")";
  458. }
  459. }
  460. // if (pageSorting.equals("''")) {
  461. // pageSorting = "status desc, period desc";
  462. // }
  463. QuerySQL querySQL = queryList(where);
  464. querySQL.setOrderBy(pageSorting);
  465. // if (!isExport) {
  466. querySQL.setPage(pageSize, pageNumber);
  467. // }
  468. Rows rows = querySQL.query();
  469. SQLFactory areasqlFactory = new SQLFactory(this, "收支凭证关联区域列表查询");
  470. areasqlFactory.addParameter("siteid", siteid);
  471. areasqlFactory.addParameter_in("sys_enterpriseids", rows.toArrayList("sys_enterpriseid", new ArrayList<>()));
  472. Rows areaRows = dbConnect.runSqlQuery(areasqlFactory);
  473. RowsMap areaRowsMap = areaRows.toRowsMap("sys_enterpriseid");
  474. ArrayList sa_cashbillids = rows.toArrayList("sa_cashbillid", new ArrayList<>());
  475. sa_cashbillids.add(0L);
  476. 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;
  477. sql = sql.replace("[", "(").replace("]", ")");
  478. RowsMap offsettingRowsMap = dbConnect.runSqlQuery(sql).toRowsMap("sa_cashbillid");
  479. for (Row row : rows) {
  480. if (row.getString("ownertable").equals("sa_cashbill") && offsettingRowsMap.containsKey(row.getString("sa_cashbillid"))) {
  481. row.put("offsettingbillno", offsettingRowsMap.get(row.getString("sa_cashbillid")).get(0).getString("billno"));
  482. }
  483. row.put("amount", row.getBigDecimal("amount"));
  484. if (areaRowsMap.containsKey(row.getString("sys_enterpriseid"))) {
  485. row.put("areaname", areaRowsMap.get(row.getString("sys_enterpriseid")).get(0).getString("areaname"));
  486. } else {
  487. row.put("areaname", "");
  488. }
  489. }
  490. // if (isExport) {
  491. // //去除不需要导出项
  492. // rows.getFieldList().remove("sa_accountclassid");
  493. // rows.getFieldList().remove("period");
  494. // rows.getFieldList().remove("sys_enterpriseid");
  495. // rows.getFieldList().remove("abbreviation");
  496. // rows.getFieldList().remove("enterprisename");
  497. // rows.getFieldList().remove("sa_accountclassid");
  498. // rows.getFieldList().remove("status");
  499. // rows.getFieldList().remove("sourcenote");
  500. // rows.getFieldList().remove("ownertable");
  501. // rows.getFieldList().remove("ownerid");
  502. // rows.getFieldList().remove("createuserid");
  503. // rows.getFieldList().remove("createby");
  504. // rows.getFieldList().remove("createdate");
  505. // rows.getFieldList().remove("changeuserid");
  506. // rows.getFieldList().remove("changeby");
  507. // rows.getFieldList().remove("changedate");
  508. // rows.getFieldList().remove("subclass");
  509. // rows.getFieldList().remove("class");
  510. // rows.getFieldList().remove("unwriteoffamount");
  511. // rows.getFieldList().remove("offsettingbillno");
  512. //
  513. // Rows uploadRows = uploadExcelToObs("cashBill", "收入凭证列表", rows, getTitleMap());
  514. // return getSucReturnObject().setData(uploadRows).toString();
  515. // }
  516. return getSucReturnObject().setData(rows).toString();
  517. }
  518. @API(title = "支出收入凭证列表", apiversion = R.ID20221010102903.v1.class)
  519. @CACHEING
  520. public String queryPayCashbillList() throws YosException, IOException {
  521. /*
  522. * 过滤条件设置
  523. */
  524. boolean isExport = content.getBooleanValue("isExport");
  525. String where = " 1=1 and t1.type=0 ";
  526. if (content.containsKey("where")) {
  527. JSONObject whereObject = content.getJSONObject("where");
  528. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  529. where = where + " and(t2.enterprisename like'%" + whereObject.getString("condition")
  530. + "%' or t3.accountname like '%" + whereObject.getString("condition") + "%'"
  531. + " or t2.abbreviation like '%" + whereObject.getString("condition") + "%'"
  532. + " or t1.billno like '%" + whereObject.getString("condition") + "%'"
  533. + " or t4.agentnum like '%" + whereObject.getString("condition") + "%'"
  534. + " or t1.remarks like '%" + whereObject.getString("condition") + "%'"
  535. + " or t1.class like '%" + whereObject.getString("condition") + "%'"
  536. + " or t1.subclass like '%" + whereObject.getString("condition") + "%'"
  537. + " or t1.amount like '%" + whereObject.getString("condition") + "%'"
  538. + ")";
  539. }
  540. if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
  541. where = where + " and t1.status ='" + whereObject.getString("status") + "' ";
  542. }
  543. if (whereObject.containsKey("accountname") && !"".equals(whereObject.getString("accountname"))) {
  544. where = where + " and t3.accountname ='" + whereObject.getString("accountname") + "' ";
  545. }
  546. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  547. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') >='" + whereObject.getString("begindate") + "'";
  548. }
  549. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  550. where = where + " and DATE_FORMAT(t1.createdate, '%Y-%m-%d') <='" + whereObject.getString("enddate") + "'";
  551. }
  552. if (whereObject.containsKey("beginperiod") && !"".equals(whereObject.getString("beginperiod"))) {
  553. where = where + " and t1.period >='" + whereObject.getString("beginperiod") + "' ";
  554. }
  555. if (whereObject.containsKey("endperiod") && !"".equals(whereObject.getString("endperiod"))) {
  556. where = where + " and t1.period <='" + whereObject.getString("endperiod") + "' ";
  557. }
  558. if (whereObject.containsKey("billno") && !"".equals(whereObject.getString("billno"))) {
  559. where = where + " and t1.billno ='" + whereObject.getString("billno") + "'";
  560. }
  561. if (whereObject.containsKey("isrebate") && !"".equals(whereObject.getString("isrebate"))) {
  562. where = where + " and ifnull(t3.isrebate,0) ='" + whereObject.getLongValue("isrebate") + "'";
  563. }
  564. if (whereObject.containsKey("remarks") && !"".equals(whereObject.getString("remarks"))) {
  565. where = where + " and t1.remarks like'%" + whereObject.getString("remarks") + "%' ";
  566. }
  567. if (whereObject.containsKey("agentinfo") && !"".equals(whereObject.getString("agentinfo"))) {
  568. where = where + " and(t2.enterprisename like'%" + whereObject.getString("agentinfo") + "%'"
  569. + " or t4.agentnum like '%" + whereObject.getString("agentinfo") + "%'"
  570. + ")";
  571. }
  572. }
  573. if (pageSorting.equals("''")) {
  574. pageSorting = "status desc, createdate desc";
  575. }
  576. QuerySQL querySQL = queryList(where);
  577. querySQL.setOrderBy(pageSorting);
  578. querySQL.setPage(pageSize, pageNumber);
  579. Rows rows = querySQL.query();
  580. SQLFactory areasqlFactory = new SQLFactory(this, "收支凭证关联区域列表查询");
  581. areasqlFactory.addParameter("siteid", siteid);
  582. areasqlFactory.addParameter_in("sys_enterpriseids", rows.toArrayList("sys_enterpriseid", new ArrayList<>()));
  583. Rows areaRows = dbConnect.runSqlQuery(areasqlFactory);
  584. RowsMap areaRowsMap = areaRows.toRowsMap("sys_enterpriseid");
  585. for (Row row : rows) {
  586. row.put("amount", row.getBigDecimal("amount"));
  587. if (areaRowsMap.containsKey(row.getString("sys_enterpriseid"))) {
  588. row.put("areaname", areaRowsMap.get(row.getString("sys_enterpriseid")).get(0).getString("areaname"));
  589. } else {
  590. row.put("areaname", "");
  591. }
  592. }
  593. // if (isExport) {
  594. // //去除不需要导出项
  595. // rows.getFieldList().remove("sa_accountclassid");
  596. // rows.getFieldList().remove("period");
  597. // rows.getFieldList().remove("sys_enterpriseid");
  598. // rows.getFieldList().remove("abbreviation");
  599. // rows.getFieldList().remove("enterprisename");
  600. // rows.getFieldList().remove("sa_accountclassid");
  601. // rows.getFieldList().remove("status");
  602. // rows.getFieldList().remove("sourcenote");
  603. // rows.getFieldList().remove("ownertable");
  604. // rows.getFieldList().remove("ownerid");
  605. // rows.getFieldList().remove("createuserid");
  606. // rows.getFieldList().remove("createby");
  607. // rows.getFieldList().remove("createdate");
  608. // rows.getFieldList().remove("changeuserid");
  609. // rows.getFieldList().remove("changeby");
  610. // rows.getFieldList().remove("changedate");
  611. // rows.getFieldList().remove("subclass");
  612. // rows.getFieldList().remove("class");
  613. // rows.getFieldList().remove("unwriteoffamount");
  614. // rows.getFieldList().remove("offsettingbillno");
  615. //
  616. // Rows uploadRows = uploadExcelToObs("cashBill", "支出凭证列表", rows, getTitleMap());
  617. // return getSucReturnObject().setData(uploadRows).toString();
  618. // }
  619. return getSucReturnObject().setData(rows).toString();
  620. }
  621. public QuerySQL queryList(String where) throws YosException {
  622. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_cashbill","*");
  623. querySQL.setTableAlias("t1");
  624. querySQL.addQueryFields("unwriteoffamount", "t1.amount - t1.writeoffamount");
  625. querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t1.sys_enterpriseid = t2.sys_enterpriseid and t1.siteid = t2.siteid",
  626. "enterprisename", "abbreviation", "sys_enterpriseid");
  627. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t4", "t4.sys_enterpriseid = t2.sys_enterpriseid and t4.siteid = t2.siteid",
  628. "agentnum");
  629. querySQL.addJoinTable(JOINTYPE.left, "sa_accountclass", "t3", "t1.sa_accountclassid = t3.sa_accountclassid and t1.siteid = t3.siteid and t3.isused = 1",
  630. "accountno", "accountname");
  631. querySQL.addJoinTable(JOINTYPE.left, "sa_cashbill", "t5", "t1.siteid = t5.siteid and t5.ownerid = t1.sa_cashbillid and t5.ownertable = 'sa_cashbill'");
  632. querySQL.addQueryFields("offsettingbillno", "t5.billno");
  633. querySQL.setWhere(where);
  634. querySQL.setWhere("t1.siteid", siteid);
  635. return querySQL;
  636. }
  637. @API(title = "收支凭证详情", apiversion = R.ID20221009103003.v1.class)
  638. public String queryCashbillMain() throws YosException {
  639. Long sa_cashbillid = content.getLong("sa_cashbillid");
  640. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证详情查询");
  641. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  642. Rows rows = dbConnect.runSqlQuery(sqlFactory);
  643. if (rows.size() > 0) {
  644. 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"));
  645. if (offsetting.isNotEmpty()) {
  646. rows.get(0).put("offsettingbillno", offsetting.get(0).getString("billno"));
  647. }
  648. rows.get(0).put("amount", rows.get(0).getBigDecimal("amount"));
  649. }
  650. return getSucReturnObject().setData(rows.size() > 0 ? rows.get(0) : new Row()).toString();
  651. }
  652. /**
  653. * 收支凭证审核
  654. *
  655. * @return
  656. */
  657. @API(title = "收支凭证审核", apiversion = R.ID20221009103103.v1.class)
  658. @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})
  659. public String release() throws YosException {
  660. long sa_cashbillid = content.getLong("sa_cashbillid");
  661. String[] s = {"sa_cashbillid"};
  662. for (String s1 : s) {
  663. if (!content.containsKey(s1))
  664. return getErrReturnObject().setErrMsg("缺少" + s1 + "参数").toString();
  665. }
  666. //List<String> list = sa_creditbillids.toJavaList(String.class);
  667. //String[] stringArray = list.toArray(new String[0]);
  668. //SQLFactory sqlFactoryquery = new SQLFactory(this, "信用额度调整单状态查询");
  669. //sqlFactoryquery.addParameter("siteid", siteid);
  670. //sqlFactoryquery.addParameter_in("sa_creditbillids", stringArray);
  671. Rows rows = dbConnect.runSqlQuery("select t1.sa_cashbillid,t1.sys_enterpriseid,t1.sa_accountclassid,t1.status,t1.billno,t1.amount,ifnull(t1.discountamount,0) discountamount,t1.type,t1.ownerid,t2.accountname,t1.remarks from sa_cashbill t1 left join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t1.sa_cashbillid ='" + sa_cashbillid + "' and t1.siteid='" + siteid + "'");
  672. for (Row row : rows) {
  673. if (row.getString("status").equals("审核")) {
  674. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证已审核,无法再次审核")
  675. .toString();
  676. }
  677. if (!row.getString("status").equals("新建")) {
  678. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证为非新建状态,无法审核")
  679. .toString();
  680. }
  681. }
  682. ArrayList<String> sqlList = new ArrayList<>();
  683. BigDecimal balance = BigDecimal.ZERO; //当前账户余额
  684. BigDecimal discountamount = BigDecimal.ZERO; //当前账户余额
  685. if (!rows.isEmpty()) {
  686. long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
  687. long sa_accountclassid = rows.get(0).getLong("sa_accountclassid");
  688. long type = rows.get(0).getLong("type");
  689. Rows rowsaccountbalance = dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota,ifnull(discountamount,0) discountamount from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  690. if (type == 1) {
  691. Rows offsettingRows = dbConnect.runSqlQuery("select amount from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + rows.get(0).getLong("ownerid"));
  692. if (offsettingRows.isNotEmpty()) {
  693. 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"));
  694. }
  695. if (rowsaccountbalance.isEmpty()) {
  696. balance = rows.get(0).getBigDecimal("amount");
  697. SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  698. sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  699. sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  700. sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  701. sqlFactory.addParameter("siteid", siteid);
  702. sqlFactory.addParameter("balance", rows.get(0).getBigDecimal("amount"));
  703. sqlFactory.addParameter("discountamount", rows.get(0).getBigDecimal("discountamount"));
  704. sqlFactory.addParameter("userid", userid);
  705. sqlFactory.addParameter("username", username);
  706. sqlList.add(sqlFactory.getSQL());
  707. } else {
  708. BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance")).add(rowsaccountbalance.get(0).getBigDecimal("discountamount"));
  709. if ((rows.get(0).getBigDecimal("amount").add(canuseamount)).compareTo(BigDecimal.ZERO) == -1 && rows.get(0).getBigDecimal("amount").compareTo(BigDecimal.ZERO)<=0) {
  710. return getErrReturnObject().setErrMsg("该营销账户可用余额不足,收入凭证无法审核")
  711. .toString();
  712. }
  713. balance = rows.get(0).getBigDecimal("amount").add(rowsaccountbalance.get(0).getBigDecimal("balance"));
  714. discountamount = rows.get(0).getBigDecimal("discountamount").add(rowsaccountbalance.get(0).getBigDecimal("discountamount"));
  715. sqlList.add("update sa_accountbalance set balance='" + rows.get(0).getBigDecimal("amount").add(rowsaccountbalance.get(0).getBigDecimal("balance")) + "',discountamount="+discountamount+",changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  716. }
  717. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "审核", "收入凭证审核成功").getSQL());
  718. } else {
  719. if (rowsaccountbalance.isEmpty()) {
  720. // SQLFactory sqlFactory = new SQLFactory(this, "营销账户余额新增");
  721. // sqlFactory.addParameter("sa_accountbalanceid", createTableID("sa_accountbalance"));
  722. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  723. // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  724. // sqlFactory.addParameter("siteid", siteid);
  725. // sqlFactory.addParameter("balance", -rows.get(0).getLong("amount"));
  726. // sqlFactory.addParameter("userid", userid);
  727. // sqlFactory.addParameter("username", username);
  728. // sqlList.add(sqlFactory.getSQL());
  729. return getErrReturnObject().setErrMsg("该营销账户不存在,支出凭证无法审核")
  730. .toString();
  731. } else {
  732. BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("amount")).add(rowsaccountbalance.get(0).getBigDecimal("discountamount"));
  733. if (rows.get(0).getBigDecimal("amount").compareTo(canuseamount) == 1 ) {
  734. return getErrReturnObject().setErrMsg("该营销账户可用余额不足,支出凭证无法审核")
  735. .toString();
  736. }
  737. BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(rows.get(0).getBigDecimal("amount"));
  738. balance = newbalance;
  739. discountamount = rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(rows.get(0).getBigDecimal("discountamount"));
  740. sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount="+discountamount+",changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  741. }
  742. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "审核", "支出凭证审核成功").getSQL());
  743. }
  744. }
  745. SQLFactory sqlFactoryupdate = new SQLFactory(this, "收支凭证审核");
  746. sqlFactoryupdate.addParameter("siteid", siteid);
  747. sqlFactoryupdate.addParameter("sa_cashbillid", sa_cashbillid);
  748. sqlFactoryupdate.addParameter("balance", balance);
  749. sqlFactoryupdate.addParameter("checkby", username);
  750. sqlList.add(sqlFactoryupdate.getSQL());
  751. dbConnect.runSqlUpdate(sqlList);
  752. if (!rows.isEmpty()) {
  753. long type = rows.get(0).getLong("type");
  754. if (type == 1) {
  755. String message = "您的【" + rows.get(0).getString("accountname") + "】账户已收入【" + rows.get(0).getBigDecimal("amount") + "】元!";
  756. sendMsg(message, sa_cashbillid, rows.get(0).getLong("sys_enterpriseid"));
  757. } else {
  758. String message = "您的【" + rows.get(0).getString("accountname") + "】账户已支出【" + rows.get(0).getBigDecimal("amount") + "】元,【备注:" + rows.get(0).getString("remarks") + "】!!";
  759. sendMsg(message, sa_cashbillid, rows.get(0).getLong("sys_enterpriseid"));
  760. }
  761. }
  762. return getSucReturnObject().toString();
  763. }
  764. /**
  765. * 收支凭证反审核
  766. *
  767. * @return
  768. */
  769. @API(title = "收入凭证反审核", apiversion = R.ID20230509085703.v1.class)
  770. @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})
  771. public String unrelease() throws YosException {
  772. long sa_cashbillid = content.getLong("sa_cashbillid");
  773. //List<String> list = sa_creditbillids.toJavaList(String.class);
  774. //String[] stringArray = list.toArray(new String[0]);
  775. //SQLFactory sqlFactoryquery = new SQLFactory(this, "信用额度调整单状态查询");
  776. //sqlFactoryquery.addParameter("siteid", siteid);
  777. //sqlFactoryquery.addParameter_in("sa_creditbillids", stringArray);
  778. Rows rows = dbConnect.runSqlQuery("select checkdate,sa_cashbillid,sys_enterpriseid,sa_accountclassid,status,billno,amount,type,ownerid,ifnull(discountamount,0) discountamount from sa_cashbill where sa_cashbillid ='" + sa_cashbillid + "' and siteid='" + siteid + "'");
  779. Date date = new Date();
  780. for (Row row : rows) {
  781. if (!row.getString("status").equals("审核")) {
  782. return getErrReturnObject().setErrMsg("单号为:【" + row.getString("billno") + "】的收支凭证为非审核状态,无法反审核")
  783. .toString();
  784. }
  785. if (row.getLong("type") != 1) {
  786. return getErrReturnObject().setErrMsg("非收入凭证无法反审核")
  787. .toString();
  788. }
  789. if (!isMonth(row.getDate("checkdate"), date)) {
  790. return getErrReturnObject().setErrMsg("跨月禁止反审").toString();
  791. }
  792. }
  793. ArrayList<String> sqlList = new ArrayList<>();
  794. BigDecimal balance = BigDecimal.ZERO; //当前账户余额
  795. BigDecimal discountamount = BigDecimal.ZERO; //当前账户余额
  796. if (!rows.isEmpty()) {
  797. long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
  798. long sa_accountclassid = rows.get(0).getLong("sa_accountclassid");
  799. long type = rows.get(0).getLong("type");
  800. Rows rowsaccountbalance = dbConnect.runSqlQuery("select sa_accountbalanceid,balance,creditquota,ifnull(discountamount,0) discountamount from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  801. //System.out.println("select sa_accountbalanceid,balance,creditquota from sa_accountbalance where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  802. if (type == 1) {
  803. Rows offsettingRows = dbConnect.runSqlQuery("select amount from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + rows.get(0).getLong("ownerid"));
  804. if (offsettingRows.isNotEmpty()) {
  805. 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"));
  806. }
  807. if (rowsaccountbalance.isEmpty()) {
  808. return getErrReturnObject().setErrMsg("该营销账户不存在,收入凭证无法反审核")
  809. .toString();
  810. } else {
  811. BigDecimal canuseamount = rowsaccountbalance.get(0).getBigDecimal("creditquota").add(rowsaccountbalance.get(0).getBigDecimal("balance")).add(rowsaccountbalance.get(0).getBigDecimal("discountamount"));
  812. if (rows.get(0).getBigDecimal("amount").compareTo(canuseamount) == 1) {
  813. return getErrReturnObject().setErrMsg("该营销账户可用余额不足,收入凭证无法反审核")
  814. .toString();
  815. }
  816. BigDecimal newbalance = rowsaccountbalance.get(0).getBigDecimal("balance").subtract(rows.get(0).getBigDecimal("amount"));
  817. balance = newbalance;
  818. discountamount= rowsaccountbalance.get(0).getBigDecimal("discountamount").subtract(rows.get(0).getBigDecimal("discountamount"));
  819. sqlList.add("update sa_accountbalance set balance='" + newbalance + "',discountamount="+discountamount+",changedate=CURRENT_TIME,changeby ='" + username + "',changeuserid='" + userid + "' where sys_enterpriseid ='" + sys_enterpriseid + "' and sa_accountclassid='" + sa_accountclassid + "' and siteid='" + siteid + "'");
  820. }
  821. sqlList.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "反审核", "收入凭证反审核成功").getSQL());
  822. }
  823. }
  824. SQLFactory sqlFactoryupdate = new SQLFactory(this, "收支凭证反审核");
  825. sqlFactoryupdate.addParameter("siteid", siteid);
  826. sqlFactoryupdate.addParameter("sa_cashbillid", sa_cashbillid);
  827. sqlFactoryupdate.addParameter("balance", balance);
  828. sqlList.add(sqlFactoryupdate.getSQL());
  829. dbConnect.runSqlUpdate(sqlList);
  830. return getSucReturnObject().toString();
  831. }
  832. @API(title = "删除", apiversion = R.ID20221009103203.v1.class)
  833. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  834. public String delete() throws YosException {
  835. JSONArray sa_cashbillids = content.getJSONArray("sa_cashbillids");
  836. BatchDeleteErr batchDeleteErr = BatchDeleteErr.create(this, sa_cashbillids.size());
  837. for (Object o : sa_cashbillids) {
  838. long sa_cashbillid = Long.parseLong(o.toString());
  839. Rows RowsStatus = dbConnect.runSqlQuery("select billno,class,subclass,amount,status,sa_cashbillid,source,sourcenote,remarks from sa_cashbill where siteid='"
  840. + siteid + "' and sa_cashbillid='" + sa_cashbillid + "'");
  841. ArrayList<String> list = new ArrayList<>();
  842. if (RowsStatus.isNotEmpty()) {
  843. if (!RowsStatus.get(0).getString("status").equals("新建")) {
  844. batchDeleteErr.addErr(sa_cashbillid, "非新建状态的凭证无法删除");
  845. continue;
  846. }
  847. list.add(DataContrlLog.createLog(this, "sa_cashbill", sa_cashbillid, "删除", RowsStatus.get(0).toString()).getSQL());
  848. }
  849. list.add("delete from sa_cashbill where siteid='" + siteid
  850. + "' and sa_cashbillid=" + sa_cashbillid);
  851. dbConnect.runSqlUpdate(list);
  852. }
  853. ClearData.clearCashbill(this);
  854. return batchDeleteErr.getReturnObject().toString();
  855. }
  856. @API(title = "审核状态的收支凭证详情列表", apiversion = R.ID20221022161304.v1.class)
  857. @CACHEING
  858. public String query_cashnill_audit() throws Exception {
  859. /*
  860. 过滤条件
  861. */
  862. StringBuffer where = new StringBuffer(" 1=1 ");
  863. Long sa_accountclassid = content.getLong("sa_accountclassid");
  864. Long sys_enterpriseid = content.getLong("sys_enterpriseid");
  865. if (content.containsKey("where")) {
  866. JSONObject whereObject = content.getJSONObject("where");
  867. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  868. where.append(" and (t1.billno like '%").append(whereObject.getString("condition")).append("%'");
  869. where.append(" or t3.enterprisename like '%").append(whereObject.getString("condition")).append("%'");
  870. where.append(" or t1.remarks like '%").append(whereObject.getString("condition")).append("%'");
  871. where.append(" or t1.source like '%").append(whereObject.getString("condition")).append("%')");
  872. }
  873. if (whereObject.containsKey("minAmount") && whereObject.getBigDecimal("minAmount").compareTo(new BigDecimal("0")) == 1) {
  874. BigDecimal minAmount = whereObject.getBigDecimal("minAmount");
  875. if (whereObject.containsKey("maxAmount") && whereObject.getBigDecimal("maxAmount").compareTo(new BigDecimal("0")) == 1) {
  876. BigDecimal maxAmount = whereObject.getBigDecimal("maxAmount");
  877. where.append(" and t1.amount between ").append(minAmount).append(" and ").append(maxAmount);
  878. } else {
  879. where.append(" and t1.amount > ").append(minAmount);
  880. }
  881. } else if (whereObject.containsKey("maxAmount") && whereObject.getBigDecimal("maxAmount").compareTo(new BigDecimal("0")) == 1) {
  882. BigDecimal maxAmount = whereObject.getBigDecimal("maxAmount");
  883. where.append(" and t1.amount < ").append(maxAmount);
  884. }
  885. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  886. where.append(" and t1.type = ").append(whereObject.getLong("type"));
  887. }
  888. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  889. where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
  890. }
  891. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  892. where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
  893. }
  894. }
  895. //// boolean isExport = content.getBooleanValue("isExport");
  896. // SQLFactory sqlFactory = new SQLFactory(this, "审核状态的收支凭证详情列表", pageSize, pageNumber, pageSorting);
  897. //// if (isExport) {
  898. //// sqlFactory = new SQLFactory(this, "审核状态的收支凭证详情列表");
  899. //// }
  900. // sqlFactory.addParameter_SQL("where", where);
  901. // sqlFactory.addParameter("sa_accountclassid", sa_accountclassid);
  902. // sqlFactory.addParameter("sys_enterpriseid", sys_enterpriseid);
  903. // sqlFactory.addParameter("siteid", siteid);
  904. // Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  905. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_cashbill", "billno", "type",
  906. "amount","remarks","balance","source","checkby","checkdate","sa_accountclassid");
  907. querySQL.setTableAlias("t1");
  908. querySQL.addQueryFields("type_ch", "if(t1.type=1,'收入','支出')");
  909. querySQL.addQueryFields("unwriteoffamount", "t1.amount - t1.writeoffamount");
  910. querySQL.addJoinTable(JOINTYPE.inner, "sa_accountclass", "t2", "t1.sa_accountclassid = t2.sa_accountclassid and t1.siteid = t2.siteid","accountname");
  911. querySQL.addJoinTable(JOINTYPE.inner, "sys_enterprise", "t3", "t1.sys_enterpriseid = t3.sys_enterpriseid and t1.siteid = t3.siteid","enterprisename");
  912. querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t4", "t1.sys_enterpriseid = t4.sys_enterpriseid AND t1.siteid = t4.siteid","agentnum");
  913. querySQL.setSiteid(siteid);
  914. querySQL.setWhere("t1.status = '审核'");
  915. querySQL.setWhere("t1.sa_accountclassid",sa_accountclassid);
  916. querySQL.setWhere("t1.sys_enterpriseid",sys_enterpriseid);
  917. querySQL.setWhere(where.toString());
  918. querySQL.setPage(pageSize, pageNumber);
  919. Rows rows = querySQL.query();
  920. // if (isExport) {
  921. // //去除不需要导出项
  922. // rows.getFieldList().remove("sa_accountclassid");
  923. // rows.getFieldList().remove("unwriteoffamount");
  924. // rows.getFieldList().remove("agentnum");
  925. // rows.getFieldList().remove("type");
  926. // Rows uploadRows = uploadExcelToObs("cashBill", "审核状态的收支凭证详情列表", rows, getTitleMap_audit());
  927. // return getSucReturnObject().setData(uploadRows).toString();
  928. // }
  929. return getSucReturnObject().setData(rows).toString();
  930. }
  931. //返回导出的标题
  932. public HashMap<String, String> getTitleMap_audit() {
  933. HashMap<String, String> titleMap = new HashMap<>();
  934. titleMap.put("billno", "凭证编号");
  935. titleMap.put("enterprisename", "企业名称");
  936. titleMap.put("type_ch", "收支类型");
  937. titleMap.put("accountname", "账户名称");
  938. titleMap.put("amount", "收支金额");
  939. titleMap.put("remarks", "备注");
  940. titleMap.put("source", "凭证来源");
  941. titleMap.put("checkby", "审核人");
  942. titleMap.put("checkdate", "审核时间");
  943. return titleMap;
  944. }
  945. @API(title = "资金流水账列表查询", apiversion = R.ID20230111103403.v1.class)
  946. @CACHEING
  947. public String query_cashBill() throws YosException, IOException {
  948. /*
  949. 过滤条件
  950. */
  951. Long sa_accountclassid = content.getLong("sa_accountclassid");
  952. if (content.containsKey("sys_enterpriseid")) {
  953. sys_enterpriseid = content.getLong("sys_enterpriseid");
  954. }
  955. Map<String, Rows> map = new HashMap<String, Rows>();
  956. /**
  957. * 过滤条件设置
  958. */
  959. String where = " 1=1 ";
  960. if (content.containsKey("where")) {
  961. JSONObject whereObject = content.getJSONObject("where");
  962. if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
  963. where = where + " and(t1.class like '%" + whereObject.getString("condition")
  964. + "%' or t1.subclass like '%" + whereObject.getString("condition")
  965. + "%' or t1.billno like '%" + whereObject.getString("condition")
  966. + "%' or t1.remarks like '%" + whereObject.getString("condition") + "%')";
  967. }
  968. if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
  969. where = where + " and DATE_FORMAT(t1.checkdate,'%Y-%m-%d') >=DATE_FORMAT('" + whereObject.getString("begindate") + "','%Y-%m-%d')";
  970. }
  971. if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
  972. where = where + " and DATE_FORMAT(t1.checkdate,'%Y-%m-%d') <=DATE_FORMAT('" + whereObject.getString("enddate") + "','%Y-%m-%d')";
  973. }
  974. if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
  975. where = where + " and t1.type ='" + whereObject.getString("type") + "' ";
  976. }
  977. if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
  978. where = where + " and t1.class ='" + whereObject.getString("class") + "' ";
  979. }
  980. if (whereObject.containsKey("class") && !"".equals(whereObject.getString("class"))) {
  981. where = where + " and t1.class ='" + whereObject.getString("class") + "' ";
  982. }
  983. if (whereObject.containsKey("subclass") && !"".equals(whereObject.getString("subclass"))) {
  984. where = where + " and t1.subclass ='" + whereObject.getString("subclass") + "' ";
  985. }
  986. }
  987. /**
  988. * SQL资金流水账查询参数设置并查询
  989. */
  990. // boolean isExport = content.getBooleanValue("isExport");
  991. // SQLFactory factory = new SQLFactory(this, "资金流水账查询", pageSize, pageNumber, pageSorting);
  992. //// if (isExport) {
  993. //// factory = new SQLFactory(this, "资金流水账查询导出");
  994. //// }
  995. // factory.addParameter("sys_enterpriseid", sys_enterpriseid);
  996. // factory.addParameter("sa_accountclassid", sa_accountclassid);
  997. // factory.addParameter("siteid", siteid);
  998. // factory.addParameter_SQL("where", where);
  999. // Rows rows = dbConnect.runSqlQuery(factory.getSQL());
  1000. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_cashbill", "billno", "type",
  1001. "class","subclass","amount","remarks","source","sourcenote","ownerid","ownertable","createdate","createby","checkby","checkdate","sa_accountclassid");
  1002. querySQL.setTableAlias("t1");
  1003. querySQL.addQueryFields("balance", "ifnull(t1.balance,0)");
  1004. querySQL.addJoinTable(JOINTYPE.inner, "sa_accountclass", "t4", "t1.sa_accountclassid = t4.sa_accountclassid and t1.siteid = t4.siteid","accountname");
  1005. querySQL.setSiteid(siteid);
  1006. querySQL.setWhere("t1.status = '审核'");
  1007. querySQL.setWhere("t1.sa_accountclassid",sa_accountclassid);
  1008. querySQL.setWhere("t1.sys_enterpriseid",sys_enterpriseid);
  1009. querySQL.setWhere(where);
  1010. querySQL.setPage(pageSize, pageNumber);
  1011. querySQL.setOrderBy(pageSorting);
  1012. Rows rows = querySQL.query();
  1013. // if (isExport) {
  1014. // //去除不需要导出项
  1015. // rows.getFieldList().remove("sa_accountclassid");
  1016. // Rows uploadRows = uploadExcelToObs("cashBill", "资金流水账列表", rows, getTitleMap());
  1017. // return getSucReturnObject().setData(uploadRows).toString();
  1018. // }
  1019. /**
  1020. * SQL资金流水账汇总信息查询参数设置并查询
  1021. */
  1022. SQLFactory factoryhz = new SQLFactory(this, "资金流水账查询汇总");
  1023. factoryhz.addParameter("sys_enterpriseid", sys_enterpriseid);
  1024. factoryhz.addParameter("sa_accountclassid", sa_accountclassid);
  1025. factoryhz.addParameter("siteid", siteid);
  1026. factoryhz.addParameter_SQL("where", where);
  1027. Rows rowszh = dbConnect.runSqlQuery(factoryhz.getSQL());
  1028. if (!rows.isEmpty()) {
  1029. rows.get(0).put("total", rowszh);
  1030. }
  1031. return getSucReturnObject().setData(rows).toString();
  1032. }
  1033. @API(title = "核销单关联查询", apiversion = R.ID20230224185904.v1.class)
  1034. @CACHEING
  1035. public String querywriteoffamount() throws YosException {
  1036. Long sa_cashbillid = content.getLong("sa_cashbillid");
  1037. // SQLFactory sqlFactory = new SQLFactory(this, "核销单关联查询", pageSize, pageNumber, pageSorting);
  1038. // sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  1039. // sqlFactory.addParameter("siteid", siteid);
  1040. // Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  1041. QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_writeoffbill", "billno", "billnodate",
  1042. "unwriteoffamount","writeoffamount","sys_enterpriseid","status","remarks","createuserid","createby","createdate","changeuserid","checkby","checkdate","changeby","changedate");
  1043. querySQL.setTableAlias("t1");
  1044. querySQL.setSiteid(siteid);
  1045. querySQL.setWhere("t1.sa_cashbillid",sa_cashbillid);
  1046. querySQL.setPage(pageSize, pageNumber);
  1047. Rows rows = querySQL.query();
  1048. return getSucReturnObject().setData(rows).toString();
  1049. }
  1050. @API(title = "收入凭证对冲生成", apiversion = R.ID20230306102904.v1.class)
  1051. @CACHEING_CLEAN(apiversions = {R.ID20221009102903.v1.class, R.ID20221010102903.v1.class, R.ID20221009103003.v1.class, R.ID20230111103403.v1.class})
  1052. public String cashbilloffsetting() throws YosException {
  1053. Long sa_cashbillid = content.getLong("sa_cashbillid");
  1054. SQLFactory sqlFactory = new SQLFactory(this, "收支凭证详情查询");
  1055. sqlFactory.addParameter("siteid", siteid);
  1056. sqlFactory.addParameter("sa_cashbillid", sa_cashbillid);
  1057. Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL());
  1058. if (rows.isEmpty()) {
  1059. return getErrReturnObject().setErrMsg("无效收入凭证").toString();
  1060. }
  1061. if (rows.get(0).getLong("type") == 0) {
  1062. return getErrReturnObject().setErrMsg("支出凭证不能生成对冲").toString();
  1063. }
  1064. if (!rows.get(0).getString("status").equals("审核")) {
  1065. return getErrReturnObject().setErrMsg("非审核状态不能生成对冲").toString();
  1066. }
  1067. if (rows.get(0).getBigDecimal("unwriteoffamount").compareTo(new BigDecimal(0)) < 1) {
  1068. return getErrReturnObject().setErrMsg("未核销金额必须大于0").toString();
  1069. }
  1070. if (dbConnect.runSqlQuery("select 1 from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and sa_cashbillid=" + sa_cashbillid).isNotEmpty()) {
  1071. return getErrReturnObject().setErrMsg("该凭证已生成对冲凭证").toString();
  1072. }
  1073. if (dbConnect.runSqlQuery("select 1 from sa_cashbill where siteid='" + siteid + "' and ownertable='sa_cashbill' and ownerid=" + sa_cashbillid).isNotEmpty()) {
  1074. return getErrReturnObject().setErrMsg("该凭证已生成对冲凭证").toString();
  1075. }
  1076. Long offsettingCashbillid = createTableID("sa_cashbill");
  1077. sqlFactory = new SQLFactory(this, "收支凭证新增");
  1078. sqlFactory.addParameter("siteid", siteid);
  1079. sqlFactory.addParameter("userid", userid);
  1080. sqlFactory.addParameter("username", username);
  1081. sqlFactory.addParameter("sa_cashbillid", offsettingCashbillid);
  1082. sqlFactory.addParameter("billno", createBillCode("cashbill"));
  1083. sqlFactory.addParameter("sys_enterpriseid", rows.get(0).getLong("sys_enterpriseid"));
  1084. sqlFactory.addParameter("sa_accountclassid", rows.get(0).getLong("sa_accountclassid"));
  1085. sqlFactory.addParameter("type", rows.get(0).getLong("type"));
  1086. sqlFactory.addParameter("remarks", "凭证对冲");
  1087. sqlFactory.addParameter("amount", rows.get(0).getBigDecimal("unwriteoffamount").negate());
  1088. sqlFactory.addParameter("source", rows.get(0).getString("amount"));
  1089. sqlFactory.addParameter("sourcenote", rows.get(0).getString("sourcenote"));
  1090. sqlFactory.addParameter("subclass", rows.get(0).getString("subclass"));
  1091. sqlFactory.addParameter("class", rows.get(0).getString("class"));
  1092. sqlFactory.addParameter("ownertable", "sa_cashbill");
  1093. sqlFactory.addParameter("ownerid", sa_cashbillid);
  1094. dbConnect.runSqlUpdate(sqlFactory.getSQL());
  1095. content.put("sa_cashbillid", offsettingCashbillid);
  1096. return queryCashbillMain();
  1097. }
  1098. public Object getCellFormatValue(Cell cell) {
  1099. Object cellValue = null;
  1100. if (cell != null) {
  1101. // 判断cell类型
  1102. CellType cellType = cell.getCellType();
  1103. switch (cellType) {
  1104. case NUMERIC: {
  1105. if (DateUtil.isCellDateFormatted(cell)) {
  1106. short num = cell.getCellStyle().getDataFormat();
  1107. String format = "YYYY-mm-dd";
  1108. SimpleDateFormat df = new SimpleDateFormat(format);
  1109. cellValue = df.format(cell.getDateCellValue());
  1110. } else {
  1111. cell.setCellType(CellType.STRING); // 将数值型cell设置为string型
  1112. cellValue = cell.getStringCellValue();
  1113. }
  1114. break;
  1115. }
  1116. case FORMULA: {
  1117. // 判断cell是否为日期格式
  1118. if (DateUtil.isCellDateFormatted(cell)) {
  1119. // 转换为日期格式YYYY-mm-dd
  1120. cellValue = cell.getDateCellValue();
  1121. } else {
  1122. // 数字
  1123. cellValue = String.valueOf(cell.getNumericCellValue());
  1124. }
  1125. break;
  1126. }
  1127. case STRING: {
  1128. cellValue = cell.getRichStringCellValue().getString();
  1129. break;
  1130. }
  1131. default:
  1132. cellValue = cell.getRichStringCellValue().getString();
  1133. break;
  1134. }
  1135. } else {
  1136. cellValue = "";
  1137. }
  1138. return cellValue;
  1139. }
  1140. public XSSFSheet addSheetIncome(ExcelFactory excelFactory, String sheetname, Rows datarows,
  1141. HashMap<String, String> titlemap) {
  1142. ArrayList<String> keylist = datarows.getFieldList();
  1143. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  1144. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  1145. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  1146. XSSFFont font = xssfFWorkbook.createFont();
  1147. font.setColor((short) 0xa);
  1148. font.setFontHeightInPoints((short) 12);
  1149. font.setBold(true);
  1150. xssfCellStyle1.setFont(font);
  1151. IncomeExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  1152. XSSFCellStyle titleCellStyle1 = IncomeExportExcel.createTitleCellStyle1(xssfFWorkbook);
  1153. XSSFCellStyle titleCellStyle2 = IncomeExportExcel.createTitleCellStyle2(xssfFWorkbook);
  1154. XSSFCellStyle titleCellStyle3 = IncomeExportExcel.createTitleCellStyle3(xssfFWorkbook);
  1155. IncomeExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  1156. for (int n = 0; n < datarows.size(); n++) {
  1157. Row row = datarows.get(n);
  1158. XSSFRow datarow = sheet.createRow(n + 3);
  1159. for (int i1 = 0; i1 < keylist.size(); i1++) {
  1160. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  1161. if (fieldclazztype == Integer.class) {
  1162. datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)));
  1163. } else if (fieldclazztype == Long.class) {
  1164. datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
  1165. } else if (fieldclazztype == Float.class) {
  1166. datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
  1167. } else if (fieldclazztype == Double.class) {
  1168. datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
  1169. } else {
  1170. datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
  1171. }
  1172. if (i1 == 7) {
  1173. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  1174. }
  1175. }
  1176. }
  1177. return sheet;
  1178. }
  1179. public XSSFSheet addSheetPay(ExcelFactory excelFactory, String sheetname, Rows datarows,
  1180. HashMap<String, String> titlemap) {
  1181. ArrayList<String> keylist = datarows.getFieldList();
  1182. XSSFSheet sheet = excelFactory.getXssfWorkbook().createSheet(sheetname);
  1183. XSSFWorkbook xssfFWorkbook = excelFactory.getXssfWorkbook();
  1184. XSSFCellStyle xssfCellStyle1 = xssfFWorkbook.createCellStyle();
  1185. XSSFFont font = xssfFWorkbook.createFont();
  1186. font.setColor((short) 0xa);
  1187. font.setFontHeightInPoints((short) 12);
  1188. font.setBold(true);
  1189. xssfCellStyle1.setFont(font);
  1190. PayExportExcel.setBatchDetailSheetColumn2(sheet);// 设置工作薄列宽
  1191. XSSFCellStyle titleCellStyle1 = PayExportExcel.createTitleCellStyle1(xssfFWorkbook);
  1192. XSSFCellStyle titleCellStyle2 = PayExportExcel.createTitleCellStyle2(xssfFWorkbook);
  1193. XSSFCellStyle titleCellStyle3 = PayExportExcel.createTitleCellStyle3(xssfFWorkbook);
  1194. PayExportExcel.batchDetailErr(sheet, titleCellStyle1, titleCellStyle2, titleCellStyle3, xssfFWorkbook);// 写入标题
  1195. for (int n = 0; n < datarows.size(); n++) {
  1196. Row row = datarows.get(n);
  1197. XSSFRow datarow = sheet.createRow(n + 3);
  1198. for (int i1 = 0; i1 < keylist.size(); i1++) {
  1199. Class fieldclazztype = datarows.getFieldMeta(keylist.get(i1)).getFieldtype();
  1200. if (fieldclazztype == Integer.class) {
  1201. datarow.createCell(i1).setCellValue(row.getInteger((String) keylist.get(i1)));
  1202. } else if (fieldclazztype == Long.class) {
  1203. datarow.createCell(i1).setCellValue(row.getLong((String) keylist.get(i1)));
  1204. } else if (fieldclazztype == Float.class) {
  1205. datarow.createCell(i1).setCellValue(row.getFloat((String) keylist.get(i1)));
  1206. } else if (fieldclazztype == Double.class) {
  1207. datarow.createCell(i1).setCellValue(row.getDouble((String) keylist.get(i1)));
  1208. } else {
  1209. datarow.createCell(i1).setCellValue(row.getString((String) keylist.get(i1)));
  1210. }
  1211. if (i1 == 7) {
  1212. datarow.getCell(i1).setCellStyle(xssfCellStyle1);
  1213. }
  1214. }
  1215. }
  1216. return sheet;
  1217. }
  1218. //返回导出的标题
  1219. public HashMap<String, String> getTitleMap() {
  1220. HashMap<String, String> titleMap = new HashMap<>();
  1221. titleMap.put("billno", "凭证编号");
  1222. titleMap.put("type", "收支类型");
  1223. titleMap.put("accountname", "账户名称");
  1224. titleMap.put("amount", "收支金额");
  1225. titleMap.put("balance", "账户结余");
  1226. titleMap.put("source", "凭证来源");
  1227. titleMap.put("class", "分类");
  1228. titleMap.put("subclass", "分类明细");
  1229. titleMap.put("remarks", "备注");
  1230. titleMap.put("checkby", "审核人");
  1231. titleMap.put("checkdate", "审核时间");
  1232. return titleMap;
  1233. }
  1234. /**
  1235. * 判断是否在同一个月
  1236. *
  1237. * @return false:不在同一个月内,true在同一个月内
  1238. */
  1239. public boolean isMonth(Date date1, Date date2) {
  1240. Calendar calendar1 = Calendar.getInstance();
  1241. calendar1.setTime(date1);
  1242. Calendar calendar2 = Calendar.getInstance();
  1243. calendar2.setTime(date2);
  1244. int year1 = calendar1.get(Calendar.YEAR);
  1245. int year2 = calendar2.get(Calendar.YEAR);
  1246. int month1 = calendar1.get(Calendar.MONTH);
  1247. int month2 = calendar2.get(Calendar.MONTH);
  1248. return calendar1.get(Calendar.YEAR) == calendar2.get(Calendar.YEAR) && calendar1.get(Calendar.MONTH) == calendar2.get(Calendar.MONTH);
  1249. }
  1250. public void sendMsg(String content, Long sa_cashbillid, Long sys_enterpriseid) throws YosException {
  1251. ArrayList<Long> userList = getEnterpriseHrs(sys_enterpriseid).toArrayList("userid", new ArrayList<>());
  1252. Remind remind = new Remind(this);
  1253. remind.setTitle("收支凭证消息");
  1254. remind.setContent(content);
  1255. remind.setType("应用");
  1256. remind.setObjectid(sa_cashbillid);
  1257. remind.setObjectname("sa_cashbill");
  1258. remind.setTouserid(userList);
  1259. remind.sendByDialogMsg().createSys_message();
  1260. }
  1261. public boolean isValidFormat(String date) throws ParseException {
  1262. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
  1263. dateFormat.setLenient(false); // 设置解析日期时是否宽松,即是否允许解析不严格符合格式的日期字符串
  1264. try {
  1265. Date parsedDate = dateFormat.parse(date);
  1266. return true;
  1267. } catch (ParseException e) {
  1268. return false;
  1269. }
  1270. }
  1271. }