source: StockMaster/Controllers/ReportController.cs@ dfe03b8

main
Last change on this file since dfe03b8 was dfe03b8, checked in by Ceyda <ceyda.huseini@…>, 3 days ago

Initialize StockMaster project

  • Property mode set to 100644
File size: 6.6 KB
Line 
1using Microsoft.AspNetCore.Authorization;
2using Microsoft.AspNetCore.Mvc;
3using StockMaster.Services;
4using System.Threading.Tasks;
5
6namespace StockMaster.Controllers
7{
8 [Authorize]
9 public class ReportController : Controller
10 {
11 private readonly IReportService _reportService;
12
13 public ReportController(IReportService reportService)
14 {
15 _reportService = reportService;
16 }
17
18 public IActionResult Index()
19 {
20 return View();
21 }
22
23 public async Task<IActionResult> StockByWarehouse()
24 {
25 var data = await _reportService.GetStockByWarehouseAsync();
26 return View(data);
27 }
28
29 public async Task<IActionResult> ProductRevenue()
30 {
31 var data = await _reportService.GetProductRevenueAsync();
32 return View(data);
33 }
34
35 public async Task<IActionResult> POStatus()
36 {
37 var data = await _reportService.GetPOStatusAsync();
38 return View(data);
39 }
40
41 public async Task<IActionResult> CategoryRevenue()
42 {
43 var data = await _reportService.GetCategoryRevenueAsync();
44 return View(data);
45 }
46
47 public async Task<IActionResult> WarehouseCapacity()
48 {
49 var data = await _reportService.GetWarehouseCapacityAsync();
50 return View(data);
51 }
52
53 public async Task<IActionResult> StagnantProducts()
54 {
55 var data = await _reportService.GetStagnantProductsAsync();
56 return View(data);
57 }
58
59 public async Task<IActionResult> StockSufficiency()
60 {
61 var data = await _reportService.GetStockSufficiencyAsync();
62 return View(data);
63 }
64
65 public async Task<IActionResult> AnnualSales()
66 {
67 var data = await _reportService.GetAnnualSalesReportAsync();
68 return View(data);
69 }
70
71 public async Task<IActionResult> DetailedPO()
72 {
73 var data = await _reportService.GetDetailedPOReportAsync();
74 return View(data);
75 }
76
77 public async Task<IActionResult> PriceLogs()
78 {
79 var data = await _reportService.GetPriceLogsAsync();
80 return View(data);
81 }
82
83 public async Task<IActionResult> ExportStockByWarehouse()
84 {
85 var data = await _reportService.GetStockByWarehouseAsync();
86 return CreateCsvFile(data, "StockByWarehouse.csv");
87 }
88
89 public async Task<IActionResult> ExportProductRevenue()
90 {
91 var data = await _reportService.GetProductRevenueAsync();
92 return CreateCsvFile(data, "ProductRevenue.csv");
93 }
94
95 public async Task<IActionResult> ExportPOStatus()
96 {
97 var data = await _reportService.GetPOStatusAsync();
98 return CreateCsvFile(data, "POStatus.csv");
99 }
100
101 public async Task<IActionResult> ExportCategoryRevenue()
102 {
103 var data = await _reportService.GetCategoryRevenueAsync();
104 return CreateCsvFile(data, "CategoryRevenue.csv");
105 }
106
107 public async Task<IActionResult> ExportWarehouseCapacity()
108 {
109 var data = await _reportService.GetWarehouseCapacityAsync();
110 return CreateCsvFile(data, "WarehouseCapacity.csv");
111 }
112
113 public async Task<IActionResult> ExportStagnantProducts()
114 {
115 var data = await _reportService.GetStagnantProductsAsync();
116 return CreateCsvFile(data, "StagnantProducts.csv");
117 }
118
119 public async Task<IActionResult> ExportStockSufficiency()
120 {
121 var data = await _reportService.GetStockSufficiencyAsync();
122 return CreateCsvFile(data, "StockTrendAnalysis.csv");
123 }
124
125 public async Task<IActionResult> ExportAnnualSales()
126 {
127 var data = await _reportService.GetAnnualSalesReportAsync();
128 return CreateCsvFile(data, "AnnualSales.csv");
129 }
130
131 public async Task<IActionResult> ExportDetailedPO()
132 {
133 var data = await _reportService.GetDetailedPOReportAsync();
134 return CreateCsvFile(data, "DetailedPO.csv");
135 }
136
137 public async Task<IActionResult> SalesByDay()
138 {
139 var data = await _reportService.GetSalesByDayAsync();
140
141 return View(data);
142 }
143
144 public async Task<IActionResult> ExportSalesByDay()
145 {
146 var data = await _reportService.GetSalesByDayAsync();
147 return CreateCsvFile(data, "SalesByDay.csv");
148 }
149
150 public async Task<IActionResult> ExportPriceLogs()
151 {
152 var data = await _reportService.GetPriceLogsAsync();
153 return CreateCsvFile(data, "PriceChangeLogs.csv");
154 }
155
156 public async Task<IActionResult> ExportEmployeeRanking()
157 {
158 var data = await _reportService.GetEmployeeRankingsAsync();
159 return CreateCsvFile(data, "EmployeePerformanceReport.csv");
160 }
161
162 public async Task<IActionResult> EmployeePerformance()
163 {
164 var data = await _reportService.GetEmployeeRankingsAsync();
165 return View(data);
166 }
167
168 public async Task<IActionResult> TodaysSummary()
169 {
170 var data = await _reportService.GetTodaysSummaryAsync();
171 return View(data);
172 }
173
174 public async Task<IActionResult> ExportTodaysSummary()
175 {
176 var data = await _reportService.GetTodaysSummaryAsync();
177 return CreateCsvFile(new List<StockMaster.Models.VwTodaysSummary> { data }, "TodaysSummary.csv");
178 }
179
180 private FileResult CreateCsvFile<T>(IEnumerable<T> data, string fileName)
181 {
182 var builder = new System.Text.StringBuilder();
183 var props = typeof(T).GetProperties();
184
185 builder.AppendLine(string.Join(",", props.Select(p => p.Name)));
186
187 foreach (var item in data)
188 {
189 var values = new List<string>();
190 foreach (var prop in props)
191 {
192 var value = prop.GetValue(item, null) ?? "";
193 var strValue = value.ToString().Replace("\"", "\"\"");
194
195
196 if (strValue.Contains(",") || strValue.Contains("\n"))
197 {
198 strValue = $"\"{strValue}\"";
199 }
200 values.Add(strValue);
201 }
202 builder.AppendLine(string.Join(",", values));
203 }
204
205 var bytes = System.Text.Encoding.UTF8.GetBytes(builder.ToString());
206 return File(bytes, "text/csv", fileName);
207 }
208 }
209
210
211
212}
Note: See TracBrowser for help on using the repository browser.