gemcap-be-common 1.2.91 → 1.2.92

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.
@@ -25,6 +25,7 @@
25
25
  import mongoose from 'mongoose';
26
26
  import { IPaginatorOptions } from '../interfaces/collaterals.interface';
27
27
  import { ECollaterals } from '../enums/collaterals.enum';
28
+ import { IBBCSheetDoc } from '../models/BBCSheet.model';
28
29
  export interface IBbcDateWithSheets {
29
30
  _id: mongoose.Types.ObjectId;
30
31
  bbcDate: Date;
@@ -84,7 +85,7 @@ export declare const ITEMS_PAGINATION: (paginatorOptions: IPaginatorOptions) =>
84
85
  $skip?: undefined;
85
86
  })[];
86
87
  export declare const findCollateralsWithSheets: (borrowerId: string, collateralTypes?: ECollaterals[]) => Promise<IBbcDateWithSheets[]>;
87
- export declare const getBBCSheetsForBorrowerAndType: (borrowerId: string, collateralType: ECollaterals) => Promise<import("../models/BBCSheet.model").IBBCSheetDoc[]>;
88
+ export declare const getBBCSheetsForBorrowerAndType: (borrowerId: string, collateralType: ECollaterals) => Promise<IBBCSheetDoc[]>;
88
89
  export declare const getCollateralListBySheet: (sheetIds: string[], collateralType: ECollaterals) => Promise<any>;
