--- /dev/null
+/*
+ * Copyright © FYLAB and the Conseil Régional d'Île-de-France, 2009
+ * This file is part of L'Interface Libre et Interactive de l'Enseignement (Lilie).
+ *
+ * Lilie is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE.txt in the directory of this software
+ * distribution.
+ *
+ * Lilie is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * and the CeCILL-C along with Lilie. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ */
+
+package org.lilie.services.eliot.applications.absences.bilan
+
+import org.lilie.services.eliot.applications.absences.statistiques.commons.StatsAbsencesParPeriode
+import org.lilie.services.eliot.absences.PreferencesEtablissementAbsences
+import org.lilie.services.eliot.scolarite.Personne
+import org.lilie.services.eliot.absences.Appel
+import org.lilie.services.eliot.absences.AbsenceJournee
+import org.lilie.services.eliot.scolarite.StructureEnseignement
+import org.lilie.services.eliot.applications.absences.PriseEnCompteMotif
+import org.lilie.services.eliot.absences.AppelLigne
+import org.lilie.services.eliot.temps.DateUtil
+import org.lilie.services.eliot.absences.PlageHoraire
+
+/**
+ * classe utilitaire pour bilanService
+ */
+class BilanUtils {
+
+ public static Double getIncrementValeur(Byte nbDemiJours,
+ Byte lastDemiJour,
+ Date currentJour,
+ Date lastJour) {
+ /**
+ * Pour une absence qui s'étale sur 2 1/2 journées (matin et après-midi),
+ * on vérifie que l'absence précédente ne date pas du matin même,
+ * auquel cas, la nouvelle absence ne compte que pour l'après-midi
+ */
+ if (nbDemiJours == 2) {
+ if (currentJour == lastJour && lastDemiJour == BilanService.MATIN) {
+ return 1
+ } else {
+ return 2
+ }
+ } else {
+ return nbDemiJours
+ }
+ }
+
+ public static StatsAbsencesParPeriode calculeCountAbsencesRetardDepart(BilanAbsencesParPersonneInfo absencesDatas,
+ PreferencesEtablissementAbsences pref,
+ StatsAbsencesParPeriode stats) {
+
+ absencesDatas.eachAbsence {
+ Personne personne, BilanAbsenceInfo info ->
+ Appel appel = info.appelLigne.appel
+ AbsenceJournee absenceJournee = info.absenceJournee
+ StructureEnseignement struct = info.structureEnseignement
+ Date dateAbsence
+
+ if (appel) {
+ dateAbsence = appel.dateHeureDebut
+ } else {
+ dateAbsence = absenceJournee.date
+ }
+
+ stats.incrementeValeur(struct, personne, dateAbsence, 1)
+ }
+ return stats
+ }
+
+ /**
+ * @return la restriction HQL pour tenir compte de la prise en compte des
+ * motifs dans les bulletins ou les stats
+ */
+ public static String getRestrictionForPriseEnCompteMotifs(
+ PriseEnCompteMotif priseEnCompteMotif
+ ) {
+ switch (priseEnCompteMotif) {
+ case PriseEnCompteMotif.BULLETIN:
+ return "and al.motif.dispoBulletin = true"
+
+ case PriseEnCompteMotif.STATS:
+ return "and al.motif.dispoStats = true"
+ }
+ return ""
+ }
+
+ /**
+ * Fait le comptage des absences en jours
+ * @return un Float
+ */
+ public static Float calculeCountJour(List appelsDatas) {
+ Date lastDay = null
+ Date currentDay = null
+ Float result = 0.0
+ Calendar cal = Calendar.getInstance()
+ appelsDatas.sort {
+ def data1, def data2 ->
+ getDateDebut(data1) <=> getDateDebut(data2)
+ }.each {
+ Appel appel = (Appel) it[1]
+ cal.clear()
+ if (appel) {
+ cal.setTime(appel.dateHeureDebut)
+ } else {
+ AbsenceJournee absenceJournee = ((AppelLigne) it[0]).absenceJournee
+ cal.setTime(absenceJournee.date)
+ }
+ DateUtil.setDebutJour(cal)
+ currentDay = cal.getTime()
+ if (cal.getTime() != lastDay) {
+ result += 1
+ }
+ lastDay = currentDay
+ }
+ return result
+ }
+
+ /**
+ * Retourne la date et heure de début d'une ligne de data
+ */
+ public static Date getDateDebut(def data) {
+ Appel appel = (Appel) data[1]
+ AppelLigne appelLigne = (AppelLigne) data[0]
+ if (appel) {
+ return appel.dateHeureDebut
+ } else {
+ return DateUtil.calculeDateHeureForDateEtHeure(
+ appelLigne.absenceJournee.date,
+ appelLigne.heureDebut
+ )
+ }
+ }
+
+ /**
+ * Calcule le nombre de plages horaires sur lesquelles porte l'absence
+ * @param plages : la liste des plages horaires de l'établissement
+ * @param appelLigne : la ligne d'absence
+ * @return un Integer
+ */
+ public static Integer calculeNbPlagesForAppelLigne(List<PlageHoraire> plages,
+ AppelLigne appelLigne) {
+ Integer count = 0
+ plages.each {
+ if (appelLigne.heureFin > it.debut && appelLigne.heureDebut < it.fin) {
+ count++
+ }
+ }
+ return count
+ }
+
+
+}