@tomei/finance 0.2.14 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/README.md +8 -36
  2. package/dist/account/account.d.ts +2 -2
  3. package/dist/account/account.js +52 -39
  4. package/dist/account/account.js.map +1 -1
  5. package/dist/account/account.repository.d.ts +1 -1
  6. package/dist/account/account.repository.js +2 -2
  7. package/dist/account/account.repository.js.map +1 -1
  8. package/dist/account/interfaces/account.repository.interface.d.ts +1 -1
  9. package/dist/account-system-entity/account-system-entity.js +51 -30
  10. package/dist/account-system-entity/account-system-entity.js.map +1 -1
  11. package/dist/account-system-entity/post-history.repository.d.ts +1 -1
  12. package/dist/account-system-entity/post-history.repository.js +2 -3
  13. package/dist/account-system-entity/post-history.repository.js.map +1 -1
  14. package/dist/customer/customer.d.ts +6 -5
  15. package/dist/customer/customer.js +32 -19
  16. package/dist/customer/customer.js.map +1 -1
  17. package/dist/customer/finance-customer.repository.d.ts +1 -1
  18. package/dist/customer/finance-customer.repository.js +2 -2
  19. package/dist/customer/finance-customer.repository.js.map +1 -1
  20. package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +1 -1
  21. package/dist/database.d.ts +4 -0
  22. package/dist/database.js +15 -0
  23. package/dist/database.js.map +1 -0
  24. package/dist/document/document-item.d.ts +2 -2
  25. package/dist/document/document-item.repository.d.ts +1 -1
  26. package/dist/document/document-item.repository.js +2 -2
  27. package/dist/document/document-item.repository.js.map +1 -1
  28. package/dist/document/document.d.ts +43 -21
  29. package/dist/document/document.js +202 -67
  30. package/dist/document/document.js.map +1 -1
  31. package/dist/document/document.repository.d.ts +1 -1
  32. package/dist/document/document.repository.js +2 -2
  33. package/dist/document/document.repository.js.map +1 -1
  34. package/dist/document/interfaces/document-attr.interface.d.ts +10 -4
  35. package/dist/document/interfaces/document-attr.interface.js.map +1 -1
  36. package/dist/document/interfaces/document-item-attr.interface.d.ts +2 -2
  37. package/dist/document/interfaces/document-item.repository.interface.d.ts +1 -1
  38. package/dist/document/interfaces/document.repository.interface.d.ts +1 -1
  39. package/dist/enum/doc-type.enum.d.ts +1 -0
  40. package/dist/enum/doc-type.enum.js +1 -0
  41. package/dist/enum/doc-type.enum.js.map +1 -1
  42. package/dist/enum/document-status.enum.d.ts +3 -2
  43. package/dist/enum/document-status.enum.js +3 -2
  44. package/dist/enum/document-status.enum.js.map +1 -1
  45. package/dist/finance-company/finance-company.d.ts +14 -8
  46. package/dist/finance-company/finance-company.js +195 -151
  47. package/dist/finance-company/finance-company.js.map +1 -1
  48. package/dist/finance-company/finance-company.repository.d.ts +1 -1
  49. package/dist/finance-company/finance-company.repository.js +2 -3
  50. package/dist/finance-company/finance-company.repository.js.map +1 -1
  51. package/dist/index.d.ts +12 -9
  52. package/dist/index.js +20 -25
  53. package/dist/index.js.map +1 -1
  54. package/dist/interfaces/account-system.interface.d.ts +4 -4
  55. package/dist/journal-entry/journal-entry.d.ts +3 -3
  56. package/dist/journal-entry/journal-entry.js +52 -37
  57. package/dist/journal-entry/journal-entry.js.map +1 -1
  58. package/dist/journal-entry/journal-entry.repository.d.ts +1 -1
  59. package/dist/journal-entry/journal-entry.repository.js +2 -2
  60. package/dist/journal-entry/journal-entry.repository.js.map +1 -1
  61. package/dist/ledger-transaction/ledger-transaction.js +39 -26
  62. package/dist/ledger-transaction/ledger-transaction.js.map +1 -1
  63. package/dist/ledger-transaction/ledger-transaction.repository.d.ts +1 -1
  64. package/dist/ledger-transaction/ledger-transaction.repository.js +2 -2
  65. package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -1
  66. package/dist/models/account.entity.d.ts +26 -0
  67. package/dist/models/account.entity.js +198 -0
  68. package/dist/models/account.entity.js.map +1 -0
  69. package/dist/models/customer.entity.d.ts +13 -0
  70. package/dist/models/customer.entity.js +110 -0
  71. package/dist/models/customer.entity.js.map +1 -0
  72. package/dist/models/document-item.entity.d.ts +27 -0
  73. package/dist/models/document-item.entity.js +173 -0
  74. package/dist/models/document-item.entity.js.map +1 -0
  75. package/dist/models/document.entity.d.ts +30 -0
  76. package/dist/models/document.entity.js +222 -0
  77. package/dist/models/document.entity.js.map +1 -0
  78. package/dist/models/finance-company.entity.d.ts +13 -0
  79. package/dist/models/finance-company.entity.js +65 -0
  80. package/dist/models/finance-company.entity.js.map +1 -0
  81. package/dist/models/journal-entry.entity.d.ts +16 -0
  82. package/dist/models/journal-entry.entity.js +128 -0
  83. package/dist/models/journal-entry.entity.js.map +1 -0
  84. package/dist/models/ledger-transaction.entity.d.ts +19 -0
  85. package/dist/models/ledger-transaction.entity.js +156 -0
  86. package/dist/models/ledger-transaction.entity.js.map +1 -0
  87. package/dist/models/payment-item.entity.d.ts +10 -0
  88. package/dist/models/payment-item.entity.js +61 -0
  89. package/dist/models/payment-item.entity.js.map +1 -0
  90. package/dist/models/payment.entity.d.ts +25 -0
  91. package/dist/models/payment.entity.js +151 -0
  92. package/dist/models/payment.entity.js.map +1 -0
  93. package/dist/models/post-history.entity.d.ts +11 -0
  94. package/dist/models/post-history.entity.js +64 -0
  95. package/dist/models/post-history.entity.js.map +1 -0
  96. package/dist/payment/interfaces/payment-item.repository.interface.d.ts +1 -1
  97. package/dist/payment/interfaces/payment.repository.interface.d.ts +1 -1
  98. package/dist/payment/payment-item.repository.d.ts +1 -1
  99. package/dist/payment/payment-item.repository.js +2 -2
  100. package/dist/payment/payment-item.repository.js.map +1 -1
  101. package/dist/payment/payment.d.ts +4 -4
  102. package/dist/payment/payment.js +92 -77
  103. package/dist/payment/payment.js.map +1 -1
  104. package/dist/payment/payment.repository.d.ts +1 -1
  105. package/dist/payment/payment.repository.js +2 -2
  106. package/dist/payment/payment.repository.js.map +1 -1
  107. package/dist/tsconfig.tsbuildinfo +1 -1
  108. package/img.png +0 -0
  109. package/img_1.png +0 -0
  110. package/migrations/finance-document-item-migration.js +2 -2
  111. package/migrations/finance-document-migration.js +44 -13
  112. package/package.json +7 -4
  113. package/src/account/account.repository.ts +1 -1
  114. package/src/account/account.ts +3 -2
  115. package/src/account/interfaces/account.repository.interface.ts +1 -1
  116. package/src/account-system-entity/account-system-entity.ts +7 -3
  117. package/src/account-system-entity/post-history.repository.ts +2 -3
  118. package/src/customer/customer.ts +12 -5
  119. package/src/customer/finance-customer.repository.ts +1 -1
  120. package/src/customer/interfaces/finance-customer.repository.interface.ts +1 -1
  121. package/src/database.ts +15 -0
  122. package/src/document/document-item.repository.ts +1 -1
  123. package/src/document/document-item.ts +2 -2
  124. package/src/document/document.repository.ts +1 -1
  125. package/src/document/document.ts +281 -76
  126. package/src/document/interfaces/document-attr.interface.ts +10 -4
  127. package/src/document/interfaces/document-item-attr.interface.ts +2 -2
  128. package/src/document/interfaces/document-item.repository.interface.ts +1 -1
  129. package/src/document/interfaces/document.repository.interface.ts +1 -1
  130. package/src/enum/doc-type.enum.ts +2 -1
  131. package/src/enum/document-status.enum.ts +3 -2
  132. package/src/finance-company/finance-company.repository.ts +2 -3
  133. package/src/finance-company/finance-company.ts +69 -31
  134. package/src/index.ts +22 -9
  135. package/src/interfaces/account-system.interface.ts +10 -4
  136. package/src/journal-entry/journal-entry.repository.ts +1 -1
  137. package/src/journal-entry/journal-entry.ts +4 -4
  138. package/src/ledger-transaction/ledger-transaction.repository.ts +1 -1
  139. package/src/{account/entities → models}/account.entity.ts +5 -5
  140. package/src/{customer/entities → models}/customer.entity.ts +2 -2
  141. package/src/{document/entities → models}/document-item.entity.ts +5 -5
  142. package/src/models/document.entity.ts +193 -0
  143. package/src/{finance-company → models}/finance-company.entity.ts +2 -2
  144. package/src/{journal-entry/entities → models}/journal-entry.entity.ts +3 -3
  145. package/src/{ledger-transaction/entities → models}/ledger-transaction.entity.ts +3 -3
  146. package/src/{payment/entities → models}/payment-item.entity.ts +2 -2
  147. package/src/{payment/entities → models}/payment.entity.ts +4 -4
  148. package/src/{account-system-entity → models}/post-history.entity.ts +1 -1
  149. package/src/payment/interfaces/payment-item.repository.interface.ts +1 -1
  150. package/src/payment/interfaces/payment.repository.interface.ts +1 -1
  151. package/src/payment/payment-item.repository.ts +1 -1
  152. package/src/payment/payment.repository.ts +1 -1
  153. package/src/payment/payment.ts +7 -6
  154. package/tsconfig.json +1 -9
  155. package/src/account/index.ts +0 -17
  156. package/src/account-system-entity/index.ts +0 -3
  157. package/src/customer/index.ts +0 -15
  158. package/src/document/entities/document.entity.ts +0 -106
  159. package/src/document/index.ts +0 -23
  160. package/src/finance-company/index.ts +0 -4
  161. package/src/journal-entry/index.ts +0 -13
  162. package/src/ledger-transaction/index.ts +0 -13
  163. package/src/payment/index.ts +0 -21
