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:
<?php
namespace App\Controllers;
use \App\View\View;
use \App\Utils\Form;
use \App\Utils\ErrorLogger;
class RenseignerFraisController extends BaseController
{
public function __construct() {
parent::__construct('VISTR');
$this->mois = \App\Utils\Date::getMois(date('d/m/Y'));
$this->numAnnee = substr($this->mois, 0, 4);
$this->numMois = substr($this->mois, 4, 2);
$this->idVisiteur = \App\Utils\Session::get('idVisiteur');
}
public function index()
{
if ($this->db->estPremierFraisMois($this->idVisiteur, $this->mois)) {
$this->db->creeNouvellesLignesFrais($this->idVisiteur, $this->mois);
}
$this->lesFraisHorsForfait = $this->db->getLesFraisHorsForfait($this->idVisiteur, $this->mois);
$this->lesFraisForfait = $this->db->getLesFraisForfait($this->idVisiteur, $this->mois);
$this->vehicule = $this->db->getVehicule($this->idVisiteur, $this->mois);
View::make('renseignerFicheFrais.twig', array('erreurs' => ErrorLogger::get(),
'lesFraisForfait' => $this->lesFraisForfait,
'lesFraisHorsForfait' => $this->lesFraisHorsForfait,
'numAnnee' => $this->numAnnee,
'vehicule' => $this->vehicule,
'numMois' => $this->numMois));
}
public function deleteFrais($request)
{
$this->db->supprimerFraisHorsForfait($request['id']);
View::redirect('/frais/saisir');
}
public function updateFraisForfait()
{
if(\App\Utils\ArrayUtils::isIntArray($_POST['lesFrais'])) {
if (isset($_POST['vehicule'])) {
$req = $this->db->majFraisForfait($this->idVisiteur, $this->mois, $_POST['lesFrais'],$_POST['vehicule']);
}
else $req = $this->db->majFraisForfait($this->idVisiteur, $this->mois, $_POST['lesFrais']);
View::redirect('/frais/saisir');
} else {
ErrorLogger::add('Les valeurs des frais doivent être numériques');
$this->index();
}
}
public function createFrais()
{
if(Form::isNotEmpty($_POST, array('dateFrais', 'montant', 'libelle'))) {
$dateFrais = Form::isDate($_POST['dateFrais']);
if(\App\Utils\Date::outDated($dateFrais)) {
ErrorLogger::add("Date d'enregistrement du frais dépassé, plus de 1 an");
}
$libelle = Form::isString($_POST['libelle'], 3);
$montant = Form::isInt($_POST['montant']);
} else {
ErrorLogger::add('Toutes les données ne sont pas renseignées');
}
if(ErrorLogger::count() == 0) {
$this->db->creeNouveauFraisHorsForfait($this->idVisiteur, $this->mois, $libelle, $dateFrais, $montant);
View::redirect('/frais/saisir');
} else {
$this->index();
}
}
}