gemcap-be-common 1.5.167 → 1.5.169
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/Borrower.model.ts +0 -1
- package/models/ProductBroker.model.d.ts +32 -19
- package/models/ProductBroker.model.js +16 -4
- package/models/ProductBroker.model.ts +28 -8
- package/package.json +1 -1
- package/services/borrowers.service.d.ts +2 -2
- package/services/brokers.service.js +2 -0
- package/services/brokers.service.ts +3 -1
- package/services/loan-transactions.service.d.ts +1 -1
- package/services/quickbooks.service.js +13 -10
- package/services/quickbooks.service.ts +14 -10
- package/tsconfig.tsbuildinfo +1 -1
package/models/Borrower.model.ts
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
/// <reference types="mongoose/types/inferschematype" />
|
|
25
25
|
import mongoose from 'mongoose';
|
|
26
26
|
import Joi from 'joi';
|
|
27
|
-
import { ILoanBrokerLean } from './LoanBroker.model';
|
|
27
|
+
import { ILoanBrokerLean, ILoanBrokerPlain } from './LoanBroker.model';
|
|
28
28
|
export declare const ProductBrokerValidationSchema: Joi.ObjectSchema<any>;
|
|
29
29
|
export interface IProductBroker {
|
|
30
30
|
uiId: string;
|
|
@@ -32,8 +32,10 @@ export interface IProductBroker {
|
|
|
32
32
|
borrowerId: mongoose.Types.ObjectId;
|
|
33
33
|
active: boolean;
|
|
34
34
|
loanBrokerId: mongoose.Types.ObjectId;
|
|
35
|
-
BSCode
|
|
36
|
-
|
|
35
|
+
BSCode?: string;
|
|
36
|
+
BSCodeId: mongoose.Types.ObjectId;
|
|
37
|
+
PLCode?: string;
|
|
38
|
+
PLCodeId: mongoose.Types.ObjectId;
|
|
37
39
|
productId: mongoose.Types.ObjectId;
|
|
38
40
|
baseInterestTotal: number;
|
|
39
41
|
interestShare: number;
|
|
@@ -46,15 +48,20 @@ export interface IProductBrokerLean extends IProductBroker {
|
|
|
46
48
|
createdAt: Date;
|
|
47
49
|
updatedAt: Date;
|
|
48
50
|
}
|
|
49
|
-
export interface IProductBrokerPlain extends Omit<IProductBroker, 'borrowerId' | 'loanBrokerId' | 'productId'> {
|
|
51
|
+
export interface IProductBrokerPlain extends Omit<IProductBroker, 'borrowerId' | 'loanBrokerId' | 'productId' | 'BSCodeId' | 'PLCodeId'> {
|
|
50
52
|
_id: string;
|
|
51
53
|
borrowerId: string;
|
|
52
54
|
loanBrokerId: string;
|
|
53
55
|
productId: string;
|
|
56
|
+
BSCodeId: string;
|
|
57
|
+
PLCodeId: string;
|
|
54
58
|
}
|
|
55
59
|
export interface IProductBrokerDocWithLoanBroker extends TProductBrokerDoc {
|
|
56
60
|
loanBroker: ILoanBrokerLean;
|
|
57
61
|
}
|
|
62
|
+
export interface IProductBrokerWithLoanBrokerPlain extends IProductBrokerPlain {
|
|
63
|
+
loanBroker: ILoanBrokerPlain;
|
|
64
|
+
}
|
|
58
65
|
export type IProductBrokerView = Omit<IProductBrokerLean, 'borrowerId' | 'order'>;
|
|
59
66
|
export type TProductBrokerModel = mongoose.Model<IProductBroker>;
|
|
60
67
|
export declare const ProductBrokerSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
@@ -63,52 +70,58 @@ export declare const ProductBrokerSchema: mongoose.Schema<any, mongoose.Model<an
|
|
|
63
70
|
createdAt: NativeDate;
|
|
64
71
|
updatedAt: NativeDate;
|
|
65
72
|
} & {
|
|
66
|
-
|
|
67
|
-
productId: mongoose.Types.ObjectId;
|
|
73
|
+
uiId: string;
|
|
68
74
|
order: number;
|
|
75
|
+
borrowerId: mongoose.Types.ObjectId;
|
|
69
76
|
active: boolean;
|
|
70
|
-
PLCode: string;
|
|
71
|
-
uiId: string;
|
|
72
77
|
loanBrokerId: mongoose.Types.ObjectId;
|
|
73
|
-
|
|
78
|
+
BSCodeId: mongoose.Types.ObjectId;
|
|
79
|
+
PLCodeId: mongoose.Types.ObjectId;
|
|
80
|
+
productId: mongoose.Types.ObjectId;
|
|
74
81
|
baseInterestTotal: number;
|
|
75
82
|
interestShare: number;
|
|
76
83
|
adminShare: number;
|
|
77
84
|
otherShare: number;
|
|
85
|
+
BSCode?: string;
|
|
86
|
+
PLCode?: string;
|
|
78
87
|
__v?: number;
|
|
79
88
|
}, mongoose.Document<unknown, {}, mongoose.FlatRecord<{
|
|
80
89
|
createdAt: NativeDate;
|
|
81
90
|
updatedAt: NativeDate;
|
|
82
91
|
} & {
|
|
83
|
-
|
|
84
|
-
productId: mongoose.Types.ObjectId;
|
|
92
|
+
uiId: string;
|
|
85
93
|
order: number;
|
|
94
|
+
borrowerId: mongoose.Types.ObjectId;
|
|
86
95
|
active: boolean;
|
|
87
|
-
PLCode: string;
|
|
88
|
-
uiId: string;
|
|
89
96
|
loanBrokerId: mongoose.Types.ObjectId;
|
|
90
|
-
|
|
97
|
+
BSCodeId: mongoose.Types.ObjectId;
|
|
98
|
+
PLCodeId: mongoose.Types.ObjectId;
|
|
99
|
+
productId: mongoose.Types.ObjectId;
|
|
91
100
|
baseInterestTotal: number;
|
|
92
101
|
interestShare: number;
|
|
93
102
|
adminShare: number;
|
|
94
103
|
otherShare: number;
|
|
104
|
+
BSCode?: string;
|
|
105
|
+
PLCode?: string;
|
|
95
106
|
__v?: number;
|
|
96
107
|
}>> & mongoose.FlatRecord<{
|
|
97
108
|
createdAt: NativeDate;
|
|
98
109
|
updatedAt: NativeDate;
|
|
99
110
|
} & {
|
|
100
|
-
|
|
101
|
-
productId: mongoose.Types.ObjectId;
|
|
111
|
+
uiId: string;
|
|
102
112
|
order: number;
|
|
113
|
+
borrowerId: mongoose.Types.ObjectId;
|
|
103
114
|
active: boolean;
|
|
104
|
-
PLCode: string;
|
|
105
|
-
uiId: string;
|
|
106
115
|
loanBrokerId: mongoose.Types.ObjectId;
|
|
107
|
-
|
|
116
|
+
BSCodeId: mongoose.Types.ObjectId;
|
|
117
|
+
PLCodeId: mongoose.Types.ObjectId;
|
|
118
|
+
productId: mongoose.Types.ObjectId;
|
|
108
119
|
baseInterestTotal: number;
|
|
109
120
|
interestShare: number;
|
|
110
121
|
adminShare: number;
|
|
111
122
|
otherShare: number;
|
|
123
|
+
BSCode?: string;
|
|
124
|
+
PLCode?: string;
|
|
112
125
|
__v?: number;
|
|
113
126
|
}> & {
|
|
114
127
|
_id: mongoose.Types.ObjectId;
|
|
@@ -14,8 +14,10 @@ exports.ProductBrokerValidationSchema = joi_1.default.object({
|
|
|
14
14
|
borrowerId: joi_1.default.string().required(),
|
|
15
15
|
active: joi_1.default.boolean().required(),
|
|
16
16
|
loanBrokerId: joi_1.default.string().required(),
|
|
17
|
-
BSCode: joi_1.default.string().
|
|
18
|
-
|
|
17
|
+
BSCode: joi_1.default.string().optional(),
|
|
18
|
+
BSCodeId: joi_1.default.string().required(),
|
|
19
|
+
PLCode: joi_1.default.string().optional(),
|
|
20
|
+
PLCodeId: joi_1.default.string().required(),
|
|
19
21
|
productId: joi_1.default.string().required(),
|
|
20
22
|
baseInterestTotal: joi_1.default.number().required(),
|
|
21
23
|
interestShare: joi_1.default.number().required(),
|
|
@@ -48,14 +50,24 @@ exports.ProductBrokerSchema = new mongoose_1.default.Schema({
|
|
|
48
50
|
},
|
|
49
51
|
BSCode: {
|
|
50
52
|
type: String,
|
|
51
|
-
required:
|
|
53
|
+
required: false,
|
|
52
54
|
trim: true,
|
|
53
55
|
},
|
|
56
|
+
BSCodeId: {
|
|
57
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
58
|
+
ref: _models_1.MODEL_NAMES.quickbooksAccounts,
|
|
59
|
+
required: true,
|
|
60
|
+
},
|
|
54
61
|
PLCode: {
|
|
55
62
|
type: String,
|
|
56
|
-
required:
|
|
63
|
+
required: false,
|
|
57
64
|
trim: true,
|
|
58
65
|
},
|
|
66
|
+
PLCodeId: {
|
|
67
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
68
|
+
ref: _models_1.MODEL_NAMES.quickbooksAccounts,
|
|
69
|
+
required: true,
|
|
70
|
+
},
|
|
59
71
|
productId: {
|
|
60
72
|
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
61
73
|
ref: _models_1.MODEL_NAMES.loanProducts,
|
|
@@ -2,7 +2,7 @@ import mongoose from 'mongoose';
|
|
|
2
2
|
import Joi from 'joi';
|
|
3
3
|
|
|
4
4
|
import { MODEL_NAMES } from './_models';
|
|
5
|
-
import { ILoanBrokerLean } from './LoanBroker.model';
|
|
5
|
+
import { ILoanBrokerLean, ILoanBrokerPlain } from './LoanBroker.model';
|
|
6
6
|
|
|
7
7
|
export const ProductBrokerValidationSchema = Joi.object({
|
|
8
8
|
_id: Joi.string(),
|
|
@@ -11,8 +11,10 @@ export const ProductBrokerValidationSchema = Joi.object({
|
|
|
11
11
|
borrowerId: Joi.string().required(),
|
|
12
12
|
active: Joi.boolean().required(),
|
|
13
13
|
loanBrokerId: Joi.string().required(),
|
|
14
|
-
BSCode: Joi.string().
|
|
15
|
-
|
|
14
|
+
BSCode: Joi.string().optional(),
|
|
15
|
+
BSCodeId: Joi.string().required(),
|
|
16
|
+
PLCode: Joi.string().optional(),
|
|
17
|
+
PLCodeId: Joi.string().required(),
|
|
16
18
|
productId: Joi.string().required(),
|
|
17
19
|
baseInterestTotal: Joi.number().required(),
|
|
18
20
|
interestShare: Joi.number().required(),
|
|
@@ -26,8 +28,10 @@ export interface IProductBroker {
|
|
|
26
28
|
borrowerId: mongoose.Types.ObjectId;
|
|
27
29
|
active: boolean;
|
|
28
30
|
loanBrokerId: mongoose.Types.ObjectId;
|
|
29
|
-
BSCode
|
|
30
|
-
|
|
31
|
+
BSCode?: string;
|
|
32
|
+
BSCodeId: mongoose.Types.ObjectId;
|
|
33
|
+
PLCode?: string;
|
|
34
|
+
PLCodeId: mongoose.Types.ObjectId;
|
|
31
35
|
productId: mongoose.Types.ObjectId;
|
|
32
36
|
baseInterestTotal: number;
|
|
33
37
|
interestShare: number;
|
|
@@ -43,17 +47,23 @@ export interface IProductBrokerLean extends IProductBroker {
|
|
|
43
47
|
updatedAt: Date;
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
export interface IProductBrokerPlain extends Omit<IProductBroker, 'borrowerId' | 'loanBrokerId' | 'productId'> {
|
|
50
|
+
export interface IProductBrokerPlain extends Omit<IProductBroker, 'borrowerId' | 'loanBrokerId' | 'productId' | 'BSCodeId' | 'PLCodeId'> {
|
|
47
51
|
_id: string;
|
|
48
52
|
borrowerId: string;
|
|
49
53
|
loanBrokerId: string;
|
|
50
54
|
productId: string;
|
|
55
|
+
BSCodeId: string;
|
|
56
|
+
PLCodeId: string;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
export interface IProductBrokerDocWithLoanBroker extends TProductBrokerDoc {
|
|
54
60
|
loanBroker: ILoanBrokerLean;
|
|
55
61
|
}
|
|
56
62
|
|
|
63
|
+
export interface IProductBrokerWithLoanBrokerPlain extends IProductBrokerPlain {
|
|
64
|
+
loanBroker: ILoanBrokerPlain;
|
|
65
|
+
}
|
|
66
|
+
|
|
57
67
|
export type IProductBrokerView = Omit<IProductBrokerLean, 'borrowerId' | 'order'>
|
|
58
68
|
|
|
59
69
|
export type TProductBrokerModel = mongoose.Model<IProductBroker>;
|
|
@@ -85,14 +95,24 @@ export const ProductBrokerSchema = new mongoose.Schema(
|
|
|
85
95
|
},
|
|
86
96
|
BSCode: {
|
|
87
97
|
type: String,
|
|
88
|
-
required:
|
|
98
|
+
required: false,
|
|
89
99
|
trim: true,
|
|
90
100
|
},
|
|
101
|
+
BSCodeId: {
|
|
102
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
103
|
+
ref: MODEL_NAMES.quickbooksAccounts,
|
|
104
|
+
required: true,
|
|
105
|
+
},
|
|
91
106
|
PLCode: {
|
|
92
107
|
type: String,
|
|
93
|
-
required:
|
|
108
|
+
required: false,
|
|
94
109
|
trim: true,
|
|
95
110
|
},
|
|
111
|
+
PLCodeId: {
|
|
112
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
113
|
+
ref: MODEL_NAMES.quickbooksAccounts,
|
|
114
|
+
required: true,
|
|
115
|
+
},
|
|
96
116
|
productId: {
|
|
97
117
|
type: mongoose.Schema.Types.ObjectId,
|
|
98
118
|
ref: MODEL_NAMES.loanProducts,
|
package/package.json
CHANGED
|
@@ -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
|
-
SELECTED_PERIOD?: boolean;
|
|
88
87
|
ENTIRE_LOAN?: boolean;
|
|
89
|
-
|
|
88
|
+
SELECTED_PERIOD?: boolean;
|
|
90
89
|
CURRENT_MONTH?: boolean;
|
|
90
|
+
LAST_MONTH?: boolean;
|
|
91
91
|
TERM_LOAN?: boolean;
|
|
92
92
|
};
|
|
93
93
|
}>;
|
|
@@ -24,6 +24,8 @@ const defaultBrokerList: BrokerView[] = [
|
|
|
24
24
|
active: true,
|
|
25
25
|
BSCode: '',
|
|
26
26
|
PLCode: '',
|
|
27
|
+
BSCodeId: null,
|
|
28
|
+
PLCodeId: null,
|
|
27
29
|
productId: null,
|
|
28
30
|
loanBrokerId: null,
|
|
29
31
|
baseInterestTotal: 0,
|
|
@@ -31,7 +33,7 @@ const defaultBrokerList: BrokerView[] = [
|
|
|
31
33
|
interestShare: 0,
|
|
32
34
|
otherShare: 0,
|
|
33
35
|
},
|
|
34
|
-
];
|
|
36
|
+
] satisfies BrokerView[];
|
|
35
37
|
|
|
36
38
|
type ShareType = 'adminShare' | 'interestShare' | 'otherShare';
|
|
37
39
|
|
|
@@ -164,7 +164,7 @@ export declare class LoanTransactionsService {
|
|
|
164
164
|
getTransactionReport(transactionIds: string[], borrowerId: string, effectiveDate: Date): Promise<{
|
|
165
165
|
transactionIdsToMark: string[];
|
|
166
166
|
transactions: {
|
|
167
|
-
[x: string]: (string | number |
|
|
167
|
+
[x: string]: (string | number | string[] | Date)[];
|
|
168
168
|
}[];
|
|
169
169
|
}>;
|
|
170
170
|
getBorrowerIdsForFile(transactionFileId: string): Promise<{
|
|
@@ -311,12 +311,13 @@ class QuickbooksService {
|
|
|
311
311
|
if (reportErrorsSet.size > 0) {
|
|
312
312
|
return { reportData: [], reportErrors: Array.from(reportErrorsSet) };
|
|
313
313
|
}
|
|
314
|
+
const accounts = await QuickbooksAccount_model_1.QuickbooksAccount.find({}).lean().exec();
|
|
314
315
|
const companyFilter = { companyId: { $in: params.companyIds.map((id) => new mongoose_1.default.Types.ObjectId(id)) } };
|
|
315
316
|
const { reportType, productIds, chargeTypes, reportDate } = params;
|
|
316
317
|
const reportDateFormatted = dayjs_1.default.utc(reportDate).format('MM/DD/YYYY').toUpperCase();
|
|
317
318
|
const reportDateTrFormatted = dayjs_1.default.utc(reportDate).format(transactionsDateFormat).toUpperCase();
|
|
318
319
|
const currentDateTrFormatted = dayjs_1.default.utc(new Date).format(transactionsDateFormat).toUpperCase();
|
|
319
|
-
const
|
|
320
|
+
const isAccrualReport = reportType === 'accrual';
|
|
320
321
|
const mainData = [];
|
|
321
322
|
const trTemplate = {
|
|
322
323
|
service: 'SPL',
|
|
@@ -336,7 +337,7 @@ class QuickbooksService {
|
|
|
336
337
|
const filteredCharges = charges.filter((charge) => chargeTypes.includes(charge.chargeType));
|
|
337
338
|
const productBrokers = await this.brokersService.getProductBrokers(productId);
|
|
338
339
|
const borrower = await Borrower_model_1.BorrowerModel.findById(product.borrowerId).lean();
|
|
339
|
-
const allTransactions =
|
|
340
|
+
const allTransactions = isAccrualReport
|
|
340
341
|
? await this.getChargeTransactionsForAccrual([productId], reportDate)
|
|
341
342
|
: await this.getChargeTransactionsForPayments([productId], reportDate);
|
|
342
343
|
await Promise.all(filteredCharges.map(async (charge) => {
|
|
@@ -344,7 +345,7 @@ class QuickbooksService {
|
|
|
344
345
|
if (!chargeTransactions.length) {
|
|
345
346
|
return;
|
|
346
347
|
}
|
|
347
|
-
const totalAmountGroups =
|
|
348
|
+
const totalAmountGroups = isAccrualReport
|
|
348
349
|
? { [charge.PLCode]: chargeTransactions.reduce((acc, tr) => new decimal_js_1.default(acc).add(tr.amount).toNumber(), 0) }
|
|
349
350
|
: chargeTransactions.reduce((acc, tr) => {
|
|
350
351
|
if (tr.settlementCode) {
|
|
@@ -363,7 +364,7 @@ class QuickbooksService {
|
|
|
363
364
|
return;
|
|
364
365
|
}
|
|
365
366
|
let totalAmount = product.masterLoanProductId != null ? -totalAmountValue : totalAmountValue;
|
|
366
|
-
totalAmount =
|
|
367
|
+
totalAmount = isAccrualReport ? totalAmount : -totalAmount;
|
|
367
368
|
const quickbooksAccountBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
|
|
368
369
|
const quickbooksAccountPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
|
|
369
370
|
if (!quickbooksAccountBS || !quickbooksAccountPL) {
|
|
@@ -387,16 +388,18 @@ class QuickbooksService {
|
|
|
387
388
|
tr.account = quickbooksAccountPL.fullName;
|
|
388
389
|
tr.amount = -totalAmount;
|
|
389
390
|
mainData.push({ ...tr });
|
|
390
|
-
if (chargeTypes.includes('BROKERS') &&
|
|
391
|
+
if (chargeTypes.includes('BROKERS') && isAccrualReport) {
|
|
391
392
|
const handleFee = async (broker, shareName) => {
|
|
392
|
-
const quickbooksAccountBrokerBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({
|
|
393
|
-
const quickbooksAccountBrokerPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({
|
|
393
|
+
const quickbooksAccountBrokerBS = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ _id: broker.BSCodeId, ...companyFilter }).lean();
|
|
394
|
+
const quickbooksAccountBrokerPL = await QuickbooksAccount_model_1.QuickbooksAccount.findOne({ _id: broker.PLCodeId, ...companyFilter }).lean();
|
|
394
395
|
if (!quickbooksAccountBrokerBS || !quickbooksAccountBrokerPL) {
|
|
395
396
|
if (!quickbooksAccountBrokerBS) {
|
|
396
|
-
|
|
397
|
+
const foundAccount = accounts.find((a) => a._id === broker.BSCodeId);
|
|
398
|
+
reportErrorsSet.add(foundAccount?.accountCode ?? broker.BSCode);
|
|
397
399
|
}
|
|
398
400
|
if (!quickbooksAccountBrokerPL) {
|
|
399
|
-
|
|
401
|
+
const foundAccount = accounts.find((a) => a._id === broker.PLCodeId);
|
|
402
|
+
reportErrorsSet.add(foundAccount?.accountCode ?? broker.PLCode);
|
|
400
403
|
}
|
|
401
404
|
return;
|
|
402
405
|
}
|
|
@@ -433,7 +436,7 @@ class QuickbooksService {
|
|
|
433
436
|
}
|
|
434
437
|
}));
|
|
435
438
|
}));
|
|
436
|
-
const principalPayments =
|
|
439
|
+
const principalPayments = isAccrualReport || product.type === loan_types_enum_1.ELoanTypes.REVOLVER
|
|
437
440
|
? {}
|
|
438
441
|
: await this.getPrincipalTransactionsForPayments(productId, reportDate);
|
|
439
442
|
await Promise.all(Object.entries(principalPayments).map(async ([settlementCode, amount]) => {
|
|
@@ -362,13 +362,15 @@ export class QuickbooksService {
|
|
|
362
362
|
return { reportData: [], reportErrors: Array.from(reportErrorsSet) };
|
|
363
363
|
}
|
|
364
364
|
|
|
365
|
+
const accounts = await QuickbooksAccount.find({}).lean().exec();
|
|
366
|
+
|
|
365
367
|
const companyFilter = { companyId: { $in: params.companyIds.map((id) => new mongoose.Types.ObjectId(id)) } };
|
|
366
368
|
|
|
367
369
|
const { reportType, productIds, chargeTypes, reportDate } = params;
|
|
368
370
|
const reportDateFormatted = dayjs.utc(reportDate).format('MM/DD/YYYY').toUpperCase();
|
|
369
371
|
const reportDateTrFormatted = dayjs.utc(reportDate).format(transactionsDateFormat).toUpperCase();
|
|
370
372
|
const currentDateTrFormatted = dayjs.utc(new Date).format(transactionsDateFormat).toUpperCase();
|
|
371
|
-
const
|
|
373
|
+
const isAccrualReport = reportType === 'accrual';
|
|
372
374
|
const mainData: IQBReportTransaction[] = [];
|
|
373
375
|
|
|
374
376
|
const trTemplate: IQBReportTransaction = {
|
|
@@ -392,7 +394,7 @@ export class QuickbooksService {
|
|
|
392
394
|
const productBrokers = await this.brokersService.getProductBrokers(productId);
|
|
393
395
|
const borrower = await BorrowerModel.findById(product.borrowerId).lean();
|
|
394
396
|
|
|
395
|
-
const allTransactions =
|
|
397
|
+
const allTransactions = isAccrualReport
|
|
396
398
|
? await this.getChargeTransactionsForAccrual([productId], reportDate)
|
|
397
399
|
: await this.getChargeTransactionsForPayments([productId], reportDate);
|
|
398
400
|
|
|
@@ -402,7 +404,7 @@ export class QuickbooksService {
|
|
|
402
404
|
return;
|
|
403
405
|
}
|
|
404
406
|
|
|
405
|
-
const totalAmountGroups =
|
|
407
|
+
const totalAmountGroups = isAccrualReport
|
|
406
408
|
? { [charge.PLCode]: chargeTransactions.reduce((acc, tr) => new Decimal(acc).add(tr.amount).toNumber(), 0) }
|
|
407
409
|
: chargeTransactions.reduce((acc, tr) => {
|
|
408
410
|
if (tr.settlementCode) {
|
|
@@ -422,7 +424,7 @@ export class QuickbooksService {
|
|
|
422
424
|
return;
|
|
423
425
|
}
|
|
424
426
|
let totalAmount = product.masterLoanProductId != null ? -totalAmountValue : totalAmountValue;
|
|
425
|
-
totalAmount =
|
|
427
|
+
totalAmount = isAccrualReport ? totalAmount : -totalAmount;
|
|
426
428
|
const quickbooksAccountBS = await QuickbooksAccount.findOne({ accountCode: charge.code, ...companyFilter }).lean();
|
|
427
429
|
const quickbooksAccountPL = await QuickbooksAccount.findOne({ accountCode: PLCode, ...companyFilter }).lean();
|
|
428
430
|
if (!quickbooksAccountBS || !quickbooksAccountPL) {
|
|
@@ -449,18 +451,20 @@ export class QuickbooksService {
|
|
|
449
451
|
tr.amount = -totalAmount;
|
|
450
452
|
mainData.push({ ...tr });
|
|
451
453
|
|
|
452
|
-
if (chargeTypes.includes('BROKERS') &&
|
|
454
|
+
if (chargeTypes.includes('BROKERS') && isAccrualReport) {
|
|
453
455
|
|
|
454
456
|
const handleFee = async (broker: IProductBrokerDocWithLoanBroker, shareName: 'adminShare' | 'interestShare' | 'otherShare') => {
|
|
455
457
|
|
|
456
|
-
const quickbooksAccountBrokerBS = await QuickbooksAccount.findOne({
|
|
457
|
-
const quickbooksAccountBrokerPL = await QuickbooksAccount.findOne({
|
|
458
|
+
const quickbooksAccountBrokerBS = await QuickbooksAccount.findOne({ _id: broker.BSCodeId, ...companyFilter }).lean();
|
|
459
|
+
const quickbooksAccountBrokerPL = await QuickbooksAccount.findOne({ _id: broker.PLCodeId, ...companyFilter }).lean();
|
|
458
460
|
if (!quickbooksAccountBrokerBS || !quickbooksAccountBrokerPL) {
|
|
459
461
|
if (!quickbooksAccountBrokerBS) {
|
|
460
|
-
|
|
462
|
+
const foundAccount = accounts.find((a) => a._id === broker.BSCodeId);
|
|
463
|
+
reportErrorsSet.add(foundAccount?.accountCode ?? broker.BSCode);
|
|
461
464
|
}
|
|
462
465
|
if (!quickbooksAccountBrokerPL) {
|
|
463
|
-
|
|
466
|
+
const foundAccount = accounts.find((a) => a._id === broker.PLCodeId);
|
|
467
|
+
reportErrorsSet.add(foundAccount?.accountCode ?? broker.PLCode);
|
|
464
468
|
}
|
|
465
469
|
return;
|
|
466
470
|
}
|
|
@@ -503,7 +507,7 @@ export class QuickbooksService {
|
|
|
503
507
|
}));
|
|
504
508
|
}));
|
|
505
509
|
|
|
506
|
-
const principalPayments =
|
|
510
|
+
const principalPayments = isAccrualReport || product.type === ELoanTypes.REVOLVER
|
|
507
511
|
? {}
|
|
508
512
|
: await this.getPrincipalTransactionsForPayments(productId, reportDate);
|
|
509
513
|
|