@tomei/finance 0.3.20 → 0.3.21

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.3.20",
3
+ "version": "0.3.21",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -20,8 +20,8 @@ export default class JournalEntry extends AccountSystemEntity {
20
20
  new LedgerTransactionRepository();
21
21
 
22
22
  private _DbTransaction: any;
23
- private _DebitTransactions = null;
24
- private _CreditTransactions = null;
23
+ private _DebitTransactions: LedgerTransaction[] = [];
24
+ private _CreditTransactions: LedgerTransaction[] = [];
25
25
 
26
26
  get JournalEntryId() {
27
27
  return this._JournalEntryId;
@@ -77,6 +77,18 @@ export default class JournalEntry extends AccountSystemEntity {
77
77
  .catch((err) => {
78
78
  console.log('Journal entry constructor err: ', err);
79
79
  });
80
+ } else {
81
+ this.init({
82
+ JournalEntryId: cuid(),
83
+ CompanyId: this.CompanyId,
84
+ Date: new Date(),
85
+ Name: '',
86
+ Description: '',
87
+ AccSystemRefId: '',
88
+ PostedToAccSystemYN: 'N',
89
+ PostedById: '',
90
+ PostedDateTime: null,
91
+ });
80
92
  }
81
93
  }
82
94
 
@@ -95,12 +107,11 @@ export default class JournalEntry extends AccountSystemEntity {
95
107
  })
96
108
  .then((debitTransactions) => {
97
109
  const debitTransactionObjects = debitTransactions.map(
98
- (debitTransactionData) => {
99
- new LedgerTransaction(
110
+ (debitTransactionData) => new LedgerTransaction(
100
111
  this._DbTransaction,
101
112
  debitTransactionData.TransactionId,
102
- );
103
- },
113
+ )
114
+
104
115
  );
105
116
  return Promise.all(debitTransactionObjects);
106
117
  })
@@ -131,12 +142,12 @@ export default class JournalEntry extends AccountSystemEntity {
131
142
  })
132
143
  .then((creditTransaction) => {
133
144
  const creditTransactionObjects = creditTransaction.map(
134
- (creditTransactionData) => {
145
+ (creditTransactionData) =>
135
146
  new LedgerTransaction(
136
147
  this._DbTransaction,
137
148
  creditTransactionData.TransactionId,
138
- );
139
- },
149
+ )
150
+
140
151
  );
141
152
  return Promise.all(creditTransactionObjects);
142
153
  })
@@ -256,32 +267,18 @@ export default class JournalEntry extends AccountSystemEntity {
256
267
  async newLedgerTransaction(
257
268
  transactionType: TransactionTypeOptions,
258
269
  ): Promise<LedgerTransaction> {
259
- this.init({
260
- JournalEntryId: cuid(),
261
- CompanyId: this.CompanyId,
262
- Date: new Date(),
263
- Name: '',
264
- Description: '',
265
- AccSystemRefId: '',
266
- PostedToAccSystemYN: 'N',
267
- PostedById: '',
268
- PostedDateTime: null,
269
- });
270
270
 
271
271
  const ledgerTransaction = new LedgerTransaction(
272
+ this._DbTransaction,
272
273
  );
273
-
274
- const newLedgerTransaction = await ledgerTransaction.newLedgerTransaction(
275
- transactionType,
276
- this.JournalEntryId,
277
- );
274
+ ledgerTransaction.JournalEntryId = this.JournalEntryId;
278
275
 
279
276
  if (transactionType === TransactionTypeOptions.DEBIT) {
280
- this.DebitTransactions;
277
+ this._DebitTransactions.push(ledgerTransaction);
281
278
  } else if (transactionType === TransactionTypeOptions.CREDIT) {
282
- this.CreditTransactions;
279
+ this._CreditTransactions.push(ledgerTransaction);
283
280
  }
284
281
 
285
- return newLedgerTransaction;
282
+ return ledgerTransaction;
286
283
  }
287
284
  }
@@ -17,11 +17,16 @@ export default class LedgerTransaction {
17
17
  RelatedObjectType: string;
18
18
 
19
19
  TransactionType: string;
20
+ private _DbTransaction: any;
20
21
 
21
22
  private static _LedgerTransactionRepository =
22
23
  new LedgerTransactionRepository();
23
24
 
24
- constructor(dbTransaction?: any, transactionId?: string) {}
25
+ constructor(dbTransaction?: any, transactionId?: string) {
26
+ if(dbTransaction){
27
+ this._DbTransaction = dbTransaction;
28
+ }
29
+ }
25
30
 
26
31
  init(params?: ILedgerTransactionAttr) {
27
32
  this.TransactionId = params.TransactionId;
@@ -56,7 +61,7 @@ export default class LedgerTransaction {
56
61
  }
57
62
 
58
63
  async create() {
59
- return await LedgerTransaction._LedgerTransactionRepository.create(this.getData);
64
+ return await LedgerTransaction._LedgerTransactionRepository.create(this.getData, {transaction: this._DbTransaction});
60
65
  }
61
66
 
62
67
  async newLedgerTransaction(
@@ -66,7 +71,8 @@ export default class LedgerTransaction {
66
71
  this.init({
67
72
  TransactionId: cuid(),
68
73
  TransactionType: transactionType,
69
- JournalEntryId: '',
74
+ JournalEntryId: journalEntryId,
75
+ //TODO: AccountNo should be Filled In. Not sure with What
70
76
  AccountNo: '',
71
77
  Date: new Date(),
72
78
  Name: '',