@zauru-sdk/services 1.0.6 → 1.0.7

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 (65) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/index.d.ts +20 -0
  3. package/dist/index.js +20 -0
  4. package/dist/zauru/zauru-currencies.server.d.ts +6 -0
  5. package/dist/zauru/zauru-currencies.server.js +20 -0
  6. package/dist/zauru/zauru-deliveries.server.d.ts +22 -0
  7. package/dist/zauru/zauru-deliveries.server.js +44 -0
  8. package/dist/zauru/zauru-discharges.server.d.ts +26 -0
  9. package/dist/zauru/zauru-discharges.server.js +46 -0
  10. package/dist/zauru/zauru-employees.server.d.ts +6 -0
  11. package/dist/zauru/zauru-employees.server.js +23 -0
  12. package/dist/zauru/zauru-forms.server.d.ts +96 -0
  13. package/dist/zauru/zauru-forms.server.js +343 -0
  14. package/dist/zauru/zauru-invoices.server.d.ts +26 -0
  15. package/dist/zauru/zauru-invoices.server.js +94 -0
  16. package/dist/zauru/zauru-items.server.d.ts +91 -0
  17. package/dist/zauru/zauru-items.server.js +238 -0
  18. package/dist/zauru/zauru-lote-record.server.d.ts +8 -0
  19. package/dist/zauru/zauru-lote-record.server.js +26 -0
  20. package/dist/zauru/zauru-lotes.server.d.ts +91 -0
  21. package/dist/zauru/zauru-lotes.server.js +294 -0
  22. package/dist/zauru/zauru-motivos-rechazo.server.d.ts +9 -0
  23. package/dist/zauru/zauru-motivos-rechazo.server.js +49 -0
  24. package/dist/zauru/zauru-payees.server.d.ts +97 -0
  25. package/dist/zauru/zauru-payees.server.js +227 -0
  26. package/dist/zauru/zauru-payment-terms.server.d.ts +20 -0
  27. package/dist/zauru/zauru-payment-terms.server.js +65 -0
  28. package/dist/zauru/zauru-price-lists.server.d.ts +22 -0
  29. package/dist/zauru/zauru-price-lists.server.js +40 -0
  30. package/dist/zauru/zauru-purchase-orders.server.d.ts +160 -0
  31. package/dist/zauru/zauru-purchase-orders.server.js +414 -0
  32. package/dist/zauru/zauru-receptions.server.d.ts +33 -0
  33. package/dist/zauru/zauru-receptions.server.js +94 -0
  34. package/dist/zauru/zauru-shipments.server.d.ts +20 -0
  35. package/dist/zauru/zauru-shipments.server.js +53 -0
  36. package/dist/zauru/zauru-suggested-prices.server.d.ts +30 -0
  37. package/dist/zauru/zauru-suggested-prices.server.js +83 -0
  38. package/dist/zauru/zauru-tags.server.d.ts +7 -0
  39. package/dist/zauru/zauru-tags.server.js +13 -0
  40. package/dist/zauru/zauru-templates.server.d.ts +7 -0
  41. package/dist/zauru/zauru-templates.server.js +15 -0
  42. package/dist/zauru/zauru-web-app-tables.server.d.ts +48 -0
  43. package/dist/zauru/zauru-web-app-tables.server.js +120 -0
  44. package/package.json +6 -6
  45. package/src/index.ts +20 -0
  46. package/src/zauru/zauru-currencies.server.ts +39 -0
  47. package/src/zauru/zauru-deliveries.server.ts +70 -0
  48. package/src/zauru/zauru-discharges.server.ts +90 -0
  49. package/src/zauru/zauru-employees.server.ts +43 -0
  50. package/src/zauru/zauru-forms.server.ts +618 -0
  51. package/src/zauru/zauru-invoices.server.ts +142 -0
  52. package/src/zauru/zauru-items.server.ts +427 -0
  53. package/src/zauru/zauru-lote-record.server.ts +77 -0
  54. package/src/zauru/zauru-lotes.server.ts +484 -0
  55. package/src/zauru/zauru-motivos-rechazo.server.ts +121 -0
  56. package/src/zauru/zauru-payees.server.ts +398 -0
  57. package/src/zauru/zauru-payment-terms.server.ts +126 -0
  58. package/src/zauru/zauru-price-lists.server.ts +68 -0
  59. package/src/zauru/zauru-purchase-orders.server.ts +701 -0
  60. package/src/zauru/zauru-receptions.server.ts +148 -0
  61. package/src/zauru/zauru-shipments.server.ts +88 -0
  62. package/src/zauru/zauru-suggested-prices.server.ts +134 -0
  63. package/src/zauru/zauru-tags.server.ts +22 -0
  64. package/src/zauru/zauru-templates.server.ts +24 -0
  65. package/src/zauru/zauru-web-app-tables.server.ts +200 -0
