@tomei/finance 0.2.2 → 0.2.4

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.
@@ -1,33 +1,33 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- async up(queryInterface, Sequelize) {
5
- await queryInterface.createTable('finance_Customer', {
6
- CustomerId: {
7
- type: Sequelize.STRING(30),
8
- primaryKey: true,
9
- allowNull: false,
10
- },
11
- SystemCode: {
12
- type: Sequelize.STRING(30),
13
- allowNull: false,
14
- },
15
- AccSystemCode: {
16
- type: Sequelize.STRING(30),
17
- allowNull: false,
18
- },
19
- AccSystemCustomerId: {
20
- type: Sequelize.STRING(30),
21
- allowNull: false,
22
- },
23
- CustomerRefId: {
24
- type: Sequelize.STRING(30),
25
- allowNull: false,
26
- },
27
- });
28
- },
29
-
30
- async down(queryInterface) {
31
- await queryInterface.dropTable('finance_Customer');
32
- },
33
- };
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable('finance_Customer', {
6
+ CustomerId: {
7
+ type: Sequelize.STRING(30),
8
+ primaryKey: true,
9
+ allowNull: false,
10
+ },
11
+ SystemCode: {
12
+ type: Sequelize.STRING(30),
13
+ allowNull: false,
14
+ },
15
+ AccSystemCode: {
16
+ type: Sequelize.STRING(30),
17
+ allowNull: false,
18
+ },
19
+ AccSystemCustomerId: {
20
+ type: Sequelize.STRING(30),
21
+ allowNull: false,
22
+ },
23
+ CustomerRefId: {
24
+ type: Sequelize.STRING(30),
25
+ allowNull: false,
26
+ },
27
+ });
28
+ },
29
+
30
+ async down(queryInterface) {
31
+ await queryInterface.dropTable('finance_Customer');
32
+ },
33
+ };
@@ -1,89 +1,89 @@
1
- 'use strict';
2
-
3
- module.exports = {
4
- async up(queryInterface, Sequelize) {
5
- await queryInterface.createTable('finance_Payment', {
6
- PaymentId: {
7
- type: Sequelize.STRING(30),
8
- primaryKey: true,
9
- allowNull: false,
10
- },
11
- AccountNo: {
12
- type: Sequelize.STRING(30),
13
- allowNull: false,
14
- references: {
15
- model: 'finance_Account',
16
- key: 'AccountNo',
17
- },
18
- onUpdate: 'CASCADE',
19
- onDelete: 'CASCADE',
20
- },
21
- PaymentType: {
22
- type: Sequelize.ENUM(['Payment Received', 'Payout']),
23
- defaultValue: 'Payment Received',
24
- allowNull: false,
25
- },
26
- PaymentDate: {
27
- type: Sequelize.DATE,
28
- allowNull: false,
29
- },
30
- Currency: {
31
- type: Sequelize.CHAR(3),
32
- allowNull: false,
33
- },
34
- Amount: {
35
- type: Sequelize.DECIMAL(10, 2),
36
- allowNull: false,
37
- },
38
- Status: {
39
- type: Sequelize.STRING(20),
40
- allowNull: false,
41
- },
42
- Method: {
43
- type: Sequelize.STRING,
44
- allowNull: false,
45
- },
46
- MethodParty: {
47
- type: Sequelize.STRING(255),
48
- allowNull: false,
49
- },
50
- MethodAccountName: {
51
- type: Sequelize.STRING(100),
52
- allowNull: true,
53
- },
54
- MethodAccountNo: {
55
- type: Sequelize.STRING(100),
56
- allowNull: true,
57
- },
58
- TransactionId: {
59
- type: Sequelize.STRING(100),
60
- allowNull: true,
61
- },
62
- ApprovalId: {
63
- type: Sequelize.STRING(100),
64
- allowNull: true,
65
- },
66
- ReceivedBy: {
67
- type: Sequelize.STRING(30),
68
- allowNull: false,
69
- },
70
- UpdatedAt: {
71
- allowNull: false,
72
- defaultValue: new Date(),
73
- type: Sequelize.DATE,
74
- },
75
- UpdatedBy: {
76
- allowNull: false,
77
- type: Sequelize.STRING,
78
- },
79
- Remarks: {
80
- type: Sequelize.TEXT,
81
- allowNull: true,
82
- },
83
- });
84
- },
85
-
86
- async down(queryInterface) {
87
- await queryInterface.dropTable('finance_Payment');
88
- },
89
- };
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ async up(queryInterface, Sequelize) {
5
+ await queryInterface.createTable('finance_Payment', {
6
+ PaymentId: {
7
+ type: Sequelize.STRING(30),
8
+ primaryKey: true,
9
+ allowNull: false,
10
+ },
11
+ AccountNo: {
12
+ type: Sequelize.STRING(30),
13
+ allowNull: false,
14
+ references: {
15
+ model: 'finance_Account',
16
+ key: 'AccountNo',
17
+ },
18
+ onUpdate: 'CASCADE',
19
+ onDelete: 'CASCADE',
20
+ },
21
+ PaymentType: {
22
+ type: Sequelize.ENUM(['Payment Received', 'Payout']),
23
+ defaultValue: 'Payment Received',
24
+ allowNull: false,
25
+ },
26
+ PaymentDate: {
27
+ type: Sequelize.DATE,
28
+ allowNull: false,
29
+ },
30
+ Currency: {
31
+ type: Sequelize.CHAR(3),
32
+ allowNull: false,
33
+ },
34
+ Amount: {
35
+ type: Sequelize.DECIMAL(10, 2),
36
+ allowNull: false,
37
+ },
38
+ Status: {
39
+ type: Sequelize.STRING(20),
40
+ allowNull: false,
41
+ },
42
+ Method: {
43
+ type: Sequelize.STRING,
44
+ allowNull: false,
45
+ },
46
+ MethodParty: {
47
+ type: Sequelize.STRING(255),
48
+ allowNull: false,
49
+ },
50
+ MethodAccountName: {
51
+ type: Sequelize.STRING(100),
52
+ allowNull: true,
53
+ },
54
+ MethodAccountNo: {
55
+ type: Sequelize.STRING(100),
56
+ allowNull: true,
57
+ },
58
+ TransactionId: {
59
+ type: Sequelize.STRING(100),
60
+ allowNull: true,
61
+ },
62
+ ApprovalId: {
63
+ type: Sequelize.STRING(100),
64
+ allowNull: true,
65
+ },
66
+ ReceivedBy: {
67
+ type: Sequelize.STRING(30),
68
+ allowNull: false,
69
+ },
70
+ UpdatedAt: {
71
+ allowNull: false,
72
+ defaultValue: new Date(),
73
+ type: Sequelize.DATE,
74
+ },
75
+ UpdatedBy: {
76
+ allowNull: false,
77
+ type: Sequelize.STRING,
78
+ },
79
+ Remarks: {
80
+ type: Sequelize.TEXT,
81
+ allowNull: true,
82
+ },
83
+ });
84
+ },
85
+
86
+ async down(queryInterface) {
87
+ await queryInterface.dropTable('finance_Payment');
88
+ },
89
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/finance",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "NestJS package for finance module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -1,44 +1,44 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { InjectModel } from '@nestjs/sequelize';
3
- import { AccountModel } from './entities/account.entity';
4
- import { BaseRepository } from '@tomei/general';
5
- import {
6
- IAccountAttr,
7
- ICreateAccountAttr,
8
- } from './interfaces/account-attr.interface';
9
- import { IAccountRepository } from './interfaces/account.repository.interface';
10
-
11
- @Injectable()
12
- export class AccountRepository
13
- extends BaseRepository<AccountModel>
14
- implements IAccountRepository
15
- {
16
- constructor(
17
- @InjectModel(AccountModel)
18
- private readonly accountModel: typeof AccountModel,
19
- ) {
20
- super(accountModel);
21
- }
22
-
23
- create(data: ICreateAccountAttr, options?: any): Promise<AccountModel> | any {
24
- return this.accountModel.create({ ...data }, options);
25
- }
26
-
27
- findAll(options: any): Promise<AccountModel[]> {
28
- return this.accountModel.findAll(options);
29
- }
30
-
31
- findAllWithPagination(
32
- options: any,
33
- ): Promise<{ count: number; rows: AccountModel[] }> {
34
- return this.accountModel.findAndCountAll(options);
35
- }
36
-
37
- findOne(options: any): Promise<AccountModel> {
38
- return this.accountModel.findOne(options);
39
- }
40
-
41
- update(data: IAccountAttr, options?: any): any {
42
- return this.accountModel.update({ ...data }, options);
43
- }
44
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { InjectModel } from '@nestjs/sequelize';
3
+ import { AccountModel } from './entities/account.entity';
4
+ import { BaseRepository } from '@tomei/general';
5
+ import {
6
+ IAccountAttr,
7
+ ICreateAccountAttr,
8
+ } from './interfaces/account-attr.interface';
9
+ import { IAccountRepository } from './interfaces/account.repository.interface';
10
+
11
+ @Injectable()
12
+ export class AccountRepository
13
+ extends BaseRepository<AccountModel>
14
+ implements IAccountRepository
15
+ {
16
+ constructor(
17
+ @InjectModel(AccountModel)
18
+ private readonly accountModel: typeof AccountModel,
19
+ ) {
20
+ super(accountModel);
21
+ }
22
+
23
+ create(data: ICreateAccountAttr, options?: any): Promise<AccountModel> | any {
24
+ return this.accountModel.create({ ...data }, options);
25
+ }
26
+
27
+ findAll(options: any): Promise<AccountModel[]> {
28
+ return this.accountModel.findAll(options);
29
+ }
30
+
31
+ findAllWithPagination(
32
+ options: any,
33
+ ): Promise<{ count: number; rows: AccountModel[] }> {
34
+ return this.accountModel.findAndCountAll(options);
35
+ }
36
+
37
+ findOne(options: any): Promise<AccountModel> {
38
+ return this.accountModel.findOne(options);
39
+ }
40
+
41
+ update(data: IAccountAttr, options?: any): any {
42
+ return this.accountModel.update({ ...data }, options);
43
+ }
44
+ }
@@ -22,33 +22,38 @@ export class Account {
22
22
  private AccountType: string;
23
23
  private AccountSubtype: string;
24
24
 
25
+ constructor();
25
26
  constructor(
26
- accountRepository: IBaseRepository<AccountModel>,
27
- accountNo: string,
27
+ accountRepository?: IBaseRepository<AccountModel>,
28
+ accountNo?: string,
28
29
  ) {
29
- this.accountRepository = accountRepository;
30
- this.AccountNo = accountNo;
31
- const accountData = this.accountRepository.findOne({
32
- where: { AccountNo: accountNo },
33
- });
34
- if (accountData) {
35
- this.isNewRecord = false;
36
- this.ParentAccountNo = accountData.ParentAccountNo;
37
- this.SystemCode = accountData.SystemCode;
38
- this.AccSystemCode = accountData.AccSystemCode;
39
- this.AccSystemAccountId = accountData.AccSystemAccountId;
40
- this.Name = accountData.Name;
41
- this.Description = accountData.Description;
42
- this.AccountType = accountData.AccountType;
43
- this.AccountSubtype = accountData.AccountSubtype;
44
- this.OwnerId = accountData.OwnerId;
45
- this.OwnerType = accountData.OwnerType;
46
- this.RelatedObjectId = accountData.RelatedObjectId;
47
- this.RelatedObjectType = accountData.RelatedObjectType;
48
- this.AccSystemCode = accountData.AccSystemCode;
49
- } else {
50
- const notFoundError = new RecordNotFoundError('No Record Found.');
51
- throw notFoundError;
30
+ if (accountRepository && accountNo) {
31
+ this.accountRepository = accountRepository;
32
+ this.AccountNo = accountNo;
33
+ const accountData = this.accountRepository.findOne({
34
+ where: { AccountNo: accountNo },
35
+ });
36
+ if (accountData) {
37
+ this.isNewRecord = false;
38
+ this.ParentAccountNo = accountData.ParentAccountNo;
39
+ this.SystemCode = accountData.SystemCode;
40
+ this.AccSystemCode = accountData.AccSystemCode;
41
+ this.AccSystemAccountId = accountData.AccSystemAccountId;
42
+ this.Name = accountData.Name;
43
+ this.Description = accountData.Description;
44
+ this.AccountType = accountData.AccountType;
45
+ this.AccountSubtype = accountData.AccountSubtype;
46
+ this.OwnerId = accountData.OwnerId;
47
+ this.OwnerType = accountData.OwnerType;
48
+ this.RelatedObjectId = accountData.RelatedObjectId;
49
+ this.RelatedObjectType = accountData.RelatedObjectType;
50
+ this.AccSystemCode = accountData.AccSystemCode;
51
+ } else {
52
+ const notFoundError = new RecordNotFoundError('No Record Found.');
53
+ throw notFoundError;
54
+ }
55
+ } else if (accountRepository || accountNo) {
56
+ throw new Error('AccountNo and AccountRepository both are required.');
52
57
  }
53
58
  }
54
59
 
@@ -1,4 +1,4 @@
1
- import { IBaseRepository } from '@tomei/general';
2
- import { AccountModel } from '../entities/account.entity';
3
-
4
- export type IAccountRepository = IBaseRepository<AccountModel>;
1
+ import { IBaseRepository } from '@tomei/general';
2
+ import { AccountModel } from '../entities/account.entity';
3
+
4
+ export type IAccountRepository = IBaseRepository<AccountModel>;