Update Bestelluebersicht BestelluebersichtD-Chefin

This commit is contained in:
MET18937 2023-06-25 18:32:34 +02:00
parent 72cffa664e
commit 64da182295
3 changed files with 369 additions and 193 deletions

View File

@ -1,6 +1,9 @@
@page "/Bestelluebersicht"
@layout ChefinLayout
@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
<div class="container d-flex flex-column">
<div class="row">
<div class="col-lg-8">
@ -8,53 +11,51 @@
<table class="table table-bordered">
<thead>
<tr>
<th colspan="2">Aktive Bestellungen</th>
<th colspan="2">Aktive Bestellungen @day.@month.@year</th>
</tr>
</thead>
<tbody>
@*iterate all kunden*@
@foreach (var kunde in kunden)
{
bool firstTime = true;
@*if kunde has made a recent bestellungsposiotn from today and higher value than now, print it*@
@foreach (var bestellungsposition in bestellungspositions)
{
if (bestellungsposition.KundeIdkunde == kunde.Idkunde)
{
@*get the last highes datum from Datum*@
if (firstTime)
{
if (bestellungsposition.Datum == bestellungspositions.Max(x => x.Datum))
{
@*get hour and minute from datetime of last bestellungsposition*@
hour = bestellungsposition.Datum.Hour;
minute = bestellungsposition.Datum.Minute;
day = bestellungsposition.Datum.Day;
month = bestellungsposition.Datum.Month;
year = bestellungsposition.Datum.Year;
@*print kunde.code, hour and minute from last bestellungsposition*@
@*print only if date is higher than now datum *@
if (bestellungsposition.Datum > DateTime.Now)
{
<tr>
<td><a href="BDetail">#1234 &nbsp; 12:30</a></td>
<td><a href="BDetail">#2345 &nbsp; 18:45</a></td>
<td>
<p @onclick="@(()=>BDetail(@kunde.Idkunde))" class="mb-0 pb-0">
#@kunde.Code &nbsp;
@hour:@minute
</p>
</td>
</tr>
<tr>
<td><a href="BDetail">#3456 &nbsp; 13:00</a></td>
<td><a href="BDetail">#4567 &nbsp; 19:00</a></td>
</tr>
<tr>
<td><a href="BDetail">#5678 &nbsp; 14:30</a></td>
<td><a href="BDetail">#6789 &nbsp; 19:15</a></td>
</tr>
<tr>
<td><a href="BDetail">#4321 &nbsp; 15:15</a></td>
<td><a href="BDetail">#5432 &nbsp; 19:15</a></td>
</tr>
<tr>
<td><a href="BDetail">#6543 &nbsp; 15:30</a></td>
<td><a href="BDetail">#7654 &nbsp; 19:15</a></td>
</tr>
<tr>
<td><a href="BDetail">#7654 &nbsp; 15:30</a></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><a href="BDetail">#8765 &nbsp; 16:00</a></td>
<td>&nbsp;</td>
</tr>
<tr>
<td><a href="BDetail">#9876 &nbsp; 17:30</a></td>
<td>&nbsp;</td>
</tr>
}
}
firstTime = false;
}
}
}
}
</tbody>
</table>
</div>
@ -78,5 +79,59 @@
@code {
public int hour;
public int minute;
public int day;
public int month;
public int year;
private List<Bestellungsposition> bestellungspositions = new List<Bestellungsposition>();
private List<Kunde> kunden = new List<Kunde>();
private Kunde kunde = new Kunde();
public void BDetail(int id)
{
localStorage.SetItem<int>("KundeId", id);
_navigationManager.NavigateTo("/BestelluebersichtD-Chefin");
}
protected override async Task OnInitializedAsync()
{
// get data from api
bestellungspositions = await Http.GetFromJsonAsync<List<Bestellungsposition>>("https://localhost:7076/api/bestellungspositionen");
kunden = await Http.GetFromJsonAsync<List<Kunde>>("https://localhost:7076/api/kunden");
// set hour, minute, day , month, year to now date
hour = DateTime.Now.Hour;
minute = DateTime.Now.Minute;
day = DateTime.Now.Day;
month = DateTime.Now.Month;
year = DateTime.Now.Year;
}
public class Bestellungsposition
{
public int Idbestellung { get; set; }
public int Menge { get; set; }
public DateTime Datum { get; set; }
public int KundeIdkunde { get; set; }
public int? RabattIdrabatt { get; set; }
}
public class Kunde
{
public int Idkunde { get; set; }
public string Code { get; set; }
public int Treuepunkte { get; set; }
}
}

View File

@ -1,6 +1,10 @@
@page "/BestelluebersichtD-Chefin"
@layout ChefinLayout
@inject HttpClient Http
@inject Blazored.LocalStorage.ISyncLocalStorageService localStorage
@inject NavigationManager _navigationManager
<div class="container">
<div class="row">
<div class="col-sm-12 col-lg-6">
@ -9,75 +13,50 @@
<table class="table bdr">
<thead class="bg_green">
<tr>
<td>Ihre Bestellung</td>
<td>Ihre Bestellung (@day.@month.@year)</td>
<th></th>
</tr>
</thead>
<tbody class="bg_lightgreen" style="background-color:white;">
@if (menuitemIds.Count == 0)
{
<div class="card-body">
<h5 class="card-title" style="font-size:10pt; margin-bottom:0px;">Warenkorb ist leer</h5>
</div>
}
else
{
@foreach (var item in menuitemIds)
{
@foreach (var item2 in menuitems)
{
@if (item.Key == item2.IdmenuItem)
{
<tr>
<td class="br" style="padding-top:20px; padding-bottom:0px; border-bottom-width: 0px;">
1 Nudel mit Hühnerfleisch (groß)
<div style="font-size:0.7rem;padding-left:15px;">mit Knoblauchsoße</div>
@item.Value x
@item2.Bezeichnung
<div style="font-size:0.7rem;padding-left:15px;">@item2.Zusatzinformation</div>
</td>
<td class="d-flex justify-content-center align-items-center" style="padding-top:20px; padding-bottom:0px; border-style:hidden;">9,10€</td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;">1 Coca Cola</td>
<td class="d-flex justify-content-center align-items-center" style="padding-top:0px; border-style:hidden;">2,50€</td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-bottom-width: 0px; border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-bottom-width: 0px; border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-bottom-width: 0px; border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-bottom-width: 0px; border-style:hidden;"></td>
</tr>
<tr>
<td class="br" style=" padding-top:0px; border-bottom-width: 0px;"></td>
<td class="d-flex justify-content-center align-items-center" style="border-bottom-width: 0px; border-style:hidden;"></td>
<td class="d-flex justify-content-center align-items-center" style="padding-top:20px; border-bottom-width:0px;">@(item2.Preis * item.Value)€</td>
</tr>
}
}
}
}
</tbody>
<tfoot class="bg_lightgreen">
<tr style="border-top:solid 1px black; background-color:white;">
<th class="" style="text-align:right;">Summe</th>
<td class="d-flex justify-content-center align-items-center">11,60€</td>
<td class="d-flex justify-content-center align-items-center">
@summe€ &nbsp;
@if (rabattEinloesen)
{
<span style="color:green;">(- @rabatt.Prozent%)</span>
}
</td>
</tr>
</tfoot>
</table>
@ -103,7 +82,7 @@
<td class="d-flex justify-content-center align-items-center" style="padding-top:0px; background-color:white;">
<div style="margin:20px;">
<div class="d-flex justify-content-center align-items-center">
<p>12:30 Uhr</p>
<p>@hour:@minute Uhr (@day.@month.@year)</p>
</div>
</div>
</td>
@ -112,9 +91,9 @@
</table>
<div class="d-flex flex-column" style="align-items: center; margin-left: 100px;">
<button class="btn_back w-75">Zurück</button>
<button class="btn btn-danger w-75" style="border-radius: 50px; padding-top:12px; padding-bottom:12px; color:black;">Bestellung auflösen</button>
<button class="btn_forward w-75">Bestellung abschließen</button>
@*<button class="btn_back w-75">Zurück</button>*@
@*<button class="btn btn-danger w-75" style="border-radius: 50px; padding-top:12px; padding-bottom:12px; color:black;">Bestellung auflösen</button>*@
@*<button class="btn_forward w-75">Bestellung abschließen</button>*@
</div>
</div>
@ -136,4 +115,150 @@
</div>*@
@code {
public int hour;
public int minute;
public int day;
public int month;
public int year;
public decimal summe;
public Dictionary<int, int> menuitemIds = new Dictionary<int, int>();
private Rabatt rabatt = new Rabatt();
private bool rabattEinloesen;
public decimal rabattGutschrift;
private List<Bestellungsposition> bestellungspositions = new List<Bestellungsposition>();
private List<Kunde> kunden = new List<Kunde>();
private Kunde kunde = new Kunde();
private List<Menuitem> menuitems = new List<Menuitem>();
private List<Rabatt> rabatte = new List<Rabatt>();
private List<BestellungspositionHasMenuitem> bestellungspositionHasMenuitems = new List<BestellungspositionHasMenuitem>();
protected override async Task OnInitializedAsync()
{
// get data from api
bestellungspositions = await Http.GetFromJsonAsync<List<Bestellungsposition>>("https://localhost:7076/api/bestellungspositionen");
kunden = await Http.GetFromJsonAsync<List<Kunde>>("https://localhost:7076/api/kunden");
menuitems = await Http.GetFromJsonAsync<List<Menuitem>>("https://localhost:7076/api/Menuitems");
rabatte = await Http.GetFromJsonAsync<List<Rabatt>>("https://localhost:7076/api/Rabatte");
bestellungspositionHasMenuitems = await Http.GetFromJsonAsync<List<BestellungspositionHasMenuitem>>("https://localhost:7076/api/BestellungspositionHasMenuitems");
// get kunde from localstorage
int kundeId = localStorage.GetItem<int>("KundeId");
kunde = kunden.Where(x => x.Idkunde == kundeId).FirstOrDefault();
// get all menuitemIds from bestellungspositions with the last date
foreach (var bestellungsposition in bestellungspositions)
{
if (bestellungsposition.KundeIdkunde == kunde.Idkunde)
{
if (bestellungsposition.Datum == bestellungspositions.Max(x => x.Datum))
{
// get hour and minute from datetime of last bestellungsposition
hour = bestellungsposition.Datum.Hour;
minute = bestellungsposition.Datum.Minute;
day = bestellungsposition.Datum.Day;
month = bestellungsposition.Datum.Month;
year = bestellungsposition.Datum.Year;
//if rabatt is used
if (bestellungsposition.RabattIdrabatt != null)
{
rabattEinloesen = true;
foreach (var rabatt in rabatte)
{
if (rabatt.Idrabatt == bestellungsposition.RabattIdrabatt)
{
this.rabatt = rabatt;
}
}
}
foreach (var bestellungspositionHasMenuitem in bestellungspositionHasMenuitems)
{
if (bestellungspositionHasMenuitem.Bestellungsposition_IDBestellung == bestellungsposition.Idbestellung)
{
menuitemIds.Add(bestellungspositionHasMenuitem.MenuItem_IDMenuItem, bestellungsposition.Menge);
}
}
}
}
}
// get summe
foreach (var menuitem in menuitems)
{
foreach (var menuitemId in menuitemIds)
{
if (menuitem.IdmenuItem == menuitemId.Key)
{
summe += menuitem.Preis * menuitemId.Value;
}
}
}
//if rabatt is used calculate new summe
if (rabattEinloesen)
{
rabattGutschrift = (summe * rabatt.Prozent / 100);
summe = summe - rabattGutschrift;
summe = Math.Round(summe, 2);
}
}
public class Bestellungsposition
{
public int Idbestellung { get; set; }
public int Menge { get; set; }
public DateTime Datum { get; set; }
public int KundeIdkunde { get; set; }
public int? RabattIdrabatt { get; set; }
}
public class Kunde
{
public int Idkunde { get; set; }
public string? Code { get; set; }
public int? Treuepunkte { get; set; }
}
public class Menuitem
{
public int IdmenuItem { get; set; }
public string? Bezeichnung { get; set; }
public string? Zusatzinformation { get; set; }
public decimal Preis { get; set; }
}
public class Rabatt
{
public int Idrabatt { get; set; }
public decimal Prozent { get; set; }
public DateTime? GueltigkeitVon { get; set; }
public DateTime? GueltigkeitBis { get; set; }
}
public class BestellungspositionHasMenuitem
{
public int Bestellungsposition_IDBestellung { get; set; }
public int MenuItem_IDMenuItem { get; set; }
}
}

View File

@ -126,6 +126,7 @@
@code {
bool changeButtonBool { get; set; } = true;
@ -137,11 +138,6 @@
changeButtonBool = !changeButtonBool;
}
}
@code {
public int hour;
public int minute;
public int day;