<commit_before>package controllers.s7_employment

import language.reflectiveCalls
import play.api.mvc.Controller
import play.api.data.{FormError, Form}
import play.api.data.Forms._
import models.view.{Navigable, CachedClaim}
import models.domain.{Jobs, JobDetails}
import utils.helpers.CarersForm._
import controllers.Mappings._
import Employment._
import controllers.CarersForms._
import scala.Some

object G2JobDetails extends Controller with CachedClaim with Navigable {
  val form = Form(mapping(
    "jobID" -> nonEmptyText,
    "employerName"-> carersNonEmptyText(maxLength = 60),
    "jobStartDate" -> dayMonthYear.verifying(validDate),
    "finishedThisJob" -> nonEmptyText,
    "lastWorkDate" -> optional(dayMonthYear.verifying(validDate)),
    "p45LeavingDate" -> optional(dayMonthYear.verifying(validDateOnly)),
    "hoursPerWeek" -> optional(text(maxLength = 2).verifying(validNumber)),
    "payrollEmployeeNumber" -> optional(carersText)
  )(JobDetails.apply)(JobDetails.unapply)
    .verifying("lastWorkDate", JobDetails.validateLastWorkDate _)
  )

  def job(jobID: String) = claiming { implicit claim => implicit request =>
    claim.questionGroup(Jobs) match {
      case Some(js: Jobs) if js.job(jobID).isDefined =>
        track(JobDetails) { implicit claim => Ok(views.html.s7_employment.g2_jobDetails(form.fillWithJobID(JobDetails, jobID))) }
      case _ =>
        Redirect(routes.G1BeenEmployed.present())
    }
  }

  def present(jobID: String) = claiming { implicit claim => implicit request =>
    track(JobDetails) { implicit claim => Ok(views.html.s7_employment.g2_jobDetails(form.fillWithJobID(JobDetails, jobID))) }
  }

  def submit = claimingInJob { jobID => implicit claim => implicit request =>
    form.bindEncrypted.fold(
      formWithErrors =>{
        val form = formWithErrors.replaceError("", "lastWorkDate", FormError("lastWorkDate", "error.required"))
        BadRequest(views.html.s7_employment.g2_jobDetails(form))
      },jobDetails => claim.update(jobs.update(jobDetails)) -> Redirect(routes.G3EmployerContactDetails.present(jobID)))
  }
}<commit_msg>fixed defect - About your employment - Additional Details on your last wage -> when do you get paid message not well formatted: {0}<commit_after>package controllers.s7_employment

import language.reflectiveCalls
import play.api.mvc.Controller
import play.api.data.{FormError, Form}
import play.api.data.Forms._
import models.view.{Navigable, CachedClaim}
import models.domain.{Jobs, JobDetails}
import utils.helpers.CarersForm._
import controllers.Mappings._
import Employment._
import controllers.CarersForms._
import scala.Some
import utils.helpers.PastPresentLabelHelper._
import play.api.data.FormError
import scala.Some
import play.api.Logger

object G2JobDetails extends Controller with CachedClaim with Navigable {
  val form = Form(mapping(
    "jobID" -> nonEmptyText,
    "employerName"-> carersNonEmptyText(maxLength = 60),
    "jobStartDate" -> dayMonthYear.verifying(validDate),
    "finishedThisJob" -> nonEmptyText,
    "lastWorkDate" -> optional(dayMonthYear.verifying(validDate)),
    "p45LeavingDate" -> optional(dayMonthYear.verifying(validDateOnly)),
    "hoursPerWeek" -> optional(text(maxLength = 2).verifying(validNumber)),
    "payrollEmployeeNumber" -> optional(carersText)
  )(JobDetails.apply)(JobDetails.unapply)
    .verifying("lastWorkDate", JobDetails.validateLastWorkDate _)
  )

  def job(jobID: String) = claiming { implicit claim => implicit request =>
    claim.questionGroup(Jobs) match {
      case Some(js: Jobs) if js.job(jobID).isDefined =>
        track(JobDetails) { implicit claim => Ok(views.html.s7_employment.g2_jobDetails(form.fillWithJobID(JobDetails, jobID))) }
      case _ =>
        Redirect(routes.G1BeenEmployed.present())
    }
  }

  def present(jobID: String) = claiming { implicit claim => implicit request =>
    track(JobDetails) { implicit claim => Ok(views.html.s7_employment.g2_jobDetails(form.fillWithJobID(JobDetails, jobID))) }
  }

  def submit = claimingInJob { jobID => implicit claim => implicit request =>
    form.bindEncrypted.fold(
      formWithErrors =>{
        val pastPresent = formWithErrors("finishedThisJob").value match {
          case Some(v) => if (v.toLowerCase == no) "do you" else "did you"
          case _ => "do you"
        }
        val form = formWithErrors.replaceError("", "lastWorkDate", FormError("lastWorkDate", "error.required"))
        .replaceError("hoursPerWeek","number.invalid",FormError("hoursPerWeek","number.invalid", Seq(pastPresent)))
        BadRequest(views.html.s7_employment.g2_jobDetails(form))
      },jobDetails => claim.update(jobs.update(jobDetails)) -> Redirect(routes.G3EmployerContactDetails.present(jobID)))
  }
}
{'fraction_non_alphanumeric': 0.12157028281975517, 'fraction_numerical': 0.006542845082313212, 'mean_word_length': 4.716525934861279, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 50, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7481607', 'n_tokens_mistral': 1467, 'n_tokens_neox': 1425, 'n_words': 275}