def getProjectsEligibleForStatusChange()

in app/models/ProjectEntry.scala [252:294]


  def getProjectsEligibleForStatusChange(newStatus: EntryStatus.Value, commissionId: Int): DBIO[Seq[(Int, ProjectEntry)]] = {
    import EntryStatusMapper._

    def getProjects(query: Query[ProjectEntryRow, ProjectEntry, Seq]) = {
      query.result.map(projects => projects.map(p => (p.id.getOrElse(-1), p)))
    }

    val baseQuery = TableQuery[ProjectEntryRow].filter(_.commission === commissionId)

    newStatus match {
      case EntryStatus.Completed =>
        // All projects NOT Completed or Killed should be set to Completed
        val filteredQuery = baseQuery.filter(p => 
          p.status =!= EntryStatus.Completed && 
          p.status =!= EntryStatus.Killed
        )
        getProjects(filteredQuery)

      case EntryStatus.Killed =>
        // All projects NOT Completed or Killed should be set to Killed
        val filteredQuery = baseQuery.filter(p => 
          p.status =!= EntryStatus.Completed && 
          p.status =!= EntryStatus.Killed
        )
        getProjects(filteredQuery)

      case EntryStatus.Held =>
        // All projects NOT Completed, Killed or Held should be set to Held
        val filteredQuery = baseQuery.filter(p => 
          p.status =!= EntryStatus.Completed && 
          p.status =!= EntryStatus.Killed &&
          p.status =!= EntryStatus.Held
        )
        getProjects(filteredQuery)

      case EntryStatus.InProduction =>
        // No changes needed for In Production
        DBIO.successful(Seq.empty[(Int, ProjectEntry)])

      case _ => 
        DBIO.successful(Seq.empty[(Int, ProjectEntry)])
    }
  }