gemcap-be-common 1.2.73 → 1.2.75
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 -0
- package/db/collaterals.db.js +6 -1
- package/db/collaterals.db.ts +5 -0
- package/db/inventories.d.ts +4 -0
- package/db/inventories.js +55 -1
- package/db/inventories.ts +50 -0
- package/helpers/excel.helper.d.ts +3 -0
- package/helpers/excel.helper.js +15 -1
- package/helpers/excel.helper.ts +14 -0
- package/models/BorrowerSettings.model.d.ts +1 -0
- package/models/BorrowerSettings.model.ts +1 -1
- package/models/QueryResult.model.d.ts +1 -4
- package/models/QueryResult.model.js +44 -27
- package/models/QueryResult.model.ts +46 -30
- package/package.json +1 -1
- package/queries/inventory/invoice-difference.d.ts +9 -0
- package/queries/inventory/invoice-difference.js +50 -0
- package/queries/inventory/invoice-difference.ts +50 -0
- package/queries/inventory/turn.d.ts +9 -0
- package/queries/inventory/turn.js +168 -0
- package/queries/inventory/turn.ts +176 -0
- package/queries/inventory/unit-cost-difference.d.ts +1 -9
- package/queries/inventory/unit-cost-difference.js +8 -2
- package/queries/inventory/unit-cost-difference.ts +8 -1
- package/tsconfig.tsbuildinfo +1 -1
package/db/collaterals.db.d.ts
CHANGED
|
@@ -91,3 +91,4 @@ export declare const getPreviousCollateralDocument: (borrowerId: string, date: D
|
|
|
91
91
|
bbcDate: Date;
|
|
92
92
|
}[]>;
|
|
93
93
|
export declare const getCollateralDocsByBBC: (bbcIds: string[], collateralType: ECollaterals) => Promise<any>;
|
|
94
|
+
export declare const getCollateralListByBBCAndType: (bbcDateId: string, collateralType: ECollaterals) => Promise<any>;
|
package/db/collaterals.db.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.getCollateralDocsByBBC = exports.getPreviousCollateralDocument = exports.getCollateralListBySheet = exports.getBBCSheetsForBorrowerAndType = exports.findCollateralsWithSheets = exports.ITEMS_PAGINATION = exports.createQuery = exports.COLLATERALS_LOOKUP = exports.collateralFields = exports.collateralMap = void 0;
|
|
6
|
+
exports.getCollateralListByBBCAndType = exports.getCollateralDocsByBBC = exports.getPreviousCollateralDocument = exports.getCollateralListBySheet = exports.getBBCSheetsForBorrowerAndType = exports.findCollateralsWithSheets = exports.ITEMS_PAGINATION = exports.createQuery = exports.COLLATERALS_LOOKUP = exports.collateralFields = exports.collateralMap = void 0;
|
|
7
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
8
|
const _models_1 = require("../models/_models");
|
|
9
9
|
const collaterals_enum_1 = require("../enums/collaterals.enum");
|
|
@@ -282,3 +282,8 @@ const getCollateralDocsByBBC = async (bbcIds, collateralType) => {
|
|
|
282
282
|
return aggregationResult;
|
|
283
283
|
};
|
|
284
284
|
exports.getCollateralDocsByBBC = getCollateralDocsByBBC;
|
|
285
|
+
const getCollateralListByBBCAndType = async (bbcDateId, collateralType) => {
|
|
286
|
+
const sheets = await (0, bbcSheets_db_1.getBBCSheetsByType)([bbcDateId], collateralType);
|
|
287
|
+
return (0, exports.getCollateralListBySheet)(sheets.map((sheet) => sheet._id), collateralType);
|
|
288
|
+
};
|
|
289
|
+
exports.getCollateralListByBBCAndType = getCollateralListByBBCAndType;
|
package/db/collaterals.db.ts
CHANGED
|
@@ -297,3 +297,8 @@ export const getCollateralDocsByBBC = async (bbcIds: string[], collateralType: E
|
|
|
297
297
|
}
|
|
298
298
|
return aggregationResult;
|
|
299
299
|
}
|
|
300
|
+
|
|
301
|
+
export const getCollateralListByBBCAndType = async (bbcDateId: string, collateralType: ECollaterals) => {
|
|
302
|
+
const sheets = await getBBCSheetsByType([bbcDateId], collateralType);
|
|
303
|
+
return getCollateralListBySheet(sheets.map((sheet) => sheet._id), collateralType);
|
|
304
|
+
}
|
package/db/inventories.d.ts
CHANGED
package/db/inventories.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getSKUUnitCostForAllDates = void 0;
|
|
6
|
+
exports.getAllUniqSKUInRangeNew = exports.getSKUUnitCostForAllDates = void 0;
|
|
7
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
4
8
|
const InventoryItem_model_1 = require("../models/InventoryItem.model");
|
|
5
9
|
const collaterals_db_1 = require("./collaterals.db");
|
|
6
10
|
const getSKUUnitCostForAllDates = async (sheetsIds) => {
|
|
@@ -38,3 +42,53 @@ const getSKUUnitCostForAllDates = async (sheetsIds) => {
|
|
|
38
42
|
]);
|
|
39
43
|
};
|
|
40
44
|
exports.getSKUUnitCostForAllDates = getSKUUnitCostForAllDates;
|
|
45
|
+
const getAllUniqSKUInRangeNew = async (bbcSheetIds) => {
|
|
46
|
+
return InventoryItem_model_1.InventoryItemModel.aggregate([
|
|
47
|
+
{
|
|
48
|
+
$match: {
|
|
49
|
+
'bbcSheetId': {
|
|
50
|
+
$in: bbcSheetIds.map((bbcSheetId) => new mongoose_1.default.Types.ObjectId(bbcSheetId))
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
$lookup: {
|
|
56
|
+
from: 'bbcsheets',
|
|
57
|
+
localField: 'bbcSheetId',
|
|
58
|
+
foreignField: '_id',
|
|
59
|
+
as: 'bbcSheet'
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
$unwind: {
|
|
64
|
+
path: '$bbcSheet'
|
|
65
|
+
}
|
|
66
|
+
}, {
|
|
67
|
+
$lookup: {
|
|
68
|
+
from: 'bbcdates',
|
|
69
|
+
localField: 'bbcSheet.bbcDateId',
|
|
70
|
+
foreignField: '_id',
|
|
71
|
+
as: 'bbc'
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
$unwind: {
|
|
76
|
+
path: '$bbc'
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
$sort: {
|
|
81
|
+
'bbc.bbcDate': 1
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
$group: {
|
|
86
|
+
'_id': '$bbc.borrowerId',
|
|
87
|
+
'skus': {
|
|
88
|
+
$addToSet: '$sku'
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
]);
|
|
93
|
+
};
|
|
94
|
+
exports.getAllUniqSKUInRangeNew = getAllUniqSKUInRangeNew;
|
package/db/inventories.ts
CHANGED
|
@@ -42,3 +42,53 @@ export const getSKUUnitCostForAllDates = async (sheetsIds: mongoose.Types.Object
|
|
|
42
42
|
},
|
|
43
43
|
]);
|
|
44
44
|
};
|
|
45
|
+
|
|
46
|
+
export const getAllUniqSKUInRangeNew = async (bbcSheetIds: string[]): Promise<{ _id: string, skus: string[] }[]> => {
|
|
47
|
+
return InventoryItemModel.aggregate([
|
|
48
|
+
{
|
|
49
|
+
$match: {
|
|
50
|
+
'bbcSheetId': {
|
|
51
|
+
$in: bbcSheetIds.map((bbcSheetId) => new mongoose.Types.ObjectId(bbcSheetId))
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
$lookup: {
|
|
57
|
+
from: 'bbcsheets',
|
|
58
|
+
localField: 'bbcSheetId',
|
|
59
|
+
foreignField: '_id',
|
|
60
|
+
as: 'bbcSheet'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
$unwind: {
|
|
65
|
+
path: '$bbcSheet'
|
|
66
|
+
}
|
|
67
|
+
}, {
|
|
68
|
+
$lookup: {
|
|
69
|
+
from: 'bbcdates',
|
|
70
|
+
localField: 'bbcSheet.bbcDateId',
|
|
71
|
+
foreignField: '_id',
|
|
72
|
+
as: 'bbc'
|
|
73
|
+
}
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
$unwind: {
|
|
77
|
+
path: '$bbc'
|
|
78
|
+
}
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
$sort: {
|
|
82
|
+
'bbc.bbcDate': 1
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
$group: {
|
|
87
|
+
'_id': '$bbc.borrowerId',
|
|
88
|
+
'skus': {
|
|
89
|
+
$addToSet: '$sku'
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
]);
|
|
94
|
+
}
|
package/helpers/excel.helper.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.convertDataToFileWithStyle = exports.convertDataToFile = void 0;
|
|
26
|
+
exports.addHeaderToData = exports.convertDataToFileWithStyle = exports.convertDataToFile = void 0;
|
|
27
27
|
const XLSX = __importStar(require("xlsx"));
|
|
28
28
|
const XLSXStyle = __importStar(require("xlsx-js-style"));
|
|
29
29
|
const defaultColumnWidth = 20;
|
|
@@ -86,3 +86,17 @@ const convertDataToFileWithStyle = async (dataToConvert, options) => {
|
|
|
86
86
|
return XLSXStyle.write(wb, { bookType: 'xlsx', type: 'buffer' });
|
|
87
87
|
};
|
|
88
88
|
exports.convertDataToFileWithStyle = convertDataToFileWithStyle;
|
|
89
|
+
const addHeaderToData = (header, data) => {
|
|
90
|
+
const filterAndReorder = (item) => {
|
|
91
|
+
const newItem = {};
|
|
92
|
+
Object.keys(header).forEach(key => {
|
|
93
|
+
if (item.hasOwnProperty(key)) {
|
|
94
|
+
newItem[key] = item[key];
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
return newItem;
|
|
98
|
+
};
|
|
99
|
+
const processedItems = data.map(filterAndReorder);
|
|
100
|
+
return [header, ...processedItems];
|
|
101
|
+
};
|
|
102
|
+
exports.addHeaderToData = addHeaderToData;
|
package/helpers/excel.helper.ts
CHANGED
|
@@ -72,3 +72,17 @@ export const convertDataToFileWithStyle = async (
|
|
|
72
72
|
});
|
|
73
73
|
return XLSXStyle.write(wb, { bookType: 'xlsx', type: 'buffer' });
|
|
74
74
|
};
|
|
75
|
+
|
|
76
|
+
export const addHeaderToData = (header: { [key: string]: string }, data: object[]) => {
|
|
77
|
+
const filterAndReorder = (item: object) => {
|
|
78
|
+
const newItem = {};
|
|
79
|
+
Object.keys(header).forEach(key => {
|
|
80
|
+
if (item.hasOwnProperty(key)) {
|
|
81
|
+
newItem[key] = item[key];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return newItem;
|
|
85
|
+
};
|
|
86
|
+
const processedItems = data.map(filterAndReorder);
|
|
87
|
+
return [header, ...processedItems];
|
|
88
|
+
}
|
|
@@ -14,7 +14,7 @@ import { MODEL_NAMES } from './_models';
|
|
|
14
14
|
|
|
15
15
|
export interface IBorrowerSettings {
|
|
16
16
|
borrower: mongoose.Types.ObjectId;
|
|
17
|
-
queries: { [group: string]: { [queryName: string]: { isCalculateOnUpload: boolean } } };
|
|
17
|
+
queries: { [group: string]: { [queryName: string]: { isCalculateOnUpload: boolean, queryParams: object } } };
|
|
18
18
|
dataTypes: { [group: string]: string[] };
|
|
19
19
|
dataAvailability: {
|
|
20
20
|
[key in 'receivables' | 'inventories']: boolean;
|
|
@@ -75,13 +75,10 @@ export declare enum EFilterParams {
|
|
|
75
75
|
}
|
|
76
76
|
interface IQueryDetail {
|
|
77
77
|
scheduled: boolean;
|
|
78
|
-
|
|
78
|
+
queryAPI: string;
|
|
79
79
|
queryFunction: ((params: TQueryParams) => unknown) | null;
|
|
80
80
|
filterParams?: EFilterParams;
|
|
81
81
|
sheetTitle?: string;
|
|
82
|
-
header?: {
|
|
83
|
-
[headerKey: string]: string;
|
|
84
|
-
};
|
|
85
82
|
}
|
|
86
83
|
type TQueryGroups = {
|
|
87
84
|
[EQueriesGroups.INVENTORY]: {
|
|
@@ -6,6 +6,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.QueryResult = exports.QUERY_GROUPS = exports.EFilterParams = exports.EChartsCash = exports.EChartsMisc = exports.EChartsReceivable = exports.EChartsInventory = exports.EQueriesGroups = void 0;
|
|
7
7
|
const mongoose_1 = __importDefault(require("mongoose"));
|
|
8
8
|
const unit_cost_difference_1 = require("../queries/inventory/unit-cost-difference");
|
|
9
|
+
const turn_1 = require("../queries/inventory/turn");
|
|
10
|
+
const invoice_difference_1 = require("../queries/inventory/invoice-difference");
|
|
9
11
|
var EQueriesGroups;
|
|
10
12
|
(function (EQueriesGroups) {
|
|
11
13
|
EQueriesGroups["INVENTORY"] = "INVENTORY";
|
|
@@ -58,48 +60,63 @@ var EFilterParams;
|
|
|
58
60
|
})(EFilterParams || (exports.EFilterParams = EFilterParams = {}));
|
|
59
61
|
exports.QUERY_GROUPS = {
|
|
60
62
|
[EQueriesGroups.INVENTORY]: {
|
|
61
|
-
[EChartsInventory.BENFORD]: { scheduled: false,
|
|
62
|
-
[EChartsInventory.INVOICE_DIFFERENCE]: {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
[EChartsInventory.BENFORD]: { scheduled: false, queryAPI: 'benford', queryFunction: null },
|
|
64
|
+
[EChartsInventory.INVOICE_DIFFERENCE]: {
|
|
65
|
+
scheduled: false,
|
|
66
|
+
queryAPI: 'invoice-difference',
|
|
67
|
+
queryFunction: invoice_difference_1.getInvoiceDifferenceFull,
|
|
68
|
+
filterParams: EFilterParams.BBC,
|
|
69
|
+
sheetTitle: 'INV.New|Dropped SKUs',
|
|
70
|
+
},
|
|
71
|
+
[EChartsInventory.EXPOSURES]: { scheduled: false, queryAPI: 'exposures', queryFunction: null },
|
|
72
|
+
[EChartsInventory.EXPOSURES_CATEGORIES]: {
|
|
73
|
+
scheduled: false,
|
|
74
|
+
queryAPI: 'exposures-categories',
|
|
75
|
+
queryFunction: null,
|
|
76
|
+
},
|
|
77
|
+
[EChartsInventory.AVERAGE_SKU_VALUES]: { scheduled: false, queryAPI: 'average-sku-values', queryFunction: null },
|
|
78
|
+
[EChartsInventory.AGING_PLOT]: { scheduled: false, queryAPI: 'aging-plot', queryFunction: null },
|
|
67
79
|
[EChartsInventory.UNIT_COST_DIFFERENCE]: {
|
|
68
80
|
scheduled: true,
|
|
69
|
-
|
|
70
|
-
queryFunction: unit_cost_difference_1.
|
|
81
|
+
queryAPI: 'unit-cost-difference',
|
|
82
|
+
queryFunction: unit_cost_difference_1.getUnitCostDifferenceFull,
|
|
71
83
|
filterParams: EFilterParams.NONE,
|
|
72
84
|
sheetTitle: 'INV.Change in unit cost',
|
|
73
|
-
header: (0, unit_cost_difference_1.getUnitCostDifferenceHeader)(),
|
|
74
85
|
},
|
|
75
|
-
[EChartsInventory.INCONSISTENT_DATA]: { scheduled: false,
|
|
76
|
-
[EChartsInventory.INVENTORY_TURN]: {
|
|
77
|
-
|
|
78
|
-
|
|
86
|
+
[EChartsInventory.INCONSISTENT_DATA]: { scheduled: false, queryAPI: 'inconsistent-data', queryFunction: null },
|
|
87
|
+
[EChartsInventory.INVENTORY_TURN]: {
|
|
88
|
+
scheduled: true,
|
|
89
|
+
queryAPI: 'turn',
|
|
90
|
+
queryFunction: turn_1.getInventoryTurnFull,
|
|
91
|
+
filterParams: EFilterParams.PERIOD,
|
|
92
|
+
sheetTitle: 'INV.Inventory turn',
|
|
93
|
+
},
|
|
94
|
+
[EChartsInventory.MOVEMENT]: { scheduled: false, queryAPI: 'movement', queryFunction: null },
|
|
95
|
+
[EChartsInventory.EXTENSION]: { scheduled: false, queryAPI: 'extension', queryFunction: null },
|
|
79
96
|
},
|
|
80
97
|
[EQueriesGroups.RECEIVABLE]: {
|
|
81
|
-
[EChartsReceivable.BENFORD]: { scheduled: false,
|
|
82
|
-
[EChartsReceivable.EXPOSURES]: { scheduled: false,
|
|
83
|
-
[EChartsReceivable.EXPOSURES_CUSTOMERS]: { scheduled: false,
|
|
84
|
-
[EChartsReceivable.DUPLICATES]: { scheduled: false,
|
|
85
|
-
[EChartsReceivable.AVERAGE_INVOICE]: { scheduled: false,
|
|
86
|
-
[EChartsReceivable.INVOICE_VALUE_PLOT]: { scheduled: false,
|
|
87
|
-
[EChartsReceivable.AGING_PLOT]: { scheduled: false,
|
|
88
|
-
[EChartsReceivable.INVOICE_DIFFERENCE]: { scheduled: false,
|
|
98
|
+
[EChartsReceivable.BENFORD]: { scheduled: false, queryAPI: 'benford', queryFunction: null },
|
|
99
|
+
[EChartsReceivable.EXPOSURES]: { scheduled: false, queryAPI: 'exposures', queryFunction: null },
|
|
100
|
+
[EChartsReceivable.EXPOSURES_CUSTOMERS]: { scheduled: false, queryAPI: 'exposures-customers', queryFunction: null },
|
|
101
|
+
[EChartsReceivable.DUPLICATES]: { scheduled: false, queryAPI: 'duplicates', queryFunction: null },
|
|
102
|
+
[EChartsReceivable.AVERAGE_INVOICE]: { scheduled: false, queryAPI: 'average-invoice', queryFunction: null },
|
|
103
|
+
[EChartsReceivable.INVOICE_VALUE_PLOT]: { scheduled: false, queryAPI: 'average-sku-values', queryFunction: null },
|
|
104
|
+
[EChartsReceivable.AGING_PLOT]: { scheduled: false, queryAPI: 'aging-plot', queryFunction: null },
|
|
105
|
+
[EChartsReceivable.INVOICE_DIFFERENCE]: { scheduled: false, queryAPI: 'invoice-difference', queryFunction: null },
|
|
89
106
|
[EChartsReceivable.PARTIALLY_PAID_RESTATED]: {
|
|
90
107
|
scheduled: false,
|
|
91
|
-
|
|
108
|
+
queryAPI: 'partially-paid-restated',
|
|
92
109
|
queryFunction: null,
|
|
93
110
|
},
|
|
94
|
-
[EChartsReceivable.AR_TURN]: { scheduled: false,
|
|
95
|
-
[EChartsReceivable.GROUP_CUSTOMERS]: { scheduled: false,
|
|
111
|
+
[EChartsReceivable.AR_TURN]: { scheduled: false, queryAPI: 'ar-turn', queryFunction: null },
|
|
112
|
+
[EChartsReceivable.GROUP_CUSTOMERS]: { scheduled: false, queryAPI: 'grouped-receivables', queryFunction: null },
|
|
96
113
|
},
|
|
97
114
|
[EQueriesGroups.OTHER]: {
|
|
98
|
-
[EChartsMisc.CONTRAS]: { scheduled: false,
|
|
115
|
+
[EChartsMisc.CONTRAS]: { scheduled: false, queryAPI: 'contras', queryFunction: null },
|
|
99
116
|
},
|
|
100
117
|
[EQueriesGroups.CASH]: {
|
|
101
|
-
[EChartsCash.TRANSACTIONS]: { scheduled: false,
|
|
102
|
-
[EChartsCash.DELUTION]: { scheduled: false,
|
|
118
|
+
[EChartsCash.TRANSACTIONS]: { scheduled: false, queryAPI: 'transactions', queryFunction: null },
|
|
119
|
+
[EChartsCash.DELUTION]: { scheduled: false, queryAPI: 'delution', queryFunction: null },
|
|
103
120
|
},
|
|
104
121
|
};
|
|
105
122
|
const QueryResultSchema = new mongoose_1.default.Schema({
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import mongoose, { Document, Model } from 'mongoose';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { getUnitCostDifferenceFull } from '../queries/inventory/unit-cost-difference';
|
|
4
|
+
import { getInventoryTurnFull } from '../queries/inventory/turn';
|
|
5
|
+
import { getInvoiceDifferenceFull } from '../queries/inventory/invoice-difference';
|
|
4
6
|
|
|
5
7
|
export type TQueryParams = {
|
|
6
8
|
borrowerId: mongoose.Types.ObjectId;
|
|
@@ -61,11 +63,10 @@ export enum EFilterParams {
|
|
|
61
63
|
|
|
62
64
|
interface IQueryDetail {
|
|
63
65
|
scheduled: boolean;
|
|
64
|
-
|
|
66
|
+
queryAPI: string;
|
|
65
67
|
queryFunction: ((params: TQueryParams) => unknown) | null;
|
|
66
68
|
filterParams?: EFilterParams;
|
|
67
69
|
sheetTitle?: string;
|
|
68
|
-
header?: { [headerKey: string]: string };
|
|
69
70
|
}
|
|
70
71
|
|
|
71
72
|
type TQueryGroups = {
|
|
@@ -85,51 +86,66 @@ type TQueryGroups = {
|
|
|
85
86
|
|
|
86
87
|
export const QUERY_GROUPS: TQueryGroups = {
|
|
87
88
|
[EQueriesGroups.INVENTORY]: {
|
|
88
|
-
[EChartsInventory.BENFORD]: { scheduled: false,
|
|
89
|
-
[EChartsInventory.INVOICE_DIFFERENCE]: {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
89
|
+
[EChartsInventory.BENFORD]: { scheduled: false, queryAPI: 'benford', queryFunction: null },
|
|
90
|
+
[EChartsInventory.INVOICE_DIFFERENCE]: {
|
|
91
|
+
scheduled: false,
|
|
92
|
+
queryAPI: 'invoice-difference',
|
|
93
|
+
queryFunction: getInvoiceDifferenceFull,
|
|
94
|
+
filterParams: EFilterParams.BBC,
|
|
95
|
+
sheetTitle: 'INV.New|Dropped SKUs',
|
|
96
|
+
},
|
|
97
|
+
[EChartsInventory.EXPOSURES]: { scheduled: false, queryAPI: 'exposures', queryFunction: null },
|
|
98
|
+
[EChartsInventory.EXPOSURES_CATEGORIES]: {
|
|
99
|
+
scheduled: false,
|
|
100
|
+
queryAPI: 'exposures-categories',
|
|
101
|
+
queryFunction: null,
|
|
102
|
+
},
|
|
103
|
+
[EChartsInventory.AVERAGE_SKU_VALUES]: { scheduled: false, queryAPI: 'average-sku-values', queryFunction: null },
|
|
104
|
+
[EChartsInventory.AGING_PLOT]: { scheduled: false, queryAPI: 'aging-plot', queryFunction: null },
|
|
94
105
|
[EChartsInventory.UNIT_COST_DIFFERENCE]: {
|
|
95
106
|
scheduled: true,
|
|
96
|
-
|
|
97
|
-
queryFunction:
|
|
107
|
+
queryAPI: 'unit-cost-difference',
|
|
108
|
+
queryFunction: getUnitCostDifferenceFull,
|
|
98
109
|
filterParams: EFilterParams.NONE,
|
|
99
110
|
sheetTitle: 'INV.Change in unit cost',
|
|
100
|
-
header: getUnitCostDifferenceHeader(),
|
|
101
111
|
},
|
|
102
|
-
[EChartsInventory.INCONSISTENT_DATA]: { scheduled: false,
|
|
103
|
-
[EChartsInventory.INVENTORY_TURN]: {
|
|
104
|
-
|
|
105
|
-
|
|
112
|
+
[EChartsInventory.INCONSISTENT_DATA]: { scheduled: false, queryAPI: 'inconsistent-data', queryFunction: null },
|
|
113
|
+
[EChartsInventory.INVENTORY_TURN]: {
|
|
114
|
+
scheduled: true,
|
|
115
|
+
queryAPI: 'turn',
|
|
116
|
+
queryFunction: getInventoryTurnFull,
|
|
117
|
+
filterParams: EFilterParams.PERIOD,
|
|
118
|
+
sheetTitle: 'INV.Inventory turn',
|
|
119
|
+
},
|
|
120
|
+
[EChartsInventory.MOVEMENT]: { scheduled: false, queryAPI: 'movement', queryFunction: null },
|
|
121
|
+
[EChartsInventory.EXTENSION]: { scheduled: false, queryAPI: 'extension', queryFunction: null },
|
|
106
122
|
},
|
|
107
123
|
|
|
108
124
|
[EQueriesGroups.RECEIVABLE]: {
|
|
109
|
-
[EChartsReceivable.BENFORD]: { scheduled: false,
|
|
110
|
-
[EChartsReceivable.EXPOSURES]: { scheduled: false,
|
|
111
|
-
[EChartsReceivable.EXPOSURES_CUSTOMERS]: { scheduled: false,
|
|
112
|
-
[EChartsReceivable.DUPLICATES]: { scheduled: false,
|
|
113
|
-
[EChartsReceivable.AVERAGE_INVOICE]: { scheduled: false,
|
|
114
|
-
[EChartsReceivable.INVOICE_VALUE_PLOT]: { scheduled: false,
|
|
115
|
-
[EChartsReceivable.AGING_PLOT]: { scheduled: false,
|
|
116
|
-
[EChartsReceivable.INVOICE_DIFFERENCE]: { scheduled: false,
|
|
125
|
+
[EChartsReceivable.BENFORD]: { scheduled: false, queryAPI: 'benford', queryFunction: null },
|
|
126
|
+
[EChartsReceivable.EXPOSURES]: { scheduled: false, queryAPI: 'exposures', queryFunction: null },
|
|
127
|
+
[EChartsReceivable.EXPOSURES_CUSTOMERS]: { scheduled: false, queryAPI: 'exposures-customers', queryFunction: null },
|
|
128
|
+
[EChartsReceivable.DUPLICATES]: { scheduled: false, queryAPI: 'duplicates', queryFunction: null },
|
|
129
|
+
[EChartsReceivable.AVERAGE_INVOICE]: { scheduled: false, queryAPI: 'average-invoice', queryFunction: null },
|
|
130
|
+
[EChartsReceivable.INVOICE_VALUE_PLOT]: { scheduled: false, queryAPI: 'average-sku-values', queryFunction: null },
|
|
131
|
+
[EChartsReceivable.AGING_PLOT]: { scheduled: false, queryAPI: 'aging-plot', queryFunction: null },
|
|
132
|
+
[EChartsReceivable.INVOICE_DIFFERENCE]: { scheduled: false, queryAPI: 'invoice-difference', queryFunction: null },
|
|
117
133
|
[EChartsReceivable.PARTIALLY_PAID_RESTATED]: {
|
|
118
134
|
scheduled: false,
|
|
119
|
-
|
|
135
|
+
queryAPI: 'partially-paid-restated',
|
|
120
136
|
queryFunction: null,
|
|
121
137
|
},
|
|
122
|
-
[EChartsReceivable.AR_TURN]: { scheduled: false,
|
|
123
|
-
[EChartsReceivable.GROUP_CUSTOMERS]: { scheduled: false,
|
|
138
|
+
[EChartsReceivable.AR_TURN]: { scheduled: false, queryAPI: 'ar-turn', queryFunction: null },
|
|
139
|
+
[EChartsReceivable.GROUP_CUSTOMERS]: { scheduled: false, queryAPI: 'grouped-receivables', queryFunction: null },
|
|
124
140
|
},
|
|
125
141
|
|
|
126
142
|
[EQueriesGroups.OTHER]: {
|
|
127
|
-
[EChartsMisc.CONTRAS]: { scheduled: false,
|
|
143
|
+
[EChartsMisc.CONTRAS]: { scheduled: false, queryAPI: 'contras', queryFunction: null },
|
|
128
144
|
},
|
|
129
145
|
|
|
130
146
|
[EQueriesGroups.CASH]: {
|
|
131
|
-
[EChartsCash.TRANSACTIONS]: { scheduled: false,
|
|
132
|
-
[EChartsCash.DELUTION]: { scheduled: false,
|
|
147
|
+
[EChartsCash.TRANSACTIONS]: { scheduled: false, queryAPI: 'transactions', queryFunction: null },
|
|
148
|
+
[EChartsCash.DELUTION]: { scheduled: false, queryAPI: 'delution', queryFunction: null },
|
|
133
149
|
},
|
|
134
150
|
};
|
|
135
151
|
|
package/package.json
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TQueryParams } from '../../models/QueryResult.model';
|
|
2
|
+
export declare const getInvoiceDifferenceFull: (params: TQueryParams) => Promise<{
|
|
3
|
+
added: {}[];
|
|
4
|
+
removed: {}[];
|
|
5
|
+
}>;
|
|
6
|
+
export declare const getInvoiceDifference: (params: TQueryParams) => Promise<{
|
|
7
|
+
addedInventories: any[];
|
|
8
|
+
removedInventories: any[];
|
|
9
|
+
}>;
|
|
@@ -0,0 +1,50 @@
|
|
|
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.getInvoiceDifference = exports.getInvoiceDifferenceFull = void 0;
|
|
7
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
8
|
+
const collaterals_enum_1 = require("../../enums/collaterals.enum");
|
|
9
|
+
const collaterals_db_1 = require("../../db/collaterals.db");
|
|
10
|
+
const BBCDate_model_1 = require("../../models/BBCDate.model");
|
|
11
|
+
const excel_helper_1 = require("../../helpers/excel.helper");
|
|
12
|
+
const getInvoiceDifferenceFull = async (params) => {
|
|
13
|
+
const { addedInventories, removedInventories } = await (0, exports.getInvoiceDifference)(params);
|
|
14
|
+
const headerAdded = getInvoiceDifferenceHeader();
|
|
15
|
+
const headerRemoved = getInvoiceDifferenceHeader();
|
|
16
|
+
const addedInventoriesFull = (0, excel_helper_1.addHeaderToData)(headerAdded, addedInventories);
|
|
17
|
+
const removedInventoriesFull = (0, excel_helper_1.addHeaderToData)(headerRemoved, removedInventories);
|
|
18
|
+
return {
|
|
19
|
+
'added': addedInventoriesFull, 'removed': removedInventoriesFull,
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.getInvoiceDifferenceFull = getInvoiceDifferenceFull;
|
|
23
|
+
const getInvoiceDifference = async (params) => {
|
|
24
|
+
const { bbcDateId } = params;
|
|
25
|
+
const currentBbcDate = await BBCDate_model_1.BBCDateModel.findById(bbcDateId);
|
|
26
|
+
const previousDocuments = await (0, collaterals_db_1.getPreviousCollateralDocument)(currentBbcDate.borrowerId.toString(), currentBbcDate.bbcDate, collaterals_enum_1.ECollaterals.INVENTORY, 1);
|
|
27
|
+
const items1 = await (0, collaterals_db_1.getCollateralListByBBCAndType)(currentBbcDate._id.toString(), collaterals_enum_1.ECollaterals.INVENTORY);
|
|
28
|
+
const items2 = await (0, collaterals_db_1.getCollateralListByBBCAndType)(previousDocuments[0]._id.toString(), collaterals_enum_1.ECollaterals.INVENTORY);
|
|
29
|
+
const compareInventories = (items1, items2) => {
|
|
30
|
+
const addedInventories = lodash_1.default.differenceBy(items1, items2, 'sku');
|
|
31
|
+
const removedInventories = lodash_1.default.differenceBy(items2, items1, 'sku');
|
|
32
|
+
return { addedInventories, removedInventories };
|
|
33
|
+
};
|
|
34
|
+
return compareInventories(items1, items2);
|
|
35
|
+
};
|
|
36
|
+
exports.getInvoiceDifference = getInvoiceDifference;
|
|
37
|
+
const getInvoiceDifferenceHeader = () => {
|
|
38
|
+
return {
|
|
39
|
+
bbcDate: 'BBC date',
|
|
40
|
+
category: 'Category',
|
|
41
|
+
sku: 'SKU',
|
|
42
|
+
expiryDate: 'Expiry date',
|
|
43
|
+
qty: 'Quantity',
|
|
44
|
+
unitCost: 'Unit amount',
|
|
45
|
+
value: 'Value',
|
|
46
|
+
skuDescription1: 'SKU description 1',
|
|
47
|
+
skuDescription2: 'SKU description 2',
|
|
48
|
+
skuDescription3: 'SKU description 3',
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import _ from 'lodash';
|
|
2
|
+
|
|
3
|
+
import { ECollaterals } from '../../enums/collaterals.enum';
|
|
4
|
+
import { getCollateralListByBBCAndType, getPreviousCollateralDocument } from '../../db/collaterals.db';
|
|
5
|
+
import { BBCDateModel } from '../../models/BBCDate.model';
|
|
6
|
+
import { TQueryParams } from '../../models/QueryResult.model';
|
|
7
|
+
import { addHeaderToData } from '../../helpers/excel.helper';
|
|
8
|
+
|
|
9
|
+
export const getInvoiceDifferenceFull = async (params: TQueryParams) => {
|
|
10
|
+
const { addedInventories, removedInventories } = await getInvoiceDifference(params);
|
|
11
|
+
const headerAdded = getInvoiceDifferenceHeader();
|
|
12
|
+
const headerRemoved = getInvoiceDifferenceHeader();
|
|
13
|
+
|
|
14
|
+
const addedInventoriesFull = addHeaderToData(headerAdded, addedInventories);
|
|
15
|
+
const removedInventoriesFull = addHeaderToData(headerRemoved, removedInventories);
|
|
16
|
+
|
|
17
|
+
return {
|
|
18
|
+
'added': addedInventoriesFull, 'removed': removedInventoriesFull,
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const getInvoiceDifference = async (params: TQueryParams) => {
|
|
23
|
+
const { bbcDateId } = params;
|
|
24
|
+
const currentBbcDate = await BBCDateModel.findById(bbcDateId);
|
|
25
|
+
const previousDocuments = await getPreviousCollateralDocument(currentBbcDate.borrowerId.toString(), currentBbcDate.bbcDate, ECollaterals.INVENTORY, 1);
|
|
26
|
+
const items1 = await getCollateralListByBBCAndType(currentBbcDate._id.toString(), ECollaterals.INVENTORY);
|
|
27
|
+
const items2 = await getCollateralListByBBCAndType(previousDocuments[0]._id.toString(), ECollaterals.INVENTORY);
|
|
28
|
+
|
|
29
|
+
const compareInventories = (items1: any[], items2: any[]) => {
|
|
30
|
+
const addedInventories = _.differenceBy(items1, items2, 'sku');
|
|
31
|
+
const removedInventories = _.differenceBy(items2, items1, 'sku');
|
|
32
|
+
return { addedInventories, removedInventories };
|
|
33
|
+
};
|
|
34
|
+
return compareInventories(items1, items2);
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getInvoiceDifferenceHeader = () => {
|
|
38
|
+
return {
|
|
39
|
+
bbcDate: 'BBC date',
|
|
40
|
+
category: 'Category',
|
|
41
|
+
sku: 'SKU',
|
|
42
|
+
expiryDate: 'Expiry date',
|
|
43
|
+
qty: 'Quantity',
|
|
44
|
+
unitCost: 'Unit amount',
|
|
45
|
+
value: 'Value',
|
|
46
|
+
skuDescription1: 'SKU description 1',
|
|
47
|
+
skuDescription2: 'SKU description 2',
|
|
48
|
+
skuDescription3: 'SKU description 3',
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TQueryParams } from '../../models/QueryResult.model';
|
|
2
|
+
export declare const getInventoryTurnFull: (params: TQueryParams) => Promise<{
|
|
3
|
+
'by unit': {}[];
|
|
4
|
+
'by value': {}[];
|
|
5
|
+
}>;
|
|
6
|
+
export declare const getInventoryTurn: (borrowerId: string, startDate: string, endDate: string) => Promise<{
|
|
7
|
+
tableByUnit: any[];
|
|
8
|
+
tableByValue: any[];
|
|
9
|
+
}>;
|