[ 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/facture/ -> fiche-rec.php (source)

   1  <?php
   2  /* Copyright (C) 2002-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: fiche-rec.php,v 1.31 2005/10/10 20:15:32 eldy Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/compta/facture/fiche-rec.php,v $
  21   */
  22  
  23  /**
  24          \file       htdocs/compta/facture/fiche-rec.php
  25          \ingroup    facture
  26          \brief      Page d'affichage d'une facture récurrent
  27          \version    $Revision: 1.31 $
  28  */
  29  
  30  require ("./pre.inc.php");
  31  require_once ("./facture-rec.class.php");
  32  require_once(DOL_DOCUMENT_ROOT."/project.class.php");
  33  require_once(DOL_DOCUMENT_ROOT."/product.class.php");
  34  
  35  $user->getrights('facture');
  36  
  37  if (!$user->rights->facture->lire)
  38    accessforbidden();
  39  
  40  $facid=isset($_GET["facid"])?$_GET["facid"]:$_POST["facid"];
  41  $action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
  42  
  43  
  44  llxHeader('','Facture récurrente','ch-facture.html#s-fac-facture-rec');
  45  
  46  // Sécurité accés client
  47  if ($user->societe_id > 0) 
  48  {
  49    $action = '';
  50    $socidp = $user->societe_id;
  51  }
  52  
  53  
  54  /*
  55   * Actions
  56   */    
  57  
  58  // Ajout
  59  if ($_POST["action"] == 'add')
  60  {
  61      $facturerec = new FactureRec($db, $facid);
  62      $facturerec->titre = $_POST["titre"];
  63  
  64      if ($facturerec->create($user) > 0)
  65      {
  66          $facid = $facturerec->id;
  67          $action = '';
  68      }
  69      else
  70      {
  71          $action = "create";
  72      }
  73  }
  74  
  75  // Suppression
  76  if ($_REQUEST["action"] == 'delete' && $user->rights->facture->supprimer) 
  77  {
  78    $fac = new FactureRec($db);
  79    $fac->delete($_REQUEST["facid"]);
  80    $facid = 0 ;
  81  }
  82  
  83  /*
  84   *
  85   */
  86  
  87  $html = new Form($db);
  88  
  89  /*********************************************************************
  90   *
  91   * Mode creation
  92   *
  93   ************************************************************************/
  94  if ($_GET["action"] == 'create') 
  95  {
  96    print_titre("Créer une facture récurrente");
  97  
  98    $facture = new Facture($db);
  99  
 100    if ($facture->fetch($_GET["facid"]) > 0) 
 101      {
 102         
 103        print '<form action="fiche-rec.php" method="post">';
 104        print '<input type="hidden" name="action" value="add">';
 105        print '<input type="hidden" name="facid" value="'.$facture->id.'">';
 106        
 107        print '<table class="border" width="100%">';
 108        
 109        $facture->fetch_client();
 110  
 111        print '<tr><td>'.$langs->trans("Customer").' :</td><td>'.$facture->client->nom.'</td>';
 112        print '<td>'.$langs->trans("Comment").'</td></tr>';
 113        
 114        print '<tr><td>'.$langs->trans("Title").' :</td><td><input type="text" name="titre" size="16"></td>';
 115  
 116        print '<td rowspan="4" valign="top">';
 117        print '<textarea name="note" wrap="soft" cols="60" rows="8"></textarea></td></tr>';    
 118        
 119        print "<tr><td>".$langs->trans("Author")." :</td><td>".$user->fullname."</td></tr>";
 120        print "<tr><td>Conditions de réglement :</td><td>";
 121        
 122        print $facture->cond_reglement;
 123        
 124        print "</td></tr>";
 125        
 126        print "<tr><td>Projet :</td><td>";
 127        if ($facture->projetid > 0)
 128      {
 129        $proj = new Project($db);
 130        $proj->fetch($facture->projetid);
 131        print $proj->title;
 132      }
 133        print "</td></tr></table>";
 134  
 135  
 136      
 137        print '<br>';
 138        print_titre('Services/Produits');
 139        
 140        print '<table class="noborder" width="100%">';
 141        /*
 142         * Lignes de factures
 143         *
 144         */
 145        print '<tr><td colspan="3">';
 146      
 147        $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux, l.remise_percent, l.subprice";
 148        $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l WHERE l.fk_facture = $facture->id ORDER BY l.rowid";
 149        
 150        $result = $db->query($sql);
 151        if ($result)
 152      {
 153        $num = $db->num_rows();
 154        $i = 0; $total = 0;
 155        
 156        echo '<table class="notopnoleftnoright" width="100%">';
 157        if ($num)
 158          {
 159            print "<tr class=\"liste_titre\">";
 160            print '<td width="54%">'.$langs->trans("Description").'</td>';
 161            print '<td width="8%" align="center">'.$langs->trans("VAT").'</td>';
 162            print '<td width="8%" align="center">'.$langs->trans("Qty").'</td>';
 163            print '<td width="8%" align="right">'.$langs->trans("Discount").'</td>';
 164            print '<td width="12%" align="right">'.$langs->trans("PriceU").'</td>';
 165            print '<td width="12%" align="right">N.P.</td>';
 166            print "</tr>\n";
 167          }
 168        $var=True;
 169        while ($i < $num)
 170          {
 171            $objp = $db->fetch_object();
 172  
 173            if ($objp->fk_product > 0)
 174          {
 175            $product = New Product($db);
 176            $product->fetch($objp->fk_product);
 177          }
 178  
 179            $var=!$var;
 180            print "<TR $bc[$var]>";
 181            if ($objp->fk_product)
 182          {
 183            print '<td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
 184          }
 185            else
 186          {
 187            print "<td>".stripslashes(nl2br($objp->description))."</TD>\n";
 188          }
 189            print '<TD align="center">'.$objp->tva_taux.' %</TD>';
 190            print '<TD align="center">'.$objp->qty.'</TD>';
 191            if ($objp->remise_percent > 0)
 192          {
 193            print '<td align="right">'.$objp->remise_percent." %</td>\n";
 194          }
 195            else
 196          {
 197            print '<td>&nbsp;</td>';
 198          }
 199  
 200            print '<TD align="right">'.price($objp->subprice)."</td>\n";
 201  
 202            if ($objp->fk_product > 0 && $objp->subprice <> $product->price)
 203          {
 204            print '<td align="right">'.price($product->price)."</td>\n";
 205            $flag_different_price++;
 206          }
 207            else
 208          {
 209            print '<td>&nbsp;</td>';
 210          }
 211            
 212            print "</tr>";
 213            
 214            $i++;
 215          }
 216        
 217        $db->free();
 218        
 219      } 
 220        else
 221      {
 222        print $db->error();
 223      }
 224        print "</table>";
 225        
 226        print '</td></tr>';
 227        if ($flag_different_price)
 228      {
 229        print '<tr><td colspan="3" align="left">';
 230        print '<select name="deal_price">';
 231        if ($flag_different_price>1)
 232          {
 233            print '<option value="new">Prendre en compte les nouveaux prix</option>';
 234            print '<option value="old">Utiliser les anciens prix</option>';
 235          }
 236        else
 237          {
 238            print '<option value="new">Prendre en compte le nouveau prix</option>';
 239            print '<option value="old">Utiliser l\'ancien prix</option>';
 240          }
 241        print '</select>';
 242        print '</td></tr>';
 243      }
 244        print '<tr><td colspan="3" align="center"><input type="submit" value="Créer"></td></tr>';
 245        print "</form>\n";
 246        print "</table>\n";
 247        
 248      } 
 249    else 
 250      {
 251        print "Erreur facture $facture->id inexistante";
 252      }
 253  } 
 254  else 
 255  /* *************************************************************************** */
 256  /*                                                                             */
 257  /*                                                                             */
 258  /*                                                                             */
 259  /* *************************************************************************** */
 260  {
 261    
 262    if ($facid > 0)
 263      {    
 264        $fac = New FactureRec($db,0);
 265  
 266        if ( $fac->fetch($facid, $user->societe_id) > 0)
 267      {      
 268        $soc = new Societe($db, $fac->socidp);
 269        $soc->fetch($fac->socidp);
 270        $author = new User($db);
 271        $author->id = $fac->user_author;
 272        $author->fetch();
 273        
 274        print_titre("Facture : ".$fac->titre);
 275        
 276        /*
 277         *   Facture
 278         */
 279        print '<table class="border" width="100%">';
 280        print '<tr><td>'.$langs->trans("Customer").'</td>';
 281        print "<td colspan=\"3\">";
 282        print '<b><a href="../fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></b></td>';
 283        
 284        print "<td>Conditions de réglement : " . $fac->cond_reglement ."</td></tr>";
 285        
 286        print "<tr><td>".$langs->trans("Author")."</td><td colspan=\"3\">$author->fullname</td>";
 287        
 288        if ($fac->remise_percent > 0)
 289          {
 290            print '<td rowspan="5" valign="top">';
 291          }
 292        else
 293          {
 294            print '<td rowspan="4" valign="top">';
 295          }
 296        
 297      print "</td></tr>";
 298      
 299      print '<tr><td>'.$langs->trans("AmountHT").'</td>';
 300      print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>';
 301      print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
 302  
 303      print '<tr><td>'.$langs->trans("VAT").'</td><td align="right" colspan="2">'.price($fac->total_tva).'</td>';
 304      print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
 305      print '<tr><td>'.$langs->trans("TotalTTC").'</td><td align="right" colspan="2">'.price($fac->total_ttc).'</td>';
 306      print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
 307      if ($fac->note)
 308        {
 309          print '<tr><td colspan="5">'.$langs->trans("Note").' : '.nl2br($fac->note)."</td></tr>";
 310        }
 311  
 312      print "</table><br>";
 313      /*
 314       * Lignes
 315       *
 316       */
 317      print_titre($langs->trans("Products"));
 318            
 319      print '<table class="noborder" width="100%">';
 320      print '<tr class="liste_titre"><td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Product").'</td>';
 321      print '<td align="right">'.$langs->trans("Price").'</td><td align="center">'.$langs->trans("Discount").'</td><td align="center">'.$langs->trans("Qty").'</td></tr>';
 322      
 323      $num = sizeof($fac->lignes);
 324      $i = 0;    
 325      $var=True;    
 326      while ($i < $num) 
 327        {
 328          $var=!$var;
 329          if ($fac->lignes[$i]->produit_id > 0)
 330            {
 331          $prod = New Product($db);
 332          $prod->fetch($fac->lignes[$i]->produit_id);
 333          print "<tr $bc[$var]><td>";
 334          print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$prod->id.'">';
 335          print img_object($langs->trans("ShowProduct"),"product").' '.$prod->ref;
 336          print '</a>';
 337          print '</td>';
 338          print '<td>'.$fac->lignes[$i]->desc.'</td>';
 339            }
 340          else
 341            {
 342          print "<tr $bc[$var]><td>&nbsp;</td>";
 343          print '<td>'.$fac->lignes[$i]->desc.'</td>';
 344            }
 345          print "<td align=\"right\">".price($fac->lignes[$i]->price)."</TD>";
 346          print '<td align="center">'.$fac->lignes[$i]->remise_percent.' %</td>';
 347          print "<td align=\"center\">".$fac->lignes[$i]->qty."</td></tr>\n";
 348          $i++;
 349        }
 350      print '</table>';
 351  
 352      /*
 353       * Actions
 354       *
 355       */
 356      if ($user->societe_id == 0 && $fac->paye == 0)
 357        {
 358          print '<p><table id="actions" width="100%"><tr>';
 359      
 360          if ($fac->statut == 0 && $user->rights->facture->supprimer)
 361            {
 362          print "<td align=\"center\" width=\"25%\">[<a href=\"fiche-rec.php?facid=$facid&action=delete\">Supprimer</a>]</td>";
 363            } 
 364          else
 365            {
 366          print "<td align=\"center\" width=\"25%\">-</td>";
 367            } 
 368          
 369  
 370          print "<td align=\"center\" width=\"25%\">-</td>";
 371  
 372          
 373  
 374          print '<td align="center" width="25%">-</td>';        
 375          print '<td align="center" width="25%">-</td>';
 376  
 377          print "</tr></table>";
 378        }
 379      print "<p>\n";
 380  
 381      /*
 382       *
 383       *
 384       */       
 385        }
 386      else
 387        {
 388      /* Facture non trouvée */
 389      print "Facture inexistante ou accés refusé";
 390        }
 391    } else {
 392      /***************************************************************************
 393       *                                                                         *
 394       *                      Mode Liste                                         *
 395       *                                                                         * 
 396       *                                                                         *
 397       ***************************************************************************/
 398      if ($page == -1)
 399        {
 400      $page = 0 ;
 401        }
 402  
 403      if ($user->rights->facture->lire)
 404        {
 405      $limit = $conf->liste_limit;
 406      $offset = $limit * $page ;
 407  
 408      if ($sortorder == "")
 409        $sortorder="DESC";
 410  
 411      if ($sortfield == "")
 412        $sortfield="f.datef";
 413  
 414      $sql = "SELECT s.nom,s.idp,f.titre,f.total,f.rowid as facid";
 415      $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f WHERE f.fk_soc = s.idp";
 416      
 417      if ($socidp)
 418        $sql .= " AND s.idp = $socidp";
 419               
 420      //$sql .= " ORDER BY $sortfield $sortorder, rowid DESC ";
 421      //    $sql .= $db->plimit($limit + 1,$offset);
 422      
 423      $result = $db->query($sql);
 424        }
 425      if ($result)
 426        {
 427      $num = $db->num_rows();
 428      print_barre_liste($langs->trans("Bills"),$page,"fiche-rec.php","&socidp=$socidp",$sortfield,$sortorder,'',$num);
 429  
 430      $i = 0;
 431      print "<table class=\"noborder\" width=\"100%\">";
 432      print '<tr class="liste_titre">';
 433      print '<td>'.$langs->trans("Ref").'</td>';
 434      print_liste_field_titre($langs->trans("Company"),"fiche-rec.php","s.nom","","&socidp=$socidp");
 435      print '</td><td align="right">'.$langs->trans("Amount").'</td>';
 436      print '<td>&nbsp;</td>';
 437      print "</td>\n";
 438        
 439      if ($num > 0) 
 440        {
 441          $var=True;
 442          while ($i < min($num,$limit))
 443            {
 444          $objp = $db->fetch_object();
 445          $var=!$var;
 446  
 447          print "<tr $bc[$var]>";
 448  
 449          print '<td><a href="fiche-rec.php?facid='.$objp->facid.'">'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->titre;
 450          print "</a></td>\n";
 451          print '<td><a href="../fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
 452          
 453          print "<td align=\"right\">".price($objp->total)."</td>\n";
 454          
 455          if (! $objp->paye)
 456            {
 457              if ($objp->fk_statut == 0)
 458                {
 459              print '<td align="center">brouillon</td>';
 460                }
 461              else
 462                {
 463              print '<td align="center"><a href="facture.php?filtre=paye:0,fk_statut:1">impayée</a></td>';
 464                }
 465            }
 466          else
 467            {
 468              print '<td>&nbsp;</td>';
 469            }
 470          
 471          print "</tr>\n";
 472          $i++;
 473            }
 474        }
 475      
 476      print "</table>";
 477      $db->free();
 478        }
 479      else
 480        {
 481      dolibarr_print_error($db);
 482        }    
 483    }
 484    
 485  }
 486  
 487  $db->close();
 488  
 489  llxFooter("<em>Derni&egrave;re modification $Date: 2005/10/10 20:15:32 $ r&eacute;vision $Revision: 1.31 $</em>");
 490  ?>


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