public void TestTimeCardTransaction() { int empId = 5; AddHourlyEmployee t = new AddHourlyEmployee(empId, "Bill", "Home", 15.25, database); t.Execute(); TimeCardTransaction tct = new TimeCardTransaction( new DateTime(2005, 7, 31), 8.0, empId, database); tct.Execute(); Employee e = database.GetEmployee(empId); Assert.IsNotNull(e); PaymentClassification pc = e.Classification; Assert.IsTrue(pc is HourlyClassification); HourlyClassification hc = pc as HourlyClassification; TimeCard tc = hc.GetTimeCard(new DateTime(2005, 7, 31)); Assert.IsNotNull(tc); Assert.AreEqual(8.0, tc.Hours); }
private double CalculatePayForTimeCard(TimeCard card) { double overtimeHours = Math.Max(0.0, card.Hours - 8); double normalHours = card.Hours - overtimeHours; return(hourlyRate * normalHours + hourlyRate * 1.5 * overtimeHours); }
// private void CalculateFinalGrossPay(object sender, EventArgs e) private void CalculateFinalGrossPay(DateTime month_date) { try{ if (month_date != null) { int fgp_month = month_date.Month; GenDoc gd = new GenDoc(); // TimeCard tc = new TimeCard(); DataTable dtGrossPay = new DataTable(); dtGrossPay = Utilities.DataBaseUtility.GetTable("Select * from emp_gross_calc where IntRef=" + emp_ID + "and Month =" + fgp_month); double finGross = 0.0; for (int i = 0; i < dtGrossPay.Rows.Count; i++) { // show Empl_ID : Firstname Lastname from Employees table finGross += Convert.ToDouble(dtGrossPay.Rows[i][10]); Console.WriteLine("The value of finGross" + i + "" + finGross); } Console.WriteLine("Displays the record for the emp_grossPay" + finGross); Gross_Pay gp = new Gross_Pay(finGross); gp.EmplId = Userid; //Calculating number of rows DataTable dtGrosscalc = new DataTable(); dtGrosscalc = Utilities.DataBaseUtility.GetTable("Select * from emp_gross_pay "); string gpc_LastRow = Convert.ToString(dtGrosscalc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("emp_gross_pay", 0, gpc_LastRow); //{0} gd.DocType = 32; gd.Status = 0; gp.DocRef = 0; gp.ExtRef = 0; DateTime start_date = new DateTime(month_date.Year, month_date.Month, 1); string sd_date = start_date.ToString(format); DateTime end_date = new DateTime(month_date.Year, month_date.Month, System.DateTime.DaysInMonth(System.DateTime.Now.Year, month_date.Month)); Console.WriteLine("last date of month for monthly gross pay " + end_date.ToString(format)); string ld_date = Convert.ToString(end_date.ToString(format)); TimeCard tc_date = new TimeCard(sd_date, ld_date); tc.PayStartDate = sd_date; tc.PayEndDate = ld_date; string gpPart1 = "INSERT into emp_gross_pay values ("; string gpPart2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,{6},'{7}','{8}','{9}'", gd.DocNum, gd.DocType, gp.EmplId, gp.ExtRef, gd.Status, gp.DocRef, finGross, tc.PayStartDate, tc.PayEndDate, gp.Comment); insert_Command = gpPart1 + gpPart2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); Console.WriteLine("gross pay in final GrossPay DocInsert was executed with output " + insert_Command); gd.ExternalRef = 0; // DataTable dtProcessDoc = new DataTable(); dtProcessDoc = Utilities.DataBaseUtility.GetTable("Select * from ProcessDocs "); prodoc_LastRow = Convert.ToString(dtProcessDoc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("ProcessDocs", 0, prodoc_LastRow); string pdPart1 = "INSERT into ProcessDocs values ("; string pdPart2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},'{10}'", gd.DocNum, gd.DocType, gp.EmplId, gd.ExternalRef, gd.Status, gd.ExternalRef, tc.PayStartDate, tc.PayEndDate, finGross,0, gp.Comment); insert_Command = pdPart1 + pdPart2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); Console.WriteLine("gross pay in Process DocInsert was executed with output " + insert_Command); Console.WriteLine("gross pay in processDoc was executed"); Console.WriteLine(" fin value" + finGross); } } catch(NullReferenceException ne) { throw new InvalidOperationException("a message"); } }
private void button1_Click(object sender, EventArgs e) { int totNormHrs =0 ; int.TryParse(totTextBox.Text, out totNormHrs); int totOtHrs = 0; int.TryParse(totTextBox.Text, out totOtHrs); if (totNormHrs > 40 || totOtHrs > 40) { MessageBox.Show("Invalid Number of hours Please enter correct Number of Hrs"); } if (totTextBox.Text.Equals("0") || totTextBox.Text.Equals("") || startDatePicker.Value.DayOfWeek != DayOfWeek.Monday || endDatePicker.Value.DayOfWeek != DayOfWeek.Sunday) { MessageBox.Show("Please fill in the Time Sheet"); } else if (MessageBox.Show("Are you sure to submit this time card", "Confirm Submit", MessageBoxButtons.YesNo) == DialogResult.Yes) { DataTable dtGrosscalc = new DataTable(); String emp_ID = base.ident.UserID.Trim(); int pg_hrly; int pg_sal; int pg_normRate; double pg_otRate; gd = new GenDoc(); DataTable dtEmp = new DataTable(); dtEmp = Utilities.DataBaseUtility.GetTable("Select * from emp_time_card "); string lastRow = Convert.ToString(dtEmp.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("emp_time_card", 0, lastRow); List<string> _emplPayGrade = Utilities.DataBaseUtility.GetList("select * from emp_pay_grade where IntRef = " + empId.Text); Console.WriteLine("The employee ID isss" + _emplPayGrade[1]); PayGrade pg = new PayGrade(_emplPayGrade[1]); gd.DocType = 34; int emplID = pg.EmplId; pg.ExtRef = 0; pg.TimeCardStatus = 0; pg.DocRef = 0; if (_emplPayGrade[1] != null) { tc = new TimeCard(textBox1.Text, textBox7.Text); pg_hrly = pg.HourlyBasis; pg_sal = pg.SalBasis; pg_normRate = pg.PayRate; pg_otRate = pg.OverTimeRate; Console.WriteLine("The employee ID hrly" + pg_hrly); Console.WriteLine("The employee ID sal" + pg_sal); Console.WriteLine("The employee ID hrly" + pg_normRate); Console.WriteLine("The employee ID sal" + pg.OverTimeRate); } string part1 = "INSERT into emp_time_card values ("; string part2 = String.Format("{0} ,{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},{10},'{11}'", gd.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, pg.TimeCardStatus, pg.DocRef, tc.PayStartDate, tc.PayEndDate, totalHours, totalOtHours, 0, pg.Comment); // 0 1 2 3 4 5 6 string insert_Command = part1 + part2 + ");"; Console.WriteLine("The Time card insert in emp_time_card" + insert_Command); Console.WriteLine(insert_Command); Utilities.DataBaseUtility.Execute(insert_Command, obj); Console.WriteLine("Time card Insert was executed"); dtProcessDoc = Utilities.DataBaseUtility.GetTable("Select * from ProcessDocs "); string prodoc_LastRow = Convert.ToString(dtProcessDoc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("ProcessDocs", 0, prodoc_LastRow); part1 = "INSERT into ProcessDocs values ("; part2 = String.Format("{0} ,{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},'{10}'", gd.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, pg.TimeCardStatus, pg.DocRef, tc.PayStartDate, tc.PayEndDate, totalHours, totalOtHours, pg.Comment); // 0 1 2 3 4 5 6 insert_Command = part1 + part2 + ");"; Console.WriteLine("Time card insert in ProcessDocs" + insert_Command); Utilities.DataBaseUtility.Execute(insert_Command, obj); Console.WriteLine("Time card Insert in Process Docs was executed"); // Calculating grosss pay if Gross Pay is for the same month time card int tempMonth = startDatePicker.Value.Month; int startDateMonth = startDatePicker.Value.Month; int endDateMonth = endDatePicker.Value.Month; if (startDateMonth == endDateMonth) { if (noOvertimeRadio.Checked == true) { grossPay += totalHours * pg.PayRate; Console.WriteLine("grossPay is" + grossPay); } if (after8Radiobtn.Checked == true) { grossPay += totalHours * pg.PayRate; grossPay += totalOtHours * (pg.PayRate * pg.OverTimeRate); Console.WriteLine("grossPay is" + grossPay); } if (after40Radiobtn.Checked == true) { grossPay = totalHours * pg.PayRate; grossPay += totalOtHours * (pg.PayRate * pg.OverTimeRate); Console.WriteLine("grossPay is" + grossPay); } Console.WriteLine("Start date month Value is " + startDatePicker.Value.Month); Gross_Pay gp = new Gross_Pay(grossPay); //same month Time Card gross pay calc gd.DocType = 33; pg.ExtRef = 0; gd.Status = 0; gd.ExternalRef = 0; tc = new TimeCard(textBox1.Text, textBox7.Text); gp.GrossPay = grossPay; gp.Month = Convert.ToString(startDatePicker.Value.Month); dtGrosscalc = Utilities.DataBaseUtility.GetTable("Select * from emp_gross_calc"); string gpc_LastRow = Convert.ToString(dtGrosscalc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("emp_gross_calc", 0, gpc_LastRow); cmd_Part1 = "INSERT into emp_gross_calc values ("; cmd_Part2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},{10},'{11}','{12}'", gd.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, gd.Status, gd.ExternalRef, tc.PayStartDate, tc.PayEndDate, totalHours, totalOtHours, gp.GrossPay, gp.Month, gp.Comment); // 0 1 2 3 4 5 6 insert_Command = cmd_Part1 + cmd_Part2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); Console.WriteLine("gross pay Insert was executed with output " + insert_Command); Console.WriteLine("gross pay Insert was executed"); //Insert of same month Gross pay in Process docs dtProcessDoc = Utilities.DataBaseUtility.GetTable("Select * from ProcessDocs "); prodoc_LastRow = Convert.ToString(dtProcessDoc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("ProcessDocs", 0, prodoc_LastRow); cmd_Part1 = "INSERT into ProcessDocs values ("; cmd_Part2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},'{10}'", gp.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, gd.Status, gd.ExternalRef, tc.PayStartDate, tc.PayEndDate, gp.GrossPay, gp.Month, gp.Comment); // 0 1 2 3 4 5 6 7 8 9 10 insert_Command = cmd_Part1 + cmd_Part2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); this.Close(); } // End of Calculating grosss pay if Gross Pay is for the same month time card //Different months in one Time Card calculation int firstPart = 0; int twoPart = 0; int firstPartOt = 0; int twoPartOt = 0; double firstPartGrossPay = 0.0; double secondPartGrossPay = 0.0; int year = startDatePicker.Value.Year; int month = startDatePicker.Value.Month; DateTime dt = new DateTime(year, month, System.DateTime.DaysInMonth(System.DateTime.Now.Year, month)); Console.WriteLine("last date of month" + dt.ToString(format)); string ld_date = Convert.ToString(dt.ToString(format)); if (startDateMonth != endDateMonth) { if (startDateMonth == startDatePicker.Value.Month) { firstPart = monValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { firstPartOt += monOtValue; } } if (startDateMonth == startDatePicker.Value.AddDays(1).Month) { firstPart += tueValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { firstPartOt += tueOtValue; } } if (startDateMonth == startDatePicker.Value.AddDays(2).Month) { firstPart += wedValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { firstPartOt += wedOtValue; } } if (startDateMonth == startDatePicker.Value.AddDays(3).Month) { firstPart += thuValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { firstPartOt += thuOtValue; } } if (startDateMonth == startDatePicker.Value.AddDays(4).Month) { firstPart += friValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { firstPartOt += friOtValue; } } if (startDateMonth == startDatePicker.Value.AddDays(5).Month) { firstPartOt = satOtValue; firstPart += satValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { firstPartOt += satOtValue; } } if (noOvertimeRadio.Checked == true) { firstPartGrossPay += firstPart * pg.PayRate; Console.WriteLine("The first part grossPay is" + firstPartGrossPay); } if (after8Radiobtn.Checked == true) { firstPartGrossPay += firstPart * pg.PayRate; firstPartGrossPay += firstPartOt * (pg.PayRate * pg.OverTimeRate); Console.WriteLine("The first part grossPay is" + firstPartGrossPay); } if (after40Radiobtn.Checked == true) { firstPartGrossPay = firstPart * pg.PayRate; firstPartGrossPay += firstPartOt * (pg.PayRate * pg.OverTimeRate); Console.WriteLine("The first part grossPay is" + grossPay); } Gross_Pay gp = new Gross_Pay(firstPartGrossPay); //Calculating number of rows dtGrosscalc = Utilities.DataBaseUtility.GetTable("Select * from emp_gross_calc "); string gpc_LastRow = Convert.ToString(dtGrosscalc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("emp_gross_calc", 0, gpc_LastRow); gd.DocType = 33; pg.ExtRef = 0; gd.Status = 0; gd.ExternalRef = 0; tc = new TimeCard(textBox1.Text, ld_date); tc.PayEndDate = ld_date; // Calcualate gross pay for the first part gp.GrossPay = firstPartGrossPay; gp.Month = Convert.ToString(startDatePicker.Value.Month); cmd_Part1 = "INSERT into emp_gross_calc values ("; cmd_Part2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},{10},'{11}','{12}'", gd.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, gd.Status, gd.ExternalRef, tc.PayStartDate, tc.PayEndDate, firstPart, firstPartOt, gp.GrossPay, gp.Month, gp.Comment); // 0 1 2 3 4 5 6 insert_Command = cmd_Part1 + cmd_Part2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); // Insert of First Part Gross Pay in Process docs dtProcessDoc = Utilities.DataBaseUtility.GetTable("Select * from ProcessDocs "); prodoc_LastRow = Convert.ToString(dtProcessDoc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("ProcessDocs", 0, prodoc_LastRow); cmd_Part1 = "INSERT into ProcessDocs values ("; cmd_Part2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},'{10}'", gp.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, gd.Status, gd.ExternalRef, tc.PayStartDate, tc.PayEndDate, gp.GrossPay, gp.Month, gp.Comment); // 0 1 2 3 4 5 6 7 8 9 10 insert_Command = cmd_Part1 + cmd_Part2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); Console.WriteLine("gross pay part 1 Insert was executed with output " + insert_Command); Console.WriteLine("gross pay part 1 Insert was executed"); if (endDateMonth == startDatePicker.Value.AddDays(1).Month) { twoPart += tueValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { twoPartOt += tueOtValue; } } if (endDateMonth == startDatePicker.Value.AddDays(2).Month) { twoPart += wedValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { twoPartOt += wedOtValue; } } if (endDateMonth == startDatePicker.Value.AddDays(3).Month) { twoPart += thuValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { twoPartOt += thuOtValue; } } if (endDateMonth == startDatePicker.Value.AddDays(4).Month) { twoPart += friValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { twoPartOt += friOtValue; } } if (endDateMonth == startDatePicker.Value.AddDays(5).Month) { twoPartOt += satValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { twoPartOt += satOtValue; } } if (endDateMonth == endDatePicker.Value.Month) { twoPartOt += sunValue; if (after8Radiobtn.Checked == true || after40Radiobtn.Checked == true) { twoPartOt += sunOtValue; } } Console.WriteLine("second part of normal hours" + twoPart); Console.WriteLine("second part of over time hours " + twoPartOt); if (noOvertimeRadio.Checked == true) { secondPartGrossPay += twoPart * pg.PayRate; Console.WriteLine("grossPay for second part is" + secondPartGrossPay); } if (after8Radiobtn.Checked == true) { secondPartGrossPay += twoPart * pg.PayRate; secondPartGrossPay += twoPartOt * (pg.PayRate * pg.OverTimeRate); Console.WriteLine("grossPay for second partis" + secondPartGrossPay); } if (after40Radiobtn.Checked == true) { secondPartGrossPay = twoPart * pg.PayRate; secondPartGrossPay += twoPartOt * (pg.PayRate * pg.OverTimeRate); Console.WriteLine("grossPay for second part is" + grossPay); } int sd_year = startDatePicker.Value.Year; int sd_month = endDatePicker.Value.Month; DateTime sd = new DateTime(year, month, 1); Console.WriteLine("start date of month" + sd.ToString(format)); string sd_date = sd.ToString(format); tc = new TimeCard(sd_date, textBox7.Text); tc.PayStartDate = sd.ToString(format); gd.DocType = 33; dtGrosscalc = Utilities.DataBaseUtility.GetTable("Select * from emp_gross_calc "); string gpc_LastRow_2 = Convert.ToString(dtGrosscalc.Rows.Count); gp.DocNum = Utilities.DataBaseUtility.GetNextNumber("emp_gross_calc", 0, gpc_LastRow_2); // Calcualate gross pay for the second part gp.GrossPay = secondPartGrossPay; gp.Month = Convert.ToString(sd_month); cmd_Part1 = "INSERT into emp_gross_calc values ("; cmd_Part2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},{10},'{11}','{12}'", gp.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, gd.Status, gd.ExternalRef, tc.PayStartDate, tc.PayEndDate, firstPart, firstPartOt, gp.GrossPay, gp.Month, gp.Comment); // 0 1 2 3 4 5 6 insert_Command = cmd_Part1 + cmd_Part2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); Console.WriteLine("gross pay part 2 Insert was executed with output " + insert_Command); Console.WriteLine("gross pay part 2 Insert was executed"); // Insert of part 2 of Gross Pay in Process Docs dtProcessDoc = Utilities.DataBaseUtility.GetTable("Select * from ProcessDocs "); prodoc_LastRow = Convert.ToString(dtProcessDoc.Rows.Count); gd.DocNum = Utilities.DataBaseUtility.GetNextNumber("ProcessDocs", 0, prodoc_LastRow); cmd_Part1 = "INSERT into ProcessDocs values ("; cmd_Part2 = String.Format("{0},{1} ,{2} ,{3} ,{4} ,{5} ,'{6}','{7}',{8},{9},'{10}'", gp.DocNum, gd.DocType, pg.EmplId, pg.ExtRef, gd.Status, gd.ExternalRef, tc.PayStartDate, tc.PayEndDate, gp.GrossPay, gp.Month, gp.Comment); // 0 1 2 3 4 5 6 7 8 9 10 insert_Command = cmd_Part1 + cmd_Part2 + ");"; Utilities.DataBaseUtility.Execute(insert_Command, ident); this.Close(); //End of exception Time card } //Claculating Final Monthly Gross Pay DateTime fGp; if ((startDatePicker.Value.ToString(format).Equals(ld_date))) { fGp = startDatePicker.Value; CalculateFinalGrossPay(fGp); } if ((startDatePicker.Value.AddDays(1).ToString(format).Equals(ld_date))) { fGp = startDatePicker.Value; CalculateFinalGrossPay(fGp); } if ((startDatePicker.Value.AddDays(2).ToString(format).Equals(ld_date))) { fGp = startDatePicker.Value; CalculateFinalGrossPay(fGp); } if ((startDatePicker.Value.AddDays(3).ToString(format).Equals(ld_date))) { fGp = startDatePicker.Value; CalculateFinalGrossPay(fGp); } if ((startDatePicker.Value.AddDays(4).ToString(format).Equals(ld_date))) { fGp = startDatePicker.Value; CalculateFinalGrossPay(fGp); } if ((startDatePicker.Value.AddDays(5).ToString(format).Equals(ld_date))) { fGp = startDatePicker.Value; CalculateFinalGrossPay(fGp); } if ((startDatePicker.Value.AddDays(6).ToString(format).Equals(ld_date))) { fGp = startDatePicker.Value; CalculateFinalGrossPay(fGp); } this.Close(); } }
public void AddTimeCard(TimeCard card) { timeCards[card.Date] = card; }
public void AddTimeCard(TimeCard tc) { timeCards[tc.Date] = tc; }
public void AddTimeCard(TimeCard timeCard) { timeCards.Add(timeCard.Date, timeCard); }