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