@@ -0,0 +1,238 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getGraphQLAPIHeaders } from "~/common.server.js";
3
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
4
+ import { getItemByNameStringQuery, getItemCategoryByIdStringQuery, getItemsByCategoryStringQuery, getItemsBySuperCategoryStringQuery, getItemsStringQuery, getSuperCategoryByIdStringQuery, } from "@zauru-sdk/graphql";
5
+ import httpZauru from "./httpZauru.server.js";
6
+ /**
7
+ * getItems
8
+ */
9
+ export async function getItems(session) {
10
+ return handlePossibleAxiosErrors(async () => {
11
+ const headers = await getGraphQLAPIHeaders(session);
12
+ const response = await httpGraphQLAPI.post("", {
13
+ query: getItemsStringQuery,
14
+ }, { headers });
15
+ if (response.data.errors) {
16
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
17
+ }
18
+ const items = response?.data?.data?.items ?? [];
19
+ return items;
20
+ });
21
+ }
22
+ /**
23
+ * getItemByName
24
+ */
25
+ export async function getItemByName(session, name) {
26
+ return handlePossibleAxiosErrors(async () => {
27
+ const headers = await getGraphQLAPIHeaders(session);
28
+ const response = await httpGraphQLAPI.post("", {
29
+ query: getItemByNameStringQuery,
30
+ variables: {
31
+ name,
32
+ },
33
+ }, { headers });
34
+ if (response.data.errors) {
35
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
36
+ }
37
+ if (!response?.data?.data?.items[0]) {
38
+ throw new Error(`No se encontró ningún item con el nombre: ${name} asociado`);
39
+ }
40
+ const register = response?.data?.data?.items[0];
41
+ return register;
42
+ });
43
+ }
44
+ //===================== ITEM CATEGORIES
45
+ /**
46
+ * getItemCategories
47
+ * @param headers
48
+ * @param agency_id
49
+ * @returns
50
+ */
51
+ export async function getItemCategories(headers, item_category_id) {
52
+ const response = await httpZauru.get(`/settings/items/item_categories/${item_category_id}.json`, {
53
+ headers,
54
+ });
55
+ return response.data;
56
+ }
57
+ /**
58
+ * getItemsByCategoryId
59
+ */
60
+ export async function getItemsByCategoryId(session, id) {
61
+ return handlePossibleAxiosErrors(async () => {
62
+ const headers = await getGraphQLAPIHeaders(session);
63
+ const response = await httpGraphQLAPI.post("", {
64
+ query: getItemsByCategoryStringQuery,
65
+ variables: {
66
+ id,
67
+ },
68
+ }, { headers });
69
+ if (response.data.errors) {
70
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
71
+ }
72
+ if (!response?.data?.data?.item_categories[0]) {
73
+ throw new Error("No se encontró la categoría de item indicada");
74
+ }
75
+ const items = response?.data?.data?.item_categories[0]?.items ?? [];
76
+ return items;
77
+ });
78
+ }
79
+ /**
80
+ * getItemCategory
81
+ * @param session
82
+ * @param id
83
+ */
84
+ export async function getItemCategory(session, id) {
85
+ return handlePossibleAxiosErrors(async () => {
86
+ const headers = await getGraphQLAPIHeaders(session);
87
+ const response = await httpGraphQLAPI.post("", {
88
+ query: getItemCategoryByIdStringQuery,
89
+ variables: {
90
+ id,
91
+ },
92
+ }, { headers });
93
+ if (response.data.errors) {
94
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
95
+ }
96
+ if (!response?.data?.data?.item_categories[0]) {
97
+ throw new Error("No se encontró la categoría de item indicada");
98
+ }
99
+ return response?.data?.data?.item_categories[0];
100
+ });
101
+ }
102
+ /**
103
+ * getItemCategoriesBySuperCategoryId
104
+ * @param session
105
+ * @param categoryId
106
+ * @returns
107
+ */
108
+ export async function getItemCategoriesBySuperCategoryId(session, id) {
109
+ return handlePossibleAxiosErrors(async () => {
110
+ const headers = await getGraphQLAPIHeaders(session);
111
+ const response = await httpGraphQLAPI.post(``, {
112
+ query: getSuperCategoryByIdStringQuery,
113
+ variables: { id },
114
+ }, { headers });
115
+ if (response.data.errors) {
116
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
117
+ }
118
+ if (!response?.data?.data.item_super_categories[0].item_categories) {
119
+ return [];
120
+ }
121
+ return response.data?.data.item_super_categories[0]?.item_categories;
122
+ });
123
+ }
124
+ /**
125
+ * getItemsBySuperCategoryId
126
+ * @param session
127
+ * @param categoryId
128
+ * @returns
129
+ */
130
+ export async function getItemsBySuperCategoryId(session, id, agency_id) {
131
+ return handlePossibleAxiosErrors(async () => {
132
+ const headers = await getGraphQLAPIHeaders(session);
133
+ const response = await httpGraphQLAPI.post(``, {
134
+ query: getItemsBySuperCategoryStringQuery,
135
+ variables: { id, agency_id },
136
+ }, { headers });
137
+ if (response.data.errors) {
138
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
139
+ }
140
+ if (!response?.data?.data.item_super_categories[0].item_categories) {
141
+ return [];
142
+ }
143
+ const items = [];
144
+ response.data?.data.item_super_categories[0]?.item_categories.forEach((x) => items.push(...x.items));
145
+ return items;
146
+ });
147
+ }
148
+ /**
149
+ * createItemSuperCategory
150
+ * @param session
151
+ * @param headers
152
+ * @returns
153
+ */
154
+ export async function createItemSuperCategory(headers, body) {
155
+ return handlePossibleAxiosErrors(async () => {
156
+ const response = await httpZauru.post("/settings/items/item_super_categories.json", { item_super_category: body }, { headers });
157
+ return response.data;
158
+ });
159
+ }
160
+ /**
161
+ * createItemCategory
162
+ * @param session
163
+ * @param headers
164
+ * @returns
165
+ */
166
+ export async function createItemCategory(headers, body) {
167
+ return handlePossibleAxiosErrors(async () => {
168
+ const itemCategoryResponse = await httpZauru.post("/settings/items/item_categories", { item_category: body }, { headers });
169
+ return itemCategoryResponse.data;
170
+ });
171
+ }
172
+ /**
173
+ * deleteItemCategory
174
+ * @param headers
175
+ * @param id
176
+ * @returns
177
+ */
178
+ export async function deleteItemCategory(headers, id) {
179
+ return handlePossibleAxiosErrors(async () => {
180
+ await httpZauru.delete(`/settings/items/item_categories/${id}?destroy=true`, {
181
+ headers,
182
+ });
183
+ return true;
184
+ });
185
+ }
186
+ /**
187
+ * updatePayee
188
+ * @param session
189
+ * @param headers
190
+ * @returns
191
+ */
192
+ export async function updateItemCategory(headers, body) {
193
+ return handlePossibleAxiosErrors(async () => {
194
+ await httpZauru.patch(`/settings/items/item_categories/${body.id}`, { item_category: body }, { headers });
195
+ return true;
196
+ });
197
+ }
198
+ /**
199
+ * createItem
200
+ * @param headers
201
+ * @param body
202
+ * @returns
203
+ */
204
+ export async function createItem(headers, body) {
205
+ return handlePossibleAxiosErrors(async () => {
206
+ const response = await httpZauru.post(`/settings/items.json`, { item: body }, { headers });
207
+ return response.data;
208
+ });
209
+ }
210
+ /**
211
+ * updateItem
212
+ * @param headers
213
+ * @param body
214
+ * @param id
215
+ * @returns
216
+ */
217
+ export async function updateItem(headers, body) {
218
+ return handlePossibleAxiosErrors(async () => {
219
+ await httpZauru.patch(`/settings/items/${body.id}.json`, body, {
220
+ headers,
221
+ });
222
+ return true;
223
+ });
224
+ }
225
+ /**
226
+ * deleteItemCategory
227
+ * @param headers
228
+ * @param id
229
+ * @returns
230
+ */
231
+ export async function deleteItem(headers, id) {
232
+ return handlePossibleAxiosErrors(async () => {
233
+ await httpZauru.delete(`/settings/items/${id}?destroy=true`, {
234
+ headers,
235
+ });
236
+ return true;
237
+ });
238
+ }
@@ -0,0 +1,8 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { LoteRecordBody, WebAppRowGraphQL } from "@zauru-sdk/types";
3
+ export declare function getLoteRecord(headers: any, session: Session): Promise<WebAppRowGraphQL<LoteRecordBody>[]>;
4
+ export declare function deleteLoteRecord(headers: any, session: Session, id: number): Promise<any>;
5
+ export declare function createLoteRecord(headers: any, session: Session, body: LoteRecordBody): Promise<{
6
+ Nombre: string;
7
+ }>;
8
+ export declare function updateLoteRecord(headers: any, session: Session, id: number): Promise<any>;
@@ -0,0 +1,26 @@
1
+ import { getVariablesByName } from "~/common.server.js";
2
+ import { createWebAppTableRegister, deleteWebAppTableRegister, getWebAppTableRegisters, } from "./zauru-web-app-tables.server.js";
3
+ export async function getLoteRecord(headers, session) {
4
+ const { lote_record_webapp_table_id: webapp_table_id } = await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
5
+ const response = await getWebAppTableRegisters(session, webapp_table_id);
6
+ if (response.error) {
7
+ throw new Error(`Error al obtener el lote: ${response.userMsg}`);
8
+ }
9
+ const lotes = response.data ?? [];
10
+ return lotes;
11
+ }
12
+ export async function deleteLoteRecord(headers, session, id) {
13
+ const { lote_record_webapp_table_id: webapp_table_id } = await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
14
+ const response = await deleteWebAppTableRegister(headers, webapp_table_id, id);
15
+ return response.data;
16
+ }
17
+ export async function createLoteRecord(headers, session, body) {
18
+ const { lote_record_webapp_table_id: webapp_table_id } = await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
19
+ const response = await createWebAppTableRegister(headers, webapp_table_id, body);
20
+ return response.data;
21
+ }
22
+ export async function updateLoteRecord(headers, session, id) {
23
+ const { lote_record_webapp_table_id: webapp_table_id } = await getVariablesByName(headers, session, ["lote_record_webapp_table_id"]);
24
+ const response = await deleteWebAppTableRegister(headers, webapp_table_id, id);
25
+ return response.data;
26
+ }
@@ -0,0 +1,91 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, ItemAssociatedLots, LotGraphQL, LotStockGraphQL, LoteDescription, LoteProcesadoSchema, LoteSchema, LoteWithPurchaseFormatedSchema, ObjectKeyString, PurchasesDataTableListFormatedSchema, UpdateLoteBody } from "@zauru-sdk/types";
3
+ /**
4
+ * getBasketsLots
5
+ * @param headers
6
+ * @param session
7
+ * @returns
8
+ */
9
+ export declare const getBasketsLots: (headers: any, session: Session) => Promise<AxiosUtilsResponse<ItemAssociatedLots>>;
10
+ /**
11
+ *
12
+ * @param headers
13
+ * @param lot_id
14
+ * @param lot_name
15
+ * @returns
16
+ */
17
+ export declare const retenerLote: (headers: any, session: Session, lot_id: string, lot_name: string) => Promise<{
18
+ Nombre: string;
19
+ }>;
20
+ /**
21
+ *
22
+ * @param headers
23
+ * @param lot_id
24
+ * @param lot_name
25
+ * @returns
26
+ */
27
+ export declare const liberarLote: (headers: any, session: Session, lot_id: string, lot_name: string) => Promise<{
28
+ Nombre: string;
29
+ }>;
30
+ /**
31
+ * getLote Function for get all details of the current lote
32
+ * @param headers
33
+ * @param agency_id
34
+ * @returns
35
+ */
36
+ export declare function getLote(headers: any, lot_id: number | string, agency_id?: string): Promise<LoteDescription>;
37
+ /**
38
+ * getLoteByName
39
+ * @param headers
40
+ * @param lot_name
41
+ * @returns
42
+ */
43
+ export declare function getLoteByName(session: Session, lot_name: string): Promise<AxiosUtilsResponse<LotGraphQL>>;
44
+ /**
45
+ * getMyAgencyLotStocks
46
+ * @param session
47
+ * @returns
48
+ */
49
+ export declare function getMyAgencyLotStocks(session: Session): Promise<AxiosUtilsResponse<LotStockGraphQL[]>>;
50
+ /**
51
+ * getLote Function for get all details of the current lote
52
+ * @param headers
53
+ * @param agency_id
54
+ * @returns
55
+ */
56
+ export declare function updateLote(headers: any, lot_id: number, updatedData: UpdateLoteBody): Promise<any>;
57
+ /**
58
+ * getLotesExportJSON Function for get all zauru lotes by id_agencia
59
+ * @param headers
60
+ * @param agency_id
61
+ * @returns
62
+ */
63
+ export declare function getLotesExportJSON(headers: any, agency_id: string, desde?: string, hasta?: string): Promise<LoteSchema[]>;
64
+ /**
65
+ *
66
+ * @param headers
67
+ * @param agency_id
68
+ * @param baskets
69
+ * @param basket_id
70
+ * @returns
71
+ */
72
+ export declare function getLotesFiltered(headers: any, agency_id: string, baskets?: boolean, basket_id?: number): Promise<LoteSchema[]>;
73
+ /**
74
+ *
75
+ * @param headers
76
+ * @param agency_id
77
+ * @param basket_id
78
+ * @param orders
79
+ * @param desde
80
+ * @param hasta
81
+ * @returns
82
+ */
83
+ export declare function getLotesWithPurchaseFormated(headers: any, agency_id: string, basket_id: number, orders: ObjectKeyString<PurchasesDataTableListFormatedSchema>, desde?: string, hasta?: string): Promise<AxiosUtilsResponse<LoteWithPurchaseFormatedSchema[]>>;
84
+ export declare function getLotesProcesados(headers: any, agency_id: string): Promise<LoteProcesadoSchema[]>;
85
+ /**
86
+ *
87
+ * @param headers
88
+ * @param lot_id
89
+ * @returns
90
+ */
91
+ export declare const inactivarLote: (headers: any, lot_id: string | number) => Promise<AxiosUtilsResponse<boolean>>;
@@ -0,0 +1,294 @@
1
+ import { getBasketsSchema, handlePossibleAxiosErrors, reduceAdd, truncateDecimals, } from "@zauru-sdk/common";
2
+ import moment from "moment";
3
+ import { getGraphQLAPIHeaders, getVariablesByName } from "~/common.server.js";
4
+ import httpZauru from "./httpZauru.server.js";
5
+ import { createLoteRecord } from "./zauru-lote-record.server.js";
6
+ import httpGraphQLAPI from "./httpGraphQL.server.js";
7
+ import { getLotStocksByAgencyIdStringQuery, getLotsByNameStringQuery, } from "@zauru-sdk/graphql";
8
+ import { getDeliveriesDataTables } from "./zauru-deliveries.server.js";
9
+ /**
10
+ * getBasketsLots
11
+ * @param headers
12
+ * @param session
13
+ * @returns
14
+ */
15
+ export const getBasketsLots = async (headers, session) => {
16
+ return handlePossibleAxiosErrors(async () => {
17
+ const { recepciones_basket_item_id } = await getVariablesByName(headers, session, ["recepciones_basket_item_id"]);
18
+ const basketLotsResponse = await httpZauru.get(`/inventories/lots/${recepciones_basket_item_id}/item`, { headers });
19
+ const poBasket = {};
20
+ basketLotsResponse?.data?.lots.map((basket) => (poBasket[basket.name] = {
21
+ lot_id: basket.id,
22
+ rBaskets: 0,
23
+ qcBaskets: 0,
24
+ }));
25
+ return {
26
+ ...basketLotsResponse.data,
27
+ recepciones_basket_item_id: Number(recepciones_basket_item_id),
28
+ poBasket,
29
+ };
30
+ });
31
+ };
32
+ //LIBERAR/RETENER LOTES
33
+ /**
34
+ *
35
+ * @param headers
36
+ * @param lot_id
37
+ * @param lot_name
38
+ * @returns
39
+ */
40
+ export const retenerLote = async (headers, session, lot_id, lot_name) => {
41
+ await httpZauru.patch(`/inventories/lots/${lot_id}.json`, { lot: { name: `${lot_name}-RETENIDO` } }, { headers });
42
+ return await createLoteRecord(headers, session, {
43
+ agency_id: session.get("agency_id"),
44
+ created_at: moment().toISOString(),
45
+ employee_id: session.get("employee_id"),
46
+ employee_name: session.get("name"),
47
+ lote_id: lot_id,
48
+ lote_name: lot_name,
49
+ retenido: 1,
50
+ });
51
+ };
52
+ /**
53
+ *
54
+ * @param headers
55
+ * @param lot_id
56
+ * @param lot_name
57
+ * @returns
58
+ */
59
+ export const liberarLote = async (headers, session, lot_id, lot_name) => {
60
+ await httpZauru.patch(`/inventories/lots/${lot_id}.json`, { lot: { name: `${lot_name.split("-")[0]}` } }, { headers });
61
+ return await createLoteRecord(headers, session, {
62
+ agency_id: session.get("agency_id"),
63
+ created_at: moment().toISOString(),
64
+ employee_id: session.get("employee_id"),
65
+ employee_name: session.get("name"),
66
+ lote_id: lot_id,
67
+ lote_name: lot_name,
68
+ retenido: 0,
69
+ });
70
+ };
71
+ /**
72
+ * getLote Function for get all details of the current lote
73
+ * @param headers
74
+ * @param agency_id
75
+ * @returns
76
+ */
77
+ export async function getLote(headers, lot_id, agency_id) {
78
+ const response = await httpZauru.get(`/inventories/lots/${lot_id}.json`, {
79
+ headers,
80
+ });
81
+ //Paso de 23-1234-VERDE, 34-34242-AZUL => a un objeto completo de canastas
82
+ const baskets = getBasketsSchema(response.data.description);
83
+ response.data.description_baskets = baskets;
84
+ //Calculo el total de canastas, la suma de todas
85
+ response.data.baskets_quantity = baskets
86
+ .map((x) => x.total)
87
+ .reduce(reduceAdd, 0);
88
+ if (agency_id) {
89
+ //Saco el available actual
90
+ response.data.stock_actual = response.data.stocks[agency_id];
91
+ //El available by basket
92
+ response.data.availableByBaskets =
93
+ Number(response.data.stock_actual.available) /
94
+ response.data.baskets_quantity;
95
+ }
96
+ return response.data;
97
+ }
98
+ /**
99
+ * getLoteByName
100
+ * @param headers
101
+ * @param lot_name
102
+ * @returns
103
+ */
104
+ export async function getLoteByName(session, lot_name) {
105
+ return handlePossibleAxiosErrors(async () => {
106
+ const headers = await getGraphQLAPIHeaders(session);
107
+ const response = await httpGraphQLAPI.post("", {
108
+ query: getLotsByNameStringQuery,
109
+ variables: {
110
+ name: lot_name,
111
+ entity_id: session.get("selectedEntity"),
112
+ },
113
+ }, { headers });
114
+ if (response.data.errors) {
115
+ throw new Error(`Ocurrió un error al obtener el lote por nombre: ${response.data.errors
116
+ .map((x) => x.message)
117
+ .join(";")}`);
118
+ }
119
+ if (response?.data?.data.lots?.length <= 0) {
120
+ throw new Error(`No se encontró ningún resultado para el name del lote enviado: ${lot_name}`);
121
+ }
122
+ const registerFound = response.data?.data?.lots[0];
123
+ return registerFound;
124
+ });
125
+ }
126
+ /**
127
+ * getMyAgencyLotStocks
128
+ * @param session
129
+ * @returns
130
+ */
131
+ export async function getMyAgencyLotStocks(session) {
132
+ return handlePossibleAxiosErrors(async () => {
133
+ const headers = await getGraphQLAPIHeaders(session);
134
+ const response = await httpGraphQLAPI.post("", {
135
+ query: getLotStocksByAgencyIdStringQuery,
136
+ variables: {
137
+ agency_id: session.get("agency_id"),
138
+ },
139
+ }, { headers });
140
+ if (response.data.errors) {
141
+ throw new Error(`Ocurrió un error al obtener el stock de lotes por agencia: ${response.data.errors
142
+ .map((x) => x.message)
143
+ .join(";")}`);
144
+ }
145
+ if (response?.data?.data.lot_stocks?.length <= 0) {
146
+ throw new Error(`No se encontró ningún resultado para el stock de lotes por agencia: ${session.get("agency_id")}`);
147
+ }
148
+ const registerFound = response.data?.data?.lot_stocks;
149
+ return registerFound;
150
+ });
151
+ }
152
+ /**
153
+ * getLote Function for get all details of the current lote
154
+ * @param headers
155
+ * @param agency_id
156
+ * @returns
157
+ */
158
+ export async function updateLote(headers, lot_id, updatedData) {
159
+ const response = await httpZauru.patch(`/inventories/lots/${lot_id}.json`, updatedData, {
160
+ headers,
161
+ });
162
+ return response.data;
163
+ }
164
+ /**
165
+ * getLotesExportJSON Function for get all zauru lotes by id_agencia
166
+ * @param headers
167
+ * @param agency_id
168
+ * @returns
169
+ */
170
+ export async function getLotesExportJSON(headers, agency_id, desde, hasta) {
171
+ const response = await httpZauru.get(`/inventories/lots/lots_export.json`, {
172
+ headers,
173
+ params: {
174
+ warehouse: agency_id,
175
+ //Desde: desde,
176
+ //Hasta: hasta,
177
+ },
178
+ });
179
+ return response.data;
180
+ }
181
+ /**
182
+ *
183
+ * @param headers
184
+ * @param agency_id
185
+ * @param baskets
186
+ * @param basket_id
187
+ * @returns
188
+ */
189
+ export async function getLotesFiltered(headers, agency_id, baskets, basket_id) {
190
+ let lotes = await getLotesExportJSON(headers, agency_id);
191
+ if (!baskets && basket_id) {
192
+ //quito los que son de tipo canasta
193
+ lotes = lotes.filter((lot) => lot.lot?.item_id !== basket_id);
194
+ }
195
+ else if (baskets && basket_id) {
196
+ //jalo sólo los que son de tipo canasta
197
+ lotes = lotes.filter((lot) => lot.lot?.item_id === basket_id);
198
+ }
199
+ lotes = lotes.map((lot) => {
200
+ const baskets = getBasketsSchema(lot.lot.description);
201
+ const baskets_quantity = baskets.map((x) => x.total).reduce(reduceAdd, 0);
202
+ const availableByBasket = truncateDecimals(Number(lot.available) / baskets_quantity, 2);
203
+ return {
204
+ ...lot,
205
+ baskets,
206
+ availableByBasket,
207
+ baskets_quantity,
208
+ };
209
+ });
210
+ return lotes;
211
+ }
212
+ /**
213
+ *
214
+ * @param headers
215
+ * @param agency_id
216
+ * @param basket_id
217
+ * @param orders
218
+ * @param desde
219
+ * @param hasta
220
+ * @returns
221
+ */
222
+ export async function getLotesWithPurchaseFormated(headers, agency_id, basket_id, orders, desde, hasta) {
223
+ return handlePossibleAxiosErrors(async () => {
224
+ const TODAY = new Date().getTime();
225
+ const lotes = (await getLotesExportJSON(headers, agency_id, desde, hasta))
226
+ //quito los que son de tipo canasta
227
+ .filter((lot) => lot.lot?.item_id !== basket_id)
228
+ //filtro sólo los de las ordenes que vienen
229
+ .filter((lot) => Object.keys(orders).includes(lot.lot.name))
230
+ .map((lot) => {
231
+ return {
232
+ ...orders[lot.lot.name],
233
+ id_lote: lot.lot?.id,
234
+ name_lote: lot.lot?.name,
235
+ item: lot.lot?.item?.name,
236
+ created_at: lot.lot?.created_at,
237
+ weight: lot.available,
238
+ baskets: lot?.lot?.description !== null && lot?.lot?.description?.length > 0
239
+ ? lot.lot?.description
240
+ .split(",")
241
+ .map((basket) => parseInt(basket.split("-")[0]))
242
+ .reduce((sum, qty) => sum + qty)
243
+ : 0,
244
+ editable: Math.floor((TODAY - new Date(lot.lot?.created_at).getTime()) /
245
+ (1000 * 3600 * 24)) < 1,
246
+ };
247
+ })
248
+ .sort((a, b) => new Date(b.created_at).getTime() - new Date(a.created_at).getTime());
249
+ return lotes;
250
+ });
251
+ }
252
+ export async function getLotesProcesados(headers, agency_id) {
253
+ const deliveries = await getDeliveriesDataTables(headers, {
254
+ length: 0,
255
+ order: {
256
+ "0": {
257
+ column: "0",
258
+ dir: "desc",
259
+ },
260
+ },
261
+ start: 0,
262
+ agency_from: agency_id,
263
+ });
264
+ const dataFormateada = deliveries?.data?.data
265
+ ?.filter((result) => result.mem)
266
+ .map((result) => {
267
+ //Ejemplo: "53876;351693;MINI ZANAHORIA (NARANJA);1775.0;35;25;2022-06-10"
268
+ //${LOTE_ID};${LOTE_NAME};${VERDURA};${booked_quantity};${CANTIDAD_CANASTAS_ENVIADAS_A_CC};${porcentajeRechazo};${DELIVERY_DATE}
269
+ const memSplited = result.mem.split(";");
270
+ return {
271
+ lote_id: memSplited[0],
272
+ lote_name: memSplited[1],
273
+ verdura: memSplited[2],
274
+ pesoNeto: memSplited[3],
275
+ canastas: memSplited[4],
276
+ rechazo: `${truncateDecimals(Number(memSplited[5]), 2)}`,
277
+ delivery_date: memSplited[6],
278
+ pesoNetoPorCanasta: `${truncateDecimals((Number(memSplited[3]) ?? 0) / (Number(memSplited[4]) ?? 1), 2)}`,
279
+ };
280
+ });
281
+ return dataFormateada ?? [];
282
+ }
283
+ /**
284
+ *
285
+ * @param headers
286
+ * @param lot_id
287
+ * @returns
288
+ */
289
+ export const inactivarLote = (headers, lot_id) => {
290
+ return handlePossibleAxiosErrors(async () => {
291
+ await httpZauru.patch(`/inventories/lots/${lot_id}.json`, { active: false }, { headers });
292
+ return true;
293
+ });
294
+ };
@@ -0,0 +1,9 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, MotivoRechazo, RegisterMotivosRechazoBody, WebAppRowGraphQL, WebAppTableUpdateResponse } from "@zauru-sdk/types";
3
+ export declare function getMotivosRechazo(headers: any, session: Session): Promise<AxiosUtilsResponse<WebAppRowGraphQL<MotivoRechazo>[]>>;
4
+ export declare function deleteMotivosRechazo(headers: any, session: Session, id: number): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
5
+ export declare function createMotivoRechazo(headers: any, session: Session, body: MotivoRechazo): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
6
+ export declare function updateMotivosRechazo(headers: any, session: Session, id: number): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>>;
7
+ export declare function saveMotivosDeRechazoByPurchase(headers: any, session: Session, body: RegisterMotivosRechazoBody, extraBody: {
8
+ temp_purchase_order_id: string;
9
+ }): Promise<AxiosUtilsResponse<any>>;