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->rights->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->rights->contrat->creer) {
412 $object->setProject(
GETPOST(
'projectid'));
413 } elseif ($action ==
'addline' && $user->rights->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');
444 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
448 if (empty($remise_percent)) {
453 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
456 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
457 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
463 if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
464 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
469 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
470 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
472 if (is_array($extralabelsline)) {
474 foreach ($extralabelsline as $key => $value) {
475 unset($_POST[
"options_".$key]);
488 $prod->fetch($idprod);
493 if (empty($tva_tx)) {
497 $price_min = $prod->price_min;
498 $price_min_ttc = $prod->price_min_ttc;
501 if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) {
502 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
503 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
504 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
506 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
510 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
512 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
514 if (count($prodcustprice->lines) > 0) {
515 $price_min =
price($prodcustprice->lines[0]->price_min);
516 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
517 $tva_tx = $prodcustprice->lines[0]->tva_tx;
518 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
519 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
521 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
522 if (empty($tva_tx)) {
529 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
530 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
533 if (!empty($price_ht) || $price_ht ===
'0') {
535 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
536 $price_base_type =
'HT';
537 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
539 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
540 $price_base_type =
'TTC';
543 $desc = $prod->description;
546 if ($product_desc == $desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
550 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
551 $desc = $product_desc;
553 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
556 $fk_unit = $prod->fk_unit;
560 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
561 if (empty($tva_tx)) {
564 $tva_tx = str_replace(
'*',
'', $tva_tx);
565 $desc = $product_desc;
566 $fk_unit =
GETPOST(
'units',
'alpha');
567 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
568 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
570 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
573 if (!empty($price_ht) || $price_ht ===
'0') {
575 $pu_ttc =
price2num($pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
576 $price_base_type =
'HT';
577 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
579 $pu_ht =
price2num($pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
580 $price_base_type =
'TTC';
584 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
585 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
588 $fk_fournprice =
GETPOST(
'fournprice');
590 $pa_ht =
GETPOST(
'buying_price');
600 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance))
601 || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
602 $object->error = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
606 $result = $object->addline(
630 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) {
631 $outputlangs = $langs;
634 $newlang =
GETPOST(
'lang_id',
'aZ09');
637 $newlang = $object->thirdparty->default_lang;
639 if (!empty($newlang)) {
641 $outputlangs->setDefaultLang($newlang);
644 $ret = $object->fetch($id);
646 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
649 unset($_POST[
'prod_entry_mode']);
651 unset($_POST[
'qty']);
652 unset($_POST[
'type']);
653 unset($_POST[
'remise_percent']);
654 unset($_POST[
'price_ht']);
655 unset($_POST[
'multicurrency_price_ht']);
656 unset($_POST[
'price_ttc']);
657 unset($_POST[
'tva_tx']);
658 unset($_POST[
'product_ref']);
659 unset($_POST[
'product_label']);
660 unset($_POST[
'product_desc']);
661 unset($_POST[
'fournprice']);
662 unset($_POST[
'buying_price']);
663 unset($_POST[
'np_marginRate']);
664 unset($_POST[
'np_markRate']);
665 unset($_POST[
'dp_desc']);
666 unset($_POST[
'idprod']);
668 unset($_POST[
'date_starthour']);
669 unset($_POST[
'date_startmin']);
670 unset($_POST[
'date_startsec']);
671 unset($_POST[
'date_startday']);
672 unset($_POST[
'date_startmonth']);
673 unset($_POST[
'date_startyear']);
674 unset($_POST[
'date_endhour']);
675 unset($_POST[
'date_endmin']);
676 unset($_POST[
'date_endsec']);
677 unset($_POST[
'date_endday']);
678 unset($_POST[
'date_endmonth']);
679 unset($_POST[
'date_endyear']);
684 } elseif ($action ==
'updateline' && $user->rights->contrat->creer && !
GETPOST(
'cancel',
'alpha')) {
688 if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
689 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
690 $action =
'editline';
691 $_GET[
'rowid'] =
GETPOST(
'elrowid');
697 if ($objectline->fetch(
GETPOST(
'elrowid',
'int')) < 0) {
701 $objectline->fetch_optionals();
703 $objectline->oldcopy =
dol_clone($objectline);
709 if ($date_start_real_update ==
'') {
710 $date_start_real_update = $objectline->date_start_real;
712 if ($date_end_real_update ==
'') {
713 $date_end_real_update = $objectline->date_end_real;
716 $vat_rate =
GETPOST(
'eltva_tx');
719 if (preg_match(
'/\*/', $vat_rate)) {
724 $vat_rate = str_replace(
'*',
'', $vat_rate);
725 $localtax1_tx =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
726 $localtax2_tx =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
733 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
734 $vat_src_code = $reg[1];
735 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
745 $fk_unit =
GETPOST(
'unit',
'alpha');
752 if ($remise_percent > 0) {
753 $remise = round(($price_ht * $remise_percent / 100), 2);
754 $price_ht = ($price_ht - $remise);
757 $objectline->fk_product =
GETPOST(
'idprod',
'int');
758 $objectline->description =
GETPOST(
'product_desc',
'restricthtml');
759 $objectline->price_ht = $price_ht;
762 $objectline->remise_percent = $remise_percent;
763 $objectline->tva_tx = ($txtva ? $txtva : 0);
764 $objectline->vat_src_code = $vat_src_code;
765 $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
766 $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
767 $objectline->date_start = $date_start_update;
768 $objectline->date_start_real = $date_start_real_update;
769 $objectline->date_end = $date_end_update;
770 $objectline->date_end_real = $date_end_real_update;
771 $objectline->fk_user_cloture = $user->id;
773 $objectline->pa_ht = $pa_ht;
774 $objectline->rang = $objectline->rang;
777 $objectline->fk_unit =
GETPOST(
'unit');
779 $objectline->fk_unit =
null;
783 $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
784 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
786 if (is_array($array_options) && count($array_options) > 0) {
788 foreach ($array_options as $key => $value) {
789 $objectline->array_options[$key] = $array_options[$key];
795 $result = $objectline->update($user);
807 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->rights->contrat->creer) {
808 $result = $object->deleteline(
GETPOST(
'lineid',
'int'), $user);
811 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
816 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $user->rights->contrat->creer) {
817 $result = $object->validate($user);
821 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
822 $outputlangs = $langs;
825 $newlang =
GETPOST(
'lang_id',
'aZ09');
828 $newlang = $object->thirdparty->default_lang;
830 if (!empty($newlang)) {
832 $outputlangs->setDefaultLang($newlang);
834 $model = $object->model_pdf;
835 $ret = $object->fetch($id);
837 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
842 } elseif ($action ==
'reopen' && $user->rights->contrat->creer) {
843 $result = $object->reopen($user);
847 } elseif ($action ==
'confirm_close' && $confirm ==
'yes' && $user->rights->contrat->creer) {
849 $result = $object->closeAll($user);
853 } elseif ($action ==
'confirm_activate' && $confirm ==
'yes' && $user->rights->contrat->creer) {
856 $comment =
GETPOST(
'comment',
'alpha');
857 $result = $object->activateAll($user, $date_start, 0, $comment, $date_end);
861 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->contrat->supprimer) {
862 $result = $object->delete($user);
864 header(
"Location: list.php?restore_lastsearch_values=1");
869 } elseif ($action ==
'confirm_move' && $confirm ==
'yes' && $user->rights->contrat->creer) {
872 $result = $contractline->fetch(
GETPOSTINT(
'lineid'));
873 $contractline->fk_contrat =
GETPOSTINT(
'newcid');
874 $result = $contractline->update($user, 1);
876 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
882 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"RefNewContract")),
null,
'errors');
884 } elseif ($action ==
'update_extras') {
888 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
894 $result = $object->insertExtraFields(
'CONTRACT_MODIFY');
902 $action =
'edit_extras';
904 } elseif ($action ==
'setref_supplier') {
908 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
911 $action =
'editref_supplier';
913 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
917 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
920 } elseif ($action ==
'setref_customer') {
924 $result = $object->setValueFrom(
'ref_customer',
GETPOST(
'ref_customer',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
927 $action =
'editref_customer';
929 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
933 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
936 } elseif ($action ==
'setref') {
938 $result = $object->fetch($id);
943 $old_ref = $object->ref;
945 $result = $object->setValueFrom(
'ref',
GETPOST(
'ref',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
950 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
951 $old_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($old_ref);
952 $new_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
957 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
961 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
964 } elseif ($action ==
'setdate_contrat') {
966 $result = $object->fetch($id);
971 $result = $object->setValueFrom(
'date_contrat', $datacontrat,
'',
null,
'date',
'', $user,
'CONTRACT_MODIFY');
974 $action =
'editdate_contrat';
976 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
980 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
986 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
989 $upload_dir = $conf->contrat->multidir_output[$object->entity];
990 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
993 $triggersendname =
'CONTRACT_SENTBYMAIL';
995 $mode =
'emailfromcontract';
996 $trackid =
'con'.$object->id;
997 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1000 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer) {
1001 if ($action ==
'addcontact') {
1004 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1007 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1010 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1011 $langs->load(
"errors");
1012 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1017 } elseif ($action ==
'swapstatut') {
1019 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1020 } elseif ($action ==
'deletecontact') {
1022 $result = $object->delete_contact(
GETPOST(
'lineid',
'int'));
1025 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1034 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
1036 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1038 if ($object->id > 0) {
1039 $result = $object->createFromClone($user, $socid);
1041 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1044 if (count($object->errors) > 0) {
1060 $help_url =
'EN:Module_Contracts|FR:Module_Contrat';
1071 $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON :
'mod_contract_serpis');
1072 if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
1073 $module = substr($module, 0,
dol_strlen($module) - 4);
1077 $modCodeContract =
new $module();
1081 if ($action ==
'create') {
1086 $soc->fetch($socid);
1092 $element = $subelement =
GETPOST(
'origin');
1093 if (preg_match(
'/^([^_]+)_([^_]+)/i',
GETPOST(
'origin'), $regs)) {
1094 $element = $regs[1];
1095 $subelement = $regs[2];
1098 if ($element ==
'project') {
1099 $projectid =
GETPOST(
'originid',
'int');
1102 if ($element ==
'order' || $element ==
'commande') {
1103 $element = $subelement =
'commande';
1105 if ($element ==
'propal') {
1106 $element =
'comm/propal'; $subelement =
'propal';
1108 if ($element ==
'invoice' || $element ==
'facture') {
1109 $element =
'compta/facture';
1110 $subelement =
'facture';
1115 $classname = ucfirst($subelement);
1116 $objectsrc =
new $classname($db);
1117 $objectsrc->fetch($originid);
1118 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1119 $objectsrc->fetch_lines();
1121 $objectsrc->fetch_thirdparty();
1124 $objectsrc->fetch_optionals();
1125 $object->array_options = $objectsrc->array_options;
1127 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1129 $soc = $objectsrc->thirdparty;
1131 $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private :
'');
1132 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public :
'');
1135 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1138 $projectid =
GETPOST(
'projectid',
'int');
1139 $note_private =
GETPOST(
"note_private");
1140 $note_public =
GETPOST(
"note_public");
1143 $object->date_contrat =
dol_now();
1145 print
'<form name="form_contract" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1146 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1148 print
'<input type="hidden" name="action" value="add">';
1149 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1150 print
'<input type="hidden" name="remise_percent" value="0">';
1154 print
'<table class="border centpercent">';
1157 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>';
1158 if (!empty($modCodeContract->code_auto)) {
1159 $tmpcode = $langs->trans(
"Draft");
1161 $tmpcode =
'<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(
GETPOST(
'ref') ?
GETPOST(
'ref') : $tmpcode).
'">';
1167 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
1168 print
'<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(
GETPOST(
'ref_customer',
'alpha')).
'"></td></tr>';
1171 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td>';
1172 print
'<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(
GETPOST(
'ref_supplier',
'alpha')).
'"></td></tr>';
1176 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1179 print $soc->getNomUrl(1);
1180 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1184 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
1185 print
$form->select_company(
'',
'socid',
'',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
1186 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>';
1193 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1194 if ($soc->remise_percent) {
1195 print $langs->trans(
"CompanyHasRelativeDiscount", $soc->remise_percent).
' ';
1197 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1199 $absolute_discount = $soc->getAvailableDiscounts();
1200 if ($absolute_discount) {
1201 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1203 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1209 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPFOLL").
'</span></td><td>';
1210 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1211 print
$form->select_dolusers(
GETPOST(
"commercial_suivi_id") ?
GETPOST(
"commercial_suivi_id") : $user->id,
'commercial_suivi_id', 1,
'');
1215 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPSIGN").
'</span></td><td>';
1216 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1217 print
$form->select_dolusers(
GETPOST(
"commercial_signature_id") ?
GETPOST(
"commercial_signature_id") : $user->id,
'commercial_signature_id', 1,
'');
1220 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Date").
'</span></td><td>';
1221 print
$form->selectDate($datecontrat,
'', 0, 0,
'',
"contrat");
1226 $langs->load(
'projects');
1230 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
1231 $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
"projectid", 0, 0, 1, 1);
1232 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>';
1236 print
'<tr><td>'.$langs->trans(
"NotePublic").
'</td><td class="tdtop">';
1237 $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%');
1238 print $doleditor->Create(1);
1241 if (empty($user->socid)) {
1242 print
'<tr><td>'.$langs->trans(
"NotePrivate").
'</td><td class="tdtop">';
1243 $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%');
1244 print $doleditor->Create(1);
1249 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="3"',
'cols' =>
'3');
1250 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1251 print $hookmanager->resPrint;
1254 if (empty($reshook)) {
1255 print $object->showOptionals($extrafields,
'create',
$parameters);
1262 print
$form->buttonsSaveCancel(
"Create");
1264 if (is_object($objectsrc)) {
1265 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1266 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1268 if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
1269 print
'<br>'.$langs->trans(
"Note").
': '.$langs->trans(
"OnlyLinesWithTypeServiceAreUsed");
1278 if ($object->id > 0) {
1279 $object->fetch_thirdparty();
1281 $soc = $object->thirdparty;
1283 $result = $object->fetch_lines();
1288 $nbofservices = count($object->lines);
1290 $author =
new User($db);
1291 $author->fetch($object->user_author_id);
1293 $commercial_signature =
new User($db);
1294 $commercial_signature->fetch($object->commercial_signature_id);
1296 $commercial_suivi =
new User($db);
1297 $commercial_suivi->fetch($object->commercial_suivi_id);
1304 print
dol_get_fiche_head($head, $hselected, $langs->trans(
"Contract"), -1,
'contract');
1307 if ($action ==
'delete') {
1309 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"DeleteAContract"), $langs->trans(
"ConfirmDeleteAContract"),
"confirm_delete",
'', 0, 1);
1310 } elseif ($action ==
'valid') {
1312 $ref = substr($object->ref, 1, 4);
1313 if ($ref ==
'PROV' && !empty($modCodeContract->code_auto)) {
1314 $numref = $object->getNextNumRef($object->thirdparty);
1316 $numref = $object->ref;
1318 $text = $langs->trans(
'ConfirmValidateContract', $numref);
1319 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ValidateAContract"), $text,
"confirm_valid",
'', 0, 1);
1320 } elseif ($action ==
'close') {
1322 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"CloseAContract"), $langs->trans(
"ConfirmCloseContract"),
"confirm_close",
'', 0, 1);
1323 } elseif ($action ==
'activate') {
1324 $formquestion = array(
1325 array(
'type' =>
'date',
'name' =>
'd_start',
'label' => $langs->trans(
"DateServiceActivate"),
'value' =>
dol_now()),
1326 array(
'type' =>
'date',
'name' =>
'd_end',
'label' => $langs->trans(
"DateEndPlanned"),
'',
''),
1327 array(
'type' =>
'text',
'name' =>
'comment',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'',
'',
'class' =>
'minwidth300',
'moreattr'=>
'autofocus')
1329 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ActivateAllOnContract"), $langs->trans(
"ConfirmActivateAllOnContract"),
"confirm_activate", $formquestion,
'yes', 1, 280);
1330 } elseif ($action ==
'clone') {
1332 $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)')));
1333 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneContract', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1344 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
1345 if (empty($reshook)) {
1347 } elseif ($reshook > 0) {
1356 if (!empty($object->brouillon) && $user->rights->contrat->creer) {
1357 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="POST">';
1358 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1359 print
'<input type="hidden" name="action" value="setremise">';
1364 $linkback =
'<a href="'.DOL_URL_ROOT.
'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1368 if (!empty($modCodeContract->code_auto)) {
1369 $morehtmlref .= $object->ref;
1371 $morehtmlref .=
$form->editfieldkey(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 3);
1372 $morehtmlref .=
$form->editfieldval(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 2);
1375 $morehtmlref .=
'<div class="refidno">';
1377 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1378 $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');
1380 $morehtmlref .=
'<br>';
1381 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1382 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'',
null,
null,
'', 1,
'getFormatedSupplierRef');
1384 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1);
1385 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
1386 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/contrat/list.php?socid='.$object->thirdparty->id.
'&search_name='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherContracts").
'</a>)';
1390 $langs->load(
"projects");
1391 $morehtmlref .=
'<br>';
1392 if ($permissiontoadd) {
1393 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1394 if ($action !=
'classify') {
1395 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
1397 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
1399 if (!empty($object->fk_project)) {
1401 $proj->fetch($object->fk_project);
1402 $morehtmlref .= $proj->getNomUrl(1);
1404 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
1409 $morehtmlref .=
'</div>';
1412 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'none', $morehtmlref);
1415 print
'<div class="fichecenter">';
1416 print
'<div class="underbanner clearboth"></div>';
1419 print
'<table class="border tableforfield" width="100%">';
1422 print
'<tr><td class="titlefield">'.$langs->trans(
'Discount').
'</td><td colspan="3">';
1423 if ($object->thirdparty->remise_percent) {
1424 print $langs->trans(
"CompanyHasRelativeDiscount", $object->thirdparty->remise_percent).
'. ';
1426 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1428 $absolute_discount = $object->thirdparty->getAvailableDiscounts();
1429 if ($absolute_discount) {
1430 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1432 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1438 print
'<td class="titlefield">';
1439 print
$form->editfieldkey(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer);
1441 print
$form->editfieldval(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer,
'datehourpicker');
1447 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1453 if (!empty($object->brouillon) && $user->rights->contrat->creer) {
1459 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1460 $blocname =
'contacts';
1461 $title = $langs->trans(
'ContactsAddresses');
1462 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1465 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1466 $blocname =
'notes';
1467 $title = $langs->trans(
'Notes');
1468 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1472 $arrayothercontracts = $object->getListOfContracts(
'others');
1480 global $inputalsopricewithtax;
1481 $inputalsopricewithtax = 1;
1483 $productstatic =
new Product($db);
1486 if (
isModEnabled(
'margin') && !empty($object->element) && in_array($object->element, array(
'facture',
'propal',
'commande'))) {
1494 print
'<div id="contrat-lines-container" id="contractlines" data-contractid="'.$object->id.
'" data-element="'.$object->element.
'" >';
1495 while ($cursorline <= $nbofservices) {
1496 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.
'" >';
1497 print
'<form name="update" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="post">';
1498 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1499 print
'<input type="hidden" name="action" value="updateline">';
1500 print
'<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.
'">';
1501 print
'<input type="hidden" name="fournprice" value="'.(!empty($object->lines[$cursorline - 1]->fk_fournprice) ? $object->lines[$cursorline - 1]->fk_fournprice : 0).
'">';
1504 print
'<div class="div-table-responsive-no-min">';
1505 print
'<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">';
1507 $sql =
"SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,";
1508 $sql .=
" cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1509 $sql .=
" cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";
1510 $sql .=
" cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";
1511 $sql .=
" cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1512 $sql .=
" cd.fk_unit,";
1513 $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";
1514 $sql .=
" ,cd.rang";
1515 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
1516 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
1517 $sql .=
" WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id);
1519 $result = $db->query($sql);
1523 $objp = $db->fetch_object($result);
1525 print
'<tr class="liste_titre'.($cursorline ?
' liste_titre_add' :
'').
'">';
1526 print
'<td>'.$langs->trans(
"ServiceNb", $cursorline).
'</td>';
1527 print
'<td width="80" class="center">'.$langs->trans(
"VAT").
'</td>';
1528 print
'<td width="80" class="right">'.$langs->trans(
"PriceUHT").
'</td>';
1532 print
'<td width="30" class="center">'.$langs->trans(
"Qty").
'</td>';
1533 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1534 print
'<td width="30" class="left">'.$langs->trans(
"Unit").
'</td>';
1536 print
'<td width="50" class="right">'.$langs->trans(
"ReductionShort").
'</td>';
1537 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1538 print
'<td width="50" class="right">'.$langs->trans(
"BuyingPrice").
'</td>';
1542 if ($nbofservices > 1 && $conf->browser->layout !=
'phone' && !empty($user->rights->contrat->creer)) {
1543 print
'<td width="30" class="linecolmove tdlineupdown center">';
1544 if ($cursorline > 1) {
1545 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=up&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1546 echo
img_up(
'default', 0,
'imgupforline');
1549 if ($cursorline < $nbofservices) {
1550 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=down&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1551 echo
img_down(
'default', 0,
'imgdownforline');
1556 print
'<td width="30"> </td>';
1564 if ($action !=
'editline' ||
GETPOST(
'rowid') != $objp->rowid) {
1566 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1567 $moreparam =
'style="display: none;"';
1569 print
'<tr class="tdtop oddeven" '.$moreparam.
'>';
1571 if ($objp->fk_product > 0) {
1572 $productstatic->id = $objp->fk_product;
1573 $productstatic->type = $objp->ptype;
1574 $productstatic->ref = $objp->pref;
1575 $productstatic->entity = $objp->pentity;
1576 $productstatic->label = $objp->plabel;
1577 $productstatic->status = $objp->tosell;
1578 $productstatic->status_buy = $objp->tobuy;
1579 $productstatic->status_batch = $objp->tobatch;
1582 $text = $productstatic->getNomUrl(1,
'', 32);
1583 if ($objp->plabel) {
1585 $text .= $objp->plabel;
1587 $description = $objp->description;
1591 $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ?
'<br>'.
dol_htmlentitiesbr($objp->description) :
'';
1595 echo
$form->textwithtooltip($text, $description, 3,
'',
'', $cursorline, 0, (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
1599 print
'<td>'.img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description).
"</td>\n";
1602 print
'<td class="center">';
1603 print
vatrate($objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''),
'%', $objp->info_bits);
1606 print
'<td class="right">'.($objp->subprice !=
'' ?
price($objp->subprice) :
'').
"</td>\n";
1612 print
'<td class="center">'.$objp->qty.
'</td>';
1614 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1615 print
'<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).
'</td>';
1618 if ($objp->remise_percent > 0) {
1619 print
'<td class="right">'.$objp->remise_percent.
"%</td>\n";
1621 print
'<td> </td>';
1625 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1626 print
'<td class="right nowraponall">'.price($objp->pa_ht).
'</td>';
1630 print
'<td class="nowraponall right">';
1631 if ($user->rights->contrat->creer && is_array($arrayothercontracts) && count($arrayothercontracts) && ($object->statut >= 0)) {
1632 print
'<!-- link to move service line into another contract -->';
1633 print
'<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=move&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1634 print
img_picto($langs->trans(
"MoveToAnotherContract"),
'uparrow');
1637 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1638 print
'<a class="reposition marginrightonly editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1642 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1643 print
'<a class="reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=deleteline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1652 if ($objp->subprice >= 0) {
1661 print
'<tr class="oddeven" '.$moreparam.
'>';
1662 print
'<td colspan="'.$colspan.
'">';
1665 print $langs->trans(
"DateStartPlanned").
': ';
1666 if ($objp->date_start) {
1669 if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now - $conf->contrat->services->inactifs->warning_delay)) {
1670 $warning_delay = $conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1671 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1672 print
" ".img_warning($textlate);
1675 print $langs->trans(
"Unknown");
1677 print
' - ';
1678 print $langs->trans(
"DateEndPlanned").
': ';
1679 if ($objp->date_end) {
1681 if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now - $conf->contrat->services->expires->warning_delay)) {
1682 $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
1683 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1684 print
" ".img_warning($textlate);
1687 print $langs->trans(
"Unknown");
1695 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1697 $line->id = $objp->rowid;
1698 $line->fetch_optionals();
1699 print $line->showOptionals($extrafields,
'view', array(
'class'=>
'oddeven',
'style'=>$moreparam,
'colspan'=>$colspan),
'',
'', 1);
1704 print
'<tr class="oddeven">';
1706 if ($objp->fk_product > 0) {
1707 $canchangeproduct = 1;
1708 if (empty($canchangeproduct)) {
1709 $productstatic->id = $objp->fk_product;
1710 $productstatic->type = $objp->ptype;
1711 $productstatic->ref = $objp->pref;
1712 $productstatic->entity = $objp->pentity;
1713 print $productstatic->getNomUrl(1,
'', 32);
1714 print $objp->label ?
' - '.dol_trunc($objp->label, 32) :
'';
1715 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1717 $senderissupplier = 0;
1718 if (empty($senderissupplier)) {
1719 print
$form->select_produits((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1721 $form->select_produits_fournisseurs((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1726 print $objp->label ? $objp->label.
'<br>' :
'';
1727 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1731 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1733 if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1734 $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1736 $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1737 $doleditor =
new DolEditor(
'product_desc', $objp->description,
'', 92,
'dolibarr_details',
'',
false,
true, $enable, $nbrows,
'90%');
1738 $doleditor->Create();
1743 print
'<td class="right">';
1744 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);
1748 print
'<td class="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).
'"></td>';
1756 print
'<td class="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.
'"></td>';
1759 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1760 print
'<td class="left">';
1761 print
$form->selectUnits($objp->fk_unit,
"unit");
1766 print
'<td class="nowrap right"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.
'">%</td>';
1768 if (!empty($usemargins)) {
1769 print
'<td class="right">';
1770 if ($objp->fk_product) {
1771 print
'<select id="fournprice" name="fournprice"></select>';
1773 print
'<input id="buying_price" type="text" size="5" name="buying_price" value="'.price($objp->pa_ht, 0,
'', 0).
'"></td>';
1775 print
'<td class="center">';
1776 print
'<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans(
"Modify").
'">';
1777 print
'<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1782 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1785 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1790 print
'<tr class="oddeven">';
1791 print
'<td colspan="'.$colspan.
'">';
1792 print $langs->trans(
"DateStartPlanned").
' ';
1793 print
$form->selectDate($db->jdate($objp->date_start),
"date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1),
"update");
1794 print
' '.$langs->trans(
"DateEndPlanned").
' ';
1795 print
$form->selectDate($db->jdate($objp->date_end),
"date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1),
"update");
1799 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1801 $line->id = $objp->rowid;
1802 $line->fetch_optionals();
1803 print $line->showOptionals($extrafields,
'edit', array(
'style'=>
'class="oddeven"',
'colspan'=>$colspan),
'',
'', 1);
1812 if ($object->statut > 0) {
1814 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1815 $moreparam =
'style="display: none;"';
1817 print
'<tr class="oddeven" '.$moreparam.
'>';
1818 print
'<td class="tdhrthin" colspan="'.($conf->margin->enabled ? 7 : 6).
'"><hr class="opacitymedium tdhrthin"></td>';
1831 if ($action ==
'deleteline' && !$_REQUEST[
"cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1832 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid'), $langs->trans(
"DeleteContractLine"), $langs->trans(
"ConfirmDeleteContractLine"),
"confirm_deleteline",
'', 0, 1);
1833 if ($ret ==
'html') {
1834 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1841 if ($action ==
'move' && !$_REQUEST[
"cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1842 $arraycontractid = array();
1843 foreach ($arrayothercontracts as $contractcursor) {
1844 $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1848 $formquestion = array(
1849 'text' => $langs->trans(
"ConfirmMoveToAnotherContractQuestion"),
1850 array(
'type' =>
'select',
'name' =>
'newcid',
'values' => $arraycontractid));
1852 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid',
'int'), $langs->trans(
"MoveToAnotherContract"), $langs->trans(
"ConfirmMoveToAnotherContract"),
"confirm_move", $formquestion);
1853 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1857 if ($object->statut > 0) {
1858 print
'<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1860 print
'<tr class="oddeven" '.$moreparam.
'>';
1861 print
'<td><span class="valignmiddle hideonsmartphone">'.$langs->trans(
"ServiceStatus").
':</span> '.$object->lines[$cursorline - 1]->getLibStatut(4).
'</td>';
1862 print
'<td width="30" class="right">';
1863 if ($user->socid == 0) {
1864 if ($object->statut > 0 && $action !=
'activateline' && $action !=
'unactivateline') {
1865 $tmpaction =
'activateline';
1866 $tmpactionpicto =
'play';
1867 $tmpactiontext = $langs->trans(
"Activate");
1868 if ($objp->statut == 4) {
1869 $tmpaction =
'unactivateline';
1870 $tmpactionpicto =
'playstop';
1871 $tmpactiontext = $langs->trans(
"Disable");
1873 if (($tmpaction ==
'activateline' && $user->rights->contrat->activer) || ($tmpaction ==
'unactivateline' && $user->rights->contrat->desactiver)) {
1874 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'&action='.$tmpaction.
'">';
1875 print
img_picto($tmpactiontext, $tmpactionpicto);
1883 print
'<tr class="oddeven" '.$moreparam.
'>';
1887 if (!$objp->date_start_real) {
1888 print $langs->trans(
"DateStartReal").
': ';
1889 if ($objp->date_start_real) {
1892 print $langs->trans(
"ContractStatusNotRunning");
1896 if ($objp->date_start_real && !$objp->date_end_real) {
1897 print $langs->trans(
"DateStartReal").
': ';
1901 if ($objp->date_start_real && $objp->date_end_real) {
1902 print $langs->trans(
"DateStartReal").
': ';
1904 print
' - ';
1905 print $langs->trans(
"DateEndReal").
': ';
1908 if (!empty($objp->comment)) {
1909 print
" - ".$objp->comment;
1913 print
'<td class="center"> </td>';
1920 if ($user->rights->contrat->activer && $action ==
'activateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1921 print
'<form name="active" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1922 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1923 print
'<input type="hidden" name="action" value="confirm_active">';
1924 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1925 print
'<input type="hidden" name="ligne" value="'.GETPOST(
'ligne',
'int').
'">';
1926 print
'<input type="hidden" name="confirm" value="yes">';
1928 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1931 $dateactstart = $objp->date_start;
1934 } elseif (!$dateactstart) {
1935 $dateactstart = time();
1938 $dateactend = $objp->date_end;
1941 } elseif (!$dateactend) {
1942 if ($objp->fk_product > 0) {
1944 $product->fetch($objp->fk_product);
1945 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
1949 print
'<tr class="oddeven">';
1950 print
'<td class="nohover">'.$langs->trans(
"DateServiceActivate").
'</td><td class="nohover">';
1951 print
$form->selectDate($dateactstart,
'start', $usehm, $usehm,
'',
"active", 1, 0);
1953 print
'<td class="nohover">'.$langs->trans(
"DateEndPlanned").
'</td><td class="nohover">';
1954 print
$form->selectDate($dateactend,
"end", $usehm, $usehm,
'',
"active", 1, 0);
1956 print
'<td class="center nohover">';
1961 print
'<tr class="oddeven">';
1962 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>';
1963 print
'<td class="nohover right">';
1964 print
'<input type="submit" class="button" name="activate" value="'.$langs->trans(
"Activate").
'"> ';
1965 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1974 if ($user->rights->contrat->activer && $action ==
'unactivateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1978 print
'<!-- Form to disabled a line -->'.
"\n";
1979 print
'<form name="confirm_closeline" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'" method="post">';
1980 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1981 print
'<input type="hidden" name="confirm" value="yes">';
1982 print
'<input type="hidden" name="action" value="confirm_closeline">';
1984 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1987 $dateactstart = $objp->date_start_real;
1990 } elseif (!$dateactstart) {
1991 $dateactstart = time();
1994 $dateactend = $objp->date_end_real;
1997 } elseif (!$dateactend) {
1998 if ($objp->fk_product > 0) {
2000 $product->fetch($objp->fk_product);
2001 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2005 if ($dateactend > $now) {
2009 print
'<tr class="oddeven"><td colspan="2" class="nohover">';
2010 if ($objp->statut >= 4) {
2011 if ($objp->statut == 4) {
2012 print $langs->trans(
"DateEndReal").
' ';
2013 print
$form->selectDate($dateactend,
"end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1),
"closeline", 1, 1);
2017 print
'<td class="center nohover">';
2020 print
'<tr class="oddeven">';
2021 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>';
2022 print
'<td class="nohover right">';
2023 print
'<input type="submit" class="button" name="close" value="'.$langs->trans(
"Disable").
'"> ';
2024 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2038 if ($user->rights->contrat->creer && ($object->statut == 0)) {
2042 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2043 <input type="hidden" name="token" value="'.
newToken().
'">
2044 <input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">
2045 <input type="hidden" name="mode" value="">
2046 <input type="hidden" name="id" value="'.$object->id.
'">
2047 <input type="hidden" name="page_y" value="">
2050 print
'<div class="div-table-responsive-no-min">';
2051 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2054 if ($action !=
'editline') {
2055 $forcetoshowtitlelines = 1;
2056 if (empty($object->multicurrency_code)) {
2057 $object->multicurrency_code = $conf->currency;
2063 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2064 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2065 if (empty($reshook))
2066 $object->formAddObjectLine(1, $mysoc, $soc);
2077 if (
GETPOST(
'modelselected')) {
2078 $action =
'presend';
2084 if ($user->socid == 0 && $action !=
'presend' && $action !=
'editline') {
2085 print
'<div class="tabsAction">';
2088 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2090 if (empty($reshook)) {
2094 'class' =>
'classfortooltip'
2099 if (empty($user->socid)) {
2100 if ($object->statut == 1) {
2101 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) {
2102 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle',
'',
true, $params);
2104 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
2109 if ($object->statut == 0 && $nbofservices) {
2110 if ($user->rights->contrat->creer) {
2111 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
2113 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2114 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default',
'#',
'',
false, $params);
2117 if ($object->statut == 1) {
2118 if ($user->rights->contrat->creer) {
2119 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
2121 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2122 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
2126 if (
isModEnabled(
'commande') && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) {
2127 $langs->load(
"orders");
2128 if ($user->rights->commande->creer) {
2129 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);
2131 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2132 print
dolGetButtonAction($langs->trans(
'CreateOrder'),
'',
'default',
'#',
'',
false, $params);
2137 $langs->load(
"bills");
2138 if ($user->rights->facture->creer) {
2139 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);
2141 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2142 print
dolGetButtonAction($langs->trans(
'CreateBill'),
'',
'default',
'#',
'',
false, $params);
2146 if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {
2147 if ($user->rights->contrat->activer) {
2148 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=activate&token='.
newToken(),
'',
true, $params);
2150 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default',
'#',
'',
false, $params);
2153 if ($object->nbofservicesclosed < $nbofservices) {
2154 if ($user->rights->contrat->desactiver) {
2155 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=close&token='.
newToken(),
'',
true, $params);
2157 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default',
'#',
'',
false, $params);
2169 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) {
2170 if ($action ==
'showclosedlines') {
2171 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>';
2173 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>';
2178 if ($user->rights->contrat->creer) {
2179 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&token='.
newToken(),
'',
true, $params);
2183 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete, $params);
2189 if ($action !=
'presend') {
2190 print
'<div class="fichecenter"><div class="fichehalfleft">';
2196 $filedir = $conf->contrat->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2197 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2198 $genallowed = $user->rights->contrat->lire;
2199 $delallowed = $user->rights->contrat->creer;
2202 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);
2206 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'contrat'));
2207 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
2210 if ($object->statut != Contrat::STATUS_DRAFT &&
getDolGlobalString(
'CONTRACT_ALLOW_ONLINESIGN')) {
2211 print
'<br><!-- Link to sign -->';
2212 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2214 print showOnlineSignatureUrl(
'contract', $object->ref).
'<br>';
2217 print
'</div><div class="fichehalfright">';
2221 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/agenda.php?id='.$object->id);
2225 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2227 $somethingshown =
$formactions->showactions($object,
'contract', $socid, 1,
'listactions', $MAXEVENT,
'', $morehtmlcenter);
2229 print
'</div></div>';
2233 $modelmail =
'contract';
2234 $defaulttopic =
'SendContractRef';
2235 $diroutput = $conf->contrat->multidir_output[$object->entity];
2236 $trackid =
'con'.$object->id;
2238 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
2252 <script
type=
"text/javascript">
2253 $(document).ready(
function() {
2254 var idprod = $(
"input[name='idprod']").val();
2255 var fournprice = $(
"input[name='fournprice']").val();
2256 var token =
'<?php echo currentToken(); ?>';
2258 $.post(
'<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2262 if (data.length > 0) {
2265 $(data).each(
function() {
2266 options +=
'<option value="'+this.
id+
'" price="'+this.
price+
'"';
2267 if (fournprice > 0) {
2268 if (this.
id == fournprice) {
2269 options +=
' selected';
2270 $(
"#buying_price").val(this.price);
2274 options +=
'>'+this.label+
'</option>';
2276 options +=
'<option value=null'+(trouve?
'':
' selected')+
'><?php echo $langs->trans("InputPrice"); ?></option>';
2277 $(
"#fournprice").html(options);
2279 $(
"#buying_price").hide();
2280 $(
"#fournprice").show();
2283 $(
"#buying_price").show();
2285 $(
"#fournprice").change(
function() {
2286 var selval = $(
this).find(
'option:selected').attr(
"price");
2288 $(
"#buying_price").val(selval).hide();
2290 $(
'#buying_price').show();
2294 $(
"#fournprice").hide();
2295 $(
'#buying_price').show();
2301 $(
"#fournprice").hide();
2302 $(
'#buying_price').show();