[EDIT] VALIDACIONES DE REGISTRO CONFORMIDAD CON SUBIDAD DE ARCHIVOS

parent ddf174f7
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -42,3 +42,24 @@ mat-label {
white-space: pre-line; /* Permite respetar saltos de línea */
}
.progress-bar {
width: 100%;
height: 20px;
background: #ccc;
border-radius: 10px;
overflow: hidden;
margin-top: 10px;
}
.progress {
height: 100%;
background: #4caf50;
transition: width 0.3s ease-in-out;
}
.success-snackbar {
background-color: #4caf50 !important; /* Color verde */
color: white !important;
text-align: center;
font-weight: bold;
}
......@@ -429,7 +429,7 @@
<mat-label>SUBIR FOTO DE LA ATS</mat-label>
<mat-icon>file_open</mat-icon>
</button>
<input type="file" #fotoATC (change)="onEventoSubirArchivo($event,3)" class="hidden" accept="image/png, image/jpeg">
<input type="file" #fotoATC (change)="onEventoSubirArchivo($event,3)" class="hidden" multiple accept="image/png, image/jpeg">
</div>
<div *ngFor="let archivo of archivosEvidencia; let i = index">
<div *ngIf="archivo.tipoEvidencia === 3" class="flex w-full mt-2">
......
......@@ -53,8 +53,25 @@ export class ConformidadHelper {
}
}
async subidaEvidencia( json : any ){
const respuesta = await this.ConformidadService.subidaEvidencia(json);
return respuesta
}
async subidaEvidencia2( json : any ){
const respuesta = await this.ConformidadService.subidaEvidencia2(json);
//console.log(respuesta);
return respuesta
}
async subidaEvidencia3( json : any ){
const respuesta = await this.ConformidadService.subidaEvidencia3(json);
//console.log(respuesta);
return respuesta
}
async eliminarDocumento(json : any){
const respuesta = await this.ConformidadService.eliminarDocumento(json);
return respuesta
}
......
......@@ -22,7 +22,7 @@
<mat-label>CANTIDAD : </mat-label>
<mat-form-field class="w-full">
<mat-label>Ingrese cantidad</mat-label>
<input formControlName="cantidadArticulo" matInput soloNumeros="entero" maxlength="2" placeholder="Máx. 2 dígitos">
<input formControlName="cantidadArticulo" matInput soloNumeros="entero" maxlength="3" placeholder="Máx. 3 dígitos">
</mat-form-field>
</div>
......
......@@ -118,7 +118,7 @@ export class modalFirmaComponent implements AfterViewInit {
//this.dialogRef.close(sign);
console.log(blob);
//console.log(blob);
}
dataURLToBlob(dataURL: string): Blob {
......@@ -137,7 +137,7 @@ export class modalFirmaComponent implements AfterViewInit {
drawComplete(event: TouchEvent) {
const sign = this.signaturePad.toDataURL();
console.log(sign);
//console.log(sign);
//this.signImage.emit(sign);
}
......
import {Injectable} from "@angular/core";
import axios from "axios";
import {environment} from "../../../environment/env";
import {BehaviorSubject} from "rxjs";
import Notiflix from "notiflix";
@Injectable({
providedIn: 'root'
})
export class ConformidadService {
t_asistencia_rest_link = environment.t_asistencia_rest_link;
t_horizon_rest_link = environment.horizon_services_link;
t_facturacion_electronica_link = environment.facturacion_electronica_link;
......@@ -17,6 +18,9 @@ export class ConformidadService {
constructor() {
}
progresoSubida = new BehaviorSubject<number>(0);
progresoSubida$ = this.progresoSubida.asObservable();
async listadoGeneral(opcion: number) {
try {
const respuesta = await axios.post(this.t_asistencia_rest_link + '/api/v1/Conformidad/listadoGeneral',
......@@ -124,7 +128,7 @@ export class ConformidadService {
return respuesta;
}
async subidaEvidencia2(json:any){
async subidaEvidencia(json:any){
const url = `${this.t_redireccionamiento}/google/drive`;
let respuesta: any;
......@@ -189,21 +193,186 @@ export class ConformidadService {
}
}
return respuesta;
}
// REEMPLAZO DE SUBIDA DE ARCHIVOS
// FUNCION , RECONOCER QUE TODOS LOS ARCHIVOS SE SUBIERON
async subidaEvidencia2(json:any){
const url = `${this.t_redireccionamiento}/google/drive`;
const respuestas: any[] = [];
let archivosSubidos = 0;
const totalArchivos = json.length;
const promesas = json.map(async (datos: { nombreArchivo: string | Blob; archivo: string | Blob; idCarpeta: any; tipoEvidencia: number; codconformidad: any; }, index: any) => {
const formData = new FormData();
formData.append("archivo_nombre", datos.nombreArchivo);
formData.append("archivo_binario", datos.archivo);
formData.append("archivo_id_actual", "");
formData.append("carpeta_id", datos.idCarpeta || this.value_idDrive);
formData.append("correo", this.value_correoDrive);
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), 90000);
const response = await fetch(url, {
method: "POST",
body: formData,
signal: controller.signal,
});
clearTimeout(timeout);
if (!response.ok) {
console.error("Error en la respuesta del servidor:", response);
return { status: false, message: "Error al subir el archivo" };
}
const responseBody = await response.json();
if (responseBody?.status) {
await this.registroDocumento({
codconformidad: datos.codconformidad || 0,
tipoEvidencia: datos.tipoEvidencia || 0,
idDrive: responseBody.data.archivo_id || "",
enlaceDrive: responseBody.data.archivo_url_vista || "",
enlaceDescarga: responseBody.data.archivo_url || "",
nombreDocumento: datos.nombreArchivo || "",
idCarpeta: datos.idCarpeta || "",
});
archivosSubidos++;
//this.progresoSubida.next(Math.round((archivosSubidos / totalArchivos) * 100));
const progreso = Math.round((archivosSubidos / totalArchivos) * 100);
this.progresoSubida.next(progreso);
// Actualizar Notiflix con el progreso
Notiflix.Loading.change(`Carga al ${progreso}%`);
return { status: true, message: "Archivo subido correctamente" };
} else {
return { status: false, message: "Error al registrar evidencia" };
}
} catch (error) {
console.error("Error al registrar el archivo:", error);
return { status: false, message: error };
}
});
return Promise.all(promesas);
}
async subidaEvidencia3(json: any[]) {
const url = `${this.t_redireccionamiento}/google/drive`;
const totalArchivos = json.length;
let archivosSubidos = 0;
const maxReintentos = 3; // Intentos máximos
const timeoutBase = 40000; // Timeout inicial de 30 segundos
// Mostrar la carga en Notiflix
Notiflix.Loading.standard("Preparando subida...");
const subirArchivo = async (datos: any, intentos: number = 1 , index : number): Promise<boolean> => {
let tiempoEspera = timeoutBase * intentos; // Aumentar timeout con cada intento
if (tiempoEspera > 120000) tiempoEspera = 120000; // Limitar timeout a 90 segundos
try {
const controller = new AbortController();
const timeout = setTimeout(() => controller.abort(), tiempoEspera);
const formData = new FormData();
formData.append("archivo_nombre", datos.nombreArchivo);
formData.append("archivo_binario", datos.archivo);
formData.append("archivo_id_actual", "");
formData.append("carpeta_id", datos.idCarpeta || this.value_idDrive);
formData.append("correo", this.value_correoDrive);
/*if(index === 2){ // PROVOCAR UN FALLO EN EL ARCHIVO 2
throw new Error("Error al registrar evidencia");
}*/
const response = await fetch(url, {
method: "POST",
body: formData,
signal: controller.signal,
});
clearTimeout(timeout);
if (!response.ok) {
throw new Error("Error HTTP: " + response.status);
}
const responseBody = await response.json();
if (responseBody?.status) {
await this.registroDocumento({
codconformidad: datos.codconformidad || 0,
tipoEvidencia: datos.tipoEvidencia || 0,
idDrive: responseBody.data.archivo_id || "",
enlaceDrive: responseBody.data.archivo_url_vista || "",
enlaceDescarga: responseBody.data.archivo_url || "",
nombreDocumento: datos.nombreArchivo || "",
idCarpeta: datos.idCarpeta || "",
});
archivosSubidos++;
const progreso = Math.round((archivosSubidos / totalArchivos) * 100);
Notiflix.Loading.change(`Subida al ${progreso}%`);
return true;
} else {
throw new Error("Error al registrar evidencia");
}
} catch (error) {
console.error(`Error en intento ${intentos} de subida:`, error);
if (intentos < maxReintentos) {
Notiflix.Loading.change(`Reintentando ${datos.nombreArchivo}... (Intento ${intentos + 1})`);
return await subirArchivo(datos, intentos + 1,index);
} else {
console.error(`Fallo definitivo en ${datos.nombreArchivo}`);
return false;
}
}
};
// Ejecutar la subida en paralelo
const resultados = await Promise.all(json.map((archivo,index) => subirArchivo(archivo,1,index)));
// Cerrar Notiflix Loading
Notiflix.Loading.change(`Subida de archivos Existosa`);
// Verificar si hubo fallos
const archivosFallidos = resultados.filter((resultado) => !resultado).length;
if (archivosFallidos > 0) {
const mensaje = `Fallaron ${archivosFallidos} archivos después de ${maxReintentos} intentos.`;
return {status : false , mensaje};
} else {
// ✅ Mostrar mensaje de éxito y reiniciar la página después de 1000ms
console.log("Subida Existosa");
return {status : true , mensaje : "Subida Existosa"};
}
}
async registroDocumento(json: any) {
const parametros = {
accion : 1,
accion: 1,
codconformidad: json.codconformidad || 0,
tipoEvidencia: json.tipoEvidencia || 0,
idDrive: json.idDrive || '',
enlaceDrive: json.enlaceDrive || '',
enlaceDescarga: json.enlaceDescarga || '',
nombreDocumento: json.nombreDocumento || '',
idCarpeta : json.idCarpeta || ''
idCarpeta: json.idCarpeta || ''
};
try {
......@@ -215,6 +384,20 @@ export class ConformidadService {
}
}
async eliminarDocumento(json : any){
const parametros = {
accion: 1,
codconformidad: json.codconformidad || 0,
};
try {
const respuesta = await axios.post(this.t_facturacion_electronica_link + '/api/v1/conformidad/eliminarConformidad', parametros);
return respuesta.data;
} catch (e) {
return e;
}
}
async gestionOrdenSalida(json : any){
const parametros = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment