[ Index ]
 

Code source de Dolibarr 2.0.1

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/htdocs/compta/ -> index.php (source)

   1  <?php
   2  /* Copyright (C) 2001-2005 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: index.php,v 1.83.2.3 2006/01/16 16:38:22 tipaul Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/index.php,v $
  21   */
  22  
  23  /**   
  24        \file       htdocs/compta/index.php
  25        \ingroup    compta
  26        \brief      Page accueil zone comptabilité
  27        \version    $Revision: 1.83.2.3 $
  28  */
  29  
  30  require ("./pre.inc.php");
  31  
  32  $user->getrights(); // On a besoin des permissions sur plusieurs modules
  33  
  34  if (!$user->rights->compta->general->lire)
  35    accessforbidden();
  36  
  37  $langs->load("compta");
  38  $langs->load("bills");
  39  
  40  // Sécurité accés client
  41  $socidp='';
  42  if ($user->societe_id > 0)
  43  {
  44    $action = '';
  45    $socidp = $user->societe_id;
  46  }
  47  
  48  
  49  llxHeader("",$langs->trans("AccountancyTreasuryArea"));
  50  
  51  
  52  /*
  53   * Actions
  54   */
  55  
  56  if (isset($_GET["action"]) && $_GET["action"] == 'add_bookmark')
  57  {
  58    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE fk_soc = ".$socidp." AND fk_user=".$user->id;
  59    if (! $db->query($sql) )
  60      {
  61        dolibarr_print_error($db);
  62      }
  63    $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_soc, dateb, fk_user) VALUES ($socidp, now(),".$user->id.");";
  64    if (! $db->query($sql) )
  65      {
  66        dolibarr_print_error($db);
  67      }
  68  }
  69  
  70  if (isset($_GET["action"]) && $_GET["action"] == 'del_bookmark')
  71  {
  72    $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE rowid=".$_GET["bid"];
  73    $result = $db->query($sql);
  74  }
  75  
  76  
  77  
  78  /*
  79   * Affichage page
  80   *
  81   */
  82  print_fiche_titre($langs->trans("AccountancyTreasuryArea"));
  83  
  84  print '<table border="0" width="100%" class="notopnoleftnoright">';
  85  
  86  print '<tr><td valign="top" width="30%" class="notopnoleft">';
  87  
  88  /*
  89   * Zone recherche facture
  90   */
  91  if ($conf->facture->enabled)
  92  {
  93    print '<form method="post" action="facture.php">';
  94    
  95    print '<table class="noborder" width="100%">';
  96    print "<tr class=\"liste_titre\">";
  97    print '<td colspan="3">'.$langs->trans("SearchABill").'</td></tr>';
  98    print "<tr $bc[0]><td>".$langs->trans("Ref").':</td><td><input type="text" name="sf_ref" class="flat" size="18"></td>';
  99    print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
 100    print "<tr $bc[0]><td>".$langs->trans("Other").':</td><td><input type="text" name="sall" class="flat" size="18"></td>';
 101    print '</tr>';
 102    print "</table></form><br>";
 103  }
 104  
 105  
 106  /**
 107   * Factures brouillons
 108   */
 109  if ($conf->facture->enabled && $user->rights->facture->lire)
 110  {  
 111    $sql  = "SELECT f.facnumber, f.rowid, f.total_ttc, s.nom, s.idp";
 112    $sql .= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s";
 113    $sql .= " WHERE s.idp = f.fk_soc AND f.fk_statut = 0";
 114    
 115    if ($socidp)
 116      {
 117        $sql .= " AND f.fk_soc = $socidp";
 118      }
 119    
 120    $resql = $db->query($sql);
 121    
 122    if ( $resql )
 123      {
 124        $num = $db->num_rows($resql);
 125        if ($num)
 126          {
 127        print '<table class="noborder" width="100%">';
 128        print '<tr class="liste_titre">';
 129        print '<td colspan="3">'.$langs->trans("DraftBills").' ('.$num.')</td></tr>';
 130        $i = 0;
 131        $tot_ttc = 0;
 132        $var = True;
 133        while ($i < $num && $i < 20)
 134              {
 135            $obj = $db->fetch_object($resql);
 136            $var=!$var;
 137            print '<tr '.$bc[$var].'><td nowrap><a href="facture.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.'</a></td>';
 138            print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dolibarr_trunc($obj->nom,20).'</a></td>';
 139            print '<td align="right">'.price($obj->total_ttc).'</td>';
 140            print '</tr>';
 141            $tot_ttc+=$obj->total_ttc;
 142            $i++;
 143              }
 144        
 145        print '<tr class="liste_total"><td colspan="2" align="left">'.$langs->trans("Total").'</td>';
 146        print '<td align="right">'.price($tot_ttc).'</td>';
 147        print '</tr>';
 148        
 149        print "</table><br>";
 150          }
 151        $db->free($resql);
 152      }
 153    else
 154      {
 155        dolibarr_print_error($db);
 156      }
 157  }
 158  
 159  /**
 160   * Charges a payer
 161   */
 162  if ($conf->compta->enabled)
 163  {
 164      if ($user->societe_id == 0)
 165      {
 166  
 167          $sql = "SELECT c.rowid, c.amount, cc.libelle";
 168          $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as c, ".MAIN_DB_PREFIX."c_chargesociales as cc";
 169          $sql .= " WHERE c.fk_type = cc.id AND c.paye=0";
 170  
 171          $resql = $db->query($sql);
 172  
 173          if ( $resql )
 174          {
 175              $num = $db->num_rows($resql);
 176              if ($num)
 177              {
 178                  print '<table class="noborder" width="100%">';
 179                  print '<tr class="liste_titre">';
 180                  print '<td colspan="2">'.$langs->trans("ContributionsToPay").' ('.$num.')</td></tr>';
 181                  $i = 0;
 182                  $tot_ttc=0;
 183                  $var = True;
 184                  while ($i < $num)
 185                  {
 186                      $obj = $db->fetch_object($resql);
 187                      $var = !$var;
 188                      print "<tr $bc[$var]>";
 189                      print '<td><a href="'.DOL_URL_ROOT.'/compta/sociales/charges.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->libelle.'</td>';
 190                      print '<td align="right">'.price($obj->amount).'</td>';
 191                      print '</tr>';
 192                      $tot_ttc+=$obj->amount;
 193                      $i++;
 194                  }
 195  
 196                  print '<tr class="liste_total"><td align="left">'.$langs->trans("Total").'</td>';
 197                  print '<td align="right">'.price($tot_ttc).'</td>';
 198                  print '</tr>';
 199  
 200                  print '</table><br>';
 201              }
 202              $db->free($resql);
 203          }
 204          else
 205          {
 206              dolibarr_print_error($db);
 207          }
 208      }
 209  }
 210  
 211  
 212  /**
 213   * Bookmark
 214   */
 215  $sql = "SELECT s.idp, s.nom,b.rowid as bid";
 216  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."bookmark as b";
 217  $sql .= " WHERE b.fk_soc = s.idp AND b.fk_user = ".$user->id;
 218  $sql .= " ORDER BY lower(s.nom) ASC";
 219  
 220  $resql = $db->query($sql);
 221  
 222  if ( $resql )
 223  {
 224    $num = $db->num_rows($resql);
 225    $i = 0;
 226    if ($num)
 227      {
 228        print '<table class="noborder" width="100%">';
 229        print "<tr class=\"liste_titre\"><td colspan=\"2\">".$langs->trans("Bookmarks")."</td></tr>\n";
 230        $var = True;
 231        while ($i < $num)
 232      {
 233        $obj = $db->fetch_object($resql);
 234        $var = !$var;
 235        print "<tr $bc[$var]>";
 236        print '<td><a href="fiche.php?socid='.$obj->idp.'">'.$obj->nom.'</a></td>';
 237        print '<td align="right"><a href="index.php?action=del_bookmark&amp;bid='.$obj->bid.'">'.img_delete().'</a></td>';
 238        print '</tr>';
 239        $i++;
 240      }
 241        print '</table>';
 242      }
 243    $db->free($resql);
 244  }
 245  else
 246  {
 247    dolibarr_print_error($db);
 248  }
 249  
 250  
 251  print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
 252  
 253  
 254  /*
 255   * Commandes à facturer
 256   */
 257  if ($conf->commande->enabled && $user->rights->commande->lire)
 258  {
 259    $langs->load("orders");
 260  
 261    $sql = "SELECT sum(f.total) as tot_fht, sum(f.total_ttc) as tot_fttc";
 262    $sql .= " ,s.nom, s.idp, p.rowid, p.ref, p.total_ht, p.total_ttc";
 263    $sql .= " FROM ".MAIN_DB_PREFIX."societe AS s, ".MAIN_DB_PREFIX."commande AS p";
 264    $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."co_fa AS co_fa ON co_fa.fk_commande = p.rowid";
 265    $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture AS f ON co_fa.fk_facture = f.rowid AND f.fk_statut<>3";
 266    $sql .= " WHERE p.fk_soc = s.idp";
 267    if ($socidp)
 268      {
 269        $sql .= " AND p.fk_soc = $socidp";
 270      }
 271    $sql .= " AND p.fk_statut >=1    AND p.facture=0";
 272    $sql .= " GROUP BY p.rowid";
 273  
 274    $resql = $db->query($sql);
 275  
 276    if ( $resql )
 277      {
 278        $num = $db->num_rows($resql);
 279        if ($num)
 280      {
 281        $i = 0;
 282        print '<table class="noborder" width="100%">';
 283        print "<tr class=\"liste_titre\">";
 284        print '<td colspan="2">'.$langs->trans("OrdersToBill").' ('.$num.')</td>';
 285        print '<td align="right">'.$langs->trans("AmountHT").'</td>';
 286        print '<td align="right">'.$langs->trans("AmountTTC").'</td>';
 287        print '<td align="right">'.$langs->trans("ToBill").'</td>';
 288        print '</tr>';
 289        $var = True;
 290        $tot_ht=$tot_ttc=$tot_tobill=0;
 291        while ($i < $num)
 292          {
 293              $obj = $db->fetch_object($resql);
 294  //            if ($obj->total_ttc-$obj->tot_fttc >0)
 295  //            {
 296                  $var=!$var;
 297                  print "<tr $bc[$var]>";
 298                  print "<td width=\"20%\"><a href=\"commande/fiche.php?id=$obj->rowid\">".img_object($langs->trans("ShowOrder"),"order").'</a>&nbsp;';
 299                  print "<a href=\"commande/fiche.php?id=$obj->rowid\">".$obj->ref.'</a></td>';
 300                  
 301                  print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCompany"),"company").'</a>&nbsp;';
 302                  print '<a href="fiche.php?socid='.$obj->idp.'">'.dolibarr_trunc($obj->nom,50).'</a></td>';
 303                  print '<td align="right">'.price($obj->total_ht).'</td>';
 304                  print '<td align="right">'.price($obj->total_ttc).'</td>';
 305                  print '<td align="right">'.price($obj->total_ht-$obj->tot_fht).'</td></tr>';
 306                  $tot_ht += $obj->total_ht;
 307                  $tot_ttc += $obj->total_ttc;
 308                  $tot_tobill += ($obj->total_ht-$obj->tot_fht);
 309  //            }
 310              $i++;
 311          }
 312        $var=!$var;
 313  
 314        print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToBill").': '.price($tot_tobill).')</font> </td>';
 315        print '<td align="right">'.price($tot_ht).'</td>';
 316        print '<td align="right">'.price($tot_ttc).'</td>';
 317        print '<td align="right">'.price($tot_tobill).'</td>';
 318        print '</tr>';
 319        print '</table><br>';
 320      }
 321        $db->free($resql);
 322      }
 323    else
 324      {
 325        dolibarr_print_error($db);
 326      }
 327  }
 328  
 329  
 330  if ($conf->facture->enabled && $user->rights->facture->lire)
 331  {
 332  
 333    /*
 334     * Factures impayées
 335     *
 336     */
 337  
 338    $sql = "SELECT f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc, ".$db->pdate("f.date_lim_reglement")." as datelimite, sum(pf.amount) as am";
 339    $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f left join ".MAIN_DB_PREFIX."paiement_facture as pf on f.rowid=pf.fk_facture";
 340    $sql.= " WHERE s.idp = f.fk_soc AND f.paye = 0 AND f.fk_statut = 1";
 341    if ($socidp) $sql .= " AND f.fk_soc = $socidp";
 342    $sql.= " GROUP BY f.facnumber, f.rowid, s.nom, s.idp, f.total, f.total_ttc";
 343    $sql.= " ORDER BY f.datef ASC, f.facnumber ASC";
 344  
 345    $resql = $db->query($sql);
 346    if ($resql)
 347      {
 348        $num = $db->num_rows($resql);
 349        $i = 0;
 350  
 351        if ($num)
 352      {
 353        print '<table class="noborder" width="100%">';
 354        print '<tr class="liste_titre"><td colspan="2"><a href="'.DOL_URL_ROOT.'/compta/facture/impayees.php">'.$langs->trans("BillsCustomersUnpayed",min($conf->liste_limit,$num)).' ('.$num.')</a></td>';
 355        print '<td align="right">'.$langs->trans("AmountHT").'</td><td align="right">'.$langs->trans("AmountTTC").'</td><td align="right">'.$langs->trans("Received").'</td></tr>';
 356        $var = True;
 357        $total_ttc = $totalam = $total = 0;
 358        while ($i < $num)
 359          {
 360            $obj = $db->fetch_object($resql);
 361  
 362            if ($i < $conf->liste_limit)
 363          {
 364            $var=!$var;
 365            print '<tr '.$bc[$var].'>';
 366            print '<td nowrap><a href="facture.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.'</a>';
 367            if ($obj->datelimite < (time() - $conf->facture->client->warning_delay)) print img_warning($langs->trans("Late"));
 368            print '</td>';
 369            print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowCustomer"),"company").' '.dolibarr_trunc($obj->nom,44).'</a></td>';
 370            print '<td align="right">'.price($obj->total).'</td>';
 371            print '<td align="right">'.price($obj->total_ttc).'</td>';
 372            print '<td align="right">'.price($obj->am).'</td></tr>';
 373          }
 374            $total_ttc +=  $obj->total_ttc;
 375            $total += $obj->total;
 376            $totalam +=  $obj->am;
 377            $i++;
 378          }
 379        $var=!$var;
 380  
 381        print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToTake").': '.price($total_ttc-$totalam).')</font> </td>';
 382        print '<td align="right">'.price($total).'</td>';
 383        print '<td align="right">'.price($total_ttc).'</td>';
 384        print '<td align="right">'.price($totalam).'</td>';
 385        print '</tr>';
 386        print '</table><br>';
 387      }
 388        $db->free($resql);
 389      }
 390    else
 391      {
 392        dolibarr_print_error($db);
 393      }
 394  }
 395  
 396  
 397  // \todo Mettre ici recup des actions en rapport avec la compta
 398  $resql = 0;
 399  if ($resql)
 400  {
 401    print '<table class="noborder" width="100%">';
 402    print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("TasksToDo").'</td>';
 403    print "</tr>\n";
 404    $var = True;
 405    $i = 0;
 406    while ($i < $db->num_rows($resql) )
 407      {
 408        $obj = $db->fetch_object($resql);
 409        $var=!$var;
 410  
 411        print "<tr $bc[$var]><td>".strftime("%d %b %Y",$obj->da)."</td><td><a href=\"action/fiche.php\">$obj->libelle $obj->label</a></td></tr>";
 412        $i++;
 413      }
 414    $db->free($resql);
 415    print "</table><br>";
 416  }
 417  
 418  
 419  /*
 420   * Factures a payer
 421   */
 422  if ($conf->facture->enabled) {
 423  
 424      if ($user->societe_id == 0)
 425      {
 426        $sql = "SELECT ff.rowid, ff.facnumber, ff.libelle, ff.total_ht, ff.total_ttc, s.nom, s.idp";
 427        $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as ff";
 428        $sql .= " WHERE s.idp = ff.fk_soc";
 429        $sql .= " AND ff.paye=0";
 430  
 431        $result=$db->query($sql);
 432        if ($result)
 433          {
 434            $num = $db->num_rows();
 435            if ($num)
 436          {
 437            print '<table class="noborder" width="100%">';
 438            print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("BillsSuppliersUnpayed").' ('.$num.')</td>';
 439            print '<td align="right">'.$langs->trans("AmountHT").'</td>';
 440            print '<td align="right">'.$langs->trans("AmountTTC").'</td></tr>';
 441            print "</tr>\n";
 442            $i = 0;
 443            $var = True;
 444            $total = $total_ttc = $totalam = 0;
 445            while ($i < $num)
 446              {
 447                $obj = $db->fetch_object($result);
 448                $var = !$var;
 449                print '<tr '.$bc[$var].'><td><a href="'.DOL_URL_ROOT.'/fourn/facture/fiche.php?facid='.$obj->rowid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$obj->facnumber.'</a></td>';
 450                print '<td><a href="fiche.php?socid='.$obj->idp.'">'.img_object($langs->trans("ShowSupplier"),"company").' '.dolibarr_trunc($obj->nom,50).'</a></td>';
 451                print '<td align="right">'.price($obj->total_ht).'</td>';
 452                print '<td align="right">'.price($obj->total_ttc).'</td>';
 453                print '</tr>';
 454                $total += $obj->total_ht;
 455                $total_ttc +=  $obj->total_ttc;
 456                $totalam +=  $obj->am;
 457                $i++;
 458              }
 459            $var=!$var;
 460            
 461            print '<tr class="liste_total"><td colspan="2" align="right">'.$langs->trans("Total").' &nbsp; <font style="font-weight: normal">('.$langs->trans("RemainderToPay").': '.price($total_ttc-$totalam).')</font> </td>';
 462            print '<td align="right">'.price($total).'</td>';
 463            print '<td align="right">'.price($total_ttc).'</td>';
 464            print '</tr>';
 465            print '</table><br>';
 466          }
 467          }
 468        else
 469          {
 470            dolibarr_print_error($db);
 471          }
 472      }
 473  
 474  }
 475  
 476  
 477  print '</td></tr>';
 478  
 479  print '</table>';
 480  
 481  $db->close();
 482  
 483   
 484  llxFooter('$Date: 2006/01/16 16:38:22 $ - $Revision: 1.83.2.3 $');
 485  ?>


Généré le : Mon Nov 26 12:29:37 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics