[ 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/expedition/ -> commande.php (source)

   1  <?php
   2  /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3   * Copyright (C) 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: commande.php,v 1.26.2.2 2006/01/14 13:43:08 eldy Exp $
  20   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/expedition/commande.php,v $
  21   */
  22  
  23  // Code identique a /expedition/fiche.php
  24  
  25  /**
  26          \file       htdocs/expedition/commande.php
  27          \ingroup    expedition
  28          \version    $Revision: 1.26.2.2 $
  29  */
  30  
  31  require ("./pre.inc.php");
  32  require_once(DOL_DOCUMENT_ROOT."/product.class.php");
  33  require_once(DOL_DOCUMENT_ROOT."/project.class.php");
  34  require_once (DOL_DOCUMENT_ROOT."/propal.class.php");
  35  require_once(DOL_DOCUMENT_ROOT."/product/stock/entrepot.class.php");
  36  
  37  
  38  $user->getrights('commande');
  39  $user->getrights('expedition');
  40  if (!$user->rights->commande->lire)
  41      accessforbidden();
  42  
  43  
  44  // Sécurité accés client
  45  if ($user->societe_id > 0)
  46  {
  47      $action = '';
  48      $socidp = $user->societe_id;
  49  }
  50  
  51  
  52  /*
  53   * Actions
  54   */
  55  if ($_POST["action"] == 'confirm_cloture' && $_POST["confirm"] == 'yes')
  56  {
  57      $commande = new Commande($db);
  58      $commande->fetch($_GET["id"]);
  59      $result = $commande->cloture($user);
  60  }
  61  
  62  
  63  $html = new Form($db);
  64  
  65  
  66  /* *************************************************************************** */
  67  /*                                                                             */
  68  /* Mode vue et edition                                                         */
  69  /*                                                                             */
  70  /* *************************************************************************** */
  71  
  72  llxHeader('',$langs->trans("OrderCard"));
  73  
  74  
  75  if ($_GET["id"] > 0)
  76  {
  77      $commande = New Commande($db);
  78      if ( $commande->fetch($_GET["id"]) > 0)
  79      {
  80          $commande->livraison_array(1);
  81  
  82          $soc = new Societe($db);
  83          $soc->fetch($commande->soc_id);
  84          $author = new User($db);
  85          $author->id = $commande->user_author_id;
  86          $author->fetch();
  87  
  88          $h=0;
  89  
  90          if ($conf->commande->enabled && $user->rights->commande->lire)
  91          {
  92              $head[$h][0] = DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id;
  93              $head[$h][1] = $langs->trans("OrderCard");
  94              $h++;
  95          }
  96  
  97          if ($conf->expedition->enabled && $user->rights->expedition->lire)
  98          {
  99              $head[$h][0] = DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id;
 100              $head[$h][1] = $langs->trans("SendingCard");
 101              $hselected = $h;
 102              $h++;
 103          }
 104  
 105          if ($conf->compta->enabled)
 106          {
 107              $head[$h][0] = DOL_URL_ROOT.'/compta/commande/fiche.php?id='.$commande->id;
 108              $head[$h][1] = $langs->trans("ComptaCard");
 109              $h++;
 110          }
 111  
 112          $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$commande->id;
 113          $head[$h][1] = $langs->trans("Info");
 114          $h++;
 115  
 116          dolibarr_fiche_head($head, $hselected, $langs->trans("Order").": $commande->ref");
 117  
 118          /*
 119           * Confirmation de la validation
 120           *
 121           */
 122          if ($_GET["action"] == 'cloture')
 123          {
 124              $html->form_confirm("commande.php?id=".$_GET["id"],"Clôturer la commande","Etes-vous sûr de vouloir clôturer cette commande ?","confirm_cloture");
 125              print "<br />";
 126          }
 127  
 128          // Onglet commande
 129          print '<table class="border" width="100%">';
 130  
 131          // Ref
 132          print '<tr><td width="15%">'.$langs->trans('Ref').'</td>';
 133          print '<td colspan="2">'.$commande->ref.'</td>';
 134          print '<td width="50%">'.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ;
 135          if ($commande->source == 0)
 136          {
 137              // Si source = propal
 138              $propal = new Propal($db);
 139              $propal->fetch($commande->propale_id);
 140              print ' -> <a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id.'">'.$propal->ref.'</a>';
 141          }
 142          print '</td></tr>';
 143          
 144          // Société
 145          print '<tr><td>'.$langs->trans('Customer').'</td>';
 146          print '<td colspan="3">';
 147          print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>';
 148          print '</tr>';
 149          
 150          $nbrow=3;
 151          
 152          // Ref commande client
 153          print '<tr><td>';
 154          print '<table class="nobordernopadding" width="100%"><tr><td nowrap>';
 155          print $langs->trans('RefCdeClient').'</td><td align="left">';
 156          print '</td>';
 157          print '</tr></table>';
 158          print '</td><td colspan="2">';
 159          print $commande->ref_client;
 160          print '</td>';
 161          print '<td rowspan="'.$nbrow.'" valign="top">'.$langs->trans('Note').' :<br>';
 162          print nl2br($commande->note);
 163          print '</td>';
 164          print '</tr>';
 165          
 166          print '<tr><td>'.$langs->trans('Status').'</td>';
 167          print '<td colspan="2">'.$commande->statuts[$commande->statut].'</td>';
 168          print '</tr>';
 169          
 170          print '<tr><td>'.$langs->trans('Date').'</td>';
 171          print '<td colspan="2">'.dolibarr_print_date($commande->date,'%A %d %B %Y').'</td>';
 172          print '</tr>';
 173          
 174          print '</table>';
 175  
 176          /**
 177           *  Lignes de commandes avec quantité livrées et reste à livrer
 178           *
 179           */
 180          echo '<br><table class="liste" width="100%">';
 181  
 182          $sql = "SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice";
 183          $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as l ";
 184          $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product = p.rowid";
 185          $sql.= " WHERE l.fk_commande = ".$commande->id;
 186          $sql.= " AND p.fk_product_type <> 1";
 187          $sql.= " ORDER BY l.rowid";
 188  
 189          $resql = $db->query($sql);
 190          if ($resql)
 191          {
 192              $num = $db->num_rows($resql);
 193              $i = 0;
 194  
 195              print '<tr class="liste_titre">';
 196              print '<td>'.$langs->trans("Description").'</td>';
 197              print '<td align="center">'.$langs->trans("QtyOrdered").'</td>';
 198              print '<td align="center">'.$langs->trans("QtyShipped").'</td>';
 199              print '<td align="center">'.$langs->trans("KeepToShip").'</td>';
 200              if ($conf->stock->enabled)
 201              {
 202                  print '<td align="center">'.$langs->trans("Stock").'</td>';
 203              }
 204              print "</tr>\n";
 205  
 206              $var=true;
 207              $reste_a_livrer = array();
 208              while ($i < $num)
 209              {
 210                  $objp = $db->fetch_object($resql);
 211  
 212                  $var=!$var;
 213                  print "<tr $bc[$var]>";
 214                  if ($objp->fk_product > 0)
 215                  {
 216                      $product = new Product($db);
 217                      $product->fetch($objp->fk_product);
 218                      print '<td>';
 219                      print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';
 220                      print img_object($langs->trans("Product"),"product").' '.$product->ref.'</a>';
 221                      print $product->libelle?' - '.$product->libelle:'';
 222                      print '</td>';
 223                  }
 224                  else
 225                  {
 226                      print "<td>".stripslashes(nl2br($objp->description))."</td>\n";
 227                  }
 228  
 229                  print '<td align="center">'.$objp->qty.'</td>';
 230  
 231                  print '<td align="center">';
 232                  $quantite_livree = $commande->livraisons[$objp->fk_product];
 233                  print $quantite_livree;
 234                  print '</td>';
 235  
 236                  $reste_a_livrer[$objp->fk_product] = $objp->qty - $quantite_livree;
 237                  $reste_a_livrer_x = $objp->qty - $quantite_livree;
 238                  $reste_a_livrer_total = $reste_a_livrer_total + $reste_a_livrer_x;
 239                  print '<td align="center">';
 240                  print $reste_a_livrer[$objp->fk_product];
 241                  print '</td>';
 242  
 243                  if ($conf->stock->enabled)
 244                  {
 245                      if ($product->stock_reel < $reste_a_livrer_x)
 246                      {
 247                          print '<td align="center" class="alerte">'.$product->stock_reel.'</td>';
 248                      }
 249                      else
 250                      {
 251                          print '<td align="center">'.$product->stock_reel.'</td>';
 252                      }
 253                  }
 254                  print "</tr>";
 255  
 256                  $i++;
 257                  $var=!$var;
 258              }
 259              $db->free();
 260              print "</table>";
 261              
 262              if (! $num)
 263              {
 264                  print $langs->trans("None").'<br>';
 265              }
 266  
 267          }
 268          else
 269          {
 270              dolibarr_print_error($db);
 271          }
 272  
 273          print '</div>';
 274          
 275          
 276          /*
 277           * Boutons Actions
 278           */
 279          if ($user->societe_id == 0)
 280          {
 281              print '<div class="tabsAction">';
 282  
 283              if (! $conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->brouillon == 0 && $user->rights->expedition->creer)
 284              {
 285                  print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/fiche.php?action=create&amp;commande_id='.$_GET["id"].'">'.$langs->trans("NewSending").'</a>';
 286              }
 287  
 288              print "</div>";
 289  
 290          }
 291  
 292  
 293          /**
 294           *  Formulaire nouvelle expedition depuis un entrepot
 295           */
 296          if ($conf->stock->enabled && $reste_a_livrer_total > 0 && $commande->brouillon == 0 && $user->rights->expedition->creer)
 297          {
 298  
 299              print '<form method="GET" action="'.DOL_URL_ROOT.'/expedition/fiche.php">';
 300              print '<input type="hidden" name="action" value="create">';
 301              print '<input type="hidden" name="id" value="'.$commande->id.'">';
 302              print '<input type="hidden" name="commande_id" value="'.$commande->id.'">';
 303              print '<table class="border" width="100%">';
 304  
 305              $entrepot = new Entrepot($db);
 306              $langs->load("stocks");
 307  
 308              print '<tr>';
 309              print '<td>'.$langs->trans("Warehouse").'</td>';
 310              print '<td>';
 311              $html->select_array("entrepot_id",$entrepot->list_array());
 312              if (sizeof($entrepot->list_array()) <= 0) 
 313              {
 314                  print ' &nbsp; Aucun entrepôt définit, <a href="'.DOL_URL_ROOT.'/product/stock/fiche.php?action=create">definissez en un</a>';
 315              }
 316              print '</td></tr>';
 317              /*
 318              print '<tr><td width="20%">Mode d\'expédition</td>';
 319              print '<td>';
 320              $html->select_array("entrepot_id",$entrepot->list_array());
 321              print '</td></tr>';
 322              */
 323  
 324              print '<tr><td align="center" colspan="2">';
 325              print '<input type="submit" class="button" named="save" value="'.$langs->trans("NewSending").'">';
 326              print '</td></tr>';
 327  
 328              print "</table><br>";
 329              print "</form>\n";
 330          }
 331  
 332  
 333          /*
 334           * Alerte de seuil
 335           */
 336          if ($reste_a_livrer_total > 0 && $conf->stock->enabled)
 337          {
 338              print '<br><table class="liste" width="100%"><tr>';
 339              foreach ($reste_a_livrer as $key => $value)
 340              {
 341                  if ($value > 0)
 342                  {
 343                      $sql = "SELECT e.label as entrepot, ps.reel, p.label ";
 344                      $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e, ".MAIN_DB_PREFIX."product_stock as ps, ".MAIN_DB_PREFIX."product as p";
 345                      $sql .= " WHERE e.rowid = ps.fk_entrepot AND ps.fk_product = p.rowid AND ps.fk_product = $key";
 346                      $sql .= " AND e.statut = 1 AND reel < $value";
 347  
 348                      $resql = $db->query($sql);
 349                      if ($resql)
 350                      {
 351                          $num = $db->num_rows($resql);
 352                          $i = 0;
 353  
 354                          $var=True;
 355                          while ($i < $num)
 356                          {
 357                              $obja = $db->fetch_object($resql);
 358                              print "<tr $bc[$var]>";
 359                              print '<td width="54%">'.$obja->label.'</td><td>'.$obja->entrepot.'</td><td><b>Stock : '.$obja->reel.'</b></td>';
 360                              print "</tr>\n";
 361                              $i++;
 362                          }
 363                          $db->free($resql);
 364                      }
 365                      else {
 366                          dolibarr_print_error($db);
 367                      }
 368  
 369                  }
 370              }
 371              print "</table>";
 372          }
 373  
 374          /*
 375           * Déjà livré
 376           */
 377          $sql = "SELECT cd.fk_product, cd.description, cd.rowid, cd.qty as qty_commande";
 378          $sql .= " , ed.qty as qty_livre, e.ref, ed.fk_expedition as expedition_id";
 379          $sql .= ",".$db->pdate("e.date_expedition")." as date_expedition";
 380          $sql .= " FROM ".MAIN_DB_PREFIX."commandedet as cd";
 381          $sql .= " , ".MAIN_DB_PREFIX."expeditiondet as ed, ".MAIN_DB_PREFIX."expedition as e";
 382          $sql .= " WHERE cd.fk_commande = ".$commande->id;
 383          $sql .= " AND cd.rowid = ed.fk_commande_ligne";
 384          $sql .= " AND ed.fk_expedition = e.rowid";
 385          $sql .= " AND e.fk_statut > 0";
 386          $sql .= " ORDER BY cd.fk_product";
 387  
 388          $resql = $db->query($sql);
 389          if ($resql)
 390          {
 391              $num = $db->num_rows($resql);
 392              $i = 0;
 393  
 394              if ($num)
 395              {
 396                  print '<br>';
 397                  
 398                  print_titre($langs->trans("OtherSendingsForSameOrder"));
 399                  print '<table class="liste" width="100%">';
 400                  print '<tr class="liste_titre">';
 401                  print '<td width="54%">'.$langs->trans("Description").'</td>';
 402                  print '<td align="center">Quan. livrée</td>';
 403                  print '<td align="center">'.$langs->trans("Sending").'</td>';
 404                  print '<td align="center">'.$langs->trans("Date").'</td>';
 405                  print "</tr>\n";
 406  
 407                  $var=True;
 408                  while ($i < $num)
 409                  {
 410                      $var=!$var;
 411                      $objp = $db->fetch_object($resql);
 412                      print "<tr $bc[$var]>";
 413                      if ($objp->fk_product > 0)
 414                      {
 415                        $product = new Product($db);
 416                        $product->fetch($objp->fk_product);
 417                        
 418                        print '<td>';
 419                        print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),"product").' '.$product->ref.'</a> - '.$product->libelle;
 420                        if ($objp->description) print nl2br($objp->description);
 421                        print '</td>';
 422                      }
 423                      else
 424                      {
 425                          print "<td>".stripslashes(nl2br($objp->description))."</td>\n";
 426                      }
 427                      print '<td align="center">'.$objp->qty_livre.'</td>';
 428                      print '<td align="center"><a href="'.DOL_URL_ROOT.'/expedition/fiche.php?id='.$objp->expedition_id.'">'.img_object($langs->trans("ShowSending"),'sending').' '.$objp->ref.'<a></td>';
 429                      print '<td align="center">'.dolibarr_print_date($objp->date_expedition).'</td>';
 430                      $i++;
 431                  }
 432  
 433                  print '</table>';
 434              }
 435            $db->free($resql);
 436          }
 437          else {
 438              dolibarr_print_error($db);
 439          }
 440      }
 441      else
 442      {
 443          /* Commande non trouvée */
 444          print "Commande inexistante";
 445      }
 446  }
 447  
 448  
 449  $db->close();
 450  
 451  llxFooter('$Date: 2006/01/14 13:43:08 $ - $Revision: 1.26.2.2 $');
 452  ?>


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