Exemplo n.º 1
0
        private void calculateBtn_Click(object sender, EventArgs e)
        {
            if (validateControls())
            {
                getWeek1Values();
                getWeek2Values();
                getWeek3Values();
                getWeek4Values();

                totalHoursWk1 = Mon1 + Tues1 + wed1 + thurs1 + fri1 + sat1 + sun1;
                totalHoursWk2 = Mon2 + Tues2 + wed2 + thurs2 + fri2 + sat2 + sun2;
                totalHoursWk3 = Mon3 + Tues3 + wed3 + thurs3 + fri3 + sat3 + sun3;
                totalHoursWk4 = Mon4 + Tues4 + wed4 + thurs4 + fri4 + sat4 + sun4;

                try
                {
                    hourlySalaryRate = double.Parse(hourlyRateNumericUpDown.Value.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Following Error occured" + ex.Message, "Error Message");
                }

                overTimeSalaryRate = hourlySalaryRate * 1.5;

                //Week 1 Computation
                if (totalHoursWk1 <= 36)
                {
                    contractualHoursWk1  = totalHoursWk1;
                    contarctualAmountWk1 = hourlySalaryRate * totalHoursWk1;
                    overTimeHoursWk1     = 0.00;
                    overTimeAmountWk1    = 0.00;
                }
                else if (totalHoursWk1 > 36)
                {
                    contractualHoursWk1  = 36;
                    contarctualAmountWk1 = hourlySalaryRate * contractualHoursWk1;
                    overTimeHoursWk1     = totalHoursWk1 - contractualHoursWk1;
                    overTimeAmountWk1    = overTimeHoursWk1 * overTimeSalaryRate;
                }
                //Week 2 Computation
                if (totalHoursWk2 <= 36)
                {
                    contractualHoursWk2  = totalHoursWk2;
                    contarctualAmountWk2 = hourlySalaryRate * totalHoursWk2;
                    overTimeHoursWk2     = 0.00;
                    overTimeAmountWk2    = 0.00;
                }
                else if (totalHoursWk2 > 36)
                {
                    contractualHoursWk2  = 36;
                    contarctualAmountWk2 = hourlySalaryRate * contractualHoursWk2;
                    overTimeHoursWk2     = totalHoursWk2 - contractualHoursWk2;
                    overTimeAmountWk2    = overTimeHoursWk2 * overTimeSalaryRate;
                }
                //Week 3 Computation
                if (totalHoursWk3 <= 36)
                {
                    contractualHoursWk3  = totalHoursWk3;
                    contarctualAmountWk3 = hourlySalaryRate * totalHoursWk3;
                    overTimeHoursWk3     = 0.00;
                    overTimeAmountWk3    = 0.00;
                }
                else if (totalHoursWk3 > 36)
                {
                    contractualHoursWk3  = 36;
                    contarctualAmountWk3 = hourlySalaryRate * contractualHoursWk3;
                    overTimeHoursWk3     = totalHoursWk3 - contractualHoursWk3;
                    overTimeAmountWk3    = overTimeHoursWk3 * overTimeSalaryRate;
                }
                //Week 4 Computation
                if (totalHoursWk4 <= 36)
                {
                    contractualHoursWk4  = totalHoursWk4;
                    contarctualAmountWk4 = hourlySalaryRate * totalHoursWk4;
                    overTimeHoursWk4     = 0.00;
                    overTimeAmountWk4    = 0.00;
                }
                else if (totalHoursWk4 > 36)
                {
                    contractualHoursWk4  = 36;
                    contarctualAmountWk4 = hourlySalaryRate * contractualHoursWk4;
                    overTimeHoursWk4     = totalHoursWk4 - contractualHoursWk4;
                    overTimeAmountWk4    = overTimeHoursWk4 * overTimeSalaryRate;
                }

                totalContractualHours  = contractualHoursWk1 + contractualHoursWk2 + contractualHoursWk3 + contractualHoursWk4;
                totalOverTimeHours     = overTimeHoursWk1 + overTimeHoursWk2 + overTimeHoursWk3 + overTimeHoursWk4;
                totalContractualAmount = contarctualAmountWk1 + contarctualAmountWk2 + contarctualAmountWk3 + contarctualAmountWk4;
                totalOverTimeAmount    = overTimeAmountWk1 + overTimeAmountWk2 + overTimeAmountWk3 + overTimeAmountWk4;
                totalHoursWorked       = totalContractualHours + totalOverTimeHours;
                totalAmountEarned      = totalContractualAmount + totalOverTimeAmount;

                if (totalAmountEarned <= 916.67)
                {
                    taxRate = .0;
                    tax     = totalAmountEarned * taxRate;
                }
                else if (totalAmountEarned > 916.67 && totalAmountEarned <= 3583.33)
                {
                    taxRate = .20;
                    tax     = ((916.67 * .0) + ((totalAmountEarned - 916.67) * taxRate));
                }
                else if (totalAmountEarned > 3583.33 && totalAmountEarned <= 12500)
                {
                    taxRate = .40;
                    tax     = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((totalAmountEarned - 3583.33) * taxRate));
                }
                else if (totalAmountEarned > 12500)
                {
                    taxRate = .45;
                    tax     = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((12500 - 3583.33) * .40) + ((totalAmountEarned - 12500) * taxRate));
                }


                // NI Computation

                if (totalAmountEarned < 620)
                {
                    NiRate = .0;
                }
                else if (totalAmountEarned >= 620 && totalAmountEarned <= 3308)
                {
                    NiRate = .12;
                }
                else if (totalAmountEarned > 3308)
                {
                    NiContribution = .02;
                }

                NiContribution = totalAmountEarned * NiRate;
                SLC            = totalAmountEarned * SLCRate;

                totalDeductions = tax + NiContribution + SLC + union;

                netPay = totalAmountEarned - totalDeductions;


                contratualHoursTxt.Text = totalContractualHours.ToString("F");
                overTimeHoursTxt.Text   = totalOverTimeHours.ToString("F");
                TotalHoursTxt.Text      = totalHoursWorked.ToString("F");
                ContEarningTxt.Text     = totalContractualAmount.ToString("C");
                overTimeEarningTxt.Text = totalOverTimeAmount.ToString("C");
                totalEarningTxt.Text    = totalAmountEarned.ToString("C");
                overTimeRateTxt.Text    = overTimeSalaryRate.ToString("F");
                taxAmountTxt.Text       = tax.ToString("C");
                NIContributionTxt.Text  = NiContribution.ToString("C");
                slcTxt.Text             = SLC.ToString("C");
                unionTxt.Text           = union.ToString("C");
                totalDeductionsTxt.Text = totalDeductions.ToString("C");
                netPayTxt.Text          = netPay.ToString("C");
            }
        }
        private void btnComputePay_Click(object sender, EventArgs e)
        {
            if (ValidateControls())
            {
                GetWeek1Values();
                GetWeek2Values();
                GetWeek3Values();
                GetWeek4Values();

                //Compute Weekly Hours
                totalHoursWk1 = Mon1 + Tues1 + Wen1 + Thurs1 + Fri1 + Sat1 + Sun1;
                totalHoursWk2 = Mon2 + Tues2 + Wen2 + Thurs2 + Fri2 + Sat2 + Sun2;
                totalHoursWk3 = Mon3 + Tues3 + Wen3 + Thurs3 + Fri3 + Sat3 + Sun3;
                totalHoursWk4 = Mon4 + Tues4 + Wen4 + Thurs4 + Fri4 + Sat4 + Sun4;

                //Retrieve Hourly Rate
                try
                {
                    hourlySalaryRate = double.Parse(nudHourlyRate.Value.ToString());
                }
                catch (FormatException ex)
                {
                    MessageBox.Show("The following error has occured : " + ex.Message, "Error Message");
                }

                //Overtime Rate
                overtimeSalaryRate = hourlySalaryRate * 1.5;
                #region ----- Week 1 Computation ----
                //Hours worked, No Overtime
                if (totalHoursWk1 <= 36)
                {
                    contractualHoursWk1  = totalHoursWk1;
                    contractualAmountWk1 = hourlySalaryRate * totalHoursWk1;
                    overtimeHoursWk1     = 0.00;
                    overtimeAmountWk1    = 0.00;
                }
                //Hours Worked, with Overtime
                else if (totalHoursWk1 > 36)
                {
                    contractualHoursWk1  = 36;
                    contractualAmountWk1 = hourlySalaryRate * contractualHoursWk1;
                    overtimeHoursWk1     = totalHoursWk1 - contractualHoursWk1;
                    overtimeAmountWk1    = overtimeHoursWk1 * overtimeSalaryRate;
                }
                #endregion
                #region               ----- Week 2 Computation ----
                //Hours worked, No Overtime
                if (totalHoursWk2 <= 36)
                {
                    contractualHoursWk2  = totalHoursWk2;
                    contractualAmountWk2 = hourlySalaryRate * totalHoursWk2;
                    overtimeHoursWk2     = 0.00;
                    overtimeAmountWk2    = 0.00;
                }
                //Hours worked, with overtime
                else if (totalHoursWk2 > 36)
                {
                    contractualHoursWk2  = 36;
                    contractualAmountWk2 = hourlySalaryRate * contractualHoursWk2;
                    overtimeHoursWk2     = totalHoursWk2 - contractualHoursWk2;
                    overtimeAmountWk2    = overtimeHoursWk2 * overtimeSalaryRate;
                }
                #endregion
                #region               ----- Week 3 Computation ----
                //Hours worked, No Overtime
                if (totalHoursWk3 <= 36)
                {
                    contractualHoursWk3  = totalHoursWk3;
                    contractualAmountWk3 = hourlySalaryRate * totalHoursWk3;
                    overtimeHoursWk3     = 0.00;
                    overtimeAmountWk3    = 0.00;
                }
                //Hours worked, with overtime
                else if (totalHoursWk3 > 36)
                {
                    contractualHoursWk3  = 36;
                    contractualAmountWk3 = hourlySalaryRate * contractualHoursWk3;
                    overtimeHoursWk3     = totalHoursWk3 - contractualHoursWk3;
                    overtimeAmountWk3    = overtimeHoursWk3 * overtimeSalaryRate;
                }
                #endregion
                #region               ----- Week 4 Computation ----
                //Hours worked, No Overtime
                if (totalHoursWk4 <= 36)
                {
                    contractualHoursWk4  = totalHoursWk4;
                    contractualAmountWk4 = hourlySalaryRate * totalHoursWk4;
                    overtimeHoursWk4     = 0.00;
                    overtimeAmountWk4    = 0.00;
                }
                //Hours worked, with overtime
                else if (totalHoursWk4 > 36)
                {
                    contractualHoursWk4  = 36;
                    contractualAmountWk4 = hourlySalaryRate * contractualHoursWk4;
                    overtimeHoursWk4     = totalHoursWk4 - contractualHoursWk4;
                    overtimeAmountWk4    = overtimeHoursWk4 * overtimeSalaryRate;
                }
                #endregion

                //Compute total Hours and Amount
                totalContractualHours  = contractualHoursWk1 + contractualHoursWk2 + contractualHoursWk3 + contractualHoursWk4;
                totalOvertimeHours     = overtimeHoursWk1 + overtimeHoursWk2 + overtimeHoursWk3 + overtimeHoursWk4;
                totalContractualAmount = contractualAmountWk1 + contractualAmountWk2 + contractualAmountWk3 + contractualAmountWk4;
                totalOvertimeAmount    = overtimeAmountWk1 + overtimeAmountWk2 + overtimeAmountWk3 + overtimeAmountWk4;
                totalHoursWorked       = totalContractualHours + totalOvertimeHours;
                totalAmountEarned      = totalContractualAmount + totalOvertimeAmount;

                //Compute for deductions
                #region --- Tax Computation ---
                //Compute for Income tax
                if (totalAmountEarned <= 916.67)
                {
                    //Tax free rate
                    taxRate = .0;
                    tax     = totalAmountEarned * taxRate;
                }
                else if (totalAmountEarned > 916.67 && totalAmountEarned <= 3583.33)
                {
                    //Basic tax rate
                    taxRate = .20;
                    //Income tax
                    tax = ((916.67 * .0) + ((totalAmountEarned - 916.67) * taxRate));
                }
                else if (totalAmountEarned > 3583.33 && totalAmountEarned <= 12500)
                {
                    //Higher tax rate
                    taxRate = .40;
                    //Income tax
                    tax = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((totalAmountEarned - 3583.33) * taxRate));
                }
                else if (totalAmountEarned > 12500)
                {
                    //Additional tax rate
                    taxRate = .45;
                    //Income tax
                    tax = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((12500 - 3583.33) * .40) + ((totalAmountEarned - 12500) * taxRate));
                }
                #endregion
                #region --- NI Computation ---
                // Compute National Insurance Contribution
                if (totalAmountEarned < 620)
                {
                    // Lower Earnings Limit Rate (LEL)
                    NIRate = .0;
                }
                else if (totalAmountEarned >= 620 && totalAmountEarned <= 3308)
                {
                    // primary - Upper Earnings Limit (UEL)
                    NIRate = .12;
                }
                else if (totalAmountEarned > 3308)
                {
                    // Secondary - Upper Earnings Limit (UEL)
                    NIContribution = .02;
                }
                #endregion


                NIContribution = totalAmountEarned * NIRate;
                SLC            = totalAmountEarned * SLCRate;

                //Total amount deductable
                totalDeductions = tax + NIContribution + SLC + Union;

                //Compute Net Pay after deductions
                netPay = totalAmountEarned - totalDeductions;

                //Output to Controls
                txtContractualHours.Text    = totalContractualHours.ToString("F");
                txtOvertimeHours.Text       = totalOvertimeHours.ToString("F");
                txtTotalHoursWorked.Text    = totalHoursWorked.ToString("F");
                txtContractualEarnings.Text = totalContractualAmount.ToString("C");
                txtOvertimeEarnings.Text    = totalOvertimeAmount.ToString("C");
                txtTotalEarnings.Text       = totalAmountEarned.ToString("C");
                txtOvertimeRate.Text        = overtimeSalaryRate.ToString("F");
                txtTaxAmount.Text           = tax.ToString("C");
                txtNIContribution.Text      = NIContribution.ToString("C");
                txtSLC.Text             = SLC.ToString("C");
                txtUnion.Text           = Union.ToString("C");
                txtTotalDeductions.Text = totalDeductions.ToString("C");
                txtNetPay.Text          = netPay.ToString("C");
            }
        }
