[ 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/product/ -> fournisseurs.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   * Copyright (C) 2004      Eric Seigne          <eric.seigne@ryxeo.com>
   5   * Copyright (C) 2005      Regis Houssin        <regis.houssin@cap-networks.com>
   6   *
   7   * This program is free software; you can redistribute it and/or modify
   8   * it under the terms of the GNU General Public License as published by
   9   * the Free Software Foundation; either version 2 of the License, or
  10   * (at your option) any later version.
  11   *
  12   * This program is distributed in the hope that it will be useful,
  13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15   * GNU General Public License for more details.
  16   *
  17   * You should have received a copy of the GNU General Public License
  18   * along with this program; if not, write to the Free Software
  19   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20   *
  21   * $Id: fournisseurs.php,v 1.26.2.1 2005/12/25 00:39:56 eldy Exp $
  22   * $Source: /cvsroot/dolibarr/dolibarr/htdocs/product/fournisseurs.php,v $
  23   */
  24  
  25  /**
  26          \file       htdocs/product/fournisseurs.php
  27          \ingroup    product
  28          \brief      Page de la fiche produit
  29          \version    $Revision: 1.26.2.1 $
  30  */
  31  
  32  require ("./pre.inc.php");
  33  require_once (DOL_DOCUMENT_ROOT."/propal.class.php");
  34  require_once (DOL_DOCUMENT_ROOT."/facture.class.php");
  35  require_once(DOL_DOCUMENT_ROOT."/product.class.php");
  36  
  37  $langs->load("products");
  38  $langs->load("suppliers");
  39  $langs->load("bills");
  40  
  41  $user->getrights('produit');
  42  $user->getrights('propale');
  43  $user->getrights('facture');
  44  $mesg = '';
  45  
  46  if (! $user->rights->produit->lire) accessforbidden();
  47  
  48  $types[0] = $langs->trans("Product");
  49  $types[1] = $langs->trans("Service");
  50  
  51  
  52  /*
  53   * Actions
  54   */
  55   
  56  if ($_GET["action"] == 'remove_fourn')
  57  {
  58      $product = new Product($db);
  59      if( $product->fetch($_GET["id"]) )
  60      {
  61          if ($_GET["qty"]) { // On supprime une quantité
  62              if ($product->remove_price($user, $_GET["id_fourn"], $_GET["qty"]) > 0)
  63              {
  64                  $_GET["action"] = '';
  65                  $mesg = '<div class="ok">'.$langs->trans("PriceRemoved").'.</div>';
  66              }
  67              else
  68              {
  69                  $_GET["action"] = '';
  70              }
  71          }
  72          else {              // On supprime un fournisseur
  73              if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0)
  74              {
  75                  $_GET["action"] = '';
  76                  $mesg = '<div class="ok">'.$langs->trans("SupplierRemoved").'.</div>';
  77              }
  78              else
  79              {
  80                  $_GET["action"] = '';
  81              }
  82          }
  83      }
  84  }
  85  
  86  if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel"))
  87  {
  88  
  89      $product = new Product($db);
  90      if( $product->fetch($_GET["id"]) )
  91      {
  92          $db->begin();
  93  
  94          $error=0;
  95  
  96          if ($_POST["ref_fourn"]) {
  97              $ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]);
  98              if ($ret < 0) {
  99                  $error++;
 100                  $mesg='<div class="error">'.$product->error.'</div>';
 101              }
 102          }
 103          else {
 104              $error++;
 105              $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("Ref")).'</div>';
 106          }
 107          
 108          if ($_POST["qty"] && $_POST["price"] > 0) {
 109              $ret=$product->update_buyprice($_POST["id_fourn"], $_POST["qty"], $_POST["price"], $user);
 110              if ($ret < 0) {
 111                  $error++;
 112                  $mesg='<div class="error">'.$product->error.'</div>';
 113              }
 114          }
 115          
 116          if (! $error)
 117          {
 118              $db->commit();
 119          }
 120          else {
 121              $db->rollback();
 122          }
 123      }
 124  }
 125  
 126  if ($_POST["cancel"] == $langs->trans("Cancel"))
 127  {
 128      $action = '';
 129      Header("Location: fournisseurs.php?id=".$_GET["id"]);
 130      exit;
 131  }
 132  
 133  
 134  llxHeader("","",$langs->trans("CardProduct".$product->type));
 135  
 136  
 137  /*
 138   * Fiche produit
 139   */
 140  if ($_GET["id"] || $_GET["ref"])
 141  {
 142      if ($_GET["action"] <> 're-edit')
 143      {
 144          $product = new Product($db);
 145          if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
 146          if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
 147      }
 148  
 149      if ( $result )
 150      { 
 151        
 152        if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit')
 153      {
 154        /*
 155         *  En mode visu
 156         */
 157  
 158        // Zone recherche
 159        /* Deja présent dans menu gauche
 160        print '<div class="formsearch">';
 161        print '<form action="liste.php" method="post">';
 162        print '<input type="hidden" name="type" value="'.$product->type.'">';
 163        print $langs->trans("Ref").': <input class="flat" type="text" size="10" name="sref">&nbsp;<input class="flat" type="submit" value="'.$langs->trans("Go").'"> &nbsp;';
 164        print $langs->trans("Label").': <input class="flat" type="text" size="20" name="snom">&nbsp;<input class="flat" type="submit" value="'.$langs->trans("Go").'">';
 165        print '</form></div>';      
 166        */
 167        
 168        $h=0;
 169        
 170        $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id;
 171        $head[$h][1] = $langs->trans("Card");
 172        $h++;
 173        
 174        $head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$product->id;
 175        $head[$h][1] = $langs->trans("Price");
 176        $h++;
 177  
 178           if($product->type == 0)
 179           {
 180               if ($user->rights->barcode->lire)
 181               {
 182                   if ($conf->barcode->enabled)
 183                   {
 184                       $head[$h][0] = DOL_URL_ROOT."/product/barcode.php?id=".$product->id;
 185                       $head[$h][1] = $langs->trans("BarCode");
 186                       $h++;
 187                   }
 188               }
 189           }
 190  
 191        
 192          $head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
 193          $head[$h][1] = $langs->trans("Photos");
 194          $h++;
 195        
 196        if($product->type == 0)
 197          {
 198            if ($conf->stock->enabled)
 199              {
 200                $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
 201                $head[$h][1] = 'Stock';
 202                $h++;
 203              }
 204          }
 205          
 206            if ($conf->fournisseur->enabled)
 207          {
 208                  $head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$product->id;
 209                  $head[$h][1] = $langs->trans("Suppliers");
 210                  $hselected = $h;
 211                  $h++;
 212          }
 213  
 214          $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
 215          $head[$h][1] = $langs->trans('Statistics');
 216          $h++;
 217          
 218          //erics: pour créer des produits composés de x 'sous' produits
 219          /*
 220          $head[$h][0] = DOL_URL_ROOT."/product/pack.php?id=".$product->id;
 221          $head[$h][1] = $langs->trans('Packs');
 222          $h++;
 223          */
 224          
 225          $head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$product->id;
 226          $head[$h][1] = $langs->trans('Referers');
 227          $h++;
 228        
 229          $head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$product->id;
 230          $head[$h][1] = $langs->trans('Documents');
 231          $h++;
 232  
 233          $titre=$langs->trans("CardProduct".$product->type);
 234          dolibarr_fiche_head($head, $hselected, $titre);
 235  
 236          print '<table class="border" width="100%">';
 237  
 238          // Reference
 239          print '<tr>';
 240          print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
 241          $product->load_previous_next_ref();
 242          $previous_ref = $product->ref_previous?'<a href="'.$_SERVER["PHP_SELF"].'?ref='.$product->ref_previous.'">'.img_previous().'</a>':'';
 243          $next_ref     = $product->ref_next?'<a href="'.$_SERVER["PHP_SELF"].'?ref='.$product->ref_next.'">'.img_next().'</a>':'';
 244          if ($previous_ref || $next_ref) print '<table class="nobordernopadding" width="100%"><tr class="nobordernopadding"><td class="nobordernopadding">';
 245          print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'">'.$product->ref.'</a>';
 246          if ($previous_ref || $next_ref) print '</td><td class="nobordernopadding" align="center" width="20">'.$previous_ref.'</td><td class="nobordernopadding" align="center" width="20">'.$next_ref.'</td></tr></table>';
 247          print '</td>';
 248          print '</tr>';
 249      
 250          // Libelle
 251          print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td></tr>';
 252        
 253          // Prix
 254          print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">'.price($product->price).'</td></tr>';
 255  
 256          // Statut
 257          print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
 258          if ($product->envente) print $langs->trans("OnSell");
 259          else print $langs->trans("NotOnSell");
 260          print '</td></tr>';
 261  
 262        print '</table>';
 263        
 264        print "</div>\n";
 265  
 266          if ($mesg) print($mesg);
 267  
 268  
 269          // Formulaire ajout prix
 270            if ($_GET["action"] == 'add_price' && $user->rights->produit->creer)
 271              {
 272                $langs->load("suppliers");
 273                
 274                if ($_GET["id_fourn"]) {
 275                    print_fiche_titre($langs->trans("ChangeSupplierPrice"));
 276                } else {
 277                    print_fiche_titre($langs->trans("AddSupplierPrice"));
 278                }          
 279                print '<table class="border" width="100%">';
 280                print '<form action="fournisseurs.php?id='.$product->id.'" method="post">';
 281                print '<input type="hidden" name="action" value="updateprice">';
 282  
 283                if ($_GET["id_fourn"]) {
 284                  print '<input type="hidden" name="id_fourn" value="'.$_GET["id_fourn"].'">';
 285                  $product->fetch_fourn_data($_GET["id_fourn"]);
 286                  print '<input type="hidden" name="ref_fourn" value="'.$product->ref_fourn.'">';
 287                } else {
 288                    print '<tr><td>'.$langs->trans("Supplier").'</td><td colspan="3">';
 289                    $html=new Form($db);
 290                    $html->select_societes('','id_fourn','fournisseur=1');
 291                    print '</td></tr>';
 292                    print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
 293                  print '<input class="flat" name="ref_fourn" size="25" value="">';
 294                    print '</td></tr>';
 295              }
 296                            
 297                print '<tr><td>'.$langs->trans("Qty").'</td>';
 298                 print '<td><input class="flat" name="qty" size="5" value="'.$_GET["qty"].'"></td>';
 299                print '<td>'.$langs->trans("Price").'</td>';
 300                print '<td><input class="flat" name="price" size="8" value="'.price($_GET["price"]).'"></td></tr>';
 301  
 302                print '<tr><td colspan="4" align="center"><input class="button" type="submit" value="'.$langs->trans("Save").'">&nbsp;';
 303                print '<input class="button" type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
 304                print '</form>';
 305                print '</table>';
 306              }    
 307  
 308          /* ************************************************************************** */
 309          /*                                                                            */ 
 310          /* Barre d'action                                                             */ 
 311          /*                                                                            */ 
 312          /* ************************************************************************** */
 313          
 314          print "\n<div class=\"tabsAction\">\n";
 315          
 316          if ($_GET["action"] != 'add_price') {
 317  
 318              if ($user->rights->produit->creer)
 319                          {
 320                  print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$product->id.'&amp;action=add_price">';
 321                  print $langs->trans("AddSupplier").'</a>';
 322              }
 323  
 324          }
 325          
 326          print "\n</div>\n";
 327          print '<br>';
 328  
 329  
 330        // Titre liste des fournisseurs
 331        print '<table class="noborder" width="100%">';
 332        if ($product->type == 0) $nblignefour=4;
 333        else $nblignefour=4;
 334        print '<tr class="liste_titre"><td valign="top">';
 335        print $langs->trans("Suppliers").'</td>';
 336        print '<td>'.$langs->trans("Ref").'</td>';
 337        print '<td align="center">'.$langs->trans("Qty").'</td>';
 338        print '<td align="right">'.$langs->trans("BuyingPrice").'</td>';
 339        print '<td align="right">'.$langs->trans("UnitPrice").'</td>';
 340        print '<td>&nbsp;</td>';
 341        print '</tr>';
 342  
 343        // Liste des fournisseurs
 344        $sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity";
 345        $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf";
 346        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
 347        $sql.= " ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product";
 348        $sql.= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id;
 349        $sql.= " ORDER BY lower(s.nom), pfp.quantity";
 350  
 351        $resql=$db->query($sql);
 352        if ($resql)
 353          {
 354            $num = $db->num_rows($resql);
 355            $i = 0;
 356  
 357            $var=True;      
 358            while ($i < $num)
 359          {
 360            $objp = $db->fetch_object($resql);
 361            $var=!$var;
 362            
 363            print "<tr $bc[$var]>";
 364            print '<td><a href="../fourn/fiche.php?socid='.$objp->idp.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.'</a></td>';
 365  
 366            // Fournisseur
 367            print '<td align="left">'.$objp->ref_fourn.'</td>';
 368  
 369            // Quantité
 370            print '<td align="center">';
 371            print $objp->quantity;
 372            print '</td>';
 373  
 374            // Prix quantité
 375            print '<td align="right">';
 376            print $objp->price?price($objp->price):"";
 377            print '</td>';
 378            
 379            // Prix unitaire
 380            print '<td align="right">';
 381            print $objp->quantity?price($objp->price / $objp->quantity):"&nbsp;";
 382            print '</td>';
 383            
 384            // Modifier-Supprimer
 385            print '<td align="center">';
 386            if ($user->rights->produit->creer) {
 387                  print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=add_price&amp;id_fourn='.$objp->idp.'&amp;qty='.$objp->quantity.'&amp;price='.$objp->price.'">'.img_edit()."</a>";
 388                  print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=remove_fourn&amp;id_fourn='.$objp->idp.'&amp;qty='.$objp->quantity.'">';
 389            }
 390            print img_disable($langs->trans("Remove")).'</a>';
 391            print '</td>';
 392            
 393            print '</tr>';
 394  
 395            $i++;
 396          }
 397  
 398            $db->free($resql);
 399          }
 400          else {
 401              dolibarr_print_error($db);
 402          }
 403          
 404          print '</table>';
 405      }
 406      }
 407  }
 408  else
 409  {
 410    print $langs->trans("ErrorUnknown");
 411  }
 412  
 413  
 414  $db->close();
 415  
 416  llxFooter('$Date: 2005/12/25 00:39:56 $ - $Revision: 1.26.2.1 $');
 417  ?>


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