0byt3m1n1
Path:
/
home
/
k
/
a
/
s
/
kassiope
/
www
/
administrer
/
[
Home
]
File: stats_prod_ok.php
<?php include("../configuration.inc.php"); necessite_identification(); necessite_priv("admin"); $DOC_TITLE = "Rapport des ventes"; include("modeles/haut.php"); $nowDay = date("d"); $nowMonth = date("m"); $nowYear = date("Y"); if ($nowMonth=="1") $nowMonth = "Janvier"; if ($nowMonth=="2") $nowMonth = "Février"; if ($nowMonth=="3") $nowMonth = "Mars"; if ($nowMonth=="4") $nowMonth = "Avril"; if ($nowMonth=="5") $nowMonth = "Mai"; if ($nowMonth=="6") $nowMonth = "Juin"; if ($nowMonth=="7") $nowMonth = "Juillet"; if ($nowMonth=="8") $nowMonth = "Août"; if ($nowMonth=="9") $nowMonth = "Septembre"; if ($nowMonth=="10") $nowMonth= "Octobre"; if ($nowMonth=="11") $nowMonth= "Novembre"; if ($nowMonth=="12") $nowMonth= "Décembre"; if(isset($_GET['mois1']) and $_GET['mois1'] =="Janvier") $_GET['mois1']=1; if(isset($_GET['mois1']) and $_GET['mois1'] =="Février") $_GET['mois1']=2; if(isset($_GET['mois1']) and $_GET['mois1'] =="Mars") $_GET['mois1']=3; if(isset($_GET['mois1']) and $_GET['mois1'] =="Avril") $_GET['mois1']=4; if(isset($_GET['mois1']) and $_GET['mois1'] =="Mai") $_GET['mois1']=5; if(isset($_GET['mois1']) and $_GET['mois1'] =="Juin") $_GET['mois1']=6; if(isset($_GET['mois1']) and $_GET['mois1'] =="Juillet") $_GET['mois1']=7; if(isset($_GET['mois1']) and $_GET['mois1'] =="Août") $_GET['mois1']=8; if(isset($_GET['mois1']) and $_GET['mois1'] =="Septembre") $_GET['mois1']=9; if(isset($_GET['mois1']) and $_GET['mois1'] =="Octobre") $_GET['mois1']=10; if(isset($_GET['mois1']) and $_GET['mois1'] =="Novembre") $_GET['mois1']=11; if(isset($_GET['mois1']) and $_GET['mois1'] =="Décembre") $_GET['mois1']=12; if(isset($_GET['mois2']) and $_GET['mois2'] =="Janvier") $_GET['mois2']=1; if(isset($_GET['mois2']) and $_GET['mois2'] =="Février") $_GET['mois2']=2; if(isset($_GET['mois2']) and $_GET['mois2'] =="Mars") $_GET['mois2']=3; if(isset($_GET['mois2']) and $_GET['mois2'] =="Avril") $_GET['mois2']=4; if(isset($_GET['mois2']) and $_GET['mois2'] =="Mai") $_GET['mois2']=5; if(isset($_GET['mois2']) and $_GET['mois2'] =="Juin") $_GET['mois2']=6; if(isset($_GET['mois2']) and $_GET['mois2'] =="Juillet") $_GET['mois2']=7; if(isset($_GET['mois2']) and $_GET['mois2'] =="Août") $_GET['mois2']=8; if(isset($_GET['mois2']) and $_GET['mois2'] =="Septembre") $_GET['mois2']=9; if(isset($_GET['mois2']) and $_GET['mois2'] =="Octobre") $_GET['mois2']=10; if(isset($_GET['mois2']) and $_GET['mois2'] =="Novembre") $_GET['mois2']=11; if(isset($_GET['mois2']) and $_GET['mois2'] =="Décembre") $_GET['mois2']=12; $days1 = array("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"); $months1 = array("1"=>"Janvier","2"=>"Février","3"=>"Mars","4"=>"Avril","5"=>"Mai","6"=>"Juin","7"=>"Juillet","8"=>"Août","9"=>"Septembre","10"=>"Octobre","11"=>"Novembre","12"=>"Décembre"); //$years1 = array("2005","2006","2007","2008","2009","2010"); $firstann = 2009;$decal = date('Y')-$firstann +1; $years1 = array(); for($i=0;$i<$decal;$i++) { $years1[] = $firstann+$i; } echo "<table width=\"100%\" border=\"0\" class=\"tablespace\">"; echo "<tr><th class=\"entete\" align=\"center\" colspan=\"4\">Résumé des ventes</th></tr>"; echo "<tr><td class=\"menu\" align=\"center\" colspan=\"4\">Aujourd'hui : ".date("d M Y")."</td></tr>"; echo "<form method=\"GET\" action=\"".$_SERVER['PHP_SELF']."\">"; echo "<tr>"; echo "<td>"; echo "<b>DU</b>: "; //AFFICHE LES JOURS 1 echo "<select name=\"jour1\" class=\"input-small\">"; for ($c=0; $c<= count($days1)-1; $c++) { $a=$c+1; if(isset($_GET['jour1'])) { if($days1[$c]== $_GET['jour1']) $sel1 = "selected"; else $sel1=""; } else { if($days1[$c]==$nowDay) $sel1 = "selected"; else $sel1=""; } echo "<option value=$a $sel1>$days1[$c]</option>"; } echo "</select>"; // AFFICHE LA LISTE DES MOIS 1 echo "<select name=\"mois1\" class=\"input-small\">"; $keys = array_keys($months1); for ($x1=1; $x1 <= count($months1); $x1++) { $p=$x1-1; if(isset($_GET['mois1'])) { if($keys[$p]== $_GET['mois1']) $sel2 = "selected"; else $sel2=""; } else { if($months1[$x1]==$nowMonth) $sel2 = "selected"; else $sel2=""; } echo "<option value=".$keys[$p]." $sel2>$months1[$x1]</option>"; } echo "</select>"; // AFFICHE LA LISTE DES ANNéES 1 echo "<select name=\"an1\" class=\"input-small\">"; for ($x3=0; $x3 <= count($years1)-1; $x3++) { if(isset($_GET['an1'])) { if($years1[$x3]== $_GET['an1']) $sel3 = "selected"; else $sel3=""; } else { if($years1[$x3]==$nowYear-1) $sel3 = "selected"; else $sel3=""; } echo "<option value=$years1[$x3] $sel3>$years1[$x3]</option>"; } echo "</select>"; echo "</td>"; echo "<td>"; echo "<b>AU</b>: "; //AFFICHE LES JOURS 2 echo "<select name=\"jour2\" class=\"input-small\">"; for ($c=0; $c<= count($days1)-1; $c++) { $a=$c+1; if(isset($_GET['jour2'])) { if($days1[$c]== $_GET['jour2']) $sel1 = "selected"; else $sel1=""; } else { if($days1[$c]==$nowDay) $sel1 = "selected"; else $sel1=""; } echo "<option value=$a $sel1>$days1[$c]</option>"; } echo "</select>"; // AFFICHE LA LISTE DES MOIS 2 echo "<select name=\"mois2\" class=\"input-small\">"; $keys = array_keys($months1); for ($x=1; $x <= count($months1); $x++) { $p=$x-1; if(isset($_GET['mois2'])) { if($keys[$p]== $_GET['mois2']) $sel2 = "selected"; else $sel2=""; } else { if($months1[$x]==$nowMonth) $sel2 = "selected"; else $sel2=""; } echo "<option value=$keys[$p] $sel2>$months1[$x]</option>"; } echo "</select>"; // AFFICHE LA LISTE DES ANNéES 2 echo "<select name=\"an2\" class=\"input-small\">"; for ($x=0; $x <= count($years1)-1; $x++) { if(isset($_GET['an2'])) { if($years1[$x]== $_GET['an2']) $sel3 = "selected"; else $sel3=""; } else { $n=$x3+1; if($years1[$x]==$nowYear) $sel3 = "selected"; else $sel3=""; } echo "<option $sel3>$years1[$x]</option>"; } echo "</select>"; echo "</td>"; echo '<td><input type="submit" name="send" value" OK">'; echo '</tr>'; echo '<tr><td colspan="2">'; 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 "; $recTaille = mysql_query_override("SELECT * FROM gaia_tailles"); if($recTaille) { if (mysql_num_rows_override($recTaille)) { echo "<select name=\"taille\" class=\"formulaire1\" style=\"width:150px\">"; echo "<option value=\"\">Toutes les tailles</option>"; while($Taille = mysql_fetch_array_override($recTaille)) { echo "<option value=\"".$Taille['nom_fr']."\""; if ($Taille['nom_fr'] == ($taille)) {echo " selected";} echo ">".stripslashes($Taille['nom_fr'])."</option>"; } echo "</select> "; } } $recCodes = mysql_query_override("SELECT * FROM gaia_codes_promos"); if($recCodes) { if (mysql_num_rows_override($recCodes)) { echo "<select name=\"code\" class=\"formulaire1\" style=\"width:150px\">"; echo "<option value=\"\">aucun code</option>"; while($Code = mysql_fetch_array_override($recCodes)) { echo "<option value=\"".$Code['nom']."\""; if ($Code['nom'] == ($code)) {echo " selected";} echo ">".stripslashes($Code['nom'])."</option>"; } echo "</select> "; } } $resProfil = mysql_query_override("SELECT * FROM gaia_profil"); if($resProfil) { if (mysql_num_rows_override($resProfil)) { echo "<select name=\"priv\" class=\"formulaire1\" style=\"width:150px\">"; echo "<option value=\"\">Tous les profils</option>"; while($Profil = mysql_fetch_array_override($resProfil)) { echo "<option value=\"".$Profil['priv']."\""; if ($Profil['priv'] == vb($priv)) {echo " selected";} echo ">".stripslashes($Profil['name'])."</option>"; } echo "</select>"; } } if (isset($_GET['priv'])) { if($_GET['priv']=='reve') $ord = 'societe'; else $ord = 'nom_famille'; $resUser = mysql_query_override("SELECT * FROM gaia_utilisateurs where priv = '".$priv."' order by ".$ord); if($resUser) { if (mysql_num_rows_override($resUser)) { echo " <select name=\"user\" class=\"formulaire1\" style=\"width:150px\">"; echo "<option value=\"\">Tous les clients</option>"; while($User = mysql_fetch_array_override($resUser)) { echo "<option value=\"".$User['id_utilisateur']."\""; if ($User['id_utilisateur'] == vb($user)) {echo " selected";} if($_GET['priv']=='reve') $us = mb_strtoupper(stripslashes($User['societe'])); else $us = mb_strtoupper(stripslashes($User['nom_famille'])." ".stripslashes($User['prenom'])); echo ">".$us." (".$User['id_utilisateur'].")</option>"; } echo "</select>"; } } } echo '</td></tr>'; echo '</table>'; $firstann = 2009; if(isset($_GET['jour1']) or isset($dateAdded1)) { //################################################################# //################################################################# //STATISTIQUES GLOBALES /*$url = " select sum(ca.total_prix_ht) as tot_ht, 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 = '3' or statut = '5' or statut = '8') and o_timestamp between ";*/ $supcat = " AND p.defcat 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 .= "))"; $url = "select sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc FROM gaia_commandes c, gaia_commandes_articles ca, gaia_produits p, gaia_categories cat ".$sql_priv." cat.id = p.defcat and c.id = ca.commande_id AND ca.produit_id = p.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 between ";?> <table width="100%" border="0" class="tablespace"> <tr><th class="entete" align="center">Statistiques globales de ventes</th></tr> </table> <table width="100%" border="0" class="tablespace stats"> <tr> <td class="menu" align="center" style="padding:5px">C.A.</td> <td class="menu" align="center" style="padding:5px">Marge</td> <td class="menu" align="center" style="padding:5px">Volume</td> <td class="menu" align="center" style="padding:5px">C.A. (n-1)</td> <td class="menu" align="center" style="padding:5px">Marge (n-1)</td> <td class="menu" align="center" style="padding:5px">Volume (n-1)</td> <td class="menu" align="center" style="padding:5px">Progression</td> </tr> <?=return_stat($url,'', 0, 1)?> </table> <? //################################################################# //################################################################# //################################################################# // RECAP TOP 5 $supcat = " AND p.defcat 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 .= "))"; //######################################### // PRODUITS $url = "select nom_produit, sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc FROM gaia_commandes c, gaia_categories cat, gaia_commandes_articles ca, gaia_produits p ".$sql_priv." cat.id = p.defcat and c.id = ca.commande_id AND ca.produit_id = p.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 between '".$_GET['an1']."-".substr('0'.$_GET['mois1'],-2,2)."-".substr('00'.$_GET['jour1'],-2,2)."' and '".$_GET['an2']."-".substr('0'.$_GET['mois2'],-2,2)."-".substr('00'.$_GET['jour2'],-2,2)."' group by p.id order by tot_ht desc limit 0,5"; $s = mysql_query_override($url); $cpt=0; while($d = mysql_fetch_array_override($s)) { $val[$cpt][] = $d['nom_produit']; $ca[$cpt][] = $d['tot_ht']; $volume[$cpt][] = $d['volume']; $cpt++; } //######################################### // CATEGORIES $url = "select cat.nom_fr as catname, sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc FROM gaia_commandes c, gaia_categories cat, gaia_commandes_articles ca, gaia_produits p ".$sql_priv." cat.id = p.defcat and c.id = ca.commande_id AND ca.produit_id = p.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 between '".$_GET['an1']."-".substr('0'.$_GET['mois1'],-2,2)."-".substr('00'.$_GET['jour1'],-2,2)."' and '".$_GET['an2']."-".substr('0'.$_GET['mois2'],-2,2)."-".substr('00'.$_GET['jour2'],-2,2)."' group by cat.id order by tot_ht desc limit 0,5"; $s = mysql_query_override($url); $cpt=0; while($d = mysql_fetch_array_override($s)) { $val[$cpt][] = $d['catname']; $ca[$cpt][] = $d['tot_ht']; $volume[$cpt][] = $d['volume']; $cpt++; } //######################################### // TAILLES $url = "select taille, sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc FROM gaia_commandes c, gaia_categories cat, gaia_commandes_articles ca, gaia_produits p ".$sql_priv." cat.id = p.defcat and c.id = ca.commande_id AND ca.produit_id = p.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 between '".$_GET['an1']."-".substr('0'.$_GET['mois1'],-2,2)."-".substr('00'.$_GET['jour1'],-2,2)."' and '".$_GET['an2']."-".substr('0'.$_GET['mois2'],-2,2)."-".substr('00'.$_GET['jour2'],-2,2)."' group by taille order by tot_ht desc limit 0,5"; $s = mysql_query_override($url); $cpt=0; while($d = mysql_fetch_array_override($s)) { $val[$cpt][] = $d['taille']; $ca[$cpt][] = $d['tot_ht']; $volume[$cpt][] = $d['volume']; $cpt++; } //######################################### // CLIENTS $url = "select IF(societe_bill != '',societe_bill, CONCAT(nom_bill, ' ', prenom_bill)) as customer, sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc FROM gaia_commandes c, gaia_categories cat, gaia_commandes_articles ca, gaia_produits p ".$sql_priv." cat.id = p.defcat and c.id = ca.commande_id AND ca.produit_id = p.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 between '".$_GET['an1']."-".substr('0'.$_GET['mois1'],-2,2)."-".substr('00'.$_GET['jour1'],-2,2)."' and '".$_GET['an2']."-".substr('0'.$_GET['mois2'],-2,2)."-".substr('00'.$_GET['jour2'],-2,2)."' group by c.id_utilisateur order by tot_ht desc limit 0,5"; $s = mysql_query_override($url); $cpt=0; while($d = mysql_fetch_array_override($s)) { $val[$cpt][] = $d['customer']; $ca[$cpt][] = $d['tot_ht']; $volume[$cpt][] = $d['volume']; $cpt++; } //######################################### ?> <table width="100%" border="0" class="tablespace"> <tr><th class="entete" align="center">TOP 5 sur la période</th></tr> </table> <table width="100%" border="0" class="tablespace stats"> <tr> <td class="menu" align="center" style="padding:5px">Produits vendus</td> <td class="menu" align="center" style="padding:5px">CA</td> <td class="menu" align="center" style="padding:5px">Volume</td> <td class="menu" align="center" style="padding:5px">Catégories vendues</td> <td class="menu" align="center" style="padding:5px">CA</td> <td class="menu" align="center" style="padding:5px">Volume</td> <td class="menu" align="center" style="padding:5px">Tailles vendues</td> <td class="menu" align="center" style="padding:5px">CA</td> <td class="menu" align="center" style="padding:5px">Volume</td> <td class="menu" align="center" style="padding:5px">Clients</td> <td class="menu" align="center" style="padding:5px">CA</td> <td class="menu" align="center" style="padding:5px">Volume</td> </tr> <?php foreach ($val as $k => $v) : ?> <tr> <?php foreach ($v as $i => $j) : ?> <td align="center" style="padding:5px"><?php echo $val[$k][$i]; ?></td> <td align="center" style="padding:5px"><?php echo $ca[$k][$i]; ?></td> <td align="center" style="padding:5px"><?php echo $volume[$k][$i]; ?></td> <?php endforeach; ?> </tr> <?php endforeach; ?> </table> <?//################################################################# //################################################################# //################################################################# // STATISTIQUES GAMMES ?> <table width="100%" border="0" class="tablespace"> <tr><th class="entete" align="center">Statistiques de ventes par catégories</th></tr> </table> <table width="100%" border="0" class="tablespace stats"> <tr> <td class="menu" align="center" style="padding:5px"></td> <td class="menu" align="center" style="padding:5px">C.A.</td> <td class="menu" align="center" style="padding:5px">Marge</td> <td class="menu" align="center" style="padding:5px">Volume</td> <td class="menu" align="center" style="padding:5px">C.A. (n-1)</td> <td class="menu" align="center" style="padding:5px">Marge (n-1)</td> <td class="menu" align="center" style="padding:5px">Volume (n-1)</td> <td class="menu" align="center" style="padding:5px">Progression</td> </tr> <? $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 * from gaia_categories where parent_id = '".$allcat['id']."' order by position, nom_fr"); $recsous = mysql_query_override("select c.* from gaia_categories c, gaia_produits p where p.defcat = 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'], 2); while ($allcatsous = mysql_fetch_array_override($recsous)) { echo recup_cat_stat($allcatsous['id'], 1); } } } ?> </table> <? //################################################################# //################################################################# // STATISTIQUES PAR PRODUITS ?> <table width="100%" border="0" class="tablespace"> <tr><th class="entete" align="center">Statistiques de ventes par produits</th></tr> </table> <table width="100%" border="0" class="tablespace stats"> <tr> <td class="menu" align="center" style="padding:5px"></td> <td class="menu" align="center" style="padding:5px">C.A.</td> <td class="menu" align="center" style="padding:5px">Marge</td> <td class="menu" align="center" style="padding:5px">Volume</td> <td class="menu" align="center" style="padding:5px">C.A. (n-1)</td> <td class="menu" align="center" style="padding:5px">Marge (n-1)</td> <td class="menu" align="center" style="padding:5px">Volume (n-1)</td> <td class="menu" align="center" style="padding:5px">Progression</td> </tr> <? $superca = $supermarge = $supervolume = 0; $dates = ''; if(isset($_GET['an1'])) $dates = " and o_timestamp between '".$_GET['an1']."-".substr('0'.$_GET['mois1'],-2,2)."-".substr('00'.$_GET['jour1'],-2,2)."' and '".$_GET['an2']."-".substr('0'.$_GET['mois2'],-2,2)."-".substr('00'.$_GET['jour2'],-2,2)."' "; $sql = "select ca.nom_produit, sum(ca.total_prix_ht) as tot, sum(ca.quantite) as volume, ca.produit_id as id 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') ".$dates." group by ca.produit_id order by sum(ca.quantite) desc"; $recc = mysql_query_override($sql); //select ca.nom_produit, sum(ca.total_prix_ht) as tot, sum(ca.quantite) as volume, ca.produit_id as id from gaia_commandes_articles ca, gaia_commandes c , gaia_utilisateurs u where c.id_utilisateur = u.id_utilisateur and u.priv <> 'spon' and ca.commande_id = c.id AND (statut = '3' or statut = '5' or statut = '8') group by ca.produit_id order by sum(ca.quantite) desc $cpt=0; 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.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc from gaia_commandes c, gaia_commandes_articles ca, gaia_categories cat, gaia_produits p ".$sql_priv." c.id = ca.commande_id AND cat.id = p.defcat and ca.produit_id = p.id and ca.produit_id = ".$allcat['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 between "; echo return_stat($url, $allcat['nom_produit'], 1); } /* echo ' <tr> <td><td> <td>CA '.number_format($superca,2,'.','').'</td> <td>MARGE '.number_format($supermarge,2,'.','').'</td> <td>VOLUME '.number_format($supervolume,2,'.','').'</td> </tr> '; */ echo '</table>'; //################################################################# } include("modeles/bas.php"); //################################################################# //################################################################# // FUNCTIONS function recup_cat_stat($id, $t=0) { 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.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 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 between "; if ($t==1) $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 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 between "; */ $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 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 between "; if ($t==1) $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 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 between "; //echo $url; return return_stat($url, $allcat['nom_fr'], $t); } /* select sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc FROM gaia_commandes c, gaia_commandes_articles ca, gaia_produits_categories pc WHERE c.id = ca.commande_id AND ca.produit_id = pc.produit_id and (statut = '3' or statut = '5' or statut = '8') and o_timestamp between '2015-09-01' and '2015-09-31' group by c.id select sum(ca.total_prix_ht) as tot_ht, sum(ca.marge) as marge_ht, sum(ca.quantite) as volume, sum(ca.remise_produit DIV 1.2) as reduc FROM gaia_commandes c, gaia_commandes_articles ca, gaia_produits_categories pc WHERE c.id = ca.commande_id AND ca.produit_id = pc.produit_id AND (statut = '3' or statut = '5' or statut = '8') AND pc.categorie_id in (select distinct(id) from gaia_categories where parent_id = '26') and o_timestamp between '2015-09-01' and '2015-09-31' group by c.id */ function return_stat($url, $nom, $t, $global=0) { global $sql_priv, $year, $superca, $supermarge, $supervolume; $totca = $totmarge = $totcaold = $totmois = $totmargeold = $totvolume = $totvolumeold = 0; $entete = $marge = $totalmarge = $volume = $totalvolume = $encaisse = $ca = $caold = $margeold = $volumeold = $progress = ''; $urlnew = $url ." '".$_GET['an1']."-".substr('0'.$_GET['mois1'],-2,2)."-".substr('00'.$_GET['jour1'],-2,2)."' and '".$_GET['an2']."-".substr('0'.$_GET['mois2'],-2,2)."-".substr('00'.$_GET['jour2'],-2,2)."' "; $urlold = $url ." '".($_GET['an1']-1)."-".substr('0'.$_GET['mois1'],-2,2)."-".substr('00'.$_GET['jour1'],-2,2)."' and '".($_GET['an2']-1)."-".substr('0'.$_GET['mois2'],-2,2)."-".substr('00'.$_GET['jour2'],-2,2)."' "; $reccom = mysql_query_override($urlnew." group by c.id "); //$getht = mysql_fetch_array_override($reccom); //echo $urlnew." group by c.id, pc.produit_id "; $tot_ht = $tot_reduc = $marge_ht = $volume = 0; while($getht = mysql_fetch_array_override($reccom)) { $tot_ht += $getht['tot_ht']; $marge_ht += $getht['marge_ht']; $volume += $getht['volume']; $tot_reduc += $getht['reduc']; } $reccomold = mysql_query_override($urlold." group by c.id "); //$gethtold = mysql_fetch_array_override($reccomold); $otot_ht = $otot_reduc = $omarge_ht = $ovolume = 0; while($gethtold = mysql_fetch_array_override($reccomold)) { $otot_ht += $gethtold['tot_ht']; $omarge_ht += $gethtold['marge_ht']; $ovolume += $gethtold['volume']; $otot_reduc += $gethtold['reduc']; } if($t>0) $entete = '<td align="center" '.(($t==2)?'style="background:#333; font-weight:bold; color:#fff"':'').'>'.stripslashes($nom).'</td>'; //### Calcul ca ht ### $ca = '<td align="center">'.number_format(($tot_ht),2,'.',' ').'</td>'; $superca += ($tot_ht); $supermarge += ($marge_ht); $supervolume += $volume; //### Calcul marge ht ### $marge = '<td align="center">'.number_format(($marge_ht),2,'.',' ').'</td>'; //### Calcul volume ### $volume = '<td align="center">'.(!empty($volume)?$volume:0).'</td>'; //### Calcul ca ht n-1 ### $caold = '<td align="center">'.number_format(($otot_ht),2,'.',' ').'</td>'; //### Calcul marge ht n-1 ### $margeold = '<td align="center">'.number_format(($omarge_ht),2,'.',' ').'</td>'; //### Calcul volume n-1 ### $volumeold = '<td align="center">'.(!empty($ovolume)?$ovolume:0).'</td>'; //### Calcul progression mois ### $pourc = 0; if($tot_ht - $otot_ht==0) $pourc = 0; elseif($tot_ht==0) $pourc = -100; else { $ecart = $tot_ht - $otot_ht; $pourc = number_format($ecart * 100 / $tot_ht,2,'.',''); } $progress .= '<td align="center" class="'.(($pourc>0)?'up':'down').'"><i class="icon-arrow-'.(($pourc>0)?'up':(($pourc<0)?'down':'')).'"></i> '.$pourc.' %</td>'; $ret = ' <tr> '.$entete.' '.$ca.' '.$marge.' '.$volume.' '.$caold.' '.$margeold.' '.$volumeold.' '.$progress.' </tr> '; return $ret; } ?>