PageRenderTime 220ms CodeModel.GetById 81ms app.highlight 90ms RepoModel.GetById 30ms app.codeStats 1ms

/htdocs/comm/propal.php

https://github.com/zeert/dolibarr
PHP | 1805 lines | 1415 code | 202 blank | 188 comment | 473 complexity | 4eb4e77b608832d8460bf16219554f26 MD5 | raw file

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

   1<?php
   2/* Copyright (C) 2001-2007 Rodolphe Quiedeville  <rodolphe@quiedeville.org>
   3 * Copyright (C) 2004-2011 Laurent Destailleur   <eldy@users.sourceforge.net>
   4 * Copyright (C) 2004      Eric Seigne           <eric.seigne@ryxeo.com>
   5 * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
   6 * Copyright (C) 2005-2012 Regis Houssin         <regis@dolibarr.fr>
   7 * Copyright (C) 2006      Andre Cianfarani      <acianfa@free.fr>
   8 * Copyright (C) 2010-2012 Juanjo Menent         <jmenent@2byte.es>
   9 * Copyright (C) 2010-2011 Philippe Grand        <philippe.grand@atoo-net.com>
  10 * Copyright (C) 2012      Christophe Battarel   <christophe.battarel@altairis.fr>
  11*
  12 * This program is free software; you can redistribute it and/or modify
  13 * it under the terms of the GNU General Public License as published by
  14 * the Free Software Foundation; either version 2 of the License, or
  15 * (at your option) any later version.
  16 *
  17 * This program is distributed in the hope that it will be useful,
  18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20 * GNU General Public License for more details.
  21 *
  22 * You should have received a copy of the GNU General Public License
  23 * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24 */
  25
  26/**
  27 *	\file       	htdocs/comm/propal.php
  28 *	\ingroup    	propale
  29 *	\brief      	Page of commercial proposals card and list
  30 */
  31
  32require("../main.inc.php");
  33require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php");
  34require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  35require_once(DOL_DOCUMENT_ROOT."/core/class/html.formpropal.class.php");
  36require_once(DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php');
  37require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php');
  38require_once(DOL_DOCUMENT_ROOT."/core/modules/propale/modules_propale.php");
  39require_once(DOL_DOCUMENT_ROOT."/core/lib/propal.lib.php");
  40require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
  41if (! empty($conf->projet->enabled))   require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
  42
  43$langs->load('companies');
  44$langs->load('propal');
  45$langs->load('compta');
  46$langs->load('bills');
  47$langs->load('orders');
  48$langs->load('products');
  49if (! empty($conf->margin->enabled))
  50  $langs->load('margins');
  51
  52$id=GETPOST('id','int');
  53$ref=GETPOST('ref','alpha');
  54$socid=GETPOST('socid','int');
  55$action=GETPOST('action','alpha');
  56$confirm=GETPOST('confirm','alpha');
  57$lineid=GETPOST('lineid','int');
  58
  59$search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  60$search_refcustomer=GETPOST('search_refcustomer','alpha');
  61$search_societe=GETPOST('search_societe','alpha');
  62$search_montant_ht=GETPOST('search_montant_ht','alpha');
  63
  64$sall=GETPOST("sall");
  65$year=GETPOST("year");
  66$month=GETPOST("month");
  67
  68//PDF
  69$hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  70$hidedesc 	 = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ?  1 : 0));
  71$hideref 	 = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  72
  73// Nombre de ligne pour choix de produit/service predefinis
  74$NBLINES=4;
  75
  76// Security check
  77$module='propale';
  78if (isset($socid))
  79{
  80	$objectid=$socid;
  81	$module='societe';
  82	$dbtable='&societe';
  83}
  84else if (isset($id) &&  $id > 0)
  85{
  86	$objectid=$id;
  87	$module='propale';
  88	$dbtable='propal';
  89}
  90if ($user->societe_id) $socid=$user->societe_id;
  91$result = restrictedArea($user, $module, $objectid, $dbtable);
  92
  93$object = new Propal($db);
  94
  95// Load object
  96if ($id > 0 || ! empty($ref))
  97{
  98	$ret=$object->fetch($id, $ref);
  99	$object->fetch_thirdparty();
 100}
 101
 102// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
 103include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
 104$hookmanager=new HookManager($db);
 105$hookmanager->initHooks(array('propalcard'));
 106
 107
 108
 109/*
 110 * Actions
 111 */
 112
 113$parameters=array('socid'=>$socid);
 114$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
 115
 116// Action clone object
 117if ($action == 'confirm_clone' && $confirm == 'yes')
 118{
 119	if (1==0 &&  ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
 120	{
 121		setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
 122	}
 123	else
 124	{
 125		if ($object->id > 0)
 126		{
 127			$result=$object->createFromClone($socid, $hookmanager);
 128			if ($result > 0)
 129			{
 130				header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
 131				exit;
 132			}
 133			else
 134			{
 135				setEventMessage($object->error, 'errors');
 136				$action='';
 137			}
 138		}
 139	}
 140}
 141
 142// Suppression de la propale
 143else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propale->supprimer)
 144{
 145	$result=$object->delete($user);
 146	if ($result > 0)
 147	{
 148		Header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
 149		exit;
 150	}
 151	else
 152	{
 153		$langs->load("errors");
 154		setEventMessage($langs->trans($object->error), 'errors');
 155	}
 156}
 157
 158// Remove line
 159else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propale->creer)
 160{
 161	$result = $object->deleteline($lineid);
 162	// reorder lines
 163	if ($result) $object->line_order(true);
 164
 165	// Define output language
 166	$outputlangs = $langs;
 167	$newlang='';
 168	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
 169	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 170	if (! empty($newlang))
 171	{
 172		$outputlangs = new Translate("",$conf);
 173		$outputlangs->setDefaultLang($newlang);
 174	}
 175	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 176	{
 177		$ret=$object->fetch($id);    // Reload to get new records
 178		propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 179	}
 180
 181	Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 182	exit;
 183}
 184
 185// Validation
 186else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propale->valider)
 187{
 188	$result=$object->valid($user);
 189	if ($result >= 0)
 190	{
 191		// Define output language
 192		$outputlangs = $langs;
 193		$newlang='';
 194		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
 195		if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 196		if (! empty($newlang))
 197		{
 198			$outputlangs = new Translate("",$conf);
 199			$outputlangs->setDefaultLang($newlang);
 200		}
 201		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 202		{
 203            $ret=$object->fetch($object->id);    // Reload to get new records
 204		    propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 205		}
 206	}
 207	else
 208	{
 209		$langs->load("errors");
 210		setEventMessage($langs->trans($object->error), 'errors');
 211	}
 212}
 213
 214else if ($action == 'setdate' && $user->rights->propale->creer)
 215{
 216    $datep=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
 217
 218    if (empty($datep))
 219    {
 220        $error++;
 221        setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
 222    }
 223
 224    if (! $error)
 225    {
 226    	$result=$object->set_date($user,$datep);
 227    	if ($result < 0) dol_print_error($db,$object->error);
 228    }
 229}
 230else if ($action == 'setecheance' && $user->rights->propale->creer)
 231{
 232	$result=$object->set_echeance($user,dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']));
 233	if ($result < 0) dol_print_error($db,$object->error);
 234}
 235else if ($action == 'setdate_livraison' && $user->rights->propale->creer)
 236{
 237	$result=$object->set_date_livraison($user,dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']));
 238	if ($result < 0) dol_print_error($db,$object->error);
 239}
 240
 241// Positionne ref client
 242else if ($action == 'set_ref_client' && $user->rights->propale->creer)
 243{
 244	$object->set_ref_client($user, $_POST['ref_client']);
 245}
 246
 247else if ($action == 'setnote_public' && $user->rights->propale->creer)
 248{
 249	$result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
 250	if ($result < 0) dol_print_error($db,$object->error);
 251}
 252
 253else if ($action == 'setnote' && $user->rights->propale->creer)
 254{
 255	$result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
 256	if ($result < 0) dol_print_error($db,$object->error);
 257}
 258
 259// Create proposal
 260else if ($action == 'add' && $user->rights->propale->creer)
 261{
 262	$object->socid=$socid;
 263	$object->fetch_thirdparty();
 264
 265	$datep=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
 266	$date_delivery=dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
 267	$duration=GETPOST('duree_validite');
 268
 269	if (empty($datep))
 270	{
 271		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
 272	    header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create');
 273	    exit;
 274	}
 275	if (empty($duration))
 276	{
 277		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ValidityDuration")), 'errors');
 278		header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create');
 279		exit;
 280	}
 281
 282	if (! $error)
 283	{
 284    	$db->begin();
 285
 286    	// Si on a selectionne une propal a copier, on realise la copie
 287    	if (GETPOST('createmode')=='copy' && GETPOST('copie_propal'))
 288    	{
 289    		if ($object->fetch(GETPOST('copie_propal')) > 0)
 290    		{
 291    			$object->ref       				= GETPOST('ref');
 292    			$object->datep 					= $datep;
 293    			$object->date_livraison 		= $date_delivery;
 294    			$object->availability_id 		= GETPOST('availability_id');
 295    			$object->demand_reason_id       = GETPOST('demand_reason_id');
 296    			$object->fk_delivery_address 	= GETPOST('fk_address');
 297    			$object->duree_validite			= $duration;
 298    			$object->cond_reglement_id 		= GETPOST('cond_reglement_id');
 299    			$object->mode_reglement_id 		= GETPOST('mode_reglement_id');
 300    			$object->remise_percent 		= GETPOST('remise_percent');
 301    			$object->remise_absolue 		= GETPOST('remise_absolue');
 302    			$object->socid    				= GETPOST('socid');
 303    			$object->contactid 				= GETPOST('contactidp');
 304    			$object->fk_project				= GETPOST('projectid');
 305    			$object->modelpdf  				= GETPOST('model');
 306    			$object->author    				= $user->id;			// deprecated
 307    			$object->note      				= GETPOST('note');
 308    			$object->statut    				= 0;
 309
 310    			$id = $object->create_from($user);
 311    		}
 312    		else
 313    		{
 314    			setEventMessage($langs->trans("ErrorFailedToCopyProposal",GETPOST('copie_propal')), 'errors');
 315    		}
 316    	}
 317    	else
 318    	{
 319    		$object->ref					= GETPOST('ref');
 320    		$object->ref_client 			= GETPOST('ref_client');
 321    		$object->datep 					= $datep;
 322    		$object->date_livraison 		= $date_delivery;
 323    		$object->availability_id 		= GETPOST('availability_id');
 324    		$object->demand_reason_id       = GETPOST('demand_reason_id');
 325    		$object->fk_delivery_address 	= GETPOST('fk_address');
 326    		$object->duree_validite 		= GETPOST('duree_validite');
 327    		$object->cond_reglement_id 		= GETPOST('cond_reglement_id');
 328    		$object->mode_reglement_id 		= GETPOST('mode_reglement_id');
 329
 330    		$object->contactid  = GETPOST('contactidp');
 331    		$object->fk_project = GETPOST('projectid');
 332    		$object->modelpdf   = GETPOST('model');
 333    		$object->author     = $user->id;		// deprecated
 334    		$object->note       = GETPOST('note');
 335
 336    		$object->origin		= GETPOST('origin');
 337    		$object->origin_id	= GETPOST('originid');
 338
 339    		for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++)
 340    		{
 341    			if ($_POST['idprod'.$i])
 342    			{
 343    				$xid = 'idprod'.$i;
 344    				$xqty = 'qty'.$i;
 345    				$xremise = 'remise'.$i;
 346    				$object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
 347    			}
 348    		}
 349
 350    		$id = $object->create($user);
 351    	}
 352
 353    	if ($id > 0)
 354    	{
 355    		// Insertion contact par defaut si defini
 356    		if (GETPOST('contactidp'))
 357    		{
 358    			$result=$object->add_contact(GETPOST('contactidp'),'CUSTOMER','external');
 359    			if ($result < 0)
 360    			{
 361    				$error++;
 362    				setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors');
 363    			}
 364    		}
 365
 366    		if (! $error)
 367    		{
 368    			$db->commit();
 369
 370    			// Define output language
 371    			$outputlangs = $langs;
 372    			$newlang='';
 373    			if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
 374    			if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 375    			if (! empty($newlang))
 376    			{
 377    				$outputlangs = new Translate("",$conf);
 378    				$outputlangs->setDefaultLang($newlang);
 379    			}
 380    			if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 381
 382    			Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
 383    			exit;
 384    		}
 385    		else
 386    		{
 387    			$db->rollback();
 388    		}
 389    	}
 390    	else
 391    	{
 392    		dol_print_error($db,$object->error);
 393    		$db->rollback();
 394    		exit;
 395    	}
 396	}
 397}
 398
 399// Classify billed
 400else if ($action == 'classifybilled' && $user->rights->propale->cloturer)
 401{
 402	$object->cloture($user, 4, '');
 403}
 404
 405// Reopen proposal
 406else if ($action == 'confirm_reopen' && $user->rights->propale->cloturer && ! GETPOST('cancel'))
 407{
 408	// prevent browser refresh from reopening proposal several times
 409	if ($object->statut==2 || $object->statut==3)
 410	{
 411		$object->setStatut(1);
 412	}
 413}
 414
 415// Close proposal
 416else if ($action == 'setstatut' && $user->rights->propale->cloturer && ! GETPOST('cancel'))
 417{
 418	if (! GETPOST('statut'))
 419	{
 420		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("CloseAs")), 'errors');
 421		$action='statut';
 422	}
 423	else
 424	{
 425		// prevent browser refresh from closing proposal several times
 426		if ($object->statut==1)
 427		{
 428			$object->cloture($user, GETPOST('statut'), GETPOST('note'));
 429		}
 430	}
 431}
 432
 433/*
 434 * Add file in email form
 435 */
 436if (GETPOST('addfile'))
 437{
 438	require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
 439
 440	// Set tmp user directory TODO Use a dedicated directory for temp mails files
 441	$vardir=$conf->user->dir_output."/".$user->id;
 442	$upload_dir_tmp = $vardir.'/temp';
 443
 444	dol_add_file_process($upload_dir_tmp,0,0);
 445	$action='presend';
 446}
 447
 448/*
 449 * Remove file in email form
 450 */
 451if (GETPOST('removedfile'))
 452{
 453	require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
 454
 455	// Set tmp user directory
 456	$vardir=$conf->user->dir_output."/".$user->id;
 457	$upload_dir_tmp = $vardir.'/temp';
 458
 459	// TODO Delete only files that was uploaded from email form
 460	dol_remove_file_process($_POST['removedfile'],0);
 461	$action='presend';
 462}
 463
 464/*
 465 * Send mail
 466 */
 467if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
 468{
 469	$langs->load('mails');
 470
 471	if ($object->id > 0)
 472	{
 473		if ($_POST['sendto'])
 474		{
 475			// Le destinataire a ete fourni via le champ libre
 476			$sendto = $_POST['sendto'];
 477			$sendtoid = 0;
 478		}
 479		elseif ($_POST['receiver'] != '-1')
 480		{
 481			// Recipient was provided from combo list
 482			if ($_POST['receiver'] == 'thirdparty')	// Id of third party
 483			{
 484				$sendto = $object->client->email;
 485				$sendtoid = 0;
 486			}
 487			else	// Id du contact
 488			{
 489				$sendto = $object->client->contact_get_property($_POST['receiver'],'email');
 490				$sendtoid = $_POST['receiver'];
 491			}
 492		}
 493
 494		if (dol_strlen($sendto))
 495		{
 496			$langs->load("commercial");
 497
 498			$from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
 499			$replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
 500			$message = $_POST['message'];
 501			$sendtocc = $_POST['sendtocc'];
 502			$deliveryreceipt = $_POST['deliveryreceipt'];
 503
 504			if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
 505			else $subject = $langs->transnoentities('Propal').' '.$object->ref;
 506			$actiontypecode='AC_PROP';
 507			$actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
 508			if ($message)
 509			{
 510				$actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
 511				$actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
 512				$actionmsg.=$message;
 513			}
 514			$actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
 515
 516			// Create form object
 517			include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
 518			$formmail = new FormMail($db);
 519
 520			$attachedfiles=$formmail->get_attached_files();
 521			$filepath = $attachedfiles['paths'];
 522			$filename = $attachedfiles['names'];
 523			$mimetype = $attachedfiles['mimes'];
 524
 525			// Envoi de la propal
 526			require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
 527			$mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
 528			if ($mailfile->error)
 529			{
 530				setEventMessage($mailfile->error, 'errors');
 531			}
 532			else
 533			{
 534				$result=$mailfile->sendfile();
 535				if ($result)
 536				{
 537					// Initialisation donnees
 538					$object->sendtoid		= $sendtoid;
 539					$object->actiontypecode	= $actiontypecode;
 540					$object->actionmsg		= $actionmsg;
 541					$object->actionmsg2		= $actionmsg2;
 542					$object->fk_element		= $object->id;
 543					$object->elementtype	= $object->element;
 544
 545					// Appel des triggers
 546					include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
 547					$interface=new Interfaces($db);
 548					$result=$interface->run_triggers('PROPAL_SENTBYMAIL',$object,$user,$langs,$conf);
 549					if ($result < 0) {
 550						$error++; $this->errors=$interface->errors;
 551					}
 552					// Fin appel triggers
 553
 554					if (! $error)
 555					{
 556						// Redirect here
 557						// This avoid sending mail twice if going out and then back to page
 558						$mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
 559						setEventMessage($mesg);
 560						Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
 561						exit;
 562					}
 563					else
 564					{
 565						dol_print_error($db);
 566					}
 567				}
 568				else
 569				{
 570					$langs->load("other");
 571					if ($mailfile->error)
 572					{
 573						$mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
 574						$mesg.='<br>'.$mailfile->error;
 575					}
 576					else
 577					{
 578						$mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
 579					}
 580					setEventMessage($mesg, 'errors');
 581				}
 582			}
 583		}
 584		else
 585		{
 586			$langs->load("other");
 587			setEventMessage($langs->trans('ErrorMailRecipientIsEmpty').'!', 'errors');
 588			dol_syslog($langs->trans('ErrorMailRecipientIsEmpty'));
 589		}
 590	}
 591	else
 592	{
 593		$langs->load("other");
 594		setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal")), 'errors');
 595		dol_syslog($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal")));
 596	}
 597}
 598
 599// Go back to draft
 600if ($action == 'modif' && $user->rights->propale->creer)
 601{
 602	$object->set_draft($user);
 603
 604	// Define output language
 605	$outputlangs = $langs;
 606	$newlang='';
 607	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
 608	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 609	if (! empty($newlang))
 610	{
 611		$outputlangs = new Translate("",$conf);
 612		$outputlangs->setDefaultLang($newlang);
 613	}
 614
 615	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 616}
 617
 618else if ($action == "setabsolutediscount" && $user->rights->propale->creer)
 619{
 620	if ($_POST["remise_id"])
 621	{
 622		if ($object->id > 0)
 623		{
 624			$result=$object->insert_discount($_POST["remise_id"]);
 625			if ($result < 0)
 626			{
 627				setEventMessage($object->error, 'errors');
 628			}
 629		}
 630	}
 631}
 632
 633//Ajout d'une ligne produit dans la propale
 634else if ($action == "addline" && $user->rights->propale->creer)
 635{
 636	if (empty($_POST['idprod']) && GETPOST('type') < 0)
 637	{
 638		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
 639		$error++;
 640	}
 641	if (empty($_POST['idprod']) && (! isset($_POST["np_price"]) || $_POST["np_price"]==''))	// Unit price can be 0 but not ''
 642	{
 643		setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
 644		$error++;
 645	}
 646
 647	if (! $error && isset($_POST['qty']) && ((GETPOST('np_price')!='' && (GETPOST('np_desc') || GETPOST('dp_desc'))) || GETPOST('idprod')))
 648	{
 649		$pu_ht=0;
 650		$pu_ttc=0;
 651		$price_min=0;
 652		$price_base_type = 'HT';
 653
 654		// Ecrase $pu par celui du produit
 655		// Ecrase $desc par celui du produit
 656		// Ecrase $txtva par celui du produit
 657		if (GETPOST('idprod'))
 658		{
 659			$prod = new Product($db);
 660			$prod->fetch(GETPOST('idprod'));
 661
 662			$tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
 663			$localtax1_tx= get_localtax($tva_tx, 1, $object->client);  //get_default_localtax($mysoc,$object->client,1,$prod->id);
 664			$localtax2_tx= get_localtax($tva_tx, 2, $object->client); //get_default_localtax($mysoc,$object->client,2,$prod->id);
 665			$tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
 666
 667			// On defini prix unitaire
 668			if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->client->price_level)
 669			{
 670				$pu_ht  = $prod->multiprices[$object->client->price_level];
 671				$pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
 672				$price_min = $prod->multiprices_min[$object->client->price_level];
 673				$price_base_type = $prod->multiprices_base_type[$object->client->price_level];
 674			}
 675			else
 676			{
 677				$pu_ht = $prod->price;
 678				$pu_ttc = $prod->price_ttc;
 679				$price_min = $prod->price_min;
 680				$price_base_type = $prod->price_base_type;
 681			}
 682
 683			// On reevalue prix selon taux tva car taux tva transaction peut etre different
 684			// de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
 685			if ($tva_tx != $prod->tva_tx)
 686			{
 687				if ($price_base_type != 'HT')
 688				{
 689					$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
 690				}
 691				else
 692				{
 693					$pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
 694				}
 695			}
 696
 697			// Define output language
 698			if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
 699			{
 700				$outputlangs = $langs;
 701				$newlang='';
 702				if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
 703				if (empty($newlang)) $newlang=$object->client->default_lang;
 704				if (! empty($newlang))
 705				{
 706					$outputlangs = new Translate("",$conf);
 707					$outputlangs->setDefaultLang($newlang);
 708				}
 709
 710				$desc = (! empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
 711			}
 712			else
 713			{
 714				$desc = $prod->description;
 715			}
 716
 717			$desc.= ($desc && GETPOST('np_desc')) ? ((dol_textishtml($desc) || dol_textishtml(GETPOST('np_desc')))?"<br />\n":"\n") : "";
 718			$desc.= GETPOST('np_desc');
 719			$type = $prod->type;
 720		}
 721		else
 722		{
 723			$pu_ht=GETPOST('np_price');
 724			$tva_tx=str_replace('*','',GETPOST('np_tva_tx'));
 725			$tva_npr=preg_match('/\*/',GETPOST('np_tva_tx'))?1:0;
 726			$desc=GETPOST('dp_desc');
 727			$type=GETPOST('type');
 728			$localtax1_tx=get_localtax($tva_tx,1,$object->client);
 729			$localtax2_tx=get_localtax($tva_tx,2,$object->client);
 730		}
 731
 732		$info_bits=0;
 733		if ($tva_npr) $info_bits |= 0x01;
 734
 735		if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
 736		{
 737			$mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency));
 738			setEventMessage($mesg, 'errors');
 739		}
 740		else
 741		{
 742			// Insert line
 743			$result=$object->addline(
 744    			$id,
 745    			$desc,
 746    			$pu_ht,
 747    			GETPOST('qty'),
 748    			$tva_tx,
 749    			$localtax1_tx,
 750    			$localtax2_tx,
 751    			GETPOST('idprod'),
 752    			GETPOST('remise_percent'),
 753    			$price_base_type,
 754    			$pu_ttc,
 755    			$info_bits,
 756    			$type,
 757    			-1,
 758    			0,
 759    			GETPOST('fk_parent_line'),
 760    			GETPOST('np_fournprice'),
 761    			GETPOST('np_buying_price')
 762			);
 763
 764			if ($result > 0)
 765			{
 766				// Define output language
 767				$outputlangs = $langs;
 768				$newlang='';
 769				if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
 770				if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 771				if (! empty($newlang))
 772				{
 773					$outputlangs = new Translate("",$conf);
 774					$outputlangs->setDefaultLang($newlang);
 775				}
 776				if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 777				{
 778                    $ret=$object->fetch($id);    // Reload to get new records
 779				    propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 780				}
 781
 782				unset($_POST['qty']);
 783				unset($_POST['type']);
 784				unset($_POST['np_price']);
 785				unset($_POST['dp_desc']);
 786				unset($_POST['np_tva_tx']);
 787				unset($_POST['np_desc']);
 788				unset($_POST['np_buying_price']);
 789			}
 790			else
 791			{
 792				setEventMessage($object->error, 'errors');
 793			}
 794		}
 795	}
 796}
 797
 798// Mise a jour d'une ligne dans la propale
 799else if ($action == 'updateligne' && $user->rights->propale->creer && GETPOST('save') == $langs->trans("Save"))
 800{
 801	// Define info_bits
 802	$info_bits=0;
 803	if (preg_match('/\*/',$_POST['tva_tx'])) $info_bits |= 0x01;
 804
 805	// Define vat_rate
 806	$vat_rate=$_POST['tva_tx'];
 807	$vat_rate=str_replace('*','',$vat_rate);
 808	$localtax1_rate=get_localtax($vat_rate,1,$object->client);
 809	$localtax2_rate=get_localtax($vat_rate,2,$object->client);
 810	$pu_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice');
 811
 812	// Define special_code for special lines
 813	$special_code=0;
 814	if (empty($_POST['qty'])) $special_code=3;
 815
 816	// On verifie que le prix minimum est respecte
 817	$productid = $_POST['productid'] ;
 818	if ($productid)
 819	{
 820		$product = new Product($db);
 821		$res=$product->fetch($productid);
 822		$price_min = $product->price_min;
 823		if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level)	$price_min = $product->multiprices_min[$object->client->price_level];
 824	}
 825	if ($productid && $price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min)))
 826	{
 827		$mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency));
 828		setEventMessage($mesg, 'errors');
 829	}
 830	else
 831	{
 832		$result = $object->updateline(
 833    		$_POST['lineid'],
 834    		$pu_ht,
 835    		$_POST['qty'],
 836    		$_POST['remise_percent'],
 837    		$vat_rate,
 838    		$localtax1_rate,
 839    		$localtax2_rate,
 840    		$_POST['desc'],
 841    		'HT',
 842    		$info_bits,
 843    		$special_code,
 844    		$_POST['fk_parent_line'],
 845    		0,
 846    		GETPOST('fournprice'),
 847    		GETPOST('buying_price')
 848		);
 849
 850		// Define output language
 851		$outputlangs = $langs;
 852		$newlang='';
 853		if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
 854		if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 855		if (! empty($newlang))
 856		{
 857			$outputlangs = new Translate("",$conf);
 858			$outputlangs->setDefaultLang($newlang);
 859		}
 860		if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 861		{
 862			$ret=$object->fetch($id);    // Reload to get new records
 863			propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 864
 865			unset($_POST['qty']);
 866			unset($_POST['type']);
 867			unset($_POST['np_price']);
 868			unset($_POST['dp_desc']);
 869			unset($_POST['np_tva_tx']);
 870			unset($_POST['np_buying_price']);
 871		}
 872	}
 873}
 874
 875// Generation doc (depuis lien ou depuis cartouche doc)
 876else if ($action == 'builddoc' && $user->rights->propale->creer)
 877{
 878	if (GETPOST('model'))
 879	{
 880		$object->setDocModel($user, GETPOST('model'));
 881	}
 882
 883	// Define output language
 884	$outputlangs = $langs;
 885	$newlang='';
 886	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
 887	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 888	if (! empty($newlang))
 889	{
 890		$outputlangs = new Translate("",$conf);
 891		$outputlangs->setDefaultLang($newlang);
 892	}
 893	$result=propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 894	if ($result <= 0)
 895	{
 896		dol_print_error($db,$result);
 897		exit;
 898	}
 899	else
 900	{
 901		Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
 902		exit;
 903	}
 904}
 905
 906// Remove file in doc form
 907else if ($action == 'remove_file' && $user->rights->propale->creer)
 908{
 909	if ($object->id > 0)
 910	{
 911		require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
 912
 913		$langs->load("other");
 914		$upload_dir = $conf->propal->dir_output;
 915		$file = $upload_dir . '/' . GETPOST('file');
 916		$ret=dol_delete_file($file,0,0,0,$object);
 917		if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 918		else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
 919	}
 920}
 921
 922// Set project
 923else if ($action == 'classin' && $user->rights->propale->creer)
 924{
 925	$object->setProject($_POST['projectid']);
 926}
 927
 928// Delai de livraison
 929else if ($action == 'setavailability' && $user->rights->propale->creer)
 930{
 931	$result = $object->availability($_POST['availability_id']);
 932}
 933
 934// Origine de la propale
 935else if ($action == 'setdemandreason' && $user->rights->propale->creer)
 936{
 937	$result = $object->demand_reason($_POST['demand_reason_id']);
 938}
 939
 940// Conditions de reglement
 941else if ($action == 'setconditions' && $user->rights->propale->creer)
 942{
 943	$result = $object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
 944}
 945
 946else if ($action == 'setremisepercent' && $user->rights->propale->creer)
 947{
 948	$result = $object->set_remise_percent($user, $_POST['remise_percent']);
 949}
 950
 951else if ($action == 'setremiseabsolue' && $user->rights->propale->creer)
 952{
 953	$result = $object->set_remise_absolue($user, $_POST['remise_absolue']);
 954}
 955
 956// Mode de reglement
 957else if ($action == 'setmode' && $user->rights->propale->creer)
 958{
 959	$result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
 960}
 961
 962/*
 963 * Ordonnancement des lignes
 964 */
 965
 966else if ($action == 'up' && $user->rights->propale->creer)
 967{
 968	$object->line_up(GETPOST('rowid'));
 969
 970	// Define output language
 971	$outputlangs = $langs;
 972	$newlang='';
 973	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
 974	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 975	if (! empty($newlang))
 976	{
 977		$outputlangs = new Translate("",$conf);
 978		$outputlangs->setDefaultLang($newlang);
 979	}
 980	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
 981
 982	Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid'));
 983	exit;
 984}
 985
 986else if ($action == 'down' && $user->rights->propale->creer)
 987{
 988	$object->line_down(GETPOST('rowid'));
 989
 990	// Define output language
 991	$outputlangs = $langs;
 992	$newlang='';
 993	if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
 994	if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 995	if (! empty($newlang))
 996	{
 997		$outputlangs = new Translate("",$conf);
 998		$outputlangs->setDefaultLang($newlang);
 999	}
1000	if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
1001
1002	Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid'));
1003	exit;
1004}
1005
1006if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propale->creer)
1007{
1008	if ($action == 'addcontact')
1009	{
1010		if ($object->id > 0)
1011		{
1012			$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1013			$result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
1014		}
1015
1016		if ($result >= 0)
1017		{
1018			Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1019			exit;
1020		}
1021		else
1022		{
1023			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1024			{
1025				$langs->load("errors");
1026				setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
1027			}
1028			else
1029			{
1030				setEventMessage($object->error, 'errors');
1031			}
1032		}
1033	}
1034
1035	// Bascule du statut d'un contact
1036	else if ($action == 'swapstatut')
1037	{
1038		if ($object->fetch($id) > 0)
1039		{
1040			$result=$object->swapContactStatus(GETPOST('ligne'));
1041		}
1042		else
1043		{
1044			dol_print_error($db);
1045		}
1046	}
1047
1048	// Efface un contact
1049	else if ($action == 'deletecontact')
1050	{
1051		$object->fetch($id);
1052		$result = $object->delete_contact($lineid);
1053
1054		if ($result >= 0)
1055		{
1056			Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1057			exit;
1058		}
1059		else
1060		{
1061			dol_print_error($db);
1062		}
1063	}
1064}
1065
1066
1067/*
1068 * View
1069 */
1070
1071llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
1072
1073$form = new Form($db);
1074$formother = new FormOther($db);
1075$formfile = new FormFile($db);
1076$formpropal = new FormPropal($db);
1077$companystatic=new Societe($db);
1078
1079$now=dol_now();
1080
1081/*
1082 * Show object in view mode
1083 */
1084
1085$soc = new Societe($db);
1086$soc->fetch($object->socid);
1087
1088$head = propal_prepare_head($object);
1089dol_fiche_head($head, 'comm', $langs->trans('Proposal'), 0, 'propal');
1090
1091$formconfirm='';
1092
1093// Clone confirmation
1094if ($action == 'clone')
1095{
1096	// Create an array for form
1097	$formquestion=array(
1098	//'text' => $langs->trans("ConfirmClone"),
1099	//array('type' => 'checkbox', 'name' => 'clone_content',   'label' => $langs->trans("CloneMainAttributes"),   'value' => 1),
1100	//array('type' => 'checkbox', 'name' => 'update_prices',   'label' => $langs->trans("PuttingPricesUpToDate"),   'value' => 1),
1101	array('type' => 'other', 'name' => 'socid',   'label' => $langs->trans("SelectThirdParty"),   'value' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=2 OR s.client=3)'))
1102	);
1103	// Paiement incomplet. On demande si motif = escompte ou autre
1104	$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1);
1105}
1106
1107// Confirm delete
1108else if ($action == 'delete')
1109{
1110	$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp',$object->ref), 'confirm_delete','',0,1);
1111}
1112
1113// Confirm reopen
1114else if ($action == 'reopen')
1115{
1116	$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp',$object->ref), 'confirm_reopen','',0,1);
1117}
1118
1119// Confirmation delete product/service line
1120else if ($action == 'ask_deleteline')
1121{
1122	$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1);
1123}
1124
1125// Confirm validate proposal
1126else if ($action == 'validate')
1127{
1128    $error=0;
1129
1130	// on verifie si l'objet est en numerotation provisoire
1131	$ref = substr($object->ref, 1, 4);
1132	if ($ref == 'PROV')
1133	{
1134		$numref = $object->getNextNumRef($soc);
1135		if (empty($numref))
1136		{
1137		    $error++;
1138		    dol_htmloutput_errors($object->error);
1139		}
1140	}
1141	else
1142	{
1143		$numref = $object->ref;
1144	}
1145
1146	$text=$langs->trans('ConfirmValidateProp',$numref);
1147	if ($conf->notification->enabled)
1148	{
1149		require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php");
1150		$notify=new Notify($db);
1151		$text.='<br>';
1152		$text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$object->socid);
1153	}
1154
1155	if (! $error) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1);
1156}
1157
1158if (! $formconfirm)
1159{
1160    $parameters=array('lineid'=>$lineid);
1161    $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1162}
1163
1164// Print form confirm
1165print $formconfirm;
1166
1167
1168print '<table class="border" width="100%">';
1169
1170$linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
1171
1172// Ref
1173print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="5">';
1174print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
1175print '</td></tr>';
1176
1177// Ref client
1178print '<tr><td>';
1179print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
1180print $langs->trans('RefCustomer').'</td><td align="left">';
1181print '</td>';
1182if ($action != 'refclient' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refclient&amp;id='.$object->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
1183print '</tr></table>';
1184print '</td><td colspan="5">';
1185if ($user->rights->propale->creer && $action == 'refclient')
1186{
1187	print '<form action="propal.php?id='.$object->id.'" method="post">';
1188	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1189	print '<input type="hidden" name="action" value="set_ref_client">';
1190	print '<input type="text" class="flat" size="20" name="ref_client" value="'.$object->ref_client.'">';
1191	print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1192	print '</form>';
1193}
1194else
1195{
1196	print $object->ref_client;
1197}
1198print '</td>';
1199print '</tr>';
1200
1201// Company
1202print '<tr><td>'.$langs->trans('Company').'</td><td colspan="5">'.$soc->getNomUrl(1).'</td>';
1203print '</tr>';
1204
1205// Ligne info remises tiers
1206print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="5">';
1207if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
1208else print $langs->trans("CompanyHasNoRelativeDiscount");
1209print '. ';
1210$absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
1211$absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
1212$absolute_discount=price2num($absolute_discount,'MT');
1213$absolute_creditnote=price2num($absolute_creditnote,'MT');
1214if ($absolute_discount)
1215{
1216	if ($object->statut > 0)
1217	{
1218		print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
1219	}
1220	else
1221	{
1222		// Remise dispo de type non avoir
1223		$filter='fk_facture_source IS NULL';
1224		print '<br>';
1225		$form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter);
1226	}
1227}
1228if ($absolute_creditnote)
1229{
1230	print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. ';
1231}
1232if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
1233print '</td></tr>';
1234
1235// Date of proposal
1236print '<tr>';
1237print '<td>';
1238print '<table class="nobordernopadding" width="100%"><tr><td>';
1239print $langs->trans('Date');
1240print '</td>';
1241if ($action != 'editdate' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
1242print '</tr></table>';
1243print '</td><td colspan="3">';
1244if (! empty($object->brouillon) && $action == 'editdate')
1245{
1246	print '<form name="editdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1247	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1248	print '<input type="hidden" name="action" value="setdate">';
1249	$form->select_date($object->date,'re','','',0,"editdate");
1250	print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1251	print '</form>';
1252}
1253else
1254{
1255	if ($object->date)
1256	{
1257		print dol_print_date($object->date,'daytext');
1258	}
1259	else
1260	{
1261		print '&nbsp;';
1262	}
1263}
1264print '</td>';
1265
1266// Date end proposal
1267print '<tr>';
1268print '<td>';
1269print '<table class="nobordernopadding" width="100%"><tr><td>';
1270print $langs->trans('DateEndPropal');
1271print '</td>';
1272if ($action != 'editecheance' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editecheance&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
1273print '</tr></table>';
1274print '</td><td colspan="3">';
1275if (! empty($object->brouillon) && $action == 'editecheance')
1276{
1277	print '<form name="editecheance" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1278	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1279	print '<input type="hidden" name="action" value="setecheance">';
1280	$form->select_date($object->fin_validite,'ech','','','',"editecheance");
1281	print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1282	print '</form>';
1283}
1284else
1285{
1286	if (! empty($object->fin_validite))
1287	{
1288		print dol_print_date($object->fin_validite,'daytext');
1289		if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
1290	}
1291	else
1292	{
1293		print '&nbsp;';
1294	}
1295}
1296print '</td>';
1297print '</tr>';
1298
1299// Payment term
1300print '<tr><td>';
1301print '<table class="nobordernopadding" width="100%"><tr><td>';
1302print $langs->trans('PaymentConditionsShort');
1303print '</td>';
1304if ($action != 'editconditions' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'),1).'</a></td>';
1305print '</tr></table>';
1306print '</td><td colspan="3">';
1307if ($action == 'editconditions')
1308{
1309    $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id');
1310}
1311else
1312{
1313    $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none');
1314}
1315print '</td>';
1316print '</tr>';
1317
1318// Delivery date
1319$langs->load('deliveries');
1320print '<tr><td>';
1321print '<table class="nobordernopadding" width="100%"><tr><td>';
1322print $langs->trans('DeliveryDate');
1323print '</td>';
1324if ($action != 'editdate_livraison' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'),1).'</a></td>';
1325print '</tr></table>';
1326print '</td><td colspan="3">';
1327if ($action == 'editdate_livraison')
1328{
1329	print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1330	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1331	print '<input type="hidden" name="action" value="setdate_livraison">';
1332	$form->select_date($object->date_livraison,'liv_','','','',"editdate_livraison");
1333	print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
1334	print '</form>';
1335}
1336else
1337{
1338	print dol_print_date($object->date_livraison,'daytext');
1339}
1340print '</td>';
1341print '</tr>';
1342
1343// Delivery delay
1344print '<tr><td>';
1345print '<table class="nobordernopadding" width="100%"><tr><td>';
1346print $langs->trans('AvailabilityPeriod');
1347if (! empty($conf->commande->enabled)) print ' ('.$langs->trans('AfterOrder').')';
1348print '</td>';
1349if ($action != 'editavailability' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editavailability&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'),1).'</a></td>';
1350print '</tr></table>';
1351print '</td><td colspan="3">';
1352if ($action == 'editavailability')
1353{
1354	$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1);
1355}
1356else
1357{
1358	$form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1);
1359}
1360
1361print '</td>';
1362print '</tr>';
1363
1364// Origin of demand
1365print '<tr><td>';
1366print '<table class="nobordernopadding" width="100%"><tr><td>';
1367print $langs->trans('Source');
1368print '</td>';
1369if ($action != 'editdemandreason' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'),1).'</a></td>';
1370print '</tr></table>';
1371print '</td><td colspan="3">';
1372//print $object->demand_reason_id;
1373if ($action == 'editdemandreason')
1374{
1375	$form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1);
1376}
1377else
1378{
1379	$form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none');
1380}
1381
1382print '</td>';
1383print '</tr>';
1384
1385// Payment mode
1386print '<tr>';
1387print '<td width="25%">';
1388print '<table class="nobordernopadding" width="100%"><tr><td>';
1389print $langs->trans('PaymentMode');
1390print '</td>';
1391if ($action != 'editmode' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'),1).'</a></td>';
1392print '</tr></table>';
1393print '</td><td colspan="3">';
1394if ($action == 'editmode')
1395{
1396	$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
1397}
1398else
1399{
1400	$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
1401}
1402print '</td></tr>';
1403
1404// Project
1405if (! empty($conf->projet->enabled))
1406{
1407	$langs->load("projects");
1408	print '<tr><td>';
1409	print '<table class="nobordernopadding" width="100%"><tr><td>';
1410	print $langs->trans('Project').'</td>';
1411	if ($user->rights->propale->creer)
1412	{
1413		if ($action != 'classify') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a></td>';
1414		print '</tr></table>';
1415		print '</td><td colspan="3">';
1416		if ($action == 'classify')
1417		{
1418			$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid');
1419		}
1420		else
1421		{
1422			$form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
1423		}
1424		print '</td></tr>';
1425	}
1426	else
1427	{
1428		print '</td></tr></table>';
1429		if (! empty($object->fk_project))
1430		{
1431			print '<td colspan="3">';
1432			$proj = new Project($db);
1433			$proj->fetch($object->fk_project);
1434			print '<a href="../projet/fiche.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
1435			print $proj->ref;
1436			print '</a>';
1437			print '</td>';
1438		}
1439		else {
1440			print '<td colspan="3">&nbsp;</td>';
1441		}
1442	}
1443	print '</tr>';
1444}
1445
1446// Other attributes
1447$parameters=array('colspan' => ' colspan="3"');
1448$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
1449if (empty($reshook) && ! empty($extrafields->attribute_label))
1450{
1451    foreach($extrafields->attribute_label as $key=>$label)
1452    {
1453        $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
1454        print "<tr><td>".$label.'</td><td colspan="3">';
1455        print $extrafields->showInputField($key,$value);
1456        print '</td></tr>'."\n";
1457    }
1458}
1459
1460// Amount HT
1461print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';
1462print '<td align="right" nowrap><b>'.price($object->total_ht).'</b></td>';
1463print '<td>'.$langs->trans("Currency".$conf->currency).'</td>';
1464
1465// Margin Infos
1466if (! empty($conf->margin->enabled)) {
1467  print '<td valign="top" width="50%" rowspan="4">';
1468  $object->displayMarginInfos();
1469  print '</td>';
1470}
1471print '</tr>';
1472
1473// Amount VAT
1474print '<tr><td height="10">'.$langs->trans('AmountVAT').'</td>';
1475print '<td align="right" nowrap>'.price($object->total_tva).'</td>';
1476print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1477
1478// Amount Local Taxes
1479if ($mysoc->country_code=='ES')
1480{
1481	if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
1482	{
1483		print '<tr><td height="10">'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
1484		print '<td align="right" nowrap>'.price($object->total_localtax1).'</td>';
1485		print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1486	}
1487	if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
1488	{
1489		print '<tr><td height="10">'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
1490		print '<td align="right" nowrap>'.price($object->total_localtax2).'</td>';
1491		print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1492	}
1493}
1494
1495// Amount TTC
1496print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td>';
1497print '<td align="right" nowrap>'.price($object->total_ttc).'</td>';
1498print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
1499
1500// Statut
1501print '<tr><td height="10">'.$langs->trans('Status').'</td><td align="left" colspan="2">'.$object->getLibStatut(4).'</td></tr>';
1502
1503print '</table><br>';
1504
1505if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
1506{
1507	require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
1508	$formcompany= new FormCompany($db);
1509
1510	$blocname = 'contacts';
1511	$title = $langs->trans('ContactsAddresses');
1512	include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
1513}
1514
1515if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
1516{
1517	$blocname = 'notes';
1518	$title = $langs->trans('Notes');
1519	include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
1520}
1521
1522/*
1523 * Lines
1524 */
1525
1526if ($conf->use_javascript_ajax && $object->statut == 0)
1527{
1528	include(DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php');
1529}
1530
1531print '<table id="tablelines" class="noborder" width="100%">';
1532
1533// Show object lines
1534$result = $object->getLinesArray();
1535if (! empty($object->lines)) $object->printObjectLines($action,$mysoc,$soc,$lineid,0,$hookmanager);
1536
1537/*
1538 * Form to add new line
1539 */
1540if ($object->statut == 0 && $user->rights->propale->creer)
1541{
1542	if ($action != 'editline')
1543	{
1544		$var=true;
1545
1546		// Add free products/services
1547		$object->formAddFreeProduct(0,$mysoc,$soc,$hookmanager);
1548
1549		// Add predefined products/services
1550		if ($conf->product->ena…

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