1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176:
<?php
namespace App\Controllers;
use \App\View\View;
use \App\Utils\ErrorLogger;
use \App\Utils\ArrayUtils;
use \App\Utils\Form;
class ValidationFraisController extends BaseController {
public function __construct() {
parent::__construct('CPTBL');
$this->lesVisiteurs = $this->db->getLesVisiteursAyantFichesFrais();
}
public function index() {
if (!isset($_POST['lstVisiteurs'])) {
$this->idVisiteurFinal = $this->lesVisiteurs[0]['id'];
$this->lesMois = $this->db->getLesMoisDisponibles($this->idVisiteurFinal);
$this->moisFinal = $this->lesMois[0]['mois'];
} else {
$this->idVisiteurFinal = $_POST['lstVisiteurs'];
$this->lesMois = $this->db->getLesMoisDisponibles($this->idVisiteurFinal);
$moisChoisi = $this->lesMois[0]["mois"];
for ($i = 0; $i < count($this->lesMois); $i++) {
if (in_array($_POST['lstMois'], $this->lesMois[$i])) {
$moisChoisi = $_POST['lstMois'];
}
}
$this->moisFinal = $moisChoisi;
}
$this->majFraisForfaitSucces = "";
$this->majFraisHorsForfaitSucces = "";
if (isset($_POST['corrigerForfait'])) {
$this->corrigerForfait($this->idVisiteurFinal, $this->moisFinal);
$this->majFraisForfaitSucces = "La correction du frais forfaitisé a été prise en compte";
} else if (isset($_POST['corrigerLesHorsForfait'])) {
$this->corrigerHorsForfait($this->idVisiteurFinal, $this->moisFinal);
$this->majFraisHorsForfaitSucces = "La correction du frais non forfaitisé a été prise en compte";
} else if (isset($_POST['validerNbJustificatifs'])) {
$this->validerNbJustificatifs($this->idVisiteurFinal, $this->moisFinal, $_POST['nbJustificatifs']);
} else if (isset($_POST['reporterLesHorsForfait'])) {
$this->reporterLesHorsForfait($this->idVisiteurFinal, $this->moisFinal);
}
$this->vehicule = $this->db->getVehicule($this->idVisiteurFinal, $this->moisFinal);
View::make('validationFrais.twig', array('lesMois' => $this->lesMois,
'moisASelectionner' => $this->moisFinal,
'lesVisiteurs' => $this->lesVisiteurs,
'vehicule' => $this->vehicule,
'visiteurASelectionner' => $this->idVisiteurFinal,
'lesFraisForfait' => $this->db->getLesFraisForfait($this->idVisiteurFinal, $this->moisFinal),
'lesFraisHorsForfait' => $this->db->getLesFraisHorsForfait($this->idVisiteurFinal, $this->moisFinal),
'nbJustificatifs' => $this->db->getNbjustificatifs($this->idVisiteurFinal, $this->moisFinal),
'majFraisForfaitSucces' => $this->majFraisForfaitSucces,
'erreurs' => ErrorLogger::get(),
'majFraisHorsForfaitSucces' => $this->majFraisHorsForfaitSucces
));
}
public function corrigerForfait($idVis, $mois) {
if (ArrayUtils::isIntArray($_POST['lesFrais'])) {
if (isset($_POST['vehicule'])) {
$req = $this->db->majFraisForfait($idVis, $mois, $_POST['lesFrais'],$_POST['vehicule'], 'CPTBL');
}
else $req = $this->db->majFraisForfait($idVis, $mois, $_POST['lesFrais'], 'CPTBL');
} else {
ErrorLogger::add('Les valeurs des frais doivent être numériques');
}
}
public function corrigerHorsForfait($idVis, $mois) {
if(isset($_POST['fraisHorsForfait'])) {
$lesFraisHorsForfait = $_POST['fraisHorsForfait'];
foreach ($lesFraisHorsForfait as $id => $unFraisHorsForfait) {
$date = \App\Utils\Form::isDate($unFraisHorsForfait['date']);
$date = \App\Utils\Date::FrToEng($date);
$libelle = Form::isString($unFraisHorsForfait['libelle']);
$montant = Form::isInt($unFraisHorsForfait['montant']);
if(ErrorLogger::count() == 0) {
$this->db->majFraisHorsForfait($idVis, $mois, $id, $date, $libelle, $montant);
if (isset($unFraisHorsForfait['reporter'])) {
$nvMois = \App\Utils\Date::report($mois);
if ($this->db->estPremierFraisMois($idVis, $nvMois)) {
$this->db->creeNouvellesLignesFrais($idVis, $nvMois);
}
$this->db->reporteLeHorsForfait($id, $nvMois);
}
}
}
} else {
ErrorLogger::add('Il n\'y à pas de frais hors forfait à mettre à jour');
}
View::redirect('/frais/valider');
}
public function reporterLesHorsForfait($idVis, $mois) {
if(isset($_POST['fraisHorsForfait'])) {
$lesFraisHorsForfait = $_POST['fraisHorsForfait'];
foreach ($lesFraisHorsForfait as $id => $unFraisHorsForfait) {
if (isset($unFraisHorsForfait['reporter'])) {
$nvMois = \App\Utils\Date::report($mois);
if ($this->db->estPremierFraisMois($idVis, $nvMois)) {
$this->db->creeNouvellesLignesFrais($idVis, $nvMois);
}
$this->db->reporteLeHorsForfait($id, $nvMois);
}
}
} else {
ErrorLogger::add('Il n\'y à pas de frais hors forfait à reporter');
}
View::redirect('/frais/valider');
}
public function validerNbJustificatifs($idVis, $mois, $nbJustificatifs) {
if (Form::isInt($nbJustificatifs)) {
$this->db->majNbJustificatifs($idVis, $mois, $nbJustificatifs);
}
}
}