120 lines
3.8 KiB
C#
120 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
using Pos.Models;
|
|
using Pos.Service;
|
|
|
|
namespace Pos
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for PrintReceiptWindow.xaml
|
|
/// </summary>
|
|
public partial class PrintReceiptWindow : Window
|
|
{
|
|
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()
|
|
{
|
|
InitializeComponent();
|
|
|
|
StartDatePicker.DisplayDate = DateTime.Now.AddDays(-7);
|
|
StartDatePicker.SelectedDate = DateTime.Now.AddDays(-7);
|
|
EndDatePicker.DisplayDate = DateTime.Now;
|
|
EndDatePicker.SelectedDate = DateTime.Now;
|
|
}
|
|
|
|
private void Search_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
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 = 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;
|
|
}
|
|
|
|
|
|
public class ListReceiptModel
|
|
{
|
|
public int Id { get; set; }
|
|
public string Content { get; set; }
|
|
|
|
public override string ToString()
|
|
{
|
|
return Content;
|
|
}
|
|
}
|
|
|
|
private void ListReciept_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
|
{
|
|
if (_init || e.AddedItems.Count == 0)
|
|
return;
|
|
|
|
ListReceiptModel data = (ListReceiptModel) e.AddedItems[0];
|
|
_saleId = data.Id;
|
|
ReceiptDetailModel receipt =
|
|
_saleHistoryService.GetReceipt(data.Id);
|
|
StringBuilder sb = new StringBuilder();
|
|
foreach (ReceiptLineModel saleLine in receipt.Lines)
|
|
{
|
|
sb.AppendLine(
|
|
$"{saleLine.Product} - {saleLine.Pieces} stk. a' {saleLine.Price:0.00} = {saleLine.Total:0.00}");
|
|
}
|
|
|
|
sb.AppendLine($"Total: {receipt.Total:0.00} kr.");
|
|
PrintReceipt.Visibility = Visibility.Visible;
|
|
SaleLines.Clear();
|
|
SaleLines.Text = sb.ToString();
|
|
}
|
|
|
|
private void PrintReceipt_OnClick(object sender, RoutedEventArgs e)
|
|
{
|
|
_saleService.PrintReceipt(_saleId);
|
|
}
|
|
}
|
|
}
|