public void TestEditItemQuantity() { // arrange, the attribute that need ITransactionManager transactionManager = new TransactionManager(_transactionAccessor); bool result = false; bool expected = true; TransactionLineProducts transactionLineProducts = new TransactionLineProducts(); List <ProductVM> _productsSold = new List <ProductVM>(); var productVM1 = new ProductVM(); productVM1.ItemID = 100; productVM1.ItemQuantity = 5; var productVM2 = new ProductVM(); productVM2.ItemID = 200; productVM2.ItemQuantity = 10; _productsSold.Add(productVM1); _productsSold.Add(productVM2); transactionLineProducts.ProductsSold = _productsSold; //act result = _transactionManager.EditItemQuantity(transactionLineProducts); // Assert Assert.AreEqual(expected, result); }
/// <summary> /// Creator: Jaeho Kim /// Created: 2020/04/24 /// Approver: Robert Holmes /// /// This method calls the update item quantity method in the DataAccessLayer. /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <returns>TransactionStatus</returns> public bool EditItemQuantity(TransactionLineProducts transactionLineProducts) { bool result = false; try { result = (_transactionAccessor.UpdateItemQuantity(transactionLineProducts) > 0); } catch (Exception ex) { throw new ApplicationException("Could Not Add Transaction.", ex); } return(result); }
/// <summary> /// Creator: Jaeho Kim /// Created: 04/04/2020 /// Approver: Rasha Mohammed /// /// Implementation of AddTransactionLineProducts method. /// Adds the transaction. /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <returns>bool</returns> public bool AddTransactionLineProducts(TransactionLineProducts transactionLineProducts) { bool result = false; try { result = (_transactionAccessor.InsertTransactionLineProducts(transactionLineProducts) > 0); } catch (Exception ex) { throw new ApplicationException("Could Not Add Transaction.", ex); } return(result); }
/// <summary> /// Creator: Jaeho Kim /// Created: 4/04/2020 /// Approver: Rasha Mohammed /// /// Method to test insert products related to transaction /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// </remarks> /// <param name="transactionLineProducts">The products related to the transaction</param> public int InsertTransactionLineProducts(TransactionLineProducts transactionLineProducts) { int result = 0; FakeTransactionAccessor fakeTransactionAccessor = new FakeTransactionAccessor(); List <TransactionLineProducts> transactionLineProductsList = fakeTransactionAccessor.SelectAllTransactionLineProducts(); if (!transactionLineProductsList.Contains(transactionLineProducts)) { transactionLineProductsList.Add(transactionLineProducts); result = 1; } return(result); }
public void TestAddTransactionLineProducts() { bool result = false; TransactionLineProducts newTransactionLineProducts = new TransactionLineProducts() { TransactionID = 100002 }; FakeTransactionAccessor _transactionAccessor = new FakeTransactionAccessor(); result = _transactionAccessor.InsertTransactionLineProducts(newTransactionLineProducts) == 1; Assert.AreEqual(result, true); }
/// <summary> /// Creator: Jaeho Kim /// Created: 2020/04/25 /// Approver: Robert Holmes /// /// Fake Transaction Accessor Method, uses dummy data for testing. /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// </remarks> /// <returns>int</returns> public int UpdateItemQuantity(TransactionLineProducts transactionLineProducts) { int rows = 0; foreach (Item item in itemList) { foreach (ProductVM productVM in transactionLineProducts.ProductsSold) { if (productVM.ItemID == item.ItemID) { int newQuantity = item.ItemQuantity - productVM.ItemQuantity; item.ItemQuantity = newQuantity; rows++; } } } return(rows); }
/// <summary> /// Creator: Jaeho Kim /// Created: 04/04/2020 /// Approver: Rasha Mohammed /// /// Implementation for inserting a products related to the transaction. /// </summary> /// <remarks> /// Updater: Robert Holmes /// Updated: 4/20/2020 /// Update: Now actually saves the quantity purchased to the database. /// </remarks> /// <param name="transactionLineProducts"> /// The products related to the transaction that is inserted to the database. /// </param> /// <returns>rows effected</returns> public int InsertTransactionLineProducts(TransactionLineProducts transactionLineProducts) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_insert_transaction_line_products", conn); cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); foreach (var item in transactionLineProducts.ProductsSold) { cmd.Parameters.Clear(); cmd.Parameters.Add(new SqlParameter("@TransactionID", SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.NVarChar)); cmd.Parameters.Add(new SqlParameter("@Quantity", SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@PriceSold", SqlDbType.Decimal)); cmd.Parameters[0].Value = TransactionID; cmd.Parameters[1].Value = item.ProductID; // This is the item quantity that got purchased. cmd.Parameters[2].Value = item.Quantity; // This is the price that is sold for this transaction. cmd.Parameters[3].Value = item.Price; rows = cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <summary> /// Creator: Jaeho Kim /// Created: 4/25/2020 /// Approver: Robert Holmes /// /// Implementation for adjusting item quantity /// /// </summary> /// <remarks> /// Updater: NA /// Updated: NA /// Update: NA /// </remarks> /// <returns>int</returns> public int UpdateItemQuantity(TransactionLineProducts transactionLineProducts) { int rows = 0; var conn = DBConnection.GetConnection(); var cmd = new SqlCommand("sp_update_item_quantity", conn); cmd.CommandType = CommandType.StoredProcedure; try { conn.Open(); foreach (var item in transactionLineProducts.ProductsSold) { cmd.Parameters.Clear(); cmd.Parameters.Add(new SqlParameter("@TransactionID", SqlDbType.Int)); cmd.Parameters.Add(new SqlParameter("@ProductID", SqlDbType.NVarChar)); cmd.Parameters[0].Value = TransactionID; cmd.Parameters[1].Value = item.ProductID; rows = cmd.ExecuteNonQuery(); } } catch (Exception ex) { throw ex; } finally { conn.Close(); } return(rows); }
/// <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()); }