@zauru-sdk/common 6.3.5 → 6.4.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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [6.4.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.3.5...@zauru-sdk/common@6.4.0) (2026-09-11)
7
+
8
+
9
+ ### Features
10
+
11
+ * calculate monetary PO discount from rejection percentage ([270a484](https://github.com/intuitiva/zauru-typescript-sdk/commit/270a4844ced0034700257a57cb9ceb2e331f15e9))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [6.3.5](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.3.4...@zauru-sdk/common@6.3.5) (2026-09-10)
7
18
 
8
19
  **Note:** Version bump only for package @zauru-sdk/common
package/dist/common.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import "moment-timezone";
2
- import type { PayeeGraphQL, AxiosUtilsResponse, BasketSchema, SelectFieldOption, JsonMemoType } from "@zauru-sdk/types";
2
+ import type { PayeeGraphQL, AxiosUtilsResponse, BasketSchema, SelectFieldOption, JsonMemoType, CalculatePurchaseOrderFinancialsInput, CalculatePurchaseOrderFinancialsResult } from "@zauru-sdk/types";
3
3
  export declare const DESTINOS_MUESTRA_OPTIONS: SelectFieldOption[];
4
4
  export declare const parseJsonMemo: (memo?: string | object) => JsonMemoType;
5
5
  export declare const stringifyJsonMemo: (memo: JsonMemoType) => string;
@@ -12,6 +12,12 @@ export declare const getRejectionPercentage: (source: string | {
12
12
  memo?: string | object;
13
13
  } | JsonMemoType | undefined) => number;
14
14
  export declare const setRejectionPercentage: (memo: string | object | undefined, percentage: number) => string;
15
+ /**
16
+ * Header money for a purchase order: subtotal = qty × unit_cost,
17
+ * discount = subtotal × rejectionPercentage / 100.
18
+ * Does not change unit cost. purchase_orders.discount is the monetary column.
19
+ */
20
+ export declare const calculatePurchaseOrderFinancials: (input: CalculatePurchaseOrderFinancialsInput) => CalculatePurchaseOrderFinancialsResult;
15
21
  /**
16
22
  * Obtener el objeto de canastas en base al memo
17
23
  * @param memo
@@ -3,7 +3,7 @@ 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.parsedObject = exports.sortByProperty = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.ZAURU_REGEX = exports.priceToText = exports.arrayToObject = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.obtenerFechaActualConZonaHoraria = exports.getDatePickerCurrentDate = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.getBasketsSchema = exports.setRejectionPercentage = exports.getRejectionPercentage = exports.mergeJsonMemo = exports.stringifyJsonMemo = exports.parseJsonMemo = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
6
+ exports.parsedObject = exports.sortByProperty = exports.labFormPatter = exports.labServicePattern = exports.getRandomNum = exports.CURRENCY_PREFIX = exports.truncateDecimals = exports.ZAURU_REGEX = exports.priceToText = exports.arrayToObject = exports.isNumeric = exports.toFixedIfNeeded = exports.formatTimeToTimePicker = exports.formatDateToDatePicker = exports.getFormattedDate = exports.parsedBaculoFormValue = exports.getPayeeInfoOptions = exports.getPayeeInfoIdOptions = exports.getPayeeFormated = exports.getDateAfterDays = exports.getTimePickerCurrentTime = exports.obtenerFechaActualConZonaHoraria = exports.getDatePickerCurrentDate = exports.stringDateToParsedUTCDate = exports.localDateToUSDate = exports.getStringFullDate = exports.getTodayMinutesDifference = exports.getTodayDaysDifference = exports.getStringDate = exports.getZauruDateByText = exports.getNewDateByFormat = exports.getFechaJuliana = exports.getBasketsSchema = exports.calculatePurchaseOrderFinancials = exports.setRejectionPercentage = exports.getRejectionPercentage = exports.mergeJsonMemo = exports.stringifyJsonMemo = exports.parseJsonMemo = exports.DESTINOS_MUESTRA_OPTIONS = void 0;
7
7
  exports.generateClientUUID = generateClientUUID;
8
8
  exports.extractValueBetweenTags = extractValueBetweenTags;
9
9
  exports.isJsonArray = isJsonArray;
@@ -80,6 +80,41 @@ const getRejectionPercentage = (source) => {
80
80
  exports.getRejectionPercentage = getRejectionPercentage;
81
81
  const setRejectionPercentage = (memo, percentage) => (0, exports.mergeJsonMemo)(memo, { rejectionPercentage: percentage });
82
82
  exports.setRejectionPercentage = setRejectionPercentage;
83
+ const roundMoney = (value) => Math.round((value + Number.EPSILON) * 100) / 100;
84
+ const lineQuantity = (detail) => {
85
+ const delivered = toFiniteNumber(detail.delivered_quantity) ??
86
+ toFiniteNumber(detail.delivered);
87
+ if (delivered != null && delivered > 0)
88
+ return delivered;
89
+ return (toFiniteNumber(detail.booked_quantity) ??
90
+ toFiniteNumber(detail.booked) ??
91
+ toFiniteNumber(detail.quantity) ??
92
+ 0);
93
+ };
94
+ /**
95
+ * Header money for a purchase order: subtotal = qty × unit_cost,
96
+ * discount = subtotal × rejectionPercentage / 100.
97
+ * Does not change unit cost. purchase_orders.discount is the monetary column.
98
+ */
99
+ const calculatePurchaseOrderFinancials = (input) => {
100
+ const details = input.details ?? [];
101
+ const subtotal = roundMoney(details.reduce((sum, detail) => {
102
+ const unitCost = toFiniteNumber(detail.unit_cost) ?? 0;
103
+ return sum + lineQuantity(detail) * unitCost;
104
+ }, 0));
105
+ const rejectionPercentage = toFiniteNumber(input.rejectionPercentage);
106
+ if (rejectionPercentage == null ||
107
+ rejectionPercentage <= 0 ||
108
+ !Number.isFinite(subtotal) ||
109
+ subtotal <= 0) {
110
+ return { subtotal: Number.isFinite(subtotal) ? subtotal : 0, discount: 0 };
111
+ }
112
+ return {
113
+ subtotal,
114
+ discount: roundMoney(subtotal * (rejectionPercentage / 100)),
115
+ };
116
+ };
117
+ exports.calculatePurchaseOrderFinancials = calculatePurchaseOrderFinancials;
83
118
  /**
84
119
  * Obtener el objeto de canastas en base al memo
85
120
  * @param memo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/common",
3
- "version": "6.3.5",
3
+ "version": "6.4.0",
4
4
  "description": "Funciones de uso común en el desarrollo de webapps en Zauru",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -21,9 +21,9 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@remix-run/node": "^2.8.1",
24
- "@zauru-sdk/types": "^6.13.0",
24
+ "@zauru-sdk/types": "^6.14.0",
25
25
  "moment": "^2.30.1",
26
26
  "moment-timezone": "^0.5.45"
27
27
  },
28
- "gitHead": "9d36380b88d7e251132cf68af896afecab65569f"
28
+ "gitHead": "66fea5adcf174e0a5e7a5f9324eb45ae0223f8b7"
29
29
  }
package/src/common.ts CHANGED
@@ -7,6 +7,9 @@ import type {
7
7
  SelectFieldOption,
8
8
  MonthsType,
9
9
  JsonMemoType,
10
+ CalculatePurchaseOrderFinancialsInput,
11
+ CalculatePurchaseOrderFinancialsResult,
12
+ PurchaseOrderFinancialDetail,
10
13
  } from "@zauru-sdk/types";
11
14
  import { MONTHS } from "@zauru-sdk/types";
12
15
 
@@ -82,6 +85,55 @@ export const setRejectionPercentage = (
82
85
  percentage: number,
83
86
  ): string => mergeJsonMemo(memo, { rejectionPercentage: percentage });
84
87
 
88
+ const roundMoney = (value: number): number =>
89
+ Math.round((value + Number.EPSILON) * 100) / 100;
90
+
91
+ const lineQuantity = (detail: PurchaseOrderFinancialDetail): number => {
92
+ const delivered =
93
+ toFiniteNumber(detail.delivered_quantity) ??
94
+ toFiniteNumber(detail.delivered);
95
+ if (delivered != null && delivered > 0) return delivered;
96
+
97
+ return (
98
+ toFiniteNumber(detail.booked_quantity) ??
99
+ toFiniteNumber(detail.booked) ??
100
+ toFiniteNumber(detail.quantity) ??
101
+ 0
102
+ );
103
+ };
104
+
105
+ /**
106
+ * Header money for a purchase order: subtotal = qty × unit_cost,
107
+ * discount = subtotal × rejectionPercentage / 100.
108
+ * Does not change unit cost. purchase_orders.discount is the monetary column.
109
+ */
110
+ export const calculatePurchaseOrderFinancials = (
111
+ input: CalculatePurchaseOrderFinancialsInput,
112
+ ): CalculatePurchaseOrderFinancialsResult => {
113
+ const details = input.details ?? [];
114
+ const subtotal = roundMoney(
115
+ details.reduce((sum, detail) => {
116
+ const unitCost = toFiniteNumber(detail.unit_cost) ?? 0;
117
+ return sum + lineQuantity(detail) * unitCost;
118
+ }, 0),
119
+ );
120
+
121
+ const rejectionPercentage = toFiniteNumber(input.rejectionPercentage);
122
+ if (
123
+ rejectionPercentage == null ||
124
+ rejectionPercentage <= 0 ||
125
+ !Number.isFinite(subtotal) ||
126
+ subtotal <= 0
127
+ ) {
128
+ return { subtotal: Number.isFinite(subtotal) ? subtotal : 0, discount: 0 };
129
+ }
130
+
131
+ return {
132
+ subtotal,
133
+ discount: roundMoney(subtotal * (rejectionPercentage / 100)),
134
+ };
135
+ };
136
+
85
137
  /**
86
138
  * Obtener el objeto de canastas en base al memo
87
139
  * @param memo