This commit is contained in:
Andre Beging
2024-11-06 16:00:26 +01:00
commit de76b1d432
42 changed files with 1922 additions and 0 deletions

38
.gitignore vendored Normal file
View File

@@ -0,0 +1,38 @@
# Common IntelliJ Platform excludes
# User specific
**/.idea/**/workspace.xml
**/.idea/**/tasks.xml
**/.idea/shelf/*
**/.idea/dictionaries
**/.idea/httpRequests/
# Sensitive or high-churn files
**/.idea/**/dataSources/
**/.idea/**/dataSources.ids
**/.idea/**/dataSources.xml
**/.idea/**/dataSources.local.xml
**/.idea/**/sqlDataSources.xml
**/.idea/**/dynamic.xml
# Rider
# Rider auto-generates .iml files, and contentModel.xml
**/.idea/**/*.iml
**/.idea/**/contentModel.xml
**/.idea/**/modules.xml
*.suo
*.user
.vs/
[Bb]in/
[Oo]bj/
_UpgradeReport_Files/
[Pp]ackages/
Thumbs.db
Desktop.ini
.DS_Store
Publish/
app.db*
_app.db*

13
.idea/.idea.TinyInvoice/.idea/.gitignore generated vendored Normal file
View File

@@ -0,0 +1,13 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/projectSettingsUpdater.xml
/contentModel.xml
/modules.xml
/.idea.TinyInvoice.iml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GitToolBoxBlameSettings">
<option name="version" value="2" />
</component>
</project>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<base href="/"/>
<link rel="stylesheet" href="bootstrap/bootstrap.min.css"/>
<link rel="stylesheet" href="app.css"/>
<link rel="stylesheet" href="Server.styles.css"/>
<link rel="icon" type="image/png" href="favicon.png"/>
<HeadOutlet/>
</head>
<body>
<Routes />
<script src="_framework/blazor.web.js"></script>
</body>
</html>

View File

@@ -0,0 +1,23 @@
@inherits LayoutComponentBase
<div class="page">
<div class="sidebar">
<NavMenu/>
</div>
<main>
<div class="top-row px-4">
<a href="https://learn.microsoft.com/aspnet/core/" target="_blank">About</a>
</div>
<article class="content px-4">
@Body
</article>
</main>
</div>
<div id="blazor-error-ui">
An unhandled error has occurred.
<a href="" class="reload">Reload</a>
<a class="dismiss">🗙</a>
</div>

View File

@@ -0,0 +1,96 @@
.page {
position: relative;
display: flex;
flex-direction: column;
}
main {
flex: 1;
}
.sidebar {
background-image: linear-gradient(180deg, rgb(5, 39, 103) 0%, #3a0647 70%);
}
.top-row {
background-color: #f7f7f7;
border-bottom: 1px solid #d6d5d5;
justify-content: flex-end;
height: 3.5rem;
display: flex;
align-items: center;
}
.top-row ::deep a, .top-row ::deep .btn-link {
white-space: nowrap;
margin-left: 1.5rem;
text-decoration: none;
}
.top-row ::deep a:hover, .top-row ::deep .btn-link:hover {
text-decoration: underline;
}
.top-row ::deep a:first-child {
overflow: hidden;
text-overflow: ellipsis;
}
@media (max-width: 640.98px) {
.top-row {
justify-content: space-between;
}
.top-row ::deep a, .top-row ::deep .btn-link {
margin-left: 0;
}
}
@media (min-width: 641px) {
.page {
flex-direction: row;
}
.sidebar {
width: 250px;
height: 100vh;
position: sticky;
top: 0;
}
.top-row {
position: sticky;
top: 0;
z-index: 1;
}
.top-row.auth ::deep a:first-child {
flex: 1;
text-align: right;
width: 0;
}
.top-row, article {
padding-left: 2rem !important;
padding-right: 1.5rem !important;
}
}
#blazor-error-ui {
background: lightyellow;
bottom: 0;
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
display: none;
left: 0;
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
position: fixed;
width: 100%;
z-index: 1000;
}
#blazor-error-ui .dismiss {
cursor: pointer;
position: absolute;
right: 0.75rem;
top: 0.5rem;
}

View File

