예제 #1
0
        public void PromptPayslipInformation(UserInputInformation userInputInformation)
        {
            userInputInformation.Name = PromptString("Please input your name:", 30);

            userInputInformation.Surname = PromptString("Please input your surname:", 30);

            userInputInformation.Salary = PromptUnsignedInteger("Please enter your annual salary:");

            userInputInformation.SuperRate = PromptUnsignedInteger("Please enter your super rate:");

            bool validPaymentPeriod = false;

            while (!validPaymentPeriod)
            {
                userInputInformation.PaymentStartDate = PromptDateTime("Please enter your payment start date (e.g. '17 March'):");

                userInputInformation.PaymentEndDate = PromptDateTime("Please enter your payment end date:");

                TimeSpan span = userInputInformation.PaymentEndDate.Subtract(userInputInformation.PaymentStartDate);

                if (span.Days >= 27 || span.Days <= 31) // Ensuring time period is monthly
                {
                    validPaymentPeriod = true;
                }
                else
                {
                    Console.WriteLine("The given payment period is not monthly, please enter a monthly payment period");
                }
            }
        }
예제 #2
0
        public List <UserInputInformation> ParseCsvPayslipInformation(string filepath)
        {
            List <UserInputInformation> userInputList = new List <UserInputInformation>();

            using (TextFieldParser parser = new TextFieldParser(filepath))
            {
                parser.TextFieldType = FieldType.Delimited;
                parser.SetDelimiters(",");

                parser.ReadFields(); // To skip first lines

                while (!parser.EndOfData)
                {
                    UserInputInformation userInputInformation = new UserInputInformation();

                    //Processing user input
                    string[] fields = parser.ReadFields();

                    userInputInformation.Name      = fields[0];
                    userInputInformation.Surname   = fields[1];
                    userInputInformation.Salary    = uint.Parse(fields[2]);
                    userInputInformation.SuperRate = uint.Parse(fields[3].Replace("%", ""));

                    var dateInput = fields[4].Split("-");

                    var dateInputs = dateInput[0].Split(" ");
                    dateInputs.ToList().Remove("-");
                    var dayString    = dateInputs[0];
                    var monthString  = dateInputs[1];
                    var monthInteger = _monthDictionary[FirstCharToUpperCase(monthString)];
                    var dayInteger   = uint.Parse(dayString);
                    userInputInformation.PaymentStartDate = new DateTime(1, monthInteger, checked ((int)dayInteger));

                    dayString    = dateInputs[3];
                    monthString  = dateInputs[4];
                    monthInteger = _monthDictionary[FirstCharToUpperCase(monthString)];
                    dayInteger   = uint.Parse(dayString);
                    userInputInformation.PaymentEndDate = new DateTime(1, monthInteger, checked ((int)dayInteger));

                    userInputList.Add(userInputInformation);
                }
            }

            return(userInputList);
        }
        public PayslipInformation GeneratePayslip(UserInputInformation userInputInformation)
        {
            PayslipInformation payslipInformation = new PayslipInformation();

            payslipInformation.Fullname = userInputInformation.Name + " " + userInputInformation.Surname;

            payslipInformation.GrossIncome = Convert.ToUInt32(Math.Round(userInputInformation.Salary / 12.0)); // Gross income is monthly, so divide by 12

            payslipInformation.IncomeTax = CalculateIncomeTax(payslipInformation.GrossIncome * 12);            // Income tax calculated on annual pay, then made monthly within method

            payslipInformation.NetIncome = payslipInformation.GrossIncome - payslipInformation.IncomeTax;

            payslipInformation.Super = checked ((uint)Math.Round(payslipInformation.GrossIncome * (userInputInformation.SuperRate / 100.0)));

            payslipInformation.PaymentStartDate = userInputInformation.PaymentStartDate;

            payslipInformation.PaymentEndDate = userInputInformation.PaymentEndDate;

            return(payslipInformation);
        }