@tomei/finance 0.6.114 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/dist/account/account.d.ts +1 -0
  2. package/dist/account/account.d.ts.map +1 -0
  3. package/dist/account/account.js.map +1 -1
  4. package/dist/account/account.repository.d.ts +1 -0
  5. package/dist/account/account.repository.d.ts.map +1 -0
  6. package/dist/account/account.repository.js +4 -1
  7. package/dist/account/account.repository.js.map +1 -1
  8. package/dist/account/interfaces/account-attr.interface.d.ts +1 -0
  9. package/dist/account/interfaces/account-attr.interface.d.ts.map +1 -0
  10. package/dist/account-system-entity/account-system-entity.d.ts +1 -0
  11. package/dist/account-system-entity/account-system-entity.d.ts.map +1 -0
  12. package/dist/account-system-entity/account-system-entity.js +4 -1
  13. package/dist/account-system-entity/account-system-entity.js.map +1 -1
  14. package/dist/account-system-entity/post-history.repository.d.ts +1 -0
  15. package/dist/account-system-entity/post-history.repository.d.ts.map +1 -0
  16. package/dist/account-system-entity/post-history.repository.js +4 -1
  17. package/dist/account-system-entity/post-history.repository.js.map +1 -1
  18. package/dist/config.d.ts +1 -0
  19. package/dist/config.d.ts.map +1 -0
  20. package/dist/config.js +17 -4
  21. package/dist/config.js.map +1 -1
  22. package/dist/customer/customer.d.ts +1 -0
  23. package/dist/customer/customer.d.ts.map +1 -0
  24. package/dist/customer/customer.js +38 -2
  25. package/dist/customer/customer.js.map +1 -1
  26. package/dist/customer/finance-customer.repository.d.ts +1 -0
  27. package/dist/customer/finance-customer.repository.d.ts.map +1 -0
  28. package/dist/customer/finance-customer.repository.js +4 -1
  29. package/dist/customer/finance-customer.repository.js.map +1 -1
  30. package/dist/customer/interfaces/customer.repository.interface.d.ts +1 -0
  31. package/dist/customer/interfaces/customer.repository.interface.d.ts.map +1 -0
  32. package/dist/customer/interfaces/finance-customer-attr.interface.d.ts +1 -0
  33. package/dist/customer/interfaces/finance-customer-attr.interface.d.ts.map +1 -0
  34. package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +1 -0
  35. package/dist/customer/interfaces/finance-customer.repository.interface.d.ts.map +1 -0
  36. package/dist/database.d.ts +1 -0
  37. package/dist/database.d.ts.map +1 -0
  38. package/dist/database.js +18 -15
  39. package/dist/database.js.map +1 -1
  40. package/dist/document/document-item.d.ts +3 -2
  41. package/dist/document/document-item.d.ts.map +1 -0
  42. package/dist/document/document-item.js +1 -1
  43. package/dist/document/document-item.js.map +1 -1
  44. package/dist/document/document-item.repository.d.ts +1 -0
  45. package/dist/document/document-item.repository.d.ts.map +1 -0
  46. package/dist/document/document-item.repository.js +4 -1
  47. package/dist/document/document-item.repository.js.map +1 -1
  48. package/dist/document/document.d.ts +2 -1
  49. package/dist/document/document.d.ts.map +1 -0
  50. package/dist/document/document.js +242 -191
  51. package/dist/document/document.js.map +1 -1
  52. package/dist/document/document.repository.d.ts +1 -0
  53. package/dist/document/document.repository.d.ts.map +1 -0
  54. package/dist/document/document.repository.js +4 -1
  55. package/dist/document/document.repository.js.map +1 -1
  56. package/dist/document/interfaces/document-attr.interface.d.ts +1 -0
  57. package/dist/document/interfaces/document-attr.interface.d.ts.map +1 -0
  58. package/dist/document/interfaces/document-find-all.interface.d.ts +1 -0
  59. package/dist/document/interfaces/document-find-all.interface.d.ts.map +1 -0
  60. package/dist/document/interfaces/document-item-attr.interface.d.ts +1 -0
  61. package/dist/document/interfaces/document-item-attr.interface.d.ts.map +1 -0
  62. package/dist/document/interfaces/document-item.repository.interface.d.ts +1 -0
  63. package/dist/document/interfaces/document-item.repository.interface.d.ts.map +1 -0
  64. package/dist/document-tag/document-tag.d.ts +19 -0
  65. package/dist/document-tag/document-tag.d.ts.map +1 -0
  66. package/dist/document-tag/document-tag.js +68 -0
  67. package/dist/document-tag/document-tag.js.map +1 -0
  68. package/dist/document-tag/document-tag.repository.d.ts +6 -0
  69. package/dist/document-tag/document-tag.repository.d.ts.map +1 -0
  70. package/dist/document-tag/document-tag.repository.js +15 -0
  71. package/dist/document-tag/document-tag.repository.js.map +1 -0
  72. package/dist/document-tag/interfaces/document-tag-attr.interface.d.ts +8 -0
  73. package/dist/document-tag/interfaces/document-tag-attr.interface.d.ts.map +1 -0
  74. package/dist/document-tag/interfaces/document-tag-attr.interface.js +3 -0
  75. package/dist/document-tag/interfaces/document-tag-attr.interface.js.map +1 -0
  76. package/dist/enum/collect-payment-type.d.ts +1 -0
  77. package/dist/enum/collect-payment-type.d.ts.map +1 -0
  78. package/dist/enum/doc-type.enum.d.ts +1 -0
  79. package/dist/enum/doc-type.enum.d.ts.map +1 -0
  80. package/dist/enum/document-status.enum.d.ts +1 -0
  81. package/dist/enum/document-status.enum.d.ts.map +1 -0
  82. package/dist/enum/index.d.ts +2 -2
  83. package/dist/enum/index.d.ts.map +1 -0
  84. package/dist/enum/index.js +1 -3
  85. package/dist/enum/index.js.map +1 -1
  86. package/dist/enum/payment-method.enum.d.ts +1 -0
  87. package/dist/enum/payment-method.enum.d.ts.map +1 -0
  88. package/dist/enum/payment-status.enum.d.ts +1 -0
  89. package/dist/enum/payment-status.enum.d.ts.map +1 -0
  90. package/dist/enum/payment-type.enum.d.ts +1 -0
  91. package/dist/enum/payment-type.enum.d.ts.map +1 -0
  92. package/dist/enum/quick-book-client-scopes.enum.d.ts +1 -0
  93. package/dist/enum/quick-book-client-scopes.enum.d.ts.map +1 -0
  94. package/dist/enum/quick-book-client-scopes.enum.js +34 -1
  95. package/dist/enum/quick-book-client-scopes.enum.js.map +1 -1
  96. package/dist/enum/transaction-type.enum.d.ts +1 -0
  97. package/dist/enum/transaction-type.enum.d.ts.map +1 -0
  98. package/dist/finance-company/finance-company.d.ts +20 -17
  99. package/dist/finance-company/finance-company.d.ts.map +1 -0
  100. package/dist/finance-company/finance-company.js +89 -23
  101. package/dist/finance-company/finance-company.js.map +1 -1
  102. package/dist/finance-company/finance-company.repository.d.ts +1 -0
  103. package/dist/finance-company/finance-company.repository.d.ts.map +1 -0
  104. package/dist/finance-company/finance-company.repository.js +4 -1
  105. package/dist/finance-company/finance-company.repository.js.map +1 -1
  106. package/dist/helpers/login-user.d.ts +1 -0
  107. package/dist/helpers/login-user.d.ts.map +1 -0
  108. package/dist/helpers/typeof.d.ts +1 -0
  109. package/dist/helpers/typeof.d.ts.map +1 -0
  110. package/dist/index.d.ts +1 -0
  111. package/dist/index.d.ts.map +1 -0
  112. package/dist/index.js +51 -15
  113. package/dist/index.js.map +1 -1
  114. package/dist/interfaces/account-system.interface.d.ts +4 -0
  115. package/dist/interfaces/account-system.interface.d.ts.map +1 -0
  116. package/dist/interfaces/index.d.ts +1 -0
  117. package/dist/interfaces/index.d.ts.map +1 -0
  118. package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +1 -0
  119. package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts.map +1 -0
  120. package/dist/journal-entry/journal-entry.d.ts +1 -0
  121. package/dist/journal-entry/journal-entry.d.ts.map +1 -0
  122. package/dist/journal-entry/journal-entry.js +4 -1
  123. package/dist/journal-entry/journal-entry.js.map +1 -1
  124. package/dist/journal-entry/journal-entry.repository.d.ts +1 -0
  125. package/dist/journal-entry/journal-entry.repository.d.ts.map +1 -0
  126. package/dist/journal-entry/journal-entry.repository.js +4 -1
  127. package/dist/journal-entry/journal-entry.repository.js.map +1 -1
  128. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +1 -0
  129. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts.map +1 -0
  130. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +1 -0
  131. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts.map +1 -0
  132. package/dist/ledger-transaction/ledger-transaction.d.ts +1 -0
  133. package/dist/ledger-transaction/ledger-transaction.d.ts.map +1 -0
  134. package/dist/ledger-transaction/ledger-transaction.repository.d.ts +1 -0
  135. package/dist/ledger-transaction/ledger-transaction.repository.d.ts.map +1 -0
  136. package/dist/ledger-transaction/ledger-transaction.repository.js +4 -1
  137. package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -1
  138. package/dist/models/account.entity.d.ts +1 -0
  139. package/dist/models/account.entity.d.ts.map +1 -0
  140. package/dist/models/account.entity.js +7 -4
  141. package/dist/models/account.entity.js.map +1 -1
  142. package/dist/models/customer.entity.d.ts +1 -0
  143. package/dist/models/customer.entity.d.ts.map +1 -0
  144. package/dist/models/customer.entity.js +4 -1
  145. package/dist/models/customer.entity.js.map +1 -1
  146. package/dist/models/document-item.entity.d.ts +1 -0
  147. package/dist/models/document-item.entity.d.ts.map +1 -0
  148. package/dist/models/document-item.entity.js +5 -2
  149. package/dist/models/document-item.entity.js.map +1 -1
  150. package/dist/models/document-tag.entity.d.ts +14 -0
  151. package/dist/models/document-tag.entity.d.ts.map +1 -0
  152. package/dist/models/document-tag.entity.js +64 -0
  153. package/dist/models/document-tag.entity.js.map +1 -0
  154. package/dist/models/document.entity.d.ts +3 -0
  155. package/dist/models/document.entity.d.ts.map +1 -0
  156. package/dist/models/document.entity.js +12 -4
  157. package/dist/models/document.entity.js.map +1 -1
  158. package/dist/models/finance-company.entity.d.ts +1 -0
  159. package/dist/models/finance-company.entity.d.ts.map +1 -0
  160. package/dist/models/finance-company.entity.js +5 -2
  161. package/dist/models/finance-company.entity.js.map +1 -1
  162. package/dist/models/journal-entry.entity.d.ts +1 -0
  163. package/dist/models/journal-entry.entity.d.ts.map +1 -0
  164. package/dist/models/journal-entry.entity.js +5 -2
  165. package/dist/models/journal-entry.entity.js.map +1 -1
  166. package/dist/models/ledger-transaction.entity.d.ts +1 -0
  167. package/dist/models/ledger-transaction.entity.d.ts.map +1 -0
  168. package/dist/models/ledger-transaction.entity.js +7 -4
  169. package/dist/models/ledger-transaction.entity.js.map +1 -1
  170. package/dist/models/payment-item.entity.d.ts +1 -0
  171. package/dist/models/payment-item.entity.d.ts.map +1 -0
  172. package/dist/models/payment-item.entity.js +4 -1
  173. package/dist/models/payment-item.entity.js.map +1 -1
  174. package/dist/models/payment-method-type.entity.d.ts +1 -0
  175. package/dist/models/payment-method-type.entity.d.ts.map +1 -0
  176. package/dist/models/payment-method-type.entity.js +5 -2
  177. package/dist/models/payment-method-type.entity.js.map +1 -1
  178. package/dist/models/payment-method.entity.d.ts +1 -0
  179. package/dist/models/payment-method.entity.d.ts.map +1 -0
  180. package/dist/models/payment-method.entity.js +5 -2
  181. package/dist/models/payment-method.entity.js.map +1 -1
  182. package/dist/models/payment-paid-with.entity.d.ts +1 -0
  183. package/dist/models/payment-paid-with.entity.d.ts.map +1 -0
  184. package/dist/models/payment-paid-with.entity.js +5 -2
  185. package/dist/models/payment-paid-with.entity.js.map +1 -1
  186. package/dist/models/payment.entity.d.ts +1 -0
  187. package/dist/models/payment.entity.d.ts.map +1 -0
  188. package/dist/models/payment.entity.js +6 -3
  189. package/dist/models/payment.entity.js.map +1 -1
  190. package/dist/models/post-history.entity.d.ts +1 -0
  191. package/dist/models/post-history.entity.d.ts.map +1 -0
  192. package/dist/models/tag-group.entity.d.ts +16 -0
  193. package/dist/models/tag-group.entity.d.ts.map +1 -0
  194. package/dist/models/tag-group.entity.js +95 -0
  195. package/dist/models/tag-group.entity.js.map +1 -0
  196. package/dist/models/tag.entity.d.ts +17 -0
  197. package/dist/models/tag.entity.d.ts.map +1 -0
  198. package/dist/models/tag.entity.js +100 -0
  199. package/dist/models/tag.entity.js.map +1 -0
  200. package/dist/models/tax.entity.d.ts +1 -0
  201. package/dist/models/tax.entity.d.ts.map +1 -0
  202. package/dist/models/tax.entity.js +4 -1
  203. package/dist/models/tax.entity.js.map +1 -1
  204. package/dist/payment/interfaces/payment-attr.interface.d.ts +1 -0
  205. package/dist/payment/interfaces/payment-attr.interface.d.ts.map +1 -0
  206. package/dist/payment/interfaces/payment-params.interface.d.ts +1 -0
  207. package/dist/payment/interfaces/payment-params.interface.d.ts.map +1 -0
  208. package/dist/payment/payment.d.ts +1 -0
  209. package/dist/payment/payment.d.ts.map +1 -0
  210. package/dist/payment/payment.js +5 -2
  211. package/dist/payment/payment.js.map +1 -1
  212. package/dist/payment/payment.repository.d.ts +1 -0
  213. package/dist/payment/payment.repository.d.ts.map +1 -0
  214. package/dist/payment/payment.repository.js +4 -1
  215. package/dist/payment/payment.repository.js.map +1 -1
  216. package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +1 -0
  217. package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts.map +1 -0
  218. package/dist/payment-item/payment-item.d.ts +1 -0
  219. package/dist/payment-item/payment-item.d.ts.map +1 -0
  220. package/dist/payment-item/payment-item.js +4 -4
  221. package/dist/payment-item/payment-item.repository.d.ts +1 -0
  222. package/dist/payment-item/payment-item.repository.d.ts.map +1 -0
  223. package/dist/payment-item/payment-item.repository.js +4 -1
  224. package/dist/payment-item/payment-item.repository.js.map +1 -1
  225. package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts +1 -0
  226. package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts.map +1 -0
  227. package/dist/payment-method/payment-method.d.ts +1 -0
  228. package/dist/payment-method/payment-method.d.ts.map +1 -0
  229. package/dist/payment-method/payment-method.js +4 -1
  230. package/dist/payment-method/payment-method.js.map +1 -1
  231. package/dist/payment-method/payment-method.repository.d.ts +1 -0
  232. package/dist/payment-method/payment-method.repository.d.ts.map +1 -0
  233. package/dist/payment-method/payment-method.repository.js +4 -1
  234. package/dist/payment-method/payment-method.repository.js.map +1 -1
  235. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts +1 -0
  236. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts.map +1 -0
  237. package/dist/payment-method-type/payment-method-type.d.ts +1 -0
  238. package/dist/payment-method-type/payment-method-type.d.ts.map +1 -0
  239. package/dist/payment-method-type/payment-method-type.repository.d.ts +1 -0
  240. package/dist/payment-method-type/payment-method-type.repository.d.ts.map +1 -0
  241. package/dist/payment-method-type/payment-method-type.repository.js +4 -1
  242. package/dist/payment-method-type/payment-method-type.repository.js.map +1 -1
  243. package/dist/payment-paid-with/interfaces/payment-paid-with.interface.d.ts +1 -0
  244. package/dist/payment-paid-with/interfaces/payment-paid-with.interface.d.ts.map +1 -0
  245. package/dist/payment-paid-with/payment-paid-with.d.ts +1 -0
  246. package/dist/payment-paid-with/payment-paid-with.d.ts.map +1 -0
  247. package/dist/payment-paid-with/payment-paid-with.repository.d.ts +1 -0
  248. package/dist/payment-paid-with/payment-paid-with.repository.d.ts.map +1 -0
  249. package/dist/payment-paid-with/payment-paid-with.repository.js +4 -1
  250. package/dist/payment-paid-with/payment-paid-with.repository.js.map +1 -1
  251. package/dist/tag/interfaces/tag-attr.interface.d.ts +14 -0
  252. package/dist/tag/interfaces/tag-attr.interface.d.ts.map +1 -0
  253. package/dist/tag/interfaces/tag-attr.interface.js +3 -0
  254. package/dist/tag/interfaces/tag-attr.interface.js.map +1 -0
  255. package/dist/tag/tag.d.ts +26 -0
  256. package/dist/tag/tag.d.ts.map +1 -0
  257. package/dist/tag/tag.js +110 -0
  258. package/dist/tag/tag.js.map +1 -0
  259. package/dist/tag/tag.repository.d.ts +6 -0
  260. package/dist/tag/tag.repository.d.ts.map +1 -0
  261. package/dist/tag/tag.repository.js +15 -0
  262. package/dist/tag/tag.repository.js.map +1 -0
  263. package/dist/tag-group/interfaces/tag-group-attr.interface.d.ts +13 -0
  264. package/dist/tag-group/interfaces/tag-group-attr.interface.d.ts.map +1 -0
  265. package/dist/tag-group/interfaces/tag-group-attr.interface.js +3 -0
  266. package/dist/tag-group/interfaces/tag-group-attr.interface.js.map +1 -0
  267. package/dist/tag-group/tag-group.d.ts +24 -0
  268. package/dist/tag-group/tag-group.d.ts.map +1 -0
  269. package/dist/tag-group/tag-group.js +82 -0
  270. package/dist/tag-group/tag-group.js.map +1 -0
  271. package/dist/tag-group/tag-group.repository.d.ts +6 -0
  272. package/dist/tag-group/tag-group.repository.d.ts.map +1 -0
  273. package/dist/tag-group/tag-group.repository.js +15 -0
  274. package/dist/tag-group/tag-group.repository.js.map +1 -0
  275. package/dist/tax/interfaces/tax-attr.interface.d.ts +1 -0
  276. package/dist/tax/interfaces/tax-attr.interface.d.ts.map +1 -0
  277. package/dist/tax/tax.d.ts +1 -0
  278. package/dist/tax/tax.d.ts.map +1 -0
  279. package/dist/tax/tax.repository.d.ts +1 -0
  280. package/dist/tax/tax.repository.d.ts.map +1 -0
  281. package/dist/tax/tax.repository.js +4 -1
  282. package/dist/tax/tax.repository.js.map +1 -1
  283. package/dist/test-document.d.ts +1 -0
  284. package/dist/test-document.d.ts.map +1 -0
  285. package/dist/test.d.ts +1 -0
  286. package/dist/test.d.ts.map +1 -0
  287. package/dist/tsconfig.tsbuildinfo +1 -1
  288. package/migrations/finance-document-tag-migration.js +46 -0
  289. package/migrations/finance-tag-group-migration.js +53 -0
  290. package/migrations/finance-tag-migration.js +63 -0
  291. package/package.json +18 -18
  292. package/.gitlab-ci.yml +0 -16
  293. package/.husky/commit-msg +0 -13
  294. package/.husky/pre-commit +0 -4
  295. package/.prettierrc +0 -5
  296. package/CONTRIBUTING.md +0 -31
  297. package/README.md +0 -13
  298. package/eslint.config.mjs +0 -58
  299. package/nest-cli.json +0 -19
  300. package/sonar-project.properties +0 -13
  301. package/src/account/account.repository.ts +0 -11
  302. package/src/account/account.ts +0 -307
  303. package/src/account/interfaces/account-attr.interface.ts +0 -31
  304. package/src/account-system-entity/account-system-entity.ts +0 -66
  305. package/src/account-system-entity/post-history.repository.ts +0 -11
  306. package/src/config.ts +0 -382
  307. package/src/customer/customer.ts +0 -311
  308. package/src/customer/finance-customer.repository.ts +0 -13
  309. package/src/customer/interfaces/customer.repository.interface.ts +0 -3
  310. package/src/customer/interfaces/finance-customer-attr.interface.ts +0 -10
  311. package/src/customer/interfaces/finance-customer.repository.interface.ts +0 -4
  312. package/src/database.ts +0 -48
  313. package/src/document/document-item.repository.ts +0 -11
  314. package/src/document/document-item.ts +0 -146
  315. package/src/document/document.repository.ts +0 -11
  316. package/src/document/document.ts +0 -1328
  317. package/src/document/interfaces/document-attr.interface.ts +0 -28
  318. package/src/document/interfaces/document-find-all.interface.ts +0 -14
  319. package/src/document/interfaces/document-item-attr.interface.ts +0 -26
  320. package/src/document/interfaces/document-item.repository.interface.ts +0 -4
  321. package/src/enum/collect-payment-type.ts +0 -4
  322. package/src/enum/doc-type.enum.ts +0 -8
  323. package/src/enum/document-status.enum.ts +0 -6
  324. package/src/enum/index.ts +0 -19
  325. package/src/enum/payment-method.enum.ts +0 -3
  326. package/src/enum/payment-status.enum.ts +0 -11
  327. package/src/enum/payment-type.enum.ts +0 -4
  328. package/src/enum/quick-book-client-scopes.enum.ts +0 -14
  329. package/src/enum/transaction-type.enum.ts +0 -4
  330. package/src/finance-company/finance-company.repository.ts +0 -11
  331. package/src/finance-company/finance-company.ts +0 -2434
  332. package/src/helpers/login-user.ts +0 -38
  333. package/src/helpers/typeof.ts +0 -35
  334. package/src/index.ts +0 -32
  335. package/src/interfaces/account-system.interface.ts +0 -51
  336. package/src/interfaces/index.ts +0 -3
  337. package/src/journal-entry/interfaces/journal-entry-attr.interface.ts +0 -12
  338. package/src/journal-entry/journal-entry.repository.ts +0 -17
  339. package/src/journal-entry/journal-entry.ts +0 -264
  340. package/src/ledger-transaction/interfaces/ledger-transaction-attr.interface.ts +0 -18
  341. package/src/ledger-transaction/interfaces/ledger-transaction.repository.interface.ts +0 -7
  342. package/src/ledger-transaction/ledger-transaction.repository.ts +0 -17
  343. package/src/ledger-transaction/ledger-transaction.ts +0 -182
  344. package/src/models/account.entity.ts +0 -206
  345. package/src/models/customer.entity.ts +0 -93
  346. package/src/models/document-item.entity.ts +0 -167
  347. package/src/models/document.entity.ts +0 -211
  348. package/src/models/finance-company.entity.ts +0 -69
  349. package/src/models/journal-entry.entity.ts +0 -110
  350. package/src/models/ledger-transaction.entity.ts +0 -148
  351. package/src/models/payment-item.entity.ts +0 -60
  352. package/src/models/payment-method-type.entity.ts +0 -70
  353. package/src/models/payment-method.entity.ts +0 -51
  354. package/src/models/payment-paid-with.entity.ts +0 -133
  355. package/src/models/payment.entity.ts +0 -165
  356. package/src/models/post-history.entity.ts +0 -41
  357. package/src/models/tax.entity.ts +0 -75
  358. package/src/payment/interfaces/payment-attr.interface.ts +0 -23
  359. package/src/payment/interfaces/payment-params.interface.ts +0 -8
  360. package/src/payment/payment.repository.ts +0 -11
  361. package/src/payment/payment.ts +0 -236
  362. package/src/payment-item/interfaces/payment-item-attr.interface.ts +0 -10
  363. package/src/payment-item/payment-item.repository.ts +0 -11
  364. package/src/payment-item/payment-item.ts +0 -134
  365. package/src/payment-method/interfaces/payment-method-attr.interface.ts +0 -5
  366. package/src/payment-method/payment-method.repository.ts +0 -11
  367. package/src/payment-method/payment-method.ts +0 -146
  368. package/src/payment-method-type/interfaces/payment-method-type-attr.interface.ts +0 -8
  369. package/src/payment-method-type/payment-method-type.repository.ts +0 -11
  370. package/src/payment-method-type/payment-method-type.ts +0 -79
  371. package/src/payment-paid-with/interfaces/payment-paid-with.interface.ts +0 -20
  372. package/src/payment-paid-with/payment-paid-with.repository.ts +0 -11
  373. package/src/payment-paid-with/payment-paid-with.ts +0 -74
  374. package/src/tax/interfaces/tax-attr.interface.ts +0 -10
  375. package/src/tax/tax.repository.ts +0 -11
  376. package/src/tax/tax.ts +0 -68
  377. package/src/test-document.ts +0 -25
  378. package/src/test.ts +0 -3
  379. package/tsconfig.build.json +0 -4
  380. package/tsconfig.json +0 -23
