@zauru-sdk/services 1.0.49 → 1.0.52
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/cjs/common.js +235 -0
- package/dist/cjs/index.js +50 -0
- package/dist/cjs/sessions/sessions.js +18 -0
- package/dist/cjs/sessions/upstash.js +59 -0
- package/dist/cjs/zauru/httpGraphQL.js +42 -0
- package/dist/cjs/zauru/httpOauth.js +42 -0
- package/dist/cjs/zauru/httpZauru.js +42 -0
- package/dist/cjs/zauru/zauru-agencies.js +27 -0
- package/dist/cjs/zauru/zauru-automatic-numbers.js +28 -0
- package/dist/cjs/zauru/zauru-bookings.js +90 -0
- package/dist/cjs/zauru/zauru-bundles.js +104 -0
- package/dist/cjs/zauru/zauru-cases.js +30 -0
- package/dist/cjs/zauru/zauru-consolidated.js +81 -0
- package/dist/cjs/zauru/zauru-currencies.js +27 -0
- package/dist/cjs/zauru/zauru-deliveries.js +53 -0
- package/dist/cjs/zauru/zauru-discharges.js +55 -0
- package/dist/cjs/zauru/zauru-employees.js +30 -0
- package/dist/cjs/zauru/zauru-forms.js +363 -0
- package/dist/cjs/zauru/zauru-invoices.js +104 -0
- package/dist/cjs/zauru/zauru-items.js +293 -0
- package/dist/cjs/zauru/zauru-lote-record.js +33 -0
- package/dist/cjs/zauru/zauru-lotes.js +312 -0
- package/dist/cjs/zauru/zauru-motivos-rechazo.js +57 -0
- package/dist/cjs/zauru/zauru-payees.js +247 -0
- package/dist/cjs/zauru/zauru-payment-terms.js +75 -0
- package/dist/cjs/zauru/zauru-price-lists.js +49 -0
- package/dist/cjs/zauru/zauru-profiles.js +80 -0
- package/dist/cjs/zauru/zauru-purchase-orders.js +438 -0
- package/dist/cjs/zauru/zauru-receptions.js +104 -0
- package/dist/cjs/zauru/zauru-shipments.js +62 -0
- package/dist/cjs/zauru/zauru-suggested-prices.js +94 -0
- package/dist/cjs/zauru/zauru-tags.js +20 -0
- package/dist/cjs/zauru/zauru-templates.js +22 -0
- package/dist/cjs/zauru/zauru-variables.js +56 -0
- package/dist/cjs/zauru/zauru-web-app-tables.js +167 -0
- package/package.json +12 -9
- package/CHANGELOG.md +0 -232
- package/src/common.ts +0 -343
- package/src/index.ts +0 -37
- package/src/sessions/sessions.ts +0 -17
- package/src/sessions/upstash.ts +0 -55
- package/src/zauru/httpGraphQL.ts +0 -55
- package/src/zauru/httpOauth.ts +0 -55
- package/src/zauru/httpZauru.ts +0 -56
- package/src/zauru/zauru-agencies.ts +0 -32
- package/src/zauru/zauru-automatic-numbers.ts +0 -35
- package/src/zauru/zauru-bookings.ts +0 -134
- package/src/zauru/zauru-bundles.ts +0 -157
- package/src/zauru/zauru-cases.ts +0 -44
- package/src/zauru/zauru-consolidated.ts +0 -129
- package/src/zauru/zauru-currencies.ts +0 -39
- package/src/zauru/zauru-deliveries.ts +0 -70
- package/src/zauru/zauru-discharges.ts +0 -90
- package/src/zauru/zauru-employees.ts +0 -43
- package/src/zauru/zauru-forms.ts +0 -618
- package/src/zauru/zauru-invoices.ts +0 -142
- package/src/zauru/zauru-items.ts +0 -481
- package/src/zauru/zauru-lote-record.ts +0 -77
- package/src/zauru/zauru-lotes.ts +0 -484
- package/src/zauru/zauru-motivos-rechazo.ts +0 -121
- package/src/zauru/zauru-payees.ts +0 -402
- package/src/zauru/zauru-payment-terms.ts +0 -126
- package/src/zauru/zauru-price-lists.ts +0 -68
- package/src/zauru/zauru-profiles.ts +0 -106
- package/src/zauru/zauru-purchase-orders.ts +0 -701
- package/src/zauru/zauru-receptions.ts +0 -148
- package/src/zauru/zauru-shipments.ts +0 -88
- package/src/zauru/zauru-suggested-prices.ts +0 -137
- package/src/zauru/zauru-tags.ts +0 -22
- package/src/zauru/zauru-templates.ts +0 -24
- package/src/zauru/zauru-variables.ts +0 -67
- package/src/zauru/zauru-web-app-tables.ts +0 -256
- package/tsconfig.json +0 -24
- /package/dist/{common.js → esm/common.js} +0 -0
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{sessions → esm/sessions}/sessions.js +0 -0
- /package/dist/{sessions → esm/sessions}/upstash.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpGraphQL.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpOauth.js +0 -0
- /package/dist/{zauru → esm/zauru}/httpZauru.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-agencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-automatic-numbers.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bookings.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-bundles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-cases.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-consolidated.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-currencies.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-deliveries.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-discharges.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-employees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-forms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-invoices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-items.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lote-record.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-lotes.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-motivos-rechazo.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payees.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-payment-terms.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-price-lists.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-profiles.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-purchase-orders.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-receptions.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-shipments.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-suggested-prices.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-tags.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-templates.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-variables.js +0 -0
- /package/dist/{zauru → esm/zauru}/zauru-web-app-tables.js +0 -0
|
@@ -1,701 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import {
|
|
3
|
-
arrayToObject,
|
|
4
|
-
convertToFormData,
|
|
5
|
-
formatDateToUTC,
|
|
6
|
-
getBasketsSchema,
|
|
7
|
-
handlePossibleAxiosErrors,
|
|
8
|
-
reduceAdd,
|
|
9
|
-
} from "@zauru-sdk/common";
|
|
10
|
-
import {
|
|
11
|
-
AxiosUtilsResponse,
|
|
12
|
-
BasketSchema,
|
|
13
|
-
CreateNewPurchaseOrderBody,
|
|
14
|
-
DataTablesFilterBody,
|
|
15
|
-
HTMLPurchasesListSchema,
|
|
16
|
-
NewPurchaseOrderResponse,
|
|
17
|
-
PurchaseOrderGraphQL,
|
|
18
|
-
PurchasesListResponseSchema,
|
|
19
|
-
SelectFieldOption,
|
|
20
|
-
UpdatePurchaseOrderBody,
|
|
21
|
-
} from "@zauru-sdk/types";
|
|
22
|
-
import {
|
|
23
|
-
createNewLotPurchaseOrderReception,
|
|
24
|
-
createNewPurchaseOrderReception,
|
|
25
|
-
} from "./zauru-receptions.js";
|
|
26
|
-
import httpZauru from "./httpZauru.js";
|
|
27
|
-
import { getGraphQLAPIHeaders, getVariablesByName } from "../common.js";
|
|
28
|
-
import httpGraphQLAPI from "./httpGraphQL.js";
|
|
29
|
-
import {
|
|
30
|
-
getLast100ReceptionsStringQuery,
|
|
31
|
-
getPurchaseOrderByIdNumberStringQuery,
|
|
32
|
-
getPurchaseOrderStringQuery,
|
|
33
|
-
getPurchaseOrdersBetweenDatesStringQuery,
|
|
34
|
-
} from "@zauru-sdk/graphql";
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* markAsReceivePurchaseOrder
|
|
38
|
-
* 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
|
|
39
|
-
* si se quiere recibir parcialmente, utilizar el endpoint de /receptions
|
|
40
|
-
* @param headers
|
|
41
|
-
* @param body
|
|
42
|
-
* @returns
|
|
43
|
-
*/
|
|
44
|
-
export const markAsReceivePurchaseOrder = (
|
|
45
|
-
headers: any,
|
|
46
|
-
body: Partial<PurchaseOrderGraphQL> & { fechaVencimiento?: string }
|
|
47
|
-
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
48
|
-
return handlePossibleAxiosErrors(async () => {
|
|
49
|
-
const sendBody = { ...body };
|
|
50
|
-
|
|
51
|
-
if (sendBody.fechaVencimiento) {
|
|
52
|
-
await receiveLotPurchaseOrder(headers, sendBody as any);
|
|
53
|
-
} else {
|
|
54
|
-
await receivePurchaseOrder(headers, sendBody as any);
|
|
55
|
-
}
|
|
56
|
-
return true;
|
|
57
|
-
});
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* markAsReceivePartialPurchaseOrder
|
|
62
|
-
* @param headers
|
|
63
|
-
* @param body
|
|
64
|
-
* @returns
|
|
65
|
-
*/
|
|
66
|
-
export const markAsReceivePartialPurchaseOrder = (
|
|
67
|
-
headers: any,
|
|
68
|
-
session: Session,
|
|
69
|
-
body: Partial<PurchaseOrderGraphQL> & { fechaVencimiento?: string }
|
|
70
|
-
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
71
|
-
return handlePossibleAxiosErrors(async () => {
|
|
72
|
-
const sendBody = { ...body };
|
|
73
|
-
|
|
74
|
-
if (sendBody.fechaVencimiento) {
|
|
75
|
-
await createNewLotPurchaseOrderReception(
|
|
76
|
-
headers,
|
|
77
|
-
session,
|
|
78
|
-
sendBody as any
|
|
79
|
-
);
|
|
80
|
-
} else {
|
|
81
|
-
await createNewPurchaseOrderReception(headers, session, body);
|
|
82
|
-
}
|
|
83
|
-
return true;
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
* @param headers
|
|
90
|
-
* @param body
|
|
91
|
-
* @returns
|
|
92
|
-
*/
|
|
93
|
-
export const createNewPurchaseOrder = (
|
|
94
|
-
headers: any,
|
|
95
|
-
body: Partial<PurchaseOrderGraphQL>
|
|
96
|
-
): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL>> => {
|
|
97
|
-
return handlePossibleAxiosErrors(async () => {
|
|
98
|
-
let sendBody = {
|
|
99
|
-
...body,
|
|
100
|
-
purchase_order_details_attributes: arrayToObject(
|
|
101
|
-
body?.purchase_order_details
|
|
102
|
-
),
|
|
103
|
-
tag_ids: [
|
|
104
|
-
"",
|
|
105
|
-
...(body?.taggings?.map((x) => x.tag_id?.toString()) ?? []),
|
|
106
|
-
],
|
|
107
|
-
} as any;
|
|
108
|
-
|
|
109
|
-
delete headers["Content-type"];
|
|
110
|
-
delete sendBody.__rvfInternalFormId;
|
|
111
|
-
delete sendBody.taggings;
|
|
112
|
-
delete sendBody.purchase_order_details;
|
|
113
|
-
|
|
114
|
-
if (!(sendBody?.pdf instanceof File) || sendBody.pdf?.size <= 0) {
|
|
115
|
-
delete sendBody.pdf;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
sendBody = convertToFormData({
|
|
119
|
-
purchase_order: sendBody,
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
const response = await httpZauru.post<PurchaseOrderGraphQL>(
|
|
123
|
-
`/purchases/purchase_orders.json`,
|
|
124
|
-
sendBody,
|
|
125
|
-
{ headers }
|
|
126
|
-
);
|
|
127
|
-
|
|
128
|
-
return response.data;
|
|
129
|
-
});
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
*
|
|
134
|
-
* @param headers
|
|
135
|
-
* @param body
|
|
136
|
-
* @returns
|
|
137
|
-
*/
|
|
138
|
-
export const createNewAuthorizedPurchaseOrder = (
|
|
139
|
-
headers: any,
|
|
140
|
-
body: CreateNewPurchaseOrderBody,
|
|
141
|
-
withReceive: boolean = true
|
|
142
|
-
): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL>> => {
|
|
143
|
-
return handlePossibleAxiosErrors(async () => {
|
|
144
|
-
const sendBody = {
|
|
145
|
-
...body,
|
|
146
|
-
purchase_order_details_attributes: arrayToObject(
|
|
147
|
-
body?.purchase_order_details
|
|
148
|
-
),
|
|
149
|
-
} as any;
|
|
150
|
-
|
|
151
|
-
const response = await httpZauru.post<PurchaseOrderGraphQL>(
|
|
152
|
-
`/purchases/purchase_orders.json`,
|
|
153
|
-
{ purchase_order: sendBody },
|
|
154
|
-
{ headers }
|
|
155
|
-
);
|
|
156
|
-
|
|
157
|
-
await httpZauru.get<any>(
|
|
158
|
-
`/purchases/purchase_orders/${response.data.id}/authorize.json`,
|
|
159
|
-
{ headers }
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
if (withReceive) {
|
|
163
|
-
if (sendBody.fechaVencimiento) {
|
|
164
|
-
await receiveLotPurchaseOrder(headers, response.data as any);
|
|
165
|
-
} else {
|
|
166
|
-
await receivePurchaseOrder(headers, response.data);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
return response.data;
|
|
171
|
-
});
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* receiveLotPurchaseOrder
|
|
176
|
-
* @param headers
|
|
177
|
-
* @param body
|
|
178
|
-
* @returns
|
|
179
|
-
*/
|
|
180
|
-
export const receiveLotPurchaseOrder = (
|
|
181
|
-
headers: any,
|
|
182
|
-
body: PurchaseOrderGraphQL & { fechaVencimiento: string }
|
|
183
|
-
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
184
|
-
return handlePossibleAxiosErrors(async () => {
|
|
185
|
-
const sendBody = {
|
|
186
|
-
agency_id: body.agency_id,
|
|
187
|
-
delivery_date: body.issue_date,
|
|
188
|
-
id: body.id,
|
|
189
|
-
needs_transit: false,
|
|
190
|
-
purchase_order_details_attributes: arrayToObject(
|
|
191
|
-
body.purchase_order_details?.map((x: any) => {
|
|
192
|
-
const newDetail = {
|
|
193
|
-
id: x.id,
|
|
194
|
-
booked_quantity: x.booked_quantity,
|
|
195
|
-
item_id: x.item_id,
|
|
196
|
-
lot_delivered_quantity: [x.delivered_quantity],
|
|
197
|
-
lot_name: [body.id_number],
|
|
198
|
-
lot_expire: [body.fechaVencimiento],
|
|
199
|
-
} as any;
|
|
200
|
-
return newDetail;
|
|
201
|
-
})
|
|
202
|
-
),
|
|
203
|
-
};
|
|
204
|
-
await httpZauru.patch<any>(
|
|
205
|
-
`/purchases/purchase_orders/${body.id}/receive_action`,
|
|
206
|
-
{ purchase_order: sendBody },
|
|
207
|
-
{ headers }
|
|
208
|
-
);
|
|
209
|
-
return true;
|
|
210
|
-
});
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* receivePurchaseOrder
|
|
215
|
-
* @param headers
|
|
216
|
-
* @param body
|
|
217
|
-
* @returns
|
|
218
|
-
*/
|
|
219
|
-
export const receivePurchaseOrder = (
|
|
220
|
-
headers: any,
|
|
221
|
-
body: PurchaseOrderGraphQL
|
|
222
|
-
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
223
|
-
return handlePossibleAxiosErrors(async () => {
|
|
224
|
-
const sendBody = {
|
|
225
|
-
agency_id: body.agency_id,
|
|
226
|
-
delivery_date: body.issue_date,
|
|
227
|
-
id: body.id,
|
|
228
|
-
needs_transit: false,
|
|
229
|
-
purchase_order_details_attributes: arrayToObject(
|
|
230
|
-
body.purchase_order_details?.map((x: any) => {
|
|
231
|
-
const newDetail = {
|
|
232
|
-
id: x.id,
|
|
233
|
-
delivered_quantity: x.delivered_quantity,
|
|
234
|
-
booked_quantity: x.booked_quantity,
|
|
235
|
-
item_id: x.item_id,
|
|
236
|
-
} as any;
|
|
237
|
-
return newDetail;
|
|
238
|
-
})
|
|
239
|
-
),
|
|
240
|
-
};
|
|
241
|
-
await httpZauru.patch<any>(
|
|
242
|
-
`/purchases/purchase_orders/${body.id}/receive_action`,
|
|
243
|
-
{ purchase_order: sendBody },
|
|
244
|
-
{ headers }
|
|
245
|
-
);
|
|
246
|
-
return true;
|
|
247
|
-
});
|
|
248
|
-
};
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
*
|
|
252
|
-
* @param headers
|
|
253
|
-
* @returns
|
|
254
|
-
*/
|
|
255
|
-
export const getNewPurchaseOrderInfo = (
|
|
256
|
-
headers: any
|
|
257
|
-
): Promise<AxiosUtilsResponse<NewPurchaseOrderResponse>> => {
|
|
258
|
-
return handlePossibleAxiosErrors(async () => {
|
|
259
|
-
const response = await httpZauru.get<NewPurchaseOrderResponse>(
|
|
260
|
-
"/purchases/purchase_orders/new.json",
|
|
261
|
-
{ headers }
|
|
262
|
-
);
|
|
263
|
-
|
|
264
|
-
const purchasersList: SelectFieldOption[] = [];
|
|
265
|
-
response.data?.purchasers?.forEach((purchaser: any) => {
|
|
266
|
-
if (purchaser?.id) {
|
|
267
|
-
purchasersList.push({
|
|
268
|
-
value: purchaser?.id,
|
|
269
|
-
label: purchaser?.name,
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
return { ...response.data, purchasersList } as NewPurchaseOrderResponse;
|
|
275
|
-
});
|
|
276
|
-
};
|
|
277
|
-
|
|
278
|
-
/**
|
|
279
|
-
* getPurchasesListDataTables Function for get all zauru orden-compras
|
|
280
|
-
* @param headers
|
|
281
|
-
* @returns
|
|
282
|
-
*/
|
|
283
|
-
export const getPurchasesListDataTables = (
|
|
284
|
-
headers: any,
|
|
285
|
-
body: DataTablesFilterBody
|
|
286
|
-
): Promise<
|
|
287
|
-
AxiosUtilsResponse<PurchasesListResponseSchema<HTMLPurchasesListSchema>>
|
|
288
|
-
> => {
|
|
289
|
-
return handlePossibleAxiosErrors(async () => {
|
|
290
|
-
const response = await httpZauru.post<
|
|
291
|
-
PurchasesListResponseSchema<HTMLPurchasesListSchema>
|
|
292
|
-
>(`/purchases/purchase_orders/datatables.json`, body, { headers });
|
|
293
|
-
|
|
294
|
-
return response.data;
|
|
295
|
-
});
|
|
296
|
-
};
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* getPurchasesList Function for get all zauru orden-compras
|
|
300
|
-
* @param headers
|
|
301
|
-
* @param params
|
|
302
|
-
* @returns
|
|
303
|
-
*/
|
|
304
|
-
export const getPurchasesList = (
|
|
305
|
-
headers: any,
|
|
306
|
-
session: Session,
|
|
307
|
-
params: {
|
|
308
|
-
fechaInicio?: string;
|
|
309
|
-
fechaFin?: string;
|
|
310
|
-
item?: string | number;
|
|
311
|
-
payeeCategory?: string | number;
|
|
312
|
-
agency_id?: string | number;
|
|
313
|
-
} = {},
|
|
314
|
-
config?: { fromProduction?: boolean }
|
|
315
|
-
): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL[]>> => {
|
|
316
|
-
return handlePossibleAxiosErrors(async () => {
|
|
317
|
-
//Si quiere obtener los de producción, obtengo primero su agencia producción
|
|
318
|
-
if (config?.fromProduction) {
|
|
319
|
-
const { production_agency_id: temp_production_agency_id } =
|
|
320
|
-
await getVariablesByName(headers, session, ["production_agency_id"]);
|
|
321
|
-
const hashProductionAgencyId = JSON.parse(
|
|
322
|
-
temp_production_agency_id ?? "{}"
|
|
323
|
-
);
|
|
324
|
-
const production_agency_id =
|
|
325
|
-
hashProductionAgencyId[session.get("agency_id")];
|
|
326
|
-
params.agency_id = production_agency_id;
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
const response = await httpZauru.get<PurchaseOrderGraphQL[]>(
|
|
330
|
-
`/purchases/purchase_orders/export.json`,
|
|
331
|
-
{
|
|
332
|
-
headers,
|
|
333
|
-
params,
|
|
334
|
-
}
|
|
335
|
-
);
|
|
336
|
-
|
|
337
|
-
return response.data;
|
|
338
|
-
});
|
|
339
|
-
};
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* getPurchase Function for get an especific purchase order
|
|
343
|
-
* @param headers
|
|
344
|
-
* @returns
|
|
345
|
-
*/
|
|
346
|
-
export const getPurchase = (
|
|
347
|
-
headers: any,
|
|
348
|
-
purchase_order_id: number | string
|
|
349
|
-
): Promise<
|
|
350
|
-
AxiosUtilsResponse<
|
|
351
|
-
PurchaseOrderGraphQL & {
|
|
352
|
-
baskets_memo: BasketSchema[];
|
|
353
|
-
baskets_memo_quantity: number;
|
|
354
|
-
}
|
|
355
|
-
>
|
|
356
|
-
> => {
|
|
357
|
-
return handlePossibleAxiosErrors(async () => {
|
|
358
|
-
const response = await httpZauru<PurchaseOrderGraphQL>(
|
|
359
|
-
`/purchases/purchase_orders/${purchase_order_id}.json`,
|
|
360
|
-
{ method: "GET", headers }
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
const baskets_memo = getBasketsSchema(response.data.memo);
|
|
364
|
-
const baskets_memo_quantity = baskets_memo
|
|
365
|
-
.map((basket) => basket.total)
|
|
366
|
-
.reduce(reduceAdd, 0);
|
|
367
|
-
|
|
368
|
-
return {
|
|
369
|
-
...response.data,
|
|
370
|
-
baskets_memo,
|
|
371
|
-
baskets_memo_quantity,
|
|
372
|
-
};
|
|
373
|
-
});
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* enablePurchase Enable a purchase order
|
|
378
|
-
* @param headers
|
|
379
|
-
* @param purchase_order_id
|
|
380
|
-
* @param reception_id
|
|
381
|
-
* @returns
|
|
382
|
-
*/
|
|
383
|
-
export const enablePurchase = (
|
|
384
|
-
headers: any,
|
|
385
|
-
purchase_order_id: number,
|
|
386
|
-
reception_id: number
|
|
387
|
-
): Promise<AxiosUtilsResponse<any>> => {
|
|
388
|
-
return handlePossibleAxiosErrors(async () => {
|
|
389
|
-
const response = await httpZauru.get<any>(
|
|
390
|
-
`/purchases/receptions/${reception_id}/rebound.json?purchase_order_id=${purchase_order_id}`,
|
|
391
|
-
{ headers }
|
|
392
|
-
);
|
|
393
|
-
|
|
394
|
-
return response.data;
|
|
395
|
-
});
|
|
396
|
-
};
|
|
397
|
-
|
|
398
|
-
/**
|
|
399
|
-
* updatePurchaseOrder
|
|
400
|
-
* @param headers
|
|
401
|
-
* @param body
|
|
402
|
-
* @param purchase_order_id
|
|
403
|
-
* @returns
|
|
404
|
-
*/
|
|
405
|
-
export const updatePurchaseOrder = (
|
|
406
|
-
headers: any,
|
|
407
|
-
body: UpdatePurchaseOrderBody,
|
|
408
|
-
purchase_order_id: number
|
|
409
|
-
): Promise<AxiosUtilsResponse<any>> => {
|
|
410
|
-
return handlePossibleAxiosErrors(async () => {
|
|
411
|
-
const response = await httpZauru.patch<any>(
|
|
412
|
-
`/purchases/purchase_orders/${purchase_order_id}.json`,
|
|
413
|
-
body,
|
|
414
|
-
{ headers }
|
|
415
|
-
);
|
|
416
|
-
|
|
417
|
-
return response.data;
|
|
418
|
-
});
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
/**
|
|
422
|
-
* updatePurchaseOrder
|
|
423
|
-
* @param headers
|
|
424
|
-
* @param body
|
|
425
|
-
* @param purchase_order_id
|
|
426
|
-
* @returns
|
|
427
|
-
*/
|
|
428
|
-
export const updateReceivedPurchaseOrder = (
|
|
429
|
-
headers: any,
|
|
430
|
-
body: UpdatePurchaseOrderBody,
|
|
431
|
-
purchase_order_id: number
|
|
432
|
-
): Promise<AxiosUtilsResponse<any>> => {
|
|
433
|
-
return handlePossibleAxiosErrors(async () => {
|
|
434
|
-
const response = await httpZauru.patch<any>(
|
|
435
|
-
`/purchases/purchase_orders/${purchase_order_id}/update_received.json`,
|
|
436
|
-
body,
|
|
437
|
-
{ headers }
|
|
438
|
-
);
|
|
439
|
-
|
|
440
|
-
return response.data;
|
|
441
|
-
});
|
|
442
|
-
};
|
|
443
|
-
|
|
444
|
-
/**
|
|
445
|
-
* getLast100Receptions
|
|
446
|
-
* @param headers
|
|
447
|
-
* @returns
|
|
448
|
-
*/
|
|
449
|
-
export const getLast100Receptions = (
|
|
450
|
-
session: Session,
|
|
451
|
-
agency_id?: number | string
|
|
452
|
-
): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL[]>> => {
|
|
453
|
-
return handlePossibleAxiosErrors(async () => {
|
|
454
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
455
|
-
|
|
456
|
-
const response = await httpGraphQLAPI.post<{
|
|
457
|
-
data: { purchase_orders: PurchaseOrderGraphQL[] };
|
|
458
|
-
errors?: {
|
|
459
|
-
message: string;
|
|
460
|
-
extensions: { path: string; code: string };
|
|
461
|
-
}[];
|
|
462
|
-
}>(
|
|
463
|
-
"",
|
|
464
|
-
{
|
|
465
|
-
query: getLast100ReceptionsStringQuery,
|
|
466
|
-
variables: {
|
|
467
|
-
agencyId: agency_id ?? session.get("agency_id"),
|
|
468
|
-
},
|
|
469
|
-
},
|
|
470
|
-
{ headers }
|
|
471
|
-
);
|
|
472
|
-
|
|
473
|
-
if (response.data.errors) {
|
|
474
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
return response.data?.data?.purchase_orders;
|
|
478
|
-
});
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
/**
|
|
482
|
-
* getPurchaseOrder
|
|
483
|
-
* @param headers
|
|
484
|
-
* @returns
|
|
485
|
-
*/
|
|
486
|
-
export const getPurchaseOrder = (
|
|
487
|
-
session: Session,
|
|
488
|
-
poId: string | number,
|
|
489
|
-
config: { withLotStocksToMyAgency: boolean } = {
|
|
490
|
-
withLotStocksToMyAgency: false,
|
|
491
|
-
}
|
|
492
|
-
): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL>> => {
|
|
493
|
-
return handlePossibleAxiosErrors(async () => {
|
|
494
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
495
|
-
|
|
496
|
-
const response = await httpGraphQLAPI.post<{
|
|
497
|
-
data: { purchase_orders: PurchaseOrderGraphQL[] };
|
|
498
|
-
errors?: {
|
|
499
|
-
message: string;
|
|
500
|
-
extensions: { path: string; code: string };
|
|
501
|
-
}[];
|
|
502
|
-
}>(
|
|
503
|
-
"",
|
|
504
|
-
{
|
|
505
|
-
query: getPurchaseOrderStringQuery({
|
|
506
|
-
withLotStocks: config.withLotStocksToMyAgency,
|
|
507
|
-
}),
|
|
508
|
-
variables: {
|
|
509
|
-
id: poId,
|
|
510
|
-
},
|
|
511
|
-
},
|
|
512
|
-
{ headers }
|
|
513
|
-
);
|
|
514
|
-
|
|
515
|
-
if (response.data.errors) {
|
|
516
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
517
|
-
}
|
|
518
|
-
|
|
519
|
-
const tempResponse = response.data?.data?.purchase_orders[0];
|
|
520
|
-
|
|
521
|
-
if (config.withLotStocksToMyAgency) {
|
|
522
|
-
tempResponse.lots[0].lot_stocks = tempResponse.lots[0].lot_stocks.filter(
|
|
523
|
-
(x) => x.agency_id === Number(session.get("agency_id"))
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
|
|
527
|
-
return tempResponse;
|
|
528
|
-
});
|
|
529
|
-
};
|
|
530
|
-
|
|
531
|
-
/**
|
|
532
|
-
* getPurchaseOrder
|
|
533
|
-
* @param headers
|
|
534
|
-
* @returns
|
|
535
|
-
*/
|
|
536
|
-
export const getGraphQLPurchaseOrderBetweenDates = (
|
|
537
|
-
session: Session,
|
|
538
|
-
dates: {
|
|
539
|
-
startDate: string;
|
|
540
|
-
endDate: string;
|
|
541
|
-
},
|
|
542
|
-
config: {
|
|
543
|
-
agencyFilter: boolean;
|
|
544
|
-
agencyId?: number;
|
|
545
|
-
useProductionAgencyId?: boolean;
|
|
546
|
-
consolidateIdFilter?: boolean;
|
|
547
|
-
lotItemIdExclusion?: number;
|
|
548
|
-
poDetailTagId?: number;
|
|
549
|
-
withShipmentToMyAgency?: boolean;
|
|
550
|
-
withLotStocksToMyAgency?: boolean;
|
|
551
|
-
itemId?: number | string;
|
|
552
|
-
payeeCategoryId?: number | string;
|
|
553
|
-
} = {
|
|
554
|
-
agencyFilter: true,
|
|
555
|
-
consolidateIdFilter: false,
|
|
556
|
-
useProductionAgencyId: false,
|
|
557
|
-
withShipmentToMyAgency: false,
|
|
558
|
-
withLotStocksToMyAgency: false,
|
|
559
|
-
}
|
|
560
|
-
): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL[]>> => {
|
|
561
|
-
return handlePossibleAxiosErrors(async () => {
|
|
562
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
563
|
-
|
|
564
|
-
let agency_id = config.agencyId;
|
|
565
|
-
|
|
566
|
-
if (config.useProductionAgencyId) {
|
|
567
|
-
const { production_agency_id /**{5693: 5696} */ } =
|
|
568
|
-
await getVariablesByName(headers, session, ["production_agency_id"]);
|
|
569
|
-
const hashAgencyId = JSON.parse(production_agency_id ?? "{}");
|
|
570
|
-
agency_id = hashAgencyId[session.get("agency_id")];
|
|
571
|
-
}
|
|
572
|
-
|
|
573
|
-
const query = getPurchaseOrdersBetweenDatesStringQuery({
|
|
574
|
-
agencyFilter: config.agencyFilter,
|
|
575
|
-
consolidateIdFilter: config.consolidateIdFilter,
|
|
576
|
-
lotItemIdExclusion: config.lotItemIdExclusion,
|
|
577
|
-
poDetailTagId: config.poDetailTagId,
|
|
578
|
-
withLotStocks: config.withLotStocksToMyAgency,
|
|
579
|
-
//itemId: config.itemId,
|
|
580
|
-
//payeeCategoryId: config.payeeCategoryId,
|
|
581
|
-
});
|
|
582
|
-
|
|
583
|
-
const variables = {
|
|
584
|
-
...(config.agencyFilter
|
|
585
|
-
? { agencyId: agency_id ?? session.get("agency_id") }
|
|
586
|
-
: {}),
|
|
587
|
-
...(config.lotItemIdExclusion
|
|
588
|
-
? { lotItemIdExclusion: config.lotItemIdExclusion }
|
|
589
|
-
: {}),
|
|
590
|
-
...(config.poDetailTagId ? { poDetailTagId: config.poDetailTagId } : {}),
|
|
591
|
-
startDate: formatDateToUTC(dates.startDate),
|
|
592
|
-
endDate: formatDateToUTC(dates.endDate),
|
|
593
|
-
};
|
|
594
|
-
|
|
595
|
-
const response = await httpGraphQLAPI.post<{
|
|
596
|
-
data: { purchase_orders: PurchaseOrderGraphQL[] };
|
|
597
|
-
errors?: {
|
|
598
|
-
message: string;
|
|
599
|
-
extensions: { path: string; code: string };
|
|
600
|
-
}[];
|
|
601
|
-
}>(
|
|
602
|
-
"",
|
|
603
|
-
{
|
|
604
|
-
query,
|
|
605
|
-
variables,
|
|
606
|
-
},
|
|
607
|
-
{ headers }
|
|
608
|
-
);
|
|
609
|
-
|
|
610
|
-
if (response.data.errors) {
|
|
611
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
//============ Aplicación de filtros
|
|
615
|
-
let responseData: PurchaseOrderGraphQL[] = [];
|
|
616
|
-
|
|
617
|
-
if (config.withShipmentToMyAgency) {
|
|
618
|
-
responseData = response.data?.data?.purchase_orders.filter((x) =>
|
|
619
|
-
x.shipment_purchase_orders.some(
|
|
620
|
-
(y) => y.shipment.agency_to_id?.toString() == session.get("agency_id")
|
|
621
|
-
)
|
|
622
|
-
);
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
if (config.withLotStocksToMyAgency) {
|
|
626
|
-
responseData = responseData.map((x) => {
|
|
627
|
-
x.lots = x.lots.map((y) => {
|
|
628
|
-
y.lot_stocks = y.lot_stocks.filter(
|
|
629
|
-
(z) => z.agency_id == session.get("agency_id")
|
|
630
|
-
);
|
|
631
|
-
return y;
|
|
632
|
-
});
|
|
633
|
-
return x;
|
|
634
|
-
});
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
return responseData;
|
|
638
|
-
});
|
|
639
|
-
};
|
|
640
|
-
|
|
641
|
-
/**
|
|
642
|
-
* deletePurchaseOrder
|
|
643
|
-
* @param headers
|
|
644
|
-
* @param id
|
|
645
|
-
* @returns
|
|
646
|
-
*/
|
|
647
|
-
export const deletePurchaseOrder = (
|
|
648
|
-
headers: any,
|
|
649
|
-
id: string | number
|
|
650
|
-
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
651
|
-
return handlePossibleAxiosErrors(async () => {
|
|
652
|
-
await httpZauru.delete(
|
|
653
|
-
`/purchases/purchase_orders/${id}.json?destroy=true`,
|
|
654
|
-
{ headers }
|
|
655
|
-
);
|
|
656
|
-
|
|
657
|
-
return true;
|
|
658
|
-
});
|
|
659
|
-
};
|
|
660
|
-
|
|
661
|
-
/**
|
|
662
|
-
* getPurchaseOrderByIdNumber
|
|
663
|
-
* @param session
|
|
664
|
-
* @param idNumber
|
|
665
|
-
* @returns
|
|
666
|
-
*/
|
|
667
|
-
export const getPurchasesOrderByIdNumber = (
|
|
668
|
-
session: Session,
|
|
669
|
-
id_number: string
|
|
670
|
-
): Promise<AxiosUtilsResponse<PurchaseOrderGraphQL[]>> => {
|
|
671
|
-
return handlePossibleAxiosErrors(async () => {
|
|
672
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
673
|
-
|
|
674
|
-
const response = await httpGraphQLAPI.post<{
|
|
675
|
-
data: { purchase_orders: PurchaseOrderGraphQL[] };
|
|
676
|
-
errors?: {
|
|
677
|
-
message: string;
|
|
678
|
-
extensions: { path: string; code: string };
|
|
679
|
-
}[];
|
|
680
|
-
}>(
|
|
681
|
-
"",
|
|
682
|
-
{
|
|
683
|
-
query: getPurchaseOrderByIdNumberStringQuery,
|
|
684
|
-
variables: {
|
|
685
|
-
id_number,
|
|
686
|
-
},
|
|
687
|
-
},
|
|
688
|
-
{ headers }
|
|
689
|
-
);
|
|
690
|
-
|
|
691
|
-
if (response.data.errors) {
|
|
692
|
-
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
if (!response?.data?.data.purchase_orders) {
|
|
696
|
-
return [];
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
return response.data?.data?.purchase_orders;
|
|
700
|
-
});
|
|
701
|
-
};
|