@tomei/finance 0.5.0 → 0.5.2

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 (171) hide show
  1. package/dist/account/account.d.ts +35 -35
  2. package/dist/account/account.js +233 -231
  3. package/dist/account/account.js.map +1 -1
  4. package/dist/account/account.repository.d.ts +5 -5
  5. package/dist/account/account.repository.js +11 -11
  6. package/dist/account/interfaces/account-attr.interface.d.ts +29 -29
  7. package/dist/account/interfaces/account-attr.interface.js +2 -2
  8. package/dist/account-system-entity/account-system-entity.d.ts +11 -11
  9. package/dist/account-system-entity/account-system-entity.js +66 -66
  10. package/dist/account-system-entity/post-history.repository.d.ts +5 -5
  11. package/dist/account-system-entity/post-history.repository.js +11 -11
  12. package/dist/config.d.ts +1888 -1888
  13. package/dist/config.js +331 -331
  14. package/dist/customer/customer.d.ts +43 -41
  15. package/dist/customer/customer.js +236 -214
  16. package/dist/customer/customer.js.map +1 -1
  17. package/dist/customer/finance-customer.repository.d.ts +5 -5
  18. package/dist/customer/finance-customer.repository.js +25 -25
  19. package/dist/customer/interfaces/customer.repository.interface.d.ts +3 -3
  20. package/dist/customer/interfaces/customer.repository.interface.js +2 -2
  21. package/dist/customer/interfaces/finance-customer-attr.interface.d.ts +10 -10
  22. package/dist/customer/interfaces/finance-customer-attr.interface.js +2 -2
  23. package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +3 -3
  24. package/dist/customer/interfaces/finance-customer.repository.interface.js +2 -2
  25. package/dist/database.d.ts +4 -4
  26. package/dist/database.js +14 -14
  27. package/dist/document/document-item.d.ts +38 -38
  28. package/dist/document/document-item.js +83 -83
  29. package/dist/document/document-item.repository.d.ts +5 -5
  30. package/dist/document/document-item.repository.js +11 -11
  31. package/dist/document/document.d.ts +76 -76
  32. package/dist/document/document.js +566 -566
  33. package/dist/document/document.repository.d.ts +5 -5
  34. package/dist/document/document.repository.js +11 -11
  35. package/dist/document/interfaces/document-attr.interface.d.ts +27 -27
  36. package/dist/document/interfaces/document-attr.interface.js +6 -6
  37. package/dist/document/interfaces/document-item-attr.interface.d.ts +22 -22
  38. package/dist/document/interfaces/document-item-attr.interface.js +6 -6
  39. package/dist/document/interfaces/document-item.repository.interface.d.ts +3 -3
  40. package/dist/document/interfaces/document-item.repository.interface.js +2 -2
  41. package/dist/enum/doc-type.enum.d.ts +8 -8
  42. package/dist/enum/doc-type.enum.js +12 -12
  43. package/dist/enum/document-status.enum.d.ts +6 -6
  44. package/dist/enum/document-status.enum.js +10 -10
  45. package/dist/enum/index.d.ts +8 -8
  46. package/dist/enum/index.js +17 -17
  47. package/dist/enum/payment-method.enum.d.ts +3 -3
  48. package/dist/enum/payment-method.enum.js +7 -7
  49. package/dist/enum/payment-status.enum.d.ts +4 -4
  50. package/dist/enum/payment-status.enum.js +8 -8
  51. package/dist/enum/payment-type.enum.d.ts +4 -4
  52. package/dist/enum/payment-type.enum.js +8 -8
  53. package/dist/enum/quick-book-client-scopes.enum.d.ts +13 -13
  54. package/dist/enum/quick-book-client-scopes.enum.js +18 -18
  55. package/dist/enum/transaction-type.enum.d.ts +4 -4
  56. package/dist/enum/transaction-type.enum.js +8 -8
  57. package/dist/finance-company/finance-company.d.ts +57 -57
  58. package/dist/finance-company/finance-company.js +1192 -1192
  59. package/dist/finance-company/finance-company.repository.d.ts +5 -5
  60. package/dist/finance-company/finance-company.repository.js +11 -11
  61. package/dist/helpers/typeof.d.ts +1 -1
  62. package/dist/helpers/typeof.js +26 -26
  63. package/dist/index.d.ts +17 -17
  64. package/dist/index.js +32 -32
  65. package/dist/interfaces/account-system.interface.d.ts +13 -13
  66. package/dist/interfaces/account-system.interface.js +2 -2
  67. package/dist/interfaces/index.d.ts +2 -2
  68. package/dist/interfaces/index.js +2 -2
  69. package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +11 -11
  70. package/dist/journal-entry/interfaces/journal-entry-attr.interface.js +2 -2
  71. package/dist/journal-entry/journal-entry.d.ts +39 -39
  72. package/dist/journal-entry/journal-entry.js +215 -215
  73. package/dist/journal-entry/journal-entry.repository.d.ts +5 -5
  74. package/dist/journal-entry/journal-entry.repository.js +11 -11
  75. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +17 -17
  76. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js +2 -2
  77. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +5 -5
  78. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js +2 -2
  79. package/dist/ledger-transaction/ledger-transaction.d.ts +48 -48
  80. package/dist/ledger-transaction/ledger-transaction.js +155 -155
  81. package/dist/ledger-transaction/ledger-transaction.repository.d.ts +5 -5
  82. package/dist/ledger-transaction/ledger-transaction.repository.js +11 -11
  83. package/dist/models/account.entity.d.ts +30 -30
  84. package/dist/models/account.entity.js +232 -232
  85. package/dist/models/account.entity.js.map +1 -1
  86. package/dist/models/customer.entity.d.ts +13 -13
  87. package/dist/models/customer.entity.js +109 -109
  88. package/dist/models/document-item.entity.d.ts +27 -27
  89. package/dist/models/document-item.entity.js +172 -172
  90. package/dist/models/document.entity.d.ts +36 -36
  91. package/dist/models/document.entity.js +242 -242
  92. package/dist/models/finance-company.entity.d.ts +9 -9
  93. package/dist/models/finance-company.entity.js +44 -44
  94. package/dist/models/journal-entry.entity.d.ts +16 -16
  95. package/dist/models/journal-entry.entity.js +127 -127
  96. package/dist/models/ledger-transaction.entity.d.ts +24 -24
  97. package/dist/models/ledger-transaction.entity.js +172 -172
  98. package/dist/models/payment-item.entity.d.ts +12 -12
  99. package/dist/models/payment-item.entity.js +75 -75
  100. package/dist/models/payment-method-type.entity.d.ts +13 -13
  101. package/dist/models/payment-method-type.entity.js +85 -85
  102. package/dist/models/payment-method.entity.d.ts +10 -10
  103. package/dist/models/payment-method.entity.js +62 -62
  104. package/dist/models/payment-paid-with.entity.d.ts +24 -24
  105. package/dist/models/payment-paid-with.entity.js +158 -158
  106. package/dist/models/payment.entity.d.ts +27 -27
  107. package/dist/models/payment.entity.js +188 -188
  108. package/dist/models/post-history.entity.d.ts +11 -11
  109. package/dist/models/post-history.entity.js +63 -63
  110. package/dist/payment/interfaces/payment-attr.interface.d.ts +22 -22
  111. package/dist/payment/interfaces/payment-attr.interface.js +6 -6
  112. package/dist/payment/interfaces/payment-params.interface.d.ts +7 -7
  113. package/dist/payment/interfaces/payment-params.interface.js +2 -2
  114. package/dist/payment/payment.d.ts +51 -51
  115. package/dist/payment/payment.js +179 -179
  116. package/dist/payment/payment.repository.d.ts +5 -5
  117. package/dist/payment/payment.repository.js +11 -11
  118. package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +10 -10
  119. package/dist/payment-item/interfaces/payment-item-attr.interface.js +6 -6
  120. package/dist/payment-item/payment-item.d.ts +23 -23
  121. package/dist/payment-item/payment-item.js +115 -115
  122. package/dist/payment-item/payment-item.repository.d.ts +5 -5
  123. package/dist/payment-item/payment-item.repository.js +11 -11
  124. package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts +5 -5
  125. package/dist/payment-method/interfaces/payment-method-attr.interface.js +2 -2
  126. package/dist/payment-method/payment-method.d.ts +18 -18
  127. package/dist/payment-method/payment-method.js +98 -98
  128. package/dist/payment-method/payment-method.repository.d.ts +5 -5
  129. package/dist/payment-method/payment-method.repository.js +11 -11
  130. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts +8 -8
  131. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js +2 -2
  132. package/dist/payment-method-type/payment-method-type.d.ts +16 -16
  133. package/dist/payment-method-type/payment-method-type.js +70 -70
  134. package/dist/payment-method-type/payment-method-type.repository.d.ts +5 -5
  135. package/dist/payment-method-type/payment-method-type.repository.js +11 -11
  136. package/dist/payment-paid-with/interfaces/payment-paid-with.interface.d.ts +19 -19
  137. package/dist/payment-paid-with/interfaces/payment-paid-with.interface.js +6 -6
  138. package/dist/payment-paid-with/payment-paid-with.d.ts +31 -31
  139. package/dist/payment-paid-with/payment-paid-with.js +52 -52
  140. package/dist/payment-paid-with/payment-paid-with.repository.d.ts +5 -5
  141. package/dist/payment-paid-with/payment-paid-with.repository.js +11 -11
  142. package/dist/test-document.d.ts +3 -3
  143. package/dist/test-document.js +18 -18
  144. package/dist/test.d.ts +1 -1
  145. package/dist/test.js +7 -7
  146. package/dist/tsconfig.tsbuildinfo +1 -1
  147. package/package.json +1 -1
  148. package/src/account/account.ts +3 -1
  149. package/src/customer/customer.ts +40 -0
  150. package/src/models/account.entity.ts +1 -1
  151. package/dist/account/interfaces/account.repository.interface.d.ts +0 -3
  152. package/dist/account/interfaces/account.repository.interface.js +0 -3
  153. package/dist/account/interfaces/account.repository.interface.js.map +0 -1
  154. package/dist/document/interfaces/document.repository.interface.d.ts +0 -3
  155. package/dist/document/interfaces/document.repository.interface.js +0 -3
  156. package/dist/document/interfaces/document.repository.interface.js.map +0 -1
  157. package/dist/journal-entry/interfaces/journal-entry.repository.interface.d.ts +0 -10
  158. package/dist/journal-entry/interfaces/journal-entry.repository.interface.js +0 -3
  159. package/dist/journal-entry/interfaces/journal-entry.repository.interface.js.map +0 -1
  160. package/dist/payment/interfaces/payment-item-attr.interface.d.ts +0 -7
  161. package/dist/payment/interfaces/payment-item-attr.interface.js +0 -7
  162. package/dist/payment/interfaces/payment-item-attr.interface.js.map +0 -1
  163. package/dist/payment/interfaces/payment-item.repository.interface.d.ts +0 -3
  164. package/dist/payment/interfaces/payment-item.repository.interface.js +0 -3
  165. package/dist/payment/interfaces/payment-item.repository.interface.js.map +0 -1
  166. package/dist/payment/interfaces/payment.repository.interface.d.ts +0 -3
  167. package/dist/payment/interfaces/payment.repository.interface.js +0 -3
  168. package/dist/payment/interfaces/payment.repository.interface.js.map +0 -1
  169. package/dist/payment/payment-item.repository.d.ts +0 -17
  170. package/dist/payment/payment-item.repository.js +0 -51
  171. package/dist/payment/payment-item.repository.js.map +0 -1
@@ -1,271 +1,271 @@
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 fs = require("fs");
14
- const puppeteer = require("puppeteer");
15
- const general_1 = require("@tomei/general");
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 path = require("path");
23
- class Document extends account_system_entity_1.AccountSystemEntity {
24
- get IsNewRecord() {
25
- return this._IsNewRecord;
26
- }
27
- set IsNewRecord(record) {
28
- this._IsNewRecord = record;
29
- }
30
- get DocType() {
31
- return this._DocType;
32
- }
33
- set DocType(docType) {
34
- this._DocType = docType;
35
- }
36
- get DocDate() {
37
- return this._DocDate;
38
- }
39
- set DocDate(date) {
40
- this._DocDate = date;
41
- }
42
- get DocHTMLFileMediaId() {
43
- return this._DocHTMLFileMediaId;
44
- }
45
- set DocHTMLFileMediaId(mediaId) {
46
- this._DocHTMLFileMediaId = mediaId;
47
- }
48
- get DocPDFFileMediaId() {
49
- return this._DocPDFFileMediaId;
50
- }
51
- set DocPDFFileMediaId(mediaId) {
52
- this._DocPDFFileMediaId = mediaId;
53
- }
54
- get Amount() {
55
- return this._Amount;
56
- }
57
- set Amount(amount) {
58
- this._Amount = amount;
59
- }
60
- get Status() {
61
- return this._Status;
62
- }
63
- set Status(status) {
64
- this._Status = status;
65
- }
66
- get RepositoryBase() {
67
- return Document._RepositoryBase;
68
- }
69
- get ObjectId() {
70
- return this.DocNo;
71
- }
72
- get ObjectName() {
73
- return this.DocNo;
74
- }
75
- get TableName() {
76
- return 'finance_Document';
77
- }
78
- constructor(dbTransaction, docNo) {
79
- super();
80
- this.DocNo = 'New';
81
- this._DocDate = new Date();
82
- this.Currency = 'MYR';
83
- this._Amount = 0;
84
- this.Description = '';
85
- this._Status = enum_1.DocumentStatus.UNPAID;
86
- this.IssuedById = '';
87
- this.IssuedToId = '';
88
- this.IssuedToType = '';
89
- this.RelatedObjectId = '';
90
- this.RelatedObjectType = '';
91
- this.CreatedById = '';
92
- this.UpdatedById = '';
93
- this.UseAccSystemDocYN = 'N';
94
- this._DocHTMLFileMediaId = '';
95
- this._DocPDFFileMediaId = '';
96
- this._IsNewRecord = true;
97
- this._DocumentItems = [];
98
- if (dbTransaction) {
99
- this._DbTransaction = dbTransaction;
100
- }
101
- if (docNo) {
102
- this.DocNo = docNo;
103
- this.RepositoryBase.findOne({
104
- where: {
105
- DocNo: this.DocNo,
106
- },
107
- transaction: dbTransaction,
108
- })
109
- .then((documentData) => {
110
- if (documentData) {
111
- this.IsNewRecord = false;
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
- else {
138
- const notFoundError = new general_1.RecordNotFoundError('No Record Found.');
139
- throw notFoundError;
140
- }
141
- })
142
- .catch((err) => {
143
- console.log('Document Class constructor err: ', err);
144
- });
145
- }
146
- }
147
- static initDocument(dbTransaction, docNo) {
148
- return __awaiter(this, void 0, void 0, function* () {
149
- const document = new Document(dbTransaction);
150
- const documentData = yield this._RepositoryBase.findOne({
151
- where: {
152
- DocNo: docNo,
153
- },
154
- });
155
- if (documentData) {
156
- document.IsNewRecord = false;
157
- document.DocType = documentData.DocType;
158
- document.DocDate = documentData.DocDate;
159
- document.CompanyId = documentData.CompanyId;
160
- document.Currency = documentData.Currency;
161
- document.Amount = documentData.Amount;
162
- document.Description = documentData.Description;
163
- document.Status = documentData.Status;
164
- document.IssuedById = documentData.IssuedById;
165
- document.IssuedToId = documentData.IssuedToId;
166
- document.IssuedToType = documentData.IssuedToType;
167
- document.RelatedObjectId = documentData.RelatedObjectId;
168
- document.RelatedObjectType = documentData.RelatedObjectType;
169
- document.CreatedById = documentData.CreatedById;
170
- document.CreatedAt = documentData.CreatedAt;
171
- document.UpdatedById = documentData.UpdatedById;
172
- document.UpdatedAt = documentData.UpdatedAt;
173
- document.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
174
- document.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
175
- document.AccSystemRefId = documentData.AccSystemRefId;
176
- document.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
177
- document.PostedById = documentData.PostedById;
178
- document.PostedDateTime = documentData.PostedDateTime;
179
- document.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
180
- document.IsNewRecord = false;
181
- }
182
- else {
183
- const notFoundError = new general_1.RecordNotFoundError('No Record Found.');
184
- throw notFoundError;
185
- }
186
- return document;
187
- });
188
- }
189
- reCalculateAmount() {
190
- return __awaiter(this, void 0, void 0, function* () {
191
- this.Amount = 0;
192
- for (const documentItem of this._DocumentItems) {
193
- this.Amount += documentItem.Amount;
194
- }
195
- });
196
- }
197
- get DocumentItems() {
198
- return new Promise((resolve, reject) => {
199
- if (!this.IsNewRecord) {
200
- Document._DocumentItemRepository
201
- .findAll({
202
- where: {
203
- DocNo: this.DocNo,
204
- },
205
- transaction: this._DbTransaction,
206
- })
207
- .then((documentItems) => {
208
- const documentItemObjects = documentItems.map((documentItem) => {
209
- const di = new document_item_1.default(this._DbTransaction, this);
210
- di.init(Object.assign({}, documentItem.get({ plain: true })));
211
- });
212
- return Promise.all(documentItemObjects);
213
- })
214
- .then((documentItemObjects) => {
215
- this._DocumentItems = documentItemObjects;
216
- resolve(this._DocumentItems);
217
- })
218
- .catch((err) => {
219
- reject(err);
220
- });
221
- }
222
- else {
223
- resolve(this._DocumentItems);
224
- }
225
- });
226
- }
227
- static DEFAULT_INVOICE_TEMPLATE_HTML() {
228
- return __awaiter(this, void 0, void 0, function* () {
229
- const templateLocation = path.resolve('./invoice-template/index.html');
230
- const readFileContent = util.promisify(fs.readFile);
231
- const htmlBuffer = yield readFileContent(templateLocation);
232
- const htmlStream = {
233
- buffer: htmlBuffer,
234
- fieldname: 'FileStream',
235
- originalname: 'index.html',
236
- mimetype: 'text/html',
237
- size: htmlBuffer.length,
238
- encoding: '8bit',
239
- filename: 'sample-invoice.html',
240
- destination: path.dirname(templateLocation),
241
- path: '',
242
- stream: null,
243
- };
244
- return htmlStream;
245
- });
246
- }
247
- DEFAULT_INVOICE_TEMPLATE_PDF(customer) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- const templateLocation = path.resolve('./invoice-template/index.html');
250
- const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
251
- const readFileContent = util.promisify(fs.readFile);
252
- const [htmlString] = yield Promise.all([
253
- readFileContent(templateLocation, 'utf8'),
254
- ]);
255
- const browser = yield puppeteer.launch();
256
- const page = yield browser.newPage();
257
- const imagePath = path.resolve('./invoice-template/assets/img/tomei-logo.svg');
258
- const imageBuffer = yield readFileContent(imagePath);
259
- const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
260
- const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
261
- yield page.setContent(htmlString);
262
- yield page.addStyleTag({ path: cssLocation });
263
- const divHandle = yield page.$('.tm_logo');
264
- yield divHandle.evaluate((div, imgTag) => {
265
- div.innerHTML = imgTag;
266
- }, imgTag);
267
- const currentDate = new Date().toLocaleDateString('en-GB');
268
- const invoiceNo = this.DocNo;
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 fs = require("fs");
14
+ const puppeteer = require("puppeteer");
15
+ const general_1 = require("@tomei/general");
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 path = require("path");
23
+ class Document extends account_system_entity_1.AccountSystemEntity {
24
+ get IsNewRecord() {
25
+ return this._IsNewRecord;
26
+ }
27
+ set IsNewRecord(record) {
28
+ this._IsNewRecord = record;
29
+ }
30
+ get DocType() {
31
+ return this._DocType;
32
+ }
33
+ set DocType(docType) {
34
+ this._DocType = docType;
35
+ }
36
+ get DocDate() {
37
+ return this._DocDate;
38
+ }
39
+ set DocDate(date) {
40
+ this._DocDate = date;
41
+ }
42
+ get DocHTMLFileMediaId() {
43
+ return this._DocHTMLFileMediaId;
44
+ }
45
+ set DocHTMLFileMediaId(mediaId) {
46
+ this._DocHTMLFileMediaId = mediaId;
47
+ }
48
+ get DocPDFFileMediaId() {
49
+ return this._DocPDFFileMediaId;
50
+ }
51
+ set DocPDFFileMediaId(mediaId) {
52
+ this._DocPDFFileMediaId = mediaId;
53
+ }
54
+ get Amount() {
55
+ return this._Amount;
56
+ }
57
+ set Amount(amount) {
58
+ this._Amount = amount;
59
+ }
60
+ get Status() {
61
+ return this._Status;
62
+ }
63
+ set Status(status) {
64
+ this._Status = status;
65
+ }
66
+ get RepositoryBase() {
67
+ return Document._RepositoryBase;
68
+ }
69
+ get ObjectId() {
70
+ return this.DocNo;
71
+ }
72
+ get ObjectName() {
73
+ return this.DocNo;
74
+ }
75
+ get TableName() {
76
+ return 'finance_Document';
77
+ }
78
+ constructor(dbTransaction, docNo) {
79
+ super();
80
+ this.DocNo = 'New';
81
+ this._DocDate = new Date();
82
+ this.Currency = 'MYR';
83
+ this._Amount = 0;
84
+ this.Description = '';
85
+ this._Status = enum_1.DocumentStatus.UNPAID;
86
+ this.IssuedById = '';
87
+ this.IssuedToId = '';
88
+ this.IssuedToType = '';
89
+ this.RelatedObjectId = '';
90
+ this.RelatedObjectType = '';
91
+ this.CreatedById = '';
92
+ this.UpdatedById = '';
93
+ this.UseAccSystemDocYN = 'N';
94
+ this._DocHTMLFileMediaId = '';
95
+ this._DocPDFFileMediaId = '';
96
+ this._IsNewRecord = true;
97
+ this._DocumentItems = [];
98
+ if (dbTransaction) {
99
+ this._DbTransaction = dbTransaction;
100
+ }
101
+ if (docNo) {
102
+ this.DocNo = docNo;
103
+ this.RepositoryBase.findOne({
104
+ where: {
105
+ DocNo: this.DocNo,
106
+ },
107
+ transaction: dbTransaction,
108
+ })
109
+ .then((documentData) => {
110
+ if (documentData) {
111
+ this.IsNewRecord = false;
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
+ else {
138
+ const notFoundError = new general_1.RecordNotFoundError('No Record Found.');
139
+ throw notFoundError;
140
+ }
141
+ })
142
+ .catch((err) => {
143
+ console.log('Document Class constructor err: ', err);
144
+ });
145
+ }
146
+ }
147
+ static initDocument(dbTransaction, docNo) {
148
+ return __awaiter(this, void 0, void 0, function* () {
149
+ const document = new Document(dbTransaction);
150
+ const documentData = yield this._RepositoryBase.findOne({
151
+ where: {
152
+ DocNo: docNo,
153
+ },
154
+ });
155
+ if (documentData) {
156
+ document.IsNewRecord = false;
157
+ document.DocType = documentData.DocType;
158
+ document.DocDate = documentData.DocDate;
159
+ document.CompanyId = documentData.CompanyId;
160
+ document.Currency = documentData.Currency;
161
+ document.Amount = documentData.Amount;
162
+ document.Description = documentData.Description;
163
+ document.Status = documentData.Status;
164
+ document.IssuedById = documentData.IssuedById;
165
+ document.IssuedToId = documentData.IssuedToId;
166
+ document.IssuedToType = documentData.IssuedToType;
167
+ document.RelatedObjectId = documentData.RelatedObjectId;
168
+ document.RelatedObjectType = documentData.RelatedObjectType;
169
+ document.CreatedById = documentData.CreatedById;
170
+ document.CreatedAt = documentData.CreatedAt;
171
+ document.UpdatedById = documentData.UpdatedById;
172
+ document.UpdatedAt = documentData.UpdatedAt;
173
+ document.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
174
+ document.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
175
+ document.AccSystemRefId = documentData.AccSystemRefId;
176
+ document.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
177
+ document.PostedById = documentData.PostedById;
178
+ document.PostedDateTime = documentData.PostedDateTime;
179
+ document.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
180
+ document.IsNewRecord = false;
181
+ }
182
+ else {
183
+ const notFoundError = new general_1.RecordNotFoundError('No Record Found.');
184
+ throw notFoundError;
185
+ }
186
+ return document;
187
+ });
188
+ }
189
+ reCalculateAmount() {
190
+ return __awaiter(this, void 0, void 0, function* () {
191
+ this.Amount = 0;
192
+ for (const documentItem of this._DocumentItems) {
193
+ this.Amount += documentItem.Amount;
194
+ }
195
+ });
196
+ }
197
+ get DocumentItems() {
198
+ return new Promise((resolve, reject) => {
199
+ if (!this.IsNewRecord) {
200
+ Document._DocumentItemRepository
201
+ .findAll({
202
+ where: {
203
+ DocNo: this.DocNo,
204
+ },
205
+ transaction: this._DbTransaction,
206
+ })
207
+ .then((documentItems) => {
208
+ const documentItemObjects = documentItems.map((documentItem) => {
209
+ const di = new document_item_1.default(this._DbTransaction, this);
210
+ di.init(Object.assign({}, documentItem.get({ plain: true })));
211
+ });
212
+ return Promise.all(documentItemObjects);
213
+ })
214
+ .then((documentItemObjects) => {
215
+ this._DocumentItems = documentItemObjects;
216
+ resolve(this._DocumentItems);
217
+ })
218
+ .catch((err) => {
219
+ reject(err);
220
+ });
221
+ }
222
+ else {
223
+ resolve(this._DocumentItems);
224
+ }
225
+ });
226
+ }
227
+ static DEFAULT_INVOICE_TEMPLATE_HTML() {
228
+ return __awaiter(this, void 0, void 0, function* () {
229
+ const templateLocation = path.resolve('./invoice-template/index.html');
230
+ const readFileContent = util.promisify(fs.readFile);
231
+ const htmlBuffer = yield readFileContent(templateLocation);
232
+ const htmlStream = {
233
+ buffer: htmlBuffer,
234
+ fieldname: 'FileStream',
235
+ originalname: 'index.html',
236
+ mimetype: 'text/html',
237
+ size: htmlBuffer.length,
238
+ encoding: '8bit',
239
+ filename: 'sample-invoice.html',
240
+ destination: path.dirname(templateLocation),
241
+ path: '',
242
+ stream: null,
243
+ };
244
+ return htmlStream;
245
+ });
246
+ }
247
+ DEFAULT_INVOICE_TEMPLATE_PDF(customer) {
248
+ return __awaiter(this, void 0, void 0, function* () {
249
+ const templateLocation = path.resolve('./invoice-template/index.html');
250
+ const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
251
+ const readFileContent = util.promisify(fs.readFile);
252
+ const [htmlString] = yield Promise.all([
253
+ readFileContent(templateLocation, 'utf8'),
254
+ ]);
255
+ const browser = yield puppeteer.launch();
256
+ const page = yield browser.newPage();
257
+ const imagePath = path.resolve('./invoice-template/assets/img/tomei-logo.svg');
258
+ const imageBuffer = yield readFileContent(imagePath);
259
+ const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
260
+ const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
261
+ yield page.setContent(htmlString);
262
+ yield page.addStyleTag({ path: cssLocation });
263
+ const divHandle = yield page.$('.tm_logo');
264
+ yield divHandle.evaluate((div, imgTag) => {
265
+ div.innerHTML = imgTag;
266
+ }, imgTag);
267
+ const currentDate = new Date().toLocaleDateString('en-GB');
268
+ const invoiceNo = this.DocNo;
269
269
  const invoiceTitleInfo = `
270
270
  <div class="tm_invoice_seperator tm_gray_bg"></div>
271
271
  <div class="tm_invoice_info_list">
@@ -276,11 +276,11 @@ class Document extends account_system_entity_1.AccountSystemEntity {
276
276
  Date: <b class="tm_primary_color">${currentDate}</b>
277
277
  </p>
278
278
  </div>
279
- `;
280
- const invoiceTitleInfoHandle = yield page.$('.tm_invoice_info');
281
- yield invoiceTitleInfoHandle.evaluate((invoice, invoiceTitleInfo) => {
282
- invoice.innerHTML = invoiceTitleInfo;
283
- }, invoiceTitleInfo);
279
+ `;
280
+ const invoiceTitleInfoHandle = yield page.$('.tm_invoice_info');
281
+ yield invoiceTitleInfoHandle.evaluate((invoice, invoiceTitleInfo) => {
282
+ invoice.innerHTML = invoiceTitleInfo;
283
+ }, invoiceTitleInfo);
284
284
  const invoiceCustomerContent = `
285
285
  <p class="tm_mb2">
286
286
  <b class="tm_primary_color">Invoice To:</b>
@@ -291,23 +291,23 @@ class Document extends account_system_entity_1.AccountSystemEntity {
291
291
  ${customer.DefaultAddress.Country} <br />
292
292
  ${customer.Email}
293
293
  </p>
294
- `;
295
- const invoiceCustomerHandle = yield page.$('.tm_customer_detail');
296
- yield invoiceCustomerHandle.evaluate((invoice, invoiceCustomerContent) => {
297
- invoice.innerHTML = invoiceCustomerContent;
298
- }, invoiceCustomerContent);
299
- const invoicePayToContent = ``;
300
- const invoicePayToHandle = yield page.$('.tm_payto_detail');
301
- yield invoicePayToHandle.evaluate((invoice, invoicePayToContent) => {
302
- invoice.innerHTML = invoicePayToContent;
303
- }, invoicePayToContent);
304
- const invoicePaymentInfoContent = ``;
305
- const invoicePaymentInfoHandle = yield page.$('.tm_payment_info');
306
- yield invoicePaymentInfoHandle.evaluate((invoice, invoicePaymentInfoContent) => {
307
- invoice.innerHTML = invoicePaymentInfoContent;
308
- }, invoicePaymentInfoContent);
309
- const invoiceSubtotal = +this.Amount;
310
- const invoiceTax = 0;
294
+ `;
295
+ const invoiceCustomerHandle = yield page.$('.tm_customer_detail');
296
+ yield invoiceCustomerHandle.evaluate((invoice, invoiceCustomerContent) => {
297
+ invoice.innerHTML = invoiceCustomerContent;
298
+ }, invoiceCustomerContent);
299
+ const invoicePayToContent = ``;
300
+ const invoicePayToHandle = yield page.$('.tm_payto_detail');
301
+ yield invoicePayToHandle.evaluate((invoice, invoicePayToContent) => {
302
+ invoice.innerHTML = invoicePayToContent;
303
+ }, invoicePayToContent);
304
+ const invoicePaymentInfoContent = ``;
305
+ const invoicePaymentInfoHandle = yield page.$('.tm_payment_info');
306
+ yield invoicePaymentInfoHandle.evaluate((invoice, invoicePaymentInfoContent) => {
307
+ invoice.innerHTML = invoicePaymentInfoContent;
308
+ }, invoicePaymentInfoContent);
309
+ const invoiceSubtotal = +this.Amount;
310
+ const invoiceTax = 0;
311
311
  const invoiceRightFooterContent = `
312
312
  <table>
313
313
  <tbody>
@@ -349,11 +349,11 @@ class Document extends account_system_entity_1.AccountSystemEntity {
349
349
  </tr>
350
350
  </tbody>
351
351
  </table>
352
- `;
353
- const invoiceRightFooterHandle = yield page.$('.tm_item_total_section');
354
- yield invoiceRightFooterHandle.evaluate((invoice, invoiceRightFooterContent) => {
355
- invoice.innerHTML = invoiceRightFooterContent;
356
- }, invoiceRightFooterContent);
352
+ `;
353
+ const invoiceRightFooterHandle = yield page.$('.tm_item_total_section');
354
+ yield invoiceRightFooterHandle.evaluate((invoice, invoiceRightFooterContent) => {
355
+ invoice.innerHTML = invoiceRightFooterContent;
356
+ }, invoiceRightFooterContent);
357
357
  const invoiceTNCContent = `
358
358
  <li>
359
359
  All payment must be made to:
@@ -366,14 +366,14 @@ class Document extends account_system_entity_1.AccountSystemEntity {
366
366
  <li>
367
367
  Once payment has been made, please email your transaction confirmation slip to <i>payment@ezcash.com.my</i>
368
368
  </li>
369
- `;
370
- const invoiceTNCHandle = yield page.$('.tm_tnc_content');
371
- yield invoiceTNCHandle.evaluate((invoice, invoiceTNCContent) => {
372
- invoice.innerHTML = invoiceTNCContent;
373
- }, invoiceTNCContent);
374
- const invoiceDocumentItems = yield this.DocumentItems;
375
- let invoiceItemContent = ``;
376
- invoiceDocumentItems.forEach((documentItem, i) => {
369
+ `;
370
+ const invoiceTNCHandle = yield page.$('.tm_tnc_content');
371
+ yield invoiceTNCHandle.evaluate((invoice, invoiceTNCContent) => {
372
+ invoice.innerHTML = invoiceTNCContent;
373
+ }, invoiceTNCContent);
374
+ const invoiceDocumentItems = yield this.DocumentItems;
375
+ let invoiceItemContent = ``;
376
+ invoiceDocumentItems.forEach((documentItem, i) => {
377
377
  invoiceItemContent += `
378
378
  <tr>
379
379
  <td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
@@ -384,68 +384,68 @@ class Document extends account_system_entity_1.AccountSystemEntity {
384
384
  <td class="tm_width_1">${documentItem.Quantity}</td>
385
385
  <td class="tm_width_2 tm_text_right">${documentItem.Currency} ${+documentItem.UnitPrice * +documentItem.Quantity}</td>
386
386
  </tr>
387
- `;
388
- });
389
- const invoiceDocumentItemHandle = yield page.$('.tm_items_content');
390
- yield invoiceDocumentItemHandle.evaluate((invoice, invoiceItemContent) => {
391
- invoice.innerHTML = invoiceItemContent;
392
- }, invoiceItemContent);
393
- const pdfBuffer = yield page.pdf({
394
- format: 'a4',
395
- printBackground: true,
396
- margin: {
397
- left: '0px',
398
- top: '0px',
399
- right: '0px',
400
- bottom: '0px',
401
- },
402
- });
403
- const pdfStream = {
404
- buffer: pdfBuffer,
405
- fieldname: 'FileStream',
406
- originalname: 'sample-invoice.pdf',
407
- mimetype: 'application/pdf',
408
- size: pdfBuffer.length,
409
- encoding: '8bit',
410
- filename: 'sample-invoice.pdf',
411
- destination: '',
412
- path: '',
413
- stream: null,
414
- };
415
- return pdfStream;
416
- });
417
- }
418
- DEFAULT_RECEIPT_TEMPLATE_PDF(customer) {
419
- return __awaiter(this, void 0, void 0, function* () {
420
- const templateLocation = path.resolve('./invoice-template/index.html');
421
- const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
422
- const readFileContent = util.promisify(fs.readFile);
423
- const [htmlString] = yield Promise.all([
424
- readFileContent(templateLocation, 'utf8'),
425
- ]);
426
- const browser = yield puppeteer.launch();
427
- const page = yield browser.newPage();
428
- const imagePath = path.resolve('./invoice-template/assets/img/tomei-logo.svg');
429
- const imageBuffer = yield readFileContent(imagePath);
430
- const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
431
- const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
432
- yield page.setContent(htmlString);
433
- yield page.addStyleTag({ path: cssLocation });
434
- const divHandle = yield page.$('.tm_logo');
435
- yield divHandle.evaluate((div, imgTag) => {
436
- div.innerHTML = imgTag;
437
- }, imgTag);
438
- const currentDate = new Date().toLocaleDateString('en-GB');
439
- const receiptNo = this.DocNo;
387
+ `;
388
+ });
389
+ const invoiceDocumentItemHandle = yield page.$('.tm_items_content');
390
+ yield invoiceDocumentItemHandle.evaluate((invoice, invoiceItemContent) => {
391
+ invoice.innerHTML = invoiceItemContent;
392
+ }, invoiceItemContent);
393
+ const pdfBuffer = yield page.pdf({
394
+ format: 'a4',
395
+ printBackground: true,
396
+ margin: {
397
+ left: '0px',
398
+ top: '0px',
399
+ right: '0px',
400
+ bottom: '0px',
401
+ },
402
+ });
403
+ const pdfStream = {
404
+ buffer: pdfBuffer,
405
+ fieldname: 'FileStream',
406
+ originalname: 'sample-invoice.pdf',
407
+ mimetype: 'application/pdf',
408
+ size: pdfBuffer.length,
409
+ encoding: '8bit',
410
+ filename: 'sample-invoice.pdf',
411
+ destination: '',
412
+ path: '',
413
+ stream: null,
414
+ };
415
+ return pdfStream;
416
+ });
417
+ }
418
+ DEFAULT_RECEIPT_TEMPLATE_PDF(customer) {
419
+ return __awaiter(this, void 0, void 0, function* () {
420
+ const templateLocation = path.resolve('./invoice-template/index.html');
421
+ const cssLocation = path.resolve('./invoice-template/assets/css/style.css');
422
+ const readFileContent = util.promisify(fs.readFile);
423
+ const [htmlString] = yield Promise.all([
424
+ readFileContent(templateLocation, 'utf8'),
425
+ ]);
426
+ const browser = yield puppeteer.launch();
427
+ const page = yield browser.newPage();
428
+ const imagePath = path.resolve('./invoice-template/assets/img/tomei-logo.svg');
429
+ const imageBuffer = yield readFileContent(imagePath);
430
+ const imageDataUrl = `data:image/svg+xml;base64,${imageBuffer.toString('base64')}`;
431
+ const imgTag = `<img src="${imageDataUrl}" alt="Logo">`;
432
+ yield page.setContent(htmlString);
433
+ yield page.addStyleTag({ path: cssLocation });
434
+ const divHandle = yield page.$('.tm_logo');
435
+ yield divHandle.evaluate((div, imgTag) => {
436
+ div.innerHTML = imgTag;
437
+ }, imgTag);
438
+ const currentDate = new Date().toLocaleDateString('en-GB');
439
+ const receiptNo = this.DocNo;
440
440
  const receiptTitle = `
441
441
  <div class="tm_primary_color tm_f50 tm_text_uppercase">
442
442
  Receipt
443
443
  </div>
444
- `;
445
- const receiptTitleHandle = yield page.$('.tm_invoice_title');
446
- yield receiptTitleHandle.evaluate((receipt, receiptTitle) => {
447
- receipt.innerHTML = receiptTitle;
448
- }, receiptTitle);
444
+ `;
445
+ const receiptTitleHandle = yield page.$('.tm_invoice_title');
446
+ yield receiptTitleHandle.evaluate((receipt, receiptTitle) => {
447
+ receipt.innerHTML = receiptTitle;
448
+ }, receiptTitle);
449
449
  const receiptTitleInfo = `
450
450
  <div class="tm_invoice_seperator tm_gray_bg"></div>
451
451
  <div class="tm_invoice_info_list">
@@ -456,11 +456,11 @@ class Document extends account_system_entity_1.AccountSystemEntity {
456
456
  Date: <b class="tm_primary_color">${currentDate}</b>
457
457
  </p>
458
458
  </div>
459
- `;
460
- const receiptTitleInfoHandle = yield page.$('.tm_invoice_info');
461
- yield receiptTitleInfoHandle.evaluate((receipt, receiptTitleInfo) => {
462
- receipt.innerHTML = receiptTitleInfo;
463
- }, receiptTitleInfo);
459
+ `;
460
+ const receiptTitleInfoHandle = yield page.$('.tm_invoice_info');
461
+ yield receiptTitleInfoHandle.evaluate((receipt, receiptTitleInfo) => {
462
+ receipt.innerHTML = receiptTitleInfo;
463
+ }, receiptTitleInfo);
464
464
  const receiptCustomerContent = `
465
465
  <p class="tm_mb2">
466
466
  <b class="tm_primary_color">Issued To:</b>
@@ -471,23 +471,23 @@ class Document extends account_system_entity_1.AccountSystemEntity {
471
471
  ${customer.DefaultAddress.Country} <br />
472
472
  ${customer.Email}
473
473
  </p>
474
- `;
475
- const receiptCustomerHandle = yield page.$('.tm_customer_detail');
476
- yield receiptCustomerHandle.evaluate((receipt, receiptCustomerContent) => {
477
- receipt.innerHTML = receiptCustomerContent;
478
- }, receiptCustomerContent);
479
- const receiptPayToContent = ``;
480
- const receiptPayToHandle = yield page.$('.tm_payto_detail');
481
- yield receiptPayToHandle.evaluate((receipt, receiptPayToContent) => {
482
- receipt.innerHTML = receiptPayToContent;
483
- }, receiptPayToContent);
484
- const receiptPaymentInfoContent = ``;
485
- const receiptPaymentInfoHandle = yield page.$('.tm_payment_info');
486
- yield receiptPaymentInfoHandle.evaluate((receipt, receiptPaymentInfoContent) => {
487
- receipt.innerHTML = receiptPaymentInfoContent;
488
- }, receiptPaymentInfoContent);
489
- const receiptSubtotal = +this.Amount;
490
- const receiptTax = 0;
474
+ `;
475
+ const receiptCustomerHandle = yield page.$('.tm_customer_detail');
476
+ yield receiptCustomerHandle.evaluate((receipt, receiptCustomerContent) => {
477
+ receipt.innerHTML = receiptCustomerContent;
478
+ }, receiptCustomerContent);
479
+ const receiptPayToContent = ``;
480
+ const receiptPayToHandle = yield page.$('.tm_payto_detail');
481
+ yield receiptPayToHandle.evaluate((receipt, receiptPayToContent) => {
482
+ receipt.innerHTML = receiptPayToContent;
483
+ }, receiptPayToContent);
484
+ const receiptPaymentInfoContent = ``;
485
+ const receiptPaymentInfoHandle = yield page.$('.tm_payment_info');
486
+ yield receiptPaymentInfoHandle.evaluate((receipt, receiptPaymentInfoContent) => {
487
+ receipt.innerHTML = receiptPaymentInfoContent;
488
+ }, receiptPaymentInfoContent);
489
+ const receiptSubtotal = +this.Amount;
490
+ const receiptTax = 0;
491
491
  const receiptRightFooterContent = `
492
492
  <table>
493
493
  <tbody>
@@ -529,14 +529,14 @@ class Document extends account_system_entity_1.AccountSystemEntity {
529
529
  </tr>
530
530
  </tbody>
531
531
  </table>
532
- `;
533
- const receiptRightFooterHandle = yield page.$('.tm_item_total_section');
534
- yield receiptRightFooterHandle.evaluate((receipt, receiptRightFooterContent) => {
535
- receipt.innerHTML = receiptRightFooterContent;
536
- }, receiptRightFooterContent);
537
- const receiptDocumentItems = yield this.DocumentItems;
538
- let receiptItemContent = ``;
539
- receiptDocumentItems.forEach((documentItem, i) => {
532
+ `;
533
+ const receiptRightFooterHandle = yield page.$('.tm_item_total_section');
534
+ yield receiptRightFooterHandle.evaluate((receipt, receiptRightFooterContent) => {
535
+ receipt.innerHTML = receiptRightFooterContent;
536
+ }, receiptRightFooterContent);
537
+ const receiptDocumentItems = yield this.DocumentItems;
538
+ let receiptItemContent = ``;
539
+ receiptDocumentItems.forEach((documentItem, i) => {
540
540
  receiptItemContent += `
541
541
  <tr>
542
542
  <td class="tm_width_3">${i + 1}. ${documentItem.Name}</td>
@@ -547,12 +547,12 @@ class Document extends account_system_entity_1.AccountSystemEntity {
547
547
  <td class="tm_width_1">${documentItem.Quantity}</td>
548
548
  <td class="tm_width_2 tm_text_right">${documentItem.Currency} ${+documentItem.UnitPrice * +documentItem.Quantity}</td>
549
549
  </tr>
550
- `;
551
- });
552
- const receiptDocumentItemHandle = yield page.$('.tm_items_content');
553
- yield receiptDocumentItemHandle.evaluate((receipt, receiptItemContent) => {
554
- receipt.innerHTML = receiptItemContent;
555
- }, receiptItemContent);
550
+ `;
551
+ });
552
+ const receiptDocumentItemHandle = yield page.$('.tm_items_content');
553
+ yield receiptDocumentItemHandle.evaluate((receipt, receiptItemContent) => {
554
+ receipt.innerHTML = receiptItemContent;
555
+ }, receiptItemContent);
556
556
  const receiptFooterContent = `
557
557
  <p class="tm_mb5 tm_text_center tm_f11">
558
558
  <i>
@@ -560,173 +560,173 @@ class Document extends account_system_entity_1.AccountSystemEntity {
560
560
  - no signature is required.
561
561
  </i>
562
562
  </p>
563
- `;
564
- const receiptFooterHandle = yield page.$('.tm_footer_section');
565
- yield receiptFooterHandle.evaluate((receipt, receiptFooterContent) => {
566
- receipt.innerHTML = receiptFooterContent;
567
- }, receiptFooterContent);
568
- const pdfBuffer = yield page.pdf({
569
- format: 'a4',
570
- printBackground: true,
571
- margin: {
572
- left: '0px',
573
- top: '0px',
574
- right: '0px',
575
- bottom: '0px',
576
- },
577
- });
578
- const pdfStream = {
579
- buffer: pdfBuffer,
580
- fieldname: 'FileStream',
581
- originalname: 'sample-invoice.pdf',
582
- mimetype: 'application/pdf',
583
- size: pdfBuffer.length,
584
- encoding: '8bit',
585
- filename: 'sample-invoice.pdf',
586
- destination: '',
587
- path: '',
588
- stream: null,
589
- };
590
- return pdfStream;
591
- });
592
- }
593
- get DocumentFileInHTML() {
594
- return (() => __awaiter(this, void 0, void 0, function* () {
595
- const { HTMLMedia } = yield this.generateInvoice();
596
- return HTMLMedia;
597
- }))();
598
- }
599
- get DocumentFileInPDF() {
600
- return (() => __awaiter(this, void 0, void 0, function* () {
601
- const { PDFMedia } = yield this.generateInvoice();
602
- return PDFMedia;
603
- }))();
604
- }
605
- init(params) {
606
- this.DocNo = params.DocNo;
607
- this.DocType = params.DocType;
608
- this.DocDate = params.DocDate;
609
- this.CompanyId = params.CompanyId;
610
- this.Currency = params.Currency;
611
- this.Amount = params.Amount;
612
- this.Description = params.Description;
613
- this.Status = params.Status;
614
- this.IssuedById = params.IssuedById;
615
- this.IssuedToId = params.IssuedToId;
616
- this.IssuedToType = params.IssuedToType;
617
- this.RelatedObjectId = params.RelatedObjectId;
618
- this.RelatedObjectType = params.RelatedObjectType;
619
- this.CreatedById = params.CreatedById;
620
- this.CreatedAt = params.CreatedAt;
621
- this.UpdatedById = params.UpdatedById;
622
- this.UpdatedAt = params.UpdatedAt;
623
- this.DocPDFFileMediaId = params.DocPDFFileMediaId;
624
- this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
625
- this.AccSystemRefId = params.AccSystemRefId;
626
- this.PostedToAccSystemYN = params.PostedToAccSystemYN;
627
- this.PostedById = params.PostedById;
628
- this.PostedDateTime = params.PostedDateTime;
629
- this.UseAccSystemDocYN = params.UseAccSystemDocYN;
630
- }
631
- generateInvoice(userId, customer) {
632
- return __awaiter(this, void 0, void 0, function* () {
633
- const media = new media_1.Medias(Document._MediaRepository, this.mediaCommonService);
634
- const htmlPayload = {
635
- ObjectId: this.DocNo,
636
- ObjectType: this.DocType,
637
- Type: media_1.MediaType.Document,
638
- FileName: `${this.DocType}-${this.DocNo}`,
639
- FileStream: yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
640
- FileExtension: 'html',
641
- Title: `${this.DocType}-${this.DocNo}.html`,
642
- Description: `HTML ${this.DocType}`,
643
- IsEncryptedYN: 'N',
644
- };
645
- const HTMLInvoiceMedia = yield media.postInternal(yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, userId !== null && userId !== void 0 ? userId : 'System');
646
- const pdfPayload = {
647
- ObjectId: this.DocNo,
648
- ObjectType: this.DocType,
649
- Type: media_1.MediaType.Document,
650
- FileName: `${this.DocType}-${this.DocNo}`,
651
- FileStream: yield this.DEFAULT_INVOICE_TEMPLATE_PDF(customer),
652
- FileExtension: 'pdf',
653
- Title: `${this.DocType}-${this.DocNo}.pdf`,
654
- Description: `PDF ${this.DocType}`,
655
- IsEncryptedYN: 'N',
656
- };
657
- const PDFInvoiceMedia = yield media.postInternal(yield this.DEFAULT_INVOICE_TEMPLATE_PDF(customer), pdfPayload, userId !== null && userId !== void 0 ? userId : 'System');
658
- return {
659
- HTMLMedia: HTMLInvoiceMedia,
660
- PDFMedia: PDFInvoiceMedia,
661
- };
662
- });
663
- }
664
- generateReceipt(userId, customer) {
665
- return __awaiter(this, void 0, void 0, function* () {
666
- const media = new media_1.Medias(Document._MediaRepository, this.mediaCommonService);
667
- const htmlPayload = {
668
- ObjectId: this.DocNo,
669
- ObjectType: this.DocType,
670
- Type: media_1.MediaType.Document,
671
- FileName: `${this.DocType}-${this.DocNo}`,
672
- FileStream: yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
673
- FileExtension: 'html',
674
- Title: `${this.DocType}-${this.DocNo}.html`,
675
- Description: `HTML ${this.DocType}`,
676
- IsEncryptedYN: 'N',
677
- };
678
- const HTMLInvoiceMedia = yield media.postInternal(yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, userId !== null && userId !== void 0 ? userId : 'System');
679
- const pdfPayload = {
680
- ObjectId: this.DocNo,
681
- ObjectType: this.DocType,
682
- Type: media_1.MediaType.Document,
683
- FileName: `${this.DocType}-${this.DocNo}`,
684
- FileStream: yield this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer),
685
- FileExtension: 'pdf',
686
- Title: `${this.DocType}-${this.DocNo}.pdf`,
687
- Description: `PDF ${this.DocType}`,
688
- IsEncryptedYN: 'N',
689
- };
690
- const PDFInvoiceMedia = yield media.postInternal(yield this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer), pdfPayload, userId !== null && userId !== void 0 ? userId : 'System');
691
- return {
692
- HTMLMedia: HTMLInvoiceMedia,
693
- PDFMedia: PDFInvoiceMedia,
694
- };
695
- });
696
- }
697
- generateCreditNote(userId, customer) {
698
- return __awaiter(this, void 0, void 0, function* () {
699
- console.log(userId, customer, '<< generateCreditNote');
700
- });
701
- }
702
- newDocumentItem(documentItem) {
703
- return __awaiter(this, void 0, void 0, function* () {
704
- let di;
705
- if (documentItem) {
706
- di = documentItem;
707
- }
708
- else {
709
- di = new document_item_1.default(this._DbTransaction, this);
710
- }
711
- di.DocNo = this.DocNo;
712
- this._DocumentItems.push(di);
713
- this.reCalculateAmount();
714
- return documentItem;
715
- });
716
- }
717
- getPreviousDocument(docType) {
718
- return __awaiter(this, void 0, void 0, function* () {
719
- return yield this.RepositoryBase.findOne({
720
- where: {
721
- DocType: docType,
722
- },
723
- order: [['CreatedAt', 'DESC']],
724
- });
725
- });
726
- }
727
- }
728
- exports.default = Document;
729
- Document._RepositoryBase = new document_repository_1.DocumentRepository();
730
- Document._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
731
- Document._MediaRepository = new media_1.MediasRepository(media_1.MediasModel);
563
+ `;
564
+ const receiptFooterHandle = yield page.$('.tm_footer_section');
565
+ yield receiptFooterHandle.evaluate((receipt, receiptFooterContent) => {
566
+ receipt.innerHTML = receiptFooterContent;
567
+ }, receiptFooterContent);
568
+ const pdfBuffer = yield page.pdf({
569
+ format: 'a4',
570
+ printBackground: true,
571
+ margin: {
572
+ left: '0px',
573
+ top: '0px',
574
+ right: '0px',
575
+ bottom: '0px',
576
+ },
577
+ });
578
+ const pdfStream = {
579
+ buffer: pdfBuffer,
580
+ fieldname: 'FileStream',
581
+ originalname: 'sample-invoice.pdf',
582
+ mimetype: 'application/pdf',
583
+ size: pdfBuffer.length,
584
+ encoding: '8bit',
585
+ filename: 'sample-invoice.pdf',
586
+ destination: '',
587
+ path: '',
588
+ stream: null,
589
+ };
590
+ return pdfStream;
591
+ });
592
+ }
593
+ get DocumentFileInHTML() {
594
+ return (() => __awaiter(this, void 0, void 0, function* () {
595
+ const { HTMLMedia } = yield this.generateInvoice();
596
+ return HTMLMedia;
597
+ }))();
598
+ }
599
+ get DocumentFileInPDF() {
600
+ return (() => __awaiter(this, void 0, void 0, function* () {
601
+ const { PDFMedia } = yield this.generateInvoice();
602
+ return PDFMedia;
603
+ }))();
604
+ }
605
+ init(params) {
606
+ this.DocNo = params.DocNo;
607
+ this.DocType = params.DocType;
608
+ this.DocDate = params.DocDate;
609
+ this.CompanyId = params.CompanyId;
610
+ this.Currency = params.Currency;
611
+ this.Amount = params.Amount;
612
+ this.Description = params.Description;
613
+ this.Status = params.Status;
614
+ this.IssuedById = params.IssuedById;
615
+ this.IssuedToId = params.IssuedToId;
616
+ this.IssuedToType = params.IssuedToType;
617
+ this.RelatedObjectId = params.RelatedObjectId;
618
+ this.RelatedObjectType = params.RelatedObjectType;
619
+ this.CreatedById = params.CreatedById;
620
+ this.CreatedAt = params.CreatedAt;
621
+ this.UpdatedById = params.UpdatedById;
622
+ this.UpdatedAt = params.UpdatedAt;
623
+ this.DocPDFFileMediaId = params.DocPDFFileMediaId;
624
+ this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
625
+ this.AccSystemRefId = params.AccSystemRefId;
626
+ this.PostedToAccSystemYN = params.PostedToAccSystemYN;
627
+ this.PostedById = params.PostedById;
628
+ this.PostedDateTime = params.PostedDateTime;
629
+ this.UseAccSystemDocYN = params.UseAccSystemDocYN;
630
+ }
631
+ generateInvoice(userId, customer) {
632
+ return __awaiter(this, void 0, void 0, function* () {
633
+ const media = new media_1.Medias(Document._MediaRepository, this.mediaCommonService);
634
+ const htmlPayload = {
635
+ ObjectId: this.DocNo,
636
+ ObjectType: this.DocType,
637
+ Type: media_1.MediaType.Document,
638
+ FileName: `${this.DocType}-${this.DocNo}`,
639
+ FileStream: yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
640
+ FileExtension: 'html',
641
+ Title: `${this.DocType}-${this.DocNo}.html`,
642
+ Description: `HTML ${this.DocType}`,
643
+ IsEncryptedYN: 'N',
644
+ };
645
+ const HTMLInvoiceMedia = yield media.postInternal(yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, userId !== null && userId !== void 0 ? userId : 'System');
646
+ const pdfPayload = {
647
+ ObjectId: this.DocNo,
648
+ ObjectType: this.DocType,
649
+ Type: media_1.MediaType.Document,
650
+ FileName: `${this.DocType}-${this.DocNo}`,
651
+ FileStream: yield this.DEFAULT_INVOICE_TEMPLATE_PDF(customer),
652
+ FileExtension: 'pdf',
653
+ Title: `${this.DocType}-${this.DocNo}.pdf`,
654
+ Description: `PDF ${this.DocType}`,
655
+ IsEncryptedYN: 'N',
656
+ };
657
+ const PDFInvoiceMedia = yield media.postInternal(yield this.DEFAULT_INVOICE_TEMPLATE_PDF(customer), pdfPayload, userId !== null && userId !== void 0 ? userId : 'System');
658
+ return {
659
+ HTMLMedia: HTMLInvoiceMedia,
660
+ PDFMedia: PDFInvoiceMedia,
661
+ };
662
+ });
663
+ }
664
+ generateReceipt(userId, customer) {
665
+ return __awaiter(this, void 0, void 0, function* () {
666
+ const media = new media_1.Medias(Document._MediaRepository, this.mediaCommonService);
667
+ const htmlPayload = {
668
+ ObjectId: this.DocNo,
669
+ ObjectType: this.DocType,
670
+ Type: media_1.MediaType.Document,
671
+ FileName: `${this.DocType}-${this.DocNo}`,
672
+ FileStream: yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
673
+ FileExtension: 'html',
674
+ Title: `${this.DocType}-${this.DocNo}.html`,
675
+ Description: `HTML ${this.DocType}`,
676
+ IsEncryptedYN: 'N',
677
+ };
678
+ const HTMLInvoiceMedia = yield media.postInternal(yield Document.DEFAULT_INVOICE_TEMPLATE_HTML(), htmlPayload, userId !== null && userId !== void 0 ? userId : 'System');
679
+ const pdfPayload = {
680
+ ObjectId: this.DocNo,
681
+ ObjectType: this.DocType,
682
+ Type: media_1.MediaType.Document,
683
+ FileName: `${this.DocType}-${this.DocNo}`,
684
+ FileStream: yield this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer),
685
+ FileExtension: 'pdf',
686
+ Title: `${this.DocType}-${this.DocNo}.pdf`,
687
+ Description: `PDF ${this.DocType}`,
688
+ IsEncryptedYN: 'N',
689
+ };
690
+ const PDFInvoiceMedia = yield media.postInternal(yield this.DEFAULT_RECEIPT_TEMPLATE_PDF(customer), pdfPayload, userId !== null && userId !== void 0 ? userId : 'System');
691
+ return {
692
+ HTMLMedia: HTMLInvoiceMedia,
693
+ PDFMedia: PDFInvoiceMedia,
694
+ };
695
+ });
696
+ }
697
+ generateCreditNote(userId, customer) {
698
+ return __awaiter(this, void 0, void 0, function* () {
699
+ console.log(userId, customer, '<< generateCreditNote');
700
+ });
701
+ }
702
+ newDocumentItem(documentItem) {
703
+ return __awaiter(this, void 0, void 0, function* () {
704
+ let di;
705
+ if (documentItem) {
706
+ di = documentItem;
707
+ }
708
+ else {
709
+ di = new document_item_1.default(this._DbTransaction, this);
710
+ }
711
+ di.DocNo = this.DocNo;
712
+ this._DocumentItems.push(di);
713
+ this.reCalculateAmount();
714
+ return documentItem;
715
+ });
716
+ }
717
+ getPreviousDocument(docType) {
718
+ return __awaiter(this, void 0, void 0, function* () {
719
+ return yield this.RepositoryBase.findOne({
720
+ where: {
721
+ DocType: docType,
722
+ },
723
+ order: [['CreatedAt', 'DESC']],
724
+ });
725
+ });
726
+ }
727
+ }
728
+ exports.default = Document;
729
+ Document._RepositoryBase = new document_repository_1.DocumentRepository();
730
+ Document._DocumentItemRepository = new document_item_repository_1.DocumentItemRepository();
731
+ Document._MediaRepository = new media_1.MediasRepository(media_1.MediasModel);
732
732
  //# sourceMappingURL=document.js.map