From ef50cbc3ff531e0b828930876b09f1410b6ff657 Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 15 Dec 2022 17:05:09 +0100 Subject: [PATCH] WIP: quote listing and status update --- .../Components/QuoteListComponent.razor | 99 +++++++++++++++++++ Wonky.Client/Helpers/Utils.cs | 8 +- .../ICrmActivityHttpRepository.cs | 2 +- .../CrmActivityHttpRepository.cs | 16 +-- Wonky.Client/Models/QStatus.cs | 11 +++ Wonky.Client/Models/QuoteCallbackArgs.cs | 7 ++ Wonky.Client/Pages/CrmActivityNewPage.razor | 14 +-- .../Pages/CrmActivityNewPage.razor.cs | 48 +++++---- Wonky.Client/Pages/CrmQuotes.razor | 69 ------------- Wonky.Client/Pages/CrmQuotes.razor.cs | 39 -------- Wonky.Client/Pages/CrmQuotesListPage.razor | 44 +++++++++ Wonky.Client/Pages/CrmQuotesListPage.razor.cs | 81 +++++++++++++++ Wonky.Client/wwwroot/appsettings.json | 4 +- 13 files changed, 297 insertions(+), 145 deletions(-) create mode 100644 Wonky.Client/Components/QuoteListComponent.razor create mode 100644 Wonky.Client/Models/QStatus.cs create mode 100644 Wonky.Client/Models/QuoteCallbackArgs.cs delete mode 100644 Wonky.Client/Pages/CrmQuotes.razor delete mode 100644 Wonky.Client/Pages/CrmQuotes.razor.cs create mode 100644 Wonky.Client/Pages/CrmQuotesListPage.razor create mode 100644 Wonky.Client/Pages/CrmQuotesListPage.razor.cs diff --git a/Wonky.Client/Components/QuoteListComponent.razor b/Wonky.Client/Components/QuoteListComponent.razor new file mode 100644 index 00000000..ae26ba59 --- /dev/null +++ b/Wonky.Client/Components/QuoteListComponent.razor @@ -0,0 +1,99 @@ +@using Wonky.Entity.Views +@using Wonky.Client.Models + +
+
+
+
+ Reference +
+
+ Kunde +
+
+ Dato +
+
+ Status +
+
+
+
+ @if (Quotes.Any()) + { + foreach (var quote in Quotes) + { +
+
+ +
+ @quote.Company.Name +
+ + @quote.OrderDate + +
+ @switch (quote.QuoteStatusEnum) + { + case "None": + + break; + case "Win": + Ordre + break; + case "Lose": + + break; + case "Note": + + break; + case "Archive": + + break; + default: + + break; + } +
+
+ + + + +
+ @if (!string.IsNullOrWhiteSpace(quote.OfficeNote)) + { +
+
+ @quote.OfficeNote +
+ } +
+
+ } + } + else + { +
Ingen data
+ } +
+ +@code { + + [Parameter] + public List Quotes { get; set; } = new(); + [Parameter] public EventCallback OnChangedCallback { get; set; } + + private async Task SetQuote(string eSalesNumber, QStatus status) + { + var args = new QuoteCallbackArgs() + { + ESalesNumber = eSalesNumber, + Status = status + }; + await OnChangedCallback.InvokeAsync(args); + } +} diff --git a/Wonky.Client/Helpers/Utils.cs b/Wonky.Client/Helpers/Utils.cs index 57b4db2d..ebce0ac1 100644 --- a/Wonky.Client/Helpers/Utils.cs +++ b/Wonky.Client/Helpers/Utils.cs @@ -35,7 +35,13 @@ public static class Utils catch { return false; } - } + } + + public static string EnumToString(Enum value) + { + return value.ToString(); + } + public static int GetHashFromNow() { return DateTime.Now.ToFileTimeUtc().GetHashCode(); diff --git a/Wonky.Client/HttpInterfaces/ICrmActivityHttpRepository.cs b/Wonky.Client/HttpInterfaces/ICrmActivityHttpRepository.cs index 7abb669c..dbab34d8 100644 --- a/Wonky.Client/HttpInterfaces/ICrmActivityHttpRepository.cs +++ b/Wonky.Client/HttpInterfaces/ICrmActivityHttpRepository.cs @@ -31,7 +31,7 @@ public interface ICrmActivityHttpRepository /// /// /// - Task AcceptQuote(ReportItemView activity); + Task UpdateQuoteStatus(ReportItemView activity); /// /// Get activities by date diff --git a/Wonky.Client/HttpRepository/CrmActivityHttpRepository.cs b/Wonky.Client/HttpRepository/CrmActivityHttpRepository.cs index d9c088fe..2e1d877b 100644 --- a/Wonky.Client/HttpRepository/CrmActivityHttpRepository.cs +++ b/Wonky.Client/HttpRepository/CrmActivityHttpRepository.cs @@ -13,6 +13,7 @@ // along with this program. If not, see [https://www.gnu.org/licenses/agpl-3.0.en.html] // +using System.Net; using System.Net.Http.Json; using System.Text.Json; using Microsoft.AspNetCore.Components; @@ -60,14 +61,13 @@ public class CrmActivityHttpRepository : ICrmActivityHttpRepository /// /// /// - public async Task AcceptQuote(ReportItemView activity) + public async Task UpdateQuoteStatus(ReportItemView activity) { - var response = await _client.PutAsJsonAsync( - $"{_api.CrmActivities}/{activity.ActivityId}/accept", activity, _options); - + var response = await _client.PutAsJsonAsync( + $"{_api.CrmActivities}/quote/{activity.ActivityId}", activity, _options); var content = await response.Content.ReadAsStringAsync(); - var result = JsonSerializer.Deserialize(content); - return result!; + _logger.LogDebug("UpdateQuote Response Content <= {}", content); + return JsonSerializer.Deserialize(content, _options); } /// @@ -150,7 +150,9 @@ public class CrmActivityHttpRepository : ICrmActivityHttpRepository /// ApiResponseView public async Task GetExpressState(string activityId) { - var response = await _client.GetFromJsonAsync($"{_api.CrmActivities}/express/{activityId}?status=Express", _options); + var response = + await _client.GetFromJsonAsync($"{_api.CrmActivities}/express/{activityId}?status=Express", + _options); return response ?? new ApiResponseView { Code = 404, diff --git a/Wonky.Client/Models/QStatus.cs b/Wonky.Client/Models/QStatus.cs new file mode 100644 index 00000000..130994ce --- /dev/null +++ b/Wonky.Client/Models/QStatus.cs @@ -0,0 +1,11 @@ +namespace Wonky.Client.Models; + +public enum QStatus +{ + None, + Win, + Lose, + Archive, + Note, + All +} \ No newline at end of file diff --git a/Wonky.Client/Models/QuoteCallbackArgs.cs b/Wonky.Client/Models/QuoteCallbackArgs.cs new file mode 100644 index 00000000..44e2ab68 --- /dev/null +++ b/Wonky.Client/Models/QuoteCallbackArgs.cs @@ -0,0 +1,7 @@ +namespace Wonky.Client.Models; + +public class QuoteCallbackArgs +{ + public string ESalesNumber { get; set; } = ""; + public QStatus Status { get; set; } +} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmActivityNewPage.razor b/Wonky.Client/Pages/CrmActivityNewPage.razor index abd5f453..ea304e21 100644 --- a/Wonky.Client/Pages/CrmActivityNewPage.razor +++ b/Wonky.Client/Pages/CrmActivityNewPage.razor @@ -64,7 +64,7 @@ else @if (!string.IsNullOrEmpty(Activity.VatNumber) && !string.IsNullOrWhiteSpace(Activity.Address1) && Company.HasFolded == 0) { - @if (DraftStateProvider.Draft.DraftType == "order") + @if (DraftProvider.Draft.DraftType == "order") { } @@ -73,7 +73,7 @@ else } - @if(DraftStateProvider.Draft.DraftType == "offer") + @if(DraftProvider.Draft.DraftType == "offer") { } @@ -158,10 +158,10 @@ else - Ordrekladde Global kladde (udløber efter @(DraftStateProvider.Draft.TimeToLiveInSeconds / 60)m inaktivitet) + Ordrekladde Global kladde (udløber efter @(DraftProvider.Draft.TimeToLiveInSeconds / 60)m inaktivitet) - + @@ -176,9 +176,9 @@ else - @if (DraftStateProvider.Draft.Items.Count > 0) + @if (DraftProvider.Draft.Items.Count > 0) { - @foreach (var cartItem in DraftStateProvider.Draft.Items) + @foreach (var cartItem in DraftProvider.Draft.Items) { @cartItem.Item.Name @@ -199,7 +199,7 @@ else Total - @($"{DraftStateProvider.Draft.Total:N2}") + @($"{DraftProvider.Draft.Total:N2}") private async Task DeleteDraft() { - await DraftStateProvider.DeleteDraftAsync(); + await DraftProvider.DeleteDraftAsync(); Activity.ActivityStatusEnum = "noSale"; } @@ -342,11 +342,11 @@ public partial class CrmActivityNewPage : IDisposable Price = "0"; Discount = "0"; // add it to the cart - DraftStateProvider.Draft.Items.Add(item); + DraftProvider.Draft.Items.Add(item); if(Activity.ActivityStatusEnum != "quote") Activity.ActivityStatusEnum = "order"; // save the item using the CartStateProvider's save method - await DraftStateProvider.SaveChangesAsync(); + await DraftProvider.SaveChangesAsync(); } /// @@ -356,10 +356,10 @@ public partial class CrmActivityNewPage : IDisposable private async Task RemoveItem(DraftItem item) { // remove item - DraftStateProvider.Draft.Items.Remove(item); + DraftProvider.Draft.Items.Remove(item); // save the remaining draft - await DraftStateProvider.SaveChangesAsync(); - if (!DraftStateProvider.Draft.Items.Any()) + await DraftProvider.SaveChangesAsync(); + if (!DraftProvider.Draft.Items.Any()) Activity.ActivityStatusEnum = "noSale"; } @@ -370,11 +370,20 @@ public partial class CrmActivityNewPage : IDisposable /// private void HandleFieldChanged(object sender, FieldChangedEventArgs e) { - DraftStateProvider.Draft.DraftType = Activity.ActivityStatusEnum; + Logger.LogDebug("ActivityNewPage => HandleFieldChanged => ActivityStatusEnum <= '{}'", Activity.ActivityStatusEnum); + DraftProvider.Draft.DraftType = Activity.ActivityStatusEnum; + if (Activity.ActivityStatusEnum == "noSale") + { + Logger.LogDebug("ActivityNewPage => ActivityStatusEnum == 'noSale' <= remove items"); + DraftProvider.Draft.Items = new List(); + + } + + // InvalidCanvas = InvalidActivityType; InvalidActivity = InvalidActivityType || PoFormInvalid - || DraftStateProvider.Draft.Items.Count == 0 + || DraftProvider.Draft.Items.Count == 0 || (Activity.ActivityStatusEnum == "offer" && string.IsNullOrWhiteSpace(Activity.Email)); if (Activity.YourRef.Length > 35 || Activity.ReferenceNumber.Length > 20 || InvalidActivity) { @@ -395,6 +404,7 @@ public partial class CrmActivityNewPage : IDisposable if (string.IsNullOrEmpty(Activity.ActivityTypeEnum) && !ReportClosed) { Toast.ShowWarning("Aktivitet type kan ikke være tom"); + PoFormInvalid = true; return; } PoFormInvalid = false; diff --git a/Wonky.Client/Pages/CrmQuotes.razor b/Wonky.Client/Pages/CrmQuotes.razor deleted file mode 100644 index 2db46fb8..00000000 --- a/Wonky.Client/Pages/CrmQuotes.razor +++ /dev/null @@ -1,69 +0,0 @@ -@page "/open-quotes" -@using Wonky.Client.Components -
-
-

Åbne tilbud

-
-
-
-
-
-
- Reference -
-
- Kunde -
-
- Dato -
-
- Tilbudssum -
-
-
-
- @if (Quotes.Any()) - { - foreach (var quote in Quotes) - { -
-
- -
- @quote.Company.Name -
- - @quote.OrderDate - -
- @($"{quote.OrderAmount:N2}") -
-
-
-
-
- @if (!string.IsNullOrWhiteSpace(quote.OfficeNote)) - { -
Note
-
- @quote.OfficeNote -
- } -
-
- } - } - else - { -
Ingen data
- } -
- - -@if (Working) -{ - -} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmQuotes.razor.cs b/Wonky.Client/Pages/CrmQuotes.razor.cs deleted file mode 100644 index 3255c9aa..00000000 --- a/Wonky.Client/Pages/CrmQuotes.razor.cs +++ /dev/null @@ -1,39 +0,0 @@ -using Microsoft.AspNetCore.Components; -using Wonky.Client.HttpInterceptors; -using Wonky.Client.HttpInterfaces; -using Wonky.Entity.DTO; -using Wonky.Entity.Views; - -namespace Wonky.Client.Pages; - -public partial class CrmQuotes : IDisposable -{ - [Inject] public ICrmActivityHttpRepository ActivityRepo { get; set; } - [Inject] public HttpInterceptorService Interceptor { get; set; } - private List Quotes { get; set; } = new(); - private bool Working { get; set; } = true; - - protected override async Task OnInitializedAsync() - { - Interceptor.RegisterEvent(); - Interceptor.RegisterBeforeSendEvent(); - Quotes = await ActivityRepo.GetQuotes(); - if (Quotes.Any()) - Quotes = Quotes.OrderBy(x => x.CreateTimestamp).ToList(); - Working = false; - } - - private void SetQuote(int status) - { - // todo - implement update quote from status - // status matches QuoteStatusEnum - // 0 - None - // 1 - Win - // 2 - Lose - // 3 - Draw - } - public void Dispose() - { - Interceptor.DisposeEvent(); - } -} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmQuotesListPage.razor b/Wonky.Client/Pages/CrmQuotesListPage.razor new file mode 100644 index 00000000..1812509c --- /dev/null +++ b/Wonky.Client/Pages/CrmQuotesListPage.razor @@ -0,0 +1,44 @@ +@page "/open-quotes" +@using Wonky.Client.Components +@using Wonky.Client.Models + +
+
+

Tilbud

+
+
+
+ + + + + + + + + + + + + + + + +
+ + @* +
+ + +
+ *@ +
+
+ + + +@if (Working) +{ + +} \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmQuotesListPage.razor.cs b/Wonky.Client/Pages/CrmQuotesListPage.razor.cs new file mode 100644 index 00000000..01d3535f --- /dev/null +++ b/Wonky.Client/Pages/CrmQuotesListPage.razor.cs @@ -0,0 +1,81 @@ +using System.Diagnostics.CodeAnalysis; +using System.Security.Policy; +using System.Text.Json; +using Blazored.LocalStorage; +using Blazored.Toast.Services; +using Microsoft.AspNetCore.Components; +using Wonky.Client.Helpers; +using Wonky.Client.HttpInterceptors; +using Wonky.Client.HttpInterfaces; +using Wonky.Client.Models; +using Wonky.Entity.DTO; +using Wonky.Entity.Views; + +namespace Wonky.Client.Pages; + +public partial class CrmQuotesListPage : IDisposable +{ + [Inject] public ICrmActivityHttpRepository ActivityRepo { get; set; } + [Inject] public HttpInterceptorService Interceptor { get; set; } + [Inject] public ILogger Logger { get; set; } + [Inject] public IToastService Toaster { get; set; } + [Inject] public ILocalStorageService Storage { get; set; } + private List Quotes { get; set; } = new(); + private List _quotes { get; set; } = new(); + private bool Working { get; set; } = true; + private QStatus QFilter { get; set; } = QStatus.None; + + protected override async Task OnInitializedAsync() + { + Interceptor.RegisterEvent(); + Interceptor.RegisterBeforeSendEvent(); + Quotes = await ActivityRepo.GetQuotes(); + await Storage.SetItemAsync("quotes", Quotes); + if (Quotes.Any()) + _quotes = Quotes.Where(x => x.QuoteStatusEnum is "Note" or "None").ToList(); + Working = false; + } + + private async Task FilterQuotes(QStatus status) + { + QFilter = status; + Quotes = await Storage.GetItemAsync>("quotes"); + _quotes = QFilter switch + { + QStatus.None => Quotes.Where(x => x.QuoteStatusEnum is "None").ToList(), + QStatus.Win => Quotes.Where(x => x.QuoteStatusEnum is "Win").ToList(), + QStatus.Lose => Quotes.Where(x => x.QuoteStatusEnum is "Lose").ToList(), + QStatus.Archive => Quotes.Where(x => x.QuoteStatusEnum is "Archive").ToList(), + QStatus.Note => Quotes.Where(x => x.QuoteStatusEnum is "Note").ToList(), + _ => Quotes.ToList() + }; + } + + private async Task UpdateQuoteCallback(QuoteCallbackArgs args) + { + var quote = Quotes.First(x => x.ESalesNumber == args.ESalesNumber); + if (args.Status == QStatus.Win) + quote.OrderDate = $"{DateTime.Now:yyyy-MM-dd}"; + quote.QuoteStatusEnum = Utils.EnumToString(args.Status); + var response = await ActivityRepo.UpdateQuoteStatus(quote); + Toaster.ShowInfo($"{response.Message}", $"HTTP STATUS {response.Code}"); + + Quotes = new List(); + await Storage.RemoveItemAsync("quotes"); + Quotes = await ActivityRepo.GetQuotes(); + while (!Quotes.Any()) + await Task.Delay(1000); + + await Storage.SetItemAsync("quotes", Quotes); + + await FilterQuotes(QFilter); + + StateHasChanged(); + } + + public void Dispose() + { + Storage.RemoveItemAsync("quotes"); + Interceptor.DisposeEvent(); + } +} \ No newline at end of file diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index 1a94a9f0..89abe1a5 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,7 +1,7 @@ { "appInfo": { "name": "Wonky Client", - "version": "0.85.5", + "version": "0.85.7", "rc": true, "sandBox": false, "image": "grumpy-coder.png" @@ -33,7 +33,7 @@ }, "Logging": { "LogLevel": { - "Default": "Debug", + "Default": "Information", "System": "Information", "Microsoft": "Information" },