public override void Execute() { Console.WriteLine("Executing Example: " + this.Title); Console.WriteLine("See: " + Settings.Default.DeveloperPortalBaseUrl + this.DocsUrl); Console.WriteLine("==================================="); // Step 1: Create an Employer Console.WriteLine("Step 1: Create an Employer"); var employer = new Employer { EffectiveDate = new DateTime(2020, 1, 1), Name = "Getting Started Co Ltd", BacsServiceUserNumber = "123456", RuleExclusions = RuleExclusionFlags.None, Territory = CalculatorTerritory.UnitedKingdom, Region = CalculatorRegion.England, Address = new Address { Address1 = "House", Address2 = "Street", Address3 = "Town", Address4 = "County", Postcode = "TE1 1ST", Country = "United Kingdom" }, HmrcSettings = new HmrcSettings { TaxOfficeNumber = "451", TaxOfficeReference = "A451", AccountingOfficeRef = "123PA1234567X", Sender = Sender.Employer, SenderId = "ISV451", Password = "******", ContactFirstName = "Joe", ContactLastName = "Bloggs", ContactEmail = "*****@*****.**", ContactTelephone = "01234567890", ContactFax = "01234567890" }, BankAccount = new BankAccount { AccountName = "Getting St", AccountNumber = "12345678", SortCode = "012345" } }; var employerLink = this.ApiHelper.Post("/Employers", employer); Console.WriteLine($" CREATED: {employerLink.Title} - {employerLink.Href}"); // Step 2: Create a Pay Schedule Console.WriteLine("Step 2: Create a Pay Schedule"); var paySchedule = new PaySchedule { Name = "My Monthly", PayFrequency = PayFrequency.Monthly }; var payScheduleLink = this.ApiHelper.Post(employerLink.Href + "/PaySchedules", paySchedule); Console.WriteLine($" CREATED: {payScheduleLink.Title} - {payScheduleLink.Href}"); // Step 3: Create an Employee Console.WriteLine("Step 3: Create an Employee"); var employee = new Employee { EffectiveDate = new DateTime(2020, 4, 1), Code = "EMP001", Title = "Mr", FirstName = "Terry", MiddleName = "T", LastName = "Tester", Initials = "TTT", NiNumber = "AA000000A", DateOfBirth = new DateTime(1980, 1, 1), Gender = Gender.Male, NicLiability = NicLiability.IsFullyLiable, Region = CalculatorRegion.England, Territory = CalculatorTerritory.UnitedKingdom, PaySchedule = payScheduleLink, StartDate = new DateTime(2020, 4, 6), StarterDeclaration = StarterDeclaration.A, RuleExclusions = RuleExclusionFlags.None, WorkingWeek = WorkingWeek.AllWeekDays, Address = new Address { Address1 = "House", Address2 = "Street", Address3 = "Town", Address4 = "County", Postcode = "TE1 1ST", Country = "United Kingdom" }, HoursPerWeek = 40, PassportNumber = "123457890", BankAccount = new BankAccount { AccountName = "Mr T Tester", AccountNumber = "12345678", SortCode = "012345" }, EmployeePartner = new EmployeePartner { FirstName = "Teresa", MiddleName = "T", Initials = "TTT", LastName = "Tester", NiNumber = "AB000000A" } }; var employeeLink = this.ApiHelper.Post(employerLink.Href + "/Employees", employee); Console.WriteLine($" CREATED: {employeeLink.Title} - {employeeLink.Href}"); // Step 4: Create a Pay Instruction (Salary) Console.WriteLine("Step 4: Create a Pay Instruction (Salary)"); var salaryInstruction = new SalaryPayInstruction { StartDate = new DateTime(2020, 4, 1), AnnualSalary = 25000.00m }; var salaryInstructionLink = this.ApiHelper.Post(employeeLink.Href + "/PayInstructions", salaryInstruction); Console.WriteLine($" CREATED: {salaryInstructionLink.Title} - {salaryInstructionLink.Href}"); // Step 5: Create a Pay Run Job Console.WriteLine("Step 5: Create a Pay Run Job"); var payRunJob = new PayRunJobInstruction { PaymentDate = new DateTime(2020, 4, 30), StartDate = new DateTime(2020, 4, 1), EndDate = new DateTime(2020, 4, 30), PaySchedule = payScheduleLink }; var jobInfoLink = this.ApiHelper.Post("/Jobs/Payruns", payRunJob); Console.WriteLine($" CREATED: {jobInfoLink.Title} - {jobInfoLink.Href}"); // Step 6: Query Pay Run Job Status Console.WriteLine("Step 6: Query Pay Run Job Status"); while (true) { Thread.Sleep(1000); var payRunJobInfo = this.ApiHelper.Get <JobInfo>(jobInfoLink.Href); Console.WriteLine($" Job Status: {payRunJobInfo.JobStatus} - {payRunJobInfo.Progress:P2}"); if (payRunJobInfo.JobStatus == JobStatus.Success) { break; } if (payRunJobInfo.JobStatus == JobStatus.Failed) { throw new Exception("Payrun job failed:" + string.Join(Environment.NewLine, payRunJobInfo.Errors)); } } // Step 7: Get the Employee Payslip Console.WriteLine("Step 7: Get the Employee Payslip"); var employerId = employerLink.Href.Split('/').Last(); var payslipReport = this.ApiHelper.GetRawXml($"/Report/PAYSLIP/run?EmployerKey={employerId}&TaxYear=2020&TaxPeriod=1"); Console.WriteLine(payslipReport.InnerXml); // Step 8: Review Calculation Commentary Console.WriteLine("Step 8: Review Calculation Commentary"); var commentaryLinks = this.ApiHelper.GetLinks(employeeLink.Href + "/Commentaries"); var commentary = this.ApiHelper.Get <Commentary>(commentaryLinks.Links.First().Href); Console.WriteLine(commentary.Detail); // Step 9: Create RTI FPS submission Job Console.WriteLine("Step 9: Create RTI FPS submission Job"); var rtiFpsJobInstruction = new RtiJobInstruction { RtiType = "FPS", Generate = true, Transmit = true, TaxYear = 2020, Employer = employerLink, PaySchedule = payScheduleLink, PaymentDate = new DateTime(2020, 4, 30), Timestamp = new DateTime(2020, 4, 30) }; jobInfoLink = this.ApiHelper.Post("/Jobs/Rti", rtiFpsJobInstruction); Console.WriteLine($" CREATED: {jobInfoLink.Title} - {jobInfoLink.Href}"); // Step 10: Query RTI Job Status Console.WriteLine("Step 10: Query RTI FPS Job Status"); while (true) { Thread.Sleep(1000); var rtiJobInfo = this.ApiHelper.Get <JobInfo>(jobInfoLink.Href); Console.WriteLine($" Job Status: {rtiJobInfo.JobStatus}"); if (rtiJobInfo.JobStatus == JobStatus.Success) { break; } if (rtiJobInfo.JobStatus == JobStatus.Failed) { throw new Exception("RTI job failed:" + string.Join(Environment.NewLine, rtiJobInfo.Errors)); } } // Step 11: Review FPS transmission results Console.WriteLine("Step 11: Review FPS transmission results"); var rtiTransactionLinks = this.ApiHelper.GetLinks(employerLink.Href + "/RtiTransactions"); var rtiFpsTransaction = this.ApiHelper.Get <RtiFpsTransaction>(rtiTransactionLinks.Links.First().Href); Console.WriteLine(rtiFpsTransaction.Response.Replace("<", "<").Replace(">", ">").Replace(""", "\"")); // End of examples Console.WriteLine(string.Empty); Console.WriteLine("-- THE END --"); }
public override void Execute() { Console.WriteLine("Executing Example: " + this.Title); Console.WriteLine("See: " + Settings.Default.DeveloperPortalBaseUrl + this.DocsUrl); Console.WriteLine("==================================="); // Step 1: Create an Employer Console.WriteLine("Step 1: Create an Employer"); var employer = new Employer { EffectiveDate = new DateTime(2020, 8, 1), Name = "Getting Started Co Ltd", BacsServiceUserNumber = "123456", RuleExclusions = RuleExclusionFlags.None, Territory = CalculatorTerritory.UnitedKingdom, Region = CalculatorRegion.England, Address = new Address { Address1 = "House", Address2 = "Street", Address3 = "Town", Address4 = "County", Postcode = "TE1 1ST", Country = "United Kingdom" }, HmrcSettings = new HmrcSettings { TaxOfficeNumber = "451", TaxOfficeReference = "A451", AccountingOfficeRef = "123PA1234567X", Sender = Sender.Employer, SenderId = "ISV451", Password = "******", ContactFirstName = "Joe", ContactLastName = "Bloggs", ContactEmail = "*****@*****.**", ContactTelephone = "01234567890", ContactFax = "01234567890" }, BankAccount = new BankAccount { AccountName = "Getting St", AccountNumber = "12345678", SortCode = "012345" } }; var employerLink = this.ApiHelper.Post("/Employers", employer); Console.WriteLine($" CREATED: {employerLink.Title} - {employerLink.Href}"); // Step 2: Create a Pay Schedule Console.WriteLine("Step 2: Create a Pay Schedule"); var paySchedule = new PaySchedule { Name = "My Weekly", PayFrequency = PayFrequency.Weekly }; var payScheduleLink = this.ApiHelper.Post(employerLink.Href + "/PaySchedules", paySchedule); Console.WriteLine($" CREATED: {payScheduleLink.Title} - {payScheduleLink.Href}"); // Step 3: Create an Employee Console.WriteLine("Step 3: Create an Employee"); var employee = new Employee { EffectiveDate = new DateTime(2020, 8, 1), Code = "EMP001", Title = "Mr", FirstName = "Terry", MiddleName = "T", LastName = "Tester", Initials = "TTT", NiNumber = "AA000000A", DateOfBirth = new DateTime(1980, 1, 1), Gender = Gender.Male, NicLiability = NicLiability.IsFullyLiable, Region = CalculatorRegion.England, Territory = CalculatorTerritory.UnitedKingdom, PaySchedule = payScheduleLink, StartDate = new DateTime(2020, 8, 1), StarterDeclaration = StarterDeclaration.A, RuleExclusions = RuleExclusionFlags.None, WorkingWeek = WorkingWeek.AllWeekDays, Address = new Address { Address1 = "House", Address2 = "Street", Address3 = "Town", Address4 = "County", Postcode = "TE1 1ST", Country = "United Kingdom" }, HoursPerWeek = 40, PassportNumber = "123457890" }; var employeeLink = this.ApiHelper.Post(employerLink.Href + "/Employees", employee); Console.WriteLine($" CREATED: {employeeLink.Title} - {employeeLink.Href}"); // Step 4: Create a Pay Instruction (Salary) Console.WriteLine("Step 4: Create a Pay Instruction (Salary)"); var salaryInstruction = new SalaryPayInstruction { StartDate = new DateTime(2020, 8, 1), AnnualSalary = 25000.00m }; var salaryInstructionLink = this.ApiHelper.Post(employeeLink.Href + "/PayInstructions", salaryInstruction); Console.WriteLine($" CREATED: {salaryInstructionLink.Title} - {salaryInstructionLink.Href}"); // Step 5: Create a Pay Instruction (Salary) Console.WriteLine("Step 5: Create a Tax Instruction (1185L)"); var taxInstruction = new TaxPayInstruction { StartDate = new DateTime(2020, 8, 1), TaxCode = "1185L" }; var taxInstructionLink = this.ApiHelper.Post(employeeLink.Href + "/PayInstructions", taxInstruction); Console.WriteLine($" CREATED: {taxInstructionLink.Title} - {taxInstructionLink.Href}"); // Step 6: Create a Pay Run Job Console.WriteLine("Step 6: Create a Pay Run Job"); var payRunJob = new PayRunJobInstruction { PaymentDate = new DateTime(2020, 8, 17), StartDate = new DateTime(2020, 8, 13), EndDate = new DateTime(2020, 8, 19), PaySchedule = payScheduleLink }; var jobInfoLink = this.ApiHelper.Post("/Jobs/Payruns", payRunJob); Console.WriteLine($" CREATED: {jobInfoLink.Title} - {jobInfoLink.Href}"); // Step 7: Query Pay Run Job Status Console.WriteLine("Step 7: Query Pay Run Job Status"); this.PollPayRunJobStatus(jobInfoLink); // Step 8: Create 2nd Pay Run Job Console.WriteLine("Step 8: Create a 2nd Pay Run Job"); var payRunJob2 = new PayRunJobInstruction { PaymentDate = new DateTime(2020, 8, 24), StartDate = new DateTime(2020, 8, 20), EndDate = new DateTime(2020, 8, 26), PaySchedule = payScheduleLink }; var jobInfoLink2 = this.ApiHelper.Post("/Jobs/Payruns", payRunJob2); Console.WriteLine($" CREATED: {jobInfoLink2.Title} - {jobInfoLink2.Href}"); // Step 9: Query Pay Run Job Status Console.WriteLine("Step 9: Query Pay Run Job Status"); this.PollPayRunJobStatus(jobInfoLink2); // Step 10: Query Pay Run Job Status Console.WriteLine("Step 10: Recieve late notification of employee tax code change, requires retrospective correction."); var newTaxInstruction = new TaxPayInstruction { StartDate = new DateTime(2020, 8, 20), TaxCode = "1285L" }; // Step 11: Get all payruns for employee Console.WriteLine("Step 11: Get all PayRuns for Employee"); var payruns = this.ApiHelper.GetLinks(employeeLink.Href + "/PayRuns"); foreach (var link in payruns.Links) { Console.WriteLine($" -- {link.Title} ({link.Href})"); } // Step 12: Loop Employee PayRuns and DELETE any with payment date after new tax code effective date. Console.WriteLine("Step 12: Loop Employee PayRuns and DELETE any with payment date after new tax code effective date."); Console.WriteLine($"New tax code effective date: {newTaxInstruction.StartDate:yyyy-MM-dd}"); foreach (var link in payruns.Links) { var payrun = this.ApiHelper.Get <PayRun>(link.Href); if (payrun.PaymentDate >= newTaxInstruction.StartDate) { this.ApiHelper.Delete(link.Href); Console.WriteLine($" -- DELETE {link.Title} ({link.Href})"); } } // Step 13: End Existing Tax Instruction Console.WriteLine("Step 13: End Existing Tax Instruction"); taxInstruction.EndDate = newTaxInstruction.StartDate.AddDays(-1); taxInstruction = this.ApiHelper.Put <TaxPayInstruction>(taxInstructionLink.Href, taxInstruction); Console.WriteLine($" UPDATE: {jobInfoLink2.Title} successfully ended {taxInstruction.EndDate.GetValueOrDefault():yyyy-MM-dd}"); // Step 14: Create new Tax Instruction (1285L) Console.WriteLine("Step 14: Create new Tax Instruction (1285L)"); var newTaxInstructionLink = this.ApiHelper.Post(employeeLink.Href + "/PayInstructions", newTaxInstruction); Console.WriteLine($" CREATED: {newTaxInstructionLink.Title} - {newTaxInstructionLink.Href}"); // Step 15: Re-queue 2nd Payrun Job Console.WriteLine("Step 15: Re-queue 2nd Payrun Job"); var jobInfoLink3 = this.ApiHelper.Post("/Jobs/Payruns", payRunJob2); Console.WriteLine($" CREATED: {jobInfoLink3.Title} - {jobInfoLink3.Href}"); // Step 16: Query Pay Run Job Status Console.WriteLine("Step 16: Query Pay Run Job Status"); this.PollPayRunJobStatus(jobInfoLink3); // Step 17: Get the Employee Payslip Console.WriteLine("Step 17: Get the Employee Payslip"); var employerKey = employerLink.Href.Split('/').Last(); var payscheuleKey = payScheduleLink.Href.Split('/').Last(); var payslipReport = this.ApiHelper.GetRawXml($"/Report/PAYSLIP3/run?EmployerKey={employerKey}&PayScheduleKey={payscheuleKey}&TaxYear=2020&PaymentDate={payRunJob2.PaymentDate:yyyy-MM-dd}"); Console.WriteLine(payslipReport.InnerXml); // Step 18: Review Calculation Commentary Console.WriteLine("Step 18: Review Calculation Commentary"); var commentaryLinks = this.ApiHelper.GetLinks(employeeLink.Href + "/Commentaries"); var commentary = this.ApiHelper.Get <Commentary>(commentaryLinks.Links.Last().Href); Console.WriteLine(commentary.Detail); // End of example Console.WriteLine(string.Empty); Console.WriteLine("-- THE END --"); }
public override void Execute() { Console.WriteLine("Executing Example: " + this.Title); Console.WriteLine("See: " + Settings.Default.DeveloperPortalBaseUrl + this.DocsUrl); Console.WriteLine("==================================="); // Step 1: Create an Employer Console.WriteLine("Step 1: Create an Employer"); var employer = new Employer { EffectiveDate = new DateTime(2020, 4, 1), Name = "AE Test Ltd", Region = CalculatorRegion.England, Territory = CalculatorTerritory.UnitedKingdom, RuleExclusions = RuleExclusionFlags.None, AutoEnrolment = new EmployerAutoEnrolment { StagingDate = new DateTime(2014, 4, 1), PrimaryFirstName = "Terry", PrimaryLastName = "Tester", PrimaryEmail = "*****@*****.**", PrimaryTelephone = "0123456789", PrimaryJobTitle = "HR Manager" } }; var employerLink = this.ApiHelper.Post("/Employers", employer); Console.WriteLine($" CREATED: {employerLink.Title} - {employerLink.Href}"); // Step 2: Create Auto Enrolment Pension Scheme Console.WriteLine("Step 2: Create Auto Enrolment Pension Scheme"); var autoEnrolmentPension = new Pension { EffectiveDate = new DateTime(2020, 4, 1), SchemeName = "AE Scheme", ProviderName = "NEST", ProviderEmployerRef = "EMP123456789", EmployeeContributionPercent = 0.05m, EmployerContributionPercent = 0.03m, TaxationMethod = PensionTaxationMethod.ReliefAtSource, AECompatible = true, UseAEThresholds = true, PensionablePayCodes = new Collection <string> { "BASIC" }, QualifyingPayCodes = new Collection <string> { "BASIC" } }; var aePensionLinkHref = employerLink.Href + "/Pension/AEPENSION"; var aePensionLink = this.ApiHelper.Put(aePensionLinkHref, autoEnrolmentPension); Console.WriteLine($" CREATED: {aePensionLink.SchemeName} - {aePensionLinkHref}"); // Step 3: Update Employer Auto Enrolment Pension Scheme Console.WriteLine("Step 3: Update Employer Auto Enrolment Pension Scheme"); employer.AutoEnrolment.Pension = new Link { Href = aePensionLinkHref }; this.ApiHelper.Patch <Employer>(employerLink.Href, XmlSerialiserHelper.Serialise(employer)); Console.WriteLine($" UPDATE: Updated employer with AE pension - {aePensionLinkHref}"); // Step 4: Create a Pay Schedule Console.WriteLine("Step 2: Create a Pay Schedule"); var paySchedule = new PaySchedule { Name = "My Monthly", PayFrequency = PayFrequency.Monthly }; var payScheduleLink = this.ApiHelper.Post(employerLink.Href + "/PaySchedules", paySchedule); Console.WriteLine($" CREATED: {payScheduleLink.Title} - {payScheduleLink.Href}"); // Step 5: Create an Employee Console.WriteLine("Step 3: Create an Employee"); var employee = new Employee { EffectiveDate = new DateTime(2020, 4, 1), Code = "EMPAE1", FirstName = "Jane", LastName = "Johnson", DateOfBirth = new DateTime(1990, 12, 10), Gender = Gender.Female, NicLiability = NicLiability.IsFullyLiable, Region = CalculatorRegion.England, Territory = CalculatorTerritory.UnitedKingdom, WorkingWeek = WorkingWeek.AllWeekDays, HoursPerWeek = 37.5m, RuleExclusions = RuleExclusionFlags.None, PaySchedule = payScheduleLink, StartDate = new DateTime(2013, 4, 1), AEAssessmentOverride = AEAssessmentOverride.None }; var employeeLink = this.ApiHelper.Post(employerLink.Href + "/Employees", employee); Console.WriteLine($" CREATED: {employeeLink.Title} - {employeeLink.Href}"); // Step 6: Create a Pay Instruction (Salary) Console.WriteLine("Step 6: Pay the Employee"); var rateInstruction = new RatePayInstruction { StartDate = new DateTime(2020, 4, 1), EndDate = new DateTime(2020, 4, 1), Rate = 13.56m, RateUoM = UomBasicPay.Hour, Units = 160 }; var rateInstructionLink = this.ApiHelper.Post(employeeLink.Href + "/PayInstructions", rateInstruction); Console.WriteLine($" CREATED: {rateInstructionLink.Title} - {rateInstructionLink.Href}"); // Step 7: Create a Pay Run Job Console.WriteLine("Step 7: Create a Pay Run Job"); var payRunJob = new PayRunJobInstruction { PaymentDate = new DateTime(2020, 4, 30), StartDate = new DateTime(2020, 4, 1), EndDate = new DateTime(2020, 4, 30), PaySchedule = payScheduleLink }; var jobInfoLink = this.ApiHelper.Post("/Jobs/Payruns", payRunJob); Console.WriteLine($" CREATED: {jobInfoLink.Title} - {jobInfoLink.Href}"); // Step 8: Query Pay Run Job Status Console.WriteLine("Step 8: Query Pay Run Job Status"); while (true) { Thread.Sleep(1000); var payRunJobInfo = this.ApiHelper.Get <JobInfo>(jobInfoLink.Href); Console.WriteLine($" Job Status: {payRunJobInfo.JobStatus} - {payRunJobInfo.Progress:P2}"); if (payRunJobInfo.JobStatus == JobStatus.Success) { break; } if (payRunJobInfo.JobStatus == JobStatus.Failed) { throw new Exception("Payrun job failed:" + string.Join(Environment.NewLine, payRunJobInfo.Errors)); } } // Step 9: Examine the AE Assessment Result Console.WriteLine("Step 9: Examine the AE Assessment Result"); var aeAsseeement = this.ApiHelper.GetRawXml($"{employeeLink}/AEAssessment/AE001"); Console.WriteLine(aeAsseeement.InnerXml); // Step 10: Review Calculation Commentary Console.WriteLine("Step 10: Review Calculation Commentary"); var commentaryLinks = this.ApiHelper.GetLinks(employeeLink.Href + "/Commentaries"); var commentary = this.ApiHelper.Get <Commentary>(commentaryLinks.Links.First().Href); Console.WriteLine(commentary.Detail); // End of examples Console.WriteLine(string.Empty); Console.WriteLine("-- THE END --"); }