create invoice component

This commit is contained in:
zzdrojewskipaw
2025-11-27 23:52:32 +01:00
parent 2b7ed3e451
commit 437d6d8f42
14 changed files with 624 additions and 1 deletions

View File

@@ -0,0 +1,118 @@
@using MudBlazor.Internal
<MudText Typo="Typo.h4" Class="mb-4">Lista Faktur</MudText>
<MudExpansionPanels Class="mb-4">
<MudExpansionPanel Icon="@Icons.Material.Filled.FilterList"
Text="Filtry"
Expanded="true">
<MudGrid>
<MudItem xs="12" sm="6" md="4">
<MudTextField @bind-Value="filterRequest.Search"
Label="Szukaj"
Placeholder="Numer dokumentu, klient..."
Immediate="true"
DebounceInterval="500"
OnDebounceIntervalElapsed="SearchInvoices"
Clearable="true"/>
</MudItem>
<MudItem xs="12" sm="6" md="4">
<MudTextField @bind-Value="filterRequest.DocumentNo"
Label="Numer dokumentu"
Immediate="true"
DebounceInterval="500"
OnDebounceIntervalElapsed="SearchInvoices"
Clearable="true"/>
</MudItem>
<MudItem xs="12" sm="6" md="4">
<MudTextField @bind-Value="filterRequest.ClientName"
Label="Nazwa klienta"
Immediate="true"
DebounceInterval="500"
OnDebounceIntervalElapsed="SearchInvoices"
Clearable="true"/>
</MudItem>
<MudItem xs="12" sm="6" md="4">
<MudTextField @bind-Value="filterRequest.Type"
Label="Typ dokumentu"
Immediate="true"
DebounceInterval="500"
OnDebounceIntervalElapsed="SearchInvoices"
Clearable="true"/>
</MudItem>
<MudItem xs="12" sm="6" md="4">
<MudButton Variant="Variant.Outlined"
OnClick="ClearFilters"
StartIcon="Icons.Material.Filled.Clear">
Wyczyść filtry
</MudButton>
</MudItem>
</MudGrid>
</MudExpansionPanel>
</MudExpansionPanels>
<MudDivider Class="my-4"></MudDivider>
<MudTable Items="invoices.Items"
Dense="true"
Hover="true"
Loading="isLoading"
LoadingProgressColor="Color.Info">
<HeaderContent>
<MudTh>Numer dokumentu</MudTh>
<MudTh>Typ</MudTh>
<MudTh>Klient</MudTh>
<MudTh>Data rejestracji</MudTh>
<MudTh>Data sprzedaży</MudTh>
<MudTh>Wartość brutto</MudTh>
<MudTh>Akcje</MudTh>
</HeaderContent>
<RowTemplate>
<MudTd DataLabel="Numer dokumentu">@context.DocumentNo</MudTd>
<MudTd DataLabel="Typ">@context.Type</MudTd>
<MudTd DataLabel="Klient">@context.ClientName</MudTd>
<MudTd DataLabel="Data rejestracji">@context.RegisterDate.ToShortDateString()</MudTd>
<MudTd DataLabel="Data sprzedaży">@context.SellDate.ToShortDateString()</MudTd>
<MudTd DataLabel="Wartość brutto">@context.TotalBrutto.ToString("C2")</MudTd>
<MudTd DataLabel="Akcje">
<MudIconButton Icon="@Icons.Material.Filled.Visibility"
Size="Size.Small"
OnClick="() => ViewInvoice(context.Id)"/>
<MudIconButton Icon="@Icons.Material.Filled.Edit"
Size="Size.Small"
OnClick="() => EditInvoice(context.Id)"/>
<MudIconButton Icon="@Icons.Material.Filled.Delete"
Size="Size.Small"
Color="Color.Error"
OnClick="() => DeleteInvoice(context.Id)"/>
</MudTd>
</RowTemplate>
<NoRecordsContent>
<MudText>Brak faktur do wyświetlenia</MudText>
</NoRecordsContent>
<LoadingContent>
Ładowanie...
</LoadingContent>
</MudTable>
@if (invoices.TotalCount > 0)
{
<MudGrid Class="mt-4" AlignItems="Center.Center">
<MudItem xs="12" sm="6">
<MudText Typo="Typo.body2">
Wyniki @((invoices.Page - 1) * invoices.PageSize + 1) - @Math.Min(invoices.Page * invoices.PageSize, invoices.TotalCount)
z @invoices.TotalCount
</MudText>
</MudItem>
<MudItem xs="12" sm="6" Class="d-flex justify-end">
<MudPagination Count="invoices.TotalPages"
Selected="invoices.Page"
SelectedChanged="OnPageChanged"
ShowFirstButton="true"
ShowLastButton="true"/>
</MudItem>
</MudGrid>
}

View File

