private static double RefundTicket(Ticket selectedTicket, TicketRefundType refundType) { double sumOfPayments = TicketPayment.GetAll(selectedTicket.PrimaryKey) .Sum(payment => payment.Amount); // Don't refund money for items that were already returned sumOfPayments = TicketItemReturn.GetAllForTicket(selectedTicket.PrimaryKey) .Aggregate(sumOfPayments, (current, ticketItemReturn) => current - ticketItemReturn.Amount); RegisterManager.ActiveRegisterDrawer.RemoveFromCurrentAmount(sumOfPayments); TicketPayment.DeleteAll(selectedTicket.PrimaryKey); TicketRefund.Add(selectedTicket.PrimaryKey, SessionManager.ActiveEmployee.Id, RegisterManager.ActiveRegisterDrawer.Id, sumOfPayments, refundType); return(sumOfPayments); }
// Rule: This should not be called on a cashed-out ticket. A ticket needs to // be refunded before it can be voided. public static bool VoidTicketCommand(Ticket selectedTicket) { IEnumerable <TicketPayment> ticketPayments = TicketPayment.GetAll(selectedTicket.PrimaryKey); if (ticketPayments.Any()) { PosDialogWindow.ShowDialog( Types.Strings.YouCantVoidATicketThatIsCashedoutTheTicketMustBeRefundedFirst, Types.Strings.VoidError); } else if (ConfirmVoidPrompt()) { VoidTicket(selectedTicket); return(true); } return(false); }
private void Button_Click(object sender, RoutedEventArgs e) { if (numberEntryControl.FloatValue != null) { double amount = numberEntryControl.FloatValue.Value; if (amount > 0) { PaymentSource type = GetPaymentType(sender); double sum = GetTotalPayments(TicketPayment.GetAll(SelectedTicket.PrimaryKey)); double total = GetTicketTotal(); double due = total - sum; double actualAmount = amount; if (amount > due) { amount = due; } TicketPayment.Add(SelectedTicket.PrimaryKey, RegisterManager.ActiveRegisterDrawer.Id, SessionManager.ActiveEmployee.Id, amount, type); InitializeTicket(); if (IsTicketPayed) { double amountPaid = sum + actualAmount; double change = actualAmount - amount; labelAmountPayed.Content = amountPaid.ToString("C2"); labelAmountDueLabel.Content = Types.Strings.ChangeDue; labelAmountDue.Content = change.ToString("C2"); RegisterManager.ActiveRegisterDrawer.AddToCurrentAmount(total); SelectedTicket.SetCloseTime(DateTime.Now); SelectedTicket.Update(); RegisterManager.OpenCashDrawer(); } } numberEntryControl.FloatValue = null; } }