@tomei/finance 0.1.13 → 0.2.1

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 (85) hide show
  1. package/dist/account/entities/account.entity.d.ts +3 -1
  2. package/dist/account/entities/account.entity.js +6 -1
  3. package/dist/account/entities/account.entity.js.map +1 -1
  4. package/dist/account/interfaces/account.repository.interface.d.ts +1 -1
  5. package/dist/config.d.ts +1 -1
  6. package/dist/enum/index.d.ts +2 -1
  7. package/dist/enum/index.js +3 -1
  8. package/dist/enum/index.js.map +1 -1
  9. package/dist/enum/transaction-type.enum.d.ts +4 -0
  10. package/dist/enum/transaction-type.enum.js +9 -0
  11. package/dist/enum/transaction-type.enum.js.map +1 -0
  12. package/dist/finance-company/finance-company.d.ts +10 -0
  13. package/dist/finance-company/finance-company.js +63 -0
  14. package/dist/finance-company/finance-company.js.map +1 -0
  15. package/dist/finance-company/index.d.ts +2 -0
  16. package/dist/finance-company/index.js +6 -0
  17. package/dist/finance-company/index.js.map +1 -0
  18. package/dist/index.d.ts +3 -0
  19. package/dist/index.js +3 -0
  20. package/dist/index.js.map +1 -1
  21. package/dist/interfaces/account-system.interface.d.ts +1 -0
  22. package/dist/journal-entry/entities/journal-entry.entity.d.ts +12 -0
  23. package/dist/journal-entry/entities/journal-entry.entity.js +98 -0
  24. package/dist/journal-entry/entities/journal-entry.entity.js.map +1 -0
  25. package/dist/journal-entry/index.d.ts +6 -0
  26. package/dist/journal-entry/index.js +10 -0
  27. package/dist/journal-entry/index.js.map +1 -0
  28. package/dist/journal-entry/interfaces/journal-entry-attr.interface.d.ts +9 -0
  29. package/dist/journal-entry/interfaces/journal-entry-attr.interface.js +3 -0
  30. package/dist/journal-entry/interfaces/journal-entry-attr.interface.js.map +1 -0
  31. package/dist/journal-entry/interfaces/journal-entry.repository.interface.d.ts +10 -0
  32. package/dist/journal-entry/interfaces/journal-entry.repository.interface.js +3 -0
  33. package/dist/journal-entry/interfaces/journal-entry.repository.interface.js.map +1 -0
  34. package/dist/journal-entry/journal-entry.d.ts +32 -0
  35. package/dist/journal-entry/journal-entry.js +97 -0
  36. package/dist/journal-entry/journal-entry.js.map +1 -0
  37. package/dist/journal-entry/journal-entry.repository.d.ts +15 -0
  38. package/dist/journal-entry/journal-entry.repository.js +43 -0
  39. package/dist/journal-entry/journal-entry.repository.js.map +1 -0
  40. package/dist/ledger-transaction/entities/ledger-transaction.entity.d.ts +19 -0
  41. package/dist/ledger-transaction/entities/ledger-transaction.entity.js +157 -0
  42. package/dist/ledger-transaction/entities/ledger-transaction.entity.js.map +1 -0
  43. package/dist/ledger-transaction/index.d.ts +6 -0
  44. package/dist/ledger-transaction/index.js +10 -0
  45. package/dist/ledger-transaction/index.js.map +1 -0
  46. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.d.ts +18 -0
  47. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js +3 -0
  48. package/dist/ledger-transaction/interfaces/ledger-transaction-attr.interface.js.map +1 -0
  49. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.d.ts +5 -0
  50. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js +3 -0
  51. package/dist/ledger-transaction/interfaces/ledger-transaction.repository.interface.js.map +1 -0
  52. package/dist/ledger-transaction/ledger-transaction.d.ts +35 -0
  53. package/dist/ledger-transaction/ledger-transaction.js +71 -0
  54. package/dist/ledger-transaction/ledger-transaction.js.map +1 -0
  55. package/dist/ledger-transaction/ledger-transaction.repository.d.ts +10 -0
  56. package/dist/ledger-transaction/ledger-transaction.repository.js +37 -0
  57. package/dist/ledger-transaction/ledger-transaction.repository.js.map +1 -0
  58. package/dist/payment/interfaces/payment-item.repository.interface.d.ts +1 -1
  59. package/dist/payment/interfaces/payment.repository.interface.d.ts +1 -1
  60. package/dist/tsconfig.tsbuildinfo +1 -1
  61. package/migrations/finance-journal-entry-migration.js +41 -0
  62. package/migrations/finance-ledger-transaction-migration.js +73 -0
  63. package/package.json +2 -2
  64. package/src/account/account.ts +189 -189
  65. package/src/account/entities/account.entity.ts +111 -107
  66. package/src/account/interfaces/account-attr.interface.ts +23 -23
  67. package/src/enum/index.ts +6 -5
  68. package/src/enum/transaction-type.enum.ts +4 -0
  69. package/src/finance-company/finance-company.ts +95 -0
  70. package/src/finance-company/index.ts +3 -0
  71. package/src/index.ts +9 -6
  72. package/src/interfaces/account-system.interface.ts +14 -13
  73. package/src/journal-entry/entities/journal-entry.entity.ts +74 -0
  74. package/src/journal-entry/index.ts +13 -0
  75. package/src/journal-entry/interfaces/journal-entry-attr.interface.ts +9 -0
  76. package/src/journal-entry/interfaces/journal-entry.repository.interface.ts +11 -0
  77. package/src/journal-entry/journal-entry.repository.ts +38 -0
  78. package/src/journal-entry/journal-entry.ts +136 -0
  79. package/src/ledger-transaction/entities/ledger-transaction.entity.ts +134 -0
  80. package/src/ledger-transaction/index.ts +13 -0
  81. package/src/ledger-transaction/interfaces/ledger-transaction-attr.interface.ts +20 -0
  82. package/src/ledger-transaction/interfaces/ledger-transaction.repository.interface.ts +7 -0
  83. package/src/ledger-transaction/ledger-transaction.repository.ts +28 -0
  84. package/src/ledger-transaction/ledger-transaction.ts +96 -0
  85. package/src/payment/payment.ts +209 -209
@@ -0,0 +1,136 @@
1
+ import { LedgerTransactionRepository } from 'src/ledger-transaction/ledger-transaction.repository';
2
+ import { LedgerTransaction } from 'src/ledger-transaction';
3
+ import { ILedgerTransactionTypeOptionsAttr } from 'src/ledger-transaction/interfaces/ledger-transaction-attr.interface';
4
+ import { JournalEntryRepository } from './journal-entry.repository';
5
+ import { IJournalEntryAttr } from './interfaces/journal-entry-attr.interface';
6
+ import { TransactionTypeOptions } from 'src/enum';
7
+ import { Op } from 'sequelize';
8
+
9
+ export class JournalEntry {
10
+ JournalEntryId: string;
11
+ Date: Date;
12
+ Name: string;
13
+ Description: string;
14
+ PostedById: string;
15
+ PostedToAccSystemYN: string;
16
+ DatePosted?: string;
17
+
18
+ journalEntryRepository: JournalEntryRepository;
19
+ ledgerTransactionRepository: LedgerTransactionRepository;
20
+
21
+ private _DebitTransactions: any = null;
22
+ private _CreditTransactions: any = null;
23
+
24
+ constructor(
25
+ journalEntryRepository: JournalEntryRepository,
26
+ ledgerTransactionRepository: LedgerTransactionRepository,
27
+ ) {
28
+ this.ledgerTransactionRepository = ledgerTransactionRepository;
29
+ this.journalEntryRepository = journalEntryRepository;
30
+ }
31
+
32
+ public get DebitTransactions() {
33
+ if (this._DebitTransactions === null) {
34
+ // this._DebitTransactions = new LedgerTransaction(
35
+ // this.ledgerTransactionRepository,
36
+ // );
37
+ if (this.JournalEntryId !== 'New') {
38
+ this.ledgerTransactionRepository
39
+ .findAll({
40
+ where: {
41
+ JournalEntryId: {
42
+ [Op.ne]: 'New',
43
+ },
44
+ TransactionType: TransactionTypeOptions.Debit,
45
+ },
46
+ })
47
+ .then((allDebitTransactions) => {
48
+ return allDebitTransactions;
49
+ });
50
+ }
51
+ }
52
+
53
+ return this._DebitTransactions;
54
+ }
55
+
56
+ public get CreditTransactions() {
57
+ if (this._CreditTransactions === null) {
58
+ // this._CreditTransactions = new LedgerTransaction(
59
+ // this.ledgerTransactionRepository,
60
+ // );
61
+ if (this.JournalEntryId !== 'New') {
62
+ this.ledgerTransactionRepository
63
+ .findAll({
64
+ where: {
65
+ JournalEntryId: {
66
+ [Op.ne]: 'New',
67
+ },
68
+ TransactionType: TransactionTypeOptions.Credit,
69
+ },
70
+ })
71
+ .then((allCreditTransactions) => {
72
+ return allCreditTransactions;
73
+ });
74
+ }
75
+ }
76
+
77
+ return this._CreditTransactions;
78
+ }
79
+
80
+ init(params: IJournalEntryAttr) {
81
+ this.JournalEntryId = params.JournalEntryId;
82
+ this.Date = params.Date;
83
+ this.Name = params.Name;
84
+ this.Description = params.Description;
85
+ this.PostedById = params.PostedById;
86
+ this.PostedToAccSystemYN = params.PostedToAccSystemYN;
87
+ this.DatePosted = params.DatePosted;
88
+ }
89
+
90
+ getData() {
91
+ return {
92
+ JournalEntryId: this.JournalEntryId,
93
+ Date: this.Date,
94
+ Name: this.Name,
95
+ Description: this.Description,
96
+ PostedById: this.PostedById,
97
+ PostedToAccSystemYN: this.PostedToAccSystemYN,
98
+ DatePosted: this.DatePosted,
99
+ };
100
+ }
101
+
102
+ async create() {
103
+ return await this.journalEntryRepository.create(this.getData);
104
+ }
105
+
106
+ async newLedgerTransaction({
107
+ transactionType,
108
+ }: ILedgerTransactionTypeOptionsAttr): Promise<any> {
109
+ this.init({
110
+ JournalEntryId: 'New',
111
+ Date: new Date(),
112
+ Name: '',
113
+ Description: '',
114
+ PostedById: '',
115
+ PostedToAccSystemYN: 'N',
116
+ DatePosted: null,
117
+ });
118
+
119
+ const ledgerTransaction = new LedgerTransaction(
120
+ this.ledgerTransactionRepository,
121
+ );
122
+
123
+ const newLedgerTransaction = await ledgerTransaction.newLedgerTransaction(
124
+ { transactionType },
125
+ this.JournalEntryId,
126
+ );
127
+
128
+ if (transactionType === TransactionTypeOptions.Debit) {
129
+ this.DebitTransactions;
130
+ } else if (transactionType === TransactionTypeOptions.Credit) {
131
+ this.CreditTransactions;
132
+ }
133
+
134
+ return newLedgerTransaction;
135
+ }
136
+ }
@@ -0,0 +1,134 @@
1
+ import { ApiProperty } from '@nestjs/swagger';
2
+ import {
3
+ Column,
4
+ ForeignKey,
5
+ Model,
6
+ Table,
7
+ DataType,
8
+ BelongsTo,
9
+ } from 'sequelize-typescript';
10
+ import { AccountModel } from 'src/account';
11
+ import { JournalEntryModel } from 'src/journal-entry/entities/journal-entry.entity';
12
+
13
+ @Table({
14
+ tableName: 'finance_LedgerTransaction',
15
+ timestamps: false,
16
+ })
17
+ export class LedgerTransactionModel extends Model {
18
+ @ApiProperty({ type: String, description: 'Transactionid' })
19
+ @Column({
20
+ primaryKey: true,
21
+ allowNull: false,
22
+ type: DataType.STRING(30),
23
+ })
24
+ TransactionId: string;
25
+
26
+ @ApiProperty({
27
+ type: String,
28
+ description: 'Transaction Type eg. "Credit", "Debit"',
29
+ })
30
+ @Column({
31
+ allowNull: false,
32
+ type: DataType.STRING(20),
33
+ })
34
+ TransactionType: string;
35
+
36
+ @ApiProperty({ type: String, description: 'JournalEntryId' })
37
+ @ForeignKey(() => JournalEntryModel)
38
+ @Column({
39
+ allowNull: false,
40
+ type: DataType.STRING(30),
41
+ })
42
+ JournalEntryId: string;
43
+
44
+ @ApiProperty({ type: String, description: 'AccountNo' })
45
+ @ForeignKey(() => AccountModel)
46
+ @Column({
47
+ allowNull: false,
48
+ type: DataType.STRING(30),
49
+ })
50
+ AccountNo: string;
51
+
52
+ @ApiProperty({ type: Date, description: 'Date' })
53
+ @Column({
54
+ allowNull: false,
55
+ type: DataType.DATE,
56
+ })
57
+ Date: Date;
58
+
59
+ @ApiProperty({
60
+ type: String,
61
+ description: 'Name of the ledger transaction',
62
+ })
63
+ @Column({
64
+ allowNull: false,
65
+ type: DataType.STRING(200),
66
+ })
67
+ Name: string;
68
+
69
+ @ApiProperty({
70
+ type: String,
71
+ description: 'Description of the ledger transaction',
72
+ })
73
+ @Column({
74
+ allowNull: true,
75
+ type: DataType.STRING(1000),
76
+ })
77
+ Description: string;
78
+
79
+ @ApiProperty({
80
+ type: String,
81
+ description: 'Currency',
82
+ })
83
+ @Column({
84
+ allowNull: false,
85
+ type: DataType.CHAR(3),
86
+ })
87
+ Currency: string;
88
+
89
+ @ApiProperty({
90
+ type: Number,
91
+ description: 'Debit Amount of the ledger transaction',
92
+ })
93
+ @Column({
94
+ allowNull: true,
95
+ type: DataType.DECIMAL(10, 2),
96
+ })
97
+ DebitAmount: number;
98
+
99
+ @ApiProperty({
100
+ type: Number,
101
+ description: 'Credit Amount of the ledger transaction',
102
+ })
103
+ @Column({
104
+ allowNull: true,
105
+ type: DataType.DECIMAL(10, 2),
106
+ })
107
+ CreditAmount: number;
108
+
109
+ @ApiProperty({
110
+ type: String,
111
+ description: 'RelatedObjectId',
112
+ })
113
+ @Column({
114
+ allowNull: false,
115
+ type: DataType.STRING(30),
116
+ })
117
+ RelatedObjectId: string;
118
+
119
+ @ApiProperty({
120
+ type: String,
121
+ description: 'RelatedObjectType',
122
+ })
123
+ @Column({
124
+ allowNull: false,
125
+ type: DataType.STRING(200),
126
+ })
127
+ RelatedObjectType: string;
128
+
129
+ @BelongsTo(() => AccountModel)
130
+ Account: AccountModel;
131
+
132
+ @BelongsTo(() => JournalEntryModel)
133
+ JournalEntry: JournalEntryModel;
134
+ }
@@ -0,0 +1,13 @@
1
+ import { LedgerTransaction } from './ledger-transaction';
2
+ import { LedgerTransactionModel } from './entities/ledger-transaction.entity';
3
+ import { ILedgerTransactionAttr } from './interfaces/ledger-transaction-attr.interface';
4
+ import { ILedgerTransactionRepository } from './interfaces/ledger-transaction.repository.interface';
5
+ import { LedgerTransactionRepository } from './ledger-transaction.repository';
6
+
7
+ export {
8
+ ILedgerTransactionRepository,
9
+ LedgerTransaction,
10
+ LedgerTransactionModel,
11
+ ILedgerTransactionAttr,
12
+ LedgerTransactionRepository,
13
+ };
@@ -0,0 +1,20 @@
1
+ import { TransactionTypeOptions } from 'src/enum/transaction-type.enum';
2
+
3
+ export interface ILedgerTransactionAttr {
4
+ TransactionId: string;
5
+ TransactionType: string;
6
+ JournalEntryId: string;
7
+ AccountNo: string;
8
+ Date: Date;
9
+ Name: string;
10
+ Description: string;
11
+ Currency: string;
12
+ DebitAmount: number;
13
+ CreditAmount: number;
14
+ RelatedObjectId: string;
15
+ RelatedObjectType: string;
16
+ }
17
+
18
+ export interface ILedgerTransactionTypeOptionsAttr {
19
+ transactionType: TransactionTypeOptions;
20
+ }
@@ -0,0 +1,7 @@
1
+ export interface ILedgerTransactionRepository<T> {
2
+ create?(data: T | any, options?: any): Promise<T> | any;
3
+
4
+ findAll?(options?: any): Promise<T[]>;
5
+
6
+ findOne?(options: any): Promise<T>;
7
+ }
@@ -0,0 +1,28 @@
1
+ import { InjectModel } from '@nestjs/sequelize';
2
+ import { LedgerTransactionModel } from './entities/ledger-transaction.entity';
3
+ import { ILedgerTransactionAttr } from './interfaces/ledger-transaction-attr.interface';
4
+ import { ILedgerTransactionRepository } from './interfaces/ledger-transaction.repository.interface';
5
+
6
+ export class LedgerTransactionRepository
7
+ implements ILedgerTransactionRepository<LedgerTransactionModel>
8
+ {
9
+ constructor(
10
+ @InjectModel(LedgerTransactionModel)
11
+ private readonly ledgerTransactionModel: typeof LedgerTransactionModel,
12
+ ) {}
13
+
14
+ create(
15
+ data: ILedgerTransactionAttr | any,
16
+ options?: any,
17
+ ): Promise<LedgerTransactionModel> | any {
18
+ return this.ledgerTransactionModel.create(data, options);
19
+ }
20
+
21
+ findAll(options?: any): Promise<LedgerTransactionModel[]> {
22
+ return this.ledgerTransactionModel.findAll(options);
23
+ }
24
+
25
+ findOne(options: any): Promise<LedgerTransactionModel> | any {
26
+ return this.ledgerTransactionModel.findOne(options);
27
+ }
28
+ }
@@ -0,0 +1,96 @@
1
+ import {
2
+ ILedgerTransactionAttr,
3
+ ILedgerTransactionTypeOptionsAttr,
4
+ } from './interfaces/ledger-transaction-attr.interface';
5
+ import { TransactionTypeOptions } from 'src/enum/transaction-type.enum';
6
+ import { LedgerTransactionRepository } from './ledger-transaction.repository';
7
+ import * as uniqid from 'uniqid';
8
+
9
+ export class LedgerTransaction {
10
+ TransactionId: string;
11
+ JournalEntryId: string;
12
+ AccountNo: string;
13
+ Date: Date;
14
+ Name: string;
15
+ Description: string;
16
+ Currency: string;
17
+ DebitAmount: number;
18
+ CreditAmount: number;
19
+ RelatedObjectId: string;
20
+ RelatedObjectType: string;
21
+
22
+ TransactionType: string;
23
+
24
+ ledgerTransactionRepository: LedgerTransactionRepository;
25
+ constructor(ledgerTransactionRepository: LedgerTransactionRepository) {
26
+ this.ledgerTransactionRepository = ledgerTransactionRepository;
27
+ }
28
+
29
+ init(params?: ILedgerTransactionAttr) {
30
+ this.TransactionId = params.TransactionId;
31
+ this.TransactionType = params.TransactionType;
32
+ this.JournalEntryId = params.JournalEntryId;
33
+ this.AccountNo = params.AccountNo;
34
+ this.Date = params.Date;
35
+ this.Name = params.Name;
36
+ this.Description = params.Description;
37
+ this.Currency = params.Currency;
38
+ this.DebitAmount = params.DebitAmount;
39
+ this.CreditAmount = params.CreditAmount;
40
+ this.RelatedObjectId = params.RelatedObjectId;
41
+ this.RelatedObjectType = params.RelatedObjectType;
42
+ }
43
+
44
+ getData() {
45
+ return {
46
+ TransactionId: this.TransactionId,
47
+ TransactionType: this.TransactionType,
48
+ JournalEntryId: this.JournalEntryId,
49
+ AccountNo: this.AccountNo,
50
+ Date: this.Date,
51
+ Name: this.Name,
52
+ Description: this.Description,
53
+ Currency: this.Currency,
54
+ DebitAmount: this.DebitAmount,
55
+ CreditAmount: this.CreditAmount,
56
+ RelatedObjectId: this.RelatedObjectId,
57
+ RelatedObjectType: this.RelatedObjectType,
58
+ };
59
+ }
60
+
61
+ async create() {
62
+ return await this.ledgerTransactionRepository.create(this.getData);
63
+ }
64
+
65
+ async newLedgerTransaction(
66
+ { transactionType }: ILedgerTransactionTypeOptionsAttr,
67
+ journalEntryId?: string,
68
+ ): Promise<any> {
69
+ this.init({
70
+ TransactionId: uniqid(),
71
+ TransactionType: 'Debit',
72
+ JournalEntryId: '',
73
+ AccountNo: '',
74
+ Date: new Date(),
75
+ Name: '',
76
+ Description: '',
77
+ Currency: 'MYR',
78
+ DebitAmount: 0,
79
+ CreditAmount: 0,
80
+ RelatedObjectId: '',
81
+ RelatedObjectType: '',
82
+ });
83
+
84
+ if (transactionType === TransactionTypeOptions.Debit) {
85
+ this.TransactionType = 'Debit';
86
+ } else if (transactionType === TransactionTypeOptions.Credit) {
87
+ this.TransactionType = 'Credit';
88
+ }
89
+
90
+ if (journalEntryId) {
91
+ this.JournalEntryId = journalEntryId;
92
+ }
93
+
94
+ return await this.create();
95
+ }
96
+ }