From 00ff0a66f7f7874c7083a1b202c09e807529d57a Mon Sep 17 00:00:00 2001 From: Frede Hundewadt Date: Thu, 10 Nov 2022 12:31:21 +0100 Subject: [PATCH] Invoice history - v.0.38.x --- .../Components/InvoiceTableComponent.razor | 58 +++++++++++++++++++ .../ICrmHistoryHttpRepository.cs | 2 + .../CrmHistoryHttpRepository.cs | 26 +++++++++ .../Pages/CrmCompanyInventoryPage.razor.cs | 13 ++--- .../Pages/CrmCompanyInvoiceListPage.razor | 21 +++++-- .../Pages/CrmCompanyInvoiceListPage.razor.cs | 37 +++++++++++- .../Pages/CrmCompanyViewPage.razor.cs | 4 +- Wonky.Client/wwwroot/appsettings.json | 2 +- Wonky.Entity/Views/InvoiceCompanyView.cs | 19 ++++++ Wonky.Entity/Views/InvoiceLineView.cs | 10 ++++ Wonky.Entity/Views/InvoiceListItemView.cs | 14 +++++ Wonky.Entity/Views/InvoiceListView.cs | 7 +++ Wonky.Entity/Views/InvoiceView.cs | 19 ++++++ 13 files changed, 215 insertions(+), 17 deletions(-) create mode 100644 Wonky.Client/Components/InvoiceTableComponent.razor create mode 100644 Wonky.Entity/Views/InvoiceCompanyView.cs create mode 100644 Wonky.Entity/Views/InvoiceLineView.cs create mode 100644 Wonky.Entity/Views/InvoiceListItemView.cs create mode 100644 Wonky.Entity/Views/InvoiceListView.cs create mode 100644 Wonky.Entity/Views/InvoiceView.cs diff --git a/Wonky.Client/Components/InvoiceTableComponent.razor b/Wonky.Client/Components/InvoiceTableComponent.razor new file mode 100644 index 00000000..42927901 --- /dev/null +++ b/Wonky.Client/Components/InvoiceTableComponent.razor @@ -0,0 +1,58 @@ +@using Wonky.Entity.Views +@using System.Linq.Expressions + +@if (InvoiceList.Any()) +{ +
+
+
+
+

Dato

+
+
+

Faktura

+
+
+

Rekvisition

+
+
+

Reference

+
+
+

Beløb

+
+
+
+ @foreach (var invoice in InvoiceList) + { +
+
+
@invoice.DocumentDate
+
@invoice.DocumentNumber
+
@invoice.ReferenceNumber
+
@invoice.YourRef
+
@invoice.InvoiceAmount
+
+ @if (!string.IsNullOrWhiteSpace(invoice.OrderNote)) + { +
+
+
+
@invoice.OrderNote
+
+ } +
+ } +
+} +else +{ + Ingen data +} + +@code{ + + [Parameter] + public List InvoiceList { get; set; } + +} \ No newline at end of file diff --git a/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs b/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs index 61e3ef80..e7b16bf9 100644 --- a/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs +++ b/Wonky.Client/HttpInterfaces/ICrmHistoryHttpRepository.cs @@ -20,6 +20,8 @@ namespace Wonky.Client.HttpInterfaces; public interface ICrmHistoryHttpRepository { + Task FetchInvoiceList(string companyId); + Task FetchInvoice(string companyId, string invoiceId); Task?> FetchInventory(string companyId); Task?> FetchHistory(string companyId); Task?> FetchHistory(string companyId, string sku); diff --git a/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs b/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs index 60cbd1e3..aecb95fe 100644 --- a/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs +++ b/Wonky.Client/HttpRepository/CrmHistoryHttpRepository.cs @@ -46,6 +46,32 @@ public class CrmHistoryHttpRepository : ICrmHistoryHttpRepository _navigation = navigation; _api = configuration.Value; } + /// + /// fetch a list of invoices for CompanyId + /// + /// + /// + public async Task FetchInvoiceList(string companyId) + { + var response = await _client.GetAsync($"{_api.CrmCustomers}/{companyId}/invoices"); + var content = await response.Content.ReadAsStringAsync(); + return response.IsSuccessStatusCode + ? JsonSerializer.Deserialize(content, _options) + : new InvoiceListView(); + } + + /// + /// Fetch invoice from archiveHeadId + /// + /// + /// + /// + public async Task FetchInvoice(string companyId, string invoiceId) + { + return await _client + .GetFromJsonAsync($"{_api.CrmCustomers}/{companyId}/invoices/{invoiceId}"); + } + /// /// fetch inventory - summarized list of products /// diff --git a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs index 69f6975a..a016ebda 100644 --- a/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs +++ b/Wonky.Client/Pages/CrmCompanyInventoryPage.razor.cs @@ -34,9 +34,9 @@ public partial class CrmCompanyInventoryPage : IDisposable [Inject] public IToastService Toaster { get; set; } [Inject] public ILogger Logger { get; set; } private CompanyDto Company { get; set; } = new(); - private List? Inventory { get; set; } = new(); + private List? Inventory { get; set; } private bool Loading { get; set; } = true; - + protected override async Task OnInitializedAsync() { Interceptor.RegisterEvent(); @@ -46,16 +46,15 @@ public partial class CrmCompanyInventoryPage : IDisposable await RefreshHistory(); } - + private async Task RefreshHistory() { - Toaster.ShowInfo("Varekøb opdateres ....", "Vent venligst"); - await CrmHistoryRepo.RpcSyncErpToCrm(CompanyId, Company.HistorySync); - + Toaster.ShowInfo("Arbejder på sagen ...", "Vent venligst"); Inventory = await CrmHistoryRepo.FetchInventory(CompanyId); - Inventory = Inventory.OrderBy(x => x.Description).ToList(); + Inventory = Inventory?.OrderBy(x => x.Description).ToList(); Loading = false; + Toaster.ClearAll(); } public void Dispose() diff --git a/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor b/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor index d5729873..9e87756a 100644 --- a/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor +++ b/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor @@ -1,6 +1,19 @@ @page "/companies/{CompanyId}/invoices" -
-
-

