//add items to the expense report
        protected void btnAddItem_Click(object sender, EventArgs e)
        {
            ExpenseItem expenseItem = new ExpenseItem();
            FileUploader fileUploader = new FileUploader();

            expenseItem.ExpenseDate = Convert.ToDateTime(txtItemDate.Text);
            expenseItem.Location = txtItemLocation.Text;
            expenseItem.Description = txtItemDescription.Text;
            expenseItem.Amount = Convert.ToDecimal(txtItemAmount.Text);
            expenseItem.Currency = ddlItemCurrency.SelectedValue;
            expenseItem.AudAmount = CurrencyConverter.ConvertToAUD(expenseItem.Currency, expenseItem.Amount);
            expenseItem.ReceiptFileName = fileUploader.Upload(fileReceipt);

            reportBuilder.AddExpenseItem(expenseItem);

            Session["expenseReportBuilder"] = reportBuilder;

            gvExpenseItems.DataSource = reportBuilder.expenseReport.ExpenseItems;
            gvExpenseItems.DataBind();

            ClearItemForm();
        }
        /// <summary>
        /// Private method to get the individual expense items for a expense report
        /// </summary>
        /// <param name="expenseid">Expense Header Id</param>
        /// <param name="expenseTotal">output the total of the expense report</param>
        /// <returns>Expense items</returns>
        private List<ExpenseItem> GetExpenseItemsByExpenseId(int expenseid, out decimal expenseTotal)
        {
            expenseTotal = 0;

            List<ExpenseItem> expenseItems = new List<ExpenseItem>();

            DataAccessFunctions daFunctions = new DataAccessFunctions();

            string query = String.Format("SELECT * FROM ExpenseItem WHERE ExpenseHeaderId={0}", expenseid);

            try
            {
                daFunctions.Connection.Open();
                daFunctions.Command.CommandText = query;
                SqlDataReader rdr = daFunctions.Command.ExecuteReader();

                while (rdr.Read())
                {
                    ExpenseItem item = new ExpenseItem();

                    item.ExpenseHeaderId = rdr["ExpenseHeaderId"] as int? ?? default(int);
                    item.ItemId = rdr["ItemId"] as int? ?? default(int);
                    item.ExpenseDate = (DateTime)rdr["ExpenseDate"];
                    item.Location = (string)rdr["Location"];
                    item.Description = (string)rdr["Description"];
                    item.Currency = (string)rdr["Currency"];
                    item.Amount = rdr["Amount"] as decimal? ?? default(decimal);
                    item.AudAmount = rdr["AudAmount"] as decimal? ?? default(decimal);
                    item.ReceiptFileName = (string)rdr["ReceiptFileName"];

                    expenseTotal += item.AudAmount;
                    expenseItems.Add(item);
                }
            }
            catch (Exception ex)
            {
                throw new Exception("There was a problem retrieving expense items for expenseid: " + expenseid + ": " + ex.Message);
            }
            finally
            {
                daFunctions.Connection.Close();
            }
            return expenseItems;
        }
 public void ExpenseReportDAL_SupervisorActionOnExpenseReport_Reject_ActionSuccess()
 {
     using (TransactionScope testTransaction = new TransactionScope())
     {
         ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();
         ExpenseReport expenseReport = new ExpenseReport();
         ExpenseItem item = new ExpenseItem();
         expenseReport.CreateDate = DateTime.Now;
         expenseReport.CreatedBy.UserId = new Guid("18b783f1-cb97-4e03-bb54-d3c41637b69c");
         expenseReport.CreatedBy.Dept.DepartmentId = 1;
         expenseReport.Status = ReportStatus.Submitted;
         item.ExpenseDate = DateTime.Now;
         item.Location = "London";
         item.Description = "AirTicket";
         item.Amount = 2000;
         item.Currency = "AUD";
         item.AudAmount = item.Amount;
         expenseReport.ExpenseItems.Add(item);
         string status = "RejectedBySupervisor";
         Guid approvedBy = new Guid("832e2e47-e82c-40be-9c39-8587274468fe");
         expenseReportDAL.ProcessExpense(expenseReport);
         Assert.IsTrue(CheckDatabaseForExpenseId(expenseReport.ExpenseId), "Expense Id was not found in database");
         expenseReportDAL.SupervisorActionOnExpenseReport(expenseReport.ExpenseId, approvedBy, status);
         testTransaction.Dispose();
      }
 }
        public void ExpenseReportDAL_ProcessExpense_InsertSuccess()
        {
            ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();

            ExpenseReport expenseReport = new ExpenseReport();
            ExpenseItem item = new ExpenseItem();

            expenseReport.CreateDate = DateTime.Now;
            expenseReport.CreatedBy.UserId = new Guid("78560DD3-F95E-4011-B40D-A7B56ED17F24");
            expenseReport.CreatedBy.Dept.DepartmentId = 2;
            expenseReport.Status = ReportStatus.Submitted;

            item.ExpenseDate = DateTime.Now;
            item.Location = "Sydney";
            item.Description = "AirTicket";
            item.Amount = 2000;
            item.Currency = "AUD";
            item.AudAmount = item.Amount;

            expenseReport.ExpenseItems.Add(item);

            using (TransactionScope testTransaction = new TransactionScope())
            {
                expenseReportDAL.ProcessExpense(expenseReport);
                Assert.IsTrue(CheckDatabaseForExpenseId(expenseReport.ExpenseId), "Expense Id was not found in database");
                testTransaction.Dispose();
            }
        }
 public void ExpenseReportDAL_GetReportBySupervisor_StatusIsSubmitted_IsTrue()
 {
     using (TransactionScope testTransaction = new TransactionScope())
     {
         ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();
         ExpenseReport expenseReport = new ExpenseReport();
         ExpenseItem item = new ExpenseItem();
         List<ExpenseReport> reports = new List<ExpenseReport>();
         int deptId = 1;
         string status = ReportStatus.Submitted.ToString();
         expenseReport.CreateDate = DateTime.Now;
         expenseReport.CreatedBy.UserId = new Guid("18b783f1-cb97-4e03-bb54-d3c41637b69c");
         expenseReport.ExpenseToDept.DepartmentId = 1;
         expenseReport.CreatedBy.Dept.DepartmentId = 1;
         expenseReport.Status = ReportStatus.Submitted;
         item.ExpenseDate = DateTime.Now;
         item.Location = "Sydney";
         item.Description = "AirTicket";
         item.Amount = 5000;
         item.Currency = "AUD";
         item.AudAmount = item.Amount;
         expenseReport.ExpenseItems.Add(item);
         expenseReportDAL.ProcessExpense(expenseReport);
         Assert.IsTrue(CheckDatabaseForExpenseId(expenseReport.ExpenseId), "Expense Id was not found in database");
         reports = expenseReportDAL.GetReportsByDepartment(deptId, status);
         Assert.IsTrue(reports.Count > 0, "No data in expense report");
         testTransaction.Dispose();
     }
 }
 public void ExpenseReportDAL_GetReportBySupervisor_StatusIsApprovedByAccounts_IsTrue()
 {
     using (TransactionScope testTransaction = new TransactionScope())
     {
         ExpenseReportDAL expenseReportDAL = new ExpenseReportDAL();
         ExpenseReport expenseReport = new ExpenseReport();
         ExpenseItem item = new ExpenseItem();
         List<ExpenseReport> reports = new List<ExpenseReport>();
         int deptId = 1;
         string status = ReportStatus.ApprovedByAccounts.ToString();
         expenseReport.CreateDate = DateTime.Now;
         expenseReport.CreatedBy.UserId = new Guid("78560dd3-f95e-4011-b40d-a7b56ed17f24");
         expenseReport.ExpenseToDept.DepartmentId = 1;
         expenseReport.CreatedBy.Dept.DepartmentId = 1;
         expenseReport.Status = ReportStatus.ApprovedByAccounts;
         item.ExpenseDate = DateTime.Now;
         item.Location = "Sydney";
         item.Description = "AirTicket";
         item.Amount = 5000;
         item.Currency = "AUD";
         item.AudAmount = item.Amount;
         expenseReport.ExpenseItems.Add(item);
         expenseReportDAL.ProcessExpense(expenseReport);
         reports = expenseReportDAL.GetReportsByDepartment(deptId, status);
         Assert.IsTrue(reports.Count > 0, "No data in expense report");
         testTransaction.Dispose();
     }
 }
 /// <summary>
 /// Adds expense items to expenseItems list in ExpenseReport
 /// </summary>
 /// <param name="item">expense item</param>
 public void AddExpenseItem(ExpenseItem item)
 {
     expenseReport.ExpenseItems.Add(item);
     expenseReport.ExpenseTotal += item.AudAmount;
 }