@zauru-sdk/utils 2.2.0 → 2.3.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 CHANGED
@@ -21,3 +21,4 @@ export * from "./zauru/specialItem.utils.js";
21
21
  export * from "./zauru/templates.utils.js";
22
22
  export * from "./zauru/tiposMuestra.utils.js";
23
23
  export * from "./zauru/webapp-tables.utils.js";
24
+ export * from "./zauru/4pinos-po-discount-history.utils.js";
@@ -0,0 +1,36 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { create4pinosPoDiscountHistory, getPurchaseOrder, getVariablesByName, update4pinosPoDiscountHistory, } from "@zauru-sdk/services";
3
+ export const add4pinosPoDiscountsHistory = async (session, headers, purchaseOrderId, discounts) => {
4
+ return handlePossibleAxiosErrors(async () => {
5
+ const { historial_porcentajes_de_rechazo_webapp_table_id } = await getVariablesByName(headers, session, [
6
+ "historial_porcentajes_de_rechazo_webapp_table_id",
7
+ ]);
8
+ const purchaseOrderResponse = await getPurchaseOrder(session, purchaseOrderId);
9
+ if (purchaseOrderResponse.error || !purchaseOrderResponse.data) {
10
+ throw new Error(purchaseOrderResponse.userMsg);
11
+ }
12
+ const purchaseOrder = purchaseOrderResponse.data;
13
+ // Pregunto si tiene historial de descuentos
14
+ const purchaseOrderHistory = purchaseOrder.webapp_table_rowables?.find((x) => x.webapp_rows?.webapp_table_id ===
15
+ Number(historial_porcentajes_de_rechazo_webapp_table_id));
16
+ if (purchaseOrderHistory) {
17
+ console.log("Ya existe una tabla de historial de porcentaje de rechazo");
18
+ await update4pinosPoDiscountHistory(headers, session, purchaseOrderHistory.webapp_rows?.id ?? -1, {
19
+ purchase_order_id: purchaseOrder.id,
20
+ purchase_order_id_number: purchaseOrder.id_number,
21
+ discounts: [
22
+ ...(purchaseOrderHistory.webapp_rows?.data?.discounts ?? []),
23
+ ...discounts,
24
+ ],
25
+ });
26
+ }
27
+ else {
28
+ console.log("No existe una tabla de historial de porcentaje de rechazo - Creando nueva...");
29
+ await create4pinosPoDiscountHistory(headers, session, {
30
+ purchase_order_id: purchaseOrder.id,
31
+ purchase_order_id_number: purchaseOrder.id_number,
32
+ discounts: discounts,
33
+ });
34
+ }
35
+ });
36
+ };
package/dist/index.d.ts CHANGED
@@ -21,3 +21,4 @@ export * from "./zauru/specialItem.utils.js";
21
21
  export * from "./zauru/templates.utils.js";
22
22
  export * from "./zauru/tiposMuestra.utils.js";
23
23
  export * from "./zauru/webapp-tables.utils.js";
24
+ export * from "./zauru/4pinos-po-discount-history.utils.js";
@@ -0,0 +1,3 @@
1
+ import { Session } from "@remix-run/node";
2
+ import { PoDiscountHistory } from "@zauru-sdk/types";
3
+ export declare const add4pinosPoDiscountsHistory: (session: Session, headers: any, purchaseOrderId: number | string, discounts: PoDiscountHistory["discounts"]) => Promise<import("@zauru-sdk/types").AxiosUtilsResponse<void>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/utils",
3
- "version": "2.2.0",
3
+ "version": "2.3.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",
@@ -24,11 +24,11 @@
24
24
  },
25
25
  "dependencies": {
26
26
  "@remix-run/node": "^2.8.1",
27
- "@zauru-sdk/common": "^2.2.0",
27
+ "@zauru-sdk/common": "^2.3.1",
28
28
  "@zauru-sdk/config": "^2.0.220",
29
29
  "@zauru-sdk/graphql": "^2.2.0",
30
- "@zauru-sdk/services": "^2.2.0",
31
- "@zauru-sdk/types": "^2.2.0"
30
+ "@zauru-sdk/services": "^2.3.1",
31
+ "@zauru-sdk/types": "^2.3.1"
32
32
  },
33
- "gitHead": "eaa293691510bcff7233d44098944210bf109bdb"
33
+ "gitHead": "149a6e42d2a40f20a7714392e3ef17b6f24be360"
34
34
  }