@@ -0,0 +1,44 @@
<div class="top-row ps-3 navbar navbar-dark">
<div class="container-fluid">
<a class="navbar-brand" href="">Server</a>
</div>
</div>
<input type="checkbox" title="Navigation menu" class="navbar-toggler"/>
<div class="nav-scrollable" onclick="document.querySelector('.navbar-toggler').click()">
<nav class="flex-column">
<div class="nav-item px-3">
<NavLink class="nav-link" href="/create" Match="NavLinkMatch.All">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-square-fill" viewBox="0 0 16 16">
<path d="M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0"/>
</svg> Neue Rechnung
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="/" Match="NavLinkMatch.All">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-receipt" viewBox="0 0 16 16">
<path d="M1.92.506a.5.5 0 0 1 .434.14L3 1.293l.646-.647a.5.5 0 0 1 .708 0L5 1.293l.646-.647a.5.5 0 0 1 .708 0L7 1.293l.646-.647a.5.5 0 0 1 .708 0L9 1.293l.646-.647a.5.5 0 0 1 .708 0l.646.647.646-.647a.5.5 0 0 1 .708 0l.646.647.646-.647a.5.5 0 0 1 .801.13l.5 1A.5.5 0 0 1 15 2v12a.5.5 0 0 1-.053.224l-.5 1a.5.5 0 0 1-.8.13L13 14.707l-.646.647a.5.5 0 0 1-.708 0L11 14.707l-.646.647a.5.5 0 0 1-.708 0L9 14.707l-.646.647a.5.5 0 0 1-.708 0L7 14.707l-.646.647a.5.5 0 0 1-.708 0L5 14.707l-.646.647a.5.5 0 0 1-.708 0L3 14.707l-.646.647a.5.5 0 0 1-.801-.13l-.5-1A.5.5 0 0 1 1 14V2a.5.5 0 0 1 .053-.224l.5-1a.5.5 0 0 1 .367-.27m.217 1.338L2 2.118v11.764l.137.274.51-.51a.5.5 0 0 1 .707 0l.646.647.646-.646a.5.5 0 0 1 .708 0l.646.646.646-.646a.5.5 0 0 1 .708 0l.646.646.646-.646a.5.5 0 0 1 .708 0l.646.646.646-.646a.5.5 0 0 1 .708 0l.646.646.646-.646a.5.5 0 0 1 .708 0l.509.509.137-.274V2.118l-.137-.274-.51.51a.5.5 0 0 1-.707 0L12 1.707l-.646.647a.5.5 0 0 1-.708 0L10 1.707l-.646.647a.5.5 0 0 1-.708 0L8 1.707l-.646.647a.5.5 0 0 1-.708 0L6 1.707l-.646.647a.5.5 0 0 1-.708 0L4 1.707l-.646.647a.5.5 0 0 1-.708 0z"/>
<path d="M3 4.5a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 1 1 0 1h-6a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h6a.5.5 0 0 1 0 1h-6a.5.5 0 0 1-.5-.5m8-6a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 0 1h-1a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 0 1h-1a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 0 1h-1a.5.5 0 0 1-.5-.5m0 2a.5.5 0 0 1 .5-.5h1a.5.5 0 0 1 0 1h-1a.5.5 0 0 1-.5-.5"/>
</svg> Rechnungen
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="customers">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-person-vcard-fill" viewBox="0 0 16 16">
<path d="M0 4a2 2 0 0 1 2-2h12a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H2a2 2 0 0 1-2-2zm9 1.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 0-1h-4a.5.5 0 0 0-.5.5M9 8a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 0-1h-4A.5.5 0 0 0 9 8m1 2.5a.5.5 0 0 0 .5.5h3a.5.5 0 0 0 0-1h-3a.5.5 0 0 0-.5.5m-1 2C9 10.567 7.21 9 5 9c-2.086 0-3.8 1.398-3.984 3.181A1 1 0 0 0 2 13h6.96q.04-.245.04-.5M7 6a2 2 0 1 0-4 0 2 2 0 0 0 4 0"/>
</svg> Kunden
</NavLink>
</div>
<div class="nav-item px-3">
<NavLink class="nav-link" href="settings">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-gear-fill" viewBox="0 0 16 16">
<path d="M9.405 1.05c-.413-1.4-2.397-1.4-2.81 0l-.1.34a1.464 1.464 0 0 1-2.105.872l-.31-.17c-1.283-.698-2.686.705-1.987 1.987l.169.311c.446.82.023 1.841-.872 2.105l-.34.1c-1.4.413-1.4 2.397 0 2.81l.34.1a1.464 1.464 0 0 1 .872 2.105l-.17.31c-.698 1.283.705 2.686 1.987 1.987l.311-.169a1.464 1.464 0 0 1 2.105.872l.1.34c.413 1.4 2.397 1.4 2.81 0l.1-.34a1.464 1.464 0 0 1 2.105-.872l.31.17c1.283.698 2.686-.705 1.987-1.987l-.169-.311a1.464 1.464 0 0 1 .872-2.105l.34-.1c1.4-.413 1.4-2.397 0-2.81l-.34-.1a1.464 1.464 0 0 1-.872-2.105l.17-.31c.698-1.283-.705-2.686-1.987-1.987l-.311.169a1.464 1.464 0 0 1-2.105-.872zM8 10.93a2.929 2.929 0 1 1 0-5.86 2.929 2.929 0 0 1 0 5.858z"/>
</svg> Einstellungen
</NavLink>
</div>
</nav>
</div>

View File

@@ -0,0 +1,105 @@
.navbar-toggler {
appearance: none;
cursor: pointer;
width: 3.5rem;
height: 2.5rem;
color: white;
position: absolute;
top: 0.5rem;
right: 1rem;
border: 1px solid rgba(255, 255, 255, 0.1);
background: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3e%3cpath stroke='rgba%28255, 255, 255, 0.55%29' stroke-linecap='round' stroke-miterlimit='10' stroke-width='2' d='M4 7h22M4 15h22M4 23h22'/%3e%3c/svg%3e") no-repeat center/1.75rem rgba(255, 255, 255, 0.1);
}
.navbar-toggler:checked {
background-color: rgba(255, 255, 255, 0.5);
}
.top-row {
height: 3.5rem;
background-color: rgba(0,0,0,0.4);
}
.navbar-brand {
font-size: 1.1rem;
}
.bi {
display: inline-block;
position: relative;
width: 1.25rem;
height: 1.25rem;
margin-right: 0.75rem;
top: -1px;
background-size: cover;
}
.bi-house-door-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-house-door-fill' viewBox='0 0 16 16'%3E%3Cpath d='M6.5 14.5v-3.505c0-.245.25-.495.5-.495h2c.25 0 .5.25.5.5v3.5a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5v-7a.5.5 0 0 0-.146-.354L13 5.793V2.5a.5.5 0 0 0-.5-.5h-1a.5.5 0 0 0-.5.5v1.293L8.354 1.146a.5.5 0 0 0-.708 0l-6 6A.5.5 0 0 0 1.5 7.5v7a.5.5 0 0 0 .5.5h4a.5.5 0 0 0 .5-.5Z'/%3E%3C/svg%3E");
}
.bi-plus-square-fill-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-plus-square-fill' viewBox='0 0 16 16'%3E%3Cpath d='M2 0a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V2a2 2 0 0 0-2-2H2zm6.5 4.5v3h3a.5.5 0 0 1 0 1h-3v3a.5.5 0 0 1-1 0v-3h-3a.5.5 0 0 1 0-1h3v-3a.5.5 0 0 1 1 0z'/%3E%3C/svg%3E");
}
.bi-list-nested-nav-menu {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' class='bi bi-list-nested' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M4.5 11.5A.5.5 0 0 1 5 11h10a.5.5 0 0 1 0 1H5a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 3 7h10a.5.5 0 0 1 0 1H3a.5.5 0 0 1-.5-.5zm-2-4A.5.5 0 0 1 1 3h10a.5.5 0 0 1 0 1H1a.5.5 0 0 1-.5-.5z'/%3E%3C/svg%3E");
}
.nav-item {
font-size: 0.9rem;
padding-bottom: 0.5rem;
}
.nav-item:first-of-type {
padding-top: 1rem;
}
.nav-item:last-of-type {
padding-bottom: 1rem;
}
.nav-item ::deep .nav-link {
color: #d7d7d7;
background: none;
border: none;
border-radius: 4px;
height: 3rem;
display: flex;
align-items: center;
line-height: 3rem;
width: 100%;
}
.nav-item ::deep a.active {
background-color: rgba(255,255,255,0.37);
color: white;
}
.nav-item ::deep .nav-link:hover {
background-color: rgba(255,255,255,0.1);
color: white;
}
.nav-scrollable {
display: none;
}
.navbar-toggler:checked ~ .nav-scrollable {
display: block;
}
@media (min-width: 641px) {
.navbar-toggler {
display: none;
}
.nav-scrollable {
/* Never collapse the sidebar for wide screens */
display: block;
/* Allow sidebar to scroll for tall menus */
height: calc(100vh - 3.5rem);
overflow-y: auto;
}
}

