@zauru-sdk/utils 6.25.0 → 6.26.1
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/dist/esm/index.js +1 -0
- package/dist/esm/zauru/providerReceptionMatrix.utils.js +84 -0
- package/dist/esm/zauru/weeklyItemPrice.utils.js +18 -5
- package/dist/index.d.ts +1 -0
- package/dist/zauru/providerReceptionMatrix.utils.d.ts +18 -0
- package/dist/zauru/weeklyItemPrice.utils.d.ts +6 -0
- package/package.json +6 -6
package/dist/esm/index.js
CHANGED
|
@@ -31,3 +31,4 @@ export * from "./zauru/webapp-tables.utils.js";
|
|
|
31
31
|
export * from "./zauru/4pinos-po-discount-history.utils.js";
|
|
32
32
|
export * from "./zauru/programaciones.utils.js";
|
|
33
33
|
export * from "./zauru/providerRestrictions.utils.js";
|
|
34
|
+
export * from "./zauru/providerReceptionMatrix.utils.js";
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors, normalizeProviderRestrictionValues, normalizeRestrictionValue, PROVIDER_RECEPTION_EXCEPTIONS_TABLE_VAR, PROVIDER_RECEPTION_MATRIX_TABLE_VAR, } from "@zauru-sdk/common";
|
|
2
|
+
import { createWebAppTableRegister, getVariablesByName, getWebAppTableRegisters, updateWebAppTableRegister, } from "@zauru-sdk/services";
|
|
3
|
+
export const FOUR_PINOS_NON_SELECTABLE_RECEPTION_ITEM_IDS = [
|
|
4
|
+
782312, 782638,
|
|
5
|
+
];
|
|
6
|
+
export const filter4PinosSelectableReceptionItems = (items) => {
|
|
7
|
+
const excluded = new Set(FOUR_PINOS_NON_SELECTABLE_RECEPTION_ITEM_IDS);
|
|
8
|
+
return items.filter((item) => !excluded.has(Number(item.id)));
|
|
9
|
+
};
|
|
10
|
+
const getTableId = async (headers, session, varName) => {
|
|
11
|
+
const variables = await getVariablesByName(headers, session, [varName]);
|
|
12
|
+
return variables[varName];
|
|
13
|
+
};
|
|
14
|
+
const getRows = async (input) => handlePossibleAxiosErrors(async () => {
|
|
15
|
+
const tableId = await getTableId(input.headers, input.session, input.varName);
|
|
16
|
+
const data = {};
|
|
17
|
+
if (input.filters?.payeeId != null) {
|
|
18
|
+
data.payee_id = Number(input.filters.payeeId);
|
|
19
|
+
}
|
|
20
|
+
if (input.filters?.receptionTypeCode != null) {
|
|
21
|
+
data.reception_type_code = normalizeRestrictionValue(input.filters.receptionTypeCode);
|
|
22
|
+
}
|
|
23
|
+
const response = await getWebAppTableRegisters(input.session, tableId, {
|
|
24
|
+
...(Object.keys(data).length ? { data } : {}),
|
|
25
|
+
});
|
|
26
|
+
if (response.error) {
|
|
27
|
+
throw new Error(`Ocurrió un error al consultar ${input.label}: ${response.userMsg}`);
|
|
28
|
+
}
|
|
29
|
+
return response.data ?? [];
|
|
30
|
+
});
|
|
31
|
+
const createRow = async (input) => handlePossibleAxiosErrors(async () => {
|
|
32
|
+
const tableId = await getTableId(input.headers, input.session, input.varName);
|
|
33
|
+
return createWebAppTableRegister(input.headers, tableId, input.body);
|
|
34
|
+
});
|
|
35
|
+
const updateRow = async (input) => handlePossibleAxiosErrors(async () => {
|
|
36
|
+
const tableId = await getTableId(input.headers, input.session, input.varName);
|
|
37
|
+
return updateWebAppTableRegister(input.headers, tableId, input.id, input.body);
|
|
38
|
+
});
|
|
39
|
+
export const getProviderReceptionBlockRules = (headers, session, filters) => getRows({
|
|
40
|
+
headers,
|
|
41
|
+
session,
|
|
42
|
+
varName: PROVIDER_RECEPTION_MATRIX_TABLE_VAR,
|
|
43
|
+
label: "la matriz de restricciones de recepción",
|
|
44
|
+
filters,
|
|
45
|
+
});
|
|
46
|
+
export const createProviderReceptionBlockRule = (headers, session, body) => createRow({
|
|
47
|
+
headers,
|
|
48
|
+
session,
|
|
49
|
+
varName: PROVIDER_RECEPTION_MATRIX_TABLE_VAR,
|
|
50
|
+
body: {
|
|
51
|
+
...body,
|
|
52
|
+
blocked_item_ids: normalizeProviderRestrictionValues(body.blocked_item_ids),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
export const updateProviderReceptionBlockRule = (headers, session, id, body) => updateRow({
|
|
56
|
+
headers,
|
|
57
|
+
session,
|
|
58
|
+
varName: PROVIDER_RECEPTION_MATRIX_TABLE_VAR,
|
|
59
|
+
id,
|
|
60
|
+
body,
|
|
61
|
+
});
|
|
62
|
+
export const getProviderReceptionExceptions = (headers, session, filters) => getRows({
|
|
63
|
+
headers,
|
|
64
|
+
session,
|
|
65
|
+
varName: PROVIDER_RECEPTION_EXCEPTIONS_TABLE_VAR,
|
|
66
|
+
label: "las excepciones temporales de recepción",
|
|
67
|
+
filters,
|
|
68
|
+
});
|
|
69
|
+
export const createProviderReceptionException = (headers, session, body) => createRow({
|
|
70
|
+
headers,
|
|
71
|
+
session,
|
|
72
|
+
varName: PROVIDER_RECEPTION_EXCEPTIONS_TABLE_VAR,
|
|
73
|
+
body: {
|
|
74
|
+
...body,
|
|
75
|
+
item_ids: normalizeProviderRestrictionValues(body.item_ids),
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
export const updateProviderReceptionException = (headers, session, id, body) => updateRow({
|
|
79
|
+
headers,
|
|
80
|
+
session,
|
|
81
|
+
varName: PROVIDER_RECEPTION_EXCEPTIONS_TABLE_VAR,
|
|
82
|
+
id,
|
|
83
|
+
body,
|
|
84
|
+
});
|
|
@@ -5,6 +5,21 @@ import { applyPriceAdjustmentRules, filterActivePriceAdjustmentRules, formatPric
|
|
|
5
5
|
import { getSpecialItems } from "./specialItem.utils.js";
|
|
6
6
|
export const MASSIVE_VEGETABLE_COST_ACCION = "Costos masivamente";
|
|
7
7
|
const FALLBACK_UNIT_COST = 1;
|
|
8
|
+
export const pickProviderCategoryId = (payee, payees, payeeId) => {
|
|
9
|
+
const fromPayee = payee?.payee_category_id;
|
|
10
|
+
if (fromPayee != null && Number.isFinite(Number(fromPayee))) {
|
|
11
|
+
return Number(fromPayee);
|
|
12
|
+
}
|
|
13
|
+
if (payeeId == null || !payees?.length) {
|
|
14
|
+
return undefined;
|
|
15
|
+
}
|
|
16
|
+
const match = payees.find((item) => item.id === payeeId);
|
|
17
|
+
const fromList = match?.payee_category_id;
|
|
18
|
+
if (fromList == null || !Number.isFinite(Number(fromList))) {
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
return Number(fromList);
|
|
22
|
+
};
|
|
8
23
|
const isSpecialItemRow = (item) => typeof item.id === "number" &&
|
|
9
24
|
Boolean(item.data);
|
|
10
25
|
const isWeekday = (value) => value === 0 ||
|
|
@@ -190,15 +205,13 @@ export const resolveItemPriceFromLatestWeeklyMatrix = (headers, session, params)
|
|
|
190
205
|
let providerCategoryId;
|
|
191
206
|
if (params.payeeId != null) {
|
|
192
207
|
const payeeResponse = await getPayee(session, params.payeeId);
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
else {
|
|
208
|
+
providerCategoryId = pickProviderCategoryId(payeeResponse.data);
|
|
209
|
+
if (providerCategoryId == null) {
|
|
197
210
|
const payeesResponse = await getPayees(session);
|
|
198
211
|
if (payeesResponse.error || !payeesResponse.data) {
|
|
199
212
|
throw new Error(`Error al obtener el proveedor para aplicar las reglas de ajuste: ${payeeResponse.userMsg ?? payeesResponse.userMsg ?? ""}`);
|
|
200
213
|
}
|
|
201
|
-
providerCategoryId = payeesResponse.data
|
|
214
|
+
providerCategoryId = pickProviderCategoryId(undefined, payeesResponse.data, params.payeeId);
|
|
202
215
|
}
|
|
203
216
|
}
|
|
204
217
|
return calculateItemPriceFromWeeklyMatrix({
|
package/dist/index.d.ts
CHANGED
|
@@ -31,3 +31,4 @@ export * from "./zauru/webapp-tables.utils.js";
|
|
|
31
31
|
export * from "./zauru/4pinos-po-discount-history.utils.js";
|
|
32
32
|
export * from "./zauru/programaciones.utils.js";
|
|
33
33
|
export * from "./zauru/providerRestrictions.utils.js";
|
|
34
|
+
export * from "./zauru/providerReceptionMatrix.utils.js";
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import type { AxiosUtilsResponse, ProviderReceptionBlockRule, ProviderReceptionException, WebAppRowGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
|
|
3
|
+
export declare const FOUR_PINOS_NON_SELECTABLE_RECEPTION_ITEM_IDS: readonly [782312, 782638];
|
|
4
|
+
export declare const filter4PinosSelectableReceptionItems: <T extends {
|
|
5
|
+
id: number;
|
|
6
|
+
}>(items: T[]) => T[];
|
|
7
|
+
export declare const getProviderReceptionBlockRules: (headers: any, session: Session, filters?: {
|
|
8
|
+
payeeId?: number;
|
|
9
|
+
receptionTypeCode?: string;
|
|
10
|
+
}) => Promise<AxiosUtilsResponse<WebAppRowGraphQL<ProviderReceptionBlockRule>[]>>;
|
|
11
|
+
export declare const createProviderReceptionBlockRule: (headers: any, session: Session, body: ProviderReceptionBlockRule) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
12
|
+
export declare const updateProviderReceptionBlockRule: (headers: any, session: Session, id: number, body: Partial<ProviderReceptionBlockRule>) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
13
|
+
export declare const getProviderReceptionExceptions: (headers: any, session: Session, filters?: {
|
|
14
|
+
payeeId?: number;
|
|
15
|
+
receptionTypeCode?: string;
|
|
16
|
+
}) => Promise<AxiosUtilsResponse<WebAppRowGraphQL<ProviderReceptionException>[]>>;
|
|
17
|
+
export declare const createProviderReceptionException: (headers: any, session: Session, body: ProviderReceptionException) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
18
|
+
export declare const updateProviderReceptionException: (headers: any, session: Session, id: number, body: Partial<ProviderReceptionException>) => Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
2
|
import { AxiosUtilsResponse, BitacoraCostosItems, CalculateItemPriceFromWeeklyMatrixInput, CalculateItemPriceFromWeeklyMatrixResult, CostoSemanal, CostoSemanalSpecialItem, SpecialItem, WebAppRowGraphQL, WeeklyCostMatrix, WeeklyCostPeriod } from "@zauru-sdk/types";
|
|
3
3
|
export declare const MASSIVE_VEGETABLE_COST_ACCION = "Costos masivamente";
|
|
4
|
+
export declare const pickProviderCategoryId: (payee?: {
|
|
5
|
+
payee_category_id?: number | null;
|
|
6
|
+
} | null, payees?: Array<{
|
|
7
|
+
id?: number;
|
|
8
|
+
payee_category_id?: number | null;
|
|
9
|
+
}> | null, payeeId?: number) => number | undefined;
|
|
4
10
|
export declare const parseWeeklyCostDate: (value: string) => Date | null;
|
|
5
11
|
export declare const getMondayOfWeeklyCostDate: (date: string) => string | null;
|
|
6
12
|
export declare const getWeeklyCostPeriod: (date: string) => WeeklyCostPeriod;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.26.1",
|
|
4
4
|
"description": "Utilidades, parseo de request y demás para desarrollo de webapps de Zauru",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -71,12 +71,12 @@
|
|
|
71
71
|
"dependencies": {
|
|
72
72
|
"@aws-sdk/client-cloudwatch-logs": "^3.1123.0",
|
|
73
73
|
"@remix-run/node": "^2.8.1",
|
|
74
|
-
"@zauru-sdk/common": "^6.
|
|
74
|
+
"@zauru-sdk/common": "^6.12.0",
|
|
75
75
|
"@zauru-sdk/config": "^6.0.0",
|
|
76
|
-
"@zauru-sdk/graphql": "^6.9.
|
|
77
|
-
"@zauru-sdk/services": "^6.15.
|
|
78
|
-
"@zauru-sdk/types": "^6.
|
|
76
|
+
"@zauru-sdk/graphql": "^6.9.1",
|
|
77
|
+
"@zauru-sdk/services": "^6.15.1",
|
|
78
|
+
"@zauru-sdk/types": "^6.28.0",
|
|
79
79
|
"moment": "^2.30.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "862f3a72643479e1b124cfc9159d33901e5b6912"
|
|
82
82
|
}
|