@tomei/finance
Version:
NestJS package for finance module
190 lines • 8.2 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const record_not_found_error_1 = require("@tomei/general/dist/class/exceptions/record-not-found.error");
const account_system_entity_1 = require("../account-system-entity/account-system-entity");
const payment_repository_1 = require("./payment.repository");
const payment_item_repository_1 = require("../payment-item/payment-item.repository");
const payment_item_1 = __importDefault(require("../payment-item/payment-item"));
const payment_paid_with_1 = __importDefault(require("../payment-paid-with/payment-paid-with"));
const payment_paid_with_repository_1 = require("../payment-paid-with/payment-paid-with.repository");
class Payment extends account_system_entity_1.AccountSystemEntity {
get PaymentId() {
return this._PaymentId;
}
get ObjectType() {
return this._ObjectType;
}
set PaymentId(id) {
this._PaymentId = id;
}
get RepositoryBase() {
return Payment._RepositoryBase;
}
get ObjectId() {
return this.PaymentId;
}
get ObjectName() {
return this.PaymentId;
}
get TableName() {
return 'finance_Payment';
}
constructor(dbTransaction, paymentId) {
super();
this._PaymentId = 'New';
this.Description = '';
this.Currency = 'MYR';
this.Amount = 0;
this.ReceivedBy = '';
this.IssuedBy = '';
this.UpdatedBy = '';
this.Remarks = '';
this.RelatedObjectId = '';
this.RelatedObjectType = '';
this.ReceiptDocNo = '';
this._PaymentItems = [];
this._PaymentPaidWith = [];
if (dbTransaction) {
this._DbTransaction = dbTransaction;
}
if (paymentId) {
this.PaymentId = paymentId;
}
}
static async initPayment(dbTransaction, paymentId) {
try {
const paymentData = await this._RepositoryBase.findOne({
where: {
PaymentId: paymentId,
},
transaction: dbTransaction,
});
if (paymentData) {
const payment = new Payment(dbTransaction, paymentId);
payment.PaymentType = paymentData.PaymentType;
payment.PaymentDate = paymentData.PaymentDate;
payment.Description = paymentData.Description;
payment.Currency = paymentData.Currency;
payment.Amount = paymentData.Amount;
payment.Status = paymentData.Status;
payment.ReceivedBy = paymentData.ReceivedBy;
payment.IssuedBy = paymentData.IssuedBy;
payment.UpdatedAt = paymentData.UpdatedAt;
payment.UpdatedBy = paymentData.UpdatedBy;
payment.Remarks = paymentData.Remarks;
payment.RelatedObjectId = paymentData.RelatedObjectId;
payment.RelatedObjectType = paymentData.RelatedObjectType;
payment.ReceiptDocNo = paymentData.ReceiptDocNo;
payment.AccSystemRefId = paymentData.AccSystemRefId;
payment.PostedToAccSystemYN = paymentData.PostedToAccSystemYN;
payment.PostedById = paymentData.PostedById;
payment.PostedDateTime = paymentData.PostedDateTime;
return payment;
}
else {
const notFoundError = new record_not_found_error_1.RecordNotFoundError('PaymentErrMsg', 'No Record Found.');
throw notFoundError;
}
}
catch (error) {
console.log('Payment Class constructor err: ', error);
}
}
async getPaymentItems(dbTransaction) {
try {
if (this.PaymentId !== 'New') {
const paymentItems = await Payment._PaymentItemRepository.findAll({
where: {
PaymentId: this.PaymentId,
},
transaction: dbTransaction || this._DbTransaction,
});
const paymentItemObjects = paymentItems.map((paymentItem) => {
const pi = new payment_item_1.default(new Payment(this._DbTransaction, paymentItem.PaymentId), {
ObjectId: this.ObjectId,
ObjectName: this.ObjectName,
TableName: this.TableName,
ObjectType: this.ObjectType,
});
pi.PayForObjectType = paymentItem.PayForObjectType;
pi.PayForObjectId = paymentItem.PayForObjectId;
pi.Currency = paymentItem.Currency;
pi.Amount = paymentItem.Amount;
pi.Name = paymentItem.Name;
pi.Description = paymentItem.Description;
return pi;
});
this._PaymentItems = paymentItemObjects;
return this._PaymentItems;
}
else {
return this._PaymentItems;
}
}
catch (error) {
throw error;
}
}
async getPaymentPaidWith(dbTransaction) {
try {
if (this.PaymentId !== 'New') {
const paymentPaidWithItems = await Payment._PaymentPaidWithRepository.findAll({
where: {
PaymentId: this.PaymentId,
},
transaction: dbTransaction || this._DbTransaction,
});
const paymentPaidWithObjects = paymentPaidWithItems.map((paymentPaidWithItem) => {
const ppw = new payment_paid_with_1.default(new Payment(this._DbTransaction, paymentPaidWithItem.PaymentId), paymentPaidWithItem.MethodTypeId);
ppw.Currency = paymentPaidWithItem.Currency;
ppw.Amount = paymentPaidWithItem.Amount;
ppw.Status = paymentPaidWithItem.Status;
ppw.TransactionId = paymentPaidWithItem.TransactionId;
ppw.RefBank = paymentPaidWithItem.RefBank;
ppw.RefName = paymentPaidWithItem.RefName;
ppw.RefNo = paymentPaidWithItem.RefNo;
ppw.RefOther1 = paymentPaidWithItem.RefOther1;
ppw.RefOther2 = paymentPaidWithItem.RefOther2;
ppw.RefOther3 = paymentPaidWithItem.RefOther3;
ppw.RefOther4 = paymentPaidWithItem.RefOther4;
ppw.RefOther5 = paymentPaidWithItem.RefOther5;
ppw.Remarks = paymentPaidWithItem.Remarks;
ppw.PaymentMediaId = paymentPaidWithItem.PaymentMediaId;
return ppw;
});
this._PaymentPaidWith = paymentPaidWithObjects;
return this._PaymentPaidWith;
}
else {
return this._PaymentPaidWith;
}
}
catch (error) {
throw error;
}
}
newPaymentItem(objectBeingPaidFor) {
const paymentItem = new payment_item_1.default(this, objectBeingPaidFor);
this._PaymentItems.push(paymentItem);
return paymentItem;
}
newPaymentPaidWith(paymentMethodTypeId) {
const paymentPaidWith = new payment_paid_with_1.default(this, paymentMethodTypeId, this._DbTransaction);
this._PaymentPaidWith.push(paymentPaidWith);
return paymentPaidWith;
}
init(Params) {
if (Params.Currency)
this.Currency = Params.Currency;
if (Params.PaymentType)
this.PaymentType = Params.PaymentType;
}
}
Payment._RepositoryBase = new payment_repository_1.PaymentRepository();
Payment._PaymentItemRepository = new payment_item_repository_1.PaymentItemRepository();
Payment._PaymentPaidWithRepository = new payment_paid_with_repository_1.PaymentPaidWithRepository();
exports.default = Payment;
//# sourceMappingURL=payment.js.map