Skip to content

Commit

Permalink
New - Ajout d'un listing des declarations manquantes pour les product…
Browse files Browse the repository at this point in the history
…eurs approchant les 150€ par mois
  • Loading branch information
noelmugnier committed Nov 8, 2020
1 parent df10ccf commit 5133667
Show file tree
Hide file tree
Showing 5 changed files with 157 additions and 34 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Sheaft.Domain.Enums;
using System;

namespace Sheaft.Application.Models
{
public class ProducerRequiredDeclarationViewModel
{
public Guid Id { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Name { get; set; }
public decimal Total { get; set; }
}
}
45 changes: 45 additions & 0 deletions Sheaft.Web.Manage/Controllers/DeclarationsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Threading.Tasks;
using System.Collections.Generic;
using Sheaft.Domain.Models;
using Sheaft.Domain.Enums;

namespace Sheaft.Web.Manage.Controllers
{
Expand All @@ -33,6 +34,50 @@ public DeclarationsController(
_logger = logger;
}

[HttpGet]
public async Task<IActionResult> Index(CancellationToken token, int page = 0, int take = 10)
{
if (page < 0)
page = 0;

if (take > 100)
take = 100;

var legalIds = await _context.Legals
.OfType<BusinessLegal>()
.Get(c => c.DeclarationRequired && c.Declaration != null && c.Declaration.Status == DeclarationStatus.Validated)
.Select(c => c.Id)
.ToListAsync(token);

var currentMonth = DateTimeOffset.UtcNow.Month;
var query = await _context.PurchaseOrders.Get(d =>
d.Status >= PurchaseOrderStatus.Accepted
&& d.Status < PurchaseOrderStatus.Refused)
.Where(d => d.CreatedOn.Month == currentMonth && !legalIds.Contains(d.Vendor.Id))
.Select(d => new { d.Vendor, d.TotalOnSalePrice })
.ToListAsync(token);

var results = query.GroupBy(c => c.Vendor).Select(d => new ProducerRequiredDeclarationViewModel
{
Id = d.Key.Id,
Name = d.Key.Name,
Email = d.Key.Email,
Phone = d.Key.Phone,
Total = d.Sum(e => e.TotalOnSalePrice)
}).Where(d => d.Total > 100);

var entities = results
.OrderByDescending(c => c.Total)
.Skip(page * take)
.Take(take)
.ToList();

ViewBag.Page = page;
ViewBag.Take = take;

return View(entities);
}

[HttpGet]
public async Task<IActionResult> Details(Guid declarationId, CancellationToken token)
{
Expand Down
6 changes: 2 additions & 4 deletions Sheaft.Web.Manage/Views/Agreements/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
<table class="table table-hover">
<thead class="thead-dark">
<tr>
<th scope="col">Id</th>
<th scope="col">Producer</th>
<th scope="col">Store</th>
<th scope="col">Status</th>
Expand All @@ -78,8 +77,7 @@
@foreach (var entity in Model)
{
<tr>
<th scope="row">@entity.Id</th>
<td>
<th scope="row">
@entity.Delivery.Producer.Name

@if (!imperonatingId.HasValue)
Expand All @@ -91,7 +89,7 @@
</button>
}
}
</td>
</th>
<td>
@entity.Store.Name

Expand Down
67 changes: 37 additions & 30 deletions Sheaft.Web.Manage/Views/Dashboard/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -30,40 +30,40 @@
</div>
</div>
@*<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Tags</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Tags</h6>
<a asp-controller="Tags" asp-action="index" class="card-link">Show</a>
<div class="card-body">
<h5 class="card-title">Tags</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Tags</h6>
<a asp-controller="Tags" asp-action="index" class="card-link">Show</a>
</div>
</div>
</div>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Departments</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Departments</h6>
<a asp-controller="Departments" asp-action="index" class="card-link">Show</a>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Departments</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Departments</h6>
<a asp-controller="Departments" asp-action="index" class="card-link">Show</a>
</div>
</div>
</div>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Regions</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Regions</h6>
<a asp-controller="Regions" asp-action="index" class="card-link">Show</a>
</div>
</div>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Levels</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Levels</h6>
<a asp-controller="Levels" asp-action="index" class="card-link">Show</a>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Regions</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Regions</h6>
<a asp-controller="Regions" asp-action="index" class="card-link">Show</a>
</div>
</div>
</div>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Rewards</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Rewards</h6>
<a asp-controller="Rewards" asp-action="index" class="card-link">Show</a>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Levels</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Levels</h6>
<a asp-controller="Levels" asp-action="index" class="card-link">Show</a>
</div>
</div>
</div>*@
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Rewards</h5>
<h6 class="card-subtitle mb-2 text-muted">@ViewBag.Rewards</h6>
<a asp-controller="Rewards" asp-action="index" class="card-link">Show</a>
</div>
</div>*@
}
@if (!user.IsInRole("STORE") && !user.IsInRole("CONSUMER"))
{
Expand Down Expand Up @@ -159,4 +159,11 @@
<a asp-controller="Donations" asp-action="index" class="card-link">Show</a>
</div>
</div>
<div class="card w-25 d-inline-block">
<div class="card-body">
<h5 class="card-title">Declarations</h5>
<h6 class="card-subtitle mb-2 text-muted"></h6>
<a asp-controller="Declarations" asp-action="index" class="card-link">Show</a>
</div>
</div>
</div>
59 changes: 59 additions & 0 deletions Sheaft.Web.Manage/Views/Declarations/Index.cshtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
@model IEnumerable<ProducerRequiredDeclarationViewModel>
@{
ViewData["Title"] = "Declarations";
int take = ViewBag.Take;
int currentPage = ViewBag.Page;
Guid? imperonatingId = Context.Request.ImpersonificationId();
}

<div class="container">
<h2 class="display-5">DeliveryModes</h2>
<br />

<table class="table table-hover">
<thead class="thead-dark">
<tr>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Total</th>
<th scope="col">
</th>
</tr>
</thead>
<tbody>
@foreach (var entity in Model)
{
<tr>
<th scope="row">@entity.Name</th>
<td>@entity.Email</td>
<td>@entity.Phone</td>
<td>@(entity.Total)€</td>
<td>
<a asp-controller="Producers" asp-action="Edit" asp-route-id="@entity.Id" class="btn btn-info">
<i class="fa fa-pen"></i>
</a>
</td>
</tr>
}
</tbody>
<tfoot>
<tr class="text-center">
<td colspan="6">
@if (currentPage >= 1)
{
<a asp-controller="Producers" asp-action="Index" asp-route-take="@take" asp-route-page="@(currentPage-1)" class="btn btn-outline-secondary">
<i class="fa fa-caret-left"></i>
</a>
}
@if (take == Model.Count())
{
<a asp-controller="Producers" asp-action="Index" asp-route-take="@take" asp-route-page="@(currentPage+1)" class="btn btn-outline-secondary">
<i class="fa fa-caret-right"></i>
</a>
}
</td>
</tr>
</tfoot>
</table>
</div>

0 comments on commit 5133667

Please sign in to comment.