@zauru-sdk/utils 1.0.49 → 1.0.52
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/dist/cjs/index.js +40 -0
- package/dist/cjs/zauru/4pinos-receptions-form-history.utils.js +80 -0
- package/dist/cjs/zauru/automatic-number.utils.js +28 -0
- package/dist/cjs/zauru/bitacora-edicion-masiva.utils.js +56 -0
- package/dist/cjs/zauru/bundles.utils.js +168 -0
- package/dist/cjs/zauru/cases.utils.js +21 -0
- package/dist/cjs/zauru/consolidated-history.utils.js +58 -0
- package/dist/cjs/zauru/costos-items.utils.js +617 -0
- package/dist/cjs/zauru/deliveries.utils.js +50 -0
- package/dist/cjs/zauru/discharges-histsory.utils.js +52 -0
- package/dist/cjs/zauru/employees.utils.js +44 -0
- package/dist/cjs/zauru/form.utils.js +160 -0
- package/dist/cjs/zauru/invoices.utils.js +85 -0
- package/dist/cjs/zauru/items.utils.js +126 -0
- package/dist/cjs/zauru/lotes.utils.js +313 -0
- package/dist/cjs/zauru/motivos-rechazo.utils.js +23 -0
- package/dist/cjs/zauru/payees.utils.js +136 -0
- package/dist/cjs/zauru/profiles.utils.js +41 -0
- package/dist/cjs/zauru/providers.utils.js +40 -0
- package/dist/cjs/zauru/purchase-orders.utils.js +390 -0
- package/dist/cjs/zauru/shipments.utils.js +95 -0
- package/dist/cjs/zauru/specialItem.utils.js +69 -0
- package/dist/cjs/zauru/templates.utils.js +102 -0
- package/dist/cjs/zauru/tiposMuestra.utils.js +69 -0
- package/dist/cjs/zauru/webapp-tables.utils.js +20 -0
- package/package.json +13 -10
- package/CHANGELOG.md +0 -248
- package/src/index.ts +0 -24
- package/src/zauru/4pinos-receptions-form-history.utils.ts +0 -142
- package/src/zauru/automatic-number.utils.ts +0 -38
- package/src/zauru/bitacora-edicion-masiva.utils.ts +0 -99
- package/src/zauru/bundles.utils.ts +0 -251
- package/src/zauru/cases.utils.ts +0 -31
- package/src/zauru/consolidated-history.utils.ts +0 -102
- package/src/zauru/costos-items.utils.ts +0 -871
- package/src/zauru/deliveries.utils.ts +0 -77
- package/src/zauru/discharges-histsory.utils.ts +0 -105
- package/src/zauru/employees.utils.ts +0 -59
- package/src/zauru/form.utils.ts +0 -243
- package/src/zauru/invoices.utils.ts +0 -114
- package/src/zauru/items.utils.ts +0 -221
- package/src/zauru/lotes.utils.ts +0 -411
- package/src/zauru/motivos-rechazo.utils.ts +0 -47
- package/src/zauru/payees.utils.ts +0 -213
- package/src/zauru/profiles.utils.ts +0 -44
- package/src/zauru/providers.utils.ts +0 -67
- package/src/zauru/purchase-orders.utils.ts +0 -594
- package/src/zauru/shipments.utils.ts +0 -139
- package/src/zauru/specialItem.utils.ts +0 -136
- package/src/zauru/templates.utils.ts +0 -199
- package/src/zauru/tiposMuestra.utils.ts +0 -136
- package/src/zauru/webapp-tables.utils.ts +0 -36
- package/tsconfig.json +0 -24
- /package/dist/{index.js → esm/index.js} +0 -0
- /package/dist/{zauru → esm/zauru}/4pinos-receptions-form-history.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/automatic-number.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/bitacora-edicion-masiva.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/bundles.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/cases.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/consolidated-history.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/costos-items.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/deliveries.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/discharges-histsory.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/employees.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/form.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/invoices.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/items.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/lotes.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/motivos-rechazo.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/payees.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/profiles.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/providers.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/purchase-orders.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/shipments.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/specialItem.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/templates.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/tiposMuestra.utils.js +0 -0
- /package/dist/{zauru → esm/zauru}/webapp-tables.utils.js +0 -0
package/src/zauru/items.utils.ts
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import {
|
|
3
|
-
extractValueBetweenTags,
|
|
4
|
-
handlePossibleAxiosErrors,
|
|
5
|
-
} from "@zauru-sdk/common";
|
|
6
|
-
import {
|
|
7
|
-
createItem,
|
|
8
|
-
createItemCategory,
|
|
9
|
-
getItemCategoriesBySuperCategoryId,
|
|
10
|
-
getItemsByCategoryId,
|
|
11
|
-
getItemsBySuperCategoryId,
|
|
12
|
-
getVariablesByName,
|
|
13
|
-
} from "@zauru-sdk/services";
|
|
14
|
-
import {
|
|
15
|
-
AxiosUtilsResponse,
|
|
16
|
-
ItemGraphQL,
|
|
17
|
-
SearchItemParams,
|
|
18
|
-
ItemDataTable,
|
|
19
|
-
ResponseItemList,
|
|
20
|
-
HTMLItemListSchema,
|
|
21
|
-
ItemCategoryGraphQL,
|
|
22
|
-
} from "@zauru-sdk/types";
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
* @param headers
|
|
27
|
-
* @param session
|
|
28
|
-
* @returns
|
|
29
|
-
*/
|
|
30
|
-
export const getItemsByReceptionCategory = async (
|
|
31
|
-
headers: any,
|
|
32
|
-
session: Session
|
|
33
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL[]>> => {
|
|
34
|
-
return handlePossibleAxiosErrors(async () => {
|
|
35
|
-
const { recepciones_item_category_id } = await getVariablesByName(
|
|
36
|
-
headers,
|
|
37
|
-
session,
|
|
38
|
-
["recepciones_item_category_id"]
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
const response = await getItemsByCategoryId(
|
|
42
|
-
session,
|
|
43
|
-
recepciones_item_category_id
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
if (response.error) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
`Ocurrió un error al consultar los items por categoría de recepción: ${response.userMsg}`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return response?.data ?? [];
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
*
|
|
58
|
-
* @param headers
|
|
59
|
-
* @param session
|
|
60
|
-
* @returns
|
|
61
|
-
*/
|
|
62
|
-
export const getItemsByLabCategory = async (
|
|
63
|
-
headers: any,
|
|
64
|
-
session: Session
|
|
65
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL[]>> => {
|
|
66
|
-
return handlePossibleAxiosErrors(async () => {
|
|
67
|
-
const { lab_super_category_item_id, lab_agency_id } =
|
|
68
|
-
await getVariablesByName(headers, session, [
|
|
69
|
-
"lab_super_category_item_id",
|
|
70
|
-
"lab_agency_id",
|
|
71
|
-
]);
|
|
72
|
-
|
|
73
|
-
const response = await getItemsBySuperCategoryId(
|
|
74
|
-
session,
|
|
75
|
-
lab_super_category_item_id,
|
|
76
|
-
lab_agency_id
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
if (response.error) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
`Ocurrió un error al consultar los items por categoría de laboratorio: ${response.userMsg}`
|
|
82
|
-
);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return response?.data ?? [];
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
*
|
|
91
|
-
* @param headers
|
|
92
|
-
* @param session
|
|
93
|
-
* @returns
|
|
94
|
-
*/
|
|
95
|
-
export const getItemServicesByLabCategory = async (
|
|
96
|
-
headers: any,
|
|
97
|
-
session: Session
|
|
98
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL[]>> => {
|
|
99
|
-
return handlePossibleAxiosErrors(async () => {
|
|
100
|
-
const { lab_services_item_category_id } = await getVariablesByName(
|
|
101
|
-
headers,
|
|
102
|
-
session,
|
|
103
|
-
["lab_services_item_category_id"]
|
|
104
|
-
);
|
|
105
|
-
|
|
106
|
-
const response = await getItemsByCategoryId(
|
|
107
|
-
session,
|
|
108
|
-
lab_services_item_category_id
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
if (response.error) {
|
|
112
|
-
throw new Error(
|
|
113
|
-
`Ocurrió un error al consultar los items-servicios por categoría de laboratorio: ${response.userMsg}`
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return response?.data ?? [];
|
|
118
|
-
});
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* getLabItemCategories
|
|
123
|
-
* @param session
|
|
124
|
-
* @param headers
|
|
125
|
-
* @returns
|
|
126
|
-
*/
|
|
127
|
-
export const getLabItemCategories = (
|
|
128
|
-
headers: any,
|
|
129
|
-
session: Session
|
|
130
|
-
): Promise<AxiosUtilsResponse<ItemCategoryGraphQL[]>> => {
|
|
131
|
-
return handlePossibleAxiosErrors(async () => {
|
|
132
|
-
const { lab_super_category_item_id } = await getVariablesByName(
|
|
133
|
-
headers,
|
|
134
|
-
session,
|
|
135
|
-
["lab_super_category_item_id"]
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const response = await getItemCategoriesBySuperCategoryId(
|
|
139
|
-
session,
|
|
140
|
-
lab_super_category_item_id
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
if (response.error || !response.data) {
|
|
144
|
-
throw new Error(response.userMsg);
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
return response.data;
|
|
148
|
-
});
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
/**
|
|
152
|
-
* createNewLaboratoryClient
|
|
153
|
-
* @param session
|
|
154
|
-
* @param headers
|
|
155
|
-
* @param body
|
|
156
|
-
* @returns
|
|
157
|
-
*/
|
|
158
|
-
export const createNewLaboratoryItemCategory = (
|
|
159
|
-
session: Session,
|
|
160
|
-
headers: any,
|
|
161
|
-
body: Partial<ItemCategoryGraphQL>
|
|
162
|
-
): Promise<AxiosUtilsResponse<boolean>> => {
|
|
163
|
-
return handlePossibleAxiosErrors(async () => {
|
|
164
|
-
const { lab_super_category_item_id } = await getVariablesByName(
|
|
165
|
-
headers,
|
|
166
|
-
session,
|
|
167
|
-
["lab_super_category_item_id"]
|
|
168
|
-
);
|
|
169
|
-
|
|
170
|
-
const sendBody = {
|
|
171
|
-
...body,
|
|
172
|
-
item_super_category_id: Number(lab_super_category_item_id),
|
|
173
|
-
color: "#ff0000",
|
|
174
|
-
} as ItemCategoryGraphQL;
|
|
175
|
-
|
|
176
|
-
const createResponse = await createItemCategory(headers, sendBody);
|
|
177
|
-
|
|
178
|
-
if (!createResponse.data) {
|
|
179
|
-
throw new Error(
|
|
180
|
-
`Ocurrió un error al intentar crear el item category: ${createResponse.userMsg}`
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return true;
|
|
185
|
-
});
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* createNewLaboratoryItem
|
|
190
|
-
* @param session
|
|
191
|
-
* @param headers
|
|
192
|
-
* @param body
|
|
193
|
-
* @returns
|
|
194
|
-
*/
|
|
195
|
-
export const createNewLaboratoryItem = (
|
|
196
|
-
headers: any,
|
|
197
|
-
body: Partial<ItemGraphQL>
|
|
198
|
-
): Promise<AxiosUtilsResponse<ItemGraphQL>> => {
|
|
199
|
-
return handlePossibleAxiosErrors(async () => {
|
|
200
|
-
const sendBody = {
|
|
201
|
-
active: true,
|
|
202
|
-
sellable: true,
|
|
203
|
-
quotable: true,
|
|
204
|
-
ecommerce: false,
|
|
205
|
-
purchasable: true,
|
|
206
|
-
weight: 0,
|
|
207
|
-
color: "#cccccc",
|
|
208
|
-
...body,
|
|
209
|
-
} as ItemGraphQL;
|
|
210
|
-
|
|
211
|
-
const createResponse = await createItem(headers, sendBody);
|
|
212
|
-
|
|
213
|
-
if (!createResponse.data || createResponse.error) {
|
|
214
|
-
throw new Error(
|
|
215
|
-
`Ocurrió un error al intentar crear el item: ${createResponse.userMsg}`
|
|
216
|
-
);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return createResponse.data;
|
|
220
|
-
});
|
|
221
|
-
};
|
package/src/zauru/lotes.utils.ts
DELETED
|
@@ -1,411 +0,0 @@
|
|
|
1
|
-
import type { Session } from "@remix-run/node";
|
|
2
|
-
import { getBasketsSchema, reduceAdd, toFixedIfNeeded } from "@zauru-sdk/common";
|
|
3
|
-
import { createNewReception, enablePurchase, getDeliveryByBooking, getLote, getLotesFiltered, getPurchase, getPurchaseOrder, getVariablesByName, insertBookings, saveMotivosDeRechazoByPurchase, updateLote, updatePurchaseOrder } from "@zauru-sdk/services";
|
|
4
|
-
import { BasketSchema, InsertBookingBody, NewReceptionBody, UpdatePurchaseOrderBody } from "@zauru-sdk/types";
|
|
5
|
-
import { getPurchaseOrderDataTables } from "./purchase-orders.utils.js";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Obtiene el listado de ordenes de compra, formateado especialmente para armar la tabla de edición de porcentajes de rechazo
|
|
9
|
-
* @param headers
|
|
10
|
-
* @param session
|
|
11
|
-
* @returns
|
|
12
|
-
*/
|
|
13
|
-
export const getLotesFormated = async (headers: any, session: Session) => {
|
|
14
|
-
//PASO 1: Obtengo las variables, para buscar mi tag_id y mi basket_id
|
|
15
|
-
const {
|
|
16
|
-
recepciones_basket_item_id: basket_id,
|
|
17
|
-
production_agency_id /**{5693: 5696} */,
|
|
18
|
-
} = await getVariablesByName(headers, session, [
|
|
19
|
-
"recepciones_basket_item_id",
|
|
20
|
-
"production_agency_id",
|
|
21
|
-
]);
|
|
22
|
-
const hashAgencyId = JSON.parse(production_agency_id ?? "{}");
|
|
23
|
-
const agency_id = hashAgencyId[session.get("agency_id")];
|
|
24
|
-
|
|
25
|
-
//PASO 2: Busco mis lotes
|
|
26
|
-
if (agency_id) {
|
|
27
|
-
return await getLotesFiltered(headers, agency_id, false, Number(basket_id));
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return [];
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* procesarLote
|
|
35
|
-
* @param headers
|
|
36
|
-
* @param session
|
|
37
|
-
* @param data
|
|
38
|
-
* @param byPercent
|
|
39
|
-
*/
|
|
40
|
-
export const procesarLote = async (
|
|
41
|
-
headers: any,
|
|
42
|
-
session: Session,
|
|
43
|
-
data: any,
|
|
44
|
-
poId: number | string
|
|
45
|
-
) => {
|
|
46
|
-
//=====================================================================================
|
|
47
|
-
//=====================================================================================
|
|
48
|
-
//PASO 1: OBTENER TODAS LAS VARIABLES QUE VAMOS A UTILIZAR EN EL FLUJO
|
|
49
|
-
const {
|
|
50
|
-
production_agency,
|
|
51
|
-
operative_rejection_agency_id,
|
|
52
|
-
recepciones_basket_item_id: basket_id,
|
|
53
|
-
} = await getVariablesByName(headers, session, [
|
|
54
|
-
"production_agency",
|
|
55
|
-
"operative_rejection_agency_id",
|
|
56
|
-
"recepciones_basket_item_id",
|
|
57
|
-
]);
|
|
58
|
-
const session_agency_id = session.get("agency_id");
|
|
59
|
-
const hashObject = JSON.parse(operative_rejection_agency_id);
|
|
60
|
-
const op_rejection_agency_id = hashObject[session_agency_id];
|
|
61
|
-
|
|
62
|
-
//PARSEO DE LA INFORMACIÓN QUE VIENE DEL SUBMIT
|
|
63
|
-
const byPercent = data.byPercent === "true";
|
|
64
|
-
const porcentajeRechazo = !byPercent
|
|
65
|
-
? toFixedIfNeeded(
|
|
66
|
-
(Number(data.lbRechazo ?? "0") /
|
|
67
|
-
(Number(data?.lbRechazo ?? "0") + Number(data.lbBueno))) *
|
|
68
|
-
100
|
|
69
|
-
)
|
|
70
|
-
: data.porcentajeRechazo;
|
|
71
|
-
const basket_keys = Object.keys(data).filter((x) => x.includes("basket-"));
|
|
72
|
-
const baskets_regresadas = basket_keys.map((basket_key: string) => {
|
|
73
|
-
//ejemplo de una key: basket-CONVENCIONAL-58281
|
|
74
|
-
const splited = basket_key.split("-");
|
|
75
|
-
return {
|
|
76
|
-
id: splited[2] || 0,
|
|
77
|
-
color: splited[1] || "",
|
|
78
|
-
total: Number(data[basket_key]) || 0,
|
|
79
|
-
} as BasketSchema;
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
//1.2 OBTENER LA INFORMACIÓN DEL LOTE A PROCESAR (LA TOMO DE LA QUE YA TENGO AL CARGAR LA INFO)
|
|
83
|
-
const purchaseOrderResponse = await getPurchaseOrder(session, poId, {
|
|
84
|
-
withLotStocksToMyAgency: true,
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
if (purchaseOrderResponse.error || !purchaseOrderResponse?.data) {
|
|
88
|
-
throw new Error(
|
|
89
|
-
`Error al intentar encontrar la órden de compra: ${purchaseOrderResponse.userMsg}`
|
|
90
|
-
);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const purchaseOrder = purchaseOrderResponse.data;
|
|
94
|
-
const lbsEsperadas = purchaseOrder.lots[0].lot_stocks[0].available;
|
|
95
|
-
|
|
96
|
-
const lbsMalas = lbsEsperadas * (Number(porcentajeRechazo) / 100);
|
|
97
|
-
const lbsBuenas = lbsEsperadas - lbsMalas;
|
|
98
|
-
|
|
99
|
-
const baskets_memo = getBasketsSchema(purchaseOrder.memo);
|
|
100
|
-
const baskets_memo_quantity = baskets_memo
|
|
101
|
-
.map((basket) => basket.total)
|
|
102
|
-
.reduce(reduceAdd, 0);
|
|
103
|
-
|
|
104
|
-
//SI SE INGRESA POR LIBRAS, ES QUE SE ESTÁ INGRESANDO CANASTAS A DEVOLVER ETC Y HAY QUE HACER LOS ENVÍOS CORRESPONDIENTES
|
|
105
|
-
if (!byPercent) {
|
|
106
|
-
console.log("=============> PROCESANDO DATA POR PESO...");
|
|
107
|
-
//CUANDO NO ES POR PORCENTAJE DIRECTO HAY QUE HACER TODO EL FLUJO DE CREAR LOS ENVÍOS ETC...
|
|
108
|
-
//1.3: SE CREA EL ENVÍO DE VEGETALES Y CANASTAS DEVUELTOS POR CONTROL DE CALIDAD, (LOS QUE ESTÁN BUENOS)
|
|
109
|
-
//Las canastas vienen en data en campos como estos "basket-CONVENCIONAL-58281": "2",
|
|
110
|
-
const bodyGoodToProduction: InsertBookingBody = {
|
|
111
|
-
booker_id: Number(session.get("employee_id")),
|
|
112
|
-
needs_transport: false,
|
|
113
|
-
payee_id: purchaseOrder.payee_id,
|
|
114
|
-
memo: `${purchaseOrder.lots[0].id};${purchaseOrder.id_number};${
|
|
115
|
-
purchaseOrder.purchase_order_details[0]?.item?.name
|
|
116
|
-
};${purchaseOrder.purchase_order_details
|
|
117
|
-
.map((purchase) => Number(purchase.booked_quantity))
|
|
118
|
-
.reduce(reduceAdd, 0)};${baskets_memo_quantity};${porcentajeRechazo};${
|
|
119
|
-
purchaseOrder.delivery_date
|
|
120
|
-
}`,
|
|
121
|
-
planned_delivery: `${data.date}`,
|
|
122
|
-
agency_from_id: Number(session_agency_id), //agencia donde está loggeado mi usuario
|
|
123
|
-
agency_to_id: purchaseOrder.agency_id, //de donde viene la orden de compra
|
|
124
|
-
reference: "Vegetales buenos devueltos desde control de calidad.",
|
|
125
|
-
movements: [
|
|
126
|
-
{
|
|
127
|
-
item_id: purchaseOrder.purchase_order_details[0].item_id,
|
|
128
|
-
lot_id: purchaseOrder.lots[0].id,
|
|
129
|
-
reference: "Vegetales devueltos de CC",
|
|
130
|
-
booked_quantity: lbsBuenas,
|
|
131
|
-
},
|
|
132
|
-
],
|
|
133
|
-
};
|
|
134
|
-
/**
|
|
135
|
-
* Para las canastas
|
|
136
|
-
* el item_id = 490533 = recepciones_basket_item_id
|
|
137
|
-
* lot_id: código de la canasta,
|
|
138
|
-
* booked_quantity = cantidad de canastas que ingresa el usuario que va a devolver
|
|
139
|
-
*/
|
|
140
|
-
baskets_regresadas.forEach((basket: BasketSchema) => {
|
|
141
|
-
bodyGoodToProduction.movements.push({
|
|
142
|
-
item_id: Number(basket_id),
|
|
143
|
-
lot_id: basket.id,
|
|
144
|
-
reference: `Canasta ${basket.color}-${basket.id} devuelta a CC`,
|
|
145
|
-
booked_quantity: basket.total,
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
console.log("-------- Insertando booking con canastas buenas devueltas");
|
|
150
|
-
const goodVegetablesInserted = await insertBookings(
|
|
151
|
-
headers,
|
|
152
|
-
bodyGoodToProduction,
|
|
153
|
-
`${purchaseOrder.id}`
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
if (!goodVegetablesInserted.error && goodVegetablesInserted.data) {
|
|
157
|
-
//1.4 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
158
|
-
console.log("recibiendo la reserva: ", goodVegetablesInserted.data?.id);
|
|
159
|
-
await getDeliveryByBooking(headers, goodVegetablesInserted.data?.id);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (lbsMalas && lbsMalas > 0) {
|
|
163
|
-
//=====================================================================================
|
|
164
|
-
//=====================================================================================
|
|
165
|
-
//PASO 2: Envío con vegetales rechazados a bodega de PRODUCCIÓN desde la agencia del usuario loggeado
|
|
166
|
-
const bodyOchToProduction: InsertBookingBody = {
|
|
167
|
-
booker_id: Number(session.get("employee_id")),
|
|
168
|
-
needs_transport: false,
|
|
169
|
-
memo: "",
|
|
170
|
-
planned_delivery: `${data.date}`,
|
|
171
|
-
agency_from_id: Number(session_agency_id), //agencia donde está loggeado mi usuario
|
|
172
|
-
agency_to_id: Number(production_agency), //de donde viene la orden de compra
|
|
173
|
-
reference: "Envío de vegetales rechazados a la bodega de producción.",
|
|
174
|
-
movements: [
|
|
175
|
-
{
|
|
176
|
-
item_id: purchaseOrder.purchase_order_details[0].item_id,
|
|
177
|
-
lot_id: purchaseOrder.lots[0].id,
|
|
178
|
-
reference: "Vegetales rechazados de CC",
|
|
179
|
-
booked_quantity: lbsMalas,
|
|
180
|
-
},
|
|
181
|
-
],
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
console.log(
|
|
185
|
-
"--------- enviando a insertar booking de rechazo a la bodega de producción"
|
|
186
|
-
);
|
|
187
|
-
const ochToProductionVegetablesInserted = await insertBookings(
|
|
188
|
-
headers,
|
|
189
|
-
bodyOchToProduction,
|
|
190
|
-
`${purchaseOrder.id}`
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
if (
|
|
194
|
-
!ochToProductionVegetablesInserted.error &&
|
|
195
|
-
ochToProductionVegetablesInserted.data
|
|
196
|
-
) {
|
|
197
|
-
//2.1 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
198
|
-
console.log("Recibiendo booking de rechazo...");
|
|
199
|
-
await getDeliveryByBooking(
|
|
200
|
-
headers,
|
|
201
|
-
ochToProductionVegetablesInserted.data.id
|
|
202
|
-
);
|
|
203
|
-
}
|
|
204
|
-
//=====================================================================================
|
|
205
|
-
//=====================================================================================
|
|
206
|
-
//PASO 3: Envío con vegetales rechazados a bodega de RECHAZO desde la bodega de PRODUCCIÓN
|
|
207
|
-
//Sólo cambia el agency_from_id y el agency_to_id, de ahí lo demás lo mismo que PASO 2
|
|
208
|
-
bodyOchToProduction.agency_from_id = Number(production_agency);
|
|
209
|
-
bodyOchToProduction.agency_to_id = Number(op_rejection_agency_id);
|
|
210
|
-
bodyOchToProduction.reference =
|
|
211
|
-
"Envío de vegetales rechazados a la bodega de rechazo.";
|
|
212
|
-
|
|
213
|
-
console.log(
|
|
214
|
-
"--------- enviando a insertar booking de rechazo a la bodega de rechazo"
|
|
215
|
-
);
|
|
216
|
-
const ochToOchVegetablesInserted = await insertBookings(
|
|
217
|
-
headers,
|
|
218
|
-
bodyOchToProduction
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
if (
|
|
222
|
-
!ochToOchVegetablesInserted.error &&
|
|
223
|
-
ochToOchVegetablesInserted.data
|
|
224
|
-
) {
|
|
225
|
-
//3.1 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
226
|
-
await getDeliveryByBooking(
|
|
227
|
-
headers,
|
|
228
|
-
ochToOchVegetablesInserted.data?.id
|
|
229
|
-
);
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
//=====================================================================================
|
|
234
|
-
//=====================================================================================
|
|
235
|
-
//PASO 5: Modificación de canastas en el lote de verdura
|
|
236
|
-
//la misma description del detalle del lote pero modificando la cantidad de canastas que quedaron.
|
|
237
|
-
//ejemplo: original: 27-53311-VERDE,1-53313-ROJA,1-53317-CELESTE,3-53312-AZUL,3-53314-AMARILLA
|
|
238
|
-
//ahora: 27-53311-VERDE,1-53313-ROJA,1-53317-CELESTE,2-53312-AZUL,3-53314-AMARILLA // ahora sólo 2 azules porque no devolví una
|
|
239
|
-
const newDescriptions: Array<string> = [];
|
|
240
|
-
baskets_memo.forEach((basket: BasketSchema) => {
|
|
241
|
-
//Si existe una basket a regresar con el mismo id, pregunto cuantas va a regresar, para restarlas del total.
|
|
242
|
-
const basket_regresada = baskets_regresadas.find(
|
|
243
|
-
(x) => x.id === basket.id
|
|
244
|
-
);
|
|
245
|
-
const resta = basket_regresada?.total ?? 0;
|
|
246
|
-
newDescriptions.push(
|
|
247
|
-
`${basket.total - resta}-${basket.id}-${basket.color}`
|
|
248
|
-
);
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
await updateLote(headers, purchaseOrder.lots[0].id, {
|
|
252
|
-
lot: {
|
|
253
|
-
description: newDescriptions.join(","),
|
|
254
|
-
},
|
|
255
|
-
});
|
|
256
|
-
} else {
|
|
257
|
-
console.log("PROCESANDO DATA POR PORCENTAJE...");
|
|
258
|
-
//CUANDO NO ES POR PORCENTAJE DIRECTO HAY QUE HACER TODO EL FLUJO DE CREAR LOS ENVÍOS ETC...
|
|
259
|
-
//1.3: SE CREA EL ENVÍO DE VEGETALES Y CANASTAS DEVUELTOS POR CONTROL DE CALIDAD, (LOS QUE ESTÁN BUENOS)
|
|
260
|
-
//Las canastas vienen en data en campos como estos "basket-CONVENCIONAL-58281": "2",
|
|
261
|
-
const bodyGoodToProduction: InsertBookingBody = {
|
|
262
|
-
booker_id: Number(session.get("employee_id")),
|
|
263
|
-
needs_transport: false,
|
|
264
|
-
payee_id: purchaseOrder.payee_id,
|
|
265
|
-
memo: `${purchaseOrder.lots[0].id};${purchaseOrder.lots[0].name};${
|
|
266
|
-
purchaseOrder.purchase_order_details[0]?.item?.name
|
|
267
|
-
};${purchaseOrder.purchase_order_details
|
|
268
|
-
.map((detail) => Number(detail.booked_quantity))
|
|
269
|
-
.reduce(reduceAdd, 0)};${baskets_memo_quantity};${porcentajeRechazo};${
|
|
270
|
-
purchaseOrder.delivery_date
|
|
271
|
-
}`,
|
|
272
|
-
planned_delivery: `${data.date}`,
|
|
273
|
-
agency_from_id: Number(session_agency_id), //agencia donde está loggeado mi usuario
|
|
274
|
-
agency_to_id: purchaseOrder.agency_id, //de donde viene la orden de compra
|
|
275
|
-
reference: "Regreando vegetales buenos desde control de calidad.",
|
|
276
|
-
movements: [
|
|
277
|
-
{
|
|
278
|
-
item_id: purchaseOrder.purchase_order_details[0].item_id,
|
|
279
|
-
lot_id: purchaseOrder.lots[0].id,
|
|
280
|
-
reference: "Vegetales devueltos de CC",
|
|
281
|
-
booked_quantity: lbsEsperadas, //devuelvo la misma cantidad que fue enviada
|
|
282
|
-
},
|
|
283
|
-
],
|
|
284
|
-
};
|
|
285
|
-
/**
|
|
286
|
-
* Para las canastas
|
|
287
|
-
* el item_id = 490533 = recepciones_basket_item_id
|
|
288
|
-
* lot_id: código de la canasta,
|
|
289
|
-
* booked_quantity = cantidad de canastas que ingresa el usuario que va a devolver
|
|
290
|
-
*/
|
|
291
|
-
//Todas las canastas que fueron enviadas originalmente
|
|
292
|
-
baskets_memo.forEach((basket: BasketSchema) => {
|
|
293
|
-
bodyGoodToProduction.movements.push({
|
|
294
|
-
item_id: Number(basket_id),
|
|
295
|
-
lot_id: basket.id,
|
|
296
|
-
reference: `Canasta ${basket.color}-${basket.id} devuelta a CC`,
|
|
297
|
-
booked_quantity: basket.total,
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
console.log("-------- Insertando booking con canastas buenas devueltas");
|
|
301
|
-
const goodVegetablesInserted = await insertBookings(
|
|
302
|
-
headers,
|
|
303
|
-
bodyGoodToProduction,
|
|
304
|
-
`${purchaseOrder.id}`
|
|
305
|
-
);
|
|
306
|
-
|
|
307
|
-
//1.4 Recibir la reserva para que las cantidades se muevan correctamente a la bodega de destino
|
|
308
|
-
if (!goodVegetablesInserted.error && goodVegetablesInserted.data) {
|
|
309
|
-
console.log("A RECIBIR BOOKING - POR PORCENTAJE");
|
|
310
|
-
await getDeliveryByBooking(headers, goodVegetablesInserted.data.id);
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
//=====================================================================================
|
|
315
|
-
//=====================================================================================
|
|
316
|
-
//PASO 4: Modificación de porcentaje de rechazo en la orden de compra
|
|
317
|
-
//4.1 El primer paso es devolver la recepción recibida en la orden de compra.
|
|
318
|
-
//Primero se debe obtener el id de dicha recepción
|
|
319
|
-
const reception = purchaseOrder.receptions[0];
|
|
320
|
-
const reception_details = reception?.reception_details[0];
|
|
321
|
-
|
|
322
|
-
//4.2 Habilito la orden de compra
|
|
323
|
-
await enablePurchase(headers, purchaseOrder.id, reception?.id);
|
|
324
|
-
|
|
325
|
-
//4.3 Editar porcentajes de rechazo
|
|
326
|
-
const updateBodyPurchase = {
|
|
327
|
-
purchase_order: { discount: porcentajeRechazo },
|
|
328
|
-
} as UpdatePurchaseOrderBody;
|
|
329
|
-
await updatePurchaseOrder(headers, updateBodyPurchase, purchaseOrder.id);
|
|
330
|
-
|
|
331
|
-
//4.4 Crear una nueva recepcion
|
|
332
|
-
const bodyReception = {
|
|
333
|
-
reception: {
|
|
334
|
-
agency_id: reception.agency_id,
|
|
335
|
-
entity_id: reception.entity_id,
|
|
336
|
-
needs_transit: false,
|
|
337
|
-
purchase_order_id: purchaseOrder.id,
|
|
338
|
-
received_at: new Date(Date.now() + 12096e5).toISOString().split("T")[0],
|
|
339
|
-
invoice_number: `${reception.invoice_number ?? ""}`,
|
|
340
|
-
reception_details_attributes: {
|
|
341
|
-
"0": {
|
|
342
|
-
item_id: `${reception_details?.item_id}`,
|
|
343
|
-
lot_delivered_quantity: [reception_details?.lot_delivered_quantity],
|
|
344
|
-
lot_description: [reception_details?.lot_description],
|
|
345
|
-
lot_expire: [reception_details?.lot_expire],
|
|
346
|
-
lot_name: [reception_details?.lot_name],
|
|
347
|
-
purchase_order_detail_id: `${reception_details?.purchase_order_detail_id}`,
|
|
348
|
-
},
|
|
349
|
-
},
|
|
350
|
-
},
|
|
351
|
-
} as NewReceptionBody;
|
|
352
|
-
await createNewReception(headers, bodyReception, purchaseOrder.id);
|
|
353
|
-
|
|
354
|
-
//=====================================================================================
|
|
355
|
-
//=====================================================================================
|
|
356
|
-
//PASO 6: Guardar razones de rechazo en webapp table
|
|
357
|
-
await saveMotivosDeRechazoByPurchase(
|
|
358
|
-
headers,
|
|
359
|
-
session,
|
|
360
|
-
{
|
|
361
|
-
Razon_primaria: `${data.razonPrincipal ?? ""}`,
|
|
362
|
-
Razon_secundaria: `${data.razonSecundaria ?? ""}`,
|
|
363
|
-
Razon_terciaria: `${data.razonTerciaria ?? ""}`,
|
|
364
|
-
Canastas: `${data.ochBaskets ?? ""}`,
|
|
365
|
-
},
|
|
366
|
-
{
|
|
367
|
-
temp_purchase_order_id: `${purchaseOrder.id}`,
|
|
368
|
-
}
|
|
369
|
-
);
|
|
370
|
-
};
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
* Obtiene toda la información de lote, con las canastas y razones de rechazo
|
|
374
|
-
* @param headers
|
|
375
|
-
* @param session
|
|
376
|
-
* @returns
|
|
377
|
-
*/
|
|
378
|
-
export const getLoteDescription = async (
|
|
379
|
-
headers: any,
|
|
380
|
-
session: Session,
|
|
381
|
-
lote_id: number
|
|
382
|
-
) => {
|
|
383
|
-
//PASO 1: Obtengo las variables, para buscar mi basket_id
|
|
384
|
-
const { production_agency_id /**{5693: 5696} */ } = await getVariablesByName(
|
|
385
|
-
headers,
|
|
386
|
-
session,
|
|
387
|
-
["production_agency_id"]
|
|
388
|
-
);
|
|
389
|
-
const hashAgencyId = JSON.parse(production_agency_id ?? "{}");
|
|
390
|
-
const agency_id = hashAgencyId[session.get("agency_id")];
|
|
391
|
-
|
|
392
|
-
//PASO 2: Busco mi lote
|
|
393
|
-
const lote = await getLote(headers, lote_id, agency_id);
|
|
394
|
-
|
|
395
|
-
//PASO 3: Obtener listado de canastas enviadas a bodega control de calidad
|
|
396
|
-
//El primer paso es ubicar la orden de compra original, la cual permitirá ubicar el envío que se
|
|
397
|
-
//realizó a la bodega de control de calidad
|
|
398
|
-
const purchase_order = await getPurchaseOrderDataTables(
|
|
399
|
-
headers,
|
|
400
|
-
lote.name.replace("-RETENIDO", "") // por si trae la palabra RETENIDO,
|
|
401
|
-
);
|
|
402
|
-
|
|
403
|
-
//PASO 4: Obtener los envíos asociados a la orden de compra
|
|
404
|
-
const purchaseResponse = await getPurchase(headers, purchase_order.no_orden);
|
|
405
|
-
|
|
406
|
-
return {
|
|
407
|
-
lote,
|
|
408
|
-
purchase_order,
|
|
409
|
-
purchase: purchaseResponse.data,
|
|
410
|
-
};
|
|
411
|
-
};
|
|
@@ -1,47 +0,0 @@
|
|
|
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 const 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 const 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
|
-
};
|