From c929e7e17a489dbe858cbe9ec496cb67d5bf1d34 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Fri, 25 Aug 2023 15:35:26 +0200 Subject: [PATCH] print customer statistic with or without price --- .../AdvisorCustomerStatisticComponent.razor | 76 ++++++++++++++++ .../Local.Services/CabinetDrawerService.cs | 2 +- Wonky.Client/Models/DkStatisticPrint.cs | 9 ++ .../{HistoryFilter.cs => InventoryItem.cs} | 2 +- Wonky.Client/Models/StatisticDrawer.cs | 2 +- .../Pages/AdvisorCustomerStatisticPage.razor | 81 +++-------------- .../AdvisorCustomerStatisticPage.razor.cs | 81 ++++++++++++----- .../AdvisorCustomerStatisticPrintPage.razor | 36 ++++++++ ...AdvisorCustomerStatisticPrintPage.razor.cs | 91 +++++++++++++++++++ Wonky.Client/wwwroot/appsettings.json | 4 +- 10 files changed, 290 insertions(+), 94 deletions(-) create mode 100644 Wonky.Client/Components/AdvisorCustomerStatisticComponent.razor create mode 100644 Wonky.Client/Models/DkStatisticPrint.cs rename Wonky.Client/Models/{HistoryFilter.cs => InventoryItem.cs} (91%) create mode 100644 Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor create mode 100644 Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor.cs diff --git a/Wonky.Client/Components/AdvisorCustomerStatisticComponent.razor b/Wonky.Client/Components/AdvisorCustomerStatisticComponent.razor new file mode 100644 index 00000000..e77ea645 --- /dev/null +++ b/Wonky.Client/Components/AdvisorCustomerStatisticComponent.razor @@ -0,0 +1,76 @@ +@using Wonky.Client.Models + + + + + + + + + + + + @if (IncludePrice) + { + + + } + + + + @foreach (var item in Items) + { + + + + + + @if (IncludePrice) + { + + + } + + } + +
+

Produktkøb @CompanyName

+

@HeaderGenerated

+
+ Beskrivelse + + Vare Nr. + + Dato + + Antal + + Pris + + Afslag +
+ @item.Description + + @item.Sku + + @item.DeliveryDate.ToShortDateString() + + @item.Quantity + + @item.Price + + @(item.Discount)% +
+ + +@code { + + [Parameter] public string CompanyName { get; set; } = ""; + + [Parameter] public string HeaderGenerated { get; set; } = ""; + + [Parameter] public List Items { get; set; } = new(); + + [Parameter] public bool IncludePrice { get; set; } + +} \ No newline at end of file diff --git a/Wonky.Client/Local.Services/CabinetDrawerService.cs b/Wonky.Client/Local.Services/CabinetDrawerService.cs index 2dd11715..ef101ce1 100644 --- a/Wonky.Client/Local.Services/CabinetDrawerService.cs +++ b/Wonky.Client/Local.Services/CabinetDrawerService.cs @@ -132,7 +132,7 @@ public class CabinetDrawerService : ICabinetDrawerService if (drawer == null) force = true; if (!force) return drawer ?? new StatisticDrawer(); var result = await _historyRepo.GetProductInvoiceLines(companyId); - var content = result.Select(x => new HistoryFilter + var content = result.Select(x => new InventoryItem { DeliveryDate = DateTime.Parse(x.DeliveryDate), Description = x.Description, diff --git a/Wonky.Client/Models/DkStatisticPrint.cs b/Wonky.Client/Models/DkStatisticPrint.cs new file mode 100644 index 00000000..00caa58d --- /dev/null +++ b/Wonky.Client/Models/DkStatisticPrint.cs @@ -0,0 +1,9 @@ +namespace Wonky.Client.Models; + +public class DkStatisticPrint +{ + public string DeliveryDate { get; set; } = ""; + public string Description { get; set; } = ""; + public string Sku { get; set; } = ""; + public int Quantity { get; set; } +} \ No newline at end of file diff --git a/Wonky.Client/Models/HistoryFilter.cs b/Wonky.Client/Models/InventoryItem.cs similarity index 91% rename from Wonky.Client/Models/HistoryFilter.cs rename to Wonky.Client/Models/InventoryItem.cs index 05bcef89..fe2bd3be 100644 --- a/Wonky.Client/Models/HistoryFilter.cs +++ b/Wonky.Client/Models/InventoryItem.cs @@ -1,6 +1,6 @@ namespace Wonky.Client.Models; -public class HistoryFilter +public class InventoryItem { public DateTime DeliveryDate { get; set; } public string Description { get; set; } = ""; diff --git a/Wonky.Client/Models/StatisticDrawer.cs b/Wonky.Client/Models/StatisticDrawer.cs index c7bf413c..446af056 100644 --- a/Wonky.Client/Models/StatisticDrawer.cs +++ b/Wonky.Client/Models/StatisticDrawer.cs @@ -6,5 +6,5 @@ public class StatisticDrawer { public const string Label = "Statistic"; public DateTime LastDateModified { get; set; } - public List Content { get; set; } = new(); + public List Content { get; set; } = new(); } \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor index d22a1402..9a6776e1 100644 --- a/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor +++ b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor @@ -20,80 +20,27 @@ Produktkøb @_company.Name
-
-
-
-
- +
+ + Tilbage
-@if (DisplayList.Any()) -{ - - - - - - - - - - - - - - - - @foreach (var item in DisplayList) - { - - - - - - - - - } - -
-

Produktkøb @_company.Name

-

Dannet @DateTime.Today.ToLongDateString() (@Months md.)

-
- Beskrivelse - - Vare Nr. - - Dato - - Antal - - Pris - - Afslag -
- @item.Description - - @item.Sku - - @item.DeliveryDate.ToShortDateString() - - @item.Quantity - - @item.Price - - @(item.Discount)% -
-} -else -{ -
Ingen data
-} \ No newline at end of file +
+ +
+ diff --git a/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor.cs index 18355a16..c31fa9e6 100644 --- a/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor.cs +++ b/Wonky.Client/Pages/AdvisorCustomerStatisticPage.razor.cs @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Components; using Wonky.Client.Local.Services; using Wonky.Client.Models; using Wonky.Entity.DTO; -using Wonky.Entity.Views; #pragma warning disable CS8618 @@ -10,45 +9,83 @@ namespace Wonky.Client.Pages; public partial class AdvisorCustomerStatisticPage { + // ############################################################## [Inject] public ICabinetDrawerService DrawerService { get; set; } - + [Inject] public ILogger Logger { get; set; } + [Inject] public NavigationManager Navigator { get; set; } + + // ############################################################## [Parameter] public string CompanyId { get; set; } = ""; - + + // ############################################################## private InfoDrawer _infoDrawer = new(); private StatisticDrawer _statisticDrawer = new(); - private List DisplayList { get; set; } = new(); private CompanyDto _company = new(); - private int Months { get; set; } - + private List _displayList = new(); + private string _headerGenerated = ""; + private string _baseUri = ""; + private int _months = 24; + private bool _includePrice = true; + + protected override async Task OnInitializedAsync() { _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId); _statisticDrawer = await DrawerService.GetStatisticDrawerAsync(CompanyId); _company = _infoDrawer.Content; - if (Months == 0) - { - Months = 24; - } - FilterDisplayList(Months); + _baseUri = Navigator.Uri.Split("?")[0]; + _displayList = GenerateDisplayList(_months, _includePrice); + UpdateDisplayData(_months, _includePrice); } - private void FilterDisplayList(int months) + + private void PrintReport() { - if (_statisticDrawer.Content.Any()) - { - DisplayList = _statisticDrawer.Content - .Where(x => x.DeliveryDate > DateTime.Now.AddMonths(-months)) - .OrderBy(x => x.Description).ThenByDescending(x => x.DeliveryDate) - .ToList(); - } + Navigator.NavigateTo($"{_baseUri}/print/{_months}/{_includePrice}"); } + + private void TogglePrice() + { + _includePrice = !_includePrice; + UpdateDisplayData(_months, _includePrice); + } + + private void OnSelectChanged(ChangeEventArgs e) { var val = e.Value?.ToString(); - var x = Convert.ToInt32(val); - if (x > 24) x = 24; - FilterDisplayList(x); + var months = Convert.ToInt32(val); + if (months > 24) months = 24; + _months = months; + UpdateDisplayData(_months, _includePrice); } + + private void UpdateDisplayData(int months, bool includePrice) + { + _headerGenerated = $"Dannet {DateTime.Today.ToLongDateString()} ({months} md.)"; + _displayList = GenerateDisplayList(months, includePrice); + } + + + private List GenerateDisplayList(int months, bool includePrice) + { + return includePrice + ? _statisticDrawer.Content + .Where(x => x.DeliveryDate > DateTime.Now.AddMonths(-months)) + .OrderBy(x => x.Description).ThenByDescending(x => x.DeliveryDate) + .ToList() + : _statisticDrawer.Content + .Where(x => x.DeliveryDate > DateTime.Now.AddMonths(-months)) + .OrderBy(x => x.Description).ThenByDescending(x => x.DeliveryDate) + .Select(x => + new InventoryItem + { + DeliveryDate = x.DeliveryDate, + Description = x.Description, + Quantity = x.Quantity, + Sku = x.Sku + }).ToList(); + } } \ No newline at end of file diff --git a/Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor b/Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor new file mode 100644 index 00000000..ae127cb7 --- /dev/null +++ b/Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor @@ -0,0 +1,36 @@ +@* Copyright (C) 2022 FCS Frede's Computer Services. +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] +*@ + +@using Wonky.Client.Components +@using Microsoft.AspNetCore.Authorization +@attribute [Authorize(Roles = "Advisor")] +@page "/advisor/customers/{CompanyId}/statistic/print/{Months}/{IncludePrice}" + +Produktkøb @_company.Name + +
+
+ + +
+
+ +
+
+ +
+
+ diff --git a/Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor.cs b/Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor.cs new file mode 100644 index 00000000..05fdf65a --- /dev/null +++ b/Wonky.Client/Pages/AdvisorCustomerStatisticPrintPage.razor.cs @@ -0,0 +1,91 @@ +using System.Text.Json; +using Microsoft.AspNetCore.Components; +using Microsoft.AspNetCore.Components.Routing; +using Microsoft.JSInterop; +using Wonky.Client.Helpers; +using Wonky.Client.Local.Services; +using Wonky.Client.Models; +using Wonky.Entity.DTO; + +#pragma warning disable CS8618 + +namespace Wonky.Client.Pages; + +public partial class AdvisorCustomerStatisticPrintPage +{ + // ############################################################## + [Inject] public ICabinetDrawerService DrawerService { get; set; } + [Inject] public ILogger Logger { get; set; } + [Inject] public NavigationManager Navigator { get; set; } + [Inject] public IJSRuntime JsRuntime { get; set; } + + // ############################################################## + [Parameter] public string CompanyId { get; set; } = ""; + [Parameter] public string Months { get; set; } + [Parameter] public string IncludePrice { get; set; } + + + // ############################################################## + private IJSObjectReference JsModule { get; set; } + private InfoDrawer _infoDrawer = new(); + private StatisticDrawer _statisticDrawer = new(); + private CompanyDto _company = new(); + private List _displayList = new(); + private string _headerGenerated = ""; + private int _months; + private bool _includePrice; + + + protected override async Task OnInitializedAsync() + { + Logger.LogDebug(Months); + Logger.LogDebug(IncludePrice); + _infoDrawer = await DrawerService.GetInfoDrawerAsync(CompanyId); + _company = _infoDrawer.Content; + + _statisticDrawer = await DrawerService.GetStatisticDrawerAsync(CompanyId); + _includePrice = Convert.ToBoolean(IncludePrice); + _months = Convert.ToInt32(Months); + _displayList = GenerateDisplayList(_months, _includePrice); + + Logger.LogDebug("{}", JsonSerializer.Serialize(_displayList)); + _headerGenerated = $"Dannet {DateTime.Today.ToLongDateString()} ({Months} md.)"; + } + + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + JsModule = await JsRuntime + .InvokeAsync("import", "/scripts/print-invoke.js"); + } + } + + + private async Task DoPrint() + { + await JsModule.InvokeVoidAsync("printInvoke"); + } + + + private List GenerateDisplayList(int months, bool includePrice) + { + return includePrice + ? _statisticDrawer.Content + .Where(x => x.DeliveryDate > DateTime.Now.AddMonths(-months)) + .OrderBy(x => x.Description).ThenByDescending(x => x.DeliveryDate) + .ToList() + : _statisticDrawer.Content + .Where(x => x.DeliveryDate > DateTime.Now.AddMonths(-months)) + .OrderBy(x => x.Description).ThenByDescending(x => x.DeliveryDate) + .Select(x => + new InventoryItem + { + DeliveryDate = x.DeliveryDate, + Description = x.Description, + Quantity = x.Quantity, + Sku = x.Sku + }).ToList(); + } +} \ No newline at end of file diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index 41d1a3da..cec924de 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,9 +1,9 @@ { "appInfo": { "name": "Wonky Online", - "version": "224.0", + "version": "227.0", "rc": true, - "sandBox": false, + "sandBox": true, "image": "grumpy-coder.png", "sdk": "dotnet 7.0" },