Faktura oversigt

+@using Wonky.Client.Components +
+
+

@Company.Name

-
\ No newline at end of file + +
+@if (Loading) +{ + +} +else +{ + +} diff --git a/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor.cs b/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor.cs index 14c6bdc3..d33b30df 100644 --- a/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor.cs +++ b/Wonky.Client/Pages/CrmCompanyInvoiceListPage.razor.cs @@ -1,14 +1,45 @@ +using System.Net.NetworkInformation; +using System.Text.Json; +using Blazored.Toast.Services; 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 CrmCompanyInvoiceListPage +public partial class CrmCompanyInvoiceListPage : IDisposable { [Parameter] public string CompanyId { get; set; } = ""; [Inject] public ICrmCompanyHttpRepository CompanyRepo { get; set; } [Inject] public HttpInterceptorService Interceptor { get; set; } - - + [Inject] public ICrmHistoryHttpRepository HistoryRepo { get; set; } + [Inject] public IToastService Toaster { get; set; } + + private InvoiceListView History { get; set; } = new(); + private CompanyDto Company { get; set; } + private bool Loading { get; set; } = true; + + protected override async Task OnInitializedAsync() + { + Interceptor.RegisterEvent(); + Interceptor.RegisterBeforeSendEvent(); + + Company = await CompanyRepo.GetCompanyById(CompanyId); + await RefreshHistory(); + } + + private async Task RefreshHistory() + { + Toaster.ShowInfo("Arbejder på sagen ...", "Vent venligst"); + await HistoryRepo.RpcSyncErpToCrm(CompanyId, Company.HistorySync); + History = await HistoryRepo.FetchInvoiceList(CompanyId); + Loading = false; + Toaster.ClearAll(); + } + public void Dispose() + { + Interceptor.DisposeEvent(); + } } \ No newline at end of file diff --git a/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs b/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs index 0bfdbf1a..a6a96e1e 100644 --- a/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs +++ b/Wonky.Client/Pages/CrmCompanyViewPage.razor.cs @@ -82,7 +82,7 @@ public partial class CrmCompanyViewPage : IDisposable var ux = await _storage.GetItemAsync("_xu"); _countryCode = ux.CountryCode; _dk = ux.CountryCode.ToLower() == "dk"; - + _interceptor.RegisterEvent(); _interceptor.RegisterBeforeSendEvent(); @@ -131,7 +131,7 @@ public partial class CrmCompanyViewPage : IDisposable _editContext.OnFieldChanged += HandleFieldChanged; _editContext.OnValidationStateChanged += ValidationChanged; } - + private void ForceActivity() { _enableActivity = _enableActivity == 0 ? 1 : 0; diff --git a/Wonky.Client/wwwroot/appsettings.json b/Wonky.Client/wwwroot/appsettings.json index 2211fbde..93cec4fc 100644 --- a/Wonky.Client/wwwroot/appsettings.json +++ b/Wonky.Client/wwwroot/appsettings.json @@ -1,7 +1,7 @@ { "appInfo": { "name": "Wonky Client", - "version": "0.36.1", + "version": "0.38.3", "rc": true, "sandBox": false, "image": "grumpy-coder.png" diff --git a/Wonky.Entity/Views/InvoiceCompanyView.cs b/Wonky.Entity/Views/InvoiceCompanyView.cs new file mode 100644 index 00000000..ca76cd3a --- /dev/null +++ b/Wonky.Entity/Views/InvoiceCompanyView.cs @@ -0,0 +1,19 @@ +namespace Wonky.Entity.Views; + +public class InvoiceCompanyView +{ + public string CompanyId { get; set; } = ""; + public string VatNumber { get; set; } = ""; + public string Account { get; set; } = ""; + public string Name { get; set; } = ""; + public string Address1 { get; set; } = ""; + public string Address2 { get; set; } = ""; + public string ZipCode { get; set; } = ""; + public string City { get; set; } = ""; + public string Attention { get; set; } = ""; + public string Email { get; set; } = ""; + public string Mobile { get; set; } = ""; + public string Phone { get; set; } = ""; + public string Blocked { get; set; } = ""; + public string Note { get; set; } = ""; +} \ No newline at end of file diff --git a/Wonky.Entity/Views/InvoiceLineView.cs b/Wonky.Entity/Views/InvoiceLineView.cs new file mode 100644 index 00000000..c295b40a --- /dev/null +++ b/Wonky.Entity/Views/InvoiceLineView.cs @@ -0,0 +1,10 @@ +namespace Wonky.Entity.Views; + +public class InvoiceLineView +{ + public string Sku { get; set; } = ""; + public string Text { get; set; } = ""; + public int Qty { get; set; } + public decimal Price { get; set; } + public decimal Discount { get; set; } +} \ No newline at end of file diff --git a/Wonky.Entity/Views/InvoiceListItemView.cs b/Wonky.Entity/Views/InvoiceListItemView.cs new file mode 100644 index 00000000..c0cc728d --- /dev/null +++ b/Wonky.Entity/Views/InvoiceListItemView.cs @@ -0,0 +1,14 @@ +namespace Wonky.Entity.Views; + +public class InvoiceListItemView +{ + public string ArchiveHeadId { get; set; } = ""; + public string ESalesNumber { get; set; } = ""; + public string DocumentNumber { get; set; } = ""; + public string ReferenceNumber { get; set; } = ""; + public string YourRef { get; set; } = ""; + public string OrderNote { get; set; } = ""; + public string TrackingNumber { get; set; } = ""; + public string DocumentDate { get; set; } = ""; + public decimal InvoiceAmount { get; set; } +} \ No newline at end of file diff --git a/Wonky.Entity/Views/InvoiceListView.cs b/Wonky.Entity/Views/InvoiceListView.cs new file mode 100644 index 00000000..4e7e2a55 --- /dev/null +++ b/Wonky.Entity/Views/InvoiceListView.cs @@ -0,0 +1,7 @@ +namespace Wonky.Entity.Views; + +public class InvoiceListView +{ + public InvoiceCompanyView Company { get; set; } = new(); + public List InvoiceList { get; set; } = new(); +} \ No newline at end of file diff --git a/Wonky.Entity/Views/InvoiceView.cs b/Wonky.Entity/Views/InvoiceView.cs new file mode 100644 index 00000000..4de3cabb --- /dev/null +++ b/Wonky.Entity/Views/InvoiceView.cs @@ -0,0 +1,19 @@ +namespace Wonky.Entity.Views; + +public class InvoiceView +{ + public InvoiceCompanyView Company { get; set; } = new(); + public string Account { get; set; } = ""; + public string ArchiveHeadId { get; set; } = ""; + public string DocumentDate { get; set; } = ""; + public string DocumentNumber { get; set; } = ""; + public string ESalesNumber { get; set; } = ""; + public decimal InvoiceAmount { get; set; } + public string OrderNote { get; set; } = ""; + public string OurRef { get; set; } = ""; + public string ReferenceNumber { get; set; } = ""; + public string YourRef { get; set; } = ""; + public string TrackingNumber { get; set; } = ""; + public string VatNumber { get; set; } = ""; + public List Lines { get; set; } = new(); +} \ No newline at end of file