@tomei/finance
Version:
NestJS package for finance module
144 lines • 5.64 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const transaction_type_enum_1 = require("../enum/transaction-type.enum");
const ledger_transaction_repository_1 = require("./ledger-transaction.repository");
const general_1 = require("@tomei/general");
class LedgerTransaction extends general_1.ObjectBase {
get LedgerNo() {
return this.ObjectId;
}
set LedgerNo(id) {
this.ObjectId = id;
}
constructor(transactionType, dbTransaction, LedgerNo) {
super();
this.ObjectType = 'LedgerTransaction';
this.ObjectId = 'New';
this.TransactionType = transaction_type_enum_1.TransactionTypeOptions.DEBIT;
this.JournalEntryId = '';
this.AccountNo = '';
this.Date = new Date();
this.Name = '';
this.Description = '';
this.Currency = 'MYR';
this.DebitAmount = 0;
this.CreditAmount = 0;
this.RelatedObjectId = '';
this.RelatedObjectType = '';
this.RelatedDocNo = '';
this.RelatedPaymentId = '';
this.TransactionType = transactionType;
if (dbTransaction) {
this._DbTransaction = dbTransaction;
}
if (LedgerNo) {
this.LedgerNo = LedgerNo;
}
}
init(params) {
if (params.LedgerNo)
this.LedgerNo = params.LedgerNo;
if (params.TransactionType)
this.TransactionType = params.TransactionType;
if (params.JournalEntryId)
this.JournalEntryId = params.JournalEntryId;
if (params.AccountNo)
this.AccountNo = params.AccountNo;
if (params.Date)
this.Date = params.Date;
if (params.Description)
this.Description = params.Description;
if (params.Currency)
this.Currency = params.Currency;
if (params.DebitAmount)
this.DebitAmount = params.DebitAmount;
if (params.CreditAmount)
this.CreditAmount = params.CreditAmount;
if (params.RelatedObjectId)
this.RelatedObjectId = params.RelatedObjectId;
if (params.RelatedObjectType)
this.RelatedObjectType = params.RelatedObjectType;
if (params.Name)
this.Name = params.Name;
}
getData() {
return {
LedgerNo: this.LedgerNo,
TransactionType: this.TransactionType,
JournalEntryId: this.JournalEntryId,
AccountNo: this.AccountNo,
Date: this.Date,
Name: this.Name,
Description: this.Description,
Currency: this.Currency,
DebitAmount: this.DebitAmount,
CreditAmount: this.CreditAmount,
RelatedObjectId: this.RelatedObjectId,
RelatedObjectType: this.RelatedObjectType,
RelatedDocNo: this.RelatedDocNo,
RelatedPaymentId: this.RelatedPaymentId,
};
}
async save(dbTransaction) {
try {
const count = await LedgerTransaction._LedgerTransactionRepository.count(dbTransaction);
this.LedgerNo = `${count + 1}`;
return await LedgerTransaction._LedgerTransactionRepository.create({
LedgerNo: this.LedgerNo,
TransactionType: this.TransactionType,
JournalEntryId: this.JournalEntryId,
AccountNo: this.AccountNo,
Date: this.Date,
Name: this.Name,
Description: this.Description,
Currency: this.Currency,
DebitAmount: this.DebitAmount,
CreditAmount: this.CreditAmount,
RelatedObjectId: this.RelatedObjectId || undefined,
RelatedObjectType: this.RelatedObjectType || undefined,
RelatedDocNo: this.RelatedDocNo || undefined,
RelatedPaymentId: this.RelatedPaymentId || undefined,
}, { transaction: dbTransaction });
}
catch (error) {
throw error;
}
}
async create() {
return await LedgerTransaction._LedgerTransactionRepository.create(this.getData, { transaction: this._DbTransaction });
}
async findAll(options) {
return await LedgerTransaction._LedgerTransactionRepository.findAll(options);
}
async findAllWithPagination(options) {
return await LedgerTransaction._LedgerTransactionRepository.findAllWithPagination(options);
}
async accountTransactionHistory(accountNo) {
return await this.findAll({
where: {
AccountNo: accountNo,
},
order: [['Date', 'DESC']],
});
}
async newLedgerTransaction(transactionType, journalEntryId) {
this.init({
LedgerNo: this.createId(),
TransactionType: transactionType,
JournalEntryId: journalEntryId,
});
if (transactionType === transaction_type_enum_1.TransactionTypeOptions.DEBIT) {
this.TransactionType = transaction_type_enum_1.TransactionTypeOptions.DEBIT;
}
else if (transactionType === transaction_type_enum_1.TransactionTypeOptions.CREDIT) {
this.TransactionType = transaction_type_enum_1.TransactionTypeOptions.CREDIT;
}
if (journalEntryId) {
this.JournalEntryId = journalEntryId;
}
return await this.create();
}
}
LedgerTransaction._LedgerTransactionRepository = new ledger_transaction_repository_1.LedgerTransactionRepository();
exports.default = LedgerTransaction;
//# sourceMappingURL=ledger-transaction.js.map