@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.
Files changed (74) hide show
  1. package/CHANGELOG.md +16 -0
  2. package/dist/index.d.ts +23 -2
  3. package/dist/index.js +23 -2
  4. package/dist/zauru/automatic-number.utils.d.ts +9 -0
  5. package/dist/zauru/automatic-number.utils.js +24 -0
  6. package/dist/zauru/bitacora-edicion-masiva.utils.d.ts +23 -0
  7. package/dist/zauru/bitacora-edicion-masiva.utils.js +50 -0
  8. package/dist/zauru/bundles.utils.d.ts +39 -0
  9. package/dist/zauru/bundles.utils.js +160 -0
  10. package/dist/zauru/cases.utils.d.ts +9 -0
  11. package/dist/zauru/cases.utils.js +17 -0
  12. package/dist/zauru/consolidated-history.utils.d.ts +24 -0
  13. package/dist/zauru/consolidated-history.utils.js +52 -0
  14. package/dist/zauru/costos-items.utils.d.ts +87 -0
  15. package/dist/zauru/costos-items.utils.js +601 -0
  16. package/dist/zauru/deliveries.utils.d.ts +17 -0
  17. package/dist/zauru/deliveries.utils.js +46 -0
  18. package/dist/zauru/discharges-histsory.utils.d.ts +24 -0
  19. package/dist/zauru/discharges-histsory.utils.js +46 -0
  20. package/dist/zauru/employees.utils.d.ts +16 -0
  21. package/dist/zauru/employees.utils.js +39 -0
  22. package/dist/zauru/form.utils.d.ts +34 -0
  23. package/dist/zauru/form.utils.js +152 -0
  24. package/dist/zauru/invoices.utils.d.ts +22 -0
  25. package/dist/zauru/invoices.utils.js +79 -0
  26. package/dist/zauru/items.utils.d.ts +52 -0
  27. package/dist/zauru/items.utils.js +152 -0
  28. package/dist/zauru/lotes.utils.d.ts +31 -0
  29. package/dist/zauru/lotes.utils.js +307 -0
  30. package/dist/zauru/motivos-rechazo.utils.d.ts +10 -0
  31. package/dist/zauru/motivos-rechazo.utils.js +18 -0
  32. package/dist/zauru/payees.utils.d.ts +42 -0
  33. package/dist/zauru/payees.utils.js +128 -0
  34. package/dist/zauru/profiles.utils.d.ts +15 -0
  35. package/dist/zauru/profiles.utils.js +37 -0
  36. package/dist/zauru/providers.utils.d.ts +13 -0
  37. package/dist/zauru/providers.utils.js +36 -0
  38. package/dist/zauru/purchase-orders.utils.d.ts +114 -0
  39. package/dist/zauru/purchase-orders.utils.js +376 -0
  40. package/dist/zauru/shipments.utils.d.ts +21 -0
  41. package/dist/zauru/shipments.utils.js +90 -0
  42. package/dist/zauru/specialItem.utils.d.ts +34 -0
  43. package/dist/zauru/specialItem.utils.js +62 -0
  44. package/dist/zauru/templates.utils.d.ts +49 -0
  45. package/dist/zauru/templates.utils.js +93 -0
  46. package/dist/zauru/tiposMuestra.utils.d.ts +34 -0
  47. package/dist/zauru/tiposMuestra.utils.js +62 -0
  48. package/dist/zauru/webapp-tables.utils.d.ts +16 -0
  49. package/dist/zauru/webapp-tables.utils.js +51 -0
  50. package/package.json +6 -6
  51. package/src/index.ts +23 -0
  52. package/src/zauru/bitacora-edicion-masiva.utils.ts +99 -0
  53. package/src/zauru/bundles.utils.ts +251 -0
  54. package/src/zauru/cases.utils.ts +31 -0
  55. package/src/zauru/consolidated-history.utils.ts +102 -0
  56. package/src/zauru/costos-items.utils.ts +865 -0
  57. package/src/zauru/deliveries.utils.ts +77 -0
  58. package/src/zauru/discharges-histsory.utils.ts +105 -0
  59. package/src/zauru/employees.utils.ts +59 -0
  60. package/src/zauru/form.utils.ts +243 -0
  61. package/src/zauru/invoices.utils.ts +114 -0
  62. package/src/zauru/items.utils.ts +269 -0
  63. package/src/zauru/lotes.utils.ts +411 -0
  64. package/src/zauru/motivos-rechazo.utils.ts +47 -0
  65. package/src/zauru/payees.utils.ts +213 -0
  66. package/src/zauru/profiles.utils.ts +44 -0
  67. package/src/zauru/providers.utils.ts +67 -0
  68. package/src/zauru/purchase-orders.utils.ts +594 -0
  69. package/src/zauru/shipments.utils.ts +139 -0
  70. package/src/zauru/specialItem.utils.ts +126 -0
  71. package/src/zauru/templates.utils.ts +199 -0
  72. package/src/zauru/tiposMuestra.utils.ts +136 -0
  73. package/src/zauru/webapp-tables.utils.ts +94 -0
  74. /package/src/{automatic-number.utils.ts → zauru/automatic-number.utils.ts} +0 -0
