| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com> 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: fiche.php,v 1.74 2005/12/18 22:55:24 eldy Exp $ 21 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/commande/fiche.php,v $ 22 */ 23 24 /** 25 \file htdocs/commande/fiche.php 26 \ingroup commande 27 \brief Fiche commande 28 \version $Revision: 1.74 $ 29 */ 30 31 require ('./pre.inc.php'); 32 33 $langs->load('orders'); 34 $langs->load('sendings'); 35 $langs->load('companies'); 36 $langs->load('bills'); 37 $langs->load('propal'); 38 39 $user->getrights('commande'); 40 $user->getrights('expedition'); 41 42 if (!$user->rights->commande->lire) accessforbidden(); 43 44 require_once(DOL_DOCUMENT_ROOT.'/project.class.php'); 45 require_once(DOL_DOCUMENT_ROOT.'/propal.class.php'); 46 require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); 47 48 // Sécurité accés client 49 $socidp=0; 50 if ($user->societe_id > 0) 51 { 52 $action = ''; 53 $socidp = $user->societe_id; 54 } 55 56 57 /* 58 * Actions 59 */ 60 61 // Categorisation dans projet 62 if ($_POST['action'] == 'classin' && $user->rights->commande->creer) 63 { 64 $commande = new Commande($db); 65 $commande->fetch($_GET['id']); 66 $commande->classin($_POST['projetid']); 67 } 68 69 // Ajout commande 70 if ($_POST['action'] == 'add' && $user->rights->commande->creer) 71 { 72 $datecommande = mktime(12, 0 , 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); 73 74 $commande = new Commande($db); 75 76 $commande->soc_id = $_POST['soc_id']; 77 $commande->date_commande = $datecommande; 78 $commande->note = $_POST['note']; 79 $commande->source = $_POST['source_id']; 80 $commande->projetid = $_POST['projetid']; 81 $commande->remise_percent = $_POST['remise_percent']; 82 $commande->ref_client = $_POST['ref_client']; 83 84 $commande->add_product($_POST['idprod1'],$_POST['qty1'],$_POST['remise_percent1']); 85 $commande->add_product($_POST['idprod2'],$_POST['qty2'],$_POST['remise_percent2']); 86 $commande->add_product($_POST['idprod3'],$_POST['qty3'],$_POST['remise_percent3']); 87 $commande->add_product($_POST['idprod4'],$_POST['qty4'],$_POST['remise_percent4']); 88 $commande->add_product($_POST['idprod5'],$_POST['qty5'],$_POST['remise_percent5']); 89 $commande->add_product($_POST['idprod6'],$_POST['qty6'],$_POST['remise_percent6']); 90 $commande->add_product($_POST['idprod7'],$_POST['qty7'],$_POST['remise_percent7']); 91 $commande->add_product($_POST['idprod8'],$_POST['qty8'],$_POST['remise_percent8']); 92 93 $commande_id = $commande->create($user); 94 95 $_GET['id'] = $commande->id; 96 97 $action = ''; 98 } 99 100 // Positionne ref commande client 101 if ($_POST['action'] == 'set_ref_client' && $user->rights->commande->creer) 102 { 103 $commande = new Commande($db); 104 $commande->fetch($_GET['id']); 105 $commande->set_ref_client($user, $_POST['ref_client']); 106 } 107 108 if ($_POST['action'] == 'setremise' && $user->rights->commande->creer) 109 { 110 $commande = new Commande($db); 111 $commande->fetch($_GET['id']); 112 $commande->set_remise($user, $_POST['remise']); 113 } 114 115 if ($_POST['action'] == 'setnote' && $user->rights->commande->creer) 116 { 117 $commande = new Commande($db); 118 $commande->fetch($_GET['id']); 119 $commande->set_note($user, $_POST['note']); 120 } 121 122 if ($_POST['action'] == 'addligne' && $user->rights->commande->creer) 123 { 124 /* 125 * Ajout d'une ligne produit dans la commande 126 */ 127 if ($_POST['qty'] && (($_POST['pu'] && $_POST['desc']) || $_POST['p_idprod'])) 128 { 129 $commande = new Commande($db); 130 $ret=$commande->fetch($_POST['id']); 131 132 if (isset($_POST['p_idprod'])) 133 { 134 $result = $commande->addline( 135 $_POST['np_desc'], 136 $_POST['pu'], 137 $_POST['qty'], 138 $_POST['tva_tx'], 139 $_POST['p_idprod'], 140 $_POST['remise_percent']); 141 } 142 else 143 { 144 $result = $commande->addline( 145 $_POST['desc'], 146 $_POST['pu'], 147 $_POST['qty'], 148 $_POST['tva_tx'], 149 0, 150 $_POST['remise_percent']); 151 } 152 } 153 } 154 155 if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POST['save'] == $langs->trans('Save')) 156 { 157 $commande = new Commande($db,'',$_POST['id']); 158 if (! $commande->fetch($_POST['id']) > 0) 159 dolibarr_print_error($db); 160 $result = $commande->update_line($_POST['elrowid'], 161 $_POST['eldesc'], 162 $_POST['elprice'], 163 $_POST['elqty'], 164 $_POST['elremise_percent'], 165 $_POST['eltva_tx'] 166 ); 167 168 $_GET['id']=$_POST['id']; // Pour réaffichage de la fiche en cours d'édition 169 } 170 171 if ($_POST['action'] == 'updateligne' && $user->rights->commande->creer && $_POST['cancel'] == $langs->trans('Cancel')) 172 { 173 Header('Location: fiche.php?id='.$_POST['id']); // Pour réaffichage de la fiche en cours d'édition 174 exit; 175 } 176 177 if ($_GET['action'] == 'deleteline' && $user->rights->commande->creer) 178 { 179 $commande = new Commande($db); 180 $commande->fetch($_GET['id']); 181 $result = $commande->delete_line($_GET['lineid']); 182 Header('Location: fiche.php?id='.$_GET['id']); 183 } 184 185 if ($_POST['action'] == 'confirm_valid' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider) 186 { 187 $commande = new Commande($db); 188 $commande->fetch($_GET['id']); 189 $soc = new Societe($db); 190 $soc->fetch($commande->soc_id); 191 $result = $commande->valid($user); 192 } 193 194 if ($_POST['action'] == 'confirm_close' && $_POST['confirm'] == 'yes' && $user->rights->commande->creer) 195 { 196 $commande = new Commande($db); 197 $commande->fetch($_GET['id']); 198 $result = $commande->cloture($user); 199 } 200 201 if ($_POST['action'] == 'confirm_cancel' && $_POST['confirm'] == 'yes' && $user->rights->commande->valider) 202 { 203 $commande = new Commande($db); 204 $commande->fetch($_GET['id']); 205 $result = $commande->cancel($user); 206 } 207 208 if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes') 209 { 210 if ($user->rights->commande->supprimer ) 211 { 212 $commande = new Commande($db); 213 $commande->id = $_GET['id']; 214 $commande->delete(); 215 Header('Location: index.php'); 216 } 217 } 218 219 if ($_GET['action'] == 'pdf') 220 { 221 /* 222 * Generation de la commande 223 * définit dans /includes/modules/commande/modules_commande.php 224 */ 225 commande_pdf_create($db, $_GET['id']); 226 } 227 228 229 llxHeader('',$langs->trans('OrderCard'),'Commande'); 230 231 232 233 $html = new Form($db); 234 235 /********************************************************************* 236 * 237 * Mode creation 238 * 239 *********************************************************************/ 240 if ($_GET['action'] == 'create' && $user->rights->commande->creer) 241 { 242 print_titre($langs->trans('CreateOrder')); 243 244 $new_commande = new Commande($db); 245 246 if ($propalid) 247 { 248 $sql = 'SELECT s.nom, s.prefix_comm, s.idp, p.price, p.remise, p.remise_percent, p.tva, p.total, p.ref, '.$db->pdate('p.datep').' as dp, c.id as statut, c.label as lst'; 249 $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'c_propalst as c'; 250 $sql .= ' WHERE p.fk_soc = s.idp AND p.fk_statut = c.id'; 251 $sql .= ' AND p.rowid = '.$propalid; 252 } 253 else 254 { 255 $sql = 'SELECT s.nom, s.prefix_comm, s.idp '; 256 $sql .= 'FROM '.MAIN_DB_PREFIX.'societe as s '; 257 $sql .= 'WHERE s.idp = '.$_GET['socidp']; 258 } 259 $resql = $db->query($sql); 260 if ( $resql ) 261 { 262 $num = $db->num_rows($resql); 263 if ($num) 264 { 265 $obj = $db->fetch_object($resql); 266 267 $soc = new Societe($db); 268 $soc->fetch($obj->idp); 269 270 $nbrow=4; 271 if ($conf->projet->enabled) $nbrow++; 272 273 print '<form action="fiche.php" method="post">'; 274 print '<input type="hidden" name="action" value="add">'; 275 print '<input type="hidden" name="soc_id" value="'.$soc->id.'">' ."\n"; 276 print '<input type="hidden" name="remise_percent" value="0">'; 277 print '<input name="facnumber" type="hidden" value="provisoire">'; 278 279 print '<table class="border" width="100%">'; 280 281 // Reference 282 print '<tr><td>'.$langs->trans('Ref').'</td><td>Provisoire</td>'; 283 print '<td>'.$langs->trans('Comments').'</td></tr>'; 284 285 // Reference client 286 print '<tr><td>'.$langs->trans('RefCustomer').'</td><td>'; 287 print '<input type="text" name="ref_client" value=""></td>'; 288 print '<td rowspan="'.$nbrow.'" valign="top"><textarea name="note" wrap="soft" cols="50" rows="4"></textarea></td>'; 289 print '</tr>'; 290 291 // Client 292 print '<tr><td>'.$langs->trans('Customer').'</td><td>'.$soc->nom_url.'</td>'; 293 print '</tr>'; 294 295 print '<tr><td>'.$langs->trans('Date').'</td><td>'; 296 $html->select_date(); 297 print '</td></tr>'; 298 299 if ($conf->projet->enabled) 300 { 301 print '<tr><td>'.$langs->trans('Project').'</td><td>'; 302 $html->select_projects($soc->id,'','projetid'); 303 print '</td></tr>'; 304 } 305 306 print '<tr><td>'.$langs->trans('Source').'</td><td>'; 307 $html->select_array('source_id',$new_commande->sources,2); 308 print '</td></tr>'; 309 310 if ($propalid > 0) 311 { 312 $amount = ($obj->price); 313 print '<input type="hidden" name="amount" value="'.$amount.'">'."\n"; 314 print '<input type="hidden" name="total" value="'.$obj->total.'">'."\n"; 315 print '<input type="hidden" name="remise" value="'.$obj->remise.'">'."\n"; 316 print '<input type="hidden" name="remise_percent" value="'.$obj->remise_percent.'">'."\n"; 317 print '<input type="hidden" name="tva" value="'.$obj->tva.'">'."\n"; 318 print '<input type="hidden" name="propalid" value="'.$propalid.'">'; 319 320 print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="2">'.$obj->ref.'</td></tr>'; 321 print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($amount).'</td></tr>'; 322 print '<tr><td>'.$langs->trans('VAT').'</td><td colspan="2">'.price($obj->tva).'</td></tr>'; 323 print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($obj->total).'</td></tr>'; 324 } 325 else 326 { 327 /* 328 * Services/produits prédéfinis 329 */ 330 $NBLINES=8; 331 332 print '<tr><td colspan="3">'; 333 334 print '<table class="noborder">'; 335 print '<tr><td>'.$langs->trans('ProductsAndServices').'</td><td>'.$langs->trans('Qty').'</td><td>'.$langs->trans('Discount').'</td></tr>'; 336 for ($i = 1 ; $i <= $NBLINES ; $i++) 337 { 338 print '<tr><td>'; 339 print $html->select_produits('','idprod'.$i,'',$conf->produit->limit_size); 340 print '</td>'; 341 print '<td><input type="text" size="3" name="qty'.$i.'" value="1"></td>'; 342 print '<td><input type="text" size="3" name="remise_percent'.$i.'" value="0">%</td></tr>'; 343 } 344 345 print '</table>'; 346 print '</td></tr>'; 347 } 348 349 /* 350 * 351 */ 352 print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans('CreateDraft').'"></td></tr>'; 353 print '</form>'; 354 print '</table>'; 355 356 if ($propalid) 357 { 358 /* 359 * Produits 360 */ 361 print_titre($langs->trans('Products')); 362 print '<table class="noborder" width="100%">'; 363 print '<tr class="liste_titre"><td>'.$langs->trans('Ref').'</td><td>'.$langs->trans('Product').'</td>'; 364 print '<td align="right">'.$langs->trans('Price').'</td><td align="center">'.$langs->trans('Discount').'</td><td align="center">'.$langs->trans('Qty').'</td></tr>'; 365 366 $var=false; 367 368 $sql = 'SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.remise_percent'; 369 $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt, '.MAIN_DB_PREFIX.'product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = '.$propalid; 370 $sql .= ' ORDER BY pt.rowid ASC'; 371 $result = $db->query($sql); 372 if ($result) 373 { 374 $num = $db->num_rows($result); 375 $i = 0; 376 while ($i < $num) 377 { 378 $objp = $db->fetch_object($result); 379 $var=!$var; 380 print '<tr '.$bc[$var].'><td>['.$objp->ref.']</td>'; 381 print '<td>'.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.'</td>'; 382 print '<td align="right">'.price($objp->price).'</td>'; 383 print '<td align="center">'.$objp->remise_percent.'%</td>'; 384 print '<td align="center">'.$objp->qty.'</td></tr>'; 385 $i++; 386 } 387 } 388 389 $sql = 'SELECT pt.rowid, pt.description as product, pt.price, pt.qty, pt.remise_percent'; 390 $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt WHERE pt.fk_propal = '.$propalid.' AND pt.fk_product = 0'; 391 $sql .= ' ORDER BY pt.rowid ASC'; 392 if ($db->query($sql)) 393 { 394 $num = $db->num_rows(); 395 $i = 0; 396 while ($i < $num) 397 { 398 $objp = $db->fetch_object(); 399 $var=!$var; 400 print '<tr '.$bc[$var].'><td> </td>'; 401 print '<td>'.img_object($langs->trans('ShowProduct'),'product').' '.$objp->product.'</td>'; 402 print '<td align="right">'.price($objp->price).'</td>'; 403 print '<td align="center">'.$objp->remise_percent.'%</td>'; 404 print '<td align="center">'.$objp->qty.'</td></tr>'; 405 $i++; 406 } 407 } 408 else 409 { 410 dolibarr_print_error($db); 411 } 412 413 print '</table>'; 414 } 415 } 416 } 417 else 418 { 419 dolibarr_print_error($db); 420 } 421 } 422 else 423 /* *************************************************************************** */ 424 /* */ 425 /* Mode vue et edition */ 426 /* */ 427 /* *************************************************************************** */ 428 { 429 $id = $_GET['id']; 430 if ($id > 0) 431 { 432 $commande = new Commande($db); 433 if ( $commande->fetch($_GET['id']) > 0) 434 { 435 $soc = new Societe($db); 436 $soc->fetch($commande->soc_id); 437 438 $author = new User($db); 439 $author->id = $commande->user_author_id; 440 $author->fetch(); 441 442 $h=0; 443 444 if ($conf->commande->enabled && $user->rights->commande->lire) 445 { 446 $head[$h][0] = DOL_URL_ROOT.'/commande/fiche.php?id='.$commande->id; 447 $head[$h][1] = $langs->trans('OrderCard'); 448 $hselected = $h; 449 $h++; 450 } 451 452 if ($conf->expedition->enabled && $user->rights->expedition->lire) 453 { 454 $head[$h][0] = DOL_URL_ROOT.'/expedition/commande.php?id='.$commande->id; 455 $head[$h][1] = $langs->trans('SendingCard'); 456 $h++; 457 } 458 459 if ($conf->compta->enabled) 460 { 461 $head[$h][0] = DOL_URL_ROOT.'/compta/commande/fiche.php?id='.$commande->id; 462 $head[$h][1] = $langs->trans('ComptaCard'); 463 $h++; 464 } 465 466 $head[$h][0] = DOL_URL_ROOT.'/commande/info.php?id='.$commande->id; 467 $head[$h][1] = $langs->trans('Info'); 468 $h++; 469 470 dolibarr_fiche_head($head, $hselected, $langs->trans('Order').': '.$commande->ref); 471 472 /* 473 * Confirmation de la suppression de la commande 474 */ 475 if ($_GET['action'] == 'delete') 476 { 477 $html->form_confirm('fiche.php?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete'); 478 print '<br />'; 479 } 480 481 /* 482 * Confirmation de la validation 483 */ 484 if ($_GET['action'] == 'valid') 485 { 486 //$numfa = commande_get_num($soc); 487 $html->form_confirm('fiche.php?id='.$id, $langs->trans('ValidateOrder'), $langs->trans('ConfirmValidateOrder'), 'confirm_valid'); 488 print '<br />'; 489 } 490 491 /* 492 * Confirmation de la cloture 493 */ 494 if ($_GET['action'] == 'cloture') 495 { 496 //$numfa = commande_get_num($soc); 497 $html->form_confirm('fiche.php?id='.$id, $langs->trans('CloseOrder'), $langs->trans('ConfirmCloseOrder'), 'confirm_close'); 498 print '<br />'; 499 } 500 501 /* 502 * Confirmation de l'annulation 503 */ 504 if ($_GET['action'] == 'annuler') 505 { 506 $html->form_confirm('fiche.php?id='.$id, $langs->trans('Cancel'), $langs->trans('ConfirmCancelOrder'), 'confirm_cancel'); 507 print '<br />'; 508 } 509 510 /* 511 * Commande 512 */ 513 $nbrow=8; 514 if ($conf->projet->enabled) $nbrow++; 515 516 print '<table class="border" width="100%">'; 517 518 // Ref 519 print '<tr><td width="15%">'.$langs->trans('Ref').'</td>'; 520 print '<td colspan="2">'.$commande->ref.'</td>'; 521 print '<td width="50%">'.$langs->trans('Source').' : ' . $commande->sources[$commande->source] ; 522 if ($commande->source == 0) 523 { 524 // Si source = propal 525 $propal = new Propal($db); 526 $propal->fetch($commande->propale_id); 527 print ' -> <a href="'.DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id.'">'.$propal->ref.'</a>'; 528 } 529 print '</td></tr>'; 530 531 // Ref commande client 532 print '<tr><td>'; 533 print '<table class="nobordernopadding" width="100%"><tr><td nowrap>'; 534 print $langs->trans('RefCustomer').'</td><td align="left">'; 535 print '</td>'; 536 if ($_GET['action'] != 'refcdeclient') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refcdeclient&id='.$commande->id.'">'.img_edit($langs->trans('Edit')).'</a></td>'; 537 print '</tr></table>'; 538 print '</td><td colspan="2">'; 539 if ($user->rights->commande->creer && $_GET['action'] == 'refcdeclient') 540 { 541 print '<form action="fiche.php?id='.$id.'" method="post">'; 542 print '<input type="hidden" name="action" value="set_ref_client">'; 543 print '<input type="text" class="flat" size="20" name="ref_client" value="'.$commande->ref_client.'">'; 544 print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">'; 545 print '</form>'; 546 } 547 else 548 { 549 print $commande->ref_client; 550 } 551 print '</td>'; 552 print '<td rowspan="'.$nbrow.'" valign="top">'.$langs->trans('Note').' :<br>'; 553 if ($commande->brouillon == 1 && $user->rights->commande->creer) 554 { 555 print '<form action="fiche.php?id='.$id.'" method="post">'; 556 print '<input type="hidden" name="action" value="setnote">'; 557 print '<textarea name="note" rows="4" style="width:95%;">'.$commande->note.'</textarea><br>'; 558 print '<center><input type="submit" class="button" value="'.$langs->trans('Save').'"></center>'; 559 print '</form>'; 560 } 561 else 562 { 563 print nl2br($commande->note); 564 } 565 print '</td>'; 566 print '</tr>'; 567 568 // Société 569 print '<tr><td>'.$langs->trans('Customer').'</td>'; 570 print '<td colspan="2">'; 571 print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$soc->id.'">'.$soc->nom.'</a></td>'; 572 print '</tr>'; 573 574 print '<tr><td>'.$langs->trans('Status').'</td>'; 575 print '<td colspan="2">'.$commande->statuts[$commande->statut].'</td>'; 576 print '</tr>'; 577 578 print '<tr><td>'.$langs->trans('Date').'</td>'; 579 print '<td colspan="2">'.dolibarr_print_date($commande->date,'%A %d %B %Y').'</td>'; 580 print '</tr>'; 581 582 // Projet 583 if ($conf->projet->enabled) 584 { 585 $langs->load('projects'); 586 print '<tr><td height="10">'; 587 print '<table class="nobordernopadding" width="100%"><tr><td>'; 588 print $langs->trans('Project'); 589 print '</td>'; 590 if ($_GET['action'] != 'classer') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classer&id='.$commande->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>'; 591 print '</tr></table>'; 592 print '</td><td colspan="2">'; 593 if ($_GET['action'] == 'classer') 594 { 595 $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->soc_id, $commande->projet_id, 'projetid'); 596 } 597 else 598 { 599 $html->form_project($_SERVER['PHP_SELF'].'?id='.$commande->id, $commande->soc_id, $commande->projet_id, 'none'); 600 } 601 print '</td></tr>'; 602 } 603 604 // Lignes de 3 colonnes 605 606 print '<tr><td>'; 607 print '<table class="nobordernopadding" width="100%"><tr><td>'; 608 print $langs->trans('GlobalDiscount').'</td><td align="right">'; 609 print '</td>'; 610 if ($_GET['action'] != 'setdiscount') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=setdiscount&id='.$commande->id.'">'.img_edit($langs->trans('Edit')).'</a></td>'; 611 print '</tr></table>'; 612 print '</td>'; 613 if ($user->rights->commande->creer && $_GET['action'] == 'setdiscount') 614 { 615 print '<td align="right">'; 616 print '<form action="fiche.php?id='.$id.'" method="post">'; 617 print '<input type="hidden" name="action" value="setremise">'; 618 print '<input type="text" class="flat" name="remise" size="3" value="'.$commande->remise_percent.'">%'; 619 print '</td><td><input type="submit" class="button" value="'.$langs->trans('Modify').'">'; 620 print '</form>'; 621 print '</td>'; 622 } 623 else 624 { 625 print '<td align="right">'.$commande->remise_percent.'</td><td>%</td>'; 626 } 627 print '</tr>'; 628 629 // Total HT 630 print '<tr><td>'.$langs->trans('TotalHT').'</td>'; 631 print '<td align="right"><b>'.price($commande->total_ht).'</b></td>'; 632 print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; 633 634 // Total TVA 635 print '<tr><td>'.$langs->trans('TotalVAT').'</td><td align="right">'.price($commande->total_tva).'</td>'; 636 print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; 637 638 // Total TTC 639 print '<tr><td>'.$langs->trans('TotalTTC').'</td><td align="right">'.price($commande->total_ttc).'</td>'; 640 print '<td>'.$langs->trans('Currency'.$conf->monnaie).'</td></tr>'; 641 642 print '</table><br>'; 643 644 /* 645 * Lignes de commandes 646 */ 647 $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_tx, l.remise_percent, l.subprice,'; 648 $sql.= ' p.label as product, p.ref, p.fk_product_type, p.rowid as prodid'; 649 $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; 650 $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product=p.rowid'; 651 $sql.= ' WHERE l.fk_commande = '.$commande->id; 652 $sql.= ' ORDER BY l.rowid'; 653 654 $resql = $db->query($sql); 655 if ($resql) 656 { 657 $num = $db->num_rows($resql); 658 $i = 0; $total = 0; 659 660 print '<table class="noborder" width="100%">'; 661 if ($num) 662 { 663 print '<tr class="liste_titre">'; 664 print '<td>'.$langs->trans('Description').'</td>'; 665 print '<td align="right" width="50">'.$langs->trans('VAT').'</td>'; 666 print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>'; 667 print '<td align="right" width="50">'.$langs->trans('Qty').'</td>'; 668 print '<td align="right" width="50">'.$langs->trans('Discount').'</td>'; 669 print '<td align="right" width="50">'.$langs->trans('AmountHT').'</td>'; 670 print '<td> </td><td> </td>'; 671 print '</tr>'; 672 } 673 $var=true; 674 while ($i < $num) 675 { 676 $objp = $db->fetch_object($resql); 677 $var=!$var; 678 679 // Ligne en mode visu 680 if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) 681 { 682 print '<tr '.$bc[$var].'>'; 683 if ($objp->fk_product > 0) 684 { 685 print '<td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'; 686 if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); 687 else print img_object($langs->trans('ShowProduct'),'product'); 688 print ' '.$objp->ref.'</a> - '.stripslashes(nl2br($objp->product)); 689 print ($objp->description && $objp->description!=$objp->product)?'<br>'.$objp->description:''; 690 print '</td>'; 691 } 692 else 693 { 694 print '<td>'.stripslashes(nl2br($objp->description)); 695 print '</td>'; 696 } 697 print '<td align="right">'.$objp->tva_tx.'%</td>'; 698 print '<td align="right">'.price($objp->subprice).'</td>'; 699 print '<td align="right">'.$objp->qty.'</td>'; 700 if ($objp->remise_percent > 0) 701 { 702 print '<td align="right">'.$objp->remise_percent.'%</td>'; 703 } 704 else 705 { 706 print '<td> </td>'; 707 } 708 print '<td align="right">'.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100).'</td>'; 709 710 // Icone d'edition et suppression 711 if ($commande->statut == 0 && $user->rights->commande->creer && $_GET['action'] == '') 712 { 713 print '<td align="right"><a href="fiche.php?id='.$id.'&action=editline&rowid='.$objp->rowid.'">'; 714 print img_edit(); 715 print '</a></td>'; 716 print '<td align="right"><a href="fiche.php?id='.$id.'&action=deleteline&lineid='.$objp->rowid.'">'; 717 print img_delete(); 718 print '</a></td>'; 719 } 720 else 721 { 722 print '<td> </td><td> </td>'; 723 } 724 print '</tr>'; 725 } 726 727 // Ligne en mode update 728 if ($_GET['action'] == 'editline' && $user->rights->commande->creer && $_GET['rowid'] == $objp->rowid) 729 { 730 print '<form action="fiche.php" method="post">'; 731 print '<input type="hidden" name="action" value="updateligne">'; 732 print '<input type="hidden" name="id" value="'.$id.'">'; 733 print '<input type="hidden" name="elrowid" value="'.$_GET['rowid'].'">'; 734 print '<tr '.$bc[$var].'>'; 735 print '<td>'; 736 if ($objp->fk_product > 0) 737 { 738 print '<a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">'; 739 if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); 740 else print img_object($langs->trans('ShowProduct'),'product'); 741 print ' '.$objp->ref.'</a>'; 742 print ' - '.stripslashes(nl2br($objp->product)); 743 print '<br>'; 744 } 745 print '<textarea name="eldesc" cols="50" rows="1">'.stripslashes($objp->description).'</textarea></td>'; 746 print '<td align="right">'; 747 print $html->select_tva('eltva_tx',$objp->tva_tx,$mysoc,$soc); 748 print '</td>'; 749 print '<td align="right"><input size="5" type="text" class="flat" name="elprice" value="'.price($objp->subprice).'"></td>'; 750 print '<td align="right"><input size="2" type="text" class="flat" name="elqty" value="'.$objp->qty.'"></td>'; 751 print '<td align="right" nowrap><input size="1" type="text" class="flat" name="elremise_percent" value="'.$objp->remise_percent.'">%</td>'; 752 print '<td align="center" colspan="3"><input type="submit" class="button" name="save" value="'.$langs->trans('Save').'">'; 753 print '<br /><input type="submit" class="button" name="cancel" value="'.$langs->trans('Cancel').'"></td>'; 754 print '</tr>'; 755 print '</form>'; 756 } 757 758 $total = $total + ($objp->qty * $objp->price); 759 $i++; 760 } 761 $db->free($resql); 762 } 763 else 764 { 765 dolibarr_print_error($db); 766 } 767 768 /* 769 * Ajouter une ligne 770 */ 771 if ($commande->statut == 0 && $user->rights->commande->creer && $_GET['action'] == '') 772 { 773 print '<tr class="liste_titre">'; 774 print '<td>'.$langs->trans('Description').'</td>'; 775 print '<td align="right">'.$langs->trans('VAT').'</td>'; 776 print '<td align="right">'.$langs->trans('PriceUHT').'</td>'; 777 print '<td align="right">'.$langs->trans('Qty').'</td>'; 778 print '<td align="right">'.$langs->trans('Discount').'</td>'; 779 print '<td> </td>'; 780 print '<td> </td>'; 781 print '<td> </td>'; 782 print '</tr>'; 783 784 // Ajout produit produits/services personalisés 785 print '<form action="fiche.php?id='.$id.'" method="post">'; 786 print '<input type="hidden" name="id" value="'.$id.'">'; 787 print '<input type="hidden" name="action" value="addligne">'; 788 789 $var=true; 790 print '<tr '.$bc[$var].'>'; 791 print ' <td><textarea cols="50" name="desc" rows="1"></textarea></td>'; 792 print '<td align="center">'; 793 print $html->select_tva('tva_tx',$conf->defaulttx,$mysoc,$soc); 794 print '</td>'; 795 print '<td align="right"><input type="text" name="pu" size="5"></td>'; 796 print '<td align="right"><input type="text" name="qty" value="1" size="2"></td>'; 797 print '<td align="right" nowrap><input type="text" name="remise_percent" size="2" value="0">%</td>'; 798 print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans('Add').'"></td>'; 799 print '</tr>'; 800 801 print '</form>'; 802 803 // Ajout de produits/services prédéfinis 804 print '<form action="fiche.php?id='.$id.'" method="post">'; 805 print '<input type="hidden" name="id" value="'.$id.'">'; 806 print '<input type="hidden" name="action" value="addligne">'; 807 808 $var=!$var; 809 print '<tr '.$bc[$var].'>'; 810 print '<td colspan="2">'; 811 $html->select_produits('','p_idprod','',$conf->produit->limit_size); 812 print '<br>'; 813 print '<textarea cols="50" name="np_desc" rows="1"></textarea>'; 814 print '</td>'; 815 print '<td> </td>'; 816 print '<td align="right"><input type="text" size="2" name="qty" value="1"></td>'; 817 print '<td align="right" nowrap><input type="text" size="2" name="remise_percent" value="0">%</td>'; 818 print '<td align="center" colspan="3"><input type="submit" class="button" value="'.$langs->trans('Add').'"></td></tr>'; 819 print '</tr>'; 820 821 print '</form>'; 822 } 823 print '</table>'; 824 print '</div>'; 825 826 /* 827 * Boutons actions 828 */ 829 if ($user->societe_id == 0 && $commande->statut < 3 && $_GET['action'] == '') 830 { 831 print '<div class="tabsAction">'; 832 833 if ($conf->expedition->enabled && $commande->statut > 0 && $commande->statut < 3 && $user->rights->expedition->creer) 834 { 835 print '<a class="butAction" href="'.DOL_URL_ROOT.'/expedition/commande.php?id='.$_GET['id'].'">'.$langs->trans('Send').'</a>'; 836 } 837 838 if ($commande->statut == 0) 839 { 840 if ($user->rights->commande->valider) 841 { 842 print '<a class="butAction" href="fiche.php?id='.$id.'&action=valid">'.$langs->trans('Valid').'</a>'; 843 } 844 } 845 846 if ($commande->statut == 1 || $commande->statut == 2) 847 { 848 if ($user->rights->commande->creer) 849 { 850 print '<a class="butAction" href="fiche.php?id='.$id.'&action=cloture">'.$langs->trans('Close').'</a>'; 851 } 852 } 853 854 if ($commande->statut == 0 && $user->rights->commande->supprimer) 855 { 856 print '<a class="butActionDelete" href="fiche.php?id='.$id.'&action=delete">'.$langs->trans('Delete').'</a>'; 857 } 858 859 if ($commande->statut == 1) 860 { 861 $nb_expedition = $commande->nb_expedition(); 862 if ($user->rights->commande->valider && $nb_expedition == 0) 863 { 864 print '<a class="butActionDelete" href="fiche.php?id='.$id.'&action=annuler">'.$langs->trans('CancelOrder').'</a>'; 865 } 866 } 867 868 print '</div>'; 869 } 870 print '<br>'; 871 872 873 print '<table width="100%"><tr><td width="50%" valign="top">'; 874 875 /* 876 * Documents générés 877 * 878 */ 879 $file = $conf->commande->dir_output . '/' . $commande->ref . '/' . $commande->ref . '.pdf'; 880 $relativepath = $commande->ref.'/'.$commande->ref.'.pdf'; 881 882 $var=true; 883 884 if (file_exists($file)) 885 { 886 print_titre($langs->trans('Documents')); 887 print '<table width="100%" class="border">'; 888 print '<tr '.$bc[$var].'><td>'.$langs->trans('Order').' PDF</td>'; 889 print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=commande&file='.urlencode($relativepath).'">'.$commande->ref.'.pdf</a></td>'; 890 print '<td align="right">'.filesize($file). ' bytes</td>'; 891 print '<td align="right">'.strftime('%d %b %Y %H:%M:%S',filemtime($file)).'</td>'; 892 print '</tr>'; 893 print '</table>'; 894 print '<br>'; 895 } 896 897 /* 898 * Liste des factures 899 */ 900 $sql = 'SELECT f.rowid,f.facnumber, f.total_ttc, '.$db->pdate('f.datef').' as df'; 901 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture as f, '.MAIN_DB_PREFIX.'co_fa as cf'; 902 $sql .= ' WHERE f.rowid = cf.fk_facture AND cf.fk_commande = '. $commande->id; 903 904 $result = $db->query($sql); 905 if ($result) 906 { 907 $num = $db->num_rows($result); 908 if ($num) 909 { 910 print_titre($langs->trans('RelatedBills')); 911 $i = 0; $total = 0; 912 print '<table class="noborder" width="100%">'; 913 print '<tr class="liste_titre"><td>'.$langs->trans('Ref')."</td>"; 914 print '<td align="center">'.$langs->trans('Date').'</td>'; 915 print '<td align="right">'.$langs->trans('Price').'</td>'; 916 print '</tr>'; 917 918 $var=True; 919 while ($i < $num) 920 { 921 $objp = $db->fetch_object($result); 922 $var=!$var; 923 print '<tr '.$bc[$var].'>'; 924 print '<td><a href="../compta/facture.php?facid='.$objp->rowid.'">'.img_object($langs->trans('ShowBill'),'bill').' '.$objp->facnumber.'</a></td>'; 925 print '<td align="center">'.dolibarr_print_date($objp->df).'</td>'; 926 print '<td align="right">'.$objp->total_ttc.'</td></tr>'; 927 $i++; 928 } 929 print '</table>'; 930 } 931 } 932 else 933 { 934 dolibarr_print_error($db); 935 } 936 print '</td><td valign="top" width="50%">'; 937 938 /* 939 * Liste des expéditions 940 */ 941 $sql = 'SELECT e.rowid,e.ref,'.$db->pdate('e.date_expedition').' as de'; 942 $sql .= ' FROM '.MAIN_DB_PREFIX.'expedition as e'; 943 $sql .= ' WHERE e.fk_commande = '. $commande->id; 944 945 $result = $db->query($sql); 946 if ($result) 947 { 948 $num = $db->num_rows($result); 949 if ($num) 950 { 951 print_titre($langs->trans('Sendings')); 952 $i = 0; $total = 0; 953 print '<table class="border" width="100%">'; 954 print '<tr '.$bc[$var].'><td>'.$langs->trans('Sendings').'</td><td>'.$langs->trans('Date').'</td></tr>'; 955 956 $var=True; 957 while ($i < $num) 958 { 959 $objp = $db->fetch_object($result); 960 $var=!$var; 961 print '<tr '.$bc[$var].'>'; 962 print '<td><a href="../expedition/fiche.php?id='.$objp->rowid.'">'.img_object($langs->trans('ShowSending'),'sending').' '.$objp->ref.'</a></td>'; 963 print '<td>'.dolibarr_print_date($objp->de).'</td></tr>'; 964 $i++; 965 } 966 print '</table>'; 967 } 968 } 969 else 970 { 971 dolibarr_print_error($db); 972 } 973 print '</td></tr></table>'; 974 } 975 else 976 { 977 /* Commande non trouvée */ 978 print 'Commande inexistante ou accés refusé'; 979 } 980 } 981 } 982 983 $db->close(); 984 985 llxFooter('$Date: 2005/12/18 22:55:24 $ - $Revision: 1.74 $'); 986 ?>
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 |
|