View File

@@ -0,0 +1,20 @@
@page "/counter"
@rendermode InteractiveServer
<PageTitle>Counter</PageTitle>
<h1>Counter</h1>
<p role="status">Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
@code {
private int currentCount = 0;
private void IncrementCount()
{
currentCount++;
}
}

View File

@@ -0,0 +1,19 @@
@page "/create"
@rendermode InteractiveServer
<h3>Neue Rechnung</h3>
<hr />
<div class="mb-3">
<label class="form-label">Rechnungsnummer</label>
<InputText class="form-control" @bind-Value="@InvoiceId" style="width: 100%; max-width: 400px;"></InputText>
</div>
@if (!string.IsNullOrWhiteSpace(AlertMessage))
{
<div class="alert alert-danger mt-3">
@AlertMessage
</div>
}
<button type="button" class="btn btn-primary" @onclick="CreateInvoiceAsync">Anlegen</button>

View File

@@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Components;
using Server.Data;
using Server.Model;
namespace Server.Components.Pages
{
public partial class CreatePage
{
#region Dependencies
[Inject]
private NavigationManager NavigationManager { get; set; } = null!;
#endregion
#region Private Properties
private string? AlertMessage { get; set; }
private string? InvoiceId { get; set; }
#endregion
#region Override SetParametersAsync
/// <inheritdoc />
public override async Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
await SettingsData.LoadAsync();
await base.SetParametersAsync(ParameterView.Empty);
}
#endregion
#region Private Method CreateInvoiceAsync
/// <summary>
/// Asynchronously creates a new invoice if the provided InvoiceId is not null, empty,
/// or whitespace, and does not already exist in the system. If the invoice is created
/// successfully, navigates to the newly created invoice page.
/// </summary>
/// <returns>
/// A Task representing the asynchronous operation.
/// </returns>
private async Task CreateInvoiceAsync()
{
if (string.IsNullOrWhiteSpace(InvoiceId)) return;
if (await InvoiceData.ExistsAsync(InvoiceId))
{
AlertMessage = "Eine Rechnung mit der Rechnungsnummer existiert bereits";
return;
}
var invoice = new InvoiceModel
{
InvoiceId = InvoiceId,
Comment = SettingsData.Instance.Comment,
PaymentData = SettingsData.Instance.PaymentData,
Seller = SettingsData.Instance.SellerAddress
};
await InvoiceData.SaveAsync(invoice);
NavigationManager.NavigateTo($"/edit/{InvoiceId}");
}
#endregion
}
}

View File

@@ -0,0 +1,68 @@
@page "/customers"
@using Server.Data
@using Server.Model
@rendermode InteractiveServer
<h3>Kunden</h3>
@if (EditFormShow && EditFormObject != null)
{
<div class="mb-3">
<label class="form-label">Name</label>
<InputText DisplayName="Name" class="form-control" @bind-Value="@EditFormObject.Name"></InputText>
</div>
<div class="mb-3">
<label class="form-label">Name2</label>
<InputText DisplayName="Name2" class="form-control" @bind-Value="@EditFormObject.Name2"></InputText>
</div>
<div class="mb-3">
<label class="form-label">Street</label>
<InputText DisplayName="Street" class="form-control" @bind-Value="@EditFormObject.Street"></InputText>
</div>
<div class="mb-3">
<label class="form-label">Zip</label>
<InputText DisplayName="Zip" class="form-control" @bind-Value="@EditFormObject.Zip"></InputText>
</div>
<div class="mb-3">
<label class="form-label">City</label>
<InputText DisplayName="City" class="form-control" @bind-Value="@EditFormObject.City"></InputText>
</div>
<div class="mb-3">
<label class="form-label">Phone</label>
<InputText DisplayName="Phone" class="form-control" @bind-Value="@EditFormObject.Phone"></InputText>
</div>
<button type="button" class="btn btn-sm btn-primary" @onclick="SaveCustomerAsync">Speichern</button>
<button type="button" class="btn btn-sm btn-secondary" @onclick="HideEditFormAsync">Abbrechen</button>
}
else
{
<button type="button" class="btn btn-primary" @onclick="ShowCreateAsync">Neuer Kunde</button>
}
<hr />
<div class="row">
@foreach (var customer in CustomerData.Instance.Customers.Where(x => x.State != RecordState.Deleted))
{
<div class="col-md-auto pt-3">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">@customer.Name</h5>
<p class="card-text">
@customer.Name2<br>
@customer.Street<br>
@customer.Zip - @customer.City<br>
@customer.Phone<br>
</p>
<button type="button" class="btn btn-sm btn-primary" @onclick="() => EditCustomerAsync(customer)">Bearbeiten</button>
<button type="button" class="btn btn-sm btn-danger" @onclick="() => DeleteCustomerAsync(customer)">Löschen</button>
</div>
</div>
</div>
}
</div>

View File

@@ -0,0 +1,116 @@
using Microsoft.AspNetCore.Components;
using Server.Data;
using Server.Model;
namespace Server.Components.Pages
{
public partial class CustomerPage : ComponentBase
{
#region Private Properties
private bool EditFormIsNew { get; set; }
private Address? EditFormObject { get; set; }
private bool EditFormShow { get; set; }
#endregion
#region Override SetParametersAsync
//// <inheritdoc />
public override async Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
await CustomerData.LoadAsync();
await base.SetParametersAsync(ParameterView.Empty);
}
#endregion
#region Private Method DeleteCustomerAsync
/// <summary>
/// Deletes the specified customer asynchronously.
/// </summary>
/// <param name="customer">The customer to be deleted.</param>
/// <return>A Task representing the asynchronous operation.</return>
private async Task DeleteCustomerAsync(Address customer)
{
customer.State = RecordState.Deleted;
await CustomerData.SaveAsync();
}
#endregion
#region Private Method EditCustomerAsync
/// <summary>
/// Initiates the edit process for a given customer asynchronously.
/// </summary>
/// <param name="customer">The customer to be edited.</param>
/// <returns>A Task representing the asynchronous operation.</returns>
private Task EditCustomerAsync(Address customer)
{
EditFormIsNew = false;
EditFormObject = customer;
EditFormShow = true;
return Task.CompletedTask;
}
#endregion
#region Private Method HideEditFormAsync
/// <summary>
/// Hides the edit form asynchronously.
/// </summary>
/// <return>A Task representing the asynchronous operation.</return>
private Task HideEditFormAsync()
{
EditFormObject = new();
EditFormShow = false;
return Task.CompletedTask;
}
#endregion
#region Private Method SaveCustomerAsync
/// <summary>
/// Saves the current customer data asynchronously.
/// </summary>
/// <returns>A Task representing the asynchronous operation.</returns>
private async Task SaveCustomerAsync()
{
if (EditFormObject == null) return;
EditFormShow = false;
if (EditFormIsNew) CustomerData.Instance.Customers.Add(EditFormObject);
await CustomerData.SaveAsync();
EditFormObject = new();
}
#endregion
#region Private Method ShowCreateAsync
/// <summary>
/// Displays the form for creating a new customer.
/// </summary>
/// <returns>A Task representing the asynchronous operation.</returns>
private Task ShowCreateAsync()
{
EditFormIsNew = true;
EditFormObject = new();
EditFormShow = true;
return Task.CompletedTask;
}
#endregion
}
}