@@ -1,1328 +0,0 @@
1
- import * as util from 'util';
2
- import * as path from 'path';
3
- import * as fs from 'fs';
4
- import * as puppeteer from 'puppeteer';
5
- import {
6
- Medias,
7
- InternalMediaDto,
8
- CommonService as MediaCommonService,
9
- MediaType,
10
- MediasModel,
11
- MediasRepository,
12
- } from '@tomei/media';
13
- import { DocumentStatus, DocType } from '../enum';
14
- import { IDocumentAttr } from './interfaces/document-attr.interface';
15
- import { IDocumentFindAll } from './interfaces/document-find-all.interface';
16
- import { DocumentItemRepository } from './document-item.repository';
17
- import DocumentItem from './document-item';
18
- import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
19
- import { DocumentRepository } from './document.repository';
20
- import FinanceCustomerBase from '../customer/customer';
21
- import DocumentModel from '../models/document.entity';
22
- import DocumentItemModel from '../models/document-item.entity';
23
- import { ClassError, LoginUserBase } from '@tomei/general';
24
- import { ApplicationConfig } from '@tomei/config';
25
- import { Op } from 'sequelize';
26
- import { LoginUser } from '../helpers/login-user';
27
- import { ActionEnum, Activity } from '@tomei/activity-history';
28
- import { IAccountSystem } from '../interfaces/account-system.interface';
29
-
30
- export default class Document extends AccountSystemEntity {
31
- DocNo = 'New';
32
- private _DocType: DocType;
33
- private _DocDate = new Date();
34
- Currency = 'MYR';
35
- private _Amount = 0;
36
- Description = '';
37
- private _Status = DocumentStatus.UNPAID;
38
- IssuedById = '';
39
- IssuedToId = '';
40
- IssuedToType = '';
41
- RelatedObjectId = '';
42
- RelatedObjectType = '';
43
- CreatedById = '';
44
- CreatedAt: Date;
45
- UpdatedById = '';
46
- UpdatedAt: Date;
47
- UseAccSystemDocYN = 'N';
48
- protected _ObjectType = 'Document';
49
-
50
- get ObjectType() {
51
- return this._ObjectType;
52
- }
53
-
54
- private _DocHTMLFileMediaId = '';
55
- private _DocPDFFileMediaId = '';
56
-
57
- private static _RepositoryBase = new DocumentRepository();
58
- private static _DocumentItemRepository = new DocumentItemRepository();
59
- private static _AccountingSystem: IAccountSystem;
60
-
61
- private _DbTransaction: any;
62
- private _IsNewRecord = true;
63
- private _DocumentItems = [];
64
-
65
- private static _MediaRepository = new MediasRepository();
66
- mediaCommonService: MediaCommonService;
67
-
68
- private get IsNewRecord() {
69
- return this._IsNewRecord;
70
- }
71
-
72
- private set IsNewRecord(record: boolean) {
73
- this._IsNewRecord = record;
74
- }
75
-
76
- public get DocType() {
77
- return this._DocType;
78
- }
79
-
80
- public set DocType(docType: DocType) {
81
- this._DocType = docType;
82
- }
83
-
84
- public get DocDate() {
85
- return this._DocDate;
86
- }
87
-
88
- public set DocDate(date: Date) {
89
- this._DocDate = date;
90
- }
91
-
92
- public get DocHTMLFileMediaId() {
93
- return this._DocHTMLFileMediaId;
94
- }
95
-
96
- public set DocHTMLFileMediaId(mediaId: string) {
97
- this._DocHTMLFileMediaId = mediaId;
98
- }
99
-
100
- public get DocPDFFileMediaId() {
101
- return this._DocPDFFileMediaId;
102
- }
103
-
104
- public set DocPDFFileMediaId(mediaId: string) {
105
- this._DocPDFFileMediaId = mediaId;
106
- }
107
-
108
- public get Amount() {
109
- return this._Amount;
110
- }
111
-
112
- private set Amount(amount: number) {
113
- this._Amount = amount;
114
- }
115
-
116
- public get Status() {
117
- return this._Status;
118
- }
119
-
120
- public set Status(status: DocumentStatus) {
121
- this._Status = status;
122
- }
123
-
124
- /* AccountSystemEntity Implementation */
125
- get RepositoryBase() {
126
- return Document._RepositoryBase;
127
- }
128
-
129
- /* ObjectBase Implementation */
130
- get ObjectId() {
131
- return this.DocNo;
132
- }
133
-
134
- get ObjectName() {
135
- return this.DocNo;
136
- }
137
-
138
- get TableName() {
139
- return 'finance_Document';
140
- }
141
-
142
- constructor(dbTransaction?: any, documentData?: any) {
143
- super();
144
- if (dbTransaction) {
145
- this._DbTransaction = dbTransaction;
146
- }
147
- if (documentData) {
148
- this.DocNo = documentData.DocNo;
149
- this.DocType = documentData.DocType;
150
- this.DocDate = documentData.DocDate;
151
- this.CompanyId = documentData.CompanyId;
152
- this.Currency = documentData.Currency;
153
- this.Amount = documentData.Amount;
154
- this.Description = documentData.Description;
155
- this.Status = documentData.Status;
156
- this.IssuedById = documentData.IssuedById;
157
- this.IssuedToId = documentData.IssuedToId;
158
- this.IssuedToType = documentData.IssuedToType;
159
- this.RelatedObjectId = documentData.RelatedObjectId;
160
- this.RelatedObjectType = documentData.RelatedObjectType;
161
- this.CreatedById = documentData.CreatedById;
162
- this.CreatedAt = documentData.CreatedAt;
163
- this.UpdatedById = documentData.UpdatedById;
164
- this.UpdatedAt = documentData.UpdatedAt;
165
- this.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
166
- this.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
167
- this.AccSystemRefId = documentData.AccSystemRefId;
168
- this.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
169
- this.PostedById = documentData.PostedById;
170
- this.PostedDateTime = documentData.PostedDateTime;
171
- this.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
172
- this.IsNewRecord = false;
173
- }
174
- }
175
-
176
- init(params: IDocumentAttr) {
177
- this.DocNo = params.DocNo;
178
- this.DocType = params.DocType;
179
- this.DocDate = params.DocDate;
180
- this.CompanyId = params.CompanyId;
181
- this.Currency = params.Currency;
182
- this.Amount = params.Amount;
183
- this.Description = params.Description;
184
- this.Status = params.Status;
185
- this.IssuedById = params.IssuedById;
186
- this.IssuedToId = params.IssuedToId;
187
- this.IssuedToType = params.IssuedToType;
188
- this.RelatedObjectId = params.RelatedObjectId;
189
- this.RelatedObjectType = params.RelatedObjectType;
190
- this.CreatedById = params.CreatedById;
191
- this.CreatedAt = params.CreatedAt;
192
- this.UpdatedById = params.UpdatedById;
193
- this.UpdatedAt = params.UpdatedAt;
194
- this.DocPDFFileMediaId = params.DocPDFFileMediaId;
195
- this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
196
- this.AccSystemRefId = params.AccSystemRefId;
197
- this.PostedToAccSystemYN = params.PostedToAccSystemYN;
198
- this.PostedById = params.PostedById;
199
- this.PostedDateTime = params.PostedDateTime;
200
- this.UseAccSystemDocYN = params.UseAccSystemDocYN;
201
- }
202
-
203
- public static async initDocument(dbTransaction: any, docNo: string) {
204
- try {
205
- const documentData = await this._RepositoryBase.findOne({
206
- where: {
207
- DocNo: docNo,
208
- },
209
- include: [
210
- {
211
- model: DocumentItemModel,
212
- },
213
- ],
214
- transaction: dbTransaction,
215
- });
216
- if (documentData) {
217
- const document = new Document(dbTransaction, {
218
- DocNo: documentData.DocNo,
219
- DocType: documentData.DocType,
220
- CompanyId: documentData.CompanyId,
221
- DocDate: documentData.DocDate,
222
- Currency: documentData.Currency,
223
- Amount: documentData.Amount,
224
- Description: documentData.Description,
225
- Status: documentData.Status,
226
- IssuedById: documentData.IssuedById,
227
- IssuedToId: documentData.IssuedToId,
228
- IssuedToType: documentData.IssuedToType,
229
- RelatedObjectId: documentData.RelatedObjectId,
230
- RelatedObjectType: documentData.RelatedObjectType,
231
- CreatedById: documentData.CreatedById,
232
- CreatedAt: documentData.CreatedAt,
233
- UpdatedById: documentData.UpdatedById,
234
- UpdatedAt: documentData.UpdatedAt,
235
- DocPDFFileMediaId: documentData.DocPDFFileMediaId,
236
- DocHTMLFileMediaId: documentData.DocHTMLFileMediaId,
237
- AccSystemRefId: documentData.AccSystemRefId,
238
- PostedToAccSystemYN: documentData.PostedToAccSystemYN,
239
- PostedById: documentData.PostedById,
240
- PostedDateTime: documentData.PostedDateTime,
241
- UseAccSystemDocYN: documentData.UseAccSystemDocYN,
242
- });
243
-
244
- return document;
245
- } else {
246
- const notFoundError = new ClassError(
247
- 'Document',
248
- 'InitDocumentErrMsg00',
249
- `No Document record found.`,
250
- );
251
-
252
- throw notFoundError;
253
- }
254
- } catch (error) {
255
- throw error;
256
- }
257
- }
258
-
259
- /**
260
- * Recalculate the Amount of the Document based on all the amount of the Document Items
261
- *
262
- * @returns {void}
263
- */
264
- async reCalculateAmount(): Promise<void> {
265
- const roundToTwoDecimals = (value: number): number =>
266
- Math.round(value * 100) / 100;
267
-
268
- this.Amount = 0;
269
- for (const documentItem of this._DocumentItems) {
270
- this.Amount = roundToTwoDecimals(this.Amount + documentItem.Amount);
271
- }
272
- }
273
-
274
- get DocumentItems(): Promise<DocumentItem[]> {
275
- return new Promise((resolve, reject) => {
276
- if (!this.IsNewRecord) {
277
- DocumentItem.initDocumentItems(this._DbTransaction, this)
278
- .then((documentItems) => {
279
- resolve(documentItems);
280
- })
281
- .catch((err) => {
282
- reject(err);
283
- });
284
- } else {
285
- resolve(this._DocumentItems);
286
- }
287
- });
288
- }
289
-
290
- public async getDocumentItems(dbTransaction?: any) {
291
- try {
292
- if (!this.IsNewRecord) {
293
- const documentItems = await DocumentItem.initDocumentItems(
294
- dbTransaction,
295
- this,
296
- );
297
- this._DocumentItems = documentItems;
298
- }
299
- return this._DocumentItems;
300
- } catch (error) {
301
- throw error;
302
- }
303
- }
304
-
305
- public static async settleByCreditNote(
306
- loginUser: LoginUserBase,
307
- dbTransaction: any,
308
- DocNo: string,
309
- AmountToReduce: number,
310
- ) {
311
- //This method will update the document info when issue credit note event happens.
312
-
313
- //Part 1: Validation
314
- //Instantiate existing Document by passing:
315
- const document = await this.initDocument(dbTransaction, DocNo);
316
-
317
- //Make sure document.DocType equals to DocumentType.INVOICE. If not, throw new ClassError
318
- if (document.DocType !== DocType.INVOICE) {
319
- throw new ClassError(
320
- 'Document',
321
- 'SettleByCreditNoteErrMsgXX',
322
- 'Only Invoice can be issued credit note.',
323
- );
324
- }
325
-
326
- //Check Params.AmountToReduce not more than document.Amount. If yes, throw ClassError
327
- if (AmountToReduce > document.Amount) {
328
- throw new ClassError(
329
- 'Document',
330
- 'SettleByCreditNoteErrMsgXX',
331
- 'Amount to reduce is more than the document amount.',
332
- );
333
- }
334
-
335
- //Part 2: Update Record
336
- //Set EntityValueBefore to document
337
- const EntityValueBefore = {
338
- DocNo: document.DocNo,
339
- DocType: document.DocType,
340
- CompanyId: document.CompanyId,
341
- DocDate: document.DocDate,
342
- Currency: document.Currency,
343
- Amount: document.Amount,
344
- Description: document.Description,
345
- Status: document.Status,
346
- IssuedById: document.IssuedById,
347
- IssuedToId: document.IssuedToId,
348
- IssuedToType: document.IssuedToType,
349
- RelatedObjectId: document.RelatedObjectId,
350
- RelatedObjectType: document.RelatedObjectType,
351
- CreatedById: document.CreatedById,
352
- CreatedAt: document.CreatedAt,
353
- UpdatedById: document.UpdatedById,
354
- UpdatedAt: document.UpdatedAt,
355
- DocPDFFileMediaId: document.DocPDFFileMediaId,
356
- DocHTMLFileMediaId: document.DocHTMLFileMediaId,
357
- AccSystemRefId: document.AccSystemRefId,
358
- PostedToAccSystemYN: document.PostedToAccSystemYN,
359
- PostedById: document.PostedById,
360
- PostedDateTime: document.PostedDateTime,
361
- UseAccSystemDocYN: document.UseAccSystemDocYN,
362
- };
363
-
364
- //updated Status to DocumentStatus.SETTLED if Params.AmountToReduce equals to document.Amount.
365
- let updatedStatus;
366
- if (AmountToReduce == document.Amount) {
367
- updatedStatus = DocumentStatus.SETTLED;
368
- } else {
369
- updatedStatus = DocumentStatus.PARTIALSETTLED;
370
- }
371
-
372
- //Call Document._Repo update method
373
- await this._RepositoryBase.update(
374
- {
375
- Amount: AmountToReduce,
376
- Status: updatedStatus,
377
- UpdatedAt: document.UpdatedAt,
378
- UpdatedById: document.UpdatedById,
379
- },
380
- {
381
- where: {
382
- DocNo: document.DocNo,
383
- },
384
- transaction: dbTransaction,
385
- },
386
- );
387
-
388
- const UpdatedDocument = await this.initDocument(dbTransaction, DocNo);
389
-
390
- //Part 3: Record Update Document Activity
391
- //Initialise EntityValueAfter to UpdatedDocument
392
- const EntityValueAfter = {
393
- DocNo: UpdatedDocument.DocNo,
394
- DocType: UpdatedDocument.DocType,
395
- CompanyId: UpdatedDocument.CompanyId,
396
- DocDate: UpdatedDocument.DocDate,
397
- Currency: UpdatedDocument.Currency,
398
- Amount: UpdatedDocument.Amount,
399
- Description: UpdatedDocument.Description,
400
- Status: UpdatedDocument.Status,
401
- IssuedById: UpdatedDocument.IssuedById,
402
- IssuedToId: UpdatedDocument.IssuedToId,
403
- IssuedToType: UpdatedDocument.IssuedToType,
404
- RelatedObjectId: UpdatedDocument.RelatedObjectId,
405
- RelatedObjectType: UpdatedDocument.RelatedObjectType,
406
- CreatedById: UpdatedDocument.CreatedById,
407
- CreatedAt: UpdatedDocument.CreatedAt,
408
- UpdatedById: UpdatedDocument.UpdatedById,
409
- UpdatedAt: UpdatedDocument.UpdatedAt,
410
- DocPDFFileMediaId: UpdatedDocument.DocPDFFileMediaId,
411
- DocHTMLFileMediaId: UpdatedDocument.DocHTMLFileMediaId,
412
- AccSystemRefId: UpdatedDocument.AccSystemRefId,
413
- PostedToAccSystemYN: UpdatedDocument.PostedToAccSystemYN,
414
- PostedById: UpdatedDocument.PostedById,
415
- PostedDateTime: UpdatedDocument.PostedDateTime,
416
- UseAccSystemDocYN: UpdatedDocument.UseAccSystemDocYN,
417
- };
418
- //Instantiate new activity
419
- const activity = new Activity();
420
- activity.ActivityId = activity.createId();
421
- activity.Action = ActionEnum.UPDATE;
422
- activity.Description = `Settle Finance Document (${UpdatedDocument._DocType}) from Credit Note.`;
423
- activity.EntityType = 'FinanceCustomer';
424
- activity.EntityId = DocNo;
425
- activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
426
- activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
427
-
428
- //Call activity._Repo create method
429
- await activity.create(loginUser.ObjectId, dbTransaction);
430
-
431
- return UpdatedDocument;
432
- }
433
-
434
- /**
435
- * Returns HTML template file for invoice generation
436
- *
437
- * @see generateInvoice - for implementation
438
- *
439
- * @returns {Express.Multer.File} - HTML File
440
- */
441
- public static async DEFAULT_INVOICE_TEMPLATE_HTML(): Promise<Express.Multer.File> {
442
- /* getting invoice template in HTML format */
443
- const templateLocation = path.resolve('./invoice-template/index.html');
444
- const readFileContent = util.promisify(fs.readFile);
445
- const htmlBuffer = await readFileContent(templateLocation);
446
-
447
- const htmlStream: Express.Multer.File = {
448
- buffer: htmlBuffer,
449
- fieldname: 'FileStream',
450
- originalname: 'index.html',
451
- mimetype: 'text/html',
452
- size: htmlBuffer.length,
453
- encoding: '8bit',
454
- filename: 'sample-invoice.html',
455
- destination: path.dirname(templateLocation),
456
- path: '',
457
- stream: null,
458
- };
459
-
460
- return htmlStream;
461
- }
462
-
463
- /**
464
- * Returns PDF template file for invoice generation
465
- *
466
- * @remarks - This function is converting generated HTML into PDF
467
- *
468
- * @see generateInvoice - for implementation
469
- *
470
- * @returns {Express.Multer.File} - PDF File
471
- */
472
- public async DEFAULT_INVOICE_TEMPLATE_PDF(
473
- customer: FinanceCustomerBase,
474
- date: Date = new Date(),
475
- ): Promise<Express.Multer.File> {
476
- /* prepping HTML conversion by getting its URL and String */
477
-
478
- /* todo: needs to generate HTML first before converting to PDF */
479
- const templateLocation = path.resolve('./invoice-template/index.html');
480
- const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
481
- const readFileContent = util.promisify(fs.readFile);
482
- // const htmlString = await readFileContent(templateLocation, 'utf8');
483
- const [htmlString] = await Promise.all([
484
- readFileContent(templateLocation, 'utf8'),
485
- ]);
486
-
487
- /* converting HTML to PDF */
488
- const browser = await puppeteer.launch({
489
- headless: true,
490
- args: ['--no-sandbox', '--disable-setuid-sandbox'],
491
- });
492
- const page = await browser.newPage();
493
-
494
- const imagePath = path.resolve(
495
- './invoice-template/assets/img/ezcash-logo.svg',
496
- );
497
- const imageBuffer = await readFileContent(imagePath);
498
- const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString(
499
- 'base64',
500
- )}`;
501
-
502
- const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
503
-
504
- await page.setContent(htmlString);
505
- await page.addStyleTag({ path: cssLocation });
506
-
507
- // Replace the <img> tag with the new image
508
- const divHandle = await page.$('.tm_logo');
509
- await divHandle.evaluate((div, imgTag) => {
510
- div.innerHTML = imgTag;
511
- }, imgTag);
512
-
513
- // Get the current date and invoice number from customer
514
- const currentDate = date.toLocaleDateString('en-GB');
515
- const invoiceNo = this.DocNo;
516
-
517
- // Update the invoice number and date in the HTML content
518
- const invoiceTitleInfo = `
519
- <div class="tm_invoice_seperator tm_gray_bg"></div>
520
- <div class="tm_invoice_info_list">
521
- <p class="tm_invoice_number tm_m0">
522
- Invoice No: <b class="tm_primary_color">${invoiceNo}</b>
523
- </p>
524
- <p class="tm_invoice_date tm_m0">
525
- Date: <b class="tm_primary_color">${currentDate}</b>
526
- </p>
527
- </div>
528
- `;
529
- const invoiceTitleInfoHandle = await page.$('.tm_invoice_info');
530
- await invoiceTitleInfoHandle.evaluate((invoice, invoiceTitleInfo) => {
531
- invoice.innerHTML = invoiceTitleInfo;
532
- }, invoiceTitleInfo);
533
-
534
- // Update the invoice customer detail in the HTML content
535
- const invoiceCustomerContent = `
536
- <p class="tm_mb2">
537
- <b class="tm_primary_color">Invoice To:</b>
538
- </p>
539
- <p>
540
- ${customer.FullName} <br />
541
- ${customer.DefaultAddress.Address}, ${customer.DefaultAddress.City} <br />
542
- ${customer.DefaultAddress.Country} <br />
543
- ${customer.Email}
544
- </p>
545
- `;
546
- const invoiceCustomerHandle = await page.$('.tm_customer_detail');
547
- await invoiceCustomerHandle.evaluate((invoice, invoiceCustomerContent) => {
548
- invoice.innerHTML = invoiceCustomerContent;
549
- }, invoiceCustomerContent);
550
-
551
- // Update the invoice Pay To details in the HTML content
552
- const invoicePayToContent = ``;
553
- const invoicePayToHandle = await page.$('.tm_payto_detail');
554
- await invoicePayToHandle.evaluate((invoice, invoicePayToContent) => {
555
- invoice.innerHTML = invoicePayToContent;
556
- }, invoicePayToContent);
557
-
558
- // Update the invoice payment info in the HTML content
559
- const invoicePaymentInfoContent = ``;
560
- const invoicePaymentInfoHandle = await page.$('.tm_payment_info');
561
- await invoicePaymentInfoHandle.evaluate(
562
- (invoice, invoicePaymentInfoContent) => {
563
- invoice.innerHTML = invoicePaymentInfoContent;
564
- },
565
- invoicePaymentInfoContent,
566
- );
567
-
568
- // Update the invoice right footer content in the HTML content
569
- const invoiceSubtotal = +this.Amount;
570
- const invoiceTax = 0;
571
- const invoiceRightFooterContent = `
572
- <table>
573
- <tbody>
574
- <tr>
575
- <td
576
- class="tm_width_3 tm_primary_color tm_border_none tm_bold"
577
- >
578
- Subtotal
579
- </td>
580
- <td
581
- class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_bold"
582
- >
583
- ${this.Currency} ${invoiceSubtotal.toFixed(2)}
584
- </td>
585
- </tr>
586
- <tr>
587
- <td
588
- class="tm_width_3 tm_primary_color tm_border_none tm_pt0"
589
- >
590
- Tax <span class="tm_ternary_color">(0%)</span>
591
- </td>
592
- <td
593
- class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_pt0"
594
- >
595
- ${this.Currency} ${invoiceTax.toFixed(2)}
596
- </td>
597
- </tr>
598
- <tr class="tm_border_top tm_border_bottom">
599
- <td
600
- class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color"
601
- >
602
- Grand Total
603
- </td>
604
- <td
605
- class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color tm_text_right"
606
- >
607
- ${this.Currency} ${(invoiceSubtotal + invoiceTax).toFixed(2)}
608
- </td>
609
- </tr>
610
- </tbody>
611
- </table>
612
- `;
613
- const invoiceRightFooterHandle = await page.$('.tm_item_total_section');
614
- await invoiceRightFooterHandle.evaluate(
615
- (invoice, invoiceRightFooterContent) => {
616
- invoice.innerHTML = invoiceRightFooterContent;
617
- },
618
- invoiceRightFooterContent,
619
- );
620
-
621
- // Update the invoice Terms & Agreement content in the HTML content
622
- const invoiceTNCContent = `
623
- <li>
624
- All payment must be made to:
625
- <ul>
626
- <li>Bank: <b>RHB BANK BHD</b></li>
627
- <li>Account Name: <b>TXG Financial Solutions Sdn Bhd</b></li>
628
- <li>Account No.: <b>2142 13000 17954</b></li>
629
- </ul>
630
- </li>
631
- <li>
632
- Once payment has been made, please email your transaction confirmation slip to <i>payment@ezcash.com.my</i>
633
- </li>
634
- `;
635
- const invoiceTNCHandle = await page.$('.tm_tnc_content');
636
- await invoiceTNCHandle.evaluate((invoice, invoiceTNCContent) => {
637
- invoice.innerHTML = invoiceTNCContent;
638
- }, invoiceTNCContent);
639
-
640
- // Update the invoice items content in the HTML content
641
- const invoiceDocumentItems = await this.DocumentItems;
642
-
643
- let invoiceItemContent = ``;
644
- invoiceDocumentItems.forEach((documentItem, i) => {
645
- invoiceItemContent += `
646
- <tr>
647
- <td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
648
- <td class="tm_width_4">
649
- ${documentItem.Description}
650
- </td>
651
- <td class="tm_width_2">${documentItem.Currency} ${
652
- documentItem.UnitPrice
653
- }</td>
654
- <td class="tm_width_1">${documentItem.Quantity}</td>
655
- <td class="tm_width_2 tm_text_right">${documentItem.Currency} ${(
656
- +documentItem.UnitPrice * +documentItem.Quantity
657
- ).toFixed(2)}</td>
658
- </tr>
659
- `;
660
- });
661
- const invoiceDocumentItemHandle = await page.$('.tm_items_content');
662
- await invoiceDocumentItemHandle.evaluate((invoice, invoiceItemContent) => {
663
- invoice.innerHTML = invoiceItemContent;
664
- }, invoiceItemContent);
665
-
666
- const pdfBuffer = await page.pdf({
667
- format: 'a4',
668
- printBackground: true,
669
- margin: {
670
- left: '0px',
671
- top: '0px',
672
- right: '0px',
673
- bottom: '0px',
674
- },
675
- });
676
-
677
- // Convert Uint8Array to Buffer
678
- const pdfBufferAsBuffer = Buffer.from(pdfBuffer);
679
-
680
- const pdfStream: Express.Multer.File = {
681
- buffer: pdfBufferAsBuffer,
682
- fieldname: 'FileStream',
683
- originalname: 'sample-invoice.pdf',
684
- mimetype: 'application/pdf',
685
- size: pdfBuffer.length,
686
- encoding: '8bit',
687
- filename: 'sample-invoice.pdf',
688
- destination: '',
689
- path: '',
690
- stream: null,
691
- };
692
-
693
- return pdfStream;
694
- }
695
-
696
- /**
697
- * Returns PDF template file for receipt generation
698
- *
699
- * @remarks - This function is converting generated HTML into PDF
700
- *
701
- * @see generateReceipt - for implementation
702
- *
703
- * @returns {Express.Multer.File} - PDF File
704
- */
705
- public async DEFAULT_RECEIPT_TEMPLATE_PDF(
706
- customer: FinanceCustomerBase,
707
- date: Date = new Date(),
708
- ): Promise<Express.Multer.File> {
709
- /* prepping HTML conversion by getting its URL and String */
710
-
711
- /* todo: needs to generate HTML first before converting to PDF */
712
- const templateLocation = path.resolve('./invoice-template/index.html');
713
- const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
714
- const readFileContent = util.promisify(fs.readFile);
715
- // const htmlString = await readFileContent(templateLocation, 'utf8');
716
- const [htmlString] = await Promise.all([
717
- readFileContent(templateLocation, 'utf8'),
718
- ]);
719
-
720
- /* converting HTML to PDF */
721
- const browser = await puppeteer.launch({
722
- headless: true,
723
- args: ['--no-sandbox', '--disable-setuid-sandbox'],
724
- });
725
- const page = await browser.newPage();
726
-
727
- const imagePath = path.resolve(
728
- './invoice-template/assets/img/ezcash-logo.svg',
729
- );
730
- const imageBuffer = await readFileContent(imagePath);
731
- const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString(
732
- 'base64',
733
- )}`;
734
-
735
- const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
736
-
737
- await page.setContent(htmlString);
738
- await page.addStyleTag({ path: cssLocation });
739
-
740
- // Replace the <img> tag with the new image
741
- const divHandle = await page.$('.tm_logo');
742
- await divHandle.evaluate((div, imgTag) => {
743
- div.innerHTML = imgTag;
744
- }, imgTag);
745
-
746
- // Get the current date and recei[t] number from customer
747
- const currentDate = date.toLocaleDateString('en-GB');
748
- const receiptNo = this.DocNo;
749
-
750
- // Change and update from invoice template title to receipt title
751
- const receiptTitle = `
752
- <div class="tm_primary_color tm_f50 tm_text_uppercase">
753
- Receipt
754
- </div>
755
- `;
756
- const receiptTitleHandle = await page.$('.tm_invoice_title');
757
- await receiptTitleHandle.evaluate((receipt, receiptTitle) => {
758
- receipt.innerHTML = receiptTitle;
759
- }, receiptTitle);
760
-
761
- // Update the receipt number and date in the HTML content
762
- const receiptTitleInfo = `
763
- <div class="tm_invoice_seperator tm_gray_bg"></div>
764
- <div class="tm_invoice_info_list">
765
- <p class="tm_invoice_number tm_m0">
766
- Receipt No: <b class="tm_primary_color">${receiptNo}</b>
767
- </p>
768
- <p class="tm_invoice_date tm_m0">
769
- Date: <b class="tm_primary_color">${currentDate}</b>
770
- </p>
771
- </div>
772
- `;
773
- const receiptTitleInfoHandle = await page.$('.tm_invoice_info');
774
- await receiptTitleInfoHandle.evaluate((receipt, receiptTitleInfo) => {
775
- receipt.innerHTML = receiptTitleInfo;
776
- }, receiptTitleInfo);
777
-
778
- // Update the receipt customer detail in the HTML content
779
- const receiptCustomerContent = `
780
- <p class="tm_mb2">
781
- <b class="tm_primary_color">Issued To:</b>
782
- </p>
783
- <p>
784
- ${customer.FullName} <br />
785
- ${customer.DefaultAddress.Address}, ${customer.DefaultAddress.City} <br />
786
- ${customer.DefaultAddress.Country} <br />
787
- ${customer.Email}
788
- </p>
789
- `;
790
- const receiptCustomerHandle = await page.$('.tm_customer_detail');
791
- await receiptCustomerHandle.evaluate((receipt, receiptCustomerContent) => {
792
- receipt.innerHTML = receiptCustomerContent;
793
- }, receiptCustomerContent);
794
-
795
- // Remove the receipt Pay To details in the HTML content
796
- const receiptPayToContent = ``;
797
- const receiptPayToHandle = await page.$('.tm_payto_detail');
798
- await receiptPayToHandle.evaluate((receipt, receiptPayToContent) => {
799
- receipt.innerHTML = receiptPayToContent;
800
- }, receiptPayToContent);
801
-
802
- // Remove the receipt payment info in the HTML content
803
- const receiptPaymentInfoContent = ``;
804
- const receiptPaymentInfoHandle = await page.$('.tm_payment_info');
805
- await receiptPaymentInfoHandle.evaluate(
806
- (receipt, receiptPaymentInfoContent) => {
807
- receipt.innerHTML = receiptPaymentInfoContent;
808
- },
809
- receiptPaymentInfoContent,
810
- );
811
-
812
- // Update the receipt right footer content in the HTML content
813
- const receiptSubtotal = +this.Amount;
814
- const receiptTax = 0;
815
- const receiptRightFooterContent = `
816
- <table>
817
- <tbody>
818
- <tr>
819
- <td
820
- class="tm_width_3 tm_primary_color tm_border_none tm_bold"
821
- >
822
- Subtotal
823
- </td>
824
- <td
825
- class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_bold"
826
- >
827
- ${this.Currency} ${receiptSubtotal}
828
- </td>
829
- </tr>
830
- <tr>
831
- <td
832
- class="tm_width_3 tm_primary_color tm_border_none tm_pt0"
833
- >
834
- Tax <span class="tm_ternary_color">(0%)</span>
835
- </td>
836
- <td
837
- class="tm_width_3 tm_primary_color tm_text_right tm_border_none tm_pt0"
838
- >
839
- ${this.Currency} ${receiptTax}
840
- </td>
841
- </tr>
842
- <tr class="tm_border_top tm_border_bottom">
843
- <td
844
- class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color"
845
- >
846
- Grand Total
847
- </td>
848
- <td
849
- class="tm_width_3 tm_border_top_0 tm_bold tm_f16 tm_primary_color tm_text_right"
850
- >
851
- ${this.Currency} ${receiptSubtotal + receiptTax}
852
- </td>
853
- </tr>
854
- </tbody>
855
- </table>
856
- `;
857
- const receiptRightFooterHandle = await page.$('.tm_item_total_section');
858
- await receiptRightFooterHandle.evaluate(
859
- (receipt, receiptRightFooterContent) => {
860
- receipt.innerHTML = receiptRightFooterContent;
861
- },
862
- receiptRightFooterContent,
863
- );
864
-
865
- // Update the receipt items content in the HTML content
866
- const receiptDocumentItems = await this.DocumentItems;
867
-
868
- let receiptItemContent = ``;
869
- receiptDocumentItems.forEach((documentItem, i) => {
870
- receiptItemContent += `
871
- <tr>
872
- <td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
873
- <td class="tm_width_4">
874
- ${documentItem.Description}
875
- </td>
876
- <td class="tm_width_2">${documentItem.Currency} ${
877
- documentItem.UnitPrice
878
- }</td>
879
- <td class="tm_width_1">${documentItem.Quantity}</td>
880
- <td class="tm_width_2 tm_text_right">${documentItem.Currency} ${
881
- +documentItem.UnitPrice * +documentItem.Quantity
882
- }</td>
883
- </tr>
884
- `;
885
- });
886
- const receiptDocumentItemHandle = await page.$('.tm_items_content');
887
- await receiptDocumentItemHandle.evaluate((receipt, receiptItemContent) => {
888
- receipt.innerHTML = receiptItemContent;
889
- }, receiptItemContent);
890
-
891
- // Update the receipt Terms & Agreement content in the HTML content
892
- const receiptFooterContent = `
893
- <p class="tm_mb5 tm_text_center tm_f11">
894
- <i>
895
- Thank you for your payment. This is computer generated receipt
896
- - no signature is required.
897
- </i>
898
- </p>
899
- `;
900
- const receiptFooterHandle = await page.$('.tm_footer_section');
901
- await receiptFooterHandle.evaluate((receipt, receiptFooterContent) => {
902
- receipt.innerHTML = receiptFooterContent;
903
- }, receiptFooterContent);
904
-
905
- const pdfBuffer = await page.pdf({
906
- format: 'a4',
907
- printBackground: true,
908
- margin: {
909
- left: '0px',
910
- top: '0px',
911
- right: '0px',
912
- bottom: '0px',
913
- },
914
- });
915
-
916
- // Convert Uint8Array to Buffer
917
- const pdfBufferAsBuffer = Buffer.from(pdfBuffer);
918
-
919
- const pdfStream: Express.Multer.File = {
920
- buffer: pdfBufferAsBuffer,
921
- fieldname: 'FileStream',
922
- originalname: 'sample-invoice.pdf',
923
- mimetype: 'application/pdf',
924
- size: pdfBuffer.length,
925
- encoding: '8bit',
926
- filename: 'sample-invoice.pdf',
927
- destination: '',
928
- path: '',
929
- stream: null,
930
- };
931
-
932
- return pdfStream;
933
- }
934
-
935
- /**
936
- * Returns the media representing the document in HTML format
937
- *
938
- * @returns {MediasModel} - Invoice Media in HTML Format
939
- */
940
- public get DocumentFileInHTML(): Promise<MediasModel> {
941
- return (async () => {
942
- const { HTMLMedia } = await this.generateInvoice();
943
-
944
- return HTMLMedia;
945
- })();
946
- }
947
-
948
- /**
949
- * Returns the media representing the document in PDF format
950
- *
951
- * @returns {MediasModel} - Invoice Media in PDF Format
952
- */
953
- public get DocumentFileInPDF(): Promise<MediasModel> {
954
- return (async () => {
955
- const { PDFMedia } = await this.generateInvoice();
956
-
957
- return PDFMedia;
958
- })();
959
- }
960
-
961
- /**
962
- * Returns generated HTML & PDF Invoice Media
963
- *
964
- * @remarks - This function also create each media element in common_Media table
965
- *
966
- * @see DocumentFileInHTML - for implementation
967
- * @see DocumentFileInPDF - for implementation
968
- *
969
- * @see {@link FinanceCompany.issueInvoice} - for implementation
970
- *
971
- * @param userId - userId that trigger this function
972
- *
973
- * @returns {MediasModel} - HTML & PDF Media
974
- */
975
- async generateInvoice(
976
- userId?: string,
977
- customer?: FinanceCustomerBase,
978
- dbTransaction?: any,
979
- date?: Date,
980
- ): Promise<{
981
- HTMLMedia: MediasModel;
982
- PDFMedia: MediasModel;
983
- }> {
984
- const media: Medias = new Medias(this.mediaCommonService);
985
-
986
- /* insert FileStream on htmlPayload */
987
- const htmlPayload: InternalMediaDto = {
988
- ObjectId: this.DocNo,
989
- ObjectType: 'Document',
990
- Type: MediaType.Document,
991
- FileName: `${this.DocType}-${this.DocNo}`,
992
- FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
993
- FileExtension: 'html',
994
- Title: `${this.DocType}-${this.DocNo}.html`,
995
- Description: `HTML ${this.DocType}`,
996
- IsEncryptedYN: 'N',
997
- };
998
- const user = new LoginUser(userId ?? 'System', null, null);
999
-
1000
- /* create HTML media of the generated HTML */
1001
- const HTMLInvoiceMedia = await media.postInternal(
1002
- await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
1003
- htmlPayload,
1004
- user as any,
1005
- dbTransaction,
1006
- );
1007
-
1008
- /* insert FileStream on pdfPayload */
1009
- const pdfPayload: InternalMediaDto = {
1010
- ObjectId: this.DocNo,
1011
- ObjectType: 'Document',
1012
- Type: MediaType.Document,
1013
- FileName: `${this.DocType}-${this.DocNo}`,
1014
- FileStream: await this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date),
1015
- FileExtension: 'pdf',
1016
- Title: `${this.DocType}-${this.DocNo}.pdf`,
1017
- Description: `PDF ${this.DocType}`,
1018
- IsEncryptedYN: 'N',
1019
- };
1020
-
1021
- /* create PDF media from the converted HTML */
1022
- const PDFInvoiceMedia = await media.postInternal(
1023
- await this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date),
1024
- pdfPayload,
1025
- user as any,
1026
- dbTransaction,
1027
- );
1028
-
1029
- /*Below is commented because the current implentation flow does not add up (PLEASE DON'T DELETE)*/
1030
- // try {
1031
- // const document = await this.RepositoryBase.findOne({
1032
- // where: {
1033
- // DocNo: this.DocNo,
1034
- // },
1035
- // transaction: this._DbTransaction,
1036
- // });
1037
-
1038
- // /* storing HTML & PDF MediaId to finance_Document */
1039
- // document.DocHTMLFileMediaId = HTMLInvoiceMedia.MediaId;
1040
- // document.DocPDFFileMediaId = PDFInvoiceMedia.MediaId;
1041
-
1042
- // await document.save({ transaction: this._DbTransaction });
1043
- // } catch (err) {
1044
- // // tslint:disable-next-line:no-console
1045
- // console.log(err);
1046
- // }
1047
-
1048
- return {
1049
- HTMLMedia: HTMLInvoiceMedia,
1050
- PDFMedia: PDFInvoiceMedia,
1051
- };
1052
- }
1053
-
1054
- /**
1055
- * Returns generated HTML & PDF Receipt Media
1056
- *
1057
- * @remarks - This function also create each media element in common_Media table
1058
- *
1059
- * @see DocumentFileInHTML - for implementation
1060
- *
1061
- * @param userId - userId that trigger this function
1062
- *
1063
- * @returns {MediasModel} - HTML & PDF Media
1064
- */
1065
- async generateReceipt(
1066
- userId?: string,
1067
- customer?: FinanceCustomerBase,
1068
- transaction?: any,
1069
- date?: Date,
1070
- ): Promise<{
1071
- HTMLMedia: MediasModel;
1072
- PDFMedia: MediasModel;
1073
- }> {
1074
- const media: Medias = new Medias(this.mediaCommonService);
1075
- const user = new LoginUser(userId ?? 'System', null, null);
1076
- /* insert FileStream on htmlPayload */
1077
- const htmlPayload: InternalMediaDto = {
1078
- ObjectId: this.DocNo,
1079
- ObjectType: 'Document',
1080
- Type: MediaType.Document,
1081
- FileName: `${this.DocType}-${this.DocNo}`,
1082
- FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
1083
- FileExtension: 'html',
1084
- Title: `${this.DocType}-${this.DocNo}.html`,
1085
- Description: `HTML ${this.DocType}`,
1086
- IsEncryptedYN: 'N',
1087
- };
1088
-
1089
- /* create HTML media of the generated HTML */
1090
- const HTMLInvoiceMedia = await media.postInternal(
1091
- await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
1092
- htmlPayload,
1093
- user as any,
1094
- transaction,
1095
- );
1096
-
1097
- /* insert FileStream on pdfPayload */
1098
- const pdfPayload: InternalMediaDto = {
1099
- ObjectId: this.DocNo,
1100
- ObjectType: 'Document',
1101
- Type: MediaType.Document,
1102
- FileName: `${this.DocType}-${this.DocNo}`,
1103
- FileStream: await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date),
1104
- FileExtension: 'pdf',
1105
- Title: `${this.DocType}-${this.DocNo}.pdf`,
1106
- Description: `PDF ${this.DocType}`,
1107
- IsEncryptedYN: 'N',
1108
- };
1109
-
1110
- /* create PDF media from the converted HTML */
1111
- const PDFInvoiceMedia = await media.postInternal(
1112
- await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date),
1113
- pdfPayload,
1114
- user as any,
1115
- transaction,
1116
- );
1117
-
1118
- return {
1119
- HTMLMedia: HTMLInvoiceMedia,
1120
- PDFMedia: PDFInvoiceMedia,
1121
- };
1122
- }
1123
-
1124
- async generateCreditNote(userId?: string, customer?: FinanceCustomerBase) {
1125
- console.log(userId, customer, '<< generateCreditNote');
1126
- }
1127
-
1128
- /**
1129
- * Create a new Document Item which is automatically added to the DocumentItems list
1130
- * @param documentItem
1131
- *
1132
- * @returns {DocumentItem}
1133
- */
1134
- async newDocumentItem(documentItem?: DocumentItem): Promise<DocumentItem> {
1135
- let di: DocumentItem;
1136
- if (documentItem) {
1137
- di = documentItem;
1138
- } else {
1139
- di = new DocumentItem(this._DbTransaction, this);
1140
- }
1141
- di.DocNo = this.DocNo;
1142
- this._DocumentItems.push(di);
1143
- this.reCalculateAmount();
1144
- return documentItem;
1145
- }
1146
-
1147
- /**
1148
- * this is temporary method to get the latest previous document
1149
- *
1150
- * @see SimpleLoans.BillLatePaymentCharges - for implementation
1151
- *
1152
- * @param docType - The document type
1153
- *
1154
- * @returns {DocumentModel}
1155
- */
1156
- async getPreviousDocument(docType: DocType): Promise<DocumentModel> {
1157
- return await this.RepositoryBase.findOne({
1158
- where: {
1159
- DocType: docType,
1160
- },
1161
- order: [['CreatedAt', 'DESC']],
1162
- });
1163
- }
1164
-
1165
- /**
1166
- * Retrieve a list of documents from the database.
1167
- *
1168
- * @param loginUser - The user who is issuing the request.
1169
- * @param dbTransaction - The database transaction to be used, if any.
1170
- * @param page - Optional. The page number for paginated results.
1171
- * @param row - Optional. The number of rows to retrieve per page.
1172
- * @param search - Optional. An object containing search criteria.
1173
- *
1174
- * @returns {count: number, rows: DocumentModel[]} - An object containing the count of matching documents and an array of DocumentModel objects.
1175
- * @throws {Error} - If the user does not have the required privilege or if an error occurs during the operation.
1176
- */
1177
- public static async findAll(
1178
- loginUser: LoginUserBase,
1179
- dbTransaction: any,
1180
- page?: number,
1181
- row?: number,
1182
- search?: IDocumentFindAll,
1183
- order?: [string, string][],
1184
- accountingSystem?: IAccountSystem,
1185
- ): Promise<{ count: number; rows: DocumentModel[] }> {
1186
- try {
1187
- const systemCode =
1188
- ApplicationConfig.getComponentConfigValue('system-code');
1189
-
1190
- const isPrivileged = await loginUser.checkPrivileges(
1191
- systemCode,
1192
- 'Invoice - View',
1193
- );
1194
- if (!isPrivileged) {
1195
- throw new ClassError(
1196
- 'Document',
1197
- 'DocumentFindAllErrMsg00',
1198
- `You do not have 'Invoice - View' privilege.`,
1199
- );
1200
- }
1201
-
1202
- let options: any = {
1203
- transaction: dbTransaction,
1204
- order: [['CreatedAt', 'DESC']],
1205
- };
1206
-
1207
- /*Create an object to store search criteria*/
1208
- const searchObj: IDocumentFindAll | any = {};
1209
-
1210
- /*Apply search filters if they are provided*/
1211
- if (search?.DocNo) {
1212
- searchObj.DocNo = search.DocNo;
1213
- }
1214
-
1215
- if (search?.DocType) {
1216
- searchObj.DocType = search.DocType;
1217
- }
1218
-
1219
- if (search?.StartDate) {
1220
- searchObj.DocDate = {
1221
- ...searchObj.DocDate,
1222
- [Op.gte]: new Date(search.StartDate).toISOString(),
1223
- };
1224
- }
1225
-
1226
- if (search?.EndDate) {
1227
- searchObj.DocDate = {
1228
- ...searchObj.DocDate,
1229
- [Op.lte]: new Date(search.EndDate).toISOString(),
1230
- };
1231
- }
1232
-
1233
- if (search?.IssuedToId) {
1234
- searchObj.IssuedToId = search.IssuedToId;
1235
- }
1236
-
1237
- if (search?.IssuedToType) {
1238
- searchObj.IssuedToType = search.IssuedToType;
1239
- }
1240
-
1241
- if (search?.Status) {
1242
- searchObj.Status = search.Status;
1243
- }
1244
-
1245
- if (search?.RelatedObjectId) {
1246
- searchObj.RelatedObjectId = search.RelatedObjectId;
1247
- }
1248
- if (search?.RelatedObjectType) {
1249
- searchObj.RelatedObjectType = search.RelatedObjectType;
1250
- }
1251
- if (search?.Description) {
1252
- searchObj.Description = search.Description;
1253
- }
1254
-
1255
- /*If pagination is requested, update query options*/
1256
- if (page && row) {
1257
- options = {
1258
- ...options,
1259
- limit: row,
1260
- offset: row * (page - 1),
1261
- };
1262
- }
1263
-
1264
- if (order) {
1265
- options = {
1266
- ...options,
1267
- order: order,
1268
- };
1269
- }
1270
-
1271
- /*If search criteria exist, add them to the query options*/
1272
- if (Object.keys(searchObj).length) {
1273
- options = {
1274
- ...options,
1275
- where: searchObj,
1276
- };
1277
- }
1278
-
1279
- /*Retrieve documents from the database with pagination and search filters applied*/
1280
- let documents =
1281
- await Document._RepositoryBase.findAllWithPagination(options);
1282
-
1283
- let isChangesExit = false;
1284
-
1285
- for (let i = 0; i < documents?.rows?.length; i++) {
1286
- const doc = await documents?.rows[i];
1287
- if (doc.UseAccSystemDocYN.toLowerCase() === 'y') {
1288
- console.log(doc.UseAccSystemDocYN.toLowerCase());
1289
-
1290
- if (accountingSystem === null || accountingSystem === undefined) {
1291
- throw new ClassError(
1292
- 'Document',
1293
- 'DocumentFindAllErrMsg01',
1294
- `Accounting System is not set`,
1295
- );
1296
- }
1297
- const invoiceStatus = await accountingSystem.getInvoiceStatus(
1298
- doc.AccSystemRefId,
1299
- );
1300
- if (doc.Status !== invoiceStatus) {
1301
- doc.Status = invoiceStatus;
1302
- await this._RepositoryBase.update(
1303
- {
1304
- Status: invoiceStatus,
1305
- },
1306
- {
1307
- where: {
1308
- DocNo: doc.DocNo,
1309
- },
1310
- transaction: dbTransaction,
1311
- },
1312
- );
1313
- isChangesExit = true;
1314
- }
1315
- }
1316
- }
1317
-
1318
- if (isChangesExit) {
1319
- documents =
1320
- await Document._RepositoryBase.findAllWithPagination(options);
1321
- }
1322
-
1323
- return documents; // make sure the returned data is updated
1324
- } catch (error) {
1325
- throw error;
1326
- }
1327
- }
1328
- }