private void PrintReceipt() { this.Dispatcher.Invoke((Action)(() => { PrintButton.IsEnabled = false; PrintButton.Content = "Printing..."; })); if (orderDetails.CurrentAddress == null) { printer.Print(orderDetails); } ItemManager.AddOrderToCount(orderDetails.ItemBasket.Items); if (orderDetails.CurrentAddress != null) { if (!string.IsNullOrEmpty(orderDetails.CurrentAddress.Number) && !string.IsNullOrEmpty(orderDetails.CurrentAddress.Road) && !string.IsNullOrEmpty(orderDetails.CurrentAddress.PhoneNumber)) { printer.Print(orderDetails); AddressManager.AddCustomerToCount(orderDetails.CurrentAddress); } NotifyPropertyChanged("PrintDiagnosticMessage"); } AddressManager.AddToRecentOrder(orderDetails); }
private void PrintReceipt(bool card) { ReceiptPrinter printer = new ReceiptPrinter(); DateTime currentTime = DateTime.Now; if (DataContext is Order order) { printer.Print("Order Number:\t" + Order.OrderNumber.ToString()); printer.Print("\n" + currentTime.ToString() + "\n\n"); foreach (IOrderItem item in order.Items) { printer.Print(item.ToString() + "\t" + item.Price.ToString("C2") + "\n"); int temp = 0; while (temp < item.SpecialInstructions.Count) { printer.Print("\t" + item.SpecialInstructions[temp].ToString() + "\n"); temp++; } } printer.Print("\nSubtotal:\t" + order.Subtotal.ToString("C2")); printer.Print("\nTotal:\t\t" + order.Total.ToString("C2")); if (card) { printer.Print("\nPayment Type:\tCredit\n\n\n"); } else { printer.Print("\nPayment Type:\tCash"); } } }
/// <summary> /// Creates a click event for the Credit button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnCreditPaymentClicked(object sender, RoutedEventArgs e) { var orderControl = this.FindAncestor <OrderControl>(); CardTerminal terminal = new CardTerminal(); ResultCode result = ResultCode.InsufficentFunds; if (DataContext is Order o) { result = terminal.ProcessTransaction(o.Subtotal); if (result != ResultCode.Success) { MessageBox.Show("Card Reader Error - Try Again", "ERROR", MessageBoxButton.OK); } else { ReceiptPrinter receipt = new ReceiptPrinter(); receipt.Print(o.ToString()); orderControl.Stupid(); orderControl.SwapScreen(new MenuItemSelectionControl()); } } else { MessageBox.Show("Coding Error - Try Again", "ERROR", MessageBoxButton.OK); } }
/// <summary> /// Completes a credit transaction on click /// </summary> /// <param name="sender"></param> /// <param name="arg"></param> private void CreditButton_Click(object sender, RoutedEventArgs arg) { if (DataContext is Order order) { switch (terminal.ProcessTransaction(order.Total)) { case ResultCode.Success: printer.Print(order.Receipt(false, 0, 0)); FinishOrder(this, arg); break; case ResultCode.CancelledCard: MessageBox.Show("ERROR: Cancelled Card"); break; case ResultCode.ReadError: MessageBox.Show("ERROR: Read Error"); break; case ResultCode.InsufficentFunds: MessageBox.Show("ERROR: Insuffucient Funds"); break; default: MessageBox.Show("ERROR: Unknown Error"); break; } } }
public void ItPrintsABasicReceipt() { var receipt = new Receipt { ItemPrices = new List <ItemPrice> { new ItemPrice { Name = "Apple", Price = 0.5M, Promotion = new BuyOneGetOneFree() }, new ItemPrice { Name = "Banana", Price = 2.45M }, }, ScannedItems = new List <ScannedItem> { new ScannedItem() { Name = "Apple" }, new ScannedItem() { Name = "Apple" }, new ScannedItem() { Name = "Banana" } } }; var receiptPrinter = new ReceiptPrinter(receipt); Assert.AreEqual("Apple x2\t$0.50\r\nBanana x1\t$2.45\r\nTotal: $2.95", receiptPrinter.Print()); }
public void ItPrintsAnEmptyReceipt() { var receipt = new Receipt(); var receiptPrinter = new ReceiptPrinter(receipt); Assert.AreEqual("No items found\r\nTotal: $0.00", receiptPrinter.Print()); }
/// <summary> /// Event handler for when the Credit Payment Button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void CreditPaymentButton_Click(object sender, RoutedEventArgs e) { Cash = false; CardTerminal card = new CardTerminal(); ReceiptPrinter printer = new ReceiptPrinter(); if (DataContext is Order order) { switch (card.ProcessTransaction(order.Total)) { case ResultCode.Success: credit = true; printer.Print(ReceiptText()); CancelOrderButton_Click(new object(), new RoutedEventArgs()); break; case ResultCode.InsufficentFunds: MessageBox.Show("Error: " + ResultCode.InsufficentFunds.ToString()); break; case ResultCode.CancelledCard: MessageBox.Show("Error: " + ResultCode.CancelledCard.ToString()); break; case ResultCode.ReadError: MessageBox.Show("Error: " + ResultCode.ReadError.ToString()); break; case ResultCode.UnknownErrror: MessageBox.Show("Error: " + ResultCode.UnknownErrror.ToString()); break; } } }
/// <summary> /// When the credit button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnCreditButtonClicked(object sender, RoutedEventArgs e) { CardTerminal card = new CardTerminal(); Order o = (Order)DataContext; double total = o.Total; ResultCode result = card.ProcessTransaction(total); if (result == ResultCode.Success) { ReceiptPrinter rp = Register.ReceiptPrinter; String reciept = ReceiptCreator(); reciept += "\n\nPaid by Credit Card\n\n"; reciept += DateTime.Now.ToString() + "\n\n"; rp.Print(reciept); var orderInfo = this.FindAncestor <OrderControl>(); OrderControl od = new OrderControl(); orderInfo.SwapOrderSum(od); } else { MessageBox.Show(result.ToString()); } }
/// <summary> /// Helper method to construct the string for the receipt /// </summary> /// <param name="data">The Order</param> private void ReceiptPrinting(Order data, bool credit) { var receiptPrinter = new ReceiptPrinter(); StringBuilder sb = new StringBuilder(); sb.AppendLine("Order: " + data.OrderNumber.ToString()); sb.AppendLine(DateTime.Now.ToString()); foreach (IOrderItem item in data.Items) { sb.AppendLine(item.ToString()); if (item.SpecialInstructions != null) { foreach (string details in item.SpecialInstructions) { sb.AppendLine(details); } } } sb.AppendLine("Subtotal: " + String.Format("{0:C2}", data.Subtotal)); sb.AppendLine("Total: " + String.Format("{0:C2}", data.Total)); if (credit) { sb.AppendLine("Paid with Credit"); } else { sb.AppendLine("Paid with Cash"); } receiptPrinter.Print(sb.ToString()); }
/// <summary> /// Print Reciept Helper Method /// </summary> /// <param name="method">Method of payment</param> /// <param name="paid">Amount paid</param> /// <param name="returned">Amount returned</param> private void PrintReciept(string method, double paid, double returned) { var recieptPrinter = new ReceiptPrinter(); var order = this.DataContext as Order; string text = ""; uint on = order.OrderNumber - 1; DateTime dt = DateTime.Now; text = "Order Number: " + on + "\n Date: " + dt; foreach (var item in order.Items) { text += "\n" + item.ToString() + " Price: " + item.Price; } if (method == "Card") { text += "\n Card Charged: " + paid; } else { text += "\n Cash Given: " + paid; text += "\n Cash Returned: " + returned; } recieptPrinter.Print(text); }
/// <summary> /// When the complete button is pressed /// </summary> public void complete() { Pennies = Pennies + EnterPennies; Dimes = Dimes + EnterDimes; Nickels = Nickels + EnterNickels; Quarters = Quarters + EnterQuarters; HalfDollars = HalfDollars + EnterHalfDollars; Dollars = Dollars + EnterDollars; Ones = Ones + EnterOnes; Twos = Twos + EnterTwos; Fives = Fives + EnterFives; Tens = Tens + EnterTens; Twentys = Twentys + EnterTwentys; Fiftys = Fiftys + EnterFiftys; Hundreds = Hundreds + EnterHundreds; MessageBox.Show(ReturnChange()); string reciept = Register.Receipt; reciept += "\n\nTotal Paid: " + EnterTotal.ToString("C2") + "\nTotal Change: " + Change.ToString("C02") + "\n\n" + DateTime.Now.ToString() + "\n\n"; ReceiptPrinter rp = Register.ReceiptPrinter; rp.Print(reciept); }
/// <summary> /// Click event handler for Cash Payment selection /// </summary> /// <param name="sender">Button</param> /// <param name="args">Event arguments</param> void onCompleteTransactionClicked(object sender, RoutedEventArgs e) { var orderControl = this.FindAncestor <OrderControl>(); if (DataContext is Order order) { if (sender is Button button) { if (order.Owed == 0.0) { if (initialPayment != 0.0) { printer.Print(order.FormatCashReceipt(initialPayment, change)); } orderControl.DataContext = new Order(); orderControl.SwapScreen(new MenuItemSelectionControl()); } else { AmountOwedBorder.BorderBrush = Brushes.Red; SwapScreen(null); CashButton.IsEnabled = true; CardButton.IsEnabled = true; } } } }
/// <summary> /// Prints receipt /// </summary> /// <param name="pay"> number that represents the method of payment</param> private void Receipt(int pay) { ReceiptPrinter r = new ReceiptPrinter(); StringBuilder sb = new StringBuilder(); sb.Append("\t Cowboy Cafe\n _________________________________________\n\nOrder #" + OrderNumber.ToString() + "\t\t\t" + DateTime.Now + "\n\n"); foreach (IOrderItem i in Items) { sb.Append(i.ToString() + "\t\t " + i.Price.ToString("C2")); foreach (string st in i.SpecialInstructions) { sb.Append("\n\t" + st); } sb.Append("\n"); } sb.Append("\nSubtotal: " + Subtotal.ToString("C2") + "\nTax: \t " + Tax.ToString("C2") + "\nTotal: \t " + Total.ToString("C2") + "\n"); if (pay == 0) { sb.Append("\nPaid: \t" + Paid.ToString("C2")); } else { sb.Append("\nCredit: \t " + Paid.ToString("C2")); } sb.Append("\nChange: \t " + Change.ToString("C2")); string s = sb.ToString(); MessageBox.Show(s); r.Print(s); s = "Contents of the Cash Drawer\n\n____________________________\n Coins\n____________________________\n\nPennies: " + cd.Pennies + "\nNickels: " + cd.Nickels + "\nDimes: " + cd.Dimes + "\nQuarters: " + cd.Quarters + "\nHalf Dollars: " + cd.HalfDollars + "\nDollars: " + cd.Dollars + "\n\n____________________________\n Bills\n____________________________\n\nOnes: " + cd.Ones + "\nTwos: " + cd.Twos + "\nFives: " + cd.Fives + "\nTens: " + cd.Tens + "\nTwenties: " + cd.Twenties + "\nFifties: " + cd.Fifties + "\nHundreds: " + cd.Hundreds + "\n\n____________________________\nCash Drawer Total: " + cd.TotalValue.ToString("C2") + "\n____________________________\n"; MessageBox.Show(s); NewOrder(); }
/// <summary> /// Calculates the change needed when the cash given is submitted /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnTotalChanged(object sender, EventArgs e) { double change = 0.00; if (sender is CashRegisterControl CRC) { if (DataContext is Order o) { change = Math.Round(Total - CRC.CashGiven, 2); } if (change < 0) { MessageBox.Show(GetChangeReport(-change)); MessageBox.Show("Success, printing receipt..."); string CreditReceipt = CreateReceipt() + string.Format("\nCASH GIVEN: {0:C}\nCHANGE:\t{1:C}\n", CRC.CashGiven, -change); var receiptPrinter = new ReceiptPrinter(); receiptPrinter.Print(CreditReceipt); var orderControl = ExtensionMethods.FindAncestor <OrderControl>(this); orderControl.DataContext = new Order(); orderControl.SwapScreen(new MenuItemSelectionControl()); } } }
private void PrintReceiptForTransaction(double amountpaid, double returnedamount, string paymenttype) { var recieptPrinter = new ReceiptPrinter(); var order = this.DataContext as Order; string text = ""; DateTime date = DateTime.Now; uint orderNum = order.OrderNumber - 1; text = "\nOrder Number: " + orderNum + "\n Date: " + date; foreach (var item in order.Items) { text += "\n" + item.ToString() + " Price: " + item.Price; } if (paymenttype == "Card") { text += "\n Card Charged: " + amountpaid; } else { text += "\n Cash Given: " + amountpaid; text += "\n Cash Returned: " + returnedamount; } recieptPrinter.Print(text); }
/// <summary> /// Prints the receipt after a credit payment, or shows an error in the cardreading /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnCreditPayment(object sender, RoutedEventArgs e) { CardTerminal ct = new CardTerminal(); ResultCode message = ct.ProcessTransaction(Total); if (message != ResultCode.Success) { MessageBox.Show(message.ToString()); } else { ReceiptPrinter rp = new ReceiptPrinter(); StringBuilder sb = new StringBuilder(); sb.Append("Order #" + orderSummary.OrderNumber.Text + "\n" + DateTime.Now.ToString() + "\n\n"); foreach (IOrderItem i in orderSummary.listBox.Items) { sb.Append(i.ToString() + String.Format(" {0:C2}", i.Price) + "\n"); foreach (string s in i.SpecialInstructions) { sb.Append(s + "\n"); } } sb.Append("\n"); sb.Append("Subtotal: " + orderSummary.Subtotal.Text + "\n"); sb.Append(String.Format("Total: {0:C2}\n", Total)); sb.Append("Credit\n\n"); rp.Print(sb.ToString()); MessageBox.Show(sb.ToString()); orderSummary.IsEnabled = true; TransactionContainer.Child = new OrderControl(); } }
private void PayCredit_Click(object sender, RoutedEventArgs e) { Order or = (Order)this.DataContext; var card = new CardTerminal(); ResultCode res = card.ProcessTransaction(total); if (res == ResultCode.Success) { var pr = new ReceiptPrinter(); DateTime date = DateTime.Now; string rec = ("Order: " + or.OrderNumber + " " + date.ToString() + " " + ReceiptHelper(or) + "Subtotal: " + or.Subtotal.ToString("C") + " Total: " + ((or.Subtotal * 0.16 + or.Subtotal).ToString("C")) + " Credit"); pr.Print(rec); var wind = this.FindAncestor <MainWindow>(); wind.Content = new OrderControl(); } else if (res == ResultCode.InsufficentFunds) { ErrorBox.Text = "Insufficient Funds on Card."; } else if (res == ResultCode.ReadError) { ErrorBox.Text = "Card Read Error, Try Again."; } else if (res == ResultCode.CancelledCard) { ErrorBox.Text = "Card Has Been Cancelled."; } else if (res == ResultCode.UnknownErrror) { ErrorBox.Text = "Unknown Error Occured."; } }
private void CardPayment(object sender, RoutedEventArgs e) { var oc = this.FindAncestor<OrderControl>(); if(oc.DataContext is Order order) { var reader = new CardTerminal(); var printer = new ReceiptPrinter(); var result = reader.ProcessTransaction(order.Total); switch (result) { case ResultCode.Success: Display.Text = "Success."; printer.Print(CreateCardReceipt(order)); oc.SwapScreen(new MenuItemSelectionControl()); oc.DataContext = new Order(); break; case ResultCode.CancelledCard: case ResultCode.InsufficentFunds: case ResultCode.ReadError: case ResultCode.UnknownErrror: string r = result.ToString(); Display.Text = r; oc.SwapScreen(new TransactionControl()); break; } } }
/// <summary> /// Proccess Credit Card Transaction /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnCreditClicked(object sender, RoutedEventArgs e) { CardTerminal card = new CardTerminal(); paymentMethod = false; ReceiptPrinter printer = new ReceiptPrinter(); MainWindow mw = this.FindAncestor <MainWindow>(); if (DataContext is Order order) { var result = card.ProcessTransaction(TotalWithTax); if (result == ResultCode.Success) { MessageBox.Show("Success"); printer.Print(Reciept()); mw.DataContext = new Order(); mw.Container.Child = new OrderControl(); } else { MessageBox.Show(result.ToString()); mw.Container.Child = new TransactionControl(order); } } }
/// <summary> /// Creates a click event for the One button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnAddHundredClicked(object sender, RoutedEventArgs e) { var orderControl = this.FindAncestor <OrderControl>(); StillDue -= 100.0; AmountGiven += 100.0; orderControl.CurrentDrawer.AddBill(Bills.Hundred, 1); if (StillDue == 0) { MessageBox.Show("Customer gave exact amount, no change due", "Change Due", MessageBoxButton.OK); ReceiptPrinter receipt = new ReceiptPrinter(); var o = DataContext as Order; receipt.Print(o.ToString(AmountGiven)); orderControl.Stupid(); orderControl.SwapScreen(new OrderSummaryControl()); } else if (StillDue < 0) { StillDue *= -1.0; AdjustDrawer(StillDue); MessageBox.Show("Customer was dispensed $" + StillDue.ToString("#.00") + " below and drawer has adjusted accordingly", "Change Due", MessageBoxButton.OK); ReceiptPrinter receipt = new ReceiptPrinter(); var o = DataContext as Order; receipt.Print(o.ToString(AmountGiven)); orderControl.Stupid(); orderControl.SwapScreen(new OrderSummaryControl()); } }
/// <summary> /// Prints a receipt according to the payment method passed /// </summary> /// <param name="paymentMethod">payment method as a string for display on the receipt</param> public void PrintReceipt(string paymentMethod) { ReceiptPrinter printer = new ReceiptPrinter(); printer.Print(TransactionToString(paymentMethod)); MessageBox.Show("Receipt is printing."); }
/// <summary> /// Event handler for when cashier gives back cash. When instructions and given change are equal, the receipt is printed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnChangeReceived(object sender, RoutedEventArgs e) { if (GivenChange.Text != "") { GivenChangeTitle.Visibility = Visibility.Visible; } if (("Give as change:\n\n" + GivenChange.Text) == ChangeInstructions.Text) { ReceiptPrinter rp = new ReceiptPrinter(); StringBuilder sb = new StringBuilder(); double total = Convert.ToDouble(TotalTextBox.Text.Remove(0, 1)); double amountPaid = Convert.ToDouble(RunningTotalBox.Text.Remove(0, 1)); sb.Append("Order #" + orderSummary.OrderNumber.Text + "\n" + DateTime.Now.ToString() + "\n\n"); foreach (IOrderItem i in orderSummary.listBox.Items) { sb.Append(i.ToString() + String.Format(" {0:C2}", i.Price) + "\n"); foreach (string s in i.SpecialInstructions) { sb.Append(s + "\n"); } } sb.Append("\n"); sb.Append("Subtotal: " + orderSummary.Subtotal.Text + "\n"); sb.Append(String.Format("Total: {0:C2}\n", total)); sb.Append(String.Format("Amount Paid: {0:C2}\n", amountPaid)); sb.Append(String.Format("Change given: {0:C2}\n", amountPaid - total)); sb.Append("Cash\n\n"); rp.Print(sb.ToString()); MessageBox.Show(sb.ToString()); RegisterContainer.Child = new OrderControl(); } }
/// <summary> /// method to calculate the changed needed when cash is submitted /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnTotalChanged(object sender, EventArgs e) { double change = 0; if (sender is CashPayControl cpc) { if (DataContext is Order o) { change = Math.Round(cpc.CashPaid - Total, 2); } if (change > 0) { MessageBox.Show(CalculateChange(change)); MessageBox.Show("Printing receipt"); string CreditReceipt = MakeReceipt() + string.Format("\nCASH GIVEN: {0:C}\nCHANGE:\t{1:C}\n", cpc.CashPaid, -change); var receiptPrinter = new ReceiptPrinter(); receiptPrinter.Print(CreditReceipt); var orderControl = ExtensionMethods.FindAncestor <OrderControl>(this); orderControl.DataContext = new Order(); orderControl.SwapScreen(new MenuItemSelectionControl()); } } }
private void CreditButtonClick(object sender, RoutedEventArgs e) { var card = new CardTerminal(); if (DataContext is Order data) { ResultCode result = card.ProcessTransaction(data.Total); switch (result) { case ResultCode.Success: ReceiptPrinter receiptPrinter = new ReceiptPrinter(); var orderControl = new OrderControl(); var mainWindow = this.FindAncestor <MainWindow>(); mainWindow.SwapScreenMain(orderControl); ReceiptPrinter print = new ReceiptPrinter(); print.Print(data.OrderNumber.ToString()); print.Print(DateTime.Now.ToString()); foreach (IOrderItem item in data.Items) { print.Print(item.ToString() + " : " + item.Price.ToString()); print.Print(item.SpecialInstructions.ToString()); } print.Print(data.Total.ToString()); break; case ResultCode.InsufficentFunds: cardStatus = "Insufficent Funds"; break; case ResultCode.ReadError: cardStatus = "Read Error"; break; case ResultCode.UnknownErrror: cardStatus = "Unknown Error"; break; } CardStatus.Text = cardStatus; } }
public ChangeView(OrderControl orderC, double change) { InitializeComponent(); orderControl = orderC; ChangeDisplayText.Text = String.Format("Resulting Change: {0:C}", change); ReceiptPrinter receiptPrinter = new ReceiptPrinter(); receiptPrinter.Print(ReceiptBuilder(change)); }
public void GivenMoreCash(double given) { ReceiptPrinter receipt = new ReceiptPrinter(); var o = DataContext as Order; receipt.Print(o.ToString(given)); Stupid(); SwapScreen(new MenuItemSelectionControl()); }
/// <summary> /// Actually print receipt and finish /// </summary> public void FinishTransaction() { // Print receipt ReceiptPrinter receiptPrinter = new ReceiptPrinter(); receiptPrinter.Print(Transaction.ToString()); parent.SwapScreen(new OrderControl()); }
public void GivenExactCash(double given) { MessageBox.Show("Customer gave exact amount, no change due", "Change Due", MessageBoxButton.OK); ReceiptPrinter receipt = new ReceiptPrinter(); var o = DataContext as Order; receipt.Print(o.ToString(given)); Stupid(); SwapScreen(new MenuItemSelectionControl()); }
/// <summary> /// Button event for Cancelling an order. Sets DataContext to a new instance. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void OnCompleteOrderButtonClicked(object sender, RoutedEventArgs e) { if (DataContext is UsersMoneyGivenModelView view) { view.TotalOwed = order.Total; receiptprinter.Print(order.Receipt(true, view.TotalValue, view.TotalOwed)); double change = Math.Round(view.TotalValue - view.TotalOwed, 2); var screen = new ChangeControl(change); this.Content = screen; } }
/// <summary> /// Completes order and prints the receipt. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void OnCompleteButton_Clicked(object sender, RoutedEventArgs e) { if (DataContext is CashRegisterModelView view) { if (total == owed) { receiptPrinter.Print(order.Receipt(false, 0, 0)); var screen = new OrderControl(); this.Content = screen; } } }
public void ItPrintsABasicReceipt() { var receipt = new Receipt { ItemPrices = new List<ItemPrice> { new ItemPrice { Name = "Apple", Price = 0.5M, Promotion = new BuyOneGetOneFree()}, new ItemPrice { Name = "Banana", Price = 2.45M}, }, ScannedItems = new List<ScannedItem> { new ScannedItem() { Name="Apple" }, new ScannedItem() { Name="Apple" }, new ScannedItem() { Name="Banana" } } }; var receiptPrinter = new ReceiptPrinter(receipt); Assert.AreEqual("Apple x2\t$0.50\r\nBanana x1\t$2.45\r\nTotal: $2.95", receiptPrinter.Print()); }