@@ -1,49 +1,155 @@
1
1
  import * as util from 'util';
2
2
  import * as fs from 'fs';
3
- import { IBaseRepository } from '@tomei/general';
3
+ import puppeteer from 'puppeteer';
4
+ import { IBaseRepository, RecordNotFoundError } from '@tomei/general';
4
5
  import {
5
6
  Medias,
6
7
  InternalMediaDto,
7
8
  IMediasRepository,
8
9
  CommonService as MediaCommonService,
9
10
  MediaType,
11
+ MediasModel,
10
12
  } from '@tomei/media';
11
13
  import { DocumentStatus, DocType } from '../enum';
12
- import { DocumentRepository } from './document.repository';
13
14
  import { IDocumentAttr } from './interfaces/document-attr.interface';
14
15
  import { DocumentItemRepository } from './document-item.repository';
15
16
  import { DocumentItem } from './document-item';
16
- import { AccountSystemEntity } from '../account-system-entity';
17
+ import { IDocumentRepository } from './interfaces/document.repository.interface';
18
+ import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
19
+ import DocumentModel from '../models/document.entity';
17
20
 
18
21
  export class Document extends AccountSystemEntity {
19
- protected BaseRepository: IBaseRepository;
20
- ObjectId: string;
21
- ObjectName: string;
22
- TableName: string;
23
22
  DocNo: string;
24
- DocType: DocType;
25
- DocDate: Date;
26
- SystemCode: string;
23
+ private _DocType: DocType;
24
+ private _DocDate: Date = new Date();
27
25
  Currency: string;
28
26
  Amount: number;
29
27
  Description: string;
30
28
  IssuedById: string;
31
29
  IssuedToId: string;
32
30
  IssuedToType: string;
33
- AccSystemCode: string;
31
+ CreatedById: string;
32
+ CreatedAt: Date;
33
+ UpdatedById?: string;
34
+ UpdatedAt?: Date;
34
35
  UseAccSystemDocYN: string;
35
- private DocHTMLFilePath: string;
36
- private DocPDFFilePath: string;
37
- private Status: DocumentStatus;
36
+
37
+ private _documentRepository: IBaseRepository<DocumentModel> =
38
+ new DocumentModel();
39
+ protected _BaseRepository: IBaseRepository;
40
+
41
+ _ObjectId: string;
42
+ _ObjectName: string;
43
+ _TableName: string;
44
+
45
+ private _DocHTMLFileMediaId: string;
46
+ private _DocPDFFileMediaId: string;
47
+ private _Status: DocumentStatus = DocumentStatus.UNPAID;
38
48
 
39
49
  private IsNewRecord = true;
40
50
  private _DocumentItems: any;
41
51
 
42
- documentRepository: DocumentRepository;
52
+ documentRepository: IDocumentRepository;
43
53
  documentItemRepository: DocumentItemRepository;
44
54
  mediaRepository: IMediasRepository;
45
55
  mediaCommonService: MediaCommonService;
46
56
 
57
+ public get DocType() {
58
+ return this._DocType;
59
+ }
60
+
61
+ private set DocType(docType: DocType) {
62
+ this._DocType = docType;
63
+ }
64
+
65
+ public get DocDate() {
66
+ return this._DocDate;
67
+ }
68
+
69
+ private set DocDate(date: Date) {
70
+ this._DocDate = date;
71
+ }
72
+
73
+ public get DocHTMLFileMediaId() {
74
+ return this._DocHTMLFileMediaId;
75
+ }
76
+
77
+ private set DocHTMLFileMediaId(mediaId: string) {
78
+ this._DocHTMLFileMediaId = mediaId;
79
+ }
80
+
81
+ public get DocPDFFileMediaId() {
82
+ return this._DocPDFFileMediaId;
83
+ }
84
+
85
+ private set DocPDFFileMediaId(mediaId: string) {
86
+ this._DocPDFFileMediaId = mediaId;
87
+ }
88
+
89
+ public get Status() {
90
+ return this._Status;
91
+ }
92
+
93
+ private set Status(status: DocumentStatus) {
94
+ this._Status = status;
95
+ }
96
+
97
+ /* AccountSystemEntity Implementation */
98
+ override get BaseRepository() {
99
+ return this._documentRepository;
100
+ }
101
+
102
+ /* ObjectBase Implementation */
103
+ override get ObjectId() {
104
+ return this.DocNo;
105
+ }
106
+
107
+ override get ObjectName() {
108
+ return this.DocNo;
109
+ }
110
+
111
+ override get TableName() {
112
+ return 'finance_Document';
113
+ }
114
+
115
+ constructor(dbTransaction: any);
116
+ constructor(dbTransaction: any, docNo?: string) {
117
+ super();
118
+ const documentData = this.BaseRepository.findOne({
119
+ where: {
120
+ DocNo: docNo,
121
+ },
122
+ transaction: dbTransaction,
123
+ });
124
+ if (documentData) {
125
+ this.IsNewRecord = false;
126
+ this.DocType = documentData.DocType;
127
+ this.DocDate = documentData.DocDate;
128
+ this.CompanyId = documentData.CompanyId;
129
+ this.Currency = documentData.Currency;
130
+ this.Amount = documentData.Amount;
131
+ this.Description = documentData.Description;
132
+ this.Status = documentData.Status;
133
+ this.IssuedById = documentData.IssuedById;
134
+ this.IssuedToId = documentData.IssuedToId;
135
+ this.IssuedToType = documentData.IssuedToType;
136
+ this.CreatedById = documentData.CreatedById;
137
+ this.CreatedAt = documentData.CreatedAt;
138
+ this.UpdatedById = documentData.UpdatedById;
139
+ this.UpdatedAt = documentData.UpdatedAt;
140
+ this.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
141
+ this.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
142
+ this.AccSystemRefId = documentData.AccSystemRefId;
143
+ this.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
144
+ this.PostedById = documentData.PostedById;
145
+ this.PostedDateTime = documentData.PostedDateTime;
146
+ this.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
147
+ } else {
148
+ const notFoundError = new RecordNotFoundError('No Record Found.');
149
+ throw notFoundError;
150
+ }
151
+ }
152
+
47
153
  public get DocumentItems() {
48
154
  // this._DocumentItems = new DocumentItem();
49
155
  if (this._DocumentItems === null) {
@@ -63,64 +169,124 @@ export class Document extends AccountSystemEntity {
63
169
  return this._DocumentItems;
64
170
  }
65
171
 
66
- public get InvoiceInHTML() {
67
- return (async () => {
68
- this.DocHTMLFilePath = './invoice-template/index.html';
69
- const readFileContent = util.promisify(fs.readFile);
70
- const htmlBuffer = await readFileContent(this.DocHTMLFilePath);
71
-
72
- const htmlStream: Express.Multer.File = {
73
- buffer: htmlBuffer,
74
- fieldname: 'FileStream',
75
- originalname: 'index.html',
76
- mimetype: 'text/html',
77
- size: htmlBuffer.length,
78
- encoding: '8bit',
79
- filename: 'sample-invoice.html',
80
- destination: '',
81
- path: '',
82
- stream: null,
83
- };
84
-
85
- return htmlStream;
86
- })();
172
+ /**
173
+ * Returns HTML template file for invoice generation
174
+ *
175
+ * @see generateInvoice - for implementation
176
+ *
177
+ * @returns {Express.Multer.File} - HTML File
178
+ */
179
+ public static async DEFAULT_INVOICE_TEMPLATE_HTML(): Promise<Express.Multer.File> {
180
+ /* getting invoice template in HTML format */
181
+ const HTMLTemplateFilePath = './invoice-template/index.html';
182
+ const readFileContent = util.promisify(fs.readFile);
183
+ const htmlBuffer = await readFileContent(HTMLTemplateFilePath);
184
+
185
+ const htmlStream: Express.Multer.File = {
186
+ buffer: htmlBuffer,
187
+ fieldname: 'FileStream',
188
+ originalname: 'index.html',
189
+ mimetype: 'text/html',
190
+ size: htmlBuffer.length,
191
+ encoding: '8bit',
192
+ filename: 'sample-invoice.html',
193
+ destination: '',
194
+ path: '',
195
+ stream: null,
196
+ };
197
+
198
+ return htmlStream;
87
199
  }
88
200
 
89
- public get InvoiceInPDF() {
201
+ /**
202
+ * Returns PDF template file for invoice generation
203
+ *
204
+ * @remarks - This function is converting generated HTML into PDF
205
+ *
206
+ * @see generateInvoice - for implementation
207
+ *
208
+ * @returns {Express.Multer.File} - PDF File
209
+ */
210
+ public static async DEFAULT_INVOICE_TEMPLATE_PDF(): Promise<Express.Multer.File> {
211
+ /* prepping HTML conversion by getting its URL and String */
212
+
213
+ /* todo: needs to generate HTML first before converting to PDF */
214
+ const HTMLTemplateFilePath = './invoice-template/index.html';
215
+ const readFileContent = util.promisify(fs.readFile);
216
+ const htmlString = await readFileContent(HTMLTemplateFilePath, 'utf8');
217
+
218
+ /* converting HTML to PDF */
219
+ const browser = await puppeteer.launch();
220
+ const page = await browser.newPage();
221
+
222
+ if (HTMLTemplateFilePath) {
223
+ await page.goto(HTMLTemplateFilePath, {
224
+ waitUntil: 'networkidle2',
225
+ });
226
+ } else if (htmlString) {
227
+ await page.setContent(htmlString);
228
+ } else {
229
+ await browser.close();
230
+ }
231
+
232
+ const pdfBuffer = await page.pdf({
233
+ format: 'a4',
234
+ printBackground: true,
235
+ margin: {
236
+ left: '0px',
237
+ top: '0px',
238
+ right: '0px',
239
+ bottom: '0px',
240
+ },
241
+ });
242
+
243
+ const pdfStream: Express.Multer.File = {
244
+ buffer: pdfBuffer,
245
+ fieldname: 'FileStream',
246
+ originalname: 'sample-invoice.pdf',
247
+ mimetype: 'application/pdf',
248
+ size: pdfBuffer.length,
249
+ encoding: '8bit',
250
+ filename: 'sample-invoice.pdf',
251
+ destination: '',
252
+ path: '',
253
+ stream: null,
254
+ };
255
+
256
+ return pdfStream;
257
+ }
258
+
259
+ /**
260
+ * Returns the media representing the document in HTML format
261
+ *
262
+ * @returns {MediasModel} - Invoice Media in HTML Format
263
+ */
264
+ public get DocumentFileInHTML(): Promise<MediasModel> {
90
265
  return (async () => {
91
- this.DocPDFFilePath = './invoice-template/sample-invoice.pdf';
92
- const readFileContent = util.promisify(fs.readFile);
93
- const pdfBuffer = await readFileContent(this.DocPDFFilePath);
94
-
95
- const pdfStream: Express.Multer.File = {
96
- buffer: pdfBuffer,
97
- fieldname: 'FileStream',
98
- originalname: 'sample-invoice.[df]',
99
- mimetype: 'application/pdf',
100
- size: pdfBuffer.length,
101
- encoding: '8bit',
102
- filename: 'sample-invoice.pdf',
103
- destination: '',
104
- path: '',
105
- stream: null,
106
- };
107
-
108
- return pdfStream;
266
+ const { HTMLMedia } = await this.generateInvoice();
267
+
268
+ return HTMLMedia;
109
269
  })();
110
270
  }
111
271
 
112
- get objectId(): string {
113
- return this.ObjectId;
114
- }
115
- get objectName(): string {
116
- return this.ObjectName;
272
+ /**
273
+ * Returns the media representing the document in PDF format
274
+ *
275
+ * @returns {MediasModel} - Invoice Media in PDF Format
276
+ */
277
+ public get DocumentFileInPDF(): Promise<MediasModel> {
278
+ return (async () => {
279
+ const { PDFMedia } = await this.generateInvoice();
280
+
281
+ return PDFMedia;
282
+ })();
117
283
  }
118
284
 
119
285
  init(params: IDocumentAttr) {
120
286
  this.DocNo = params.DocNo;
121
287
  this.DocType = params.DocType;
122
288
  this.DocDate = params.DocDate;
123
- this.SystemCode = params.SystemCode;
289
+ this.CompanyId = params.CompanyId;
124
290
  this.Currency = params.Currency;
125
291
  this.Amount = params.Amount;
126
292
  this.Description = params.Description;
@@ -128,50 +294,77 @@ export class Document extends AccountSystemEntity {
128
294
  this.IssuedById = params.IssuedById;
129
295
  this.IssuedToId = params.IssuedToId;
130
296
  this.IssuedToType = params.IssuedToType;
131
- this.AccSystemCode = params.AccSystemCode;
297
+ this.CreatedById = params.CreatedById;
298
+ this.CreatedAt = params.CreatedAt;
299
+ this.UpdatedById = params.UpdatedById;
300
+ this.UpdatedAt = params.UpdatedAt;
301
+ this.DocPDFFileMediaId = params.DocPDFFileMediaId;
302
+ this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
303
+ this.AccSystemRefId = params.AccSystemRefId;
132
304
  this.PostedToAccSystemYN = params.PostedToAccSystemYN;
305
+ this.PostedById = params.PostedById;
306
+ this.PostedDateTime = params.PostedDateTime;
133
307
  this.UseAccSystemDocYN = params.UseAccSystemDocYN;
134
- this.DocPDFFilePath = params.DocPDFFilePath;
135
- this.DocHTMLFilePath = params.DocHTMLFilePath;
136
308
  }
137
309
 
138
- async generateInvoice(userId?: string): Promise<void> {
310
+ /**
311
+ * Returns generated HTML & PDF Media
312
+ *
313
+ * @remarks - This function also create each media element in common_Media table
314
+ *
315
+ * @see DocumentFileInHTML - for implementation
316
+ * @see DocumentFileInPDF - for implementation
317
+ *
318
+ * @param userId - userId that trigger this function
319
+ * @returns {MediasModel} - HTML & PDF Media
320
+ */
321
+ async generateInvoice(userId?: string): Promise<{
322
+ HTMLMedia: MediasModel;
323
+ PDFMedia: MediasModel;
324
+ }> {
139
325
  const media: Medias = new Medias(
140
326
  this.mediaRepository,
141
327
  this.mediaCommonService,
142
328
  );
143
329
 
330
+ /* todo: needs to manipulate HTML DOM before uploading to media*/
331
+
332
+ /* insert FileStream on htmlPayload */
144
333
  const htmlPayload: InternalMediaDto = {
145
334
  ObjectId: this.DocNo,
146
335
  ObjectType: this.DocType,
147
336
  Type: MediaType.Document,
148
337
  FileName: `${this.DocType}-${this.DocNo}`,
149
- FileStream: '',
150
- FileExtension: 'HTML',
338
+ FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
339
+ FileExtension: 'html',
151
340
  Title: `${this.DocType}-${this.DocNo}.html`,
152
341
  Description: `HTML ${this.DocType}`,
153
342
  IsEncryptedYN: 'N',
154
343
  };
155
- await media.postInternal(
156
- await this.InvoiceInHTML,
344
+
345
+ /* create HTML media of the generated HTML */
346
+ const HTMLInvoiceMedia = await media.postInternal(
347
+ await Document.DEFAULT_INVOICE_TEMPLATE_HTML(),
157
348
  htmlPayload,
158
349
  userId ?? 'System',
159
350
  );
160
351
 
352
+ /* insert FileStream on pdfPayload */
161
353
  const pdfPayload: InternalMediaDto = {
162
354
  ObjectId: this.DocNo,
163
355
  ObjectType: this.DocType,
164
356
  Type: MediaType.Document,
165
357
  FileName: `${this.DocType}-${this.DocNo}`,
166
- FileStream: '',
167
- FileExtension: 'PDF',
358
+ FileStream: await Document.DEFAULT_INVOICE_TEMPLATE_PDF(),
359
+ FileExtension: 'pdf',
168
360
  Title: `${this.DocType}-${this.DocNo}.pdf`,
169
361
  Description: `PDF ${this.DocType}`,
170
362
  IsEncryptedYN: 'N',
171
363
  };
172
364
 
173
- await media.postInternal(
174
- await this.InvoiceInPDF,
365
+ /* create PDF media from the converted HTML */
366
+ const PDFInvoiceMedia = await media.postInternal(
367
+ await Document.DEFAULT_INVOICE_TEMPLATE_PDF(),
175
368
  pdfPayload,
176
369
  userId ?? 'System',
177
370
  );
@@ -183,15 +376,27 @@ export class Document extends AccountSystemEntity {
183
376
  },
184
377
  });
185
378
 
186
- document.DocHTMLFilePath = this.DocHTMLFilePath;
187
- document.DocPDFFilePath = this.DocPDFFilePath;
379
+ /* storing HTML & PDF MediaId to finance_Document */
380
+ document.DocHTMLFileMediaId = HTMLInvoiceMedia.MediaId;
381
+ document.DocPDFFileMediaId = PDFInvoiceMedia.MediaId;
188
382
  await document.save();
189
383
  } catch (err) {
384
+ // tslint:disable-next-line:no-console
190
385
  console.log(err);
191
386
  }
387
+
388
+ return {
389
+ HTMLMedia: HTMLInvoiceMedia,
390
+ PDFMedia: PDFInvoiceMedia,
391
+ };
192
392
  }
193
393
 
194
- async newDocumentItem() {
394
+ /**
395
+ * Create a new Document Item which is automatically added to the DocumentItems list
396
+ *
397
+ * @returns {DocumentItem}
398
+ */
399
+ async newDocumentItem(): Promise<DocumentItem> {
195
400
  const documentItem = new DocumentItem();
196
401
  documentItem.DocNo = this.DocNo;
197
402
  this.DocumentItems.push(documentItem);
@@ -4,7 +4,7 @@ export class IDocumentAttr {
4
4
  DocNo: string;
5
5
  DocType: DocType;
6
6
  DocDate: Date;
7
- SystemCode: string;
7
+ CompanyId: string;
8
8
  Currency: string;
9
9
  Amount: number;
10
10
  Description: string;
@@ -12,9 +12,15 @@ export class IDocumentAttr {
12
12
  IssuedById: string;
13
13
  IssuedToId: string;
14
14
  IssuedToType: string;
15
- AccSystemCode: string;
15
+ CreatedById: string;
16
+ CreatedAt: Date;
17
+ UpdatedById?: string;
18
+ UpdatedAt?: Date;
19
+ DocPDFFileMediaId?: string;
20
+ DocHTMLFileMediaId?: string;
21
+ AccSystemRefId?: string;
16
22
  PostedToAccSystemYN: string;
23
+ PostedById?: string;
24
+ PostedDateTime?: Date;
17
25
  UseAccSystemDocYN: string;
18
- DocPDFFilePath: string;
19
- DocHTMLFilePath: string;
20
26
  }
@@ -17,6 +17,6 @@ export class IDocumentItemAttr {
17
17
  TaxAmount?: number;
18
18
  TaxRate?: number;
19
19
  TaxInclusiveYN?: string;
20
- DtAccountNo: string;
21
- CtAccountNo: string;
20
+ DtAccountNo?: string;
21
+ CtAccountNo?: string;
22
22
  }
@@ -1,4 +1,4 @@
1
1
  import { IBaseRepository } from '@tomei/general';
2
- import { DocumentItemModel } from '../entities/document-item.entity';
2
+ import DocumentItemModel from '../../models/document-item.entity';
3
3
 
4
4
  export type IDocumentItemRepository = IBaseRepository<DocumentItemModel>;
@@ -1,4 +1,4 @@
1
1
  import { IBaseRepository } from '@tomei/general';
2
- import { DocumentModel } from '../entities/document.entity'
2
+ import DocumentModel from '../../models/document.entity';
3
3
 
4
4
  export type IDocumentRepository = IBaseRepository<DocumentModel>;
@@ -3,5 +3,6 @@ export enum DocType {
3
3
  DEBIT_NOTE = 'Debit Note',
4
4
  CREDIT_NOTE = 'Credit Note',
5
5
  QUOTATION = 'Quotation',
6
+ PURCHASEORDER = 'Purchase Order',
6
7
  RECEIPT = 'Receipt',
7
- }
8
+ }
@@ -1,4 +1,5 @@
1
1
  export enum DocumentStatus {
2
- ACTIVE = 'Active',
3
- CANCELED = 'Canceled',
2
+ UNPAID = 'Unpaid',
3
+ PAID = 'Paid',
4
+ CANCELLED = 'Cancelled',
4
5
  }
@@ -1,12 +1,11 @@
1
1
  import { BaseRepository, IBaseRepository } from '@tomei/general';
2
- import { FinanceCompanyModel } from './finance-company.entity';
2
+ import FinanceCompanyModel from '../models/finance-company.entity';
3
3
 
4
4
  export class FinanceCompanyRepository
5
5
  extends BaseRepository<FinanceCompanyModel>
6
6
  implements IBaseRepository<FinanceCompanyModel>
7
7
  {
8
8
  constructor() {
9
- const financeCompanyModel = new FinanceCompanyModel();
10
- super(financeCompanyModel);
9
+ super(FinanceCompanyModel);
11
10
  }
12
11
  }