@tomei/finance 0.3.36 → 0.3.37
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.
- package/dist/document/document-item.d.ts +17 -3
- package/dist/document/document-item.js +37 -3
- package/dist/document/document-item.js.map +1 -1
- package/dist/document/document.d.ts +5 -4
- package/dist/document/document.js +18 -10
- package/dist/document/document.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/document/document-item.ts +51 -3
- package/src/document/document.ts +24 -15
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import Document from './document';
|
|
2
|
+
import { ObjectBase } from '@tomei/general';
|
|
1
3
|
import { DocumentItemRepository } from './document-item.repository';
|
|
2
4
|
|
|
3
|
-
export default class DocumentItem {
|
|
5
|
+
export default class DocumentItem extends ObjectBase {
|
|
4
6
|
DocumentItemId = 'New';
|
|
5
7
|
DocNo = '';
|
|
6
8
|
Name = '';
|
|
@@ -14,7 +16,7 @@ export default class DocumentItem {
|
|
|
14
16
|
UnitPrice = 0;
|
|
15
17
|
Quantity = 0;
|
|
16
18
|
QuantityUOM = 'Pieces';
|
|
17
|
-
|
|
19
|
+
private _Amount = 0;
|
|
18
20
|
TaxCode = '';
|
|
19
21
|
TaxAmount = 0;
|
|
20
22
|
TaxRate = 0;
|
|
@@ -22,5 +24,51 @@ export default class DocumentItem {
|
|
|
22
24
|
DtAccountNo = '';
|
|
23
25
|
CtAccountNo = '';
|
|
24
26
|
|
|
25
|
-
|
|
27
|
+
private static _RepositoryBase = new DocumentItemRepository();
|
|
28
|
+
|
|
29
|
+
private _DbTransaction: any;
|
|
30
|
+
private _Document: Document;
|
|
31
|
+
|
|
32
|
+
/* ObjectBase Implementation */
|
|
33
|
+
get ObjectId() {
|
|
34
|
+
return this.ItemId;
|
|
35
|
+
}
|
|
36
|
+
get ObjectName() {
|
|
37
|
+
return this.Name;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get TableName() {
|
|
41
|
+
return 'finance_DocumentItem';
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get Document() {
|
|
45
|
+
return this._Document;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
set Document(document: Document) {
|
|
49
|
+
this._Document = document;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
get DbTransaction() {
|
|
53
|
+
return this._DbTransaction;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
set DbTransaction(dbTransaction: any) {
|
|
57
|
+
this._DbTransaction = dbTransaction;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get Amount() {
|
|
61
|
+
return this._Amount;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
set Amount(amount: number) {
|
|
65
|
+
this._Amount = amount;
|
|
66
|
+
this._Document.reCalculateAmount();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
constructor(dbTransaction: any, document: Document) {
|
|
70
|
+
super();
|
|
71
|
+
this._DbTransaction = dbTransaction;
|
|
72
|
+
this._Document = document;
|
|
73
|
+
}
|
|
26
74
|
}
|
package/src/document/document.ts
CHANGED
|
@@ -28,11 +28,11 @@ const getConfig = require('../config');
|
|
|
28
28
|
const config = getConfig();
|
|
29
29
|
|
|
30
30
|
export default class Document extends AccountSystemEntity {
|
|
31
|
-
|
|
31
|
+
DocNo = 'New';
|
|
32
32
|
private _DocType: DocType;
|
|
33
33
|
private _DocDate = new Date();
|
|
34
34
|
Currency = 'MYR';
|
|
35
|
-
|
|
35
|
+
private _Amount = 0;
|
|
36
36
|
Description = '';
|
|
37
37
|
private _Status = DocumentStatus.UNPAID;
|
|
38
38
|
IssuedById = '';
|
|
@@ -67,14 +67,6 @@ export default class Document extends AccountSystemEntity {
|
|
|
67
67
|
this._IsNewRecord = record;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
public get DocNo() {
|
|
71
|
-
return this._DocNo;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
public set DocNo(id: string) {
|
|
75
|
-
this._DocNo = id;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
70
|
public get DocType() {
|
|
79
71
|
return this._DocType;
|
|
80
72
|
}
|
|
@@ -107,6 +99,14 @@ export default class Document extends AccountSystemEntity {
|
|
|
107
99
|
this._DocPDFFileMediaId = mediaId;
|
|
108
100
|
}
|
|
109
101
|
|
|
102
|
+
public get Amount() {
|
|
103
|
+
return this._Amount;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
private set Amount(amount: number) {
|
|
107
|
+
this._Amount = amount;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
110
|
public get Status() {
|
|
111
111
|
return this._Status;
|
|
112
112
|
}
|
|
@@ -182,6 +182,18 @@ export default class Document extends AccountSystemEntity {
|
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
/**
|
|
186
|
+
* Recalculate the Amount of the Document based on all the amount of the Document Items
|
|
187
|
+
*
|
|
188
|
+
* @returns {void}
|
|
189
|
+
*/
|
|
190
|
+
async reCalculateAmount(): Promise<void> {
|
|
191
|
+
this.Amount = 0;
|
|
192
|
+
for (const documentItem of this._DocumentItems) {
|
|
193
|
+
this.Amount += documentItem.Amount;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
185
197
|
get DocumentItems(): Promise<DocumentItem[]> {
|
|
186
198
|
return new Promise((resolve, reject) => {
|
|
187
199
|
if (!this.IsNewRecord) {
|
|
@@ -194,10 +206,7 @@ export default class Document extends AccountSystemEntity {
|
|
|
194
206
|
})
|
|
195
207
|
.then((documentItems) => {
|
|
196
208
|
const documentItemObjects = documentItems.map((documentItem) => {
|
|
197
|
-
new DocumentItem(
|
|
198
|
-
this._DbTransaction,
|
|
199
|
-
documentItem.DocumentItemId,
|
|
200
|
-
);
|
|
209
|
+
new DocumentItem(this._DbTransaction, this);
|
|
201
210
|
});
|
|
202
211
|
return Promise.all(documentItemObjects);
|
|
203
212
|
})
|
|
@@ -471,7 +480,7 @@ export default class Document extends AccountSystemEntity {
|
|
|
471
480
|
* @returns {DocumentItem}
|
|
472
481
|
*/
|
|
473
482
|
async newDocumentItem(documentItem?: any): Promise<DocumentItem> {
|
|
474
|
-
const di = new DocumentItem();
|
|
483
|
+
const di = new DocumentItem(this._DbTransaction, this);
|
|
475
484
|
di.DocNo = this.DocNo;
|
|
476
485
|
this._DocumentItems.push(documentItem);
|
|
477
486
|
return documentItem;
|