@tomei/finance 0.3.0 → 0.3.2

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.
Files changed (178) hide show
  1. package/dist/account/account.d.ts +22 -27
  2. package/dist/account/account.js +89 -77
  3. package/dist/account/account.js.map +1 -1
  4. package/dist/account/account.repository.d.ts +3 -14
  5. package/dist/account/account.repository.js +4 -39
  6. package/dist/account/account.repository.js.map +1 -1
  7. package/dist/account/interfaces/account-attr.interface.d.ts +15 -7
  8. package/dist/account-system-entity/account-system-entity.d.ts +2 -2
  9. package/dist/account-system-entity/account-system-entity.js +1 -1
  10. package/dist/account-system-entity/post-history.repository.d.ts +2 -2
  11. package/dist/account-system-entity/post-history.repository.js +1 -1
  12. package/dist/customer/customer.d.ts +3 -3
  13. package/dist/customer/customer.js +1 -2
  14. package/dist/customer/customer.js.map +1 -1
  15. package/dist/customer/finance-customer.repository.d.ts +2 -2
  16. package/dist/customer/finance-customer.repository.js +1 -1
  17. package/dist/customer/interfaces/finance-customer.repository.interface.d.ts +2 -2
  18. package/dist/document/document-item.d.ts +2 -1
  19. package/dist/document/document-item.js +2 -2
  20. package/dist/document/document-item.js.map +1 -1
  21. package/dist/document/document-item.repository.d.ts +3 -15
  22. package/dist/document/document-item.repository.js +4 -43
  23. package/dist/document/document-item.repository.js.map +1 -1
  24. package/dist/document/document.d.ts +20 -23
  25. package/dist/document/document.js +85 -54
  26. package/dist/document/document.js.map +1 -1
  27. package/dist/document/document.repository.d.ts +3 -14
  28. package/dist/document/document.repository.js +4 -39
  29. package/dist/document/document.repository.js.map +1 -1
  30. package/dist/document/interfaces/document-item.repository.interface.d.ts +2 -2
  31. package/dist/enum/index.d.ts +2 -1
  32. package/dist/enum/index.js +3 -1
  33. package/dist/enum/index.js.map +1 -1
  34. package/dist/enum/payment-status.enum.d.ts +4 -0
  35. package/dist/enum/payment-status.enum.js +9 -0
  36. package/dist/enum/payment-status.enum.js.map +1 -0
  37. package/dist/enum/transaction-type.enum.d.ts +2 -2
  38. package/dist/enum/transaction-type.enum.js +2 -2
  39. package/dist/enum/transaction-type.enum.js.map +1 -1
  40. package/dist/finance-company/finance-company.d.ts +15 -10
  41. package/dist/finance-company/finance-company.js +473 -30
  42. package/dist/finance-company/finance-company.js.map +1 -1
  43. package/dist/finance-company/finance-company.repository.d.ts +2 -2
  44. package/dist/finance-company/finance-company.repository.js +1 -1
  45. package/dist/index.d.ts +11 -8
  46. package/dist/index.js +14 -8
  47. package/dist/index.js.map +1 -1
  48. package/dist/interfaces/account-system.interface.d.ts +2 -2
  49. package/dist/journal-entry/journal-entry.d.ts +13 -17
  50. package/dist/journal-entry/journal-entry.js +83 -35
  51. package/dist/journal-entry/journal-entry.js.map +1 -1
  52. package/dist/journal-entry/journal-entry.repository.d.ts +3 -13
  53. package/dist/journal-entry/journal-entry.repository.js +5 -38
  54. package/dist/journal-entry/journal-entry.repository.js.map +1 -1
  55. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +0 -4
  56. package/dist/ledger-transaction/ledger-transaction.d.ts +6 -5
  57. package/dist/ledger-transaction/ledger-transaction.js +6 -9
  58. package/dist/ledger-transaction/ledger-transaction.js.map +1 -1
  59. package/dist/ledger-transaction/ledger-transaction.repository.d.ts +3 -8
  60. package/dist/ledger-transaction/ledger-transaction.repository.js +5 -32
  61. package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -1
  62. package/dist/models/account.entity.d.ts +7 -3
  63. package/dist/models/account.entity.js +69 -34
  64. package/dist/models/account.entity.js.map +1 -1
  65. package/dist/models/finance-company.entity.d.ts +0 -4
  66. package/dist/models/finance-company.entity.js +0 -20
  67. package/dist/models/finance-company.entity.js.map +1 -1
  68. package/dist/models/payment-item.entity.d.ts +1 -0
  69. package/dist/models/payment-item.entity.js +7 -0
  70. package/dist/models/payment-item.entity.js.map +1 -1
  71. package/dist/models/payment-method-type.entity.d.ts +13 -0
  72. package/dist/models/payment-method-type.entity.js +86 -0
  73. package/dist/models/payment-method-type.entity.js.map +1 -0
  74. package/dist/models/payment-method.entity.d.ts +7 -0
  75. package/dist/models/payment-method.entity.js +46 -0
  76. package/dist/models/payment-method.entity.js.map +1 -0
  77. package/dist/models/payment.entity.d.ts +15 -10
  78. package/dist/models/payment.entity.js +92 -34
  79. package/dist/models/payment.entity.js.map +1 -1
  80. package/dist/payment/interfaces/payment-attr.interface.d.ts +11 -8
  81. package/dist/payment/interfaces/payment-attr.interface.js.map +1 -1
  82. package/dist/payment/interfaces/payment-item-attr.interface.d.ts +1 -0
  83. package/dist/payment/interfaces/payment-item-attr.interface.js.map +1 -1
  84. package/dist/payment/payment-item.repository.d.ts +3 -15
  85. package/dist/payment/payment-item.repository.js +4 -43
  86. package/dist/payment/payment-item.repository.js.map +1 -1
  87. package/dist/payment/payment.d.ts +44 -48
  88. package/dist/payment/payment.js +122 -133
  89. package/dist/payment/payment.js.map +1 -1
  90. package/dist/payment/payment.repository.d.ts +3 -14
  91. package/dist/payment/payment.repository.js +4 -39
  92. package/dist/payment/payment.repository.js.map +1 -1
  93. package/dist/payment-item/interfaces/payment-item-attr.interface.d.ts +8 -0
  94. package/dist/payment-item/interfaces/payment-item-attr.interface.js +7 -0
  95. package/dist/payment-item/interfaces/payment-item-attr.interface.js.map +1 -0
  96. package/{src/payment/interfaces/payment-item.repository.interface.ts → dist/payment-item/interfaces/payment-item.repository.interface.d.ts} +0 -1
  97. package/dist/payment-item/interfaces/payment-item.repository.interface.js +3 -0
  98. package/dist/payment-item/interfaces/payment-item.repository.interface.js.map +1 -0
  99. package/dist/payment-item/payment-item.d.ts +19 -0
  100. package/dist/payment-item/payment-item.js +42 -0
  101. package/dist/payment-item/payment-item.js.map +1 -0
  102. package/dist/payment-item/payment-item.repository.d.ts +5 -0
  103. package/dist/payment-item/payment-item.repository.js +12 -0
  104. package/dist/payment-item/payment-item.repository.js.map +1 -0
  105. package/dist/payment-method/interfaces/payment-method-attr.interface.d.ts +4 -0
  106. package/dist/payment-method/interfaces/payment-method-attr.interface.js +3 -0
  107. package/dist/payment-method/interfaces/payment-method-attr.interface.js.map +1 -0
  108. package/dist/payment-method/payment-method.d.ts +17 -0
  109. package/dist/payment-method/payment-method.js +83 -0
  110. package/dist/payment-method/payment-method.js.map +1 -0
  111. package/dist/payment-method/payment-method.repository.d.ts +5 -0
  112. package/dist/payment-method/payment-method.repository.js +12 -0
  113. package/dist/payment-method/payment-method.repository.js.map +1 -0
  114. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.d.ts +8 -0
  115. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js +3 -0
  116. package/dist/payment-method-type/interfaces/payment-method-type-attr.interface.js.map +1 -0
  117. package/dist/payment-method-type/payment-method-type.d.ts +15 -0
  118. package/dist/payment-method-type/payment-method-type.js +55 -0
  119. package/dist/payment-method-type/payment-method-type.js.map +1 -0
  120. package/dist/payment-method-type/payment-method-type.repository.d.ts +5 -0
  121. package/dist/payment-method-type/payment-method-type.repository.js +12 -0
  122. package/dist/payment-method-type/payment-method-type.repository.js.map +1 -0
  123. package/dist/tsconfig.tsbuildinfo +1 -1
  124. package/migrations/finance-account-migration.js +30 -16
  125. package/migrations/finance-company-migration.js +0 -14
  126. package/migrations/finance-payment-item-migration.js +4 -0
  127. package/migrations/finance-payment-method-migration.js +21 -0
  128. package/migrations/finance-payment-method-type-migration.js +55 -0
  129. package/migrations/finance-payment-migration.js +42 -25
  130. package/package.json +4 -4
  131. package/src/account/account.repository.ts +5 -38
  132. package/src/account/account.ts +115 -98
  133. package/src/account/interfaces/account-attr.interface.ts +15 -7
  134. package/src/account-system-entity/account-system-entity.ts +4 -4
  135. package/src/account-system-entity/post-history.repository.ts +3 -3
  136. package/src/customer/customer.ts +3 -3
  137. package/src/customer/finance-customer.repository.ts +2 -2
  138. package/src/customer/interfaces/finance-customer.repository.interface.ts +2 -2
  139. package/src/document/document-item.repository.ts +5 -43
  140. package/src/document/document-item.ts +5 -1
  141. package/src/document/document.repository.ts +5 -35
  142. package/src/document/document.ts +127 -74
  143. package/src/document/interfaces/document-item.repository.interface.ts +2 -2
  144. package/src/enum/index.ts +2 -0
  145. package/src/enum/payment-status.enum.ts +4 -0
  146. package/src/enum/transaction-type.enum.ts +2 -2
  147. package/src/finance-company/finance-company.repository.ts +3 -3
  148. package/src/finance-company/finance-company.ts +685 -48
  149. package/src/index.ts +13 -7
  150. package/src/interfaces/account-system.interface.ts +2 -2
  151. package/src/journal-entry/journal-entry.repository.ts +5 -34
  152. package/src/journal-entry/journal-entry.ts +163 -63
  153. package/src/ledger-transaction/interfaces/ledger-transaction-attr.interface.ts +0 -5
  154. package/src/ledger-transaction/ledger-transaction.repository.ts +5 -24
  155. package/src/ledger-transaction/ledger-transaction.ts +8 -12
  156. package/src/models/account.entity.ts +67 -32
  157. package/src/models/finance-company.entity.ts +0 -16
  158. package/src/models/payment-item.entity.ts +6 -0
  159. package/src/models/payment-method-type.entity.ts +70 -0
  160. package/src/models/payment-method.entity.ts +28 -0
  161. package/src/models/payment.entity.ts +86 -31
  162. package/src/payment/interfaces/payment-attr.interface.ts +11 -8
  163. package/src/payment/payment.repository.ts +5 -35
  164. package/src/payment/payment.ts +183 -181
  165. package/src/{payment → payment-item}/interfaces/payment-item-attr.interface.ts +1 -0
  166. package/src/payment-item/payment-item.repository.ts +11 -0
  167. package/src/payment-item/payment-item.ts +54 -0
  168. package/src/payment-method/interfaces/payment-method-attr.interface.ts +4 -0
  169. package/src/payment-method/payment-method.repository.ts +11 -0
  170. package/src/payment-method/payment-method.ts +95 -0
  171. package/src/payment-method-type/interfaces/payment-method-type-attr.interface.ts +8 -0
  172. package/src/payment-method-type/payment-method-type.repository.ts +11 -0
  173. package/src/payment-method-type/payment-method-type.ts +58 -0
  174. package/src/account/interfaces/account.repository.interface.ts +0 -4
  175. package/src/document/interfaces/document.repository.interface.ts +0 -4
  176. package/src/journal-entry/interfaces/journal-entry.repository.interface.ts +0 -11
  177. package/src/payment/interfaces/payment.repository.interface.ts +0 -4
  178. package/src/payment/payment-item.repository.ts +0 -49
package/src/index.ts CHANGED
@@ -1,11 +1,14 @@
1
- import { Account } from './account/account';
1
+ import Account from './account/account';
2
2
  import FinanceCompany from './finance-company/finance-company';
3
- import { FinanceCustomerBase } from './customer/customer';
4
- import { Document } from './document/document';
5
- import { DocumentItem } from './document/document-item';
6
- import { JournalEntry } from './journal-entry/journal-entry';
7
- import { LedgerTransaction } from './ledger-transaction/ledger-transaction';
8
- import { Payment } from './payment/payment';
3
+ import FinanceCustomerBase from './customer/customer';
4
+ import Document from './document/document';
5
+ import DocumentItem from './document/document-item';
6
+ import JournalEntry from './journal-entry/journal-entry';
7
+ import LedgerTransaction from './ledger-transaction/ledger-transaction';
8
+ import Payment from './payment/payment';
9
+ import PaymentItem from './payment-item/payment-item';
10
+ import PaymentMethod from './payment-method/payment-method';
11
+ import PaymentMethodType from './payment-method-type/payment-method-type';
9
12
 
10
13
  export {
11
14
  FinanceCompany,
@@ -16,6 +19,9 @@ export {
16
19
  JournalEntry,
17
20
  LedgerTransaction,
18
21
  Payment,
22
+ PaymentItem,
23
+ PaymentMethod,
24
+ PaymentMethodType,
19
25
  };
20
26
  export * as FinanceEnum from './enum';
21
27
  export * as FinanceInterfaces from './interfaces';
@@ -1,5 +1,5 @@
1
- import { Payment } from '../payment/payment';
2
- import { FinanceCustomerBase } from '../customer/customer';
1
+ import Payment from '../payment/payment';
2
+ import FinanceCustomerBase from '../customer/customer';
3
3
 
4
4
  export interface IAccountSystem {
5
5
  createAccount(payload: any): Promise<any>;
@@ -1,40 +1,11 @@
1
- import { InjectModel } from '@nestjs/sequelize';
1
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
2
2
  import JournalEntryModel from '../models/journal-entry.entity';
3
- import { IJournalEntryRepository } from './interfaces/journal-entry.repository.interface';
4
- import { IJournalEntryAttr } from './interfaces/journal-entry-attr.interface';
5
- import { Injectable } from '@nestjs/common/decorators';
6
3
 
7
- @Injectable()
8
4
  export class JournalEntryRepository
9
- implements IJournalEntryRepository<JournalEntryModel>
5
+ extends RepositoryBase<JournalEntryModel>
6
+ implements IRepositoryBase<JournalEntryModel>
10
7
  {
11
- constructor(
12
- @InjectModel(JournalEntryModel)
13
- private readonly journalEntryModel: typeof JournalEntryModel,
14
- ) {}
15
-
16
- create(
17
- data: IJournalEntryAttr | any,
18
- options?: any,
19
- ): Promise<JournalEntryModel> | any {
20
- return this.journalEntryModel.create(data, options);
21
- }
22
-
23
- findAll(options?: any): Promise<JournalEntryModel[]> {
24
- return this.journalEntryModel.findAll(options);
25
- }
26
-
27
- findAllWithPagination(
28
- options: any,
29
- ): Promise<{ count: number; rows: JournalEntryModel[] }> {
30
- return this.journalEntryModel.findAndCountAll(options);
31
- }
32
-
33
- findOne(options: any): Promise<JournalEntryModel> {
34
- return this.journalEntryModel.findOne(options);
35
- }
36
-
37
- update(data: IJournalEntryAttr, options?: any): any {
38
- return this.journalEntryModel.update({ ...data }, options);
8
+ constructor() {
9
+ super(JournalEntryModel);
39
10
  }
40
11
  }
@@ -1,33 +1,29 @@
1
1
  import * as cuid from 'cuid';
2
2
  import { Op } from 'sequelize';
3
- import { ILedgerTransactionTypeOptionsAttr } from '../ledger-transaction/interfaces/ledger-transaction-attr.interface';
4
- import { JournalEntryRepository } from './journal-entry.repository';
5
3
  import { IJournalEntryAttr } from './interfaces/journal-entry-attr.interface';
6
4
  import { TransactionTypeOptions } from '../enum';
7
5
  import JournalEntryModel from '../models/journal-entry.entity';
8
- import { IBaseRepository } from '@tomei/general';
9
6
  import { AccountSystemEntity } from '../account-system-entity/account-system-entity';
10
7
  import { LedgerTransactionRepository } from '../ledger-transaction/ledger-transaction.repository';
11
- import { LedgerTransaction } from '../ledger-transaction/ledger-transaction';
8
+ import LedgerTransaction from '../ledger-transaction/ledger-transaction';
9
+ import { JournalEntryRepository } from './journal-entry.repository';
10
+ import { RecordNotFoundError } from '@tomei/general';
12
11
 
13
- export class JournalEntry extends AccountSystemEntity {
12
+ export default class JournalEntry extends AccountSystemEntity {
14
13
  private _JournalEntryId: string;
15
14
  Date: Date;
16
15
  Name: string;
17
16
  Description: string;
18
17
 
19
- private _JournalEntryModel: IBaseRepository<JournalEntryModel> =
20
- new JournalEntryModel();
21
- protected _BaseRepository: IBaseRepository;
22
-
23
- _TableName: string;
24
- _ObjectId: string;
25
- _ObjectName: string;
18
+ private static _RepositoryBase = new JournalEntryRepository();
19
+ private static _LedgerTransactionRepository =
20
+ new LedgerTransactionRepository();
26
21
 
27
- journalEntryRepository: JournalEntryRepository;
28
22
  ledgerTransactionRepository: LedgerTransactionRepository;
29
- private _DebitTransactions: any = null;
30
- private _CreditTransactions: any = null;
23
+
24
+ private _DbTransaction: any;
25
+ private _DebitTransactions = null;
26
+ private _CreditTransactions = null;
31
27
 
32
28
  get JournalEntryId() {
33
29
  return this._JournalEntryId;
@@ -37,82 +33,177 @@ export class JournalEntry extends AccountSystemEntity {
37
33
  this._JournalEntryId = id;
38
34
  }
39
35
 
40
- override get BaseRepository() {
41
- return this._JournalEntryModel;
36
+ get RepositoryBase() {
37
+ return JournalEntry._RepositoryBase;
42
38
  }
43
39
 
44
- override get TableName() {
40
+ get TableName() {
45
41
  return 'finance_JournalEntry';
46
42
  }
47
43
 
48
- override get ObjectName() {
44
+ get ObjectName() {
49
45
  return this.Name;
50
46
  }
51
47
 
52
- override get ObjectId() {
48
+ get ObjectId() {
53
49
  return this._JournalEntryId;
54
50
  }
55
51
 
56
- constructor(dbTransaction: any);
57
- constructor(dbTransaction: any, journalEntryId: string);
58
- constructor(dbTransaction: any, journalEntryId?: string) {
52
+ constructor(dbTransaction?: any, journalEntryId?: string) {
59
53
  super();
60
- this.journalEntryRepository = this.ledgerTransactionRepository.findOne({
61
- where: {
62
- JournalEntryId: journalEntryId,
63
- },
64
- transaction: dbTransaction,
65
- });
54
+ if (dbTransaction) {
55
+ this._DbTransaction = dbTransaction;
56
+ }
57
+ if (journalEntryId) {
58
+ this.RepositoryBase.findOne({
59
+ where: {
60
+ JournalEntryId: journalEntryId,
61
+ },
62
+ transaction: dbTransaction,
63
+ })
64
+ .then((journalEntryData) => {
65
+ if (journalEntryData) {
66
+ this.CompanyId = journalEntryData.CompanyId;
67
+ this.Date = journalEntryData.Date;
68
+ this.Name = journalEntryData.Name;
69
+ this.Description = journalEntryData.Description;
70
+ this.AccSystemRefId = journalEntryData.AccSystemRefId;
71
+ this.PostedToAccSystemYN = journalEntryData.PostedToAccSystemYN;
72
+ this.PostedById = journalEntryData.PostedById;
73
+ this.PostedDateTime = journalEntryData.PostedDateTime;
74
+ } else {
75
+ const notFoundError = new RecordNotFoundError('No Record Found.');
76
+ throw notFoundError;
77
+ }
78
+ })
79
+ .catch((err) => {
80
+ console.log('Journal entry constructor err: ', err);
81
+ });
82
+ }
66
83
  }
67
84
 
68
- public get DebitTransactions() {
69
- if (this._DebitTransactions === null) {
70
- // this._DebitTransactions = new LedgerTransaction(
71
- // this.ledgerTransactionRepository,
72
- // );
85
+ get DebitTransactions(): Promise<LedgerTransaction[]> {
86
+ return new Promise((resolve, reject) => {
73
87
  if (this.JournalEntryId !== 'New') {
74
- this.ledgerTransactionRepository
88
+ JournalEntry._LedgerTransactionRepository
75
89
  .findAll({
76
90
  where: {
77
91
  JournalEntryId: {
78
92
  [Op.ne]: 'New',
79
93
  },
80
- TransactionType: TransactionTypeOptions.Debit,
94
+ TransactionType: TransactionTypeOptions.DEBIT,
81
95
  },
96
+ transaction: this._DbTransaction,
97
+ })
98
+ .then((debitTransactions) => {
99
+ const debitTransactionObjects = debitTransactions.map(
100
+ (debitTransactionData) => {
101
+ new LedgerTransaction(
102
+ this._DbTransaction,
103
+ debitTransactionData.TransactionId,
104
+ );
105
+ },
106
+ );
107
+ return Promise.all(debitTransactionObjects);
108
+ })
109
+ .then((debitTransactionObjects) => {
110
+ this._DebitTransactions = debitTransactionObjects;
111
+ resolve(this._DebitTransactions);
82
112
  })
83
- .then((allDebitTransactions) => {
84
- this._DebitTransactions = allDebitTransactions;
113
+ .catch((err) => {
114
+ reject(err);
85
115
  });
86
116
  }
87
- }
88
-
89
- return this._DebitTransactions;
117
+ resolve(this._DebitTransactions);
118
+ });
90
119
  }
91
120
 
92
- public get CreditTransactions() {
93
- if (this._CreditTransactions === null) {
94
- // this._CreditTransactions = new LedgerTransaction(
95
- // this.ledgerTransactionRepository,
96
- // );
121
+ get CreditTransactions(): Promise<LedgerTransaction[]> {
122
+ return new Promise((resolve, reject) => {
97
123
  if (this.JournalEntryId !== 'New') {
98
- this.ledgerTransactionRepository
124
+ JournalEntry._LedgerTransactionRepository
99
125
  .findAll({
100
126
  where: {
101
127
  JournalEntryId: {
102
128
  [Op.ne]: 'New',
103
129
  },
104
- TransactionType: TransactionTypeOptions.Credit,
130
+ TransactionType: TransactionTypeOptions.CREDIT,
105
131
  },
132
+ transaction: this._DbTransaction,
133
+ })
134
+ .then((creditTransaction) => {
135
+ const creditTransactionObjects = creditTransaction.map(
136
+ (creditTransactionData) => {
137
+ new LedgerTransaction(
138
+ this._DbTransaction,
139
+ creditTransactionData.TransactionId,
140
+ );
141
+ },
142
+ );
143
+ return Promise.all(creditTransactionObjects);
144
+ })
145
+ .then((creditTransactionObjects) => {
146
+ this._CreditTransactions = creditTransactionObjects;
147
+ resolve(this._CreditTransactions);
106
148
  })
107
- .then((allCreditTransactions) => {
108
- this._CreditTransactions = allCreditTransactions;
149
+ .catch((err) => {
150
+ reject(err);
109
151
  });
110
152
  }
111
- }
112
-
113
- return this._CreditTransactions;
153
+ resolve(this._CreditTransactions);
154
+ });
114
155
  }
115
156
 
157
+ // public get DebitTransactions() {
158
+ // if (this._DebitTransactions === null) {
159
+ // // this._DebitTransactions = new LedgerTransaction(
160
+ // // this.ledgerTransactionRepository,
161
+ // // );
162
+ // if (this.JournalEntryId !== 'New') {
163
+ // JournalEntry._LedgerTransactionRepository
164
+ // .findAll({
165
+ // where: {
166
+ // JournalEntryId: {
167
+ // [Op.ne]: 'New',
168
+ // },
169
+ // TransactionType: TransactionTypeOptions.DEBIT,
170
+ // },
171
+ // transaction: this._DbTransaction,
172
+ // })
173
+ // .then((allDebitTransactions) => {
174
+ // this._DebitTransactions = allDebitTransactions;
175
+ // });
176
+ // }
177
+ // }
178
+
179
+ // return this._DebitTransactions;
180
+ // }
181
+
182
+ // public get CreditTransactions() {
183
+ // if (this._CreditTransactions === null) {
184
+ // // this._CreditTransactions = new LedgerTransaction(
185
+ // // this.ledgerTransactionRepository,
186
+ // // );
187
+ // if (this.JournalEntryId !== 'New') {
188
+ // JournalEntry._LedgerTransactionRepository
189
+ // .findAll({
190
+ // where: {
191
+ // JournalEntryId: {
192
+ // [Op.ne]: 'New',
193
+ // },
194
+ // TransactionType: TransactionTypeOptions.CREDIT,
195
+ // },
196
+ // transaction: this._DbTransaction,
197
+ // })
198
+ // .then((allCreditTransactions) => {
199
+ // this._CreditTransactions = allCreditTransactions;
200
+ // });
201
+ // }
202
+ // }
203
+
204
+ // return this._CreditTransactions;
205
+ // }
206
+
116
207
  init(params: IJournalEntryAttr) {
117
208
  this.JournalEntryId = params.JournalEntryId;
118
209
  this.Date = params.Date;
@@ -136,11 +227,11 @@ export class JournalEntry extends AccountSystemEntity {
136
227
  }
137
228
 
138
229
  async create() {
139
- return await this.journalEntryRepository.create(this.getData);
230
+ return await this.RepositoryBase.create(this.getData);
140
231
  }
141
232
 
142
233
  async save(userId: string, dbTransaction?: any): Promise<JournalEntryModel> {
143
- const data = await this.journalEntryRepository.create(
234
+ const data = await this.RepositoryBase.create(
144
235
  {
145
236
  JournalEntryId: this.JournalEntryId,
146
237
  Date: this.Date,
@@ -155,12 +246,21 @@ export class JournalEntry extends AccountSystemEntity {
155
246
  return data;
156
247
  }
157
248
 
158
- async newLedgerTransaction({
159
- transactionType,
160
- }: ILedgerTransactionTypeOptionsAttr): Promise<any> {
249
+ /**
250
+ * Create a new LedgerTransaction
251
+ *
252
+ * @see {@link FinanceCompany.issueInvoice} - for implementation
253
+ *
254
+ * @param transactionType - Indicating the type of ledger transaction to create
255
+ *
256
+ * @returns {LedgerTransaction}
257
+ */
258
+ async newLedgerTransaction(
259
+ transactionType: TransactionTypeOptions,
260
+ ): Promise<LedgerTransaction> {
161
261
  this.init({
162
- CompanyId: cuid(),
163
- JournalEntryId: 'New',
262
+ JournalEntryId: cuid(),
263
+ CompanyId: this.CompanyId,
164
264
  Date: new Date(),
165
265
  Name: '',
166
266
  Description: '',
@@ -175,13 +275,13 @@ export class JournalEntry extends AccountSystemEntity {
175
275
  );
176
276
 
177
277
  const newLedgerTransaction = await ledgerTransaction.newLedgerTransaction(
178
- { transactionType },
278
+ transactionType,
179
279
  this.JournalEntryId,
180
280
  );
181
281
 
182
- if (transactionType === TransactionTypeOptions.Debit) {
282
+ if (transactionType === TransactionTypeOptions.DEBIT) {
183
283
  this.DebitTransactions;
184
- } else if (transactionType === TransactionTypeOptions.Credit) {
284
+ } else if (transactionType === TransactionTypeOptions.CREDIT) {
185
285
  this.CreditTransactions;
186
286
  }
187
287
 
@@ -1,4 +1,3 @@
1
- import { TransactionTypeOptions } from '../../enum';
2
1
  export interface ILedgerTransactionAttr {
3
2
  TransactionId: string;
4
3
  TransactionType: string;
@@ -13,7 +12,3 @@ export interface ILedgerTransactionAttr {
13
12
  RelatedObjectId: string;
14
13
  RelatedObjectType: string;
15
14
  }
16
-
17
- export interface ILedgerTransactionTypeOptionsAttr {
18
- transactionType: TransactionTypeOptions;
19
- }
@@ -1,30 +1,11 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/sequelize';
3
1
  import LedgerTransactionModel from '../models/ledger-transaction.entity';
4
- import { ILedgerTransactionAttr } from './interfaces/ledger-transaction-attr.interface';
5
- import { ILedgerTransactionRepository } from './interfaces/ledger-transaction.repository.interface';
2
+ import { RepositoryBase, IRepositoryBase } from '@tomei/general';
6
3
 
7
- @Injectable()
8
4
  export class LedgerTransactionRepository
9
- implements ILedgerTransactionRepository<LedgerTransactionModel>
5
+ extends RepositoryBase<LedgerTransactionModel>
6
+ implements IRepositoryBase<LedgerTransactionModel>
10
7
  {
11
- constructor(
12
- @InjectModel(LedgerTransactionModel)
13
- private readonly ledgerTransactionModel: typeof LedgerTransactionModel,
14
- ) {}
15
-
16
- create(
17
- data: ILedgerTransactionAttr | any,
18
- options?: any,
19
- ): Promise<LedgerTransactionModel> | any {
20
- return this.ledgerTransactionModel.create(data, options);
21
- }
22
-
23
- findAll(options?: any): Promise<LedgerTransactionModel[]> {
24
- return this.ledgerTransactionModel.findAll(options);
25
- }
26
-
27
- findOne(options: any): Promise<LedgerTransactionModel> | any {
28
- return this.ledgerTransactionModel.findOne(options);
8
+ constructor() {
9
+ super(LedgerTransactionModel);
29
10
  }
30
11
  }
@@ -1,12 +1,9 @@
1
- import {
2
- ILedgerTransactionAttr,
3
- ILedgerTransactionTypeOptionsAttr,
4
- } from './interfaces/ledger-transaction-attr.interface';
1
+ import { ILedgerTransactionAttr } from './interfaces/ledger-transaction-attr.interface';
5
2
  import { TransactionTypeOptions } from '../enum/transaction-type.enum';
6
3
  import { LedgerTransactionRepository } from './ledger-transaction.repository';
7
4
  import * as uniqid from 'uniqid';
8
5
 
9
- export class LedgerTransaction {
6
+ export default class LedgerTransaction {
10
7
  TransactionId: string;
11
8
  JournalEntryId: string;
12
9
  AccountNo: string;
@@ -22,9 +19,8 @@ export class LedgerTransaction {
22
19
  TransactionType: string;
23
20
 
24
21
  ledgerTransactionRepository: LedgerTransactionRepository;
25
- constructor(ledgerTransactionRepository: LedgerTransactionRepository) {
26
- this.ledgerTransactionRepository = ledgerTransactionRepository;
27
- }
22
+
23
+ constructor(dbTransaction?: any, transactionId?: string) {}
28
24
 
29
25
  init(params?: ILedgerTransactionAttr) {
30
26
  this.TransactionId = params.TransactionId;
@@ -63,12 +59,12 @@ export class LedgerTransaction {
63
59
  }
64
60
 
65
61
  async newLedgerTransaction(
66
- { transactionType }: ILedgerTransactionTypeOptionsAttr,
62
+ transactionType: TransactionTypeOptions,
67
63
  journalEntryId?: string,
68
64
  ): Promise<any> {
69
65
  this.init({
70
66
  TransactionId: uniqid(),
71
- TransactionType: 'Debit',
67
+ TransactionType: transactionType,
72
68
  JournalEntryId: '',
73
69
  AccountNo: '',
74
70
  Date: new Date(),
@@ -81,9 +77,9 @@ export class LedgerTransaction {
81
77
  RelatedObjectType: '',
82
78
  });
83
79
 
84
- if (transactionType === TransactionTypeOptions.Debit) {
80
+ if (transactionType === TransactionTypeOptions.DEBIT) {
85
81
  this.TransactionType = 'Debit';
86
- } else if (transactionType === TransactionTypeOptions.Credit) {
82
+ } else if (transactionType === TransactionTypeOptions.CREDIT) {
87
83
  this.TransactionType = 'Credit';
88
84
  }
89
85
 
@@ -1,5 +1,7 @@
1
1
  import { ApiProperty } from '@nestjs/swagger';
2
2
  import {
3
+ ForeignKey,
4
+ BelongsTo,
3
5
  Column,
4
6
  CreatedAt,
5
7
  Model,
@@ -11,6 +13,7 @@ import {
11
13
  import LedgerTransactionModel from './ledger-transaction.entity';
12
14
  import PaymentModel from './payment.entity';
13
15
  import DocumentItemModel from './document-item.entity';
16
+ import FinanceCompanyModel from './finance-company.entity';
14
17
 
15
18
  @Table({ tableName: 'finance_Account', createdAt: false, updatedAt: false })
16
19
  export default class AccountModel extends Model {
@@ -22,48 +25,31 @@ export default class AccountModel extends Model {
22
25
  })
23
26
  AccountNo: string;
24
27
 
25
- @ApiProperty({ type: String, description: 'Parent account of this object' })
26
- @Column({
27
- type: DataType.STRING(30),
28
- })
29
- ParentAccountNo: string;
30
-
31
- @ApiProperty({
32
- type: String,
33
- description: 'System Code eg. "EZC", "CRM"',
34
- })
35
- @Column({
36
- allowNull: false,
37
- type: DataType.STRING(10),
38
- })
39
- SystemCode: string;
40
-
41
28
  @ApiProperty({
42
- type: String,
43
- description: 'Finance account system code eg. "quickbook"',
29
+ example: 'cl6nzvo780000qcw38ihpd8w6',
30
+ description: 'CompanyId',
44
31
  })
32
+ @ForeignKey(() => FinanceCompanyModel)
45
33
  @Column({
46
34
  allowNull: false,
47
- type: DataType.STRING(10),
35
+ type: DataType.STRING(30),
48
36
  })
49
- AccSystemCode: string;
37
+ CompanyId: string;
50
38
 
51
- @ApiProperty({
52
- type: String,
53
- description: 'Account id in finance system',
54
- })
39
+ //copy from finance account migration table
40
+ @ApiProperty({ type: String, description: 'Parent account of this object' })
55
41
  @Column({
56
- allowNull: false,
57
- type: DataType.STRING(10),
42
+ type: DataType.STRING(30),
43
+ allowNull: true,
58
44
  })
59
- AccSystemRefId: string;
45
+ ParentAccountNo: string;
60
46
 
61
47
  @ApiProperty({
62
48
  type: String,
63
49
  description: 'Name of the account',
64
50
  })
65
51
  @Column({
66
- allowNull: true,
52
+ allowNull: false,
67
53
  type: DataType.STRING(200),
68
54
  })
69
55
  Name: string;
@@ -74,7 +60,7 @@ export default class AccountModel extends Model {
74
60
  })
75
61
  @Column({
76
62
  allowNull: true,
77
- type: DataType.TEXT,
63
+ type: DataType.STRING(2000),
78
64
  })
79
65
  Description: string;
80
66
 
@@ -83,7 +69,7 @@ export default class AccountModel extends Model {
83
69
  description: 'Account Type',
84
70
  })
85
71
  @Column({
86
- allowNull: true,
72
+ allowNull: false,
87
73
  type: DataType.STRING(100),
88
74
  })
89
75
  AccountType: string;
@@ -143,7 +129,10 @@ export default class AccountModel extends Model {
143
129
  example: '138140891dd211b288d34bc7b4312a49',
144
130
  description: 'The CreatedById for Media.',
145
131
  })
146
- @Column({ allowNull: false, type: DataType.STRING(30) })
132
+ @Column({
133
+ allowNull: false,
134
+ type: DataType.STRING(30),
135
+ })
147
136
  CreatedById: string;
148
137
 
149
138
  @ApiProperty({
@@ -157,9 +146,52 @@ export default class AccountModel extends Model {
157
146
  example: '138140891dd211b288d34bc7b4312a49',
158
147
  description: 'The UpdatedById for Media.',
159
148
  })
160
- @Column({ allowNull: false, type: DataType.STRING(30) })
149
+ @Column({
150
+ allowNull: true,
151
+ type: DataType.STRING(30),
152
+ })
161
153
  UpdatedById: string;
162
154
 
155
+ @ApiProperty({
156
+ type: String,
157
+ description: 'Account id in finance system',
158
+ })
159
+ @Column({
160
+ allowNull: false,
161
+ type: DataType.STRING(10),
162
+ })
163
+ AccSystemRefId: string;
164
+
165
+ @ApiProperty({
166
+ example: 'N',
167
+ description: 'PostedToAccSystemYN',
168
+ })
169
+ @Column({
170
+ allowNull: false,
171
+ type: DataType.ENUM('Y', 'N'),
172
+ })
173
+ PostedToAccSystemYN: string;
174
+
175
+ @ApiProperty({
176
+ example: '138140891dd211b288',
177
+ description: 'PostedById',
178
+ })
179
+ @Column({
180
+ allowNull: true,
181
+ type: DataType.STRING(30),
182
+ })
183
+ PostedById: string;
184
+
185
+ @ApiProperty({
186
+ example: new Date(),
187
+ description: 'PostedToAccSystem Date',
188
+ })
189
+ @Column({
190
+ allowNull: true,
191
+ type: DataType.DATE,
192
+ })
193
+ PostedDateTime: Date;
194
+
163
195
  @HasMany(() => PaymentModel)
164
196
  Payments: PaymentModel[];
165
197
 
@@ -168,4 +200,7 @@ export default class AccountModel extends Model {
168
200
 
169
201
  @HasMany(() => LedgerTransactionModel)
170
202
  LedgerTransactions: LedgerTransactionModel[];
203
+
204
+ @BelongsTo(() => FinanceCompanyModel)
205
+ FinanceCompany: FinanceCompanyModel;
171
206
  }