| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
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: fiche.php,v 1.15 2005/10/09 23:08:18 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/fourn/product/fiche.php,v $ 21 */ 22 23 /** 24 \file htdocs/fourn/product/fiche.php 25 \ingroup product 26 \brief Page de la fiche produit 27 \version $Revision: 1.15 $ 28 */ 29 30 require ("./pre.inc.php"); 31 require_once(DOL_DOCUMENT_ROOT."/product.class.php"); 32 33 $langs->load("products"); 34 35 $user->getrights('produit'); 36 $user->getrights('propale'); 37 $user->getrights('facture'); 38 $mesg = ''; 39 40 if (!$user->rights->produit->lire) accessforbidden(); 41 42 43 $types[0] = $langs->trans("Product"); 44 $types[1] = $langs->trans("Service"); 45 46 /* 47 * 48 */ 49 50 if ($_GET["action"] == 'fastappro') 51 { 52 $product = new Product($db); 53 $product->fetch($_GET["id"]); 54 $result = $product->fastappro($user); 55 Header("Location: fiche.php?id=".$_GET["id"]); 56 } 57 58 59 // Action ajout d'un produit ou service 60 if ($_POST["action"] == 'add' && $user->rights->produit->creer) 61 { 62 $product = new Product($db); 63 64 $product->ref = $_POST["ref"]; 65 $product->libelle = $_POST["libelle"]; 66 $product->price = $_POST["price"]; 67 $product->catid = $_POST["catid"]; 68 $product->tva_tx = $_POST["tva_tx"]; 69 $product->type = $_POST["type"]; 70 $product->envente = $_POST["statut"]; 71 $product->description = $_POST["desc"]; 72 $product->duration_value = $_POST["duration_value"]; 73 $product->duration_unit = $_POST["duration_unit"]; 74 $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; 75 76 $e_product = $product; 77 78 $id = $product->create($user); 79 if ($id > 0) 80 { 81 Header("Location: fiche.php?id=$id"); 82 } 83 else 84 { 85 if ($id == -3) 86 { 87 $mesg='<div class="error">'.$product->error.'</div>'; 88 $_error = 1; 89 $_GET["action"] = "create"; 90 $_GET["type"] = $_POST["type"]; 91 } 92 } 93 } 94 95 // Action mise a jour d'un produit ou service 96 if ($_POST["action"] == 'update' && 97 $_POST["cancel"] <> $langs->trans("Cancel") && 98 $user->rights->produit->creer) 99 { 100 $product = new Product($db); 101 if ($product->fetch($_POST["id"])) 102 { 103 $product->ref = $_POST["ref"]; 104 $product->libelle = $_POST["libelle"]; 105 $product->price = $_POST["price"]; 106 $product->description = $_POST["desc"]; 107 $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"]; 108 $product->duration_value = $_POST["duration_value"]; 109 $product->duration_unit = $_POST["duration_unit"]; 110 111 if ($product->check()) 112 { 113 if ($product->update($product->id, $user) > 0) 114 { 115 $_GET["action"] = ''; 116 $_GET["id"] = $_POST["id"]; 117 118 Header("Location: fiche.php?id=".$_POST["id"]); 119 120 } 121 else 122 { 123 $_GET["action"] = 're-edit'; 124 $_GET["id"] = $_POST["id"]; 125 $mesg = $product->mesg_error; 126 } 127 } 128 else 129 { 130 $_GET["action"] = 're-edit'; 131 $_GET["id"] = $_POST["id"]; 132 $mesg = $langs->trans("ErrorProductBadRefOrLabel"); 133 } 134 } 135 } 136 137 if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel")) 138 { 139 140 $product = new Product($db); 141 if( $product->fetch($_GET["id"]) ) 142 { 143 if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0) 144 { 145 $action = ''; 146 } 147 else 148 { 149 $action = ''; 150 } 151 } 152 } 153 if ($_GET["action"] == 'remove_fourn') 154 { 155 $product = new Product($db); 156 if( $product->fetch($_GET["id"]) ) 157 { 158 if ($product->remove_fournisseur($user, $_GET["id_fourn"]) > 0) 159 { 160 $_GET["action"] = ''; 161 $mesg = $langs->trans("SupplierRemoved"); 162 } 163 else 164 { 165 $_GET["action"] = ''; 166 } 167 } 168 } 169 170 171 if ($_POST["action"] == 'update_price' && 172 $_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer) 173 { 174 $product = new Product($db); 175 176 $result = $product->fetch($_GET["id"]); 177 178 $product->price = ereg_replace(" ","",$_POST["price"]); 179 180 if ( $product->update_price($product->id, $user) > 0 ) 181 182 { 183 $_GET["action"] = ''; 184 $mesg = 'Fiche mise à jour'; 185 } 186 else 187 { 188 $_GET["action"] = 'edit_price'; 189 $mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error; 190 } 191 } 192 193 194 if ($_POST["cancel"] == $langs->trans("Cancel")) 195 { 196 $action = ''; 197 Header("Location: fiche.php?id=".$_POST["id"]); 198 } 199 200 201 // Le produit n'est pas encore chargé a ce stade 202 llxHeader("","",$langs->trans("CardProduct0")); 203 204 /* 205 * Création du produit 206 * 207 */ 208 if ($_GET["action"] == 'create' && $user->rights->produit->creer) 209 { 210 $html = new Form($db); 211 $nbligne=0; 212 $product = new Product($db); 213 if ($_error == 1) 214 { 215 $product = $e_product; 216 } 217 218 print '<form action="fiche.php" method="post">'; 219 print '<input type="hidden" name="action" value="add">'; 220 print '<input type="hidden" name="type" value="'.$_GET["type"].'">'."\n"; 221 print '<input type="hidden" name="catid" value="'.$_REQUEST["catid"].'">'."\n"; 222 223 if ($_GET["type"]==0) { $title=$langs->trans("NewProduct"); } 224 if ($_GET["type"]==1) { $title=$langs->trans("NewService"); } 225 print_fiche_titre($title); 226 227 print '<table class="border" width="100%">'; 228 229 if ($mesg) print $mesg; 230 231 if ($conf->categorie->enabled) 232 { 233 print '<tr><td>'.$langs->trans("Categorie"); 234 print '</td><td>'; 235 236 if (isset($_REQUEST["catid"])) 237 { 238 $c = new Categorie ($db, $_REQUEST["catid"]); 239 $ways = $c->print_all_ways(' > ','fourn/product/liste.php'); 240 print $ways[0]."<br />\n"; 241 } 242 print '</td></tr>'; 243 } 244 245 print '<tr><td>'.$langs->trans("Ref").'</td><td><input name="ref" size="20" value="'.$product->ref.'">'; 246 if ($_error == 1) 247 { 248 print $langs->trans("RefAlreadyExists"); 249 } 250 print '</td></tr>'; 251 print '<tr><td>'.$langs->trans("Label").'</td><td><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>'; 252 253 if ($_GET["type"] == 0 && $conf->stock->enabled) 254 { 255 print "<tr>".'<td>Seuil stock</td><td colspan="2">'; 256 print '<input name="seuil_stock_alerte" size="4" value="0">'; 257 print '</td></tr>'; 258 } 259 else 260 { 261 print '<input name="seuil_stock_alerte" type="hidden" value="0">'; 262 } 263 print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>'; 264 print '<textarea name="desc" rows="8" cols="50">'; 265 print "</textarea></td></tr>"; 266 if ($_GET["type"] == 1) 267 { 268 print '<tr><td>'.$langs->trans("Duration").'</td><td><input name="duration_value" size="6" maxlength="5" value="'.$product->duree.'"> '; 269 print '<input name="duration_unit" type="radio" value="d">'.$langs->trans("Day").' '; 270 print '<input name="duration_unit" type="radio" value="w">'.$langs->trans("Week").' '; 271 print '<input name="duration_unit" type="radio" value="m">'.$langs->trans("Month").' '; 272 print '<input name="duration_unit" type="radio" value="y">'.$langs->trans("Year").' '; 273 print '</td></tr>'; 274 } 275 276 print '<tr><td> </td><td><input type="submit" class="button" value="'.$langs->trans("Create").'"></td></tr>'; 277 print '</table>'; 278 print '</form>'; 279 } 280 else 281 { 282 /* 283 * Fiche produit 284 */ 285 if ($_GET["id"]) 286 { 287 288 if ($_GET["action"] <> 're-edit') 289 { 290 $product = new Product($db); 291 $result = $product->fetch($_GET["id"]); 292 } 293 294 if ( $product->id > 0 ) 295 { 296 297 if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit') 298 { 299 /* 300 * En mode visu 301 */ 302 303 $h=0; 304 305 $head[$h][0] = DOL_URL_ROOT."/fourn/product/fiche.php?id=".$product->id; 306 $head[$h][1] = $langs->trans("Card"); 307 $hselected = $h; 308 $h++; 309 310 if($product->type == 0) 311 { 312 if ($conf->stock->enabled) 313 { 314 $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id; 315 $head[$h][1] = $langs->trans("Stock"); 316 $h++; 317 } 318 319 } 320 321 $head[$h][0] = DOL_URL_ROOT."/fourn/product/photos.php?id=".$product->id; 322 $head[$h][1] = $langs->trans("Photos"); 323 $h++; 324 325 //Affichage onglet Catégories 326 if ($conf->categorie->enabled){ 327 $head[$h][0] = DOL_URL_ROOT."/fourn/product/categorie.php?id=".$product->id; 328 $head[$h][1] = $langs->trans('Categories'); 329 $h++; 330 } 331 332 $head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id; 333 $head[$h][1] = $langs->trans("CommercialCard"); 334 $h++; 335 336 dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); 337 338 if ($mesg) print($mesg); 339 340 print '<table class="border" width="100%">'; 341 342 if ($conf->categorie->enabled) 343 { 344 print '<tr id="ways">'; 345 print '<td colspan="3">'; 346 $cat = new Categorie ($db); 347 $way = $cat->print_primary_way($product->id," > ",'fourn/product/liste.php'); 348 if ($way == "") 349 { 350 print "Ce produit n'appartient à aucune catégorie"; 351 } 352 else 353 { 354 print $langs->trans("Categorie")." : "; 355 print $way; 356 } 357 print '</td>'; 358 print '</tr>'; 359 } 360 361 print "<tr>"; 362 print '<td width="20%">'.$langs->trans("Ref").'</td><td width="40%">'.$product->ref.'</td>'; 363 print '<td width="40%">'; 364 if ($product->envente) 365 { 366 print $langs->trans("OnSell"); 367 } 368 else 369 { 370 print $langs->trans("NotOnSell"); 371 } 372 print '</td></tr>'; 373 print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td></tr>'; 374 print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>'.price($product->price).'</td>'; 375 376 $nblignefour=2; 377 if ($product->type == 0 && $conf->stock->enabled) $nblignefour++; 378 if ($product->type == 1) $nblignefour++; 379 380 print '<td valign="middle" align="center" rowspan="'.$nblignefour.'">'; 381 $product->show_photo($conf->produit->dir_output,1); 382 print '</td></tr>'; 383 384 // Description 385 print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>'.nl2br($product->description).'</td></tr>'; 386 387 // Stock 388 if ($product->type == 0 && $conf->stock->enabled) 389 { 390 print '<tr><td><a href="'.DOL_URL_ROOT.'/product/stock/product.php?id='.$product->id.'">'.$langs->trans("Stock").'</a></td>'; 391 if ($product->no_stock) 392 { 393 print "<td>Pas de définition de stock pour ce produit"; 394 } 395 else 396 { 397 if ($product->stock_reel <= $product->seuil_stock_alerte) 398 { 399 print '<td class="alerte">'.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte; 400 } 401 else 402 { 403 print "<td>".$product->stock_reel; 404 } 405 } 406 print '</td></tr>'; 407 } 408 409 // Duration 410 if ($product->type == 1) 411 { 412 print '<tr><td>'.$langs->trans("Duration").'</td><td>'.$product->duration_value.' '; 413 414 if ($product->duration_value > 1) 415 { 416 $dur=array("d"=>$langs->trans("Days"),"w"=>$langs->trans("Weeks"),"m"=>$langs->trans("Months"),"y"=>$langs->trans("Years")); 417 } 418 else 419 { 420 $dur=array("d"=>$langs->trans("Day"),"w"=>$langs->trans("Week"),"m"=>$langs->trans("Month"),"y"=>$langs->trans("Year")); 421 } 422 print $langs->trans($dur[$product->duration_unit])." "; 423 424 print '</td></tr>'; 425 } 426 print "</table><br>\n"; 427 428 // Liste des fournisseurs 429 print '<table class="noborder" width="100%">'; 430 print '<tr class="liste_titre"><td>'; 431 print $langs->trans("Suppliers").'</td>'; 432 print '<td>'.$langs->trans("Ref").'</td>'; 433 print '<td align="right">'.$langs->trans("BuiingPrice").'</td>'; 434 print '<td align="center">'.$langs->trans("Quantity").'</td>'; 435 print '</tr>'; 436 437 $sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity"; 438 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf"; 439 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON s.idp = pfp.fk_soc"; 440 $sql .= " AND pfp.fk_product =".$product->id; 441 $sql .= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id; 442 $sql .= " ORDER BY pfp.price ASC, lower(s.nom)"; 443 444 if ( $db->query($sql) ) 445 { 446 $num_fournisseur = $db->num_rows($resql); 447 $i = 0; 448 $var=True; 449 while ($i < $num_fournisseur) 450 { 451 $objp = $db->fetch_object($resql); 452 $var=!$var; 453 print "<tr $bc[$var]>"; 454 print '<td><a href="'.DOL_URL_ROOT.'/fourn/fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>'; 455 print '<td>'; 456 print '<a href="fourn.php?id='.$product->id.'&id_fourn='.$objp->idp.'">'; 457 print img_edit($langs->trans("Edit")); 458 print ' <a href="fourn.php?id='.$product->id.'&id_fourn='.$objp->idp.'">'; 459 print $objp->ref_fourn.'</a></td>'; 460 461 print '<td align="right">'; 462 print price($objp->price); 463 print '</td>'; 464 print '<td align="center">'.$objp->quantity.'</td></tr>'; 465 $i++; 466 } 467 $db->free(); 468 } 469 print '</table>'; 470 print "</div>\n"; 471 472 473 /* 474 * Ajouter un fournisseur 475 * 476 */ 477 if ($_GET["action"] == 'ajout_fourn' && $user->rights->produit->creer) 478 { 479 $langs->load("suppliers"); 480 481 print_titre($langs->trans("AddSupplier")); 482 print '<form action="fiche.php?id='.$product->id.'" method="post">'; 483 print '<input type="hidden" name="action" value="add_fourn">'; 484 print '<input type="hidden" name="id" value="'.$product->id.'">'; 485 print '<table class="border" width="100%"><tr>'; 486 print '<td>'.$langs->trans("Suppliers").'</td><td><select name="id_fourn">'; 487 488 $sql = "SELECT s.idp, s.nom, s.ville"; 489 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s WHERE s.fournisseur=1"; 490 $sql .= " ORDER BY lower(s.nom)"; 491 492 $resql = $db->query($sql); 493 if ($resql) 494 { 495 $num = $db->num_rows($resql); 496 $i = 0; 497 while ($i < $num) 498 { 499 $obj = $db->fetch_object($resql); 500 print '<option value="'.$obj->idp.'">'.$obj->nom . ($obj->ville?" ($obj->ville)":""); 501 $i++; 502 } 503 $db->free($resql); 504 } 505 print '</select></td></tr><tr><td>'.$langs->trans("SupplierRef").'</td>'; 506 print '<td><input name="ref_fourn" size="25" value=""></td></tr>'; 507 print '<tr><td colspan="2" align="center">'; 508 print '<input type="submit" value="'.$langs->trans("Save").'"> '; 509 print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>'; 510 print '</table>'; 511 print '</form>'; 512 } 513 } 514 515 /* 516 * Fiche en mode edition 517 */ 518 if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer) 519 { 520 521 print_fiche_titre('Edition de la fiche '.$types[$product->type].' : '.$product->ref, ""); 522 523 if ($mesg) { 524 print '<br><div class="error">'.$mesg.'</div><br>'; 525 } 526 527 print "<form action=\"fiche.php\" method=\"post\">\n"; 528 print '<input type="hidden" name="action" value="update">'; 529 print '<input type="hidden" name="id" value="'.$product->id.'">'; 530 print '<table class="border" width="100%">'; 531 print "<tr>".'<td width="20%">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" size="20" value="'.$product->ref.'"></td></tr>'; 532 print '<td>'.$langs->trans("Label").'</td><td colspan="2"><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>'; 533 534 535 if ($product->type == 0 && $conf->stock->enabled) 536 { 537 print "<tr>".'<td>Seuil stock</td><td colspan="2">'; 538 print '<input name="seuil_stock_alerte" size="4" value="'.$product->seuil_stock_alerte.'">'; 539 print '</td></tr>'; 540 } 541 else 542 { 543 print '<input name="seuil_stock_alerte" type="hidden" value="0">'; 544 } 545 print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="2">'; 546 print '<textarea name="desc" rows="8" cols="50">'; 547 print $product->description; 548 print "</textarea></td></tr>"; 549 550 if ($product->type == 1) 551 { 552 print '<tr><td>'.$langs->trans("Duration").'</td><td colspan="2"><input name="duration_value" size="3" maxlength="5" value="'.$product->duration_value.'">'; 553 print ' '; 554 print '<input name="duration_unit" type="radio" value="d"'.($product->duration_unit=='d'?' checked':'').'>'.$langs->trans("Day"); 555 print ' '; 556 print '<input name="duration_unit" type="radio" value="w"'.($product->duration_unit=='w'?' checked':'').'>'.$langs->trans("Week"); 557 print ' '; 558 print '<input name="duration_unit" type="radio" value="m"'.($product->duration_unit=='m'?' checked':'').'>'.$langs->trans("Month"); 559 print ' '; 560 print '<input name="duration_unit" type="radio" value="y"'.($product->duration_unit=='y'?' checked':'').'>'.$langs->trans("Year"); 561 562 print '</td></tr>'; 563 } 564 565 print '<tr><td colspan="3" align="center"><input type="submit" value="'.$langs->trans("Save").'"> '; 566 print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>'; 567 print '</table>'; 568 print '</form>'; 569 } 570 571 572 573 574 /* ************************************************************************** */ 575 /* */ 576 /* Barre d'action */ 577 /* */ 578 /* ************************************************************************** */ 579 580 print "\n<div class=\"tabsAction\">\n"; 581 582 if ($_GET["action"] == '') 583 { 584 585 print '<a class="butAction" href="fiche.php?id='.$product->id.'&action=ajout_fourn">'.$langs->trans("AddSupplier").'</a>'; 586 587 if ($product->type == 0 && $user->rights->produit->commander && $num_fournisseur == 1) 588 { 589 print '<a class="tabAction" href="fiche.php?action=fastappro&id='.$product->id.'">'; 590 print $langs->trans("Order").'</a>'; 591 } 592 593 if ( $user->rights->produit->creer) 594 { 595 print '<a class="tabAction" href="fiche.php?action=edit&id='.$product->id.'">'.$langs->trans("Edit").'</a>'; 596 } 597 598 if ($product->type == 0 && $conf->stock->enabled) 599 { 600 print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/stock/product.php?id='.$product->id.'&action=correction">'.$langs->trans("CorrectStock").'</a>'; 601 } 602 } 603 604 print "\n</div>\n"; 605 606 } 607 else 608 { 609 print $langs->trans("BadId"); 610 } 611 } 612 else 613 { 614 print $langs->trans("BadId"); 615 } 616 } 617 618 $db->close(); 619 620 llxFooter('$Date: 2005/10/09 23:08:18 $ - $Revision: 1.15 $'); 621 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|