@zauru-sdk/utils 1.0.7 → 1.0.9
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/index.d.ts +23 -2
- package/dist/index.js +23 -2
- package/dist/zauru/automatic-number.utils.d.ts +9 -0
- package/dist/zauru/automatic-number.utils.js +24 -0
- package/dist/zauru/bitacora-edicion-masiva.utils.d.ts +23 -0
- package/dist/zauru/bitacora-edicion-masiva.utils.js +50 -0
- package/dist/zauru/bundles.utils.d.ts +39 -0
- package/dist/zauru/bundles.utils.js +160 -0
- package/dist/zauru/cases.utils.d.ts +9 -0
- package/dist/zauru/cases.utils.js +17 -0
- package/dist/zauru/consolidated-history.utils.d.ts +24 -0
- package/dist/zauru/consolidated-history.utils.js +52 -0
- package/dist/zauru/costos-items.utils.d.ts +87 -0
- package/dist/zauru/costos-items.utils.js +601 -0
- package/dist/zauru/deliveries.utils.d.ts +17 -0
- package/dist/zauru/deliveries.utils.js +46 -0
- package/dist/zauru/discharges-histsory.utils.d.ts +24 -0
- package/dist/zauru/discharges-histsory.utils.js +46 -0
- package/dist/zauru/employees.utils.d.ts +16 -0
- package/dist/zauru/employees.utils.js +39 -0
- package/dist/zauru/form.utils.d.ts +34 -0
- package/dist/zauru/form.utils.js +152 -0
- package/dist/zauru/invoices.utils.d.ts +22 -0
- package/dist/zauru/invoices.utils.js +79 -0
- package/dist/zauru/items.utils.d.ts +52 -0
- package/dist/zauru/items.utils.js +152 -0
- package/dist/zauru/lotes.utils.d.ts +31 -0
- package/dist/zauru/lotes.utils.js +307 -0
- package/dist/zauru/motivos-rechazo.utils.d.ts +10 -0
- package/dist/zauru/motivos-rechazo.utils.js +18 -0
- package/dist/zauru/payees.utils.d.ts +42 -0
- package/dist/zauru/payees.utils.js +128 -0
- package/dist/zauru/profiles.utils.d.ts +15 -0
- package/dist/zauru/profiles.utils.js +37 -0
- package/dist/zauru/providers.utils.d.ts +13 -0
- package/dist/zauru/providers.utils.js +36 -0
- package/dist/zauru/purchase-orders.utils.d.ts +114 -0
- package/dist/zauru/purchase-orders.utils.js +376 -0
- package/dist/zauru/shipments.utils.d.ts +21 -0
- package/dist/zauru/shipments.utils.js +90 -0
- package/dist/zauru/specialItem.utils.d.ts +34 -0
- package/dist/zauru/specialItem.utils.js +62 -0
- package/dist/zauru/templates.utils.d.ts +49 -0
- package/dist/zauru/templates.utils.js +93 -0
- package/dist/zauru/tiposMuestra.utils.d.ts +34 -0
- package/dist/zauru/tiposMuestra.utils.js +62 -0
- package/dist/zauru/webapp-tables.utils.d.ts +16 -0
- package/dist/zauru/webapp-tables.utils.js +51 -0
- package/package.json +6 -6
- package/src/index.ts +23 -0
- package/src/zauru/bitacora-edicion-masiva.utils.ts +99 -0
- package/src/zauru/bundles.utils.ts +251 -0
- package/src/zauru/cases.utils.ts +31 -0
- package/src/zauru/consolidated-history.utils.ts +102 -0
- package/src/zauru/costos-items.utils.ts +865 -0
- package/src/zauru/deliveries.utils.ts +77 -0
- package/src/zauru/discharges-histsory.utils.ts +105 -0
- package/src/zauru/employees.utils.ts +59 -0
- package/src/zauru/form.utils.ts +243 -0
- package/src/zauru/invoices.utils.ts +114 -0
- package/src/zauru/items.utils.ts +269 -0
- package/src/zauru/lotes.utils.ts +411 -0
- package/src/zauru/motivos-rechazo.utils.ts +47 -0
- package/src/zauru/payees.utils.ts +213 -0
- package/src/zauru/profiles.utils.ts +44 -0
- package/src/zauru/providers.utils.ts +67 -0
- package/src/zauru/purchase-orders.utils.ts +594 -0
- package/src/zauru/shipments.utils.ts +139 -0
- package/src/zauru/specialItem.utils.ts +126 -0
- package/src/zauru/templates.utils.ts +199 -0
- package/src/zauru/tiposMuestra.utils.ts +136 -0
- package/src/zauru/webapp-tables.utils.ts +94 -0
- /package/src/{automatic-number.utils.ts → zauru/automatic-number.utils.ts} +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import { createWebAppTableRegister, getVariablesByName, getWebAppTableRegisters, updateWebAppTableRegister, } from "@zauru-sdk/services";
|
|
3
|
+
/**
|
|
4
|
+
* Get getDischargeHistories from the web app table.
|
|
5
|
+
* @param headers Request headers.
|
|
6
|
+
* @param session Session object.
|
|
7
|
+
* @returns A Promise of AxiosUtilsResponse<DischargeHistory[]>.
|
|
8
|
+
*/
|
|
9
|
+
export async function getDischargeHistories(headers, session) {
|
|
10
|
+
return handlePossibleAxiosErrors(async () => {
|
|
11
|
+
const { discharge_history_web_app_table_id } = await getVariablesByName(headers, session, ["discharge_history_web_app_table_id"]);
|
|
12
|
+
const response = await getWebAppTableRegisters(session, discharge_history_web_app_table_id);
|
|
13
|
+
if (response.error) {
|
|
14
|
+
throw new Error(`Ocurrió un error al consultar el historial de discharges: ${response.userMsg}`);
|
|
15
|
+
}
|
|
16
|
+
const history = response?.data ?? [];
|
|
17
|
+
return history;
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Create a template in the web app table.
|
|
22
|
+
* @param headers Request headers.
|
|
23
|
+
* @param session Session object.
|
|
24
|
+
* @param body DischargeHistory data to be created.
|
|
25
|
+
* @returns A Promise of AxiosUtilsResponse<DischargeHistory>.
|
|
26
|
+
*/
|
|
27
|
+
export async function createDischargeHistory(headers, session, body) {
|
|
28
|
+
return handlePossibleAxiosErrors(async () => {
|
|
29
|
+
const { discharge_history_web_app_table_id } = await getVariablesByName(headers, session, ["discharge_history_web_app_table_id"]);
|
|
30
|
+
const response = await createWebAppTableRegister(headers, discharge_history_web_app_table_id, body);
|
|
31
|
+
return response;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Put updateDischargeHistory from the web app table.
|
|
36
|
+
* @param headers Request headers.
|
|
37
|
+
* @param session Session object.
|
|
38
|
+
* @returns A Promise of AxiosUtilsResponse<DischargeHistory[]>.
|
|
39
|
+
*/
|
|
40
|
+
export async function updateDischargeHistory(headers, session, body, id_registro) {
|
|
41
|
+
return handlePossibleAxiosErrors(async () => {
|
|
42
|
+
const { discharge_history_web_app_table_id } = await getVariablesByName(headers, session, ["discharge_history_web_app_table_id"]);
|
|
43
|
+
const response = await updateWebAppTableRegister(headers, discharge_history_web_app_table_id, id_registro, { ...body });
|
|
44
|
+
return response;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, EmployeeGraphQL } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param headers
|
|
6
|
+
* @param session
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const getEmployeesByLabAgency: (headers: any, session: Session) => Promise<AxiosUtilsResponse<EmployeeGraphQL[]>>;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param headers
|
|
13
|
+
* @param session
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const getEmployeesByCurrentAgency: (session: Session) => Promise<AxiosUtilsResponse<EmployeeGraphQL[]>>;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import { getEmployeesByAgencyId, getVariablesByName, } from "@zauru-sdk/services";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param headers
|
|
6
|
+
* @param session
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export const getEmployeesByLabAgency = async (headers, session) => {
|
|
10
|
+
return handlePossibleAxiosErrors(async () => {
|
|
11
|
+
const { lab_agency_id } = await getVariablesByName(headers, session, [
|
|
12
|
+
"lab_agency_id",
|
|
13
|
+
]);
|
|
14
|
+
const response = await getEmployeesByAgencyId(session, lab_agency_id);
|
|
15
|
+
if (response.error) {
|
|
16
|
+
const msg = `Ocurrió un error al consultar los empleados por agencia de laboratorio: ${response.userMsg}`;
|
|
17
|
+
console.error(msg);
|
|
18
|
+
throw new Error(msg);
|
|
19
|
+
}
|
|
20
|
+
return response?.data ?? [];
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
*
|
|
25
|
+
* @param headers
|
|
26
|
+
* @param session
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
export const getEmployeesByCurrentAgency = async (session) => {
|
|
30
|
+
return handlePossibleAxiosErrors(async () => {
|
|
31
|
+
const response = await getEmployeesByAgencyId(session, session.get("agency_id"));
|
|
32
|
+
if (response.error) {
|
|
33
|
+
const msg = `Ocurrió un error al consultar los empleados por la agencia actual: ${response.userMsg}`;
|
|
34
|
+
console.error(msg);
|
|
35
|
+
throw new Error(msg);
|
|
36
|
+
}
|
|
37
|
+
return response?.data ?? [];
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, SubmissionInvoicesGraphQL, TransformedObject } from "@zauru-sdk/types";
|
|
3
|
+
export declare function transformFormSubmitObject(input: {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}): TransformedObject;
|
|
6
|
+
type OutputData = {
|
|
7
|
+
index: number;
|
|
8
|
+
item_id: number;
|
|
9
|
+
form_id?: number;
|
|
10
|
+
document_id: number;
|
|
11
|
+
reference?: string;
|
|
12
|
+
zid?: string;
|
|
13
|
+
fields: {
|
|
14
|
+
[field_id: number]: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
export declare function transformResultadosFormData(input: {
|
|
18
|
+
[key: string]: string;
|
|
19
|
+
}, document_id: number): OutputData[];
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param data
|
|
23
|
+
* @returns
|
|
24
|
+
*/
|
|
25
|
+
export declare const createRespuestaFormSubmission: (headers: any, data: OutputData) => Promise<AxiosUtilsResponse<any>>;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* @param headers
|
|
29
|
+
* @param session
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
export declare const getLastMuestra: (headers: any, session: Session) => Promise<AxiosUtilsResponse<SubmissionInvoicesGraphQL>>;
|
|
33
|
+
export declare const getMuestrasByInvoiceId: (headers: any, session: Session, invoice_id: string) => Promise<AxiosUtilsResponse<SubmissionInvoicesGraphQL[]>>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { arrayToObject, handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import { createFormSubmission, getInvoiceFormSubmissionsByInvoiceId, getLastInvoiceFormSubmission, getVariablesByName, } from "@zauru-sdk/services";
|
|
3
|
+
export function transformFormSubmitObject(input) {
|
|
4
|
+
const form_submission_values = [];
|
|
5
|
+
// Itera sobre las propiedades del objeto
|
|
6
|
+
for (const key in input) {
|
|
7
|
+
// Utiliza una expresión regular para detectar claves que coinciden con el patrón 'word_number'
|
|
8
|
+
const match = key.match(/^(.+?)_(\d+)$/);
|
|
9
|
+
if (match) {
|
|
10
|
+
const [, , form_field_id] = match;
|
|
11
|
+
let newObj = {
|
|
12
|
+
form_field_id,
|
|
13
|
+
groups_path: "[]",
|
|
14
|
+
};
|
|
15
|
+
if (input[key] instanceof File) {
|
|
16
|
+
const fileType = input[key].type;
|
|
17
|
+
newObj["value"] = "";
|
|
18
|
+
if (input[key]?.size > 0) {
|
|
19
|
+
// Verifica si el archivo es una imagen
|
|
20
|
+
if (fileType.startsWith("image/")) {
|
|
21
|
+
newObj["image"] = input[key];
|
|
22
|
+
}
|
|
23
|
+
// Verifica si el archivo es un PDF
|
|
24
|
+
else if (fileType === "application/pdf") {
|
|
25
|
+
newObj["pdf"] = input[key];
|
|
26
|
+
}
|
|
27
|
+
// Cualquier otro tipo de archivo
|
|
28
|
+
else {
|
|
29
|
+
newObj["file"] = input[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
newObj["value"] = input[key];
|
|
35
|
+
}
|
|
36
|
+
form_submission_values.push(newObj);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
form_submission_values_attributes: arrayToObject(form_submission_values),
|
|
41
|
+
form_id: input.form_id,
|
|
42
|
+
document_id: input.document_id,
|
|
43
|
+
zid: input.zid,
|
|
44
|
+
document_type: input.document_type,
|
|
45
|
+
reference: input.reference,
|
|
46
|
+
id_number: input.id_number ?? "",
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
export function transformResultadosFormData(input, document_id) {
|
|
50
|
+
const resultMap = {};
|
|
51
|
+
for (const [key, value] of Object.entries(input)) {
|
|
52
|
+
const parts = key.split("_");
|
|
53
|
+
if (parts.length === 3 &&
|
|
54
|
+
(parts[2] === "zid" || parts[2] === "reference")) {
|
|
55
|
+
const [index, item_id, specialField] = parts;
|
|
56
|
+
const compositeKey = `${index}_${item_id}`;
|
|
57
|
+
if (!resultMap[compositeKey]) {
|
|
58
|
+
resultMap[compositeKey] = {
|
|
59
|
+
index: parseInt(index),
|
|
60
|
+
item_id: parseInt(item_id),
|
|
61
|
+
document_id,
|
|
62
|
+
fields: [],
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
if (specialField === "zid") {
|
|
66
|
+
resultMap[compositeKey].zid = value;
|
|
67
|
+
}
|
|
68
|
+
else if (specialField === "reference") {
|
|
69
|
+
resultMap[compositeKey].reference = value;
|
|
70
|
+
}
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
if (parts.length !== 4)
|
|
74
|
+
continue;
|
|
75
|
+
if (parts.some((part) => isNaN(parseInt(part, 10))))
|
|
76
|
+
continue;
|
|
77
|
+
const [index, item_id, form_id, field_id] = parts.map((part) => parseInt(part, 10));
|
|
78
|
+
const compositeKey = `${index}_${item_id}`;
|
|
79
|
+
if (!resultMap[compositeKey]) {
|
|
80
|
+
resultMap[compositeKey] = {
|
|
81
|
+
index,
|
|
82
|
+
item_id,
|
|
83
|
+
form_id,
|
|
84
|
+
document_id,
|
|
85
|
+
fields: [],
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
resultMap[compositeKey].fields.push({ [field_id]: value });
|
|
89
|
+
resultMap[compositeKey].form_id = form_id;
|
|
90
|
+
}
|
|
91
|
+
return Object.values(resultMap);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
*
|
|
95
|
+
* @param data
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
export const createRespuestaFormSubmission = (headers, data) => {
|
|
99
|
+
return handlePossibleAxiosErrors(async () => {
|
|
100
|
+
const form_submission_values = [];
|
|
101
|
+
for (const value of data.fields) {
|
|
102
|
+
const form_field_id = Object.keys(value)[0];
|
|
103
|
+
const associatedValue = value[form_field_id];
|
|
104
|
+
form_submission_values.push({
|
|
105
|
+
form_field_id,
|
|
106
|
+
value: associatedValue,
|
|
107
|
+
groups_path: "[]",
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
const sendBody = {
|
|
111
|
+
form_id: data.form_id,
|
|
112
|
+
reference: `${data.index}_${data.item_id};${data?.reference}`,
|
|
113
|
+
document_type: "invoice",
|
|
114
|
+
document_id: data.document_id,
|
|
115
|
+
form_submission_values_attributes: arrayToObject(form_submission_values),
|
|
116
|
+
zid: data.zid,
|
|
117
|
+
};
|
|
118
|
+
const response = await createFormSubmission(headers, sendBody);
|
|
119
|
+
if (response.error) {
|
|
120
|
+
throw new Error(`Ocurrió un error al intentar crear la respuesta de formulario: ${data}`);
|
|
121
|
+
}
|
|
122
|
+
return true;
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
/**
|
|
126
|
+
*
|
|
127
|
+
* @param headers
|
|
128
|
+
* @param session
|
|
129
|
+
* @returns
|
|
130
|
+
*/
|
|
131
|
+
export const getLastMuestra = (headers, session) => {
|
|
132
|
+
return handlePossibleAxiosErrors(async () => {
|
|
133
|
+
const { lab_muestras_form_zid } = await getVariablesByName(headers, session, ["lab_muestras_form_zid"]);
|
|
134
|
+
const response = await getLastInvoiceFormSubmission(session, {
|
|
135
|
+
formZid: Number(lab_muestras_form_zid),
|
|
136
|
+
});
|
|
137
|
+
if (response.error || !response.data) {
|
|
138
|
+
throw new Error(`Ocurrió un error al intentar obtener la última muestra registrada: ${response.userMsg}`);
|
|
139
|
+
}
|
|
140
|
+
return response.data;
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
export const getMuestrasByInvoiceId = (headers, session, invoice_id) => {
|
|
144
|
+
return handlePossibleAxiosErrors(async () => {
|
|
145
|
+
const { lab_muestras_form_zid } = await getVariablesByName(headers, session, ["lab_muestras_form_zid"]);
|
|
146
|
+
const response = await getInvoiceFormSubmissionsByInvoiceId(session, invoice_id, { formZid: Number(lab_muestras_form_zid) });
|
|
147
|
+
if (response.error || !response.data) {
|
|
148
|
+
throw new Error(`Ocurrió un error al intentar obtener las muestras de la remisión: ${response.userMsg}`);
|
|
149
|
+
}
|
|
150
|
+
return response.data;
|
|
151
|
+
});
|
|
152
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, InvoiceDetailsGraphQL, InvoiceGraphQL } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param headers
|
|
6
|
+
* @param session
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const getInvoicesByLabAgency: (headers: any, session: Session) => Promise<AxiosUtilsResponse<InvoiceGraphQL[]>>;
|
|
10
|
+
/**
|
|
11
|
+
* createNewLabInvoiceOrder
|
|
12
|
+
* @param headers
|
|
13
|
+
* @param session
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const createNewLabInvoiceOrder: (headers: any, session: Session, body: Partial<InvoiceGraphQL>) => Promise<AxiosUtilsResponse<boolean>>;
|
|
17
|
+
/**
|
|
18
|
+
* makeInvoiceDetailsWithPrice
|
|
19
|
+
* @param invoice_details
|
|
20
|
+
* @returns
|
|
21
|
+
*/
|
|
22
|
+
export declare const makeInvoiceDetailsWithPrice: (invoice_details: any[], deleted_invoice_details?: any[]) => InvoiceDetailsGraphQL[];
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
|
|
2
|
+
import { createInvoiceOrder, getInvoicesByAgencyId, getVariablesByName, } from "@zauru-sdk/services";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param headers
|
|
6
|
+
* @param session
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export const getInvoicesByLabAgency = async (headers, session) => {
|
|
10
|
+
return handlePossibleAxiosErrors(async () => {
|
|
11
|
+
const { lab_agency_id } = await getVariablesByName(headers, session, [
|
|
12
|
+
"lab_agency_id",
|
|
13
|
+
]);
|
|
14
|
+
const response = await getInvoicesByAgencyId(session, lab_agency_id);
|
|
15
|
+
if (response.error) {
|
|
16
|
+
const msg = `Ocurrió un error al consultar las órdenes/facturas por agencia de laboratorio: ${response.userMsg}`;
|
|
17
|
+
console.error(msg);
|
|
18
|
+
throw new Error(msg);
|
|
19
|
+
}
|
|
20
|
+
return response?.data ?? [];
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* createNewLabInvoiceOrder
|
|
25
|
+
* @param headers
|
|
26
|
+
* @param session
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
export const createNewLabInvoiceOrder = async (headers, session, body) => {
|
|
30
|
+
return handlePossibleAxiosErrors(async () => {
|
|
31
|
+
const { lab_agency_id, laboratory_proyect_id } = await getVariablesByName(headers, session, ["lab_agency_id", "laboratory_proyect_id"]);
|
|
32
|
+
const sendBody = {
|
|
33
|
+
...body,
|
|
34
|
+
agency_id: Number(lab_agency_id),
|
|
35
|
+
tagging_invoices: [
|
|
36
|
+
{ tag_id: Number(laboratory_proyect_id), id: 0, invoice_id: 0 },
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
const bundleResponse = await createInvoiceOrder(headers, sendBody);
|
|
40
|
+
if (bundleResponse.error) {
|
|
41
|
+
const msg = `Ocurrió un error al intentar crear (invoice-order): ${bundleResponse.userMsg}`;
|
|
42
|
+
console.error(msg);
|
|
43
|
+
throw new Error(msg);
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* makeInvoiceDetailsWithPrice
|
|
50
|
+
* @param invoice_details
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
export const makeInvoiceDetailsWithPrice = (invoice_details, deleted_invoice_details = []) => {
|
|
54
|
+
return [
|
|
55
|
+
...invoice_details.map((x) => {
|
|
56
|
+
//Si trae una B al inicio, es un bundleID, de lo contrario, es un item_id
|
|
57
|
+
const bundle_id = x.item_id?.startsWith("B")
|
|
58
|
+
? Number(x.item_id.replace("B", ""))
|
|
59
|
+
: undefined;
|
|
60
|
+
const item_id = !bundle_id ? Number(x.item_id) : undefined;
|
|
61
|
+
const id = isNaN(x.id) ? undefined : x.id;
|
|
62
|
+
return {
|
|
63
|
+
id,
|
|
64
|
+
bundle_id,
|
|
65
|
+
item_id,
|
|
66
|
+
quantity: Number(x.quantity),
|
|
67
|
+
//unit_price: Number(x.price),
|
|
68
|
+
//price: Number(x.total),
|
|
69
|
+
_destroy: false,
|
|
70
|
+
};
|
|
71
|
+
}),
|
|
72
|
+
...deleted_invoice_details.map((x) => {
|
|
73
|
+
return {
|
|
74
|
+
id: x.id,
|
|
75
|
+
_destroy: true,
|
|
76
|
+
};
|
|
77
|
+
}),
|
|
78
|
+
];
|
|
79
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { AxiosUtilsResponse, ItemGraphQL, SearchItemParams, ItemDataTable, ItemCategoryGraphQL } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
*
|
|
5
|
+
* @param headers
|
|
6
|
+
* @param session
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const getItemsByReceptionCategory: (headers: any, session: Session) => Promise<AxiosUtilsResponse<ItemGraphQL[]>>;
|
|
10
|
+
/**
|
|
11
|
+
*
|
|
12
|
+
* @param headers
|
|
13
|
+
* @param session
|
|
14
|
+
* @returns
|
|
15
|
+
*/
|
|
16
|
+
export declare const getItemsByLabCategory: (headers: any, session: Session) => Promise<AxiosUtilsResponse<ItemGraphQL[]>>;
|
|
17
|
+
/**
|
|
18
|
+
*
|
|
19
|
+
* @param headers
|
|
20
|
+
* @param session
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare const getItemServicesByLabCategory: (headers: any, session: Session) => Promise<AxiosUtilsResponse<ItemGraphQL[]>>;
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param headers
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
export declare const getItemsDataTable: (headers: any, search: SearchItemParams) => Promise<AxiosUtilsResponse<ItemDataTable[]>>;
|
|
30
|
+
/**
|
|
31
|
+
* getLabItemCategories
|
|
32
|
+
* @param session
|
|
33
|
+
* @param headers
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
export declare function getLabItemCategories(headers: any, session: Session): Promise<AxiosUtilsResponse<ItemCategoryGraphQL[]>>;
|
|
37
|
+
/**
|
|
38
|
+
* createNewLaboratoryClient
|
|
39
|
+
* @param session
|
|
40
|
+
* @param headers
|
|
41
|
+
* @param body
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
export declare function createNewLaboratoryItemCategory(session: Session, headers: any, body: Partial<ItemCategoryGraphQL>): Promise<AxiosUtilsResponse<boolean>>;
|
|
45
|
+
/**
|
|
46
|
+
* createNewLaboratoryItem
|
|
47
|
+
* @param session
|
|
48
|
+
* @param headers
|
|
49
|
+
* @param body
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
export declare function createNewLaboratoryItem(headers: any, body: Partial<ItemGraphQL>): Promise<AxiosUtilsResponse<ItemGraphQL>>;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
import { extractValueBetweenTags, handlePossibleAxiosErrors, } from "@zauru-sdk/common";
|
|
2
|
+
import { createItem, createItemCategory, getItemCategoriesBySuperCategoryId, getItemsByCategoryId, getItemsBySuperCategoryId, getVariablesByName, } from "@zauru-sdk/services";
|
|
3
|
+
import httpZauru from "@zauru-sdk/services/dist/zauru/httpZauru.server.js";
|
|
4
|
+
/**
|
|
5
|
+
*
|
|
6
|
+
* @param headers
|
|
7
|
+
* @param session
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export const getItemsByReceptionCategory = async (headers, session) => {
|
|
11
|
+
return handlePossibleAxiosErrors(async () => {
|
|
12
|
+
const { recepciones_item_category_id } = await getVariablesByName(headers, session, ["recepciones_item_category_id"]);
|
|
13
|
+
const response = await getItemsByCategoryId(session, recepciones_item_category_id);
|
|
14
|
+
if (response.error) {
|
|
15
|
+
throw new Error(`Ocurrió un error al consultar los items por categoría de recepción: ${response.userMsg}`);
|
|
16
|
+
}
|
|
17
|
+
return response?.data ?? [];
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param headers
|
|
23
|
+
* @param session
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export const getItemsByLabCategory = async (headers, session) => {
|
|
27
|
+
return handlePossibleAxiosErrors(async () => {
|
|
28
|
+
const { lab_super_category_item_id, lab_agency_id } = await getVariablesByName(headers, session, [
|
|
29
|
+
"lab_super_category_item_id",
|
|
30
|
+
"lab_agency_id",
|
|
31
|
+
]);
|
|
32
|
+
const response = await getItemsBySuperCategoryId(session, lab_super_category_item_id, lab_agency_id);
|
|
33
|
+
if (response.error) {
|
|
34
|
+
throw new Error(`Ocurrió un error al consultar los items por categoría de laboratorio: ${response.userMsg}`);
|
|
35
|
+
}
|
|
36
|
+
return response?.data ?? [];
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
*
|
|
41
|
+
* @param headers
|
|
42
|
+
* @param session
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
export const getItemServicesByLabCategory = async (headers, session) => {
|
|
46
|
+
return handlePossibleAxiosErrors(async () => {
|
|
47
|
+
const { lab_services_item_category_id } = await getVariablesByName(headers, session, ["lab_services_item_category_id"]);
|
|
48
|
+
const response = await getItemsByCategoryId(session, lab_services_item_category_id);
|
|
49
|
+
if (response.error) {
|
|
50
|
+
throw new Error(`Ocurrió un error al consultar los items-servicios por categoría de laboratorio: ${response.userMsg}`);
|
|
51
|
+
}
|
|
52
|
+
return response?.data ?? [];
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
*
|
|
57
|
+
* @param headers
|
|
58
|
+
* @returns
|
|
59
|
+
*/
|
|
60
|
+
export const getItemsDataTable = async (headers, search) => {
|
|
61
|
+
return handlePossibleAxiosErrors(async () => {
|
|
62
|
+
const response = await httpZauru.post(`/settings/items/datatables.json`, search, { headers });
|
|
63
|
+
const items = response.data?.data?.map((x) => formatHTMLItemList(x)) ?? [];
|
|
64
|
+
return items;
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
//============================ FORMATEADO DE ITEMS
|
|
68
|
+
function extractIdFromURL(input) {
|
|
69
|
+
const regex = /\/items\/(\d+)/;
|
|
70
|
+
const match = input.match(regex);
|
|
71
|
+
return match ? parseInt(match[1], 10) : -1;
|
|
72
|
+
}
|
|
73
|
+
function formatHTMLItemList(item) {
|
|
74
|
+
return {
|
|
75
|
+
zid: parseInt(extractValueBetweenTags(item.zid, "a"), 10),
|
|
76
|
+
itemId: extractIdFromURL(item.cod),
|
|
77
|
+
name: extractValueBetweenTags(item.name, "a"),
|
|
78
|
+
stck: extractValueBetweenTags(item.stck, "i") || null,
|
|
79
|
+
act: extractValueBetweenTags(item.act, "i") || null,
|
|
80
|
+
sell: extractValueBetweenTags(item.sell, "i") || null,
|
|
81
|
+
purch: extractValueBetweenTags(item.purch, "i") || null,
|
|
82
|
+
vat: extractValueBetweenTags(item.vat, "i") || null,
|
|
83
|
+
cat: item.cat,
|
|
84
|
+
warr: item.warr,
|
|
85
|
+
cat_note: item.cat_note,
|
|
86
|
+
DT_RowId: parseInt(item.DT_RowId.replace("settings-item-", ""), 10),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* getLabItemCategories
|
|
91
|
+
* @param session
|
|
92
|
+
* @param headers
|
|
93
|
+
* @returns
|
|
94
|
+
*/
|
|
95
|
+
export async function getLabItemCategories(headers, session) {
|
|
96
|
+
return handlePossibleAxiosErrors(async () => {
|
|
97
|
+
const { lab_super_category_item_id } = await getVariablesByName(headers, session, ["lab_super_category_item_id"]);
|
|
98
|
+
const response = await getItemCategoriesBySuperCategoryId(session, lab_super_category_item_id);
|
|
99
|
+
if (response.error || !response.data) {
|
|
100
|
+
throw new Error(response.userMsg);
|
|
101
|
+
}
|
|
102
|
+
return response.data;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* createNewLaboratoryClient
|
|
107
|
+
* @param session
|
|
108
|
+
* @param headers
|
|
109
|
+
* @param body
|
|
110
|
+
* @returns
|
|
111
|
+
*/
|
|
112
|
+
export async function createNewLaboratoryItemCategory(session, headers, body) {
|
|
113
|
+
return handlePossibleAxiosErrors(async () => {
|
|
114
|
+
const { lab_super_category_item_id } = await getVariablesByName(headers, session, ["lab_super_category_item_id"]);
|
|
115
|
+
const sendBody = {
|
|
116
|
+
...body,
|
|
117
|
+
item_super_category_id: Number(lab_super_category_item_id),
|
|
118
|
+
color: "#ff0000",
|
|
119
|
+
};
|
|
120
|
+
const createResponse = await createItemCategory(headers, sendBody);
|
|
121
|
+
if (!createResponse.data) {
|
|
122
|
+
throw new Error(`Ocurrió un error al intentar crear el item category: ${createResponse.userMsg}`);
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* createNewLaboratoryItem
|
|
129
|
+
* @param session
|
|
130
|
+
* @param headers
|
|
131
|
+
* @param body
|
|
132
|
+
* @returns
|
|
133
|
+
*/
|
|
134
|
+
export async function createNewLaboratoryItem(headers, body) {
|
|
135
|
+
return handlePossibleAxiosErrors(async () => {
|
|
136
|
+
const sendBody = {
|
|
137
|
+
active: true,
|
|
138
|
+
sellable: true,
|
|
139
|
+
quotable: true,
|
|
140
|
+
ecommerce: false,
|
|
141
|
+
purchasable: true,
|
|
142
|
+
weight: 0,
|
|
143
|
+
color: "#cccccc",
|
|
144
|
+
...body,
|
|
145
|
+
};
|
|
146
|
+
const createResponse = await createItem(headers, sendBody);
|
|
147
|
+
if (!createResponse.data || createResponse.error) {
|
|
148
|
+
throw new Error(`Ocurrió un error al intentar crear el item: ${createResponse.userMsg}`);
|
|
149
|
+
}
|
|
150
|
+
return createResponse.data;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { Session } from "@remix-run/node";
|
|
2
|
+
import { BasketSchema } from "@zauru-sdk/types";
|
|
3
|
+
/**
|
|
4
|
+
* Obtiene el listado de ordenes de compra, formateado especialmente para armar la tabla de edición de porcentajes de rechazo
|
|
5
|
+
* @param headers
|
|
6
|
+
* @param session
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
export declare const getLotesFormated: (headers: any, session: Session) => Promise<import("@zauru-sdk/types").LoteSchema[]>;
|
|
10
|
+
/**
|
|
11
|
+
* procesarLote
|
|
12
|
+
* @param headers
|
|
13
|
+
* @param session
|
|
14
|
+
* @param data
|
|
15
|
+
* @param byPercent
|
|
16
|
+
*/
|
|
17
|
+
export declare const procesarLote: (headers: any, session: Session, data: any, poId: number | string) => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* Obtiene toda la información de lote, con las canastas y razones de rechazo
|
|
20
|
+
* @param headers
|
|
21
|
+
* @param session
|
|
22
|
+
* @returns
|
|
23
|
+
*/
|
|
24
|
+
export declare const getLoteDescription: (headers: any, session: Session, lote_id: number) => Promise<{
|
|
25
|
+
lote: import("@zauru-sdk/types").LoteDescription;
|
|
26
|
+
purchase_order: import("@zauru-sdk/types").PurchasesDataTableListFormatedSchema;
|
|
27
|
+
purchase: (import("@zauru-sdk/types").PurchaseOrderGraphQL & {
|
|
28
|
+
baskets_memo: BasketSchema[];
|
|
29
|
+
baskets_memo_quantity: number;
|
|
30
|
+
}) | undefined;
|
|
31
|
+
}>;
|