PageRenderTime 62ms CodeModel.GetById 3ms app.highlight 47ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/fourn/commande/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1841 lines | 1390 code | 234 blank | 217 comment | 418 complexity | 86e91cc064a66e1d0ccb8f26e6fd966c MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2/* Copyright (C) 2004-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
   3 * Copyright (C) 2004-2012 Laurent Destailleur  <eldy@users.sourceforge.net>
   4 * Copyright (C) 2005      Eric	Seigne          <eric.seigne@ryxeo.com>
   5 * Copyright (C) 2005-2012 Regis Houssin        <regis.houssin@capnetworks.com>
   6 * Copyright (C) 2010-2012 Juanjo Menent        <jmenent@2byte.es>
   7 * Copyright (C) 2011      Philippe Grand       <philippe.grand@atoo-net.com>
   8 * Copyright (C) 2012      Marcos García        <marcosgdf@gmail.com>
   9 *
  10 * This	program	is free	software; you can redistribute it and/or modify
  11 * it under	the	terms of the GNU General Public	License	as published by
  12 * the Free	Software Foundation; either	version	2 of the License, or
  13 * (at your	option)	any	later version.
  14 *
  15 * This	program	is distributed in the hope that	it will	be useful,
  16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 * MERCHANTABILITY or FITNESS FOR A	PARTICULAR PURPOSE.	 See the
  18 * GNU General Public License for more details.
  19 *
  20 * You should have received a copy of the GNU General Public License
  21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22 * or see http://www.gnu.org/
  23 */
  24
  25/**
  26 *	\file		htdocs/fourn/commande/fiche.php
  27 *	\ingroup	supplier, order
  28 *	\brief		Card supplier order
  29 */
  30
  31require '../../main.inc.php';
  32require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php';
  34require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php';
  35require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  36require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
  37require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  38require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  39if (! empty($conf->produit->enabled))
  40	require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  41if (! empty($conf->projet->enabled))
  42	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  43
  44$langs->load('orders');
  45$langs->load('sendings');
  46$langs->load('companies');
  47$langs->load('bills');
  48$langs->load('propal');
  49$langs->load('deliveries');
  50$langs->load('products');
  51$langs->load('stocks');
  52
  53$id 			= GETPOST('id','int');
  54$ref 			= GETPOST('ref','alpha');
  55$action 		= GETPOST('action','alpha');
  56$confirm		= GETPOST('confirm','alpha');
  57$comclientid 	= GETPOST('comid','int');
  58$socid			= GETPOST('socid','int');
  59$projectid		= GETPOST('projectid','int');
  60
  61//PDF
  62$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  63$hidedesc 	 = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ?  1 : 0));
  64$hideref 	 = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  65
  66
  67// Security check
  68if ($user->societe_id) $socid=$user->societe_id;
  69$result = restrictedArea($user, 'commande_fournisseur', $id,'');
  70
  71// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  72$hookmanager->initHooks(array('ordersuppliercard'));
  73
  74$mesg='';
  75$errors=array();
  76
  77$object = new CommandeFournisseur($db);
  78
  79
  80/*
  81 * Actions
  82 */
  83if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer)
  84{
  85    $object->fetch($id);
  86    $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha'));
  87    if ($result < 0) dol_print_error($db, $object->error);
  88}
  89
  90// conditions de reglement
  91if ($action == 'setconditions' && $user->rights->fournisseur->commande->creer)
  92{
  93    $object->fetch($id);
  94    $result=$object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
  95}
  96
  97// mode de reglement
  98else if ($action == 'setmode' && $user->rights->fournisseur->commande->creer)
  99{
 100    $object->fetch($id);
 101    $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
 102}
 103
 104// date de livraison
 105if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->creer)
 106{
 107	$datelivraison=dol_mktime(0, 0, 0, GETPOST('liv_month','int'), GETPOST('liv_day','int'),GETPOST('liv_year','int'));
 108
 109	$object->fetch($id);
 110	$result=$object->set_date_livraison($user,$datelivraison);
 111	if ($result < 0)
 112	{
 113		$mesg='<div class="error">'.$object->error.'</div>';
 114	}
 115}
 116
 117// Set project
 118else if ($action ==	'classin' && $user->rights->fournisseur->commande->creer)
 119{
 120    $object->fetch($id);
 121    $object->setProject($projectid);
 122}
 123
 124else if ($action ==	'setremisepercent' && $user->rights->fournisseur->commande->creer)
 125{
 126    $object->fetch($id);
 127    $result = $object->set_remise($user, $_POST['remise_percent']);
 128}
 129
 130else if ($action == 'setnote_public' && $user->rights->fournisseur->commande->creer)
 131{
 132	$object->fetch($id);
 133	$result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
 134	if ($result < 0) dol_print_error($db,$object->error);
 135}
 136
 137else if ($action == 'setnote' && $user->rights->fournisseur->commande->creer)
 138{
 139	$object->fetch($id);
 140	$result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
 141	if ($result < 0) dol_print_error($db,$object->error);
 142}
 143
 144else if ($action == 'reopen' && $user->rights->fournisseur->commande->approuver)
 145{
 146    $order = new CommandeFournisseur($db);
 147    $result = $order->fetch($id);
 148    if ($order->statut == 5 || $order->statut == 6 || $order->statut == 7 || $order->statut == 9)
 149    {
 150        if ($order->statut == 5) $newstatus=4;	// Received->Received partially
 151        if ($order->statut == 6) $newstatus=2;	// Canceled->Approved
 152        if ($order->statut == 7) $newstatus=3;	// Canceled->Process running
 153        if ($order->statut == 9) $newstatus=1;	// Refused->Validated
 154
 155        $result = $order->setStatus($user,$newstatus);
 156        if ($result > 0)
 157        {
 158            header('Location: '.$_SERVER["PHP_SELF"].'?id='.$_REQUEST['id']);
 159            exit;
 160        }
 161        else
 162        {
 163            $mesg='<div class="error">'.$order->error.'</div>';
 164        }
 165    }
 166}
 167
 168/*
 169 *	Add a line into product
 170 */
 171else if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
 172{
 173    $langs->load('errors');
 174    $error = false;
 175
 176    if ($_POST['pu'] < 0 && $_POST['qty'] < 0)
 177    {
 178        setEventMessage($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), 'errors');
 179        $error = true;
 180    }
 181    if (empty($_POST['idprodfournprice']) && $_POST['type'] < 0)
 182    {
 183        setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), 'errors');
 184        $error = true;
 185    }
 186    if (empty($_POST['idprodfournprice']) && (! isset($_POST['pu']) || $_POST['pu']=='')) // Unit price can be 0 but not ''
 187    {
 188        setEventMessage($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), 'errors');
 189        $error = true;
 190    }
 191    if (empty($_POST['idprodfournprice']) && empty($_POST['np_desc']) && empty($_POST['dp_desc']))
 192    {
 193        setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), 'errors');
 194        $error = true;
 195    }
 196    if (empty($_POST['idprodfournprice']) && (! isset($_POST['qty']) || $_POST['qty'] == '')
 197    || ! empty($_POST['idprodfournprice']) && (! isset($_POST['pqty']) || $_POST['pqty'] == ''))
 198    {
 199        setEventMessage($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), 'errors');
 200        $error = true;
 201    }
 202
 203    if (! $error && (($_POST['qty'] || $_POST['pqty']) && (($_POST['pu'] && ($_POST['np_desc'] || $_POST['dp_desc'])) || $_POST['idprodfournprice'])))
 204    {
 205        if ($object->fetch($id) < 0) dol_print_error($db,$object->error);
 206        if ($object->fetch_thirdparty() < 0) dol_print_error($db,$object->error);
 207
 208        // Ecrase $pu par celui	du produit
 209        // Ecrase $desc	par	celui du produit
 210        // Ecrase $txtva  par celui du produit
 211        if ($_POST["idprodfournprice"])	// >0 or -1
 212        {
 213            $qty = $_POST['qty'] ? $_POST['qty'] : $_POST['pqty'];
 214
 215            $productsupplier = new ProductFournisseur($db);
 216            $idprod=$productsupplier->get_buyprice($_POST['idprodfournprice'], $qty);    // Just to see if a price exists for the quantity. Not used to found vat
 217
 218            if ($idprod > 0)
 219            {
 220                $res=$productsupplier->fetch($idprod);
 221
 222                // cas special pour lequel on a les meme reference que le fournisseur
 223                // $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
 224                $label = $productsupplier->libelle;
 225
 226                $desc = $productsupplier->description;
 227                $desc.= $productsupplier->description && $_POST['np_desc'] ? "\n" : "";
 228                $desc.= $_POST['np_desc'];
 229
 230                $remise_percent = $_POST["remise_percent"] ? $_POST["remise_percent"] : $_POST["p_remise_percent"];
 231
 232                $tva_tx	= get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
 233                $type = $productsupplier->type;
 234
 235                // Local Taxes
 236                $localtax1_tx= get_localtax($tva_tx, 1, $object->thirdparty);
 237                $localtax2_tx= get_localtax($tva_tx, 2, $object->thirdparty);
 238
 239                $result=$object->addline(
 240                    $desc,
 241                    $pu,
 242                    $qty,
 243                    $tva_tx,
 244                    $localtax1_tx,
 245                    $localtax2_tx,
 246                    $productsupplier->id,
 247                    $_POST['idprodfournprice'],
 248                    $productsupplier->fourn_ref,
 249                    $remise_percent,
 250                    'HT',
 251                    $type
 252                );
 253            }
 254            if ($idprod == -1)
 255            {
 256                // Quantity too low
 257                $mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
 258            }
 259        }
 260        else
 261        {
 262            $type=$_POST["type"];
 263            $desc=$_POST['dp_desc'];
 264            $tva_tx = price2num($_POST['tva_tx']);
 265
 266            // Local Taxes
 267            $localtax1_tx= get_localtax($tva_tx, 1, $object->thirdparty);
 268            $localtax2_tx= get_localtax($tva_tx, 2, $object->thirdparty);
 269
 270            if (! $_POST['dp_desc'])
 271            {
 272                $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label")).'</div>';
 273            }
 274            else
 275            {
 276                if (!empty($_POST['pu']))
 277                {
 278                    $price_base_type = 'HT';
 279                    $ht = price2num($_POST['pu']);
 280                    $result=$object->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, 0, $type);
 281                }
 282                else
 283                {
 284                    $ttc = price2num($_POST['amountttc']);
 285                    $ht = $ttc / (1 + ($tauxtva / 100));
 286                    $price_base_type = 'HT';
 287                    $result=$object->addline($desc, $ht, $_POST['qty'], $tva_tx, $localtax1_tx, $localtax2_tx, 0, 0, '', $_POST['remise_percent'], $price_base_type, $ttc, $type);
 288                }
 289            }
 290        }
 291
 292        //print "xx".$tva_tx; exit;
 293        if ($result > 0)
 294        {
 295            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 296            {
 297            	// Define output language
 298            	$outputlangs = $langs;
 299                $newlang=GETPOST('lang_id','alpha');
 300                if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 301            	if (! empty($newlang))
 302            	{
 303            		$outputlangs = new Translate();
 304            		$outputlangs->setDefaultLang($newlang);
 305            	}
 306
 307                $ret=$object->fetch($id);    // Reload to get new records
 308                supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 309            }
 310            unset($_POST['qty']);
 311            unset($_POST['type']);
 312            unset($_POST['idprodfournprice']);
 313            unset($_POST['remmise_percent']);
 314            unset($_POST['dp_desc']);
 315            unset($_POST['np_desc']);
 316            unset($_POST['pu']);
 317            unset($_POST['tva_tx']);
 318            unset($localtax1_tx);
 319            unset($localtax2_tx);
 320        }
 321        else
 322        {
 323            setEventMessage($object->error, 'errors');
 324        }
 325    }
 326}
 327
 328/*
 329 *	Mise a jour	d'une ligne	dans la	commande
 330 */
 331else if ($action == 'updateligne' && $user->rights->fournisseur->commande->creer &&	$_POST['save'] == $langs->trans('Save'))
 332{
 333    $product=new Product($db);
 334    if ($_POST["elrowid"])
 335    {
 336        if ($product->fetch($_POST["elrowid"]) < 0) dol_print_error($db);
 337    }
 338
 339    if ($object->fetch($id) < 0) dol_print_error($db,$object->error);
 340    if ($object->fetch_thirdparty() < 0) dol_print_error($db,$object->error);
 341
 342    $localtax1_tx=get_localtax($_POST['tva_tx'],1,$object->thirdparty);
 343    $localtax2_tx=get_localtax($_POST['tva_tx'],2,$object->thirdparty);
 344
 345    $result	= $object->updateline(
 346        $_POST['elrowid'],
 347        $_POST['eldesc'],
 348        $_POST['pu'],
 349        $_POST['qty'],
 350        $_POST['remise_percent'],
 351        $_POST['tva_tx'],
 352        $localtax1_tx,
 353        $localtax2_tx,
 354        'HT',
 355        0,
 356        isset($_POST["type"])?$_POST["type"]:$product->type
 357    );
 358
 359    if ($result	>= 0)
 360    {
 361        $outputlangs = $langs;
 362        if (! empty($_REQUEST['lang_id']))
 363        {
 364            $outputlangs = new Translate();
 365            $outputlangs->setDefaultLang($_REQUEST['lang_id']);
 366        }
 367        if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 368        {
 369            $ret=$object->fetch($id);    // Reload to get new records
 370            supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 371        }
 372    }
 373    else
 374    {
 375        dol_print_error($db,$object->error);
 376        exit;
 377    }
 378}
 379
 380else if ($action == 'confirm_deleteproductline' && $confirm == 'yes' && $user->rights->fournisseur->commande->creer)
 381{
 382    $object->fetch($id);
 383
 384    $result = $object->deleteline(GETPOST('lineid'));
 385    if ($result	>= 0)
 386    {
 387        $outputlangs = $langs;
 388        if (! empty($_REQUEST['lang_id']))
 389        {
 390            $outputlangs = new Translate();
 391            $outputlangs->setDefaultLang($_REQUEST['lang_id']);
 392        }
 393        if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 394        {
 395            $ret=$object->fetch($id);    // Reload to get new records
 396            supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 397        }
 398    }
 399    else
 400    {
 401        $error++;
 402        $mesg=$object->error;
 403    }
 404
 405    if (! $error)
 406    {
 407        header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
 408        exit;
 409    }
 410}
 411
 412else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->commande->valider)
 413{
 414    $object->fetch($id);
 415    $object->fetch_thirdparty();
 416
 417    $object->date_commande=dol_now();
 418    $result = $object->valid($user);
 419    if ($result	>= 0)
 420    {
 421        $outputlangs = $langs;
 422        if (! empty($_REQUEST['lang_id']))
 423        {
 424            $outputlangs = new Translate();
 425            $outputlangs->setDefaultLang($_REQUEST['lang_id']);
 426        }
 427        if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 428        {
 429            $ret=$object->fetch($id);    // Reload to get new records
 430            supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 431        }
 432    }
 433    else
 434    {
 435        $mesg=$object->error;
 436    }
 437
 438    // If we have permission, and if we don't need to provide th idwarehouse, we go directly on approved step
 439    if ($user->rights->fournisseur->commande->approuver && ! (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1)))
 440    {
 441        $action='confirm_approve';
 442    }
 443}
 444
 445else if ($action == 'confirm_approve' && $confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
 446{
 447    $idwarehouse=GETPOST('idwarehouse', 'int');
 448
 449    $object->fetch($id);
 450    $object->fetch_thirdparty();
 451
 452    // Check parameters
 453    if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
 454    {
 455        if (! $idwarehouse || $idwarehouse == -1)
 456        {
 457            $error++;
 458            $errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse"));
 459            $action='';
 460        }
 461    }
 462
 463    if (! $error)
 464    {
 465        $result	= $object->approve($user, $idwarehouse);
 466        if ($result > 0)
 467        {
 468            header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
 469            exit;
 470        }
 471        else
 472        {
 473            $mesg=$object->error;
 474        }
 475    }
 476}
 477
 478else if ($action == 'confirm_refuse' &&	$confirm == 'yes' && $user->rights->fournisseur->commande->approuver)
 479{
 480    $object->fetch($id);
 481    $result = $object->refuse($user);
 482    if ($result > 0)
 483    {
 484        header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
 485        exit;
 486    }
 487    else
 488    {
 489        $mesg=$object->error;
 490    }
 491}
 492
 493else if ($action == 'confirm_commande' && $confirm	== 'yes' &&	$user->rights->fournisseur->commande->commander)
 494{
 495    $object->fetch($id);
 496    $result	= $object->commande($user, $_REQUEST["datecommande"],	$_REQUEST["methode"], $_REQUEST['comment']);
 497    if ($result > 0)
 498    {
 499        header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
 500        exit;
 501    }
 502    else
 503    {
 504        $mesg=$object->error;
 505    }
 506}
 507
 508
 509else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->commande->supprimer)
 510{
 511    $object->fetch($id);
 512    $object->fetch_thirdparty();
 513    $result=$object->delete($user);
 514    if ($result > 0)
 515    {
 516        header("Location: ".DOL_URL_ROOT.'/fourn/commande/liste.php');
 517        exit;
 518    }
 519    else
 520    {
 521        $mesg=$object->error;
 522    }
 523}
 524
 525// Receive
 526else if ($action == 'livraison' && $user->rights->fournisseur->commande->receptionner)
 527{
 528    $object->fetch($id);
 529
 530    if ($_POST["type"])
 531    {
 532        $date_liv = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
 533
 534        $result	= $object->Livraison($user, $date_liv, $_POST["type"], $_POST["comment"]);
 535        if ($result > 0)
 536        {
 537            header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
 538            exit;
 539        }
 540        else if($result == -3)
 541        {
 542            $mesg='<div class="error">'.$langs->trans("NotAuthorized").'</div>';
 543        }
 544        else
 545        {
 546            dol_print_error($db,$object->error);
 547            exit;
 548        }
 549    }
 550    else
 551    {
 552        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Delivery")).'</div>';
 553    }
 554}
 555
 556else if ($action == 'confirm_cancel' && $confirm == 'yes' &&	$user->rights->fournisseur->commande->commander)
 557{
 558    $object->fetch($id);
 559    $result	= $object->cancel($user);
 560    if ($result > 0)
 561    {
 562        header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
 563        exit;
 564    }
 565    else
 566    {
 567        $mesg=$object->error;
 568    }
 569}
 570
 571// Line ordering
 572else if ($action == 'up'	&& $user->rights->fournisseur->commande->creer)
 573{
 574    $object->fetch($id);
 575    $object->line_up($_GET['rowid']);
 576
 577    $outputlangs = $langs;
 578    if (! empty($_REQUEST['lang_id']))
 579    {
 580        $outputlangs = new Translate();
 581        $outputlangs->setDefaultLang($_REQUEST['lang_id']);
 582    }
 583    if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 584    header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
 585    exit;
 586}
 587else if ($action == 'down' && $user->rights->fournisseur->commande->creer)
 588{
 589    $object->fetch($id);
 590    $object->line_down($_GET['rowid']);
 591
 592    $outputlangs = $langs;
 593    if (! empty($_REQUEST['lang_id']))
 594    {
 595        $outputlangs = new Translate();
 596        $outputlangs->setDefaultLang($_REQUEST['lang_id']);
 597    }
 598    if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_order_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
 599    header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#'.$_GET['rowid']));
 600    exit;
 601}
 602
 603else if ($action == 'builddoc' && $user->rights->fournisseur->commande->creer)	// En get ou en	post
 604{
 605    // Build document
 606
 607    // Sauvegarde le dernier module	choisi pour	generer	un document
 608    $object->fetch($id);
 609    $object->fetch_thirdparty();
 610
 611    if ($_REQUEST['model'])
 612    {
 613        $object->setDocModel($user, $_REQUEST['model']);
 614    }
 615
 616    $outputlangs = $langs;
 617    if (! empty($_REQUEST['lang_id']))
 618    {
 619        $outputlangs = new Translate();
 620        $outputlangs->setDefaultLang($_REQUEST['lang_id']);
 621    }
 622    $result=supplier_order_pdf_create($db, $object,$object->modelpdf,$outputlangs, $hidedetails, $hidedesc, $hideref);
 623    if ($result	<= 0)
 624    {
 625        dol_print_error($db,$result);
 626        exit;
 627    }
 628    else
 629    {
 630        header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
 631        exit;
 632    }
 633}
 634
 635// Delete file in doc form
 636else if ($action == 'remove_file' && $user->rights->fournisseur->commande->creer)
 637{
 638    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 639
 640    if ($object->fetch($id))
 641    {
 642    	$object->fetch_thirdparty();
 643
 644        $langs->load("other");
 645        $upload_dir =	$conf->fournisseur->commande->dir_output;
 646        $file =	$upload_dir	. '/' .	GETPOST('file');
 647        $ret=dol_delete_file($file,0,0,0,$object);
 648        if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 649        else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 650    }
 651}
 652
 653/*
 654 * Create an order
 655 */
 656else if ($action == 'create' && $user->rights->fournisseur->commande->creer)
 657{
 658    $error=0;
 659
 660    $fourn = new Fournisseur($db);
 661    $result=$fourn->fetch($socid);
 662
 663    $object->socid = $fourn->id;
 664
 665    $db->begin();
 666
 667    $orderid=$object->create($user);
 668    if (! $orderid > 0)
 669    {
 670        $error++;
 671        $mesg=$object->error;
 672    }
 673
 674    if (! $error)
 675    {
 676        if ($comclientid !=	'')
 677        {
 678    		$object->updateFromCommandeClient($user, $orderid, $comclientid);
 679        }
 680
 681        $id=$orderid;
 682
 683        $db->commit();
 684    }
 685    else
 686    {
 687        $db->rollback();
 688    }
 689}
 690
 691/*
 692 * Add file in email form
 693 */
 694if (GETPOST('addfile'))
 695{
 696    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 697
 698    // Set tmp user directory TODO Use a dedicated directory for temp mails files
 699    $vardir=$conf->user->dir_output."/".$user->id;
 700    $upload_dir_tmp = $vardir.'/temp';
 701
 702    dol_add_file_process($upload_dir_tmp,0,0);
 703    $action='presend';
 704}
 705
 706/*
 707 * Remove file in email form
 708 */
 709if (GETPOST('removedfile'))
 710{
 711    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
 712
 713    // Set tmp user directory
 714    $vardir=$conf->user->dir_output."/".$user->id;
 715    $upload_dir_tmp = $vardir.'/temp';
 716
 717	// TODO Delete only files that was uploaded from email form
 718    dol_remove_file_process($_POST['removedfile'],0);
 719    $action='presend';
 720}
 721
 722/*
 723 * Send mail
 724 */
 725if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
 726{
 727    $langs->load('mails');
 728
 729    $result=$object->fetch($_POST['orderid']);
 730    $result=$object->fetch_thirdparty();
 731
 732    if ($result > 0)
 733    {
 734//        $ref = dol_sanitizeFileName($object->ref);
 735//        $file = $conf->fournisseur->commande->dir_output . '/' . $ref . '/' . $ref . '.pdf';
 736
 737//        if (is_readable($file))
 738//        {
 739            if ($_POST['sendto'])
 740            {
 741                // Le destinataire a ete fourni via le champ libre
 742                $sendto = $_POST['sendto'];
 743                $sendtoid = 0;
 744            }
 745            elseif ($_POST['receiver'] != '-1')
 746            {
 747                // Recipient was provided from combo list
 748                if ($_POST['receiver'] == 'thirdparty') // Id of third party
 749                {
 750                    $sendto = $object->client->email;
 751                    $sendtoid = 0;
 752                }
 753                else	// Id du contact
 754                {
 755                    $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
 756                    $sendtoid = $_POST['receiver'];
 757                }
 758            }
 759
 760            if (dol_strlen($sendto))
 761            {
 762                $langs->load("commercial");
 763
 764                $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
 765                $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
 766                $message = $_POST['message'];
 767                $sendtocc = $_POST['sendtocc'];
 768                $deliveryreceipt = $_POST['deliveryreceipt'];
 769
 770                if ($action == 'send')
 771                {
 772                    if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
 773                    else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
 774                    $actiontypecode='AC_SUP_ORD';
 775                    $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
 776                    if ($message)
 777                    {
 778                        $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
 779                        $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
 780                        $actionmsg.=$message;
 781                    }
 782                    $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
 783                }
 784
 785                // Create form object
 786                include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
 787                $formmail = new FormMail($db);
 788
 789                $attachedfiles=$formmail->get_attached_files();
 790                $filepath = $attachedfiles['paths'];
 791                $filename = $attachedfiles['names'];
 792                $mimetype = $attachedfiles['mimes'];
 793
 794                // Send mail
 795                require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
 796                $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
 797                if ($mailfile->error)
 798                {
 799                    $mesg='<div class="error">'.$mailfile->error.'</div>';
 800                }
 801                else
 802                {
 803                    $result=$mailfile->sendfile();
 804                    if ($result)
 805                    {
 806                        $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));		// Must not contain "
 807
 808                        $error=0;
 809
 810                        // Initialisation donnees
 811                        $object->sendtoid		= $sendtoid;
 812                        $object->actiontypecode	= $actiontypecode;
 813                        $object->actionmsg 		= $actionmsg;
 814                        $object->actionmsg2		= $actionmsg2;
 815                        $object->fk_element		= $object->id;
 816                        $object->elementtype	= $object->element;
 817
 818                        // Appel des triggers
 819                        include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
 820                        $interface=new Interfaces($db);
 821                        $result=$interface->run_triggers('ORDER_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
 822                        if ($result < 0) { $error++; $errors=$interface->errors; }
 823                        // Fin appel triggers
 824
 825                        if ($error)
 826                        {
 827                            dol_print_error($db);
 828                        }
 829                        else
 830                        {
 831                            // Redirect here
 832                            // This avoid sending mail twice if going out and then back to page
 833                            header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg));
 834                            exit;
 835                        }
 836                    }
 837                    else
 838                    {
 839                        $langs->load("other");
 840                        $mesg='<div class="error">';
 841                        if ($mailfile->error)
 842                        {
 843                            $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
 844                            $mesg.='<br>'.$mailfile->error;
 845                        }
 846                        else
 847                        {
 848                            $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
 849                        }
 850                        $mesg.='</div>';
 851                    }
 852                }
 853/*            }
 854            else
 855            {
 856                $langs->load("other");
 857                $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
 858                $action='presend';
 859                dol_syslog('Recipient email is empty');
 860            }*/
 861        }
 862        else
 863        {
 864            $langs->load("errors");
 865            $mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
 866            dol_syslog('Failed to read file: '.$file);
 867        }
 868    }
 869    else
 870    {
 871        $langs->load("other");
 872        $mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'</div>';
 873        dol_syslog('Impossible de lire les donnees de la facture. Le fichier facture n\'a peut-etre pas ete genere.');
 874    }
 875}
 876
 877if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->commande->creer)
 878{
 879	if ($action == 'addcontact')
 880	{
 881		$result = $object->fetch($id);
 882
 883		if ($result > 0 && $id > 0)
 884		{
 885			$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
 886			$result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
 887		}
 888
 889		if ($result >= 0)
 890		{
 891			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 892			exit;
 893		}
 894		else
 895		{
 896			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 897			{
 898				$langs->load("errors");
 899				$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 900			}
 901			else
 902			{
 903				$mesg = '<div class="error">'.$object->error.'</div>';
 904			}
 905		}
 906	}
 907
 908	// bascule du statut d'un contact
 909	else if ($action == 'swapstatut')
 910	{
 911		if ($object->fetch($id))
 912		{
 913			$result=$object->swapContactStatus(GETPOST('ligne'));
 914		}
 915		else
 916		{
 917			dol_print_error($db);
 918		}
 919	}
 920
 921	// Efface un contact
 922	else if ($action == 'deletecontact')
 923	{
 924		$object->fetch($id);
 925		$result = $object->delete_contact($_GET["lineid"]);
 926
 927		if ($result >= 0)
 928		{
 929			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 930			exit;
 931		}
 932		else {
 933			dol_print_error($db);
 934		}
 935	}
 936}
 937
 938
 939/*
 940 * View
 941 */
 942
 943llxHeader('',$langs->trans("OrderCard"),"CommandeFournisseur");
 944
 945$form =	new	Form($db);
 946$formfile = new FormFile($db);
 947$formorder = new FormOrder($db);
 948$productstatic = new Product($db);
 949
 950
 951/* *************************************************************************** */
 952/*                                                                             */
 953/* Mode vue et edition                                                         */
 954/*                                                                             */
 955/* *************************************************************************** */
 956
 957$now=dol_now();
 958
 959if ($id > 0 || ! empty($ref))
 960{
 961    //if ($mesg) print $mesg.'<br>';
 962
 963    $result=$object->fetch($id,$ref);
 964    if ($result >= 0)
 965    {
 966        $soc = new Societe($db);
 967        $soc->fetch($object->socid);
 968
 969        $author	= new User($db);
 970        $author->fetch($object->user_author_id);
 971
 972        $head = ordersupplier_prepare_head($object);
 973
 974        $title=$langs->trans("SupplierOrder");
 975        dol_fiche_head($head, 'card', $title, 0, 'order');
 976
 977        /*
 978         * Confirmation de la suppression de	la commande
 979         */
 980        if ($action	== 'delete')
 981        {
 982            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('DeleteOrder'), $langs->trans('ConfirmDeleteOrder'), 'confirm_delete', '', 0, 2);
 983            if ($ret == 'html') print '<br>';
 984        }
 985
 986        /*
 987         * Confirmation de la validation
 988         */
 989        if ($action	== 'valid')
 990        {
 991            $object->date_commande=dol_now();
 992
 993            // We check if number is temporary number
 994            if (preg_match('/^[\(]?PROV/i',$object->ref)) $newref = $object->getNextNumRef($soc);
 995            else $newref = $object->ref;
 996
 997            $text=$langs->trans('ConfirmValidateOrder',$newref);
 998            if (! empty($conf->notification->enabled))
 999            {
1000                require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
1001                $notify=new	Notify($db);
1002                $text.='<br>';
1003                $text.=$notify->confirmMessage(3,$object->socid);
1004            }
1005
1006            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$id, $langs->trans('ValidateOrder'), $text, 'confirm_valid', '', 0, 1);
1007            if ($ret == 'html') print '<br>';
1008        }
1009        /*
1010         * Confirmation de l'approbation
1011         */
1012        if ($action	== 'approve')
1013        {
1014            $formquestion=array();
1015            if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
1016            {
1017                $langs->load("stocks");
1018                require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1019                $formproduct=new FormProduct($db);
1020                $formquestion=array(
1021                //'text' => $langs->trans("ConfirmClone"),
1022                //array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
1023                //array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
1024                array('type' => 'other', 'name' => 'idwarehouse',   'label' => $langs->trans("SelectWarehouseForStockDecrease"),   'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
1025            }
1026
1027            $ret=$form->form_confirm("fiche.php?id=".$object->id,$langs->trans("ApproveThisOrder"),$langs->trans("ConfirmApproveThisOrder",$object->ref),"confirm_approve", $formquestion, 1, 1, 240);
1028            if ($ret == 'html') print '<br>';
1029        }
1030        /*
1031         * Confirmation de la desapprobation
1032         */
1033        if ($action	== 'refuse')
1034        {
1035            $ret=$form->form_confirm("fiche.php?id=$object->id",$langs->trans("DenyingThisOrder"),$langs->trans("ConfirmDenyingThisOrder",$object->ref),"confirm_refuse", '', 0, 1);
1036            if ($ret == 'html') print '<br>';
1037        }
1038        /*
1039         * Confirmation de l'annulation
1040         */
1041        if ($action	== 'cancel')
1042        {
1043            $ret=$form->form_confirm("fiche.php?id=$object->id",$langs->trans("Cancel"),$langs->trans("ConfirmCancelThisOrder",$object->ref),"confirm_cancel", '', 0, 1);
1044            if ($ret == 'html') print '<br>';
1045        }
1046
1047        /*
1048         * Confirmation de l'envoi de la commande
1049         */
1050        if ($action	== 'commande')
1051        {
1052            $date_com = dol_mktime(0,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
1053            $ret=$form->form_confirm("fiche.php?id=".$object->id."&datecommande=".$date_com."&methode=".$_POST["methodecommande"]."&comment=".urlencode($_POST["comment"]), $langs->trans("MakeOrder"),$langs->trans("ConfirmMakeOrder",dol_print_date($date_com,'day')),"confirm_commande",'',0,2);
1054            if ($ret == 'html') print '<br>';
1055        }
1056
1057        /*
1058         * Confirmation de la suppression d'une ligne produit
1059         */
1060        if ($action == 'delete_product_line')
1061        {
1062            $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteproductline','',0,2);
1063            if ($ret == 'html') print '<br>';
1064        }
1065
1066        /*
1067         *	Commande
1068         */
1069        $nbrow=8;
1070        if (! empty($conf->projet->enabled))	$nbrow++;
1071
1072        //Local taxes
1073        if ($mysoc->country_code=='ES')
1074        {
1075            if($mysoc->localtax1_assuj=="1") $nbrow++;
1076            if($mysoc->localtax2_assuj=="1") $nbrow++;
1077        }
1078
1079        print '<table class="border" width="100%">';
1080
1081        $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/commande/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
1082
1083        // Ref
1084        print '<tr><td width="20%">'.$langs->trans("Ref").'</td>';
1085        print '<td colspan="2">';
1086        print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref');
1087        print '</td>';
1088        print '</tr>';
1089
1090        // Ref supplier
1091        print '<tr><td>';
1092        print $form->editfieldkey("RefSupplier",'ref_supplier',$langs->trans($object->ref_supplier),$object,$user->rights->fournisseur->commande->creer);
1093        print '</td><td colspan="2">';
1094        print $form->editfieldval("RefSupplier",'ref_supplier',$langs->trans($object->ref_supplier),$object,$user->rights->fournisseur->commande->creer);
1095        print '</td></tr>';
1096
1097        // Fournisseur
1098        print '<tr><td>'.$langs->trans("Supplier")."</td>";
1099        print '<td colspan="2">'.$soc->getNomUrl(1,'supplier').'</td>';
1100        print '</tr>';
1101
1102        // Statut
1103        print '<tr>';
1104        print '<td>'.$langs->trans("Status").'</td>';
1105        print '<td colspan="2">';
1106        print $object->getLibStatut(4);
1107        print "</td></tr>";
1108
1109        // Date
1110        if ($object->methode_commande_id > 0)
1111        {
1112            print '<tr><td>'.$langs->trans("Date").'</td><td colspan="2">';
1113            if ($object->date_commande)
1114            {
1115                print dol_print_date($object->date_commande,"dayhourtext")."\n";
1116            }
1117            print "</td></tr>";
1118
1119            if ($object->methode_commande)
1120            {
1121                print '<tr><td>'.$langs->trans("Method").'</td><td colspan="2">'.$object->getInputMethod().'</td></tr>';
1122            }
1123        }
1124
1125        // Author
1126        print '<tr><td>'.$langs->trans("AuthorRequest").'</td>';
1127        print '<td colspan="2">'.$author->getNomUrl(1).'</td>';
1128        print '</tr>';
1129
1130        // Conditions de reglement par defaut
1131        $langs->load('bills');
1132        $form = new Form($db);
1133        print '<tr><td nowrap>';
1134        print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
1135        print $langs->trans('PaymentConditions');
1136        print '<td>';
1137        if ($action != 'editconditions') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
1138        print '</tr></table>';
1139        print '</td><td colspan="2">';
1140        if ($action == 'editconditions')
1141        {
1142            $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,  $object->cond_reglement_id,'cond_reglement_id');
1143        }
1144        else
1145        {
1146            $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,  $object->cond_reglement_id,'none');
1147        }
1148        print "</td>";
1149        print '</tr>';
1150
1151        // Mode of payment
1152        $langs->load('bills');
1153        $form = new Form($db);
1154        print '<tr><td nowrap>';
1155        print '<table width="100%" class="nobordernopadding"><tr><td nowrap>';
1156        print $langs->trans('PaymentMode');
1157        print '</td>';
1158        if ($action != 'editmode') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->trans('SetMode'),1).'</a></td>';
1159        print '</tr></table>';
1160        print '</td><td colspan="2">';
1161        if ($action == 'editmode')
1162        {
1163            $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
1164        }
1165        else
1166        {
1167            $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
1168        }
1169        print '</td></tr>';
1170
1171		// Delivery date planed
1172            print '<tr><td height="10">';
1173            print '<table class="nobordernopadding" width="100%"><tr><td>';
1174            print $langs->trans('DateDeliveryPlanned');
1175            print '</td>';
1176
1177            if ($action != 'editdate_livraison') print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDeliveryDate'),1).'</a></td>';
1178            print '</tr></table>';
1179            print '</td><td colspan="2">';
1180            if ($action == 'editdate_livraison')
1181            {
1182                print '<form name="setdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1183                print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1184                print '<input type="hidden" name="action" value="setdate_livraison">';
1185                $form->select_date($object->date_livraison?$object->date_livraison:-1,'liv_','','','',"setdate_livraison");
1186                print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1187                print '</form>';
1188            }
1189            else
1190            {
1191                print $object->date_livraison ? dol_print_date($object->date_livraison,'daytext') : '&nbsp;';
1192            }
1193            print '</td>';
1194
1195        // Project
1196        if (! empty($conf->projet->enabled))
1197        {
1198            $langs->load('projects');
1199            print '<tr><td height="10">';
1200            print '<table class="nobordernopadding" width="100%"><tr><td>';
1201            print $langs->trans('Project');
1202            print '</td>';
1203            if ($action != 'classify') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->trans('SetProject')).'</a></td>';
1204            print '</tr></table>';
1205            print '</td><td colspan="2">';
1206            //print "$object->id, $object->socid, $object->fk_project";
1207            if ($action == 'classify')
1208            {
1209                $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS)?$object->socid:'-1', $object->fk_project, 'projectid');
1210            }
1211            else
1212            {
1213                $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
1214            }
1215            print '</td>';
1216            print '</tr>';
1217        }
1218
1219		// Other attributes
1220		$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"');
1221		$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1222
1223        // Ligne de	3 colonnes
1224        print '<tr><td>'.$langs->trans("AmountHT").'</td>';
1225        print '<td align="right"><b>'.price($object->total_ht).'</b></td>';
1226        print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1227
1228        print '<tr><td>'.$langs->trans("AmountVAT").'</td><td align="right">'.price($object->total_tva).'</td>';
1229        print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1230
1231        // Amount Local Taxes
1232        if ($mysoc->country_code=='ES')
1233        {
1234            if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
1235            {
1236                print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
1237                print '<td align="right">'.price($object->total_localtax1).'</td>';
1238                print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1239            }
1240            if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
1241            {
1242                print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
1243                print '<td align="right">'.price($object->total_localtax2).'</td>';
1244                print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1245            }
1246        }
1247        print '<tr><td>'.$langs->trans("AmountTTC").'</td><td align="right">'.price($object->total_ttc).'</td>';
1248        print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1249
1250        print "</table><br>";
1251
1252        if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
1253        {
1254        	$blocname = 'contacts';
1255        	$title = $langs->trans('ContactsAddresses');
1256        	include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1257        }
1258
1259        if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
1260        {
1261        	$blocname = 'notes';
1262        	$title = $langs->trans('Notes');
1263        	include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1264        }
1265
1266        dol_htmloutput_mesg($mesg);
1267        dol_htmloutput_errors('',$errors);
1268
1269        /*
1270         * Lines
1271         */
1272        print '<table class="noborder" width="100%">';
1273
1274        $num = count($object->lines);
1275        $i = 0;	$total = 0;
1276
1277        if ($num)
1278        {
1279            print '<tr class="liste_titre">';
1280            print '<td>'.$langs->trans('Label').'</td>';
1281            print '<td align="right" width="50">'.$langs->trans('VAT').'</td>';
1282            print '<td align="right" width="80">'.$langs->trans('PriceUHT').'</td>';
1283            print '<td align="right" width="50">'.$langs->trans('Qty').'</td>';
1284            print '<td align="right" width="50">'.$langs->trans('ReductionShort').'</td>';
1285            print '<td align="right" width="50">'.$langs->trans('TotalHTShort').'</td>';
1286            print '<td width="48" colspan="3">&nbsp;</td>';
1287            print "</tr>\n";
1288        }
1289        $var=true;
1290        while ($i <	$num)
1291        {
1292            $line =	$object->lines[$i];
1293            $var=!$var;
1294
1295            // Show product and description
1296            $type=(! empty($line->product_type)?$line->product_type:(! empty($line->fk_product_type)?$line->fk_product_type:0));
1297            // Try to enhance type detection using date_start and date_end for free lines where type
1298            // was not saved.
1299            $date_start='';
1300            $date_end='';
1301            if (! empty($line->date_start))
1302            {
1303            	$date_start=$line->date_start;
1304            	$type=1;
1305            }
1306            if (! empty($line->date_end))
1307            {
1308            	$date_end=$line->date_end;
1309            	$type=1;
1310            }
1311
1312            // Ligne en mode visu
1313            if ($action != 'editline' || $_GET['rowid'] != $line->id)
1314            {
1315                print '<tr '.$bc[$var].'>';
1316
1317                // Show product and description
1318                print '<td>';
1319                if ($line->fk_product > 0)
1320                {
1321                    print '<a name="'.$line->id.'"></a>'; // ancre pour retourner sur la ligne
1322
1323                    $product_static=new ProductFournisseur($db);
1324                    $product_static->fetch($line->fk_product);
1325                    $text=$product_static->getNomUrl(1,'supplier');
1326                    $text.= ' - '.$product_static->libelle;
1327                    $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($line->description));
1328                    print $form->textwithtooltip($text,$description,3,'','',$i);
1329
1330                    // Show range
1331                    print_date_range($date_start,$date_end);
1332
1333                    // Add description in form
1334                    if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) print ($line->description && $line->description!=$product_static->libelle)?'<br>'.dol_htmlentitiesbr($line->description):'';
1335                }
1336
1337                // Description - Editor wysiwyg
1338                if (! $line->fk_product)
1339                {
1340                    if ($type==1) $text = img_object($langs->trans('Service'),'service');
1341                    else $text = img_object($langs->trans('Product'),'product');
1342                    print $text.' '.nl2br($line->description);
1343
1344                    // Show range
1345                    print_date_range($date_start,$date_end);
1346                }
1347
1348                print '</td>';
1349
1350                print '<td align="right" nowrap="nowrap">'.vatrate($line->tva_tx).'%</td>';
1351
1352                print '<td align="right" nowrap="nowrap">'.price($line->subprice)."</td>\n";
1353
1354                print '<td align="right" nowrap="nowrap">'.$line->qty.'</td>';
1355
1356                if ($line->remise_percent >	0)
1357                {
1358                    print '<td align="right" nowrap="nowrap">'.dol_print_reduction($line->remise_percent,$langs)."</td>\n";
1359                }
1360                else
1361                {
1362                    print '<td>&nbsp;</td>';
1363                }
1364
1365                print '<td align="right" nowrap="nowrap">'.price($line->total_ht).'</td>';
1366                if ($object->statut == 0	&& $user->rights->fournisseur->commande->creer)
1367                {
1368                    print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$line->id.'#'.$line->id.'">';
1369                    print img_edit();
1370                    print '</a></td>';
1371
1372                    $actiondelete='delete_product_line';
1373                    print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action='.$actiondelete.'&amp;lineid='.$line->id.'">';
1374              

Large files files are truncated, but you can click here to view the full file