@zauru-sdk/services 6.3.0 → 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/dist/esm/index.js CHANGED
@@ -34,6 +34,7 @@ export * from "./zauru/zauru-payment-terms.js";
34
34
  export * from "./zauru/zauru-payment-method.js";
35
35
  export * from "./zauru/zauru-price-lists.js";
36
36
  export * from "./zauru/zauru-print-templates.js";
37
+ export * from "./zauru/zauru-production-work-orders.js";
37
38
  export * from "./zauru/zauru-purchase-orders.js";
38
39
  export * from "./zauru/zauru-profiles.js";
39
40
  export * from "./zauru/zauru-receptions.js";
@@ -0,0 +1,122 @@
1
+ import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getProductionWorkOrderStringQuery } from "@zauru-sdk/graphql";
3
+ import { getGraphQLAPIHeaders } from "../common.js";
4
+ import { httpGraphQLAPI } from "./httpGraphQL.js";
5
+ import { httpZauru } from "./httpZauru.js";
6
+ /**
7
+ * getProductionWorkOrder
8
+ * @param session
9
+ * @param config
10
+ * @returns
11
+ */
12
+ export async function getProductionWorkOrder(session, config) {
13
+ return handlePossibleAxiosErrors(async () => {
14
+ const headers = await getGraphQLAPIHeaders(session);
15
+ const response = await httpGraphQLAPI.post("", {
16
+ query: getProductionWorkOrderStringQuery({
17
+ id: config.id,
18
+ closed: config.closed ?? false,
19
+ voided: config.voided ?? false,
20
+ }),
21
+ }, { headers });
22
+ if (response.data.errors) {
23
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
24
+ }
25
+ const workOrder = response.data.data.production_work_orders[0];
26
+ if (!workOrder) {
27
+ throw new Error("Production work order not found");
28
+ }
29
+ return workOrder;
30
+ });
31
+ }
32
+ /**
33
+ * getOpenWorkOrdersDataTables
34
+ * @param headers
35
+ * @param body
36
+ * @returns
37
+ */
38
+ export const getOpenWorkOrdersDataTables = (headers, body) => {
39
+ return handlePossibleAxiosErrors(async () => {
40
+ const response = await httpZauru.post(`/production/open_work_orders/datatables.json`, body, { headers });
41
+ return response.data;
42
+ });
43
+ };
44
+ /**
45
+ * buildCloseOpenWorkOrderBody
46
+ * @param details
47
+ * @param options
48
+ * @returns
49
+ */
50
+ export const buildCloseOpenWorkOrderBody = (details, options) => {
51
+ const defaultDeliveredToBooked = options?.defaultDeliveredToBooked ?? true;
52
+ const work_order_details_attributes = details.map((detail) => {
53
+ const deliveredQuantity = defaultDeliveredToBooked
54
+ ? (detail.delivered_quantity ?? detail.booked_quantity)
55
+ : detail.delivered_quantity;
56
+ return {
57
+ id: detail.id,
58
+ item_id: detail.item_id,
59
+ bundle_id: detail.bundle_id,
60
+ cost_center_id: detail.cost_center_id,
61
+ lot_id: detail.lot_id,
62
+ serial_id: detail.serial_id,
63
+ booked_quantity: detail.booked_quantity,
64
+ delivered_quantity: deliveredQuantity === null || deliveredQuantity === undefined
65
+ ? undefined
66
+ : deliveredQuantity,
67
+ reference: detail.reference,
68
+ };
69
+ });
70
+ return {
71
+ production_work_order: {
72
+ work_order_details_attributes,
73
+ },
74
+ };
75
+ };
76
+ /**
77
+ * closeOpenWorkOrder
78
+ * @param headers
79
+ * @param id
80
+ * @param body
81
+ * @returns
82
+ */
83
+ export const closeOpenWorkOrder = (headers, id, body) => {
84
+ return handlePossibleAxiosErrors(async () => {
85
+ const sendBody = body ?? { production_work_order: {} };
86
+ const normalizedBody = sendBody.production_work_order
87
+ ?.work_order_details_attributes
88
+ ? {
89
+ production_work_order: {
90
+ work_order_details_attributes: arrayToObject(sendBody.production_work_order.work_order_details_attributes),
91
+ },
92
+ }
93
+ : sendBody;
94
+ const response = await httpZauru.patch(`/production/open_work_orders/${id}/update_close`, normalizedBody, { headers });
95
+ return response.data;
96
+ });
97
+ };
98
+ /**
99
+ * closeOpenWorkOrderWithBookedQuantities
100
+ * @param headers
101
+ * @param session
102
+ * @param id
103
+ * @returns
104
+ */
105
+ export const closeOpenWorkOrderWithBookedQuantities = async (headers, session, id) => {
106
+ const workOrderResult = await getProductionWorkOrder(session, {
107
+ id,
108
+ closed: false,
109
+ voided: false,
110
+ });
111
+ if (workOrderResult.error) {
112
+ return workOrderResult;
113
+ }
114
+ const details = workOrderResult.data?.production_work_order_details ?? [];
115
+ if (details.length === 0) {
116
+ return closeOpenWorkOrder(headers, id);
117
+ }
118
+ const body = buildCloseOpenWorkOrderBody(details, {
119
+ defaultDeliveredToBooked: true,
120
+ });
121
+ return closeOpenWorkOrder(headers, id, body);
122
+ };
package/dist/index.d.ts CHANGED
@@ -34,6 +34,7 @@ export * from "./zauru/zauru-payment-terms.js";
34
34
  export * from "./zauru/zauru-payment-method.js";
