@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
package/src/zauru/zauru-lotes.ts
DELETED
|
@@ -1,484 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import {
|
|
3
|
-
getBasketsSchema,
|
|
4
|
-
handlePossibleAxiosErrors,
|
|
5
|
-
reduceAdd,
|
|
6
|
-
truncateDecimals,
|
|
7
|
-
} from "@zauru-sdk/common";
|
|
8
|
-
import {
|
|
9
|
-
AxiosUtilsResponse,
|
|
10
|
-
ItemAssociatedLots,
|
|
11
|
-
LotGraphQL,
|
|
12
|
-
LotStockGraphQL,
|
|
13
|
-
LoteDescription,
|
|
14
|
-
LoteProcesadoSchema,
|
|
15
|
-
LoteSchema,
|
|
16
|
-
LoteWithPurchaseFormatedSchema,
|
|
17
|
-
ObjectKeyString,
|
|
18
|
-
PoBasketType,
|
|
19
|
-
PurchasesDataTableListFormatedSchema,
|
|
20
|
-
UpdateLoteBody,
|
|
21
|
-
} from "@zauru-sdk/types";
|
|
22
|
-
import moment from "moment";
|
|
23
|
-
import { getGraphQLAPIHeaders, getVariablesByName } from "../common.js";
|
|
24
|
-
import httpZauru from "./httpZauru.js";
|
|
25
|
-
import { createLoteRecord } from "./zauru-lote-record.js";
|
|
26
|
-
import httpGraphQLAPI from "./httpGraphQL.js";
|
|
27
|
-
import {
|
|
28
|
-
getLotStocksByAgencyIdStringQuery,
|
|
29
|
-
getLotsByNameStringQuery,
|
|
30
|
-
} from "@zauru-sdk/graphql";
|
|
31
|
-
import { getDeliveriesDataTables } from "./zauru-deliveries.js";
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* getBasketsLots
|
|
35
|
-
* @param headers
|
|
36
|
-
* @param session
|
|
37
|
-
* @returns
|
|
38
|
-
*/
|
|
39
|
-
export const getBasketsLots = async (
|
|
40
|
-
headers: any,
|
|
41
|
-
session: Session
|
|
42
|
-
): Promise<AxiosUtilsResponse<ItemAssociatedLots>> => {
|
|
43
|
-
return handlePossibleAxiosErrors(async () => {
|
|
44
|
-
const { recepciones_basket_item_id } = await getVariablesByName(
|
|
45
|
-
headers,
|
|
46
|
-
session,
|
|
47
|
-
["recepciones_basket_item_id"]
|
|
48
|
-
);
|
|
49
|
-
|
|
50
|
-
const basketLotsResponse = await httpZauru.get<ItemAssociatedLots>(
|
|
51
|
-
`/inventories/lots/${recepciones_basket_item_id}/item`,
|
|
52
|
-
{ headers }
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
const poBasket: PoBasketType = {};
|
|
56
|
-
basketLotsResponse?.data?.lots.map(
|
|
57
|
-
(basket: any) =>
|
|
58
|
-
(poBasket[basket.name] = {
|
|
59
|
-
lot_id: basket.id,
|
|
60
|
-
rBaskets: 0,
|
|
61
|
-
qcBaskets: 0,
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
return {
|
|
66
|
-
...basketLotsResponse.data,
|
|
67
|
-
recepciones_basket_item_id: Number(recepciones_basket_item_id),
|
|
68
|
-
poBasket,
|
|
69
|
-
} as ItemAssociatedLots;
|
|
70
|
-
});
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
//LIBERAR/RETENER LOTES
|
|
74
|
-
/**
|
|
75
|
-
*
|
|
76
|
-
* @param headers
|
|
77
|
-
* @param lot_id
|
|
78
|
-
* @param lot_name
|
|
79
|
-
* @returns
|
|
80
|
-
*/
|
|
81
|
-
export const retenerLote = async (
|
|
82
|
-
headers: any,
|
|
83
|
-
session: Session,
|
|
84
|
-
lot_id: string,
|
|
85
|
-
lot_name: string
|
|
86
|
-
) => {
|
|
87
|
-
await httpZauru.patch(
|
|
88
|
-
`/inventories/lots/${lot_id}.json`,
|
|
89
|
-
{ lot: { name: `${lot_name}-RETENIDO` } },
|
|
90
|
-
{ headers }
|
|
91
|
-
);
|
|
92
|
-
|
|
93
|
-
return await createLoteRecord(headers, session, {
|
|
94
|
-
agency_id: session.get("agency_id"),
|
|
95
|
-
created_at: moment().toISOString(),
|
|
96
|
-
employee_id: session.get("employee_id"),
|
|
97
|
-
employee_name: session.get("name"),
|
|
98
|
-
lote_id: lot_id,
|
|
99
|
-
lote_name: lot_name,
|
|
100
|
-
retenido: 1,
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
*
|
|
106
|
-
* @param headers
|
|
107
|
-
* @param lot_id
|
|
108
|
-
* @param lot_name
|
|
109
|
-
* @returns
|
|
110
|
-
*/
|
|
111
|
-
export const liberarLote = async (
|
|
112
|
-
headers: any,
|
|
113
|
-
session: Session,
|
|
114
|
-
lot_id: string,
|
|
115
|
-
lot_name: string
|
|
116
|
-
) => {
|
|
117
|
-
await httpZauru.patch(
|
|
118
|
-
`/inventories/lots/${lot_id}.json`,
|
|
119
|
-
{ lot: { name: `${lot_name.split("-")[0]}` } },
|
|
120
|
-
{ headers }
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
return await createLoteRecord(headers, session, {
|
|
124
|
-
agency_id: session.get("agency_id"),
|
|
125
|
-
created_at: moment().toISOString(),
|
|
126
|
-
employee_id: session.get("employee_id"),
|
|
127
|
-
employee_name: session.get("name"),
|
|
128
|
-
lote_id: lot_id,
|
|
129
|
-
lote_name: lot_name,
|
|
130
|
-
retenido: 0,
|
|
131
|
-
});
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* getLote Function for get all details of the current lote
|
|
136
|
-
* @param headers
|
|
137
|
-
* @param agency_id
|
|
138
|
-
* @returns
|
|
139
|
-
*/
|
|
140
|
-
export async function getLote(
|
|
141
|
-
headers: any,
|
|
142
|
-
lot_id: number | string,
|
|
143
|
-
agency_id?: string
|
|
144
|
-
): Promise<LoteDescription> {
|
|
145
|
-
const response = await httpZauru.get<LoteDescription>(
|
|
146
|
-
`/inventories/lots/${lot_id}.json`,
|
|
147
|
-
{
|
|
148
|
-
headers,
|
|
149
|
-
}
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
//Paso de 23-1234-VERDE, 34-34242-AZUL => a un objeto completo de canastas
|
|
153
|
-
const baskets = getBasketsSchema(response.data.description);
|
|
154
|
-
response.data.description_baskets = baskets;
|
|
155
|
-
|
|
156
|
-
//Calculo el total de canastas, la suma de todas
|
|
157
|
-
response.data.baskets_quantity = baskets
|
|
158
|
-
.map((x) => x.total)
|
|
159
|
-
.reduce(reduceAdd, 0);
|
|
160
|
-
|
|
161
|
-
if (agency_id) {
|
|
162
|
-
//Saco el available actual
|
|
163
|
-
response.data.stock_actual = response.data.stocks[
|
|
164
|
-
agency_id
|
|
165
|
-
] as LotStockGraphQL;
|
|
166
|
-
//El available by basket
|
|
167
|
-
response.data.availableByBaskets =
|
|
168
|
-
Number(response.data.stock_actual.available) /
|
|
169
|
-
response.data.baskets_quantity;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return response.data;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
/**
|
|
176
|
-
* getLoteByName
|
|
177
|
-
* @param headers
|
|
178
|
-
* @param lot_name
|
|
179
|
-
* @returns
|
|
180
|
-
*/
|
|
181
|
-
export async function getLoteByName(
|
|
182
|
-
session: Session,
|
|
183
|
-
lot_name: string
|
|
184
|
-
): Promise<AxiosUtilsResponse<LotGraphQL>> {
|
|
185
|
-
return handlePossibleAxiosErrors(async () => {
|
|
186
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
187
|
-
|
|
188
|
-
const response = await httpGraphQLAPI.post<{
|
|
189
|
-
data: { lots: LotGraphQL[] };
|
|
190
|
-
errors?: {
|
|
191
|
-
message: string;
|
|
192
|
-
extensions: { path: string; code: string };
|
|
193
|
-
}[];
|
|
194
|
-
}>(
|
|
195
|
-
"",
|
|
196
|
-
{
|
|
197
|
-
query: getLotsByNameStringQuery,
|
|
198
|
-
variables: {
|
|
199
|
-
name: lot_name,
|
|
200
|
-
entity_id: session.get("selectedEntity"),
|
|
201
|
-
},
|
|
202
|
-
},
|
|
203
|
-
{ headers }
|
|
204
|
-
);
|
|
205
|
-
|
|
206
|
-
if (response.data.errors) {
|
|
207
|
-
throw new Error(
|
|
208
|
-
`Ocurrió un error al obtener el lote por nombre: ${response.data.errors
|
|
209
|
-
.map((x) => x.message)
|
|
210
|
-
.join(";")}`
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
if (response?.data?.data.lots?.length <= 0) {
|
|
215
|
-
throw new Error(
|
|
216
|
-
`No se encontró ningún resultado para el name del lote enviado: ${lot_name}`
|
|
217
|
-
);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const registerFound = response.data?.data?.lots[0];
|
|
221
|
-
|
|
222
|
-
return registerFound;
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* getMyAgencyLotStocks
|
|
228
|
-
* @param session
|
|
229
|
-
* @returns
|
|
230
|
-
*/
|
|
231
|
-
export async function getMyAgencyLotStocks(
|
|
232
|
-
session: Session
|
|
233
|
-
): Promise<AxiosUtilsResponse<LotStockGraphQL[]>> {
|
|
234
|
-
return handlePossibleAxiosErrors(async () => {
|
|
235
|
-
const headers = await getGraphQLAPIHeaders(session);
|
|
236
|
-
|
|
237
|
-
const response = await httpGraphQLAPI.post<{
|
|
238
|
-
data: { lot_stocks: LotStockGraphQL[] };
|
|
239
|
-
errors?: {
|
|
240
|
-
message: string;
|
|
241
|
-
extensions: { path: string; code: string };
|
|
242
|
-
}[];
|
|
243
|
-
}>(
|
|
244
|
-
"",
|
|
245
|
-
{
|
|
246
|
-
query: getLotStocksByAgencyIdStringQuery,
|
|
247
|
-
variables: {
|
|
248
|
-
agency_id: session.get("agency_id"),
|
|
249
|
-
},
|
|
250
|
-
},
|
|
251
|
-
{ headers }
|
|
252
|
-
);
|
|
253
|
-
|
|
254
|
-
if (response.data.errors) {
|
|
255
|
-
throw new Error(
|
|
256
|
-
`Ocurrió un error al obtener el stock de lotes por agencia: ${response.data.errors
|
|
257
|
-
.map((x) => x.message)
|
|
258
|
-
.join(";")}`
|
|
259
|
-
);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (response?.data?.data.lot_stocks?.length <= 0) {
|
|
263
|
-
throw new Error(
|
|
264
|
-
`No se encontró ningún resultado para el stock de lotes por agencia: ${session.get(
|
|
265
|
-
"agency_id"
|
|
266
|
-
)}`
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
const registerFound = response.data?.data?.lot_stocks;
|
|
271
|
-
|
|
272
|
-
return registerFound;
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
/**
|
|
277
|
-
* getLote Function for get all details of the current lote
|
|
278
|
-
* @param headers
|
|
279
|
-
* @param agency_id
|
|
280
|
-
* @returns
|
|
281
|
-
*/
|
|
282
|
-
export async function updateLote(
|
|
283
|
-
headers: any,
|
|
284
|
-
lot_id: number,
|
|
285
|
-
updatedData: UpdateLoteBody
|
|
286
|
-
): Promise<any> {
|
|
287
|
-
const response = await httpZauru.patch<any>(
|
|
288
|
-
`/inventories/lots/${lot_id}.json`,
|
|
289
|
-
updatedData,
|
|
290
|
-
{
|
|
291
|
-
headers,
|
|
292
|
-
}
|
|
293
|
-
);
|
|
294
|
-
|
|
295
|
-
return response.data;
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
/**
|
|
299
|
-
* getLotesExportJSON Function for get all zauru lotes by id_agencia
|
|
300
|
-
* @param headers
|
|
301
|
-
* @param agency_id
|
|
302
|
-
* @returns
|
|
303
|
-
*/
|
|
304
|
-
export async function getLotesExportJSON(
|
|
305
|
-
headers: any,
|
|
306
|
-
agency_id: string,
|
|
307
|
-
desde?: string,
|
|
308
|
-
hasta?: string
|
|
309
|
-
): Promise<LoteSchema[]> {
|
|
310
|
-
const response = await httpZauru.get<LoteSchema[]>(
|
|
311
|
-
`/inventories/lots/lots_export.json`,
|
|
312
|
-
{
|
|
313
|
-
headers,
|
|
314
|
-
params: {
|
|
315
|
-
warehouse: agency_id,
|
|
316
|
-
//Desde: desde,
|
|
317
|
-
//Hasta: hasta,
|
|
318
|
-
},
|
|
319
|
-
}
|
|
320
|
-
);
|
|
321
|
-
|
|
322
|
-
return response.data;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
/**
|
|
326
|
-
*
|
|
327
|
-
* @param headers
|
|
328
|
-
* @param agency_id
|
|
329
|
-
* @param baskets
|
|
330
|
-
* @param basket_id
|
|
331
|
-
* @returns
|
|
332
|
-
*/
|
|
333
|
-
export async function getLotesFiltered(
|
|
334
|
-
headers: any,
|
|
335
|
-
agency_id: string,
|
|
336
|
-
baskets?: boolean,
|
|
337
|
-
basket_id?: number
|
|
338
|
-
) {
|
|
339
|
-
let lotes = await getLotesExportJSON(headers, agency_id);
|
|
340
|
-
|
|
341
|
-
if (!baskets && basket_id) {
|
|
342
|
-
//quito los que son de tipo canasta
|
|
343
|
-
lotes = lotes.filter((lot: LoteSchema) => lot.lot?.item_id !== basket_id);
|
|
344
|
-
} else if (baskets && basket_id) {
|
|
345
|
-
//jalo sólo los que son de tipo canasta
|
|
346
|
-
lotes = lotes.filter((lot: LoteSchema) => lot.lot?.item_id === basket_id);
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
lotes = lotes.map((lot: LoteSchema) => {
|
|
350
|
-
const baskets = getBasketsSchema(lot.lot.description);
|
|
351
|
-
const baskets_quantity = baskets.map((x) => x.total).reduce(reduceAdd, 0);
|
|
352
|
-
const availableByBasket = truncateDecimals(
|
|
353
|
-
Number(lot.available) / baskets_quantity,
|
|
354
|
-
2
|
|
355
|
-
);
|
|
356
|
-
|
|
357
|
-
return {
|
|
358
|
-
...lot,
|
|
359
|
-
baskets,
|
|
360
|
-
availableByBasket,
|
|
361
|
-
baskets_quantity,
|
|
362
|
-
} as LoteSchema;
|
|
363
|
-
});
|
|
364
|
-
|
|
365
|
-
return lotes;
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
/**
|
|
369
|
-
*
|
|
370
|
-
* @param headers
|
|
371
|
-
* @param agency_id
|
|
372
|
-
* @param basket_id
|
|
373
|
-
* @param orders
|
|
374
|
-
* @param desde
|
|
375
|
-
* @param hasta
|
|
376
|
-
* @returns
|
|
377
|
-
*/
|
|
378
|
-
export async function getLotesWithPurchaseFormated(
|
|
379
|
-
headers: any,
|
|
380
|
-
agency_id: string,
|
|
381
|
-
basket_id: number,
|
|
382
|
-
orders: ObjectKeyString<PurchasesDataTableListFormatedSchema>,
|
|
383
|
-
desde?: string,
|
|
384
|
-
hasta?: string
|
|
385
|
-
): Promise<AxiosUtilsResponse<LoteWithPurchaseFormatedSchema[]>> {
|
|
386
|
-
return handlePossibleAxiosErrors(async () => {
|
|
387
|
-
const TODAY = new Date().getTime();
|
|
388
|
-
|
|
389
|
-
const lotes = (await getLotesExportJSON(headers, agency_id, desde, hasta))
|
|
390
|
-
//quito los que son de tipo canasta
|
|
391
|
-
.filter((lot: LoteSchema) => lot.lot?.item_id !== basket_id)
|
|
392
|
-
//filtro sólo los de las ordenes que vienen
|
|
393
|
-
.filter((lot: LoteSchema) => Object.keys(orders).includes(lot.lot.name))
|
|
394
|
-
.map((lot: LoteSchema) => {
|
|
395
|
-
return {
|
|
396
|
-
...orders[lot.lot.name],
|
|
397
|
-
id_lote: lot.lot?.id,
|
|
398
|
-
name_lote: lot.lot?.name,
|
|
399
|
-
item: lot.lot?.item?.name,
|
|
400
|
-
created_at: lot.lot?.created_at,
|
|
401
|
-
weight: lot.available,
|
|
402
|
-
baskets:
|
|
403
|
-
lot?.lot?.description !== null && lot?.lot?.description?.length > 0
|
|
404
|
-
? lot.lot?.description
|
|
405
|
-
.split(",")
|
|
406
|
-
.map((basket: any) => parseInt(basket.split("-")[0]))
|
|
407
|
-
.reduce((sum: number, qty: number) => sum + qty)
|
|
408
|
-
: 0,
|
|
409
|
-
editable:
|
|
410
|
-
Math.floor(
|
|
411
|
-
(TODAY - new Date(lot.lot?.created_at).getTime()) /
|
|
412
|
-
(1000 * 3600 * 24)
|
|
413
|
-
) < 1,
|
|
414
|
-
} as LoteWithPurchaseFormatedSchema;
|
|
415
|
-
})
|
|
416
|
-
.sort(
|
|
417
|
-
(
|
|
418
|
-
a: LoteWithPurchaseFormatedSchema,
|
|
419
|
-
b: LoteWithPurchaseFormatedSchema
|
|
420
|
-
) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime()
|
|
421
|
-
);
|
|
422
|
-
|
|
423
|
-
return lotes;
|
|
424
|
-
});
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
export async function getLotesProcesados(
|
|
428
|
-
headers: any,
|
|
429
|
-
agency_id: string
|
|
430
|
-
): Promise<LoteProcesadoSchema[]> {
|
|
431
|
-
const deliveries = await getDeliveriesDataTables(headers, {
|
|
432
|
-
length: 0,
|
|
433
|
-
order: {
|
|
434
|
-
"0": {
|
|
435
|
-
column: "0",
|
|
436
|
-
dir: "desc",
|
|
437
|
-
},
|
|
438
|
-
},
|
|
439
|
-
start: 0,
|
|
440
|
-
agency_from: agency_id,
|
|
441
|
-
});
|
|
442
|
-
const dataFormateada = deliveries?.data?.data
|
|
443
|
-
?.filter((result) => result.mem)
|
|
444
|
-
.map((result) => {
|
|
445
|
-
//Ejemplo: "53876;351693;MINI ZANAHORIA (NARANJA);1775.0;35;25;2022-06-10"
|
|
446
|
-
//${LOTE_ID};${LOTE_NAME};${VERDURA};${booked_quantity};${CANTIDAD_CANASTAS_ENVIADAS_A_CC};${porcentajeRechazo};${DELIVERY_DATE}
|
|
447
|
-
const memSplited = result.mem.split(";");
|
|
448
|
-
return {
|
|
449
|
-
lote_id: memSplited[0],
|
|
450
|
-
lote_name: memSplited[1],
|
|
451
|
-
verdura: memSplited[2],
|
|
452
|
-
pesoNeto: memSplited[3],
|
|
453
|
-
canastas: memSplited[4],
|
|
454
|
-
rechazo: `${truncateDecimals(Number(memSplited[5]), 2)}`,
|
|
455
|
-
delivery_date: memSplited[6],
|
|
456
|
-
pesoNetoPorCanasta: `${truncateDecimals(
|
|
457
|
-
(Number(memSplited[3]) ?? 0) / (Number(memSplited[4]) ?? 1),
|
|
458
|
-
2
|
|
459
|
-
)}`,
|
|
460
|
-
} as LoteProcesadoSchema;
|
|
461
|
-
});
|
|
462
|
-
|
|
463
|
-
return dataFormateada ?? [];
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
/**
|
|
467
|
-
*
|
|
468
|
-
* @param headers
|
|
469
|
-
* @param lot_id
|
|
470
|
-
* @returns
|
|
471
|
-
*/
|
|
472
|
-
export const inactivarLote = (
|
|
473
|
-
headers: any,
|
|
474
|
-
lot_id: string | number
|
|
475
|
-
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
476
|
-
return handlePossibleAxiosErrors(async () => {
|
|
477
|
-
await httpZauru.patch<any>(
|
|
478
|
-
`/inventories/lots/${lot_id}.json`,
|
|
479
|
-
{ active: false },
|
|
480
|
-
{ headers }
|
|
481
|
-
);
|
|
482
|
-
return true;
|
|
483
|
-
});
|
|
484
|
-
};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
3
|
-
import {
|
|
4
|
-
AxiosUtilsResponse,
|
|
5
|
-
MotivoRechazo,
|
|
6
|
-
RegisterMotivosRechazoBody,
|
|
7
|
-
WebAppRowGraphQL,
|
|
8
|
-
WebAppTableUpdateResponse,
|
|
9
|
-
} from "@zauru-sdk/types";
|
|
10
|
-
import { getVariablesByName } from "../common.js";
|
|
11
|
-
import {
|
|
12
|
-
createWebAppTableRegister,
|
|
13
|
-
deleteWebAppTableRegister,
|
|
14
|
-
getWebAppTableRegisters,
|
|
15
|
-
} from "./zauru-web-app-tables.js";
|
|
16
|
-
|
|
17
|
-
export async function getMotivosRechazo(
|
|
18
|
-
headers: any,
|
|
19
|
-
session: Session
|
|
20
|
-
): Promise<AxiosUtilsResponse<WebAppRowGraphQL<MotivoRechazo>[]>> {
|
|
21
|
-
return handlePossibleAxiosErrors(async () => {
|
|
22
|
-
const { recepciones_rejection_types_webapp_table_id } =
|
|
23
|
-
await getVariablesByName(headers, session, [
|
|
24
|
-
"recepciones_rejection_types_webapp_table_id",
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
const response = await getWebAppTableRegisters<MotivoRechazo>(
|
|
28
|
-
session,
|
|
29
|
-
recepciones_rejection_types_webapp_table_id
|
|
30
|
-
);
|
|
31
|
-
|
|
32
|
-
if (response.error || !response.data) {
|
|
33
|
-
throw new Error(response.userMsg);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return response?.data;
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export async function deleteMotivosRechazo(
|
|
41
|
-
headers: any,
|
|
42
|
-
session: Session,
|
|
43
|
-
id: number
|
|
44
|
-
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
45
|
-
return handlePossibleAxiosErrors(async () => {
|
|
46
|
-
const { recepciones_rejection_types_webapp_table_id } =
|
|
47
|
-
await getVariablesByName(headers, session, [
|
|
48
|
-
"recepciones_rejection_types_webapp_table_id",
|
|
49
|
-
]);
|
|
50
|
-
|
|
51
|
-
const response = await deleteWebAppTableRegister(
|
|
52
|
-
headers,
|
|
53
|
-
recepciones_rejection_types_webapp_table_id,
|
|
54
|
-
id
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
return response;
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export async function createMotivoRechazo(
|
|
62
|
-
headers: any,
|
|
63
|
-
session: Session,
|
|
64
|
-
body: MotivoRechazo
|
|
65
|
-
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
66
|
-
return handlePossibleAxiosErrors(async () => {
|
|
67
|
-
const { recepciones_rejection_types_webapp_table_id } =
|
|
68
|
-
await getVariablesByName(headers, session, [
|
|
69
|
-
"recepciones_rejection_types_webapp_table_id",
|
|
70
|
-
]);
|
|
71
|
-
const response = await createWebAppTableRegister<MotivoRechazo>(
|
|
72
|
-
headers,
|
|
73
|
-
recepciones_rejection_types_webapp_table_id,
|
|
74
|
-
body
|
|
75
|
-
);
|
|
76
|
-
return response;
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export async function updateMotivosRechazo(
|
|
81
|
-
headers: any,
|
|
82
|
-
session: Session,
|
|
83
|
-
id: number
|
|
84
|
-
): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
|
|
85
|
-
return handlePossibleAxiosErrors(async () => {
|
|
86
|
-
const { recepciones_rejection_types_webapp_table_id } =
|
|
87
|
-
await getVariablesByName(headers, session, [
|
|
88
|
-
"recepciones_rejection_types_webapp_table_id",
|
|
89
|
-
]);
|
|
90
|
-
const response = await deleteWebAppTableRegister(
|
|
91
|
-
headers,
|
|
92
|
-
recepciones_rejection_types_webapp_table_id,
|
|
93
|
-
id
|
|
94
|
-
);
|
|
95
|
-
return response;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export async function saveMotivosDeRechazoByPurchase(
|
|
100
|
-
headers: any,
|
|
101
|
-
session: Session,
|
|
102
|
-
body: RegisterMotivosRechazoBody,
|
|
103
|
-
extraBody: { temp_purchase_order_id: string }
|
|
104
|
-
): Promise<AxiosUtilsResponse<any>> {
|
|
105
|
-
return handlePossibleAxiosErrors(async () => {
|
|
106
|
-
const { qc_rejections_webapp_table_id } = await getVariablesByName(
|
|
107
|
-
headers,
|
|
108
|
-
session,
|
|
109
|
-
["qc_rejections_webapp_table_id"]
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
const response =
|
|
113
|
-
await createWebAppTableRegister<RegisterMotivosRechazoBody>(
|
|
114
|
-
headers,
|
|
115
|
-
qc_rejections_webapp_table_id,
|
|
116
|
-
body,
|
|
117
|
-
extraBody
|
|
118
|
-
);
|
|
119
|
-
return response.data;
|
|
120
|
-
});
|
|
121
|
-
}
|