Distribution report
This commit is contained in:
@@ -119,11 +119,8 @@ namespace InventoryTraker.Web.Controllers
|
||||
TransactionType = TransactionType.Distributed,
|
||||
RemovedQuantity = quantityForm.Quantity,
|
||||
CurrentQuantity = inventory.Quantity,
|
||||
Memo =
|
||||
string.IsNullOrEmpty(form.Memo)
|
||||
? $"{form.Memo} | "
|
||||
: ""
|
||||
+ $"Distributed to {form.Destination}",
|
||||
Destination = form.Destination,
|
||||
Memo = form.Memo,
|
||||
Timestamp = DateTime.Now,
|
||||
TransactionDate = form.DistributedDate
|
||||
});
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using InventoryTraker.Web.Core;
|
||||
using InventoryTraker.Web.Data;
|
||||
using InventoryTraker.Web.Models;
|
||||
|
||||
namespace InventoryTraker.Web.Controllers
|
||||
{
|
||||
public class ReportController : ControllerBase
|
||||
{
|
||||
private readonly AppDbContext _context;
|
||||
|
||||
public ReportController(AppDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public ActionResult Distribution()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult Distribution(DateTime startDate, DateTime endDate)
|
||||
{
|
||||
var query =
|
||||
from t in _context.Transactions
|
||||
where
|
||||
t.TransactionType == TransactionType.Distributed
|
||||
&& t.TransactionDate >= startDate
|
||||
&& t.TransactionDate < endDate
|
||||
group t by new { t.TransactionDate, t.Destination }
|
||||
into g
|
||||
select new
|
||||
{
|
||||
Date = g.Key.TransactionDate,
|
||||
Destination = g.Key.Destination,
|
||||
Transactions = g.ToList()
|
||||
//(from transaction in g
|
||||
//select Mapper.Map<TransactionViewModel>(transaction)).ToArray()
|
||||
};
|
||||
|
||||
var report =
|
||||
from item in query.ToArray()
|
||||
select new DistributionReport
|
||||
{
|
||||
Date = item.Date,
|
||||
Destination = item.Destination,
|
||||
Transactions =
|
||||
Mapper.Map<IList<Transaction>, IList<TransactionViewModel>>
|
||||
(item.Transactions).ToArray()
|
||||
};
|
||||
|
||||
return BetterJson(report.ToArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using AutoMapper.QueryableExtensions;
|
||||
using InventoryTraker.Web.Attributes;
|
||||
|
||||
Reference in New Issue
Block a user