* Added Logo to the output file

This commit is contained in:
2025-10-01 14:42:58 +02:00
parent 8cfded48ae
commit 9163f330aa
5 changed files with 30 additions and 5 deletions

View File

@@ -10,7 +10,7 @@ namespace FaKrosnoApi.Controllers;
[ApiController]
[Route("api/[controller]")]
public class ExcelGeneratorController(IWzHeaderService wzHeaderService, IMaterialTransactionService materialTransactionService, IConfiguration configuration) : Controller
public class ExcelGeneratorController(IWzHeaderService wzHeaderService, IWzClientService wzClientService, IMaterialTransactionService materialTransactionService, IConfiguration configuration) : Controller
{
[HttpGet("generate-meyle")]
public async Task GeneratePackListForMeyle(Guid packListId)
@@ -96,6 +96,7 @@ public class ExcelGeneratorController(IWzHeaderService wzHeaderService, IMateria
public async Task GeneratePackListForMarelli(Guid packListId)
{
WzHeaderDto wzHeader = await wzHeaderService.GetByIdMarelli(packListId);
WzClientDto? wzClient = await wzClientService.GetById(wzHeader.FK_Client ?? Guid.NewGuid());
MaterialTransactionDto? materialTransaction = await materialTransactionService.GetByWzNumber(wzHeader.WzRowsMarelli.First().WzNumber);
using ExcelEngine excelEngine = new ExcelEngine();
@@ -124,14 +125,24 @@ public class ExcelGeneratorController(IWzHeaderService wzHeaderService, IMateria
worksheet["A4"].Value = "Packing List nr";
worksheet["A4"].CellStyle = boldFontStyle;
worksheet["B4"].Value = string.Join(", ", wzHeader.WzRowsMeyle.Select(x => x.WzNumber).Distinct());
worksheet["B4"].Value = string.Join(", ", wzHeader.WzRowsMarelli.Select(x => x.WzNumber).Distinct());
worksheet["B4"].CellStyle = boldFontStyle;
worksheet["A6"].Value = "Date";
worksheet["A6"].CellStyle = boldFontStyle;
worksheet["B6"].DateTime = materialTransaction?.CreateDate ?? DateTime.Now;
if (!string.IsNullOrEmpty(wzClient?.LogoBase64))
{
byte[] logoBytes = Convert.FromBase64String(wzClient.LogoBase64);
worksheet.Range["D1:F6"].Merge();
using MemoryStream imageStream = new MemoryStream(logoBytes);
worksheet.Pictures.AddPicture(1, 4, imageStream);
}
int currentRow = 12;
for (int i = 0; i < mainHeaders.Count; i++)

View File

@@ -14,4 +14,11 @@ public class WzClientController(IWzClientService service) : Controller
IEnumerable<WzClientDto> wzClients = await service.GetAll();
return Ok(wzClients);
}
[HttpGet("by-id")]
public async Task<ActionResult<WzClientDto>> GetById(Guid id)
{
WzClientDto? wzClient = await service.GetById(id);
return Ok(wzClient);
}
}

View File

@@ -260,8 +260,8 @@
{
int count = WzRowsMarelli.Count(x => x.PalletNumber == null);
_isValid = true;
_isValid = count == 0;
_isValid = _isValid && !string.IsNullOrWhiteSpace(EmailAddresses);
// _isValid = count == 0;
// _isValid = _isValid && !string.IsNullOrWhiteSpace(EmailAddresses);
if (_isValid)
{

View File

@@ -5,4 +5,5 @@ namespace SytelineSaAppEfDataModel.Services;
public interface IWzClientService
{
Task<IEnumerable<WzClientDto>> GetAll();
Task<WzClientDto?> GetById(Guid id);
}

View File

@@ -10,4 +10,10 @@ public class WzClientService(SytelineSaAppDbContext context, IMapper mapper) : I
{
return await context.WzClients.Select(x => mapper.Map<WzClientDto>(x)).ToListAsync();
}
public async Task<WzClientDto?> GetById(Guid id)
{
var entity = await context.WzClients.FirstOrDefaultAsync(x => x.ID == id);
return entity == null ? null : mapper.Map<WzClientDto>(entity);
}
}