[RESOLU] Aide Tableau et calcul en PHP

Eléphanteau du PHP | 19 Messages

24 janv. 2015, 04:26

Bonjour,

Je dois modifier une application PHP et BD SQL Server 2008 a travers laquelle on liste le retour des matériels des techniciens (Numéro de série - Article - Date de récupération - Jours de possession) et je voudrai rajouter une colonne Frais de retards (pour les tech qui ne ramènent pas les matériels afin de les inciter a vite ramener...).

Ci-dessus un aperçu de l’interface PHP a modifier:

Code : Tout sélectionner

Numéro de série Article Date de récupération Jours de possession 073G457XVW97 22973 2015-01-14 142 200858414 22973 2014-09-03 9 S8D260979 34058 2015-01-18 5

Pour la colonne frais de retards a rajouter, l’idée est daller avec une date de reference de sorte que pour la 1ere ligne ca sera INV (en inventaire), pour la 2eme 10$ et pour la 3eme 0$. Donc la pénalité est de 10$/semaine, facturée chaque 8eme jour... Aussi j’aimerai afficher le total des frais...

Ci-joint mon script PHP:
<?php 
	$userToCheck = $_SESSION['user']['selected'];

	$appareils = appareil::getAppareils(CODE_STATUT_RECUPERATION, $userToCheck); 
?>
<h1><?php echo TXT_RECUPERATION; ?></h1>

<legend><?php echo TXT_A_RETOURNER; ?></legend>
<?php if(count($appareils) >= 1){ ?>
<table class="table table-striped table-hover" style="width:100%">
	<thead>
		<tr>
			<th><?php echo TXT_NUMERO_SERIE; ?></th>
			<th><?php echo TXT_ARTICLE; ?></th>
			<th style="text-align:center">Date de récupération</th>
			<th style="text-align:center"><?php echo TXT_NB_JOURS_POSSESSION; ?></th>
			<th style="text-align:center"><?php echo TXT_TOTAL_PERCU; ?></th>
		</tr>
	</thead>
	<tbody>
		<?php foreach($appareils as $appareil){
			$d = new discussion();
			$d->loadDiscussion($userToCheck, $appareil->numeroSerie);

			$button = '+';
			if(sizeof($d->commentaires) > 0){
				$button = sizeof($d->commentaires);
				if($d->nbCommentairesNonLus > 0){
					$button.= ' ('.$d->nbCommentairesNonLus.')';
				}
			}

			if($appareil->nbJours > 14){
				echo '<tr class="error">';
			}else{
				echo '<tr>';
			}
			echo '<td>'.$appareil->numeroSerie.'</td>';
			echo '<td>'.$appareil->article.'</td>';
			echo '<td style="text-align:center">'; echo date('Y-m-d', strtotime($appareil->dlocalisation)); 
				if($appareil->nbJours > 14){
					echo '<i style="position: absolute;margin: 3px 0px 0px 5px;"class="icon-warning-sign"></i>';
				}
				echo '</td>';
			echo '<td style="text-align:center">'.$appareil->nbJours.'</td>';
			echo '<td style="text-align:center"><a href="./?page=4&numeroSerie='.$appareil->numeroSerie.'" class="btn btn-primary" style="width:50px">'.$button.'</a></td>';
			echo '</tr>';
		}?>
	</tbody>
</table>
<?php }else{ echo '<p style="text-align:center;width:100%">Aucun appareil à retourner</p>'; } ?>
<?php $appareils = appareil::getAppareilsFromHisto(CODE_STATUT_AFFI, $userToCheck); ?>
<legend><?php echo TXT_RETOURNE; ?></legend>
<table class="table table-striped table-hover" style="width:100%">
	<thead>
		<tr>
			<th><?php echo TXT_NUMERO_SERIE; ?></th>
			<th style="text-align:center">Date de retour</th>
			<!-- <th style="text-align:center"><?php echo TXT_NB_JOURS_RETOURNE; ?></th> -->
		</tr>
	</thead>
	<tbody>
		<?php 
			foreach($appareils as $appareil){
				if($appareil->nbJours <= 30){
					echo '<tr>';
					echo "<td>$appareil->numeroSerie</td>";
					echo "<td style=\"text-align:center\">". date('Y-m-d', strtotime($appareil->dlocalisation)) . "</td>";
					//echo "<td style=\"text-align:center\">$appareil->nbJours</td>";
					echo '</tr>';
				}
			}
		?>
	</tbody>
</table>
Je n’ai aucune idée par ou commencer (tableau, ...., innerHTML...)...
Je débute en PHP et je sollicite votre concours, merci d’avance.

Eléphanteau du PHP | 19 Messages

25 janv. 2015, 17:10

Bonjour,

Ci-joint ma version 1 implémente, mais erronée car j’ai un soucis avec mes dates:

Numéro de série Article Date de récupération Jours de possession Frais de retards

073G457XVW97 22973 2015-01-14 142 2031629140 $
200858414 22973 2014-09-03 9 2031629140 $
S8D260979 34058 2015-01-18 5 2031629140 $

Total: 6094887420 $

Et mon code:

<?php
$userToCheck = $_SESSION['user']['selected'];

$appareils = appareil::getAppareils(CODE_STATUT_RECUPERATION, $userToCheck);
?>
<h1><?php echo TXT_RECUPERATION; ?></h1>

<legend><?php echo TXT_A_RETOURNER; ?></legend>
<?php if(count($appareils) >= 1){ ?>
<table class="table table-striped table-hover" style="width:100%">
<thead>
<tr>
<th><?php echo TXT_NUMERO_SERIE; ?></th>
<th><?php echo TXT_ARTICLE; ?></th>
<th style="text-align:center">Date de récupération</th>
<th style="text-align:center"><?php echo TXT_NB_JOURS_POSSESSION; ?></th>
<th style="text-align:center">Frais de retards</th>
</tr>
</thead>
<tbody>
<?php
$fraisTotal=0;
foreach($appareils as $appareil){

$joursCpt; //Jours comptabilises
$nbSemaines; //nombres de semaines correspondantes aux frais de retards
$fraisSemaine=10; //Frais de retards fixes a 10/semaine
$nbJoursInv = $appareil->nbJoursInv;
$today = date("Y-m-d");
$dateInv= strtotime('2014-11-22');
$frais;

if($appareil->nbJours > 7){
echo '<tr class="error">';
}else{
echo '<tr>';
}
echo '<td>'.$appareil->numeroSerie.'</td>';
echo '<td>'.$appareil->article.'</td>';
echo '<td style="text-align:center">'; echo date('Y-m-d', strtotime($appareil->dlocalisation));

if($appareil->nbJours > 7){
echo '<i style="position: absolute;margin: 3px 0px 0px 5px;"class="icon-warning-sign"></i>';
}
echo '</td>';
echo '<td style="text-align:center">'.$appareil->nbJours.'</td>';

if($appareil->dlocalisation < $dateInv){
$joursCpt = strtotime($today) - strtotime($dateInv);
//$joursCpt = $today->diff($dateInv);
}
else {
//$joursCpt = $today - $appareil->dlocalisation;
//$joursCpt = $today->diff($appareil->dlocalisation);
//$joursCpt = strtotime($today) - strtotime($appareil->dlocalisation);
}

if($joursCpt>7){

if($joursCpt%7 !=0){

$nbSemaines = floor($joursCpt/7);
}
else {
$nbSemaines = ($joursCpt/7)-1;

}
}
else {
$nbSemaines = 0;

}

$frais= $fraisSemaine*$nbSemaines;
$fraisTotal +=$frais;


echo '<td style="text-align:center">'.$frais.' '.'$'.'</td>';

echo '</tr>';

}
echo '<tr>';
echo '<td style="text-align:center"></td>';
echo '<td style="text-align:center"></td>';
echo '<td style="text-align:center"></td>';
echo '<td style="text-align:center"></td>';
echo '<td style="text-align:center">'.'Total:'.' '.$fraisTotal.' '.'$'.'</td>';
echo '</tr>';?>
</tbody>
</table>
<?php }else{ echo '<p style="text-align:center;width:100%">Aucun appareil à retourner</p>'; } ?>

Merci de m’aider SVP.
Cordialement.

Eléphanteau du PHP | 19 Messages

27 janv. 2015, 16:51

Je viens de resoudre, merci.