0byt3m1n1
Path:
/
home
/
k
/
a
/
s
/
kassiope
/
www
/
administrer
/
[
Home
]
File: stats_ok.php
<?php $menu=13; include("../configuration.inc.php"); necessite_identification(); necessite_priv("admin"); /* ini_set('display_errors',1); error_reporting(E_ALL); */ $DOC_TITLE = "Rapport des ventes"; include("modeles/haut.php"); if(isset($_GET['year'])) $year = $_GET['year']; else $year = date('Y'); if(isset($_GET['priv'])) $priv = $_GET['priv']; else $priv = ''; if(isset($_GET['user'])) $user = $_GET['user']; else $user = ''; if(isset($_GET['code'])) $code = $_GET['code']; else $code = ''; if(isset($_GET['taille'])) $taille = $_GET['taille']; else $taille = ''; if(!empty($code)) $c = " and c.code_promo = '".$code."' "; else $c = ''; $sql_priv = " WHERE "; //ligne ajout $sql_priv = " , gaia_utilisateurs u where c.id_utilisateur = u.id_utilisateur and u.priv <> 'spon' and "; if(!empty($user)) $sql_priv = " , gaia_utilisateurs u where c.id_utilisateur = u.id_utilisateur and u.priv = '".$priv."' and u.id_utilisateur = '".$user."' ".$c." and "; elseif(!empty($priv)) $sql_priv = " , gaia_utilisateurs u where c.id_utilisateur = u.id_utilisateur and u.priv = '".$priv."' and "; if(!empty($code)) $sql_priv .= " c.code_promo = '".$code."' and "; if(!empty($taille)) $sql_priv .= " ca.taille = '".$taille."' and "; $firstann = 2021; $decal = date('Y')-$firstann + 1; echo '<div class="row">'; echo '<div class="col-md-3 p-3">'; for($i=0;$i<$decal;$i++) { echo '<a href="'.$_SERVER['PHP_SELF'].'?year='.($firstann+$i).'&priv='.$priv.'&user='.$user.'&taille='.$taille.'&code='.$code.'" class="years'.((($firstann+$i)==$year)?'_':'').'"> '.($firstann+$i).'</a>'; } echo '</div>'; $recTaille = mysql_query_override("SELECT * FROM gaia_tailles"); if($recTaille) { if (mysql_num_rows_override($recTaille)) { echo '<div class="col-md-3 p-3">'; echo "<select name=\"taille\" class=\"col-md-12\" onChange=\"location.href='".$_SERVER['PHP_SELF']."?'+this.value\">"; echo "<option value=\"year=".$year."\">Toutes les tailles</option>"; while($Taille = mysql_fetch_array_override($recTaille)) { echo "<option value=\"year=".$year."&priv=".$priv."&taille=".$Taille['nom_fr']."&user=".$user."&code=".$code."\""; if ($Taille['nom_fr'] == ($taille)) {echo " selected";} echo ">".stripslashes($Taille['nom_fr'])."</option>"; } echo "</select> "; echo '</div>'; } } $recCodes = mysql_query_override("SELECT * FROM gaia_codes_promos"); if($recCodes) { if (mysql_num_rows_override($recCodes)) { echo '<div class="col-md-3 p-3">'; echo "<select name=\"code\" class=\"col-md-12\" onChange=\"location.href='".$_SERVER['PHP_SELF']."?'+this.value\">"; echo "<option value=\"year=".$year."\">aucun code</option>"; while($Code = mysql_fetch_array_override($recCodes)) { echo "<option value=\"year=".$year."&priv=".$priv."&code=".$Code['nom']."&user=".$user."&taille=".$taille."\""; if ($Code['nom'] == ($code)) {echo " selected";} echo ">".stripslashes($Code['nom'])."</option>"; } echo "</select> "; echo '</div>'; } } $resProfil = mysql_query_override("SELECT * FROM gaia_profil"); if($resProfil) { if (mysql_num_rows_override($resProfil)) { echo '<div class="col-md-3 p-3">'; echo "<select name=\"profil\" class=\"col-md-12\" onChange=\"location.href='".$_SERVER['PHP_SELF']."?'+this.value\">"; echo "<option value=\"year=".$year."\">Tous les profils</option>"; while($Profil = mysql_fetch_array_override($resProfil)) { echo "<option value=\"year=".$year."&priv=".$Profil['priv']."&code=".$code."&user=".$user."&taille=".$taille."\""; if ($Profil['priv'] == vb($priv)) {echo " selected";} echo ">".stripslashes($Profil['name'])."</option>"; } echo "</select>"; echo '</div>'; } } if (isset($_GET['priv'])) { $resUser = mysql_query_override("SELECT * FROM gaia_utilisateurs where priv = '".$_GET['priv']."' order by societe, nom_famille"); if($resUser) { if (mysql_num_rows_override($resUser)) { echo '<div class="col-md-3 p-3">'; echo "<br /><select name=\"user\" class=\"col-md-12\" onChange=\"location.href='".$_SERVER['PHP_SELF']."?'+this.value\">"; echo "<option value=\"year=".$year."&priv=".$priv."&code=".$code."\">Tous les clients</option>"; while($User = mysql_fetch_array_override($resUser)) { echo "<option value=\"year=".$year."&priv=".$priv."&user=".$User['id_utilisateur']."&taille=".$taille."\""; if ($User['id_utilisateur'] == vb($user)) {echo " selected";} echo ">".(!empty($User['societe'])?mb_strtoupper(stripslashes($User['societe'])):mb_strtoupper(stripslashes($User['nom_famille'])." ".stripslashes($User['prenom'])))." (".$User['id_utilisateur'].")</option>"; } echo "</select>"; echo '</div>'; } } } echo '</div>'; $supcat = " AND pc.categorie_id in (select distinct(id) from gaia_categories where ( "; $recc = mysql_query_override("select * from gaia_categories where parent_id = 0 order by position, nom_fr"); $cpt = 0; while ($allcat = mysql_fetch_array_override($recc)) { if($cpt>0) $supcat .= " or "; $supcat .= " parent_id = '".$allcat['id']."' "; $cpt++; } $supcat .= "))"; //################################################################# //################################################################# // STATISTIQUES GLOBALES $url = " select sum(c.total_produit DIV 1.2) as tot_ht, sum(c.total_produit) as tot_ttc, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume from gaia_commandes c, gaia_commandes_articles ca, gaia_produits_categories pc ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = pc.produit_id and (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') and o_timestamp like "; //$url = " select sum(montant_ht) as tot_ht from gaia_commandes c ".$sql_priv." (statut = '3' or statut = '5' or statut = '8') and o_timestamp like "; $url = "select sum(c.total_produit)/1.2 / count(ca.id) as tot_ht, sum(c.total_produit) / count(ca.id) as tot_ttc, sum(ca.marge)/1.2 - sum(remise_produit_ht + remise_client_ht + remise_code_ht + remise_cheque_ht + remise_bon_ht) / count(ca.id) as marge_ht, sum(ca.quantite) as volume FROM gaia_commandes c, gaia_commandes_articles ca, gaia_produits_categories pc ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = pc.produit_id and (statut = '3' or statut = '5' or statut = '8') and o_timestamp like "; //echo $url. "2014-07%"; $url = "select sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.remise_produit DIV 1.2) as reduc, sum(ca.quantite) as volume FROM gaia_commandes c, gaia_commandes_articles ca, gaia_produits_categories pc ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = pc.produit_id and (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') ".$supcat." and o_timestamp like "; ?> <table width="100%" border="0" class="tablespace"> <tr><th class="entete" align="center"><div style="float:left">Statistiques globales de ventes</div> <div style="float:right;margin-right:10px"><a href="stats_export.php?type=global&<?='year='.$year.'&priv='.$priv.'&user='.$user.'&taille='.$taille.'&code='.$code?>" style="color:#fff; font-size:12px">Export Excel</a> </div></th></tr> </table> <table width="100%" border="0" class="tablespace stats"> <?=return_stat($url, '', 0, 1)?> </table> <? //################################################################# //################################################################# // STATISTIQUES GAMMES ?> <table width="100%" border="0" class="tablespace"> <tr><th class="entete" align="center"><div style="float:left">Statistiques de ventes par gammes</div> <div style="float:right;margin-right:10px"><a href="stats_export.php?type=gamme&<?='year='.$year.'&priv='.$priv.'&user='.$user.'&taille='.$taille.'&code='.$code?>" style="color:#fff; font-size:12px">Export Excel</a> </div></th></tr> </table> <table width="100%" border="0" class="tablespace stats"> <? $recc = mysql_query_override("select * from gaia_categories where parent_id = 0 order by position, nom_fr"); while ($allcat = mysql_fetch_array_override($recc)) { $recsous = mysql_query_override("select c.* from gaia_categories c, gaia_produits_categories pc where pc.categorie_id = c.id and c.parent_id = '".$allcat['id']."' group by c.id order by c.position, c.nom_fr"); if(mysql_num_rows_override($recsous)>0) { echo recup_cat_stat($allcat['id'], 0); while ($allcatsous = mysql_fetch_array_override($recsous)) { echo recup_cat_stat($allcatsous['id'], 1); } } } echo '</table>'; //################################################################# //################################################################# //################################################################# // STATISTIQUES PAR PRODUITS ?> <table width="100%" border="0" class="tablespace"> <tr><th class="entete" align="center"><div style="float:left">Statistiques de ventes par produits</div> <div style="float:right;margin-right:10px"><a href="stats_export.php?type=produit&<?='year='.$year.'&priv='.$priv.'&user='.$user.'&taille='.$taille.'&code='.$code?>" style="color:#fff; font-size:12px">Export Excel</a> </div></th></tr> </table> <table width="100%" border="0" class="tablespace stats"> <? $recc = mysql_query_override("select sum(ca.prix), ca.produit_id, ca.nom_produit as nom_fr from gaia_commandes_articles ca, gaia_commandes c ".$sql_priv." ca.commande_id = c.id AND (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') and o_timestamp like '".$year."%' group by ca.produit_id order by sum(ca.prix) desc"); //$recc = mysql_query_override("select * from gaia_produits"); while ($allcat = mysql_fetch_array_override($recc)) { $totca = $totcaold = 0; $entete = $encaisse = $ca = $caold = $progress = ''; $url = " select sum(ca.total_prix_ht) as tot_ht, sum(ca.total_prix) as tot_ttc, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume from gaia_commandes c, gaia_commandes_articles ca ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = ".$allcat['produit_id']." AND (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') and o_timestamp like "; echo return_stat($url, $allcat['nom_fr'], 0); } echo '</table>'; //################################################################# include("modeles/bas.php"); //################################################################# //################################################################# // FUNCTIONS function recup_cat_stat($id, $t) { global $sql_priv, $year; $totca = $totmarge = $totcaold = $totmargeold = 0; $entete = $marge = $totalmarge = $encaisse = $ca = $caold = $margeold = $progress = ''; $cat = mysql_query_override("select * from gaia_categories where id = '".$id."'"); $allcat = mysql_fetch_array_override($cat); /* $url = " select sum(ca.total_prix_ht) as tot_ht, sum(ca.total_prix) as tot_ttc, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume from gaia_commandes c, gaia_commandes_articles ca, gaia_produits_categories pc ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = pc.produit_id AND pc.categorie_id in (select distinct(id) from gaia_categories where parent_id = '".$id."') AND (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') and o_timestamp like "; if ($t>0) $url = " select sum(ca.total_prix_ht) as tot_ht, sum(ca.total_prix) as tot_ttc, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume from gaia_commandes c, gaia_commandes_articles ca, gaia_produits_categories pc ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = pc.produit_id AND pc.categorie_id = '".$id."' AND (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') and o_timestamp like "; */ $url = " select sum(ca.total_prix_ht) as tot_ht, sum(ca.total_prix) as tot_ttc, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume from gaia_commandes c, gaia_commandes_articles ca, gaia_produits p ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = p.id AND p.defcat in (select distinct(id) from gaia_categories where parent_id = '".$id."') AND (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') and o_timestamp like "; if ($t>0) $url = " select sum(ca.total_prix_ht) as tot_ht, sum(ca.total_prix) as tot_ttc, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume from gaia_commandes c, gaia_commandes_articles ca, gaia_produits p ".$sql_priv." c.id = ca.commande_id AND ca.produit_id = p.id AND p.defcat = '".$id."' AND (statut = '2' or statut = '3' or statut = '5' or statut = '8' or statut = '10' or statut = '11' or statut = '12' or statut = '13' or statut = '14') and o_timestamp like "; return return_stat($url, $allcat['nom_fr'], $t); } function return_stat($url, $nom, $t, $global=0) { global $sql_priv, $year; $totca = $totmarge = $totcaold = $totmois = $totmargeold = $totvolume = $totvolumeold = 0; $entete = $marge = $totalmarge = $volume = $totalvolume = $encaisse = $ca = $caold = $margeold = $volumeold = $progress = ''; for($i=1;$i<13;$i++) { $entete .= '<td class="stats menu" align="center">'.substr('0'.$i,-2,2).'/'.$year.'</td>'; //################################ //####### ANNEE EN COURS ######### //if($global==1 && $i==9) echo $url." '".$year."-".substr('0'.$i,-2,2)."%' group by c.id " . (($global==1)?', pc.produit_id':''); $reccom = mysql_query_override($url." '".$year."-".substr('0'.$i,-2,2)."%' group by c.id "); $tot_ht = $marge_ht = $cvolume = 0; while($ta = mysql_fetch_array_override($reccom)) { $tot_ht += $ta['tot_ht']; $marge_ht += $ta['marge_ht']; $cvolume += $ta['volume']; } if($year.'-'.substr('0'.$i,-2,2)>date('Y-m')) $totfrais = $totfraisold = 0; //### Calcul encaissé ### if($year.'-'.substr('0'.$i,-2,2)<=date('Y-m')) $totmois = $tot_ht; else $totmois = $totca = 0; $encaisse .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'>'.number_format($totmois,2,'.',' ').'</td>'; //### Calcul marge ### if($year.'-'.substr('0'.$i,-2,2)<=date('Y-m')) $totmargemois = $marge_ht; else $totmargemois = $totmarge = 0; $marge .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'>'.number_format($totmargemois,2,'.',' ').'</td>'; //### Calcul cumul marge ### $totmarge += $marge_ht; $totalmarge .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'><b>'.number_format($totmarge-$totfrais,2,'.',' ').'</b></td>'; //### Calcul volume ### if($year.'-'.substr('0'.$i,-2,2)<=date('Y-m')) $totvolumemois = (!empty($cvolume)?$cvolume:0); else $totvolumemois = $totvolume = 0; $volume .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'>'.($totvolumemois).'</td>'; //### Calcul cumul volume ### $totvolume += $cvolume; $totalvolume .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'><b>'.($totvolume).'</b></td>'; //### Calcul ca ht ### $totca += $totmois; $ca .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'><b>'.number_format($totca,2,'.',' ').'</b></td>'; //################################## //####### ANNEE PRECEDENTE ######### $recoldcom = mysql_query_override($url." '".($year-1)."-".substr('0'.$i,-2,2)."%' group by c.id "); $tot_old_ht = $marge_old_ht = $volume_old = 0; while($ta = mysql_fetch_array_override($recoldcom)) { $tot_old_ht += $ta['tot_ht']; $marge_old_ht += $ta['marge_ht']; $volume_old += $ta['volume']; } //### Calcul ca ht n-1 ### $totcaold += $tot_old_ht; $caold .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'><span>'.number_format($tot_old_ht,2,'.',' ').'</span><br/>'.number_format($totcaold,2,'.',' ').'</td>'; //### Calcul marge n-1 ### $totmargeold += $marge_old_ht; $margeold .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'><span>'.number_format($marge_old_ht,2,'.',' ').'</span><br/>'.number_format($totmargeold-$totfraisold,2,'.',' ').'</td>'; //### Calcul volume n-1 ### $totvolumeold += $volume_old; $volumeold .= '<td align="center" '.(($year.'-'.substr('0'.$i,-2,2)==date('Y-m'))?'class="curr"':'').'><span>'.(!empty($volume_old)?$volume_old:0).'</span><br/>'.($totvolumeold).'</td>'; //### Calcul progression mois ### $pourc = 0; if($year.'-'.substr('0'.$i,-2,2)<=date('Y-m')) { if($tot_ht - $tot_old_ht==0) $pourc = 0; elseif($totmois==0) $pourc = -100; else { $ecart = $totmois - $tot_old_ht; $pourc = number_format($ecart * 100 / $totmois,2,'.',''); } } $progress .= '<td align="center" class="'.(($pourc>0)?'text-success':'text-danger').'"><i class="fa fa-arrow-'.(($pourc<0)?'down':($pourc>0)?'up':'right').'"></i><br />'.$pourc.' %</td>'; //################################## //################################## } $ret = ' <tr><td class="menu" align="center" style="padding:5px;'.(($t==0)?'background:#333;color:#FFF;text-transform: uppercase;':'').'"><b>'.stripslashes($nom).'</b></td>'.$entete.'</tr> <tr><td class="menu" align="center" style="padding:5px">C.A.</td>'.$encaisse.'</tr> <tr><td class="menu" align="center" style="padding:5px">CUMUL</td>'.$ca.'</tr> <!--<tr><td class="menu" align="center" style="padding:5px">MARGE</td>'.$marge.'</tr> <tr><td class="menu" align="center" style="padding:5px">CUMUL</td>'.$totalmarge.'</tr>--> <tr><td class="menu" align="center" style="padding:5px">VOLUME</td>'.$volume.'</tr> <tr><td class="menu" align="center" style="padding:5px">CUMUL</td>'.$totalvolume.'</tr> <tr><td class="menu" align="center" style="padding:5px">C.A. (n-1)</td>'.$caold.'</tr> <!--<tr><td class="menu" align="center" style="padding:5px">MARGE (n-1)</td>'.$margeold.'</tr>--> <tr><td class="menu" align="center" style="padding:5px">VOLUME (n-1)</td>'.$volumeold.'</tr> <tr><td class="menu" align="center" style="padding:5px">Progression</td>'.$progress.'</tr> '; return $ret; } ?>