@@ -0,0 +1,83 @@
using BimAI.UI.Shared.Services;
using Microsoft.AspNetCore.Components;
using BimAI.Application.DTOModels;
using BimAI.Application.DTOModels.Common;
using MudBlazor;
namespace BimAI.UI.Shared.Components;
public partial class InvoiceListComponent : ComponentBase
{
[Inject] private InvoiceService InvoiceService { get; set; } = default!;
private PagedResult<InvoiceDto> invoices = new();
private InvoiceFilterRequest filterRequest = new();
private bool isLoading = false;
protected override async Task OnInitializedAsync()
{
Console.WriteLine("========== InvoiceListComponent OnInitializedAsync ==========");
await LoadInvoices();
}
private async Task LoadInvoices()
{
isLoading = true;
Console.WriteLine($"========== LoadInvoices - Starting load with Page: {filterRequest.Page}, PageSize: {filterRequest.PageSize} ==========");
try
{
invoices = await InvoiceService.GetInvoiceAsync(filterRequest);
Console.WriteLine($"========== LoadInvoices - Loaded {invoices.Items?.Count ?? 0} invoices, Total: {invoices.TotalCount} ==========");
}
catch (Exception ex)
{
Console.WriteLine($"========== ERROR Loading invoices failed: {ex.Message} ==========");
Console.WriteLine($"========== ERROR Stack trace: {ex.StackTrace} ==========");
if (ex.InnerException != null)
{
Console.WriteLine($"========== ERROR Inner exception: {ex.InnerException.Message} ==========");
}
}
finally
{
isLoading = false;
}
}
private async Task SearchInvoices()
{
filterRequest.Page = 1;
await LoadInvoices();
}
private async Task OnPageChanged(int page)
{
filterRequest.Page = page;
await LoadInvoices();
}
private async Task ClearFilters()
{
filterRequest = new InvoiceFilterRequest();
await LoadInvoices();
}
private async Task ViewInvoice(Guid invoiceId)
{
// TODO
Console.WriteLine($"Zobacz fakturę: {invoiceId}");
}
private async Task EditInvoice(Guid invoiceId)
{
// TODO
Console.WriteLine($"Edytuj fakturę: {invoiceId}");
}
private async Task DeleteInvoice(Guid invoiceId)
{
// TODO
Console.WriteLine($"Usuń fakturę: {invoiceId}");
}
}

View File

@@ -11,6 +11,12 @@ public static class ServiceCollectionExtensions
{
client.BaseAddress = new Uri(apiBaseUrl);
});
services.AddHttpClient<InvoiceService>(client =>
{
client.BaseAddress = new Uri(apiBaseUrl);
});
return services;
}

View File

@@ -28,6 +28,7 @@
<MudNavMenu>
<MudNavLink Href="/dashboard" Icon="@Icons.Material.Filled.Dashboard">Dashboard</MudNavLink>
<MudNavLink Href="/products" Icon="@Icons.Material.Filled.Inventory">Products</MudNavLink>
<MudNavLink Href="/invoices" Icon="@Icons.Material.Filled.FilePresent">Invoices</MudNavLink>
</MudNavMenu>
</MudDrawer>

View File

@@ -0,0 +1,8 @@
@page "/invoices"
@using BimAI.UI.Shared.Components
<PageTitle>Faktury</PageTitle>
<MudContainer MaxWidth="MaxWidth.ExtraExtraLarge">
<InvoiceListComponent />
</MudContainer>

View File

@@ -0,0 +1,65 @@
using System.Text.Json;
using BimAI.Application.DTOModels;
using BimAI.Application.DTOModels.Common;
using Microsoft.AspNetCore.WebUtilities;
namespace BimAI.UI.Shared.Services;
public class InvoiceService(HttpClient httpClient)
{
private readonly HttpClient _httpClient = httpClient;
private readonly JsonSerializerOptions _jsonOptions = new()
{
PropertyNameCaseInsensitive = true
};
public async Task<PagedResult<InvoiceDto>> GetInvoiceAsync(InvoiceFilterRequest request)
{
var queryParams = new Dictionary<string, string?>
{
["page"] = request.Page.ToString(),
["pageSize"] = request.PageSize.ToString(),
};
// if (!string.IsNullOrWhiteSpace(request.Search))
// {
// queryParams["search"] = request.Search;
// }
// if (!string.IsNullOrWhiteSpace(request.Name))
// {
// queryParams["name"] = request.Name;
// }
// if (!string.IsNullOrWhiteSpace(request.Code))
// {
// queryParams["code"] = request.Code;
// }
// if (!string.IsNullOrWhiteSpace(request.Ean))
// {
// queryParams["ean"] = request.Ean;
// }
var uri = QueryHelpers.AddQueryString("api/invoice", queryParams);
Console.WriteLine($"========== InvoiceService - Full URL: {_httpClient.BaseAddress}{uri} ==========");
var response = await _httpClient.GetAsync(uri);
Console.WriteLine($"========== InvoiceService - Response status: {response.StatusCode} ==========");
if (!response.IsSuccessStatusCode)
{
var errorContent = await response.Content.ReadAsStringAsync();
Console.WriteLine($"========== InvoiceService - Error response: {errorContent} ==========");
}
response.EnsureSuccessStatusCode();
var json = await response.Content.ReadAsStringAsync();
Console.WriteLine($"========== InvoiceService - Response JSON length: {json.Length} ==========");
Console.WriteLine($"========== InvoiceService - Response JSON: {json.Substring(0, Math.Min(500, json.Length))} ==========");
var result = JsonSerializer.Deserialize<PagedResult<InvoiceDto>>(json, _jsonOptions);
Console.WriteLine($"========== InvoiceService - Deserialized result - Items count: {result?.Items?.Count ?? 0}, Total: {result?.TotalCount ?? 0} ==========");
return result ?? new PagedResult<InvoiceDto>();
}
}