Init
This commit is contained in:
153
Server/Components/Pages/InvoicePage.razor.cs
Normal file
153
Server/Components/Pages/InvoicePage.razor.cs
Normal file
@@ -0,0 +1,153 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using QuestPDF;
|
||||
using QuestPDF.Fluent;
|
||||
using QuestPDF.Infrastructure;
|
||||
using Server.Data;
|
||||
using Server.Model;
|
||||
|
||||
namespace Server.Components.Pages
|
||||
{
|
||||
public partial class InvoicePage
|
||||
{
|
||||
#region Dependencies
|
||||
|
||||
[Inject]
|
||||
private NavigationManager NavigationManager { get; set; } = null!;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Parameters
|
||||
|
||||
[Parameter]
|
||||
public string? InvoiceId { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Properties
|
||||
|
||||
private InvoiceModel Invoice { get; set; } = new();
|
||||
|
||||
private string? AlertMessage { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Override SetParametersAsync
|
||||
|
||||
//// <inheritdoc />
|
||||
public override async Task SetParametersAsync(ParameterView parameters)
|
||||
{
|
||||
parameters.SetParameterProperties(this);
|
||||
|
||||
// No invoice id
|
||||
if (string.IsNullOrWhiteSpace(InvoiceId))
|
||||
{
|
||||
NavigationManager.NavigateTo("/");
|
||||
return;
|
||||
}
|
||||
|
||||
// Existing
|
||||
var invoice = await InvoiceData.LoadAsync(InvoiceId);
|
||||
if (invoice == null)
|
||||
{
|
||||
NavigationManager.NavigateTo("/");
|
||||
return;
|
||||
}
|
||||
|
||||
// Found
|
||||
Invoice = invoice;
|
||||
|
||||
Settings.License = LicenseType.Community;
|
||||
|
||||
await CustomerData.LoadAsync();
|
||||
|
||||
await base.SetParametersAsync(ParameterView.Empty);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method CreateItemAsync
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously creates a new item and adds it to the current invoice.
|
||||
/// </summary>
|
||||
/// <returns>A Task representing the asynchronous operation.</returns>
|
||||
private Task CreateItemAsync()
|
||||
{
|
||||
Invoice.Items.Add(new());
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method Generate
|
||||
|
||||
private async Task Generate()
|
||||
{
|
||||
var doc = new InvoiceDocument(new()
|
||||
{
|
||||
InvoiceId = "3129",
|
||||
Seller = SettingsData.Instance.SellerAddress,
|
||||
PaymentData = SettingsData.Instance.PaymentData,
|
||||
Comment = SettingsData.Instance.Comment,
|
||||
Customer = new()
|
||||
{
|
||||
Name = "DRK-Ortsverein Dreis-Tiefenbach e.V.",
|
||||
Name2 = "Jutta Weber",
|
||||
Street = "Feldwasserstraße 9",
|
||||
Zip = "57250",
|
||||
City = "Netphen"
|
||||
},
|
||||
Items =
|
||||
[
|
||||
new OrderItem
|
||||
{
|
||||
Name = "Schulung DRK-Cloud in Std.",
|
||||
Description = "09.12.2022 - Schulungsgruppe 1",
|
||||
Quantity = 5,
|
||||
TaxType = TaxType.Tax19,
|
||||
PriceNetto = 29
|
||||
},
|
||||
new OrderItem
|
||||
{
|
||||
Name = "Schulung DRK-Cloud in Std.",
|
||||
Description = "10.12.2022 - Schulungsgruppe 2",
|
||||
Quantity = 5,
|
||||
TaxType = TaxType.Tax19,
|
||||
PriceNetto = 29
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
doc.GeneratePdfAndShow();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method GenerateInvoiceAsync
|
||||
|
||||
private Task GenerateInvoiceAsync()
|
||||
{
|
||||
var doc = new InvoiceDocument(Invoice);
|
||||
doc.GeneratePdfAndShow();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Private Method SaveInvoiceAsync
|
||||
|
||||
/// <summary>
|
||||
/// Asynchronously saves the current invoice.
|
||||
/// </summary>
|
||||
/// <returns>A Task representing the asynchronous save operation.</returns>
|
||||
private async Task SaveInvoiceAsync()
|
||||
{
|
||||
AlertMessage = null;
|
||||
|
||||
await InvoiceData.SaveAsync(Invoice);
|
||||
NavigationManager.NavigateTo("/invoices");
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user