View File

@@ -0,0 +1,38 @@
@page "/Error"
@using System.Diagnostics
<PageTitle>Error</PageTitle>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request.</h2>
@if (ShowRequestId)
{
<p>
<strong>Request ID:</strong> <code>@RequestId</code>
</p>
}
<h3>Development Mode</h3>
<p>
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred.
</p>
<p>
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
It can result in displaying sensitive information from exceptions to end users.
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
and restarting the app.
</p>
@code{
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private string? RequestId { get; set; }
private bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
protected override void OnInitialized() =>
RequestId = Activity.Current?.Id ?? HttpContext?.TraceIdentifier;
}

View File

@@ -0,0 +1,30 @@
@page "/"
@page "/invoices"
@using Server.Model
@rendermode InteractiveServer
<h3>Rechnungen (@((Invoices ?? []).Count))</h3>
@foreach (var invoice in Invoices ?? [])
{
<div class="row">
<div class="col-md-auto pt-3">
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">#@invoice.InvoiceId</h5>
<h6 class="card-subtitle mb-2 text-muted">@invoice.IssueDate.ToShortDateString()</h6>
<p class="card-text">
@invoice.Customer?.Name<br />
@invoice.Items.Count Artikel<br />
@($"{invoice.TotalNetto:N2} €") Netto<br />
</p>
<a href="@($"edit/{invoice.InvoiceId}")" class="btn btn-sm btn-primary">Bearbeiten</a>
@if (invoice.DeletionAllowed)
{
<button class="btn btn-sm btn-danger" style="margin-left: .5rem;" @onclick="() => DeleteInvoiceAsync(invoice.InvoiceId)">Löschen</button>
}
</div>
</div>
</div>
</div>
}

View File

@@ -0,0 +1,45 @@
using Microsoft.AspNetCore.Components;
using Server.Data;
using Server.Model;
namespace Server.Components.Pages
{
public partial class InvoiceListPage : ComponentBase
{
#region Private Properties
private List<InvoiceModel>? Invoices { get; set; }
#endregion
#region Override SetParametersAsync
//// <inheritdoc />
public override async Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
Invoices = await InvoiceData.LoadAllAsync();
await base.SetParametersAsync(ParameterView.Empty);
}
#endregion
#region Private Method DeleteInvoiceAsync
/// <summary>
/// Deletes an invoice asynchronously by its ID.
/// </summary>
/// <param name="invoiceInvoiceId">The ID of the invoice to be deleted.</param>
/// <returns>A task representing the asynchronous delete operation.</returns>
private async Task DeleteInvoiceAsync(string? invoiceInvoiceId)
{
if (string.IsNullOrWhiteSpace(invoiceInvoiceId)) return;
await InvoiceData.DeleteAsync(invoiceInvoiceId);
Invoices = await InvoiceData.LoadAllAsync();
}
#endregion
}
}

View File

@@ -0,0 +1,86 @@
@page "/edit/{InvoiceId}"
@using Server.Model
@rendermode InteractiveServer
<PageTitle>Home</PageTitle>
<h1>@Invoice.InvoiceId</h1>
<button type="button" class="btn btn-primary" @onclick="SaveInvoiceAsync">Speichern</button>
<button type="button" class="btn btn-info" @onclick="GenerateInvoiceAsync">Generieren</button>
@if (!string.IsNullOrWhiteSpace(AlertMessage))
{
<div class="alert alert-danger mt-3">
@AlertMessage
</div>
}
<hr />
<div class="mb-3">
<div class="form-check form-switch">
<InputCheckbox @bind-Value="@Invoice.DeletionAllowed" class="form-check-input" id="deletionallowedcheck"></InputCheckbox>
<label class="form-check-label" for="deletionallowedcheck">Löschen erlaubt</label>
</div>
</div>
<div class="mb-3">
<label class="form-label">Datum</label>
<InputDate class="form-control" @bind-Value="@Invoice.IssueDate"></InputDate>
</div>
<div class="mb-3">
<label class="form-label" >Rechnungsnummer</label>
<InputText class="form-control" @bind-Value="@Invoice.InvoiceId" disabled></InputText>
</div>
<div class="mb-3">
<label class="form-label">Kommentar</label>
<InputTextArea class="form-control" @bind-Value="@Invoice.Comment"></InputTextArea>
</div>
<hr />
<button type="button" class="btn btn-sm btn-primary" @onclick="CreateItemAsync">Neuer Artikel</button>
@foreach (var item in Invoice.Items)
{
<hr />
<div class="card" style="width: 100%; max-width: 1000px;">
<div class="card-body">
<div class="row pt-1">
<div class="col-xl">
<label class="form-label mb-0">Name</label>
<InputText class="form-control" @bind-Value="@item.Name"></InputText>
</div>
<div class="col-sm">
<label class="form-label mb-0">Menge</label>
<InputNumber TValue="double" class="form-control" @bind-Value="@item.Quantity"></InputNumber>
</div>
<div class="col-sm">
<label class="form-label mb-0">Price (Netto)</label>
<InputNumber TValue="double" class="form-control" @bind-Value="@item.PriceNetto"></InputNumber>
</div>
<div class="col-sm">
<label class="form-label mb-0">Tax Type</label>
<InputSelect @bind-Value="@item.TaxType" class="form-select">
@foreach (var taxType in Enum.GetValues(typeof(TaxType)))
{
<option value="@taxType">@taxType</option>
}
</InputSelect>
</div>
</div>
<div class="mb-1 mt-2">
<label class="form-label mb-0">Description</label>
<InputText class="form-control" @bind-Value="@item.Description"></InputText>
</div>
</div>
</div>
}

