/// <summary> /// Creator: Jaeho Kim /// Created: 03/25/2020 /// Approver: Rasha Mohammed /// /// Completes the transaction and performs the transaction entry operation. /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <param name="e"></param> /// <param name="sender"></param> private void btnCompleteTransaction_Click(object sender, RoutedEventArgs e) { var transactionType = new TransactionType(); var transactionStatus = new TransactionStatus(); // This transactionDate operation // involves ignoring Milliseconds. // Seconds do count however! DateTime transactionDate = DateTime.Now; transactionDate = new DateTime( transactionDate.Ticks - (transactionDate.Ticks % TimeSpan.TicksPerSecond), transactionDate.Kind ); // end transactionDate ignore milliseconds operation. var transaction = new Transaction(); try { // This is for practical purposes. A cashier should not have to // constantly put in the transaction type for each transaction. // A default transaction type is retrieved from the database // everytime the transaction type text is empty. if (cbTransactionType.Text == "") { transactionType = _transactionManager.RetrieveDefaultTransactionType(); cbTransactionType.Text = transactionType.TransactionTypeID; } if (cbTransactionStatus.Text == "") { transactionStatus = _transactionManager.RetrieveDefaultTransactionStatus(); cbTransactionStatus.Text = transactionStatus.TransactionStatusID; } // if the transaction type was return or void, the values for item quantity // and total calculations must be negative. if (cbTransactionType.Text == "return") { subTotalTaxable *= -1; subTotal *= -1; total *= -1; } if (cbTransactionType.Text == "void") { subTotalTaxable *= -1; subTotal *= -1; total *= -1; } transaction.TransactionDateTime = transactionDate; transaction.TaxRate = taxRate; transaction.SubTotalTaxable = subTotalTaxable; transaction.SubTotal = subTotal; transaction.Total = total; transaction.TransactionTypeID = cbTransactionType.Text.ToString(); transaction.EmployeeID = employeeID; transaction.TransactionStatusID = cbTransactionStatus.Text.ToString(); transaction.TaxExemptNumber = txtTaxExemptNumber.Text.ToString(); transaction.CustomerEmail = txtEmail.Text.ToString(); } catch (Exception ex) { MessageBox.Show(ex.Message + "\n\n" + "Please set the default transaction type or status!"); } var transactionLineProducts = new TransactionLineProducts(); List <ProductVM> ProductsSoldList = new List <ProductVM>(); foreach (var item in _transactionManager.GetAllProducts()) { // return transaction type! if (cbTransactionType.Text == "return") { item.Quantity *= -1; } // return transaction type! if (cbTransactionType.Text == "void") { item.Quantity *= -1; } ProductsSoldList.Add(item); } transactionLineProducts.ProductsSold = ProductsSoldList; try { // Creating the transaction in the database if (transaction.SubTotal != 0) { if (collectPayment(transaction)) { _transactionManager.AddTransaction(transaction); _transactionManager.AddTransactionLineProducts(transactionLineProducts); _transactionManager.EditItemQuantity(transactionLineProducts); txtSearchProduct.Text = ""; txtItemName.Text = ""; chkTaxable.IsChecked = false; txtPrice.Text = ""; txtQuantity.Text = ""; txtItemDescription.Text = ""; cbTransactionType.Text = ""; cbTransactionStatus.Text = ""; txtTaxExemptNumber.Text = ""; txtEmail.Clear(); txtTotal.Text = ""; txtSubTotal.Text = ""; txtSubTotalTaxable.Text = ""; dgShoppingCart.ItemsSource = null; subTotalTaxable = 0.0M; subTotal = 0.0M; total = 0.0M; _transactionManager.ClearShoppingCart(); btnAddProduct.Visibility = Visibility.Hidden; MessageBox.Show("Transaction Complete", "Success", MessageBoxButton.OK, MessageBoxImage.Information); } else { WPFErrorHandler.ErrorMessage("Payment Processing incomplete."); } } else { MessageBox.Show("Could Not Add Transaction!"); } } catch (ApplicationException ae) { MessageBox.Show(ae.Message + "\n\n" + "You Must Enter Transaction Admin Data!"); } }
public ViewResult Thanks(Cart cart, CompleteCheckoutViewModel completeCheckoutViewModel, string stripeChargeID) { if (cart != null && completeCheckoutViewModel != null) { decimal subTotalTaxFree = 0.0M; decimal subTotalTaxable = 0.0M; var productAmounts = new Dictionary <DataTransferObjects.Product, int>(); var productsSold = new List <ProductVM>(); foreach (var line in cart.Lines) { productAmounts.Add(line.Product, line.Amount); productsSold.Add(new ProductVM { Name = line.Product.Name, ItemName = line.Product.Name, Active = line.Product.Active, Brand = line.Product.Brand, Category = line.Product.Category, Description = line.Product.Description, ItemDescription = line.Product.Description, ItemID = line.Product.ItemID, Quantity = line.Amount, ItemQuantity = line.Amount, Price = line.Product.Price, ProductID = line.Product.ProductID, Taxable = line.Product.Taxable, Type = line.Product.Type }); if (!line.Product.Taxable) { subTotalTaxFree += line.Product.Price * line.Amount; } else { subTotalTaxable += line.Product.Price * line.Amount; } } decimal subTotalWithTax = subTotalTaxable * (1 + completeCheckoutViewModel.OrderDetails.TaxRate); subTotalTaxable += subTotalTaxFree; var transaction = new Transaction { CustomerEmail = completeCheckoutViewModel.OrderDetails.Email, StripeChargeID = stripeChargeID, EmployeeID = 100000, // Admin account user id SubTotal = subTotalTaxFree, SubTotalTaxable = subTotalTaxable, TaxRate = completeCheckoutViewModel.OrderDetails.TaxRate, TransactionDateTime = DateTime.Now, TransactionStatusID = "Completed", TransactionTypeID = "Online Sale", Total = subTotalWithTax + subTotalTaxFree, ProductAmounts = productAmounts }; _transactionManager.AddTransaction(transaction); var lineProducts = new TransactionLineProducts { ProductsSold = productsSold }; _transactionManager.AddTransactionLineProducts(lineProducts); } cart.Clear(); _transactionManager = new TransactionManager(); return(View()); }