Exemplo n.º 3
0
        private void computePayment_Click(object sender, EventArgs e)
        {
            if (validateInput())
            {
                GetWeek1Values();
                GetWeek2Values();
                GetWeek3Values();
                GetWeek4Values();

                //Computing wely hours
                totalWk1Hours = Mon1 + Tues1 + Wed1 + Thurs1 + Fri1 + Sat1 + Sun1;
                totalWk2Hours = Mon2 + Tues2 + Wed2 + Thurs2 + Fri2 + Sat2 + Sun2;
                totalWk3Hours = Mon3 + Tues3 + Wed3 + Thurs3 + Fri3 + Sat3 + Sun3;
                totalWk4Hours = Mon4 + Tues4 + Wed4 + Thurs4 + Fri4 + Sat4 + Sun4;

                //Retriving Hourly rate
                try{
                    hourlySalaryRate = double.Parse(hourlyRate.Value.ToString());
                }catch (FormatException ex) {
                    MessageBox.Show("The following error occured: " + ex.Message, "Error Message");
                }

                //Retriving overtime rate
                overtimeSalaryRate = hourlySalaryRate * 1.5;

                #region   First week payments calculation
                //Calculating payments for hours worked in week1 without overtime
                if (totalWk1Hours <= 36)
                {
                    contractualWk1Hours  = hourlySalaryRate * totalWk1Hours;
                    contractualWk1Amount = hourlySalaryRate * totalWk1Hours;
                    overtimeWk1Hours     = 0.00;
                    overtimeWk1Amount    = 0.00;
                }
                //Calculating payments for hours worked in week1 with overtime
                else if (totalWk1Hours > 36)
                {
                    contractualWk1Hours  = 36;
                    contractualWk1Amount = hourlySalaryRate * contractualWk1Hours;
                    overtimeWk1Hours     = totalWk1Hours - contractualWk1Hours;
                    overtimeWk1Amount    = overtimeWk1Hours * overtimeSalaryRate;
                }
                #endregion   end of first weeek computation
                #region   Second week payments calculation
                //Calculating payments for hours worked in week2 without overtime
                if (totalWk2Hours <= 36)
                {
                    contractualWk2Hours  = hourlySalaryRate * totalWk2Hours;
                    contractualWk2Amount = hourlySalaryRate * totalWk2Hours;
                    overtimeWk2Hours     = 0.00;
                    overtimeWk2Amount    = 0.00;
                }
                //Calculating payments for hours worked in week2 with overtime
                else if (totalWk2Hours > 36)
                {
                    contractualWk2Hours  = 36;
                    contractualWk2Amount = hourlySalaryRate * contractualWk2Hours;
                    overtimeWk2Hours     = totalWk2Hours - contractualWk2Hours;
                    overtimeWk2Amount    = overtimeWk2Hours * overtimeSalaryRate;
                }
                #endregion   end of second week payment calculation
                #region   Third week payments calculation
                //Calculating payments for hours worked in week3 without overtime
                if (totalWk1Hours <= 36)
                {
                    contractualWk3Hours  = hourlySalaryRate * totalWk3Hours;
                    contractualWk3Amount = hourlySalaryRate * totalWk3Hours;
                    overtimeWk3Hours     = 0.00;
                    overtimeWk3Amount    = 0.00;
                }
                //Calculating payments for hours worked in week3 with overtime
                else if (totalWk1Hours > 36)
                {
                    contractualWk3Hours  = 36;
                    contractualWk3Amount = hourlySalaryRate * contractualWk3Hours;
                    overtimeWk3Hours     = totalWk3Hours - contractualWk3Hours;
                    overtimeWk3Amount    = overtimeWk3Hours * overtimeSalaryRate;
                }
                #endregion   end of third weeek payment calculation
                #region   Fourth week payments calculation
                //Calculating payments for hours worked in week4 without overtime
                if (totalWk1Hours <= 36)
                {
                    contractualWk4Hours  = hourlySalaryRate * totalWk4Hours;
                    contractualWk4Amount = hourlySalaryRate * totalWk4Hours;
                    overtimeWk4Hours     = 0.00;
                    overtimeWk4Amount    = 0.00;
                }
                //Calculating payments for hours worked in week4 with overtime
                else if (totalWk1Hours > 36)
                {
                    contractualWk4Hours  = 36;
                    contractualWk4Amount = hourlySalaryRate * contractualWk4Hours;
                    overtimeWk4Hours     = totalWk4Hours - contractualWk4Hours;
                    overtimeWk4Amount    = overtimeWk4Hours * overtimeSalaryRate;
                }
                #endregion   end of Fourth week payment calculation

                //Calculating total hours and amount for all 4weeks
                totalContractualAmount = contractualWk1Amount + contractualWk2Amount + contractualWk3Amount + contractualWk4Amount;
                totalContractualHours  = contractualWk1Hours + contractualWk2Hours + contractualWk3Hours + contractualWk4Hours;
                totalOvertimeHours     = overtimeWk1Hours + overtimeWk2Hours + overtimeWk3Hours + overtimeWk4Hours;
                totalOvertimeAmount    = overtimeWk1Amount + overtimeWk2Amount + overtimeWk3Amount + overtimeWk4Amount;
                totalHoursWorked       = totalContractualAmount + totalOvertimeHours;
                totalAmountEarned      = totalContractualAmount + totalOvertimeAmount;

                //Calculating deductions
                #region Tax Calculation
                // Caclulating income Tax
                if (totalAmountEarned < 916.67)
                {
                    //Tax free rate
                    taxRate = .0;
                    tax     = totalAmountEarned * taxRate;
                }
                else if (totalAmountEarned > 916.67 && totalAmountEarned < 3583.33)
                {
                    //Basic tax Rate
                    taxRate = .20;
                    //Income tax
                    tax = ((916.67 * .0) + ((totalAmountEarned - 916.67) * taxRate));
                }
                else if (totalAmountEarned > 3583.33 && totalAmountEarned < 12500)
                {
                    //High tax rate
                    taxRate = .40;
                    //Icome tax
                    tax = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((totalAmountEarned - 3583.33) * taxRate));
                }
                else if (totalAmountEarned > 12500)
                {
                    //Additional tax rate
                    taxRate = .45;
                    //Income rate
                    tax = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((12500 - 3583.33) * .40) + ((totalAmountEarned - 3583.33) * taxRate));
                }
                #endregion End of Tax calculation

                #region Calculating National Insurance
                if (totalAmountEarned < 620)
                {
                    //Lower earnnig limit
                    NIRate = .0;
                }
                else if (totalAmountEarned >= 620 && totalAmountEarned <= 3308)
                {
                    NIRate = .12;
                }
                else if (totalAmountEarned > 3308)
                {
                    NIContribution = 0.2;
                }
                #endregion

                NIContribution = totalAmountEarned * NIRate;

                SLC = totalAmountEarned * SLCRate;

                totalDeductions = tax + NIContribution + SLC + Union;

                netPay = totalAmountEarned - totalDeductions;

                //displaying result to user interface
                contractualHoursField.Text    = totalContractualHours.ToString("F");
                overtimeEarningsField.Text    = totalOvertimeAmount.ToString("C");
                overtimeHoursField.Text       = totalOvertimeHours.ToString("F");
                contractualEarningsField.Text = totalContractualAmount.ToString("F");
                totalHoursField.Text          = totalHoursWorked.ToString("F");
                taxAmountField.Text           = tax.ToString("C");
                overtimeRateField.Text        = overtimeSalaryRate.ToString("F");
                totalEarnnigsField.Text       = totalAmountEarned.ToString("C");
                niContributionField.Text      = NIContribution.ToString("C");
                slcField.Text             = SLC.ToString("C");
                unionField.Text           = Union.ToString("C");
                totalDeductionsField.Text = totalDeductions.ToString("C");
                netPayField.Text          = netPay.ToString("C");
            }
        }
        private void btnComputePayment_Click(object sender, EventArgs e)
        {
            if (ValidateControls())
            {
                GetWeek1Values();
                GetWeek2Values();
                GetWeek3Values();
                GetWeek4Values();

                totalHoursWk1 = Mon1 + Tues1 + Wen1 + Thurs1 + Fri1 + Sat1 + Sun1;
                totalHoursWk2 = Mon2 + Tues2 + Wen2 + Thurs2 + Fri2 + Sat2 + Sun2;
                totalHoursWk3 = Mon3 + Tues3 + Wen3 + Thurs3 + Fri3 + Sat3 + Sun3;
                totalHoursWk4 = Mon4 + Tues4 + Wen4 + Thurs4 + Fri4 + Sat4 + Sun4;

                hourlySalaryRate = double.Parse(nudHourlyRate.Value.ToString());

                overtimeSalaryRate = hourlySalaryRate * 1.5;

                #region ----Week 1 computation----

                //Hours worked, No overtime
                if (totalHoursWk1 <= 36)
                {
                    contractualHoursWk1  = totalHoursWk1;
                    contractualAmountWk1 = hourlySalaryRate * totalHoursWk1;
                    overtimeHoursWk1     = 0.00;
                    overtimeAmountWk1    = 0.00;
                }

                //Hours worked, with Overtime
                else if (totalHoursWk1 > 36)
                {
                    contractualHoursWk1  = 36;
                    contractualAmountWk1 = hourlySalaryRate * contractualHoursWk1;
                    overtimeHoursWk1     = totalHoursWk1 - contractualHoursWk1;
                    overtimeAmountWk1    = overtimeSalaryRate * overtimeHoursWk1;
                }

                #endregion
                #region ----Week 2 computation----

                //Hours worked, No overtime
                if (totalHoursWk2 <= 36)
                {
                    contractualHoursWk2  = totalHoursWk2;
                    contractualAmountWk2 = hourlySalaryRate * totalHoursWk2;
                    overtimeHoursWk2     = 0.00;
                    overtimeAmountWk2    = 0.00;
                }

                //Hours worked, with Overtime
                else if (totalHoursWk2 > 36)
                {
                    contractualHoursWk2  = 36;
                    contractualAmountWk2 = hourlySalaryRate * contractualHoursWk2;
                    overtimeHoursWk2     = totalHoursWk2 - contractualHoursWk2;
                    overtimeAmountWk2    = overtimeSalaryRate * overtimeHoursWk2;
                }

                #endregion
                #region ----Week 3 computation----

                //Hours worked, No overtime
                if (totalHoursWk3 <= 36)
                {
                    contractualHoursWk3  = totalHoursWk3;
                    contractualAmountWk3 = hourlySalaryRate * totalHoursWk3;
                    overtimeHoursWk3     = 0.00;
                    overtimeAmountWk3    = 0.00;
                }

                //Hours worked, with Overtime
                else if (totalHoursWk3 > 36)
                {
                    contractualHoursWk3  = 36;
                    contractualAmountWk3 = hourlySalaryRate * contractualHoursWk3;
                    overtimeHoursWk3     = totalHoursWk3 - contractualHoursWk3;
                    overtimeAmountWk3    = overtimeSalaryRate * overtimeHoursWk3;
                }

                #endregion
                #region ----Week 4 computation----

                //Hours worked, No overtime
                if (totalHoursWk4 <= 36)
                {
                    contractualHoursWk4  = totalHoursWk4;
                    contractualAmountWk4 = hourlySalaryRate * totalHoursWk4;
                    overtimeHoursWk4     = 0.00;
                    overtimeAmountWk4    = 0.00;
                }

                //Hours worked, with Overtime
                else if (totalHoursWk4 > 36)
                {
                    contractualHoursWk4  = 36;
                    contractualAmountWk4 = hourlySalaryRate * contractualHoursWk4;
                    overtimeHoursWk4     = totalHoursWk4 - contractualHoursWk4;
                    overtimeAmountWk4    = overtimeSalaryRate * overtimeHoursWk4;
                }

                #endregion

                //Compute total Hours and Amount
                totalContractualHours  = contractualHoursWk1 + contractualHoursWk2 + contractualHoursWk3 + contractualHoursWk4;
                totalContractualAmount = contractualAmountWk1 + contractualAmountWk2 + contractualAmountWk3 + contractualAmountWk4;
                totalOvertimeHours     = overtimeHoursWk1 + overtimeHoursWk2 + overtimeHoursWk3 + overtimeHoursWk4;
                totalOvertimeAmount    = overtimeAmountWk1 + overtimeAmountWk2 + overtimeAmountWk3 + overtimeAmountWk4;
                totalHoursWorked       = totalContractualHours + totalOvertimeHours;
                totalAmountEarned      = totalContractualAmount + totalOvertimeAmount;

                //Compute for deductions
                #region ---Tax Computation---
                if (totalAmountEarned <= 916.67)
                {
                    taxRate = .0;
                    tax     = totalAmountEarned * taxRate;
                }

                else if (totalAmountEarned > 916.67 && totalAmountEarned <= 3583.33)
                {
                    taxRate = .20;
                    tax     = ((916.67 * .0) + ((totalAmountEarned - 916.67) * taxRate));
                }

                else if (totalAmountEarned > 3583.33 && totalAmountEarned <= 12500)
                {
                    taxRate = .40;
                    tax     = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((totalAmountEarned - 3583.33) * taxRate));
                }

                else if (totalAmountEarned > 12500)
                {
                    taxRate = .45;
                    tax     = ((916.67 * .0) + ((3583.33 - 916.67) * .20) + ((12500 - 3583.33) * .40) + ((totalAmountEarned - 12500) * taxRate));
                }
                #endregion
                #region ---NI Computation---
                if (totalAmountEarned < 620)
                {
                    NIRate = .0;
                }

                else if (totalAmountEarned >= 620 && totalAmountEarned <= 3308)
                {
                    NIRate = .12;
                }

                else if (totalAmountEarned > 3308)
                {
                    NIContribution = .02;
                }
                #endregion

                NIContribution = totalAmountEarned * NIRate;
                SLC            = totalAmountEarned * SLCRate;

                //Total amount deductable
                totalDeductions = tax + NIContribution + SLC + Union;

                //Compute Net Pay after deductions
                netPay = totalAmountEarned - totalDeductions;

                txtContracturalHours.Text    = totalContractualHours.ToString("F");
                txtOvertimeHours.Text        = totalOvertimeHours.ToString("F");
                txtTotalHoursWorked.Text     = totalHoursWorked.ToString("F");
                txtContracturalEarnings.Text = totalContractualAmount.ToString("C");
                txtOvertimeEarnings.Text     = totalOvertimeAmount.ToString("C");
                txtTotalEarnings.Text        = totalAmountEarned.ToString("C");
                txtOvertimeRate.Text         = overtimeSalaryRate.ToString("F");
                txtTaxAmount.Text            = tax.ToString("C");
                txtNIContribution.Text       = NIContribution.ToString("C");
                txtSLC.Text             = SLC.ToString("C");
                txtUnion.Text           = SLC.ToString("C");
                txtTotalDeductions.Text = totalDeductions.ToString("C");
                txtNetPay.Text          = netPay.ToString("C");
            }
        }