@@ -0,0 +1,47 @@
1
+ import { Session } from "@remix-run/node";
2
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import {
4
+ createWebAppTableRegister,
5
+ getVariablesByName,
6
+ } from "@zauru-sdk/services";
7
+ import {
8
+ AxiosUtilsResponse,
9
+ BasicIdNameSchema,
10
+ MotivoRechazo,
11
+ WebAppRowGraphQL,
12
+ WebAppTableUpdateResponse,
13
+ } from "@zauru-sdk/types";
14
+
15
+ export function formatearMotivoDeRechazo(
16
+ entity: WebAppRowGraphQL<MotivoRechazo>
17
+ ): BasicIdNameSchema {
18
+ return { id: entity.id, name: entity.data.Nombre } as BasicIdNameSchema;
19
+ }
20
+
21
+ /**
22
+ * Post saveBitacoraPOMassive from the web app table.
23
+ * @param headers Request headers.
24
+ * @param session Session object.
25
+ * @returns A Promise of AxiosUtilsResponse<WebAppRowGraphQL<BitacoraPOMassive>[]>.
26
+ */
27
+ export async function saveRechazoCanastas(
28
+ headers: any,
29
+ session: Session,
30
+ body: any
31
+ ): Promise<AxiosUtilsResponse<WebAppTableUpdateResponse>> {
32
+ return handlePossibleAxiosErrors(async () => {
33
+ const { recepciones_rejections_webapp_table_id } = await getVariablesByName(
34
+ headers,
35
+ session,
36
+ ["recepciones_rejections_webapp_table_id"]
37
+ );
38
+
39
+ const response = await createWebAppTableRegister<any>(
40
+ headers,
41
+ recepciones_rejections_webapp_table_id,
42
+ { ...body }
43
+ );
44
+
45
+ return response;
46
+ });
47
+ }
@@ -0,0 +1,213 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import {
4
+ createPayee,
5
+ createPayeeCategory,
6
+ createPriceList,
7
+ deletePayeeCategory,
8
+ deletePriceList,
9
+ getPayeeCategoriesByNotesMatch,
10
+ getPaymentTermById,
11
+ getVariablesByName,
12
+ updatePayeeCategory,
13
+ updatePaymentTerm,
14
+ } from "@zauru-sdk/services";
15
+ import {
16
+ AxiosUtilsResponse,
17
+ CreatePriceListBody,
18
+ PayeeCategoryGraphQL,
19
+ PayeeGraphQL,
20
+ } from "@zauru-sdk/types";
21
+
22
+ export const TEXT_PAYEE_CATEGORY_NOTES_FOR_PRICE =
23
+ "CATEGORIA_QUE_REPRESENTA_UN_PRECIO_DE_LABORATORIO (No borrar esto): ";
24
+
25
+ export const TEXT_PAYEE_CATEGORY_NAME_FOR_PRICE = "CAT-LABORATORIO: ";
26
+
27
+ /**
28
+ * getClientesLaboratorio
29
+ * @param session
30
+ * @param headers
31
+ * @returns
32
+ */
33
+ export async function getClientesLaboratorio(
34
+ session: Session
35
+ ): Promise<AxiosUtilsResponse<PayeeGraphQL[]>> {
36
+ return handlePossibleAxiosErrors(async () => {
37
+ const clientesResponse = await getPayeeCategoriesByNotesMatch(
38
+ session,
39
+ TEXT_PAYEE_CATEGORY_NOTES_FOR_PRICE
40
+ );
41
+
42
+ if (clientesResponse.error || !clientesResponse.data) {
43
+ throw new Error(clientesResponse.userMsg);
44
+ }
45
+
46
+ const clientes: PayeeGraphQL[] = [];
47
+ clientesResponse.data.forEach((x) => clientes.push(...x.payees));
48
+
49
+ return clientes;
50
+ });
51
+ }
52
+
53
+ /**
54
+ * createNewLaboratoryClient
55
+ * @param session
56
+ * @param headers
57
+ * @param body
58
+ * @returns
59
+ */
60
+ export async function createNewLaboratoryClient(
61
+ headers: any,
62
+ body: Partial<PayeeGraphQL>
63
+ ): Promise<AxiosUtilsResponse<boolean>> {
64
+ return handlePossibleAxiosErrors(async () => {
65
+ const sendBody = {
66
+ ...body,
67
+ vendor: false,
68
+ currency_id: 1,
69
+ buyer: true,
70
+ service_provider: true,
71
+ } as PayeeGraphQL;
72
+
73
+ const createResponse = await createPayee(headers, sendBody);
74
+
75
+ if (!createResponse.data) {
76
+ throw new Error(
77
+ `Ocurrió un error al intentar crear el cliente: ${createResponse.userMsg}`
78
+ );
79
+ }
80
+
81
+ return true;
82
+ });
83
+ }
84
+
85
+ /**
86
+ * createNewLaboratoryClientCategoryPrice
87
+ * @param session
88
+ * @param headers
89
+ * @param body
90
+ * @returns
91
+ */
92
+ export async function updateLaboratoryClientCategoryPrice(
93
+ headers: any,
94
+ body: Partial<PayeeCategoryGraphQL>
95
+ ): Promise<AxiosUtilsResponse<boolean>> {
96
+ return handlePossibleAxiosErrors(async () => {
97
+ const sendBody: Partial<PayeeCategoryGraphQL> = {
98
+ ...body,
99
+ name: `${TEXT_PAYEE_CATEGORY_NAME_FOR_PRICE}${body.name ?? ""}`,
100
+ notes: `${TEXT_PAYEE_CATEGORY_NOTES_FOR_PRICE}${body.notes ?? ""}`,
101
+ };
102
+
103
+ const createResponse = await updatePayeeCategory(headers, sendBody);
104
+
105
+ if (!createResponse.data || createResponse.error) {
106
+ throw new Error(
107
+ `Ocurrió un error al intentar editar la categoría de cliente: ${createResponse.userMsg}`
108
+ );
109
+ }
110
+
111
+ return true;
112
+ });
113
+ }
114
+
115
+ /**
116
+ * createNewLaboratoryClientCategoryPrice
117
+ * @param session
118
+ * @param headers
119
+ * @param body
120
+ * @returns
121
+ */
122
+ export async function createNewLaboratoryClientCategoryPrice(
123
+ headers: any,
124
+ session: Session,
125
+ body: Partial<PayeeCategoryGraphQL>
126
+ ): Promise<AxiosUtilsResponse<boolean>> {
127
+ return handlePossibleAxiosErrors(async () => {
128
+ const sendBody: Partial<PayeeCategoryGraphQL> = {
129
+ ...body,
130
+ name: `${TEXT_PAYEE_CATEGORY_NAME_FOR_PRICE}${body.name ?? ""}`,
131
+ notes: `${TEXT_PAYEE_CATEGORY_NOTES_FOR_PRICE}${body.notes ?? ""}`,
132
+ };
133
+
134
+ const createResponse = await createPayeeCategory(headers, sendBody);
135
+
136
+ if (!createResponse.data || createResponse.error) {
137
+ throw new Error(
138
+ `Ocurrió un error al intentar crear la categoría de cliente: ${createResponse.userMsg}`
139
+ );
140
+ }
141
+
142
+ //Luego creo el listado de precios también
143
+ const sendBodyPriceList: CreatePriceListBody = {
144
+ client_exclusive: true,
145
+ name: `PRECIO_LABORATORIO: ${body.name}`,
146
+ description: `Listado de precio asociado a la categoría de cliente: ${body.name} id: ${createResponse.data?.id}`,
147
+ payee_category_ids: [createResponse.data.id?.toString()],
148
+ };
149
+
150
+ const createPriceResponse = await createPriceList(
151
+ headers,
152
+ sendBodyPriceList
153
+ );
154
+
155
+ if (!createPriceResponse.data || createPriceResponse.error) {
156
+ throw new Error(
157
+ `Ocurrió un error al intentar crear el listado de precio: ${createPriceResponse.userMsg}`
158
+ );
159
+ }
160
+
161
+ //Por último, asigno la categoría de empleados al término de pago de laboratorio
162
+ const { lab_payment_term_default_id } = await getVariablesByName(
163
+ headers,
164
+ session,
165
+ ["lab_payment_term_default_id"]
166
+ );
167
+ const paymentTermResponse = await getPaymentTermById(
168
+ session,
169
+ lab_payment_term_default_id
170
+ );
171
+ if (!paymentTermResponse.data || paymentTermResponse.error) {
172
+ throw new Error(
173
+ `Ocurrió un error al intentar encontrar el término de pago: ${paymentTermResponse.userMsg}`
174
+ );
175
+ }
176
+
177
+ const updatePaymentTermResponse = await updatePaymentTerm(headers, {
178
+ id: Number(lab_payment_term_default_id),
179
+ payee_category_ids: [
180
+ ...paymentTermResponse?.data?.allowed_payment_terms?.map((x) =>
181
+ x.payee_category_id.toString()
182
+ ),
183
+ createResponse.data.id?.toString(),
184
+ ],
185
+ });
186
+
187
+ if (!updatePaymentTermResponse.data || updatePaymentTermResponse.error) {
188
+ throw new Error(
189
+ `Ocurrió un error al intentar actualizar el término de pago: ${updatePaymentTermResponse.userMsg}`
190
+ );
191
+ }
192
+ return true;
193
+ });
194
+ }
195
+
196
+ /**
197
+ * deleteLaboratoryClientCategoryPrice
198
+ * @param headers
199
+ * @param body
200
+ * @returns
201
+ */
202
+ export async function deleteLaboratoryClientCategoryPrice(
203
+ headers: any,
204
+ body: Partial<PayeeCategoryGraphQL>
205
+ ): Promise<AxiosUtilsResponse<boolean>> {
206
+ return handlePossibleAxiosErrors(async () => {
207
+ //Elimino la categoría
208
+ await deletePayeeCategory(headers, body.id ?? "");
209
+ //Elimino la lista de precios
210
+ await deletePriceList(headers, body.price_list_id ?? "");
211
+ return true;
212
+ });
213
+ }
@@ -0,0 +1,44 @@
1
+ import { ProfileResponse, SelectFieldOption } from "@zauru-sdk/types";
2
+
3
+ /**
4
+ *
5
+ * @param profileInfoObject
6
+ * @returns
7
+ */
8
+ export function getInitialProfileInfo(profileInfoObject?: ProfileResponse) {
9
+ if (!Object.keys(profileInfoObject ?? {}).length || !profileInfoObject) {
10
+ return {
11
+ profileLabelInfo: [
12
+ { label: "Nombre", value: "Cargando..." },
13
+ { label: "E Mail", value: "Cargando..." },
14
+ ] as SelectFieldOption[],
15
+ membershipsInfo: [
16
+ {
17
+ entity: "Cargando...",
18
+ contractExpiration: "Cargando...",
19
+ nextPay: "Cargando...",
20
+ entityId: 0,
21
+ },
22
+ ],
23
+ };
24
+ }
25
+
26
+ const profile = profileInfoObject.profile;
27
+ const profileLabelInfo = [
28
+ { label: "Nombre", value: profile.name },
29
+ { label: "E Mail", value: profile.email },
30
+ ] as SelectFieldOption[];
31
+
32
+ const membershipsInfo = profileInfoObject.memberships.map(
33
+ (membership: any) => {
34
+ return {
35
+ entity: membership.entity.name,
36
+ contractExpiration: membership.eternal ? "NUNCA" : "EXPIRA",
37
+ nextPay: new Date(Date.parse(membership.expires)).toLocaleDateString(),
38
+ entityId: membership.entity_id,
39
+ };
40
+ }
41
+ );
42
+
43
+ return { profileLabelInfo, membershipsInfo };
44
+ }
@@ -0,0 +1,67 @@
1
+ import type { Session } from "@remix-run/node";
2
+ import { handlePossibleAxiosErrors } from "@zauru-sdk/common";
3
+ import {
4
+ getPurchasesListDataTables,
5
+ getVariablesByName,
6
+ } from "@zauru-sdk/services";
7
+ import {
8
+ AxiosUtilsResponse,
9
+ BasicIdNameSchema,
10
+ DataTablesFilterBody,
11
+ } from "@zauru-sdk/types";
12
+
13
+ /**
14
+ * getProvidersList
15
+ * @param headers
16
+ * @param session
17
+ * @param byReceptions
18
+ * @returns
19
+ */
20
+ export const getProvidersList = async (
21
+ headers: any,
22
+ session: Session,
23
+ byReceptions: boolean = true
24
+ ): Promise<
25
+ AxiosUtilsResponse<{
26
+ vendors: BasicIdNameSchema[];
27
+ vendors_categories: BasicIdNameSchema[];
28
+ }>
29
+ > => {
30
+ return handlePossibleAxiosErrors(async () => {
31
+ let tag_id = undefined;
32
+ if (byReceptions) {
33
+ const { recepciones_tag_id } = await getVariablesByName(
34
+ headers,
35
+ session,
36
+ ["recepciones_tag_id"]
37
+ );
38
+ tag_id = recepciones_tag_id;
39
+ }
40
+
41
+ //Obtengo los proveedores, que vienen en el endpoint de órdenes de compra
42
+ const body: DataTablesFilterBody = {
43
+ order: { "0": { column: "1", dir: "desc" } },
44
+ start: 0,
45
+ length: 1,
46
+ search: { value: "", regex: false },
47
+ tag: tag_id,
48
+ agency: session.get("agency_id") ?? "",
49
+ };
50
+
51
+ //Voy por las ordenes y las ordeno por fecha de recepción
52
+ const ordersDataTablesResponse = await getPurchasesListDataTables(
53
+ headers,
54
+ body
55
+ );
56
+
57
+ if (ordersDataTablesResponse.error)
58
+ throw new Error(ordersDataTablesResponse.userMsg);
59
+
60
+ const ordersDataTables = ordersDataTablesResponse.data;
61
+
62
+ return {
63
+ vendors: ordersDataTables?.vendors ?? [],
64
+ vendors_categories: ordersDataTables?.vendor_categories ?? [],
65
+ };
66
+ });
67
+ };