35
35
  export * from "./zauru/zauru-price-lists.js";
36
36
  export * from "./zauru/zauru-print-templates.js";
37
+ export * from "./zauru/zauru-production-work-orders.js";
37
38
  export * from "./zauru/zauru-purchase-orders.js";
38
39
  export * from "./zauru/zauru-profiles.js";
39
40
  export * from "./zauru/zauru-receptions.js";
@@ -0,0 +1,47 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, CloseOpenWorkOrderBody, CloseOpenWorkOrderDetailInput, CloseOpenWorkOrderResponse, DataTablesFilterBody, OpenWorkOrdersDataTableResponse, ProductionWorkOrderDetailGraphQL, ProductionWorkOrderGraphQL } from "@zauru-sdk/types";
3
+ type CloseDetailSource = ProductionWorkOrderDetailGraphQL | CloseOpenWorkOrderDetailInput;
4
+ /**
5
+ * getProductionWorkOrder
6
+ * @param session
7
+ * @param config
8
+ * @returns
9
+ */
10
+ export declare function getProductionWorkOrder(session: Session, config: {
11
+ id: number | string;
12
+ closed?: boolean;
13
+ voided?: boolean;
14
+ }): Promise<AxiosUtilsResponse<ProductionWorkOrderGraphQL>>;
15
+ /**
16
+ * getOpenWorkOrdersDataTables
17
+ * @param headers
18
+ * @param body
19
+ * @returns
20
+ */
21
+ export declare const getOpenWorkOrdersDataTables: (headers: any, body: DataTablesFilterBody) => Promise<AxiosUtilsResponse<OpenWorkOrdersDataTableResponse>>;
22
+ /**
23
+ * buildCloseOpenWorkOrderBody
24
+ * @param details
25
+ * @param options
26
+ * @returns
27
+ */
28
+ export declare const buildCloseOpenWorkOrderBody: (details: CloseDetailSource[], options?: {
29
+ defaultDeliveredToBooked?: boolean;
30
+ }) => CloseOpenWorkOrderBody;
31
+ /**
32
+ * closeOpenWorkOrder
33
+ * @param headers
34
+ * @param id
35
+ * @param body
36
+ * @returns
37
+ */
38
+ export declare const closeOpenWorkOrder: (headers: any, id: number | string, body?: CloseOpenWorkOrderBody) => Promise<AxiosUtilsResponse<CloseOpenWorkOrderResponse>>;
39
+ /**
40
+ * closeOpenWorkOrderWithBookedQuantities
41
+ * @param headers
42
+ * @param session
43
+ * @param id
44
+ * @returns
45
+ */
46
+ export declare const closeOpenWorkOrderWithBookedQuantities: (headers: any, session: Session, id: number | string) => Promise<AxiosUtilsResponse<CloseOpenWorkOrderResponse>>;
47
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zauru-sdk/services",
3
- "version": "6.3.0",
3
+ "version": "6.4.0",
4
4
  "description": "Servicios de consulta a Zauru",
5
5
  "main": "./dist/esm/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -26,13 +26,13 @@
26
26
  "dependencies": {
27
27
  "@remix-run/node": "^2.8.1",
28
28
  "@upstash/redis": "^1.34.5",
29
- "@zauru-sdk/common": "^6.2.2",
29
+ "@zauru-sdk/common": "^6.2.3",
30
30
  "@zauru-sdk/config": "^6.0.0",
31
- "@zauru-sdk/graphql": "^6.0.0",
32
- "@zauru-sdk/types": "^6.5.0",
31
+ "@zauru-sdk/graphql": "^6.1.0",
32
+ "@zauru-sdk/types": "^6.6.0",
33
33
  "axios": "^1.6.7",
34
34
  "chalk": "5.3.0",
35
35
  "moment": "^2.30.1"
36
36
  },
37
- "gitHead": "ee6a91336c5711d22879f6936429d1f91a7097f2"
37
+ "gitHead": "f07eda3ef08930a12aebb64c36f6183d26caf57b"
38
38
  }