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

   1  <?php
   2  /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 2004      Éric Seigne          <eric.seigne@ryxeo.com>
   4   * Copyright (C) 2004-2005 Laurent Destailleur  <eldy@users.sourceforge.net>
   5   *
   6   * This program is free software; you can redistribute it and/or modify
   7   * it under the terms of the GNU General Public License as published by
   8   * the Free Software Foundation; either version 2 of the License, or
   9   * (at your option) any later version.
  10   *
  11   * This program is distributed in the hope that it will be useful,
  12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14   * GNU General Public License for more details.
  15   *
  16   * You should have received a copy of the GNU General Public License
  17   * along with this program; if not, write to the Free Software
  18   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19   *
  20   * $Id: facture.php,v 1.4 2005/09/06 10:25:00 rodolphe Exp $
  21   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/client/facture.php,v $
  22   */
  23  
  24  /**
  25          \file       htdocs/compta/facture.php
  26          \ingroup    facture
  27          \brief      Page de création d'une facture
  28          \version    $Revision: 1.4 $
  29  */
  30  
  31  require ("./pre.inc.php");
  32  
  33  $user->getrights('facture');
  34  $user->getrights('banque');
  35  
  36  $langs->load("bills");
  37  
  38  $warning_delay=31*24*60*60; // Delai affichage warning retard (si retard paiement facture > delai)
  39  
  40  require_once DOL_DOCUMENT_ROOT."/facture.class.php";
  41  require_once DOL_DOCUMENT_ROOT."/paiement.class.php";
  42  require_once  DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php";
  43  
  44  
  45  if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; }
  46  if (isset($_GET["msg"])) { $msg=urldecode($_GET["msg"]); }
  47  
  48  // Sécurité accés client
  49  if ($user->societe_id > 0)
  50  {
  51      $action = '';
  52      $socidp = $user->societe_id;
  53  }
  54  
  55  // Nombre de ligne pour choix de produit/service prédéfinis
  56  $NBLINES=4;
  57  
  58  
  59  /*
  60   * Action envoi de mail
  61   */
  62  if ($_POST["action"] == 'send' || $_POST["action"] == 'relance')
  63  {
  64      $langs->load("mails");
  65  
  66      $fac = new Facture($db,"",$_POST["facid"]);
  67      if ( $fac->fetch($_POST["facid"]) )
  68      {
  69        $facref = sanitize_string($fac->ref);
  70        $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf";
  71  
  72        if (is_readable($file))
  73          {
  74        $soc = new Societe($db, $fac->socidp);
  75  
  76        if ($_POST["sendto"]) {
  77          // Le destinataire a été fourni via le champ libre
  78          $sendto = $_POST["sendto"];
  79          $sendtoid = 0;
  80        }
  81        elseif ($_POST["receiver"]) {
  82          // Le destinataire a été fourni via la liste déroulante
  83          $sendto = $soc->contact_get_email($_POST["receiver"]);
  84          $sendtoid = $_POST["receiver"];
  85        }
  86  
  87        if (strlen($sendto))
  88              {
  89            $from = $_POST["fromname"] . " <" . $_POST["frommail"] .">";
  90            $replyto = $_POST["replytoname"]. " <" . $_POST["replytomail"].">";
  91            $message = $_POST["message"];
  92            if ($_POST["action"] == 'send') {
  93          $subject = $langs->trans("Bill")." $fac->ref";
  94          $actiontypeid=9;
  95          $actionmsg ="Mail envoyé par $from à $sendto.<br>";
  96          if ($message) {
  97            $actionmsg.="Texte utilisé dans le corps du message:<br>";
  98            $actionmsg.="$message";
  99          }
 100          $actionmsg2="Envoi facture par mail";
 101            }
 102            if ($_POST["action"] == 'relance')     {
 103          $subject = "Relance facture $fac->ref";
 104          $actiontypeid=10;
 105          $actionmsg="Mail envoyé par $from à $sendto.<br>";
 106          if ($message) {
 107            $actionmsg.="Texte utilisé dans le corps du message:<br>";
 108            $actionmsg.="$message";
 109          }
 110          $actionmsg2="Relance facture par mail";
 111            }
 112  
 113            $filepath[0] = $file;
 114            $filename[0] = $fac->ref.".pdf";
 115            $mimetype[0] = "application/pdf";
 116            $filepath[1] = $_FILES['addedfile']['tmp_name'];
 117            $filename[1] = $_FILES['addedfile']['name'];
 118            $mimetype[1] = $_FILES['addedfile']['type'];
 119  
 120            // Envoi de la facture
 121            $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc);
 122  
 123            if ($mailfile->sendfile())
 124                  {
 125            $msg='<div class="ok">'.$langs->trans("MailSuccessfulySent",$from,$sendto).'.</div>';
 126  
 127            // Insertion action
 128            include_once("../contact.class.php");
 129            include_once("../actioncomm.class.php");
 130            $actioncomm = new ActionComm($db);
 131            $actioncomm->type_id     = $actiontypeid;
 132            $actioncomm->label       = $actionmsg2;
 133            $actioncomm->note        = $actionmsg;
 134            $actioncomm->date        = time();
 135            $actioncomm->percent     = 100;
 136            $actioncomm->contact     = new Contact($db,$sendtoid);
 137            $actioncomm->societe     = new Societe($db,$fac->socidp);
 138            $actioncomm->user        = $user;   // User qui a fait l'action
 139            $actioncomm->facid       = $fac->id;
 140  
 141            $ret=$actioncomm->add($user);       // User qui saisi l'action
 142  
 143            if ($ret < 0)
 144                      {
 145                dolibarr_print_error($db);
 146                      }
 147            else
 148                      {
 149                // Renvoie sur la fiche
 150                Header("Location: facture.php?facid=".$fac->id."&msg=".urlencode($msg));
 151                exit;
 152                      }
 153                  }
 154            else
 155                  {
 156            $msg='<div class="error">'.$langs->trans("ErrorFailedToSendMail",$from,$sendto).' !</div>';
 157                  }
 158              }
 159        else
 160              {
 161            $msg='<div class="error">'.$langs->trans("ErrorMailRecipientIsEmpty").'</div>';
 162            dolibarr_syslog("Le mail du destinataire est vide");
 163              }
 164  
 165          }
 166        else
 167          {
 168        dolibarr_syslog("Impossible de lire :".$file);
 169          }
 170      }
 171      else
 172        {
 173          dolibarr_syslog("Impossible de lire les données de la facture. Le fichier facture n'a peut-être pas été généré.");
 174        }
 175  }
 176  
 177  
 178  
 179  
 180  llxHeader('',$langs->trans("Bill"),'Facture');
 181  
 182  $html = new Form($db);
 183  
 184  
 185  
 186  
 187  if ($_GET["facid"] > 0)
 188  {
 189    if ($msg) print "$msg<br>";
 190    
 191    $fac = New Facture($db);
 192    if ( $fac->fetch($_GET["facid"], $user->societe_id) > 0)
 193      {      
 194        $soc = new Societe($db, $fac->socidp);
 195        $soc->fetch($fac->socidp, $user);
 196              
 197        if (!$soc->perm_read)
 198      {
 199        print "Lecture non authorisée";
 200      }
 201        
 202        if ($soc->perm_read)
 203      {      
 204        $author = new User($db);
 205        $author->id = $fac->user_author;
 206        $author->fetch();
 207        
 208        $h = 0;
 209        
 210        $head[$h][0] = DOL_URL_ROOT.'/telephonie/client/fiche.php?id='.$soc->id;
 211        $head[$h][1] = $langs->trans("Fiche client");
 212        $h++;
 213        
 214        $head[$h][0] = DOL_URL_ROOT.'/telephonie/client/factures.php?id='.$soc->id;
 215        $head[$h][1] = $langs->trans("Factures");
 216        $h++;
 217        
 218        $head[$h][0] = DOL_URL_ROOT.'/telephonie/client/facture.php?facid='.$fac->id;
 219        $head[$h][1] = $langs->trans("CardBill");
 220        $hselected = $h;
 221        $h++;
 222        
 223        dolibarr_fiche_head($head, $hselected, $langs->trans("Bill")." : $fac->ref");
 224        
 225        /*
 226         *   Facture
 227         */
 228        print '<table class="border" width="100%">';
 229        print '<tr><td>'.$langs->trans("Company").'</td>';
 230        print '<td colspan="3">';
 231        print '<b><a href="fiche.php?id='.$soc->id.'">'.$soc->nom.'</a></b></td>';
 232        
 233        print "<td>Conditions de réglement</td><td>" . $fac->cond_reglement ."</td></tr>";
 234        
 235        print '<tr><td>'.$langs->trans("Date").'</td>';
 236        print "<td colspan=\"3\">".dolibarr_print_date($fac->date,"%A %d %B %Y")."</td>\n";
 237        print '<td>'.$langs->trans("DateClosing").'</td><td>' . dolibarr_print_date($fac->date_lim_reglement,"%A %d %B %Y");
 238        print "</td></tr>";
 239        
 240        print '<tr>';
 241        
 242        // Projet
 243        if ($conf->projet->enabled)
 244      {
 245        $langs->load("projects");
 246        print '<td>';
 247        print '<table width="100%" class="nobordernopadding"><tr><td>';
 248        print $langs->trans("Project");
 249        print '</td>';
 250        if ($_GET["action"] != "classer") print '<td align="right"></td>';
 251        print '</tr></table>';
 252        print '</td><td colspan="3">';
 253        if ($_GET["action"] == "classer")
 254          {
 255            $html->form_project("facture.php?facid=$fac->id",$fac->fk_soc,$fac->projetid,"projetid");
 256          }
 257        else
 258          {
 259            $html->form_project("facture.php?facid=$fac->id",$fac->fk_soc,$fac->projetid,"none");
 260          }
 261        print "</td>";
 262      } else {
 263        print '<td height=\"10\">&nbsp;</td><td colspan="3">&nbsp;</td>';
 264      }
 265        
 266        print '<td rowspan="8" colspan="2" valign="top">';
 267        
 268        /*
 269         * Paiements
 270         */
 271        print $langs->trans("Payments").' :<br>';
 272        $sql = "SELECT ".$db->pdate("datep")." as dp, pf.amount,";
 273        $sql.= " c.libelle as paiement_type, p.num_paiement, p.rowid";
 274        $sql.= " FROM ".MAIN_DB_PREFIX."paiement as p, ".MAIN_DB_PREFIX."c_paiement as c, ".MAIN_DB_PREFIX."paiement_facture as pf";
 275        $sql.= " WHERE pf.fk_facture = ".$fac->id." AND p.fk_paiement = c.id AND pf.fk_paiement = p.rowid";
 276        $sql.= " ORDER BY dp DESC";
 277        
 278        $result = $db->query($sql);
 279        
 280        if ($result)
 281      {
 282        $num = $db->num_rows($result);
 283        $i = 0; $total = 0;
 284        print '<table class="noborder" width="100%">';
 285        print '<tr class="liste_titre"><td>'.$langs->trans("Date").'</td><td>'.$langs->trans("Type").'</td>';
 286        print '<td align="right">'.$langs->trans("Amount").'</td><td>&nbsp;</td></tr>';
 287        
 288        $var=True;
 289        while ($i < $num)
 290          {
 291            $objp = $db->fetch_object($result);
 292            $var=!$var;
 293            print "<tr $bc[$var]><td>";
 294            print "&nbsp;".strftime("%d %B %Y",$objp->dp)."</td>\n";
 295            print "<td>$objp->paiement_type $objp->num_paiement</td>\n";
 296            print '<td align="right">'.price($objp->amount)."</td><td>".$langs->trans("Currency".$conf->monnaie)."</td>\n";
 297            print "</tr>";
 298            $totalpaye += $objp->amount;
 299            $i++;
 300          }
 301        
 302        if ($fac->paye == 0)
 303          {
 304            print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("AlreadyPayed")." :</td><td align=\"right\"><b>".price($totalpaye)."</b></td><td>".$langs->trans("Currency".$conf->monnaie)."</td></tr>\n";
 305            print "<tr><td colspan=\"2\" align=\"right\">Facturé :</td><td align=\"right\" style=\"border: 1px solid;\">".price($fac->total_ttc)."</td><td>".$langs->trans("Currency".$conf->monnaie)."</td></tr>\n";
 306            
 307            $resteapayer = $fac->total_ttc - $totalpaye;
 308            
 309            print "<tr><td colspan=\"2\" align=\"right\">".$langs->trans("RemainderToPay")." :</td>";
 310            print "<td align=\"right\" style=\"border: 1px solid;\" bgcolor=\"#f0f0f0\"><b>".price($resteapayer)."</b></td><td>".$langs->trans("Currency".$conf->monnaie)."</td></tr>\n";
 311          }
 312        print "</table>";
 313        $db->free($result);
 314      } else {
 315        dolibarr_print_error($db);
 316      }
 317  
 318        print "</td></tr>";
 319        
 320        print "<tr><td height=\"10\">".$langs->trans("Author")."</td><td colspan=\"3\">$author->fullname</td></tr>";
 321        
 322        print '<tr><td height=\"10\">'.$langs->trans("GlobalDiscount").'</td>';
 323        if ($fac->brouillon == 1 && $user->rights->facture->creer)
 324      {
 325        print '<form action="facture.php?facid='.$fac->id.'" method="post">';
 326        print '<input type="hidden" name="action" value="setremise">';
 327        print '<td colspan="3"><input type="text" name="remise" size="3" value="'.$fac->remise_percent.'">% ';
 328        print '<input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
 329        print '</form>';
 330      }
 331        else
 332      {
 333        print '<td colspan="3">'.$fac->remise_percent.'%</td>';
 334      }
 335        print '</tr>';
 336        
 337        print '<tr><td height=\"10\">'.$langs->trans("AmountHT").'</td>';
 338        print '<td align="right" colspan="2"><b>'.price($fac->total_ht).'</b></td>';
 339        print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
 340        
 341        print '<tr><td height=\"10\">'.$langs->trans("VAT").'</td><td align="right" colspan="2">'.price($fac->total_tva).'</td>';
 342        print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
 343        print '<tr><td height=\"10\">'.$langs->trans("AmountTTC").'</td><td align="right" colspan="2">'.price($fac->total_ttc).'</td>';
 344        print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
 345        
 346        print '<tr><td height=\"10\">'.$langs->trans("Status").'</td><td align="left" colspan="3">'.($fac->getLibStatut()).'</td></tr>';
 347        
 348        if ($fac->note)
 349      {
 350        print '<tr><td colspan="4">'.$langs->trans("Note").' : '.nl2br($fac->note)."</td></tr>";
 351      }
 352        else {
 353      print '<tr><td colspan="4">&nbsp;</td></tr>';
 354        }
 355        
 356        print "</table><br>";
 357        
 358        /*
 359         * Lignes de factures
 360         *
 361         */
 362        $sql  = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux";
 363        $sql .= " , l.remise_percent, l.subprice,";
 364        $sql .= $db->pdate("l.date_start")." as date_start";
 365        $sql .= " , ".$db->pdate("l.date_end")." as date_end, ";
 366        $sql .= " p.fk_product_type";
 367        $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as l ";
 368        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product p ON l.fk_product=p.rowid";
 369        $sql .= " WHERE l.fk_facture = ".$fac->id;
 370        $sql .= " ORDER BY l.rang ASC, l.rowid";
 371        
 372        $resql = $db->query($sql);
 373        if ($resql)
 374      {
 375        $num_lignes = $db->num_rows($resql);
 376        $i = 0; $total = 0;
 377        
 378        print '<table class="noborder" width="100%">';
 379        if ($num_lignes)
 380          {
 381            print "<tr class=\"liste_titre\">";
 382            print '<td>'.$langs->trans("Description").'</td>';
 383            print '<td width="50" align="right">'.$langs->trans("VAT").'</td>';
 384            print '<td width="80" align="right">'.$langs->trans("PriceUHT").'</td>';
 385            print '<td width="50" align="right">'.$langs->trans("Qty").'</td>';
 386            print '<td width="50" align="right">'.$langs->trans("Discount").'</td>';
 387            print '<td width="80" align="right">'.$langs->trans("AmountHT").'</td>';
 388            print '<td colspan="3">&nbsp;</td>';
 389            print "</tr>\n";
 390          }
 391        $var=True;
 392        while ($i < $num_lignes)
 393          {
 394            $objp = $db->fetch_object($resql);
 395            $var=!$var;
 396            
 397            // Update ligne de facture
 398            if ($_GET["action"] != 'editline' || $_GET["rowid"] != $objp->rowid)
 399          {
 400            
 401            print "<tr $bc[$var]>";
 402            if ($objp->fk_product > 0)
 403              {
 404                print '<td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';
 405                if ($objp->fk_product_type) print img_object($langs->trans("ShowService"),"service");
 406                else print img_object($langs->trans("ShowProduct"),"product");
 407                print ' '.stripslashes(nl2br($objp->description)).'</a>';
 408                if ($objp->date_start && $objp->date_end) { print " (Du ".dolibarr_print_date($objp->date_start)." au ".dolibarr_print_date($objp->date_end).")"; }
 409                if ($objp->date_start && ! $objp->date_end) { print " (A partir du ".dolibarr_print_date($objp->date_start).")"; }
 410                if (! $objp->date_start && $objp->date_end) { print " (Jusqu'au ".dolibarr_print_date($objp->date_end).")"; }
 411                print '</td>';
 412              }
 413            else
 414              {
 415                print "<td>".stripslashes(nl2br($objp->description));
 416                if ($objp->date_start && $objp->date_end) { print " (Du ".dolibarr_print_date($objp->date_start)." au ".dolibarr_print_date($objp->date_end).")"; }
 417                if ($objp->date_start && ! $objp->date_end) { print " (A partir du ".dolibarr_print_date($objp->date_start).")"; }
 418                if (! $objp->date_start && $objp->date_end) { print " (Jusqu'au ".dolibarr_print_date($objp->date_end).")"; }
 419                print "</td>\n";
 420              }
 421            
 422            print '<td align="right">'.$objp->tva_taux.'%</td>';
 423            print '<td align="right">'.price($objp->subprice)."</td>\n";
 424            print '<td align="right">'.$objp->qty.'</td>';
 425            if ($objp->remise_percent > 0)
 426              {
 427                print '<td align="right">'.$objp->remise_percent."%</td>\n";
 428              }
 429            else
 430              {
 431                print '<td>&nbsp;</td>';
 432              }
 433            print '<td align="right">'.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."</td>\n";
 434  
 435            // Icone d'edition et suppression
 436            if ($fac->statut == 0  && $user->rights->facture->creer)
 437              {
 438                print '<td align="right"><a href="facture.php?facid='.$fac->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
 439                print img_edit();
 440                print '</a></td>';
 441                print '<td align="right"><a href="facture.php?facid='.$fac->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">';
 442                print img_delete();
 443                print '</a></td>';
 444  
 445                print '<td align="right">';
 446                if ($i > 0)
 447              {
 448                print '<a href="facture.php?facid='.$fac->id.'&amp;action=up&amp;rowid='.$objp->rowid.'">';
 449                print img_up();
 450                print '</a>';
 451              }
 452                if ($i < $num_lignes-1)
 453              {
 454                print '<a href="facture.php?facid='.$fac->id.'&amp;action=down&amp;rowid='.$objp->rowid.'">';
 455                print img_down();
 456                print '</a></td>';
 457              }
 458              }
 459            else
 460              {
 461                print '<td colspan="3">&nbsp;</td>';
 462              }
 463            print "</tr>";
 464  
 465          }
 466  
 467  
 468  
 469            $total = $total + ($objp->qty * $objp->price);
 470            $i++;
 471          }
 472  
 473        $db->free($resql);
 474      }
 475        else
 476      {
 477        dolibarr_print_error($db);
 478      }
 479  
 480        /*
 481         * Ajouter une ligne
 482         */
 483  
 484        print "</table>\n";
 485  
 486  
 487        print "</div>\n";
 488  
 489  
 490        /*
 491         * Boutons actions
 492         */
 493  
 494        if ($user->societe_id == 0 && $_GET["action"] <> 'valid' && $_GET["action"] <> 'editline')
 495      {
 496        print "<div class=\"tabsAction\">\n";
 497  
 498  
 499  
 500  
 501  
 502        // Envoyer
 503        if ($fac->statut == 1 && $user->rights->facture->envoyer)
 504          {
 505            print "  <a class=\"tabAction\" href=\"".$_SERVER["PHP_SELF"]."?facid=$fac->id&amp;action=presend\">".$langs->trans("Send")."</a>\n";
 506          }
 507  
 508        // Envoyer une relance
 509        if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer)
 510          {
 511            print "  <a class=\"tabAction\" href=\"".$_SERVER["PHP_SELF"]."?facid=$fac->id&amp;action=prerelance\">".$langs->trans("SendRemind")."</a>\n";
 512          }
 513  
 514  
 515  
 516  
 517  
 518        print "</div>\n";
 519  
 520      }
 521  
 522        print '<table width="100%"><tr><td width="50%" valign="top">';
 523  
 524        /*
 525         * Documents générés
 526         * Le fichier de facture détaillée est de la forme
 527         * REFFACTURE-XXXXXX-detail.pdf ou XXXXX est une forme diverse
 528         */
 529  
 530        $facref = sanitize_string($fac->ref);
 531        $file = $conf->facture->dir_output . "/" . $facref . "/" . $facref . ".pdf";
 532        $relativepath = "$facref}/$facref}.pdf";
 533  
 534        $var=true;
 535  
 536        if (file_exists($file))
 537      {
 538        print "<br>\n";
 539        print_titre("Documents");
 540        print '<table class="border" width="100%">';
 541  
 542        print "<tr $bc[$var]><td>".$langs->trans("Bill")." PDF</td>";
 543  
 544        print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=facture&file='.urlencode($relativepath).'">'.$fac->ref.'.pdf</a></td>';
 545        print '<td align="right">'.filesize($file). ' bytes</td>';
 546        print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($file)).'</td>';
 547        print '</tr>';
 548  
 549  
 550        $dir = $conf->facture->dir_output . "/" . $facref . "/";
 551        $handle=opendir($dir);
 552  
 553        while (($file = readdir($handle))!==false)
 554          {
 555            if (is_readable($dir.$file) && substr($file, -10) == 'detail.pdf')
 556          {
 557            print "<tr $bc[$var]><td>Facture détaillée</td>";
 558            $relativepathdetail = "$facref}/$file";
 559  
 560            print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=facture&file='.urlencode($relativepathdetail).'">'.$file.'</a></td>';
 561            print '<td align="right">'.filesize($dir.$file). ' bytes</td>';
 562            print '<td align="right">'.strftime("%d %b %Y %H:%M:%S",filemtime($dir.$file)).'</td>';
 563            print '</tr>';
 564          }
 565          }
 566        print "</table>\n";
 567      }
 568  
 569  
 570        /*
 571         *   Propales
 572         */
 573        $sql = "SELECT ".$db->pdate("p.datep")." as dp, p.price, p.ref, p.rowid as propalid";
 574        $sql .= " FROM ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."fa_pr as fp WHERE fp.fk_propal = p.rowid AND fp.fk_facture = $fac->id";
 575  
 576        $resql = $db->query($sql);
 577        if ($resql)
 578      {
 579        $num = $db->num_rows($resql);
 580        if ($num)
 581          {
 582            $i = 0; $total = 0;
 583            print "<br>";
 584            print_titre($langs->trans("RelatedCommercialProposals"));
 585  
 586            print '<table class="noborder" width="100%">';
 587            print '<tr class="liste_titre">';
 588            print '<td>'.$langs->trans("Ref").'</td>';
 589            print '<td>'.$langs->trans("Date").'</td>';
 590            print '<td align="right">'.$langs->trans("Price").'</td>';
 591            print "</tr>\n";
 592  
 593            $var=True;
 594            while ($i < $num)
 595          {
 596            $objp = $db->fetch_object($resql);
 597            $var=!$var;
 598            print "<tr $bc[$var]>";
 599            print '<td><a href="propal.php?propalid='.$objp->propalid.'">'.img_object($langs->trans("ShowPropal"),"propal").' '.$objp->ref.'</a></td>';
 600            print "<td>".dolibarr_print_date($objp->dp)."</td>\n";
 601            print '<td align="right">'.price($objp->price).'</td>';
 602            print "</tr>";
 603            $total = $total + $objp->price;
 604            $i++;
 605          }
 606            print "<tr class=\"liste_total\"><td>&nbsp;</td><td align=\"left\">".$langs->trans("TotalHT")."</td><td align=\"right\">".price($total)."</td></tr>\n";
 607            print "</table>";
 608          }
 609      }
 610        else
 611      {
 612        dolibarr_print_error($db);
 613      }
 614  
 615  
 616        print '</td><td valign="top" width="50%">';
 617  
 618        /*
 619         * Liste des actions propres à la facture
 620         */
 621        $sql = "SELECT id, ".$db->pdate("a.datea")." as da, a.label, a.note, code";
 622        $sql .= " FROM ".MAIN_DB_PREFIX."actioncomm as a, ".MAIN_DB_PREFIX."user as u ";
 623        $sql .= " WHERE a.fk_user_author = u.rowid ";
 624        $sql .= " AND a.fk_action in (9,10) ";
 625        $sql .= " AND a.fk_soc = ".$fac->socidp ;
 626        $sql .= " AND a.fk_facture = ".$fac->id;
 627  
 628        $resql = $db->query($sql);
 629        if ($resql)
 630      {
 631        $num = $db->num_rows($resql);
 632        if ($num)
 633          {
 634            print "<br>\n";
 635            print_titre($langs->trans("ActionsOnBill"));
 636  
 637            $i = 0; $total = 0;
 638            print '<table class="border" width="100%">';
 639            print '<tr '.$bc[$var].'><td>'.$langs->trans("Ref").'</td><td>'.$langs->trans("Date").'</td><td>'.$langs->trans("Action").'</td><td>'.$langs->trans("By").'</td></tr>';
 640            print "\n";
 641  
 642            $var=True;
 643            while ($i < $num)
 644          {
 645            $objp = $db->fetch_object($resql);
 646            $var=!$var;
 647            print "<tr $bc[$var]>";
 648            print '<td>'.img_object($langs->trans("ShowTask"),"task").' '.$objp->id.'</td>';
 649            print '<td>'.dolibarr_print_date($objp->da)."</td>\n";
 650            print '<td>'.stripslashes($objp->label).'</td>';
 651            print '<td>'.$objp->code.'</td>';
 652            print "</tr>\n";
 653            $i++;
 654          }
 655            print "</table>\n";
 656          }
 657      }
 658        else
 659      {
 660        dolibarr_print_error($db);
 661      }
 662  
 663        print "</td></tr></table>";
 664  
 665  
 666        /*
 667         * Affiche formulaire mail
 668         */
 669        if ($_GET["action"] == 'presend')
 670      {
 671        print '<br>';
 672        print_titre($langs->trans("SendBillByMail"));
 673  
 674        $liste[0]="&nbsp;";
 675        foreach ($soc->contact_email_array() as $key=>$value) {
 676          $liste[$key]=$value;
 677        }
 678  
 679        // Créé l'objet formulaire mail
 680        include_once(DOL_DOCUMENT_ROOT."/html.formmail.class.php");
 681        $formmail = new FormMail($db);
 682        $formmail->fromname = $user->fullname;
 683        $formmail->frommail = $user->email;
 684        $formmail->withfrom=1;
 685        $formmail->withto=$liste;
 686        $formmail->withcc=1;
 687        $formmail->withtopic=$langs->trans("SendBillRef","__FACREF__");
 688        $formmail->withfile=1;
 689        $formmail->withbody=1;
 690        // Tableau des substitutions
 691        $formmail->substit["__FACREF__"]=$fac->ref;
 692        // Tableau des paramètres complémentaires du post
 693        $formmail->param["action"]="send";
 694        $formmail->param["models"]="facture_send";
 695        $formmail->param["facid"]=$fac->id;
 696        $formmail->param["returnurl"]=DOL_URL_ROOT."/telephonie/client/facture.php?facid=$fac->id";
 697  
 698        $formmail->show_form();
 699  
 700        print '<br>';
 701      }
 702  
 703        if ($_GET["action"] == 'prerelance')
 704      {
 705        print '<br>';
 706        print_titre($langs->trans("SendReminderBillByMail"));
 707  
 708        $liste[0]="&nbsp;";
 709        foreach ($soc->contact_email_array() as $key=>$value)
 710          {
 711            $liste[$key]=$value;
 712          }
 713  
 714        // Créé l'objet formulaire mail
 715        include_once("../html.formmail.class.php");
 716        $formmail = new FormMail($db);
 717        $formmail->fromname = $user->fullname;
 718        $formmail->frommail = $user->email;
 719        $formmail->withfrom=1;
 720        $formmail->withto=$liste;
 721        $formmail->withcc=1;
 722        $formmail->withtopic=$langs->trans("SendReminderBillRef","__FACREF__");
 723        $formmail->withfile=1;
 724        $formmail->withbody=1;
 725        // Tableau des substitutions
 726        $formmail->substit["__FACREF__"]=$fac->ref;
 727        // Tableau des paramètres complémentaires
 728        $formmail->param["action"]="relance";
 729        $formmail->param["models"]="facture_relance";
 730        $formmail->param["facid"]=$fac->id;
 731        $formmail->param["returnurl"]=DOL_URL_ROOT."/compta/facture.php?facid=$fac->id";
 732  
 733        $formmail->show_form();
 734  
 735        print '<br>';
 736      }
 737  
 738        }
 739  
 740  
 741      }
 742    else
 743      {
 744        /* Facture non trouvée */
 745        print $langs->trans("ErrorBillNotFound",$_GET["facid"]);
 746      }
 747  
 748  }
 749  
 750  $db->close();
 751  
 752  llxFooter('$Date: 2005/09/06 10:25:00 $ - $Revision: 1.4 $');
 753  ?>


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