@tomei/finance 0.6.99 → 0.6.102

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 (223) hide show
  1. package/.husky/commit-msg +12 -3
  2. package/.husky/pre-commit +4 -4
  3. package/configs/config.js +1 -1
  4. package/dist/account/account.d.ts +37 -37
  5. package/dist/account/account.js +251 -263
  6. package/dist/account/account.js.map +1 -1
  7. package/dist/account/account.repository.d.ts +5 -5
  8. package/dist/account/account.repository.js +11 -11
  9. package/dist/account/interfaces/account-attr.interface.d.ts +29 -29
  10. package/dist/account/interfaces/account-attr.interface.js +2 -2
  11. package/dist/account-system-entity/account-system-entity.d.ts +12 -12
  12. package/dist/account-system-entity/account-system-entity.js +55 -66
  13. package/dist/account-system-entity/account-system-entity.js.map +1 -1
  14. package/dist/account-system-entity/post-history.repository.d.ts +5 -5
  15. package/dist/account-system-entity/post-history.repository.js +11 -11
  16. package/dist/config.d.ts +1888 -1888
  17. package/dist/config.js +331 -331
  18. package/dist/config.js.map +1 -1
  19. package/dist/customer/customer.d.ts +44 -44
  20. package/dist/customer/customer.js +212 -234
  21. package/dist/customer/customer.js.map +1 -1
  22. package/dist/customer/finance-customer.repository.d.ts +5 -5
  23. package/dist/customer/finance-customer.repository.js +25 -25
  24. package/dist/customer/finance-customer.repository.js.map +1 -1
  25. package/dist/customer/interfaces/customer.repository.interface.d.ts +3 -3
  26. package/dist/customer/interfaces/customer.repository.interface.js +2 -2
  27. package/dist/customer/interfaces/finance-customer-attr.interface.d.ts +10 -10
  28. package/dist/customer/interfaces/finance-customer-attr.interface.js +2 -2
  29. package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +3 -3
  30. package/dist/customer/interfaces/finance-customer.repository.interface.js +2 -2
  31. package/dist/database.d.ts +4 -4
  32. package/dist/database.js +46 -47
  33. package/dist/database.js.map +1 -1
  34. package/dist/document/document-item.d.ts +46 -46
  35. package/dist/document/document-item.js +122 -132
  36. package/dist/document/document-item.js.map +1 -1
  37. package/dist/document/document-item.repository.d.ts +5 -5
  38. package/dist/document/document-item.repository.js +11 -11
  39. package/dist/document/document.d.ts +87 -88
  40. package/dist/document/document.js +735 -766
  41. package/dist/document/document.js.map +1 -1
  42. package/dist/document/document.repository.d.ts +5 -5
  43. package/dist/document/document.repository.js +11 -11
  44. package/dist/document/interfaces/document-attr.interface.d.ts +27 -27
  45. package/dist/document/interfaces/document-attr.interface.js +6 -6
  46. package/dist/document/interfaces/document-find-all.interface.d.ts +13 -13
  47. package/dist/document/interfaces/document-find-all.interface.js +2 -2
  48. package/dist/document/interfaces/document-item-attr.interface.d.ts +26 -26
  49. package/dist/document/interfaces/document-item-attr.interface.js +6 -6
  50. package/dist/document/interfaces/document-item.repository.interface.d.ts +3 -3
  51. package/dist/document/interfaces/document-item.repository.interface.js +2 -2
  52. package/dist/enum/collect-payment-type.d.ts +4 -4
  53. package/dist/enum/collect-payment-type.js +8 -8
  54. package/dist/enum/collect-payment-type.js.map +1 -1
  55. package/dist/enum/doc-type.enum.d.ts +8 -8
  56. package/dist/enum/doc-type.enum.js +12 -12
  57. package/dist/enum/doc-type.enum.js.map +1 -1
  58. package/dist/enum/document-status.enum.d.ts +6 -6
  59. package/dist/enum/document-status.enum.js +10 -10
  60. package/dist/enum/document-status.enum.js.map +1 -1
  61. package/dist/enum/index.d.ts +9 -9
  62. package/dist/enum/index.js +19 -19
  63. package/dist/enum/payment-method.enum.d.ts +3 -3
  64. package/dist/enum/payment-method.enum.js +7 -7
  65. package/dist/enum/payment-method.enum.js.map +1 -1
  66. package/dist/enum/payment-status.enum.d.ts +10 -10
  67. package/dist/enum/payment-status.enum.js +15 -16
  68. package/dist/enum/payment-status.enum.js.map +1 -1
  69. package/dist/enum/payment-type.enum.d.ts +4 -4
  70. package/dist/enum/payment-type.enum.js +8 -8
  71. package/dist/enum/payment-type.enum.js.map +1 -1
  72. package/dist/enum/quick-book-client-scopes.enum.d.ts +13 -13
  73. package/dist/enum/quick-book-client-scopes.enum.js +18 -18
  74. package/dist/enum/quick-book-client-scopes.enum.js.map +1 -1
  75. package/dist/enum/transaction-type.enum.d.ts +4 -4
  76. package/dist/enum/transaction-type.enum.js +8 -8
  77. package/dist/enum/transaction-type.enum.js.map +1 -1
  78. package/dist/finance-company/finance-company.d.ts +88 -88
  79. package/dist/finance-company/finance-company.js +1533 -1576
  80. package/dist/finance-company/finance-company.js.map +1 -1
  81. package/dist/finance-company/finance-company.repository.d.ts +5 -5
  82. package/dist/finance-company/finance-company.repository.js +11 -11
  83. package/dist/helpers/login-user.d.ts +13 -13
  84. package/dist/helpers/login-user.js +28 -28
  85. package/dist/helpers/login-user.js.map +1 -1
  86. package/dist/helpers/typeof.d.ts +1 -1
  87. package/dist/helpers/typeof.js +28 -29
  88. package/dist/helpers/typeof.js.map +1 -1
  89. package/dist/index.d.ts +17 -17
  90. package/dist/index.js +32 -32
  91. package/dist/interfaces/account-system.interface.d.ts +30 -30
  92. package/dist/interfaces/account-system.interface.js +2 -2
  93. package/dist/interfaces/index.d.ts +2 -2
  94. package/dist/interfaces/index.js +2 -2
  95. package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +12 -12
  96. package/dist/journal-entry/interfaces/journal-entry-attr.interface.js +2 -2
  97. package/dist/journal-entry/journal-entry.d.ts +42 -42
  98. package/dist/journal-entry/journal-entry.js +216 -233
  99. package/dist/journal-entry/journal-entry.js.map +1 -1
  100. package/dist/journal-entry/journal-entry.repository.d.ts +6 -6
  101. package/dist/journal-entry/journal-entry.repository.js +16 -27
  102. package/dist/journal-entry/journal-entry.repository.js.map +1 -1
  103. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +17 -17
  104. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js +2 -2
  105. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +5 -5
  106. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js +2 -2
  107. package/dist/ledger-transaction/ledger-transaction.d.ts +54 -54
  108. package/dist/ledger-transaction/ledger-transaction.js +143 -164
  109. package/dist/ledger-transaction/ledger-transaction.js.map +1 -1
  110. package/dist/ledger-transaction/ledger-transaction.repository.d.ts +6 -6
  111. package/dist/ledger-transaction/ledger-transaction.repository.js +16 -27
  112. package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -1
  113. package/dist/models/account.entity.d.ts +30 -30
  114. package/dist/models/account.entity.js +232 -232
  115. package/dist/models/account.entity.js.map +1 -1
  116. package/dist/models/customer.entity.d.ts +13 -13
  117. package/dist/models/customer.entity.js +109 -109
  118. package/dist/models/customer.entity.js.map +1 -1
  119. package/dist/models/document-item.entity.d.ts +31 -31
  120. package/dist/models/document-item.entity.js +200 -200
  121. package/dist/models/document-item.entity.js.map +1 -1
  122. package/dist/models/document.entity.d.ts +36 -36
  123. package/dist/models/document.entity.js +242 -242
  124. package/dist/models/document.entity.js.map +1 -1
  125. package/dist/models/finance-company.entity.d.ts +15 -15
  126. package/dist/models/finance-company.entity.js +93 -93
  127. package/dist/models/finance-company.entity.js.map +1 -1
  128. package/dist/models/journal-entry.entity.d.ts +16 -16
  129. package/dist/models/journal-entry.entity.js +127 -127
  130. package/dist/models/journal-entry.entity.js.map +1 -1
  131. package/dist/models/ledger-transaction.entity.d.ts +24 -24
  132. package/dist/models/ledger-transaction.entity.js +172 -172
  133. package/dist/models/ledger-transaction.entity.js.map +1 -1
  134. package/dist/models/payment-item.entity.d.ts +12 -12
  135. package/dist/models/payment-item.entity.js +75 -75
  136. package/dist/models/payment-item.entity.js.map +1 -1
  137. package/dist/models/payment-method-type.entity.d.ts +13 -13
  138. package/dist/models/payment-method-type.entity.js +85 -85
  139. package/dist/models/payment-method-type.entity.js.map +1 -1
  140. package/dist/models/payment-method.entity.d.ts +10 -10
  141. package/dist/models/payment-method.entity.js +62 -62
  142. package/dist/models/payment-method.entity.js.map +1 -1
  143. package/dist/models/payment-paid-with.entity.d.ts +24 -24
  144. package/dist/models/payment-paid-with.entity.js +158 -158
  145. package/dist/models/payment-paid-with.entity.js.map +1 -1
  146. package/dist/models/payment.entity.d.ts +29 -29
  147. package/dist/models/payment.entity.js +193 -193
  148. package/dist/models/payment.entity.js.map +1 -1
  149. package/dist/models/post-history.entity.d.ts +11 -11
  150. package/dist/models/post-history.entity.js +63 -63
  151. package/dist/models/post-history.entity.js.map +1 -1
  152. package/dist/models/tax.entity.d.ts +13 -13
  153. package/dist/models/tax.entity.js +89 -89
  154. package/dist/models/tax.entity.js.map +1 -1
  155. package/dist/payment/interfaces/payment-attr.interface.d.ts +22 -22
  156. package/dist/payment/interfaces/payment-attr.interface.js +6 -6
  157. package/dist/payment/interfaces/payment-params.interface.d.ts +7 -7
  158. package/dist/payment/interfaces/payment-params.interface.js +2 -2
  159. package/dist/payment/payment.d.ts +53 -53
  160. package/dist/payment/payment.js +186 -201
  161. package/dist/payment/payment.js.map +1 -1
  162. package/dist/payment/payment.repository.d.ts +5 -5
  163. package/dist/payment/payment.repository.js +11 -11
  164. package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +10 -10
  165. package/dist/payment-item/interfaces/payment-item-attr.interface.js +6 -6
  166. package/dist/payment-item/payment-item.d.ts +25 -25
  167. package/dist/payment-item/payment-item.js +111 -122
  168. package/dist/payment-item/payment-item.js.map +1 -1
  169. package/dist/payment-item/payment-item.repository.d.ts +5 -5
  170. package/dist/payment-item/payment-item.repository.js +11 -11
  171. package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts +5 -5
  172. package/dist/payment-method/interfaces/payment-method-attr.interface.js +2 -2
  173. package/dist/payment-method/payment-method.d.ts +21 -21
  174. package/dist/payment-method/payment-method.js +104 -117
  175. package/dist/payment-method/payment-method.js.map +1 -1
  176. package/dist/payment-method/payment-method.repository.d.ts +5 -5
  177. package/dist/payment-method/payment-method.repository.js +11 -11
  178. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts +8 -8
  179. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js +2 -2
  180. package/dist/payment-method-type/payment-method-type.d.ts +18 -18
  181. package/dist/payment-method-type/payment-method-type.js +65 -76
  182. package/dist/payment-method-type/payment-method-type.js.map +1 -1
  183. package/dist/payment-method-type/payment-method-type.repository.d.ts +5 -5
  184. package/dist/payment-method-type/payment-method-type.repository.js +11 -11
  185. package/dist/payment-paid-with/interfaces/payment-paid-with.interface.d.ts +19 -19
  186. package/dist/payment-paid-with/interfaces/payment-paid-with.interface.js +6 -6
  187. package/dist/payment-paid-with/payment-paid-with.d.ts +33 -33
  188. package/dist/payment-paid-with/payment-paid-with.js +56 -56
  189. package/dist/payment-paid-with/payment-paid-with.js.map +1 -1
  190. package/dist/payment-paid-with/payment-paid-with.repository.d.ts +5 -5
  191. package/dist/payment-paid-with/payment-paid-with.repository.js +11 -11
  192. package/dist/tax/interfaces/tax-attr.interface.d.ts +10 -10
  193. package/dist/tax/interfaces/tax-attr.interface.js +2 -2
  194. package/dist/tax/tax.d.ts +26 -26
  195. package/dist/tax/tax.js +51 -51
  196. package/dist/tax/tax.js.map +1 -1
  197. package/dist/tax/tax.repository.d.ts +5 -5
  198. package/dist/tax/tax.repository.js +11 -11
  199. package/dist/test-document.d.ts +3 -3
  200. package/dist/test-document.js +18 -18
  201. package/dist/test.d.ts +1 -1
  202. package/dist/test.js +6 -7
  203. package/dist/test.js.map +1 -1
  204. package/dist/tsconfig.tsbuildinfo +1 -1
  205. package/eslint.config.mjs +58 -0
  206. package/invoice-template/assets/js/html2canvas.min.js +16 -16
  207. package/package.json +35 -41
  208. package/src/account/account.ts +2 -1
  209. package/src/customer/customer.ts +8 -7
  210. package/src/document/document-item.ts +3 -2
  211. package/src/document/document.ts +20 -13
  212. package/src/enum/collect-payment-type.ts +3 -3
  213. package/src/enum/payment-status.enum.ts +1 -1
  214. package/src/finance-company/finance-company.ts +5 -7
  215. package/src/journal-entry/journal-entry.ts +0 -1
  216. package/src/ledger-transaction/ledger-transaction.ts +4 -4
  217. package/src/payment-method-type/payment-method-type.ts +1 -1
  218. package/src/tax/tax.ts +0 -1
  219. package/tsconfig.json +4 -3
  220. package/.eslintrc.js +0 -72
  221. package/img.png +0 -0
  222. package/img_1.png +0 -0
  223. package/tslint.json +0 -18
@@ -1,395 +1,376 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- const util = require("util");
13
- const path = require("path");
14
- const fs = require("fs");
15
- const puppeteer = require("puppeteer");
16
- const media_1 = require("@tomei/media");
17
- const enum_1 = require("../enum");
18
- const document_item_repository_1 = require("./document-item.repository");
19
- const document_item_1 = require("./document-item");
20
- const account_system_entity_1 = require("../account-system-entity/account-system-entity");
21
- const document_repository_1 = require("./document.repository");
22
- const document_item_entity_1 = require("../models/document-item.entity");
23
- const general_1 = require("@tomei/general");
24
- const config_1 = require("@tomei/config");
25
- const sequelize_1 = require("sequelize");
26
- const login_user_1 = require("../helpers/login-user");
27
- const activity_history_1 = require("@tomei/activity-history");
28
- class Document extends account_system_entity_1.AccountSystemEntity {
29
- get ObjectType() {
30
- return this._ObjectType;
31
- }
32
- get IsNewRecord() {
33
- return this._IsNewRecord;
34
- }
35
- set IsNewRecord(record) {
36
- this._IsNewRecord = record;
37
- }
38
- get DocType() {
39
- return this._DocType;
40
- }
41
- set DocType(docType) {
42
- this._DocType = docType;
43
- }
44
- get DocDate() {
45
- return this._DocDate;
46
- }
47
- set DocDate(date) {
48
- this._DocDate = date;
49
- }
50
- get DocHTMLFileMediaId() {
51
- return this._DocHTMLFileMediaId;
52
- }
53
- set DocHTMLFileMediaId(mediaId) {
54
- this._DocHTMLFileMediaId = mediaId;
55
- }
56
- get DocPDFFileMediaId() {
57
- return this._DocPDFFileMediaId;
58
- }
59
- set DocPDFFileMediaId(mediaId) {
60
- this._DocPDFFileMediaId = mediaId;
61
- }
62
- get Amount() {
63
- return this._Amount;
64
- }
65
- set Amount(amount) {
66
- this._Amount = amount;
67
- }
68
- get Status() {
69
- return this._Status;
70
- }
71
- set Status(status) {
72
- this._Status = status;
73
- }
74
- get RepositoryBase() {
75
- return Document._RepositoryBase;
76
- }
77
- get ObjectId() {
78
- return this.DocNo;
79
- }
80
- get ObjectName() {
81
- return this.DocNo;
82
- }
83
- get TableName() {
84
- return 'finance_Document';
85
- }
86
- constructor(dbTransaction, documentData) {
87
- super();
88
- this.DocNo = 'New';
89
- this._DocDate = new Date();
90
- this.Currency = 'MYR';
91
- this._Amount = 0;
92
- this.Description = '';
93
- this._Status = enum_1.DocumentStatus.UNPAID;
94
- this.IssuedById = '';
95
- this.IssuedToId = '';
96
- this.IssuedToType = '';
97
- this.RelatedObjectId = '';
98
- this.RelatedObjectType = '';
99
- this.CreatedById = '';
100
- this.UpdatedById = '';
101
- this.UseAccSystemDocYN = 'N';
102
- this._ObjectType = 'Document';
103
- this._DocHTMLFileMediaId = '';
104
- this._DocPDFFileMediaId = '';
105
- this._IsNewRecord = true;
106
- this._DocumentItems = [];
107
- if (dbTransaction) {
108
- this._DbTransaction = dbTransaction;
109
- }
110
- if (documentData) {
111
- this.DocNo = documentData.DocNo;
112
- this.DocType = documentData.DocType;
113
- this.DocDate = documentData.DocDate;
114
- this.CompanyId = documentData.CompanyId;
115
- this.Currency = documentData.Currency;
116
- this.Amount = documentData.Amount;
117
- this.Description = documentData.Description;
118
- this.Status = documentData.Status;
119
- this.IssuedById = documentData.IssuedById;
120
- this.IssuedToId = documentData.IssuedToId;
121
- this.IssuedToType = documentData.IssuedToType;
122
- this.RelatedObjectId = documentData.RelatedObjectId;
123
- this.RelatedObjectType = documentData.RelatedObjectType;
124
- this.CreatedById = documentData.CreatedById;
125
- this.CreatedAt = documentData.CreatedAt;
126
- this.UpdatedById = documentData.UpdatedById;
127
- this.UpdatedAt = documentData.UpdatedAt;
128
- this.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
129
- this.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
130
- this.AccSystemRefId = documentData.AccSystemRefId;
131
- this.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
132
- this.PostedById = documentData.PostedById;
133
- this.PostedDateTime = documentData.PostedDateTime;
134
- this.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
135
- this.IsNewRecord = false;
136
- }
137
- }
138
- init(params) {
139
- this.DocNo = params.DocNo;
140
- this.DocType = params.DocType;
141
- this.DocDate = params.DocDate;
142
- this.CompanyId = params.CompanyId;
143
- this.Currency = params.Currency;
144
- this.Amount = params.Amount;
145
- this.Description = params.Description;
146
- this.Status = params.Status;
147
- this.IssuedById = params.IssuedById;
148
- this.IssuedToId = params.IssuedToId;
149
- this.IssuedToType = params.IssuedToType;
150
- this.RelatedObjectId = params.RelatedObjectId;
151
- this.RelatedObjectType = params.RelatedObjectType;
152
- this.CreatedById = params.CreatedById;
153
- this.CreatedAt = params.CreatedAt;
154
- this.UpdatedById = params.UpdatedById;
155
- this.UpdatedAt = params.UpdatedAt;
156
- this.DocPDFFileMediaId = params.DocPDFFileMediaId;
157
- this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
158
- this.AccSystemRefId = params.AccSystemRefId;
159
- this.PostedToAccSystemYN = params.PostedToAccSystemYN;
160
- this.PostedById = params.PostedById;
161
- this.PostedDateTime = params.PostedDateTime;
162
- this.UseAccSystemDocYN = params.UseAccSystemDocYN;
163
- }
164
- static initDocument(dbTransaction, docNo) {
165
- return __awaiter(this, void 0, void 0, function* () {
166
- try {
167
- const documentData = yield this._RepositoryBase.findOne({
168
- where: {
169
- DocNo: docNo,
170
- },
171
- include: [
172
- {
173
- model: document_item_entity_1.default,
174
- },
175
- ],
176
- transaction: dbTransaction,
177
- });
178
- if (documentData) {
179
- const document = new Document(dbTransaction, {
180
- DocNo: documentData.DocNo,
181
- DocType: documentData.DocType,
182
- CompanyId: documentData.CompanyId,
183
- DocDate: documentData.DocDate,
184
- Currency: documentData.Currency,
185
- Amount: documentData.Amount,
186
- Description: documentData.Description,
187
- Status: documentData.Status,
188
- IssuedById: documentData.IssuedById,
189
- IssuedToId: documentData.IssuedToId,
190
- IssuedToType: documentData.IssuedToType,
191
- RelatedObjectId: documentData.RelatedObjectId,
192
- RelatedObjectType: documentData.RelatedObjectType,
193
- CreatedById: documentData.CreatedById,
194
- CreatedAt: documentData.CreatedAt,
195
- UpdatedById: documentData.UpdatedById,
196
- UpdatedAt: documentData.UpdatedAt,
197
- DocPDFFileMediaId: documentData.DocPDFFileMediaId,
198
- DocHTMLFileMediaId: documentData.DocHTMLFileMediaId,
199
- AccSystemRefId: documentData.AccSystemRefId,
200
- PostedToAccSystemYN: documentData.PostedToAccSystemYN,
201
- PostedById: documentData.PostedById,
202
- PostedDateTime: documentData.PostedDateTime,
203
- UseAccSystemDocYN: documentData.UseAccSystemDocYN,
204
- });
205
- return document;
206
- }
207
- else {
208
- const notFoundError = new general_1.ClassError('Document', 'InitDocumentErrMsg00', `No Document record found.`);
209
- throw notFoundError;
210
- }
211
- }
212
- catch (error) {
213
- throw error;
214
- }
215
- });
216
- }
217
- reCalculateAmount() {
218
- return __awaiter(this, void 0, void 0, function* () {
219
- this.Amount = 0;
220
- for (const documentItem of this._DocumentItems) {
221
- this.Amount += documentItem.Amount;
222
- }
223
- });
224
- }
225
- get DocumentItems() {
226
- return new Promise((resolve, reject) => {
227
- if (!this.IsNewRecord) {
228
- document_item_1.default.initDocumentItems(this._DbTransaction, this)
229
- .then((documentItems) => {
230
- resolve(documentItems);
231
- })
232
- .catch((err) => {
233
- reject(err);
234
- });
235
- }
236
- else {
237
- resolve(this._DocumentItems);
238
- }
239
- });
240
- }
241
- getDocumentItems(dbTransaction) {
242
- return __awaiter(this, void 0, void 0, function* () {
243
- try {
244
- if (!this.IsNewRecord) {
245
- const documentItems = yield document_item_1.default.initDocumentItems(dbTransaction, this);
246
- this._DocumentItems = documentItems;
247
- }
248
- return this._DocumentItems;
249
- }
250
- catch (error) {
251
- throw error;
252
- }
253
- });
254
- }
255
- static settleByCreditNote(loginUser, dbTransaction, DocNo, AmountToReduce) {
256
- return __awaiter(this, void 0, void 0, function* () {
257
- const document = yield this.initDocument(dbTransaction, DocNo);
258
- if (document.DocType !== enum_1.DocType.INVOICE) {
259
- throw new general_1.ClassError('Document', 'SettleByCreditNoteErrMsgXX', 'Only Invoice can be issued credit note.');
260
- }
261
- if (AmountToReduce > document.Amount) {
262
- throw new general_1.ClassError('Document', 'SettleByCreditNoteErrMsgXX', 'Amount to reduce is more than the document amount.');
263
- }
264
- const EntityValueBefore = {
265
- DocNo: document.DocNo,
266
- DocType: document.DocType,
267
- CompanyId: document.CompanyId,
268
- DocDate: document.DocDate,
269
- Currency: document.Currency,
270
- Amount: document.Amount,
271
- Description: document.Description,
272
- Status: document.Status,
273
- IssuedById: document.IssuedById,
274
- IssuedToId: document.IssuedToId,
275
- IssuedToType: document.IssuedToType,
276
- RelatedObjectId: document.RelatedObjectId,
277
- RelatedObjectType: document.RelatedObjectType,
278
- CreatedById: document.CreatedById,
279
- CreatedAt: document.CreatedAt,
280
- UpdatedById: document.UpdatedById,
281
- UpdatedAt: document.UpdatedAt,
282
- DocPDFFileMediaId: document.DocPDFFileMediaId,
283
- DocHTMLFileMediaId: document.DocHTMLFileMediaId,
284
- AccSystemRefId: document.AccSystemRefId,
285
- PostedToAccSystemYN: document.PostedToAccSystemYN,
286
- PostedById: document.PostedById,
287
- PostedDateTime: document.PostedDateTime,
288
- UseAccSystemDocYN: document.UseAccSystemDocYN,
289
- };
290
- let updatedStatus;
291
- if (AmountToReduce == document.Amount) {
292
- updatedStatus = enum_1.DocumentStatus.SETTLED;
293
- }
294
- else {
295
- updatedStatus = enum_1.DocumentStatus.PARTIALSETTLED;
296
- }
297
- yield this._RepositoryBase.update({
298
- Amount: AmountToReduce,
299
- Status: updatedStatus,
300
- UpdatedAt: document.UpdatedAt,
301
- UpdatedById: document.UpdatedById,
302
- }, {
303
- where: {
304
- DocNo: document.DocNo,
305
- },
306
- transaction: dbTransaction,
307
- });
308
- const UpdatedDocument = yield this.initDocument(dbTransaction, DocNo);
309
- const EntityValueAfter = {
310
- DocNo: UpdatedDocument.DocNo,
311
- DocType: UpdatedDocument.DocType,
312
- CompanyId: UpdatedDocument.CompanyId,
313
- DocDate: UpdatedDocument.DocDate,
314
- Currency: UpdatedDocument.Currency,
315
- Amount: UpdatedDocument.Amount,
316
- Description: UpdatedDocument.Description,
317
- Status: UpdatedDocument.Status,
318
- IssuedById: UpdatedDocument.IssuedById,
319
- IssuedToId: UpdatedDocument.IssuedToId,
320
- IssuedToType: UpdatedDocument.IssuedToType,
321
- RelatedObjectId: UpdatedDocument.RelatedObjectId,
322
- RelatedObjectType: UpdatedDocument.RelatedObjectType,
323
- CreatedById: UpdatedDocument.CreatedById,
324
- CreatedAt: UpdatedDocument.CreatedAt,
325
- UpdatedById: UpdatedDocument.UpdatedById,
326
- UpdatedAt: UpdatedDocument.UpdatedAt,
327
- DocPDFFileMediaId: UpdatedDocument.DocPDFFileMediaId,
328
- DocHTMLFileMediaId: UpdatedDocument.DocHTMLFileMediaId,
329
- AccSystemRefId: UpdatedDocument.AccSystemRefId,
330
- PostedToAccSystemYN: UpdatedDocument.PostedToAccSystemYN,
331
- PostedById: UpdatedDocument.PostedById,
332
- PostedDateTime: UpdatedDocument.PostedDateTime,
333
- UseAccSystemDocYN: UpdatedDocument.UseAccSystemDocYN,
334
- };
335
- const activity = new activity_history_1.Activity();
336
- activity.ActivityId = activity.createId();
337
- activity.Action = activity_history_1.ActionEnum.UPDATE;
338
- activity.Description = `Settle Finance Document (${UpdatedDocument._DocType}) from Credit Note.`;
339
- activity.EntityType = 'FinanceCustomer';
340
- activity.EntityId = DocNo;
341
- activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
342
- activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
343
- yield activity.create(loginUser.ObjectId, dbTransaction);
344
- return UpdatedDocument;
345
- });
346
- }
347
- static DEFAULT_INVOICE_TEMPLATE_HTML() {
348
- return __awaiter(this, void 0, void 0, function* () {
349
- const templateLocation = path.resolve('./invoice-template/index.html');
350
- const readFileContent = util.promisify(fs.readFile);
351
- const htmlBuffer = yield readFileContent(templateLocation);
352
- const htmlStream = {
353
- buffer: htmlBuffer,
354
- fieldname: 'FileStream',
355
- originalname: 'index.html',
356
- mimetype: 'text/html',
357
- size: htmlBuffer.length,
358
- encoding: '8bit',
359
- filename: 'sample-invoice.html',
360
- destination: path.dirname(templateLocation),
361
- path: '',
362
- stream: null,
363
- };
364
- return htmlStream;
365
- });
366
- }
367
- DEFAULT_INVOICE_TEMPLATE_PDF(customer, date = new Date()) {
368
- return __awaiter(this, void 0, void 0, function* () {
369
- const templateLocation = path.resolve('./invoice-template/index.html');
370
- const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
371
- const readFileContent = util.promisify(fs.readFile);
372
- const [htmlString] = yield Promise.all([
373
- readFileContent(templateLocation, 'utf8'),
374
- ]);
375
- const browser = yield puppeteer.launch({
376
- headless: true,
377
- args: ['--no-sandbox', '--disable-setuid-sandbox'],
378
- });
379
- const page = yield browser.newPage();
380
- const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
381
- const imageBuffer = yield readFileContent(imagePath);
382
- const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
383
- const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
384
- yield page.setContent(htmlString);
385
- yield page.addStyleTag({ path: cssLocation });
386
- const divHandle = yield page.$('.tm_logo');
387
- yield divHandle.evaluate((div, imgTag) => {
388
- div.innerHTML = imgTag;
389
- }, imgTag);
390
- const currentDate = date.toLocaleDateString('en-GB');
391
- const invoiceNo = this.DocNo;
392
- const invoiceTitleInfo = `
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const util = require("util");
4
+ const path = require("path");
5
+ const fs = require("fs");
6
+ const puppeteer = require("puppeteer");
7
+ const media_1 = require("@tomei/media");
8
+ const enum_1 = require("../enum");
9
+ const document_item_repository_1 = require("./document-item.repository");
10
+ const document_item_1 = require("./document-item");
11
+ const account_system_entity_1 = require("../account-system-entity/account-system-entity");
12
+ const document_repository_1 = require("./document.repository");
13
+ const document_item_entity_1 = require("../models/document-item.entity");
14
+ const general_1 = require("@tomei/general");
15
+ const config_1 = require("@tomei/config");
16
+ const sequelize_1 = require("sequelize");
17
+ const login_user_1 = require("../helpers/login-user");
18
+ const activity_history_1 = require("@tomei/activity-history");
19
+ class Document extends account_system_entity_1.AccountSystemEntity {
20
+ get ObjectType() {
21
+ return this._ObjectType;
22
+ }
23
+ get IsNewRecord() {
24
+ return this._IsNewRecord;
25
+ }
26
+ set IsNewRecord(record) {
27
+ this._IsNewRecord = record;
28
+ }
29
+ get DocType() {
30
+ return this._DocType;
31
+ }
32
+ set DocType(docType) {
33
+ this._DocType = docType;
34
+ }
35
+ get DocDate() {
36
+ return this._DocDate;
37
+ }
38
+ set DocDate(date) {
39
+ this._DocDate = date;
40
+ }
41
+ get DocHTMLFileMediaId() {
42
+ return this._DocHTMLFileMediaId;
43
+ }
44
+ set DocHTMLFileMediaId(mediaId) {
45
+ this._DocHTMLFileMediaId = mediaId;
46
+ }
47
+ get DocPDFFileMediaId() {
48
+ return this._DocPDFFileMediaId;
49
+ }
50
+ set DocPDFFileMediaId(mediaId) {
51
+ this._DocPDFFileMediaId = mediaId;
52
+ }
53
+ get Amount() {
54
+ return this._Amount;
55
+ }
56
+ set Amount(amount) {
57
+ this._Amount = amount;
58
+ }
59
+ get Status() {
60
+ return this._Status;
61
+ }
62
+ set Status(status) {
63
+ this._Status = status;
64
+ }
65
+ get RepositoryBase() {
66
+ return Document._RepositoryBase;
67
+ }
68
+ get ObjectId() {
69
+ return this.DocNo;
70
+ }
71
+ get ObjectName() {
72
+ return this.DocNo;
73
+ }
74
+ get TableName() {
75
+ return 'finance_Document';
76
+ }
77
+ constructor(dbTransaction, documentData) {
78
+ super();
79
+ this.DocNo = 'New';
80
+ this._DocDate = new Date();
81
+ this.Currency = 'MYR';
82
+ this._Amount = 0;
83
+ this.Description = '';
84
+ this._Status = enum_1.DocumentStatus.UNPAID;
85
+ this.IssuedById = '';
86
+ this.IssuedToId = '';
87
+ this.IssuedToType = '';
88
+ this.RelatedObjectId = '';
89
+ this.RelatedObjectType = '';
90
+ this.CreatedById = '';
91
+ this.UpdatedById = '';
92
+ this.UseAccSystemDocYN = 'N';
93
+ this._ObjectType = 'Document';
94
+ this._DocHTMLFileMediaId = '';
95
+ this._DocPDFFileMediaId = '';
96
+ this._IsNewRecord = true;
97
+ this._DocumentItems = [];
98
+ if (dbTransaction) {
99
+ this._DbTransaction = dbTransaction;
100
+ }
101
+ if (documentData) {
102
+ this.DocNo = documentData.DocNo;
103
+ this.DocType = documentData.DocType;
104
+ this.DocDate = documentData.DocDate;
105
+ this.CompanyId = documentData.CompanyId;
106
+ this.Currency = documentData.Currency;
107
+ this.Amount = documentData.Amount;
108
+ this.Description = documentData.Description;
109
+ this.Status = documentData.Status;
110
+ this.IssuedById = documentData.IssuedById;
111
+ this.IssuedToId = documentData.IssuedToId;
112
+ this.IssuedToType = documentData.IssuedToType;
113
+ this.RelatedObjectId = documentData.RelatedObjectId;
114
+ this.RelatedObjectType = documentData.RelatedObjectType;
115
+ this.CreatedById = documentData.CreatedById;
116
+ this.CreatedAt = documentData.CreatedAt;
117
+ this.UpdatedById = documentData.UpdatedById;
118
+ this.UpdatedAt = documentData.UpdatedAt;
119
+ this.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
120
+ this.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
121
+ this.AccSystemRefId = documentData.AccSystemRefId;
122
+ this.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
123
+ this.PostedById = documentData.PostedById;
124
+ this.PostedDateTime = documentData.PostedDateTime;
125
+ this.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
126
+ this.IsNewRecord = false;
127
+ }
128
+ }
129
+ init(params) {
130
+ this.DocNo = params.DocNo;
131
+ this.DocType = params.DocType;
132
+ this.DocDate = params.DocDate;
133
+ this.CompanyId = params.CompanyId;
134
+ this.Currency = params.Currency;
135
+ this.Amount = params.Amount;
136
+ this.Description = params.Description;
137
+ this.Status = params.Status;
138
+ this.IssuedById = params.IssuedById;
139
+ this.IssuedToId = params.IssuedToId;
140
+ this.IssuedToType = params.IssuedToType;
141
+ this.RelatedObjectId = params.RelatedObjectId;
142
+ this.RelatedObjectType = params.RelatedObjectType;
143
+ this.CreatedById = params.CreatedById;
144
+ this.CreatedAt = params.CreatedAt;
145
+ this.UpdatedById = params.UpdatedById;
146
+ this.UpdatedAt = params.UpdatedAt;
147
+ this.DocPDFFileMediaId = params.DocPDFFileMediaId;
148
+ this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
149
+ this.AccSystemRefId = params.AccSystemRefId;
150
+ this.PostedToAccSystemYN = params.PostedToAccSystemYN;
151
+ this.PostedById = params.PostedById;
152
+ this.PostedDateTime = params.PostedDateTime;
153
+ this.UseAccSystemDocYN = params.UseAccSystemDocYN;
154
+ }
155
+ static async initDocument(dbTransaction, docNo) {
156
+ try {
157
+ const documentData = await this._RepositoryBase.findOne({
158
+ where: {
159
+ DocNo: docNo,
160
+ },
161
+ include: [
162
+ {
163
+ model: document_item_entity_1.default,
164
+ },
165
+ ],
166
+ transaction: dbTransaction,
167
+ });
168
+ if (documentData) {
169
+ const document = new Document(dbTransaction, {
170
+ DocNo: documentData.DocNo,
171
+ DocType: documentData.DocType,
172
+ CompanyId: documentData.CompanyId,
173
+ DocDate: documentData.DocDate,
174
+ Currency: documentData.Currency,
175
+ Amount: documentData.Amount,
176
+ Description: documentData.Description,
177
+ Status: documentData.Status,
178
+ IssuedById: documentData.IssuedById,
179
+ IssuedToId: documentData.IssuedToId,
180
+ IssuedToType: documentData.IssuedToType,
181
+ RelatedObjectId: documentData.RelatedObjectId,
182
+ RelatedObjectType: documentData.RelatedObjectType,
183
+ CreatedById: documentData.CreatedById,
184
+ CreatedAt: documentData.CreatedAt,
185
+ UpdatedById: documentData.UpdatedById,
186
+ UpdatedAt: documentData.UpdatedAt,
187
+ DocPDFFileMediaId: documentData.DocPDFFileMediaId,
188
+ DocHTMLFileMediaId: documentData.DocHTMLFileMediaId,
189
+ AccSystemRefId: documentData.AccSystemRefId,
190
+ PostedToAccSystemYN: documentData.PostedToAccSystemYN,
191
+ PostedById: documentData.PostedById,
192
+ PostedDateTime: documentData.PostedDateTime,
193
+ UseAccSystemDocYN: documentData.UseAccSystemDocYN,
194
+ });
195
+ return document;
196
+ }
197
+ else {
198
+ const notFoundError = new general_1.ClassError('Document', 'InitDocumentErrMsg00', `No Document record found.`);
199
+ throw notFoundError;
200
+ }
201
+ }
202
+ catch (error) {
203
+ throw error;
204
+ }
205
+ }
206
+ async reCalculateAmount() {
207
+ const roundToTwoDecimals = (value) => Math.round(value * 100) / 100;
208
+ this.Amount = 0;
209
+ for (const documentItem of this._DocumentItems) {
210
+ this.Amount = roundToTwoDecimals(this.Amount + documentItem.Amount);
211
+ }
212
+ }
213
+ get DocumentItems() {
214
+ return new Promise((resolve, reject) => {
215
+ if (!this.IsNewRecord) {
216
+ document_item_1.default.initDocumentItems(this._DbTransaction, this)
217
+ .then((documentItems) => {
218
+ resolve(documentItems);
219
+ })
220
+ .catch((err) => {
221
+ reject(err);
222
+ });
223
+ }
224
+ else {
225
+ resolve(this._DocumentItems);
226
+ }
227
+ });
228
+ }
229
+ async getDocumentItems(dbTransaction) {
230
+ try {
231
+ if (!this.IsNewRecord) {
232
+ const documentItems = await document_item_1.default.initDocumentItems(dbTransaction, this);
233
+ this._DocumentItems = documentItems;
234
+ }
235
+ return this._DocumentItems;
236
+ }
237
+ catch (error) {
238
+ throw error;
239
+ }
240
+ }
241
+ static async settleByCreditNote(loginUser, dbTransaction, DocNo, AmountToReduce) {
242
+ const document = await this.initDocument(dbTransaction, DocNo);
243
+ if (document.DocType !== enum_1.DocType.INVOICE) {
244
+ throw new general_1.ClassError('Document', 'SettleByCreditNoteErrMsgXX', 'Only Invoice can be issued credit note.');
245
+ }
246
+ if (AmountToReduce > document.Amount) {
247
+ throw new general_1.ClassError('Document', 'SettleByCreditNoteErrMsgXX', 'Amount to reduce is more than the document amount.');
248
+ }
249
+ const EntityValueBefore = {
250
+ DocNo: document.DocNo,
251
+ DocType: document.DocType,
252
+ CompanyId: document.CompanyId,
253
+ DocDate: document.DocDate,
254
+ Currency: document.Currency,
255
+ Amount: document.Amount,
256
+ Description: document.Description,
257
+ Status: document.Status,
258
+ IssuedById: document.IssuedById,
259
+ IssuedToId: document.IssuedToId,
260
+ IssuedToType: document.IssuedToType,
261
+ RelatedObjectId: document.RelatedObjectId,
262
+ RelatedObjectType: document.RelatedObjectType,
263
+ CreatedById: document.CreatedById,
264
+ CreatedAt: document.CreatedAt,
265
+ UpdatedById: document.UpdatedById,
266
+ UpdatedAt: document.UpdatedAt,
267
+ DocPDFFileMediaId: document.DocPDFFileMediaId,
268
+ DocHTMLFileMediaId: document.DocHTMLFileMediaId,
269
+ AccSystemRefId: document.AccSystemRefId,
270
+ PostedToAccSystemYN: document.PostedToAccSystemYN,
271
+ PostedById: document.PostedById,
272
+ PostedDateTime: document.PostedDateTime,
273
+ UseAccSystemDocYN: document.UseAccSystemDocYN,
274
+ };
275
+ let updatedStatus;
276
+ if (AmountToReduce == document.Amount) {
277
+ updatedStatus = enum_1.DocumentStatus.SETTLED;
278
+ }
279
+ else {
280
+ updatedStatus = enum_1.DocumentStatus.PARTIALSETTLED;
281
+ }
282
+ await this._RepositoryBase.update({
283
+ Amount: AmountToReduce,
284
+ Status: updatedStatus,
285
+ UpdatedAt: document.UpdatedAt,
286
+ UpdatedById: document.UpdatedById,
287
+ }, {
288
+ where: {
289
+ DocNo: document.DocNo,
290
+ },
291
+ transaction: dbTransaction,
292
+ });
293
+ const UpdatedDocument = await this.initDocument(dbTransaction, DocNo);
294
+ const EntityValueAfter = {
295
+ DocNo: UpdatedDocument.DocNo,
296
+ DocType: UpdatedDocument.DocType,
297
+ CompanyId: UpdatedDocument.CompanyId,
298
+ DocDate: UpdatedDocument.DocDate,
299
+ Currency: UpdatedDocument.Currency,
300
+ Amount: UpdatedDocument.Amount,
301
+ Description: UpdatedDocument.Description,
302
+ Status: UpdatedDocument.Status,
303
+ IssuedById: UpdatedDocument.IssuedById,
304
+ IssuedToId: UpdatedDocument.IssuedToId,
305
+ IssuedToType: UpdatedDocument.IssuedToType,
306
+ RelatedObjectId: UpdatedDocument.RelatedObjectId,
307
+ RelatedObjectType: UpdatedDocument.RelatedObjectType,
308
+ CreatedById: UpdatedDocument.CreatedById,
309
+ CreatedAt: UpdatedDocument.CreatedAt,
310
+ UpdatedById: UpdatedDocument.UpdatedById,
311
+ UpdatedAt: UpdatedDocument.UpdatedAt,
312
+ DocPDFFileMediaId: UpdatedDocument.DocPDFFileMediaId,
313
+ DocHTMLFileMediaId: UpdatedDocument.DocHTMLFileMediaId,
314
+ AccSystemRefId: UpdatedDocument.AccSystemRefId,
315
+ PostedToAccSystemYN: UpdatedDocument.PostedToAccSystemYN,
316
+ PostedById: UpdatedDocument.PostedById,
317
+ PostedDateTime: UpdatedDocument.PostedDateTime,
318
+ UseAccSystemDocYN: UpdatedDocument.UseAccSystemDocYN,
319
+ };
320
+ const activity = new activity_history_1.Activity();
321
+ activity.ActivityId = activity.createId();
322
+ activity.Action = activity_history_1.ActionEnum.UPDATE;
323
+ activity.Description = `Settle Finance Document (${UpdatedDocument._DocType}) from Credit Note.`;
324
+ activity.EntityType = 'FinanceCustomer';
325
+ activity.EntityId = DocNo;
326
+ activity.EntityValueBefore = JSON.stringify(EntityValueBefore);
327
+ activity.EntityValueAfter = JSON.stringify(EntityValueAfter);
328
+ await activity.create(loginUser.ObjectId, dbTransaction);
329
+ return UpdatedDocument;
330
+ }
331
+ static async DEFAULT_INVOICE_TEMPLATE_HTML() {
332
+ const templateLocation = path.resolve('./invoice-template/index.html');
333
+ const readFileContent = util.promisify(fs.readFile);
334
+ const htmlBuffer = await readFileContent(templateLocation);
335
+ const htmlStream = {
336
+ buffer: htmlBuffer,
337
+ fieldname: 'FileStream',
338
+ originalname: 'index.html',
339
+ mimetype: 'text/html',
340
+ size: htmlBuffer.length,
341
+ encoding: '8bit',
342
+ filename: 'sample-invoice.html',
343
+ destination: path.dirname(templateLocation),
344
+ path: '',
345
+ stream: null,
346
+ };
347
+ return htmlStream;
348
+ }
349
+ async DEFAULT_INVOICE_TEMPLATE_PDF(customer, date = new Date()) {
350
+ const templateLocation = path.resolve('./invoice-template/index.html');
351
+ const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
352
+ const readFileContent = util.promisify(fs.readFile);
353
+ const [htmlString] = await Promise.all([
354
+ readFileContent(templateLocation, 'utf8'),
355
+ ]);
356
+ const browser = await puppeteer.launch({
357
+ headless: true,
358
+ args: ['--no-sandbox', '--disable-setuid-sandbox'],
359
+ });
360
+ const page = await browser.newPage();
361
+ const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
362
+ const imageBuffer = await readFileContent(imagePath);
363
+ const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
364
+ const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
365
+ await page.setContent(htmlString);
366
+ await page.addStyleTag({ path: cssLocation });
367
+ const divHandle = await page.$('.tm_logo');
368
+ await divHandle.evaluate((div, imgTag) => {
369
+ div.innerHTML = imgTag;
370
+ }, imgTag);
371
+ const currentDate = date.toLocaleDateString('en-GB');
372
+ const invoiceNo = this.DocNo;
373
+ const invoiceTitleInfo = `
393
374
  <div class="tm_invoice_seperator tm_gray_bg"></div>
394
375
  <div class="tm_invoice_info_list">
395
376
  <p class="tm_invoice_number tm_m0">
@@ -399,12 +380,12 @@ class Document extends account_system_entity_1.AccountSystemEntity {
399
380
  Date: <b class="tm_primary_color">${currentDate}</b>
400
381
  </p>
401
382
  </div>
402
- `;
403
- const invoiceTitleInfoHandle = yield page.$('.tm_invoice_info');
404
- yield invoiceTitleInfoHandle.evaluate((invoice, invoiceTitleInfo) => {
405
- invoice.innerHTML = invoiceTitleInfo;
406
- }, invoiceTitleInfo);
407
- const invoiceCustomerContent = `
383
+ `;
384
+ const invoiceTitleInfoHandle = await page.$('.tm_invoice_info');
385
+ await invoiceTitleInfoHandle.evaluate((invoice, invoiceTitleInfo) => {
386
+ invoice.innerHTML = invoiceTitleInfo;
387
+ }, invoiceTitleInfo);
388
+ const invoiceCustomerContent = `
408
389
  <p class="tm_mb2">
409
390
  <b class="tm_primary_color">Invoice To:</b>
410
391
  </p>
@@ -414,24 +395,24 @@ class Document extends account_system_entity_1.AccountSystemEntity {
414
395
  ${customer.DefaultAddress.Country} <br />
415
396
  ${customer.Email}
416
397
  </p>
417
- `;
418
- const invoiceCustomerHandle = yield page.$('.tm_customer_detail');
419
- yield invoiceCustomerHandle.evaluate((invoice, invoiceCustomerContent) => {
420
- invoice.innerHTML = invoiceCustomerContent;
421
- }, invoiceCustomerContent);
422
- const invoicePayToContent = ``;
423
- const invoicePayToHandle = yield page.$('.tm_payto_detail');
424
- yield invoicePayToHandle.evaluate((invoice, invoicePayToContent) => {
425
- invoice.innerHTML = invoicePayToContent;
426
- }, invoicePayToContent);
427
- const invoicePaymentInfoContent = ``;
428
- const invoicePaymentInfoHandle = yield page.$('.tm_payment_info');
429
- yield invoicePaymentInfoHandle.evaluate((invoice, invoicePaymentInfoContent) => {
430
- invoice.innerHTML = invoicePaymentInfoContent;
431
- }, invoicePaymentInfoContent);
432
- const invoiceSubtotal = +this.Amount;
433
- const invoiceTax = 0;
434
- const invoiceRightFooterContent = `
398
+ `;
399
+ const invoiceCustomerHandle = await page.$('.tm_customer_detail');
400
+ await invoiceCustomerHandle.evaluate((invoice, invoiceCustomerContent) => {
401
+ invoice.innerHTML = invoiceCustomerContent;
402
+ }, invoiceCustomerContent);
403
+ const invoicePayToContent = ``;
404
+ const invoicePayToHandle = await page.$('.tm_payto_detail');
405
+ await invoicePayToHandle.evaluate((invoice, invoicePayToContent) => {
406
+ invoice.innerHTML = invoicePayToContent;
407
+ }, invoicePayToContent);
408
+ const invoicePaymentInfoContent = ``;
409
+ const invoicePaymentInfoHandle = await page.$('.tm_payment_info');
410
+ await invoicePaymentInfoHandle.evaluate((invoice, invoicePaymentInfoContent) => {
411
+ invoice.innerHTML = invoicePaymentInfoContent;
412
+ }, invoicePaymentInfoContent);
413
+ const invoiceSubtotal = +this.Amount;
414
+ const invoiceTax = 0;
415
+ const invoiceRightFooterContent = `
435
416
  <table>
436
417
  <tbody>
437
418
  <tr>
@@ -472,12 +453,12 @@ class Document extends account_system_entity_1.AccountSystemEntity {
472
453
  </tr>
473
454
  </tbody>
474
455
  </table>
475
- `;
476
- const invoiceRightFooterHandle = yield page.$('.tm_item_total_section');
477
- yield invoiceRightFooterHandle.evaluate((invoice, invoiceRightFooterContent) => {
478
- invoice.innerHTML = invoiceRightFooterContent;
479
- }, invoiceRightFooterContent);
480
- const invoiceTNCContent = `
456
+ `;
457
+ const invoiceRightFooterHandle = await page.$('.tm_item_total_section');
458
+ await invoiceRightFooterHandle.evaluate((invoice, invoiceRightFooterContent) => {
459
+ invoice.innerHTML = invoiceRightFooterContent;
460
+ }, invoiceRightFooterContent);
461
+ const invoiceTNCContent = `
481
462
  <li>
482
463
  All payment must be made to:
483
464
  <ul>
@@ -489,15 +470,15 @@ class Document extends account_system_entity_1.AccountSystemEntity {
489
470
  <li>
490
471
  Once payment has been made, please email your transaction confirmation slip to <i>payment@ezcash.com.my</i>
491
472
  </li>
492
- `;
493
- const invoiceTNCHandle = yield page.$('.tm_tnc_content');
494
- yield invoiceTNCHandle.evaluate((invoice, invoiceTNCContent) => {
495
- invoice.innerHTML = invoiceTNCContent;
496
- }, invoiceTNCContent);
497
- const invoiceDocumentItems = yield this.DocumentItems;
498
- let invoiceItemContent = ``;
499
- invoiceDocumentItems.forEach((documentItem, i) => {
500
- invoiceItemContent += `
473
+ `;
474
+ const invoiceTNCHandle = await page.$('.tm_tnc_content');
475
+ await invoiceTNCHandle.evaluate((invoice, invoiceTNCContent) => {
476
+ invoice.innerHTML = invoiceTNCContent;
477
+ }, invoiceTNCContent);
478
+ const invoiceDocumentItems = await this.DocumentItems;
479
+ let invoiceItemContent = ``;
480
+ invoiceDocumentItems.forEach((documentItem, i) => {
481
+ invoiceItemContent += `
501
482
  <tr>
502
483
  <td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
503
484
  <td class="tm_width_4">
@@ -507,72 +488,71 @@ class Document extends account_system_entity_1.AccountSystemEntity {
507
488
  <td class="tm_width_1">${documentItem.Quantity}</td>
508
489
  <td class="tm_width_2 tm_text_right">${documentItem.Currency} ${+documentItem.UnitPrice * +documentItem.Quantity}</td>
509
490
  </tr>
510
- `;
511
- });
512
- const invoiceDocumentItemHandle = yield page.$('.tm_items_content');
513
- yield invoiceDocumentItemHandle.evaluate((invoice, invoiceItemContent) => {
514
- invoice.innerHTML = invoiceItemContent;
515
- }, invoiceItemContent);
516
- const pdfBuffer = yield page.pdf({
517
- format: 'a4',
518
- printBackground: true,
519
- margin: {
520
- left: '0px',
521
- top: '0px',
522
- right: '0px',
523
- bottom: '0px',
524
- },
525
- });
526
- const pdfStream = {
527
- buffer: pdfBuffer,
528
- fieldname: 'FileStream',
529
- originalname: 'sample-invoice.pdf',
530
- mimetype: 'application/pdf',
531
- size: pdfBuffer.length,
532
- encoding: '8bit',
533
- filename: 'sample-invoice.pdf',
534
- destination: '',
535
- path: '',
536
- stream: null,
537
- };
538
- return pdfStream;
539
- });
540
- }
541
- DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date = new Date()) {
542
- return __awaiter(this, void 0, void 0, function* () {
543
- const templateLocation = path.resolve('./invoice-template/index.html');
544
- const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
545
- const readFileContent = util.promisify(fs.readFile);
546
- const [htmlString] = yield Promise.all([
547
- readFileContent(templateLocation, 'utf8'),
548
- ]);
549
- const browser = yield puppeteer.launch({
550
- headless: true,
551
- args: ['--no-sandbox', '--disable-setuid-sandbox'],
552
- });
553
- const page = yield browser.newPage();
554
- const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
555
- const imageBuffer = yield readFileContent(imagePath);
556
- const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
557
- const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
558
- yield page.setContent(htmlString);
559
- yield page.addStyleTag({ path: cssLocation });
560
- const divHandle = yield page.$('.tm_logo');
561
- yield divHandle.evaluate((div, imgTag) => {
562
- div.innerHTML = imgTag;
563
- }, imgTag);
564
- const currentDate = date.toLocaleDateString('en-GB');
565
- const receiptNo = this.DocNo;
566
- const receiptTitle = `
491
+ `;
492
+ });
493
+ const invoiceDocumentItemHandle = await page.$('.tm_items_content');
494
+ await invoiceDocumentItemHandle.evaluate((invoice, invoiceItemContent) => {
495
+ invoice.innerHTML = invoiceItemContent;
496
+ }, invoiceItemContent);
497
+ const pdfBuffer = await page.pdf({
498
+ format: 'a4',
499
+ printBackground: true,
500
+ margin: {
501
+ left: '0px',
502
+ top: '0px',
503
+ right: '0px',
504
+ bottom: '0px',
505
+ },
506
+ });
507
+ const pdfBufferAsBuffer = Buffer.from(pdfBuffer);
508
+ const pdfStream = {
509
+ buffer: pdfBufferAsBuffer,
510
+ fieldname: 'FileStream',
511
+ originalname: 'sample-invoice.pdf',
512
+ mimetype: 'application/pdf',
513
+ size: pdfBuffer.length,
514
+ encoding: '8bit',
515
+ filename: 'sample-invoice.pdf',
516
+ destination: '',
517
+ path: '',
518
+ stream: null,
519
+ };
520
+ return pdfStream;
521
+ }
522
+ async DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date = new Date()) {
523
+ const templateLocation = path.resolve('./invoice-template/index.html');
524
+ const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
525
+ const readFileContent = util.promisify(fs.readFile);
526
+ const [htmlString] = await Promise.all([
527
+ readFileContent(templateLocation, 'utf8'),
528
+ ]);
529
+ const browser = await puppeteer.launch({
530
+ headless: true,
531
+ args: ['--no-sandbox', '--disable-setuid-sandbox'],
532
+ });
533
+ const page = await browser.newPage();
534
+ const imagePath = path.resolve('./invoice-template/assets/img/ezcash-logo.svg');
535
+ const imageBuffer = await readFileContent(imagePath);
536
+ const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
537
+ const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
538
+ await page.setContent(htmlString);
539
+ await page.addStyleTag({ path: cssLocation });
540
+ const divHandle = await page.$('.tm_logo');
541
+ await divHandle.evaluate((div, imgTag) => {
542
+ div.innerHTML = imgTag;
543
+ }, imgTag);
544
+ const currentDate = date.toLocaleDateString('en-GB');
545
+ const receiptNo = this.DocNo;
546
+ const receiptTitle = `
567
547
  <div class="tm_primary_color tm_f50 tm_text_uppercase">
568
548
  Receipt
569
549
  </div>
570
- `;
571
- const receiptTitleHandle = yield page.$('.tm_invoice_title');
572
- yield receiptTitleHandle.evaluate((receipt, receiptTitle) => {
573
- receipt.innerHTML = receiptTitle;
574
- }, receiptTitle);
575
- const receiptTitleInfo = `
550
+ `;
551
+ const receiptTitleHandle = await page.$('.tm_invoice_title');
552
+ await receiptTitleHandle.evaluate((receipt, receiptTitle) => {
553
+ receipt.innerHTML = receiptTitle;
554
+ }, receiptTitle);
555
+ const receiptTitleInfo = `
576
556
  <div class="tm_invoice_seperator tm_gray_bg"></div>
577
557
  <div class="tm_invoice_info_list">
578
558
  <p class="tm_invoice_number tm_m0">
@@ -582,12 +562,12 @@ class Document extends account_system_entity_1.AccountSystemEntity {
582
562
  Date: <b class="tm_primary_color">${currentDate}</b>
583
563
  </p>
584
564
  </div>
585
- `;
586
- const receiptTitleInfoHandle = yield page.$('.tm_invoice_info');
587
- yield receiptTitleInfoHandle.evaluate((receipt, receiptTitleInfo) => {
588
- receipt.innerHTML = receiptTitleInfo;
589
- }, receiptTitleInfo);
590
- const receiptCustomerContent = `
565
+ `;
566
+ const receiptTitleInfoHandle = await page.$('.tm_invoice_info');
567
+ await receiptTitleInfoHandle.evaluate((receipt, receiptTitleInfo) => {
568
+ receipt.innerHTML = receiptTitleInfo;
569
+ }, receiptTitleInfo);
570
+ const receiptCustomerContent = `
591
571
  <p class="tm_mb2">
592
572
  <b class="tm_primary_color">Issued To:</b>
593
573
  </p>
@@ -597,24 +577,24 @@ class Document extends account_system_entity_1.AccountSystemEntity {
597
577
  ${customer.DefaultAddress.Country} <br />
598
578
  ${customer.Email}
599
579
  </p>
600
- `;
601
- const receiptCustomerHandle = yield page.$('.tm_customer_detail');
602
- yield receiptCustomerHandle.evaluate((receipt, receiptCustomerContent) => {
603
- receipt.innerHTML = receiptCustomerContent;
604
- }, receiptCustomerContent);
605
- const receiptPayToContent = ``;
606
- const receiptPayToHandle = yield page.$('.tm_payto_detail');
607
- yield receiptPayToHandle.evaluate((receipt, receiptPayToContent) => {
608
- receipt.innerHTML = receiptPayToContent;
609
- }, receiptPayToContent);
610
- const receiptPaymentInfoContent = ``;
611
- const receiptPaymentInfoHandle = yield page.$('.tm_payment_info');
612
- yield receiptPaymentInfoHandle.evaluate((receipt, receiptPaymentInfoContent) => {
613
- receipt.innerHTML = receiptPaymentInfoContent;
614
- }, receiptPaymentInfoContent);
615
- const receiptSubtotal = +this.Amount;
616
- const receiptTax = 0;
617
- const receiptRightFooterContent = `
580
+ `;
581
+ const receiptCustomerHandle = await page.$('.tm_customer_detail');
582
+ await receiptCustomerHandle.evaluate((receipt, receiptCustomerContent) => {
583
+ receipt.innerHTML = receiptCustomerContent;
584
+ }, receiptCustomerContent);
585
+ const receiptPayToContent = ``;
586
+ const receiptPayToHandle = await page.$('.tm_payto_detail');
587
+ await receiptPayToHandle.evaluate((receipt, receiptPayToContent) => {
588
+ receipt.innerHTML = receiptPayToContent;
589
+ }, receiptPayToContent);
590
+ const receiptPaymentInfoContent = ``;
591
+ const receiptPaymentInfoHandle = await page.$('.tm_payment_info');
592
+ await receiptPaymentInfoHandle.evaluate((receipt, receiptPaymentInfoContent) => {
593
+ receipt.innerHTML = receiptPaymentInfoContent;
594
+ }, receiptPaymentInfoContent);
595
+ const receiptSubtotal = +this.Amount;
596
+ const receiptTax = 0;
597
+ const receiptRightFooterContent = `
618
598
  <table>
619
599
  <tbody>
620
600
  <tr>
@@ -655,15 +635,15 @@ class Document extends account_system_entity_1.AccountSystemEntity {
655
635
  </tr>
656
636
  </tbody>
657
637
  </table>
658
- `;
659
- const receiptRightFooterHandle = yield page.$('.tm_item_total_section');
660
- yield receiptRightFooterHandle.evaluate((receipt, receiptRightFooterContent) => {
661
- receipt.innerHTML = receiptRightFooterContent;
662
- }, receiptRightFooterContent);
663
- const receiptDocumentItems = yield this.DocumentItems;
664
- let receiptItemContent = ``;
665
- receiptDocumentItems.forEach((documentItem, i) => {
666
- receiptItemContent += `
638
+ `;
639
+ const receiptRightFooterHandle = await page.$('.tm_item_total_section');
640
+ await receiptRightFooterHandle.evaluate((receipt, receiptRightFooterContent) => {
641
+ receipt.innerHTML = receiptRightFooterContent;
642
+ }, receiptRightFooterContent);
643
+ const receiptDocumentItems = await this.DocumentItems;
644
+ let receiptItemContent = ``;
645
+ receiptDocumentItems.forEach((documentItem, i) => {
646
+ receiptItemContent += `
667
647
  <tr>
668
648
  <td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
669
649
  <td class="tm_width_4">
@@ -673,249 +653,238 @@ class Document extends account_system_entity_1.AccountSystemEntity {
673
653
  <td class="tm_width_1">${documentItem.Quantity}</td>
674
654
  <td class="tm_width_2 tm_text_right">${documentItem.Currency} ${+documentItem.UnitPrice * +documentItem.Quantity}</td>
675
655
  </tr>
676
- `;
677
- });
678
- const receiptDocumentItemHandle = yield page.$('.tm_items_content');
679
- yield receiptDocumentItemHandle.evaluate((receipt, receiptItemContent) => {
680
- receipt.innerHTML = receiptItemContent;
681
- }, receiptItemContent);
682
- const receiptFooterContent = `
656
+ `;
657
+ });
658
+ const receiptDocumentItemHandle = await page.$('.tm_items_content');
659
+ await receiptDocumentItemHandle.evaluate((receipt, receiptItemContent) => {
660
+ receipt.innerHTML = receiptItemContent;
661
+ }, receiptItemContent);
662
+ const receiptFooterContent = `
683
663
  <p class="tm_mb5 tm_text_center tm_f11">
684
664
  <i>
685
665
  Thank you for your payment. This is computer generated receipt
686
666
  - no signature is required.
687
667
  </i>
688
668
  </p>
689
- `;
690
- const receiptFooterHandle = yield page.$('.tm_footer_section');
691
- yield receiptFooterHandle.evaluate((receipt, receiptFooterContent) => {
692
- receipt.innerHTML = receiptFooterContent;
693
- }, receiptFooterContent);
694
- const pdfBuffer = yield page.pdf({
695
- format: 'a4',
696
- printBackground: true,
697
- margin: {
698
- left: '0px',
699
- top: '0px',
700
- right: '0px',
701
- bottom: '0px',
702
- },
703
- });
704
- const pdfStream = {
705
- buffer: pdfBuffer,
706
- fieldname: 'FileStream',
707
- originalname: 'sample-invoice.pdf',
708
- mimetype: 'application/pdf',
709
- size: pdfBuffer.length,
710
- encoding: '8bit',
711
- filename: 'sample-invoice.pdf',
712
- destination: '',
713
- path: '',
714
- stream: null,
715
- };
716
- return pdfStream;
717
- });
718
- }
719
- get DocumentFileInHTML() {
720
- return (() => __awaiter(this, void 0, void 0, function* () {
721
- const { HTMLMedia } = yield this.generateInvoice();
722
- return HTMLMedia;
723
- }))();
724
- }
725
- get DocumentFileInPDF() {
726
- return (() => __awaiter(this, void 0, void 0, function* () {
727
- const { PDFMedia } = yield this.generateInvoice();
728
- return PDFMedia;
729
- }))();
730
- }
731
- generateInvoice(userId, customer, dbTransaction, date) {
732
- return __awaiter(this, void 0, void 0, function* () {
733
- const media = new media_1.Medias(this.mediaCommonService);
734
- const htmlPayload = {
735
- ObjectId: this.DocNo,
736
- ObjectType: 'Document',
737
- Type: media_1.MediaType.Document,
738
- FileName: `${this.DocType}-${this.DocNo}`,
739
- FileStream: yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
740
- FileExtension: 'html',
741
- Title: `${this.DocType}-${this.DocNo}.html`,
742
- Description: `HTML ${this.DocType}`,
743
- IsEncryptedYN: 'N',
744
- };
745
- const user = new login_user_1.LoginUser(userId !== null && userId !== void 0 ? userId : 'System', null, null);
746
- const HTMLInvoiceMedia = yield media.postInternal(yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, user, dbTransaction);
747
- const pdfPayload = {
748
- ObjectId: this.DocNo,
749
- ObjectType: 'Document',
750
- Type: media_1.MediaType.Document,
751
- FileName: `${this.DocType}-${this.DocNo}`,
752
- FileStream: yield this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date),
753
- FileExtension: 'pdf',
754
- Title: `${this.DocType}-${this.DocNo}.pdf`,
755
- Description: `PDF ${this.DocType}`,
756
- IsEncryptedYN: 'N',
757
- };
758
- const PDFInvoiceMedia = yield media.postInternal(yield this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date), pdfPayload, user, dbTransaction);
759
- return {
760
- HTMLMedia: HTMLInvoiceMedia,
761
- PDFMedia: PDFInvoiceMedia,
762
- };
763
- });
764
- }
765
- generateReceipt(userId, customer, transaction, date) {
766
- return __awaiter(this, void 0, void 0, function* () {
767
- const media = new media_1.Medias(this.mediaCommonService);
768
- const user = new login_user_1.LoginUser(userId !== null && userId !== void 0 ? userId : 'System', null, null);
769
- const htmlPayload = {
770
- ObjectId: this.DocNo,
771
- ObjectType: 'Document',
772
- Type: media_1.MediaType.Document,
773
- FileName: `${this.DocType}-${this.DocNo}`,
774
- FileStream: yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
775
- FileExtension: 'html',
776
- Title: `${this.DocType}-${this.DocNo}.html`,
777
- Description: `HTML ${this.DocType}`,
778
- IsEncryptedYN: 'N',
779
- };
780
- const HTMLInvoiceMedia = yield media.postInternal(yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, user, transaction);
781
- const pdfPayload = {
782
- ObjectId: this.DocNo,
783
- ObjectType: 'Document',
784
- Type: media_1.MediaType.Document,
785
- FileName: `${this.DocType}-${this.DocNo}`,
786
- FileStream: yield this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date),
787
- FileExtension: 'pdf',
788
- Title: `${this.DocType}-${this.DocNo}.pdf`,
789
- Description: `PDF ${this.DocType}`,
790
- IsEncryptedYN: 'N',
791
- };
792
- const PDFInvoiceMedia = yield media.postInternal(yield this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date), pdfPayload, user, transaction);
793
- return {
794
- HTMLMedia: HTMLInvoiceMedia,
795
- PDFMedia: PDFInvoiceMedia,
796
- };
797
- });
798
- }
799
- generateCreditNote(userId, customer) {
800
- return __awaiter(this, void 0, void 0, function* () {
801
- console.log(userId, customer, '<< generateCreditNote');
802
- });
803
- }
804
- newDocumentItem(documentItem) {
805
- return __awaiter(this, void 0, void 0, function* () {
806
- let di;
807
- if (documentItem) {
808
- di = documentItem;
809
- }
810
- else {
811
- di = new document_item_1.default(this._DbTransaction, this);
812
- }
813
- di.DocNo = this.DocNo;
814
- this._DocumentItems.push(di);
815
- this.reCalculateAmount();
816
- return documentItem;
817
- });
818
- }
819
- getPreviousDocument(docType) {
820
- return __awaiter(this, void 0, void 0, function* () {
821
- return yield this.RepositoryBase.findOne({
822
- where: {
823
- DocType: docType,
824
- },
825
- order: [['CreatedAt', 'DESC']],
826
- });
827
- });
828
- }
829
- static findAll(loginUser, dbTransaction, page, row, search, order, accountingSystem) {
830
- var _a;
831
- return __awaiter(this, void 0, void 0, function* () {
832
- try {
833
- const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
834
- const isPrivileged = yield loginUser.checkPrivileges(systemCode, 'Invoice - View');
835
- if (!isPrivileged) {
836
- throw new general_1.ClassError('Document', 'DocumentFindAllErrMsg00', `You do not have 'Invoice - View' privilege.`);
837
- }
838
- let options = {
839
- transaction: dbTransaction,
840
- order: [['CreatedAt', 'DESC']],
841
- };
842
- const searchObj = {};
843
- if (search === null || search === void 0 ? void 0 : search.DocNo) {
844
- searchObj.DocNo = search.DocNo;
845
- }
846
- if (search === null || search === void 0 ? void 0 : search.DocType) {
847
- searchObj.DocType = search.DocType;
848
- }
849
- if (search === null || search === void 0 ? void 0 : search.StartDate) {
850
- searchObj.DocDate = Object.assign(Object.assign({}, searchObj.DocDate), { [sequelize_1.Op.gte]: new Date(search.StartDate).toISOString() });
851
- }
852
- if (search === null || search === void 0 ? void 0 : search.EndDate) {
853
- searchObj.DocDate = Object.assign(Object.assign({}, searchObj.DocDate), { [sequelize_1.Op.lte]: new Date(search.EndDate).toISOString() });
854
- }
855
- if (search === null || search === void 0 ? void 0 : search.IssuedToId) {
856
- searchObj.IssuedToId = search.IssuedToId;
857
- }
858
- if (search === null || search === void 0 ? void 0 : search.IssuedToType) {
859
- searchObj.IssuedToType = search.IssuedToType;
860
- }
861
- if (search === null || search === void 0 ? void 0 : search.Status) {
862
- searchObj.Status = search.Status;
863
- }
864
- if (search === null || search === void 0 ? void 0 : search.RelatedObjectId) {
865
- searchObj.RelatedObjectId = search.RelatedObjectId;
866
- }
867
- if (search === null || search === void 0 ? void 0 : search.RelatedObjectType) {
868
- searchObj.RelatedObjectType = search.RelatedObjectType;
869
- }
870
- if (search === null || search === void 0 ? void 0 : search.Description) {
871
- searchObj.Description = search.Description;
872
- }
873
- if (page && row) {
874
- options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1) });
875
- }
876
- if (order) {
877
- options = Object.assign(Object.assign({}, options), { order: order });
878
- }
879
- if (Object.keys(searchObj).length) {
880
- options = Object.assign(Object.assign({}, options), { where: searchObj });
881
- }
882
- let documents = yield Document._RepositoryBase.findAllWithPagination(options);
883
- let isChangesExit = false;
884
- for (let i = 0; i < ((_a = documents === null || documents === void 0 ? void 0 : documents.rows) === null || _a === void 0 ? void 0 : _a.length); i++) {
885
- const doc = yield (documents === null || documents === void 0 ? void 0 : documents.rows[i]);
886
- if (doc.UseAccSystemDocYN.toLowerCase() === 'y') {
887
- console.log(doc.UseAccSystemDocYN.toLowerCase());
888
- if (accountingSystem === null || accountingSystem === undefined) {
889
- throw new general_1.ClassError('Document', 'DocumentFindAllErrMsg01', `Accounting System is not set`);
890
- }
891
- const invoiceStatus = yield accountingSystem.getInvoiceStatus(doc.AccSystemRefId);
892
- if (doc.Status !== invoiceStatus) {
893
- doc.Status = invoiceStatus;
894
- yield this._RepositoryBase.update({
895
- Status: invoiceStatus,
896
- }, {
897
- where: {
898
- DocNo: doc.DocNo,
899
- },
900
- transaction: dbTransaction,
901
- });
902
- isChangesExit = true;
903
- }
904
- }
905
- }
906
- if (isChangesExit) {
907
- documents = yield Document._RepositoryBase.findAllWithPagination(options);
908
- }
909
- return documents;
910
- }
911
- catch (error) {
912
- throw error;
913
- }
914
- });
915
- }
916
- }
917
- exports.default = Document;
918
- Document._RepositoryBase = new document_repository_1.DocumentRepository();
919
- Document._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
920
- Document._MediaRepository = new media_1.MediasRepository();
669
+ `;
670
+ const receiptFooterHandle = await page.$('.tm_footer_section');
671
+ await receiptFooterHandle.evaluate((receipt, receiptFooterContent) => {
672
+ receipt.innerHTML = receiptFooterContent;
673
+ }, receiptFooterContent);
674
+ const pdfBuffer = await page.pdf({
675
+ format: 'a4',
676
+ printBackground: true,
677
+ margin: {
678
+ left: '0px',
679
+ top: '0px',
680
+ right: '0px',
681
+ bottom: '0px',
682
+ },
683
+ });
684
+ const pdfBufferAsBuffer = Buffer.from(pdfBuffer);
685
+ const pdfStream = {
686
+ buffer: pdfBufferAsBuffer,
687
+ fieldname: 'FileStream',
688
+ originalname: 'sample-invoice.pdf',
689
+ mimetype: 'application/pdf',
690
+ size: pdfBuffer.length,
691
+ encoding: '8bit',
692
+ filename: 'sample-invoice.pdf',
693
+ destination: '',
694
+ path: '',
695
+ stream: null,
696
+ };
697
+ return pdfStream;
698
+ }
699
+ get DocumentFileInHTML() {
700
+ return (async () => {
701
+ const { HTMLMedia } = await this.generateInvoice();
702
+ return HTMLMedia;
703
+ })();
704
+ }
705
+ get DocumentFileInPDF() {
706
+ return (async () => {
707
+ const { PDFMedia } = await this.generateInvoice();
708
+ return PDFMedia;
709
+ })();
710
+ }
711
+ async generateInvoice(userId, customer, dbTransaction, date) {
712
+ const media = new media_1.Medias(this.mediaCommonService);
713
+ const htmlPayload = {
714
+ ObjectId: this.DocNo,
715
+ ObjectType: 'Document',
716
+ Type: media_1.MediaType.Document,
717
+ FileName: `${this.DocType}-${this.DocNo}`,
718
+ FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
719
+ FileExtension: 'html',
720
+ Title: `${this.DocType}-${this.DocNo}.html`,
721
+ Description: `HTML ${this.DocType}`,
722
+ IsEncryptedYN: 'N',
723
+ };
724
+ const user = new login_user_1.LoginUser(userId !== null && userId !== void 0 ? userId : 'System', null, null);
725
+ const HTMLInvoiceMedia = await media.postInternal(await Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, user, dbTransaction);
726
+ const pdfPayload = {
727
+ ObjectId: this.DocNo,
728
+ ObjectType: 'Document',
729
+ Type: media_1.MediaType.Document,
730
+ FileName: `${this.DocType}-${this.DocNo}`,
731
+ FileStream: await this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date),
732
+ FileExtension: 'pdf',
733
+ Title: `${this.DocType}-${this.DocNo}.pdf`,
734
+ Description: `PDF ${this.DocType}`,
735
+ IsEncryptedYN: 'N',
736
+ };
737
+ const PDFInvoiceMedia = await media.postInternal(await this.DEFAULT_INVOICE_TEMPLATE_PDF(customer, date), pdfPayload, user, dbTransaction);
738
+ return {
739
+ HTMLMedia: HTMLInvoiceMedia,
740
+ PDFMedia: PDFInvoiceMedia,
741
+ };
742
+ }
743
+ async generateReceipt(userId, customer, transaction, date) {
744
+ const media = new media_1.Medias(this.mediaCommonService);
745
+ const user = new login_user_1.LoginUser(userId !== null && userId !== void 0 ? userId : 'System', null, null);
746
+ const htmlPayload = {
747
+ ObjectId: this.DocNo,
748
+ ObjectType: 'Document',
749
+ Type: media_1.MediaType.Document,
750
+ FileName: `${this.DocType}-${this.DocNo}`,
751
+ FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
752
+ FileExtension: 'html',
753
+ Title: `${this.DocType}-${this.DocNo}.html`,
754
+ Description: `HTML ${this.DocType}`,
755
+ IsEncryptedYN: 'N',
756
+ };
757
+ const HTMLInvoiceMedia = await media.postInternal(await Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, user, transaction);
758
+ const pdfPayload = {
759
+ ObjectId: this.DocNo,
760
+ ObjectType: 'Document',
761
+ Type: media_1.MediaType.Document,
762
+ FileName: `${this.DocType}-${this.DocNo}`,
763
+ FileStream: await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date),
764
+ FileExtension: 'pdf',
765
+ Title: `${this.DocType}-${this.DocNo}.pdf`,
766
+ Description: `PDF ${this.DocType}`,
767
+ IsEncryptedYN: 'N',
768
+ };
769
+ const PDFInvoiceMedia = await media.postInternal(await this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer, date), pdfPayload, user, transaction);
770
+ return {
771
+ HTMLMedia: HTMLInvoiceMedia,
772
+ PDFMedia: PDFInvoiceMedia,
773
+ };
774
+ }
775
+ async generateCreditNote(userId, customer) {
776
+ console.log(userId, customer, '<< generateCreditNote');
777
+ }
778
+ async newDocumentItem(documentItem) {
779
+ let di;
780
+ if (documentItem) {
781
+ di = documentItem;
782
+ }
783
+ else {
784
+ di = new document_item_1.default(this._DbTransaction, this);
785
+ }
786
+ di.DocNo = this.DocNo;
787
+ this._DocumentItems.push(di);
788
+ this.reCalculateAmount();
789
+ return documentItem;
790
+ }
791
+ async getPreviousDocument(docType) {
792
+ return await this.RepositoryBase.findOne({
793
+ where: {
794
+ DocType: docType,
795
+ },
796
+ order: [['CreatedAt', 'DESC']],
797
+ });
798
+ }
799
+ static async findAll(loginUser, dbTransaction, page, row, search, order, accountingSystem) {
800
+ var _a;
801
+ try {
802
+ const systemCode = config_1.ApplicationConfig.getComponentConfigValue('system-code');
803
+ const isPrivileged = await loginUser.checkPrivileges(systemCode, 'Invoice - View');
804
+ if (!isPrivileged) {
805
+ throw new general_1.ClassError('Document', 'DocumentFindAllErrMsg00', `You do not have 'Invoice - View' privilege.`);
806
+ }
807
+ let options = {
808
+ transaction: dbTransaction,
809
+ order: [['CreatedAt', 'DESC']],
810
+ };
811
+ const searchObj = {};
812
+ if (search === null || search === void 0 ? void 0 : search.DocNo) {
813
+ searchObj.DocNo = search.DocNo;
814
+ }
815
+ if (search === null || search === void 0 ? void 0 : search.DocType) {
816
+ searchObj.DocType = search.DocType;
817
+ }
818
+ if (search === null || search === void 0 ? void 0 : search.StartDate) {
819
+ searchObj.DocDate = Object.assign(Object.assign({}, searchObj.DocDate), { [sequelize_1.Op.gte]: new Date(search.StartDate).toISOString() });
820
+ }
821
+ if (search === null || search === void 0 ? void 0 : search.EndDate) {
822
+ searchObj.DocDate = Object.assign(Object.assign({}, searchObj.DocDate), { [sequelize_1.Op.lte]: new Date(search.EndDate).toISOString() });
823
+ }
824
+ if (search === null || search === void 0 ? void 0 : search.IssuedToId) {
825
+ searchObj.IssuedToId = search.IssuedToId;
826
+ }
827
+ if (search === null || search === void 0 ? void 0 : search.IssuedToType) {
828
+ searchObj.IssuedToType = search.IssuedToType;
829
+ }
830
+ if (search === null || search === void 0 ? void 0 : search.Status) {
831
+ searchObj.Status = search.Status;
832
+ }
833
+ if (search === null || search === void 0 ? void 0 : search.RelatedObjectId) {
834
+ searchObj.RelatedObjectId = search.RelatedObjectId;
835
+ }
836
+ if (search === null || search === void 0 ? void 0 : search.RelatedObjectType) {
837
+ searchObj.RelatedObjectType = search.RelatedObjectType;
838
+ }
839
+ if (search === null || search === void 0 ? void 0 : search.Description) {
840
+ searchObj.Description = search.Description;
841
+ }
842
+ if (page && row) {
843
+ options = Object.assign(Object.assign({}, options), { limit: row, offset: row * (page - 1) });
844
+ }
845
+ if (order) {
846
+ options = Object.assign(Object.assign({}, options), { order: order });
847
+ }
848
+ if (Object.keys(searchObj).length) {
849
+ options = Object.assign(Object.assign({}, options), { where: searchObj });
850
+ }
851
+ let documents = await Document._RepositoryBase.findAllWithPagination(options);
852
+ let isChangesExit = false;
853
+ for (let i = 0; i < ((_a = documents === null || documents === void 0 ? void 0 : documents.rows) === null || _a === void 0 ? void 0 : _a.length); i++) {
854
+ const doc = await (documents === null || documents === void 0 ? void 0 : documents.rows[i]);
855
+ if (doc.UseAccSystemDocYN.toLowerCase() === 'y') {
856
+ console.log(doc.UseAccSystemDocYN.toLowerCase());
857
+ if (accountingSystem === null || accountingSystem === undefined) {
858
+ throw new general_1.ClassError('Document', 'DocumentFindAllErrMsg01', `Accounting System is not set`);
859
+ }
860
+ const invoiceStatus = await accountingSystem.getInvoiceStatus(doc.AccSystemRefId);
861
+ if (doc.Status !== invoiceStatus) {
862
+ doc.Status = invoiceStatus;
863
+ await this._RepositoryBase.update({
864
+ Status: invoiceStatus,
865
+ }, {
866
+ where: {
867
+ DocNo: doc.DocNo,
868
+ },
869
+ transaction: dbTransaction,
870
+ });
871
+ isChangesExit = true;
872
+ }
873
+ }
874
+ }
875
+ if (isChangesExit) {
876
+ documents =
877
+ await Document._RepositoryBase.findAllWithPagination(options);
878
+ }
879
+ return documents;
880
+ }
881
+ catch (error) {
882
+ throw error;
883
+ }
884
+ }
885
+ }
886
+ Document._RepositoryBase = new document_repository_1.DocumentRepository();
887
+ Document._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
888
+ Document._MediaRepository = new media_1.MediasRepository();
889
+ exports.default = Document;
921
890
  //# sourceMappingURL=document.js.map