コード例 #1
0
        public static string printInfo(List <Employee> le)
        {
            StringBuilder sb = new StringBuilder();
            decimal       ficaHP = 0m, fitHP = 0m, grossHP = 0m, netHP = 0m, ficaSP = 0m,
                          fitSP = 0m, grossSP = 0m, netSP = 0m;

            foreach (Employee p in le)
            {
                sb.Append("Employee Weekly Breakdown:\n");
                sb.Append("Employee name: " + p.Name + "\n");
                sb.Append("Employee age: " + p.Age + "\n");
                sb.Append("Employee ID: " + p.EmployeeID + "\n");

                if (p is HourlyEmployee)
                {
                    HourlyEmployee hp = p as HourlyEmployee;

                    sb.Append("Employee hourly pay: " + hp.hourlyPay.ToString("C2") + "\n");
                    sb.Append("Employee hours worked: " + hp.hoursWorked.ToString() + "\n");
                    sb.Append("Employee FICA paid: " + hp.fica.ToString("C2") + "\n");
                    sb.Append("Employee Federal Tax Withheld: " + hp.fit.ToString("C2") + "\n");
                    sb.Append("Employee weekly take home: " + hp.CalculatePay() + "\n");
                    sb.Append("" + "\n");

                    ficaHP  += Math.Round(hp.fica, 2);
                    fitHP   += Math.Round(hp.fit, 2);
                    grossHP += hp.weeklyPay;
                }
                netHP = grossHP - ficaHP - fitHP;

                if (p is SalariedEmployee)
                {
                    SalariedEmployee sp = p as SalariedEmployee;

                    sb.Append("Employee monthly pay: " + sp.monthlyPay.ToString("C2") + "\n");
                    sb.Append("Employee FICA paid: " + sp.fica.ToString("C2") + "\n");
                    sb.Append("Employee Federal Tax Withheld: " + sp.fit.ToString("C2") + "\n");
                    sb.Append("Employee weekly take home: " + sp.CalculatePay() + "\n");
                    sb.Append("" + "\n");

                    ficaSP += Math.Round(sp.fica, 2);
                    fitSP  += Math.Round(sp.fit, 2);
                    grossSP = grossSP + sp.weeklyPay;
                }
                netSP = grossSP - ficaSP - fitSP;
            }

            sb.Append("Hourly Employee Weekly Data:" + "\n");
            sb.Append("Gross Pay: " + grossHP.ToString("C2") + "\n");
            sb.Append("Net Pay: " + netHP.ToString("C2") + "\n");
            sb.Append("FICA paid: " + ficaHP.ToString("C2") + "\n");
            sb.Append("Federal Tax Withheld: " + fitHP.ToString("C2") + "\n");
            sb.Append("" + "\n");

            sb.Append("Salaried Employee Weekly Data:" + "\n");
            sb.Append("Gross Pay: " + grossSP.ToString("C2") + "\n");
            sb.Append("Net Pay: " + netSP.ToString("C2") + "\n");
            sb.Append("FICA paid: " + ficaSP.ToString("C2") + "\n");
            sb.Append("Federal Tax Withheld: " + fitSP.ToString("C2") + "\n");
            sb.Append("" + "\n");

            sb.Append("Company Wide Weekly Data:" + "\n");
            sb.Append("Gross Pay: " + (grossHP + grossSP).ToString("C2") + "\n");
            sb.Append("Net Pay: " + (netHP + netSP).ToString("C2") + "\n");
            sb.Append("FICA paid: " + (ficaHP + ficaSP).ToString("C2") + "\n");
            sb.Append("Federal Tax Withheld: " + (fitHP + fitSP).ToString("C2") + "\n");
            sb.Append("" + "\n");

            return(sb.ToString());
        }