View 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
}
}

View File

@@ -0,0 +1,74 @@
@page "/settings"
@using Server.Data
@using Server.Model
@rendermode InteractiveServer
<h3>Einstellungen</h3>
<button type="button" class="btn btn-primary" @onclick="Save">Save</button>
<hr />
<div class="mb-3">
<label class="form-label" >Name</label>
<InputText DisplayName="Name" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.Name"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >Name 2</label>
<InputText DisplayName="Name 2" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.Name2"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >Street</label>
<InputText DisplayName="Street" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.Street"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >Zip</label>
<InputText DisplayName="Zip" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.Zip"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >City</label>
<InputText DisplayName="City" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.City"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >Phone</label>
<InputText DisplayName="Phone" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.Phone"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >Web</label>
<InputText DisplayName="Web" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.Web"></InputText>
</div>
<hr />
<div class="mb-3">
<label class="form-label" >Comment</label>
<InputTextArea DisplayName="Comment" class="form-control" @bind-Value="@SettingsData.Instance.Comment"></InputTextArea>
</div>
<hr />
<div class="mb-3">
<label class="form-label" >TaxId</label>
<InputText DisplayName="TaxId" class="form-control" @bind-Value="@SettingsData.Instance.SellerAddress.TaxId"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >Bank</label>
<InputText DisplayName="Bank" class="form-control" @bind-Value="@SettingsData.Instance.PaymentData.BankName"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >IBAN</label>
<InputText DisplayName="IBAN" class="form-control" @bind-Value="@SettingsData.Instance.PaymentData.Iban"></InputText>
</div>
<div class="mb-3">
<label class="form-label" >BIC</label>
<InputText DisplayName="BIC" class="form-control" @bind-Value="@SettingsData.Instance.PaymentData.Bic"></InputText>
</div>

View File

@@ -0,0 +1,33 @@
using Microsoft.AspNetCore.Components;
using Server.Data;
using Server.Model;
namespace Server.Components.Pages
{
public partial class SettingsPage : ComponentBase
{
#region Override SetParametersAsync
//// <inheritdoc />
public override async Task SetParametersAsync(ParameterView parameters)
{
parameters.SetParameterProperties(this);
await SettingsData.LoadAsync();
await base.SetParametersAsync(ParameterView.Empty);
}
#endregion
#region Private Method Save
/// <summary>
/// Asynchronously saves the current settings to a JSON file.
/// </summary>
/// <returns>A task that represents the asynchronous save operation.</returns>
private async Task Save() => await SettingsData.SaveAsync();
#endregion
}
}

View File

@@ -0,0 +1,65 @@
@page "/weather"
@attribute [StreamRendering]
<PageTitle>Weather</PageTitle>
<h1>Weather</h1>
<p>This component demonstrates showing data.</p>
@if (forecasts == null)
{
<p><em>Loading...</em></p>
}
else
{
<table class="table">
<thead>
<tr>
<th>Date</th>
<th>Temp. (C)</th>
<th>Temp. (F)</th>
<th>Summary</th>
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
</tbody>
</table>
}
@code {
private WeatherForecast[]? forecasts;
protected override async Task OnInitializedAsync()
{
// Simulate asynchronous loading to demonstrate streaming rendering
await Task.Delay(500);
var startDate = DateOnly.FromDateTime(DateTime.Now);
var summaries = new[] { "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" };
forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = startDate.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = summaries[Random.Shared.Next(summaries.Length)]
}).ToArray();
}
private class WeatherForecast
{
public DateOnly Date { get; set; }
public int TemperatureC { get; set; }
public string? Summary { get; set; }
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}

View File

@@ -0,0 +1,6 @@
<Router AppAssembly="typeof(Program).Assembly">
<Found Context="routeData">
<RouteView RouteData="routeData" DefaultLayout="typeof(Layout.MainLayout)"/>
<FocusOnNavigate RouteData="routeData" Selector="h1"/>
</Found>
</Router>

View File

@@ -0,0 +1,10 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using static Microsoft.AspNetCore.Components.Web.RenderMode
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.JSInterop
@using Server
@using Server.Components

View File

