Merge branch 'main' into feature/proceso_heineken

feature/Reporte_Relacion_Facturas_Alen
Felix Morales 11 months ago
commit 92f2101244
  1. 15
      Controllers/Corresponsalias/AnticiposController.cs
  2. 52
      Controllers/FileManagerController.cs

@ -4,6 +4,7 @@ using CORRESPONSALBackend.DTO.Corresponsales;
using CORRESPONSALBackend.Models.Corresponsales; using CORRESPONSALBackend.Models.Corresponsales;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using CORRESPONSALBackend.Contracts.Utils;
namespace CORRESPONSALBackend.Controllers.Corresponsalias namespace CORRESPONSALBackend.Controllers.Corresponsalias
{ {
@ -15,11 +16,13 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias
{ {
private readonly ICorresponsaliasAnticiposRepository _Repo; private readonly ICorresponsaliasAnticiposRepository _Repo;
private readonly IConfiguration _config; private readonly IConfiguration _config;
private readonly IFileManagerRepository _fileManager;
public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config) public AnticiposController(ICorresponsaliasAnticiposRepository Repo, IConfiguration config, IFileManagerRepository fileManager)
{ {
_config = config; _config = config;
_Repo = Repo; _Repo = Repo;
_fileManager = fileManager;
} }
[HttpPost] [HttpPost]
@ -35,6 +38,16 @@ namespace CORRESPONSALBackend.Controllers.Corresponsalias
public async Task<IEnumerable<CorresponsalAnticipos>> GetAll([FromQuery] int IdTrafico) public async Task<IEnumerable<CorresponsalAnticipos>> GetAll([FromQuery] int IdTrafico)
{ {
var entrada = await _Repo.getAll(IdTrafico); var entrada = await _Repo.getAll(IdTrafico);
var sinAutorizar = entrada.Where(x => x.Autoriza == 0).ToList();
if(sinAutorizar.Count > 0){
foreach (var anticipo in sinAutorizar){
var comprobanteAnticipo = await _fileManager.getFileByProcess(anticipo.id, 4);
if(comprobanteAnticipo.Tags != ""){
await Autoriza(new DTOCorresponsalesAnticipo(){id= anticipo.id, IdUsuario = comprobanteAnticipo.IdUsuario});
}
}
return await _Repo.getAll(IdTrafico);
}
return entrada; return entrada;
} }

@ -9,6 +9,7 @@ using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Http.HttpResults;
using CORRESPONSALBackend.Contracts.Auth; using CORRESPONSALBackend.Contracts.Auth;
using CORRESPONSALBackend.Contracts.Corresponsalias;
namespace CORRESPONSALBackend.Controllers namespace CORRESPONSALBackend.Controllers
{ {
@ -23,6 +24,7 @@ namespace CORRESPONSALBackend.Controllers
private readonly IFilePaths4ProcessRepository _RepoRelativePath; private readonly IFilePaths4ProcessRepository _RepoRelativePath;
private readonly IConfiguration _config; private readonly IConfiguration _config;
private readonly IAuthService _authService; private readonly IAuthService _authService;
private readonly ICorresponsaliasTraficosRepository _traficosRepository;
private readonly string RootPathCorresponsales; private readonly string RootPathCorresponsales;
@ -31,7 +33,8 @@ namespace CORRESPONSALBackend.Controllers
IConfiguration config, IConfiguration config,
IUsuariosRepository RepoUsuarios, IUsuariosRepository RepoUsuarios,
ICasaCuervoRepository RepoCasaCuervo, ICasaCuervoRepository RepoCasaCuervo,
IAuthService authService) IAuthService authService,
ICorresponsaliasTraficosRepository traficosRepository)
{ {
_config = config; _config = config;
_Repo = Repo; _Repo = Repo;
@ -40,6 +43,7 @@ namespace CORRESPONSALBackend.Controllers
_RepoRelativePath = RepoRelativePath; _RepoRelativePath = RepoRelativePath;
RootPathCorresponsales = _config.GetValue<string>("AllFiles"); RootPathCorresponsales = _config.GetValue<string>("AllFiles");
_authService = authService; _authService = authService;
_traficosRepository = traficosRepository;
} }
[Route("GetFileInfoByProcess")] [Route("GetFileInfoByProcess")]
@ -310,5 +314,51 @@ namespace CORRESPONSALBackend.Controllers
return false; return false;
} }
} }
[HttpGet("GetClientesZip")]
public async Task<IActionResult> GetClientesZip(int id){
try{
var trafico = await _traficosRepository.Get(id);//Se obtiene el modelo del trafico.
FilePaths4Process tempFilesRelativePath = await _RepoRelativePath.getPaths4ProcessById(40); // Path: Corresponsales\Zips\Facturacion\Entregas\
var tempFilesPath = RootPathCorresponsales + tempFilesRelativePath.Path;// Path: C:data\Corresponsales\Zips\Facturacion\Entregas\
var zipFilePath = tempFilesPath + trafico.FolioGemco + ".zip";
if(!System.IO.File.Exists(zipFilePath)){//Se valida si no existe el archivo
var procesos = new int[]{2,37,38,39};//Se crea un array con los procesos de los cuales se van a necesitar los archivos
string folderName = string.Concat(trafico.FolioGemco, "\\"); // "23-000xxxC" -> "23-000xxxC\"
if(!System.IO.Directory.Exists(tempFilesPath + folderName))
System.IO.Directory.CreateDirectory(tempFilesPath + folderName);// Path: C:data\Corresponsales\Zips\Facturacion\Entregas\23-000xxxC\
//Se copian los archivos necesarios a la ruta donde se van a comprimir.
foreach (var proceso in procesos){
var fileLog = await _Repo.getFileByProcess(id, proceso);//Se busca el registro del archivo en la BD
if(fileLog.Tags == "" && proceso != 39)//Se valida que exista el registro de la BD de los archivos obligatorios
throw new Exception("No se han encontrado uno o más de los archivos obligatorios");
if(fileLog.Tags == "" && proceso == 39) break; //Si es un archivo opcional se salta la ejecucion del resto del foreach
//Se obtienen las rutas relativas donde se alojan los archivos.
FilePaths4Process fileRelativePath = await _RepoRelativePath.getPaths4ProcessById(proceso);
var filePath = RootPathCorresponsales + fileRelativePath.Path + fileLog!.NombreArchivo;
if(System.IO.File.Exists(filePath)){
var bytes = await System.IO.File.ReadAllBytesAsync(filePath);
var originalFileStream = new MemoryStream(bytes);
using(var tempFileStream = System.IO.File.Create(tempFilesPath + folderName + fileLog.NombreArchivo)){
await originalFileStream.CopyToAsync(tempFileStream);
}
}else{
throw new Exception("No se han encontrado uno o más de los archivos obligatorios");
}
}
string zipFileName = tempFilesPath + trafico.FolioGemco + ".zip";
//Se comprime el folder con el nombre del trafico para crear el zip en la ruta: c:data\Corresponsales\Zips\Facturacion\Entregas\{NombreDelZip.zip}
System.IO.Compression.ZipFile.CreateFromDirectory(tempFilesPath + folderName, zipFileName);
//Se borra el folder que contenia los archivos temporales
Directory.Delete(tempFilesPath + folderName, true);
}
var zipBytes = await System.IO.File.ReadAllBytesAsync(zipFilePath);
var zipStream = new MemoryStream(zipBytes);
return File(zipStream, "application/zip", trafico.FolioGemco + ".zip");
}catch(Exception ex){
return BadRequest(ex.Message);
}
}
} }
} }
Loading…
Cancel
Save