Rework so employee dont use repos but servies

This commit is contained in:
Alex Pedersen
2026-07-30 10:23:27 +02:00
parent 6df185d519
commit 9497afe262
26 changed files with 630 additions and 125 deletions

View File

@@ -11,8 +11,7 @@ using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Database.Models;
using Database.Repository;
using Pos.Models;
using Pos.Service;
namespace Pos
@@ -25,6 +24,9 @@ namespace Pos
private List<ListReceiptModel> _receiptList = new List<ListReceiptModel>();
private bool _init = false;
private int _saleId = 0;
private readonly SaleHistoryService _saleHistoryService =
new SaleHistoryService();
private readonly SaleService _saleService = new SaleService();
public PrintReceiptWindow()
{
@@ -38,28 +40,39 @@ namespace Pos
private void Search_OnClick(object sender, RoutedEventArgs e)
{
DateTime startDate = (DateTime)StartDatePicker.SelectedDate;
DateTime endDate = (DateTime)EndDatePicker.SelectedDate;
SaleRepository saleRepository = new SaleRepository();
List<SaleEntity> saleEntities = saleRepository.GetByDateRange(startDate, endDate);
foreach (SaleEntity entity in saleEntities)
{
List<SaleLineEntity> saleLineBySaleId = saleRepository.GetSaleLineBySaleId(entity.Id);
decimal total = 0;
foreach (SaleLineEntity lineEntity in saleLineBySaleId)
{
total += lineEntity.Total;
}
if (StartDatePicker.SelectedDate is not DateTime startDate ||
EndDatePicker.SelectedDate is not DateTime endDate)
return;
List<ReceiptSummaryModel> receipts;
try
{
receipts = _saleHistoryService.Search(startDate, endDate);
}
catch (ArgumentException exception)
{
MessageBox.Show(
exception.Message,
"Ugyldigt datointerval",
MessageBoxButton.OK,
MessageBoxImage.Warning);
return;
}
_receiptList.Clear();
foreach (ReceiptSummaryModel receipt in receipts)
{
ListReceiptModel receiptModel = new ListReceiptModel
{
Id = entity.Id,
Content = $"{entity.Time:dd-MM-yyyy HH:mm} - Pris: {total:0.00}"
Id = receipt.SaleId,
Content =
$"{receipt.SaleTime:dd-MM-yyyy HH:mm} - Pris: {receipt.Total:0.00}"
};
_receiptList.Add(receiptModel);
}
_init = true;
ListReciept.ItemsSource = null;
ListReciept.ItemsSource = _receiptList;
_init = false;
}
@@ -78,23 +91,21 @@ namespace Pos
private void ListReciept_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (_init)
if (_init || e.AddedItems.Count == 0)
return;
ListReceiptModel data = (ListReceiptModel) e.AddedItems[0];
_saleId = data.Id;
SaleRepository saleRepository = new SaleRepository();
List<SaleLineEntity> saleLineBySaleId = saleRepository.GetSaleLineBySaleId(data.Id);
ReceiptDetailModel receipt =
_saleHistoryService.GetReceipt(data.Id);
StringBuilder sb = new StringBuilder();
decimal total = 0;
foreach (SaleLineEntity saleLine in saleLineBySaleId)
foreach (ReceiptLineModel saleLine in receipt.Lines)
{
total += saleLine.Total;
sb.AppendLine(
$"{saleLine.Product} - {saleLine.Pieces} stk. a' {saleLine.Price.ToString("0.00")} = {saleLine.Total.ToString("0.00")}");
$"{saleLine.Product} - {saleLine.Pieces} stk. a' {saleLine.Price:0.00} = {saleLine.Total:0.00}");
}
sb.AppendLine($"Total: {total.ToString("0.00")} kr.");
sb.AppendLine($"Total: {receipt.Total:0.00} kr.");
PrintReceipt.Visibility = Visibility.Visible;
SaleLines.Clear();
SaleLines.Text = sb.ToString();
@@ -102,8 +113,7 @@ namespace Pos
private void PrintReceipt_OnClick(object sender, RoutedEventArgs e)
{
SaleService saleService = new SaleService();
saleService.PrintReceipt(_saleId);
_saleService.PrintReceipt(_saleId);
}
}
}