@@ -0,0 +1,58 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Server.Model;
namespace Server.Data
{
public class CustomerData
{
#region Public Properties
public List<Address> Customers { get; set; } = [];
public static CustomerData Instance { get; set; } = new();
#endregion
#region Private Properties
private static string FileName => "Customers.json";
#endregion
#region Public Method LoadAsync
/// <summary>
/// Loads customer data asynchronously from a JSON file if it exists.
/// </summary>
/// <return>
/// A Task representing the asynchronous operation.
/// </return>
public static async Task LoadAsync()
{
if (!File.Exists(FileName)) return;
var jsonString = await File.ReadAllTextAsync(FileName);
var deserialized = JsonSerializer.Deserialize<CustomerData>(jsonString)!;
Instance = deserialized;
}
#endregion
#region Public Method SaveAsync
/// <summary>
/// Saves the current customer data asynchronously to a JSON file.
/// </summary>
/// <return>
/// A Task representing the asynchronous operation.
/// </return>
public static async Task SaveAsync()
{
var jsonString = JsonSerializer.Serialize(Instance, new JsonSerializerOptions { WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
await File.WriteAllTextAsync(FileName, jsonString);
}
#endregion
}
}

118
Server/Data/InvoiceData.cs Normal file
View File

@@ -0,0 +1,118 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Server.Model;
namespace Server.Data
{
public static class InvoiceData
{
#region Private Properties
private static string DirectoryName => "invoices";
#endregion
#region Public Method DeleteAsync
/// <summary>
/// Deletes an invoice file asynchronously by its ID.
/// </summary>
/// <param name="invoiceId">The ID of the invoice to be deleted.</param>
/// <return>A task representing the asynchronous delete operation.</return>
public static Task DeleteAsync(string invoiceId)
{
var fileName = BuildFileName(invoiceId);
if (File.Exists(fileName)) File.Delete(fileName);
return Task.CompletedTask;
}
#endregion
#region Public Method ExistsAsync
/// <summary>
/// Checks if an invoice file exists asynchronously by its ID.
/// </summary>
/// <param name="invoiceId">The ID of the invoice to check for existence.</param>
/// <returns>A task representing the asynchronous check operation, with a boolean result indicating whether the file exists.</returns>
public static Task<bool> ExistsAsync(string invoiceId) => Task.FromResult(File.Exists(BuildFileName(invoiceId)));
#endregion
#region Public Method LoadAllAsync
/// <summary>
/// Loads all invoices asynchronously.
/// </summary>
/// <return>A task representing the asynchronous operation, with a list of <see cref="InvoiceModel" /> as the result.</return>
public static async Task<List<InvoiceModel>> LoadAllAsync()
{
var invoices = new List<InvoiceModel>();
var invoiceFiles = Directory.GetFiles(DirectoryName, "Invoice_*.json");
foreach (var file in invoiceFiles)
{
var invoice = await LoadFileAsync(file);
if (invoice != null) invoices.Add(invoice);
}
return invoices;
}
#endregion
#region Public Method LoadAsync
/// <summary>
/// Loads an invoice asynchronously by its ID.
/// </summary>
/// <param name="invoiceId">The ID of the invoice to be loaded.</param>
/// <return>The deserialized <see cref="InvoiceModel" /> instance if the file exists; otherwise, null.</return>
public static async Task<InvoiceModel?> LoadAsync(string invoiceId)
{
var fileName = BuildFileName(invoiceId);
return await LoadFileAsync(fileName);
}
#endregion
#region Public Method SaveAsync
/// <summary>
/// Saves an invoice asynchronously.
/// </summary>
/// <param name="invoice">The invoice model to be saved.</param>
/// <return>A task representing the asynchronous save operation.</return>
public static async Task SaveAsync(InvoiceModel invoice)
{
// Ensure id is set
if (string.IsNullOrWhiteSpace(invoice.InvoiceId))
invoice.InvoiceId = Guid.NewGuid().ToString();
// Ensure directory exists
if (!Directory.Exists(DirectoryName)) Directory.CreateDirectory(DirectoryName);
var jsonString = JsonSerializer.Serialize(invoice, new JsonSerializerOptions { WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
await File.WriteAllTextAsync(BuildFileName(invoice.InvoiceId), jsonString);
}
#endregion
#region Private Method BuildFileName
private static string BuildFileName(string invoiceId) => $"{DirectoryName}/Invoice_{invoiceId}.json";
#endregion
#region Private Method LoadFileAsync
private static async Task<InvoiceModel?> LoadFileAsync(string fileName)
{
if (!File.Exists(fileName)) return null;
var jsonString = await File.ReadAllTextAsync(fileName);
return JsonSerializer.Deserialize<InvoiceModel>(jsonString)!;
}
#endregion
}
}

View File

@@ -0,0 +1,58 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Server.Model;
namespace Server.Data
{
public class SettingsData
{
#region Public Properties
public static SettingsData Instance { get; set; } = new();
public Address SellerAddress { get; set; } = new();
public PaymentData PaymentData { get; set; } = new();
public string? Comment { get; set; }
#endregion
#region Private Properties
private static string FileName => "Settings.json";
#endregion
#region Public Method Load
/// <summary>
/// Asynchronously loads the settings from a JSON file and updates the current instance of <see cref="SettingsData" />.
/// </summary>
/// <returns>A task that represents the asynchronous load operation.</returns>
public static async Task LoadAsync()
{
if (!File.Exists(FileName)) return;
var jsonString = await File.ReadAllTextAsync(FileName);
var deserialized = JsonSerializer.Deserialize<SettingsData>(jsonString)!;
Instance = deserialized;
}
#endregion
#region Public Method SaveAsync
/// <summary>
/// Serializes the current instance of <see cref="SettingsData" /> and saves it to a JSON file asynchronously.
/// </summary>
/// <returns>A task that represents the asynchronous save operation.</returns>
public static async Task SaveAsync()
{
var jsonString = JsonSerializer.Serialize(Instance, new JsonSerializerOptions { WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull});
await File.WriteAllTextAsync(FileName, jsonString);
}
#endregion
}
}

7
Server/Extensions.cs Normal file
View File

@@ -0,0 +1,7 @@
namespace Server
{
public static class Extensions
{
public static bool IsNullOrWhiteSpace(this string? value) => string.IsNullOrWhiteSpace(value);
}
}

8
Server/Model/Enum.cs Normal file
View File

@@ -0,0 +1,8 @@
namespace Server.Model
{
public enum RecordState
{
Default = 0,
Deleted = 1
}
}

View File

@@ -0,0 +1,237 @@
using System.Globalization;
using System.Net.Mime;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace Server.Model
{
public class InvoiceDocument(InvoiceModel model) : IDocument
{
private InvoiceModel Model { get; } = model;
public void Compose(IDocumentContainer container)
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.Margin(10, Unit.Millimetre);
page.MarginLeft(20, Unit.Millimetre);
page.PageColor(Colors.White);
page.DefaultTextStyle(x => x.FontSize(12).FontFamily(Fonts.Calibri).Light());
page.Header().Element(ComposeHeader);
page.Content().Element(ComposeContent);
page.Footer().Element(ComposeFooter);
});
}
private void ComposeContent(IContainer container)
{
container.PaddingVertical(40).Column(column =>
{
column.Spacing(5);
column.Item().Element(ComposeTable);
if (!string.IsNullOrWhiteSpace(Model.Comment))
column.Item().PaddingTop(25).Element(ComposeComments);
});
}
private void ComposeTable(IContainer container)
{
container.Table(table =>
{
// Define columns
table.ColumnsDefinition(columns =>
{
columns.ConstantColumn(30, Unit.Millimetre);
columns.RelativeColumn(3);
columns.RelativeColumn();
columns.RelativeColumn();
});
// Describe header
table.Header(header =>
{
header.Cell().Element(CellStyle).AlignCenter().Text("Menge");
header.Cell().Element(CellStyle).Text("Bezeichnung");
header.Cell().Element(CellStyle).AlignRight().Text("Einzelpreis");
header.Cell().Element(CellStyle).AlignRight().Text("Gesamtpreis");
static IContainer CellStyle(IContainer container)
{
return container.DefaultTextStyle(x => x.SemiBold()).BorderBottom(1).BorderColor(Colors.Black);
}
});
// Describe content
foreach (var item in Model.Items ?? [])
{
table.Cell().Element(CellStyle).AlignCenter().Text(txt => txt.Span($"{item.Quantity:N2}"));
table.Cell().Element(CellStyle).Column(column =>
{
column.Item().Text(item.Name);
if(!string.IsNullOrWhiteSpace(item.Description)) column.Item().Text(txt =>
{
txt.Span(item.Description).FontSize(8);
});
});
// string as currency format
table.Cell().Element(CellStyle).AlignRight().Text($"{item.PriceNetto:N2} €");
table.Cell().Element(CellStyle).AlignRight().Text($"{item.PriceNetto * item.Quantity:N2} €");
continue;
}
// Gesamt Netto
table.Cell().ColumnSpan(3).PaddingTop(10).Text("Gesamt Netto");
table.Cell().PaddingTop(10).AlignRight().Text($"{Model.TotalNetto:N2} €");
// 7%
var tax7Items = Model.Items?.Where(x => x.TaxType == TaxType.Tax7).ToList() ?? [];
if (tax7Items.Count > 0)
{
var tax7Netto = tax7Items.Sum(x => x.PriceNetto * x.Quantity);
var tax7Tax = tax7Netto * 0.07;
table.Cell().ColumnSpan(2).Text("zzgl. 7% USt. auf");
table.Cell().AlignRight().Text($"{tax7Netto:N2} €");
table.Cell().AlignRight().Text($"{tax7Tax:N2} €");
}
// 19%
var tax19Items = Model.Items?.Where(x => x.TaxType == TaxType.Tax19).ToList() ?? [];
if (tax19Items.Count > 0)
{
var tax19Netto = tax19Items.Sum(x => x.PriceNetto * x.Quantity);
var tax19Tax = tax19Netto * 0.19;
table.Cell().ColumnSpan(2).Text("zzgl. 19% USt. auf");
table.Cell().AlignRight().Text($"{tax19Netto:N2} €");
table.Cell().AlignRight().Text($"{tax19Tax:N2} €");
}
table.Cell().ColumnSpan(3).Element(CellStyle).PaddingTop(10).Text("Rechnungsbetrag").Medium();
table.Cell().Element(CellStyle).PaddingTop(10).AlignRight().Text($"{Model.Items.Sum(x=> x.PriceBrutto*x.Quantity):N2} €").Medium();
return;
static IContainer CellStyle(IContainer container) => container.BorderBottom(1).BorderColor(Colors.Grey.Lighten2).PaddingVertical(5);
});
}
private void ComposeComments(IContainer container)
{
container.Background(Colors.Grey.Lighten3).Padding(10).Column(column =>
{
column.Spacing(5);
column.Item().Text(Model.Comment);
});
}
private void ComposeFooter(IContainer container)
{
container.Column(outerColumn =>
{
outerColumn.Item().DefaultTextStyle(style => style.FontSize(10)).Row(row =>
{
row.RelativeItem().Column(column =>
{
column.Item().Text(txt => txt.Span(Model.Seller?.Name).Bold());
column.Item().Text(txt => txt.Span(Model.Seller?.Street));
column.Item().Text(txt => txt.Span($"{Model.Seller?.Zip} {Model.Seller?.City}"));
});
row.RelativeItem().Column(column =>
{
if(!string.IsNullOrWhiteSpace(Model.Seller?.Phone))
column.Item().Text(txt => txt.Span($"Tel.: {Model.Seller?.Phone}"));
if(!string.IsNullOrWhiteSpace(Model.Seller?.Email))
column.Item().Text(txt => txt.Span($"E-Mail: {Model.Seller?.Email}"));
if(!string.IsNullOrWhiteSpace(Model.Seller?.Web))
column.Item().Text(txt => txt.Span($"Web: {Model.Seller?.Web}"));
});
row.RelativeItem().Column(column =>
{
if(!string.IsNullOrWhiteSpace(Model.PaymentData?.BankName))
column.Item().Text(txt => txt.Span(Model.PaymentData?.BankName));
if(!string.IsNullOrWhiteSpace(Model.PaymentData?.Iban))
column.Item().Text(txt => txt.Span($"IBAN: {Model.PaymentData?.Iban}"));
if(!string.IsNullOrWhiteSpace(Model.PaymentData?.Bic))
column.Item().Text(txt => txt.Span($"BIC: {Model.PaymentData?.Bic}"));
});
});
outerColumn.Item().PaddingTop(3, Unit.Millimetre).AlignCenter().Text(txt =>
{
txt.CurrentPageNumber();
txt.Span(" / ");
txt.TotalPages();
});
});
}
private void ComposeHeader(IContainer container)
{
container.Column(outerColumn =>
{
outerColumn.Item().AlignCenter().Row(row =>
{
row.RelativeItem().AlignCenter().Column(col =>
{
col.Item().Height(25, Unit.Millimetre).Image("bit.bmp");
});
});
outerColumn.Item().PaddingTop(15, Unit.Millimetre).Row(row =>
{
row.AutoItem().Column(column =>
{
column.Item().Text(Model.Seller?.ToString()).Style(new TextStyle().FontSize(8).SemiBold().Underline());
if(!string.IsNullOrWhiteSpace(Model.Customer?.Name)) column.Item().Text(Model.Customer?.Name);
if(!string.IsNullOrWhiteSpace(Model.Customer?.Name2)) column.Item().Text(Model.Customer?.Name2);
column.Item().Text(Model.Customer?.Street);
column.Item().Text($"{Model.Customer?.Zip} {Model.Customer?.City}");
});
row.RelativeItem();
row.AutoItem().DefaultTextStyle(style => style.FontSize(10)).Column(column =>
{
column.Item().Text(txt =>
{
txt.Span("Steuer-Nr:").Bold().Underline();
txt.Span(" ");
txt.Span(Model.Seller?.TaxId);
});
column.Item().Text(txt =>
{
txt.Span("Datum:").Bold().Underline();
txt.Span(" ");
txt.Span(Model.IssueDate.ToShortDateString());
});
column.Item().Text(txt =>
{
txt.Span("Rechnung:").Bold();
txt.Span(" ");
txt.Span($"#{Model.InvoiceId}");
});
});
});
});
}
}
}

View File

@@ -0,0 +1,74 @@
namespace Server.Model
{
public class InvoiceModel
{
public bool DeletionAllowed { get; set; }
public string? InvoiceId { get; set; }
public DateTime IssueDate { get; set; } = DateTime.Today;
public Address? Seller { get; set; }
public Address? Customer { get; set; }
public List<OrderItem> Items { get; set; } = new();
public string? Comment { get; set; }
public PaymentData? PaymentData { get; set; }
public double TotalNetto => Items?.Sum(x => x.PriceNetto*x.Quantity) ?? 0d;
}
public class PaymentData
{
public string BankName { get; set; }
public string Iban { get; set; }
public string Bic { get; set; }
}
public class OrderItem
{
public string Name { get; set; }
public double PriceNetto { get; set; }
public double PriceBrutto
{
get
{
switch (TaxType)
{
case TaxType.Tax19:
default:
return PriceNetto * 1.19;
break;
case TaxType.Tax7:
return PriceNetto *1.07;
break;
}
}
}
public double Quantity { get; set; } = 1d;
public TaxType TaxType { get; set; } = TaxType.Tax19;
public string? Description { get; set; }
}
public class Address
{
public RecordState State { get; set; }
public string? Name { get; set; }
public string? Name2 { get; set; }
public string? Street { get; set; }
public string? City { get; set; }
public string? Zip { get; set; }
public string? Email { get; set; }
public string? Phone { get; set; }
public string? Web { get; set; }
public string? TaxId { get; set; }
public override string ToString() => $"{Name} - {Street} - {Zip} {City}";
}
public enum TaxType
{
Tax19, Tax7
}
}

27
Server/Program.cs Normal file
View File

@@ -0,0 +1,27 @@
using Server.Components;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error", createScopeForErrors: true);
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseAntiforgery();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();

View File

@@ -0,0 +1,38 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:16011",
"sslPort": 44359
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5065",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7251;http://localhost:5065",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

17
Server/Server.csproj Normal file
View File

@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="QuestPDF" Version="2024.10.2" />
</ItemGroup>
<ItemGroup>
<None Remove="Invoice.pdf" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"CircuitOptions:DetailedErrors": true
}