コード例 #2
0
ファイル: Report.cs プロジェクト: bradley-kelly/Payroll
        public static string RunReport(List <Employee> list)
        {
            StringBuilder sb            = new StringBuilder();
            decimal       ficaHourly    = 0m;
            decimal       federalHourly = 0m;
            decimal       grossHourly   = 0m;
            decimal       netHourly     = 0m;
            decimal       ficaSalary    = 0m;
            decimal       federalSalary = 0m;
            decimal       grossSalary   = 0m;
            decimal       netSalary     = 0m;

            foreach (Employee emp in list)
            {
                sb.Append("Employee Weekly Summary:\n");
                sb.Append("Employee Name: " + emp.Name + "\n");
                sb.Append("Employee Age: " + emp.Age + "\n");
                sb.Append("Employee ID: " + emp.EmployeeID + "\n");

                if (emp is SalariedEmployee)
                {
                    SalariedEmployee sPay = emp as SalariedEmployee;

                    sb.Append("Employee Monthly Pay: " + sPay.monthlyPay.ToString("C2") + "\n");
                    sb.Append("Employee FICA Tax: " + sPay.fica.ToString("C2") + "\n");
                    sb.Append("Employee Federal Tax: " + sPay.federalTax.ToString("C2") + "\n");
                    sb.Append("Employee Weekly Net Payroll: " + sPay.CalculatePay() + "\n");
                    sb.Append("" + "\n");

                    ficaSalary    += Math.Round(sPay.fica, 2);
                    federalSalary += Math.Round(sPay.federalTax, 2);
                    grossSalary   += sPay.weeklyPay;
                }
                netSalary = grossSalary - ficaSalary - federalSalary;

                if (emp is HourlyEmployee)
                {
                    HourlyEmployee hPay = emp as HourlyEmployee;

                    sb.Append("Employee Hourly Pay: " + hPay.hourlyPay.ToString("C2") + "\n");
                    sb.Append("Employee Hours Worked: " + hPay.hoursWorked.ToString() + "\n");
                    sb.Append("Employee FICA Tax: " + hPay.fica.ToString("C2") + "\n");
                    sb.Append("Employee Federal Tax: " + hPay.federalTax.ToString("C2") + "\n");
                    sb.Append("Employee Weekly Net Payroll: " + hPay.CalculatePay() + "\n");
                    sb.Append("" + "\n");

                    ficaHourly    += Math.Round(hPay.fica, 2);
                    federalHourly += Math.Round(hPay.federalTax, 2);
                    grossHourly   += hPay.weeklyPay;
                }
                netHourly = grossHourly - ficaHourly - federalHourly;
            }
            sb.Append("Salaried Employee Weekly Summary:" + "\n");
            sb.Append("Gross Payroll: " + grossSalary.ToString("C2") + "\n");
            sb.Append("Net Payroll: " + netSalary.ToString("C2") + "\n");
            sb.Append("FICA Tax: " + ficaSalary.ToString("C2") + "\n");
            sb.Append("Federal Tax: " + federalSalary.ToString("C2") + "\n");
            sb.Append("" + "\n");

            sb.Append("Hourly Employee Weekly Summary:" + "\n");
            sb.Append("Gross Payroll: " + grossHourly.ToString("C2") + "\n");
            sb.Append("Net Payroll: " + netHourly.ToString("C2") + "\n");
            sb.Append("FICA Tax: " + ficaHourly.ToString("C2") + "\n");
            sb.Append("Federal Tax: " + federalHourly.ToString("C2") + "\n");
            sb.Append("" + "\n");

            sb.Append("Combined Weekly Summary:" + "\n");
            sb.Append("Gross Payroll: " + (grossHourly + grossSalary).ToString("C2") + "\n");
            sb.Append("Net Payroll: " + (netHourly + netSalary).ToString("C2") + "\n");
            sb.Append("FICA Tax: " + (ficaHourly + ficaSalary).ToString("C2") + "\n");
            sb.Append("Federal Tax: " + (federalHourly + federalSalary).ToString("C2") + "\n");
            sb.Append("" + "\n");

            return(sb.ToString());
        }