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.
- package/db/collaterals.db.d.ts +12 -1
- package/db/collaterals.db.js +101 -1
- package/db/collaterals.db.ts +110 -5
- package/db/groups.db.d.ts +45 -0
- package/db/groups.db.js +22 -0
- package/db/groups.db.ts +20 -0
- package/models/CustomerGroup.model.d.ts +29 -0
- package/models/CustomerGroup.model.js +25 -0
- package/models/CustomerGroup.model.ts +31 -0
- package/models/QueryResult.model.d.ts +3 -0
- package/models/QueryResult.model.js +9 -2
- package/models/QueryResult.model.ts +10 -2
- package/package.json +1 -1
- package/queries/inventory/extension.js +2 -2
- package/queries/inventory/extension.ts +1 -1
- package/queries/inventory/inconsistent-data.js +2 -2
- package/queries/inventory/inconsistent-data.ts +1 -1
- package/queries/inventory/movement.js +2 -2
- package/queries/inventory/movement.ts +1 -1
- package/queries/inventory/turn.js +2 -2
- package/queries/inventory/turn.ts +1 -1
- package/queries/inventory/unit-cost-difference.js +2 -2
- package/queries/inventory/unit-cost-difference.ts +1 -1
- package/queries/receivable/grouped-receivables.d.ts +5 -0
- package/queries/receivable/grouped-receivables.js +76 -0
- package/queries/receivable/grouped-receivables.ts +85 -0
- package/tsconfig.tsbuildinfo +1 -1
- /package/db/{inventories.d.ts → inventories.db.d.ts} +0 -0
- /package/db/{inventories.js → inventories.db.js} +0 -0
- /package/db/{inventories.ts → inventories.db.ts} +0 -0
|
@@ -2,7 +2,7 @@ import { TQueryParams } from '../../models/QueryResult.model';
|
|
|
2
2
|
import { addHeaderToData } from '../../helpers/excel.helper';
|
|
3
3
|
import { BBCDateModel } from '../../models/BBCDate.model';
|
|
4
4
|
import { getPreviousCollateralDocument } from '../../db/collaterals.db';
|
|
5
|
-
import { getInventoryMovement } from '../../db/inventories';
|
|
5
|
+
import { getInventoryMovement } from '../../db/inventories.db';
|
|
6
6
|
import { ECollaterals } from '../../enums/collaterals.enum';
|
|
7
7
|
|
|
8
8
|
export const getInvoiceMovementFull = async (params: TQueryParams) => {
|
|
@@ -10,8 +10,8 @@ const bbcDates_db_1 = require("../../db/bbcDates.db");
|
|
|
10
10
|
const bbcSheets_db_1 = require("../../db/bbcSheets.db");
|
|
11
11
|
const collaterals_enum_1 = require("../../enums/collaterals.enum");
|
|
12
12
|
const collaterals_db_1 = require("../../db/collaterals.db");
|
|
13
|
-
const inventories_1 = require("../../db/inventories");
|
|
14
13
|
const excel_helper_1 = require("../../helpers/excel.helper");
|
|
14
|
+
const inventories_db_1 = require("../../db/inventories.db");
|
|
15
15
|
const getInventoryTurnFull = async (params) => {
|
|
16
16
|
const { tableByUnit, tableByValue } = await (0, exports.getInventoryTurn)(params);
|
|
17
17
|
const headerByUnit = getInventoryTurnHeader('byUnit');
|
|
@@ -26,7 +26,7 @@ const getInventoryTurn = async (params) => {
|
|
|
26
26
|
const bbcDates = await (0, bbcDates_db_1.getBBCDatesForPeriod)(borrowerId.toString(), new Date(startDate), new Date(endDate));
|
|
27
27
|
const bbcIds = bbcDates.map((bbc) => bbc._id.toString());
|
|
28
28
|
const bbcSheets = await (0, bbcSheets_db_1.getBBCSheetsByType)(bbcIds, collaterals_enum_1.ECollaterals.INVENTORY);
|
|
29
|
-
const skuGroup = (await (0,
|
|
29
|
+
const skuGroup = (await (0, inventories_db_1.getAllUniqSKUInRangeNew)(bbcSheets.map((bbcSheet) => bbcSheet._id.toString()))).pop();
|
|
30
30
|
const BBCs = await (0, collaterals_db_1.getCollateralDocsByBBC)(bbcIds, collaterals_enum_1.ECollaterals.INVENTORY);
|
|
31
31
|
return getDifference(skuGroup ? skuGroup.skus.sort() : [], BBCs);
|
|
32
32
|
};
|
|
@@ -5,11 +5,11 @@ import { getBBCDatesForPeriod } from '../../db/bbcDates.db';
|
|
|
5
5
|
import { getBBCSheetsByType } from '../../db/bbcSheets.db';
|
|
6
6
|
import { ECollaterals } from '../../enums/collaterals.enum';
|
|
7
7
|
import { getCollateralDocsByBBC } from '../../db/collaterals.db';
|
|
8
|
-
import { getAllUniqSKUInRangeNew } from '../../db/inventories';
|
|
9
8
|
import { IInventoryItem } from '../../models/InventoryItem.model';
|
|
10
9
|
import { IBBCDateDoc } from '../../models/BBCDate.model';
|
|
11
10
|
import { TQueryParams } from '../../models/QueryResult.model';
|
|
12
11
|
import { addHeaderToData } from '../../helpers/excel.helper';
|
|
12
|
+
import { getAllUniqSKUInRangeNew } from '../../db/inventories.db';
|
|
13
13
|
|
|
14
14
|
interface IGroupedCollaterals extends IBBCDateDoc {
|
|
15
15
|
items: IInventoryItem[];
|
|
@@ -8,8 +8,8 @@ const mongoose_1 = __importDefault(require("mongoose"));
|
|
|
8
8
|
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
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");
|
|
12
11
|
const excel_helper_1 = require("../../helpers/excel.helper");
|
|
12
|
+
const inventories_db_1 = require("../../db/inventories.db");
|
|
13
13
|
const getUnitCostDifferenceFull = async (params) => {
|
|
14
14
|
const data = await (0, exports.getUnitCostDifference)(params);
|
|
15
15
|
const header = getUnitCostDifferenceHeader();
|
|
@@ -20,7 +20,7 @@ const getUnitCostDifference = async (params) => {
|
|
|
20
20
|
const { borrowerId } = params;
|
|
21
21
|
const bbcGroups = await (0, collaterals_db_1.findCollateralsWithSheets)(borrowerId.toString(), [collaterals_enum_1.ECollaterals.INVENTORY]);
|
|
22
22
|
const sheetIds = bbcGroups.reduce((acc, bbcGroup) => [...acc, ...bbcGroup.sheets.map((sheet) => new mongoose_1.default.Types.ObjectId(sheet._id))], []);
|
|
23
|
-
const data = await (0,
|
|
23
|
+
const data = await (0, inventories_db_1.getSKUUnitCostForAllDates)(sheetIds);
|
|
24
24
|
const mappedData = data.map((i) => {
|
|
25
25
|
const difference = new decimal_js_1.default(i.currentCost).sub(i.minCost.minCost).toDP(4).toNumber();
|
|
26
26
|
return {
|
|
@@ -3,9 +3,9 @@ import Decimal from 'decimal.js';
|
|
|
3
3
|
|
|
4
4
|
import { findCollateralsWithSheets } from '../../db/collaterals.db';
|
|
5
5
|
import { ECollaterals } from '../../enums/collaterals.enum';
|
|
6
|
-
import { getSKUUnitCostForAllDates } from '../../db/inventories';
|
|
7
6
|
import { TQueryParams } from '../../models/QueryResult.model';
|
|
8
7
|
import { addHeaderToData } from '../../helpers/excel.helper';
|
|
8
|
+
import { getSKUUnitCostForAllDates } from '../../db/inventories.db';
|
|
9
9
|
|
|
10
10
|
export const getUnitCostDifferenceFull = async (params: TQueryParams) => {
|
|
11
11
|
const data = await getUnitCostDifference(params);
|
|
@@ -0,0 +1,76 @@
|
|
|
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.getGroupedReceivables = exports.getGroupedReceivablesFull = void 0;
|
|
7
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const excel_helper_1 = require("../../helpers/excel.helper");
|
|
9
|
+
const collaterals_db_1 = require("../../db/collaterals.db");
|
|
10
|
+
const collaterals_enum_1 = require("../../enums/collaterals.enum");
|
|
11
|
+
const mongoose_1 = __importDefault(require("mongoose"));
|
|
12
|
+
const column_desciptions_helper_1 = require("../../helpers/column-desciptions.helper");
|
|
13
|
+
const BBCDate_model_1 = require("../../models/BBCDate.model");
|
|
14
|
+
const partially_paid_restated_1 = require("./partially-paid-restated");
|
|
15
|
+
const getGroupedReceivablesFull = async (params) => {
|
|
16
|
+
const data = await (0, exports.getGroupedReceivables)(params);
|
|
17
|
+
const header = getGroupedReceivablesHeader();
|
|
18
|
+
return (0, excel_helper_1.addHeaderToData)(header, data);
|
|
19
|
+
};
|
|
20
|
+
exports.getGroupedReceivablesFull = getGroupedReceivablesFull;
|
|
21
|
+
const getGroupedReceivables = async (params) => {
|
|
22
|
+
const { borrowerId, bbcDateId, extraParams } = params;
|
|
23
|
+
console.log(extraParams.someParam);
|
|
24
|
+
const { calculateDueDate } = extraParams;
|
|
25
|
+
const sheets = await (0, collaterals_db_1.findCollateralSheets)(bbcDateId.toString(), collaterals_enum_1.ECollaterals.RECEIVABLE);
|
|
26
|
+
return await Promise.all(sheets.map(async (sheet) => {
|
|
27
|
+
const data = await (0, collaterals_db_1.findCollaterals)(sheet._id.toString(), false);
|
|
28
|
+
const customerTitleIndex = column_desciptions_helper_1.COLLATERALS[collaterals_enum_1.ECollaterals.RECEIVABLE].findIndex((column) => column.db_title === 'customerTitle');
|
|
29
|
+
const columnsShort = column_desciptions_helper_1.COLLATERALS[collaterals_enum_1.ECollaterals.RECEIVABLE]
|
|
30
|
+
.map((c) => ({ db_title: c.db_title, title: c.title }))
|
|
31
|
+
.filter((c) => c.db_title !== 'bbcDate');
|
|
32
|
+
columnsShort.splice(customerTitleIndex, 0, { db_title: 'customerGroup', title: 'Customer group' });
|
|
33
|
+
columnsShort.push({ db_title: 'partiallyPaid', title: 'Partially paid' });
|
|
34
|
+
const columnDB = columnsShort.map((c) => c.db_title);
|
|
35
|
+
const bbcDate = await BBCDate_model_1.BBCDateModel.findById(bbcDateId).lean();
|
|
36
|
+
const startDate = (0, dayjs_1.default)(new Date(bbcDate.bbcDate)).subtract(180, 'day').toDate();
|
|
37
|
+
const endDate = new Date(bbcDate.bbcDate);
|
|
38
|
+
const { partiallyPaidInvoices } = await (0, partially_paid_restated_1.getPartialPaid)({ borrowerId: new mongoose_1.default.Types.ObjectId(borrowerId), startDate, endDate });
|
|
39
|
+
const dataWithPartiallyPaid = data.map((invoice) => {
|
|
40
|
+
let partiallyPaid = false;
|
|
41
|
+
const foundInvoice = partiallyPaidInvoices.find((pInvoice) => {
|
|
42
|
+
return (pInvoice.invoiceNumber === invoice.invoiceNumber) && (pInvoice.customer === invoice.customerTitle);
|
|
43
|
+
});
|
|
44
|
+
if (foundInvoice) {
|
|
45
|
+
partiallyPaid = foundInvoice.difference > 0;
|
|
46
|
+
}
|
|
47
|
+
if ((invoice.originalAmount !== 0) && (invoice.originalAmount !== invoice.invoiceAmount)) {
|
|
48
|
+
partiallyPaid = true;
|
|
49
|
+
}
|
|
50
|
+
return {
|
|
51
|
+
...invoice,
|
|
52
|
+
partiallyPaid,
|
|
53
|
+
dueDate: calculateDueDate ? (0, dayjs_1.default)(invoice.invoiceDate).utcOffset(0).add(90, 'days').toDate() : invoice.dueDate,
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
const shortData = (0, collaterals_db_1.excludeNoDataColumns)(dataWithPartiallyPaid, columnDB);
|
|
57
|
+
const dataWithGroups = await (0, collaterals_db_1.addCustomerGroups)(shortData, borrowerId.toString());
|
|
58
|
+
return { [sheet.sheetName]: dataWithGroups };
|
|
59
|
+
}));
|
|
60
|
+
};
|
|
61
|
+
exports.getGroupedReceivables = getGroupedReceivables;
|
|
62
|
+
const getGroupedReceivablesHeader = () => {
|
|
63
|
+
return {
|
|
64
|
+
sheetName: 'Sheet name',
|
|
65
|
+
invoiceNumber: 'Invoice number',
|
|
66
|
+
invoiceDate: 'Invoice date',
|
|
67
|
+
customerTitle: 'Customer title',
|
|
68
|
+
customerGroup: 'Customer group',
|
|
69
|
+
invoiceAmount: 'Invoice amount',
|
|
70
|
+
dueDate: 'Due date',
|
|
71
|
+
invoiceDetail1: 'Invoice detail 1',
|
|
72
|
+
invoiceDetail2: 'Invoice detail 2',
|
|
73
|
+
invoiceDetail3: 'Invoice detail 3',
|
|
74
|
+
partiallyPaid: 'Partially paid',
|
|
75
|
+
};
|
|
76
|
+
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
|
|
3
|
+
import { TQueryParams } from '../../models/QueryResult.model';
|
|
4
|
+
import { addHeaderToData } from '../../helpers/excel.helper';
|
|
5
|
+
import {
|
|
6
|
+
addCustomerGroups,
|
|
7
|
+
excludeNoDataColumns,
|
|
8
|
+
findCollaterals,
|
|
9
|
+
findCollateralSheets,
|
|
10
|
+
} from '../../db/collaterals.db';
|
|
11
|
+
import { ECollaterals } from '../../enums/collaterals.enum';
|
|
12
|
+
import mongoose from 'mongoose';
|
|
13
|
+
import { COLLATERALS } from '../../helpers/column-desciptions.helper';
|
|
14
|
+
import { BBCDateModel } from '../../models/BBCDate.model';
|
|
15
|
+
import { getPartialPaid } from './partially-paid-restated';
|
|
16
|
+
|
|
17
|
+
export const getGroupedReceivablesFull = async (params: TQueryParams) => {
|
|
18
|
+
const data = await getGroupedReceivables(params);
|
|
19
|
+
const header = getGroupedReceivablesHeader();
|
|
20
|
+
return addHeaderToData(header, data);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const getGroupedReceivables = async (params: TQueryParams) => {
|
|
24
|
+
const { borrowerId, bbcDateId, extraParams } = params;
|
|
25
|
+
console.log(extraParams.someParam);
|
|
26
|
+
const { calculateDueDate } = <{ calculateDueDate: boolean }>extraParams;
|
|
27
|
+
const sheets = await findCollateralSheets(bbcDateId.toString(), ECollaterals.RECEIVABLE);
|
|
28
|
+
|
|
29
|
+
return await Promise.all(sheets.map(async (sheet) => {
|
|
30
|
+
const data: any[] = await findCollaterals(sheet._id.toString(), false);
|
|
31
|
+
const customerTitleIndex = COLLATERALS[ECollaterals.RECEIVABLE].findIndex((column) => column.db_title === 'customerTitle');
|
|
32
|
+
|
|
33
|
+
const columnsShort = COLLATERALS[ECollaterals.RECEIVABLE]
|
|
34
|
+
.map((c) => ({ db_title: c.db_title, title: c.title }))
|
|
35
|
+
.filter((c) => c.db_title !== 'bbcDate');
|
|
36
|
+
columnsShort.splice(customerTitleIndex, 0, { db_title: 'customerGroup', title: 'Customer group' });
|
|
37
|
+
columnsShort.push({ db_title: 'partiallyPaid', title: 'Partially paid' });
|
|
38
|
+
|
|
39
|
+
const columnDB = columnsShort.map((c) => c.db_title);
|
|
40
|
+
|
|
41
|
+
const bbcDate = await BBCDateModel.findById(bbcDateId).lean();
|
|
42
|
+
const startDate = dayjs(new Date(bbcDate.bbcDate)).subtract(180, 'day').toDate();
|
|
43
|
+
const endDate = new Date(bbcDate.bbcDate);
|
|
44
|
+
|
|
45
|
+
const { partiallyPaidInvoices } = await getPartialPaid({ borrowerId: new mongoose.Types.ObjectId(borrowerId), startDate, endDate });
|
|
46
|
+
|
|
47
|
+
const dataWithPartiallyPaid = data.map((invoice) => {
|
|
48
|
+
let partiallyPaid = false;
|
|
49
|
+
const foundInvoice = partiallyPaidInvoices.find((pInvoice) => {
|
|
50
|
+
return (pInvoice.invoiceNumber === invoice.invoiceNumber) && (pInvoice.customer === invoice.customerTitle);
|
|
51
|
+
});
|
|
52
|
+
if (foundInvoice) {
|
|
53
|
+
partiallyPaid = foundInvoice.difference > 0;
|
|
54
|
+
}
|
|
55
|
+
if ((invoice.originalAmount !== 0) && (invoice.originalAmount !== invoice.invoiceAmount)) {
|
|
56
|
+
partiallyPaid = true;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
...invoice,
|
|
60
|
+
partiallyPaid,
|
|
61
|
+
dueDate: calculateDueDate ? dayjs(invoice.invoiceDate).utcOffset(0).add(90, 'days').toDate() : invoice.dueDate,
|
|
62
|
+
};
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const shortData = excludeNoDataColumns(dataWithPartiallyPaid, columnDB);
|
|
66
|
+
const dataWithGroups = await addCustomerGroups(shortData, borrowerId.toString());
|
|
67
|
+
return { [sheet.sheetName]: dataWithGroups };
|
|
68
|
+
}));
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const getGroupedReceivablesHeader = () => {
|
|
72
|
+
return {
|
|
73
|
+
sheetName: 'Sheet name',
|
|
74
|
+
invoiceNumber: 'Invoice number',
|
|
75
|
+
invoiceDate: 'Invoice date',
|
|
76
|
+
customerTitle: 'Customer title',
|
|
77
|
+
customerGroup: 'Customer group',
|
|
78
|
+
invoiceAmount: 'Invoice amount',
|
|
79
|
+
dueDate: 'Due date',
|
|
80
|
+
invoiceDetail1: 'Invoice detail 1',
|
|
81
|
+
invoiceDetail2: 'Invoice detail 2',
|
|
82
|
+
invoiceDetail3: 'Invoice detail 3',
|
|
83
|
+
partiallyPaid: 'Partially paid',
|
|
84
|
+
};
|
|
85
|
+
};
|