UNPKG

@tomei/finance

Version:

NestJS package for finance module

123 lines 4.55 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const general_1 = require("@tomei/general"); const document_item_repository_1 = require("./document-item.repository"); const general_2 = require("@tomei/general"); class DocumentItem extends general_1.ObjectBase { get ObjectType() { return this._ObjectType; } get ObjectId() { return this.ItemId; } get ObjectName() { return this.Name; } get TableName() { return 'finance_DocumentItem'; } get Document() { return this._Document; } set Document(document) { this._Document = document; } get DbTransaction() { return this._DbTransaction; } set DbTransaction(dbTransaction) { this._DbTransaction = dbTransaction; } get Amount() { return this._Amount; } set Amount(amount) { this._Amount = amount; this._Document.reCalculateAmount(); } constructor(dbTransaction, document) { super(); this.DocumentItemId = 'New'; this.DocNo = ''; this.Name = ''; this.NameBM = ''; this.Description = ''; this.ItemId = ''; this.ItemType = ''; this.ItemSKU = ''; this.ItemSerialNo = ''; this.Currency = 'MYR'; this.UnitPrice = 0; this.Quantity = 0; this.QuantityUOM = 'Pieces'; this._Amount = 0; this.TaxCode = ''; this.TaxAmount = 0; this.TaxRate = 0; this.TaxInclusiveYN = 'N'; this.DtAccountNo = ''; this.CtAccountNo = ''; this.AccSystemRefId = 'REF'; this.PostedToAccSystemYN = 'N'; this.PostedById = null; this.PostedDateTime = null; this._ObjectType = 'DocumentItem'; this._DbTransaction = dbTransaction; this._Document = document; } init(params) { this.DocumentItemId = params.DocumentItemId || this.DocumentItemId; this.DocNo = params.DocNo || this.DocNo; this.Name = params.Name || this.Name; this.NameBM = params.NameBM || this.NameBM; this.Description = params.Description || this.Description; this.ItemId = params.ItemId || this.ItemId; this.ItemType = params.ItemType || this.ItemType; this.ItemSKU = params.ItemSKU || this.ItemSKU; this.ItemSerialNo = params.ItemSerialNo || this.ItemSerialNo; this.Currency = params.Currency || this.Currency; this.UnitPrice = params.UnitPrice || this.UnitPrice; this.Quantity = params.Quantity || this.Quantity; this.QuantityUOM = params.QuantityUOM || this.QuantityUOM; this._Amount = params.Amount || this._Amount; this.TaxCode = params.TaxCode || this.TaxCode; this.TaxAmount = params.TaxAmount || this.TaxAmount; this.TaxRate = params.TaxRate || this.TaxRate; this.TaxInclusiveYN = params.TaxInclusiveYN || this.TaxInclusiveYN; this.DtAccountNo = params.DtAccountNo || this.DtAccountNo; this.CtAccountNo = params.CtAccountNo || this.CtAccountNo; this.AccSystemRefId = params.AccSystemRefId || this.AccSystemRefId; this.PostedToAccSystemYN = params.PostedToAccSystemYN || this.PostedToAccSystemYN; this.PostedById = params.PostedById || this.PostedById; this.PostedDateTime = params.PostedDateTime || this.PostedDateTime; } static async initDocumentItems(dbTransaction, document) { try { const documentItems = await this._RepositoryBase.findAll({ where: { DocNo: document.DocNo, }, transaction: dbTransaction, }); if (documentItems) { const documentItemObjects = documentItems.map((documentItem) => { const di = new DocumentItem(dbTransaction, document); di.init({ ...documentItem.get({ plain: true }) }); return di; }); return documentItemObjects; } else { const notFoundError = new general_2.ClassError('Document', 'InitDocumentItemErrMsg00', `No Document Item record found.`); throw notFoundError; } } catch (error) { throw error; } } } DocumentItem._RepositoryBase = new document_item_repository_1.DocumentItemRepository(); exports.default = DocumentItem; //# sourceMappingURL=document-item.js.map