34 require
"../main.inc.php";
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/contract.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
40 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
41 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
43 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
44 if (!empty($conf->propal->enabled)) {
45 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
47 if (!empty($conf->project->enabled)) {
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;
109 $reshook = $hookmanager->executeHooks(
'doActions',
$parameters, $object, $action);
113 if (empty($reshook)) {
114 $backurlforlist = DOL_URL_ROOT.
'/contrat/list.php';
116 if (empty($backtopage) || ($cancel && empty($id))) {
117 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
118 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
119 $backtopage = $backurlforlist;
121 $backtopage = DOL_URL_ROOT.
'/contrat/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
127 if (!empty($backtopageforcancel)) {
128 header(
"Location: ".$backtopageforcancel);
130 } elseif (!empty($backtopage)) {
131 header(
"Location: ".$backtopage);
137 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
139 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
141 if ($action ==
'confirm_active' && $confirm ==
'yes' && $user->rights->contrat->activer) {
145 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
150 } elseif ($action ==
'confirm_closeline' && $confirm ==
'yes' && $user->rights->contrat->activer) {
153 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEnd")),
null,
'errors');
156 $result = $object->close_line($user,
GETPOST(
'ligne',
'int'),
GETPOST(
'dateend'), urldecode(
GETPOST(
'comment')));
158 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
167 if (
GETPOST(
'mode') ==
'predefined') {
179 $date_start_update =
'';
180 $date_end_update =
'';
181 $date_start_real_update =
'';
182 $date_end_real_update =
'';
183 if (
GETPOST(
'date_start_updatemonth') &&
GETPOST(
'date_start_updateday') &&
GETPOST(
'date_start_updateyear')) {
186 if (
GETPOST(
'date_end_updatemonth') &&
GETPOST(
'date_end_updateday') &&
GETPOST(
'date_end_updateyear')) {
189 if (
GETPOST(
'date_start_real_updatemonth') &&
GETPOST(
'date_start_real_updateday') &&
GETPOST(
'date_start_real_updateyear')) {
190 $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'));
192 if (
GETPOST(
'date_end_real_updatemonth') &&
GETPOST(
'date_end_real_updateday') &&
GETPOST(
'date_end_real_updateyear')) {
193 $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'));
200 if ($action ==
'add' && $user->rights->contrat->creer) {
202 if (empty($datecontrat)) {
204 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
209 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
215 $ret = $extrafields->setOptionalsFromPost(
null, $object);
222 $object->socid = $socid;
223 $object->date_contrat = $datecontrat;
225 $object->commercial_suivi_id =
GETPOST(
'commercial_suivi_id',
'int');
226 $object->commercial_signature_id =
GETPOST(
'commercial_signature_id',
'int');
228 $object->note_private =
GETPOST(
'note_private',
'alpha');
229 $object->note_public =
GETPOST(
'note_public',
'alpha');
230 $object->fk_project =
GETPOST(
'projectid',
'int');
232 $object->ref =
GETPOST(
'ref',
'alpha');
233 $object->ref_customer =
GETPOST(
'ref_customer',
'alpha');
234 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
237 if (!empty($origin) && !empty($originid)) {
239 $element = $subelement = $origin;
240 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
242 $subelement = $regs[2];
246 if ($element ==
'order') {
247 $element = $subelement =
'commande';
249 if ($element ==
'propal') {
250 $element =
'comm/propal'; $subelement =
'propal';
252 if ($element ==
'invoice' || $element ==
'facture') {
253 $element =
'compta/facture';
254 $subelement =
'facture';
257 $object->origin = $origin;
258 $object->origin_id = $originid;
261 $object->linked_objects[$object->origin] = $object->origin_id;
262 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
263 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
266 $id = $object->create($user);
270 $classname = ucfirst($subelement);
271 $srcobject =
new $classname($db);
273 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
274 $result = $srcobject->fetch($object->origin_id);
276 $srcobject->fetch_thirdparty();
277 $lines = $srcobject->lines;
278 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
279 $srcobject->fetch_lines();
280 $lines = $srcobject->lines;
284 $num = count($lines);
286 for ($i = 0; $i < $num; $i++) {
287 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
289 if ($product_type == 1 || (!empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0, 1)))) {
291 if ($lines[$i]->fk_product > 0) {
292 $product_static =
new Product($db);
295 if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
297 $prod->id = $lines[$i]->fk_product;
298 $prod->getMultiLangs();
300 $outputlangs = $langs;
302 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
303 $newlang =
GETPOST(
'lang_id',
'aZ09');
305 if (empty($newlang)) {
306 $newlang = $srcobject->thirdparty->default_lang;
308 if (!empty($newlang)) {
310 $outputlangs->setDefaultLang($newlang);
313 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"libelle"])) ? $prod->multilangs[$outputlangs->defaultlang][
"libelle"] : $lines[$i]->product_label;
315 $label = $lines[$i]->product_label;
317 $desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->libelle) ?
dol_htmlentitiesbr($lines[$i]->desc) :
'';
323 $array_options = array();
325 if (method_exists($lines[$i],
'fetch_optionals')) {
326 $lines[$i]->fetch_optionals();
327 $array_options = $lines[$i]->array_options;
330 $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx.
' ('.$lines[$i]->vat_src_code.
')' : $lines[$i]->tva_tx;
333 $localtax1_tx =
get_localtax($txtva, 1, $object->thirdparty);
334 $localtax2_tx =
get_localtax($txtva, 2, $object->thirdparty);
336 $result = $object->addline(
338 $lines[$i]->subprice,
343 $lines[$i]->fk_product,
344 $lines[$i]->remise_percent,
345 $lines[$i]->date_start,
346 $lines[$i]->date_end,
349 $lines[$i]->info_bits,
350 $lines[$i]->fk_fournprice,
369 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
383 $result = $object->create($user);
385 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
393 } elseif ($action ==
'classin' && $user->rights->contrat->creer) {
394 $object->setProject(
GETPOST(
'projectid'));
395 } elseif ($action ==
'addline' && $user->rights->contrat->creer) {
402 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free') {
404 $tva_tx = (
GETPOST(
'tva_tx',
'alpha') ?
GETPOST(
'tva_tx',
'alpha') : 0);
406 $idprod =
GETPOST(
'idprod',
'int');
414 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
417 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
418 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
424 if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
425 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
430 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
431 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
433 if (is_array($extralabelsline)) {
435 foreach ($extralabelsline as $key => $value) {
436 unset($_POST[
"options_".$key]);
444 $price_base_type = (
GETPOST(
'price_base_type',
'alpha') ?
GETPOST(
'price_base_type',
'alpha') :
'HT');
452 $prod->fetch($idprod);
457 if (empty($tva_tx)) {
461 $pu_ht = $prod->price;
462 $pu_ttc = $prod->price_ttc;
463 $price_min = $prod->price_min;
464 $price_base_type = $prod->price_base_type;
467 if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) {
468 $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
469 $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
470 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
471 $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
472 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
473 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
477 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
479 $result = $prodcustprice->fetch_all(
'',
'', 0, 0, $filter);
481 if (count($prodcustprice->lines) > 0) {
482 $pu_ht =
price($prodcustprice->lines [0]->price);
483 $pu_ttc =
price($prodcustprice->lines [0]->price_ttc);
484 $price_base_type = $prodcustprice->lines [0]->price_base_type;
485 $tva_tx = $prodcustprice->lines [0]->tva_tx;
486 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
487 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
489 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
490 if (empty($tva_tx)) {
497 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
498 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
504 if ($tmpvat != $tmpprodvat) {
505 if ($price_base_type !=
'HT') {
506 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
508 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
512 $desc = $prod->description;
515 if ($product_desc == $desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
519 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
520 $desc = $product_desc;
522 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
525 $fk_unit = $prod->fk_unit;
528 $price_base_type =
'HT';
529 $tva_tx =
GETPOST(
'tva_tx') ?str_replace(
'*',
'',
GETPOST(
'tva_tx')) : 0;
530 $tva_npr = preg_match(
'/\*/',
GETPOST(
'tva_tx')) ? 1 : 0;
531 $desc = $product_desc;
532 $fk_unit =
GETPOST(
'units',
'alpha');
535 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
536 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
539 $fk_fournprice =
GETPOST(
'fournprice');
541 $pa_ht =
GETPOST(
'buying_price');
551 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance))
552 || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
553 $object->error = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
557 $result = $object->addline(
580 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) {
581 $outputlangs = $langs;
583 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
584 $newlang =
GETPOST(
'lang_id',
'aZ09');
586 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
587 $newlang = $object->thirdparty->default_lang;
589 if (!empty($newlang)) {
591 $outputlangs->setDefaultLang($newlang);
594 $ret = $object->fetch($id);
596 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
599 unset($_POST[
'prod_entry_mode']);
601 unset($_POST[
'qty']);
602 unset($_POST[
'type']);
603 unset($_POST[
'remise_percent']);
604 unset($_POST[
'price_ht']);
605 unset($_POST[
'multicurrency_price_ht']);
606 unset($_POST[
'price_ttc']);
607 unset($_POST[
'tva_tx']);
608 unset($_POST[
'product_ref']);
609 unset($_POST[
'product_label']);
610 unset($_POST[
'product_desc']);
611 unset($_POST[
'fournprice']);
612 unset($_POST[
'buying_price']);
613 unset($_POST[
'np_marginRate']);
614 unset($_POST[
'np_markRate']);
615 unset($_POST[
'dp_desc']);
616 unset($_POST[
'idprod']);
618 unset($_POST[
'date_starthour']);
619 unset($_POST[
'date_startmin']);
620 unset($_POST[
'date_startsec']);
621 unset($_POST[
'date_startday']);
622 unset($_POST[
'date_startmonth']);
623 unset($_POST[
'date_startyear']);
624 unset($_POST[
'date_endhour']);
625 unset($_POST[
'date_endmin']);
626 unset($_POST[
'date_endsec']);
627 unset($_POST[
'date_endday']);
628 unset($_POST[
'date_endmonth']);
629 unset($_POST[
'date_endyear']);
634 } elseif ($action ==
'updateline' && $user->rights->contrat->creer && !
GETPOST(
'cancel',
'alpha')) {
637 if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
638 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
639 $action =
'editline';
640 $_GET[
'rowid'] =
GETPOST(
'elrowid');
646 if ($objectline->fetch(
GETPOST(
'elrowid',
'int')) < 0) {
650 $objectline->fetch_optionals();
656 if ($date_start_real_update ==
'') {
657 $date_start_real_update = $objectline->date_ouverture;
659 if ($date_end_real_update ==
'') {
660 $date_end_real_update = $objectline->date_cloture;
663 $vat_rate =
GETPOST(
'eltva_tx');
666 if (preg_match(
'/\*/', $vat_rate)) {
671 $vat_rate = str_replace(
'*',
'', $vat_rate);
672 $localtax1_tx =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
673 $localtax2_tx =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
680 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
681 $vat_src_code = $reg[1];
682 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
692 $fk_unit =
GETPOST(
'unit',
'alpha');
694 $objectline->fk_product =
GETPOST(
'idprod',
'int');
695 $objectline->description =
GETPOST(
'product_desc',
'restricthtml');
700 $objectline->tva_tx = ($txtva ? $txtva : 0);
701 $objectline->vat_src_code = $vat_src_code;
702 $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
703 $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
704 $objectline->date_ouverture_prevue = $date_start_update;
705 $objectline->date_ouverture = $date_start_real_update;
706 $objectline->date_fin_validite = $date_end_update;
707 $objectline->date_cloture = $date_end_real_update;
708 $objectline->fk_user_cloture = $user->id;
709 $objectline->fk_fournprice = $fk_fournprice;
710 $objectline->pa_ht = $pa_ht;
713 $objectline->fk_unit =
GETPOST(
'unit');
715 $objectline->fk_unit =
null;
719 $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
720 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
722 if (is_array($array_options) && count($array_options) > 0) {
724 foreach ($array_options as $key => $value) {
725 $objectline->array_options[$key] = $array_options[$key];
731 $result = $objectline->update($user);
743 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->rights->contrat->creer) {
744 $result = $object->deleteline(
GETPOST(
'lineid',
'int'), $user);
747 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
752 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $user->rights->contrat->creer) {
753 $result = $object->validate($user);
757 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
758 $outputlangs = $langs;
760 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
761 $newlang =
GETPOST(
'lang_id',
'aZ09');
763 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
764 $newlang = $object->thirdparty->default_lang;
766 if (!empty($newlang)) {
768 $outputlangs->setDefaultLang($newlang);
770 $model = $object->model_pdf;
771 $ret = $object->fetch($id);
773 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
778 } elseif ($action ==
'reopen' && $user->rights->contrat->creer) {
779 $result = $object->reopen($user);
783 } elseif ($action ==
'confirm_close' && $confirm ==
'yes' && $user->rights->contrat->creer) {
785 $result = $object->closeAll($user);
789 } elseif ($action ==
'confirm_activate' && $confirm ==
'yes' && $user->rights->contrat->creer) {
791 $result = $object->activateAll($user);
795 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->contrat->supprimer) {
796 $result = $object->delete($user);
798 header(
"Location: list.php?restore_lastsearch_values=1");
803 } elseif ($action ==
'confirm_move' && $confirm ==
'yes' && $user->rights->contrat->creer) {
806 $result = $contractline->fetch(
GETPOSTINT(
'lineid'));
807 $contractline->fk_contrat =
GETPOSTINT(
'newcid');
808 $result = $contractline->update($user, 1);
810 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
816 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"RefNewContract")),
null,
'errors');
818 } elseif ($action ==
'update_extras') {
822 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
828 $result = $object->insertExtraFields(
'CONTRACT_MODIFY');
836 $action =
'edit_extras';
838 } elseif ($action ==
'setref_supplier') {
842 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
845 $action =
'editref_supplier';
847 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
851 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
854 } elseif ($action ==
'setref_customer') {
858 $result = $object->setValueFrom(
'ref_customer',
GETPOST(
'ref_customer',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
861 $action =
'editref_customer';
863 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
867 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
870 } elseif ($action ==
'setref') {
872 $result = $object->fetch($id);
877 $old_ref = $object->ref;
879 $result = $object->setValueFrom(
'ref',
GETPOST(
'ref',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
884 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
885 $old_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($old_ref);
886 $new_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
889 if (!empty($files)) {
890 if (!is_dir($new_filedir)) {
893 foreach ($files as $file) {
894 dol_move($file[
'fullname'], $new_filedir.
'/'.$file[
'name']);
898 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
902 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
905 } elseif ($action ==
'setdate_contrat') {
907 $result = $object->fetch($id);
912 $result = $object->setValueFrom(
'date_contrat', $datacontrat,
'',
null,
'date',
'', $user,
'CONTRACT_MODIFY');
915 $action =
'editdate_contrat';
917 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
921 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
927 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
930 $upload_dir = $conf->contrat->multidir_output[$object->entity];
931 $permissiontoadd = $user->rights->contrat->creer;
932 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
935 $triggersendname =
'CONTRACT_SENTBYMAIL';
937 $mode =
'emailfromcontract';
938 $trackid =
'con'.$object->id;
939 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
942 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer) {
943 if ($action ==
'addcontact') {
946 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
949 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
952 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
953 $langs->load(
"errors");
954 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
959 } elseif ($action ==
'swapstatut') {
961 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
962 } elseif ($action ==
'deletecontact') {
964 $result = $object->delete_contact(
GETPOST(
'lineid',
'int'));
967 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
976 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
980 if ($object->id > 0) {
981 $result = $object->createFromClone($user, $socid);
983 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
986 if (count($object->errors) > 0) {
1002 $help_url =
'EN:Module_Contracts|FR:Module_Contrat';
1008 if (!empty($conf->project->enabled)) {
1013 $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON :
'mod_contract_serpis');
1014 if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
1015 $module = substr($module, 0,
dol_strlen($module) - 4);
1019 $modCodeContract =
new $module();
1023 if ($action ==
'create') {
1028 $soc->fetch($socid);
1034 $element = $subelement =
GETPOST(
'origin');
1035 if (preg_match(
'/^([^_]+)_([^_]+)/i',
GETPOST(
'origin'), $regs)) {
1036 $element = $regs[1];
1037 $subelement = $regs[2];
1040 if ($element ==
'project') {
1041 $projectid =
GETPOST(
'originid',
'int');
1044 if ($element ==
'order' || $element ==
'commande') {
1045 $element = $subelement =
'commande';
1047 if ($element ==
'propal') {
1048 $element =
'comm/propal'; $subelement =
'propal';
1050 if ($element ==
'invoice' || $element ==
'facture') {
1051 $element =
'compta/facture';
1052 $subelement =
'facture';
1057 $classname = ucfirst($subelement);
1058 $objectsrc =
new $classname($db);
1059 $objectsrc->fetch($originid);
1060 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1061 $objectsrc->fetch_lines();
1063 $objectsrc->fetch_thirdparty();
1066 $objectsrc->fetch_optionals();
1067 $object->array_options = $objectsrc->array_options;
1069 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1071 $soc = $objectsrc->thirdparty;
1073 $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private :
'');
1074 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public :
'');
1077 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1080 $projectid =
GETPOST(
'projectid',
'int');
1081 $note_private =
GETPOST(
"note_private");
1082 $note_public =
GETPOST(
"note_public");
1085 $object->date_contrat =
dol_now();
1087 print
'<form name="form_contract" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1088 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1090 print
'<input type="hidden" name="action" value="add">';
1091 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1092 print
'<input type="hidden" name="remise_percent" value="0">';
1096 print
'<table class="border centpercent">';
1099 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>';
1100 if (!empty($modCodeContract->code_auto)) {
1101 $tmpcode = $langs->trans(
"Draft");
1103 $tmpcode =
'<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(
GETPOST(
'ref') ?
GETPOST(
'ref') : $tmpcode).
'">';
1109 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
1110 print
'<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(
GETPOST(
'ref_customer',
'alpha')).
'"></td></tr>';
1113 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td>';
1114 print
'<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(
GETPOST(
'ref_supplier',
'alpha')).
'"></td></tr>';
1118 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1121 print $soc->getNomUrl(1);
1122 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1126 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
1127 print
$form->select_company(
'',
'socid',
'',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
1128 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>';
1135 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1136 if ($soc->remise_percent) {
1137 print $langs->trans(
"CompanyHasRelativeDiscount", $soc->remise_percent).
' ';
1139 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1141 $absolute_discount = $soc->getAvailableDiscounts();
1142 if ($absolute_discount) {
1143 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1145 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1151 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPFOLL").
'</span></td><td>';
1152 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1153 print
$form->select_dolusers(
GETPOST(
"commercial_suivi_id") ?
GETPOST(
"commercial_suivi_id") : $user->id,
'commercial_suivi_id', 1,
'');
1157 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPSIGN").
'</span></td><td>';
1158 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1159 print
$form->select_dolusers(
GETPOST(
"commercial_signature_id") ?
GETPOST(
"commercial_signature_id") : $user->id,
'commercial_signature_id', 1,
'');
1162 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Date").
'</span></td><td>';
1163 print
$form->selectDate($datecontrat,
'', 0, 0,
'',
"contrat");
1167 if (!empty($conf->project->enabled)) {
1168 $langs->load(
'projects');
1172 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
1173 $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
"projectid", 0, 0, 1, 1);
1174 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>';
1178 print
'<tr><td>'.$langs->trans(
"NotePublic").
'</td><td class="tdtop">';
1179 $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%');
1180 print $doleditor->Create(1);
1183 if (empty($user->socid)) {
1184 print
'<tr><td>'.$langs->trans(
"NotePrivate").
'</td><td class="tdtop">';
1185 $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%');
1186 print $doleditor->Create(1);
1191 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="3"',
'cols' =>
'3');
1192 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1193 print $hookmanager->resPrint;
1196 if (empty($reshook)) {
1197 print $object->showOptionals($extrafields,
'create',
$parameters);
1204 print
$form->buttonsSaveCancel(
"Create");
1206 if (is_object($objectsrc)) {
1207 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1208 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1210 if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
1211 print
'<br>'.$langs->trans(
"Note").
': '.$langs->trans(
"OnlyLinesWithTypeServiceAreUsed");
1220 if ($object->id > 0) {
1221 $object->fetch_thirdparty();
1223 $soc = $object->thirdparty;
1225 $result = $object->fetch_lines();
1230 $nbofservices = count($object->lines);
1232 $author =
new User($db);
1233 $author->fetch($object->user_author_id);
1235 $commercial_signature =
new User($db);
1236 $commercial_signature->fetch($object->commercial_signature_id);
1238 $commercial_suivi =
new User($db);
1239 $commercial_suivi->fetch($object->commercial_suivi_id);
1246 print
dol_get_fiche_head($head, $hselected, $langs->trans(
"Contract"), -1,
'contract');
1249 if ($action ==
'delete') {
1251 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"DeleteAContract"), $langs->trans(
"ConfirmDeleteAContract"),
"confirm_delete",
'', 0, 1);
1252 } elseif ($action ==
'valid') {
1254 $ref = substr($object->ref, 1, 4);
1255 if ($ref ==
'PROV' && !empty($modCodeContract->code_auto)) {
1256 $numref = $object->getNextNumRef($object->thirdparty);
1258 $numref = $object->ref;
1260 $text = $langs->trans(
'ConfirmValidateContract', $numref);
1261 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ValidateAContract"), $text,
"confirm_valid",
'', 0, 1);
1262 } elseif ($action ==
'close') {
1264 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"CloseAContract"), $langs->trans(
"ConfirmCloseContract"),
"confirm_close",
'', 0, 1);
1265 } elseif ($action ==
'activate') {
1266 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ActivateAllOnContract"), $langs->trans(
"ConfirmActivateAllOnContract"),
"confirm_activate",
'', 0, 1);
1267 } elseif ($action ==
'clone') {
1269 $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)')));
1270 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneContract', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1281 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
1282 if (empty($reshook)) {
1284 } elseif ($reshook > 0) {
1293 if (!empty($object->brouillon) && $user->rights->contrat->creer) {
1294 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="POST">';
1295 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1296 print
'<input type="hidden" name="action" value="setremise">';
1301 $linkback =
'<a href="'.DOL_URL_ROOT.
'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1305 if (!empty($modCodeContract->code_auto)) {
1306 $morehtmlref .= $object->ref;
1308 $morehtmlref .=
$form->editfieldkey(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 3);
1309 $morehtmlref .=
$form->editfieldval(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 2);
1312 $morehtmlref .=
'<div class="refidno">';
1314 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1315 $morehtmlref .=
$form->editfieldval(
"RefCustomer",
'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer,
'string',
'',
null,
null,
'', 1,
'getFormatedCustomerRef');
1317 $morehtmlref .=
'<br>';
1318 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1319 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'',
null,
null,
'', 1,
'getFormatedSupplierRef');
1321 $morehtmlref .=
'<br>'.$langs->trans(
'ThirdParty').
' : '.$object->thirdparty->getNomUrl(1);
1322 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
1323 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/contrat/list.php?socid='.$object->thirdparty->id.
'&search_name='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherContracts").
'</a>)';
1326 if (!empty($conf->project->enabled)) {
1327 $langs->load(
"projects");
1328 $morehtmlref .=
'<br>'.$langs->trans(
'Project').
' ';
1329 if ($user->rights->contrat->creer) {
1330 if ($action !=
'classify') {
1331 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> : ';
1333 if ($action ==
'classify') {
1335 $morehtmlref .=
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'">';
1336 $morehtmlref .=
'<input type="hidden" name="action" value="classin">';
1337 $morehtmlref .=
'<input type="hidden" name="token" value="'.newToken().
'">';
1338 $morehtmlref .= $formproject->select_projects($object->thirdparty->id, $object->fk_project,
'projectid', $maxlength, 0, 1, 0, 1, 0, 0,
'', 1);
1339 $morehtmlref .=
'<input type="submit" class="button valignmiddle" value="'.$langs->trans(
"Modify").
'">';
1340 $morehtmlref .=
'</form>';
1342 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->thirdparty->id, $object->fk_project,
'none', 0, 0, 0, 1);
1345 if (!empty($object->fk_project)) {
1347 $proj->fetch($object->fk_project);
1348 $morehtmlref .=
' : '.$proj->getNomUrl(1);
1350 $morehtmlref .=
' - '.$proj->title;
1357 $morehtmlref .=
'</div>';
1360 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'none', $morehtmlref);
1363 print
'<div class="fichecenter">';
1364 print
'<div class="underbanner clearboth"></div>';
1367 print
'<table class="border tableforfield" width="100%">';
1370 print
'<tr><td class="titlefield">'.$langs->trans(
'Discount').
'</td><td colspan="3">';
1371 if ($object->thirdparty->remise_percent) {
1372 print $langs->trans(
"CompanyHasRelativeDiscount", $object->thirdparty->remise_percent).
'. ';
1374 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1376 $absolute_discount = $object->thirdparty->getAvailableDiscounts();
1377 if ($absolute_discount) {
1378 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1380 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1386 print
'<td class="titlefield">';
1387 print
$form->editfieldkey(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer);
1389 print
$form->editfieldval(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer,
'datehourpicker');
1395 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1401 if (!empty($object->brouillon) && $user->rights->contrat->creer) {
1407 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1408 $blocname =
'contacts';
1409 $title = $langs->trans(
'ContactsAddresses');
1410 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1413 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1414 $blocname =
'notes';
1415 $title = $langs->trans(
'Notes');
1416 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1420 $arrayothercontracts = $object->getListOfContracts(
'others');
1426 $productstatic =
new Product($db);
1429 if (!empty($conf->margin->enabled) && !empty($object->element) && in_array($object->element, array(
'facture',
'propal',
'commande'))) {
1435 print
'<div id="contrat-lines-container" data-contractid="'.$object->id.
'" data-element="'.$object->element.
'" >';
1436 while ($cursorline <= $nbofservices) {
1437 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.
'" >';
1438 print
'<form name="update" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="post">';
1439 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1440 print
'<input type="hidden" name="action" value="updateline">';
1441 print
'<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.
'">';
1442 print
'<input type="hidden" name="fournprice" value="'.(!empty($object->lines[$cursorline - 1]->fk_fournprice) ? $object->lines[$cursorline - 1]->fk_fournprice : 0).
'">';
1445 print
'<div class="div-table-responsive-no-min">';
1446 print
'<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">';
1448 $sql =
"SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,";
1449 $sql .=
" cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1450 $sql .=
" cd.date_ouverture_prevue as date_debut, cd.date_ouverture as date_debut_reelle,";
1451 $sql .=
" cd.date_fin_validite as date_fin, cd.date_cloture as date_fin_reelle,";
1452 $sql .=
" cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1453 $sql .=
" cd.fk_unit,";
1454 $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";
1455 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
1456 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
1457 $sql .=
" WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id);
1459 $result = $db->query($sql);
1463 print
'<tr class="liste_titre'.($cursorline ?
' liste_titre_add' :
'').
'">';
1464 print
'<td>'.$langs->trans(
"ServiceNb", $cursorline).
'</td>';
1465 print
'<td width="80" class="center">'.$langs->trans(
"VAT").
'</td>';
1466 print
'<td width="80" class="right">'.$langs->trans(
"PriceUHT").
'</td>';
1470 print
'<td width="30" class="center">'.$langs->trans(
"Qty").
'</td>';
1471 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1472 print
'<td width="30" class="left">'.$langs->trans(
"Unit").
'</td>';
1474 print
'<td width="50" class="right">'.$langs->trans(
"ReductionShort").
'</td>';
1475 if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1476 print
'<td width="50" class="right">'.$langs->trans(
"BuyingPrice").
'</td>';
1478 print
'<td width="30"> </td>';
1481 $objp = $db->fetch_object($result);
1484 if ($action !=
'editline' ||
GETPOST(
'rowid') != $objp->rowid) {
1486 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1487 $moreparam =
'style="display: none;"';
1489 print
'<tr class="tdtop oddeven" '.$moreparam.
'>';
1491 if ($objp->fk_product > 0) {
1492 $productstatic->id = $objp->fk_product;
1493 $productstatic->type = $objp->ptype;
1494 $productstatic->ref = $objp->pref;
1495 $productstatic->entity = $objp->pentity;
1496 $productstatic->label = $objp->plabel;
1497 $productstatic->status = $objp->tosell;
1498 $productstatic->status_buy = $objp->tobuy;
1499 $productstatic->status_batch = $objp->tobatch;
1502 $text = $productstatic->getNomUrl(1,
'', 32);
1503 if ($objp->plabel) {
1505 $text .= $objp->plabel;
1507 $description = $objp->description;
1510 if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) {
1511 $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ?
'<br>'.
dol_htmlentitiesbr($objp->description) :
'';
1515 echo
$form->textwithtooltip($text, $description, 3,
'',
'', $cursorline, 0, (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
1519 print
'<td>'.img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description).
"</td>\n";
1522 print
'<td class="center">';
1523 print
vatrate($objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''),
'%', $objp->info_bits);
1526 print
'<td class="right">'.($objp->subprice !=
'' ?
price($objp->subprice) :
'').
"</td>\n";
1532 print
'<td class="center">'.$objp->qty.
'</td>';
1534 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1535 print
'<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).
'</td>';
1538 if ($objp->remise_percent > 0) {
1539 print
'<td class="right">'.$objp->remise_percent.
"%</td>\n";
1541 print
'<td> </td>';
1545 if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1546 print
'<td class="right nowraponall">'.price($objp->pa_ht).
'</td>';
1550 print
'<td class="nowraponall right">';
1551 if ($user->rights->contrat->creer && is_array($arrayothercontracts) && count($arrayothercontracts) && ($object->statut >= 0)) {
1552 print
'<!-- link to move service line into another contract -->';
1553 print
'<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=move&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1554 print
img_picto($langs->trans(
"MoveToAnotherContract"),
'uparrow');
1557 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1558 print
'<a class="reposition marginrightonly editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1562 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1563 print
'<a class="reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=deleteline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1572 if ($objp->subprice >= 0) {
1575 if ($conf->margin->enabled && $conf->global->PRODUCT_USE_UNITS) {
1577 } elseif ($conf->margin->enabled || $conf->global->PRODUCT_USE_UNITS) {
1581 print
'<tr class="oddeven" '.$moreparam.
'>';
1582 print
'<td colspan="'.$colspan.
'">';
1585 print $langs->trans(
"DateStartPlanned").
': ';
1586 if ($objp->date_debut) {
1589 if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) {
1590 $warning_delay = $conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1591 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1592 print
" ".img_warning($textlate);
1595 print $langs->trans(
"Unknown");
1597 print
' - ';
1598 print $langs->trans(
"DateEndPlanned").
': ';
1599 if ($objp->date_fin) {
1601 if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) {
1602 $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
1603 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1604 print
" ".img_warning($textlate);
1607 print $langs->trans(
"Unknown");
1615 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1617 $line->id = $objp->rowid;
1618 $line->fetch_optionals();
1619 print $line->showOptionals($extrafields,
'view', array(
'class'=>
'oddeven',
'style'=>$moreparam,
'colspan'=>$colspan),
'',
'', 1);
1624 print
'<tr class="oddeven">';
1626 if ($objp->fk_product > 0) {
1627 $canchangeproduct = 1;
1628 if (empty($canchangeproduct)) {
1629 $productstatic->id = $objp->fk_product;
1630 $productstatic->type = $objp->ptype;
1631 $productstatic->ref = $objp->pref;
1632 $productstatic->entity = $objp->pentity;
1633 print $productstatic->getNomUrl(1,
'', 32);
1634 print $objp->label ?
' - '.dol_trunc($objp->label, 32) :
'';
1635 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1637 $senderissupplier = 0;
1638 if (empty($senderissupplier)) {
1639 print
$form->select_produits((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1641 print
$form->select_produits_fournisseurs((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1646 print $objp->label ? $objp->label.
'<br>' :
'';
1647 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1651 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1653 if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1654 $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1656 $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1657 $doleditor =
new DolEditor(
'product_desc', $objp->description,
'', 92,
'dolibarr_details',
'',
false,
true, $enable, $nbrows,
'90%');
1658 $doleditor->Create();
1663 print
'<td class="right">';
1664 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);
1668 print
'<td class="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).
'"></td>';
1676 print
'<td class="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.
'"></td>';
1679 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1680 print
'<td class="left">';
1681 print
$form->selectUnits($objp->fk_unit,
"unit");
1686 print
'<td class="nowrap right"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.
'">%</td>';
1688 if (!empty($usemargins)) {
1689 print
'<td class="right">';
1690 if ($objp->fk_product) {
1691 print
'<select id="fournprice" name="fournprice"></select>';
1693 print
'<input id="buying_price" type="text" size="5" name="buying_price" value="'.price($objp->pa_ht, 0,
'', 0).
'"></td>';
1695 print
'<td class="center">';
1696 print
'<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans(
"Modify").
'">';
1697 print
'<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1702 if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1705 if (!empty($conf->global->PRODUCT_USE_UNITS)) {
1710 print
'<tr class="oddeven">';
1711 print
'<td colspan="'.$colspan.
'">';
1712 print $langs->trans(
"DateStartPlanned").
' ';
1713 print
$form->selectDate($db->jdate($objp->date_debut),
"date_start_update", $usehm, $usehm, ($db->jdate($objp->date_debut) > 0 ? 0 : 1),
"update");
1714 print
' '.$langs->trans(
"DateEndPlanned").
' ';
1715 print
$form->selectDate($db->jdate($objp->date_fin),
"date_end_update", $usehm, $usehm, ($db->jdate($objp->date_fin) > 0 ? 0 : 1),
"update");
1719 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1721 $line->id = $objp->rowid;
1722 $line->fetch_optionals();
1723 print $line->showOptionals($extrafields,
'edit', array(
'style'=>
'class="oddeven"',
'colspan'=>$colspan),
'',
'', 1);
1732 if ($object->statut > 0) {
1734 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1735 $moreparam =
'style="display: none;"';
1737 print
'<tr class="oddeven" '.$moreparam.
'>';
1738 print
'<td class="tdhrthin" colspan="'.($conf->margin->enabled ? 7 : 6).
'"><hr class="opacitymedium tdhrthin"></td>';
1751 if ($action ==
'deleteline' && !$_REQUEST[
"cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1752 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid'), $langs->trans(
"DeleteContractLine"), $langs->trans(
"ConfirmDeleteContractLine"),
"confirm_deleteline",
'', 0, 1);
1753 if ($ret ==
'html') {
1754 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1761 if ($action ==
'move' && !$_REQUEST[
"cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1762 $arraycontractid = array();
1763 foreach ($arrayothercontracts as $contractcursor) {
1764 $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1768 $formquestion = array(
1769 'text' => $langs->trans(
"ConfirmMoveToAnotherContractQuestion"),
1770 array(
'type' =>
'select',
'name' =>
'newcid',
'values' => $arraycontractid));
1772 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid',
'int'), $langs->trans(
"MoveToAnotherContract"), $langs->trans(
"ConfirmMoveToAnotherContract"),
"confirm_move", $formquestion);
1773 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1779 if ($action ==
'active' && !$cancel && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1782 $comment =
GETPOST(
'comment',
'alpha');
1783 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&ligne=".
GETPOST(
'ligne',
'int').
"&date=".$dateactstart.
"&dateend=".$dateactend.
"&comment=".urlencode($comment), $langs->trans(
"ActivateService"), $langs->trans(
"ConfirmActivateService",
dol_print_date($dateactstart,
"%A %d %B %Y")),
"confirm_active",
'', 0, 1);
1784 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1790 if ($action ==
'closeline' && !$cancel && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1793 $comment =
GETPOST(
'comment',
'alpha');
1795 if (empty($dateactend)) {
1796 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEndReal")),
null,
'errors');
1798 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&ligne=".
GETPOST(
'ligne',
'int').
"&date=".$dateactstart.
"&dateend=".$dateactend.
"&comment=".urlencode($comment), $langs->trans(
"CloseService"), $langs->trans(
"ConfirmCloseService",
dol_print_date($dateactend,
"%A %d %B %Y")),
"confirm_closeline",
'', 0, 1);
1800 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1805 if ($object->statut > 0) {
1806 print
'<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1808 print
'<tr class="oddeven" '.$moreparam.
'>';
1809 print
'<td><span class="valignmiddle hideonsmartphone">'.$langs->trans(
"ServiceStatus").
':</span> '.$object->lines[$cursorline - 1]->getLibStatut(4).
'</td>';
1810 print
'<td width="30" class="right">';
1811 if ($user->socid == 0) {
1812 if ($object->statut > 0 && $action !=
'activateline' && $action !=
'unactivateline') {
1813 $tmpaction =
'activateline';
1814 $tmpactionpicto =
'play';
1815 $tmpactiontext = $langs->trans(
"Activate");
1816 if ($objp->statut == 4) {
1817 $tmpaction =
'unactivateline';
1818 $tmpactionpicto =
'playstop';
1819 $tmpactiontext = $langs->trans(
"Disable");
1821 if (($tmpaction ==
'activateline' && $user->rights->contrat->activer) || ($tmpaction ==
'unactivateline' && $user->rights->contrat->desactiver)) {
1822 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'&action='.$tmpaction.
'">';
1823 print
img_picto($tmpactiontext, $tmpactionpicto);
1831 print
'<tr class="oddeven" '.$moreparam.
'>';
1835 if (!$objp->date_debut_reelle) {
1836 print $langs->trans(
"DateStartReal").
': ';
1837 if ($objp->date_debut_reelle) {
1838 print
dol_print_date($db->jdate($objp->date_debut_reelle),
'day');
1840 print $langs->trans(
"ContractStatusNotRunning");
1844 if ($objp->date_debut_reelle && !$objp->date_fin_reelle) {
1845 print $langs->trans(
"DateStartReal").
': ';
1846 print
dol_print_date($db->jdate($objp->date_debut_reelle),
'day');
1849 if ($objp->date_debut_reelle && $objp->date_fin_reelle) {
1850 print $langs->trans(
"DateStartReal").
': ';
1851 print
dol_print_date($db->jdate($objp->date_debut_reelle),
'day');
1852 print
' - ';
1853 print $langs->trans(
"DateEndReal").
': ';
1856 if (!empty($objp->comment)) {
1857 print
" - ".$objp->comment;
1861 print
'<td class="center"> </td>';
1868 if ($user->rights->contrat->activer && $action ==
'activateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1869 print
'<form name="active" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.
GETPOST(
'ligne',
'int').
'&action=active" method="post">';
1870 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1872 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1875 $dateactstart = $objp->date_debut;
1878 } elseif (!$dateactstart) {
1879 $dateactstart = time();
1882 $dateactend = $objp->date_fin;
1885 } elseif (!$dateactend) {
1886 if ($objp->fk_product > 0) {
1888 $product->fetch($objp->fk_product);
1889 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
1893 print
'<tr class="oddeven">';
1894 print
'<td class="nohover">'.$langs->trans(
"DateServiceActivate").
'</td><td class="nohover">';
1895 print
$form->selectDate($dateactstart,
'', $usehm, $usehm,
'',
"active", 1, 0);
1897 print
'<td class="nohover">'.$langs->trans(
"DateEndPlanned").
'</td><td class="nohover">';
1898 print
$form->selectDate($dateactend,
"end", $usehm, $usehm,
'',
"active", 1, 0);
1900 print
'<td class="center nohover">';
1905 print
'<tr class="oddeven">';
1906 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>';
1907 print
'<td class="nohover right">';
1908 print
'<input type="submit" class="button" name="activate" value="'.$langs->trans(
"Activate").
'"> ';
1909 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1918 if ($user->rights->contrat->activer && $action ==
'unactivateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1922 print
'<!-- Form to disabled a line -->'.
"\n";
1923 print
'<form name="closeline" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'" method="post">';
1925 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1926 print
'<input type="hidden" name="action" value="closeline">';
1928 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1931 $dateactstart = $objp->date_debut_reelle;
1934 } elseif (!$dateactstart) {
1935 $dateactstart = time();
1938 $dateactend = $objp->date_fin_reelle;
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 if ($dateactend > $now) {
1953 print
'<tr class="oddeven"><td colspan="2" class="nohover">';
1954 if ($objp->statut >= 4) {
1955 if ($objp->statut == 4) {
1956 print $langs->trans(
"DateEndReal").
' ';
1957 print
$form->selectDate($dateactend,
"end", $usehm, $usehm, ($objp->date_fin_reelle > 0 ? 0 : 1),
"closeline", 1, 1);
1961 print
'<td class="center nohover">';
1964 print
'<tr class="oddeven">';
1965 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>';
1966 print
'<td class="nohover right">';
1967 print
'<input type="submit" class="button" name="close" value="'.$langs->trans(
"Disable").
'"> ';
1968 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1982 if ($user->rights->contrat->creer && ($object->statut == 0)) {
1986 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#add' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
1987 <input type="hidden" name="token" value="'.
newToken().
'">
1988 <input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">
1989 <input type="hidden" name="mode" value="">
1990 <input type="hidden" name="id" value="'.$object->id.
'">
1993 print
'<div class="div-table-responsive-no-min">';
1994 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
1997 if ($action !=
'editline') {
1998 $forcetoshowtitlelines = 1;
1999 if (empty($object->multicurrency_code)) {
2000 $object->multicurrency_code = $conf->currency;
2006 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2007 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2008 if (empty($reshook))
2009 $object->formAddObjectLine(1, $mysoc, $soc);
2024 if ($user->socid == 0) {
2025 print
'<div class="tabsAction">';
2028 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2030 if (empty($reshook)) {
2034 'class' =>
'classfortooltip'
2039 if (empty($user->socid)) {
2040 if ($object->statut == 1) {
2041 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) {
2042 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle',
'',
true, $params);
2044 print
dolGetButtonAction($langs->trans(
'SendMail'),
'',
'default',
'#',
'',
false, $params);
2049 if ($object->statut == 0 && $nbofservices) {
2050 if ($user->rights->contrat->creer) {
2051 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
2053 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2054 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default',
'#',
'',
false, $params);
2057 if ($object->statut == 1) {
2058 if ($user->rights->contrat->creer) {
2059 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
2061 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2062 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
2066 if (!empty($conf->commande->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) {
2067 $langs->load(
"orders");
2068 if ($user->rights->commande->creer) {
2069 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);
2071 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2072 print
dolGetButtonAction($langs->trans(
'CreateOrder'),
'',
'default',
'#',
'',
false, $params);
2077 $langs->load(
"bills");
2078 if ($user->rights->facture->creer) {
2079 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);
2081 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2082 print
dolGetButtonAction($langs->trans(
'CreateBill'),
'',
'default',
'#',
'',
false, $params);
2086 if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {
2087 if ($user->rights->contrat->activer) {
2088 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=activate&token='.
newToken(),
'',
true, $params);
2090 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default',
'#',
'',
false, $params);
2093 if ($object->nbofservicesclosed < $nbofservices) {
2094 if ($user->rights->contrat->desactiver) {
2095 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=close&token='.
newToken(),
'',
true, $params);
2097 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default',
'#',
'',
false, $params);
2109 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) {
2110 if ($action ==
'showclosedlines') {
2111 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>';
2113 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>';
2118 if ($user->rights->contrat->creer) {
2119 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&token='.
newToken(),
'',
true, $params);
2125 if (($user->rights->contrat->creer && $object->statut == $object::STATUS_DRAFT) || $user->rights->contrat->supprimer) {
2126 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'',
true, $params);
2128 $params[
'attr'][
'title'] = $langs->trans(
"NotAllowed");
2129 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'',
false, $params);
2137 if (
GETPOST(
'modelselected')) {
2138 $action =
'presend';
2141 if ($action !=
'presend') {
2142 print
'<div class="fichecenter"><div class="fichehalfleft">';
2148 $filedir = $conf->contrat->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2149 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2150 $genallowed = $user->rights->contrat->lire;
2151 $delallowed = $user->rights->contrat->creer;
2154 print $formfile->showdocuments(
'contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, ($object->model_pdf ? $object->model_pdf : $conf->global->CONTRACT_ADDON_PDF), 1, 0, 0, 28, 0,
'', 0,
'', $soc->default_lang,
'', $object);
2158 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'contrat'));
2159 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
2161 print
'</div><div class="fichehalfright">';
2165 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/agenda.php?id='.$object->id);
2168 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2170 $somethingshown =
$formactions->showactions($object,
'contract', $socid, 1,
'listactions', $MAXEVENT,
'', $morehtmlcenter);
2172 print
'</div></div>';
2176 $modelmail =
'contract';
2177 $defaulttopic =
'SendContractRef';
2178 $diroutput = $conf->contrat->multidir_output[$object->entity];
2179 $trackid =
'con'.$object->id;
2181 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
2192 if (!empty($conf->margin->enabled) && $action ==
'editline') {
2195 <script
type=
"text/javascript">
2196 $(document).ready(
function() {
2197 var idprod = $(
"input[name='idprod']").val();
2198 var fournprice = $(
"input[name='fournprice']").val();
2199 var token =
'<?php echo currentToken(); ?>';
2201 $.post(
'<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2205 if (data.length > 0) {
2208 $(data).each(
function() {
2209 options +=
'<option value="'+this.
id+
'" price="'+this.
price+
'"';
2210 if (fournprice > 0) {
2211 if (this.
id == fournprice) {
2212 options +=
' selected';
2213 $(
"#buying_price").val(this.price);
2217 options +=
'>'+this.label+
'</option>';
2219 options +=
'<option value=null'+(trouve?
'':
' selected')+
'><?php echo $langs->trans("InputPrice"); ?></option>';
2220 $(
"#fournprice").html(options);
2222 $(
"#buying_price").hide();
2223 $(
"#fournprice").show();
2226 $(
"#buying_price").show();
2228 $(
"#fournprice").change(
function() {
2229 var selval = $(
this).find(
'option:selected').attr(
"price");
2231 $(
"#buying_price").val(selval).hide();
2233 $(
'#buying_price').show();
2237 $(
"#fournprice").hide();
2238 $(
'#buying_price').show();
2244 $(
"#fournprice").hide();
2245 $(
'#buying_price').show();