@zauru-sdk/common 6.12.0 → 6.13.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 +8 -0
- package/dist/common.d.ts +6 -1
- package/dist/esm/common.js +25 -1
- package/package.json +4 -4
- package/src/common.ts +31 -0
- package/src/purchaseOrderFinancials.test.ts +64 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
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.13.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.12.0...@zauru-sdk/common@6.13.0) (2026-10-29)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* armar cost de línea como qty × unit_cost ([707d6b25](https://github.com/intuitiva/zauru-typescript-sdk/commit/707d6b25))
|
|
12
|
+
|
|
13
|
+
|
|
6
14
|
# [6.12.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/common@6.10.1...@zauru-sdk/common@6.12.0) (2026-10-26)
|
|
7
15
|
|
|
8
16
|
|
package/dist/common.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "moment-timezone";
|
|
2
|
-
import type { PayeeGraphQL, AxiosUtilsResponse, BasketSchema, SelectFieldOption, JsonMemoType, CalculatePurchaseOrderFinancialsInput, CalculatePurchaseOrderFinancialsResult, RejectionPercentageLayers } from "@zauru-sdk/types";
|
|
2
|
+
import type { PayeeGraphQL, AxiosUtilsResponse, BasketSchema, SelectFieldOption, JsonMemoType, CalculatePurchaseOrderFinancialsInput, CalculatePurchaseOrderFinancialsResult, PurchaseOrderDetailCostAttribute, PurchaseOrderFinancialDetail, RejectionPercentageLayers } 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;
|
|
@@ -38,6 +38,11 @@ export declare const resolveRejectionPercentageBase: (memo?: string | object) =>
|
|
|
38
38
|
* `rejectionPercentage` in the result is the effective % that was charged.
|
|
39
39
|
*/
|
|
40
40
|
export declare const calculatePurchaseOrderFinancials: (input: CalculatePurchaseOrderFinancialsInput) => CalculatePurchaseOrderFinancialsResult;
|
|
41
|
+
/**
|
|
42
|
+
* Nested attributes for Zauru: `cost` must be sent with `unit_cost`.
|
|
43
|
+
* Baculo does not recalculate `purchase_order_details.cost` on save.
|
|
44
|
+
*/
|
|
45
|
+
export declare const buildPurchaseOrderDetailsCostAttributes: (details: PurchaseOrderFinancialDetail[] | null | undefined, unitCostByDetailId?: Map<number, number>) => Record<string, PurchaseOrderDetailCostAttribute>;
|
|
41
46
|
/**
|
|
42
47
|
* Obtener el objeto de canastas en base al memo
|
|
43
48
|
* @param memo
|
package/dist/esm/common.js
CHANGED
|
@@ -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.calculatePurchaseOrderFinancials = exports.resolveRejectionPercentageBase = exports.hasSuccessiveRejectionPercentage = exports.getRejectionPercentageLayers = exports.resolveRejectionPercentageLayers = 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.buildPurchaseOrderDetailsCostAttributes = exports.calculatePurchaseOrderFinancials = exports.resolveRejectionPercentageBase = exports.hasSuccessiveRejectionPercentage = exports.getRejectionPercentageLayers = exports.resolveRejectionPercentageLayers = 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;
|
|
@@ -174,6 +174,30 @@ const calculatePurchaseOrderFinancials = (input) => {
|
|
|
174
174
|
};
|
|
175
175
|
};
|
|
176
176
|
exports.calculatePurchaseOrderFinancials = calculatePurchaseOrderFinancials;
|
|
177
|
+
/**
|
|
178
|
+
* Nested attributes for Zauru: `cost` must be sent with `unit_cost`.
|
|
179
|
+
* Baculo does not recalculate `purchase_order_details.cost` on save.
|
|
180
|
+
*/
|
|
181
|
+
const buildPurchaseOrderDetailsCostAttributes = (details, unitCostByDetailId) => {
|
|
182
|
+
const attributes = {};
|
|
183
|
+
let index = 0;
|
|
184
|
+
for (const detail of details ?? []) {
|
|
185
|
+
const id = toFiniteNumber(detail.id);
|
|
186
|
+
const itemId = toFiniteNumber(detail.item_id);
|
|
187
|
+
if (id == null || itemId == null)
|
|
188
|
+
continue;
|
|
189
|
+
const unitCost = unitCostByDetailId?.get(id) ?? toFiniteNumber(detail.unit_cost) ?? 0;
|
|
190
|
+
attributes[String(index)] = {
|
|
191
|
+
id,
|
|
192
|
+
item_id: itemId,
|
|
193
|
+
unit_cost: unitCost,
|
|
194
|
+
cost: roundMoney(lineQuantity(detail) * unitCost),
|
|
195
|
+
};
|
|
196
|
+
index += 1;
|
|
197
|
+
}
|
|
198
|
+
return attributes;
|
|
199
|
+
};
|
|
200
|
+
exports.buildPurchaseOrderDetailsCostAttributes = buildPurchaseOrderDetailsCostAttributes;
|
|
177
201
|
/**
|
|
178
202
|
* Obtener el objeto de canastas en base al memo
|
|
179
203
|
* @param memo
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/common",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.13.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",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "npm run build:esm",
|
|
14
14
|
"build:esm": "tsc -p tsconfig.esm.json",
|
|
15
|
-
"test": "tsx --test src/httpClientPolicy.test.ts src/providerRestrictions.test.ts src/providerReceptionMatrix.test.ts"
|
|
15
|
+
"test": "tsx --test src/httpClientPolicy.test.ts src/providerRestrictions.test.ts src/providerReceptionMatrix.test.ts src/purchaseOrderFinancials.test.ts"
|
|
16
16
|
},
|
|
17
17
|
"author": "Oscar Cuéllar",
|
|
18
18
|
"license": "MIT",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
24
|
"@remix-run/node": "^2.8.1",
|
|
25
|
-
"@zauru-sdk/types": "^6.
|
|
25
|
+
"@zauru-sdk/types": "^6.29.0",
|
|
26
26
|
"moment": "^2.30.1",
|
|
27
27
|
"moment-timezone": "^0.5.45"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "671859beecfce09a1ccf138055a4de26a8c1f059"
|
|
30
30
|
}
|
package/src/common.ts
CHANGED
|
@@ -9,6 +9,7 @@ import type {
|
|
|
9
9
|
JsonMemoType,
|
|
10
10
|
CalculatePurchaseOrderFinancialsInput,
|
|
11
11
|
CalculatePurchaseOrderFinancialsResult,
|
|
12
|
+
PurchaseOrderDetailCostAttribute,
|
|
12
13
|
PurchaseOrderFinancialDetail,
|
|
13
14
|
RejectionPercentageLayers,
|
|
14
15
|
} from "@zauru-sdk/types";
|
|
@@ -232,6 +233,36 @@ export const calculatePurchaseOrderFinancials = (
|
|
|
232
233
|
};
|
|
233
234
|
};
|
|
234
235
|
|
|
236
|
+
/**
|
|
237
|
+
* Nested attributes for Zauru: `cost` must be sent with `unit_cost`.
|
|
238
|
+
* Baculo does not recalculate `purchase_order_details.cost` on save.
|
|
239
|
+
*/
|
|
240
|
+
export const buildPurchaseOrderDetailsCostAttributes = (
|
|
241
|
+
details: PurchaseOrderFinancialDetail[] | null | undefined,
|
|
242
|
+
unitCostByDetailId?: Map<number, number>,
|
|
243
|
+
): Record<string, PurchaseOrderDetailCostAttribute> => {
|
|
244
|
+
const attributes: Record<string, PurchaseOrderDetailCostAttribute> = {};
|
|
245
|
+
let index = 0;
|
|
246
|
+
|
|
247
|
+
for (const detail of details ?? []) {
|
|
248
|
+
const id = toFiniteNumber(detail.id);
|
|
249
|
+
const itemId = toFiniteNumber(detail.item_id);
|
|
250
|
+
if (id == null || itemId == null) continue;
|
|
251
|
+
|
|
252
|
+
const unitCost =
|
|
253
|
+
unitCostByDetailId?.get(id) ?? toFiniteNumber(detail.unit_cost) ?? 0;
|
|
254
|
+
attributes[String(index)] = {
|
|
255
|
+
id,
|
|
256
|
+
item_id: itemId,
|
|
257
|
+
unit_cost: unitCost,
|
|
258
|
+
cost: roundMoney(lineQuantity(detail) * unitCost),
|
|
259
|
+
};
|
|
260
|
+
index += 1;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return attributes;
|
|
264
|
+
};
|
|
265
|
+
|
|
235
266
|
/**
|
|
236
267
|
* Obtener el objeto de canastas en base al memo
|
|
237
268
|
* @param memo
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { describe, it } from "node:test";
|
|
3
|
+
import {
|
|
4
|
+
buildPurchaseOrderDetailsCostAttributes,
|
|
5
|
+
calculatePurchaseOrderFinancials,
|
|
6
|
+
} from "./common.js";
|
|
7
|
+
|
|
8
|
+
describe("buildPurchaseOrderDetailsCostAttributes", () => {
|
|
9
|
+
it("sends cost as qty × unit_cost so Baculo can refresh subtotal", () => {
|
|
10
|
+
const attributes = buildPurchaseOrderDetailsCostAttributes(
|
|
11
|
+
[
|
|
12
|
+
{
|
|
13
|
+
id: 2827653,
|
|
14
|
+
item_id: 490543,
|
|
15
|
+
booked_quantity: 14,
|
|
16
|
+
delivered_quantity: 14,
|
|
17
|
+
unit_cost: 8.2,
|
|
18
|
+
},
|
|
19
|
+
],
|
|
20
|
+
new Map([[2827653, 7.7]]),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
assert.deepEqual(attributes, {
|
|
24
|
+
"0": {
|
|
25
|
+
id: 2827653,
|
|
26
|
+
item_id: 490543,
|
|
27
|
+
unit_cost: 7.7,
|
|
28
|
+
cost: 107.8,
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("keeps current unit_cost when there is no override", () => {
|
|
34
|
+
const attributes = buildPurchaseOrderDetailsCostAttributes([
|
|
35
|
+
{
|
|
36
|
+
id: 1,
|
|
37
|
+
item_id: 2,
|
|
38
|
+
booked_quantity: 10,
|
|
39
|
+
unit_cost: 4.5,
|
|
40
|
+
},
|
|
41
|
+
]);
|
|
42
|
+
|
|
43
|
+
assert.equal(attributes["0"].unit_cost, 4.5);
|
|
44
|
+
assert.equal(attributes["0"].cost, 45);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
describe("calculatePurchaseOrderFinancials", () => {
|
|
49
|
+
it("uses the new unit cost as the rejection discount base", () => {
|
|
50
|
+
const financials = calculatePurchaseOrderFinancials({
|
|
51
|
+
details: [
|
|
52
|
+
{
|
|
53
|
+
booked_quantity: 14,
|
|
54
|
+
delivered_quantity: 14,
|
|
55
|
+
unit_cost: 7.7,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
rejectionPercentage: 7,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
assert.equal(financials.subtotal, 107.8);
|
|
62
|
+
assert.equal(financials.discount, 7.55);
|
|
63
|
+
});
|
|
64
|
+
});
|