@zauru-sdk/utils 6.16.0 → 6.17.0
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/zauru/4pinos-po-discount-history.utils.js +10 -1
- package/dist/esm/zauru/purchase-orders.utils.js +16 -4
- package/dist/esm/zauru/rejectionPercentageAdjustmentRules.utils.js +1 -1
- package/dist/esm/zauru/remix-handle-request.server.js +3 -2
- package/dist/zauru/4pinos-po-discount-history.utils.d.ts +6 -1
- package/dist/zauru/purchase-orders.utils.d.ts +2 -2
- package/dist/zauru/rejectionPercentageAdjustmentRules.utils.d.ts +1 -1
- package/package.json +6 -6
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
1
|
+
import { formatAutomaticRejectionRuleHistoryDescription, handlePossibleAxiosErrors, REJECTION_PERCENTAGE_RULE_HISTORY_TYPE, } from "@zauru-sdk/common";
|
|
2
2
|
import { create4pinosPoDiscountHistory, getPurchaseOrder, getVariablesByName, update4pinosPoDiscountHistory, } from "@zauru-sdk/services";
|
|
3
|
+
export const mapRejectionRuleStepsToDiscountHistory = (steps, meta) => steps.map((step) => ({
|
|
4
|
+
agency_id: meta.agency_id,
|
|
5
|
+
employee_id: meta.employee_id ?? 0,
|
|
6
|
+
employee_name: "Sistema",
|
|
7
|
+
created_at: meta.created_at ?? new Date().toISOString(),
|
|
8
|
+
description: formatAutomaticRejectionRuleHistoryDescription(step),
|
|
9
|
+
type: REJECTION_PERCENTAGE_RULE_HISTORY_TYPE,
|
|
10
|
+
discount: step.appliedAmount,
|
|
11
|
+
}));
|
|
3
12
|
export const add4pinosPoDiscountsHistory = async (session, headers, purchaseOrderId, discounts) => {
|
|
4
13
|
return handlePossibleAxiosErrors(async () => {
|
|
5
14
|
const { historial_porcentajes_de_rechazo_webapp_table_id } = await getVariablesByName(headers, session, [
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CURRENCY_PREFIX, calculatePurchaseOrderFinancials, getNewDateByFormat, getStringFullDate, getZauruDateByText, handlePossibleAxiosErrors, mergeJsonMemo, } from "@zauru-sdk/common";
|
|
1
|
+
import { CURRENCY_PREFIX, calculatePurchaseOrderFinancials, getNewlyAppliedRejectionRuleSteps, getNewDateByFormat, getStringFullDate, getZauruDateByText, handlePossibleAxiosErrors, mergeJsonMemo, parseJsonMemo, } from "@zauru-sdk/common";
|
|
2
2
|
import { commitSession, createNewPurchaseOrder, deleteDelivery, deletePurchaseOrder, deleteReception, getLotesWithPurchaseFormated, getPurchase, getPurchaseOrder, getPurchasesListDataTables, getVariablesByName, inactivarLote, updateReceivedPurchaseOrder, } from "@zauru-sdk/services";
|
|
3
3
|
import { getActiveRejectionPercentageAdjustmentRules } from "./rejectionPercentageAdjustmentRules.utils.js";
|
|
4
4
|
/**
|
|
@@ -216,11 +216,13 @@ export const updateOchAndDis = async (headers, data, purchase_id, session) => {
|
|
|
216
216
|
return handlePossibleAxiosErrors(async () => {
|
|
217
217
|
const rejectionPercentage = Number(data?.rejectionPercentage ?? data?.discount ?? 0);
|
|
218
218
|
let currentMemo = data.memo;
|
|
219
|
+
let liveMemo;
|
|
219
220
|
let details = [];
|
|
220
221
|
let loadedPurchase;
|
|
221
222
|
const restPurchaseResponse = await getPurchase(headers, purchase_id);
|
|
222
223
|
if (!restPurchaseResponse.error && restPurchaseResponse.data) {
|
|
223
224
|
loadedPurchase = restPurchaseResponse.data;
|
|
225
|
+
liveMemo = restPurchaseResponse.data.memo;
|
|
224
226
|
if (currentMemo === undefined) {
|
|
225
227
|
currentMemo = restPurchaseResponse.data.memo;
|
|
226
228
|
}
|
|
@@ -236,6 +238,9 @@ export const updateOchAndDis = async (headers, data, purchase_id, session) => {
|
|
|
236
238
|
throw new Error(purchaseOrderResponse.userMsg ||
|
|
237
239
|
"No se pudo obtener la orden de compra para actualizar el porcentaje de rechazo");
|
|
238
240
|
}
|
|
241
|
+
if (liveMemo === undefined) {
|
|
242
|
+
liveMemo = purchaseOrderResponse.data.memo;
|
|
243
|
+
}
|
|
239
244
|
if (currentMemo === undefined) {
|
|
240
245
|
currentMemo = purchaseOrderResponse.data.memo;
|
|
241
246
|
}
|
|
@@ -258,10 +263,12 @@ export const updateOchAndDis = async (headers, data, purchase_id, session) => {
|
|
|
258
263
|
const payee = purchaseRecord?.payee;
|
|
259
264
|
const itemIds = extractPurchaseOrderItemIds(loadedPurchase);
|
|
260
265
|
const tipo = purchaseRecord?.reference;
|
|
266
|
+
const memoForOrigin = liveMemo ?? currentMemo;
|
|
267
|
+
const previousCalculations = parseJsonMemo(memoForOrigin).rejectionCalculations;
|
|
261
268
|
const financials = calculatePurchaseOrderFinancials({
|
|
262
269
|
details,
|
|
263
270
|
rejectionPercentage,
|
|
264
|
-
memo:
|
|
271
|
+
memo: memoForOrigin,
|
|
265
272
|
rules,
|
|
266
273
|
ctx: {
|
|
267
274
|
itemIds,
|
|
@@ -271,9 +278,10 @@ export const updateOchAndDis = async (headers, data, purchase_id, session) => {
|
|
|
271
278
|
?.payee_category_id,
|
|
272
279
|
},
|
|
273
280
|
});
|
|
281
|
+
const newlyAppliedSteps = getNewlyAppliedRejectionRuleSteps(previousCalculations, financials.rejectionCalculations);
|
|
274
282
|
const body = {
|
|
275
283
|
purchase_order: {
|
|
276
|
-
memo: mergeJsonMemo(
|
|
284
|
+
memo: mergeJsonMemo(memoForOrigin, {
|
|
277
285
|
rejectionPercentage: financials.rejectionPercentage,
|
|
278
286
|
rejectionCalculations: financials.rejectionCalculations,
|
|
279
287
|
}),
|
|
@@ -287,7 +295,11 @@ export const updateOchAndDis = async (headers, data, purchase_id, session) => {
|
|
|
287
295
|
if (responseUpdate.error || responseUpdate.data === null) {
|
|
288
296
|
throw new Error(responseUpdate.userMsg);
|
|
289
297
|
}
|
|
290
|
-
return
|
|
298
|
+
return {
|
|
299
|
+
rejectionPercentage: financials.rejectionPercentage,
|
|
300
|
+
rejectionCalculations: financials.rejectionCalculations,
|
|
301
|
+
newlyAppliedSteps,
|
|
302
|
+
};
|
|
291
303
|
});
|
|
292
304
|
};
|
|
293
305
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { filterActiveRejectionPercentageAdjustmentRules, handlePossibleAxiosErrors, REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR, } from "@zauru-sdk/common";
|
|
2
2
|
import { createWebAppTableRegister, getVariables, getVariablesByName, getWebAppTableRegisters, getWebAppTableRegistersRest, updateWebAppTableRegister, } from "@zauru-sdk/services";
|
|
3
|
-
export { applyRejectionPercentageAdjustmentRules, filterActiveRejectionPercentageAdjustmentRules, formatRejectionPercentageAdjustmentDescription, rejectionPercentageAdjustmentRuleMatches, resolveRejectionPercentageBase, resolveRejectionPercentageOrigin, REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR, } from "@zauru-sdk/common";
|
|
3
|
+
export { applyRejectionPercentageAdjustmentRules, filterActiveRejectionPercentageAdjustmentRules, formatAutomaticRejectionRuleHistoryDescription, formatRejectionPercentageAdjustmentDescription, getNewlyAppliedRejectionRuleSteps, isAutomaticRejectionRuleHistoryType, rejectionPercentageAdjustmentRuleMatches, resolveRejectionPercentageBase, resolveRejectionPercentageOrigin, REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR, REJECTION_PERCENTAGE_RULE_HISTORY_TYPE, } from "@zauru-sdk/common";
|
|
4
4
|
const getTableId = async (headers, session) => {
|
|
5
5
|
const vars = await getVariablesByName(headers, session, [
|
|
6
6
|
REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR,
|
|
@@ -5,6 +5,7 @@ import { RemixServer } from "@remix-run/react";
|
|
|
5
5
|
import { renderToPipeableStream } from "react-dom/server";
|
|
6
6
|
import { handleError } from "./cloudwatch-remix.server.js";
|
|
7
7
|
const ABORT_DELAY = 5_000;
|
|
8
|
+
const RemixServerComponent = RemixServer;
|
|
8
9
|
function isBotRequest(userAgent) {
|
|
9
10
|
if (!userAgent)
|
|
10
11
|
return false;
|
|
@@ -29,7 +30,7 @@ export function handleRequest(request, responseStatusCode, responseHeaders, remi
|
|
|
29
30
|
function handleBotRequest(request, responseStatusCode, responseHeaders, remixContext) {
|
|
30
31
|
return new Promise((resolve, reject) => {
|
|
31
32
|
let shellRendered = false;
|
|
32
|
-
const { pipe, abort } = renderToPipeableStream(createElement(
|
|
33
|
+
const { pipe, abort } = renderToPipeableStream(createElement(RemixServerComponent, {
|
|
33
34
|
context: remixContext,
|
|
34
35
|
url: request.url,
|
|
35
36
|
abortDelay: ABORT_DELAY,
|
|
@@ -61,7 +62,7 @@ function handleBotRequest(request, responseStatusCode, responseHeaders, remixCon
|
|
|
61
62
|
function handleBrowserRequest(request, responseStatusCode, responseHeaders, remixContext) {
|
|
62
63
|
return new Promise((resolve, reject) => {
|
|
63
64
|
let shellRendered = false;
|
|
64
|
-
const { pipe, abort } = renderToPipeableStream(createElement(
|
|
65
|
+
const { pipe, abort } = renderToPipeableStream(createElement(RemixServerComponent, {
|
|
65
66
|
context: remixContext,
|
|
66
67
|
url: request.url,
|
|
67
68
|
abortDelay: ABORT_DELAY,
|
|
@@ -1,3 +1,8 @@
|
|
|
1
1
|
import { Session } from "@remix-run/node";
|
|
2
|
-
import { PoDiscountHistory } from "@zauru-sdk/types";
|
|
2
|
+
import { PoDiscountHistory, PoDiscountHistoryEntry, RejectionPercentageAdjustmentStep } from "@zauru-sdk/types";
|
|
3
|
+
export declare const mapRejectionRuleStepsToDiscountHistory: (steps: RejectionPercentageAdjustmentStep[], meta: {
|
|
4
|
+
agency_id: number;
|
|
5
|
+
employee_id?: number;
|
|
6
|
+
created_at?: string;
|
|
7
|
+
}) => PoDiscountHistoryEntry[];
|
|
3
8
|
export declare const add4pinosPoDiscountsHistory: (session: Session, headers: any, purchaseOrderId: number | string, discounts: PoDiscountHistory["discounts"]) => Promise<import("@zauru-sdk/types").AxiosUtilsResponse<void>>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
|
-
import { AxiosUtilsResponse, LoteWithPurchaseFormatedSchema, PurchaseOrderGraphQL, PurchasesDataTableListFormatedSchema, PurchasesListResponseSchema } from "@zauru-sdk/types";
|
|
2
|
+
import { AxiosUtilsResponse, LoteWithPurchaseFormatedSchema, PurchaseOrderGraphQL, PurchasesDataTableListFormatedSchema, PurchasesListResponseSchema, UpdateOchAndDisResult } from "@zauru-sdk/types";
|
|
3
3
|
/**
|
|
4
4
|
* Obtiene el listado de ordenes de compra, formateado especialmente para armar la tabla de edición de porcentajes y tolerancia
|
|
5
5
|
* @param headers
|
|
@@ -47,7 +47,7 @@ export declare const updateOchAndDis: (headers: any, data: {
|
|
|
47
47
|
discount?: number | string;
|
|
48
48
|
other_charges?: number | string;
|
|
49
49
|
memo?: string | object;
|
|
50
|
-
}, purchase_id: number, session?: Session) => Promise<AxiosUtilsResponse<
|
|
50
|
+
}, purchase_id: number, session?: Session) => Promise<AxiosUtilsResponse<UpdateOchAndDisResult>>;
|
|
51
51
|
/**
|
|
52
52
|
* Obtengo los id's de las órdenes de compra en un arreglo numérico
|
|
53
53
|
* @param headers
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Session } from "@remix-run/node";
|
|
2
2
|
import { AxiosUtilsResponse, RejectionPercentageAdjustmentRule, WebAppRowGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
|
|
3
|
-
export { applyRejectionPercentageAdjustmentRules, filterActiveRejectionPercentageAdjustmentRules, formatRejectionPercentageAdjustmentDescription, rejectionPercentageAdjustmentRuleMatches, resolveRejectionPercentageBase, resolveRejectionPercentageOrigin, REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR, } from "@zauru-sdk/common";
|
|
3
|
+
export { applyRejectionPercentageAdjustmentRules, filterActiveRejectionPercentageAdjustmentRules, formatAutomaticRejectionRuleHistoryDescription, formatRejectionPercentageAdjustmentDescription, getNewlyAppliedRejectionRuleSteps, isAutomaticRejectionRuleHistoryType, rejectionPercentageAdjustmentRuleMatches, resolveRejectionPercentageBase, resolveRejectionPercentageOrigin, REJECTION_PERCENTAGE_ADJUSTMENT_RULES_TABLE_VAR, REJECTION_PERCENTAGE_RULE_HISTORY_TYPE, } from "@zauru-sdk/common";
|
|
4
4
|
export declare const getRejectionPercentageAdjustmentRules: (headers: any, session: Session) => Promise<AxiosUtilsResponse<WebAppRowGraphQL<RejectionPercentageAdjustmentRule>[]>>;
|
|
5
5
|
/**
|
|
6
6
|
* Same listing without a Remix session: resolves the table id over REST, for
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.17.0",
|
|
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",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"author": "Oscar Cuéllar",
|
|
49
49
|
"license": "MIT",
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"@remix-run/react": "^2.8.1",
|
|
51
|
+
"@remix-run/react": "^1.13.0 || ^2.8.1",
|
|
52
52
|
"react": "^18.2.0 || ^19.0.0",
|
|
53
53
|
"react-dom": "^18.2.0 || ^19.0.0"
|
|
54
54
|
},
|
|
@@ -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.7.0",
|
|
75
75
|
"@zauru-sdk/config": "^6.0.0",
|
|
76
76
|
"@zauru-sdk/graphql": "^6.7.0",
|
|
77
|
-
"@zauru-sdk/services": "^6.11.
|
|
78
|
-
"@zauru-sdk/types": "^6.
|
|
77
|
+
"@zauru-sdk/services": "^6.11.1",
|
|
78
|
+
"@zauru-sdk/types": "^6.17.0",
|
|
79
79
|
"moment": "^2.30.1"
|
|
80
80
|
},
|
|
81
|
-
"gitHead": "
|
|
81
|
+
"gitHead": "d3483aa3b55a9a692f955e6a56d13f33b70db1c4"
|
|
82
82
|
}
|