/* * this will update the value of column Supervisor_approval in Reports table * with value "APRROVED" */ public bool Approve(int reportId) { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.UpdateSupApprove(UserId, reportId); return true; }
/* * This will calulate total expenses in this current month. * Expenses approved by both accounts staff and supervisor * OR expenses approved by supervisor and not rejected by accounts staff(still processing) */ public void CalculateExpenses() { DateTime today = DateTime.Today; string startOfMonth = new DateTime(today.Year, today.Month, 1).ToString("yyyy-MM-dd"); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillByDeptExpenses(reportsTable, Department, startOfMonth); foreach (Reports.ReportsRow row in reportsTable) { Expenses += row.Total_amount; } BudgetRemained = MonthlyBudget - Expenses; }
public void AddReport_ApprovedBySupAndApprovedByAcc_GetReportStatus() { DateTime date = DateTime.Now.Date; string reportName = "REPORT"; string location = "Broadway"; string description = "food"; string strAmount = "100.1111"; double amount = Math.Round(100.1111, 2); double amount_aud = 148.16; string currency = "Euros"; byte[] receipt = new byte[] { 2, 3, 4, 2 }; int reportId = GetCurrentRowOfReportsTable() + 1; int expenseId = GetCurrentRowOfExpensesTable() + 1; Consultant consultant = new Consultant("con_he5"); Supervisor supervisor = new Supervisor("sup_he1"); AccountsStaff accountsStaff = new AccountsStaff("acc1"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { consultant.CreateExpense(date, location, description, strAmount, currency, receipt); consultant.AddExpenses(reportId); consultant.AddReport(reportName); supervisor.Approve(reportId); accountsStaff.Approve(reportId); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual(reportId, report.Id); Assert.AreEqual(reportName, report.Report_name); Assert.AreEqual(amount, report.Total_amount); Assert.AreEqual("APPROVED", report.Supervisor_approval); Assert.AreEqual("APPROVED", report.Accounts_approval); Assert.AreEqual(consultant.Department, report.Department); Assert.AreEqual(consultant.Username, report.Consultant_id); Assert.AreEqual("NONE", report.Supervisor_id); } testTransaction.Dispose(); // rollback } }
/* * This method will be called when a consultant click submit report button. * This will insert values into Reports table in DB. * And retreive reportId from the Reports table and call AddExpenses method * with reportId to make all expenses in a report have the same reportId */ public void AddReport(string reportName) { int reportId = 0; ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.Fill(reportsTable); adapter.Insert(reportName, 0, "PROCESSING", "PROCESSING", Department, UserId, "NONE", DateTime.Now.Date); adapter.FillByReportName(reportsTable, reportName); foreach (Reports.ReportsRow report in reportsTable) { reportId = report.Id; } AddExpenses(reportId); //After saving all data, reset list of expense Expenses = new List<Expense>(); }
public void AddReport_ApprovedBySupAndRejectedByAcc_GetReportStatus() { DateTime date = DateTime.Now.Date; string reportName = "REPORT"; string location = "Department Store"; string description = "computer"; string strAmount = "1000.567"; double amount = Math.Round(1000.567, 2); byte[] receipt = new byte[] { 2, 3, 4, 2 }; int reportId = GetCurrentRowOfReportsTable() + 1; int expenseId = GetCurrentRowOfExpensesTable() + 1; Consultant consultant = new Consultant("41651a9d-3122-4ea2-bfe0-dca38d7248d1"); Supervisor supervisor = new Supervisor("c252413a-1f6c-4086-b35f-1e430f7d7a14"); AccountsStaff accountsStaff = new AccountsStaff("f447b9f3-6733-42aa-b1c5-05a8b4451ca7"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { consultant.CreateExpense(date, location, description, strAmount, "AUD", receipt); consultant.AddExpenses(reportId); consultant.AddReport(reportName); supervisor.Approve(reportId); accountsStaff.Reject(reportId); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual(reportId, report.Id); Assert.AreEqual(reportName, report.Report_name); Assert.AreEqual(amount, report.Total_amount); Assert.AreEqual("APPROVED", report.Supervisor_approval); Assert.AreEqual("REJECTED", report.Accounts_approval); Assert.AreEqual(consultant.Department, report.Department); Assert.AreEqual(consultant.Username, report.Consultant_id); Assert.AreEqual("NONE", report.Supervisor_id); } testTransaction.Dispose(); // rollback } }
private int GetCurrentRowOfReportsTable() { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.Fill(reportsTable); int lastId = 0; foreach (Reports.ReportsRow report in reportsTable) { lastId = report.Id; } return lastId; }
public void GetReports_SubmitedBySeveralUserInSameDepartment_DisplayedBySupervisor() { Consultant con1 = new Consultant("715b8401-6be0-4a63-9376-267909e79200"); Consultant con2 = new Consultant("089e814b-2315-4cfc-9316-85d2a495bd96"); Consultant con3 = new Consultant("6cb4e17b-f8d9-469a-84a7-424ac788afac"); Supervisor sup = new Supervisor("ff53c7ba-170f-47b3-9bd3-1a64287d157c"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { con1.CreateExpense(DateTime.Now, "", "", "", "", null); con1.AddExpenses(GetCurrentRowOfExpensesTable() + 1); con1.AddReport("con1"); con2.CreateExpense(DateTime.Now, "", "", "", "", null); con2.AddExpenses(GetCurrentRowOfExpensesTable() + 1); con2.AddReport("con2"); con3.CreateExpense(DateTime.Now, "", "", "", "", null); con3.AddExpenses(GetCurrentRowOfExpensesTable() + 1); con3.AddReport("con3"); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = sup.GetReports(0); int counter = 1; foreach (Reports.ReportsRow report in reportsTable) { if (counter == 1) { Assert.AreEqual("con1", report.Report_name); Assert.AreEqual("715b8401-6be0-4a63-9376-267909e79200", report.Consultant_id); } else if (counter == 2) { Assert.AreEqual("con2", report.Report_name); Assert.AreEqual("089e814b-2315-4cfc-9316-85d2a495bd96", report.Consultant_id); } else { Assert.AreEqual("con3", report.Report_name); Assert.AreEqual("6cb4e17b-f8d9-469a-84a7-424ac788afac", report.Consultant_id); } counter++; } testTransaction.Dispose(); // rollback } }
public void GetReports_SubmitedByConsultantInDifferentDepartment_DisplayedBySupervisorInSameDepartment() { Consultant con_s1 = new Consultant("ce65a8ac-728b-405e-a00d-4a14e6ad23dc"); Consultant con_l1 = new Consultant("715b8401-6be0-4a63-9376-267909e79200"); Consultant con_he1 = new Consultant("4a4de22e-cd4f-4031-b0c1-126c3409dda3"); Supervisor sup_s1 = new Supervisor("1b52538c-ee54-425b-a3bc-e1b5cab1fdd3"); Supervisor sup_l1 = new Supervisor("ff53c7ba-170f-47b3-9bd3-1a64287d157c"); Supervisor sup_he1 = new Supervisor("c252413a-1f6c-4086-b35f-1e430f7d7a14"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { con_s1.CreateExpense(DateTime.Now, "", "", "", "", null); con_s1.AddExpenses(GetCurrentRowOfExpensesTable() + 1); con_s1.AddReport("con_s1"); con_l1.CreateExpense(DateTime.Now, "", "", "", "", null); con_l1.AddExpenses(GetCurrentRowOfExpensesTable() + 1); con_l1.AddReport("con_l1"); con_he1.CreateExpense(DateTime.Now, "", "", "", "", null); con_he1.AddExpenses(GetCurrentRowOfExpensesTable() + 1); con_he1.AddReport("con_he1"); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = sup_s1.GetReports(0); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual("con_s1", report.Report_name); Assert.AreEqual("ce65a8ac-728b-405e-a00d-4a14e6ad23dc", report.Consultant_id); } adapter = new ReportsTableAdapter(); reportsTable = sup_l1.GetReports(0); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual("con_l1", report.Report_name); Assert.AreEqual("715b8401-6be0-4a63-9376-267909e79200", report.Consultant_id); } adapter = new ReportsTableAdapter(); reportsTable = sup_he1.GetReports(0); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual("con_he1", report.Report_name); Assert.AreEqual("4a4de22e-cd4f-4031-b0c1-126c3409dda3", report.Consultant_id); } testTransaction.Dispose(); // rollback } }
public void CalcaluateExpences_ExpensesNotChanged() { int reportId = GetCurrentRowOfReportsTable() + 1; Consultant con_s1 = new Consultant("ce65a8ac-728b-405e-a00d-4a14e6ad23dc"); Supervisor sup_s1 = new Supervisor("1b52538c-ee54-425b-a3bc-e1b5cab1fdd3"); AccountsStaff acc1 = new AccountsStaff("f447b9f3-6733-42aa-b1c5-05a8b4451ca7"); sup_s1.CalculateExpenses(); double currentExpenses = sup_s1.Expenses; double currentBudgetRemained = sup_s1.BudgetRemained; sup_s1.ResetBudget(); using (TransactionScope testTransaction = new TransactionScope()) { con_s1.CreateExpense(DateTime.Now.Date, "sd", "first", "1000", "AUD", null); con_s1.AddReport("new report"); con_s1.AddExpenses(reportId); ReportsTableAdapter adapter2 = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter2.FillById(reportsTable, reportId); sup_s1.CalculateExpenses(); Assert.AreEqual(currentExpenses, sup_s1.Expenses); sup_s1.ResetBudget(); testTransaction.Dispose(); // rollback } }
/* * This will update the value of the colume Total_amount in Reports table */ private void UpdateReportTotalAmount(int reportId, double totalExpenses) { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.UpdateTotalAmount(totalExpenses, reportId); }
/* * this will update the value of column Accounts_approval in Reports table * with value "REJECTED" */ public bool Reject(int reportId) { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.UpdateAccReject(reportId); return true; }
public void AddReport_GivenValidExpense_AddsReportAndExpenseToDB2() { DateTime date = DateTime.Now.Date; string reportName = "REPORT"; string location = "Broadway"; string description = "food"; string strAmount = "100.1111"; double amount = Math.Round(100.1111, 2); double amount_aud = 148.16; string currency = "Euros"; byte[] receipt = new byte[] { 2, 3, 4, 2 }; int reportId = GetCurrentRowOfReportsTable() + 1; int expenseId = GetCurrentRowOfExpensesTable() + 1; Consultant consultant = new Consultant("41651a9d-3122-4ea2-bfe0-dca38d7248d1"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { consultant.CreateExpense(date, location, description, strAmount, currency, receipt); consultant.AddExpenses(reportId); consultant.AddReport(reportName); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual(reportId, report.Id); Assert.AreEqual(reportName, report.Report_name); Assert.AreEqual(amount, report.Total_amount); Assert.AreEqual("PROCESSING", report.Supervisor_approval); Assert.AreEqual("PROCESSING", report.Accounts_approval); Assert.AreEqual(consultant.Department, report.Department); Assert.AreEqual(consultant.Username, report.Consultant_id); Assert.AreEqual("NONE", report.Supervisor_id); } ExpensesTableAdapter adapter2 = new ExpensesTableAdapter(); Reports.ExpensesDataTable expensesTable = new Reports.ExpensesDataTable(); adapter2.FillByReportId(expensesTable, reportId); foreach (Reports.ExpensesRow expense in expensesTable) { Assert.AreEqual(date, expense.Date); Assert.AreEqual(location, expense.Location); Assert.AreEqual(description, expense.Description); Assert.AreEqual(amount, expense.Amount); Assert.AreEqual(currency, expense.Currency); Assert.AreEqual(amount_aud, expense.Amount_aud); } testTransaction.Dispose(); // rollback } }
public void AddReport_GivenValidExpense_AddsReportAndExpenseToDB() { DateTime date = DateTime.Now.Date; string reportName = "report"; string location = "AA"; string description = "BB"; string strAmount = "100"; double amount = Math.Round(100.000, 2); string currency = "AUD"; byte[] receipt = new byte[] { 1, 2, 3, 4 }; int reportId = GetCurrentRowOfReportsTable() + 1; int expenseId = GetCurrentRowOfExpensesTable() + 1; Consultant consultant = new Consultant("ce65a8ac-728b-405e-a00d-4a14e6ad23dc"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { consultant.CreateExpense(date, location, description, strAmount, currency, receipt); consultant.AddExpenses(reportId); consultant.AddReport(reportName); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual(reportId, report.Id); Assert.AreEqual(reportName, report.Report_name); Assert.AreEqual(amount, report.Total_amount); Assert.AreEqual("PROCESSING", report.Supervisor_approval); Assert.AreEqual("PROCESSING", report.Accounts_approval); Assert.AreEqual(consultant.Department, report.Department); Assert.AreEqual("ce65a8ac-728b-405e-a00d-4a14e6ad23dc", report.Consultant_id); Assert.AreEqual("NONE", report.Supervisor_id); } ExpensesTableAdapter adapter2 = new ExpensesTableAdapter(); Reports.ExpensesDataTable expensesTable = new Reports.ExpensesDataTable(); adapter2.FillByReportId(expensesTable, reportId); foreach (Reports.ExpensesRow expense in expensesTable) { Assert.AreEqual(date, expense.Date); Assert.AreEqual(location, expense.Location); Assert.AreEqual(description, expense.Description); Assert.AreEqual(amount, expense.Amount); Assert.AreEqual(currency, expense.Currency); Assert.AreEqual(amount, expense.Amount_aud); } testTransaction.Dispose(); // rollback } }
/* * This will determine that expenses of a report will make company over budget or not * over budet = true, no = false */ public bool IsOverBudget(int reportId) { CalculateExpenses(); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); Reports.ReportsRow row = (Reports.ReportsRow)reportsTable.Rows[0]; if (row.Total_amount > BudgetRemained) { ResetBudget(); return true; } ResetBudget(); return false; }
/* * Supervisors display all reports of their department, the reports rejected by * accounts staff. This method will return the value as ReportsDataTable. * So that this object will be binded with GridView in UI project. */ public override Reports.ReportsDataTable GetReports(int type) { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); switch (type) { case 1: adapter.FillByDepartment(reportsTable, Department); break; case 2: adapter.FillByRejected(reportsTable, Department); break; } return reportsTable; }
/* * Supervisors display reports approved by supervisors. * This method will return the value as ReportsDataTable. * So that this object will be binded with GridView in UI project. */ public override Reports.ReportsDataTable GetReports(int type) { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillByAccounts(reportsTable); return reportsTable; }
/* * This will determine that a specific report is already approved/rejected by accounts staff or not * approved/rejected = false * still processing = ture */ public bool IsProcessing(int reportId) { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); Reports.ReportsRow row = (Reports.ReportsRow)reportsTable.Rows[0]; if (row.Accounts_approval.Equals("PROCESSING")) return true; else return false; }
public void AddReport_HavingMultipleExpenses_AddsReportAndExpenseToDB() { string strAmount = "100.1111"; double amount_aud = 100.11; string strAmount2 = "50.222"; double amount_aud2 = 74.33; string strAmount3 = "99"; double amount_aud3 = 16.83; int reportId = GetCurrentRowOfReportsTable() + 1; int expenseId = GetCurrentRowOfExpensesTable() + 1; Consultant consultant = new Consultant("6cb4e17b-f8d9-469a-84a7-424ac788afac"); // start transaction using (TransactionScope testTransaction = new TransactionScope()) { consultant.CreateExpense(DateTime.Now, "", "", strAmount, "AUD", null); consultant.CreateExpense(DateTime.Now, "", "", strAmount2, "Euros", null); consultant.CreateExpense(DateTime.Now, "", "", strAmount3, "CNY", null); consultant.AddExpenses(reportId); consultant.AddReport(""); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); adapter.FillById(reportsTable, reportId); foreach (Reports.ReportsRow report in reportsTable) { Assert.AreEqual(amount_aud + amount_aud2 + amount_aud3, report.Total_amount); } testTransaction.Dispose(); // rollback } }
/* * This will calulate total expenses and remained budget of each department. * the espenses are those approved by both supervisor and accounts staff */ private void CalculateDeptExpenses(string department) { DateTime today = DateTime.Today; string startOfMonth = new DateTime(today.Year, today.Month, 1).ToString(); ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); switch (department) { case "State Services": adapter.FillByExpensesBothApproved(reportsTable, department, startOfMonth); foreach (Reports.ReportsRow row in reportsTable) { StateExpenses += row.Total_amount; } StateBudgetRemained = DeptBudget - StateExpenses; break; case "Logistics Services": adapter.FillByExpensesBothApproved(reportsTable, department, startOfMonth); foreach (Reports.ReportsRow row in reportsTable) { LogisticsExpenses += row.Total_amount; } LogisticsBudgetRemained = DeptBudget - LogisticsExpenses; break; case "Higher Education Services": adapter.FillByExpensesBothApproved(reportsTable, department, startOfMonth); foreach (Reports.ReportsRow row in reportsTable) { HigherEducationExpenses += row.Total_amount; } HigherEducationBudgetRemained = DeptBudget - HigherEducationExpenses; break; } }
/* * Consultants display all reports, approved reports and reports that is waiting * for approval. This method will return the value as ReportsDataTable. * So that this object will be binded with GridView in UI project. */ public override Reports.ReportsDataTable GetReports(int type) { ReportsTableAdapter adapter = new ReportsTableAdapter(); Reports.ReportsDataTable reportsTable = new Reports.ReportsDataTable(); switch (type) { //for all reports written by the consultant case 1: adapter.FillByUsername(reportsTable, UserId); break; //for approved reports written by the consultant case 2: adapter.FillByApproval(reportsTable, UserId); break; //for reports waiting for approval case 3: adapter.FillByNotApproval(reportsTable, UserId); break; } return reportsTable; }