@tomei/finance 0.6.4 → 0.6.5
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 +3 -1
- package/dist/document/document-item.js +58 -21
- package/dist/document/document-item.js.map +1 -1
- package/dist/document/document.d.ts +2 -2
- package/dist/document/document.js +76 -80
- 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 +57 -21
- package/src/document/document.ts +81 -84
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import Document from './document';
|
|
2
2
|
import { ObjectBase } from '@tomei/general';
|
|
3
3
|
import { DocumentItemRepository } from './document-item.repository';
|
|
4
|
+
import { ClassError } from '@tomei/general';
|
|
5
|
+
import { IDocumentItemAttr } from './interfaces/document-item-attr.interface';
|
|
4
6
|
|
|
5
7
|
export default class DocumentItem extends ObjectBase {
|
|
6
8
|
DocumentItemId = 'New';
|
|
@@ -72,26 +74,60 @@ export default class DocumentItem extends ObjectBase {
|
|
|
72
74
|
this._Document = document;
|
|
73
75
|
}
|
|
74
76
|
|
|
75
|
-
init(
|
|
76
|
-
this.DocumentItemId =
|
|
77
|
-
this.DocNo =
|
|
78
|
-
this.Name =
|
|
79
|
-
this.NameBM =
|
|
80
|
-
this.Description =
|
|
81
|
-
this.ItemId =
|
|
82
|
-
this.ItemType =
|
|
83
|
-
this.ItemSKU =
|
|
84
|
-
this.ItemSerialNo =
|
|
85
|
-
this.Currency =
|
|
86
|
-
this.UnitPrice =
|
|
87
|
-
this.Quantity =
|
|
88
|
-
this.QuantityUOM =
|
|
89
|
-
this._Amount =
|
|
90
|
-
this.TaxCode =
|
|
91
|
-
this.TaxAmount =
|
|
92
|
-
this.TaxRate =
|
|
93
|
-
this.TaxInclusiveYN =
|
|
94
|
-
this.DtAccountNo =
|
|
95
|
-
this.CtAccountNo =
|
|
77
|
+
init(params: IDocumentItemAttr) {
|
|
78
|
+
this.DocumentItemId = params.DocumentItemId || this.DocumentItemId;
|
|
79
|
+
this.DocNo = params.DocNo || this.DocNo;
|
|
80
|
+
this.Name = params.Name || this.Name;
|
|
81
|
+
this.NameBM = params.NameBM || this.NameBM;
|
|
82
|
+
this.Description = params.Description || this.Description;
|
|
83
|
+
this.ItemId = params.ItemId || this.ItemId;
|
|
84
|
+
this.ItemType = params.ItemType || this.ItemType;
|
|
85
|
+
this.ItemSKU = params.ItemSKU || this.ItemSKU;
|
|
86
|
+
this.ItemSerialNo = params.ItemSerialNo || this.ItemSerialNo;
|
|
87
|
+
this.Currency = params.Currency || this.Currency;
|
|
88
|
+
this.UnitPrice = params.UnitPrice || this.UnitPrice;
|
|
89
|
+
this.Quantity = params.Quantity || this.Quantity;
|
|
90
|
+
this.QuantityUOM = params.QuantityUOM || this.QuantityUOM;
|
|
91
|
+
this._Amount = params.Amount || this._Amount;
|
|
92
|
+
this.TaxCode = params.TaxCode || this.TaxCode;
|
|
93
|
+
this.TaxAmount = params.TaxAmount || this.TaxAmount;
|
|
94
|
+
this.TaxRate = params.TaxRate || this.TaxRate;
|
|
95
|
+
this.TaxInclusiveYN = params.TaxInclusiveYN || this.TaxInclusiveYN;
|
|
96
|
+
this.DtAccountNo = params.DtAccountNo || this.DtAccountNo;
|
|
97
|
+
this.CtAccountNo = params.CtAccountNo || this.CtAccountNo;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public static async initDocumentItems(
|
|
101
|
+
dbTransaction: any,
|
|
102
|
+
document: Document,
|
|
103
|
+
) {
|
|
104
|
+
try {
|
|
105
|
+
const documentItems = await this._RepositoryBase.findAll({
|
|
106
|
+
where: {
|
|
107
|
+
DocNo: document.DocNo,
|
|
108
|
+
},
|
|
109
|
+
transaction: dbTransaction,
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (documentItems) {
|
|
113
|
+
const documentItemObjects = documentItems.map((documentItem) => {
|
|
114
|
+
const di = new DocumentItem(dbTransaction, document);
|
|
115
|
+
di.init({ ...documentItem.get({ plain: true }) });
|
|
116
|
+
return di;
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
return documentItemObjects;
|
|
120
|
+
} else {
|
|
121
|
+
const notFoundError = new ClassError(
|
|
122
|
+
'Document',
|
|
123
|
+
'InitDocumentItemErrMsg00',
|
|
124
|
+
`No Document Item record found.`,
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
throw notFoundError;
|
|
128
|
+
}
|
|
129
|
+
} catch (error) {
|
|
130
|
+
throw error;
|
|
131
|
+
}
|
|
96
132
|
}
|
|
97
133
|
}
|
package/src/document/document.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as util from 'util';
|
|
2
|
+
import * as path from 'path';
|
|
2
3
|
import * as fs from 'fs';
|
|
3
4
|
import * as puppeteer from 'puppeteer';
|
|
4
5
|
import { RecordNotFoundError } from '@tomei/general/dist/class/exceptions/record-not-found.error';
|
|
@@ -19,7 +20,7 @@ import { AccountSystemEntity } from '../account-system-entity/account-system-ent
|
|
|
19
20
|
import { DocumentRepository } from './document.repository';
|
|
20
21
|
import FinanceCustomerBase from '../customer/customer';
|
|
21
22
|
import DocumentModel from '../models/document.entity';
|
|
22
|
-
import
|
|
23
|
+
import DocumentItemModel from '../models/document-item.entity';
|
|
23
24
|
import { ClassError, LoginUserBase } from '@tomei/general';
|
|
24
25
|
import { ApplicationConfig } from '@tomei/config';
|
|
25
26
|
import { Op } from 'sequelize';
|
|
@@ -145,7 +146,6 @@ export default class Document extends AccountSystemEntity {
|
|
|
145
146
|
})
|
|
146
147
|
.then((documentData) => {
|
|
147
148
|
if (documentData) {
|
|
148
|
-
this.IsNewRecord = false;
|
|
149
149
|
this.DocType = documentData.DocType;
|
|
150
150
|
this.DocDate = documentData.DocDate;
|
|
151
151
|
this.CompanyId = documentData.CompanyId;
|
|
@@ -185,47 +185,85 @@ export default class Document extends AccountSystemEntity {
|
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
init(params: IDocumentAttr) {
|
|
189
|
+
this.DocNo = params.DocNo;
|
|
190
|
+
this.DocType = params.DocType;
|
|
191
|
+
this.DocDate = params.DocDate;
|
|
192
|
+
this.CompanyId = params.CompanyId;
|
|
193
|
+
this.Currency = params.Currency;
|
|
194
|
+
this.Amount = params.Amount;
|
|
195
|
+
this.Description = params.Description;
|
|
196
|
+
this.Status = params.Status;
|
|
197
|
+
this.IssuedById = params.IssuedById;
|
|
198
|
+
this.IssuedToId = params.IssuedToId;
|
|
199
|
+
this.IssuedToType = params.IssuedToType;
|
|
200
|
+
this.RelatedObjectId = params.RelatedObjectId;
|
|
201
|
+
this.RelatedObjectType = params.RelatedObjectType;
|
|
202
|
+
this.CreatedById = params.CreatedById;
|
|
203
|
+
this.CreatedAt = params.CreatedAt;
|
|
204
|
+
this.UpdatedById = params.UpdatedById;
|
|
205
|
+
this.UpdatedAt = params.UpdatedAt;
|
|
206
|
+
this.DocPDFFileMediaId = params.DocPDFFileMediaId;
|
|
207
|
+
this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
|
|
208
|
+
this.AccSystemRefId = params.AccSystemRefId;
|
|
209
|
+
this.PostedToAccSystemYN = params.PostedToAccSystemYN;
|
|
210
|
+
this.PostedById = params.PostedById;
|
|
211
|
+
this.PostedDateTime = params.PostedDateTime;
|
|
212
|
+
this.UseAccSystemDocYN = params.UseAccSystemDocYN;
|
|
213
|
+
}
|
|
214
|
+
|
|
188
215
|
public static async initDocument(dbTransaction: any, docNo: string) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
216
|
+
try {
|
|
217
|
+
const document = new Document(dbTransaction);
|
|
218
|
+
const documentData = await this._RepositoryBase.findOne({
|
|
219
|
+
where: {
|
|
220
|
+
DocNo: docNo,
|
|
221
|
+
},
|
|
222
|
+
include: [
|
|
223
|
+
{
|
|
224
|
+
model: DocumentItemModel,
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
});
|
|
228
|
+
if (documentData) {
|
|
229
|
+
document.DocNo = documentData.DocNo;
|
|
230
|
+
document.DocType = documentData.DocType;
|
|
231
|
+
document.DocDate = documentData.DocDate;
|
|
232
|
+
document.CompanyId = documentData.CompanyId;
|
|
233
|
+
document.Currency = documentData.Currency;
|
|
234
|
+
document.Amount = documentData.Amount;
|
|
235
|
+
document.Description = documentData.Description;
|
|
236
|
+
document.Status = documentData.Status;
|
|
237
|
+
document.IssuedById = documentData.IssuedById;
|
|
238
|
+
document.IssuedToId = documentData.IssuedToId;
|
|
239
|
+
document.IssuedToType = documentData.IssuedToType;
|
|
240
|
+
document.RelatedObjectId = documentData.RelatedObjectId;
|
|
241
|
+
document.RelatedObjectType = documentData.RelatedObjectType;
|
|
242
|
+
document.CreatedById = documentData.CreatedById;
|
|
243
|
+
document.CreatedAt = documentData.CreatedAt;
|
|
244
|
+
document.UpdatedById = documentData.UpdatedById;
|
|
245
|
+
document.UpdatedAt = documentData.UpdatedAt;
|
|
246
|
+
document.DocPDFFileMediaId = documentData.DocPDFFileMediaId;
|
|
247
|
+
document.DocHTMLFileMediaId = documentData.DocHTMLFileMediaId;
|
|
248
|
+
document.AccSystemRefId = documentData.AccSystemRefId;
|
|
249
|
+
document.PostedToAccSystemYN = documentData.PostedToAccSystemYN;
|
|
250
|
+
document.PostedById = documentData.PostedById;
|
|
251
|
+
document.PostedDateTime = documentData.PostedDateTime;
|
|
252
|
+
document.UseAccSystemDocYN = documentData.UseAccSystemDocYN;
|
|
253
|
+
document.IsNewRecord = false;
|
|
254
|
+
} else {
|
|
255
|
+
const notFoundError = new ClassError(
|
|
256
|
+
'Document',
|
|
257
|
+
'InitDocumentErrMsg00',
|
|
258
|
+
`No Document record found.`,
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
throw notFoundError;
|
|
262
|
+
}
|
|
263
|
+
return documentData;
|
|
264
|
+
} catch (error) {
|
|
265
|
+
throw error;
|
|
227
266
|
}
|
|
228
|
-
return document;
|
|
229
267
|
}
|
|
230
268
|
|
|
231
269
|
/**
|
|
@@ -243,23 +281,9 @@ export default class Document extends AccountSystemEntity {
|
|
|
243
281
|
get DocumentItems(): Promise<DocumentItem[]> {
|
|
244
282
|
return new Promise((resolve, reject) => {
|
|
245
283
|
if (!this.IsNewRecord) {
|
|
246
|
-
|
|
247
|
-
.findAll({
|
|
248
|
-
where: {
|
|
249
|
-
DocNo: this.DocNo,
|
|
250
|
-
},
|
|
251
|
-
transaction: this._DbTransaction,
|
|
252
|
-
})
|
|
284
|
+
DocumentItem.initDocumentItems(this._DbTransaction, this)
|
|
253
285
|
.then((documentItems) => {
|
|
254
|
-
|
|
255
|
-
const di = new DocumentItem(this._DbTransaction, this);
|
|
256
|
-
di.init({ ...documentItem.get({ plain: true }) });
|
|
257
|
-
});
|
|
258
|
-
return Promise.all(documentItemObjects);
|
|
259
|
-
})
|
|
260
|
-
.then((documentItemObjects) => {
|
|
261
|
-
this._DocumentItems = documentItemObjects;
|
|
262
|
-
resolve(this._DocumentItems);
|
|
286
|
+
return Promise.all(documentItems);
|
|
263
287
|
})
|
|
264
288
|
.catch((err) => {
|
|
265
289
|
reject(err);
|
|
@@ -787,33 +811,6 @@ export default class Document extends AccountSystemEntity {
|
|
|
787
811
|
})();
|
|
788
812
|
}
|
|
789
813
|
|
|
790
|
-
init(params: IDocumentAttr) {
|
|
791
|
-
this.DocNo = params.DocNo;
|
|
792
|
-
this.DocType = params.DocType;
|
|
793
|
-
this.DocDate = params.DocDate;
|
|
794
|
-
this.CompanyId = params.CompanyId;
|
|
795
|
-
this.Currency = params.Currency;
|
|
796
|
-
this.Amount = params.Amount;
|
|
797
|
-
this.Description = params.Description;
|
|
798
|
-
this.Status = params.Status;
|
|
799
|
-
this.IssuedById = params.IssuedById;
|
|
800
|
-
this.IssuedToId = params.IssuedToId;
|
|
801
|
-
this.IssuedToType = params.IssuedToType;
|
|
802
|
-
this.RelatedObjectId = params.RelatedObjectId;
|
|
803
|
-
this.RelatedObjectType = params.RelatedObjectType;
|
|
804
|
-
this.CreatedById = params.CreatedById;
|
|
805
|
-
this.CreatedAt = params.CreatedAt;
|
|
806
|
-
this.UpdatedById = params.UpdatedById;
|
|
807
|
-
this.UpdatedAt = params.UpdatedAt;
|
|
808
|
-
this.DocPDFFileMediaId = params.DocPDFFileMediaId;
|
|
809
|
-
this.DocHTMLFileMediaId = params.DocHTMLFileMediaId;
|
|
810
|
-
this.AccSystemRefId = params.AccSystemRefId;
|
|
811
|
-
this.PostedToAccSystemYN = params.PostedToAccSystemYN;
|
|
812
|
-
this.PostedById = params.PostedById;
|
|
813
|
-
this.PostedDateTime = params.PostedDateTime;
|
|
814
|
-
this.UseAccSystemDocYN = params.UseAccSystemDocYN;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
814
|
/**
|
|
818
815
|
* Returns generated HTML & PDF Invoice Media
|
|
819
816
|
*
|