* Initialized PackingList generation for Marelli

This commit is contained in:
2025-09-29 13:41:09 +02:00
parent 08171522b9
commit f6cc62d6c8

View File

@@ -92,6 +92,86 @@ public class ExcelGeneratorController(IWzHeaderService wzHeaderService, IMateria
SendEmail(stream, wzHeader);
}
[HttpGet("generate-marelli")]
public async Task GeneratePackListForMarelli(Guid packListId)
{
WzHeaderDto wzHeader = await wzHeaderService.GetById(packListId);
MaterialTransactionDto? materialTransaction = await materialTransactionService.GetByWzNumber(wzHeader.WzRowsMeyle.First().WzNumber);
using ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
IStyle boldFontStyle = workbook.Styles.Add("BoldFontStyle");
boldFontStyle.Font.Bold = true;
var mainHeaders = new List<string>
{ "Numer zamówienia Meyle", "Meyle Numer", "Ilość w dostawie", "Numer Palety", "Nr Wz", "Nr Partii" };
worksheet["B1"].Value = "Packing List";
worksheet["B1"].CellStyle = boldFontStyle;
worksheet["B3"].Value = "Supplier Name";
worksheet["B3"].CellStyle = boldFontStyle;
worksheet["D3"].Value = "FA KROSNO";
worksheet["D3"].CellStyle = boldFontStyle;
worksheet["B4"].Value = "Packing List nr";
worksheet["B4"].CellStyle = boldFontStyle;
worksheet["B6"].Value = "Related delivery note";
worksheet["B6"].CellStyle = boldFontStyle;
worksheet["D6"].Value = string.Join(", ", wzHeader.WzRowsMeyle.Select(x => x.WzNumber).Distinct());
worksheet["D6"].CellStyle = boldFontStyle;
worksheet["B9"].Value = "Forwarder";
worksheet["B9"].CellStyle = boldFontStyle;
worksheet["B10"].Value = "Date";
worksheet["B10"].CellStyle = boldFontStyle;
worksheet["D10"].DateTime = materialTransaction?.CreateDate ?? DateTime.Now;
int currentRow = 12;
for (int i = 0; i < mainHeaders.Count; i++)
{
string columnLetter = GetColumnLetter(i);
worksheet.Range[$"{columnLetter}{currentRow}"].Text = mainHeaders[i];
worksheet.Range[$"{columnLetter}{currentRow}"].CellStyle = boldFontStyle;
}
currentRow++;
foreach (var wzRow in wzHeader.WzRowsMeyle)
{
worksheet.Range[$"A{currentRow}"].Text = wzRow.OrderNumber;
worksheet.Range[$"B{currentRow}"].Text = wzRow.ItemNumber;
worksheet.Range[$"C{currentRow}"].Number = (double)wzRow.Quantity!;
worksheet.Range[$"D{currentRow}"].Number = (double)wzRow.PalletNumber!;
worksheet.Range[$"E{currentRow}"].Text = wzRow.WzNumber;
worksheet.Range[$"F{currentRow}"].Text = wzRow.PartNumber;
currentRow++;
}
for (int i = 0; i < 6; i++)
{
worksheet.AutofitColumn(i + 1);
}
using MemoryStream stream = new MemoryStream();
workbook.SaveAs(stream);
stream.Position = 0;
SendEmail(stream, wzHeader);
}
private static string GetColumnLetter(int columnIndex)
{
string columnName = string.Empty;