PageRenderTime 1426ms CodeModel.GetById 564ms app.highlight 661ms RepoModel.GetById 184ms app.codeStats 1ms

/htdocs/contrat/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1586 lines | 1145 code | 236 blank | 205 comment | 353 complexity | 9a6986c8f466377237f769b6a3b5314b MD5 | raw file

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

   1<?php
   2/* Copyright (C) 2003-2004	Rodolphe Quiedeville	<rodolphe@quiedeville.org>
   3 * Copyright (C) 2004-2012	Laurent Destailleur		<eldy@users.sourceforge.net>
   4 * Copyright (C) 2005-2012	Regis Houssin			<regis.houssin@capnetworks.com>
   5 * Copyright (C) 2006		Andre Cianfarani		<acianfa@free.fr>
   6 * Copyright (C) 2010-2012	Juanjo Menent			<jmenent@2byte.es>
   7 *
   8 * This program is free software; you can redistribute it and/or modify
   9 * it under the terms of the GNU General Public License as published by
  10 * the Free Software Foundation; either version 3 of the License, or
  11 * (at your option) any later version.
  12 *
  13 * This program is distributed in the hope that it will be useful,
  14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16 * GNU General Public License for more details.
  17 *
  18 * You should have received a copy of the GNU General Public License
  19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20 */
  21
  22/**
  23 *       \file       htdocs/contrat/fiche.php
  24 *       \ingroup    contrat
  25 *       \brief      Page of a contract
  26 */
  27
  28require ("../main.inc.php");
  29require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  30require_once(DOL_DOCUMENT_ROOT."/core/lib/date.lib.php");
  31require_once(DOL_DOCUMENT_ROOT."/core/lib/price.lib.php");
  32require_once(DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php');
  33require_once(DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  34require_once(DOL_DOCUMENT_ROOT."/core/modules/contract/modules_contract.php");
  35if (! empty($conf->produit->enabled) || ! empty($conf->service->enabled))  require_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  36if (! empty($conf->propal->enabled))  require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
  37if ($conf->projet->enabled) {
  38	require_once(DOL_DOCUMENT_ROOT."/projet/class/project.class.php");
  39	require_once(DOL_DOCUMENT_ROOT."/core/lib/project.lib.php");
  40}
  41
  42$langs->load("contracts");
  43$langs->load("orders");
  44$langs->load("companies");
  45$langs->load("bills");
  46$langs->load("products");
  47
  48$action=GETPOST('action','alpha');
  49$confirm=GETPOST('confirm','alpha');
  50$socid = GETPOST('socid','int');
  51$id = GETPOST('id','int');
  52$ref=GETPOST('ref','alpha');
  53
  54$datecontrat='';
  55
  56// Security check
  57if ($user->societe_id) $socid=$user->societe_id;
  58$result=restrictedArea($user,'contrat',$id);
  59
  60$usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE:0);
  61
  62// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  63$hookmanager->initHooks(array('contractcard'));
  64
  65$object = new Contrat($db);
  66
  67
  68/*
  69 * Actions
  70 */
  71
  72if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer)
  73{
  74    $object->fetch($id);
  75    $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment'));
  76
  77    if ($result > 0)
  78    {
  79        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  80        exit;
  81    }
  82    else {
  83        $mesg=$object->error;
  84    }
  85}
  86
  87else if ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer)
  88{
  89    $object->fetch($id);
  90    $result = $object->close_line($user, GETPOST('ligne'), GETPOST('dateend'), urldecode(GETPOST('comment')));
  91
  92    if ($result > 0)
  93    {
  94        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  95        exit;
  96    }
  97    else {
  98        $mesg=$object->error;
  99    }
 100}
 101
 102// Si ajout champ produit predefini
 103if (GETPOST('mode')=='predefined')
 104{
 105    $date_start='';
 106    $date_end='';
 107    if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear'))
 108    {
 109        $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
 110    }
 111    if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear'))
 112    {
 113        $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
 114    }
 115}
 116
 117// Si ajout champ produit libre
 118if (GETPOST('mode')=='libre')
 119{
 120    $date_start_sl='';
 121    $date_end_sl='';
 122    if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear'))
 123    {
 124        $date_start_sl=dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear'));
 125    }
 126    if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear'))
 127    {
 128        $date_end_sl=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear'));
 129    }
 130}
 131
 132// Param dates
 133$date_contrat='';
 134$date_start_update='';
 135$date_end_update='';
 136$date_start_real_update='';
 137$date_end_real_update='';
 138if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear'))
 139{
 140    $date_start_update=dol_mktime(GETPOST('date_start_updatehour'), GETPOST('date_start_updatemin'), 0, GETPOST('date_start_updatemonth'), GETPOST('date_start_updateday'), GETPOST('date_start_updateyear'));
 141}
 142if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear'))
 143{
 144    $date_end_update=dol_mktime(GETPOST('date_end_updatehour'), GETPOST('date_end_updatemin'), 0, GETPOST('date_end_updatemonth'), GETPOST('date_end_updateday'), GETPOST('date_end_updateyear'));
 145}
 146if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear'))
 147{
 148    $date_start_real_update=dol_mktime(GETPOST('date_start_real_updatehour'), GETPOST('date_start_real_updatemin'), 0, GETPOST('date_start_real_updatemonth'), GETPOST('date_start_real_updateday'), GETPOST('date_start_real_updateyear'));
 149}
 150if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear'))
 151{
 152    $date_end_real_update=dol_mktime(GETPOST('date_end_real_updatehour'), GETPOST('date_end_real_updatemin'), 0, GETPOST('date_end_real_updatemonth'), GETPOST('date_end_real_updateday'), GETPOST('date_end_real_updateyear'));
 153}
 154if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear'))
 155{
 156    $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
 157}
 158
 159if ($action == 'add' && $user->rights->contrat->creer)
 160{
 161    $object->socid						= $socid;
 162    $object->date_contrat				= $datecontrat;
 163
 164    $object->commercial_suivi_id		= GETPOST('commercial_suivi_id','int');
 165    $object->commercial_signature_id	= GETPOST('commercial_signature_id','int');
 166
 167    $object->note						= GETPOST('note','alpha');
 168    $object->fk_project					= GETPOST('projectid','int');
 169    $object->remise_percent				= GETPOST('remise_percent','alpha');
 170    $object->ref						= GETPOST('ref','alpha');
 171
 172
 173    // Get extra fields
 174    foreach($_POST as $key => $value)
 175    {
 176        if (preg_match("/^options_/",$key))
 177        {
 178            $object->array_options[$key]=$_POST[$key];
 179        }
 180    }
 181
 182    // Check
 183    if (empty($datecontrat))
 184    {
 185        $error++;
 186        $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")).'</div>';
 187        $action='create';
 188    }
 189
 190    if (! $error)
 191    {
 192        $result = $object->create($user,$langs,$conf);
 193        if ($result > 0)
 194        {
 195            header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 196            exit;
 197        }
 198        else {
 199            $mesg='<div class="error">'.$object->error.'</div>';
 200        }
 201        $action='create';
 202    }
 203}
 204
 205if ($action == 'update')
 206{
 207    if ($_POST["cancel"])
 208    {
 209        Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$contratid);
 210        exit;
 211    }
 212
 213    $object->fetch($contratid);
 214    $object->date_contrat   = $datecontrat;
 215
 216    $object->note           = trim($_POST["note"]);
 217    $object->fk_project     = trim($_POST["projectid"]);
 218    $object->remise_percent = trim($_POST["remise_percent"]);
 219    $object->id             = $contratid;
 220
 221    // Get extra fields
 222    foreach($_POST as $key => $value)
 223    {
 224        if (preg_match("/^options_/",$key))
 225        {
 226            $object->array_options[$key]=$_POST[$key];
 227        }
 228    }
 229
 230        $result = $object->update($user,$langs,$conf);
 231        if ($result > 0)
 232        {
 233            Header("Location: fiche.php?id=".$object->id);
 234            exit;
 235        }
 236        else {
 237            $mesg='<div class="error">'.$object->error.'</div>';
 238        }
 239        $_GET["id"]=$_POST["id"];
 240        $action='edit';
 241}
 242
 243else if ($action == 'classin' && $user->rights->contrat->creer)
 244{
 245    $object->fetch($id);
 246    $object->setProject(GETPOST('projectid'));
 247}
 248
 249else if ($action == 'addline' && $user->rights->contrat->creer)
 250{
 251    if (GETPOST('pqty') && ((GETPOST('pu') != '' && GETPOST('desc')) || GETPOST('idprod')))
 252    {
 253        $ret=$object->fetch($id);
 254        if ($ret < 0)
 255        {
 256            dol_print_error($db,$object->error);
 257            exit;
 258        }
 259        $ret=$object->fetch_thirdparty();
 260
 261        $date_start='';
 262        $date_end='';
 263        // Si ajout champ produit libre
 264        if (GETPOST('mode') == 'libre')
 265        {
 266            if (GETPOST('date_start_slmonth') && GETPOST('date_start_slday') && GETPOST('date_start_slyear'))
 267            {
 268                $date_start=dol_mktime(GETPOST('date_start_slhour'), GETPOST('date_start_slmin'), 0, GETPOST('date_start_slmonth'), GETPOST('date_start_slday'), GETPOST('date_start_slyear'));
 269            }
 270            if (GETPOST('date_end_slmonth') && GETPOST('date_end_slday') && GETPOST('date_end_slyear'))
 271            {
 272                $date_end=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear'));
 273            }
 274        }
 275        // Si ajout champ produit predefini
 276        if (GETPOST('mode') == 'predefined')
 277        {
 278            if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear'))
 279            {
 280                $date_start=dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
 281            }
 282            if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear'))
 283            {
 284                $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
 285            }
 286        }
 287
 288        // Ecrase $pu par celui du produit
 289        // Ecrase $desc par celui du produit
 290        // Ecrase $txtva par celui du produit
 291        // Ecrase $base_price_type par celui du produit
 292        if (GETPOST('idprod'))
 293        {
 294            $prod = new Product($db);
 295            $prod->fetch(GETPOST('idprod'));
 296
 297            $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id);
 298            $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id);
 299
 300            // On defini prix unitaire
 301            if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level)
 302            {
 303                $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
 304                $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
 305                $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
 306                $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
 307            }
 308            else
 309            {
 310                $pu_ht = $prod->price;
 311                $pu_ttc = $prod->price_ttc;
 312                $price_min = $prod->price_min;
 313                $price_base_type = $prod->price_base_type;
 314            }
 315
 316            // On reevalue prix selon taux tva car taux tva transaction peut etre different
 317            // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
 318            if ($tva_tx != $prod->tva_tx)
 319            {
 320                if ($price_base_type != 'HT')
 321                {
 322                    $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
 323                }
 324                else
 325                {
 326                    $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
 327                }
 328            }
 329
 330           	$desc = $prod->description;
 331           	$desc.= $prod->description && GETPOST('desc') ? "\n" : "";
 332           	$desc.= GETPOST('desc');
 333        }
 334        else
 335        {
 336            $pu_ht=GETPOST('pu');
 337            $price_base_type = 'HT';
 338            $tva_tx=str_replace('*','',GETPOST('tva_tx'));
 339            $tva_npr=preg_match('/\*/',GETPOST('tva_tx'))?1:0;
 340            $desc=GETPOST('desc');
 341        }
 342
 343        $localtax1_tx=get_localtax($tva_tx,1,$object->societe);
 344        $localtax2_tx=get_localtax($tva_tx,2,$object->societe);
 345
 346        $info_bits=0;
 347        if ($tva_npr) $info_bits |= 0x01;
 348
 349        if($price_min && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
 350        {
 351            $object->error = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency));
 352            $result = -1 ;
 353        }
 354        else
 355        {
 356            // Insert line
 357            $result = $object->addline(
 358                $desc,
 359                $pu_ht,
 360                GETPOST('pqty'),
 361                $tva_tx,
 362                $localtax1_tx,
 363                $localtax2_tx,
 364                GETPOST('idprod'),
 365                GETPOST('premise'),
 366                $date_start,
 367                $date_end,
 368                $price_base_type,
 369                $pu_ttc,
 370                $info_bits
 371            );
 372        }
 373
 374        if ($result > 0)
 375        {
 376            /*
 377             // Define output language
 378             $outputlangs = $langs;
 379             $newlang='';
 380             if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
 381             if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 382             if (! empty($newlang))
 383             {
 384             $outputlangs = new Translate();
 385             $outputlangs->setDefaultLang($newlang);
 386             }
 387             if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
 388             {
 389	            $ret=$object->fetch($id);    // Reload to get new records
 390             	contrat_pdf_create($db, $object->id, $object->modelpdf, $outputlangs);
 391             }
 392             */
 393        }
 394        else
 395        {
 396            $mesg='<div class="error">'.$object->error.'</div>';
 397        }
 398    }
 399}
 400
 401else if ($action == 'updateligne' && $user->rights->contrat->creer && ! GETPOST('cancel'))
 402{
 403	$ret=$object->fetch($id);
 404	if ($ret < 0)
 405	{
 406		dol_print_error($db,$object->error);
 407		exit;
 408	}
 409
 410	$object->fetch_thirdparty();
 411    $objectline = new ContratLigne($db);
 412    if ($objectline->fetch(GETPOST('elrowid')))
 413    {
 414        $db->begin();
 415
 416        if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture;
 417        if ($date_end_real_update == '')   $date_end_real_update=$objectline->date_cloture;
 418
 419		$localtax1_tx=get_localtax(GETPOST('eltva_tx'),1,$object->thirdparty);
 420        $localtax2_tx=get_localtax(GETPOST('eltva_tx'),2,$object->thirdparty);
 421
 422        $objectline->description=GETPOST('eldesc');
 423        $objectline->price_ht=GETPOST('elprice');
 424        $objectline->subprice=GETPOST('elprice');
 425        $objectline->qty=GETPOST('elqty');
 426        $objectline->remise_percent=GETPOST('elremise_percent');
 427        $objectline->tva_tx=GETPOST('eltva_tx');
 428        $objectline->localtax1_tx=$localtax1_tx;
 429        $objectline->localtax2_tx=$localtax2_tx;
 430        $objectline->date_ouverture_prevue=$date_start_update;
 431        $objectline->date_ouverture=$date_start_real_update;
 432        $objectline->date_fin_validite=$date_end_update;
 433        $objectline->date_cloture=$date_end_real_update;
 434        $objectline->fk_user_cloture=$user->id;
 435
 436        // TODO verifier price_min si fk_product et multiprix
 437
 438        $result=$objectline->update($user);
 439        if ($result > 0)
 440        {
 441            $db->commit();
 442        }
 443        else
 444        {
 445            dol_print_error($db,'Failed to update contrat_det');
 446            $db->rollback();
 447        }
 448    }
 449    else
 450    {
 451        dol_print_error($db);
 452    }
 453}
 454
 455else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer)
 456{
 457    $object->fetch($id);
 458    $result = $object->deleteline(GETPOST('lineid'),$user);
 459
 460    if ($result >= 0)
 461    {
 462        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 463        exit;
 464    }
 465    else
 466    {
 467        $mesg=$object->error;
 468    }
 469}
 470
 471else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer)
 472{
 473    $object->fetch($id);
 474    $result = $object->validate($user);
 475}
 476
 477// Close all lines
 478else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer)
 479{
 480    $object->fetch($id);
 481    $result = $object->cloture($user);
 482}
 483
 484else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer)
 485{
 486	$object->fetch($id);
 487	$object->fetch_thirdparty();
 488	$result=$object->delete($user);
 489	if ($result >= 0)
 490	{
 491		header("Location: index.php");
 492		return;
 493	}
 494	else
 495	{
 496		$mesg='<div class="error">'.$object->error.'</div>';
 497	}
 498}
 499
 500else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contrat->creer)
 501{
 502	if (GETPOST('newcid') > 0)
 503	{
 504		$contractline = new ContratLigne($db);
 505		$result=$contractline->fetch(GETPOST('lineid'));
 506		$contractline->fk_contrat = GETPOST('newcid');
 507		$result=$contractline->update($user,1);
 508		if ($result >= 0)
 509		{
 510			header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
 511			return;
 512		}
 513		else
 514		{
 515			$mesg='<div class="error">'.$object->error.'</div>';
 516		}
 517	}
 518	else
 519	{
 520		$mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("RefNewContract")).'</div>';
 521	}
 522}
 523
 524else if ($action == 'setnote_public' && $user->rights->contrat->creer)
 525{
 526	$result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
 527	if ($result < 0) dol_print_error($db,$object->error);
 528}
 529
 530else if ($action == 'setnote' && $user->rights->contrat->creer)
 531{
 532	$result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
 533	if ($result < 0) dol_print_error($db,$object->error);
 534}
 535
 536if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer)
 537{
 538	if ($action == 'addcontact')
 539	{
 540		$result = $object->fetch($id);
 541
 542		if ($result > 0 && $id > 0)
 543		{
 544			$contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
 545			$result = $result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source'));
 546		}
 547
 548		if ($result >= 0)
 549		{
 550			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 551			exit;
 552		}
 553		else
 554		{
 555			if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
 556			{
 557				$langs->load("errors");
 558				$mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
 559			}
 560			else
 561			{
 562				$mesg = '<div class="error">'.$object->error.'</div>';
 563			}
 564		}
 565	}
 566
 567	// bascule du statut d'un contact
 568	else if ($action == 'swapstatut')
 569	{
 570		if ($object->fetch($id))
 571		{
 572			$result=$object->swapContactStatus(GETPOST('ligne'));
 573		}
 574		else
 575		{
 576			dol_print_error($db);
 577		}
 578	}
 579
 580	// Efface un contact
 581	else if ($action == 'deletecontact')
 582	{
 583		$object->fetch($id);
 584		$result = $object->delete_contact(GETPOST('lineid'));
 585
 586		if ($result >= 0)
 587		{
 588			header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
 589			exit;
 590		}
 591		else {
 592			dol_print_error($db);
 593		}
 594	}
 595}
 596
 597/*
 598 * Generate document
 599 */
 600if (GETPOST('action') == 'builddoc')	// En get ou en post
 601{
 602    $object->fetch($contratid);
 603    $object->fetch_thirdparty();
 604
 605    if (GETPOST('model'))
 606    {
 607        $object->setDocModel($user, GETPOST('model'));
 608    }
 609
 610    // Define output language
 611    $outputlangs = $langs;
 612    $newlang='';
 613    if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
 614    if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
 615    if (! empty($newlang))
 616    {
 617        $outputlangs = new Translate();
 618        $outputlangs->setDefaultLang($newlang);
 619    }
 620    $result=contrat_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'));
 621    if ($result <= 0)
 622    {
 623        dol_print_error($db,$result);
 624        exit;
 625    }
 626    else
 627    {
 628        Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
 629        exit;
 630    }
 631}
 632
 633
 634/*
 635 * View
 636 */
 637
 638llxHeader('',$langs->trans("ContractCard"),"Contrat");
 639
 640$form = new Form($db);
 641$formfile = new FormFile($db);
 642
 643$objectlignestatic=new ContratLigne($db);
 644
 645
 646/*********************************************************************
 647 *
 648 * Mode creation
 649 *
 650 *********************************************************************/
 651if ($action == 'create')
 652{
 653    dol_fiche_head('', '', $langs->trans("AddContract"), 0, 'contract');
 654
 655    dol_htmloutput_errors($mesg,'');
 656
 657    $soc = new Societe($db);
 658    $soc->fetch($socid);
 659
 660    $object->date_contrat = dol_now();
 661    if ($contratid) $result=$object->fetch($contratid);
 662
 663    $numct = $object->getNextNumRef($soc);
 664
 665    print '<form name="form_contract" action="'.$_SERVER["PHP_SELF"].'" method="post">';
 666    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 667
 668    print '<input type="hidden" name="action" value="add">';
 669    print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
 670    print '<input type="hidden" name="remise_percent" value="0">';
 671
 672    print '<table class="border" width="100%">';
 673
 674    // Ref
 675    print '<tr><td>'.$langs->trans("Ref").'</td>';
 676    print '<td><input type="text" maxlength="30" name="ref" size="20" value="'.$numct.'"></td></tr>';
 677
 678    // Customer
 679    print '<tr><td>'.$langs->trans("Customer").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
 680
 681    // Ligne info remises tiers
 682    print '<tr><td>'.$langs->trans('Discount').'</td><td>';
 683    if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
 684    else print $langs->trans("CompanyHasNoRelativeDiscount");
 685    $absolute_discount=$soc->getAvailableDiscounts();
 686    print '. ';
 687    if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
 688    else print $langs->trans("CompanyHasNoAbsoluteDiscount");
 689    print '.';
 690    print '</td></tr>';
 691
 692    // Commercial suivi
 693    print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").'</span></td><td>';
 694    print $form->select_users(GETPOST("commercial_suivi_id")?GETPOST("commercial_suivi_id"):$user->id,'commercial_suivi_id',1,'');
 695    print '</td></tr>';
 696
 697    // Commercial signature
 698    print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").'</span></td><td>';
 699    print $form->select_users(GETPOST("commercial_signature_id")?GETPOST("commercial_signature_id"):$user->id,'commercial_signature_id',1,'');
 700    print '</td></tr>';
 701
 702    print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td>';
 703    $form->select_date($datecontrat,'',0,0,'',"contrat");
 704    print "</td></tr>";
 705
 706    if (! empty($conf->projet->enabled))
 707    {
 708        print '<tr><td>'.$langs->trans("Project").'</td><td>';
 709        select_projects($soc->id,GETPOST("projectid"),"projectid");
 710        print "</td></tr>";
 711    }
 712
 713    print '<tr><td>'.$langs->trans("NotePublic").'</td><td valign="top">';
 714
 715    require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 716    $doleditor=new DolEditor('note_public', GETPOST('note_public'), '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
 717    print $doleditor->Create(1);
 718    /*
 719    print '<textarea name="note_public" wrap="soft" cols="70" rows="'.ROWS_3.'">';
 720    print GETPOST("note_public");
 721    print '</textarea></td></tr>';
 722	*/
 723
 724    if (! $user->societe_id)
 725    {
 726        print '<tr><td>'.$langs->trans("NotePrivate").'</td><td valign="top">';
 727        require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
 728        $doleditor=new DolEditor('note', GETPOST('note'), '', '100', 'dolibarr_notes', 'In', 1, true, true, ROWS_3, 70);
 729        print $doleditor->Create(1);
 730        /*
 731        print '<textarea name="note" wrap="soft" cols="70" rows="'.ROWS_3.'">';
 732        print GETPOST("note");
 733        print '</textarea>';*/
 734        print '</td></tr>';
 735    }
 736
 737    print "</table>\n";
 738
 739    print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
 740
 741    print "</form>\n";
 742
 743    dol_fiche_end();
 744}
 745elseif ($action == 'edit')
 746{
 747	/*
 748	 * Edition
 749	 */
 750	print_fiche_titre($langs->trans("EditContract"));
 751
 752	if ($contratid)
 753	{
 754		dol_fiche_head($head, $a, $langs->trans("AddContract"), 0, 'contract');
 755
 756	    dol_htmloutput_errors($mesg,'');
 757
 758	    $object->date_contrat = dol_now();
 759	    $object->fetch($contratid);
 760
 761	    $soc=new Societe($db);
 762	    $soc->fetch($object->socid);
 763
 764	    print '<form name="contrat" action="'.$_SERVER["PHP_SELF"].'" method="post">';
 765	    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 766
 767	    print '<input type="hidden" name="action" value="update">';
 768	    print '<input type="hidden" name="id" value="'.$object->id.'">'."\n";
 769	    print '<input type="hidden" name="remise_percent" value="0">';
 770
 771	    print '<table class="border" width="100%">';
 772
 773	    // Ref
 774	    print '<tr><td>'.$langs->trans("Ref").'</td>';
 775	    print '<td>'.$object->ref.'</td></tr>';
 776
 777	    // Customer
 778	    print '<tr><td>'.$langs->trans("Customer").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
 779
 780	    // Ligne info remises tiers
 781	    print '<tr><td>'.$langs->trans('Discount').'</td><td>';
 782	    if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
 783	    else print $langs->trans("CompanyHasNoRelativeDiscount");
 784	    $absolute_discount=$soc->getAvailableDiscounts();
 785	    print '. ';
 786	    if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie));
 787	    else print $langs->trans("CompanyHasNoAbsoluteDiscount");
 788	    print '.';
 789	    print '</td></tr>';
 790
 791	    // Commercial suivi
 792	    //print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").'</span></td><td>';
 793	    //print $form->select_users(GETPOST("commercial_suivi_id")?GETPOST("commercial_suivi_id"):$user->id,'commercial_suivi_id',1,'');
 794	    //print '</td></tr>';
 795
 796	    // Commercial signature
 797	    //print '<tr><td width="20%" nowrap><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").'</span></td><td>';
 798	    //print $form->select_users(GETPOST("commercial_signature_id")?GETPOST("commercial_signature_id"):$user->id,'commercial_signature_id',1,'');
 799	    //print '</td></tr>';
 800
 801	    print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td>';
 802	    $form->select_date($datecontrat,'',0,0,'',"contrat");
 803	    print "</td></tr>";
 804
 805	    // Other attributes
 806	    $parameters=array('colspan' => ' colspan="3"');
 807	    $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 808
 809	    print "</table>\n";
 810
 811	    print '<br><center><input type="submit" class="button" value="'.$langs->trans("Create").'"></center>';
 812
 813	    print "</form>\n";
 814
 815	    dol_fiche_end();
 816	}
 817}
 818else
 819/* *************************************************************************** */
 820/*                                                                             */
 821/* Mode vue et edition                                                         */
 822/*                                                                             */
 823/* *************************************************************************** */
 824{
 825    $now=dol_now();
 826
 827    if ($id > 0 || ! empty($ref))
 828    {
 829        $result=$object->fetch($id,$ref);
 830        if ($result > 0)
 831        {
 832            $result=$object->fetch_lines();
 833        }
 834        if ($result < 0)
 835        {
 836            dol_print_error($db,$object->error);
 837            exit;
 838        }
 839
 840        dol_htmloutput_errors($mesg,'');
 841
 842        $object->fetch_thirdparty();
 843
 844        $nbofservices=count($object->lines);
 845
 846        $author = new User($db);
 847        $author->fetch($object->user_author_id);
 848
 849        $commercial_signature = new User($db);
 850        $commercial_signature->fetch($object->commercial_signature_id);
 851
 852        $commercial_suivi = new User($db);
 853        $commercial_suivi->fetch($object->commercial_suivi_id);
 854
 855        $head = contract_prepare_head($object);
 856
 857        $hselected = 0;
 858
 859        dol_fiche_head($head, $hselected, $langs->trans("Contract"), 0, 'contract');
 860
 861
 862        /*
 863         * Confirmation de la suppression du contrat
 864         */
 865        if ($action == 'delete')
 866        {
 867            $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAContract"),$langs->trans("ConfirmDeleteAContract"),"confirm_delete",'',0,1);
 868            if ($ret == 'html') print '<br>';
 869        }
 870
 871        /*
 872         * Confirmation de la validation
 873         */
 874        if ($action == 'valid')
 875        {
 876            //$numfa = contrat_get_num($soc);
 877            $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("ValidateAContract"),$langs->trans("ConfirmValidateContract"),"confirm_valid",'',0,1);
 878            if ($ret == 'html') print '<br>';
 879        }
 880
 881        /*
 882         * Confirmation de la fermeture
 883         */
 884        if ($action == 'close')
 885        {
 886            $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("CloseAContract"),$langs->trans("ConfirmCloseContract"),"confirm_close",'',0,1);
 887            if ($ret == 'html') print '<br>';
 888        }
 889
 890        /*
 891         *   Contrat
 892         */
 893        if (! empty($object->brouillon) && $user->rights->contrat->creer)
 894        {
 895            print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">';
 896            print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
 897            print '<input type="hidden" name="action" value="setremise">';
 898        }
 899
 900        print '<table class="border" width="100%">';
 901
 902        $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/liste.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
 903
 904        // Ref du contrat
 905        print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
 906        print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
 907        print "</td></tr>";
 908
 909        // Customer
 910        print "<tr><td>".$langs->trans("Customer")."</td>";
 911        print '<td colspan="3">'.$object->thirdparty->getNomUrl(1).'</td></tr>';
 912
 913        // Ligne info remises tiers
 914        print '<tr><td>'.$langs->trans('Discount').'</td><td colspan="3">';
 915        if ($object->thirdparty->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_client);
 916        else print $langs->trans("CompanyHasNoRelativeDiscount");
 917        $absolute_discount=$object->thirdparty->getAvailableDiscounts();
 918        print '. ';
 919        if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->currency));
 920        else print $langs->trans("CompanyHasNoAbsoluteDiscount");
 921        print '.';
 922        print '</td></tr>';
 923
 924        // Statut contrat
 925        print '<tr><td>'.$langs->trans("Status").'</td><td colspan="3">';
 926        if ($object->statut==0) print $object->getLibStatut(2);
 927        else print $object->getLibStatut(4);
 928        print "</td></tr>";
 929
 930        // Date
 931        print '<tr><td>'.$langs->trans("Date").'</td>';
 932        print '<td colspan="3">'.dol_print_date($object->date_contrat,"dayhour")."</td></tr>\n";
 933
 934        // Other attributes
 935        $parameters=array('id'=>$object->id, 'colspan' => ' colspan="3"');
 936        $reshook=$hookmanager->executeHooks('showOutputFields',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 937
 938
 939        // Projet
 940        if (! empty($conf->projet->enabled))
 941        {
 942            $langs->load("projects");
 943            print '<tr><td>';
 944            print '<table width="100%" class="nobordernopadding"><tr><td>';
 945            print $langs->trans("Project");
 946            print '</td>';
 947            if ($action != "classify" && $user->rights->projet->creer) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->trans("SetProject")).'</a></td>';
 948            print '</tr></table>';
 949            print '</td><td colspan="3">';
 950            if ($action == "classify")
 951            {
 952                $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"projectid");
 953            }
 954            else
 955            {
 956                $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id,$object->socid,$object->fk_project,"none");
 957            }
 958            print "</td></tr>";
 959        }
 960
 961        // Other attributes
 962        $parameters=array('colspan' => ' colspan="3"');
 963        $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action);    // Note that $action and $object may have been modified by hook
 964
 965        print "</table>";
 966
 967        if (! empty($object->brouillon) && $user->rights->contrat->creer)
 968        {
 969            print '</form>';
 970        }
 971
 972        echo '<br>';
 973
 974        if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
 975        {
 976        	$blocname = 'contacts';
 977        	$title = $langs->trans('ContactsAddresses');
 978        	include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
 979        }
 980
 981        if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
 982        {
 983        	$blocname = 'notes';
 984        	$title = $langs->trans('Notes');
 985        	include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
 986        }
 987
 988
 989        $servicepos=(GETPOST('servicepos')?GETPOST('servicepos'):1); // FIXME : not used ?
 990        $colorb='666666';
 991
 992        $arrayothercontracts=$object->getListOfContracts('others');
 993
 994        /*
 995         * Lines of contracts
 996         */
 997        $productstatic=new Product($db);
 998
 999        // TODO move css and DAO
1000
1001        // Title line for service
1002        print '<table class="notopnoleft allwidth">';	// Array with (n*2)+1 lines
1003        $cursorline=1;
1004        while ($cursorline <= $nbofservices)
1005        {
1006            print '<tr height="16" '.$bc[false].'>';
1007            print '<td class="liste_titre" width="90" style="border-left: 1px solid #'.$colorb.'; border-top: 1px solid #'.$colorb.'; border-bottom: 1px solid #'.$colorb.';">';
1008            print $langs->trans("ServiceNb",$cursorline).'</td>';
1009
1010            print '<td class="tab" style="border-right: 1px solid #'.$colorb.'; border-top: 1px solid #'.$colorb.'; border-bottom: 1px solid #'.$colorb.';" rowspan="2">';
1011
1012            // Area with common detail of line
1013            print '<table class="notopnoleft" width="100%">';
1014
1015            $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.description, cd.price_ht, cd.qty,";
1016            $sql.= " cd.tva_tx, cd.remise_percent, cd.info_bits, cd.subprice,";
1017            $sql.= " cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,";
1018            $sql.= " cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,";
1019            $sql.= " cd.commentaire as comment,";
1020            $sql.= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype";
1021            $sql.= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
1022            $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
1023            $sql.= " WHERE cd.rowid = ".$object->lines[$cursorline-1]->id;
1024
1025            $result = $db->query($sql);
1026            if ($result)
1027            {
1028                $total = 0;
1029
1030                print '<tr class="liste_titre">';
1031                print '<td>'.$langs->trans("Service").'</td>';
1032                print '<td width="50" align="center">'.$langs->trans("VAT").'</td>';
1033                print '<td width="50" align="right">'.$langs->trans("PriceUHT").'</td>';
1034                print '<td width="30" align="center">'.$langs->trans("Qty").'</td>';
1035                print '<td width="50" align="right">'.$langs->trans("ReductionShort").'</td>';
1036                print '<td width="30">&nbsp;</td>';
1037                print "</tr>\n";
1038
1039                $var=true;
1040
1041                $objp = $db->fetch_object($result);
1042
1043                $var=!$var;
1044
1045                if ($action != 'editline' || GETPOST('rowid') != $objp->rowid)
1046                {
1047                    print '<tr '.$bc[$var].' valign="top">';
1048                    // Libelle
1049                    if ($objp->fk_product > 0)
1050                    {
1051                        print '<td>';
1052                        $productstatic->id=$objp->fk_product;
1053                        $productstatic->type=$objp->ptype;
1054                        $productstatic->ref=$objp->pref;
1055                        print $productstatic->getNomUrl(1,'',20);
1056                        print $objp->label?' - '.dol_trunc($objp->label,16):'';
1057                        if ($objp->description) print '<br>'.dol_nl2br($objp->description);
1058                        print '</td>';
1059                    }
1060                    else
1061                    {
1062                        print "<td>".nl2br($objp->description)."</td>\n";
1063                    }
1064                    // TVA
1065                    print '<td align="center">'.vatrate($objp->tva_tx,'%',$objp->info_bits).'</td>';
1066                    // Prix
1067                    print '<td align="right">'.price($objp->subprice)."</td>\n";
1068                    // Quantite
1069                    print '<td align="center">'.$objp->qty.'</td>';
1070                    // Remise
1071                    if ($objp->remise_percent > 0)
1072                    {
1073                        print '<td align="right">'.$objp->remise_percent."%</td>\n";
1074                    }
1075                    else
1076                    {
1077                        print '<td>&nbsp;</td>';
1078                    }
1079                    // Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme)
1080                    print '<td align="right" nowrap="nowrap">';
1081                    if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0))
1082                    {
1083                        print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=move&amp;rowid='.$objp->rowid.'">';
1084                        print img_picto($langs->trans("MoveToAnotherContract"),'uparrow');
1085                        print '</a>';
1086                    }
1087                    else {
1088                        print '&nbsp;';
1089                    }
1090                    if ($user->rights->contrat->creer && ($object->statut >= 0))
1091                    {
1092                        print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=editline&amp;rowid='.$objp->rowid.'">';
1093                        print img_edit();
1094                        print '</a>';
1095                    }
1096                    else {
1097                        print '&nbsp;';
1098                    }
1099                    if ( $user->rights->contrat->creer && ($object->statut >= 0))
1100                    {
1101                        print '&nbsp;';
1102                        print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=deleteline&amp;rowid='.$objp->rowid.'">';
1103                        print img_delete();
1104                        print '</a>';
1105                    }
1106                    print '</td>';
1107
1108                    print "</tr>\n";
1109
1110                    // Dates de en service prevues et effectives
1111                    if ($objp->subprice >= 0)
1112                    {
1113                        print '<tr '.$bc[$var].'>';
1114                        print '<td colspan="6">';
1115
1116                        // Date planned
1117                        print $langs->trans("DateStartPlanned").': ';
1118                        if ($objp->date_debut)
1119                        {
1120                            print dol_print_date($db->jdate($objp->date_debut));
1121                            // Warning si date prevu passee et pas en service
1122                            if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { print " ".img_warning($langs->trans("Late")); }
1123                        }
1124                        else print $langs->trans("Unknown");
1125                        print ' &nbsp;-&nbsp; ';
1126                        print $langs->trans("DateEndPlanned").': ';
1127                        if ($objp->date_fin)
1128                        {
1129                            print dol_print_date($db->jdate($objp->date_fin));
1130                            if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { print " ".img_warning($langs->trans("Late")); }
1131                        }
1132                        else print $langs->trans("Unknown");
1133
1134                        print '</td>';
1135                        print '</tr>';
1136                    }
1137                }
1138                // Ligne en mode update
1139                else
1140                {
1141                    print '<form name="update" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
1142                    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
1143                    print '<input type="hidden" name="action" value="updateligne">';
1144                    print '<input type="hidden" name="elrowid" value="'.GETPOST('rowid').'">';
1145                    // Ligne carac
1146                    print "<tr $bc[$var]>";
1147                    print '<td>';
1148                    if ($objp->fk_product)
1149                    {
1150                        $productstatic->id=$objp->fk_product;
1151                        $productstatic->type=$objp->ptype;
1152                        $productstatic->ref=$objp->pref;
1153                        print $productstatic->getNomUrl(1,'',20);
1154                        print $objp->label?' - '.dol_trunc($objp->label,16):'';
1155                        print '<br>';
1156                    }
1157                    else
1158                    {
1159                        print $objp->label?$objp->label.'<br>':'';
1160                    }
1161                    print '<textarea name="eldesc" cols="70" rows="1">'.$objp->description.'</textarea></td>';
1162                    print '<td align="right">';
1163                    print $form->load_tva("eltva_tx",$objp->tva_tx,$mysoc,$object->thirdparty);
1164                    print '</td>';
1165                    print '<td align="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).'"></td>';
1166                    print '<td align="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.'"></td>';
1167                    print '<td align="right" nowrap="nowrap"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.'">%</td>';
1168                    print '<td align="center" rowspan="2" valign="middle"><input type="submit" class="button" name="save" value="'.$langs->trans("Modify").'">';
1169                    print '<br><input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
1170                    print '</td>';
1171                    // Ligne dates prevues
1172                    print "<tr $bc[$var]>";
1173                    print '<td colspan="5">';
1174                    print $langs->trans("DateStartPlanned").' ';
1175                    $form->select_date($db->jdate($objp->date_debut),"date_start_update",$usehm,$usehm,($db->jdate($objp->date_debut)>0?0:1),"update");
1176                    print '<br>'.$langs->trans("DateEndPlanned").' ';
1177                    $form->select_date($db->jdate($objp->date_fin),"date_end_update",$usehm,$usehm,($db->jdate($objp->date_fin)>0?0:1),"update");
1178                    print '</td>';
1179                    print '</tr>';
1180
1181                    print "</form>\n";
1182                }
1183
1184                $db->free($result);
1185            }
1186            else
1187            {
1188                dol_print_error($db);
1189            }
1190
1191            if ($object->statut > 0)
1192            {
1193                print '<tr '.$bc[false].'>';
1194                print '<td colspan="6"><hr></td>';
1195                print "</tr>\n";
1196            }
1197
1198            print "</table>";
1199
1200
1201            /*
1202             * Confirmation to delete service line of contract
1203             */
1204            if ($action == 'deleteline' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid'))
1205            {
1206                $ret=$form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("DeleteContractLine"),$langs->trans("ConfirmDeleteContractLine"),"confirm_deleteline",'',0,1);
1207                if ($ret == 'html') print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
1208            }
1209
1210            /*
1211             * Confirmation to move service toward another contract
1212             */
1213            if ($action == 'move' && ! $_REQUEST["cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline-1]->id == GETPOST('rowid'))
1214            {
1215                $arraycontractid=array();
1216                foreach($arrayothercontracts as $contractcursor)
1217                {
1218                    $arraycontractid[$contractcursor->id]=$contractcursor->ref;
1219                }
1220                //var_dump($arraycontractid);
1221                // Cree un tableau formulaire
1222                $formquestion=array(
1223				'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"),
1224                array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid));
1225
1226                $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'),$langs->trans("MoveToAnotherContract"),$langs->trans("ConfirmMoveToAnotherContract"),"confirm_move",$formquestion);
1227                print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
1228            }
1229
1230            /*
1231             * Confirmation de la validation activation
1232             */
1233            if ($action == 'active' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne'))
1234            {
1235                $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
1236                $dateactend   = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
1237                $comment      = GETPOST('comment');
1238                $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1);
1239                print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
1240            }
1241
1242            /*
1243             * Confirmation de la validation fermeture
1244             */
1245            if ($action == 'closeline' && ! $_REQUEST["cancel"] && $user->rights->contrat->activer && $object->lines[$cursorline-1]->id == GETPOST('ligne'))
1246            {
1247                $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
1248                $dateactend   = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
1249                $comment      = GETPOST('comment');
1250                $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1);
1251                print '<table class="notopnoleftnoright" width="100%"><tr '.$bc[false].' height="6"><td></td></tr></table>';
1252            }
1253
1254
1255            // Area with status and activation info of line
1256            if ($object->statut > 0)
1257            {
1258                print '<table class="notopnoleft" width="100%">';
1259
1260                print '<tr '.$bc[false].'>';
1261                print '<td>'.$langs->trans("ServiceStatus").': '.$object->lines[$cursorline-1]->getLibStatut(4).'</td>';
1262                print '<td width="30" align="right">';
1263                if ($user->societe_id == 0)
1264                {
1265                    if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline')
1266                    {
1267                        $tmpaction='activateline';
1268                        if ($objp->statut == 4) $tmpaction='unactivateline';
1269                        print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline-1]->id.'&amp;action='.$tmpaction.'">';
1270                        print img_edit();
1271                        print '</a>';
1272                    }
1273                }
1274        

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