Advertisement
Guest User

bozo6

a guest
Nov 7th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.07 KB | None | 0 0
  1. // start namespace ixbob
  2.  
  3. var ixbob = new Object();
  4. ixbob = {
  5.  
  6. /**
  7. * Return the Mandant used in Bob from the Data\Common\Companiy.adt
  8. * @ConnectId Connection Id for the COMMON Database of Bob
  9. * @return null on error.
  10. */
  11. getCompanys: function (ConnectId) {
  12.  
  13. var data;
  14.  
  15. if (log.isDebugEnabled()) log.debug("getCompanys(");
  16.  
  17. try {
  18. data = db.getMultiLine(ConnectId, "SELECT ID, NAME, PATH FROM company");
  19. }
  20. catch(e) {
  21. var error = e;
  22. data = null;
  23. log.error("Error getting BOB Mandanten: " + error);
  24. }
  25.  
  26. return data;
  27.  
  28. if (log.isDebugEnabled()) log.debug(")getCompanys");
  29. },
  30. /**
  31. * Return the Mandant used in Bob from the Data\Common\Companiy.adt
  32. * @ConnectId Connection Id for the COMMON Database of Bob
  33. * @CompanyId BOB Company number (reference)
  34. * @return null on error.
  35. */
  36. getCompanyById: function (ConnectId, CompanyId) {
  37.  
  38. var data;
  39. var sqlQuery;
  40.  
  41.  
  42. if (log.isDebugEnabled()) log.debug("getCompanyById(");
  43.  
  44. try
  45. {
  46. sqlQuery = "SELECT ID, NAME, PATH FROM COMPANY WHERE ID = '" + CompanyId + "'";
  47. data = db.getMultiLine(ConnectId, sqlQuery, 10);
  48. }
  49. catch(e) {
  50. var error = e;
  51. data = null;
  52. log.error("Error getting BOB Mandanten: " + error);
  53. }
  54.  
  55. return data;
  56.  
  57. if (log.isDebugEnabled()) log.debug(")getCompanys");
  58. },
  59.  
  60. /**
  61. * Open a custom connection to the Bob Folder indicate by the Mandant URL
  62. * @ConnectId Connection Id for the FOLDER Database of Bob
  63. * @strURL The complete JDBC connectionString to the FOLDER database of Bob
  64. * @throws an Exception on Error
  65. */
  66. openConnection: function (connectId, strPath) {
  67.  
  68. log.debug("openConnection(");
  69.  
  70. if (EM_connections[connectId].initdone == true) {
  71. return;
  72. }
  73.  
  74. log.debug("Now init JDBC driver");
  75.  
  76. var driverName = EM_connections[connectId].driver;
  77. //var dbUrl = EM_connections[connectId].url;
  78. var strURL = EM_connections[connectId].url;
  79. var dbUrl = strURL.replace("#PATH#", strPath);
  80.  
  81. var dbUser = EM_connections[connectId].user;
  82. var dbPassword = EM_connections[connectId].password;
  83.  
  84. if (emConnect.decryptAs) {
  85. dbPassword = emConnect.decryptAs(dbPassword);
  86. }
  87.  
  88. try {
  89.  
  90. if (!EM_connections[connectId].classloaded) {
  91. Class.forName(driverName).newInstance();
  92.  
  93. log.debug("Register driver JDBC");
  94. //DriverManager.registerDriver(new JdbcOdbcDriver());
  95. EM_connections[connectId].classloaded = true;
  96. }
  97.  
  98. log.debug("Get Connection");
  99. EM_connections[connectId].dbcn = DriverManager.getConnection(dbUrl, dbUser, dbPassword);
  100.  
  101. log.debug("Init done.");
  102.  
  103. } catch (e) {
  104. log.debug("ODBC Exception: " + e);
  105. throw e;
  106. }
  107.  
  108. EM_connections[connectId].initdone = true;
  109.  
  110. log.debug(")openConnection");
  111. },
  112.  
  113. /**
  114. * Close a custom connection to the Bob Folder indicate by the Mandant URL
  115. * @ConnectId Connection Id for the FOLDER Database of Bob
  116. */
  117. closeConnection: function (connectId) {
  118.  
  119. log.debug("closeConnection(");
  120.  
  121. if (EM_connections[connectId].initdone) {
  122.  
  123. if (EM_connections[connectId].dbcn) {
  124.  
  125. try {
  126.  
  127. EM_connections[connectId].dbcn.close();
  128. EM_connections[connectId].initdone = false;
  129. log.debug("Connection closed: " + connectId);
  130.  
  131. } catch (e) {
  132. log.info("Error closing database " + connectId + ": " + e);
  133. }
  134. }
  135. }
  136.  
  137. log.debug(")closeConnection");
  138. },
  139.  
  140. /**
  141. * Return the Mandant used in Bob from the Data\Common\Companiy.adt
  142. * @ConnectId Connection Id for the FOLDER Database of Bob
  143. * @strBarcode The Barcode Data to identify the document
  144. * @return null on error.
  145. */
  146. getDocumentData: function (ConnectId, strBarcode) {
  147.  
  148. var data = null;
  149. var strSQL;
  150.  
  151. if (log.isDebugEnabled()) log.debug("getDocumentData(");
  152.  
  153. try {
  154.  
  155. strSQL = "SELECT HID, HDBK, HFYEAR, HYear, HMonth, HDocNo, HRemInt, HRemExt, abs(HAmount) as HAmount, abs(HBase) as HBase, abs(HTax) as HTax, HDocDate, MODIFIEDBY, MODIFIEDON, HNOTVALIDATED, HPROCSTATUS \
  156. FROM ac_chisto \
  157. WHERE HRemInt LIKE '%" + strBarcode + "%' \
  158. ORDER BY HDocNo DESC";
  159. if (log.isDebugEnabled()) log.debug(strSQL);
  160. data = db.getLine(ConnectId, strSQL);
  161. }
  162. catch(e) {
  163. var error = e;
  164. data = null;
  165. log.error("Error getting BOB Document data: " + error);
  166. }
  167.  
  168. return data;
  169.  
  170. if (log.isDebugEnabled()) log.debug(")getDocumentData");
  171. },
  172. /**
  173. * Returns Data from the ac_chisto.adt
  174. * @ConnectId Connection Id for the FOLDER Database of Bob
  175. * @strInvNo InvNumber in the field HRemInt
  176. * @strVendorId Id of the vendor according to invoice
  177. * @return null on error.
  178. */
  179. getDocumentDataByNumber: function (ConnectId, strInvNo, strVendorId) {
  180.  
  181. var data;
  182. var strSQL;
  183.  
  184. if (log.isDebugEnabled()) log.debug("getDocumentDataByNumber");
  185.  
  186. try {
  187.  
  188. strSQL = "SELECT ac_chisto.HDBK, ac_ahisto.HORDERNO, ac_ahisto.HID, ac_chisto.HDOCNO, \
  189. ac_ahisto.HAMOUNT, ac_ahisto.MODIFIEDBY, ac_ahisto.MODIFIEDON \
  190. FROM ac_chisto \
  191. JOIN ac_ahisto ON ac_chisto.HDOCNO = ac_ahisto.HDOCNO \
  192. AND ac_chisto.HDBK = ac_ahisto.HDBK \
  193. AND ac_chisto.HFYEAR = ac_ahisto.HFYEAR AND ac_chisto.HMONTH = ac_ahisto.HMONTH \
  194. WHERE (ac_chisto.HREMINT LIKE '%" + strInvNo + "%' \
  195. OR ac_chisto.HREMEXT LIKE '%" + strInvNo + "%') \
  196. AND ac_chisto.HID LIKE '" + strVendorId + "' \
  197. AND ac_ahisto.HORDERNO = 2";
  198.  
  199. data = db.getLine(ConnectId, strSQL);
  200. }
  201. catch(e) {
  202. var error = e;
  203. data = null;
  204. log.error("Error getting BOB Document data: " + error);
  205. }
  206.  
  207. return data;
  208.  
  209. if (log.isDebugEnabled()) log.debug("getDocumentDataByNumber");
  210. },
  211.  
  212. /**
  213. * Returns Data from the ac_chisto.adt
  214. * @ConnectId Connection Id for the FOLDER Database of Bob
  215. * @datInvDate Date of the document
  216. * @strVendorId Id of the vendor according to invoice
  217. * @numAmount Total Amount of the invoice
  218. * @return null on error.
  219. */
  220. getInvoiceDataBy: function (ConnectId, datInvDate, strVendorId, numAmount) {
  221.  
  222. var data;
  223. var strSQL;
  224. var m = datInvDate.substring(3,2);
  225. var d = datInvDate.substring(0,2);
  226. var y = datInvDate.substring(6,4);
  227.  
  228. if (log.isDebugEnabled()) log.debug("getInvoiceDataBy");
  229.  
  230. try {
  231.  
  232. strSQL = "SELECT ac_chisto.HDBK, ac_ahisto.HORDERNO, ac_ahisto.HID, ac_chisto.HDOCNO, \
  233. ac_ahisto.HAMOUNT, ac_ahisto.MODIFIEDBY, ac_ahisto.MODIFIEDON \
  234. FROM ac_chisto \
  235. JOIN ac_ahisto ON ac_chisto.HDOCNO = ac_ahisto.HDOCNO \
  236. AND ac_chisto.HDBK = ac_ahisto.HDBK \
  237. AND ac_chisto.HFYEAR = ac_ahisto.HFYEAR AND ac_chisto.HMONTH = ac_ahisto.HMONTH \
  238. WHERE ac_chisto.HAMOUNT = 1288.38 AND ac_chisto.HORDERNO = 2 AND ac_chisto.HDOCDATE = {d '2013-10-31'} AND ac_chisto.HID LIKE '" + strVendorId + "' ";
  239.  
  240. data = db.getLine(ConnectId, strSQL);
  241. }
  242. catch(e) {
  243. var error = e;
  244. data = null;
  245. log.error("Error getting BOB Invoice data: " + error);
  246. }
  247.  
  248. return data;
  249.  
  250. if (log.isDebugEnabled()) log.debug("getInvoiceDataBy");
  251. },
  252.  
  253. /**
  254. * Return the Mandant used in Bob from the Data\Common\Companiy.adt
  255. * @ConnectId Connection Id for the FOLDER Database of Bob
  256. * @strBarcode The Barcode Data to identify the document
  257. * @return null on error.
  258. */
  259. getSupplierData: function (ConnectId, strCID) {
  260.  
  261. var data;
  262. var strSQL;
  263.  
  264. if (log.isDebugEnabled()) log.debug("getDocumentData(");
  265.  
  266. try {
  267.  
  268. strSQL = "SELECT CNAME1, CVATREF, CVATNO, CID, CSUPTYPE \
  269. FROM ac_compan \
  270. WHERE CID = '" + strCID + "'";
  271.  
  272. data = db.getLine(ConnectId, strSQL);
  273. }
  274. catch(e) {
  275. var error = e;
  276. data = null;
  277. log.error("Error getting BOB Supplier data: " + error);
  278. }
  279.  
  280. return data;
  281.  
  282. if (log.isDebugEnabled()) log.debug(")getDocumentData");
  283. },
  284.  
  285. /**
  286. * Unblocks the invoice in Bob.
  287. * Update fields in ac_chisto.adt and ac_kh%JOURNAL%.adt (ex: ac_khafg.adt or ac_khnca.adt
  288. * Using the BobId AND the barcode to update in Bob.
  289. */
  290.  
  291. unblockInvoice: function (ConnectId, BobId, barcode, journal) {
  292.  
  293. var strSQL;
  294.  
  295. if (log.isDebugEnabled()) log.debug("unblockInvoice(");
  296.  
  297. var result = 0;
  298.  
  299. try {
  300. // update ac_khXXX.adt
  301. log.debug("update ac_kh" + journal + ".adt");
  302. strSQL = "Update ac_kh" + journal + " \
  303. SET [TISBLOCKED] = False, \
  304. [TPROCSTATUS] = '' \
  305. WHERE (TDOCNO = " + BobId + ")";
  306.  
  307. db.doUpdate(ConnectId, strSQL);
  308.  
  309. // update ac_chisto.adt
  310. log.debug("update ac_chisto.adt");
  311. strSQL = "Update ac_chisto \
  312. SET [HPROCSTATUS] = '' \
  313. WHERE (HDOCNO = " + BobId + ") \
  314. AND (HREMINT = '" + barcode + "')";
  315.  
  316. db.doUpdate(ConnectId, strSQL);
  317.  
  318. if (log.isDebugEnabled()) log.debug(")unblockInvoice");
  319.  
  320. result = 1;
  321. return result;
  322. }
  323. catch(e) {
  324. var error = e;
  325. log.error("Error unblocking invoice in Bob: " + error);
  326. }
  327. },
  328.  
  329. /**
  330. * Adds the link to the physical document to BOB.
  331. * Update fields in ac_linkdoc.adt
  332. * Using the vendorNumber, periodYear, Journal, and BobId insert in Bob.
  333. */
  334.  
  335. attachFileToDocument: function (ConnectId, vendorNumber, periodYear, Journal, BobId, fileName) {
  336.  
  337. var strSQL;
  338.  
  339. if (log.isDebugEnabled()) log.debug("attachFileToDocument(");
  340.  
  341. var result = "";
  342.  
  343.  
  344. // insert into ac_linkdoc.adt
  345. log.debug("insert into ac_linkdoc.adt");
  346. strSQL = "INSERT INTO ac_linkdoc (LHTYPE, LHID, LHFYEAR, LHDBK, LHDOCNO, LNAMEDOC) \
  347. VALUES ('S','" + vendorNumber + "','" + periodYear + "','" + Journal + "'," + BobId + ",'" + fileName +"')";
  348.  
  349. db.doUpdate(ConnectId, strSQL);
  350.  
  351. if (log.isDebugEnabled()) log.debug(")attachFileToDocument");
  352.  
  353. result = fileName;
  354.  
  355. return result;
  356.  
  357. },
  358.  
  359. /**
  360. * Gets the link to the physical document from BOB.
  361. * Using the vendorNumber, periodYear, Journal, and BobId insert in Bob.
  362. */
  363.  
  364. getAttachedFileFromDocument: function (ConnectId, vendorNumber, periodYear, Journal, BobId) {
  365.  
  366. var data;
  367. var strSQL;
  368.  
  369. if (log.isDebugEnabled()) log.debug("getAttachedFileFromDocument(");
  370.  
  371. var result = "";
  372.  
  373. try {
  374. log.debug("select from ac_linkdoc.adt");
  375. strSQL = "SELECT * \
  376. FROM ac_linkdoc \
  377. WHERE LHTYPE = 'S' \
  378. AND LHID = '" + vendorNumber + "' \
  379. AND LHFYEAR = '" + periodYear + "' \
  380. AND LHDBK = '" + Journal + "' \
  381. AND LHDOCNO = " + BobId;
  382.  
  383. data = db.getLine(ConnectId, strSQL);
  384.  
  385. if (log.isDebugEnabled()) log.debug(")getAttachedFileFromDocument");
  386.  
  387. result = data;
  388.  
  389. }
  390. catch(e) {
  391. var error = e;
  392. log.error("Error getting the file from Bob: " + error);
  393. }
  394.  
  395. return result;
  396.  
  397. }
  398. }
  399. // end of namespace ixbob
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement