gemcap-be-common 1.4.117 → 1.4.119
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/models/Banks.model.d.ts +21 -50
- package/models/Banks.model.js +0 -4
- package/models/Banks.model.ts +25 -9
- package/package.json +1 -1
- package/services/banks.service.d.ts +1 -1
- package/services/borrowers.service.d.ts +2 -2
- package/services/brokers.service.d.ts +2 -2
- package/services/loan-statement.service.js +5 -4
- package/services/loan-statement.service.ts +80 -79
- package/tsconfig.tsbuildinfo +1 -1
package/models/Banks.model.d.ts
CHANGED
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
/// <reference types="mongoose/types/validation" />
|
|
23
23
|
/// <reference types="mongoose/types/virtuals" />
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
-
import mongoose, { Document } from 'mongoose';
|
|
25
|
+
import mongoose, { Document, Model } from 'mongoose';
|
|
26
26
|
export interface IBank {
|
|
27
27
|
isDeleted?: boolean;
|
|
28
28
|
active: boolean;
|
|
@@ -36,56 +36,27 @@ export interface IBank {
|
|
|
36
36
|
export interface IBankWithId extends IBank {
|
|
37
37
|
_id: mongoose.Types.ObjectId;
|
|
38
38
|
}
|
|
39
|
-
export type IBankView = Omit<IBankWithId, 'order'>;
|
|
40
39
|
export interface IBankDoc extends IBank, Document {
|
|
40
|
+
_id: mongoose.Types.ObjectId;
|
|
41
|
+
createdAt: Date;
|
|
42
|
+
updatedAt: Date;
|
|
41
43
|
}
|
|
42
|
-
export
|
|
43
|
-
timestamps: true;
|
|
44
|
-
}, {
|
|
45
|
-
createdAt: NativeDate;
|
|
46
|
-
updatedAt: NativeDate;
|
|
47
|
-
} & {
|
|
48
|
-
name: string;
|
|
49
|
-
order: number;
|
|
50
|
-
isDeleted: boolean;
|
|
51
|
-
active: boolean;
|
|
52
|
-
bankAccountNumber: string;
|
|
53
|
-
ledgerAccountCodes: Map<string, {
|
|
54
|
-
type?: mongoose.Types.ObjectId;
|
|
55
|
-
ref?: unknown;
|
|
56
|
-
}>;
|
|
57
|
-
__v?: number;
|
|
58
|
-
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
59
|
-
createdAt: NativeDate;
|
|
60
|
-
updatedAt: NativeDate;
|
|
61
|
-
} & {
|
|
62
|
-
name: string;
|
|
63
|
-
order: number;
|
|
64
|
-
isDeleted: boolean;
|
|
65
|
-
active: boolean;
|
|
66
|
-
bankAccountNumber: string;
|
|
67
|
-
ledgerAccountCodes: Map<string, {
|
|
68
|
-
type?: mongoose.Types.ObjectId;
|
|
69
|
-
ref?: unknown;
|
|
70
|
-
}>;
|
|
71
|
-
__v?: number;
|
|
72
|
-
}>> & mongoose.FlatRecord<{
|
|
73
|
-
createdAt: NativeDate;
|
|
74
|
-
updatedAt: NativeDate;
|
|
75
|
-
} & {
|
|
76
|
-
name: string;
|
|
77
|
-
order: number;
|
|
78
|
-
isDeleted: boolean;
|
|
79
|
-
active: boolean;
|
|
80
|
-
bankAccountNumber: string;
|
|
81
|
-
ledgerAccountCodes: Map<string, {
|
|
82
|
-
type?: mongoose.Types.ObjectId;
|
|
83
|
-
ref?: unknown;
|
|
84
|
-
}>;
|
|
85
|
-
__v?: number;
|
|
86
|
-
}> & {
|
|
44
|
+
export interface IBankLean extends IBank {
|
|
87
45
|
_id: mongoose.Types.ObjectId;
|
|
88
|
-
|
|
89
|
-
|
|
46
|
+
createdAt: Date;
|
|
47
|
+
updatedAt: Date;
|
|
48
|
+
}
|
|
49
|
+
export interface IBankPlain extends Omit<IBank, 'ledgerAccountCodes'> {
|
|
50
|
+
_id: string;
|
|
51
|
+
createdAt: Date;
|
|
52
|
+
updatedAt: Date;
|
|
53
|
+
ledgerAccountCodes: {
|
|
54
|
+
[companyId: string]: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export type IBankView = Omit<IBankWithId, 'order'>;
|
|
58
|
+
export type IBankModel = Model<IBank>;
|
|
59
|
+
export declare const BankSchema: mongoose.Schema<IBank, IBankModel, {}, {}, {}, {}, mongoose.DefaultSchemaOptions, IBank, mongoose.Document<unknown, {}, mongoose.FlatRecord<IBank>> & mongoose.FlatRecord<IBank> & {
|
|
90
60
|
_id: mongoose.Types.ObjectId;
|
|
91
|
-
}
|
|
61
|
+
}>;
|
|
62
|
+
export declare const Bank: IBankModel;
|
package/models/Banks.model.js
CHANGED
|
@@ -36,9 +36,5 @@ exports.BankSchema = new mongoose_1.default.Schema({
|
|
|
36
36
|
of: { type: mongoose_1.default.Schema.Types.ObjectId, ref: _models_1.MODEL_NAMES.quickbooksAccounts },
|
|
37
37
|
default: {},
|
|
38
38
|
},
|
|
39
|
-
__v: {
|
|
40
|
-
type: Number,
|
|
41
|
-
select: false
|
|
42
|
-
},
|
|
43
39
|
}, { timestamps: true });
|
|
44
40
|
exports.Bank = mongoose_1.default.model(_models_1.MODEL_NAMES.banks, exports.BankSchema);
|
package/models/Banks.model.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import mongoose, { Document } from 'mongoose';
|
|
1
|
+
import mongoose, { Document, Model } from 'mongoose';
|
|
2
2
|
|
|
3
3
|
import { MODEL_NAMES } from './_models';
|
|
4
4
|
|
|
@@ -17,12 +17,32 @@ export interface IBankWithId extends IBank {
|
|
|
17
17
|
_id: mongoose.Types.ObjectId;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
export type IBankView = Omit<IBankWithId, 'order'>
|
|
21
|
-
|
|
22
20
|
export interface IBankDoc extends IBank, Document {
|
|
21
|
+
_id: mongoose.Types.ObjectId;
|
|
22
|
+
createdAt: Date;
|
|
23
|
+
updatedAt: Date;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface IBankLean extends IBank {
|
|
27
|
+
_id: mongoose.Types.ObjectId;
|
|
28
|
+
createdAt: Date;
|
|
29
|
+
updatedAt: Date;
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
export
|
|
32
|
+
export interface IBankPlain extends Omit<IBank, 'ledgerAccountCodes'> {
|
|
33
|
+
_id: string;
|
|
34
|
+
createdAt: Date;
|
|
35
|
+
updatedAt: Date;
|
|
36
|
+
ledgerAccountCodes: {
|
|
37
|
+
[companyId: string]: string;
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type IBankView = Omit<IBankWithId, 'order'>
|
|
42
|
+
|
|
43
|
+
export type IBankModel = Model<IBank>;
|
|
44
|
+
|
|
45
|
+
export const BankSchema = new mongoose.Schema<IBank, IBankModel>(
|
|
26
46
|
{
|
|
27
47
|
isDeleted: {
|
|
28
48
|
type: Boolean,
|
|
@@ -53,12 +73,8 @@ export const BankSchema = new mongoose.Schema(
|
|
|
53
73
|
of: { type: mongoose.Schema.Types.ObjectId, ref: MODEL_NAMES.quickbooksAccounts },
|
|
54
74
|
default: {},
|
|
55
75
|
},
|
|
56
|
-
__v: {
|
|
57
|
-
type: Number,
|
|
58
|
-
select: false
|
|
59
|
-
},
|
|
60
76
|
},
|
|
61
77
|
{ timestamps: true },
|
|
62
78
|
);
|
|
63
79
|
|
|
64
|
-
export const Bank = mongoose.model<
|
|
80
|
+
export const Bank = mongoose.model<IBank, IBankModel>(MODEL_NAMES.banks, BankSchema);
|
package/package.json
CHANGED
|
@@ -28,7 +28,7 @@ export declare class BanksService {
|
|
|
28
28
|
getBanks(): Promise<IBankView[]>;
|
|
29
29
|
createBank(bank: IBankView): Promise<void>;
|
|
30
30
|
editBank(bank: IBankView): Promise<void>;
|
|
31
|
-
findBankByNumber(bankAccountNumber: string): Promise<import("mongoose").FlattenMaps<import("../models/Banks.model").
|
|
31
|
+
findBankByNumber(bankAccountNumber: string): Promise<import("mongoose").FlattenMaps<import("../models/Banks.model").IBank> & {
|
|
32
32
|
_id: import("mongoose").Types.ObjectId;
|
|
33
33
|
}>;
|
|
34
34
|
findBankByAccountCode(accountCode: string): Promise<IBankWithId>;
|
|
@@ -84,10 +84,10 @@ export declare class BorrowerService {
|
|
|
84
84
|
getBorrowerCodesMap(): Promise<Map<string, string>>;
|
|
85
85
|
getBorrowerStatementDetails(borrowers: IBorrowerDoc[]): Promise<{
|
|
86
86
|
[x: string]: {
|
|
87
|
-
LAST_MONTH?: boolean;
|
|
88
|
-
CURRENT_MONTH?: boolean;
|
|
89
87
|
ENTIRE_LOAN?: boolean;
|
|
90
88
|
SELECTED_PERIOD?: boolean;
|
|
89
|
+
CURRENT_MONTH?: boolean;
|
|
90
|
+
LAST_MONTH?: boolean;
|
|
91
91
|
TERM_LOAN?: boolean;
|
|
92
92
|
};
|
|
93
93
|
}>;
|
|
@@ -46,9 +46,9 @@ export declare class BrokersService {
|
|
|
46
46
|
getAllProductBrokers(): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
|
|
47
47
|
_id: import("mongoose").Types.ObjectId;
|
|
48
48
|
})[]>;
|
|
49
|
-
getBorrowerBrokers(borrowerId: string): Promise<
|
|
49
|
+
getBorrowerBrokers(borrowerId: string): Promise<(import("mongoose").FlattenMaps<import("../models/ProductBroker.model").IProductBrokerDoc> & {
|
|
50
50
|
_id: import("mongoose").Types.ObjectId;
|
|
51
|
-
})[]>;
|
|
51
|
+
})[] | BrokerView[]>;
|
|
52
52
|
getProductBrokers(productId: string): Promise<import("../models/ProductBroker.model").IProductBrokerDocWithBroker[]>;
|
|
53
53
|
getTotalShares(borrowerId: string, brokers: IProductBrokerView[], replaceNames?: boolean): Promise<ProductTotal>;
|
|
54
54
|
getTotals(borrowerId: string): Promise<BrokerTotalView[]>;
|
|
@@ -776,7 +776,9 @@ class LoanStatementService {
|
|
|
776
776
|
const results = await Promise.all(borrowerIds.map(async (borrowerId) => {
|
|
777
777
|
const borrower = await Borrower_model_1.BorrowerModel.findById(borrowerId).lean();
|
|
778
778
|
const products = await this.loanChargesService.getLoanProducts(borrowerId);
|
|
779
|
-
return await Promise.all(products
|
|
779
|
+
return await Promise.all(products
|
|
780
|
+
.filter(product => !(0, dayjs_1.default)(product.deactivationDate).isBefore((0, dayjs_1.default)(selectedDate)))
|
|
781
|
+
.map(async (product) => {
|
|
780
782
|
if ((0, dayjs_1.default)(product.deactivationDate).isBefore((0, dayjs_1.default)(selectedDate))) {
|
|
781
783
|
return null;
|
|
782
784
|
}
|
|
@@ -855,9 +857,8 @@ class LoanStatementService {
|
|
|
855
857
|
}));
|
|
856
858
|
}));
|
|
857
859
|
return results
|
|
858
|
-
.
|
|
859
|
-
.
|
|
860
|
-
.sort((a, b) => (b.code.toUpperCase() < a.code.toUpperCase() ? 1 : -1));
|
|
860
|
+
.flat()
|
|
861
|
+
.sort((a, b) => a.code.toUpperCase().localeCompare(b.code.toUpperCase()));
|
|
861
862
|
}
|
|
862
863
|
async getOutstandingStatementsExcel(borrowerIds, selectedDate, fullMonth) {
|
|
863
864
|
const results = await this.getOutstandingStatements(borrowerIds, selectedDate, fullMonth);
|
|
@@ -831,7 +831,7 @@ export class LoanStatementService {
|
|
|
831
831
|
}
|
|
832
832
|
case ELoanTypes.TERM: {
|
|
833
833
|
data.termBalance = lastTransaction.balance ?? 0;
|
|
834
|
-
break
|
|
834
|
+
break;
|
|
835
835
|
}
|
|
836
836
|
}
|
|
837
837
|
}
|
|
@@ -870,92 +870,93 @@ export class LoanStatementService {
|
|
|
870
870
|
const results = await Promise.all(borrowerIds.map(async (borrowerId) => {
|
|
871
871
|
const borrower = await BorrowerModel.findById(borrowerId).lean();
|
|
872
872
|
const products = await this.loanChargesService.getLoanProducts(borrowerId);
|
|
873
|
-
return await Promise.all(products
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
actualBalance =
|
|
892
|
-
|
|
873
|
+
return await Promise.all(products
|
|
874
|
+
.filter(product => !dayjs(product.deactivationDate).isBefore(dayjs(selectedDate)))
|
|
875
|
+
.map(async (product) => {
|
|
876
|
+
if (dayjs(product.deactivationDate).isBefore(dayjs(selectedDate))) {
|
|
877
|
+
return null;
|
|
878
|
+
}
|
|
879
|
+
const relevantStatementEndMonth = fullMonth
|
|
880
|
+
? dayjs(selectedDate).utcOffset(0).startOf('month').subtract(1, 'seconds')
|
|
881
|
+
: dayjs(selectedDate).utcOffset(0).endOf('month');
|
|
882
|
+
const relevantStatementEnd = fullMonth
|
|
883
|
+
? dayjs(selectedDate).utcOffset(0).startOf('month').subtract(1, 'seconds')
|
|
884
|
+
: dayjs(selectedDate).utcOffset(0).endOf('day');
|
|
885
|
+
const relevantStatementStart = dayjs(selectedDate).utcOffset(0).startOf('month').subtract(1, 'seconds').startOf('month');
|
|
886
|
+
|
|
887
|
+
const paymentFilterEnd = dayjs(selectedDate).utcOffset(0).endOf('day');
|
|
888
|
+
const paymentFilterStart = relevantStatementStart;
|
|
889
|
+
|
|
890
|
+
const lastTransaction = await this.loanTransactionsService.getLastTransactionForDate(product._id.toString(), dayjs(selectedDate).endOf('day').toDate());
|
|
891
|
+
let actualBalance = 0;
|
|
892
|
+
if (lastTransaction) {
|
|
893
|
+
actualBalance = new Decimal(lastTransaction.balance).toDP(2).toNumber();
|
|
894
|
+
}
|
|
893
895
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
};
|
|
899
|
-
const paymentFilter = {
|
|
900
|
-
productIds: [product._id.toString()],
|
|
901
|
-
start: paymentFilterStart.toDate(),
|
|
902
|
-
end: paymentFilterEnd.toDate(),
|
|
903
|
-
};
|
|
904
|
-
const statementTransactions = await this.loanChargesService.getLoanStatementsForForProductWithCharges(statementFilter);
|
|
905
|
-
const statementPayments = await this.loanPaymentsService.getLoanPayments(paymentFilter, null);
|
|
906
|
-
const paidStatementIds = statementPayments.reduce((acc, s) => [...acc, ...s.paid.map((p) => p.statementId.toString())], []);
|
|
907
|
-
const fees = {
|
|
908
|
-
[ELoanChargeType.INTEREST_FEE]: 0,
|
|
909
|
-
[ELoanChargeType.ADMIN_FEE]: 0,
|
|
910
|
-
[ELoanChargeType.UNUSED_LINE_FEE]: 0,
|
|
911
|
-
[ELoanChargeType.WIRE_FEE]: 0,
|
|
912
|
-
[ELoanChargeType.OTHER]: 0,
|
|
913
|
-
[ELoanChargeType.RECOVERABLE]: 0,
|
|
914
|
-
[ELoanChargeType.ANNUAL_LINE_FEE]: 0,
|
|
915
|
-
};
|
|
916
|
-
const sumResults = statementTransactions.reduce((acc, t) => {
|
|
917
|
-
const amountPaid = paidStatementIds.includes(t._id.toString()) ? t.amountPaid : 0;
|
|
918
|
-
return {
|
|
919
|
-
...acc,
|
|
920
|
-
[t.charge.chargeType]: new Decimal(acc[t.charge.chargeType] ?? 0).add(t.amount ?? 0).sub(amountPaid ?? 0).toNumber(),
|
|
896
|
+
const statementFilter = {
|
|
897
|
+
productIds: [product._id.toString()],
|
|
898
|
+
start: relevantStatementStart.toDate(),
|
|
899
|
+
end: relevantStatementEnd.toDate(),
|
|
921
900
|
};
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
const
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
901
|
+
const paymentFilter = {
|
|
902
|
+
productIds: [product._id.toString()],
|
|
903
|
+
start: paymentFilterStart.toDate(),
|
|
904
|
+
end: paymentFilterEnd.toDate(),
|
|
905
|
+
};
|
|
906
|
+
const statementTransactions = await this.loanChargesService.getLoanStatementsForForProductWithCharges(statementFilter);
|
|
907
|
+
const statementPayments = await this.loanPaymentsService.getLoanPayments(paymentFilter, null);
|
|
908
|
+
const paidStatementIds = statementPayments.reduce((acc, s) => [...acc, ...s.paid.map((p) => p.statementId.toString())], []);
|
|
909
|
+
const fees = {
|
|
910
|
+
[ELoanChargeType.INTEREST_FEE]: 0,
|
|
911
|
+
[ELoanChargeType.ADMIN_FEE]: 0,
|
|
912
|
+
[ELoanChargeType.UNUSED_LINE_FEE]: 0,
|
|
913
|
+
[ELoanChargeType.WIRE_FEE]: 0,
|
|
914
|
+
[ELoanChargeType.OTHER]: 0,
|
|
915
|
+
[ELoanChargeType.RECOVERABLE]: 0,
|
|
916
|
+
[ELoanChargeType.ANNUAL_LINE_FEE]: 0,
|
|
917
|
+
};
|
|
918
|
+
const sumResults = statementTransactions.reduce((acc, t) => {
|
|
919
|
+
const amountPaid = paidStatementIds.includes(t._id.toString()) ? t.amountPaid : 0;
|
|
920
|
+
return {
|
|
921
|
+
...acc,
|
|
922
|
+
[t.charge.chargeType]: new Decimal(acc[t.charge.chargeType] ?? 0).add(t.amount ?? 0).sub(amountPaid ?? 0).toNumber(),
|
|
923
|
+
};
|
|
924
|
+
}, fees);
|
|
925
|
+
|
|
926
|
+
let principal = 0;
|
|
927
|
+
let principalExpectedDate = null;
|
|
928
|
+
if (product.type === ELoanTypes.TERM) {
|
|
929
|
+
const termLoan = await TermLoanModel.findOne({ productId: product._id.toString(), actual: true });
|
|
930
|
+
if (termLoan) {
|
|
931
|
+
const calculatedTermLoan = await TermLoanCalculatedModel.findOne({
|
|
932
|
+
termLoanId: termLoan._id.toString(),
|
|
933
|
+
relevantStatement: relevantStatementEndMonth.format('YYYY-MM-DD'),
|
|
934
|
+
});
|
|
935
|
+
if (calculatedTermLoan) {
|
|
936
|
+
if (calculatedTermLoan.payments && calculatedTermLoan.payments.length > 0) {
|
|
937
|
+
const totalPayment = calculatedTermLoan.payments.reduce((acc, p) => new Decimal(acc ?? 0).add(p.amount ?? 0).toNumber(), 0);
|
|
938
|
+
principal = new Decimal(calculatedTermLoan.monthlyPrincipal).sub(totalPayment).toDP(2).toNumber();
|
|
939
|
+
} else {
|
|
940
|
+
principal = calculatedTermLoan.monthlyPrincipal;
|
|
941
|
+
principalExpectedDate = calculatedTermLoan.paymentDueDate;
|
|
942
|
+
}
|
|
940
943
|
}
|
|
941
944
|
}
|
|
942
945
|
}
|
|
943
|
-
}
|
|
944
946
|
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
947
|
+
return {
|
|
948
|
+
borrowerCode: borrower.code,
|
|
949
|
+
...product,
|
|
950
|
+
actualBalance,
|
|
951
|
+
...sumResults,
|
|
952
|
+
principal,
|
|
953
|
+
principalExpectedDate,
|
|
954
|
+
};
|
|
955
|
+
}));
|
|
954
956
|
}));
|
|
955
957
|
return results
|
|
956
|
-
.
|
|
957
|
-
.
|
|
958
|
-
.sort((a, b) => (b.code.toUpperCase() < a.code.toUpperCase() ? 1 : -1));
|
|
958
|
+
.flat()
|
|
959
|
+
.sort((a, b) => a.code.toUpperCase().localeCompare(b.code.toUpperCase()));
|
|
959
960
|
}
|
|
960
961
|
|
|
961
962
|
async getOutstandingStatementsExcel(borrowerIds: string[], selectedDate: Date, fullMonth: boolean) {
|