gemcap-be-common 1.2.136 → 1.2.138
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/db/collaterals.db.d.ts +1 -1
- package/db/collaterals.db.js +2 -2
- package/db/collaterals.db.ts +2 -2
- package/db/financial-spreading.db.d.ts +34 -0
- package/db/financial-spreading.db.js +103 -0
- package/db/financial-spreading.db.ts +112 -0
- package/db/inventories.db.js +2 -2
- package/db/inventories.db.ts +2 -2
- package/db/loan-products.db.js +3 -4
- package/db/loan-products.db.ts +3 -4
- package/db/loan-transactions.db.d.ts +3 -1
- package/db/loan-transactions.db.js +62 -2
- package/db/loan-transactions.db.ts +72 -1
- package/db/receivables.db.js +1 -1
- package/db/receivables.db.ts +1 -1
- package/helpers/date.helper.d.ts +4 -0
- package/helpers/date.helper.js +6 -1
- package/helpers/date.helper.ts +5 -0
- package/models/AvilabilitySignedData.model.d.ts +33 -0
- package/models/AvilabilitySignedData.model.js +22 -0
- package/models/AvilabilitySignedData.model.ts +30 -0
- package/models/BorrowerSummary.model.d.ts +70 -0
- package/models/BorrowerSummary.model.js +37 -0
- package/models/BorrowerSummary.model.ts +72 -0
- package/models/FinancialSpreading.model.d.ts +76 -0
- package/models/FinancialSpreading.model.js +65 -0
- package/models/FinancialSpreading.model.ts +110 -0
- package/models/FinancialSpreadingSheet.model.d.ts +152 -0
- package/models/FinancialSpreadingSheet.model.js +207 -0
- package/models/FinancialSpreadingSheet.model.ts +240 -0
- package/models/LoanTransaction.model.d.ts +8 -0
- package/models/LoanTransaction.model.ts +9 -0
- package/models/PostponedTransactions.model.d.ts +3 -3
- package/models/ProspectIndustry.model.d.ts +35 -0
- package/models/ProspectIndustry.model.js +26 -0
- package/models/ProspectIndustry.model.ts +38 -0
- package/models/Yield.model.d.ts +46 -0
- package/models/Yield.model.js +20 -1
- package/models/Yield.model.ts +20 -0
- package/package.json +1 -1
- package/queries/inventory/extension.js +3 -3
- package/queries/inventory/extension.ts +3 -3
- package/queries/inventory/turn.js +3 -3
- package/queries/inventory/turn.ts +3 -3
- package/reports/new-summary.d.ts +0 -0
- package/reports/new-summary.js +1327 -0
- package/reports/new-summary.ts +1327 -0
- package/services/users.service.d.ts +3 -3
- package/services/users.service.js +3 -3
- package/services/users.service.ts +4 -4
- package/services/yield.service.d.ts +53 -0
- package/services/yield.service.js +161 -0
- package/services/yield.service.ts +198 -0
- package/tsconfig.tsbuildinfo +1 -1
package/db/collaterals.db.d.ts
CHANGED
|
@@ -75,7 +75,7 @@ export declare const createQuery: (groupFields: {
|
|
|
75
75
|
};
|
|
76
76
|
};
|
|
77
77
|
itemQueries: any;
|
|
78
|
-
enumKey: "INVENTORY" | "RECEIVABLE" | "
|
|
78
|
+
enumKey: "INVENTORY" | "RECEIVABLE" | "ACCOUNT_PAYABLE" | "OTHER" | "CASH" | "LOAN_TRANSACTIONS" | "QUICKBOOKS" | "UPLOADED_BANK_TRANSACTIONS";
|
|
79
79
|
};
|
|
80
80
|
export declare const ITEMS_PAGINATION: (paginatorOptions: IPaginatorOptions) => ({
|
|
81
81
|
$skip: number;
|
package/db/collaterals.db.js
CHANGED
|
@@ -152,7 +152,7 @@ const findCollateralsWithSheets = async (borrowerId, collateralTypes) => {
|
|
|
152
152
|
exports.findCollateralsWithSheets = findCollateralsWithSheets;
|
|
153
153
|
const getBBCSheetsForBorrowerAndType = async (borrowerId, collateralType) => {
|
|
154
154
|
const bbcDates = await (0, bbcDates_db_1.getBBCDatesByBorrower)(borrowerId);
|
|
155
|
-
return (0, bbcSheets_db_1.getBBCSheetsByType)(bbcDates.map((bbcDate) => bbcDate._id), collateralType);
|
|
155
|
+
return (0, bbcSheets_db_1.getBBCSheetsByType)(bbcDates.map((bbcDate) => String(bbcDate._id)), collateralType);
|
|
156
156
|
};
|
|
157
157
|
exports.getBBCSheetsForBorrowerAndType = getBBCSheetsForBorrowerAndType;
|
|
158
158
|
const getCollateralListBySheet = async (sheetIds, collateralType) => {
|
|
@@ -286,7 +286,7 @@ const getCollateralDocsByBBC = async (bbcIds, collateralType) => {
|
|
|
286
286
|
exports.getCollateralDocsByBBC = getCollateralDocsByBBC;
|
|
287
287
|
const getCollateralListByBBCAndType = async (bbcDateId, collateralType) => {
|
|
288
288
|
const sheets = await (0, bbcSheets_db_1.getBBCSheetsByType)([bbcDateId], collateralType);
|
|
289
|
-
return (0, exports.getCollateralListBySheet)(sheets.map((sheet) => sheet._id), collateralType);
|
|
289
|
+
return (0, exports.getCollateralListBySheet)(sheets.map((sheet) => String(sheet._id)), collateralType);
|
|
290
290
|
};
|
|
291
291
|
exports.getCollateralListByBBCAndType = getCollateralListByBBCAndType;
|
|
292
292
|
const findCollateralSheets = (bbcDateId, collateralType) => {
|
package/db/collaterals.db.ts
CHANGED
|
@@ -160,7 +160,7 @@ export const findCollateralsWithSheets = async (borrowerId: string, collateralTy
|
|
|
160
160
|
|
|
161
161
|
export const getBBCSheetsForBorrowerAndType = async (borrowerId: string, collateralType: ECollaterals) => {
|
|
162
162
|
const bbcDates = await getBBCDatesByBorrower(borrowerId);
|
|
163
|
-
return getBBCSheetsByType(bbcDates.map((bbcDate) => bbcDate._id), collateralType);
|
|
163
|
+
return getBBCSheetsByType(bbcDates.map((bbcDate) => String(bbcDate._id)), collateralType);
|
|
164
164
|
};
|
|
165
165
|
|
|
166
166
|
export const getCollateralListBySheet = async (sheetIds: string[], collateralType: ECollaterals) => {
|
|
@@ -302,7 +302,7 @@ export const getCollateralDocsByBBC = async (bbcIds: string[], collateralType: E
|
|
|
302
302
|
|
|
303
303
|
export const getCollateralListByBBCAndType = async (bbcDateId: string, collateralType: ECollaterals) => {
|
|
304
304
|
const sheets = await getBBCSheetsByType([bbcDateId], collateralType);
|
|
305
|
-
return getCollateralListBySheet(sheets.map((sheet) => sheet._id), collateralType);
|
|
305
|
+
return getCollateralListBySheet(sheets.map((sheet) => String(sheet._id)), collateralType);
|
|
306
306
|
};
|
|
307
307
|
|
|
308
308
|
export const findCollateralSheets = (bbcDateId: string, collateralType: ECollaterals) => {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
+
/// <reference types="mongoose/types/session" />
|
|
20
|
+
/// <reference types="mongoose/types/types" />
|
|
21
|
+
/// <reference types="mongoose/types/utility" />
|
|
22
|
+
/// <reference types="mongoose/types/validation" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
import mongoose from 'mongoose';
|
|
26
|
+
import { FinancialSpreadingDTO, IFinancialSpreadingParams } from '../models/FinancialSpreading.model';
|
|
27
|
+
import { FinancialSpreadingSheetDTO, IFinancialSpreadingSheet } from '../models/FinancialSpreadingSheet.model';
|
|
28
|
+
export declare const getCreateAllBorrowerSheet: (params: IFinancialSpreadingParams) => Promise<(mongoose.FlattenMaps<IFinancialSpreadingSheet> & Required<{
|
|
29
|
+
_id: mongoose.Types.ObjectId;
|
|
30
|
+
}>)[]>;
|
|
31
|
+
export declare const getFinancialSpreadingData: (params: IFinancialSpreadingParams, monthDeep?: number) => Promise<{
|
|
32
|
+
data: FinancialSpreadingDTO[];
|
|
33
|
+
sheets: FinancialSpreadingSheetDTO[];
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getFinancialSpreadingData = exports.getCreateAllBorrowerSheet = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
9
|
+
const FinancialSpreading_model_1 = require("../models/FinancialSpreading.model");
|
|
10
|
+
const date_helper_1 = require("../helpers/date.helper");
|
|
11
|
+
const FinancialSpreadingSheet_model_1 = require("../models/FinancialSpreadingSheet.model");
|
|
12
|
+
const db_data_helper_1 = require("../helpers/db-data.helper");
|
|
13
|
+
const getAllBorrowerSheets = async (params) => {
|
|
14
|
+
const allSheets = await FinancialSpreadingSheet_model_1.FinancialSpreadingSheet.find({
|
|
15
|
+
borrowerId: params.borrowerId,
|
|
16
|
+
financialSpreadingType: params.financialSpreadingType,
|
|
17
|
+
}).lean();
|
|
18
|
+
return lodash_1.default.sortBy(allSheets, ['order', 'isTotal', 'suborder']);
|
|
19
|
+
};
|
|
20
|
+
const getCreateAllBorrowerSheet = async (params) => {
|
|
21
|
+
const allSheets = await getAllBorrowerSheets(params);
|
|
22
|
+
if (allSheets.length) {
|
|
23
|
+
return allSheets;
|
|
24
|
+
}
|
|
25
|
+
const totalsMap = {
|
|
26
|
+
[FinancialSpreadingSheet_model_1.EFinancialSpreadingType.PROFIT_LOSS]: FinancialSpreadingSheet_model_1.EFinanceSpreadingPLTotal,
|
|
27
|
+
[FinancialSpreadingSheet_model_1.EFinancialSpreadingType.BALANCE_SHEET]: FinancialSpreadingSheet_model_1.EFinanceSpreadingBSTotal,
|
|
28
|
+
};
|
|
29
|
+
await Promise.all(Object.entries(FinancialSpreadingSheet_model_1.financeSpreadingLists[params.financialSpreadingType]).map(async ([totalKey, isCalculated], order) => {
|
|
30
|
+
const newPartialRow = {
|
|
31
|
+
borrowerId: new mongoose_1.default.Types.ObjectId(params.borrowerId),
|
|
32
|
+
financialSpreadingType: params.financialSpreadingType,
|
|
33
|
+
name: FinancialSpreadingSheet_model_1.financialSpreadingTotalDictionary[totalKey],
|
|
34
|
+
rowType: totalsMap[params.financialSpreadingType][totalKey],
|
|
35
|
+
isCalculated,
|
|
36
|
+
order,
|
|
37
|
+
suborder: 0,
|
|
38
|
+
};
|
|
39
|
+
if (!isCalculated) {
|
|
40
|
+
const newRow = {
|
|
41
|
+
...newPartialRow,
|
|
42
|
+
name: FinancialSpreadingSheet_model_1.financialSpreadingTotalDictionary[totalKey].toLowerCase(),
|
|
43
|
+
isTotal: false,
|
|
44
|
+
};
|
|
45
|
+
const newRowItem = new FinancialSpreadingSheet_model_1.FinancialSpreadingSheet(newRow);
|
|
46
|
+
await newRowItem.save();
|
|
47
|
+
}
|
|
48
|
+
const newTotalRow = {
|
|
49
|
+
...newPartialRow,
|
|
50
|
+
isTotal: true,
|
|
51
|
+
};
|
|
52
|
+
const newTotalRowItem = new FinancialSpreadingSheet_model_1.FinancialSpreadingSheet(newTotalRow);
|
|
53
|
+
await newTotalRowItem.save();
|
|
54
|
+
}));
|
|
55
|
+
return getAllBorrowerSheets(params);
|
|
56
|
+
};
|
|
57
|
+
exports.getCreateAllBorrowerSheet = getCreateAllBorrowerSheet;
|
|
58
|
+
const getClearData = (rawData, rawSheets) => {
|
|
59
|
+
const data = (0, db_data_helper_1.rawDataToDTO)(FinancialSpreading_model_1.FinancialSpreadingDTO, rawData);
|
|
60
|
+
const sheets = (0, db_data_helper_1.rawDataToDTO)(FinancialSpreadingSheet_model_1.FinancialSpreadingSheetDTO, rawSheets);
|
|
61
|
+
return { data, sheets };
|
|
62
|
+
};
|
|
63
|
+
const getFinancialSpreadingData = async (params, monthDeep = 3) => {
|
|
64
|
+
const validationRes = FinancialSpreading_model_1.financialSpreadingParamsValidationSchema.validate(params);
|
|
65
|
+
if (validationRes.error) {
|
|
66
|
+
console.error(validationRes.error);
|
|
67
|
+
return { data: [], sheets: [] };
|
|
68
|
+
}
|
|
69
|
+
const range = Array.from({ length: monthDeep }, (_, i) => i + 1);
|
|
70
|
+
const shifts = range.reduce((acc, curr) => {
|
|
71
|
+
acc[`minus_${curr}`] = -curr;
|
|
72
|
+
return acc;
|
|
73
|
+
}, { 'amount': 0 });
|
|
74
|
+
const rawSheets = await (0, exports.getCreateAllBorrowerSheet)(params);
|
|
75
|
+
const rawData = await Promise.all(rawSheets.map(async (sheet) => {
|
|
76
|
+
const combinedData = {
|
|
77
|
+
_id: '',
|
|
78
|
+
borrowerId: params.borrowerId,
|
|
79
|
+
sheetId: sheet._id.toString(),
|
|
80
|
+
year: params.selectedMonth.year,
|
|
81
|
+
month: params.selectedMonth.month,
|
|
82
|
+
amount: 0,
|
|
83
|
+
minus_1: 0,
|
|
84
|
+
minus_2: 0,
|
|
85
|
+
minus_3: 0,
|
|
86
|
+
};
|
|
87
|
+
await Promise.all(Object.entries(shifts).map(async ([shiftName, shiftValue]) => {
|
|
88
|
+
const filter = {
|
|
89
|
+
borrowerId: params.borrowerId,
|
|
90
|
+
sheetId: sheet._id,
|
|
91
|
+
...(0, date_helper_1.getShiftedMonth)(params.selectedMonth, shiftValue),
|
|
92
|
+
};
|
|
93
|
+
const foundData = await FinancialSpreading_model_1.FinancialSpreading.findOne(filter).lean();
|
|
94
|
+
if (shiftValue === 0) {
|
|
95
|
+
combinedData._id = foundData ? foundData._id.toString() : `new_${sheet._id}`;
|
|
96
|
+
}
|
|
97
|
+
combinedData[shiftName] = foundData ? foundData.amount : 0;
|
|
98
|
+
}));
|
|
99
|
+
return combinedData;
|
|
100
|
+
}));
|
|
101
|
+
return getClearData(rawData, rawSheets);
|
|
102
|
+
};
|
|
103
|
+
exports.getFinancialSpreadingData = getFinancialSpreadingData;
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import mongoose from 'mongoose';
|
|
2
|
+
import _ from 'lodash';
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
FinancialSpreading, FinancialSpreadingDTO,
|
|
6
|
+
financialSpreadingParamsValidationSchema, IFinancialSpreading,
|
|
7
|
+
IFinancialSpreadingParams, IFinancialSpreadingView,
|
|
8
|
+
} from '../models/FinancialSpreading.model';
|
|
9
|
+
import { getShiftedMonth } from '../helpers/date.helper';
|
|
10
|
+
import {
|
|
11
|
+
EFinanceSpreadingBSTotal,
|
|
12
|
+
EFinanceSpreadingPLTotal,
|
|
13
|
+
EFinancialSpreadingType,
|
|
14
|
+
financeSpreadingLists,
|
|
15
|
+
FinancialSpreadingSheet, FinancialSpreadingSheetDTO,
|
|
16
|
+
financialSpreadingTotalDictionary,
|
|
17
|
+
IFinancialSpreadingSheet,
|
|
18
|
+
} from '../models/FinancialSpreadingSheet.model';
|
|
19
|
+
import { rawDataToDTO } from '../helpers/db-data.helper';
|
|
20
|
+
|
|
21
|
+
const getAllBorrowerSheets = async(params: IFinancialSpreadingParams) => {
|
|
22
|
+
const allSheets = await FinancialSpreadingSheet.find({
|
|
23
|
+
borrowerId: params.borrowerId,
|
|
24
|
+
financialSpreadingType: params.financialSpreadingType,
|
|
25
|
+
}).lean();
|
|
26
|
+
return _.sortBy(allSheets, ['order', 'isTotal', 'suborder']);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const getCreateAllBorrowerSheet = async (params: IFinancialSpreadingParams) => {
|
|
30
|
+
const allSheets = await getAllBorrowerSheets(params);
|
|
31
|
+
if (allSheets.length) {
|
|
32
|
+
return allSheets;
|
|
33
|
+
}
|
|
34
|
+
const totalsMap = {
|
|
35
|
+
[EFinancialSpreadingType.PROFIT_LOSS]: EFinanceSpreadingPLTotal,
|
|
36
|
+
[EFinancialSpreadingType.BALANCE_SHEET]: EFinanceSpreadingBSTotal,
|
|
37
|
+
};
|
|
38
|
+
await Promise.all(Object.entries(financeSpreadingLists[params.financialSpreadingType]).map(async ([totalKey, isCalculated], order) => {
|
|
39
|
+
const newPartialRow: Omit<IFinancialSpreadingSheet, 'isTotal'> = {
|
|
40
|
+
borrowerId: new mongoose.Types.ObjectId(params.borrowerId),
|
|
41
|
+
financialSpreadingType: params.financialSpreadingType,
|
|
42
|
+
name: financialSpreadingTotalDictionary[totalKey],
|
|
43
|
+
rowType: totalsMap[params.financialSpreadingType][totalKey],
|
|
44
|
+
isCalculated,
|
|
45
|
+
order,
|
|
46
|
+
suborder: 0,
|
|
47
|
+
};
|
|
48
|
+
if (!isCalculated) {
|
|
49
|
+
const newRow: IFinancialSpreadingSheet = {
|
|
50
|
+
...newPartialRow,
|
|
51
|
+
name: financialSpreadingTotalDictionary[totalKey].toLowerCase(),
|
|
52
|
+
isTotal: false,
|
|
53
|
+
};
|
|
54
|
+
const newRowItem = new FinancialSpreadingSheet(newRow);
|
|
55
|
+
await newRowItem.save();
|
|
56
|
+
}
|
|
57
|
+
const newTotalRow: IFinancialSpreadingSheet = {
|
|
58
|
+
...newPartialRow,
|
|
59
|
+
isTotal: true,
|
|
60
|
+
};
|
|
61
|
+
const newTotalRowItem = new FinancialSpreadingSheet(newTotalRow);
|
|
62
|
+
await newTotalRowItem.save();
|
|
63
|
+
}));
|
|
64
|
+
return getAllBorrowerSheets(params);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const getClearData = (rawData: IFinancialSpreading[], rawSheets: IFinancialSpreadingSheet[]) => {
|
|
68
|
+
const data = rawDataToDTO<FinancialSpreadingDTO, IFinancialSpreading>(FinancialSpreadingDTO, rawData);
|
|
69
|
+
const sheets = rawDataToDTO<FinancialSpreadingSheetDTO, IFinancialSpreadingSheet>(FinancialSpreadingSheetDTO, rawSheets);
|
|
70
|
+
return { data, sheets };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export const getFinancialSpreadingData = async (params: IFinancialSpreadingParams, monthDeep = 3) => {
|
|
74
|
+
const validationRes = financialSpreadingParamsValidationSchema.validate(params);
|
|
75
|
+
if (validationRes.error) {
|
|
76
|
+
console.error(validationRes.error);
|
|
77
|
+
return { data: [], sheets: [] };
|
|
78
|
+
}
|
|
79
|
+
const range = Array.from({ length: monthDeep }, (_, i) => i + 1);
|
|
80
|
+
const shifts = range.reduce((acc, curr) => {
|
|
81
|
+
acc[`minus_${curr}`] = -curr;
|
|
82
|
+
return acc;
|
|
83
|
+
}, { 'amount': 0 });
|
|
84
|
+
const rawSheets = await getCreateAllBorrowerSheet(params);
|
|
85
|
+
const rawData = await Promise.all(rawSheets.map(async (sheet) => {
|
|
86
|
+
const combinedData: IFinancialSpreadingView = {
|
|
87
|
+
_id: '',
|
|
88
|
+
borrowerId: params.borrowerId,
|
|
89
|
+
sheetId: sheet._id.toString(),
|
|
90
|
+
year: params.selectedMonth.year,
|
|
91
|
+
month: params.selectedMonth.month,
|
|
92
|
+
amount: 0,
|
|
93
|
+
minus_1: 0,
|
|
94
|
+
minus_2: 0,
|
|
95
|
+
minus_3: 0,
|
|
96
|
+
};
|
|
97
|
+
await Promise.all(Object.entries(shifts).map(async ([shiftName, shiftValue]) => {
|
|
98
|
+
const filter = {
|
|
99
|
+
borrowerId: params.borrowerId,
|
|
100
|
+
sheetId: sheet._id,
|
|
101
|
+
...getShiftedMonth(params.selectedMonth, shiftValue),
|
|
102
|
+
};
|
|
103
|
+
const foundData = await FinancialSpreading.findOne(filter).lean();
|
|
104
|
+
if (shiftValue === 0) {
|
|
105
|
+
combinedData._id = foundData ? foundData._id.toString() : `new_${sheet._id}`;
|
|
106
|
+
}
|
|
107
|
+
combinedData[shiftName] = foundData ? foundData.amount : 0;
|
|
108
|
+
}));
|
|
109
|
+
return combinedData as unknown as IFinancialSpreading;
|
|
110
|
+
}));
|
|
111
|
+
return getClearData(rawData, rawSheets);
|
|
112
|
+
}
|
package/db/inventories.db.js
CHANGED
|
@@ -209,9 +209,9 @@ const getMovementDifference = async (skus, BBCs) => {
|
|
|
209
209
|
};
|
|
210
210
|
const getInventoryMovement = async (borrowerId, startDate, endDate) => {
|
|
211
211
|
const bbcDates = await (0, bbcDates_db_1.getBBCDatesForPeriod)(borrowerId, new Date(startDate), new Date(endDate));
|
|
212
|
-
const bbcIds = bbcDates.map((bbc) => bbc._id);
|
|
212
|
+
const bbcIds = bbcDates.map((bbc) => String(bbc._id));
|
|
213
213
|
const bbcSheets = await (0, bbcSheets_db_1.getBBCSheetsByType)(bbcIds, collaterals_enum_1.ECollaterals.INVENTORY);
|
|
214
|
-
const skuGroups = await (0, exports.getAllUniqSKUInRangeNew)(bbcSheets.map((bbcSheet) => bbcSheet._id
|
|
214
|
+
const skuGroups = await (0, exports.getAllUniqSKUInRangeNew)(bbcSheets.map((bbcSheet) => String(bbcSheet._id)));
|
|
215
215
|
if (skuGroups.length > 0) {
|
|
216
216
|
const { skus } = skuGroups.pop();
|
|
217
217
|
const BBCs = await (0, collaterals_db_1.getCollateralDocsByBBC)(bbcIds, collaterals_enum_1.ECollaterals.INVENTORY);
|
package/db/inventories.db.ts
CHANGED
|
@@ -213,9 +213,9 @@ const getMovementDifference = async (skus: string[], BBCs) => {
|
|
|
213
213
|
|
|
214
214
|
export const getInventoryMovement = async (borrowerId: string, startDate: string, endDate: string) => {
|
|
215
215
|
const bbcDates = await getBBCDatesForPeriod(borrowerId, new Date(startDate), new Date(endDate));
|
|
216
|
-
const bbcIds = bbcDates.map((bbc) => bbc._id);
|
|
216
|
+
const bbcIds = bbcDates.map((bbc) => String(bbc._id));
|
|
217
217
|
const bbcSheets = await getBBCSheetsByType(bbcIds, ECollaterals.INVENTORY);
|
|
218
|
-
const skuGroups = await getAllUniqSKUInRangeNew(bbcSheets.map((bbcSheet) => bbcSheet._id
|
|
218
|
+
const skuGroups = await getAllUniqSKUInRangeNew(bbcSheets.map((bbcSheet) => String(bbcSheet._id)));
|
|
219
219
|
if (skuGroups.length > 0) {
|
|
220
220
|
const { skus } = skuGroups.pop();
|
|
221
221
|
const BBCs = await getCollateralDocsByBBC(bbcIds, ECollaterals.INVENTORY);
|
package/db/loan-products.db.js
CHANGED
|
@@ -165,13 +165,12 @@ const getAverageActualBalance = async (productId, period, charge) => {
|
|
|
165
165
|
if (charge) {
|
|
166
166
|
period.start = dayjs_1.default.max(period.start, (0, dayjs_1.default)(charge.applyFrom));
|
|
167
167
|
}
|
|
168
|
-
const days = (0, date_helper_1.getDays)(period);
|
|
168
|
+
const days = (0, date_helper_1.getDays)({ ...period, end: (0, dayjs_1.default)(period.end).add(1, 'day') });
|
|
169
169
|
if (days.length === 0) {
|
|
170
170
|
return 0;
|
|
171
171
|
}
|
|
172
|
-
const balances = await Promise.all(days.map(async (day) => {
|
|
173
|
-
|
|
174
|
-
return allBalances;
|
|
172
|
+
const balances = await Promise.all(days.map(async (day, i) => {
|
|
173
|
+
return await (0, exports.getLoanProductBalance)(productId, (0, dayjs_1.default)(day).add(1, 'day').toDate());
|
|
175
174
|
}));
|
|
176
175
|
const totalBalance = balances.reduce((acc, balance) => new decimal_js_1.default(acc).add(balance.balance).toNumber(), 0);
|
|
177
176
|
return new decimal_js_1.default(totalBalance).div(days.length).toNumber();
|
package/db/loan-products.db.ts
CHANGED
|
@@ -171,13 +171,12 @@ export const getAverageActualBalance = async (productId: string, period: IStatem
|
|
|
171
171
|
if (charge) {
|
|
172
172
|
period.start = dayjs.max(period.start, dayjs(charge.applyFrom));
|
|
173
173
|
}
|
|
174
|
-
const days = getDays(period);
|
|
174
|
+
const days = getDays({ ...period, end: dayjs(period.end).add(1, 'day') });
|
|
175
175
|
if (days.length === 0) {
|
|
176
176
|
return 0;
|
|
177
177
|
}
|
|
178
|
-
const balances = await Promise.all(days.map(async (day) => {
|
|
179
|
-
|
|
180
|
-
return allBalances;
|
|
178
|
+
const balances = await Promise.all(days.map(async (day, i) => {
|
|
179
|
+
return await getLoanProductBalance(productId, dayjs(day).add(1, 'day').toDate());
|
|
181
180
|
}));
|
|
182
181
|
const totalBalance = balances.reduce((acc, balance) => new Decimal(acc).add(balance.balance).toNumber(), 0);
|
|
183
182
|
return new Decimal(totalBalance).div(days.length).toNumber();
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import { ILoanTransactionDoc } from '../models/LoanTransaction.model';
|
|
1
|
+
import { ILoanTransactionDoc, ILoanTransactionView, ILoanTransactionViewWithBank, ITransactionsFilter } from '../models/LoanTransaction.model';
|
|
2
|
+
import { IPaginatorOptions } from '../interfaces/collaterals.interface';
|
|
2
3
|
export declare const getLastTransactionForDate: (productId: string, date?: Date, excludeAdjustments?: boolean) => Promise<ILoanTransactionDoc>;
|
|
4
|
+
export declare const getLoanTransactions: <T extends boolean>(transactionsFilter: ITransactionsFilter, paginatorOptions: IPaginatorOptions, withBanks: T, isReverse?: boolean, isMinified?: boolean) => Promise<(T extends true ? ILoanTransactionViewWithBank : ILoanTransactionView)[]>;
|
|
@@ -3,9 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getLastTransactionForDate = void 0;
|
|
7
|
-
const LoanTransaction_model_1 = require("../models/LoanTransaction.model");
|
|
6
|
+
exports.getLoanTransactions = exports.getLastTransactionForDate = void 0;
|
|
8
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const LoanTransaction_model_1 = require("../models/LoanTransaction.model");
|
|
9
|
+
const loan_products_db_1 = require("./loan-products.db");
|
|
10
|
+
const collaterals_db_1 = require("./collaterals.db");
|
|
9
11
|
const getLastTransactionForDate = async (productId, date = new Date(), excludeAdjustments = false) => {
|
|
10
12
|
const excludeFilter = excludeAdjustments
|
|
11
13
|
? {
|
|
@@ -37,3 +39,61 @@ const getLastTransactionForDate = async (productId, date = new Date(), excludeAd
|
|
|
37
39
|
return lastTransaction[0];
|
|
38
40
|
};
|
|
39
41
|
exports.getLastTransactionForDate = getLastTransactionForDate;
|
|
42
|
+
const getLoanTransactions = async (transactionsFilter, paginatorOptions, withBanks, isReverse = false, isMinified = false) => {
|
|
43
|
+
const borrowerProducts = await (0, loan_products_db_1.getLoanProducts)(transactionsFilter.borrowerId);
|
|
44
|
+
const productIds = borrowerProducts
|
|
45
|
+
.filter((product) => transactionsFilter.productId ? product._id.toString() === transactionsFilter.productId : true)
|
|
46
|
+
.map((product) => product._id);
|
|
47
|
+
const optionalFilters = [];
|
|
48
|
+
if (transactionsFilter.amount) {
|
|
49
|
+
optionalFilters.push({ 'amount': transactionsFilter.amount });
|
|
50
|
+
}
|
|
51
|
+
if (transactionsFilter.reference) {
|
|
52
|
+
optionalFilters.push({ 'reference': { $regex: transactionsFilter.reference, $options: 'i' } });
|
|
53
|
+
}
|
|
54
|
+
const bankLookup = !withBanks
|
|
55
|
+
? []
|
|
56
|
+
: [
|
|
57
|
+
{
|
|
58
|
+
$lookup: {
|
|
59
|
+
from: 'banks',
|
|
60
|
+
localField: 'bankId',
|
|
61
|
+
foreignField: '_id',
|
|
62
|
+
as: 'bank',
|
|
63
|
+
},
|
|
64
|
+
}, {
|
|
65
|
+
$unwind: {
|
|
66
|
+
path: '$bank',
|
|
67
|
+
preserveNullAndEmptyArrays: true,
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
];
|
|
71
|
+
const projectedFields = isMinified
|
|
72
|
+
? [{ $project: { _id: 1, date: 1, amount: 1, reference: 1, balance: 1, transactionType: 1 } }]
|
|
73
|
+
: [];
|
|
74
|
+
return LoanTransaction_model_1.LoanTransaction.aggregate([
|
|
75
|
+
{
|
|
76
|
+
$match: {
|
|
77
|
+
$and: [
|
|
78
|
+
{ 'date': { $gte: transactionsFilter.periodStart } },
|
|
79
|
+
{ 'date': { $lte: transactionsFilter.periodEnd } },
|
|
80
|
+
{ 'productId': { $in: productIds } },
|
|
81
|
+
...optionalFilters,
|
|
82
|
+
],
|
|
83
|
+
},
|
|
84
|
+
}, {
|
|
85
|
+
$sort: {
|
|
86
|
+
'date': isReverse ? -1 : 1,
|
|
87
|
+
'order': isReverse ? -1 : 1,
|
|
88
|
+
'createdAt': isReverse ? -1 : 1,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
...(0, collaterals_db_1.ITEMS_PAGINATION)(paginatorOptions),
|
|
92
|
+
...bankLookup,
|
|
93
|
+
{
|
|
94
|
+
$unset: loan_products_db_1.fieldsToUnset,
|
|
95
|
+
},
|
|
96
|
+
...projectedFields,
|
|
97
|
+
]);
|
|
98
|
+
};
|
|
99
|
+
exports.getLoanTransactions = getLoanTransactions;
|
|
@@ -1,6 +1,16 @@
|
|
|
1
|
-
import { ILoanTransactionDoc, LoanTransaction } from '../models/LoanTransaction.model';
|
|
2
1
|
import mongoose from 'mongoose';
|
|
3
2
|
|
|
3
|
+
import {
|
|
4
|
+
ILoanTransactionDoc,
|
|
5
|
+
ILoanTransactionView,
|
|
6
|
+
ILoanTransactionViewWithBank,
|
|
7
|
+
ITransactionsFilter,
|
|
8
|
+
LoanTransaction,
|
|
9
|
+
} from '../models/LoanTransaction.model';
|
|
10
|
+
import { fieldsToUnset, getLoanProducts } from './loan-products.db';
|
|
11
|
+
import { ITEMS_PAGINATION } from './collaterals.db';
|
|
12
|
+
import { IPaginatorOptions } from '../interfaces/collaterals.interface';
|
|
13
|
+
|
|
4
14
|
export const getLastTransactionForDate = async (productId: string, date: Date = new Date(), excludeAdjustments = false) => {
|
|
5
15
|
const excludeFilter = excludeAdjustments
|
|
6
16
|
? {
|
|
@@ -31,3 +41,64 @@ export const getLastTransactionForDate = async (productId: string, date: Date =
|
|
|
31
41
|
}
|
|
32
42
|
return lastTransaction[0];
|
|
33
43
|
};
|
|
44
|
+
|
|
45
|
+
export const getLoanTransactions = async <T extends boolean>(transactionsFilter: ITransactionsFilter, paginatorOptions: IPaginatorOptions, withBanks: T, isReverse = false, isMinified = false) => {
|
|
46
|
+
const borrowerProducts = await getLoanProducts(transactionsFilter.borrowerId);
|
|
47
|
+
const productIds = borrowerProducts
|
|
48
|
+
.filter((product) => transactionsFilter.productId ? product._id.toString() === transactionsFilter.productId : true)
|
|
49
|
+
.map((product) => product._id);
|
|
50
|
+
|
|
51
|
+
const optionalFilters = [];
|
|
52
|
+
if (transactionsFilter.amount) {
|
|
53
|
+
optionalFilters.push({ 'amount': transactionsFilter.amount });
|
|
54
|
+
}
|
|
55
|
+
if (transactionsFilter.reference) {
|
|
56
|
+
optionalFilters.push({ 'reference': { $regex: transactionsFilter.reference, $options: 'i' } });
|
|
57
|
+
}
|
|
58
|
+
const bankLookup = !withBanks
|
|
59
|
+
? []
|
|
60
|
+
: [
|
|
61
|
+
{
|
|
62
|
+
$lookup: {
|
|
63
|
+
from: 'banks',
|
|
64
|
+
localField: 'bankId',
|
|
65
|
+
foreignField: '_id',
|
|
66
|
+
as: 'bank',
|
|
67
|
+
},
|
|
68
|
+
}, {
|
|
69
|
+
$unwind: {
|
|
70
|
+
path: '$bank',
|
|
71
|
+
preserveNullAndEmptyArrays: true,
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const projectedFields = isMinified
|
|
77
|
+
? [{ $project: { _id: 1, date: 1, amount: 1, reference: 1, balance: 1, transactionType: 1 } }]
|
|
78
|
+
: [];
|
|
79
|
+
|
|
80
|
+
return LoanTransaction.aggregate<T extends true ? ILoanTransactionViewWithBank : ILoanTransactionView>([
|
|
81
|
+
{
|
|
82
|
+
$match: {
|
|
83
|
+
$and: [
|
|
84
|
+
{ 'date': { $gte: transactionsFilter.periodStart } },
|
|
85
|
+
{ 'date': { $lte: transactionsFilter.periodEnd } },
|
|
86
|
+
{ 'productId': { $in: productIds } },
|
|
87
|
+
...optionalFilters,
|
|
88
|
+
],
|
|
89
|
+
},
|
|
90
|
+
}, {
|
|
91
|
+
$sort: {
|
|
92
|
+
'date': isReverse ? -1 : 1,
|
|
93
|
+
'order': isReverse ? -1 : 1,
|
|
94
|
+
'createdAt': isReverse ? -1 : 1,
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
...ITEMS_PAGINATION(paginatorOptions),
|
|
98
|
+
...bankLookup,
|
|
99
|
+
{
|
|
100
|
+
$unset: fieldsToUnset,
|
|
101
|
+
},
|
|
102
|
+
...projectedFields,
|
|
103
|
+
]);
|
|
104
|
+
};
|
package/db/receivables.db.js
CHANGED
|
@@ -339,7 +339,7 @@ const getAllCustomers = async (borrowerId) => {
|
|
|
339
339
|
{
|
|
340
340
|
$match: {
|
|
341
341
|
'bbcSheetId': {
|
|
342
|
-
$in: bbcSheets.map((bbcSheet) => new mongoose_1.default.Types.ObjectId(bbcSheet._id)),
|
|
342
|
+
$in: bbcSheets.map((bbcSheet) => new mongoose_1.default.Types.ObjectId(String(bbcSheet._id))),
|
|
343
343
|
},
|
|
344
344
|
},
|
|
345
345
|
},
|
package/db/receivables.db.ts
CHANGED
|
@@ -364,7 +364,7 @@ export const getAllCustomers = async (borrowerId: string) => {
|
|
|
364
364
|
{
|
|
365
365
|
$match: {
|
|
366
366
|
'bbcSheetId': {
|
|
367
|
-
$in: bbcSheets.map((bbcSheet) => new mongoose.Types.ObjectId(bbcSheet._id)),
|
|
367
|
+
$in: bbcSheets.map((bbcSheet) => new mongoose.Types.ObjectId(String(bbcSheet._id))),
|
|
368
368
|
},
|
|
369
369
|
},
|
|
370
370
|
},
|
package/helpers/date.helper.d.ts
CHANGED
package/helpers/date.helper.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getDays = exports.getStartOfMonthsBetweenDates = exports.convertSelectedMonthToDate = exports.convertToFormat = exports.excelDateToJSDate = exports.convertToDefaultFormat = exports.calculateTimeZone = exports.formatDate = exports.dateLessThan = exports.convertAnyToDate = exports.normalizeDate = exports.defaultDateFormat = void 0;
|
|
6
|
+
exports.getShiftedMonth = exports.getDays = exports.getStartOfMonthsBetweenDates = exports.convertSelectedMonthToDate = exports.convertToFormat = exports.excelDateToJSDate = exports.convertToDefaultFormat = exports.calculateTimeZone = exports.formatDate = exports.dateLessThan = exports.convertAnyToDate = exports.normalizeDate = exports.defaultDateFormat = void 0;
|
|
7
7
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
8
|
const utc_1 = __importDefault(require("dayjs/plugin/utc"));
|
|
9
9
|
const timezone_1 = __importDefault(require("dayjs/plugin/timezone"));
|
|
@@ -94,3 +94,8 @@ const getDays = (period) => {
|
|
|
94
94
|
return days;
|
|
95
95
|
};
|
|
96
96
|
exports.getDays = getDays;
|
|
97
|
+
const getShiftedMonth = (month, shift) => {
|
|
98
|
+
const nextMonth = (0, dayjs_1.default)().utcOffset(0).year(month.year).month(month.month - 1).add(shift, 'month');
|
|
99
|
+
return { year: nextMonth.year(), month: nextMonth.month() + 1 };
|
|
100
|
+
};
|
|
101
|
+
exports.getShiftedMonth = getShiftedMonth;
|
package/helpers/date.helper.ts
CHANGED
|
@@ -99,3 +99,8 @@ export const getDays = (period: { start: dayjs.Dayjs, end: dayjs.Dayjs }) => {
|
|
|
99
99
|
}
|
|
100
100
|
return days;
|
|
101
101
|
};
|
|
102
|
+
|
|
103
|
+
export const getShiftedMonth = (month: ISelectedMonth, shift: number) => {
|
|
104
|
+
const nextMonth = dayjs().utcOffset(0).year(month.year).month(month.month - 1).add(shift, 'month');
|
|
105
|
+
return { year: nextMonth.year(), month: nextMonth.month() + 1 };
|
|
106
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/// <reference types="mongoose/types/aggregate" />
|
|
2
|
+
/// <reference types="mongoose/types/callback" />
|
|
3
|
+
/// <reference types="mongoose/types/collection" />
|
|
4
|
+
/// <reference types="mongoose/types/connection" />
|
|
5
|
+
/// <reference types="mongoose/types/cursor" />
|
|
6
|
+
/// <reference types="mongoose/types/document" />
|
|
7
|
+
/// <reference types="mongoose/types/error" />
|
|
8
|
+
/// <reference types="mongoose/types/expressions" />
|
|
9
|
+
/// <reference types="mongoose/types/helpers" />
|
|
10
|
+
/// <reference types="mongoose/types/middlewares" />
|
|
11
|
+
/// <reference types="mongoose/types/indexes" />
|
|
12
|
+
/// <reference types="mongoose/types/models" />
|
|
13
|
+
/// <reference types="mongoose/types/mongooseoptions" />
|
|
14
|
+
/// <reference types="mongoose/types/pipelinestage" />
|
|
15
|
+
/// <reference types="mongoose/types/populate" />
|
|
16
|
+
/// <reference types="mongoose/types/query" />
|
|
17
|
+
/// <reference types="mongoose/types/schemaoptions" />
|
|
18
|
+
/// <reference types="mongoose/types/schematypes" />
|
|
19
|
+
/// <reference types="mongoose/types/session" />
|
|
20
|
+
/// <reference types="mongoose/types/types" />
|
|
21
|
+
/// <reference types="mongoose/types/utility" />
|
|
22
|
+
/// <reference types="mongoose/types/validation" />
|
|
23
|
+
/// <reference types="mongoose/types/virtuals" />
|
|
24
|
+
/// <reference types="mongoose/types/inferschematype" />
|
|
25
|
+
import mongoose, { Model } from 'mongoose';
|
|
26
|
+
export interface IAvailabilitySignedData {
|
|
27
|
+
_id?: mongoose.Types.ObjectId;
|
|
28
|
+
bbcDateId?: mongoose.Types.ObjectId;
|
|
29
|
+
data: any;
|
|
30
|
+
}
|
|
31
|
+
type IAvailabilitySignedDataModel = Model<IAvailabilitySignedData, {}, {}>;
|
|
32
|
+
export declare const AvailabilitySignedData: IAvailabilitySignedDataModel;
|
|
33
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AvailabilitySignedData = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
|
+
const _models_1 = require("../models/_models");
|
|
9
|
+
const AvailabilitySignedDataSchema = new mongoose_1.default.Schema({
|
|
10
|
+
bbcDateId: {
|
|
11
|
+
type: mongoose_1.default.Schema.Types.ObjectId,
|
|
12
|
+
ref: _models_1.MODEL_NAMES.BBCDates,
|
|
13
|
+
required: false,
|
|
14
|
+
},
|
|
15
|
+
data: {
|
|
16
|
+
type: mongoose_1.default.Schema.Types.Mixed,
|
|
17
|
+
},
|
|
18
|
+
}, {
|
|
19
|
+
timestamps: { createdAt: false, updatedAt: false },
|
|
20
|
+
versionKey: false,
|
|
21
|
+
});
|
|
22
|
+
exports.AvailabilitySignedData = mongoose_1.default.model(_models_1.MODEL_NAMES.availabilitySignedData, AvailabilitySignedDataSchema);
|