@zauru-sdk/services 1.0.32 → 1.0.44

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 (107) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/common.d.ts +55 -0
  3. package/dist/common.js +222 -0
  4. package/dist/index.d.ts +34 -34
  5. package/dist/index.js +34 -34
  6. package/dist/sessions/sessions.d.ts +2 -0
  7. package/dist/sessions/sessions.js +13 -0
  8. package/dist/sessions/upstash.d.ts +1 -0
  9. package/dist/sessions/upstash.js +52 -0
  10. package/dist/zauru/httpGraphQL.d.ts +2 -0
  11. package/dist/zauru/httpGraphQL.js +37 -0
  12. package/dist/zauru/httpOauth.d.ts +2 -0
  13. package/dist/zauru/httpOauth.js +37 -0
  14. package/dist/zauru/httpZauru.d.ts +2 -0
  15. package/dist/zauru/httpZauru.js +37 -0
  16. package/dist/zauru/zauru-agencies.d.ts +8 -0
  17. package/dist/zauru/zauru-agencies.js +20 -0
  18. package/dist/zauru/zauru-automatic-numbers.d.ts +8 -0
  19. package/dist/zauru/zauru-automatic-numbers.js +21 -0
  20. package/dist/zauru/zauru-bookings.d.ts +28 -0
  21. package/dist/zauru/zauru-bookings.js +80 -0
  22. package/dist/zauru/zauru-bundles.d.ts +28 -0
  23. package/dist/zauru/zauru-bundles.js +93 -0
  24. package/dist/zauru/zauru-cases.d.ts +6 -0
  25. package/dist/zauru/zauru-cases.js +23 -0
  26. package/dist/zauru/zauru-consolidated.d.ts +36 -0
  27. package/dist/zauru/zauru-consolidated.js +71 -0
  28. package/dist/zauru/zauru-currencies.d.ts +6 -0
  29. package/dist/zauru/zauru-currencies.js +20 -0
  30. package/dist/zauru/zauru-deliveries.d.ts +22 -0
  31. package/dist/zauru/zauru-deliveries.js +44 -0
  32. package/dist/zauru/zauru-discharges.d.ts +26 -0
  33. package/dist/zauru/zauru-discharges.js +46 -0
  34. package/dist/zauru/zauru-employees.d.ts +6 -0
  35. package/dist/zauru/zauru-employees.js +23 -0
  36. package/dist/zauru/zauru-forms.d.ts +96 -0
  37. package/dist/zauru/zauru-forms.js +343 -0
  38. package/dist/zauru/zauru-invoices.d.ts +26 -0
  39. package/dist/zauru/zauru-invoices.js +94 -0
  40. package/dist/zauru/zauru-items.d.ts +97 -0
  41. package/dist/zauru/zauru-items.js +272 -0
  42. package/dist/zauru/zauru-lote-record.d.ts +8 -0
  43. package/dist/zauru/zauru-lote-record.js +26 -0
  44. package/dist/zauru/zauru-lotes.d.ts +111 -0
  45. package/dist/zauru/zauru-lotes.js +294 -0
  46. package/dist/zauru/zauru-motivos-rechazo.d.ts +9 -0
  47. package/dist/zauru/zauru-motivos-rechazo.js +49 -0
  48. package/dist/zauru/zauru-payees.d.ts +97 -0
  49. package/dist/zauru/zauru-payees.js +227 -0
  50. package/dist/zauru/zauru-payment-terms.d.ts +20 -0
  51. package/dist/zauru/zauru-payment-terms.js +65 -0
  52. package/dist/zauru/zauru-price-lists.d.ts +22 -0
  53. package/dist/zauru/zauru-price-lists.js +40 -0
  54. package/dist/zauru/zauru-profiles.d.ts +28 -0
  55. package/dist/zauru/zauru-profiles.js +69 -0
  56. package/dist/zauru/zauru-purchase-orders.d.ts +160 -0
  57. package/dist/zauru/zauru-purchase-orders.js +414 -0
  58. package/dist/zauru/zauru-receptions.d.ts +33 -0
  59. package/dist/zauru/zauru-receptions.js +94 -0
  60. package/dist/zauru/zauru-shipments.d.ts +20 -0
  61. package/dist/zauru/zauru-shipments.js +53 -0
  62. package/dist/zauru/zauru-suggested-prices.d.ts +31 -0
  63. package/dist/zauru/zauru-suggested-prices.js +84 -0
  64. package/dist/zauru/zauru-tags.d.ts +7 -0
  65. package/dist/zauru/zauru-tags.js +13 -0
  66. package/dist/zauru/zauru-templates.d.ts +7 -0
  67. package/dist/zauru/zauru-templates.js +15 -0
  68. package/dist/zauru/zauru-variables.d.ts +14 -0
  69. package/dist/zauru/zauru-variables.js +48 -0
  70. package/dist/zauru/zauru-web-app-tables.d.ts +55 -0
  71. package/dist/zauru/zauru-web-app-tables.js +154 -0
  72. package/package.json +5 -5
  73. package/src/{common.server.ts → common.ts} +4 -4
  74. package/src/index.ts +34 -34
  75. package/src/sessions/{sessions.server.ts → sessions.ts} +1 -1
  76. package/src/zauru/{zauru-agencies.server.ts → zauru-agencies.ts} +2 -2
  77. package/src/zauru/{zauru-automatic-numbers.server.ts → zauru-automatic-numbers.ts} +1 -1
  78. package/src/zauru/{zauru-bookings.server.ts → zauru-bookings.ts} +3 -3
  79. package/src/zauru/{zauru-bundles.server.ts → zauru-bundles.ts} +3 -3
  80. package/src/zauru/{zauru-cases.server.ts → zauru-cases.ts} +2 -2
  81. package/src/zauru/{zauru-consolidated.server.ts → zauru-consolidated.ts} +3 -3
  82. package/src/zauru/{zauru-currencies.server.ts → zauru-currencies.ts} +2 -2
  83. package/src/zauru/{zauru-deliveries.server.ts → zauru-deliveries.ts} +1 -1
  84. package/src/zauru/{zauru-discharges.server.ts → zauru-discharges.ts} +2 -2
  85. package/src/zauru/{zauru-employees.server.ts → zauru-employees.ts} +2 -2
  86. package/src/zauru/{zauru-forms.server.ts → zauru-forms.ts} +3 -3
  87. package/src/zauru/{zauru-invoices.server.ts → zauru-invoices.ts} +3 -3
  88. package/src/zauru/{zauru-items.server.ts → zauru-items.ts} +3 -3
  89. package/src/zauru/{zauru-lote-record.server.ts → zauru-lote-record.ts} +2 -2
  90. package/src/zauru/{zauru-lotes.server.ts → zauru-lotes.ts} +5 -5
  91. package/src/zauru/{zauru-motivos-rechazo.server.ts → zauru-motivos-rechazo.ts} +2 -2
  92. package/src/zauru/{zauru-payees.server.ts → zauru-payees.ts} +3 -3
  93. package/src/zauru/{zauru-payment-terms.server.ts → zauru-payment-terms.ts} +3 -3
  94. package/src/zauru/{zauru-price-lists.server.ts → zauru-price-lists.ts} +1 -1
  95. package/src/zauru/{zauru-profiles.server.ts → zauru-profiles.ts} +2 -2
  96. package/src/zauru/{zauru-purchase-orders.server.ts → zauru-purchase-orders.ts} +4 -4
  97. package/src/zauru/{zauru-receptions.server.ts → zauru-receptions.ts} +1 -1
  98. package/src/zauru/{zauru-shipments.server.ts → zauru-shipments.ts} +3 -3
  99. package/src/zauru/{zauru-suggested-prices.server.ts → zauru-suggested-prices.ts} +3 -3
  100. package/src/zauru/{zauru-tags.server.ts → zauru-tags.ts} +1 -1
  101. package/src/zauru/{zauru-templates.server.ts → zauru-templates.ts} +1 -1
  102. package/src/zauru/{zauru-variables.server.ts → zauru-variables.ts} +1 -1
  103. package/src/zauru/{zauru-web-app-tables.server.ts → zauru-web-app-tables.ts} +3 -3
  104. /package/src/sessions/{upstash.server.ts → upstash.ts} +0 -0
  105. /package/src/zauru/{httpGraphQL.server.ts → httpGraphQL.ts} +0 -0
  106. /package/src/zauru/{httpOauth.server.ts → httpOauth.ts} +0 -0
  107. /package/src/zauru/{httpZauru.server.ts → httpZauru.ts} +0 -0
@@ -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.js";
4
+ import httpZauru from "./httpZauru.js";
5
+ import { createLoteRecord } from "./zauru-lote-record.js";
6
+ import httpGraphQLAPI from "./httpGraphQL.js";
7
+ import { getLotStocksByAgencyIdStringQuery, getLotsByNameStringQuery, } from "@zauru-sdk/graphql";
8
+ import { getDeliveriesDataTables } from "./zauru-deliveries.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>>;
@@ -0,0 +1,49 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import { getVariablesByName } from "../common.js";
3
+ import { createWebAppTableRegister, deleteWebAppTableRegister, getWebAppTableRegisters, } from "./zauru-web-app-tables.js";
4
+ export async function getMotivosRechazo(headers, session) {
5
+ return handlePossibleAxiosErrors(async () => {
6
+ const { recepciones_rejection_types_webapp_table_id } = await getVariablesByName(headers, session, [
7
+ "recepciones_rejection_types_webapp_table_id",
8
+ ]);
9
+ const response = await getWebAppTableRegisters(session, recepciones_rejection_types_webapp_table_id);
10
+ if (response.error || !response.data) {
11
+ throw new Error(response.userMsg);
12
+ }
13
+ return response?.data;
14
+ });
15
+ }
16
+ export async function deleteMotivosRechazo(headers, session, id) {
17
+ return handlePossibleAxiosErrors(async () => {
18
+ const { recepciones_rejection_types_webapp_table_id } = await getVariablesByName(headers, session, [
19
+ "recepciones_rejection_types_webapp_table_id",
20
+ ]);
21
+ const response = await deleteWebAppTableRegister(headers, recepciones_rejection_types_webapp_table_id, id);
22
+ return response;
23
+ });
24
+ }
25
+ export async function createMotivoRechazo(headers, session, body) {
26
+ return handlePossibleAxiosErrors(async () => {
27
+ const { recepciones_rejection_types_webapp_table_id } = await getVariablesByName(headers, session, [
28
+ "recepciones_rejection_types_webapp_table_id",
29
+ ]);
30
+ const response = await createWebAppTableRegister(headers, recepciones_rejection_types_webapp_table_id, body);
31
+ return response;
32
+ });
33
+ }
34
+ export async function updateMotivosRechazo(headers, session, id) {
35
+ return handlePossibleAxiosErrors(async () => {
36
+ const { recepciones_rejection_types_webapp_table_id } = await getVariablesByName(headers, session, [
37
+ "recepciones_rejection_types_webapp_table_id",
38
+ ]);
39
+ const response = await deleteWebAppTableRegister(headers, recepciones_rejection_types_webapp_table_id, id);
40
+ return response;
41
+ });
42
+ }
43
+ export async function saveMotivosDeRechazoByPurchase(headers, session, body, extraBody) {
44
+ return handlePossibleAxiosErrors(async () => {
45
+ const { qc_rejections_webapp_table_id } = await getVariablesByName(headers, session, ["qc_rejections_webapp_table_id"]);
46
+ const response = await createWebAppTableRegister(headers, qc_rejections_webapp_table_id, body, extraBody);
47
+ return response.data;
48
+ });
49
+ }
@@ -0,0 +1,97 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, PayeeCategoryGraphQL, PayeeGraphQL } from "@zauru-sdk/types";
3
+ /**
4
+ * getPayees
5
+ * @param headers
6
+ * @returns
7
+ */
8
+ export declare function getPayees(session: Session): Promise<AxiosUtilsResponse<PayeeGraphQL[]>>;
9
+ /**
10
+ * getProviders
11
+ * @param headers
12
+ * @returns
13
+ */
14
+ export declare function getProviders(session: Session): Promise<AxiosUtilsResponse<PayeeGraphQL[]>>;
15
+ /**
16
+ * getPayee
17
+ * @param session
18
+ * @param id
19
+ */
20
+ export declare function getPayee(session: Session, id: number | string): Promise<AxiosUtilsResponse<PayeeGraphQL | undefined>>;
21
+ /**
22
+ * getPayeesByCategoryId
23
+ * @param session
24
+ * @param categoryId
25
+ * @returns
26
+ */
27
+ export declare function getPayeesByCategoryId(session: Session, id: number | string): Promise<AxiosUtilsResponse<PayeeGraphQL[]>>;
28
+ /**
29
+ * getPayeeCategoriesByNotesMatch
30
+ * @param session
31
+ * @param match
32
+ * @returns
33
+ */
34
+ export declare function getPayeeCategoriesByNotesMatch(session: Session, match: string): Promise<AxiosUtilsResponse<PayeeCategoryGraphQL[]>>;
35
+ /**
36
+ * getPayeeCategories
37
+ * @param session
38
+ * @param match
39
+ * @returns
40
+ */
41
+ export declare function getPayeeCategories(session: Session): Promise<AxiosUtilsResponse<PayeeCategoryGraphQL[]>>;
42
+ /**
43
+ * getProviderCategories
44
+ * @param session
45
+ * @param match
46
+ * @returns
47
+ */
48
+ export declare function getProviderCategories(session: Session): Promise<AxiosUtilsResponse<PayeeCategoryGraphQL[]>>;
49
+ /**
50
+ * getProviderCategories
51
+ * @param session
52
+ * @param match
53
+ * @returns
54
+ */
55
+ export declare function getClientCategories(session: Session): Promise<AxiosUtilsResponse<PayeeCategoryGraphQL[]>>;
56
+ /**
57
+ * createPayee
58
+ * @param session
59
+ * @param headers
60
+ * @returns
61
+ */
62
+ export declare function createPayee(headers: any, body: Partial<PayeeGraphQL>): Promise<AxiosUtilsResponse<boolean>>;
63
+ /**
64
+ * deletePayee
65
+ * @param headers
66
+ * @param id
67
+ * @returns
68
+ */
69
+ export declare function deletePayee(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
70
+ /**
71
+ * updatePayee
72
+ * @param session
73
+ * @param headers
74
+ * @returns
75
+ */
76
+ export declare function updatePayee(headers: any, body: Partial<PayeeGraphQL>): Promise<AxiosUtilsResponse<boolean>>;
77
+ /**
78
+ * createPayeeCategory
79
+ * @param session
80
+ * @param headers
81
+ * @returns
82
+ */
83
+ export declare function createPayeeCategory(headers: any, body: Partial<PayeeCategoryGraphQL>): Promise<AxiosUtilsResponse<PayeeCategoryGraphQL>>;
84
+ /**
85
+ * updatePayeeCategory
86
+ * @param session
87
+ * @param headers
88
+ * @returns
89
+ */
90
+ export declare function updatePayeeCategory(headers: any, body: Partial<PayeeCategoryGraphQL>): Promise<AxiosUtilsResponse<boolean>>;
91
+ /**
92
+ * deletePayeeCategory
93
+ * @param headers
94
+ * @param id
95
+ * @returns
96
+ */
97
+ export declare function deletePayeeCategory(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
@@ -0,0 +1,227 @@
1
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
2
+ import httpGraphQLAPI from "./httpGraphQL.js";
3
+ import { getGraphQLAPIHeaders } from "../common.js";
4
+ import { getClientCategoriesStringQuery, getPayeeByIdStringQuery, getPayeeCategoriesByNotesMatchStringQuery, getPayeeCategoriesStringQuery, getPayeeCategoryByIdStringQuery, getPayeesStringQuery, getProviderCategoriesStringQuery, getProvidersStringQuery, } from "@zauru-sdk/graphql";
5
+ import httpZauru from "./httpZauru.js";
6
+ /**
7
+ * getPayees
8
+ * @param headers
9
+ * @returns
10
+ */
11
+ export async function getPayees(session) {
12
+ return handlePossibleAxiosErrors(async () => {
13
+ const headers = await getGraphQLAPIHeaders(session);
14
+ const response = await httpGraphQLAPI.post(``, {
15
+ query: getPayeesStringQuery,
16
+ }, {
17
+ headers,
18
+ });
19
+ return response.data?.data.payees;
20
+ });
21
+ }
22
+ /**
23
+ * getProviders
24
+ * @param headers
25
+ * @returns
26
+ */
27
+ export async function getProviders(session) {
28
+ return handlePossibleAxiosErrors(async () => {
29
+ const headers = await getGraphQLAPIHeaders(session);
30
+ const response = await httpGraphQLAPI.post(``, {
31
+ query: getProvidersStringQuery,
32
+ }, {
33
+ headers,
34
+ });
35
+ return response.data?.data.payees;
36
+ });
37
+ }
38
+ /**
39
+ * getPayee
40
+ * @param session
41
+ * @param id
42
+ */
43
+ export async function getPayee(session, id) {
44
+ return handlePossibleAxiosErrors(async () => {
45
+ const headers = await getGraphQLAPIHeaders(session);
46
+ const responsePayee = await httpGraphQLAPI.post("", {
47
+ query: getPayeeByIdStringQuery,
48
+ variables: {
49
+ id,
50
+ },
51
+ }, { headers });
52
+ if (!responsePayee?.data?.data?.payees[0]) {
53
+ throw new Error("No se encontró el beneficiario indicado");
54
+ }
55
+ return responsePayee?.data?.data?.payees[0];
56
+ });
57
+ }
58
+ /**
59
+ * getPayeesByCategoryId
60
+ * @param session
61
+ * @param categoryId
62
+ * @returns
63
+ */
64
+ export async function getPayeesByCategoryId(session, id) {
65
+ return handlePossibleAxiosErrors(async () => {
66
+ const headers = await getGraphQLAPIHeaders(session);
67
+ const response = await httpGraphQLAPI.post(``, {
68
+ query: getPayeeCategoryByIdStringQuery,
69
+ variables: { id },
70
+ }, { headers });
71
+ if (response.data.errors) {
72
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
73
+ }
74
+ if (!response?.data?.data?.payee_categories[0]) {
75
+ return [];
76
+ }
77
+ return response.data?.data?.payee_categories[0]?.payees;
78
+ });
79
+ }
80
+ /**
81
+ * getPayeeCategoriesByNotesMatch
82
+ * @param session
83
+ * @param match
84
+ * @returns
85
+ */
86
+ export async function getPayeeCategoriesByNotesMatch(session, match) {
87
+ return handlePossibleAxiosErrors(async () => {
88
+ const headers = await getGraphQLAPIHeaders(session);
89
+ const response = await httpGraphQLAPI.post(``, {
90
+ query: getPayeeCategoriesByNotesMatchStringQuery(match),
91
+ }, { headers });
92
+ if (response.data.errors) {
93
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
94
+ }
95
+ return response.data?.data?.payee_categories;
96
+ });
97
+ }
98
+ /**
99
+ * getPayeeCategories
100
+ * @param session
101
+ * @param match
102
+ * @returns
103
+ */
104
+ export async function getPayeeCategories(session) {
105
+ return handlePossibleAxiosErrors(async () => {
106
+ const headers = await getGraphQLAPIHeaders(session);
107
+ const response = await httpGraphQLAPI.post(``, {
108
+ query: getPayeeCategoriesStringQuery,
109
+ }, { headers });
110
+ if (response.data.errors) {
111
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
112
+ }
113
+ return response.data?.data?.payee_categories;
114
+ });
115
+ }
116
+ /**
117
+ * getProviderCategories
118
+ * @param session
119
+ * @param match
120
+ * @returns
121
+ */
122
+ export async function getProviderCategories(session) {
123
+ return handlePossibleAxiosErrors(async () => {
124
+ const headers = await getGraphQLAPIHeaders(session);
125
+ const response = await httpGraphQLAPI.post(``, {
126
+ query: getProviderCategoriesStringQuery,
127
+ }, { headers });
128
+ if (response.data.errors) {
129
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
130
+ }
131
+ return response.data?.data?.payee_categories;
132
+ });
133
+ }
134
+ /**
135
+ * getProviderCategories
136
+ * @param session
137
+ * @param match
138
+ * @returns
139
+ */
140
+ export async function getClientCategories(session) {
141
+ return handlePossibleAxiosErrors(async () => {
142
+ const headers = await getGraphQLAPIHeaders(session);
143
+ const response = await httpGraphQLAPI.post(``, {
144
+ query: getClientCategoriesStringQuery,
145
+ }, { headers });
146
+ if (response.data.errors) {
147
+ throw new Error(response.data.errors.map((x) => x.message).join(";"));
148
+ }
149
+ return response.data?.data?.payee_categories;
150
+ });
151
+ }
152
+ /**
153
+ * createPayee
154
+ * @param session
155
+ * @param headers
156
+ * @returns
157
+ */
158
+ export async function createPayee(headers, body) {
159
+ return handlePossibleAxiosErrors(async () => {
160
+ await httpZauru.post("/settings/payees", { payee: body }, { headers });
161
+ return true;
162
+ });
163
+ }
164
+ /**
165
+ * deletePayee
166
+ * @param headers
167
+ * @param id
168
+ * @returns
169
+ */
170
+ export async function deletePayee(headers, id) {
171
+ return handlePossibleAxiosErrors(async () => {
172
+ await httpZauru.delete(`/settings/payees/${id}?destroy=true`, {
173
+ headers,
174
+ });
175
+ return true;
176
+ });
177
+ }
178
+ /**
179
+ * updatePayee
180
+ * @param session
181
+ * @param headers
182
+ * @returns
183
+ */
184
+ export async function updatePayee(headers, body) {
185
+ return handlePossibleAxiosErrors(async () => {
186
+ await httpZauru.patch(`/settings/payees/${body.id}`, { payee: body }, { headers });
187
+ return true;
188
+ });
189
+ }
190
+ /**
191
+ * createPayeeCategory
192
+ * @param session
193
+ * @param headers
194
+ * @returns
195
+ */
196
+ export async function createPayeeCategory(headers, body) {
197
+ return handlePossibleAxiosErrors(async () => {
198
+ const response = await httpZauru.post("/settings/payees/payee_categories", { payee_category: body }, { headers });
199
+ return response.data;
200
+ });
201
+ }
202
+ /**
203
+ * updatePayeeCategory
204
+ * @param session
205
+ * @param headers
206
+ * @returns
207
+ */
208
+ export async function updatePayeeCategory(headers, body) {
209
+ return handlePossibleAxiosErrors(async () => {
210
+ await httpZauru.patch(`/settings/payees/payee_categories/${body.id}`, { payee_category: body }, { headers });
211
+ return true;
212
+ });
213
+ }
214
+ /**
215
+ * deletePayeeCategory
216
+ * @param headers
217
+ * @param id
218
+ * @returns
219
+ */
220
+ export async function deletePayeeCategory(headers, id) {
221
+ return handlePossibleAxiosErrors(async () => {
222
+ await httpZauru.delete(`/settings/payees/payee_categories/${id}?destroy=true`, {
223
+ headers,
224
+ });
225
+ return true;
226
+ });
227
+ }
@@ -0,0 +1,20 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { AxiosUtilsResponse, PaymentTermGraphQL } from "@zauru-sdk/types";
3
+ /**
4
+ * getPaymentTerms
5
+ */
6
+ export declare function getPaymentTerms(session: Session): Promise<AxiosUtilsResponse<PaymentTermGraphQL[]>>;
7
+ /**
8
+ * getPaymentTermById
9
+ */
10
+ export declare function getPaymentTermById(session: Session, id: string | number): Promise<AxiosUtilsResponse<PaymentTermGraphQL>>;
11
+ /**
12
+ * createPaymentTerm
13
+ * @param headers
14
+ */
15
+ export declare function createPaymentTerm(headers: any, payment_term: PaymentTermGraphQL): Promise<AxiosUtilsResponse<PaymentTermGraphQL>>;
16
+ /**
17
+ * updatePaymentTerm
18
+ * @param headers
19
+ */
20
+ export declare function updatePaymentTerm(headers: any, payment_term: Partial<PaymentTermGraphQL> & any): Promise<AxiosUtilsResponse<PaymentTermGraphQL>>;