@zauru-sdk/utils 1.0.109 → 1.0.110
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/zauru/4pinos-reception-register.utils.js +153 -144
- package/dist/cjs/zauru/4pinos-receptions-form-history.utils.js +2 -0
- package/dist/esm/zauru/4pinos-reception-register.utils.js +153 -144
- package/dist/esm/zauru/4pinos-receptions-form-history.utils.js +2 -0
- package/package.json +4 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.register4pinosReception = void 0;
|
|
4
|
+
const common_1 = require("@zauru-sdk/common");
|
|
4
5
|
const services_1 = require("@zauru-sdk/services");
|
|
5
6
|
const motivos_rechazo_utils_js_1 = require("./motivos-rechazo.utils.js");
|
|
6
7
|
const _4pinos_receptions_form_history_utils_js_1 = require("./4pinos-receptions-form-history.utils.js");
|
|
@@ -21,13 +22,9 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
21
22
|
}
|
|
22
23
|
const existentes = responsePOSearch?.data?.filter((x) => !x.voided);
|
|
23
24
|
if (existentes?.length > 0) {
|
|
24
|
-
throw new Error(`Ya existe una órden de compra con este número de contraseña asociado, revise el listado general. Peso: ${existentes[0].due}, Ingresado el:
|
|
25
|
-
existentes[0].issue_date
|
|
26
|
-
, Memo: ${existentes[0].memo}, Tipo: ${existentes[0].reference}`);
|
|
25
|
+
throw new Error(`Ya existe una órden de compra con este número de contraseña asociado, revise el listado general. Peso: ${existentes[0].due}, Ingresado el: ${(0, common_1.getFormattedDate)(existentes[0].issue_date, false)}, Memo: ${existentes[0].memo}, Tipo: ${existentes[0].reference}`);
|
|
27
26
|
}
|
|
28
27
|
}
|
|
29
|
-
const esCentroDeAcopio = values?.esCentroDeAcopio === "true";
|
|
30
|
-
const basketLots = JSON.parse(values?.basketLots.toString());
|
|
31
28
|
const webapp_table_rejection = {
|
|
32
29
|
Canastas: "int",
|
|
33
30
|
Razon_primaria: "string",
|
|
@@ -47,6 +44,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
47
44
|
const hashRecepcionesQCAgency = JSON.parse(fixedString ?? "{}");
|
|
48
45
|
const quality_control_agency = hashRecepcionesQCAgency[agency_id];
|
|
49
46
|
//-------------------REACT SELECT VALUES-------------------------
|
|
47
|
+
console.log("values", values);
|
|
50
48
|
const vendor = values.vendor;
|
|
51
49
|
const itemId = values.item;
|
|
52
50
|
const purchaser = values.purchaser;
|
|
@@ -54,6 +52,9 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
54
52
|
const idNumberInput = values.idNumberInput;
|
|
55
53
|
const discountReason = values.discountReason;
|
|
56
54
|
const issue_date = values.issue_date;
|
|
55
|
+
const esCentroDeAcopio = values?.esCentroDeAcopio === "true";
|
|
56
|
+
const singleBasketWeight = Number(values.singleBasketWeight);
|
|
57
|
+
const recepciones_basket_item_id = Number(values?.recepciones_basket_item_id.toString());
|
|
57
58
|
const rejections = JSON.parse(values.rejections.toString() ?? "[]");
|
|
58
59
|
const provenance = values.selectedProvenance;
|
|
59
60
|
const purchaseOrderGeneralInfo = JSON.parse(values?.purchaseOrderGeneralInfo?.toString() ?? "{}");
|
|
@@ -66,16 +67,16 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
66
67
|
};
|
|
67
68
|
let keys = Object.keys(values);
|
|
68
69
|
let netWeight = values.netWgt;
|
|
69
|
-
let singleBasketWeight = values.singleBasketWeight;
|
|
70
70
|
const total_baskets = values.totalBaskets + "";
|
|
71
|
-
const stockInteger = values.stockInteger
|
|
71
|
+
const stockInteger = values.stockInteger == "true";
|
|
72
72
|
let webapp_table_object = {};
|
|
73
73
|
const buildArray = (keyIncludes, processValue) => {
|
|
74
|
+
const regex = /\d/; // Expresión regular para buscar al menos un dígito.
|
|
74
75
|
return keys
|
|
75
|
-
.filter((key) => key.includes(keyIncludes))
|
|
76
|
-
.map((
|
|
77
|
-
|
|
78
|
-
processValue(values[
|
|
76
|
+
.filter((key) => key.includes(keyIncludes) && regex.test(key))
|
|
77
|
+
.map((key) => [
|
|
78
|
+
key.substring(keyIncludes?.length, key?.length),
|
|
79
|
+
processValue(values[key]),
|
|
79
80
|
])
|
|
80
81
|
.filter(([key, value]) => Number(value) > 0)
|
|
81
82
|
.map(([kv, val]) => `${val}-${kv}`);
|
|
@@ -84,7 +85,7 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
84
85
|
const regex = /\d/; // Expresión regular para buscar al menos un dígito.
|
|
85
86
|
return keys
|
|
86
87
|
.filter((key) => key.includes(keyIncludes) && regex.test(key))
|
|
87
|
-
.map((
|
|
88
|
+
.map((key) => processValue(values[key] === "" || values[key] === "NaN" ? 0 : values[key]));
|
|
88
89
|
};
|
|
89
90
|
const processValues = () => {
|
|
90
91
|
const received_baskets = buildArray("rec", parseInt);
|
|
@@ -107,146 +108,93 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
107
108
|
];
|
|
108
109
|
};
|
|
109
110
|
let [received_baskets, qualityControlBaskets, detail_baskets, detail_discounts, detail_weights,] = processValues();
|
|
110
|
-
//build net_weights
|
|
111
|
-
const detail_netWeights = keys
|
|
112
|
-
.filter((key) => key.includes("weight"))
|
|
113
|
-
.map((kbv, index) => (parseFloat(values[kbv]) -
|
|
114
|
-
(stockInteger
|
|
115
|
-
? 0
|
|
116
|
-
: detail_baskets[index] * parseFloat(singleBasketWeight))) *
|
|
117
|
-
((100 - detail_discounts[index]) / 100));
|
|
118
|
-
// //---------------------------PURCHASE ORDER OBJECT----------------------------------
|
|
119
|
-
console.log("========================================>");
|
|
120
|
-
console.log("paso 1: REGISTRANDO NUEVA ORDEN DE COMPRA AUTORIZADA...");
|
|
121
|
-
const newPurchaseOrderDetails = [];
|
|
122
|
-
detail_baskets.forEach((x, index) => {
|
|
123
|
-
newPurchaseOrderDetails.push({
|
|
124
|
-
reference: `${detail_weights[index]},${detail_baskets[index]},${detail_discounts[index]}`,
|
|
125
|
-
item_id: Number(itemId),
|
|
126
|
-
booked_quantity: detail_netWeights[index],
|
|
127
|
-
unit_cost: 1,
|
|
128
|
-
});
|
|
129
|
-
});
|
|
130
|
-
const newPurchaseOrderBody = {
|
|
131
|
-
reference: payeeType,
|
|
132
|
-
taxable: false,
|
|
133
|
-
issue_date,
|
|
134
|
-
shipping_date: issue_date,
|
|
135
|
-
incoterm_id: purchaseOrderGeneralInfo?.incoterm_id,
|
|
136
|
-
currency_id: purchaseOrderGeneralInfo?.currency_id,
|
|
137
|
-
charge_term_id: purchaseOrderGeneralInfo?.charge_term_id,
|
|
138
|
-
payee_info: vendor,
|
|
139
|
-
agency_id,
|
|
140
|
-
purchaser_id: Number(purchaser),
|
|
141
|
-
import: false,
|
|
142
|
-
tag_ids: ["", tag_id],
|
|
143
|
-
memo: qualityControlBaskets + "",
|
|
144
|
-
origin: netWeight,
|
|
145
|
-
purchase_order_details: newPurchaseOrderDetails,
|
|
146
|
-
incoterm_destination: provenance.slice(0, 254),
|
|
147
|
-
transport_type: discountReason,
|
|
148
|
-
id_number: idNumberInput,
|
|
149
|
-
...(esCentroDeAcopio
|
|
150
|
-
? { discount: Number(controlCalidadValues.porcentajeRechazo) }
|
|
151
|
-
: {}),
|
|
152
|
-
};
|
|
153
111
|
//========== PRIMERA LLAMADA DE API Y CAPTURA DE ERRORES
|
|
154
112
|
if (apiResponses.apiCall === 1) {
|
|
113
|
+
console.log("========================================>");
|
|
114
|
+
console.log("paso 1: REGISTRANDO NUEVA ORDEN DE COMPRA AUTORIZADA...");
|
|
115
|
+
//build net_weights
|
|
116
|
+
const detail_netWeights = keys
|
|
117
|
+
.filter((key) => key.includes("weight"))
|
|
118
|
+
.map((key, index) => {
|
|
119
|
+
const weight = Number(values[key]);
|
|
120
|
+
const detail_basket = Number(detail_baskets[index]);
|
|
121
|
+
const detail_discount = Number(detail_discounts[index]) ?? 0;
|
|
122
|
+
return ((weight - (stockInteger ? 0 : detail_basket * singleBasketWeight)) *
|
|
123
|
+
((100 - detail_discount) / 100));
|
|
124
|
+
});
|
|
125
|
+
const newPurchaseOrderDetails = detail_baskets.map((x, index) => {
|
|
126
|
+
return {
|
|
127
|
+
reference: `${detail_weights[index]},${x},${detail_discounts[index]}`,
|
|
128
|
+
item_id: Number(itemId),
|
|
129
|
+
booked_quantity: detail_netWeights[index],
|
|
130
|
+
unit_cost: 1,
|
|
131
|
+
};
|
|
132
|
+
});
|
|
133
|
+
const newPurchaseOrderBody = {
|
|
134
|
+
reference: payeeType,
|
|
135
|
+
taxable: false,
|
|
136
|
+
issue_date,
|
|
137
|
+
shipping_date: issue_date,
|
|
138
|
+
incoterm_id: purchaseOrderGeneralInfo?.incoterm_id,
|
|
139
|
+
currency_id: purchaseOrderGeneralInfo?.currency_id,
|
|
140
|
+
charge_term_id: purchaseOrderGeneralInfo?.charge_term_id,
|
|
141
|
+
payee_id: vendor,
|
|
142
|
+
agency_id,
|
|
143
|
+
purchaser_id: Number(purchaser),
|
|
144
|
+
import: false,
|
|
145
|
+
tag_ids: ["", tag_id],
|
|
146
|
+
memo: qualityControlBaskets + "",
|
|
147
|
+
origin: netWeight,
|
|
148
|
+
purchase_order_details: newPurchaseOrderDetails,
|
|
149
|
+
incoterm_destination: provenance.slice(0, 254),
|
|
150
|
+
transport_type: discountReason,
|
|
151
|
+
id_number: idNumberInput,
|
|
152
|
+
...(esCentroDeAcopio
|
|
153
|
+
? { discount: Number(controlCalidadValues.porcentajeRechazo) }
|
|
154
|
+
: {}),
|
|
155
|
+
};
|
|
155
156
|
console.log("REGISTRANDO ORDEN DE COMPRA: ", JSON.stringify(newPurchaseOrderBody));
|
|
156
157
|
const newAuthorizedPurchaseResponse = await (0, services_1.createNewAuthorizedPurchaseOrder)(headers, newPurchaseOrderBody, false);
|
|
157
158
|
if (newAuthorizedPurchaseResponse?.error ||
|
|
158
159
|
!newAuthorizedPurchaseResponse.data) {
|
|
159
160
|
throw new Error("Error al intentar crear la órden de compra autorizada: " +
|
|
160
|
-
newAuthorizedPurchaseResponse?.userMsg
|
|
161
|
+
newAuthorizedPurchaseResponse?.userMsg +
|
|
162
|
+
" Body: " +
|
|
163
|
+
JSON.stringify(newPurchaseOrderBody));
|
|
161
164
|
}
|
|
162
165
|
apiResponses.authorizedPO = newAuthorizedPurchaseResponse.data;
|
|
163
166
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
164
167
|
}
|
|
165
|
-
console.log("========================================>");
|
|
166
|
-
console.log("paso 2: CREANDO RECEPCION, ENVIO DE CANASTAS, WEBAPP TABLE DE RECHAZO DIRECTO");
|
|
167
|
-
const createNewReceptionBodyFunction = () => {
|
|
168
|
-
const receptionDetails = {};
|
|
169
|
-
apiResponses.authorizedPO.purchase_order_details.forEach((pod, index) => (receptionDetails[index] = {
|
|
170
|
-
item_id: `${pod.item_id}`,
|
|
171
|
-
purchase_order_detail_id: `${pod.id}`,
|
|
172
|
-
lot_delivered_quantity: [`${pod.booked_quantity}`],
|
|
173
|
-
lot_name: [apiResponses.authorizedPO.id_number],
|
|
174
|
-
lot_expire: [
|
|
175
|
-
new Date(Date.now() + 12096e5).toISOString().split("T")[0],
|
|
176
|
-
],
|
|
177
|
-
lot_description: [received_baskets.join(",")],
|
|
178
|
-
}));
|
|
179
|
-
const newReception = {
|
|
180
|
-
reception: {
|
|
181
|
-
agency_id,
|
|
182
|
-
received_at: issue_date,
|
|
183
|
-
purchase_order_id: apiResponses.authorizedPO.id + "",
|
|
184
|
-
entity_id: apiResponses.authorizedPO.entity_id + "",
|
|
185
|
-
needs_transit: "0",
|
|
186
|
-
invoice_number: "",
|
|
187
|
-
reception_details_attributes: receptionDetails,
|
|
188
|
-
},
|
|
189
|
-
};
|
|
190
|
-
return newReception;
|
|
191
|
-
};
|
|
192
|
-
const createBasketsShipmentBodyFunction = () => {
|
|
193
|
-
const movementDetails = [];
|
|
194
|
-
received_baskets.forEach((basket, index) => {
|
|
195
|
-
movementDetails.push({
|
|
196
|
-
item_id: basketLots?.recepciones_basket_item_id,
|
|
197
|
-
lot_id: basket.split("-")[1],
|
|
198
|
-
booked_quantity: basket.split("-")[0],
|
|
199
|
-
});
|
|
200
|
-
});
|
|
201
|
-
const BasketShipment = {
|
|
202
|
-
booker_id: Number(purchaser),
|
|
203
|
-
reference: "Envio de canastas (De proveedor a agencia)",
|
|
204
|
-
needs_transport: false,
|
|
205
|
-
planned_delivery: issue_date,
|
|
206
|
-
agency_from_id: Number(origin_agency),
|
|
207
|
-
agency_to_id: agency_id,
|
|
208
|
-
movements: movementDetails,
|
|
209
|
-
};
|
|
210
|
-
return BasketShipment;
|
|
211
|
-
};
|
|
212
|
-
const createQCBasketShipmentBody = async () => {
|
|
213
|
-
const qcMovementDetails = [];
|
|
214
|
-
qualityControlBaskets.forEach((basket) => {
|
|
215
|
-
qcMovementDetails.push({
|
|
216
|
-
item_id: basketLots?.recepciones_basket_item_id,
|
|
217
|
-
lot_id: Number(basket.split("-")[1]),
|
|
218
|
-
booked_quantity: Number(basket.split("-")[0]),
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
const total_qc_baskets = parseInt(values.totalQCBaskets + "");
|
|
222
|
-
const basket_weight = parseFloat(netWeight) / parseInt(total_baskets);
|
|
223
|
-
const lotResponse = await (0, services_1.getLoteByName)(session, apiResponses.authorizedPO.id_number);
|
|
224
|
-
if (lotResponse.error || !lotResponse.data) {
|
|
225
|
-
throw new Error("Error al intentar obtener el lote por nombre: " +
|
|
226
|
-
lotResponse?.userMsg);
|
|
227
|
-
}
|
|
228
|
-
if (lotResponse.data?.id) {
|
|
229
|
-
qcMovementDetails.push({
|
|
230
|
-
item_id: apiResponses.authorizedPO.purchase_order_details[0].item_id,
|
|
231
|
-
lot_id: Number(lotResponse.data.id),
|
|
232
|
-
booked_quantity: Number(Math.round(total_qc_baskets * basket_weight)), //TODO: Revisar si esto está bien así.
|
|
233
|
-
});
|
|
234
|
-
}
|
|
235
|
-
const qcBasketShipment = {
|
|
236
|
-
booker_id: Number(purchaser),
|
|
237
|
-
reference: "Envio de canastas y verduras a CC",
|
|
238
|
-
needs_transport: false,
|
|
239
|
-
planned_delivery: issue_date,
|
|
240
|
-
agency_from_id: agency_id,
|
|
241
|
-
agency_to_id: quality_control_agency,
|
|
242
|
-
movements: qcMovementDetails,
|
|
243
|
-
};
|
|
244
|
-
return qcBasketShipment;
|
|
245
|
-
};
|
|
246
|
-
//first create reception and receive it with the basket shipment
|
|
247
|
-
const newReception = createNewReceptionBodyFunction();
|
|
248
|
-
const newBasketShipment = createBasketsShipmentBodyFunction();
|
|
249
168
|
if (apiResponses.apiCall === 2) {
|
|
169
|
+
const createNewReceptionBodyFunction = () => {
|
|
170
|
+
const receptionDetails = {};
|
|
171
|
+
apiResponses.authorizedPO.purchase_order_details.forEach((pod, index) => (receptionDetails[index] = {
|
|
172
|
+
item_id: `${pod.item_id}`,
|
|
173
|
+
purchase_order_detail_id: `${pod.id}`,
|
|
174
|
+
lot_delivered_quantity: [`${pod.booked_quantity}`],
|
|
175
|
+
lot_name: [apiResponses.authorizedPO.id_number],
|
|
176
|
+
lot_expire: [
|
|
177
|
+
new Date(Date.now() + 12096e5).toISOString().split("T")[0],
|
|
178
|
+
],
|
|
179
|
+
lot_description: [received_baskets.join(",")],
|
|
180
|
+
}));
|
|
181
|
+
const newReception = {
|
|
182
|
+
reception: {
|
|
183
|
+
agency_id,
|
|
184
|
+
received_at: issue_date,
|
|
185
|
+
purchase_order_id: apiResponses.authorizedPO.id + "",
|
|
186
|
+
entity_id: apiResponses.authorizedPO.entity_id + "",
|
|
187
|
+
needs_transit: "0",
|
|
188
|
+
invoice_number: "",
|
|
189
|
+
reception_details_attributes: receptionDetails,
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
return newReception;
|
|
193
|
+
};
|
|
194
|
+
//first create reception and receive it with the basket shipment
|
|
195
|
+
const newReception = createNewReceptionBodyFunction();
|
|
196
|
+
console.log("========================================>");
|
|
197
|
+
console.log("paso 2: CREANDO RECEPCION, ENVIO DE CANASTAS, WEBAPP TABLE DE RECHAZO DIRECTO");
|
|
250
198
|
console.log("------------ CREANDO RECEPCIÓN.......");
|
|
251
199
|
const responseNewReception = await (0, services_1.createNewReception)(headers, newReception, apiResponses.authorizedPO.id);
|
|
252
200
|
if (responseNewReception.error || !responseNewReception.data) {
|
|
@@ -257,9 +205,33 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
257
205
|
}
|
|
258
206
|
if (apiResponses.apiCall === 3) {
|
|
259
207
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A LA AGENCIA");
|
|
208
|
+
const createBasketsShipmentBodyFunction = () => {
|
|
209
|
+
const movementDetails = [];
|
|
210
|
+
received_baskets.forEach((basket, index) => {
|
|
211
|
+
movementDetails.push({
|
|
212
|
+
item_id: recepciones_basket_item_id,
|
|
213
|
+
lot_id: basket.split("-")[1],
|
|
214
|
+
booked_quantity: basket.split("-")[0],
|
|
215
|
+
});
|
|
216
|
+
});
|
|
217
|
+
const BasketShipment = {
|
|
218
|
+
booker_id: Number(purchaser),
|
|
219
|
+
reference: "Envio de canastas (De proveedor a agencia)",
|
|
220
|
+
needs_transport: false,
|
|
221
|
+
planned_delivery: issue_date,
|
|
222
|
+
agency_from_id: Number(origin_agency),
|
|
223
|
+
agency_to_id: agency_id,
|
|
224
|
+
movements: movementDetails,
|
|
225
|
+
};
|
|
226
|
+
return BasketShipment;
|
|
227
|
+
};
|
|
228
|
+
const newBasketShipment = createBasketsShipmentBodyFunction();
|
|
260
229
|
const newShipmentResponse = await (0, services_1.insertBookings)(headers, newBasketShipment, `${apiResponses.authorizedPO.id}`);
|
|
261
230
|
if (newShipmentResponse.error || !newShipmentResponse.data) {
|
|
262
|
-
throw new Error("Error al intentar crear el envío: " +
|
|
231
|
+
throw new Error("Error al intentar crear el envío: " +
|
|
232
|
+
newShipmentResponse?.userMsg +
|
|
233
|
+
" Body: " +
|
|
234
|
+
JSON.stringify(newBasketShipment));
|
|
263
235
|
}
|
|
264
236
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
265
237
|
apiResponses.shipment = newShipmentResponse.data;
|
|
@@ -276,14 +248,51 @@ const register4pinosReception = async ({ cookie, idWebAppTable, agency_id, value
|
|
|
276
248
|
//Al momento de este comentario, un ejemplo es que sólo Planta Central no es centro de acopio
|
|
277
249
|
//Ellos si envían canastas a control de calidad.
|
|
278
250
|
//Si es de un centro de acopio, se salta esto...
|
|
279
|
-
|
|
280
|
-
if (apiResponses.apiCall === 5) {
|
|
251
|
+
if (apiResponses.apiCall === 5 && qualityControlBaskets.length > 0) {
|
|
281
252
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A CONTROL DE CALIDAD");
|
|
253
|
+
const total_qc_baskets = parseInt(values.totalQCBaskets + "");
|
|
254
|
+
const basket_weight = parseFloat(netWeight) / parseInt(total_baskets);
|
|
255
|
+
const lotResponse = await (0, services_1.getLoteByName)(session, apiResponses.authorizedPO.id_number);
|
|
256
|
+
if (lotResponse.error || !lotResponse.data || !lotResponse.data.id) {
|
|
257
|
+
throw new Error("Error al intentar obtener el lote por nombre: " +
|
|
258
|
+
lotResponse?.userMsg);
|
|
259
|
+
}
|
|
260
|
+
const createQCBasketShipmentBody = async () => {
|
|
261
|
+
const qcMovementDetails = qualityControlBaskets.map((basket) => {
|
|
262
|
+
const booked_quantity = Number(basket.split("-")[0]);
|
|
263
|
+
const lot_id = Number(basket.split("-")[1]);
|
|
264
|
+
return {
|
|
265
|
+
item_id: recepciones_basket_item_id,
|
|
266
|
+
lot_id,
|
|
267
|
+
booked_quantity,
|
|
268
|
+
reference: "Canastas a control de calidad.",
|
|
269
|
+
};
|
|
270
|
+
});
|
|
271
|
+
qcMovementDetails.push({
|
|
272
|
+
item_id: apiResponses.authorizedPO.purchase_order_details[0].item_id,
|
|
273
|
+
lot_id: Number(lotResponse.data?.id),
|
|
274
|
+
booked_quantity: Number(total_qc_baskets * basket_weight), //TODO: Revisar si esto está bien así.
|
|
275
|
+
reference: "Verduras a control de calidad.",
|
|
276
|
+
});
|
|
277
|
+
const qcBasketShipment = {
|
|
278
|
+
booker_id: Number(purchaser),
|
|
279
|
+
reference: "Envio de canastas y verduras a CC",
|
|
280
|
+
needs_transport: false,
|
|
281
|
+
planned_delivery: issue_date,
|
|
282
|
+
agency_from_id: agency_id,
|
|
283
|
+
agency_to_id: quality_control_agency,
|
|
284
|
+
movements: qcMovementDetails,
|
|
285
|
+
};
|
|
286
|
+
return qcBasketShipment;
|
|
287
|
+
};
|
|
288
|
+
const newQCBasketShipment = await createQCBasketShipmentBody();
|
|
282
289
|
const new_qc_shipment_response = await (0, services_1.insertBookings)(headers, newQCBasketShipment, `${apiResponses.authorizedPO.id}`);
|
|
283
290
|
if (!new_qc_shipment_response.data || new_qc_shipment_response.error) {
|
|
284
291
|
console.log("Body: ", JSON.stringify(newQCBasketShipment));
|
|
285
292
|
throw new Error("Error al intentar crear el envío a control de calidad: " +
|
|
286
|
-
new_qc_shipment_response?.userMsg
|
|
293
|
+
new_qc_shipment_response?.userMsg +
|
|
294
|
+
" Body: " +
|
|
295
|
+
JSON.stringify(newQCBasketShipment));
|
|
287
296
|
}
|
|
288
297
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
289
298
|
apiResponses.qcShipment = new_qc_shipment_response.data;
|
|
@@ -59,6 +59,8 @@ const createQueueFormReceptionHistory = (headers, session, body) => {
|
|
|
59
59
|
const { queue_form_recepcion_submited_web_app_table_id } = await (0, services_1.getVariablesByName)(headers, session, [
|
|
60
60
|
"queue_form_recepcion_submited_web_app_table_id",
|
|
61
61
|
]);
|
|
62
|
+
//Esto es para simular el tiempo de carga de la API nunca subir a producción
|
|
63
|
+
//await new Promise((resolve) => setTimeout(resolve, 7000));
|
|
62
64
|
const response = await (0, services_1.createWebAppTableRegister)(headers, queue_form_recepcion_submited_web_app_table_id, body);
|
|
63
65
|
return response;
|
|
64
66
|
});
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getFormattedDate } from "@zauru-sdk/common";
|
|
1
2
|
import { createNewAuthorizedPurchaseOrder, createNewReception, getDeliveryByBooking, getHeaders, getLoteByName, getPurchasesOrderByIdNumber, getSession, getVariablesByName, insertBookings, saveMotivosDeRechazoByPurchase, } from "@zauru-sdk/services";
|
|
2
3
|
import { saveRechazoCanastas } from "./motivos-rechazo.utils.js";
|
|
3
4
|
import { deleteQueueFormReceptionHistory, ESTADOS_COLA_RECEPCIONES, updateQueueFormReceptionHistory, } from "./4pinos-receptions-form-history.utils.js";
|
|
@@ -18,13 +19,9 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
18
19
|
}
|
|
19
20
|
const existentes = responsePOSearch?.data?.filter((x) => !x.voided);
|
|
20
21
|
if (existentes?.length > 0) {
|
|
21
|
-
throw new Error(`Ya existe una órden de compra con este número de contraseña asociado, revise el listado general. Peso: ${existentes[0].due}, Ingresado el:
|
|
22
|
-
existentes[0].issue_date
|
|
23
|
-
, Memo: ${existentes[0].memo}, Tipo: ${existentes[0].reference}`);
|
|
22
|
+
throw new Error(`Ya existe una órden de compra con este número de contraseña asociado, revise el listado general. Peso: ${existentes[0].due}, Ingresado el: ${getFormattedDate(existentes[0].issue_date, false)}, Memo: ${existentes[0].memo}, Tipo: ${existentes[0].reference}`);
|
|
24
23
|
}
|
|
25
24
|
}
|
|
26
|
-
const esCentroDeAcopio = values?.esCentroDeAcopio === "true";
|
|
27
|
-
const basketLots = JSON.parse(values?.basketLots.toString());
|
|
28
25
|
const webapp_table_rejection = {
|
|
29
26
|
Canastas: "int",
|
|
30
27
|
Razon_primaria: "string",
|
|
@@ -44,6 +41,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
44
41
|
const hashRecepcionesQCAgency = JSON.parse(fixedString ?? "{}");
|
|
45
42
|
const quality_control_agency = hashRecepcionesQCAgency[agency_id];
|
|
46
43
|
//-------------------REACT SELECT VALUES-------------------------
|
|
44
|
+
console.log("values", values);
|
|
47
45
|
const vendor = values.vendor;
|
|
48
46
|
const itemId = values.item;
|
|
49
47
|
const purchaser = values.purchaser;
|
|
@@ -51,6 +49,9 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
51
49
|
const idNumberInput = values.idNumberInput;
|
|
52
50
|
const discountReason = values.discountReason;
|
|
53
51
|
const issue_date = values.issue_date;
|
|
52
|
+
const esCentroDeAcopio = values?.esCentroDeAcopio === "true";
|
|
53
|
+
const singleBasketWeight = Number(values.singleBasketWeight);
|
|
54
|
+
const recepciones_basket_item_id = Number(values?.recepciones_basket_item_id.toString());
|
|
54
55
|
const rejections = JSON.parse(values.rejections.toString() ?? "[]");
|
|
55
56
|
const provenance = values.selectedProvenance;
|
|
56
57
|
const purchaseOrderGeneralInfo = JSON.parse(values?.purchaseOrderGeneralInfo?.toString() ?? "{}");
|
|
@@ -63,16 +64,16 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
63
64
|
};
|
|
64
65
|
let keys = Object.keys(values);
|
|
65
66
|
let netWeight = values.netWgt;
|
|
66
|
-
let singleBasketWeight = values.singleBasketWeight;
|
|
67
67
|
const total_baskets = values.totalBaskets + "";
|
|
68
|
-
const stockInteger = values.stockInteger
|
|
68
|
+
const stockInteger = values.stockInteger == "true";
|
|
69
69
|
let webapp_table_object = {};
|
|
70
70
|
const buildArray = (keyIncludes, processValue) => {
|
|
71
|
+
const regex = /\d/; // Expresión regular para buscar al menos un dígito.
|
|
71
72
|
return keys
|
|
72
|
-
.filter((key) => key.includes(keyIncludes))
|
|
73
|
-
.map((
|
|
74
|
-
|
|
75
|
-
processValue(values[
|
|
73
|
+
.filter((key) => key.includes(keyIncludes) && regex.test(key))
|
|
74
|
+
.map((key) => [
|
|
75
|
+
key.substring(keyIncludes?.length, key?.length),
|
|
76
|
+
processValue(values[key]),
|
|
76
77
|
])
|
|
77
78
|
.filter(([key, value]) => Number(value) > 0)
|
|
78
79
|
.map(([kv, val]) => `${val}-${kv}`);
|
|
@@ -81,7 +82,7 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
81
82
|
const regex = /\d/; // Expresión regular para buscar al menos un dígito.
|
|
82
83
|
return keys
|
|
83
84
|
.filter((key) => key.includes(keyIncludes) && regex.test(key))
|
|
84
|
-
.map((
|
|
85
|
+
.map((key) => processValue(values[key] === "" || values[key] === "NaN" ? 0 : values[key]));
|
|
85
86
|
};
|
|
86
87
|
const processValues = () => {
|
|
87
88
|
const received_baskets = buildArray("rec", parseInt);
|
|
@@ -104,146 +105,93 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
104
105
|
];
|
|
105
106
|
};
|
|
106
107
|
let [received_baskets, qualityControlBaskets, detail_baskets, detail_discounts, detail_weights,] = processValues();
|
|
107
|
-
//build net_weights
|
|
108
|
-
const detail_netWeights = keys
|
|
109
|
-
.filter((key) => key.includes("weight"))
|
|
110
|
-
.map((kbv, index) => (parseFloat(values[kbv]) -
|
|
111
|
-
(stockInteger
|
|
112
|
-
? 0
|
|
113
|
-
: detail_baskets[index] * parseFloat(singleBasketWeight))) *
|
|
114
|
-
((100 - detail_discounts[index]) / 100));
|
|
115
|
-
// //---------------------------PURCHASE ORDER OBJECT----------------------------------
|
|
116
|
-
console.log("========================================>");
|
|
117
|
-
console.log("paso 1: REGISTRANDO NUEVA ORDEN DE COMPRA AUTORIZADA...");
|
|
118
|
-
const newPurchaseOrderDetails = [];
|
|
119
|
-
detail_baskets.forEach((x, index) => {
|
|
120
|
-
newPurchaseOrderDetails.push({
|
|
121
|
-
reference: `${detail_weights[index]},${detail_baskets[index]},${detail_discounts[index]}`,
|
|
122
|
-
item_id: Number(itemId),
|
|
123
|
-
booked_quantity: detail_netWeights[index],
|
|
124
|
-
unit_cost: 1,
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
const newPurchaseOrderBody = {
|
|
128
|
-
reference: payeeType,
|
|
129
|
-
taxable: false,
|
|
130
|
-
issue_date,
|
|
131
|
-
shipping_date: issue_date,
|
|
132
|
-
incoterm_id: purchaseOrderGeneralInfo?.incoterm_id,
|
|
133
|
-
currency_id: purchaseOrderGeneralInfo?.currency_id,
|
|
134
|
-
charge_term_id: purchaseOrderGeneralInfo?.charge_term_id,
|
|
135
|
-
payee_info: vendor,
|
|
136
|
-
agency_id,
|
|
137
|
-
purchaser_id: Number(purchaser),
|
|
138
|
-
import: false,
|
|
139
|
-
tag_ids: ["", tag_id],
|
|
140
|
-
memo: qualityControlBaskets + "",
|
|
141
|
-
origin: netWeight,
|
|
142
|
-
purchase_order_details: newPurchaseOrderDetails,
|
|
143
|
-
incoterm_destination: provenance.slice(0, 254),
|
|
144
|
-
transport_type: discountReason,
|
|
145
|
-
id_number: idNumberInput,
|
|
146
|
-
...(esCentroDeAcopio
|
|
147
|
-
? { discount: Number(controlCalidadValues.porcentajeRechazo) }
|
|
148
|
-
: {}),
|
|
149
|
-
};
|
|
150
108
|
//========== PRIMERA LLAMADA DE API Y CAPTURA DE ERRORES
|
|
151
109
|
if (apiResponses.apiCall === 1) {
|
|
110
|
+
console.log("========================================>");
|
|
111
|
+
console.log("paso 1: REGISTRANDO NUEVA ORDEN DE COMPRA AUTORIZADA...");
|
|
112
|
+
//build net_weights
|
|
113
|
+
const detail_netWeights = keys
|
|
114
|
+
.filter((key) => key.includes("weight"))
|
|
115
|
+
.map((key, index) => {
|
|
116
|
+
const weight = Number(values[key]);
|
|
117
|
+
const detail_basket = Number(detail_baskets[index]);
|
|
118
|
+
const detail_discount = Number(detail_discounts[index]) ?? 0;
|
|
119
|
+
return ((weight - (stockInteger ? 0 : detail_basket * singleBasketWeight)) *
|
|
120
|
+
((100 - detail_discount) / 100));
|
|
121
|
+
});
|
|
122
|
+
const newPurchaseOrderDetails = detail_baskets.map((x, index) => {
|
|
123
|
+
return {
|
|
124
|
+
reference: `${detail_weights[index]},${x},${detail_discounts[index]}`,
|
|
125
|
+
item_id: Number(itemId),
|
|
126
|
+
booked_quantity: detail_netWeights[index],
|
|
127
|
+
unit_cost: 1,
|
|
128
|
+
};
|
|
129
|
+
});
|
|
130
|
+
const newPurchaseOrderBody = {
|
|
131
|
+
reference: payeeType,
|
|
132
|
+
taxable: false,
|
|
133
|
+
issue_date,
|
|
134
|
+
shipping_date: issue_date,
|
|
135
|
+
incoterm_id: purchaseOrderGeneralInfo?.incoterm_id,
|
|
136
|
+
currency_id: purchaseOrderGeneralInfo?.currency_id,
|
|
137
|
+
charge_term_id: purchaseOrderGeneralInfo?.charge_term_id,
|
|
138
|
+
payee_id: vendor,
|
|
139
|
+
agency_id,
|
|
140
|
+
purchaser_id: Number(purchaser),
|
|
141
|
+
import: false,
|
|
142
|
+
tag_ids: ["", tag_id],
|
|
143
|
+
memo: qualityControlBaskets + "",
|
|
144
|
+
origin: netWeight,
|
|
145
|
+
purchase_order_details: newPurchaseOrderDetails,
|
|
146
|
+
incoterm_destination: provenance.slice(0, 254),
|
|
147
|
+
transport_type: discountReason,
|
|
148
|
+
id_number: idNumberInput,
|
|
149
|
+
...(esCentroDeAcopio
|
|
150
|
+
? { discount: Number(controlCalidadValues.porcentajeRechazo) }
|
|
151
|
+
: {}),
|
|
152
|
+
};
|
|
152
153
|
console.log("REGISTRANDO ORDEN DE COMPRA: ", JSON.stringify(newPurchaseOrderBody));
|
|
153
154
|
const newAuthorizedPurchaseResponse = await createNewAuthorizedPurchaseOrder(headers, newPurchaseOrderBody, false);
|
|
154
155
|
if (newAuthorizedPurchaseResponse?.error ||
|
|
155
156
|
!newAuthorizedPurchaseResponse.data) {
|
|
156
157
|
throw new Error("Error al intentar crear la órden de compra autorizada: " +
|
|
157
|
-
newAuthorizedPurchaseResponse?.userMsg
|
|
158
|
+
newAuthorizedPurchaseResponse?.userMsg +
|
|
159
|
+
" Body: " +
|
|
160
|
+
JSON.stringify(newPurchaseOrderBody));
|
|
158
161
|
}
|
|
159
162
|
apiResponses.authorizedPO = newAuthorizedPurchaseResponse.data;
|
|
160
163
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
161
164
|
}
|
|
162
|
-
console.log("========================================>");
|
|
163
|
-
console.log("paso 2: CREANDO RECEPCION, ENVIO DE CANASTAS, WEBAPP TABLE DE RECHAZO DIRECTO");
|
|
164
|
-
const createNewReceptionBodyFunction = () => {
|
|
165
|
-
const receptionDetails = {};
|
|
166
|
-
apiResponses.authorizedPO.purchase_order_details.forEach((pod, index) => (receptionDetails[index] = {
|
|
167
|
-
item_id: `${pod.item_id}`,
|
|
168
|
-
purchase_order_detail_id: `${pod.id}`,
|
|
169
|
-
lot_delivered_quantity: [`${pod.booked_quantity}`],
|
|
170
|
-
lot_name: [apiResponses.authorizedPO.id_number],
|
|
171
|
-
lot_expire: [
|
|
172
|
-
new Date(Date.now() + 12096e5).toISOString().split("T")[0],
|
|
173
|
-
],
|
|
174
|
-
lot_description: [received_baskets.join(",")],
|
|
175
|
-
}));
|
|
176
|
-
const newReception = {
|
|
177
|
-
reception: {
|
|
178
|
-
agency_id,
|
|
179
|
-
received_at: issue_date,
|
|
180
|
-
purchase_order_id: apiResponses.authorizedPO.id + "",
|
|
181
|
-
entity_id: apiResponses.authorizedPO.entity_id + "",
|
|
182
|
-
needs_transit: "0",
|
|
183
|
-
invoice_number: "",
|
|
184
|
-
reception_details_attributes: receptionDetails,
|
|
185
|
-
},
|
|
186
|
-
};
|
|
187
|
-
return newReception;
|
|
188
|
-
};
|
|
189
|
-
const createBasketsShipmentBodyFunction = () => {
|
|
190
|
-
const movementDetails = [];
|
|
191
|
-
received_baskets.forEach((basket, index) => {
|
|
192
|
-
movementDetails.push({
|
|
193
|
-
item_id: basketLots?.recepciones_basket_item_id,
|
|
194
|
-
lot_id: basket.split("-")[1],
|
|
195
|
-
booked_quantity: basket.split("-")[0],
|
|
196
|
-
});
|
|
197
|
-
});
|
|
198
|
-
const BasketShipment = {
|
|
199
|
-
booker_id: Number(purchaser),
|
|
200
|
-
reference: "Envio de canastas (De proveedor a agencia)",
|
|
201
|
-
needs_transport: false,
|
|
202
|
-
planned_delivery: issue_date,
|
|
203
|
-
agency_from_id: Number(origin_agency),
|
|
204
|
-
agency_to_id: agency_id,
|
|
205
|
-
movements: movementDetails,
|
|
206
|
-
};
|
|
207
|
-
return BasketShipment;
|
|
208
|
-
};
|
|
209
|
-
const createQCBasketShipmentBody = async () => {
|
|
210
|
-
const qcMovementDetails = [];
|
|
211
|
-
qualityControlBaskets.forEach((basket) => {
|
|
212
|
-
qcMovementDetails.push({
|
|
213
|
-
item_id: basketLots?.recepciones_basket_item_id,
|
|
214
|
-
lot_id: Number(basket.split("-")[1]),
|
|
215
|
-
booked_quantity: Number(basket.split("-")[0]),
|
|
216
|
-
});
|
|
217
|
-
});
|
|
218
|
-
const total_qc_baskets = parseInt(values.totalQCBaskets + "");
|
|
219
|
-
const basket_weight = parseFloat(netWeight) / parseInt(total_baskets);
|
|
220
|
-
const lotResponse = await getLoteByName(session, apiResponses.authorizedPO.id_number);
|
|
221
|
-
if (lotResponse.error || !lotResponse.data) {
|
|
222
|
-
throw new Error("Error al intentar obtener el lote por nombre: " +
|
|
223
|
-
lotResponse?.userMsg);
|
|
224
|
-
}
|
|
225
|
-
if (lotResponse.data?.id) {
|
|
226
|
-
qcMovementDetails.push({
|
|
227
|
-
item_id: apiResponses.authorizedPO.purchase_order_details[0].item_id,
|
|
228
|
-
lot_id: Number(lotResponse.data.id),
|
|
229
|
-
booked_quantity: Number(Math.round(total_qc_baskets * basket_weight)), //TODO: Revisar si esto está bien así.
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
const qcBasketShipment = {
|
|
233
|
-
booker_id: Number(purchaser),
|
|
234
|
-
reference: "Envio de canastas y verduras a CC",
|
|
235
|
-
needs_transport: false,
|
|
236
|
-
planned_delivery: issue_date,
|
|
237
|
-
agency_from_id: agency_id,
|
|
238
|
-
agency_to_id: quality_control_agency,
|
|
239
|
-
movements: qcMovementDetails,
|
|
240
|
-
};
|
|
241
|
-
return qcBasketShipment;
|
|
242
|
-
};
|
|
243
|
-
//first create reception and receive it with the basket shipment
|
|
244
|
-
const newReception = createNewReceptionBodyFunction();
|
|
245
|
-
const newBasketShipment = createBasketsShipmentBodyFunction();
|
|
246
165
|
if (apiResponses.apiCall === 2) {
|
|
166
|
+
const createNewReceptionBodyFunction = () => {
|
|
167
|
+
const receptionDetails = {};
|
|
168
|
+
apiResponses.authorizedPO.purchase_order_details.forEach((pod, index) => (receptionDetails[index] = {
|
|
169
|
+
item_id: `${pod.item_id}`,
|
|
170
|
+
purchase_order_detail_id: `${pod.id}`,
|
|
171
|
+
lot_delivered_quantity: [`${pod.booked_quantity}`],
|
|
172
|
+
lot_name: [apiResponses.authorizedPO.id_number],
|
|
173
|
+
lot_expire: [
|
|
174
|
+
new Date(Date.now() + 12096e5).toISOString().split("T")[0],
|
|
175
|
+
],
|
|
176
|
+
lot_description: [received_baskets.join(",")],
|
|
177
|
+
}));
|
|
178
|
+
const newReception = {
|
|
179
|
+
reception: {
|
|
180
|
+
agency_id,
|
|
181
|
+
received_at: issue_date,
|
|
182
|
+
purchase_order_id: apiResponses.authorizedPO.id + "",
|
|
183
|
+
entity_id: apiResponses.authorizedPO.entity_id + "",
|
|
184
|
+
needs_transit: "0",
|
|
185
|
+
invoice_number: "",
|
|
186
|
+
reception_details_attributes: receptionDetails,
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
return newReception;
|
|
190
|
+
};
|
|
191
|
+
//first create reception and receive it with the basket shipment
|
|
192
|
+
const newReception = createNewReceptionBodyFunction();
|
|
193
|
+
console.log("========================================>");
|
|
194
|
+
console.log("paso 2: CREANDO RECEPCION, ENVIO DE CANASTAS, WEBAPP TABLE DE RECHAZO DIRECTO");
|
|
247
195
|
console.log("------------ CREANDO RECEPCIÓN.......");
|
|
248
196
|
const responseNewReception = await createNewReception(headers, newReception, apiResponses.authorizedPO.id);
|
|
249
197
|
if (responseNewReception.error || !responseNewReception.data) {
|
|
@@ -254,9 +202,33 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
254
202
|
}
|
|
255
203
|
if (apiResponses.apiCall === 3) {
|
|
256
204
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A LA AGENCIA");
|
|
205
|
+
const createBasketsShipmentBodyFunction = () => {
|
|
206
|
+
const movementDetails = [];
|
|
207
|
+
received_baskets.forEach((basket, index) => {
|
|
208
|
+
movementDetails.push({
|
|
209
|
+
item_id: recepciones_basket_item_id,
|
|
210
|
+
lot_id: basket.split("-")[1],
|
|
211
|
+
booked_quantity: basket.split("-")[0],
|
|
212
|
+
});
|
|
213
|
+
});
|
|
214
|
+
const BasketShipment = {
|
|
215
|
+
booker_id: Number(purchaser),
|
|
216
|
+
reference: "Envio de canastas (De proveedor a agencia)",
|
|
217
|
+
needs_transport: false,
|
|
218
|
+
planned_delivery: issue_date,
|
|
219
|
+
agency_from_id: Number(origin_agency),
|
|
220
|
+
agency_to_id: agency_id,
|
|
221
|
+
movements: movementDetails,
|
|
222
|
+
};
|
|
223
|
+
return BasketShipment;
|
|
224
|
+
};
|
|
225
|
+
const newBasketShipment = createBasketsShipmentBodyFunction();
|
|
257
226
|
const newShipmentResponse = await insertBookings(headers, newBasketShipment, `${apiResponses.authorizedPO.id}`);
|
|
258
227
|
if (newShipmentResponse.error || !newShipmentResponse.data) {
|
|
259
|
-
throw new Error("Error al intentar crear el envío: " +
|
|
228
|
+
throw new Error("Error al intentar crear el envío: " +
|
|
229
|
+
newShipmentResponse?.userMsg +
|
|
230
|
+
" Body: " +
|
|
231
|
+
JSON.stringify(newBasketShipment));
|
|
260
232
|
}
|
|
261
233
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
262
234
|
apiResponses.shipment = newShipmentResponse.data;
|
|
@@ -273,14 +245,51 @@ export const register4pinosReception = async ({ cookie, idWebAppTable, agency_id
|
|
|
273
245
|
//Al momento de este comentario, un ejemplo es que sólo Planta Central no es centro de acopio
|
|
274
246
|
//Ellos si envían canastas a control de calidad.
|
|
275
247
|
//Si es de un centro de acopio, se salta esto...
|
|
276
|
-
|
|
277
|
-
if (apiResponses.apiCall === 5) {
|
|
248
|
+
if (apiResponses.apiCall === 5 && qualityControlBaskets.length > 0) {
|
|
278
249
|
console.log("------------- REALIZANDO ENVÍO DE CANASTAS A CONTROL DE CALIDAD");
|
|
250
|
+
const total_qc_baskets = parseInt(values.totalQCBaskets + "");
|
|
251
|
+
const basket_weight = parseFloat(netWeight) / parseInt(total_baskets);
|
|
252
|
+
const lotResponse = await getLoteByName(session, apiResponses.authorizedPO.id_number);
|
|
253
|
+
if (lotResponse.error || !lotResponse.data || !lotResponse.data.id) {
|
|
254
|
+
throw new Error("Error al intentar obtener el lote por nombre: " +
|
|
255
|
+
lotResponse?.userMsg);
|
|
256
|
+
}
|
|
257
|
+
const createQCBasketShipmentBody = async () => {
|
|
258
|
+
const qcMovementDetails = qualityControlBaskets.map((basket) => {
|
|
259
|
+
const booked_quantity = Number(basket.split("-")[0]);
|
|
260
|
+
const lot_id = Number(basket.split("-")[1]);
|
|
261
|
+
return {
|
|
262
|
+
item_id: recepciones_basket_item_id,
|
|
263
|
+
lot_id,
|
|
264
|
+
booked_quantity,
|
|
265
|
+
reference: "Canastas a control de calidad.",
|
|
266
|
+
};
|
|
267
|
+
});
|
|
268
|
+
qcMovementDetails.push({
|
|
269
|
+
item_id: apiResponses.authorizedPO.purchase_order_details[0].item_id,
|
|
270
|
+
lot_id: Number(lotResponse.data?.id),
|
|
271
|
+
booked_quantity: Number(total_qc_baskets * basket_weight), //TODO: Revisar si esto está bien así.
|
|
272
|
+
reference: "Verduras a control de calidad.",
|
|
273
|
+
});
|
|
274
|
+
const qcBasketShipment = {
|
|
275
|
+
booker_id: Number(purchaser),
|
|
276
|
+
reference: "Envio de canastas y verduras a CC",
|
|
277
|
+
needs_transport: false,
|
|
278
|
+
planned_delivery: issue_date,
|
|
279
|
+
agency_from_id: agency_id,
|
|
280
|
+
agency_to_id: quality_control_agency,
|
|
281
|
+
movements: qcMovementDetails,
|
|
282
|
+
};
|
|
283
|
+
return qcBasketShipment;
|
|
284
|
+
};
|
|
285
|
+
const newQCBasketShipment = await createQCBasketShipmentBody();
|
|
279
286
|
const new_qc_shipment_response = await insertBookings(headers, newQCBasketShipment, `${apiResponses.authorizedPO.id}`);
|
|
280
287
|
if (!new_qc_shipment_response.data || new_qc_shipment_response.error) {
|
|
281
288
|
console.log("Body: ", JSON.stringify(newQCBasketShipment));
|
|
282
289
|
throw new Error("Error al intentar crear el envío a control de calidad: " +
|
|
283
|
-
new_qc_shipment_response?.userMsg
|
|
290
|
+
new_qc_shipment_response?.userMsg +
|
|
291
|
+
" Body: " +
|
|
292
|
+
JSON.stringify(newQCBasketShipment));
|
|
284
293
|
}
|
|
285
294
|
apiResponses.apiCall = apiResponses.apiCall + 1;
|
|
286
295
|
apiResponses.qcShipment = new_qc_shipment_response.data;
|
|
@@ -54,6 +54,8 @@ export const createQueueFormReceptionHistory = (headers, session, body) => {
|
|
|
54
54
|
const { queue_form_recepcion_submited_web_app_table_id } = await getVariablesByName(headers, session, [
|
|
55
55
|
"queue_form_recepcion_submited_web_app_table_id",
|
|
56
56
|
]);
|
|
57
|
+
//Esto es para simular el tiempo de carga de la API nunca subir a producción
|
|
58
|
+
//await new Promise((resolve) => setTimeout(resolve, 7000));
|
|
57
59
|
const response = await createWebAppTableRegister(headers, queue_form_recepcion_submited_web_app_table_id, body);
|
|
58
60
|
return response;
|
|
59
61
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.110",
|
|
4
4
|
"description": "Utilidades, parseo de request y demás para desarrollo de webapps de Zauru",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -25,11 +25,11 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@remix-run/node": "^2.8.1",
|
|
28
|
-
"@zauru-sdk/common": "^1.0.
|
|
28
|
+
"@zauru-sdk/common": "^1.0.110",
|
|
29
29
|
"@zauru-sdk/config": "^1.0.60",
|
|
30
30
|
"@zauru-sdk/graphql": "^1.0.105",
|
|
31
|
-
"@zauru-sdk/services": "^1.0.
|
|
31
|
+
"@zauru-sdk/services": "^1.0.110",
|
|
32
32
|
"@zauru-sdk/types": "^1.0.109"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "15d8ecf97b16b9c4bd50b8a5984435b451a846e5"
|
|
35
35
|
}
|