My view doesn't recognize the variables that are passed from controller to view for printing.
My flow of getting the result on view : model gives the result from db -> controller then checks them and puts them in different arrays -> on form submit, js is called and ajax is used to call the route where I get the results and then I want them to be printed in table format.
There is no issue in queries. The numbers in the response are perfect. But I can't print them on view. My view doesn't recognize the getComptage
arrays. Even var_dump(isset($_POST['rechercher']))
doesn't return anything. I've been trying to solve this for 2 days but nothing helped.
Form:
<h2 class="planning-stats-header">
<p>{!! __('planning.planning_stats_header') !!} </p>
<p>{!! __('planning.planning_stats_subheader') !!}</p>
</h2>
<form method="POST">
@csrf
<table class="table" id="table_recherche" cellpadding="5" cellspacing="5" border="0">
<tr>
<td>Date debut: </td>
<td>
<input type="text" id="datepickerdebut" name="datedebut" value="">
</td>
<td>Date Fin: </td>
<td>
<input type="text" id="datepickerfin" name="datefin">
</td>
</tr>
<tr>
<td align="center" colspan="4">
<input id="rechercher" type="button" value="Rechercher" name="rechercher">
</td>
</tr>
</table>
</form>
<div id="contenu">
<table class="table table-striped table-condensed table-hover table-responsive">
<thead>
<tr>
<th>{!! __("planning.nom") !!}</th>
<th>{!! __("planning.matin") !!}</th>
<th>{!! __("planning.midi") !!}</th>
<th>{!! __("planning.soir") !!}</th>
<th>{!! __("planning.recurrent") !!}</th>
<th>{!! __("planning.astreinte") !!}</th>
<th>{!! __("planning.intervention") !!}</th>
</tr>
</thead>
<tbody>
@foreach($req_personnes as $req_personnes)
<tr>
<td> </td>
@php
if(!isset($_POST['rechercher'])) {
for($i=0; $i<6; $i++) {
echo '<td>2</td>';
}
} else {
for($i=0; $i<6; $i++) {
echo '<td>'. $getComptageMA[$i] .'</td>';
echo '<td>'. $getComptageMI[$i] .'</td>';
echo '<td>'. $getComptageS[$i] .'</td>';
echo '<td>'. $getComptageR[$i] .'</td>';
echo '<td>'. $getComptageA[$i] .'</td>';
}
}
@endphp
</tr>
@endforeach
</tbody>
</table>
</div>
Controller :
public function getStats(Request $request) {
$calendrierObj = new Calendrier();
$utilisateurObj = new Utilisateur();
$hnoObj = new Hno();
$utilisateurs = $utilisateurObj->creeTableauSGI();
$req_personnes = $utilisateurObj->getPersonnes();
if($request->post('date_d') && $request->post('date_f')) {
$ddebut = $request->post('date_d');
$dfin = $request->post('date_f');
$interventions = $hnoObj->creeTableauInterventions($ddebut, $dfin, $utilisateurs);
$getComptageMA = [];
$getComptageMI = [];
$getComptageS = [];
$getComptageR = [];
$getComptageA = [];
$intervent = [];
for ($i=0; $i<count($utilisateurObj->getPersonnes()); $i++) {
$sgi = (string) $req_personnes[$i]->identifiant;
array_push($getComptageMA, $calendrierObj->getComptage($sgi, "MA", $ddebut, $dfin));
array_push($getComptageMI, $calendrierObj->getComptage($sgi, "MI", $ddebut, $dfin));
array_push($getComptageS, $calendrierObj->getComptage($sgi, "S", $ddebut, $dfin));
array_push($getComptageR, $calendrierObj->getComptage($sgi, "R", $ddebut, $dfin));
array_push($getComptageA, $calendrierObj->getComptage($sgi, "A", $ddebut, $dfin));
if (array_key_exists((string) $req_personnes[$i]->identifiant, $interventions)) {
array_push($intervent, $interventions['identifiant']);
}
}
return array('req_personnes' => $req_personnes, 'getComptageMA' => $getComptageMA,
'getComptageMI' => $getComptageMI, 'getComptageS' => $getComptageS,
'getComptageR' => $getComptageR, 'getComptageA' => $getComptageA,
'ddebut' => $ddebut, 'dfin' => $dfin, 'intervent' => $intervent);
}
JS:
// display current and previous date on textbox
$(document).ready(function () {
var todaydate = new Date();
var day = todaydate.getDate();
var month = todaydate.getMonth() + 1;
var year = todaydate.getFullYear();
var datestring = day + "/" + month + "/" + year;
document.getElementById("datepickerdebut").value = day-1 + "/" + month + "/" + year;
document.getElementById("datepickerfin").value = datestring;
});
$('#rechercher').click(function (e) {
var headers = {
'X-CSRF-TOKEN':'<meta name="csrf-token" content="">'
};
e.preventDefault();
e.stopPropagation();
var d = $("#datepickerdebut").val().split('/'); //dd/mm/yyyy
var debut = d[2]+'/'+d[1]+'/'+d[0];
var f = $("#datepickerfin").val().split('/');
var fin = f[2]+'/'+f[1]+'/'+f[0];
$.ajax({
url: '/planning/stats/statistique',
method: 'POST',
data:
{
myFunction: 'getStats',
date_d: debut,
date_f: fin
},
headers: headers,
dataType: 'html',
async: false,
});
});
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire