using General_Ledger_Service.DTOs.Reports; namespace General_Ledger_Service.Services.CsvDocuments { public static class ProfitAndLossCsvDocument { public static byte[] Generate(ProfitAndLossReportDto data) { var csv = new CsvBuilder(); csv.AddRow("Section", "Account Code", "Account Name", "Amount"); AddSection(csv, "Sales", data.Sales); AddSection(csv, "Cost of Sales", data.CostOfSales); csv.AddRow("", "", "GROSS PROFIT", data.GrossProfit); AddSection(csv, "Other Income", data.OtherIncome); AddSection(csv, "Distribution Expenses", data.DistributionExpenses); AddSection(csv, "Administration Expenses", data.AdministrationExpenses); AddSection(csv, "Other Expenses", data.OtherExpenses); AddSection(csv, "Financial Expenses", data.FinancialExpenses); if (data.Unclassified.Lines.Count > 0) { AddSection(csv, "Unclassified", data.Unclassified); } csv.AddRow("", "", "NET PROFIT FOR THE PERIOD", data.NetProfitForPeriod); return csv.Build(); } private static void AddSection(CsvBuilder csv, string section, ProfitAndLossSectionDto sectionDto) { foreach (var line in sectionDto.Lines) { csv.AddRow(section, line.AccountCode, line.AccountName, line.Amount); } csv.AddRow(section, "", $"Total {section}", sectionDto.Total); } } }