@tomei/finance 0.6.43 → 0.6.44

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.6.43",
3
+ "version": "0.6.44",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -8,4 +8,10 @@ export class JournalEntryRepository
8
8
  constructor() {
9
9
  super(JournalEntryModel);
10
10
  }
11
+
12
+ async count(dbTransaction?: any) {
13
+ return await JournalEntryModel.count({
14
+ transaction: dbTransaction,
15
+ });
16
+ }
11
17
  }
@@ -56,35 +56,7 @@ export default class JournalEntry extends AccountSystemEntity {
56
56
  if (dbTransaction) {
57
57
  this._DbTransaction = dbTransaction;
58
58
  }
59
- if (journalEntryId) {
60
- this.RepositoryBase.findOne({
61
- where: {
62
- JournalEntryId: journalEntryId,
63
- },
64
- transaction: dbTransaction,
65
- })
66
- .then((journalEntryData) => {
67
- if (journalEntryData) {
68
- this.CompanyId = journalEntryData.CompanyId;
69
- this.Date = journalEntryData.Date;
70
- this.Name = journalEntryData.Name;
71
- this.Description = journalEntryData.Description;
72
- this.AccSystemRefId = journalEntryData.AccSystemRefId;
73
- this.PostedToAccSystemYN = journalEntryData.PostedToAccSystemYN;
74
- this.PostedById = journalEntryData.PostedById;
75
- this.PostedDateTime = journalEntryData.PostedDateTime;
76
- } else {
77
- const notFoundError = new RecordNotFoundError(
78
- 'JournalEntryErrMsg',
79
- 'No Record Found.',
80
- );
81
- throw notFoundError;
82
- }
83
- })
84
- .catch((err) => {
85
- console.log('Journal entry constructor err: ', err);
86
- });
87
- } else {
59
+ if (!journalEntryId) {
88
60
  this.init({
89
61
  JournalEntryId: 'New',
90
62
  CompanyId: '',
@@ -99,6 +71,51 @@ export default class JournalEntry extends AccountSystemEntity {
99
71
  }
100
72
  }
101
73
 
74
+ public static async initJournalEntry(
75
+ dbTransaction?: any,
76
+ journalEntryId?: string,
77
+ ): Promise<JournalEntry> {
78
+ try {
79
+ if (journalEntryId) {
80
+ const journalEntryData = await JournalEntry._RepositoryBase.findOne({
81
+ where: {
82
+ JournalEntryId: journalEntryId,
83
+ },
84
+ transaction: dbTransaction,
85
+ });
86
+
87
+ if (journalEntryData) {
88
+ const journalEntry = new JournalEntry();
89
+ journalEntry.init({
90
+ JournalEntryId: journalEntryData.JournalEntryId,
91
+ CompanyId: journalEntryData.CompanyId,
92
+ Date: new Date(),
93
+ Name: journalEntryData.Name,
94
+ Description: journalEntryData.Description,
95
+ AccSystemRefId: journalEntryData.AccSystemRefId,
96
+ PostedToAccSystemYN: journalEntryData.PostedToAccSystemYN,
97
+ PostedById: journalEntryData.PostedById,
98
+ PostedDateTime: journalEntryData.PostedDateTime,
99
+ });
100
+
101
+ return journalEntry;
102
+ } else {
103
+ const notFoundError = new RecordNotFoundError(
104
+ 'JournalEntryErrMsg',
105
+ 'No Record Found.',
106
+ );
107
+ throw notFoundError;
108
+ }
109
+ } else {
110
+ const journalEntry = new JournalEntry(dbTransaction);
111
+
112
+ return journalEntry;
113
+ }
114
+ } catch (error) {
115
+ throw error;
116
+ }
117
+ }
118
+
102
119
  get DebitTransactions(): Promise<LedgerTransaction[]> {
103
120
  return new Promise((resolve, reject) => {
104
121
  if (this.JournalEntryId !== 'New') {
@@ -189,13 +206,17 @@ export default class JournalEntry extends AccountSystemEntity {
189
206
  };
190
207
  }
191
208
 
192
- async create() {
193
- return await this.RepositoryBase.create(this.getData);
209
+ async create(dbTransaction?: any) {
210
+ return await this.RepositoryBase.create(this.getData, {
211
+ transaction: dbTransaction,
212
+ });
194
213
  }
195
214
 
196
215
  async save(userId: string, dbTransaction?: any): Promise<JournalEntryModel> {
197
216
  try {
198
- this.JournalEntryId = cuid();
217
+ const count = await this.RepositoryBase.count(dbTransaction);
218
+ this.JournalEntryId = `${count + 1}`;
219
+
199
220
  const data = await this.RepositoryBase.create(
200
221
  {
201
222
  JournalEntryId: this.JournalEntryId,