@zauru-sdk/services 1.0.6 → 1.0.8

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.
Files changed (77) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/index.d.ts +23 -0
  3. package/dist/index.js +23 -0
  4. package/dist/zauru/zauru-bookings.server.d.ts +28 -0
  5. package/dist/zauru/zauru-bookings.server.js +80 -0
  6. package/dist/zauru/zauru-bundles.service.d.ts +28 -0
  7. package/dist/zauru/zauru-bundles.service.js +93 -0
  8. package/dist/zauru/zauru-cases.server.d.ts +6 -0
  9. package/dist/zauru/zauru-cases.server.js +23 -0
  10. package/dist/zauru/zauru-consolidated.server.d.ts +36 -0
  11. package/dist/zauru/zauru-consolidated.server.js +71 -0
  12. package/dist/zauru/zauru-currencies.server.d.ts +6 -0
  13. package/dist/zauru/zauru-currencies.server.js +20 -0
  14. package/dist/zauru/zauru-deliveries.server.d.ts +22 -0
  15. package/dist/zauru/zauru-deliveries.server.js +44 -0
  16. package/dist/zauru/zauru-discharges.server.d.ts +26 -0
  17. package/dist/zauru/zauru-discharges.server.js +46 -0
  18. package/dist/zauru/zauru-employees.server.d.ts +6 -0
  19. package/dist/zauru/zauru-employees.server.js +23 -0
  20. package/dist/zauru/zauru-forms.server.d.ts +96 -0
  21. package/dist/zauru/zauru-forms.server.js +343 -0
  22. package/dist/zauru/zauru-invoices.server.d.ts +26 -0
  23. package/dist/zauru/zauru-invoices.server.js +94 -0
  24. package/dist/zauru/zauru-items.server.d.ts +91 -0
  25. package/dist/zauru/zauru-items.server.js +238 -0
  26. package/dist/zauru/zauru-lote-record.server.d.ts +8 -0
  27. package/dist/zauru/zauru-lote-record.server.js +26 -0
  28. package/dist/zauru/zauru-lotes.server.d.ts +91 -0
  29. package/dist/zauru/zauru-lotes.server.js +294 -0
  30. package/dist/zauru/zauru-motivos-rechazo.server.d.ts +9 -0
  31. package/dist/zauru/zauru-motivos-rechazo.server.js +49 -0
  32. package/dist/zauru/zauru-payees.server.d.ts +97 -0
  33. package/dist/zauru/zauru-payees.server.js +227 -0
  34. package/dist/zauru/zauru-payment-terms.server.d.ts +20 -0
  35. package/dist/zauru/zauru-payment-terms.server.js +65 -0
  36. package/dist/zauru/zauru-price-lists.server.d.ts +22 -0
  37. package/dist/zauru/zauru-price-lists.server.js +40 -0
  38. package/dist/zauru/zauru-purchase-orders.server.d.ts +160 -0
  39. package/dist/zauru/zauru-purchase-orders.server.js +414 -0
  40. package/dist/zauru/zauru-receptions.server.d.ts +33 -0
  41. package/dist/zauru/zauru-receptions.server.js +94 -0
  42. package/dist/zauru/zauru-shipments.server.d.ts +20 -0
  43. package/dist/zauru/zauru-shipments.server.js +53 -0
  44. package/dist/zauru/zauru-suggested-prices.server.d.ts +30 -0
  45. package/dist/zauru/zauru-suggested-prices.server.js +83 -0
  46. package/dist/zauru/zauru-tags.server.d.ts +7 -0
  47. package/dist/zauru/zauru-tags.server.js +13 -0
  48. package/dist/zauru/zauru-templates.server.d.ts +7 -0
  49. package/dist/zauru/zauru-templates.server.js +15 -0
  50. package/dist/zauru/zauru-web-app-tables.server.d.ts +48 -0
  51. package/dist/zauru/zauru-web-app-tables.server.js +120 -0
  52. package/package.json +6 -6
  53. package/src/index.ts +23 -0
  54. package/src/zauru/zauru-bookings.server.ts +134 -0
  55. package/src/zauru/zauru-bundles.service.ts +157 -0
  56. package/src/zauru/zauru-cases.server.ts +44 -0
  57. package/src/zauru/zauru-consolidated.server.ts +129 -0
  58. package/src/zauru/zauru-currencies.server.ts +39 -0
  59. package/src/zauru/zauru-deliveries.server.ts +70 -0
  60. package/src/zauru/zauru-discharges.server.ts +90 -0
  61. package/src/zauru/zauru-employees.server.ts +43 -0
  62. package/src/zauru/zauru-forms.server.ts +618 -0
  63. package/src/zauru/zauru-invoices.server.ts +142 -0
  64. package/src/zauru/zauru-items.server.ts +427 -0
  65. package/src/zauru/zauru-lote-record.server.ts +77 -0
  66. package/src/zauru/zauru-lotes.server.ts +484 -0
  67. package/src/zauru/zauru-motivos-rechazo.server.ts +121 -0
  68. package/src/zauru/zauru-payees.server.ts +398 -0
  69. package/src/zauru/zauru-payment-terms.server.ts +126 -0
  70. package/src/zauru/zauru-price-lists.server.ts +68 -0
  71. package/src/zauru/zauru-purchase-orders.server.ts +701 -0
  72. package/src/zauru/zauru-receptions.server.ts +148 -0
  73. package/src/zauru/zauru-shipments.server.ts +88 -0
  74. package/src/zauru/zauru-suggested-prices.server.ts +134 -0
  75. package/src/zauru/zauru-tags.server.ts +22 -0
  76. package/src/zauru/zauru-templates.server.ts +24 -0
  77. package/src/zauru/zauru-web-app-tables.server.ts +200 -0
