Files
InventoryTracker/InventoryTraker.Web/Controllers/ReportController.cs
T
2016-09-22 14:14:12 -04:00

76 lines
1.8 KiB
C#

using System;
using System.Linq;
using System.Web.Mvc;
using InventoryTraker.Web.Services;
using InventoryTraker.Web.Utilities;
namespace InventoryTraker.Web.Controllers
{
public class ReportController : ControllerBase
{
private readonly ReportService _reportService;
public ReportController(ReportService reportService)
{
_reportService = reportService;
}
[HttpGet]
public ActionResult Distribution()
{
return View();
}
public ActionResult Distribution(DateTime startDate, DateTime endDate)
{
var report = _reportService.GetDistributionReport(startDate, endDate);
return BetterJson(report.ToArray());
}
public ActionResult DistributionExcel(DateTime startDate, DateTime endDate)
{
var report = _reportService.GetDistributionReport(startDate, endDate);
var writer = new DistributionReportWriter();
var excel = writer.Write(report);
var filename = $"InventoryDistributionReport{startDate:yyyyMMdd}-{endDate:yyyyMMdd}.xlsx";
return
new FileContentResult(excel, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
FileDownloadName = filename
};
}
[HttpGet]
public ActionResult Movement()
{
return View();
}
public ActionResult Movement(DateTime month)
{
var report = _reportService.GetMovementReport(month);
return BetterJson(report);
}
public ActionResult MovementExcel(DateTime month)
{
var report = _reportService.GetMovementReport(month);
var writer = new MovementReportWriter();
var excel = writer.Write(report);
var filename = $"MonthlyInventoryReport{report.Month:MMMMyyyy}.xlsx";
return
new FileContentResult(excel, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
{
FileDownloadName = filename
};
}
}
}