[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: casoc.php,v 1.20 2005/09/05 19:27:58 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/stats/casoc.php,v $ 21 */ 22 23 /** 24 \file htdocs/compta/stats/casoc.php 25 \brief Page reporting CA par société 26 \version $Revision: 1.20 $ 27 */ 28 29 require ("./pre.inc.php"); 30 31 $year=$_GET["year"]; 32 if (! $year) { $year = strftime("%Y", time()); } 33 $modecompta = $conf->compta->mode; 34 if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"]; 35 36 $sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"]; 37 $sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"]; 38 if (! $sortorder) $sortorder="asc"; 39 if (! $sortfield) $sortfield="nom"; 40 41 // Sécurité accés client 42 if ($user->societe_id > 0) $socidp = $user->societe_id; 43 44 45 llxHeader(); 46 47 $html=new Form($db); 48 49 // Affiche en-tête de rapport 50 if ($modecompta=="CREANCES-DETTES") 51 { 52 $nom="Chiffre d'affaire par société"; 53 $nom.=' (Voir le rapport en <a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=RECETTES-DEPENSES">recettes-dépenses</a> pour n\'inclure que les factures effectivement payées)'; 54 $period=$langs->trans("Year")." ".$year; 55 $periodlink='<a href='.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>'; 56 $description=$langs->trans("RulesCADue"); 57 $builddate=time(); 58 $exportlink=$langs->trans("NotYetAvailable"); 59 } 60 else { 61 $nom="Chiffre d'affaire par société"; 62 $nom.=' (Voir le rapport en <a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&modecompta=CREANCES-DETTES">créances-dettes</a> pour inclure les factures non encore payée)'; 63 $period=$langs->trans("Year")." ".$year; 64 $periodlink='<a href="'.$_SERVER["PHP_SELF"].'?year='.($year-1).'&modecompta='.$modecompta.'">'.img_previous().'</a> <a href="'.$_SERVER["PHP_SELF"].'?year='.($year+1).'&modecompta='.$modecompta.'">'.img_next().'</a>'; 65 $description=$langs->trans("RulesCAIn"); 66 $builddate=time(); 67 $exportlink=$langs->trans("NotYetAvailable"); 68 } 69 $html->report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink); 70 71 72 // Charge tableau 73 $catotal=0; 74 if ($modecompta == 'CREANCES-DETTES') 75 { 76 $sql = "SELECT s.idp as rowid, s.nom as name, sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; 77 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; 78 $sql .= " WHERE f.fk_statut = 1 AND f.fk_soc = s.idp"; 79 if ($year) $sql .= " AND f.datef between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; 80 } 81 else 82 { 83 /* 84 * Liste des paiements (les anciens paiements ne sont pas vus par cette requete car, sur les 85 * vieilles versions, ils n'étaient pas liés via paiement_facture. On les ajoute plus loin) 86 */ 87 $sql = "SELECT s.idp as rowid, s.nom as name, sum(pf.amount) as amount_ttc"; 88 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; 89 $sql .= " WHERE p.rowid = pf.fk_paiement AND pf.fk_facture = f.rowid AND f.fk_soc = s.idp"; 90 if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; 91 } 92 if ($socidp) $sql .= " AND f.fk_soc = $socidp"; 93 $sql .= " GROUP BY rowid"; 94 $sql .= " ORDER BY rowid"; 95 96 $result = $db->query($sql); 97 if ($result) 98 { 99 $num = $db->num_rows($result); 100 $i=0; 101 while ($i < $num) 102 { 103 $obj = $db->fetch_object($result); 104 $amount[$obj->rowid] = $obj->amount_ttc; 105 $name[$obj->rowid] = $obj->name; 106 $catotal+=$obj->amount_ttc; 107 $i++; 108 } 109 } 110 else { 111 dolibarr_print_error($db); 112 } 113 114 // On ajoute les paiements anciennes version, non liés par paiement_facture 115 if ($modecompta != 'CREANCES-DETTES') 116 { 117 $sql = "SELECT 'Autres' as nom, '0' as idp, sum(p.amount) as amount_ttc"; 118 $sql .= " FROM ".MAIN_DB_PREFIX."paiement as p"; 119 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement"; 120 $sql .= " WHERE pf.rowid IS NULL"; 121 if ($year) $sql .= " AND p.datep between '".$year."-01-01 00:00:00' and '".$year."-12-31 23:59:59'"; 122 $sql .= " GROUP BY nom"; 123 $sql .= " ORDER BY nom"; 124 125 $result = $db->query($sql); 126 if ($result) 127 { 128 $num = $db->num_rows($result); 129 $i=0; 130 while ($i < $num) 131 { 132 $obj = $db->fetch_object($result); 133 $amount[$obj->rowid] = $obj->amount_ttc; 134 $name[$obj->rowid] = $obj->name; 135 $catotal+=$obj->amount_ttc; 136 $i++; 137 } 138 } 139 else { 140 dolibarr_print_error($db); 141 } 142 } 143 144 145 $i = 0; 146 print "<table class=\"noborder\" width=\"100%\">"; 147 print "<tr class=\"liste_titre\">"; 148 print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"nom","",'&year='.($year).'&modecompta='.$modecompta,"",$sortfield); 149 print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"amount_ttc","",'&year='.($year).'&modecompta='.$modecompta,'align="right"',$sortfield); 150 print_liste_field_titre($langs->trans("Percentage"),$_SERVER["PHP_SELF"],"amount_ttc","",'&year='.($year).'&modecompta='.$modecompta,'align="right"',$sortfield); 151 print "</tr>\n"; 152 $var=true; 153 154 if (sizeof($amount)) 155 { 156 $arrayforsort=$name; 157 158 // On définit tableau arrayforsort 159 if ($sortfield == 'nom' && $sortorder == 'asc') { 160 asort($name); 161 $arrayforsort=$name; 162 } 163 if ($sortfield == 'nom' && $sortorder == 'desc') { 164 arsort($name); 165 $arrayforsort=$name; 166 } 167 if ($sortfield == 'amount_ttc' && $sortorder == 'asc') { 168 asort($amount); 169 $arrayforsort=$amount; 170 } 171 if ($sortfield == 'amount_ttc' && $sortorder == 'desc') { 172 arsort($amount); 173 $arrayforsort=$amount; 174 } 175 176 foreach($arrayforsort as $key=>$value) 177 { 178 $var=!$var; 179 print "<tr $bc[$var]>"; 180 181 $fullname=$name[$key]; 182 if ($key > 0) { 183 $linkname='<a href="'.DOL_URL_ROOT.'/soc.php?socid='.$key.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$fullname.'</a>'; 184 } 185 else { 186 $linkname=$langs->trans("Autres paiements liés à aucune facture, donc aucune société"); 187 } 188 print "<td>".$linkname."</td>\n"; 189 print '<td align="right">'.price($amount[$key]).'</td>'; 190 print '<td align="right">'.($catotal > 0 ? price(100 / $catotal * $amount[$key]).'%' : ' ').'</td>'; 191 print "</tr>\n"; 192 $i++; 193 } 194 195 // Total 196 print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.price($catotal).'</td><td> </td></tr>'; 197 198 $db->free($result); 199 } 200 201 print "</table>"; 202 print '<br>'; 203 204 $db->close(); 205 206 llxFooter('$Date: 2005/09/05 19:27:58 $ - $Revision: 1.20 $'); 207 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |