dolibarr  18.0.0-alpha
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
6  * Copyright (C) 2010-2017 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2013 Christophe Battarel <christophe.battarel@altairis.fr>
8  * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
9  * Copyright (C) 2014-2020 Ferran Marcet <fmarcet@2byte.es>
10  * Copyright (C) 2014-2016 Marcos García <marcosgdf@gmail.com>
11  * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
12  * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
13  *
14  * This program is free software; you can redistribute it and/or modify
15  * it under the terms of the GNU General Public License as published by
16  * the Free Software Foundation; either version 3 of the License, or
17  * (at your option) any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * You should have received a copy of the GNU General Public License
25  * along with this program. If not, see <https://www.gnu.org/licenses/>.
26  */
27 
34 require "../main.inc.php";
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/lib/contract.lib.php';
38 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
44 if (isModEnabled("propal")) {
45  require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
46 }
47 if (isModEnabled('project')) {
48  require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
49  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
50 }
51 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
52 
53 // Load translation files required by the page
54 $langs->loadLangs(array("contracts", "orders", "companies", "bills", "products", 'compta'));
55 
56 $action = GETPOST('action', 'aZ09');
57 $confirm = GETPOST('confirm', 'alpha');
58 $cancel = GETPOST('cancel', 'alpha');
59 
60 $socid = GETPOST('socid', 'int');
61 $id = GETPOST('id', 'int');
62 $ref = GETPOST('ref', 'alpha');
63 $origin = GETPOST('origin', 'alpha');
64 $originid = GETPOST('originid', 'int');
65 
66 $datecontrat = '';
67 $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
68 
69 // Security check
70 if ($user->socid) {
71  $socid = $user->socid;
72 }
73 $result = restrictedArea($user, 'contrat', $id);
74 
75 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
76 $hookmanager->initHooks(array('contractcard', 'globalcard'));
77 
78 $object = new Contrat($db);
79 $extrafields = new ExtraFields($db);
80 
81 // Load object
82 if ($id > 0 || !empty($ref) && $action != 'add') {
83  $ret = $object->fetch($id, $ref);
84  if ($ret > 0) {
85  $ret = $object->fetch_thirdparty();
86  }
87  if ($ret < 0) {
88  dol_print_error('', $object->error);
89  }
90 }
91 
92 // fetch optionals attributes and labels
93 $extrafields->fetch_name_optionals_label($object->table_element);
94 
95 // fetch optionals attributes lines and labels
96 $extralabelslines = $extrafields->fetch_name_optionals_label($object->table_element_line);
97 
98 $permissionnote = $user->rights->contrat->creer; // Used by the include of actions_setnotes.inc.php
99 $permissiondellink = $user->rights->contrat->creer; // Used by the include of actions_dellink.inc.php
100 $permissiontodelete = ($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer;
101 $permissiontoadd = $user->rights->contrat->creer; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
102 $permissiontoedit = $permissiontoadd;
103 $error = 0;
104 
105 
106 /*
107  * Actions
108  */
109 
110 $parameters = array('socid' => $socid);
111 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
112 if ($reshook < 0) {
113  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
114 }
115 if (empty($reshook)) {
116  $backurlforlist = DOL_URL_ROOT.'/contrat/list.php';
117 
118  if (empty($backtopage) || ($cancel && empty($id))) {
119  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
120  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
121  $backtopage = $backurlforlist;
122  } else {
123  $backtopage = DOL_URL_ROOT.'/contrat/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
124  }
125  }
126  }
127 
128  if ($cancel) {
129  if (!empty($backtopageforcancel)) {
130  header("Location: ".$backtopageforcancel);
131  exit;
132  } elseif (!empty($backtopage)) {
133  header("Location: ".$backtopage);
134  exit;
135  }
136  $action = '';
137  }
138 
139  include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
140 
141  include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
142 
143  include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once
144 
145  if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) {
146  $date_start = '';
147  $date_end = '';
148  if (GETPOST('startmonth') && GETPOST('startday') && GETPOST('startyear')) {
149  $date_start = dol_mktime(GETPOST('starthour'), GETPOST('startmin'), 0, GETPOST('startmonth'), GETPOST('startday'), GETPOST('startyear'));
150  }
151  if (GETPOST('endmonth') && GETPOST('endday') && GETPOST('endyear')) {
152  $date_end = dol_mktime(GETPOST('endhour'), GETPOST('endmin'), 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
153  }
154 
155  $result = $object->active_line($user, GETPOST('ligne', 'int'), $date_start, $date_end, GETPOST('comment'));
156 
157  if ($result > 0) {
158  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
159  exit;
160  } else {
161  setEventMessages($object->error, $object->errors, 'errors');
162  }
163  } elseif ($action == 'confirm_closeline' && $confirm == 'yes' && $user->rights->contrat->activer) {
164  $date_end = '';
165  if (GETPOST('endmonth') && GETPOST('endday') && GETPOST('endyear')) {
166  $date_end = dol_mktime(GETPOST('endhour'), GETPOST('endmin'), 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
167  }
168  if (!$date_end) {
169  $error++;
170  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEnd")), null, 'errors');
171  }
172  if (!$error) {
173  $result = $object->close_line($user, GETPOST('ligne', 'int'), $date_end, urldecode(GETPOST('comment')));
174  if ($result > 0) {
175  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
176  exit;
177  } else {
178  setEventMessages($object->error, $object->errors, 'errors');
179  }
180  }
181  }
182 
183  // Si ajout champ produit predefini
184  if (GETPOST('mode') == 'predefined') {
185  $date_start = '';
186  $date_end = '';
187  if (GETPOST('date_startmonth') && GETPOST('date_startday') && GETPOST('date_startyear')) {
188  $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), 0, GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
189  }
190  if (GETPOST('date_endmonth') && GETPOST('date_endday') && GETPOST('date_endyear')) {
191  $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
192  }
193  }
194 
195  // Param dates
196  $date_start_update = '';
197  $date_end_update = '';
198  $date_start_real_update = '';
199  $date_end_real_update = '';
200  if (GETPOST('date_start_updatemonth') && GETPOST('date_start_updateday') && GETPOST('date_start_updateyear')) {
201  $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'));
202  }
203  if (GETPOST('date_end_updatemonth') && GETPOST('date_end_updateday') && GETPOST('date_end_updateyear')) {
204  $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'));
205  }
206  if (GETPOST('date_start_real_updatemonth') && GETPOST('date_start_real_updateday') && GETPOST('date_start_real_updateyear')) {
207  $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'));
208  }
209  if (GETPOST('date_end_real_updatemonth') && GETPOST('date_end_real_updateday') && GETPOST('date_end_real_updateyear')) {
210  $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'));
211  }
212  if (GETPOST('remonth') && GETPOST('reday') && GETPOST('reyear')) {
213  $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
214  }
215 
216  // Add contract
217  if ($action == 'add' && $user->hasRight('contrat', 'creer')) {
218  // Check
219  if (empty($datecontrat)) {
220  $error++;
221  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
222  $action = 'create';
223  }
224 
225  if ($socid < 1) {
226  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors');
227  $action = 'create';
228  $error++;
229  }
230 
231  // Fill array 'array_options' with data from add form
232  $ret = $extrafields->setOptionalsFromPost(null, $object);
233  if ($ret < 0) {
234  $error++;
235  $action = 'create';
236  }
237 
238  if (!$error) {
239  $object->socid = $socid;
240  $object->date_contrat = $datecontrat;
241 
242  $object->commercial_suivi_id = GETPOST('commercial_suivi_id', 'int');
243  $object->commercial_signature_id = GETPOST('commercial_signature_id', 'int');
244 
245  $object->note_private = GETPOST('note_private', 'alpha');
246  $object->note_public = GETPOST('note_public', 'alpha');
247  $object->fk_project = GETPOST('projectid', 'int');
248  $object->remise_percent = price2num(GETPOST('remise_percent'), '', 2);
249  $object->ref = GETPOST('ref', 'alpha');
250  $object->ref_customer = GETPOST('ref_customer', 'alpha');
251  $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
252 
253  // If creation from another object of another module (Example: origin=propal, originid=1)
254  if (!empty($origin) && !empty($originid)) {
255  // Parse element/subelement (ex: project_task)
256  $element = $subelement = $origin;
257  if (preg_match('/^([^_]+)_([^_]+)/i', $origin, $regs)) {
258  $element = $regs[1];
259  $subelement = $regs[2];
260  }
261 
262  // For compatibility
263  if ($element == 'order') {
264  $element = $subelement = 'commande';
265  }
266  if ($element == 'propal') {
267  $element = 'comm/propal'; $subelement = 'propal';
268  }
269  if ($element == 'invoice' || $element == 'facture') {
270  $element = 'compta/facture';
271  $subelement = 'facture';
272  }
273 
274  $object->origin = $origin;
275  $object->origin_id = $originid;
276 
277  // Possibility to add external linked objects with hooks
278  $object->linked_objects[$object->origin] = $object->origin_id;
279  if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
280  $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
281  }
282 
283  $id = $object->create($user);
284  if ($id > 0) {
285  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
286 
287  $classname = ucfirst($subelement);
288  $srcobject = new $classname($db);
289 
290  dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
291  $result = $srcobject->fetch($object->origin_id);
292  if ($result > 0) {
293  $srcobject->fetch_thirdparty();
294  $lines = $srcobject->lines;
295  if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
296  $srcobject->fetch_lines();
297  $lines = $srcobject->lines;
298  }
299 
300  $fk_parent_line = 0;
301  $num = count($lines);
302 
303  for ($i = 0; $i < $num; $i++) {
304  $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
305 
306  if ($product_type == 1 || (!empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0, 1)))) { // TODO Exclude also deee
307  // service prédéfini
308  if ($lines[$i]->fk_product > 0) {
309  $product_static = new Product($db);
310 
311  // Define output language
312  if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
313  $prod = new Product($db);
314  $prod->id = $lines[$i]->fk_product;
315  $prod->getMultiLangs();
316 
317  $outputlangs = $langs;
318  $newlang = '';
319  if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
320  $newlang = GETPOST('lang_id', 'aZ09');
321  }
322  if (empty($newlang)) {
323  $newlang = $srcobject->thirdparty->default_lang;
324  }
325  if (!empty($newlang)) {
326  $outputlangs = new Translate("", $conf);
327  $outputlangs->setDefaultLang($newlang);
328  }
329 
330  $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
331  } else {
332  $label = $lines[$i]->product_label;
333  }
334  $desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->libelle) ?dol_htmlentitiesbr($lines[$i]->desc) : '';
335  } else {
336  $desc = dol_htmlentitiesbr($lines[$i]->desc);
337  }
338 
339  // Extrafields
340  $array_options = array();
341  // For avoid conflicts if trigger used
342  if (method_exists($lines[$i], 'fetch_optionals')) {
343  $lines[$i]->fetch_optionals();
344  $array_options = $lines[$i]->array_options;
345  }
346 
347  $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx.' ('.$lines[$i]->vat_src_code.')' : $lines[$i]->tva_tx;
348 
349  // View third's localtaxes for now
350  $localtax1_tx = get_localtax($txtva, 1, $object->thirdparty);
351  $localtax2_tx = get_localtax($txtva, 2, $object->thirdparty);
352 
353  $result = $object->addline(
354  $desc,
355  $lines[$i]->subprice,
356  $lines[$i]->qty,
357  $txtva,
358  $localtax1_tx,
359  $localtax2_tx,
360  $lines[$i]->fk_product,
361  $lines[$i]->remise_percent,
362  $lines[$i]->date_start,
363  $lines[$i]->date_end,
364  'HT',
365  0,
366  $lines[$i]->info_bits,
367  $lines[$i]->fk_fournprice,
368  $lines[$i]->pa_ht,
369  $array_options,
370  $lines[$i]->fk_unit,
371  $num+1
372  );
373 
374  if ($result < 0) {
375  $error++;
376  break;
377  }
378  }
379  }
380  } else {
381  setEventMessages($srcobject->error, $srcobject->errors, 'errors');
382  $error++;
383  }
384 
385  // Hooks
386  $parameters = array('objFrom' => $srcobject);
387  $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been
388  // modified by hook
389  if ($reshook < 0) {
390  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
391  $error++;
392  }
393  } else {
394  setEventMessages($object->error, $object->errors, 'errors');
395  $error++;
396  }
397  if ($error) {
398  $action = 'create';
399  }
400  } else {
401  $result = $object->create($user);
402  if ($result > 0) {
403  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
404  exit;
405  } else {
406  setEventMessages($object->error, $object->errors, 'errors');
407  }
408  $action = 'create';
409  }
410  }
411  } elseif ($action == 'classin' && $user->hasRight('contrat', 'creer')) {
412  $object->setProject(GETPOST('projectid'));
413  } elseif ($action == 'addline' && $user->hasRight('contrat', 'creer')) {
414  // Add a new line
415  // Set if we used free entry or predefined product
416  $predef = '';
417  $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
418 
419  $price_ht = '';
420  $price_ht_devise = '';
421  $price_ttc = '';
422  $price_ttc_devise = '';
423 
424  $rang = count($object->lines) + 1;
425 
426  if (GETPOST('price_ht') !== '') {
427  $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
428  }
429  if (GETPOST('multicurrency_price_ht') !== '') {
430  $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
431  }
432  if (GETPOST('price_ttc') !== '') {
433  $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
434  }
435  if (GETPOST('multicurrency_price_ttc') !== '') {
436  $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
437  }
438 
439  if (GETPOST('prod_entry_mode', 'alpha') == 'free') {
440  $idprod = 0;
441  } else {
442  $idprod = GETPOST('idprod', 'int');
443  }
444 
445  $tva_tx = GETPOST('tva_tx', 'alpha');
446 
447  $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
448  $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef), 2) : 0);
449  if (empty($remise_percent)) {
450  $remise_percent = 0;
451  }
452 
453  if ($qty == '') {
454  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors');
455  $error++;
456  }
457  if (GETPOST('prod_entry_mode', 'alpha') == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
458  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors');
459  $error++;
460  }
461 
462  $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
463  $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
464  if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
465  setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');
466  $error++;
467  }
468 
469  // Extrafields
470  $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
471  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
472  // Unset extrafield
473  if (is_array($extralabelsline)) {
474  // Get extra fields
475  foreach ($extralabelsline as $key => $value) {
476  unset($_POST["options_".$key]);
477  }
478  }
479 
480  if (!$error) {
481  // Clean parameters
482  $date_start = dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year'));
483  $date_end = dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year'));
484 
485  // Ecrase $tva_tx par celui du produit. TODO Remove this once vat selection is open
486  // Get and check minimum price
487  if ($idprod > 0) {
488  $prod = new Product($db);
489  $prod->fetch($idprod);
490 
491  // Update if prices fields are defined
492  /*$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
493  $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
494  if (empty($tva_tx)) {
495  $tva_npr = 0;
496  }*/
497 
498  $price_min = $prod->price_min;
499  $price_min_ttc = $prod->price_min_ttc;
500 
501  // On defini prix unitaire
502  if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) {
503  $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
504  $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
505  } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
506  // If price per customer
507  require_once DOL_DOCUMENT_ROOT.'/product/class/productcustomerprice.class.php';
508 
509  $prodcustprice = new Productcustomerprice($db);
510 
511  $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
512 
513  $result = $prodcustprice->fetchAll('', '', 0, 0, $filter);
514  if ($result) {
515  if (count($prodcustprice->lines) > 0) {
516  $price_min = price($prodcustprice->lines[0]->price_min);
517  $price_min_ttc = price($prodcustprice->lines[0]->price_min_ttc);
518  /*$tva_tx = $prodcustprice->lines[0]->tva_tx;
519  if ($prodcustprice->lines[0]->default_vat_code && !preg_match('/\(.*\)/', $tva_tx)) {
520  $tva_tx .= ' ('.$prodcustprice->lines[0]->default_vat_code.')';
521  }
522  $tva_npr = $prodcustprice->lines[0]->recuperableonly;
523  if (empty($tva_tx)) {
524  $tva_npr = 0;
525  }*/
526  }
527  }
528  }
529 
530  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
531  $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx));
532 
533  // Set unit price to use
534  if (!empty($price_ht) || $price_ht === '0') {
535  $pu_ht = price2num($price_ht, 'MU');
536  $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU');
537  $price_base_type = 'HT';
538  } elseif (!empty($price_ttc) || $price_ttc === '0') {
539  $pu_ttc = price2num($price_ttc, 'MU');
540  $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU');
541  $price_base_type = 'TTC';
542  }
543 
544  $desc = $prod->description;
545 
546  //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
547  if ($product_desc == $desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
548  $product_desc = '';
549  }
550 
551  if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
552  $desc = $product_desc;
553  } else {
554  $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
555  }
556 
557  $fk_unit = $prod->fk_unit;
558  } else {
559  $pu_ht = price2num($price_ht, 'MU');
560  $pu_ttc = price2num($price_ttc, 'MU');
561  $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
562  if (empty($tva_tx)) {
563  $tva_npr = 0;
564  }
565  $tva_tx = str_replace('*', '', $tva_tx);
566  $desc = $product_desc;
567  $fk_unit = GETPOST('units', 'alpha');
568  $pu_ht_devise = price2num($price_ht_devise, 'MU');
569  $pu_ttc_devise = price2num($price_ttc_devise, 'MU');
570 
571  $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx));
572 
573  // Set unit price to use
574  if (!empty($price_ht) || $price_ht === '0') {
575  $pu_ht = price2num($price_ht, 'MU');
576  $pu_ttc = price2num($pu_ht * (1 + ((float) $tmpvat / 100)), 'MU');
577  $price_base_type = 'HT';
578  } elseif (!empty($price_ttc) || $price_ttc === '0') {
579  $pu_ttc = price2num($price_ttc, 'MU');
580  $pu_ht = price2num($pu_ttc / (1 + ((float) $tmpvat / 100)), 'MU');
581  $price_base_type = 'TTC';
582  }
583  }
584 
585  $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
586  $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
587 
588  // ajout prix achat
589  $fk_fournprice = GETPOST('fournprice');
590  if (GETPOST('buying_price')) {
591  $pa_ht = GETPOST('buying_price');
592  } else {
593  $pa_ht = null;
594  }
595 
596  $info_bits = 0;
597  if ($tva_npr) {
598  $info_bits |= 0x01;
599  }
600 
601  if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance))
602  || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) {
603  $object->error = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
604  $result = -1;
605  } else {
606  // Insert line
607  $result = $object->addline(
608  $desc,
609  $pu_ht,
610  $qty,
611  $tva_tx,
612  $localtax1_tx,
613  $localtax2_tx,
614  $idprod,
615  $remise_percent,
616  $date_start,
617  $date_end,
618  $price_base_type,
619  $pu_ttc,
620  $info_bits,
621  $fk_fournprice,
622  $pa_ht,
623  $array_options,
624  $fk_unit,
625  $rang
626  );
627  }
628 
629  if ($result > 0) {
630  // Define output language
631  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) { // No generation if default type not defined
632  $outputlangs = $langs;
633  $newlang = '';
634  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
635  $newlang = GETPOST('lang_id', 'aZ09');
636  }
637  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
638  $newlang = $object->thirdparty->default_lang;
639  }
640  if (!empty($newlang)) {
641  $outputlangs = new Translate("", $conf);
642  $outputlangs->setDefaultLang($newlang);
643  }
644 
645  $ret = $object->fetch($id); // Reload to get new records
646 
647  $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
648  }
649 
650  unset($_POST['prod_entry_mode']);
651 
652  unset($_POST['qty']);
653  unset($_POST['type']);
654  unset($_POST['remise_percent']);
655  unset($_POST['price_ht']);
656  unset($_POST['multicurrency_price_ht']);
657  unset($_POST['price_ttc']);
658  unset($_POST['tva_tx']);
659  unset($_POST['product_ref']);
660  unset($_POST['product_label']);
661  unset($_POST['product_desc']);
662  unset($_POST['fournprice']);
663  unset($_POST['buying_price']);
664  unset($_POST['np_marginRate']);
665  unset($_POST['np_markRate']);
666  unset($_POST['dp_desc']);
667  unset($_POST['idprod']);
668 
669  unset($_POST['date_starthour']);
670  unset($_POST['date_startmin']);
671  unset($_POST['date_startsec']);
672  unset($_POST['date_startday']);
673  unset($_POST['date_startmonth']);
674  unset($_POST['date_startyear']);
675  unset($_POST['date_endhour']);
676  unset($_POST['date_endmin']);
677  unset($_POST['date_endsec']);
678  unset($_POST['date_endday']);
679  unset($_POST['date_endmonth']);
680  unset($_POST['date_endyear']);
681  } else {
682  setEventMessages($object->error, $object->errors, 'errors');
683  }
684  }
685  } elseif ($action == 'updateline' && $user->hasRight('contrat', 'creer') && !GETPOST('cancel', 'alpha')) {
686  $error = 0;
687  $predef = '';
688 
689  if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
690  setEventMessages($langs->trans("Error").': '.$langs->trans("DateStartPlanned").' > '.$langs->trans("DateEndPlanned"), null, 'errors');
691  $action = 'editline';
692  $_GET['rowid'] = GETPOST('elrowid');
693  $error++;
694  }
695 
696  if (!$error) {
697  $objectline = new ContratLigne($db);
698  if ($objectline->fetch(GETPOST('elrowid', 'int')) < 0) {
699  setEventMessages($objectline->error, $objectline->errors, 'errors');
700  $error++;
701  }
702  $objectline->fetch_optionals();
703 
704  $objectline->oldcopy = dol_clone($objectline);
705  }
706 
707  $db->begin();
708 
709  if (!$error) {
710  if ($date_start_real_update == '') {
711  $date_start_real_update = $objectline->date_start_real;
712  }
713  if ($date_end_real_update == '') {
714  $date_end_real_update = $objectline->date_end_real;
715  }
716 
717  $vat_rate = GETPOST('eltva_tx', 'alpha');
718  // Define info_bits
719  $info_bits = 0;
720  if (preg_match('/\*/', $vat_rate)) {
721  $info_bits |= 0x01;
722  }
723 
724  // Define vat_rate
725  $vat_rate = str_replace('*', '', $vat_rate);
726  $localtax1_tx = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
727  $localtax2_tx = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
728 
729  $txtva = $vat_rate;
730 
731  // Clean vat code
732  $reg = array();
733  $vat_src_code = '';
734  if (preg_match('/\((.*)\)/', $txtva, $reg)) {
735  $vat_src_code = $reg[1];
736  $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
737  }
738 
739  // ajout prix d'achat
740  if (GETPOST('buying_price')) {
741  $pa_ht = price2num(GETPOST('buying_price'), '', 2);
742  } else {
743  $pa_ht = null;
744  }
745 
746  $fk_unit = GETPOST('unit', 'alpha');
747 
748  $objectline->fk_product = GETPOST('idprod', 'int');
749  $objectline->description = GETPOST('product_desc', 'restricthtml');
750  $objectline->price_ht = price2num(GETPOST('elprice'), 'MU');
751  $objectline->subprice = price2num(GETPOST('elprice'), 'MU');
752  $objectline->qty = price2num(GETPOST('elqty'), 'MS');
753  $objectline->remise_percent = price2num(GETPOST('elremise_percent'), 2);
754  $objectline->tva_tx = ($txtva ? $txtva : 0); // Field may be disabled, so we use vat rate 0
755  $objectline->vat_src_code = $vat_src_code;
756  $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
757  $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
758  $objectline->date_start = $date_start_update;
759  $objectline->date_start_real = $date_start_real_update;
760  $objectline->date_end = $date_end_update;
761  $objectline->date_end_real = $date_end_real_update;
762  $objectline->fk_user_cloture = $user->id;
763  //$objectline->fk_fournprice = $fk_fournprice;
764  $objectline->pa_ht = $pa_ht;
765  $objectline->rang = $objectline->rang;
766 
767  if ($fk_unit > 0) {
768  $objectline->fk_unit = GETPOST('unit');
769  } else {
770  $objectline->fk_unit = null;
771  }
772 
773  // Extrafields
774  $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
775  $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
776 
777  if (is_array($array_options) && count($array_options) > 0) {
778  // We replace values in this->line->array_options only for entries defined into $array_options
779  foreach ($array_options as $key => $value) {
780  $objectline->array_options[$key] = $array_options[$key];
781  }
782  }
783 
784  // TODO verifier price_min si fk_product et multiprix
785 
786  $result = $objectline->update($user);
787  if ($result < 0) {
788  $error++;
789  setEventMessages($objectline->error, $objectline->errors, 'errors');
790  }
791  }
792 
793  if (!$error) {
794  $db->commit();
795  } else {
796  $db->rollback();
797  }
798  } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {
799  $result = $object->deleteline(GETPOST('lineid', 'int'), $user);
800 
801  if ($result >= 0) {
802  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
803  exit;
804  } else {
805  setEventMessages($object->error, $object->errors, 'errors');
806  }
807  } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {
808  $result = $object->validate($user);
809 
810  if ($result > 0) {
811  // Define output language
812  if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
813  $outputlangs = $langs;
814  $newlang = '';
815  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
816  $newlang = GETPOST('lang_id', 'aZ09');
817  }
818  if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
819  $newlang = $object->thirdparty->default_lang;
820  }
821  if (!empty($newlang)) {
822  $outputlangs = new Translate("", $conf);
823  $outputlangs->setDefaultLang($newlang);
824  }
825  $model = $object->model_pdf;
826  $ret = $object->fetch($id); // Reload to get new records
827 
828  $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
829  }
830  } else {
831  setEventMessages($object->error, $object->errors, 'errors');
832  }
833  } elseif ($action == 'reopen' && $user->hasRight('contrat', 'creer')) {
834  $result = $object->reopen($user);
835  if ($result < 0) {
836  setEventMessages($object->error, $object->errors, 'errors');
837  }
838  } elseif ($action == 'confirm_close' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {
839  // Close all lines
840  $result = $object->closeAll($user);
841  if ($result < 0) {
842  setEventMessages($object->error, $object->errors, 'errors');
843  }
844  } elseif ($action == 'confirm_activate' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {
845  $date_start = dol_mktime(12, 0, 0, GETPOST('d_startmonth'), GETPOST('d_startday'), GETPOST('d_startyear'));
846  $date_end = dol_mktime(12, 0, 0, GETPOST('d_endmonth'), GETPOST('d_endday'), GETPOST('d_endyear'));
847  $comment = GETPOST('comment', 'alpha');
848  $result = $object->activateAll($user, $date_start, 0, $comment, $date_end);
849  if ($result < 0) {
850  setEventMessages($object->error, $object->errors, 'errors');
851  }
852  } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer) {
853  $result = $object->delete($user);
854  if ($result >= 0) {
855  header("Location: list.php?restore_lastsearch_values=1");
856  return;
857  } else {
858  setEventMessages($object->error, $object->errors, 'errors');
859  }
860  } elseif ($action == 'confirm_move' && $confirm == 'yes' && $user->hasRight('contrat', 'creer')) {
861  if (GETPOST('newcid') > 0) {
862  $contractline = new ContratLigne($db);
863  $result = $contractline->fetch(GETPOSTINT('lineid'));
864  $contractline->fk_contrat = GETPOSTINT('newcid');
865  $result = $contractline->update($user, 1);
866  if ($result >= 0) {
867  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
868  return;
869  } else {
870  setEventMessages($object->error, $object->errors, 'errors');
871  }
872  } else {
873  setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefNewContract")), null, 'errors');
874  }
875  } elseif ($action == 'update_extras') {
876  $object->oldcopy = dol_clone($object);
877 
878  // Fill array 'array_options' with data from update form
879  $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
880  if ($ret < 0) {
881  $error++;
882  }
883 
884  if (!$error) {
885  $result = $object->insertExtraFields('CONTRACT_MODIFY');
886  if ($result < 0) {
887  setEventMessages($object->error, $object->errors, 'errors');
888  $error++;
889  }
890  }
891 
892  if ($error) {
893  $action = 'edit_extras';
894  }
895  } elseif ($action == 'setref_supplier') {
896  if (!$cancel) {
897  $object->oldcopy = dol_clone($object);
898 
899  $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier', 'alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY');
900  if ($result < 0) {
901  setEventMessages($object->error, $object->errors, 'errors');
902  $action = 'editref_supplier';
903  } else {
904  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
905  exit;
906  }
907  } else {
908  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
909  exit;
910  }
911  } elseif ($action == 'setref_customer') {
912  if (!$cancel) {
913  $object->oldcopy = dol_clone($object);
914 
915  $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer', 'alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY');
916  if ($result < 0) {
917  setEventMessages($object->error, $object->errors, 'errors');
918  $action = 'editref_customer';
919  } else {
920  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
921  exit;
922  }
923  } else {
924  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
925  exit;
926  }
927  } elseif ($action == 'setref') {
928  if (!$cancel) {
929  $result = $object->fetch($id);
930  if ($result < 0) {
931  setEventMessages($object->error, $object->errors, 'errors');
932  }
933 
934  $old_ref = $object->ref;
935 
936  $result = $object->setValueFrom('ref', GETPOST('ref', 'alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY');
937  if ($result < 0) {
938  setEventMessages($object->error, $object->errors, 'errors');
939  $action = 'editref';
940  } else {
941  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
942  $old_filedir = $conf->contrat->multidir_output[$object->entity].'/'.dol_sanitizeFileName($old_ref);
943  $new_filedir = $conf->contrat->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref);
944 
945  $files = dol_dir_list($old_filedir);
946  if (!empty($files)) {
947  if (!is_dir($new_filedir)) {
948  dol_mkdir($new_filedir);
949  }
950  foreach ($files as $file) {
951  dol_move($file['fullname'], $new_filedir.'/'.$file['name']);
952  }
953  }
954 
955  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
956  exit;
957  }
958  } else {
959  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
960  exit;
961  }
962  } elseif ($action == 'setdate_contrat') {
963  if (!$cancel) {
964  $result = $object->fetch($id);
965  if ($result < 0) {
966  setEventMessages($object->error, $object->errors, 'errors');
967  }
968  $datacontrat = dol_mktime(GETPOST('date_contrathour'), GETPOST('date_contratmin'), 0, GETPOST('date_contratmonth'), GETPOST('date_contratday'), GETPOST('date_contratyear'));
969  $result = $object->setValueFrom('date_contrat', $datacontrat, '', null, 'date', '', $user, 'CONTRACT_MODIFY');
970  if ($result < 0) {
971  setEventMessages($object->error, $object->errors, 'errors');
972  $action = 'editdate_contrat';
973  } else {
974  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
975  exit;
976  }
977  } else {
978  header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
979  exit;
980  }
981  }
982 
983  // Actions when printing a doc from card
984  include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
985 
986  // Actions to build doc
987  $upload_dir = $conf->contrat->multidir_output[$object->entity];
988  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
989 
990  // Actions to send emails
991  $triggersendname = 'CONTRACT_SENTBYMAIL';
992  $paramname = 'id';
993  $mode = 'emailfromcontract';
994  $trackid = 'con'.$object->id;
995  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
996 
997 
998  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->hasRight('contrat', 'creer')) {
999  if ($action == 'addcontact') {
1000  $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1001  $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1002  $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1003 
1004  if ($result >= 0) {
1005  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1006  exit;
1007  } else {
1008  if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1009  $langs->load("errors");
1010  setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
1011  } else {
1012  setEventMessages($object->error, $object->errors, 'errors');
1013  }
1014  }
1015  } elseif ($action == 'swapstatut') {
1016  // bascule du statut d'un contact
1017  $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
1018  } elseif ($action == 'deletecontact') {
1019  // Efface un contact
1020  $result = $object->delete_contact(GETPOST('lineid', 'int'));
1021 
1022  if ($result >= 0) {
1023  header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1024  exit;
1025  } else {
1026  setEventMessages($object->error, $object->errors, 'errors');
1027  }
1028  }
1029  }
1030 
1031  // Action clone object
1032  if ($action == 'confirm_clone' && $confirm == 'yes') {
1033  if (!GETPOST('socid', 3)) {
1034  setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
1035  } else {
1036  if ($object->id > 0) {
1037  $result = $object->createFromClone($user, $socid);
1038  if ($result > 0) {
1039  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
1040  exit();
1041  } else {
1042  if (count($object->errors) > 0) {
1043  setEventMessages($object->error, $object->errors, 'errors');
1044  }
1045  $action = '';
1046  }
1047  }
1048  }
1049  }
1050 }
1051 
1052 
1053 /*
1054  * View
1055  */
1056 
1057 
1058 $help_url = 'EN:Module_Contracts|FR:Module_Contrat';
1059 
1060 llxHeader('', $langs->trans("Contract"), $help_url);
1061 
1062 $form = new Form($db);
1063 $formfile = new FormFile($db);
1064 if (isModEnabled('project')) {
1065  $formproject = new FormProjets($db);
1066 }
1067 
1068 // Load object modContract
1069 $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON : 'mod_contract_serpis');
1070 if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') {
1071  $module = substr($module, 0, dol_strlen($module) - 4);
1072 }
1073 $result = dol_include_once('/core/modules/contract/'.$module.'.php');
1074 if ($result > 0) {
1075  $modCodeContract = new $module();
1076 }
1077 
1078 // Create
1079 if ($action == 'create') {
1080  print load_fiche_titre($langs->trans('AddContract'), '', 'contract');
1081 
1082  $soc = new Societe($db);
1083  if ($socid > 0) {
1084  $soc->fetch($socid);
1085  }
1086 
1087  if (GETPOST('origin') && GETPOST('originid', 'int')) {
1088  // Parse element/subelement (ex: project_task)
1089  $regs = array();
1090  $element = $subelement = GETPOST('origin');
1091  if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'), $regs)) {
1092  $element = $regs[1];
1093  $subelement = $regs[2];
1094  }
1095 
1096  if ($element == 'project') {
1097  $projectid = GETPOST('originid', 'int');
1098  } else {
1099  // For compatibility
1100  if ($element == 'order' || $element == 'commande') {
1101  $element = $subelement = 'commande';
1102  }
1103  if ($element == 'propal') {
1104  $element = 'comm/propal'; $subelement = 'propal';
1105  }
1106  if ($element == 'invoice' || $element == 'facture') {
1107  $element = 'compta/facture';
1108  $subelement = 'facture';
1109  }
1110 
1111  dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
1112 
1113  $classname = ucfirst($subelement);
1114  $objectsrc = new $classname($db);
1115  $objectsrc->fetch($originid);
1116  if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
1117  $objectsrc->fetch_lines();
1118  }
1119  $objectsrc->fetch_thirdparty();
1120 
1121  // Replicate extrafields
1122  $objectsrc->fetch_optionals();
1123  $object->array_options = $objectsrc->array_options;
1124 
1125  $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
1126 
1127  $soc = $objectsrc->thirdparty;
1128 
1129  $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private : '');
1130  $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : '');
1131 
1132  // Object source contacts list
1133  $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
1134  }
1135  } else {
1136  $projectid = GETPOST('projectid', 'int');
1137  $note_private = GETPOST("note_private");
1138  $note_public = GETPOST("note_public");
1139  }
1140 
1141  $object->date_contrat = dol_now();
1142 
1143  print '<form name="form_contract" action="'.$_SERVER["PHP_SELF"].'" method="post">';
1144  print '<input type="hidden" name="token" value="'.newToken().'">';
1145 
1146  print '<input type="hidden" name="action" value="add">';
1147  print '<input type="hidden" name="socid" value="'.$soc->id.'">'."\n";
1148  print '<input type="hidden" name="remise_percent" value="0">';
1149 
1150  print dol_get_fiche_head();
1151 
1152  print '<table class="border centpercent">';
1153 
1154  // Ref
1155  print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans('Ref').'</td><td>';
1156  if (!empty($modCodeContract->code_auto)) {
1157  $tmpcode = $langs->trans("Draft");
1158  } else {
1159  $tmpcode = '<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(GETPOST('ref') ?GETPOST('ref') : $tmpcode).'">';
1160  }
1161  print $tmpcode;
1162  print '</td></tr>';
1163 
1164  // Ref customer
1165  print '<tr><td>'.$langs->trans('RefCustomer').'</td>';
1166  print '<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(GETPOST('ref_customer', 'alpha')).'"></td></tr>';
1167 
1168  // Ref supplier
1169  print '<tr><td>'.$langs->trans('RefSupplier').'</td>';
1170  print '<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(GETPOST('ref_supplier', 'alpha')).'"></td></tr>';
1171 
1172  // Thirdparty
1173  print '<tr>';
1174  print '<td class="fieldrequired">'.$langs->trans('ThirdParty').'</td>';
1175  if ($socid > 0) {
1176  print '<td>';
1177  print $soc->getNomUrl(1);
1178  print '<input type="hidden" name="socid" value="'.$soc->id.'">';
1179  print '</td>';
1180  } else {
1181  print '<td>';
1182  print img_picto('', 'company', 'class="pictofixedwidth"');
1183  print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300 widthcentpercentminusxx maxwidth500');
1184  print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
1185  print '</td>';
1186  }
1187  print '</tr>'."\n";
1188 
1189  if ($socid > 0) {
1190  // Ligne info remises tiers
1191  print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
1192  if ($soc->remise_percent) {
1193  print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent).' ';
1194  } else {
1195  print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoRelativeDiscount").'. </span>';
1196  }
1197  $absolute_discount = $soc->getAvailableDiscounts();
1198  if ($absolute_discount) {
1199  print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)).'.';
1200  } else {
1201  print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoAbsoluteDiscount").'.</span>';
1202  }
1203  print '</td></tr>';
1204  }
1205 
1206  // Commercial suivi
1207  print '<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPFOLL").'</span></td><td>';
1208  print img_picto('', 'user', 'class="pictofixedwidth"');
1209  print $form->select_dolusers(GETPOST("commercial_suivi_id") ?GETPOST("commercial_suivi_id") : $user->id, 'commercial_suivi_id', 1, '');
1210  print '</td></tr>';
1211 
1212  // Commercial signature
1213  print '<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans("TypeContact_contrat_internal_SALESREPSIGN").'</span></td><td>';
1214  print img_picto('', 'user', 'class="pictofixedwidth"');
1215  print $form->select_dolusers(GETPOST("commercial_signature_id") ?GETPOST("commercial_signature_id") : $user->id, 'commercial_signature_id', 1, '');
1216  print '</td></tr>';
1217 
1218  print '<tr><td><span class="fieldrequired">'.$langs->trans("Date").'</span></td><td>';
1219  print $form->selectDate($datecontrat, '', 0, 0, '', "contrat");
1220  print "</td></tr>";
1221 
1222  // Project
1223  if (isModEnabled('project')) {
1224  $langs->load('projects');
1225 
1226  $formproject = new FormProjets($db);
1227 
1228  print '<tr><td>'.$langs->trans("Project").'</td><td>';
1229  $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid, "projectid", 0, 0, 1, 1);
1230  print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$soc->id).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
1231  print "</td></tr>";
1232  }
1233 
1234  print '<tr><td>'.$langs->trans("NotePublic").'</td><td class="tdtop">';
1235  $doleditor = new DolEditor('note_public', $note_public, '', '100', 'dolibarr_notes', 'In', 1, true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
1236  print $doleditor->Create(1);
1237  print '</td></tr>';
1238 
1239  if (empty($user->socid)) {
1240  print '<tr><td>'.$langs->trans("NotePrivate").'</td><td class="tdtop">';
1241  $doleditor = new DolEditor('note_private', $note_private, '', '100', 'dolibarr_notes', 'In', 1, true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
1242  print $doleditor->Create(1);
1243  print '</td></tr>';
1244  }
1245 
1246  // Other attributes
1247  $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'cols' => '3');
1248  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1249  print $hookmanager->resPrint;
1250 
1251  // Other attributes
1252  if (empty($reshook)) {
1253  print $object->showOptionals($extrafields, 'create', $parameters);
1254  }
1255 
1256  print "</table>\n";
1257 
1258  print dol_get_fiche_end();
1259 
1260  print $form->buttonsSaveCancel("Create");
1261 
1262  if (is_object($objectsrc)) {
1263  print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
1264  print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
1265 
1266  if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
1267  print '<br>'.$langs->trans("Note").': '.$langs->trans("OnlyLinesWithTypeServiceAreUsed");
1268  }
1269  }
1270 
1271  print "</form>\n";
1272 } else {
1273  // View and edit mode
1274  $now = dol_now();
1275 
1276  if ($object->id > 0) {
1277  $object->fetch_thirdparty();
1278 
1279  $soc = $object->thirdparty; // $soc is used later
1280 
1281  $result = $object->fetch_lines(); // This also init $this->nbofserviceswait, $this->nbofservicesopened, $this->nbofservicesexpired=, $this->nbofservicesclosed
1282  if ($result < 0) {
1283  dol_print_error($db, $object->error);
1284  }
1285 
1286  $nbofservices = count($object->lines);
1287 
1288  $author = new User($db);
1289  $author->fetch($object->user_author_id);
1290 
1291  $commercial_signature = new User($db);
1292  $commercial_signature->fetch($object->commercial_signature_id);
1293 
1294  $commercial_suivi = new User($db);
1295  $commercial_suivi->fetch($object->commercial_suivi_id);
1296 
1297  $head = contract_prepare_head($object);
1298 
1299  $hselected = 0;
1300  $formconfirm = '';
1301 
1302  print dol_get_fiche_head($head, $hselected, $langs->trans("Contract"), -1, 'contract');
1303 
1304 
1305  if ($action == 'delete') {
1306  //Confirmation de la suppression du contrat
1307  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("DeleteAContract"), $langs->trans("ConfirmDeleteAContract"), "confirm_delete", '', 0, 1);
1308  } elseif ($action == 'valid') {
1309  //Confirmation de la validation
1310  $ref = substr($object->ref, 1, 4);
1311  if ($ref == 'PROV' && !empty($modCodeContract->code_auto)) {
1312  $numref = $object->getNextNumRef($object->thirdparty);
1313  } else {
1314  $numref = $object->ref;
1315  }
1316  $text = $langs->trans('ConfirmValidateContract', $numref);
1317  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ValidateAContract"), $text, "confirm_valid", '', 0, 1);
1318  } elseif ($action == 'close') {
1319  // Confirmation de la fermeture
1320  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("CloseAContract"), $langs->trans("ConfirmCloseContract"), "confirm_close", '', 0, 1);
1321  } elseif ($action == 'activate') {
1322  $formquestion = array(
1323  array('type' => 'date', 'name' => 'd_start', 'label' => $langs->trans("DateServiceActivate"), 'value' => dol_now()),
1324  array('type' => 'date', 'name' => 'd_end', 'label' => $langs->trans("DateEndPlanned"), /*'value' => $form->selectDate('', "end", $usehm, $usehm, '', "active", 1, 0),*/ '', ''),
1325  array('type' => 'text', 'name' => 'comment', 'label' => $langs->trans("Comment"), 'value' => '', '', '', 'class' => 'minwidth300', 'moreattr'=>'autofocus')
1326  );
1327  $formconfirm = $form->formconfirm($_SERVER['PHP_SELF']."?id=".$object->id, $langs->trans("ActivateAllOnContract"), $langs->trans("ConfirmActivateAllOnContract"), "confirm_activate", $formquestion, 'yes', 1, 280);
1328  } elseif ($action == 'clone') {
1329  // Clone confirmation
1330  $formquestion = array(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)')));
1331  $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneContract', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1332  }
1333 
1334 
1335  // Call Hook formConfirm
1336  $parameters = array(
1337  'formConfirm' => $formconfirm,
1338  'id' => $id,
1339  //'lineid' => $lineid,
1340  );
1341  // Note that $action and $object may have been modified by hook
1342  $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action);
1343  if (empty($reshook)) {
1344  $formconfirm .= $hookmanager->resPrint;
1345  } elseif ($reshook > 0) {
1346  $formconfirm = $hookmanager->resPrint;
1347  }
1348 
1349  // Print form confirm
1350  print $formconfirm;
1351 
1352 
1353  // Contract
1354  if (!empty($object->brouillon) && $user->hasRight('contrat', 'creer')) {
1355  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">';
1356  print '<input type="hidden" name="token" value="'.newToken().'">';
1357  print '<input type="hidden" name="action" value="setremise">';
1358  }
1359 
1360  // Contract card
1361 
1362  $linkback = '<a href="'.DOL_URL_ROOT.'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1363 
1364 
1365  $morehtmlref = '';
1366  if (!empty($modCodeContract->code_auto)) {
1367  $morehtmlref .= $object->ref;
1368  } else {
1369  $morehtmlref .= $form->editfieldkey("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 3);
1370  $morehtmlref .= $form->editfieldval("", 'ref', $object->ref, $object, $user->rights->contrat->creer, 'string', '', 0, 2);
1371  }
1372 
1373  $morehtmlref .= '<div class="refidno">';
1374  // Ref customer
1375  $morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer, 'string', '', 0, 1);
1376  $morehtmlref .= $form->editfieldval("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer, 'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ? ':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE : ''), '', null, null, '', 1, 'getFormatedCustomerRef');
1377  // Ref supplier
1378  $morehtmlref .= '<br>';
1379  $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer, 'string', '', 0, 1);
1380  $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer, 'string', '', null, null, '', 1, 'getFormatedSupplierRef');
1381  // Thirdparty
1382  $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1);
1383  if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
1384  $morehtmlref .= ' (<a href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->thirdparty->id.'&search_name='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherContracts").'</a>)';
1385  }
1386  // Project
1387  if (isModEnabled('project')) {
1388  $langs->load("projects");
1389  $morehtmlref .= '<br>';
1390  if ($permissiontoadd) {
1391  $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1392  if ($action != 'classify') {
1393  $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1394  }
1395  $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1396  } else {
1397  if (!empty($object->fk_project)) {
1398  $proj = new Project($db);
1399  $proj->fetch($object->fk_project);
1400  $morehtmlref .= $proj->getNomUrl(1);
1401  if ($proj->title) {
1402  $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
1403  }
1404  }
1405  }
1406  }
1407  $morehtmlref .= '</div>';
1408 
1409 
1410  dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'none', $morehtmlref);
1411 
1412 
1413  print '<div class="fichecenter">';
1414  print '<div class="underbanner clearboth"></div>';
1415 
1416 
1417  print '<table class="border tableforfield" width="100%">';
1418 
1419  // Line info of thirdparty discounts
1420  print '<tr><td class="titlefield">'.$langs->trans('Discount').'</td><td colspan="3">';
1421  if ($object->thirdparty->remise_percent) {
1422  print $langs->trans("CompanyHasRelativeDiscount", $object->thirdparty->remise_percent).'. ';
1423  } else {
1424  print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoRelativeDiscount").'. </span>';
1425  }
1426  $absolute_discount = $object->thirdparty->getAvailableDiscounts();
1427  if ($absolute_discount) {
1428  print $langs->trans("CompanyHasAbsoluteDiscount", price($absolute_discount), $langs->trans("Currency".$conf->currency)).'.';
1429  } else {
1430  print '<span class="hideonsmartphone">'.$langs->trans("CompanyHasNoAbsoluteDiscount").'.</span>';
1431  }
1432  print '</td></tr>';
1433 
1434  // Date
1435  print '<tr>';
1436  print '<td class="titlefield">';
1437  print $form->editfieldkey("Date", 'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer);
1438  print '</td><td>';
1439  print $form->editfieldval("Date", 'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer, 'datehourpicker');
1440  print '</td>';
1441  print '</tr>';
1442 
1443  // Other attributes
1444  $cols = 3;
1445  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1446 
1447  print "</table>";
1448 
1449  print '</div>';
1450 
1451  if (!empty($object->brouillon) && $user->hasRight('contrat', 'creer')) {
1452  print '</form>';
1453  }
1454 
1455  echo '<br>';
1456 
1457  if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1458  $blocname = 'contacts';
1459  $title = $langs->trans('ContactsAddresses');
1460  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1461  }
1462 
1463  if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1464  $blocname = 'notes';
1465  $title = $langs->trans('Notes');
1466  include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
1467  }
1468 
1469 
1470  $arrayothercontracts = $object->getListOfContracts('others'); // array or -1 if technical error
1471 
1472  /*
1473  * Lines of contracts
1474  */
1475 
1476  // Add products/services form
1477  //$forceall = 1;
1478  global $inputalsopricewithtax;
1479  $inputalsopricewithtax = 1;
1480 
1481  $productstatic = new Product($db);
1482 
1483  $usemargins = 0;
1484  if (isModEnabled('margin') && !empty($object->element) && in_array($object->element, array('facture', 'propal', 'commande'))) {
1485  $usemargins = 1;
1486  }
1487 
1488  // Title line for service
1489  $cursorline = 1;
1490 
1491 
1492  print '<div id="contrat-lines-container" id="contractlines" data-contractid="'.$object->id.'" data-element="'.$object->element.'" >';
1493  while ($cursorline <= $nbofservices) {
1494  print '<div id="contrat-line-container'.$object->lines[$cursorline - 1]->id.'" data-contratlineid = "'.$object->lines[$cursorline - 1]->id.'" data-element="'.$object->lines[$cursorline - 1]->element.'" >';
1495  print '<form name="update" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="post">';
1496  print '<input type="hidden" name="token" value="'.newToken().'">';
1497  print '<input type="hidden" name="action" value="updateline">';
1498  print '<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.'">';
1499  print '<input type="hidden" name="fournprice" value="'.(!empty($object->lines[$cursorline - 1]->fk_fournprice) ? $object->lines[$cursorline - 1]->fk_fournprice : 0).'">';
1500 
1501  // Area with common detail of line
1502  print '<div class="div-table-responsive-no-min">';
1503  print '<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">';
1504 
1505  $sql = "SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,";
1506  $sql .= " cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1507  $sql .= " cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";
1508  $sql .= " cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";
1509  $sql .= " cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1510  $sql .= " cd.fk_unit,";
1511  $sql .= " p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity, p.tosell, p.tobuy, p.tobatch";
1512  $sql .= " ,cd.rang";
1513  $sql .= " FROM ".MAIN_DB_PREFIX."contratdet as cd";
1514  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
1515  $sql .= " WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id);
1516 
1517  $result = $db->query($sql);
1518  if ($result) {
1519  $total = 0;
1520 
1521  $objp = $db->fetch_object($result);
1522 
1523  print '<tr class="liste_titre'.($cursorline ? ' liste_titre_add' : '').'">';
1524  print '<td>'.$langs->trans("ServiceNb", $cursorline).'</td>';
1525  print '<td width="80" class="center">'.$langs->trans("VAT").'</td>';
1526  print '<td width="80" class="right">'.$langs->trans("PriceUHT").'</td>';
1527  //if (isModEnabled("multicurrency")) {
1528  // print '<td width="80" class="right">'.$langs->trans("PriceUHTCurrency").'</td>';
1529  //}
1530  print '<td width="30" class="center">'.$langs->trans("Qty").'</td>';
1531  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1532  print '<td width="30" class="left">'.$langs->trans("Unit").'</td>';
1533  }
1534  print '<td width="50" class="right">'.$langs->trans("ReductionShort").'</td>';
1535  if (isModEnabled('margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1536  print '<td width="50" class="right">'.$langs->trans("BuyingPrice").'</td>';
1537  }
1538  //
1539 
1540  if ($nbofservices > 1 && $conf->browser->layout != 'phone' && !empty($user->rights->contrat->creer)) {
1541  print '<td width="30" class="linecolmove tdlineupdown center">';
1542  if ($cursorline > 1) {
1543  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&rowid='.$objp->rowid.'">';
1544  echo img_up('default', 0, 'imgupforline');
1545  print '</a>';
1546  }
1547  if ($cursorline < $nbofservices) {
1548  print '<a class="lineupdown" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&rowid='.$objp->rowid.'">';
1549  echo img_down('default', 0, 'imgdownforline');
1550  print '</a>';
1551  }
1552  print '</td>';
1553  } else {
1554  print '<td width="30">&nbsp;</td>';
1555  }
1556 
1557  print "</tr>\n";
1558 
1559 
1560 
1561  // Line in view mode
1562  if ($action != 'editline' || GETPOST('rowid') != $objp->rowid) {
1563  $moreparam = '';
1564  if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') {
1565  $moreparam = 'style="display: none;"';
1566  }
1567  print '<tr class="tdtop oddeven" '.$moreparam.'>';
1568  // Label
1569  if ($objp->fk_product > 0) {
1570  $productstatic->id = $objp->fk_product;
1571  $productstatic->type = $objp->ptype;
1572  $productstatic->ref = $objp->pref;
1573  $productstatic->entity = $objp->pentity;
1574  $productstatic->label = $objp->plabel;
1575  $productstatic->status = $objp->tosell;
1576  $productstatic->status_buy = $objp->tobuy;
1577  $productstatic->status_batch = $objp->tobatch;
1578 
1579  print '<td>';
1580  $text = $productstatic->getNomUrl(1, '', 32);
1581  if ($objp->plabel) {
1582  $text .= ' - ';
1583  $text .= $objp->plabel;
1584  }
1585  $description = $objp->description;
1586 
1587  // Add description in form
1588  if (getDolGlobalInt('PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
1589  $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ? '<br>'.dol_htmlentitiesbr($objp->description) : '';
1590  $description = ''; // Already added into main visible desc
1591  }
1592 
1593  echo $form->textwithtooltip($text, $description, 3, '', '', $cursorline, 0, (!empty($line->fk_parent_line) ?img_picto('', 'rightarrow') : ''));
1594 
1595  print '</td>';
1596  } else {
1597  print '<td>'.img_object($langs->trans("ShowProductOrService"), ($objp->product_type ? 'service' : 'product')).' '.dol_htmlentitiesbr($objp->description)."</td>\n";
1598  }
1599  // VAT
1600  print '<td class="center">';
1601  print vatrate($objp->tva_tx.($objp->vat_src_code ? (' ('.$objp->vat_src_code.')') : ''), '%', $objp->info_bits);
1602  print '</td>';
1603  // Price
1604  print '<td class="right">'.($objp->subprice != '' ? price($objp->subprice) : '')."</td>\n";
1605  // Price multicurrency
1606  /*if (isModEnabled("multicurrency")) {
1607  print '<td class="linecoluht_currency nowrap right">'.price($objp->multicurrency_subprice).'</td>';
1608  }*/
1609  // Quantity
1610  print '<td class="center">'.$objp->qty.'</td>';
1611  // Unit
1612  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1613  print '<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).'</td>';
1614  }
1615  // Discount
1616  if ($objp->remise_percent > 0) {
1617  print '<td class="right">'.$objp->remise_percent."%</td>\n";
1618  } else {
1619  print '<td>&nbsp;</td>';
1620  }
1621 
1622  // Margin
1623  if (isModEnabled('margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1624  print '<td class="right nowraponall">'.price($objp->pa_ht).'</td>';
1625  }
1626 
1627  // Icon move, update et delete (status contract 0=draft,1=validated,2=closed)
1628  print '<td class="nowraponall right">';
1629  if ($user->rights->contrat->creer && is_array($arrayothercontracts) && count($arrayothercontracts) && ($object->statut >= 0)) {
1630  print '<!-- link to move service line into another contract -->';
1631  print '<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=move&token='.newToken().'&rowid='.$objp->rowid.'">';
1632  print img_picto($langs->trans("MoveToAnotherContract"), 'uparrow');
1633  print '</a>';
1634  }
1635  if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1636  print '<a class="reposition marginrightonly editfielda" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=editline&token='.newToken().'&rowid='.$objp->rowid.'">';
1637  print img_edit();
1638  print '</a>';
1639  }
1640  if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1641  print '<a class="reposition marginrightonly" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=deleteline&token='.newToken().'&rowid='.$objp->rowid.'">';
1642  print img_delete();
1643  print '</a>';
1644  }
1645  print '</td>';
1646 
1647  print "</tr>\n";
1648 
1649  // Dates of service planed and real
1650  if ($objp->subprice >= 0) {
1651  $colspan = 6;
1652 
1653  if (isModEnabled('margin') && getDolGlobalString('PRODUCT_USE_UNITS')) {
1654  $colspan = 8;
1655  } elseif (isModEnabled('margin') || getDolGlobalString('PRODUCT_USE_UNITS')) {
1656  $colspan = 7;
1657  }
1658 
1659  print '<tr class="oddeven" '.$moreparam.'>';
1660  print '<td colspan="'.$colspan.'">';
1661 
1662  // Date planned
1663  print $langs->trans("DateStartPlanned").': ';
1664  if ($objp->date_start) {
1665  print dol_print_date($db->jdate($objp->date_start), 'day');
1666  // Warning si date prevu passee et pas en service
1667  if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now - $conf->contrat->services->inactifs->warning_delay)) {
1668  $warning_delay = $conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1669  $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days");
1670  print " ".img_warning($textlate);
1671  }
1672  } else {
1673  print $langs->trans("Unknown");
1674  }
1675  print ' &nbsp;-&nbsp; ';
1676  print $langs->trans("DateEndPlanned").': ';
1677  if ($objp->date_end) {
1678  print dol_print_date($db->jdate($objp->date_end), 'day');
1679  if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now - $conf->contrat->services->expires->warning_delay)) {
1680  $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
1681  $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days");
1682  print " ".img_warning($textlate);
1683  }
1684  } else {
1685  print $langs->trans("Unknown");
1686  }
1687 
1688  print '</td>';
1689  print '</tr>';
1690  }
1691 
1692  // Display lines extrafields
1693  if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1694  $line = new ContratLigne($db);
1695  $line->id = $objp->rowid;
1696  $line->fetch_optionals();
1697  print $line->showOptionals($extrafields, 'view', array('class'=>'oddeven', 'style'=>$moreparam, 'colspan'=>$colspan), '', '', 1);
1698  }
1699  } else {
1700  // Line in mode update
1701  // Ligne carac
1702  print '<tr class="oddeven">';
1703  print '<td>';
1704  if ($objp->fk_product > 0) {
1705  $canchangeproduct = 1;
1706  if (empty($canchangeproduct)) {
1707  $productstatic->id = $objp->fk_product;
1708  $productstatic->type = $objp->ptype;
1709  $productstatic->ref = $objp->pref;
1710  $productstatic->entity = $objp->pentity;
1711  print $productstatic->getNomUrl(1, '', 32);
1712  print $objp->label ? ' - '.dol_trunc($objp->label, 32) : '';
1713  print '<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).'">';
1714  } else {
1715  $senderissupplier = 0;
1716  if (empty($senderissupplier)) {
1717  print $form->select_produits((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0), 'idprod');
1718  } else {
1719  $form->select_produits_fournisseurs((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0), 'idprod');
1720  }
1721  }
1722  print '<br>';
1723  } else {
1724  print $objp->label ? $objp->label.'<br>' : '';
1725  print '<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).'">';
1726  }
1727 
1728  // editeur wysiwyg
1729  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1730  $nbrows = ROWS_2;
1731  if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1732  $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1733  }
1734  $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1735  $doleditor = new DolEditor('product_desc', $objp->description, '', 92, 'dolibarr_details', '', false, true, $enable, $nbrows, '90%');
1736  $doleditor->Create();
1737 
1738  print '</td>';
1739 
1740  // VAT
1741  print '<td class="right">';
1742  print $form->load_tva("eltva_tx", $objp->tva_tx.($objp->vat_src_code ? (' ('.$objp->vat_src_code.')') : ''), $mysoc, $object->thirdparty, $objp->fk_product, $objp->info_bits, $objp->product_type, 0, 1);
1743  print '</td>';
1744 
1745  // Price
1746  print '<td class="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).'"></td>';
1747 
1748  // Price multicurrency
1749  /*if (isModEnabled("multicurrency")) {
1750  print '<td class="linecoluht_currency nowrap right">'.price($objp->multicurrency_subprice).'</td>';
1751  }*/
1752 
1753  // Quantity
1754  print '<td class="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.'"></td>';
1755 
1756  // Unit
1757  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1758  print '<td class="left">';
1759  print $form->selectUnits($objp->fk_unit, "unit");
1760  print '</td>';
1761  }
1762 
1763  // Discount
1764  print '<td class="nowrap right"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.'">%</td>';
1765 
1766  if (!empty($usemargins)) {
1767  print '<td class="right">';
1768  if ($objp->fk_product) {
1769  print '<select id="fournprice" name="fournprice"></select>';
1770  }
1771  print '<input id="buying_price" type="text" size="5" name="buying_price" value="'.price($objp->pa_ht, 0, '', 0).'"></td>';
1772  }
1773  print '<td class="center">';
1774  print '<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans("Modify").'">';
1775  print '<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1776  print '</td>';
1777  print '</tr>';
1778 
1779  $colspan = 6;
1780  if (isModEnabled('margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1781  $colspan++;
1782  }
1783  if (getDolGlobalInt('PRODUCT_USE_UNITS')) {
1784  $colspan++;
1785  }
1786 
1787  // Line dates planed
1788  print '<tr class="oddeven">';
1789  print '<td colspan="'.$colspan.'">';
1790  print $langs->trans("DateStartPlanned").' ';
1791  print $form->selectDate($db->jdate($objp->date_start), "date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1), "update");
1792  print ' &nbsp;&nbsp;'.$langs->trans("DateEndPlanned").' ';
1793  print $form->selectDate($db->jdate($objp->date_end), "date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1), "update");
1794  print '</td>';
1795  print '</tr>';
1796 
1797  if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1798  $line = new ContratLigne($db);
1799  $line->id = $objp->rowid;
1800  $line->fetch_optionals();
1801  print $line->showOptionals($extrafields, 'edit', array('style'=>'class="oddeven"', 'colspan'=>$colspan), '', '', 1);
1802  }
1803  }
1804 
1805  $db->free($result);
1806  } else {
1807  dol_print_error($db);
1808  }
1809 
1810  if ($object->statut > 0) {
1811  $moreparam = '';
1812  if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action != 'showclosedlines') {
1813  $moreparam = 'style="display: none;"';
1814  }
1815  print '<tr class="oddeven" '.$moreparam.'>';
1816  print '<td class="tdhrthin" colspan="'.($conf->margin->enabled ? 7 : 6).'"><hr class="opacitymedium tdhrthin"></td>';
1817  print "</tr>\n";
1818  }
1819 
1820  print "</table>";
1821  print '</div>';
1822 
1823  print "</form>\n";
1824 
1825 
1826  /*
1827  * Confirmation to delete service line of contract
1828  */
1829  if ($action == 'deleteline' && !$_REQUEST["cancel"] && $user->hasRight('contrat', 'creer') && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) {
1830  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid'), $langs->trans("DeleteContractLine"), $langs->trans("ConfirmDeleteContractLine"), "confirm_deleteline", '', 0, 1);
1831  if ($ret == 'html') {
1832  print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1833  }
1834  }
1835 
1836  /*
1837  * Confirmation to move service toward another contract
1838  */
1839  if ($action == 'move' && !$_REQUEST["cancel"] && $user->hasRight('contrat', 'creer') && $object->lines[$cursorline - 1]->id == GETPOST('rowid')) {
1840  $arraycontractid = array();
1841  foreach ($arrayothercontracts as $contractcursor) {
1842  $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1843  }
1844  //var_dump($arraycontractid);
1845  // Cree un tableau formulaire
1846  $formquestion = array(
1847  'text' => $langs->trans("ConfirmMoveToAnotherContractQuestion"),
1848  array('type' => 'select', 'name' => 'newcid', 'values' => $arraycontractid));
1849 
1850  print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id."&lineid=".GETPOST('rowid', 'int'), $langs->trans("MoveToAnotherContract"), $langs->trans("ConfirmMoveToAnotherContract"), "confirm_move", $formquestion);
1851  print '<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1852  }
1853 
1854  // Area with status and activation info of line
1855  if ($object->statut > 0) {
1856  print '<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').'" width="100%">';
1857 
1858  print '<tr class="oddeven" '.$moreparam.'>';
1859  print '<td><span class="valignmiddle hideonsmartphone">'.$langs->trans("ServiceStatus").':</span> '.$object->lines[$cursorline - 1]->getLibStatut(4).'</td>';
1860  print '<td width="30" class="right">';
1861  if ($user->socid == 0) {
1862  if ($object->statut > 0 && $action != 'activateline' && $action != 'unactivateline') {
1863  $tmpaction = 'activateline';
1864  $tmpactionpicto = 'play';
1865  $tmpactiontext = $langs->trans("Activate");
1866  if ($objp->statut == 4) {
1867  $tmpaction = 'unactivateline';
1868  $tmpactionpicto = 'playstop';
1869  $tmpactiontext = $langs->trans("Disable");
1870  }
1871  if (($tmpaction == 'activateline' && $user->rights->contrat->activer) || ($tmpaction == 'unactivateline' && $user->rights->contrat->desactiver)) {
1872  print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline - 1]->id.'&amp;action='.$tmpaction.'">';
1873  print img_picto($tmpactiontext, $tmpactionpicto);
1874  print '</a>';
1875  }
1876  }
1877  }
1878  print '</td>';
1879  print "</tr>\n";
1880 
1881  print '<tr class="oddeven" '.$moreparam.'>';
1882 
1883  print '<td>';
1884  // Si pas encore active
1885  if (!$objp->date_start_real) {
1886  print $langs->trans("DateStartReal").': ';
1887  if ($objp->date_start_real) {
1888  print dol_print_date($db->jdate($objp->date_start_real), 'day');
1889  } else {
1890  print $langs->trans("ContractStatusNotRunning");
1891  }
1892  }
1893  // Si active et en cours
1894  if ($objp->date_start_real && !$objp->date_end_real) {
1895  print $langs->trans("DateStartReal").': ';
1896  print dol_print_date($db->jdate($objp->date_start_real), 'day');
1897  }
1898  // Si desactive
1899  if ($objp->date_start_real && $objp->date_end_real) {
1900  print $langs->trans("DateStartReal").': ';
1901  print dol_print_date($db->jdate($objp->date_start_real), 'day');
1902  print ' &nbsp;-&nbsp; ';
1903  print $langs->trans("DateEndReal").': ';
1904  print dol_print_date($db->jdate($objp->date_end_real), 'day');
1905  }
1906  if (!empty($objp->comment)) {
1907  print " &nbsp;-&nbsp; ".$objp->comment;
1908  }
1909  print '</td>';
1910 
1911  print '<td class="center">&nbsp;</td>';
1912 
1913  print '</tr>';
1914  print '</table>';
1915  }
1916 
1917  // Form to activate line
1918  if ($user->rights->contrat->activer && $action == 'activateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne', 'int')) {
1919  print '<form name="active" action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1920  print '<input type="hidden" name="token" value="'.newToken().'">';
1921  print '<input type="hidden" name="action" value="confirm_active">';
1922  print '<input type="hidden" name="id" value="'.$object->id.'">';
1923  print '<input type="hidden" name="ligne" value="'.GETPOST('ligne', 'int').'">';
1924  print '<input type="hidden" name="confirm" value="yes">';
1925 
1926  print '<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').'" width="100%">';
1927 
1928  // Definie date debut et fin par defaut
1929  $dateactstart = $objp->date_start;
1930  if (GETPOST('remonth')) {
1931  $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
1932  } elseif (!$dateactstart) {
1933  $dateactstart = time();
1934  }
1935 
1936  $dateactend = $objp->date_end;
1937  if (GETPOST('endmonth')) {
1938  $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
1939  } elseif (!$dateactend) {
1940  if ($objp->fk_product > 0) {
1941  $product = new Product($db);
1942  $product->fetch($objp->fk_product);
1943  $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
1944  }
1945  }
1946 
1947  print '<tr class="oddeven">';
1948  print '<td class="nohover">'.$langs->trans("DateServiceActivate").'</td><td class="nohover">';
1949  print $form->selectDate($dateactstart, 'start', $usehm, $usehm, '', "active", 1, 0);
1950  print '</td>';
1951  print '<td class="nohover">'.$langs->trans("DateEndPlanned").'</td><td class="nohover">';
1952  print $form->selectDate($dateactend, "end", $usehm, $usehm, '', "active", 1, 0);
1953  print '</td>';
1954  print '<td class="center nohover">';
1955  print '</td>';
1956 
1957  print '</tr>';
1958 
1959  print '<tr class="oddeven">';
1960  print '<td class="nohover">'.$langs->trans("Comment").'</td><td colspan="3" class="nohover" colspan="'.($conf->margin->enabled ? 4 : 3).'"><input type="text" class="minwidth300" name="comment" value="'.dol_escape_htmltag(GETPOST("comment", 'alphanohtml')).'"></td>';
1961  print '<td class="nohover right">';
1962  print '<input type="submit" class="button" name="activate" value="'.$langs->trans("Activate").'"> &nbsp; ';
1963  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
1964  print '</td>';
1965  print '</tr>';
1966 
1967  print '</table>';
1968 
1969  print '</form>';
1970  }
1971 
1972  if ($user->rights->contrat->activer && $action == 'unactivateline' && $object->lines[$cursorline - 1]->id == GETPOST('ligne', 'int')) {
1976  print '<!-- Form to disabled a line -->'."\n";
1977  print '<form name="confirm_closeline" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;ligne='.$object->lines[$cursorline - 1]->id.'" method="post">';
1978  print '<input type="hidden" name="token" value="'.newToken().'">';
1979  print '<input type="hidden" name="confirm" value="yes">';
1980  print '<input type="hidden" name="action" value="confirm_closeline">';
1981 
1982  print '<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ? ' boxtablenobottom' : '').'" width="100%">';
1983 
1984  // Definie date debut et fin par defaut
1985  $dateactstart = $objp->date_start_real;
1986  if (GETPOST('remonth')) {
1987  $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
1988  } elseif (!$dateactstart) {
1989  $dateactstart = time();
1990  }
1991 
1992  $dateactend = $objp->date_end_real;
1993  if (GETPOST('endmonth')) {
1994  $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear'));
1995  } elseif (!$dateactend) {
1996  if ($objp->fk_product > 0) {
1997  $product = new Product($db);
1998  $product->fetch($objp->fk_product);
1999  $dateactend = dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2000  }
2001  }
2002  $now = dol_now();
2003  if ($dateactend > $now) {
2004  $dateactend = $now;
2005  }
2006 
2007  print '<tr class="oddeven"><td colspan="2" class="nohover">';
2008  if ($objp->statut >= 4) {
2009  if ($objp->statut == 4) {
2010  print $langs->trans("DateEndReal").' ';
2011  print $form->selectDate($dateactend, "end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1), "closeline", 1, 1);
2012  }
2013  }
2014  print '</td>';
2015  print '<td class="center nohover">';
2016  print '</td></tr>';
2017 
2018  print '<tr class="oddeven">';
2019  print '<td class="nohover">'.$langs->trans("Comment").'</td><td class="nohover"><input class="quatrevingtpercent" type="text" class="flat" name="comment" value="'.dol_escape_htmltag(GETPOST('comment', 'alpha')).'"></td>';
2020  print '<td class="nohover right">';
2021  print '<input type="submit" class="button" name="close" value="'.$langs->trans("Disable").'"> &nbsp; ';
2022  print '<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans("Cancel").'">';
2023  print '</td>';
2024  print '</tr>';
2025 
2026  print '</table>';
2027 
2028  print '</form>';
2029  }
2030  print '</div>';
2031  $cursorline++;
2032  }
2033  print '</div>';
2034 
2035  // Form to add new line
2036  if ($user->rights->contrat->creer && ($object->statut == 0)) {
2037  $dateSelector = 1;
2038 
2039  print "\n";
2040  print ' <form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '' : '#line_'.GETPOST('lineid', 'int')).'" method="POST">
2041  <input type="hidden" name="token" value="'.newToken().'">
2042  <input type="hidden" name="action" value="'.(($action != 'editline') ? 'addline' : 'updateline').'">
2043  <input type="hidden" name="mode" value="">
2044  <input type="hidden" name="id" value="'.$object->id.'">
2045  <input type="hidden" name="page_y" value="">
2046  ';
2047 
2048  print '<div class="div-table-responsive-no-min">';
2049  print '<table id="tablelines" class="noborder noshadow" width="100%">'; // Array with (n*2)+1 lines
2050 
2051  // Form to add new line
2052  if ($action != 'editline') {
2053  $forcetoshowtitlelines = 1;
2054  if (empty($object->multicurrency_code)) {
2055  $object->multicurrency_code = $conf->currency; // TODO Remove this when multicurrency supported on contracts
2056  }
2057 
2058  // Add free products/services
2059 
2060  $parameters = array();
2061  $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2062  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2063  if (empty($reshook))
2064  $object->formAddObjectLine(1, $mysoc, $soc);
2065  }
2066 
2067  print '</table>';
2068  print '</div>';
2069  print '</form>';
2070  }
2071 
2072  print dol_get_fiche_end();
2073 
2074  // Select mail models is same action as presend
2075  if (GETPOST('modelselected')) {
2076  $action = 'presend';
2077  }
2078 
2079  /*
2080  * Buttons
2081  */
2082  if ($user->socid == 0 && $action != 'presend' && $action != 'editline') {
2083  print '<div class="tabsAction">';
2084 
2085  $parameters = array();
2086  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2087 
2088  if (empty($reshook)) {
2089  $params = array(
2090  'attr' => array(
2091  'title' => '',
2092  'class' => 'classfortooltip'
2093  )
2094  );
2095 
2096  // Send
2097  if (empty($user->socid)) {
2098  if ($object->statut == 1) {
2099  if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) {
2100  print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle', '', true, $params);
2101  } else {
2102  print dolGetButtonAction('', $langs->trans('SendMail'), 'default', '#', '', false, $params);
2103  }
2104  }
2105  }
2106 
2107  if ($object->statut == 0 && $nbofservices) {
2108  if ($user->rights->contrat->creer) {
2109  print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken(), '', true, $params);
2110  } else {
2111  $params['attr']['title'] = $langs->trans("NotEnoughPermissions");
2112  print dolGetButtonAction($langs->trans('Validate'), '', 'default', '#', '', false, $params);
2113  }
2114  }
2115  if ($object->statut == 1) {
2116  if ($user->rights->contrat->creer) {
2117  print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken(), '', true, $params);
2118  } else {
2119  $params['attr']['title'] = $langs->trans("NotEnoughPermissions");
2120  print dolGetButtonAction($langs->trans('Modify'), '', 'default', '#', '', false, $params);
2121  }
2122  }
2123 
2124  if (isModEnabled('commande') && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) {
2125  $langs->load("orders");
2126  if ($user->rights->commande->creer) {
2127  print dolGetButtonAction($langs->trans('CreateOrder'), '', 'default', DOL_URL_ROOT.'/commande/card.php?action=create&token='.newToken().'&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->thirdparty->id, '', true, $params);
2128  } else {
2129  $params['attr']['title'] = $langs->trans("NotEnoughPermissions");
2130  print dolGetButtonAction($langs->trans('CreateOrder'), '', 'default', '#', '', false, $params);
2131  }
2132  }
2133 
2134  if (isModEnabled('facture') && $object->statut > 0) {
2135  $langs->load("bills");
2136  if ($user->rights->facture->creer) {
2137  print dolGetButtonAction($langs->trans('CreateBill'), '', 'default', DOL_URL_ROOT.'/compta/facture/card.php?action=create&origin='.$object->element.'&originid='.$object->id.'&socid='.$object->thirdparty->id, '', true, $params);
2138  } else {
2139  $params['attr']['title'] = $langs->trans("NotEnoughPermissions");
2140  print dolGetButtonAction($langs->trans('CreateBill'), '', 'default', '#', '', false, $params);
2141  }
2142  }
2143 
2144  if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {
2145  if ($user->rights->contrat->activer) {
2146  print dolGetButtonAction($langs->trans('ActivateAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=activate&token='.newToken(), '', true, $params);
2147  } else {
2148  print dolGetButtonAction($langs->trans('ActivateAllContracts'), '', 'default', '#', '', false, $params);
2149  }
2150  }
2151  if ($object->nbofservicesclosed < $nbofservices) {
2152  if ($user->rights->contrat->desactiver) {
2153  print dolGetButtonAction($langs->trans('CloseAllContracts'), '', 'default', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=close&token='.newToken(), '', true, $params);
2154  } else {
2155  print dolGetButtonAction($langs->trans('CloseAllContracts'), '', 'default', '#', '', false, $params);
2156  }
2157 
2158  //if (! $numactive)
2159  //{
2160  //}
2161  //else
2162  //{
2163  // print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("CloseRefusedBecauseOneServiceActive").'">'.$langs->trans("Close").'</a></div>';
2164  //}
2165  }
2166 
2167  if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) {
2168  if ($action == 'showclosedlines') {
2169  print '<div class="inline-block divButAction"><a class="butAction" id="btnhideclosedlines" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=hideclosedlines">'.$langs->trans("HideClosedServices").'</a></div>';
2170  } else {
2171  print '<div class="inline-block divButAction"><a class="butAction" id="btnshowclosedlines" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=showclosedlines">'.$langs->trans("ShowClosedServices").'</a></div>';
2172  }
2173  }
2174 
2175  // Clone
2176  if ($user->rights->contrat->creer) {
2177  print dolGetButtonAction($langs->trans('ToClone'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken(), '', true, $params);
2178  }
2179 
2180  // Delete
2181  print dolGetButtonAction($langs->trans('Delete'), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), '', $permissiontodelete, $params);
2182  }
2183 
2184  print "</div>";
2185  }
2186 
2187  if ($action != 'presend') {
2188  print '<div class="fichecenter"><div class="fichehalfleft">';
2189 
2190  /*
2191  * Generated documents
2192  */
2193  $filename = dol_sanitizeFileName($object->ref);
2194  $filedir = $conf->contrat->multidir_output[$object->entity]."/".dol_sanitizeFileName($object->ref);
2195  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2196  $genallowed = $user->rights->contrat->lire;
2197  $delallowed = $user->rights->contrat->creer;
2198 
2199 
2200  print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, ($object->model_pdf ? $object->model_pdf : getDolGlobalString('CONTRACT_ADDON_PDF')), 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang, '', $object);
2201 
2202 
2203  // Show links to link elements
2204  $linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat'));
2205  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2206 
2207  // Show online signature link
2208  if ($object->statut != Contrat::STATUS_DRAFT && getDolGlobalString('CONTRACT_ALLOW_ONLINESIGN')) {
2209  print '<br><!-- Link to sign -->';
2210  require_once DOL_DOCUMENT_ROOT.'/core/lib/signature.lib.php';
2211 
2212  print showOnlineSignatureUrl('contract', $object->ref).'<br>';
2213  }
2214 
2215  print '</div><div class="fichehalfright">';
2216 
2217  $MAXEVENT = 10;
2218 
2219  $morehtmlcenter = dolGetButtonTitle($langs->trans('SeeAll'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/contrat/agenda.php?id='.$object->id);
2220 
2221 
2222  // List of actions on element
2223  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2224  $formactions = new FormActions($db);
2225  $somethingshown = $formactions->showactions($object, 'contract', $socid, 1, 'listactions', $MAXEVENT, '', $morehtmlcenter);
2226 
2227  print '</div></div>';
2228  }
2229 
2230  // Presend form
2231  $modelmail = 'contract';
2232  $defaulttopic = 'SendContractRef';
2233  $diroutput = $conf->contrat->multidir_output[$object->entity];
2234  $trackid = 'con'.$object->id;
2235 
2236  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2237  }
2238 }
2239 
2240 
2241 llxFooter();
2242 
2243 $db->close();
2244 ?>
2245 
2246 <?php
2247 if (isModEnabled('margin') && $action == 'editline') {
2248  // TODO Why this ? To manage margin on contracts ?
2249  ?>
2250 <script type="text/javascript">
2251 $(document).ready(function() {
2252  var idprod = $("input[name='idprod']").val();
2253  var fournprice = $("input[name='fournprice']").val();
2254  var token = '<?php echo currentToken(); ?>'; // For AJAX Call we use old 'token' and not 'newtoken'
2255  if (idprod > 0) {
2256  $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2257  'idprod': idprod,
2258  'token': token
2259  }, function(data) {
2260  if (data.length > 0) {
2261  var options = '';
2262  var trouve=false;
2263  $(data).each(function() {
2264  options += '<option value="'+this.id+'" price="'+this.price+'"';
2265  if (fournprice > 0) {
2266  if (this.id == fournprice) {
2267  options += ' selected';
2268  $("#buying_price").val(this.price);
2269  trouve = true;
2270  }
2271  }
2272  options += '>'+this.label+'</option>';
2273  });
2274  options += '<option value=null'+(trouve?'':' selected')+'><?php echo $langs->trans("InputPrice"); ?></option>';
2275  $("#fournprice").html(options);
2276  if (trouve) {
2277  $("#buying_price").hide();
2278  $("#fournprice").show();
2279  }
2280  else {
2281  $("#buying_price").show();
2282  }
2283  $("#fournprice").change(function() {
2284  var selval = $(this).find('option:selected').attr("price");
2285  if (selval)
2286  $("#buying_price").val(selval).hide();
2287  else
2288  $('#buying_price').show();
2289  });
2290  }
2291  else {
2292  $("#fournprice").hide();
2293  $('#buying_price').show();
2294  }
2295  },
2296  'json');
2297  }
2298  else {
2299  $("#fournprice").hide();
2300  $('#buying_price').show();
2301  }
2302 });
2303 </script>
2304  <?php
2305 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:50
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1504
dol_sanitizeFileName
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
Definition: functions.lib.php:1236
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
Project
Class to manage projects.
Definition: project.class.php:35
Productcustomerprice
File of class to manage predefined price products or services by customer.
Definition: productcustomerprice.class.php:29
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5363
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:530
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4994
FormActions
Class to manage building of HTML components.
Definition: html.formactions.class.php:30
dol_include_once
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
Definition: functions.lib.php:1043
Translate
Class to manage translations.
Definition: translate.class.php:30
dol_dir_list
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition: files.lib.php:61
FormProjets
Class to manage building of HTML components.
Definition: html.formprojet.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_clone
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
Definition: functions.lib.php:1168
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4539
dol_banner_tab
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Definition: functions.lib.php:2097
$help_url
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
price2num
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
Definition: functions.lib.php:5834
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2566
dol_concatdesc
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
Definition: functions.lib.php:7590
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4025
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
img_up
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
Definition: functions.lib.php:4765
$formactions
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
Definition: agenda_other.php:182
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4579
$formconfirm
$formconfirm
if ($action == 'delbookkeepingyear') {
Definition: listbyaccount.php:634
FormFile
Class to offer components to list and upload files.
Definition: html.formfile.class.php:36
get_localtax
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
Definition: functions.lib.php:6015
dolGetButtonTitle
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
Definition: functions.lib.php:11044
GETPOSTINT
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:847
dol_syslog
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
Definition: functions.lib.php:1639
img_down
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
Definition: functions.lib.php:4746
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1873
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3888
restrictedArea
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:341
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11317
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2069
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
Contrat
Class to manage contracts.
Definition: contrat.class.php:43
dol_time_plus_duree
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition: date.lib.php:122
User
Class to manage Dolibarr users.
Definition: user.class.php:44
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:431
dolGetButtonAction
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
Definition: functions.lib.php:10880
ExtraFields
Class to manage standard extra fields.
Definition: extrafields.class.php:39
Product
Class to manage products or services.
Definition: product.class.php:46
ContratLigne
Class to manage lines of contracts.
Definition: contrat.class.php:2860
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
contract_prepare_head
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
Definition: contract.lib.php:31
$parameters
$parameters
Actions.
Definition: card.php:79
dol_htmlentitiesbr
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Definition: functions.lib.php:7325
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2947
price
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
Definition: functions.lib.php:5708
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8509
dol_mkdir
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
Definition: functions.lib.php:6811
dol_mktime
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Definition: functions.lib.php:2859
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96
type
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
Definition: repair.php:119
DolEditor
Class to manage a WYSIWYG editor.
Definition: doleditor.class.php:30
vatrate
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
Definition: functions.lib.php:5659
dol_move
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
Definition: files.lib.php:875