@tomei/finance 0.3.85 → 0.3.86

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.
@@ -85,10 +85,10 @@ export default class LedgerTransaction {
85
85
  Currency: this.Currency,
86
86
  DebitAmount: this.DebitAmount,
87
87
  CreditAmount: this.CreditAmount,
88
- RelatedObjectId: this.RelatedObjectId,
89
- RelatedObjectType: this.RelatedObjectType,
90
- RelatedDocNo: this.RelatedDocNo,
91
- RelatedPaymentId: this.RelatedPaymentId,
88
+ RelatedObjectId: this.RelatedObjectId || undefined,
89
+ RelatedObjectType: this.RelatedObjectType || undefined,
90
+ RelatedDocNo: this.RelatedDocNo || undefined,
91
+ RelatedPaymentId: this.RelatedPaymentId || undefined,
92
92
  },
93
93
  { transaction: dbTransaction },
94
94
  );
@@ -65,59 +65,47 @@ export default class Payment extends AccountSystemEntity {
65
65
  this._DbTransaction = dbTransaction;
66
66
  }
67
67
  if (paymentId) {
68
- this.RepositoryBase.findOne({
68
+ this.PaymentId = paymentId;
69
+ }
70
+ }
71
+
72
+ static async initPayment(
73
+ dbTransaction: any,
74
+ paymentId: string,
75
+ ): Promise<Payment> {
76
+ try {
77
+ const paymentData = await this._RepositoryBase.findOne({
69
78
  where: {
70
79
  PaymentId: paymentId,
71
80
  },
72
81
  transaction: dbTransaction,
73
- })
74
- .then((paymentData) => {
75
- if (paymentData) {
76
- this.PaymentType = paymentData.PaymentType;
77
- this.PaymentDate = paymentData.PaymentDate;
78
- this.Description = paymentData.Description;
79
- this.Currency = paymentData.Currency;
80
- this.Amount = paymentData.Amount;
81
- this.Status = paymentData.Status;
82
- this.ReceivedBy = paymentData.ReceivedBy;
83
- this.UpdatedAt = paymentData.UpdatedAt;
84
- this.UpdatedBy = paymentData.UpdatedBy;
85
- this.Remarks = paymentData.Remarks;
86
- this.AccSystemRefId = paymentData.AccSystemRefId;
87
- this.PostedToAccSystemYN = paymentData.PostedToAccSystemYN;
88
- this.PostedById = paymentData.PostedById;
89
- this.PostedDateTime = paymentData.PostedDateTime;
90
- } else {
91
- const notFoundError = new RecordNotFoundError('No Record Found.');
92
- throw notFoundError;
93
- }
94
- })
95
- .catch((err) => {
96
- // tslint:disable-next-line:no-console
97
- console.log('Payment Class constructor err: ', err);
98
- });
82
+ });
83
+ if (paymentData) {
84
+ const payment = new Payment(dbTransaction, paymentId);
85
+ payment.PaymentType = paymentData.PaymentType;
86
+ payment.PaymentDate = paymentData.PaymentDate;
87
+ payment.Description = paymentData.Description;
88
+ payment.Currency = paymentData.Currency;
89
+ payment.Amount = paymentData.Amount;
90
+ payment.Status = paymentData.Status;
91
+ payment.ReceivedBy = paymentData.ReceivedBy;
92
+ payment.UpdatedAt = paymentData.UpdatedAt;
93
+ payment.UpdatedBy = paymentData.UpdatedBy;
94
+ payment.Remarks = paymentData.Remarks;
95
+ payment.AccSystemRefId = paymentData.AccSystemRefId;
96
+ payment.PostedToAccSystemYN = paymentData.PostedToAccSystemYN;
97
+ payment.PostedById = paymentData.PostedById;
98
+ payment.PostedDateTime = paymentData.PostedDateTime;
99
+ return payment;
100
+ } else {
101
+ const notFoundError = new RecordNotFoundError('No Record Found.');
102
+ throw notFoundError;
103
+ }
104
+ } catch (error) {
105
+ console.log('Payment Class constructor err: ', error);
99
106
  }
100
107
  }
101
108
 
102
- // public get PaymentItems() {
103
- // if (this._PaymentItems === null) {
104
- // this._PaymentItems = new Array<PaymentItemModel>();
105
- // if (this.PaymentId !== 'New') {
106
- // this.paymentItemRepository
107
- // .findAll({
108
- // where: {
109
- // PaymentId: this.PaymentId,
110
- // },
111
- // })
112
- // .then((allPaymentItems) => {
113
- // this._PaymentItems = allPaymentItems;
114
- // });
115
- // }
116
- // }
117
-
118
- // return this._PaymentItems;
119
- // }
120
-
121
109
  get PaymentItems(): Promise<PaymentItem[]> {
122
110
  return new Promise((resolve, reject) => {
123
111
  if (this.PaymentId !== 'New') {
@@ -196,7 +184,11 @@ export default class Payment extends AccountSystemEntity {
196
184
  }
197
185
 
198
186
  newPaymentPaidWith(paymentMethodTypeId: string) {
199
- const paymentPaidWith = new PaymentPaidWith(this, paymentMethodTypeId);
187
+ const paymentPaidWith = new PaymentPaidWith(
188
+ this,
189
+ paymentMethodTypeId,
190
+ this._DbTransaction,
191
+ );
200
192
  this._PaymentPaidWith.push(paymentPaidWith);
201
193
  return paymentPaidWith;
202
194
  }
@@ -20,27 +20,38 @@ export default class PaymentMethodType extends ObjectBase {
20
20
  }
21
21
  if (methodTypeId) {
22
22
  this.MethodTypeId = methodTypeId;
23
- PaymentMethodType._RepositoryBase
24
- .findOne({
25
- where: {
26
- MethodTypeId: this.MethodTypeId,
27
- },
28
- transaction: this._DbTransaction,
29
- })
30
- .then((paymentMethodTypeData) => {
31
- if (paymentMethodTypeData) {
32
- this.Name = paymentMethodTypeData.Name;
33
- this.AccountNo = paymentMethodTypeData.AccountNo;
34
- this.ProcessingFeeRate = paymentMethodTypeData.ProcessingFeeRate;
35
- this.ProcessingFeeAccountNo =
36
- paymentMethodTypeData.ProcessingFeeAccountNo;
37
- } else {
38
- throw new RecordNotFoundError('No record found.');
39
- }
40
- })
41
- .catch((err) => {
42
- console.log('Payment method type constructor err: ', err);
43
- });
23
+ }
24
+ }
25
+
26
+ static async initMethodType(
27
+ dbTransaction: any,
28
+ methodTypeId: string,
29
+ ): Promise<PaymentMethodType> {
30
+ try {
31
+ const paymentMethodTypeData = await this._RepositoryBase.findOne({
32
+ where: {
33
+ MethodTypeId: methodTypeId,
34
+ },
35
+ transaction: dbTransaction,
36
+ });
37
+ if (paymentMethodTypeData) {
38
+ const paymentMethodType = new PaymentMethodType(
39
+ dbTransaction,
40
+ methodTypeId,
41
+ );
42
+ paymentMethodType.Name = paymentMethodTypeData.Name;
43
+ paymentMethodType.AccountNo = paymentMethodTypeData.AccountNo;
44
+ paymentMethodType.ProcessingFeeRate =
45
+ paymentMethodTypeData.ProcessingFeeRate;
46
+ paymentMethodType.ProcessingFeeAccountNo =
47
+ paymentMethodTypeData.ProcessingFeeAccountNo;
48
+ return paymentMethodType;
49
+ } else {
50
+ const notFoundError = new RecordNotFoundError('No Record Found.');
51
+ throw notFoundError;
52
+ }
53
+ } catch (error) {
54
+ console.log('Payment method type constructor err: ', error);
44
55
  }
45
56
  }
46
57
 
@@ -22,6 +22,7 @@ export default class PaymentPaidWith extends ObjectBase {
22
22
  PaymentMediaId = '';
23
23
 
24
24
  private static _RepositoryBase = new PaymentPaidWithRepository();
25
+ private _DbTransaction: any;
25
26
 
26
27
  public get PaymentId() {
27
28
  return this._PaymentId;
@@ -52,9 +53,16 @@ export default class PaymentPaidWith extends ObjectBase {
52
53
  return 'finance_PaymentPaidWith';
53
54
  }
54
55
 
55
- constructor(payment: Payment, paymentMethodTypeId: string) {
56
+ constructor(
57
+ payment: Payment,
58
+ paymentMethodTypeId: string,
59
+ dbTransaction?: any,
60
+ ) {
56
61
  super();
57
62
  this.PaymentId = payment.PaymentId;
58
63
  this.MethodTypeId = paymentMethodTypeId;
64
+ if (dbTransaction) {
65
+ this._DbTransaction = dbTransaction;
66
+ }
59
67
  }
60
68
  }