Exemplo n.º 5
0
        private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            #region Drawing Company Logo and Name

            // Drawing a straight horizontal line (from x=60 to x= 780 and from top y = -90) above logo and company name
            e.Graphics.DrawLine(new Pen(Color.Aqua, 2), 60, 90, 780, 90);

            // Locating logo image
            Image logo = Image.FromFile(@"..\..\Icons\Logo.ico");
            // Drawing the logo on page
            e.Graphics.DrawImage(logo, 120, 100);
            // Drawing company name beside logo on same line
            e.Graphics.DrawString(Constants.COMPANY_TITLE, new Font(Constants.TITLE_FONT, Constants.TITLE_FONT_SIZE, Constants.TITLE_FONT_STYLE), constants.TITLE_FONT_COLOUR, new Point(200, 115));

            // Drawing horizontal line just below logo and company name
            e.Graphics.DrawLine(new Pen(Color.Aqua, 2), 60, 180, 780, 180);

            #endregion

            // Displaying pay date on right side
            e.Graphics.DrawString(Constants.PAY_DATE + dtpCurrentDate.Value.ToString("MM/dd/yyyy"), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 620, 200);

            #region Drawing Employee Details

            // Drawing horizontal line just above Employee Details
            e.Graphics.DrawLine(new Pen(Color.RoyalBlue, 1), 60, 230, 780, 230);

            // Employee ID
            e.Graphics.DrawString(Constants.EMPLOYEE_ID + txtEmployeeID.Text, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 60, 240);

            // Employee Name
            e.Graphics.DrawString(Constants.EMPLOYEE_NAME + fullName, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 320, 240);

            // Employee NINO
            e.Graphics.DrawString(Constants.EMPLOYEE_NINO + txtNINumber.Text, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 635, 240);

            // Drawing horizontal line just below Employee Details
            e.Graphics.DrawLine(new Pen(Color.RoyalBlue, 1), 60, 270, 780, 270);

            #endregion

            #region Drawing Work and Payment Details

            #region Sub-Section Column Headings

            // Heading: Earnings
            e.Graphics.DrawString(Constants.HEADING_EARNINGS, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 60, 340);

            // Heading: Hours
            e.Graphics.DrawString(Constants.HEADING_HOURS, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 180, 340);

            // Heading: Rates
            e.Graphics.DrawString(Constants.HEADING_RATES, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 280, 340);

            // Heading: Amounts
            e.Graphics.DrawString(Constants.HEADING_AMOUNTS, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 380, 340);

            // Heading: Deductions
            e.Graphics.DrawString(Constants.HEADING_DEDUCTIONS, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 510, 340);

            // Heading: Amounts
            e.Graphics.DrawString(Constants.HEADING_AMOUNTS, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 670, 340);

            #endregion

            // Drawing horizontal line just below Column Headings
            e.Graphics.DrawLine(new Pen(Color.RoyalBlue, 2), 60, 370, 780, 370);

            #region Sub-Section First Row

            // Sub-Heading: Basic Earnings
            e.Graphics.DrawString(Constants.SUB_HEADING_BASIC, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 60, 390);

            // Value: Hours
            e.Graphics.DrawString(txtTotalHoursWorked.Text, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 180, 390);

            // Value: Rates
            e.Graphics.DrawString(Constants.HOURLY_RATE_INITIAL_VALUE_STRING_DOUBLE_DECIMAL, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 280, 390);

            // Value: Amounts
            e.Graphics.DrawString(totalContractualAmount.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 380, 390);

            // Sub-Heading: Tax
            e.Graphics.DrawString(Constants.SUB_HEADING_TAX_CODE, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 510, 390);

            // Value: Amounts
            e.Graphics.DrawString(tax.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 670, 390);

            #endregion

            #region Sub-Section Second Row

            // Sub-Heading: Overtime Earnings
            e.Graphics.DrawString(Constants.SUB_HEADING_OVERTIME, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 60, 420);

            // Value: Hours
            e.Graphics.DrawString(txtOvertimeHours.Text, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 180, 420);

            // Value: Rates
            e.Graphics.DrawString(constants.OVERTIME_RATE_VALUE_STRING_DOUBLE_DECIMAL, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 280, 420);

            // Value: Amounts
            e.Graphics.DrawString(totalOvertimeAmount.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 380, 420);

            // Sub-Heading: NIC
            e.Graphics.DrawString(Constants.SUB_HEADING_NIC, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 510, 420);

            // Value: Amounts
            e.Graphics.DrawString(NIContribution.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 670, 420);

            #endregion

            #region Sub-Section Third Row

            // Sub-Heading: Union
            e.Graphics.DrawString(Constants.SUB_HEADING_UNION, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 510, 450);

            // Value: Amounts
            e.Graphics.DrawString(Union.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 670, 450);

            #endregion

            #region Sub-Section Fourth Row

            // Sub-Heading: SLC
            e.Graphics.DrawString(Constants.SUB_HEADING_SLC, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 510, 480);

            // Value: Amounts
            e.Graphics.DrawString(SLC.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 670, 480);

            #endregion

            // Drawing horizontal line just below sub section ending
            e.Graphics.DrawLine(new Pen(Color.RoyalBlue, 1), 60, 520, 780, 520);

            #region Sub-Section Fifth Row

            // Sub-Heading: Total Earnings
            e.Graphics.DrawString(Constants.SUB_HEADING_TOTAL_EARNINGS, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 60, 540);

            // Value: Amounts
            e.Graphics.DrawString(totalAmountEarned.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 380, 540);

            // Sub-Heading: Total Deductions
            e.Graphics.DrawString(Constants.SUB_HEADING_TOTAL_DEDUCTIONS, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 510, 540);

            // Value: Amounts
            e.Graphics.DrawString(totalDeductions.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 670, 540);

            #endregion

            // Drawing horizontal line just below sub section ending
            e.Graphics.DrawLine(new Pen(Color.RoyalBlue, 2), 60, 580, 780, 580);

            #endregion

            #region Net Pay

            // Drawing horizontal line just below sub section ending
            e.Graphics.DrawLine(new Pen(Color.RoyalBlue, 1), 60, 680, 780, 680);

            // Sub-Heading: Total Deductions
            e.Graphics.DrawString(Constants.HEADING_NETPAY, new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE, Constants.CONTENT_HEADINGS_FONT_STYLE), constants.CONTENT_FONT_COLOUR, 510, 710);

            // Value: Amounts
            e.Graphics.DrawString(netPay.ToString("C", new CultureInfo("en-GB")), new Font(Constants.CONTENT_FONT, Constants.CONTENT_FONT_SIZE), constants.CONTENT_FONT_COLOUR, 670, 710);

            // Drawing horizontal line just below sub section ending
            e.Graphics.DrawLine(new Pen(Color.RoyalBlue, 1), 60, 750, 780, 750);

            #endregion
        }