89
90
  export declare const getPreviousCollateralDocument: (borrowerId: string, date: Date, collateralType: ECollaterals, limit?: number) => Promise<{
90
91
  _id: mongoose.Types.ObjectId;
@@ -92,3 +93,13 @@ export declare const getPreviousCollateralDocument: (borrowerId: string, date: D
92
93
  }[]>;
93
94
  export declare const getCollateralDocsByBBC: (bbcIds: string[], collateralType: ECollaterals) => Promise<any>;
94
95
  export declare const getCollateralListByBBCAndType: (bbcDateId: string, collateralType: ECollaterals) => Promise<any>;
96
+ export declare const findCollateralSheets: (bbcDateId: string, collateralType: ECollaterals) => mongoose.Query<(mongoose.Document<unknown, {}, IBBCSheetDoc> & IBBCSheetDoc & {
97
+ _id: mongoose.Types.ObjectId;
98
+ })[], mongoose.Document<unknown, {}, IBBCSheetDoc> & IBBCSheetDoc & {
99
+ _id: mongoose.Types.ObjectId;
100
+ }, {}, IBBCSheetDoc, "find">;
101
+ export declare const findCollateralSheetsById: (collateralsId: string) => Promise<IBBCSheetDoc>;
102
+ export declare const getCollateralListBySheetId: (sheet: IBBCSheetDoc, paginatorOptions?: IPaginatorOptions) => Promise<any>;
103
+ export declare const findCollaterals: (collateralsId: string, group: boolean, paginatorOptions?: IPaginatorOptions) => Promise<any>;
104
+ export declare const excludeNoDataColumns: (data: any[], columns: string[]) => Pick<any, string>[];
105
+ export declare const addCustomerGroups: (data: any[], borrowerId: string) => Promise<any[]>;
@@ -3,8 +3,9 @@ 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.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;
6
+ exports.addCustomerGroups = exports.excludeNoDataColumns = exports.findCollaterals = exports.getCollateralListBySheetId = exports.findCollateralSheetsById = exports.findCollateralSheets = 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
+ const lodash_1 = __importDefault(require("lodash"));
8
9
  const _models_1 = require("../models/_models");
9
10
  const collaterals_enum_1 = require("../enums/collaterals.enum");
10
11
  const AccountPayableItem_model_1 = require("../models/AccountPayableItem.model");
@@ -15,6 +16,7 @@ const ReceivableItem_model_1 = require("../models/ReceivableItem.model");
15
16
  const enums_helper_1 = require("../helpers/enums.helper");
16
17
  const bbcSheets_db_1 = require("./bbcSheets.db");
17
18
  const bbcDates_db_1 = require("./bbcDates.db");
19
+ const groups_db_1 = require("./groups.db");
18
20
  exports.collateralMap = {
19
21
  [collaterals_enum_1.ECollaterals.INVENTORY]: InventoryItem_model_1.InventoryItemModel,
20
22
  [collaterals_enum_1.ECollaterals.RECEIVABLE]: ReceivableItem_model_1.ReceivableItemModel,
@@ -287,3 +289,101 @@ const getCollateralListByBBCAndType = async (bbcDateId, collateralType) => {
287
289
  return (0, exports.getCollateralListBySheet)(sheets.map((sheet) => sheet._id), collateralType);
288
290
  };
289
291
  exports.getCollateralListByBBCAndType = getCollateralListByBBCAndType;
292
+ const findCollateralSheets = (bbcDateId, collateralType) => {
293
+ return BBCSheet_model_1.BBCSheetModel.find({ bbcDateId, dataType: collateralType });
294
+ };
295
+ exports.findCollateralSheets = findCollateralSheets;
296
+ const findCollateralSheetsById = async (collateralsId) => {
297
+ return BBCSheet_model_1.BBCSheetModel.findById(collateralsId);
298
+ };
299
+ exports.findCollateralSheetsById = findCollateralSheetsById;
300
+ const getCollateralsBySheet = async (sheet, paginatorOptions) => {
301
+ const groupFields = {
302
+ bbcDate: 'bbc.bbcDate',
303
+ borrowerId: 'bbc.borrowerId',
304
+ fileName: 'bbcSheet.fileName',
305
+ sheetName: 'bbcSheet.sheetName',
306
+ };
307
+ const { groupQueries, itemQueries, enumKey } = (0, exports.createQuery)(groupFields, sheet.dataType);
308
+ const groupingQuery = { _id: '$bbcSheetId', ...groupQueries, items: { $push: itemQueries } };
309
+ const collateralSheets = await exports.collateralMap[enumKey].aggregate([
310
+ {
311
+ $match: {
312
+ 'bbcSheetId': new mongoose_1.default.Types.ObjectId(sheet.id),
313
+ },
314
+ },
315
+ ...exports.COLLATERALS_LOOKUP,
316
+ {
317
+ $sort: {
318
+ order: 1,
319
+ },
320
+ },
321
+ ...(0, exports.ITEMS_PAGINATION)(paginatorOptions),
322
+ {
323
+ $group: groupingQuery,
324
+ },
325
+ ]);
326
+ if (collateralSheets.length === 0) {
327
+ const bbcDates = await BBCDate_model_1.BBCDateModel.aggregate([
328
+ {
329
+ $match: {
330
+ '_id': sheet.bbcDateId,
331
+ },
332
+ },
333
+ ]);
334
+ if (bbcDates.length === 0) {
335
+ return [];
336
+ }
337
+ return [{
338
+ _id: sheet._id,
339
+ bbcDate: bbcDates[0].bbcDate,
340
+ borrowerId: bbcDates[0].borrowerId,
341
+ fileName: sheet.fileName,
342
+ sheetName: sheet.sheetName,
343
+ items: [],
344
+ }];
345
+ }
346
+ return collateralSheets;
347
+ };
348
+ const getCollateralListBySheetId = async (sheet, paginatorOptions) => {
349
+ const enumKey = (0, enums_helper_1.getEnumKeyByEnumValue)(collaterals_enum_1.ECollaterals, sheet.dataType);
350
+ return exports.collateralMap[enumKey].aggregate([
351
+ {
352
+ $match: {
353
+ 'bbcSheetId': new mongoose_1.default.Types.ObjectId(sheet.id),
354
+ },
355
+ },
356
+ ...exports.COLLATERALS_LOOKUP,
357
+ {
358
+ $sort: {
359
+ order: 1,
360
+ },
361
+ },
362
+ ...(0, exports.ITEMS_PAGINATION)(paginatorOptions),
363
+ ]);
364
+ };
365
+ exports.getCollateralListBySheetId = getCollateralListBySheetId;
366
+ const findCollaterals = async (collateralsId, group, paginatorOptions) => {
367
+ const sheet = await (0, exports.findCollateralSheetsById)(collateralsId);
368
+ if (group) {
369
+ return await getCollateralsBySheet(sheet, paginatorOptions);
370
+ }
371
+ return await (0, exports.getCollateralListBySheetId)(sheet, paginatorOptions);
372
+ };
373
+ exports.findCollaterals = findCollaterals;
374
+ const excludeNoDataColumns = (data, columns) => {
375
+ return data.map((dataRow) => lodash_1.default.pick(dataRow, columns));
376
+ };
377
+ exports.excludeNoDataColumns = excludeNoDataColumns;
378
+ const addCustomerGroups = async (data, borrowerId) => {
379
+ const groupName = 'customers';
380
+ const groups = await (0, groups_db_1.getBorrowerGroups)(borrowerId, groupName);
381
+ return data.map((dataRow) => {
382
+ const foundGroup = groups[groupName].find((group) => group.items.includes(dataRow.customerTitle));
383
+ return {
384
+ ...dataRow,
385
+ customerGroup: foundGroup ? foundGroup.groupName : dataRow.customerTitle,
386
+ };
387
+ });
388
+ };
389
+ exports.addCustomerGroups = addCustomerGroups;
@@ -1,16 +1,18 @@
1
1
  import mongoose from 'mongoose';
2
+ import _ from 'lodash';
2
3
 
3
4
  import { MODEL_NAMES } from '../models/_models';
4
5
  import { IPaginatorOptions } from '../interfaces/collaterals.interface';
5
6
  import { ECollaterals } from '../enums/collaterals.enum';
6
7
  import { ACCOUNT_PAYABLE_FIELDS, AccountPayableItemModel } from '../models/AccountPayableItem.model';
7
- import { BBCDateModel } from '../models/BBCDate.model';
8
- import { BBCSheetModel } from '../models/BBCSheet.model';
8
+ import { BBCDateModel, IBBCDateDoc } from '../models/BBCDate.model';
9
+ import { BBCSheetModel, IBBCSheetDoc } from '../models/BBCSheet.model';
9
10
  import { INVENTORY_FIELDS, InventoryItemModel } from '../models/InventoryItem.model';
10
11
  import { RECEIVABLE_FIELDS, ReceivableItemModel } from '../models/ReceivableItem.model';
11
12
  import { getEnumKeyByEnumValue } from '../helpers/enums.helper';
12
13
  import { getBBCSheetsByType } from './bbcSheets.db';
13
14
  import { getBBCDatesByBorrower } from './bbcDates.db';
15
+ import { getBorrowerGroups } from './groups.db';
14
16
 
15
17
  export interface IBbcDateWithSheets {
16
18
  _id: mongoose.Types.ObjectId;
@@ -76,7 +78,7 @@ export const createQuery = (groupFields: { [groupFields: string]: string }, coll
76
78
  .map((fieldKey) => ({ [fieldKey]: `$${fieldKey}` }))
77
79
  .reduce((acc, group) => ({ ...acc, ...group }), {});
78
80
  return { groupQueries, itemQueries, enumKey };
79
- }
81
+ };
80
82
 
81
83
  export const ITEMS_PAGINATION = (paginatorOptions: IPaginatorOptions) => {
82
84
  if (!paginatorOptions) {
@@ -262,7 +264,7 @@ export const getCollateralDocsByBBC = async (bbcIds: string[], collateralType: E
262
264
 
263
265
  const bbcSheets = await getBBCSheetsByType(bbcIds, collateralType);
264
266
 
265
- const groupFields = {
267
+ const groupFields = {
266
268
  bbcDate: 'bbc.bbcDate',
267
269
  borrowerId: 'bbc.borrowerId',
268
270
  };
@@ -296,9 +298,112 @@ export const getCollateralDocsByBBC = async (bbcIds: string[], collateralType: E
296
298
  return BBCs.map((BBC) => ({ ...BBC, items: [] }));
297
299
  }
298
300
  return aggregationResult;
299
- }
301
+ };
300
302
 
301
303
  export const getCollateralListByBBCAndType = async (bbcDateId: string, collateralType: ECollaterals) => {
302
304
  const sheets = await getBBCSheetsByType([bbcDateId], collateralType);
303
305
  return getCollateralListBySheet(sheets.map((sheet) => sheet._id), collateralType);
306
+ };
307
+
308
+ export const findCollateralSheets = (bbcDateId: string, collateralType: ECollaterals) => {
309
+ return BBCSheetModel.find({ bbcDateId, dataType: collateralType });
310
+ };
311
+
312
+ export const findCollateralSheetsById = async (collateralsId: string): Promise<IBBCSheetDoc> => {
313
+ return BBCSheetModel.findById(collateralsId);
314
+ };
315
+
316
+ const getCollateralsBySheet = async (sheet: IBBCSheetDoc, paginatorOptions?: IPaginatorOptions) => {
317
+
318
+ const groupFields = {
319
+ bbcDate: 'bbc.bbcDate',
320
+ borrowerId: 'bbc.borrowerId',
321
+ fileName: 'bbcSheet.fileName',
322
+ sheetName: 'bbcSheet.sheetName',
323
+ };
324
+
325
+ const { groupQueries, itemQueries, enumKey } = createQuery(groupFields, sheet.dataType);
326
+ const groupingQuery = { _id: '$bbcSheetId', ...groupQueries, items: { $push: itemQueries } };
327
+
328
+ const collateralSheets = await collateralMap[enumKey].aggregate([
329
+ {
330
+ $match: {
331
+ 'bbcSheetId': new mongoose.Types.ObjectId(sheet.id),
332
+ },
333
+ },
334
+ ...COLLATERALS_LOOKUP,
335
+ {
336
+ $sort: {
337
+ order: 1,
338
+ },
339
+ },
340
+ ...ITEMS_PAGINATION(paginatorOptions),
341
+ {
342
+ $group: groupingQuery,
343
+ },
344
+ ]);
345
+ if (collateralSheets.length === 0) {
346
+ const bbcDates = await BBCDateModel.aggregate<IBBCDateDoc>([
347
+ {
348
+ $match: {
349
+ '_id': sheet.bbcDateId,
350
+ },
351
+ },
352
+ ]);
353
+ if (bbcDates.length === 0) {
354
+ return [];
355
+ }
356
+ return [{
357
+ _id: sheet._id,
358
+ bbcDate: bbcDates[0].bbcDate,
359
+ borrowerId: bbcDates[0].borrowerId,
360
+ fileName: sheet.fileName,
361
+ sheetName: sheet.sheetName,
362
+ items: [],
363
+ }];
364
+ }
365
+ return collateralSheets;
366
+ };
367
+
368
+ export const getCollateralListBySheetId = async (sheet: IBBCSheetDoc, paginatorOptions?: IPaginatorOptions) => {
369
+ const enumKey = getEnumKeyByEnumValue(ECollaterals, sheet.dataType);
370
+
371
+ return collateralMap[enumKey].aggregate([
372
+ {
373
+ $match: {
374
+ 'bbcSheetId': new mongoose.Types.ObjectId(sheet.id),
375
+ },
376
+ },
377
+ ...COLLATERALS_LOOKUP,
378
+ {
379
+ $sort: {
380
+ order: 1,
381
+ },
382
+ },
383
+ ...ITEMS_PAGINATION(paginatorOptions),
384
+ ]);
385
+ };
386
+
387
+ export const findCollaterals = async (collateralsId: string, group: boolean, paginatorOptions?: IPaginatorOptions) => {
388
+ const sheet = await findCollateralSheetsById(collateralsId);
389
+ if (group) {
390
+ return await getCollateralsBySheet(sheet, paginatorOptions);
391
+ }
392
+ return await getCollateralListBySheetId(sheet, paginatorOptions);
393
+ };
394
+
395
+ export const excludeNoDataColumns = (data: any[], columns: string[]) => {
396
+ return data.map((dataRow) => _.pick(dataRow, columns));
397
+ }
398
+
399
+ export const addCustomerGroups = async (data: any[], borrowerId: string) => {
400
+ const groupName = 'customers';
401
+ const groups = await getBorrowerGroups(borrowerId, groupName);
402
+ return data.map((dataRow) => {
403
+ const foundGroup = groups[groupName].find((group) => group.items.includes(dataRow.customerTitle));
404
+ return {
405
+ ...dataRow,
406
+ customerGroup: foundGroup ? foundGroup.groupName : dataRow.customerTitle,
407
+ };
408
+ });
304
409
  }
@@ -0,0 +1,45 @@
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" />
25
+ /// <reference types="mongoose/types/inferschematype" />
26
+ export declare const groupsMap: {
27
+ customers: {
28
+ Model: import("mongoose").Model<import("../models/CustomerGroup.model").ICustomerGroupDocument, {}, {}, {}, import("mongoose").Document<unknown, {}, import("../models/CustomerGroup.model").ICustomerGroupDocument> & import("../models/CustomerGroup.model").ICustomerGroupDocument & {
29
+ _id: import("mongoose").Types.ObjectId;
30
+ }, any>;
31
+ };
32
+ categories: {
33
+ Model: import("mongoose").Model<import("../models/CustomerGroup.model").ICustomerGroupDocument, {}, {}, {}, import("mongoose").Document<unknown, {}, import("../models/CustomerGroup.model").ICustomerGroupDocument> & import("../models/CustomerGroup.model").ICustomerGroupDocument & {
34
+ _id: import("mongoose").Types.ObjectId;
35
+ }, any>;
36
+ };
37
+ vendors: {
38
+ Model: import("mongoose").Model<import("../models/CustomerGroup.model").ICustomerGroupDocument, {}, {}, {}, import("mongoose").Document<unknown, {}, import("../models/CustomerGroup.model").ICustomerGroupDocument> & import("../models/CustomerGroup.model").ICustomerGroupDocument & {
39
+ _id: import("mongoose").Types.ObjectId;
40
+ }, any>;
41
+ };
42
+ };
43
+ export declare const getBorrowerGroups: (borrowerId: string, relationshipGroups: string | string[]) => Promise<{
44
+ [x: string]: any;
45
+ }>;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBorrowerGroups = exports.groupsMap = void 0;
4
+ const CustomerGroup_model_1 = require("../models/CustomerGroup.model");
5
+ exports.groupsMap = {
6
+ customers: { Model: CustomerGroup_model_1.CustomerGroupModel },
7
+ categories: { Model: CustomerGroup_model_1.CustomerGroupModel },
8
+ vendors: { Model: CustomerGroup_model_1.CustomerGroupModel },
9
+ };
10
+ const getBorrowerGroups = async (borrowerId, relationshipGroups) => {
11
+ if (typeof relationshipGroups == 'string') {
12
+ relationshipGroups = [relationshipGroups];
13
+ }
14
+ const allCustomerGroups = await Promise.all(relationshipGroups.map(async (groupName) => {
15
+ const groups = await exports.groupsMap[groupName].Model.find({ borrowerId }).sort({ 'createdAt': 1 });
16
+ return { [groupName]: groups };
17
+ }));
18
+ return allCustomerGroups.reduce((acc, group) => {
19
+ return { ...acc, ...group };
20
+ }, {});
21
+ };
22
+ exports.getBorrowerGroups = getBorrowerGroups;
@@ -0,0 +1,20 @@
1
+ import { CustomerGroupModel } from '../models/CustomerGroup.model';
2
+
3
+ export const groupsMap = {
4
+ customers: { Model: CustomerGroupModel },
5
+ categories: { Model: CustomerGroupModel },
6
+ vendors: { Model: CustomerGroupModel },
7
+ }
8
+
9
+ export const getBorrowerGroups = async (borrowerId: string, relationshipGroups: string | string[]) => {
10
+ if (typeof relationshipGroups == 'string') {
11
+ relationshipGroups = [relationshipGroups];
12
+ }
13
+ const allCustomerGroups = await Promise.all(relationshipGroups.map(async (groupName) => {
14
+ const groups = await groupsMap[groupName].Model.find({ borrowerId }).sort({ 'createdAt': 1 });
15
+ return { [groupName]: groups };
16
+ }));
17
+ return allCustomerGroups.reduce((acc, group) => {
18
+ return { ...acc, ...group };
19
+ }, {});
20
+ };
@@ -0,0 +1,29 @@
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, { Document } from 'mongoose';
26
+ import { IBorrowerGroup } from '../interfaces/group.interface';
27
+ export interface ICustomerGroupDocument extends IBorrowerGroup, Document {
28
+ }
29
+ export declare const CustomerGroupModel: mongoose.Model<ICustomerGroupDocument>;
@@ -0,0 +1,25 @@
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.CustomerGroupModel = void 0;
7
+ const mongoose_1 = __importDefault(require("mongoose"));
8
+ const _models_1 = require("./_models");
9
+ const mongooseLeanId = require('gemcap-be-common/plugins/id.plugin');
10
+ const CustomerGroupSchema = new mongoose_1.default.Schema({
11
+ groupName: {
12
+ type: String,
13
+ trim: true,
14
+ required: true,
15
+ },
16
+ borrowerId: {
17
+ type: mongoose_1.default.Schema.Types.ObjectId,
18
+ ref: 'borrowers',
19
+ required: true,
20
+ },
21
+ items: [String],
22
+ __v: { type: Number, select: false },
23
+ }, { timestamps: true });
24
+ CustomerGroupSchema.plugin(mongooseLeanId);
25
+ exports.CustomerGroupModel = mongoose_1.default.model(_models_1.MODEL_NAMES.customerGroups, CustomerGroupSchema);
@@ -0,0 +1,31 @@
1
+ import mongoose, { Document } from 'mongoose';
2
+
3
+ import { MODEL_NAMES } from './_models';
4
+ import { IBorrowerGroup } from '../interfaces/group.interface';
5
+
6
+ const mongooseLeanId = require('gemcap-be-common/plugins/id.plugin');
7
+
8
+ export interface ICustomerGroupDocument extends IBorrowerGroup, Document {
9
+ }
10
+
11
+ const CustomerGroupSchema = new mongoose.Schema(
12
+ {
13
+ groupName: {
14
+ type: String,
15
+ trim: true,
16
+ required: true,
17
+ },
18
+ borrowerId: {
19
+ type: mongoose.Schema.Types.ObjectId,
20
+ ref: 'borrowers',
21
+ required: true,
22
+ },
23
+ items: [String],
24
+ __v: { type: Number, select: false },
25
+ },
26
+ { timestamps: true }
27
+ );
28
+
29
+ CustomerGroupSchema.plugin(mongooseLeanId);
30
+
31
+ export const CustomerGroupModel: mongoose.Model<ICustomerGroupDocument> = mongoose.model<ICustomerGroupDocument>(MODEL_NAMES.customerGroups, CustomerGroupSchema);
@@ -28,6 +28,9 @@ export type TQueryParams = {
28
28
  bbcDateId?: mongoose.Types.ObjectId;
29
29
  startDate?: Date;
30
30
  endDate?: Date;
31
+ extraParams?: {
32
+ [key: string]: any;
33
+ };
31
34
  };
32
35
  export declare enum EQueriesGroups {
33
36
  INVENTORY = "INVENTORY",
@@ -15,6 +15,7 @@ const dublicates_1 = require("../queries/receivable/dublicates");
15
15
  const average_invoice_size_1 = require("../queries/receivable/average-invoice-size");
16
16
  const invoice_difference_2 = require("../queries/receivable/invoice-difference");
17
17
  const partially_paid_restated_1 = require("../queries/receivable/partially-paid-restated");
18
+ const grouped_receivables_1 = require("../queries/receivable/grouped-receivables");
18
19
  var EQueriesGroups;
19
20
  (function (EQueriesGroups) {
20
21
  EQueriesGroups["INVENTORY"] = "INVENTORY";
@@ -147,14 +148,20 @@ exports.QUERY_GROUPS = {
147
148
  sheetTitle: 'REC.AR movement report',
148
149
  },
149
150
  [EChartsReceivable.PARTIALLY_PAID_RESTATED]: {
150
- scheduled: false,
151
+ scheduled: true,
151
152
  queryAPI: 'partially-paid-restated',
152
153
  queryFunction: partially_paid_restated_1.getPartialPaidFull,
153
154
  filterParams: EFilterParams.PERIOD,
154
155
  sheetTitle: 'INV.Partially paid & restated',
155
156
  },
156
157
  [EChartsReceivable.AR_TURN]: { scheduled: false, queryAPI: 'ar-turn', queryFunction: null },
157
- [EChartsReceivable.GROUP_CUSTOMERS]: { scheduled: false, queryAPI: 'grouped-receivables', queryFunction: null },
158
+ [EChartsReceivable.GROUP_CUSTOMERS]: {
159
+ scheduled: true,
160
+ queryAPI: 'grouped-receivables',
161
+ queryFunction: grouped_receivables_1.getGroupedReceivablesFull,
162
+ filterParams: EFilterParams.BBC,
163
+ sheetTitle: 'REC.Detailed grouped receivables',
164
+ },
158
165
  },
159
166
  [EQueriesGroups.OTHER]: {
160
167
  [EChartsMisc.CONTRAS]: { scheduled: false, queryAPI: 'contras', queryFunction: null },
@@ -10,12 +10,14 @@ import { getReceivableDuplicatesFull } from '../queries/receivable/dublicates';
10
10
  import { getAverageInvoiceFull } from '../queries/receivable/average-invoice-size';
11
11
  import { getInvoiceDifferenceFull } from '../queries/receivable/invoice-difference';
12
12
  import { getPartialPaidFull } from '../queries/receivable/partially-paid-restated';
13
+ import { getGroupedReceivablesFull } from '../queries/receivable/grouped-receivables';
13
14
 
14
15
  export type TQueryParams = {
15
16
  borrowerId?: mongoose.Types.ObjectId;
16
17
  bbcDateId?: mongoose.Types.ObjectId;
17
18
  startDate?: Date;
18
19
  endDate?: Date;
20
+ extraParams?: { [key: string]: any };
19
21
  };
20
22
 
21
23
  export enum EQueriesGroups {
@@ -174,14 +176,20 @@ export const QUERY_GROUPS: TQueryGroups = {
174
176
  sheetTitle: 'REC.AR movement report',
175
177
  },
176
178
  [EChartsReceivable.PARTIALLY_PAID_RESTATED]: {
177
- scheduled: false,
179
+ scheduled: true,
178
180
  queryAPI: 'partially-paid-restated',
179
181
  queryFunction: getPartialPaidFull,
180
182
  filterParams: EFilterParams.PERIOD,
181
183
  sheetTitle: 'INV.Partially paid & restated',
182
184
  },
183
185
  [EChartsReceivable.AR_TURN]: { scheduled: false, queryAPI: 'ar-turn', queryFunction: null },
184
- [EChartsReceivable.GROUP_CUSTOMERS]: { scheduled: false, queryAPI: 'grouped-receivables', queryFunction: null },
186
+ [EChartsReceivable.GROUP_CUSTOMERS]: {
187
+ scheduled: true,
188
+ queryAPI: 'grouped-receivables',
189
+ queryFunction: getGroupedReceivablesFull,
190
+ filterParams: EFilterParams.BBC,
191
+ sheetTitle: 'REC.Detailed grouped receivables',
192
+ },
185
193
  },
186
194
 
187
195
  [EQueriesGroups.OTHER]: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gemcap-be-common",
3
- "version": "1.2.91",
3
+ "version": "1.2.92",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -8,7 +8,7 @@ const dayjs_1 = __importDefault(require("dayjs"));
8
8
  const excel_helper_1 = require("../../helpers/excel.helper");
9
9
  const collaterals_db_1 = require("../../db/collaterals.db");
10
10
  const collaterals_enum_1 = require("../../enums/collaterals.enum");
11
- const inventories_1 = require("../../db/inventories");
11
+ const inventories_db_1 = require("../../db/inventories.db");
12
12
  const bbcDates_db_1 = require("../../db/bbcDates.db");
13
13
  const bbcSheets_db_1 = require("../../db/bbcSheets.db");
14
14
  const getExtensionFull = async (params) => {
@@ -25,7 +25,7 @@ const getExtension = async (params) => {
25
25
  const BBCs = await (0, collaterals_db_1.getCollateralDocsByBBC)(bbcIds, collaterals_enum_1.ECollaterals.INVENTORY);
26
26
  const allInventoryBbcDates = await (0, bbcSheets_db_1.getUniqueDatesForPeriod)(borrowerId.toString(), collaterals_enum_1.ECollaterals.INVENTORY, new Date(startDate), new Date(endDate));
27
27
  const sheetIds = allInventoryBbcDates.reduce((acc, bbcGroup) => [...acc, ...bbcGroup.ids], []);
28
- const { skus } = (await (0, inventories_1.getAllUniqSKUInRangeNew)(sheetIds)).pop();
28
+ const { skus } = (await (0, inventories_db_1.getAllUniqSKUInRangeNew)(sheetIds)).pop();
29
29
  const sortedSkus = skus.sort((a, b) => a > b ? 1 : -1);
30
30
  return sortedSkus.map((sku) => {
31
31
  const qty = BBCs.reduce((acc, bbc) => {
@@ -4,7 +4,7 @@ import { TQueryParams } from '../../models/QueryResult.model';
4
4
  import { addHeaderToData } from '../../helpers/excel.helper';
5
5
  import { getCollateralDocsByBBC } from '../../db/collaterals.db';
6
6
  import { ECollaterals } from '../../enums/collaterals.enum';
7
- import { getAllUniqSKUInRangeNew } from '../../db/inventories';
7
+ import { getAllUniqSKUInRangeNew } from '../../db/inventories.db';
8
8
  import { getBBCDatesForPeriod } from '../../db/bbcDates.db';
9
9
  import { getUniqueDatesForPeriod } from '../../db/bbcSheets.db';
10
10
 
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getInconsistentData = exports.getInconsistentDataFull = void 0;
7
7
  const decimal_js_1 = __importDefault(require("decimal.js"));
8
8
  const numbers_helper_1 = require("../../helpers/numbers.helper");
9
- const inventories_1 = require("../../db/inventories");
9
+ const inventories_db_1 = require("../../db/inventories.db");
10
10
  const excel_helper_1 = require("../../helpers/excel.helper");
11
11
  const getInconsistentDataFull = async (params) => {
12
12
  const data = await (0, exports.getInconsistentData)(params);
@@ -16,7 +16,7 @@ const getInconsistentDataFull = async (params) => {
16
16
  exports.getInconsistentDataFull = getInconsistentDataFull;
17
17
  const getInconsistentData = async (params) => {
18
18
  const { bbcDateId } = params;
19
- const data = await (0, inventories_1.getSKUQtyValueUnitCost)(bbcDateId.toString());
19
+ const data = await (0, inventories_db_1.getSKUQtyValueUnitCost)(bbcDateId.toString());
20
20
  const formattedData = data.map((i) => {
21
21
  const calculatedUnitCost = (0, numbers_helper_1.round)(i.value / i.qty);
22
22
  const difference = i.unitCost - calculatedUnitCost;
@@ -1,7 +1,7 @@
1
1
  import Decimal from 'decimal.js';
2
2
 
3
3
  import { round } from '../../helpers/numbers.helper';
4
- import { getSKUQtyValueUnitCost } from '../../db/inventories';
4
+ import { getSKUQtyValueUnitCost } from '../../db/inventories.db';
5
5
  import { TQueryParams } from '../../models/QueryResult.model';
6
6
  import { addHeaderToData } from '../../helpers/excel.helper';
7
7
 
@@ -4,7 +4,7 @@ exports.getUnitCostDifferenceHeader = exports.getInvoiceMovement = exports.getIn
4
4
  const excel_helper_1 = require("../../helpers/excel.helper");
5
5
  const BBCDate_model_1 = require("../../models/BBCDate.model");
6
6
  const collaterals_db_1 = require("../../db/collaterals.db");
7
- const inventories_1 = require("../../db/inventories");
7
+ const inventories_db_1 = require("../../db/inventories.db");
8
8
  const collaterals_enum_1 = require("../../enums/collaterals.enum");
9
9
  const getInvoiceMovementFull = async (params) => {
10
10
  const { reportAdditions, reportRemoved } = await (0, exports.getInvoiceMovement)(params);
@@ -21,7 +21,7 @@ const getInvoiceMovement = async (params) => {
21
21
  if (currentBbcDate) {
22
22
  const previousDocuments = await (0, collaterals_db_1.getPreviousCollateralDocument)(currentBbcDate.borrowerId.toString(), currentBbcDate.bbcDate, collaterals_enum_1.ECollaterals.INVENTORY, 1);
23
23
  if (previousDocuments.length > 0) {
24
- return (0, inventories_1.getInventoryMovement)(borrowerId.toString(), previousDocuments[0].bbcDate.toString(), currentBbcDate.bbcDate.toString());
24
+ return (0, inventories_db_1.getInventoryMovement)(borrowerId.toString(), previousDocuments[0].bbcDate.toString(), currentBbcDate.bbcDate.toString());
25
25
  }
26
26
  }
27
27
  return { reportAdditions: [], reportRemoved: [] };