34 require
"../main.inc.php";
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/contract.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
45 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
51 require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
54 $langs->loadLangs(array(
"contracts",
"orders",
"companies",
"bills",
"products",
'compta'));
56 $action =
GETPOST(
'action',
'aZ09');
57 $confirm =
GETPOST(
'confirm',
'alpha');
58 $cancel =
GETPOST(
'cancel',
'alpha');
60 $socid =
GETPOST(
'socid',
'int');
63 $origin =
GETPOST(
'origin',
'alpha');
64 $originid =
GETPOST(
'originid',
'int');
67 $usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
71 $socid = $user->socid;
76 $hookmanager->initHooks(array(
'contractcard',
'globalcard'));
82 if ($id > 0 || !empty($ref) && $action !=
'add') {
83 $ret = $object->fetch($id, $ref);
85 $ret = $object->fetch_thirdparty();
93 $extrafields->fetch_name_optionals_label($object->table_element);
96 $extralabelslines = $extrafields->fetch_name_optionals_label($object->table_element_line);
98 $permissionnote = $user->rights->contrat->creer;
99 $permissiondellink = $user->rights->contrat->creer;
100 $permissiontodelete = ($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer;
101 $permissiontoadd = $user->rights->contrat->creer;
102 $permissiontoedit = $permissiontoadd;
111 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
115 if (empty($reshook)) {
116 $backurlforlist = DOL_URL_ROOT.
'/contrat/list.php';
118 if (empty($backtopage) || ($cancel && empty($id))) {
119 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
120 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
121 $backtopage = $backurlforlist;
123 $backtopage = DOL_URL_ROOT.
'/contrat/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
129 if (!empty($backtopageforcancel)) {
130 header(
"Location: ".$backtopageforcancel);
132 } elseif (!empty($backtopage)) {
133 header(
"Location: ".$backtopage);
139 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
141 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
143 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
145 if ($action ==
'confirm_active' && $confirm ==
'yes' && $user->rights->contrat->activer) {
155 $result = $object->active_line($user,
GETPOST(
'ligne',
'int'), $date_start, $date_end,
GETPOST(
'comment'));
158 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
163 } elseif ($action ==
'confirm_closeline' && $confirm ==
'yes' && $user->rights->contrat->activer) {
170 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEnd")),
null,
'errors');
173 $result = $object->close_line($user,
GETPOST(
'ligne',
'int'), $date_end, urldecode(
GETPOST(
'comment')));
175 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
184 if (
GETPOST(
'mode') ==
'predefined') {
196 $date_start_update =
'';
197 $date_end_update =
'';
198 $date_start_real_update =
'';
199 $date_end_real_update =
'';
200 if (
GETPOST(
'date_start_updatemonth') &&
GETPOST(
'date_start_updateday') &&
GETPOST(
'date_start_updateyear')) {
203 if (
GETPOST(
'date_end_updatemonth') &&
GETPOST(
'date_end_updateday') &&
GETPOST(
'date_end_updateyear')) {
206 if (
GETPOST(
'date_start_real_updatemonth') &&
GETPOST(
'date_start_real_updateday') &&
GETPOST(
'date_start_real_updateyear')) {
207 $date_start_real_update =
dol_mktime(
GETPOST(
'date_start_real_updatehour'),
GETPOST(
'date_start_real_updatemin'), 0,
GETPOST(
'date_start_real_updatemonth'),
GETPOST(
'date_start_real_updateday'),
GETPOST(
'date_start_real_updateyear'));
209 if (
GETPOST(
'date_end_real_updatemonth') &&
GETPOST(
'date_end_real_updateday') &&
GETPOST(
'date_end_real_updateyear')) {
210 $date_end_real_update =
dol_mktime(
GETPOST(
'date_end_real_updatehour'),
GETPOST(
'date_end_real_updatemin'), 0,
GETPOST(
'date_end_real_updatemonth'),
GETPOST(
'date_end_real_updateday'),
GETPOST(
'date_end_real_updateyear'));
217 if ($action ==
'add' && $user->hasRight(
'contrat',
'creer')) {
219 if (empty($datecontrat)) {
221 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
226 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
232 $ret = $extrafields->setOptionalsFromPost(
null, $object);
239 $object->socid = $socid;
240 $object->date_contrat = $datecontrat;
242 $object->commercial_suivi_id =
GETPOST(
'commercial_suivi_id',
'int');
243 $object->commercial_signature_id =
GETPOST(
'commercial_signature_id',
'int');
245 $object->note_private =
GETPOST(
'note_private',
'alpha');
246 $object->note_public =
GETPOST(
'note_public',
'alpha');
247 $object->fk_project =
GETPOST(
'projectid',
'int');
249 $object->ref =
GETPOST(
'ref',
'alpha');
250 $object->ref_customer =
GETPOST(
'ref_customer',
'alpha');
251 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
254 if (!empty($origin) && !empty($originid)) {
256 $element = $subelement = $origin;
257 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
259 $subelement = $regs[2];
263 if ($element ==
'order') {
264 $element = $subelement =
'commande';
266 if ($element ==
'propal') {
267 $element =
'comm/propal'; $subelement =
'propal';
269 if ($element ==
'invoice' || $element ==
'facture') {
270 $element =
'compta/facture';
271 $subelement =
'facture';
274 $object->origin = $origin;
275 $object->origin_id = $originid;
278 $object->linked_objects[$object->origin] = $object->origin_id;
279 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
280 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
283 $id = $object->create($user);
287 $classname = ucfirst($subelement);
288 $srcobject =
new $classname($db);
290 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
291 $result = $srcobject->fetch($object->origin_id);
293 $srcobject->fetch_thirdparty();
294 $lines = $srcobject->lines;
295 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
296 $srcobject->fetch_lines();
297 $lines = $srcobject->lines;
301 $num = count($lines);
303 for ($i = 0; $i < $num; $i++) {
304 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
306 if ($product_type == 1 || (!empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0, 1)))) {
308 if ($lines[$i]->fk_product > 0) {
309 $product_static =
new Product($db);
312 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
314 $prod->id = $lines[$i]->fk_product;
315 $prod->getMultiLangs();
317 $outputlangs = $langs;
319 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
320 $newlang =
GETPOST(
'lang_id',
'aZ09');
322 if (empty($newlang)) {
323 $newlang = $srcobject->thirdparty->default_lang;
325 if (!empty($newlang)) {
327 $outputlangs->setDefaultLang($newlang);
330 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"libelle"])) ? $prod->multilangs[$outputlangs->defaultlang][
"libelle"] : $lines[$i]->product_label;
332 $label = $lines[$i]->product_label;
334 $desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->libelle) ?
dol_htmlentitiesbr($lines[$i]->desc) :
'';
340 $array_options = array();
342 if (method_exists($lines[$i],
'fetch_optionals')) {
343 $lines[$i]->fetch_optionals();
344 $array_options = $lines[$i]->array_options;
347 $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx.
' ('.$lines[$i]->vat_src_code.
')' : $lines[$i]->tva_tx;
350 $localtax1_tx =
get_localtax($txtva, 1, $object->thirdparty);
351 $localtax2_tx =
get_localtax($txtva, 2, $object->thirdparty);
353 $result = $object->addline(
355 $lines[$i]->subprice,
360 $lines[$i]->fk_product,
361 $lines[$i]->remise_percent,
362 $lines[$i]->date_start,
363 $lines[$i]->date_end,
366 $lines[$i]->info_bits,
367 $lines[$i]->fk_fournprice,
387 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
401 $result = $object->create($user);
403 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
411 } elseif ($action ==
'classin' && $user->hasRight(
'contrat',
'creer')) {
412 $object->setProject(
GETPOST(
'projectid'));
413 } elseif ($action ==
'addline' && $user->hasRight(
'contrat',
'creer')) {
420 $price_ht_devise =
'';
422 $price_ttc_devise =
'';
424 $rang = count($object->lines) + 1;
426 if (
GETPOST(
'price_ht') !==
'') {
429 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
432 if (
GETPOST(
'price_ttc') !==
'') {
435 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
439 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free') {
442 $idprod =
GETPOST(
'idprod',
'int');
445 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
449 if (empty($remise_percent)) {
454 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
457 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
458 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
464 if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
465 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
470 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
471 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
473 if (is_array($extralabelsline)) {
475 foreach ($extralabelsline as $key => $value) {
476 unset($_POST[
"options_".$key]);
489 $prod->fetch($idprod);
498 $price_min = $prod->price_min;
499 $price_min_ttc = $prod->price_min_ttc;
502 if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) {
503 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
504 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
505 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
507 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
511 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
513 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
515 if (count($prodcustprice->lines) > 0) {
516 $price_min =
price($prodcustprice->lines[0]->price_min);
517 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
530 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
531 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
534 if (!empty($price_ht) || $price_ht ===
'0') {
536 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
537 $price_base_type =
'HT';
538 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
540 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
541 $price_base_type =
'TTC';
544 $desc = $prod->description;
547 if ($product_desc == $desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
551 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
552 $desc = $product_desc;
554 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
557 $fk_unit = $prod->fk_unit;
561 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
562 if (empty($tva_tx)) {
565 $tva_tx = str_replace(
'*',
'', $tva_tx);
566 $desc = $product_desc;
567 $fk_unit =
GETPOST(
'units',
'alpha');
568 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
569 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
571 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
574 if (!empty($price_ht) || $price_ht ===
'0') {
576 $pu_ttc =
price2num($pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
577 $price_base_type =
'HT';
578 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
580 $pu_ht =
price2num($pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
581 $price_base_type =
'TTC';
585 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
586 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
589 $fk_fournprice =
GETPOST(
'fournprice');
591 $pa_ht =
GETPOST(
'buying_price');
601 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance))
602 || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
603 $object->error = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
607 $result = $object->addline(
631 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) {
632 $outputlangs = $langs;
635 $newlang =
GETPOST(
'lang_id',
'aZ09');
638 $newlang = $object->thirdparty->default_lang;
640 if (!empty($newlang)) {
642 $outputlangs->setDefaultLang($newlang);
645 $ret = $object->fetch($id);
647 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
650 unset($_POST[
'prod_entry_mode']);
652 unset($_POST[
'qty']);
653 unset($_POST[
'type']);
654 unset($_POST[
'remise_percent']);
655 unset($_POST[
'price_ht']);
656 unset($_POST[
'multicurrency_price_ht']);
657 unset($_POST[
'price_ttc']);
658 unset($_POST[
'tva_tx']);
659 unset($_POST[
'product_ref']);
660 unset($_POST[
'product_label']);
661 unset($_POST[
'product_desc']);
662 unset($_POST[
'fournprice']);
663 unset($_POST[
'buying_price']);
664 unset($_POST[
'np_marginRate']);
665 unset($_POST[
'np_markRate']);
666 unset($_POST[
'dp_desc']);
667 unset($_POST[
'idprod']);
669 unset($_POST[
'date_starthour']);
670 unset($_POST[
'date_startmin']);
671 unset($_POST[
'date_startsec']);
672 unset($_POST[
'date_startday']);
673 unset($_POST[
'date_startmonth']);
674 unset($_POST[
'date_startyear']);
675 unset($_POST[
'date_endhour']);
676 unset($_POST[
'date_endmin']);
677 unset($_POST[
'date_endsec']);
678 unset($_POST[
'date_endday']);
679 unset($_POST[
'date_endmonth']);
680 unset($_POST[
'date_endyear']);
685 } elseif ($action ==
'updateline' && $user->hasRight(
'contrat',
'creer') && !
GETPOST(
'cancel',
'alpha')) {
689 if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
690 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
691 $action =
'editline';
692 $_GET[
'rowid'] =
GETPOST(
'elrowid');
698 if ($objectline->fetch(
GETPOST(
'elrowid',
'int')) < 0) {
702 $objectline->fetch_optionals();
704 $objectline->oldcopy =
dol_clone($objectline);
710 if ($date_start_real_update ==
'') {
711 $date_start_real_update = $objectline->date_start_real;
713 if ($date_end_real_update ==
'') {
714 $date_end_real_update = $objectline->date_end_real;
717 $vat_rate =
GETPOST(
'eltva_tx',
'alpha');
720 if (preg_match(
'/\*/', $vat_rate)) {
725 $vat_rate = str_replace(
'*',
'', $vat_rate);
726 $localtax1_tx =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
727 $localtax2_tx =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
734 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
735 $vat_src_code = $reg[1];
736 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
746 $fk_unit =
GETPOST(
'unit',
'alpha');
748 $objectline->fk_product =
GETPOST(
'idprod',
'int');
749 $objectline->description =
GETPOST(
'product_desc',
'restricthtml');
754 $objectline->tva_tx = ($txtva ? $txtva : 0);
755 $objectline->vat_src_code = $vat_src_code;
756 $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
757 $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
758 $objectline->date_start = $date_start_update;
759 $objectline->date_start_real = $date_start_real_update;
760 $objectline->date_end = $date_end_update;
761 $objectline->date_end_real = $date_end_real_update;
762 $objectline->fk_user_cloture = $user->id;
764 $objectline->pa_ht = $pa_ht;
765 $objectline->rang = $objectline->rang;
768 $objectline->fk_unit =
GETPOST(
'unit');
770 $objectline->fk_unit =
null;
774 $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
775 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
777 if (is_array($array_options) && count($array_options) > 0) {
779 foreach ($array_options as $key => $value) {
780 $objectline->array_options[$key] = $array_options[$key];
786 $result = $objectline->update($user);
798 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
799 $result = $object->deleteline(
GETPOST(
'lineid',
'int'), $user);
802 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
807 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
808 $result = $object->validate($user);
812 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
813 $outputlangs = $langs;
816 $newlang =
GETPOST(
'lang_id',
'aZ09');
819 $newlang = $object->thirdparty->default_lang;
821 if (!empty($newlang)) {
823 $outputlangs->setDefaultLang($newlang);
825 $model = $object->model_pdf;
826 $ret = $object->fetch($id);
828 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
833 } elseif ($action ==
'reopen' && $user->hasRight(
'contrat',
'creer')) {
834 $result = $object->reopen($user);
838 } elseif ($action ==
'confirm_close' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
840 $result = $object->closeAll($user);
844 } elseif ($action ==
'confirm_activate' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
847 $comment =
GETPOST(
'comment',
'alpha');
848 $result = $object->activateAll($user, $date_start, 0, $comment, $date_end);
852 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->contrat->supprimer) {
853 $result = $object->delete($user);
855 header(
"Location: list.php?restore_lastsearch_values=1");
860 } elseif ($action ==
'confirm_move' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
863 $result = $contractline->fetch(
GETPOSTINT(
'lineid'));
864 $contractline->fk_contrat =
GETPOSTINT(
'newcid');
865 $result = $contractline->update($user, 1);
867 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
873 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"RefNewContract")),
null,
'errors');
875 } elseif ($action ==
'update_extras') {
879 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
885 $result = $object->insertExtraFields(
'CONTRACT_MODIFY');
893 $action =
'edit_extras';
895 } elseif ($action ==
'setref_supplier') {
899 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
902 $action =
'editref_supplier';
904 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
908 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
911 } elseif ($action ==
'setref_customer') {
915 $result = $object->setValueFrom(
'ref_customer',
GETPOST(
'ref_customer',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
918 $action =
'editref_customer';
920 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
924 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
927 } elseif ($action ==
'setref') {
929 $result = $object->fetch($id);
934 $old_ref = $object->ref;
936 $result = $object->setValueFrom(
'ref',
GETPOST(
'ref',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
941 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
942 $old_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($old_ref);
943 $new_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
946 if (!empty($files)) {
947 if (!is_dir($new_filedir)) {
950 foreach ($files as $file) {
951 dol_move($file[
'fullname'], $new_filedir.
'/'.$file[
'name']);
955 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
959 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
962 } elseif ($action ==
'setdate_contrat') {
964 $result = $object->fetch($id);
969 $result = $object->setValueFrom(
'date_contrat', $datacontrat,
'',
null,
'date',
'', $user,
'CONTRACT_MODIFY');
972 $action =
'editdate_contrat';
974 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
978 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
984 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
987 $upload_dir = $conf->contrat->multidir_output[$object->entity];
988 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
991 $triggersendname =
'CONTRACT_SENTBYMAIL';
993 $mode =
'emailfromcontract';
994 $trackid =
'con'.$object->id;
995 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
998 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->hasRight(
'contrat',
'creer')) {
999 if ($action ==
'addcontact') {
1002 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1005 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1008 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1009 $langs->load(
"errors");
1010 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1015 } elseif ($action ==
'swapstatut') {
1017 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1018 } elseif ($action ==
'deletecontact') {
1020 $result = $object->delete_contact(
GETPOST(
'lineid',
'int'));
1023 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1032 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
1034 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1036 if ($object->id > 0) {
1037 $result = $object->createFromClone($user, $socid);
1039 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1042 if (count($object->errors) > 0) {
1058 $help_url =
'EN:Module_Contracts|FR:Module_Contrat';
1069 $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON :
'mod_contract_serpis');
1070 if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
1071 $module = substr($module, 0,
dol_strlen($module) - 4);
1075 $modCodeContract =
new $module();
1079 if ($action ==
'create') {
1084 $soc->fetch($socid);
1090 $element = $subelement =
GETPOST(
'origin');
1091 if (preg_match(
'/^([^_]+)_([^_]+)/i',
GETPOST(
'origin'), $regs)) {
1092 $element = $regs[1];
1093 $subelement = $regs[2];
1096 if ($element ==
'project') {
1097 $projectid =
GETPOST(
'originid',
'int');
1100 if ($element ==
'order' || $element ==
'commande') {
1101 $element = $subelement =
'commande';
1103 if ($element ==
'propal') {
1104 $element =
'comm/propal'; $subelement =
'propal';
1106 if ($element ==
'invoice' || $element ==
'facture') {
1107 $element =
'compta/facture';
1108 $subelement =
'facture';
1113 $classname = ucfirst($subelement);
1114 $objectsrc =
new $classname($db);
1115 $objectsrc->fetch($originid);
1116 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1117 $objectsrc->fetch_lines();
1119 $objectsrc->fetch_thirdparty();
1122 $objectsrc->fetch_optionals();
1123 $object->array_options = $objectsrc->array_options;
1125 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1127 $soc = $objectsrc->thirdparty;
1129 $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private :
'');
1130 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public :
'');
1133 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1136 $projectid =
GETPOST(
'projectid',
'int');
1137 $note_private =
GETPOST(
"note_private");
1138 $note_public =
GETPOST(
"note_public");
1141 $object->date_contrat =
dol_now();
1143 print
'<form name="form_contract" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1144 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1146 print
'<input type="hidden" name="action" value="add">';
1147 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1148 print
'<input type="hidden" name="remise_percent" value="0">';
1152 print
'<table class="border centpercent">';
1155 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>';
1156 if (!empty($modCodeContract->code_auto)) {
1157 $tmpcode = $langs->trans(
"Draft");
1159 $tmpcode =
'<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(
GETPOST(
'ref') ?
GETPOST(
'ref') : $tmpcode).
'">';
1165 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
1166 print
'<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(
GETPOST(
'ref_customer',
'alpha')).
'"></td></tr>';
1169 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td>';
1170 print
'<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(
GETPOST(
'ref_supplier',
'alpha')).
'"></td></tr>';
1174 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1177 print $soc->getNomUrl(1);
1178 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1182 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
1183 print
$form->select_company(
'',
'socid',
'',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
1184 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
1191 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1192 if ($soc->remise_percent) {
1193 print $langs->trans(
"CompanyHasRelativeDiscount", $soc->remise_percent).
' ';
1195 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1197 $absolute_discount = $soc->getAvailableDiscounts();
1198 if ($absolute_discount) {
1199 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1201 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1207 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPFOLL").
'</span></td><td>';
1208 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1209 print
$form->select_dolusers(
GETPOST(
"commercial_suivi_id") ?
GETPOST(
"commercial_suivi_id") : $user->id,
'commercial_suivi_id', 1,
'');
1213 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPSIGN").
'</span></td><td>';
1214 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1215 print
$form->select_dolusers(
GETPOST(
"commercial_signature_id") ?
GETPOST(
"commercial_signature_id") : $user->id,
'commercial_signature_id', 1,
'');
1218 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Date").
'</span></td><td>';
1219 print
$form->selectDate($datecontrat,
'', 0, 0,
'',
"contrat");
1224 $langs->load(
'projects');
1228 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
1229 $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
"projectid", 0, 0, 1, 1);
1230 print
' <a href="'.DOL_URL_ROOT.
'/projet/card.php?socid='.$soc->id.
'&action=create&status=1&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create&socid='.$soc->id).
'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans(
"AddProject").
'"></span></a>';
1234 print
'<tr><td>'.$langs->trans(
"NotePublic").
'</td><td class="tdtop">';
1235 $doleditor =
new DolEditor(
'note_public', $note_public,
'',
'100',
'dolibarr_notes',
'In', 1,
true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3,
'90%');
1236 print $doleditor->Create(1);
1239 if (empty($user->socid)) {
1240 print
'<tr><td>'.$langs->trans(
"NotePrivate").
'</td><td class="tdtop">';
1241 $doleditor =
new DolEditor(
'note_private', $note_private,
'',
'100',
'dolibarr_notes',
'In', 1,
true, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3,
'90%');
1242 print $doleditor->Create(1);
1247 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="3"',
'cols' =>
'3');
1248 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1249 print $hookmanager->resPrint;
1252 if (empty($reshook)) {
1253 print $object->showOptionals($extrafields,
'create',
$parameters);
1260 print
$form->buttonsSaveCancel(
"Create");
1262 if (is_object($objectsrc)) {
1263 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1264 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1266 if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
1267 print
'<br>'.$langs->trans(
"Note").
': '.$langs->trans(
"OnlyLinesWithTypeServiceAreUsed");
1276 if ($object->id > 0) {
1277 $object->fetch_thirdparty();
1279 $soc = $object->thirdparty;
1281 $result = $object->fetch_lines();
1286 $nbofservices = count($object->lines);
1288 $author =
new User($db);
1289 $author->fetch($object->user_author_id);
1291 $commercial_signature =
new User($db);
1292 $commercial_signature->fetch($object->commercial_signature_id);
1294 $commercial_suivi =
new User($db);
1295 $commercial_suivi->fetch($object->commercial_suivi_id);
1302 print
dol_get_fiche_head($head, $hselected, $langs->trans(
"Contract"), -1,
'contract');
1305 if ($action ==
'delete') {
1307 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"DeleteAContract"), $langs->trans(
"ConfirmDeleteAContract"),
"confirm_delete",
'', 0, 1);
1308 } elseif ($action ==
'valid') {
1310 $ref = substr($object->ref, 1, 4);
1311 if ($ref ==
'PROV' && !empty($modCodeContract->code_auto)) {
1312 $numref = $object->getNextNumRef($object->thirdparty);
1314 $numref = $object->ref;
1316 $text = $langs->trans(
'ConfirmValidateContract', $numref);
1317 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ValidateAContract"), $text,
"confirm_valid",
'', 0, 1);
1318 } elseif ($action ==
'close') {
1320 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"CloseAContract"), $langs->trans(
"ConfirmCloseContract"),
"confirm_close",
'', 0, 1);
1321 } elseif ($action ==
'activate') {
1322 $formquestion = array(
1323 array(
'type' =>
'date',
'name' =>
'd_start',
'label' => $langs->trans(
"DateServiceActivate"),
'value' =>
dol_now()),
1324 array(
'type' =>
'date',
'name' =>
'd_end',
'label' => $langs->trans(
"DateEndPlanned"),
'',
''),
1325 array(
'type' =>
'text',
'name' =>
'comment',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'',
'',
'class' =>
'minwidth300',
'moreattr'=>
'autofocus')
1327 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ActivateAllOnContract"), $langs->trans(
"ConfirmActivateAllOnContract"),
"confirm_activate", $formquestion,
'yes', 1, 280);
1328 } elseif ($action ==
'clone') {
1330 $formquestion = array(array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' =>
$form->select_company(
GETPOST(
'socid',
'int'),
'socid',
'(s.client=1 OR s.client=2 OR s.client=3)')));
1331 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneContract', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1342 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
1343 if (empty($reshook)) {
1345 } elseif ($reshook > 0) {
1354 if (!empty($object->brouillon) && $user->hasRight(
'contrat',
'creer')) {
1355 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="POST">';
1356 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1357 print
'<input type="hidden" name="action" value="setremise">';
1362 $linkback =
'<a href="'.DOL_URL_ROOT.
'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1366 if (!empty($modCodeContract->code_auto)) {
1367 $morehtmlref .= $object->ref;
1369 $morehtmlref .=
$form->editfieldkey(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 3);
1370 $morehtmlref .=
$form->editfieldval(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 2);
1373 $morehtmlref .=
'<div class="refidno">';
1375 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1376 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer,
'string'.(isset($conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':'.$conf->global->THIRDPARTY_REF_INPUT_SIZE :
''),
'',
null,
null,
'', 1,
'getFormatedCustomerRef');
1378 $morehtmlref .=
'<br>';
1379 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1380 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'',
null,
null,
'', 1,
'getFormatedSupplierRef');
1382 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1);
1383 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
1384 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/contrat/list.php?socid='.$object->thirdparty->id.
'&search_name='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherContracts").
'</a>)';
1388 $langs->load(
"projects");
1389 $morehtmlref .=
'<br>';
1390 if ($permissiontoadd) {
1391 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1392 if ($action !=
'classify') {
1393 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
1395 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
1397 if (!empty($object->fk_project)) {
1399 $proj->fetch($object->fk_project);
1400 $morehtmlref .= $proj->getNomUrl(1);
1402 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
1407 $morehtmlref .=
'</div>';
1410 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'none', $morehtmlref);
1413 print
'<div class="fichecenter">';
1414 print
'<div class="underbanner clearboth"></div>';
1417 print
'<table class="border tableforfield" width="100%">';
1420 print
'<tr><td class="titlefield">'.$langs->trans(
'Discount').
'</td><td colspan="3">';
1421 if ($object->thirdparty->remise_percent) {
1422 print $langs->trans(
"CompanyHasRelativeDiscount", $object->thirdparty->remise_percent).
'. ';
1424 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1426 $absolute_discount = $object->thirdparty->getAvailableDiscounts();
1427 if ($absolute_discount) {
1428 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1430 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1436 print
'<td class="titlefield">';
1437 print
$form->editfieldkey(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer);
1439 print
$form->editfieldval(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer,
'datehourpicker');
1445 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1451 if (!empty($object->brouillon) && $user->hasRight(
'contrat',
'creer')) {
1457 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1458 $blocname =
'contacts';
1459 $title = $langs->trans(
'ContactsAddresses');
1460 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1463 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1464 $blocname =
'notes';
1465 $title = $langs->trans(
'Notes');
1466 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1470 $arrayothercontracts = $object->getListOfContracts(
'others');
1478 global $inputalsopricewithtax;
1479 $inputalsopricewithtax = 1;
1481 $productstatic =
new Product($db);
1484 if (
isModEnabled(
'margin') && !empty($object->element) && in_array($object->element, array(
'facture',
'propal',
'commande'))) {
1492 print
'<div id="contrat-lines-container" id="contractlines" data-contractid="'.$object->id.
'" data-element="'.$object->element.
'" >';
1493 while ($cursorline <= $nbofservices) {
1494 print
'<div id="contrat-line-container'.$object->lines[$cursorline - 1]->id.
'" data-contratlineid = "'.$object->lines[$cursorline - 1]->id.
'" data-element="'.$object->lines[$cursorline - 1]->element.
'" >';
1495 print
'<form name="update" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="post">';
1496 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1497 print
'<input type="hidden" name="action" value="updateline">';
1498 print
'<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.
'">';
1499 print
'<input type="hidden" name="fournprice" value="'.(!empty($object->lines[$cursorline - 1]->fk_fournprice) ? $object->lines[$cursorline - 1]->fk_fournprice : 0).
'">';
1502 print
'<div class="div-table-responsive-no-min">';
1503 print
'<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">';
1505 $sql =
"SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,";
1506 $sql .=
" cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1507 $sql .=
" cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";
1508 $sql .=
" cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";
1509 $sql .=
" cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1510 $sql .=
" cd.fk_unit,";
1511 $sql .=
" p.rowid as pid, p.ref as pref, p.label as plabel, p.fk_product_type as ptype, p.entity as pentity, p.tosell, p.tobuy, p.tobatch";
1512 $sql .=
" ,cd.rang";
1513 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
1514 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
1515 $sql .=
" WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id);
1517 $result = $db->query(
$sql);
1521 $objp = $db->fetch_object($result);
1523 print
'<tr class="liste_titre'.($cursorline ?
' liste_titre_add' :
'').
'">';
1524 print
'<td>'.$langs->trans(
"ServiceNb", $cursorline).
'</td>';
1525 print
'<td width="80" class="center">'.$langs->trans(
"VAT").
'</td>';
1526 print
'<td width="80" class="right">'.$langs->trans(
"PriceUHT").
'</td>';
1530 print
'<td width="30" class="center">'.$langs->trans(
"Qty").
'</td>';
1532 print
'<td width="30" class="left">'.$langs->trans(
"Unit").
'</td>';
1534 print
'<td width="50" class="right">'.$langs->trans(
"ReductionShort").
'</td>';
1535 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1536 print
'<td width="50" class="right">'.$langs->trans(
"BuyingPrice").
'</td>';
1540 if ($nbofservices > 1 && $conf->browser->layout !=
'phone' && !empty($user->rights->contrat->creer)) {
1541 print
'<td width="30" class="linecolmove tdlineupdown center">';
1542 if ($cursorline > 1) {
1543 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=up&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1544 echo
img_up(
'default', 0,
'imgupforline');
1547 if ($cursorline < $nbofservices) {
1548 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=down&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1549 echo
img_down(
'default', 0,
'imgdownforline');
1554 print
'<td width="30"> </td>';
1562 if ($action !=
'editline' ||
GETPOST(
'rowid') != $objp->rowid) {
1564 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1565 $moreparam =
'style="display: none;"';
1567 print
'<tr class="tdtop oddeven" '.$moreparam.
'>';
1569 if ($objp->fk_product > 0) {
1570 $productstatic->id = $objp->fk_product;
1571 $productstatic->type = $objp->ptype;
1572 $productstatic->ref = $objp->pref;
1573 $productstatic->entity = $objp->pentity;
1574 $productstatic->label = $objp->plabel;
1575 $productstatic->status = $objp->tosell;
1576 $productstatic->status_buy = $objp->tobuy;
1577 $productstatic->status_batch = $objp->tobatch;
1580 $text = $productstatic->getNomUrl(1,
'', 32);
1581 if ($objp->plabel) {
1583 $text .= $objp->plabel;
1585 $description = $objp->description;
1589 $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ?
'<br>'.
dol_htmlentitiesbr($objp->description) :
'';
1593 echo
$form->textwithtooltip($text, $description, 3,
'',
'', $cursorline, 0, (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
1597 print
'<td>'.img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description).
"</td>\n";
1600 print
'<td class="center">';
1601 print
vatrate($objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''),
'%', $objp->info_bits);
1604 print
'<td class="right">'.($objp->subprice !=
'' ?
price($objp->subprice) :
'').
"</td>\n";
1610 print
'<td class="center">'.$objp->qty.
'</td>';
1613 print
'<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).
'</td>';
1616 if ($objp->remise_percent > 0) {
1617 print
'<td class="right">'.$objp->remise_percent.
"%</td>\n";
1619 print
'<td> </td>';
1623 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1624 print
'<td class="right nowraponall">'.price($objp->pa_ht).
'</td>';
1628 print
'<td class="nowraponall right">';
1629 if ($user->rights->contrat->creer && is_array($arrayothercontracts) && count($arrayothercontracts) && ($object->statut >= 0)) {
1630 print
'<!-- link to move service line into another contract -->';
1631 print
'<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=move&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1632 print
img_picto($langs->trans(
"MoveToAnotherContract"),
'uparrow');
1635 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1636 print
'<a class="reposition marginrightonly editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1640 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1641 print
'<a class="reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=deleteline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1650 if ($objp->subprice >= 0) {
1659 print
'<tr class="oddeven" '.$moreparam.
'>';
1660 print
'<td colspan="'.$colspan.
'">';
1663 print $langs->trans(
"DateStartPlanned").
': ';
1664 if ($objp->date_start) {
1667 if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now - $conf->contrat->services->inactifs->warning_delay)) {
1668 $warning_delay = $conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1669 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1670 print
" ".img_warning($textlate);
1673 print $langs->trans(
"Unknown");
1675 print
' - ';
1676 print $langs->trans(
"DateEndPlanned").
': ';
1677 if ($objp->date_end) {
1679 if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now - $conf->contrat->services->expires->warning_delay)) {
1680 $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
1681 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1682 print
" ".img_warning($textlate);
1685 print $langs->trans(
"Unknown");
1693 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1695 $line->id = $objp->rowid;
1696 $line->fetch_optionals();
1697 print $line->showOptionals($extrafields,
'view', array(
'class'=>
'oddeven',
'style'=>$moreparam,
'colspan'=>$colspan),
'',
'', 1);
1702 print
'<tr class="oddeven">';
1704 if ($objp->fk_product > 0) {
1705 $canchangeproduct = 1;
1706 if (empty($canchangeproduct)) {
1707 $productstatic->id = $objp->fk_product;
1708 $productstatic->type = $objp->ptype;
1709 $productstatic->ref = $objp->pref;
1710 $productstatic->entity = $objp->pentity;
1711 print $productstatic->getNomUrl(1,
'', 32);
1712 print $objp->label ?
' - '.dol_trunc($objp->label, 32) :
'';
1713 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1715 $senderissupplier = 0;
1716 if (empty($senderissupplier)) {
1717 print
$form->select_produits((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1719 $form->select_produits_fournisseurs((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1724 print $objp->label ? $objp->label.
'<br>' :
'';
1725 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1729 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1731 if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1732 $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1734 $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1735 $doleditor =
new DolEditor(
'product_desc', $objp->description,
'', 92,
'dolibarr_details',
'',
false,
true, $enable, $nbrows,
'90%');
1736 $doleditor->Create();
1741 print
'<td class="right">';
1742 print
$form->load_tva(
"eltva_tx", $objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''), $mysoc, $object->thirdparty, $objp->fk_product, $objp->info_bits, $objp->product_type, 0, 1);
1746 print
'<td class="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).
'"></td>';
1754 print
'<td class="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.
'"></td>';
1758 print
'<td class="left">';
1759 print
$form->selectUnits($objp->fk_unit,
"unit");
1764 print
'<td class="nowrap right"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.
'">%</td>';
1766 if (!empty($usemargins)) {
1767 print
'<td class="right">';
1768 if ($objp->fk_product) {
1769 print
'<select id="fournprice" name="fournprice"></select>';
1771 print
'<input id="buying_price" type="text" size="5" name="buying_price" value="'.price($objp->pa_ht, 0,
'', 0).
'"></td>';
1773 print
'<td class="center">';
1774 print
'<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans(
"Modify").
'">';
1775 print
'<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1780 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1788 print
'<tr class="oddeven">';
1789 print
'<td colspan="'.$colspan.
'">';
1790 print $langs->trans(
"DateStartPlanned").
' ';
1791 print
$form->selectDate($db->jdate($objp->date_start),
"date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1),
"update");
1792 print
' '.$langs->trans(
"DateEndPlanned").
' ';
1793 print
$form->selectDate($db->jdate($objp->date_end),
"date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1),
"update");
1797 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1799 $line->id = $objp->rowid;
1800 $line->fetch_optionals();
1801 print $line->showOptionals($extrafields,
'edit', array(
'style'=>
'class="oddeven"',
'colspan'=>$colspan),
'',
'', 1);
1810 if ($object->statut > 0) {
1812 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1813 $moreparam =
'style="display: none;"';
1815 print
'<tr class="oddeven" '.$moreparam.
'>';
1816 print
'<td class="tdhrthin" colspan="'.($conf->margin->enabled ? 7 : 6).
'"><hr class="opacitymedium tdhrthin"></td>';
1829 if ($action ==
'deleteline' && !$_REQUEST[
"cancel"] && $user->hasRight(
'contrat',
'creer') && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1830 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid'), $langs->trans(
"DeleteContractLine"), $langs->trans(
"ConfirmDeleteContractLine"),
"confirm_deleteline",
'', 0, 1);
1831 if ($ret ==
'html') {
1832 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1839 if ($action ==
'move' && !$_REQUEST[
"cancel"] && $user->hasRight(
'contrat',
'creer') && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1840 $arraycontractid = array();
1841 foreach ($arrayothercontracts as $contractcursor) {
1842 $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1846 $formquestion = array(
1847 'text' => $langs->trans(
"ConfirmMoveToAnotherContractQuestion"),
1848 array(
'type' =>
'select',
'name' =>
'newcid',
'values' => $arraycontractid));
1850 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid',
'int'), $langs->trans(
"MoveToAnotherContract"), $langs->trans(
"ConfirmMoveToAnotherContract"),
"confirm_move", $formquestion);
1851 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1855 if ($object->statut > 0) {
1856 print
'<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1858 print
'<tr class="oddeven" '.$moreparam.
'>';
1859 print
'<td><span class="valignmiddle hideonsmartphone">'.$langs->trans(
"ServiceStatus").
':</span> '.$object->lines[$cursorline - 1]->getLibStatut(4).
'</td>';
1860 print
'<td width="30" class="right">';
1861 if ($user->socid == 0) {
1862 if ($object->statut > 0 && $action !=
'activateline' && $action !=
'unactivateline') {
1863 $tmpaction =
'activateline';
1864 $tmpactionpicto =
'play';
1865 $tmpactiontext = $langs->trans(
"Activate");
1866 if ($objp->statut == 4) {
1867 $tmpaction =
'unactivateline';
1868 $tmpactionpicto =
'playstop';
1869 $tmpactiontext = $langs->trans(
"Disable");
1871 if (($tmpaction ==
'activateline' && $user->rights->contrat->activer) || ($tmpaction ==
'unactivateline' && $user->rights->contrat->desactiver)) {
1872 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'&action='.$tmpaction.
'">';
1873 print
img_picto($tmpactiontext, $tmpactionpicto);
1881 print
'<tr class="oddeven" '.$moreparam.
'>';
1885 if (!$objp->date_start_real) {
1886 print $langs->trans(
"DateStartReal").
': ';
1887 if ($objp->date_start_real) {
1890 print $langs->trans(
"ContractStatusNotRunning");
1894 if ($objp->date_start_real && !$objp->date_end_real) {
1895 print $langs->trans(
"DateStartReal").
': ';
1899 if ($objp->date_start_real && $objp->date_end_real) {
1900 print $langs->trans(
"DateStartReal").
': ';
1902 print
' - ';
1903 print $langs->trans(
"DateEndReal").
': ';
1906 if (!empty($objp->comment)) {
1907 print
" - ".$objp->comment;
1911 print
'<td class="center"> </td>';
1918 if ($user->rights->contrat->activer && $action ==
'activateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1919 print
'<form name="active" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1920 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1921 print
'<input type="hidden" name="action" value="confirm_active">';
1922 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1923 print
'<input type="hidden" name="ligne" value="'.GETPOST(
'ligne',
'int').
'">';
1924 print
'<input type="hidden" name="confirm" value="yes">';
1926 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1929 $dateactstart = $objp->date_start;
1932 } elseif (!$dateactstart) {
1933 $dateactstart = time();
1936 $dateactend = $objp->date_end;
1939 } elseif (!$dateactend) {
1940 if ($objp->fk_product > 0) {
1942 $product->fetch($objp->fk_product);
1943 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
1947 print
'<tr class="oddeven">';
1948 print
'<td class="nohover">'.$langs->trans(
"DateServiceActivate").
'</td><td class="nohover">';
1949 print
$form->selectDate($dateactstart,
'start', $usehm, $usehm,
'',
"active", 1, 0);
1951 print
'<td class="nohover">'.$langs->trans(
"DateEndPlanned").
'</td><td class="nohover">';
1952 print
$form->selectDate($dateactend,
"end", $usehm, $usehm,
'',
"active", 1, 0);
1954 print
'<td class="center nohover">';
1959 print
'<tr class="oddeven">';
1960 print
'<td class="nohover">'.$langs->trans(
"Comment").
'</td><td colspan="3" class="nohover" colspan="'.($conf->margin->enabled ? 4 : 3).
'"><input type="text" class="minwidth300" name="comment" value="'.
dol_escape_htmltag(
GETPOST(
"comment",
'alphanohtml')).
'"></td>';
1961 print
'<td class="nohover right">';
1962 print
'<input type="submit" class="button" name="activate" value="'.$langs->trans(
"Activate").
'"> ';
1963 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1972 if ($user->rights->contrat->activer && $action ==
'unactivateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1976 print
'<!-- Form to disabled a line -->'.
"\n";
1977 print
'<form name="confirm_closeline" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'" method="post">';
1978 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1979 print
'<input type="hidden" name="confirm" value="yes">';
1980 print
'<input type="hidden" name="action" value="confirm_closeline">';
1982 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1985 $dateactstart = $objp->date_start_real;
1988 } elseif (!$dateactstart) {
1989 $dateactstart = time();
1992 $dateactend = $objp->date_end_real;
1995 } elseif (!$dateactend) {
1996 if ($objp->fk_product > 0) {
1998 $product->fetch($objp->fk_product);
1999 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2003 if ($dateactend > $now) {
2007 print
'<tr class="oddeven"><td colspan="2" class="nohover">';
2008 if ($objp->statut >= 4) {
2009 if ($objp->statut == 4) {
2010 print $langs->trans(
"DateEndReal").
' ';
2011 print
$form->selectDate($dateactend,
"end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1),
"closeline", 1, 1);
2015 print
'<td class="center nohover">';
2018 print
'<tr class="oddeven">';
2019 print
'<td class="nohover">'.$langs->trans(
"Comment").
'</td><td class="nohover"><input class="quatrevingtpercent" type="text" class="flat" name="comment" value="'.
dol_escape_htmltag(
GETPOST(
'comment',
'alpha')).
'"></td>';
2020 print
'<td class="nohover right">';
2021 print
'<input type="submit" class="button" name="close" value="'.$langs->trans(
"Disable").
'"> ';
2022 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2036 if ($user->rights->contrat->creer && ($object->statut == 0)) {
2040 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2041 <input type="hidden" name="token" value="'.
newToken().
'">
2042 <input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">
2043 <input type="hidden" name="mode" value="">
2044 <input type="hidden" name="id" value="'.$object->id.
'">
2045 <input type="hidden" name="page_y" value="">
2048 print
'<div class="div-table-responsive-no-min">';
2049 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2052 if ($action !=
'editline') {
2053 $forcetoshowtitlelines = 1;
2054 if (empty($object->multicurrency_code)) {
2055 $object->multicurrency_code = $conf->currency;
2061 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2062 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2063 if (empty($reshook))
2064 $object->formAddObjectLine(1, $mysoc, $soc);
2075 if (
GETPOST(
'modelselected')) {
2076 $action =
'presend';
2082 if ($user->socid == 0 && $action !=
'presend' && $action !=
'editline') {
2083 print
'<div class="tabsAction">';
2086 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2088 if (empty($reshook)) {
2092 'class' =>
'classfortooltip'
2097 if (empty($user->socid)) {
2098 if ($object->statut == 1) {
2099 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) {
2100 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle',
'',
true, $params);
2102 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
2107 if ($object->statut == 0 && $nbofservices) {
2108 if ($user->rights->contrat->creer) {
2109 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
2111 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2112 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default',
'#',
'',
false, $params);
2115 if ($object->statut == 1) {
2116 if ($user->rights->contrat->creer) {
2117 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
2119 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2120 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
2124 if (
isModEnabled(
'commande') && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) {
2125 $langs->load(
"orders");
2126 if ($user->rights->commande->creer) {
2127 print
dolGetButtonAction($langs->trans(
'CreateOrder'),
'',
'default', DOL_URL_ROOT.
'/commande/card.php?action=create&token='.
newToken().
'&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->thirdparty->id,
'',
true, $params);
2129 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2130 print
dolGetButtonAction($langs->trans(
'CreateOrder'),
'',
'default',
'#',
'',
false, $params);
2135 $langs->load(
"bills");
2136 if ($user->rights->facture->creer) {
2137 print
dolGetButtonAction($langs->trans(
'CreateBill'),
'',
'default', DOL_URL_ROOT.
'/compta/facture/card.php?action=create&origin='.$object->element.
'&originid='.$object->id.
'&socid='.$object->thirdparty->id,
'',
true, $params);
2139 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2140 print
dolGetButtonAction($langs->trans(
'CreateBill'),
'',
'default',
'#',
'',
false, $params);
2144 if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {
2145 if ($user->rights->contrat->activer) {
2146 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=activate&token='.
newToken(),
'',
true, $params);
2148 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default',
'#',
'',
false, $params);
2151 if ($object->nbofservicesclosed < $nbofservices) {
2152 if ($user->rights->contrat->desactiver) {
2153 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=close&token='.
newToken(),
'',
true, $params);
2155 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default',
'#',
'',
false, $params);
2167 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) {
2168 if ($action ==
'showclosedlines') {
2169 print
'<div class="inline-block divButAction"><a class="butAction" id="btnhideclosedlines" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=hideclosedlines">'.$langs->trans(
"HideClosedServices").
'</a></div>';
2171 print
'<div class="inline-block divButAction"><a class="butAction" id="btnshowclosedlines" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=showclosedlines">'.$langs->trans(
"ShowClosedServices").
'</a></div>';
2176 if ($user->rights->contrat->creer) {
2177 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&token='.
newToken(),
'',
true, $params);
2181 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete, $params);
2187 if ($action !=
'presend') {
2188 print
'<div class="fichecenter"><div class="fichehalfleft">';
2194 $filedir = $conf->contrat->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2195 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2196 $genallowed = $user->rights->contrat->lire;
2197 $delallowed = $user->rights->contrat->creer;
2200 print $formfile->showdocuments(
'contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, ($object->model_pdf ? $object->model_pdf :
getDolGlobalString(
'CONTRACT_ADDON_PDF')), 1, 0, 0, 28, 0,
'', 0,
'', $soc->default_lang,
'', $object);
2204 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'contrat'));
2205 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
2208 if ($object->statut != Contrat::STATUS_DRAFT &&
getDolGlobalString(
'CONTRACT_ALLOW_ONLINESIGN')) {
2209 print
'<br><!-- Link to sign -->';
2210 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2212 print showOnlineSignatureUrl(
'contract', $object->ref).
'<br>';
2215 print
'</div><div class="fichehalfright">';
2219 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/agenda.php?id='.$object->id);
2223 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2225 $somethingshown =
$formactions->showactions($object,
'contract', $socid, 1,
'listactions', $MAXEVENT,
'', $morehtmlcenter);
2227 print
'</div></div>';
2231 $modelmail =
'contract';
2232 $defaulttopic =
'SendContractRef';
2233 $diroutput = $conf->contrat->multidir_output[$object->entity];
2234 $trackid =
'con'.$object->id;
2236 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
2250 <script
type=
"text/javascript">
2251 $(document).ready(
function() {
2252 var idprod = $(
"input[name='idprod']").val();
2253 var fournprice = $(
"input[name='fournprice']").val();
2254 var token =
'<?php echo currentToken(); ?>';
2256 $.post(
'<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2260 if (data.length > 0) {
2263 $(data).each(
function() {
2264 options +=
'<option value="'+this.
id+
'" price="'+this.
price+
'"';
2265 if (fournprice > 0) {
2266 if (this.
id == fournprice) {
2267 options +=
' selected';
2268 $(
"#buying_price").val(this.price);
2272 options +=
'>'+this.label+
'</option>';
2274 options +=
'<option value=null'+(trouve?
'':
' selected')+
'><?php echo $langs->trans("InputPrice"); ?></option>';
2275 $(
"#fournprice").html(options);
2277 $(
"#buying_price").hide();
2278 $(
"#fournprice").show();
2281 $(
"#buying_price").show();
2283 $(
"#fournprice").change(
function() {
2284 var selval = $(
this).find(
'option:selected').attr(
"price");
2286 $(
"#buying_price").val(selval).hide();
2288 $(
'#buying_price').show();
2292 $(
"#fournprice").hide();
2293 $(
'#buying_price').show();
2299 $(
"#fournprice").hide();
2300 $(
'#buying_price').show();