9
Server/appsettings.json Normal file
View File

@@ -0,0 +1,9 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

BIN
Server/bit.bmp Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 KiB

51
Server/wwwroot/app.css Normal file
View File

@@ -0,0 +1,51 @@
html, body {
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
}
a, .btn-link {
color: #006bb7;
}
.btn-primary {
color: #fff;
background-color: #1b6ec2;
border-color: #1861ac;
}
.btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus {
box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb;
}
.content {
padding-top: 1.1rem;
}
h1:focus {
outline: none;
}
.valid.modified:not([type=checkbox]) {
outline: 1px solid #26b050;
}
.invalid {
outline: 1px solid #e50000;
}
.validation-message {
color: #e50000;
}
.blazor-error-boundary {
background: url(data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTYiIGhlaWdodD0iNDkiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIG92ZXJmbG93PSJoaWRkZW4iPjxkZWZzPjxjbGlwUGF0aCBpZD0iY2xpcDAiPjxyZWN0IHg9IjIzNSIgeT0iNTEiIHdpZHRoPSI1NiIgaGVpZ2h0PSI0OSIvPjwvY2xpcFBhdGg+PC9kZWZzPjxnIGNsaXAtcGF0aD0idXJsKCNjbGlwMCkiIHRyYW5zZm9ybT0idHJhbnNsYXRlKC0yMzUgLTUxKSI+PHBhdGggZD0iTTI2My41MDYgNTFDMjY0LjcxNyA1MSAyNjUuODEzIDUxLjQ4MzcgMjY2LjYwNiA1Mi4yNjU4TDI2Ny4wNTIgNTIuNzk4NyAyNjcuNTM5IDUzLjYyODMgMjkwLjE4NSA5Mi4xODMxIDI5MC41NDUgOTIuNzk1IDI5MC42NTYgOTIuOTk2QzI5MC44NzcgOTMuNTEzIDI5MSA5NC4wODE1IDI5MSA5NC42NzgyIDI5MSA5Ny4wNjUxIDI4OS4wMzggOTkgMjg2LjYxNyA5OUwyNDAuMzgzIDk5QzIzNy45NjMgOTkgMjM2IDk3LjA2NTEgMjM2IDk0LjY3ODIgMjM2IDk0LjM3OTkgMjM2LjAzMSA5NC4wODg2IDIzNi4wODkgOTMuODA3MkwyMzYuMzM4IDkzLjAxNjIgMjM2Ljg1OCA5Mi4xMzE0IDI1OS40NzMgNTMuNjI5NCAyNTkuOTYxIDUyLjc5ODUgMjYwLjQwNyA1Mi4yNjU4QzI2MS4yIDUxLjQ4MzcgMjYyLjI5NiA1MSAyNjMuNTA2IDUxWk0yNjMuNTg2IDY2LjAxODNDMjYwLjczNyA2Ni4wMTgzIDI1OS4zMTMgNjcuMTI0NSAyNTkuMzEzIDY5LjMzNyAyNTkuMzEzIDY5LjYxMDIgMjU5LjMzMiA2OS44NjA4IDI1OS4zNzEgNzAuMDg4N0wyNjEuNzk1IDg0LjAxNjEgMjY1LjM4IDg0LjAxNjEgMjY3LjgyMSA2OS43NDc1QzI2Ny44NiA2OS43MzA5IDI2Ny44NzkgNjkuNTg3NyAyNjcuODc5IDY5LjMxNzkgMjY3Ljg3OSA2Ny4xMTgyIDI2Ni40NDggNjYuMDE4MyAyNjMuNTg2IDY2LjAxODNaTTI2My41NzYgODYuMDU0N0MyNjEuMDQ5IDg2LjA1NDcgMjU5Ljc4NiA4Ny4zMDA1IDI1OS43ODYgODkuNzkyMSAyNTkuNzg2IDkyLjI4MzcgMjYxLjA0OSA5My41Mjk1IDI2My41NzYgOTMuNTI5NSAyNjYuMTE2IDkzLjUyOTUgMjY3LjM4NyA5Mi4yODM3IDI2Ny4zODcgODkuNzkyMSAyNjcuMzg3IDg3LjMwMDUgMjY2LjExNiA4Ni4wNTQ3IDI2My41NzYgODYuMDU0N1oiIGZpbGw9IiNGRkU1MDAiIGZpbGwtcnVsZT0iZXZlbm9kZCIvPjwvZz48L3N2Zz4=) no-repeat 1rem/1.8rem, #b32121;
padding: 1rem 1rem 1rem 3.7rem;
color: white;
}
.blazor-error-boundary::after {
content: "An error has occurred."
}
.darker-border-checkbox.form-check-input {
border-color: #929292;
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

BIN
Server/wwwroot/favicon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

16
TinyInvoice.sln Normal file
View File

@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{5C37D859-8820-499C-A2A9-655BB70E4F6F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{5C37D859-8820-499C-A2A9-655BB70E4F6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5C37D859-8820-499C-A2A9-655BB70E4F6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5C37D859-8820-499C-A2A9-655BB70E4F6F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5C37D859-8820-499C-A2A9-655BB70E4F6F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal