@zauru-sdk/services 1.0.5 → 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.
- package/CHANGELOG.md +16 -0
- package/dist/common.server.d.ts +11 -10
- package/dist/common.server.js +44 -1
- package/dist/index.d.ts +22 -0
- package/dist/index.js +22 -0
- package/dist/zauru/httpZauru.server.d.ts +0 -12
- package/dist/zauru/httpZauru.server.js +0 -14
- package/dist/zauru/zauru-agencies.server.d.ts +1 -2
- package/dist/zauru/zauru-agencies.server.js +1 -1
- package/dist/zauru/zauru-automatic-numbers.server.d.ts +8 -0
- package/dist/zauru/zauru-automatic-numbers.server.js +21 -0
- package/dist/zauru/zauru-currencies.server.d.ts +6 -0
- package/dist/zauru/zauru-currencies.server.js +20 -0
- package/dist/zauru/zauru-deliveries.server.d.ts +22 -0
- package/dist/zauru/zauru-deliveries.server.js +44 -0
- package/dist/zauru/zauru-discharges.server.d.ts +26 -0
- package/dist/zauru/zauru-discharges.server.js +46 -0
- package/dist/zauru/zauru-employees.server.d.ts +6 -0
- package/dist/zauru/zauru-employees.server.js +23 -0
- package/dist/zauru/zauru-forms.server.d.ts +96 -0
- package/dist/zauru/zauru-forms.server.js +343 -0
- package/dist/zauru/zauru-invoices.server.d.ts +26 -0
- package/dist/zauru/zauru-invoices.server.js +94 -0
- package/dist/zauru/zauru-items.server.d.ts +91 -0
- package/dist/zauru/zauru-items.server.js +238 -0
- package/dist/zauru/zauru-lote-record.server.d.ts +8 -0
- package/dist/zauru/zauru-lote-record.server.js +26 -0
- package/dist/zauru/zauru-lotes.server.d.ts +91 -0
- package/dist/zauru/zauru-lotes.server.js +294 -0
- package/dist/zauru/zauru-motivos-rechazo.server.d.ts +9 -0
- package/dist/zauru/zauru-motivos-rechazo.server.js +49 -0
- package/dist/zauru/zauru-payees.server.d.ts +97 -0
- package/dist/zauru/zauru-payees.server.js +227 -0
- package/dist/zauru/zauru-payment-terms.server.d.ts +20 -0
- package/dist/zauru/zauru-payment-terms.server.js +65 -0
- package/dist/zauru/zauru-price-lists.server.d.ts +22 -0
- package/dist/zauru/zauru-price-lists.server.js +40 -0
- package/dist/zauru/zauru-profiles.server.d.ts +1 -2
- package/dist/zauru/zauru-profiles.server.js +2 -1
- package/dist/zauru/zauru-purchase-orders.server.d.ts +160 -0
- package/dist/zauru/zauru-purchase-orders.server.js +414 -0
- package/dist/zauru/zauru-receptions.server.d.ts +33 -0
- package/dist/zauru/zauru-receptions.server.js +94 -0
- package/dist/zauru/zauru-shipments.server.d.ts +20 -0
- package/dist/zauru/zauru-shipments.server.js +53 -0
- package/dist/zauru/zauru-suggested-prices.server.d.ts +30 -0
- package/dist/zauru/zauru-suggested-prices.server.js +83 -0
- package/dist/zauru/zauru-tags.server.d.ts +7 -0
- package/dist/zauru/zauru-tags.server.js +13 -0
- package/dist/zauru/zauru-templates.server.d.ts +7 -0
- package/dist/zauru/zauru-templates.server.js +15 -0
- package/dist/zauru/zauru-variables.server.d.ts +14 -0
- package/dist/zauru/zauru-variables.server.js +48 -0
- package/dist/zauru/zauru-web-app-tables.server.d.ts +48 -0
- package/dist/zauru/zauru-web-app-tables.server.js +120 -0
- package/package.json +6 -5
- package/src/common.server.ts +61 -13
- package/src/index.ts +22 -0
- package/src/zauru/httpZauru.server.ts +1 -23
- package/src/zauru/zauru-agencies.server.ts +2 -3
- package/src/zauru/zauru-automatic-numbers.server.ts +35 -0
- package/src/zauru/zauru-currencies.server.ts +39 -0
- package/src/zauru/zauru-deliveries.server.ts +70 -0
- package/src/zauru/zauru-discharges.server.ts +90 -0
- package/src/zauru/zauru-employees.server.ts +43 -0
- package/src/zauru/zauru-forms.server.ts +618 -0
- package/src/zauru/zauru-invoices.server.ts +142 -0
- package/src/zauru/zauru-items.server.ts +427 -0
- package/src/zauru/zauru-lote-record.server.ts +77 -0
- package/src/zauru/zauru-lotes.server.ts +484 -0
- package/src/zauru/zauru-motivos-rechazo.server.ts +121 -0
- package/src/zauru/zauru-payees.server.ts +398 -0
- package/src/zauru/zauru-payment-terms.server.ts +126 -0
- package/src/zauru/zauru-price-lists.server.ts +68 -0
- package/src/zauru/zauru-profiles.server.ts +3 -2
- package/src/zauru/zauru-purchase-orders.server.ts +701 -0
- package/src/zauru/zauru-receptions.server.ts +148 -0
- package/src/zauru/zauru-shipments.server.ts +88 -0
- package/src/zauru/zauru-suggested-prices.server.ts +134 -0
- package/src/zauru/zauru-tags.server.ts +22 -0
- package/src/zauru/zauru-templates.server.ts +24 -0
- package/src/zauru/zauru-variables.server.ts +67 -0
- package/src/zauru/zauru-web-app-tables.server.ts +200 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
import { arrayToObject, convertToFormData, handlePossibleAxiosErrors, } from "@zauru-sdk/common";
|
|
2
|
+
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
3
|
+
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
4
|
+
import { getFormByNameStringQuery, getFormSubmissionByIdStringQuery, getFormsByDocumentTypeStringQuery, getFormsStringQuery, getInvoiceFormSubmissionsByAgencyIdStringQuery, getInvoiceFormSubmissionsByInvoiceIdStringQuery, getLastInvoiceFormSubmissionStringQuery, getMyCaseFormSubmissionsStringQuery, } from "@zauru-sdk/graphql";
|
|
5
|
+
import httpZauru from "./httpZauru.server.js";
|
|
6
|
+
/**
|
|
7
|
+
* getForms
|
|
8
|
+
*/
|
|
9
|
+
export async function getForms(session) {
|
|
10
|
+
return handlePossibleAxiosErrors(async () => {
|
|
11
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
12
|
+
const response = await httpGraphQLAPI.post("", {
|
|
13
|
+
query: getFormsStringQuery,
|
|
14
|
+
}, { headers });
|
|
15
|
+
if (response.data.errors) {
|
|
16
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
17
|
+
}
|
|
18
|
+
const registers = response?.data?.data?.settings_forms;
|
|
19
|
+
return registers;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* getFormByName
|
|
24
|
+
*/
|
|
25
|
+
export async function getFormByName(session, name) {
|
|
26
|
+
return handlePossibleAxiosErrors(async () => {
|
|
27
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
28
|
+
const response = await httpGraphQLAPI.post("", {
|
|
29
|
+
query: getFormByNameStringQuery,
|
|
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?.settings_forms[0]) {
|
|
38
|
+
throw new Error(`No se encontró ningún formulario con el nombre: ${name} asociado`);
|
|
39
|
+
}
|
|
40
|
+
const register = response?.data?.data?.settings_forms[0];
|
|
41
|
+
return register;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* getFormsByDocumentType
|
|
46
|
+
*/
|
|
47
|
+
export async function getFormsByDocumentType(session, document_type, filters = {}) {
|
|
48
|
+
return handlePossibleAxiosErrors(async () => {
|
|
49
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
50
|
+
const response = await httpGraphQLAPI.post("", {
|
|
51
|
+
query: getFormsByDocumentTypeStringQuery(filters),
|
|
52
|
+
variables: {
|
|
53
|
+
document_type,
|
|
54
|
+
},
|
|
55
|
+
}, { headers });
|
|
56
|
+
if (response.data.errors) {
|
|
57
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
58
|
+
}
|
|
59
|
+
const registers = response?.data?.data?.settings_forms;
|
|
60
|
+
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
61
|
+
const groupedByVersion = registers.reduce((acc, record) => {
|
|
62
|
+
const zid = record.zid;
|
|
63
|
+
if (!acc[zid]) {
|
|
64
|
+
acc[zid] = record;
|
|
65
|
+
}
|
|
66
|
+
return acc;
|
|
67
|
+
}, {});
|
|
68
|
+
const latestVersionRecords = Object.values(groupedByVersion).reverse();
|
|
69
|
+
return latestVersionRecords;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* getFormSubmissionById
|
|
74
|
+
*/
|
|
75
|
+
export async function getFormSubmissionById(headersZauru, session, id, config = { withFiles: false }) {
|
|
76
|
+
return handlePossibleAxiosErrors(async () => {
|
|
77
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
78
|
+
const response = await httpGraphQLAPI.post("", {
|
|
79
|
+
query: getFormSubmissionByIdStringQuery,
|
|
80
|
+
variables: {
|
|
81
|
+
formId: id,
|
|
82
|
+
},
|
|
83
|
+
}, { headers });
|
|
84
|
+
if (response.data.errors) {
|
|
85
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
86
|
+
}
|
|
87
|
+
if (!response?.data?.data?.settings_form_submissions.length) {
|
|
88
|
+
throw new Error("No se encontró el form submission indicado.");
|
|
89
|
+
}
|
|
90
|
+
const register = response?.data?.data?.settings_form_submissions[0];
|
|
91
|
+
if (config.withFiles) {
|
|
92
|
+
const responseZauru = await httpZauru.get(`/settings/forms/form_submissions/${id}.json`, {
|
|
93
|
+
headers: headersZauru,
|
|
94
|
+
});
|
|
95
|
+
register.settings_form_submission_values =
|
|
96
|
+
register.settings_form_submission_values.map((x) => {
|
|
97
|
+
if (x.settings_form_field.field_type === "image" ||
|
|
98
|
+
x.settings_form_field.field_type === "file" ||
|
|
99
|
+
x.settings_form_field.field_type === "pdf") {
|
|
100
|
+
x.value = responseZauru.data[x.settings_form_field.print_var_name]
|
|
101
|
+
?.toString()
|
|
102
|
+
.replace(/\\u0026/g, "&");
|
|
103
|
+
}
|
|
104
|
+
return x;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
return register;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* getInvoiceFormSubmissionsByAgencyId
|
|
112
|
+
*/
|
|
113
|
+
export async function getInvoiceFormSubmissionsByAgencyId(session, agency_id, filters) {
|
|
114
|
+
return handlePossibleAxiosErrors(async () => {
|
|
115
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
116
|
+
const queryBuilded = getInvoiceFormSubmissionsByAgencyIdStringQuery({
|
|
117
|
+
seller_id: filters?.seller_id,
|
|
118
|
+
payee_id_number_search: filters?.payee_id_number_search,
|
|
119
|
+
//some_field_value: filters?.some_field_value, //Este filtro ahora lo hago abajo, con código, porque al hacerlo así antes,
|
|
120
|
+
//no funcionaba para cuando se cambiaba un campo, por ejemplo, tengo campo1 con "blabla", si lo cambiaba a campo1 = "bleble",
|
|
121
|
+
//ese campo1 con "blabla" ya iba a ser la versión vieja, pero si buscaba por ese blabla, si me iba a seguir apareciendo.
|
|
122
|
+
bundle_ids: filters?.bundle_ids,
|
|
123
|
+
item_ids: filters?.item_ids,
|
|
124
|
+
startDate: filters?.startDate,
|
|
125
|
+
endDate: filters?.endDate,
|
|
126
|
+
});
|
|
127
|
+
const response = await httpGraphQLAPI.post("", {
|
|
128
|
+
query: queryBuilded,
|
|
129
|
+
variables: {
|
|
130
|
+
agency_id,
|
|
131
|
+
},
|
|
132
|
+
}, { headers });
|
|
133
|
+
if (response.data.errors) {
|
|
134
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
135
|
+
}
|
|
136
|
+
const registers = response?.data?.data?.submission_invoices;
|
|
137
|
+
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
138
|
+
const groupedByVersion = registers.reduce((acc, record) => {
|
|
139
|
+
const zid = record.settings_form_submission.zid;
|
|
140
|
+
if (!acc[zid]) {
|
|
141
|
+
acc[zid] = record;
|
|
142
|
+
}
|
|
143
|
+
return acc;
|
|
144
|
+
}, {});
|
|
145
|
+
let latestVersionRecords = Object.values(groupedByVersion).reverse();
|
|
146
|
+
//aplico el filtro de somevalue
|
|
147
|
+
if (filters?.some_field_value) {
|
|
148
|
+
latestVersionRecords = latestVersionRecords.filter((x) => x.settings_form_submission.settings_form_submission_values.some((y) => y.value === filters?.some_field_value));
|
|
149
|
+
}
|
|
150
|
+
return latestVersionRecords;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* getMyCaseFormSubmissions
|
|
155
|
+
*/
|
|
156
|
+
export async function getMyCaseFormSubmissions(headersZauru, session, filters = {}, config = { withFiles: false }) {
|
|
157
|
+
return handlePossibleAxiosErrors(async () => {
|
|
158
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
159
|
+
const response = await httpGraphQLAPI.post("", {
|
|
160
|
+
query: getMyCaseFormSubmissionsStringQuery({
|
|
161
|
+
formZid: filters?.formZid,
|
|
162
|
+
caseId: filters?.caseId,
|
|
163
|
+
}),
|
|
164
|
+
variables: {
|
|
165
|
+
responsible_id: session.get("employee_id"),
|
|
166
|
+
},
|
|
167
|
+
}, { headers });
|
|
168
|
+
if (response.data.errors) {
|
|
169
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
170
|
+
}
|
|
171
|
+
let registers = response?.data?.data?.submission_cases;
|
|
172
|
+
if (config.withFiles) {
|
|
173
|
+
registers = await Promise.all(registers.map(async (register) => {
|
|
174
|
+
const responseZauru = await httpZauru.get(`/settings/forms/form_submissions/${register.settings_form_submission.id}.json`, {
|
|
175
|
+
headers: headersZauru,
|
|
176
|
+
});
|
|
177
|
+
register.settings_form_submission.settings_form_submission_values =
|
|
178
|
+
register.settings_form_submission.settings_form_submission_values.map((x) => {
|
|
179
|
+
if (x.settings_form_field.field_type === "image" ||
|
|
180
|
+
x.settings_form_field.field_type === "file" ||
|
|
181
|
+
x.settings_form_field.field_type === "pdf") {
|
|
182
|
+
x.value = responseZauru.data[x.settings_form_field.print_var_name]
|
|
183
|
+
?.toString()
|
|
184
|
+
.replace(/\\u0026/g, "&");
|
|
185
|
+
}
|
|
186
|
+
return x;
|
|
187
|
+
});
|
|
188
|
+
return register;
|
|
189
|
+
}));
|
|
190
|
+
}
|
|
191
|
+
return registers;
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* getLastInvoiceFormSubmission
|
|
196
|
+
* @param session
|
|
197
|
+
* @param filters
|
|
198
|
+
* @returns
|
|
199
|
+
*/
|
|
200
|
+
export async function getLastInvoiceFormSubmission(session, filters = {}) {
|
|
201
|
+
return handlePossibleAxiosErrors(async () => {
|
|
202
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
203
|
+
const response = await httpGraphQLAPI.post("", {
|
|
204
|
+
query: getLastInvoiceFormSubmissionStringQuery({
|
|
205
|
+
formZid: filters?.formZid,
|
|
206
|
+
}),
|
|
207
|
+
}, { headers });
|
|
208
|
+
if (response.data.errors) {
|
|
209
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
210
|
+
}
|
|
211
|
+
const register = response?.data?.data?.submission_invoices[0];
|
|
212
|
+
return register;
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* getInvoiceFormSubmissionsByInvoiceId
|
|
217
|
+
*/
|
|
218
|
+
export async function getInvoiceFormSubmissionsByInvoiceId(session, invoice_id, filters = {}) {
|
|
219
|
+
return handlePossibleAxiosErrors(async () => {
|
|
220
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
221
|
+
const response = await httpGraphQLAPI.post("", {
|
|
222
|
+
query: getInvoiceFormSubmissionsByInvoiceIdStringQuery({
|
|
223
|
+
formZid: filters?.formZid,
|
|
224
|
+
}),
|
|
225
|
+
variables: {
|
|
226
|
+
invoice_id,
|
|
227
|
+
},
|
|
228
|
+
}, { headers });
|
|
229
|
+
if (response.data.errors) {
|
|
230
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
231
|
+
}
|
|
232
|
+
const registers = response?.data?.data?.submission_invoices;
|
|
233
|
+
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
234
|
+
const groupedByVersion = registers.reduce((acc, record) => {
|
|
235
|
+
const zid = record.settings_form_submission.zid;
|
|
236
|
+
if (!acc[zid]) {
|
|
237
|
+
acc[zid] = record;
|
|
238
|
+
}
|
|
239
|
+
return acc;
|
|
240
|
+
}, {});
|
|
241
|
+
const latestVersionRecords = Object.values(groupedByVersion).reverse();
|
|
242
|
+
return latestVersionRecords;
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* createForm
|
|
247
|
+
* @param headers
|
|
248
|
+
* @param body
|
|
249
|
+
*/
|
|
250
|
+
export async function createForm(headers, body) {
|
|
251
|
+
return handlePossibleAxiosErrors(async () => {
|
|
252
|
+
const sendBody = {
|
|
253
|
+
...body,
|
|
254
|
+
form_fields_attributes: arrayToObject(body.settings_form_fields),
|
|
255
|
+
};
|
|
256
|
+
delete sendBody.settings_form_fields;
|
|
257
|
+
const response = await httpZauru.post(`/settings/forms.json`, { settings_form: sendBody }, { headers });
|
|
258
|
+
return response.data;
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* deleteForm
|
|
263
|
+
* @param headers
|
|
264
|
+
* @param body
|
|
265
|
+
*/
|
|
266
|
+
export async function deleteForm(headers, id) {
|
|
267
|
+
return handlePossibleAxiosErrors(async () => {
|
|
268
|
+
await httpZauru.delete(`/settings/forms/${id}?destroy=true`, {
|
|
269
|
+
headers,
|
|
270
|
+
});
|
|
271
|
+
return true;
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* createForm
|
|
276
|
+
* @param headers
|
|
277
|
+
* @param body
|
|
278
|
+
*/
|
|
279
|
+
export async function updateForm(headers, body) {
|
|
280
|
+
return handlePossibleAxiosErrors(async () => {
|
|
281
|
+
const sendBody = {
|
|
282
|
+
...body,
|
|
283
|
+
form_fields_attributes: arrayToObject(body.settings_form_fields),
|
|
284
|
+
};
|
|
285
|
+
delete sendBody.settings_form_fields;
|
|
286
|
+
const response = await httpZauru.post(`/settings/forms.json`, { settings_form: sendBody }, { headers });
|
|
287
|
+
return response.data;
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* createFormSubmission
|
|
292
|
+
* @param headers
|
|
293
|
+
* @param body
|
|
294
|
+
* @returns
|
|
295
|
+
*/
|
|
296
|
+
export async function createFormSubmission(headers, body) {
|
|
297
|
+
return handlePossibleAxiosErrors(async () => {
|
|
298
|
+
delete headers["Content-type"];
|
|
299
|
+
const sendBody = convertToFormData({
|
|
300
|
+
settings_form_submission: body,
|
|
301
|
+
});
|
|
302
|
+
const response = await httpZauru.post(`/settings/forms/form_submissions.json`, sendBody, { headers });
|
|
303
|
+
return response.data;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* updateSubmissionInvoiceFormSubmission
|
|
308
|
+
* @param headers
|
|
309
|
+
* @param body
|
|
310
|
+
* @returns
|
|
311
|
+
*/
|
|
312
|
+
export async function updateSubmissionInvoiceFormSubmission(headers, body) {
|
|
313
|
+
return handlePossibleAxiosErrors(async () => {
|
|
314
|
+
const settings_form_submission = {
|
|
315
|
+
form_id: body.settings_form_submission?.settings_form?.id,
|
|
316
|
+
reference: body.settings_form_submission?.reference,
|
|
317
|
+
document_type: "invoice",
|
|
318
|
+
document_id: body.invoice_id,
|
|
319
|
+
zid: body.settings_form_submission?.zid,
|
|
320
|
+
form_submission_values_attributes: arrayToObject(body.settings_form_submission?.settings_form_submission_values?.map((x) => {
|
|
321
|
+
delete x.settings_form_field;
|
|
322
|
+
return x;
|
|
323
|
+
})),
|
|
324
|
+
};
|
|
325
|
+
const response = await httpZauru.post(`/settings/forms/form_submissions.json`, {
|
|
326
|
+
settings_form_submission,
|
|
327
|
+
}, { headers });
|
|
328
|
+
return response.data;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* deleteFormSubmission
|
|
333
|
+
* @param headers
|
|
334
|
+
* @param body
|
|
335
|
+
*/
|
|
336
|
+
export async function deleteFormSubmission(headers, id) {
|
|
337
|
+
return handlePossibleAxiosErrors(async () => {
|
|
338
|
+
await httpZauru.delete(`/settings/forms/form_submissions/${id}.json`, {
|
|
339
|
+
headers,
|
|
340
|
+
});
|
|
341
|
+
return true;
|
|
342
|
+
});
|
|
343
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, InvoiceGraphQL } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
* getInvoicesByAgencyId
|
|
5
|
+
*/
|
|
6
|
+
export declare function getInvoicesByAgencyId(session: Session, id: string | null): Promise<AxiosUtilsResponse<InvoiceGraphQL[]>>;
|
|
7
|
+
/**
|
|
8
|
+
* createInvoiceOrder
|
|
9
|
+
* @param headers
|
|
10
|
+
* @param body
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
export declare function createInvoiceOrder(headers: any, body: Partial<InvoiceGraphQL>): Promise<AxiosUtilsResponse<InvoiceGraphQL>>;
|
|
14
|
+
/**
|
|
15
|
+
* updateInvoiceOrder
|
|
16
|
+
* @param headers
|
|
17
|
+
* @param body
|
|
18
|
+
* @returns
|
|
19
|
+
*/
|
|
20
|
+
export declare function updateInvoiceOrder(headers: any, body: Partial<InvoiceGraphQL>): Promise<AxiosUtilsResponse<InvoiceGraphQL>>;
|
|
21
|
+
/**
|
|
22
|
+
* deleteInvoice
|
|
23
|
+
* @param headers
|
|
24
|
+
* @param body
|
|
25
|
+
*/
|
|
26
|
+
export declare function deleteInvoiceOrder(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import { getGraphQLAPIHeaders } from "~/common.server.js";
|
|
3
|
+
import httpGraphQLAPI from "./httpGraphQL.server.js";
|
|
4
|
+
import { getInvoicesByAgencyIdStringQuery } from "@zauru-sdk/graphql";
|
|
5
|
+
import httpZauru from "./httpZauru.server.js";
|
|
6
|
+
/**
|
|
7
|
+
* getInvoicesByAgencyId
|
|
8
|
+
*/
|
|
9
|
+
export async function getInvoicesByAgencyId(session, id) {
|
|
10
|
+
return handlePossibleAxiosErrors(async () => {
|
|
11
|
+
const headers = await getGraphQLAPIHeaders(session);
|
|
12
|
+
const response = await httpGraphQLAPI.post("", {
|
|
13
|
+
query: getInvoicesByAgencyIdStringQuery,
|
|
14
|
+
variables: {
|
|
15
|
+
id,
|
|
16
|
+
},
|
|
17
|
+
}, { headers });
|
|
18
|
+
if (response.data.errors) {
|
|
19
|
+
throw new Error(response.data.errors.map((x) => x.message).join(";"));
|
|
20
|
+
}
|
|
21
|
+
// Filtrar los registros para obtener sólo los de la versión más alta.
|
|
22
|
+
const registers = response?.data?.data?.invoices.map((x) => {
|
|
23
|
+
const groupedByVersion = x.submission_invoices?.reduce((acc, record) => {
|
|
24
|
+
const zid = record.settings_form_submission?.zid;
|
|
25
|
+
if (!acc[zid]) {
|
|
26
|
+
acc[zid] = record;
|
|
27
|
+
}
|
|
28
|
+
return acc;
|
|
29
|
+
}, {});
|
|
30
|
+
x.submission_invoices = Object.values(groupedByVersion)?.reverse() ?? [];
|
|
31
|
+
return x;
|
|
32
|
+
});
|
|
33
|
+
return registers;
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* createInvoiceOrder
|
|
38
|
+
* @param headers
|
|
39
|
+
* @param body
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
export async function createInvoiceOrder(headers, body) {
|
|
43
|
+
return handlePossibleAxiosErrors(async () => {
|
|
44
|
+
const sendBody = {
|
|
45
|
+
...body,
|
|
46
|
+
issued: false, // Esto lo hace una órden y no una factura
|
|
47
|
+
invoice_details_attributes: arrayToObject(body.invoice_details),
|
|
48
|
+
tag_ids: body.tagging_invoices?.map((x) => x.tag_id) ?? [],
|
|
49
|
+
};
|
|
50
|
+
if (sendBody.deleted_invoice_details)
|
|
51
|
+
delete sendBody.deleted_invoice_details;
|
|
52
|
+
if (sendBody.__rvfInternalFormId)
|
|
53
|
+
delete sendBody.__rvfInternalFormId;
|
|
54
|
+
if (sendBody.invoice_details)
|
|
55
|
+
delete sendBody.invoice_details;
|
|
56
|
+
const response = await httpZauru.post(`/sales/orders.json`, { invoice: sendBody }, { headers });
|
|
57
|
+
return response.data;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* updateInvoiceOrder
|
|
62
|
+
* @param headers
|
|
63
|
+
* @param body
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
export async function updateInvoiceOrder(headers, body) {
|
|
67
|
+
return handlePossibleAxiosErrors(async () => {
|
|
68
|
+
const sendBody = {
|
|
69
|
+
...body,
|
|
70
|
+
invoice_details_attributes: arrayToObject(body.invoice_details),
|
|
71
|
+
};
|
|
72
|
+
if (sendBody.deleted_invoice_details)
|
|
73
|
+
delete sendBody.deleted_invoice_details;
|
|
74
|
+
if (sendBody.__rvfInternalFormId)
|
|
75
|
+
delete sendBody.__rvfInternalFormId;
|
|
76
|
+
if (sendBody.invoice_details)
|
|
77
|
+
delete sendBody.invoice_details;
|
|
78
|
+
const response = await httpZauru.patch(`/sales/orders/${body.id}.json`, { invoice: sendBody }, { headers });
|
|
79
|
+
return response.data;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* deleteInvoice
|
|
84
|
+
* @param headers
|
|
85
|
+
* @param body
|
|
86
|
+
*/
|
|
87
|
+
export async function deleteInvoiceOrder(headers, id) {
|
|
88
|
+
return handlePossibleAxiosErrors(async () => {
|
|
89
|
+
await httpZauru.get(`/sales/orders/${id}/void`, {
|
|
90
|
+
headers,
|
|
91
|
+
});
|
|
92
|
+
return true;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, ItemCategoryGraphQL, ItemGraphQL, ItemSuperCategoryGraphQL } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
* getItems
|
|
5
|
+
*/
|
|
6
|
+
export declare function getItems(session: Session): Promise<AxiosUtilsResponse<ItemGraphQL[]>>;
|
|
7
|
+
/**
|
|
8
|
+
* getItemByName
|
|
9
|
+
*/
|
|
10
|
+
export declare function getItemByName(session: Session, name: string): Promise<AxiosUtilsResponse<ItemGraphQL>>;
|
|
11
|
+
/**
|
|
12
|
+
* getItemCategories
|
|
13
|
+
* @param headers
|
|
14
|
+
* @param agency_id
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
17
|
+
export declare function getItemCategories(headers: any, item_category_id: string): Promise<ItemCategoryGraphQL>;
|
|
18
|
+
/**
|
|
19
|
+
* getItemsByCategoryId
|
|
20
|
+
*/
|
|
21
|
+
export declare function getItemsByCategoryId(session: Session, id: string): Promise<AxiosUtilsResponse<ItemGraphQL[]>>;
|
|
22
|
+
/**
|
|
23
|
+
* getItemCategory
|
|
24
|
+
* @param session
|
|
25
|
+
* @param id
|
|
26
|
+
*/
|
|
27
|
+
export declare function getItemCategory(session: Session, id: number | string): Promise<AxiosUtilsResponse<ItemCategoryGraphQL | undefined>>;
|
|
28
|
+
/**
|
|
29
|
+
* getItemCategoriesBySuperCategoryId
|
|
30
|
+
* @param session
|
|
31
|
+
* @param categoryId
|
|
32
|
+
* @returns
|
|
33
|
+
*/
|
|
34
|
+
export declare function getItemCategoriesBySuperCategoryId(session: Session, id: number | string): Promise<AxiosUtilsResponse<ItemCategoryGraphQL[]>>;
|
|
35
|
+
/**
|
|
36
|
+
* getItemsBySuperCategoryId
|
|
37
|
+
* @param session
|
|
38
|
+
* @param categoryId
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
export declare function getItemsBySuperCategoryId(session: Session, id: number | string, agency_id: number | string): Promise<AxiosUtilsResponse<ItemGraphQL[]>>;
|
|
42
|
+
/**
|
|
43
|
+
* createItemSuperCategory
|
|
44
|
+
* @param session
|
|
45
|
+
* @param headers
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
export declare function createItemSuperCategory(headers: any, body: Partial<ItemSuperCategoryGraphQL>): Promise<AxiosUtilsResponse<ItemSuperCategoryGraphQL>>;
|
|
49
|
+
/**
|
|
50
|
+
* createItemCategory
|
|
51
|
+
* @param session
|
|
52
|
+
* @param headers
|
|
53
|
+
* @returns
|
|
54
|
+
*/
|
|
55
|
+
export declare function createItemCategory(headers: any, body: Partial<ItemCategoryGraphQL>): Promise<AxiosUtilsResponse<ItemCategoryGraphQL>>;
|
|
56
|
+
/**
|
|
57
|
+
* deleteItemCategory
|
|
58
|
+
* @param headers
|
|
59
|
+
* @param id
|
|
60
|
+
* @returns
|
|
61
|
+
*/
|
|
62
|
+
export declare function deleteItemCategory(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
|
|
63
|
+
/**
|
|
64
|
+
* updatePayee
|
|
65
|
+
* @param session
|
|
66
|
+
* @param headers
|
|
67
|
+
* @returns
|
|
68
|
+
*/
|
|
69
|
+
export declare function updateItemCategory(headers: any, body: Partial<ItemCategoryGraphQL>): Promise<AxiosUtilsResponse<boolean>>;
|
|
70
|
+
/**
|
|
71
|
+
* createItem
|
|
72
|
+
* @param headers
|
|
73
|
+
* @param body
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
export declare function createItem(headers: any, body: Partial<ItemGraphQL>): Promise<AxiosUtilsResponse<ItemGraphQL>>;
|
|
77
|
+
/**
|
|
78
|
+
* updateItem
|
|
79
|
+
* @param headers
|
|
80
|
+
* @param body
|
|
81
|
+
* @param id
|
|
82
|
+
* @returns
|
|
83
|
+
*/
|
|
84
|
+
export declare function updateItem(headers: any, body: Partial<ItemGraphQL>): Promise<AxiosUtilsResponse<boolean>>;
|
|
85
|
+
/**
|
|
86
|
+
* deleteItemCategory
|
|
87
|
+
* @param headers
|
|
88
|
+
* @param id
|
|
89
|
+
* @returns
|
|
90
|
+
*/
|
|
91
|
+
export declare function deleteItem(headers: any, id: string | number): Promise<AxiosUtilsResponse<boolean>>;
|