@@ -0,0 +1,414 @@
1
+ import { arrayToObject, convertToFormData, formatDateToUTC, getBasketsSchema, handlePossibleAxiosErrors, reduceAdd, } from "@zauru-sdk/common";
2
+ import { createNewLotPurchaseOrderReception, createNewPurchaseOrderReception, } from "./zauru-receptions.server.js";
3
+ import httpZauru from "./httpZauru.server.js";
4
+ import { getGraphQLAPIHeaders, getVariablesByName } from "~/common.server.js";
5
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
6
+ import { getLast100ReceptionsStringQuery, getPurchaseOrderByIdNumberStringQuery, getPurchaseOrderStringQuery, getPurchaseOrdersBetweenDatesStringQuery, } from "@zauru-sdk/graphql";
7
+ /**
8
+ * markAsReceivePurchaseOrder
9
+ * Esta función sólo se utiliza cuando se van a marcar como recibida toda la órden de compra, se recibe todo lo que se envío
10
+ * si se quiere recibir parcialmente, utilizar el endpoint de /receptions
11
+ * @param headers
12
+ * @param body
13
+ * @returns
14
+ */
15
+ export async function markAsReceivePurchaseOrder(headers, body) {
16
+ return handlePossibleAxiosErrors(async () => {
17
+ const sendBody = { ...body };
18
+ if (sendBody.fechaVencimiento) {
19
+ await receiveLotPurchaseOrder(headers, sendBody);
20
+ }
21
+ else {
22
+ await receivePurchaseOrder(headers, sendBody);
23
+ }
24
+ return true;
25
+ });
26
+ }
27
+ /**
28
+ * markAsReceivePartialPurchaseOrder
29
+ * @param headers
30
+ * @param body
31
+ * @returns
32
+ */
33
+ export async function markAsReceivePartialPurchaseOrder(headers, session, body) {
34
+ return handlePossibleAxiosErrors(async () => {
35
+ const sendBody = { ...body };
36
+ if (sendBody.fechaVencimiento) {
37
+ await createNewLotPurchaseOrderReception(headers, session, sendBody);
38
+ }
39
+ else {
40
+ await createNewPurchaseOrderReception(headers, session, body);
41
+ }
42
+ return true;
43
+ });
44
+ }
45
+ /**
46
+ *
47
+ * @param headers
48
+ * @param body
49
+ * @returns
50
+ */
51
+ export async function createNewPurchaseOrder(headers, body) {
52
+ return handlePossibleAxiosErrors(async () => {
53
+ let sendBody = {
54
+ ...body,
55
+ purchase_order_details_attributes: arrayToObject(body?.purchase_order_details),
56
+ tag_ids: [
57
+ "",
58
+ ...(body?.taggings?.map((x) => x.tag_id?.toString()) ?? []),
59
+ ],
60
+ };
61
+ delete headers["Content-type"];
62
+ delete sendBody.__rvfInternalFormId;
63
+ delete sendBody.taggings;
64
+ delete sendBody.purchase_order_details;
65
+ if (!(sendBody?.pdf instanceof File) || sendBody.pdf?.size <= 0) {
66
+ delete sendBody.pdf;
67
+ }
68
+ sendBody = convertToFormData({
69
+ purchase_order: sendBody,
70
+ });
71
+ const response = await httpZauru.post(`/purchases/purchase_orders.json`, sendBody, { headers });
72
+ return response.data;
73
+ });
74
+ }
75
+ /**
76
+ *
77
+ * @param headers
78
+ * @param body
79
+ * @returns
80
+ */
81
+ export async function createNewAuthorizedPurchaseOrder(headers, body, withReceive = true) {
82
+ return handlePossibleAxiosErrors(async () => {
83
+ const sendBody = {
84
+ ...body,
85
+ purchase_order_details_attributes: arrayToObject(body?.purchase_order_details),
86
+ };
87
+ const response = await httpZauru.post(`/purchases/purchase_orders.json`, { purchase_order: sendBody }, { headers });
88
+ await httpZauru.get(`/purchases/purchase_orders/${response.data.id}/authorize.json`, { headers });
89
+ if (withReceive) {
90
+ if (sendBody.fechaVencimiento) {
91
+ await receiveLotPurchaseOrder(headers, response.data);
92
+ }
93
+ else {
94
+ await receivePurchaseOrder(headers, response.data);
95
+ }
96
+ }
97
+ return response.data;
98
+ });
99
+ }
100
+ /**
101
+ * receiveLotPurchaseOrder
102
+ * @param headers
103
+ * @param body
104
+ * @returns
105
+ */
106
+ export async function receiveLotPurchaseOrder(headers, body) {
107
+ return handlePossibleAxiosErrors(async () => {
108
+ const sendBody = {
109
+ agency_id: body.agency_id,
110
+ delivery_date: body.issue_date,
111
+ id: body.id,
112
+ needs_transit: false,
113
+ purchase_order_details_attributes: arrayToObject(body.purchase_order_details?.map((x) => {
114
+ const newDetail = {
115
+ id: x.id,
116
+ booked_quantity: x.booked_quantity,
117
+ item_id: x.item_id,
118
+ lot_delivered_quantity: [x.delivered_quantity],
119
+ lot_name: [body.id_number],
120
+ lot_expire: [body.fechaVencimiento],
121
+ };
122
+ return newDetail;
123
+ })),
124
+ };
125
+ await httpZauru.patch(`/purchases/purchase_orders/${body.id}/receive_action`, { purchase_order: sendBody }, { headers });
126
+ return true;
127
+ });
128
+ }
129
+ /**
130
+ * receivePurchaseOrder
131
+ * @param headers
132
+ * @param body
133
+ * @returns
134
+ */
135
+ export async function receivePurchaseOrder(headers, body) {
136
+ return handlePossibleAxiosErrors(async () => {
137
+ const sendBody = {
138
+ agency_id: body.agency_id,
139
+ delivery_date: body.issue_date,
140
+ id: body.id,
141
+ needs_transit: false,
142
+ purchase_order_details_attributes: arrayToObject(body.purchase_order_details?.map((x) => {
143
+ const newDetail = {
144
+ id: x.id,
145
+ delivered_quantity: x.delivered_quantity,
146
+ booked_quantity: x.booked_quantity,
147
+ item_id: x.item_id,
148
+ };
149
+ return newDetail;
150
+ })),
151
+ };
152
+ await httpZauru.patch(`/purchases/purchase_orders/${body.id}/receive_action`, { purchase_order: sendBody }, { headers });
153
+ return true;
154
+ });
155
+ }
156
+ /**
157
+ *
158
+ * @param headers
159
+ * @returns
160
+ */
161
+ export async function getNewPurchaseOrderInfo(headers) {
162
+ return handlePossibleAxiosErrors(async () => {
163
+ const response = await httpZauru.get("/purchases/purchase_orders/new.json", { headers });
164
+ const purchasersList = [];
165
+ response.data?.purchasers?.forEach((purchaser) => {
166
+ if (purchaser?.id) {
167
+ purchasersList.push({
168
+ value: purchaser?.id,
169
+ label: purchaser?.name,
170
+ });
171
+ }
172
+ });
173
+ return { ...response.data, purchasersList };
174
+ });
175
+ }
176
+ /**
177
+ * getPurchasesListDataTables Function for get all zauru orden-compras
178
+ * @param headers
179
+ * @returns
180
+ */
181
+ export async function getPurchasesListDataTables(headers, body) {
182
+ return handlePossibleAxiosErrors(async () => {
183
+ const response = await httpZauru.post(`/purchases/purchase_orders/datatables.json`, body, { headers });
184
+ return response.data;
185
+ });
186
+ }
187
+ /**
188
+ * getPurchasesList Function for get all zauru orden-compras
189
+ * @param headers
190
+ * @param params
191
+ * @returns
192
+ */
193
+ export async function getPurchasesList(headers, session, params = {}, config) {
194
+ return handlePossibleAxiosErrors(async () => {
195
+ //Si quiere obtener los de producción, obtengo primero su agencia producción
196
+ if (config?.fromProduction) {
197
+ const { production_agency_id: temp_production_agency_id } = await getVariablesByName(headers, session, ["production_agency_id"]);
198
+ const hashProductionAgencyId = JSON.parse(temp_production_agency_id ?? "{}");
199
+ const production_agency_id = hashProductionAgencyId[session.get("agency_id")];
200
+ params.agency_id = production_agency_id;
201
+ }
202
+ const response = await httpZauru.get(`/purchases/purchase_orders/export.json`, {
203
+ headers,
204
+ params,
205
+ });
206
+ return response.data;
207
+ });
208
+ }
209
+ /**
210
+ * getPurchase Function for get an especific purchase order
211
+ * @param headers
212
+ * @returns
213
+ */
214
+ export async function getPurchase(headers, purchase_order_id) {
215
+ return handlePossibleAxiosErrors(async () => {
216
+ const response = await httpZauru(`/purchases/purchase_orders/${purchase_order_id}.json`, { method: "GET", headers });
217
+ const baskets_memo = getBasketsSchema(response.data.memo);
218
+ const baskets_memo_quantity = baskets_memo
219
+ .map((basket) => basket.total)
220
+ .reduce(reduceAdd, 0);
221
+ return {
222
+ ...response.data,
223
+ baskets_memo,
224
+ baskets_memo_quantity,
225
+ };
226
+ });
227
+ }
228
+ /**
229
+ * enablePurchase Enable a purchase order
230
+ * @param headers
231
+ * @param purchase_order_id
232
+ * @param reception_id
233
+ * @returns
234
+ */
235
+ export async function enablePurchase(headers, purchase_order_id, reception_id) {
236
+ return handlePossibleAxiosErrors(async () => {
237
+ const response = await httpZauru.get(`/purchases/receptions/${reception_id}/rebound.json?purchase_order_id=${purchase_order_id}`, { headers });
238
+ return response.data;
239
+ });
240
+ }
241
+ /**
242
+ * updatePurchaseOrder
243
+ * @param headers
244
+ * @param body
245
+ * @param purchase_order_id
246
+ * @returns
247
+ */
248
+ export async function updatePurchaseOrder(headers, body, purchase_order_id) {
249
+ return handlePossibleAxiosErrors(async () => {
250
+ const response = await httpZauru.patch(`/purchases/purchase_orders/${purchase_order_id}.json`, body, { headers });
251
+ return response.data;
252
+ });
253
+ }
254
+ /**
255
+ * updatePurchaseOrder
256
+ * @param headers
257
+ * @param body
258
+ * @param purchase_order_id
259
+ * @returns
260
+ */
261
+ export async function updateReceivedPurchaseOrder(headers, body, purchase_order_id) {
262
+ return handlePossibleAxiosErrors(async () => {
263
+ const response = await httpZauru.patch(`/purchases/purchase_orders/${purchase_order_id}/update_received.json`, body, { headers });
264
+ return response.data;
265
+ });
266
+ }
267
+ /**
268
+ * getLast100Receptions
269
+ * @param headers
270
+ * @returns
271
+ */
272
+ export async function getLast100Receptions(session, agency_id) {
273
+ return handlePossibleAxiosErrors(async () => {
274
+ const headers = await getGraphQLAPIHeaders(session);
275
+ const response = await httpGraphQLAPI.post("", {
276
+ query: getLast100ReceptionsStringQuery,
277
+ variables: {
278
+ agencyId: agency_id ?? session.get("agency_id"),
279
+ },
280
+ }, { headers });
281
+ if (response.data.errors) {
282
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
283
+ }
284
+ return response.data?.data?.purchase_orders;
285
+ });
286
+ }
287
+ /**
288
+ * getPurchaseOrder
289
+ * @param headers
290
+ * @returns
291
+ */
292
+ export async function getPurchaseOrder(session, poId, config = {
293
+ withLotStocksToMyAgency: false,
294
+ }) {
295
+ return handlePossibleAxiosErrors(async () => {
296
+ const headers = await getGraphQLAPIHeaders(session);
297
+ const response = await httpGraphQLAPI.post("", {
298
+ query: getPurchaseOrderStringQuery({
299
+ withLotStocks: config.withLotStocksToMyAgency,
300
+ }),
301
+ variables: {
302
+ id: poId,
303
+ },
304
+ }, { headers });
305
+ if (response.data.errors) {
306
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
307
+ }
308
+ const tempResponse = response.data?.data?.purchase_orders[0];
309
+ if (config.withLotStocksToMyAgency) {
310
+ tempResponse.lots[0].lot_stocks = tempResponse.lots[0].lot_stocks.filter((x) => x.agency_id === Number(session.get("agency_id")));
311
+ }
312
+ return tempResponse;
313
+ });
314
+ }
315
+ /**
316
+ * getPurchaseOrder
317
+ * @param headers
318
+ * @returns
319
+ */
320
+ export async function getGraphQLPurchaseOrderBetweenDates(session, dates, config = {
321
+ agencyFilter: true,
322
+ consolidateIdFilter: false,
323
+ useProductionAgencyId: false,
324
+ withShipmentToMyAgency: false,
325
+ withLotStocksToMyAgency: false,
326
+ }) {
327
+ return handlePossibleAxiosErrors(async () => {
328
+ const headers = await getGraphQLAPIHeaders(session);
329
+ let agency_id = config.agencyId;
330
+ if (config.useProductionAgencyId) {
331
+ const { production_agency_id /**{5693: 5696} */ } = await getVariablesByName(headers, session, ["production_agency_id"]);
332
+ const hashAgencyId = JSON.parse(production_agency_id ?? "{}");
333
+ agency_id = hashAgencyId[session.get("agency_id")];
334
+ }
335
+ const query = getPurchaseOrdersBetweenDatesStringQuery({
336
+ agencyFilter: config.agencyFilter,
337
+ consolidateIdFilter: config.consolidateIdFilter,
338
+ lotItemIdExclusion: config.lotItemIdExclusion,
339
+ poDetailTagId: config.poDetailTagId,
340
+ withLotStocks: config.withLotStocksToMyAgency,
341
+ //itemId: config.itemId,
342
+ //payeeCategoryId: config.payeeCategoryId,
343
+ });
344
+ const variables = {
345
+ ...(config.agencyFilter
346
+ ? { agencyId: agency_id ?? session.get("agency_id") }
347
+ : {}),
348
+ ...(config.lotItemIdExclusion
349
+ ? { lotItemIdExclusion: config.lotItemIdExclusion }
350
+ : {}),
351
+ ...(config.poDetailTagId ? { poDetailTagId: config.poDetailTagId } : {}),
352
+ startDate: formatDateToUTC(dates.startDate),
353
+ endDate: formatDateToUTC(dates.endDate),
354
+ };
355
+ const response = await httpGraphQLAPI.post("", {
356
+ query,
357
+ variables,
358
+ }, { headers });
359
+ if (response.data.errors) {
360
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
361
+ }
362
+ //============ Aplicación de filtros
363
+ let responseData = [];
364
+ if (config.withShipmentToMyAgency) {
365
+ responseData = response.data?.data?.purchase_orders.filter((x) => x.shipment_purchase_orders.some((y) => y.shipment.agency_to_id?.toString() == session.get("agency_id")));
366
+ }
367
+ if (config.withLotStocksToMyAgency) {
368
+ responseData = responseData.map((x) => {
369
+ x.lots = x.lots.map((y) => {
370
+ y.lot_stocks = y.lot_stocks.filter((z) => z.agency_id == session.get("agency_id"));
371
+ return y;
372
+ });
373
+ return x;
374
+ });
375
+ }
376
+ return responseData;
377
+ });
378
+ }
379
+ /**
380
+ * deletePurchaseOrder
381
+ * @param headers
382
+ * @param id
383
+ * @returns
384
+ */
385
+ export async function deletePurchaseOrder(headers, id) {
386
+ return handlePossibleAxiosErrors(async () => {
387
+ await httpZauru.delete(`/purchases/purchase_orders/${id}.json?destroy=true`, { headers });
388
+ return true;
389
+ });
390
+ }
391
+ /**
392
+ * getPurchaseOrderByIdNumber
393
+ * @param session
394
+ * @param idNumber
395
+ * @returns
396
+ */
397
+ export async function getPurchasesOrderByIdNumber(session, id_number) {
398
+ return handlePossibleAxiosErrors(async () => {
399
+ const headers = await getGraphQLAPIHeaders(session);
400
+ const response = await httpGraphQLAPI.post("", {
401
+ query: getPurchaseOrderByIdNumberStringQuery,
402
+ variables: {
403
+ id_number,
404
+ },
405
+ }, { headers });
406
+ if (response.data.errors) {
407
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
408
+ }
409
+ if (!response?.data?.data.purchase_orders) {
410
+ return [];
411
+ }
412
+ return response.data?.data?.purchase_orders;
413
+ });
414
+ }
@@ -0,0 +1,33 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, NewReceptionBody, PurchaseOrderGraphQL } from "@zauru-sdk/types";
3
+ /**
4
+ * createNewReception
5
+ * @param headers
6
+ * @param body
7
+ * @param purchase_order_id
8
+ * @returns
9
+ */
10
+ export declare function createNewReception(headers: any, body: NewReceptionBody, purchase_order_id: number | string): Promise<AxiosUtilsResponse<any>>;
11
+ /**
12
+ * deleteReception
13
+ * @param headers
14
+ * @param id
15
+ * @returns
16
+ */
17
+ export declare function deleteReception(headers: any, receptionId: string | number, poId: string | number): Promise<AxiosUtilsResponse<boolean>>;
18
+ /**
19
+ *
20
+ * @param headers
21
+ * @param poId
22
+ * @returns
23
+ */
24
+ export declare function createNewPurchaseOrderReception(headers: any, session: Session, body: Partial<PurchaseOrderGraphQL>): Promise<AxiosUtilsResponse<boolean>>;
25
+ /**
26
+ *
27
+ * @param headers
28
+ * @param poId
29
+ * @returns
30
+ */
31
+ export declare function createNewLotPurchaseOrderReception(headers: any, session: Session, body: Partial<PurchaseOrderGraphQL> & {
32
+ fechaVencimiento: string;
33
+ }): Promise<AxiosUtilsResponse<boolean>>;
@@ -0,0 +1,94 @@
1
+ import { arrayToObject, getDatePickerCurrentDate, handlePossibleAxiosErrors, } from "@zauru-sdk/common";
2
+ import httpZauru from "./httpZauru.server.js";
3
+ /**
4
+ * createNewReception
5
+ * @param headers
6
+ * @param body
7
+ * @param purchase_order_id
8
+ * @returns
9
+ */
10
+ export async function createNewReception(headers, body, purchase_order_id) {
11
+ return handlePossibleAxiosErrors(async () => {
12
+ const response = await httpZauru(`/purchases/purchase_orders/${purchase_order_id}/receptions.json`, { method: "POST", headers, data: body });
13
+ return response.data;
14
+ });
15
+ }
16
+ /**
17
+ * deleteReception
18
+ * @param headers
19
+ * @param id
20
+ * @returns
21
+ */
22
+ export async function deleteReception(headers, receptionId, poId) {
23
+ return handlePossibleAxiosErrors(async () => {
24
+ await httpZauru.get(`/purchases/receptions/${receptionId}/rebound.json?purchase_order_id=${poId}`, {
25
+ headers,
26
+ });
27
+ return true;
28
+ });
29
+ }
30
+ /**
31
+ *
32
+ * @param headers
33
+ * @param poId
34
+ * @returns
35
+ */
36
+ export async function createNewPurchaseOrderReception(headers, session, body) {
37
+ return handlePossibleAxiosErrors(async () => {
38
+ const sendBody = {
39
+ reception: {
40
+ memo: "LABORATORIO - Recibido parcialmente desde WebApp",
41
+ purchase_order_id: body.id,
42
+ needs_transit: false,
43
+ agency_id: session.get("agency_id"),
44
+ entity_id: session.get("selectedEntity"),
45
+ received_at: getDatePickerCurrentDate(),
46
+ invoice_number: "",
47
+ reception_details_attributes: arrayToObject(body?.purchase_order_details?.map((x) => {
48
+ return {
49
+ item_id: x.item_id,
50
+ purchase_order_detail_id: x.id,
51
+ quantity: x.delivered_quantity,
52
+ };
53
+ })),
54
+ },
55
+ purchase_order_id: body.id,
56
+ };
57
+ await httpZauru.post(`/purchases/purchase_orders/${body.id}/receptions.json`, sendBody, {
58
+ headers,
59
+ });
60
+ return true;
61
+ });
62
+ }
63
+ /**
64
+ *
65
+ * @param headers
66
+ * @param poId
67
+ * @returns
68
+ */
69
+ export async function createNewLotPurchaseOrderReception(headers, session, body) {
70
+ return handlePossibleAxiosErrors(async () => {
71
+ const sendBody = {
72
+ memo: "LABORATORIO - Recibido parcialmente desde WebApp",
73
+ purchase_order_id: body.id,
74
+ needs_transit: false,
75
+ received_at: getDatePickerCurrentDate(),
76
+ invoice_number: "",
77
+ agency_id: session.get("agency_id"),
78
+ entity_id: session.get("selectedEntity"),
79
+ reception_details_attributes: arrayToObject(body?.purchase_order_details?.map((x) => {
80
+ return {
81
+ item_id: x.item_id,
82
+ purchase_order_detail_id: x.id,
83
+ lot_delivered_quantity: [x.delivered_quantity],
84
+ lot_name: [body.id_number],
85
+ lot_expire: [body.fechaVencimiento],
86
+ };
87
+ })),
88
+ };
89
+ await httpZauru.post(`/purchases/purchase_orders/${body.id}/receptions.json`, { reception: sendBody, purchase_order_id: body.id }, {
90
+ headers,
91
+ });
92
+ return true;
93
+ });
94
+ }
@@ -0,0 +1,20 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, ShipmentGraphQL } from "@zauru-sdk/types";
3
+ /**
4
+ * getShipmentsByToAgencyLast100Id_booking
5
+ */
6
+ export declare function getShipmentsByToAgencyLast100Id_booking(session: Session, agency_to_id: string | number): Promise<AxiosUtilsResponse<ShipmentGraphQL[]>>;
7
+ /**
8
+ * receiveShipment_booking
9
+ * @param headers
10
+ * @param id
11
+ * @returns
12
+ */
13
+ export declare function receiveShipment_booking(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
14
+ /**
15
+ * deleteShipment_booking
16
+ * @param headers
17
+ * @param id
18
+ * @returns
19
+ */
20
+ export declare function deleteShipment_booking(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
@@ -0,0 +1,53 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
3
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
4
+ import { getShipmentsByToAgencyLast100StringQuery } from "@zauru-sdk/graphql";
5
+ import httpZauru from "./httpZauru.server.js";
6
+ /**
7
+ * getShipmentsByToAgencyLast100Id_booking
8
+ */
9
+ export async function getShipmentsByToAgencyLast100Id_booking(session, agency_to_id) {
10
+ return handlePossibleAxiosErrors(async () => {
11
+ const headers = await getGraphQLAPIHeaders(session);
12
+ const response = await httpGraphQLAPI.post("", {
13
+ query: getShipmentsByToAgencyLast100StringQuery,
14
+ variables: {
15
+ agency_to_id,
16
+ },
17
+ }, { headers });
18
+ if (response.data.errors) {
19
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
20
+ }
21
+ const registers = response?.data?.data?.shipments;
22
+ return registers;
23
+ });
24
+ }
25
+ /**
26
+ * receiveShipment_booking
27
+ * @param headers
28
+ * @param id
29
+ * @returns
30
+ */
31
+ export async function receiveShipment_booking(headers, id) {
32
+ return handlePossibleAxiosErrors(async () => {
33
+ const response = await httpZauru.get(`/inventories/bookings/${id}/deliver.json`, { headers });
34
+ if (!response.data) {
35
+ throw new Error("Sin respuesta de: /inventories/bookings/id/deliver.json");
36
+ }
37
+ return true;
38
+ });
39
+ }
40
+ /**
41
+ * deleteShipment_booking
42
+ * @param headers
43
+ * @param id
44
+ * @returns
45
+ */
46
+ export async function deleteShipment_booking(headers, id) {
47
+ return handlePossibleAxiosErrors(async () => {
48
+ await httpZauru.delete(`/inventories/bookings/${id}.json`, {
49
+ headers,
50
+ });
51
+ return true;
52
+ });
53
+ }
@@ -0,0 +1,30 @@
1
+ import { AxiosUtilsResponse, ItemWithPrices, SuggestedPriceGraphQL } from "@zauru-sdk/types";
2
+ import { Session } from "@remix-run/node";
3
+ /**
4
+ *
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export declare const getSuggestedPricesExportJSON: (headers: any) => Promise<AxiosUtilsResponse<ItemWithPrices[]>>;
9
+ /**
10
+ * getSuggestedPrices
11
+ * @param session
12
+ * @param id
13
+ */
14
+ export declare function getSuggestedPrices(session: Session, config: {
15
+ notNullPriceList?: boolean;
16
+ withItems?: boolean;
17
+ withItemCategories?: boolean;
18
+ }): Promise<AxiosUtilsResponse<SuggestedPriceGraphQL[]>>;
19
+ /**
20
+ * createSuggestedPrice
21
+ * @param headers
22
+ * @param body
23
+ */
24
+ export declare function createSuggestedPrice(headers: any, body: Partial<SuggestedPriceGraphQL>): Promise<AxiosUtilsResponse<SuggestedPriceGraphQL>>;
25
+ /**
26
+ * deleteSuggestedPrice
27
+ * @param headers
28
+ * @param body
29
+ */
30
+ export declare function deleteSuggestedPrice(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;