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) {
149 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
154 } elseif ($action ==
'confirm_closeline' && $confirm ==
'yes' && $user->rights->contrat->activer) {
157 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEnd")),
null,
'errors');
160 $result = $object->close_line($user,
GETPOST(
'ligne',
'int'),
GETPOST(
'dateend'), urldecode(
GETPOST(
'comment')));
162 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
171 if (
GETPOST(
'mode') ==
'predefined') {
183 $date_start_update =
'';
184 $date_end_update =
'';
185 $date_start_real_update =
'';
186 $date_end_real_update =
'';
187 if (
GETPOST(
'date_start_updatemonth') &&
GETPOST(
'date_start_updateday') &&
GETPOST(
'date_start_updateyear')) {
190 if (
GETPOST(
'date_end_updatemonth') &&
GETPOST(
'date_end_updateday') &&
GETPOST(
'date_end_updateyear')) {
193 if (
GETPOST(
'date_start_real_updatemonth') &&
GETPOST(
'date_start_real_updateday') &&
GETPOST(
'date_start_real_updateyear')) {
194 $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'));
196 if (
GETPOST(
'date_end_real_updatemonth') &&
GETPOST(
'date_end_real_updateday') &&
GETPOST(
'date_end_real_updateyear')) {
197 $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'));
204 if ($action ==
'add' && $user->rights->contrat->creer) {
206 if (empty($datecontrat)) {
208 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
213 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
219 $ret = $extrafields->setOptionalsFromPost(
null, $object);
226 $object->socid = $socid;
227 $object->date_contrat = $datecontrat;
229 $object->commercial_suivi_id =
GETPOST(
'commercial_suivi_id',
'int');
230 $object->commercial_signature_id =
GETPOST(
'commercial_signature_id',
'int');
232 $object->note_private =
GETPOST(
'note_private',
'alpha');
233 $object->note_public =
GETPOST(
'note_public',
'alpha');
234 $object->fk_project =
GETPOST(
'projectid',
'int');
236 $object->ref =
GETPOST(
'ref',
'alpha');
237 $object->ref_customer =
GETPOST(
'ref_customer',
'alpha');
238 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
241 if (!empty($origin) && !empty($originid)) {
243 $element = $subelement = $origin;
244 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
246 $subelement = $regs[2];
250 if ($element ==
'order') {
251 $element = $subelement =
'commande';
253 if ($element ==
'propal') {
254 $element =
'comm/propal'; $subelement =
'propal';
256 if ($element ==
'invoice' || $element ==
'facture') {
257 $element =
'compta/facture';
258 $subelement =
'facture';
261 $object->origin = $origin;
262 $object->origin_id = $originid;
265 $object->linked_objects[$object->origin] = $object->origin_id;
266 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
267 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
270 $id = $object->create($user);
274 $classname = ucfirst($subelement);
275 $srcobject =
new $classname($db);
277 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
278 $result = $srcobject->fetch($object->origin_id);
280 $srcobject->fetch_thirdparty();
281 $lines = $srcobject->lines;
282 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
283 $srcobject->fetch_lines();
284 $lines = $srcobject->lines;
288 $num = count($lines);
290 for ($i = 0; $i < $num; $i++) {
291 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
293 if ($product_type == 1 || (!empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0, 1)))) {
295 if ($lines[$i]->fk_product > 0) {
296 $product_static =
new Product($db);
299 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
301 $prod->id = $lines[$i]->fk_product;
302 $prod->getMultiLangs();
304 $outputlangs = $langs;
306 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
307 $newlang =
GETPOST(
'lang_id',
'aZ09');
309 if (empty($newlang)) {
310 $newlang = $srcobject->thirdparty->default_lang;
312 if (!empty($newlang)) {
314 $outputlangs->setDefaultLang($newlang);
317 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"libelle"])) ? $prod->multilangs[$outputlangs->defaultlang][
"libelle"] : $lines[$i]->product_label;
319 $label = $lines[$i]->product_label;
321 $desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->libelle) ?
dol_htmlentitiesbr($lines[$i]->desc) :
'';
327 $array_options = array();
329 if (method_exists($lines[$i],
'fetch_optionals')) {
330 $lines[$i]->fetch_optionals();
331 $array_options = $lines[$i]->array_options;
334 $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx.
' ('.$lines[$i]->vat_src_code.
')' : $lines[$i]->tva_tx;
337 $localtax1_tx =
get_localtax($txtva, 1, $object->thirdparty);
338 $localtax2_tx =
get_localtax($txtva, 2, $object->thirdparty);
340 $result = $object->addline(
342 $lines[$i]->subprice,
347 $lines[$i]->fk_product,
348 $lines[$i]->remise_percent,
349 $lines[$i]->date_start,
350 $lines[$i]->date_end,
353 $lines[$i]->info_bits,
354 $lines[$i]->fk_fournprice,
374 $reshook = $hookmanager->executeHooks(
'createFrom',
$parameters, $object, $action);
387 $result = $object->create($user);
389 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
397 } elseif ($action ==
'classin' && $user->rights->contrat->creer) {
398 $object->setProject(
GETPOST(
'projectid'));
399 } elseif ($action ==
'addline' && $user->rights->contrat->creer) {
406 $price_ht_devise =
'';
408 $price_ttc_devise =
'';
410 $rang = count($object->lines) + 1;
412 if (
GETPOST(
'price_ht') !==
'') {
415 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
418 if (
GETPOST(
'price_ttc') !==
'') {
421 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
425 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free') {
428 $idprod =
GETPOST(
'idprod',
'int');
430 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
434 if (empty($remise_percent)) {
439 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
442 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
443 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
449 if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
450 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
455 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
456 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
458 if (is_array($extralabelsline)) {
460 foreach ($extralabelsline as $key => $value) {
461 unset($_POST[
"options_".$key]);
474 $prod->fetch($idprod);
479 if (empty($tva_tx)) {
483 $price_min = $prod->price_min;
484 $price_min_ttc = $prod->price_min_ttc;
487 if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) {
488 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
489 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
490 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
492 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
496 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
498 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
500 if (count($prodcustprice->lines) > 0) {
501 $price_min =
price($prodcustprice->lines[0]->price_min);
502 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
503 $tva_tx = $prodcustprice->lines[0]->tva_tx;
504 if ($prodcustprice->lines[0]->default_vat_code && !preg_match(
'/\(.*\)/', $tva_tx)) {
505 $tva_tx .=
' ('.$prodcustprice->lines[0]->default_vat_code.
')';
507 $tva_npr = $prodcustprice->lines[0]->recuperableonly;
508 if (empty($tva_tx)) {
515 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
516 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
519 if (!empty($price_ht) || $price_ht ===
'0') {
521 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
522 $price_base_type =
'HT';
523 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
525 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
526 $price_base_type =
'TTC';
529 $desc = $prod->description;
532 if ($product_desc == $desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
536 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
537 $desc = $product_desc;
539 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
542 $fk_unit = $prod->fk_unit;
546 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
547 if (empty($tva_tx)) {
550 $tva_tx = str_replace(
'*',
'', $tva_tx);
551 $desc = $product_desc;
552 $fk_unit =
GETPOST(
'units',
'alpha');
553 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
554 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
556 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
559 if (!empty($price_ht) || $price_ht ===
'0') {
561 $pu_ttc =
price2num($pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
562 $price_base_type =
'HT';
563 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
565 $pu_ht =
price2num($pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
566 $price_base_type =
'TTC';
570 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
571 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
574 $fk_fournprice =
GETPOST(
'fournprice');
576 $pa_ht =
GETPOST(
'buying_price');
586 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance))
587 || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
588 $object->error = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
592 $result = $object->addline(
616 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) {
617 $outputlangs = $langs;
620 $newlang =
GETPOST(
'lang_id',
'aZ09');
623 $newlang = $object->thirdparty->default_lang;
625 if (!empty($newlang)) {
627 $outputlangs->setDefaultLang($newlang);
630 $ret = $object->fetch($id);
632 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
635 unset($_POST[
'prod_entry_mode']);
637 unset($_POST[
'qty']);
638 unset($_POST[
'type']);
639 unset($_POST[
'remise_percent']);
640 unset($_POST[
'price_ht']);
641 unset($_POST[
'multicurrency_price_ht']);
642 unset($_POST[
'price_ttc']);
643 unset($_POST[
'tva_tx']);
644 unset($_POST[
'product_ref']);
645 unset($_POST[
'product_label']);
646 unset($_POST[
'product_desc']);
647 unset($_POST[
'fournprice']);
648 unset($_POST[
'buying_price']);
649 unset($_POST[
'np_marginRate']);
650 unset($_POST[
'np_markRate']);
651 unset($_POST[
'dp_desc']);
652 unset($_POST[
'idprod']);
654 unset($_POST[
'date_starthour']);
655 unset($_POST[
'date_startmin']);
656 unset($_POST[
'date_startsec']);
657 unset($_POST[
'date_startday']);
658 unset($_POST[
'date_startmonth']);
659 unset($_POST[
'date_startyear']);
660 unset($_POST[
'date_endhour']);
661 unset($_POST[
'date_endmin']);
662 unset($_POST[
'date_endsec']);
663 unset($_POST[
'date_endday']);
664 unset($_POST[
'date_endmonth']);
665 unset($_POST[
'date_endyear']);
670 } elseif ($action ==
'updateline' && $user->rights->contrat->creer && !
GETPOST(
'cancel',
'alpha')) {
674 if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
675 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
676 $action =
'editline';
677 $_GET[
'rowid'] =
GETPOST(
'elrowid');
683 if ($objectline->fetch(
GETPOST(
'elrowid',
'int')) < 0) {
687 $objectline->fetch_optionals();
689 $objectline->oldcopy =
dol_clone($objectline);
695 if ($date_start_real_update ==
'') {
696 $date_start_real_update = $objectline->date_start_real;
698 if ($date_end_real_update ==
'') {
699 $date_end_real_update = $objectline->date_end_real;
702 $vat_rate =
GETPOST(
'eltva_tx');
705 if (preg_match(
'/\*/', $vat_rate)) {
710 $vat_rate = str_replace(
'*',
'', $vat_rate);
711 $localtax1_tx =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
712 $localtax2_tx =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
719 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
720 $vat_src_code = $reg[1];
721 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
731 $fk_unit =
GETPOST(
'unit',
'alpha');
733 $objectline->fk_product =
GETPOST(
'idprod',
'int');
734 $objectline->description =
GETPOST(
'product_desc',
'restricthtml');
739 $objectline->tva_tx = ($txtva ? $txtva : 0);
740 $objectline->vat_src_code = $vat_src_code;
741 $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
742 $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
743 $objectline->date_start = $date_start_update;
744 $objectline->date_start_real = $date_start_real_update;
745 $objectline->date_end = $date_end_update;
746 $objectline->date_end_real = $date_end_real_update;
747 $objectline->fk_user_cloture = $user->id;
749 $objectline->pa_ht = $pa_ht;
750 $objectline->rang = $objectline->rang;
753 $objectline->fk_unit =
GETPOST(
'unit');
755 $objectline->fk_unit =
null;
759 $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
760 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
762 if (is_array($array_options) && count($array_options) > 0) {
764 foreach ($array_options as $key => $value) {
765 $objectline->array_options[$key] = $array_options[$key];
771 $result = $objectline->update($user);
783 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->rights->contrat->creer) {
784 $result = $object->deleteline(
GETPOST(
'lineid',
'int'), $user);
787 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
792 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $user->rights->contrat->creer) {
793 $result = $object->validate($user);
797 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
798 $outputlangs = $langs;
801 $newlang =
GETPOST(
'lang_id',
'aZ09');
804 $newlang = $object->thirdparty->default_lang;
806 if (!empty($newlang)) {
808 $outputlangs->setDefaultLang($newlang);
810 $model = $object->model_pdf;
811 $ret = $object->fetch($id);
813 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
818 } elseif ($action ==
'reopen' && $user->rights->contrat->creer) {
819 $result = $object->reopen($user);
823 } elseif ($action ==
'confirm_close' && $confirm ==
'yes' && $user->rights->contrat->creer) {
825 $result = $object->closeAll($user);
829 } elseif ($action ==
'confirm_activate' && $confirm ==
'yes' && $user->rights->contrat->creer) {
832 $comment =
GETPOST(
'comment',
'alpha');
833 $result = $object->activateAll($user, $date_start, 0, $comment, $date_end);
837 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->rights->contrat->supprimer) {
838 $result = $object->delete($user);
840 header(
"Location: list.php?restore_lastsearch_values=1");
845 } elseif ($action ==
'confirm_move' && $confirm ==
'yes' && $user->rights->contrat->creer) {
848 $result = $contractline->fetch(
GETPOSTINT(
'lineid'));
849 $contractline->fk_contrat =
GETPOSTINT(
'newcid');
850 $result = $contractline->update($user, 1);
852 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
858 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"RefNewContract")),
null,
'errors');
860 } elseif ($action ==
'update_extras') {
864 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
870 $result = $object->insertExtraFields(
'CONTRACT_MODIFY');
878 $action =
'edit_extras';
880 } elseif ($action ==
'setref_supplier') {
884 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
887 $action =
'editref_supplier';
889 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
893 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
896 } elseif ($action ==
'setref_customer') {
900 $result = $object->setValueFrom(
'ref_customer',
GETPOST(
'ref_customer',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
903 $action =
'editref_customer';
905 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
909 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
912 } elseif ($action ==
'setref') {
914 $result = $object->fetch($id);
919 $old_ref = $object->ref;
921 $result = $object->setValueFrom(
'ref',
GETPOST(
'ref',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
926 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
927 $old_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($old_ref);
928 $new_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
931 if (!empty($files)) {
932 if (!is_dir($new_filedir)) {
935 foreach ($files as $file) {
936 dol_move($file[
'fullname'], $new_filedir.
'/'.$file[
'name']);
940 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
944 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
947 } elseif ($action ==
'setdate_contrat') {
949 $result = $object->fetch($id);
954 $result = $object->setValueFrom(
'date_contrat', $datacontrat,
'',
null,
'date',
'', $user,
'CONTRACT_MODIFY');
957 $action =
'editdate_contrat';
959 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
963 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
969 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
972 $upload_dir = $conf->contrat->multidir_output[$object->entity];
973 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
976 $triggersendname =
'CONTRACT_SENTBYMAIL';
978 $mode =
'emailfromcontract';
979 $trackid =
'con'.$object->id;
980 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
983 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->contrat->creer) {
984 if ($action ==
'addcontact') {
987 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
990 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
993 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
994 $langs->load(
"errors");
995 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1000 } elseif ($action ==
'swapstatut') {
1002 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1003 } elseif ($action ==
'deletecontact') {
1005 $result = $object->delete_contact(
GETPOST(
'lineid',
'int'));
1008 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1017 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
1019 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1021 if ($object->id > 0) {
1022 $result = $object->createFromClone($user, $socid);
1024 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1027 if (count($object->errors) > 0) {
1043 $help_url =
'EN:Module_Contracts|FR:Module_Contrat';
1054 $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON :
'mod_contract_serpis');
1055 if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
1056 $module = substr($module, 0,
dol_strlen($module) - 4);
1060 $modCodeContract =
new $module();
1064 if ($action ==
'create') {
1069 $soc->fetch($socid);
1075 $element = $subelement =
GETPOST(
'origin');
1076 if (preg_match(
'/^([^_]+)_([^_]+)/i',
GETPOST(
'origin'), $regs)) {
1077 $element = $regs[1];
1078 $subelement = $regs[2];
1081 if ($element ==
'project') {
1082 $projectid =
GETPOST(
'originid',
'int');
1085 if ($element ==
'order' || $element ==
'commande') {
1086 $element = $subelement =
'commande';
1088 if ($element ==
'propal') {
1089 $element =
'comm/propal'; $subelement =
'propal';
1091 if ($element ==
'invoice' || $element ==
'facture') {
1092 $element =
'compta/facture';
1093 $subelement =
'facture';
1098 $classname = ucfirst($subelement);
1099 $objectsrc =
new $classname($db);
1100 $objectsrc->fetch($originid);
1101 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1102 $objectsrc->fetch_lines();
1104 $objectsrc->fetch_thirdparty();
1107 $objectsrc->fetch_optionals();
1108 $object->array_options = $objectsrc->array_options;
1110 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1112 $soc = $objectsrc->thirdparty;
1114 $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private :
'');
1115 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public :
'');
1118 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1121 $projectid =
GETPOST(
'projectid',
'int');
1122 $note_private =
GETPOST(
"note_private");
1123 $note_public =
GETPOST(
"note_public");
1126 $object->date_contrat =
dol_now();
1128 print
'<form name="form_contract" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1129 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1131 print
'<input type="hidden" name="action" value="add">';
1132 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1133 print
'<input type="hidden" name="remise_percent" value="0">';
1137 print
'<table class="border centpercent">';
1140 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>';
1141 if (!empty($modCodeContract->code_auto)) {
1142 $tmpcode = $langs->trans(
"Draft");
1144 $tmpcode =
'<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(
GETPOST(
'ref') ?
GETPOST(
'ref') : $tmpcode).
'">';
1150 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
1151 print
'<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(
GETPOST(
'ref_customer',
'alpha')).
'"></td></tr>';
1154 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td>';
1155 print
'<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(
GETPOST(
'ref_supplier',
'alpha')).
'"></td></tr>';
1159 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1162 print $soc->getNomUrl(1);
1163 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1167 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
1168 print
$form->select_company(
'',
'socid',
'',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
1169 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>';
1176 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1177 if ($soc->remise_percent) {
1178 print $langs->trans(
"CompanyHasRelativeDiscount", $soc->remise_percent).
' ';
1180 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1182 $absolute_discount = $soc->getAvailableDiscounts();
1183 if ($absolute_discount) {
1184 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1186 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1192 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPFOLL").
'</span></td><td>';
1193 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1194 print
$form->select_dolusers(
GETPOST(
"commercial_suivi_id") ?
GETPOST(
"commercial_suivi_id") : $user->id,
'commercial_suivi_id', 1,
'');
1198 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPSIGN").
'</span></td><td>';
1199 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1200 print
$form->select_dolusers(
GETPOST(
"commercial_signature_id") ?
GETPOST(
"commercial_signature_id") : $user->id,
'commercial_signature_id', 1,
'');
1203 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Date").
'</span></td><td>';
1204 print
$form->selectDate($datecontrat,
'', 0, 0,
'',
"contrat");
1209 $langs->load(
'projects');
1213 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
1214 $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
"projectid", 0, 0, 1, 1);
1215 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>';
1219 print
'<tr><td>'.$langs->trans(
"NotePublic").
'</td><td class="tdtop">';
1220 $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%');
1221 print $doleditor->Create(1);
1224 if (empty($user->socid)) {
1225 print
'<tr><td>'.$langs->trans(
"NotePrivate").
'</td><td class="tdtop">';
1226 $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%');
1227 print $doleditor->Create(1);
1232 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="3"',
'cols' =>
'3');
1233 $reshook = $hookmanager->executeHooks(
'formObjectOptions',
$parameters, $object, $action);
1234 print $hookmanager->resPrint;
1237 if (empty($reshook)) {
1238 print $object->showOptionals($extrafields,
'create',
$parameters);
1245 print
$form->buttonsSaveCancel(
"Create");
1247 if (is_object($objectsrc)) {
1248 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1249 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1251 if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
1252 print
'<br>'.$langs->trans(
"Note").
': '.$langs->trans(
"OnlyLinesWithTypeServiceAreUsed");
1261 if ($object->id > 0) {
1262 $object->fetch_thirdparty();
1264 $soc = $object->thirdparty;
1266 $result = $object->fetch_lines();
1271 $nbofservices = count($object->lines);
1273 $author =
new User($db);
1274 $author->fetch($object->user_author_id);
1276 $commercial_signature =
new User($db);
1277 $commercial_signature->fetch($object->commercial_signature_id);
1279 $commercial_suivi =
new User($db);
1280 $commercial_suivi->fetch($object->commercial_suivi_id);
1287 print
dol_get_fiche_head($head, $hselected, $langs->trans(
"Contract"), -1,
'contract');
1290 if ($action ==
'delete') {
1292 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"DeleteAContract"), $langs->trans(
"ConfirmDeleteAContract"),
"confirm_delete",
'', 0, 1);
1293 } elseif ($action ==
'valid') {
1295 $ref = substr($object->ref, 1, 4);
1296 if ($ref ==
'PROV' && !empty($modCodeContract->code_auto)) {
1297 $numref = $object->getNextNumRef($object->thirdparty);
1299 $numref = $object->ref;
1301 $text = $langs->trans(
'ConfirmValidateContract', $numref);
1302 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ValidateAContract"), $text,
"confirm_valid",
'', 0, 1);
1303 } elseif ($action ==
'close') {
1305 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"CloseAContract"), $langs->trans(
"ConfirmCloseContract"),
"confirm_close",
'', 0, 1);
1306 } elseif ($action ==
'activate') {
1307 $formquestion = array(
1308 array(
'type' =>
'date',
'name' =>
'd_start',
'label' => $langs->trans(
"DateServiceActivate"),
'value' =>
dol_now()),
1309 array(
'type' =>
'date',
'name' =>
'd_end',
'label' => $langs->trans(
"DateEndPlanned"),
'',
''),
1310 array(
'type' =>
'text',
'name' =>
'comment',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'',
'',
'class' =>
'minwidth300',
'moreattr'=>
'autofocus')
1312 $formconfirm =
$form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ActivateAllOnContract"), $langs->trans(
"ConfirmActivateAllOnContract"),
"confirm_activate", $formquestion,
'yes', 1, 280);
1313 } elseif ($action ==
'clone') {
1315 $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)')));
1316 $formconfirm =
$form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneContract', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1327 $reshook = $hookmanager->executeHooks(
'formConfirm',
$parameters, $object, $action);
1328 if (empty($reshook)) {
1330 } elseif ($reshook > 0) {
1339 if (!empty($object->brouillon) && $user->rights->contrat->creer) {
1340 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="POST">';
1341 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1342 print
'<input type="hidden" name="action" value="setremise">';
1347 $linkback =
'<a href="'.DOL_URL_ROOT.
'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1351 if (!empty($modCodeContract->code_auto)) {
1352 $morehtmlref .= $object->ref;
1354 $morehtmlref .=
$form->editfieldkey(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 3);
1355 $morehtmlref .=
$form->editfieldval(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 2);
1358 $morehtmlref .=
'<div class="refidno">';
1360 $morehtmlref .=
$form->editfieldkey(
"RefCustomer",
'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1361 $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');
1363 $morehtmlref .=
'<br>';
1364 $morehtmlref .=
$form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1365 $morehtmlref .=
$form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'',
null,
null,
'', 1,
'getFormatedSupplierRef');
1367 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1);
1368 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
1369 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/contrat/list.php?socid='.$object->thirdparty->id.
'&search_name='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherContracts").
'</a>)';
1373 $langs->load(
"projects");
1374 $morehtmlref .=
'<br>';
1375 if ($permissiontoadd) {
1376 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1377 if ($action !=
'classify') {
1378 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
1380 $morehtmlref .=
$form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, ($action ==
'classify' ? 1 : 0), 0, 1,
'');
1382 if (!empty($object->fk_project)) {
1384 $proj->fetch($object->fk_project);
1385 $morehtmlref .= $proj->getNomUrl(1);
1387 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
1392 $morehtmlref .=
'</div>';
1395 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'none', $morehtmlref);
1398 print
'<div class="fichecenter">';
1399 print
'<div class="underbanner clearboth"></div>';
1402 print
'<table class="border tableforfield" width="100%">';
1405 print
'<tr><td class="titlefield">'.$langs->trans(
'Discount').
'</td><td colspan="3">';
1406 if ($object->thirdparty->remise_percent) {
1407 print $langs->trans(
"CompanyHasRelativeDiscount", $object->thirdparty->remise_percent).
'. ';
1409 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1411 $absolute_discount = $object->thirdparty->getAvailableDiscounts();
1412 if ($absolute_discount) {
1413 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1415 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1421 print
'<td class="titlefield">';
1422 print
$form->editfieldkey(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer);
1424 print
$form->editfieldval(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer,
'datehourpicker');
1430 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1436 if (!empty($object->brouillon) && $user->rights->contrat->creer) {
1442 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1443 $blocname =
'contacts';
1444 $title = $langs->trans(
'ContactsAddresses');
1445 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1448 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1449 $blocname =
'notes';
1450 $title = $langs->trans(
'Notes');
1451 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1455 $arrayothercontracts = $object->getListOfContracts(
'others');
1463 global $inputalsopricewithtax;
1464 $inputalsopricewithtax = 1;
1466 $productstatic =
new Product($db);
1469 if (
isModEnabled(
'margin') && !empty($object->element) && in_array($object->element, array(
'facture',
'propal',
'commande'))) {
1477 print
'<div id="contrat-lines-container" id="contractlines" data-contractid="'.$object->id.
'" data-element="'.$object->element.
'" >';
1478 while ($cursorline <= $nbofservices) {
1479 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.
'" >';
1480 print
'<form name="update" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="post">';
1481 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1482 print
'<input type="hidden" name="action" value="updateline">';
1483 print
'<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.
'">';
1484 print
'<input type="hidden" name="fournprice" value="'.(!empty($object->lines[$cursorline - 1]->fk_fournprice) ? $object->lines[$cursorline - 1]->fk_fournprice : 0).
'">';
1487 print
'<div class="div-table-responsive-no-min">';
1488 print
'<table class="notopnoleftnoright allwidth tableforservicepart1" width="100%">';
1490 $sql =
"SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,";
1491 $sql .=
" cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1492 $sql .=
" cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";
1493 $sql .=
" cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";
1494 $sql .=
" cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1495 $sql .=
" cd.fk_unit,";
1496 $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";
1497 $sql .=
" ,cd.rang";
1498 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
1499 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
1500 $sql .=
" WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id);
1502 $result = $db->query($sql);
1506 $objp = $db->fetch_object($result);
1508 print
'<tr class="liste_titre'.($cursorline ?
' liste_titre_add' :
'').
'">';
1509 print
'<td>'.$langs->trans(
"ServiceNb", $cursorline).
'</td>';
1510 print
'<td width="80" class="center">'.$langs->trans(
"VAT").
'</td>';
1511 print
'<td width="80" class="right">'.$langs->trans(
"PriceUHT").
'</td>';
1515 print
'<td width="30" class="center">'.$langs->trans(
"Qty").
'</td>';
1517 print
'<td width="30" class="left">'.$langs->trans(
"Unit").
'</td>';
1519 print
'<td width="50" class="right">'.$langs->trans(
"ReductionShort").
'</td>';
1520 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1521 print
'<td width="50" class="right">'.$langs->trans(
"BuyingPrice").
'</td>';
1525 if ($nbofservices > 1 && $conf->browser->layout !=
'phone' && !empty($user->rights->contrat->creer)) {
1526 print
'<td width="30" class="linecolmove tdlineupdown center">';
1527 if ($cursorline > 1) {
1528 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=up&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1529 echo
img_up(
'default', 0,
'imgupforline');
1532 if ($cursorline < $nbofservices) {
1533 print
'<a class="lineupdown" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=down&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1534 echo
img_down(
'default', 0,
'imgdownforline');
1539 print
'<td width="30"> </td>';
1547 if ($action !=
'editline' ||
GETPOST(
'rowid') != $objp->rowid) {
1549 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1550 $moreparam =
'style="display: none;"';
1552 print
'<tr class="tdtop oddeven" '.$moreparam.
'>';
1554 if ($objp->fk_product > 0) {
1555 $productstatic->id = $objp->fk_product;
1556 $productstatic->type = $objp->ptype;
1557 $productstatic->ref = $objp->pref;
1558 $productstatic->entity = $objp->pentity;
1559 $productstatic->label = $objp->plabel;
1560 $productstatic->status = $objp->tosell;
1561 $productstatic->status_buy = $objp->tobuy;
1562 $productstatic->status_batch = $objp->tobatch;
1565 $text = $productstatic->getNomUrl(1,
'', 32);
1566 if ($objp->plabel) {
1568 $text .= $objp->plabel;
1570 $description = $objp->description;
1574 $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ?
'<br>'.
dol_htmlentitiesbr($objp->description) :
'';
1578 echo
$form->textwithtooltip($text, $description, 3,
'',
'', $cursorline, 0, (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
1582 print
'<td>'.img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->description).
"</td>\n";
1585 print
'<td class="center">';
1586 print
vatrate($objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''),
'%', $objp->info_bits);
1589 print
'<td class="right">'.($objp->subprice !=
'' ?
price($objp->subprice) :
'').
"</td>\n";
1595 print
'<td class="center">'.$objp->qty.
'</td>';
1598 print
'<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).
'</td>';
1601 if ($objp->remise_percent > 0) {
1602 print
'<td class="right">'.$objp->remise_percent.
"%</td>\n";
1604 print
'<td> </td>';
1608 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1609 print
'<td class="right nowraponall">'.price($objp->pa_ht).
'</td>';
1613 print
'<td class="nowraponall right">';
1614 if ($user->rights->contrat->creer && is_array($arrayothercontracts) && count($arrayothercontracts) && ($object->statut >= 0)) {
1615 print
'<!-- link to move service line into another contract -->';
1616 print
'<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=move&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1617 print
img_picto($langs->trans(
"MoveToAnotherContract"),
'uparrow');
1620 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1621 print
'<a class="reposition marginrightonly editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=editline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1625 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1626 print
'<a class="reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=deleteline&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1635 if ($objp->subprice >= 0) {
1644 print
'<tr class="oddeven" '.$moreparam.
'>';
1645 print
'<td colspan="'.$colspan.
'">';
1648 print $langs->trans(
"DateStartPlanned").
': ';
1649 if ($objp->date_start) {
1652 if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now - $conf->contrat->services->inactifs->warning_delay)) {
1653 $warning_delay = $conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1654 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1655 print
" ".img_warning($textlate);
1658 print $langs->trans(
"Unknown");
1660 print
' - ';
1661 print $langs->trans(
"DateEndPlanned").
': ';
1662 if ($objp->date_end) {
1664 if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now - $conf->contrat->services->expires->warning_delay)) {
1665 $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
1666 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1667 print
" ".img_warning($textlate);
1670 print $langs->trans(
"Unknown");
1678 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1680 $line->id = $objp->rowid;
1681 $line->fetch_optionals();
1682 print $line->showOptionals($extrafields,
'view', array(
'class'=>
'oddeven',
'style'=>$moreparam,
'colspan'=>$colspan),
'',
'', 1);
1687 print
'<tr class="oddeven">';
1689 if ($objp->fk_product > 0) {
1690 $canchangeproduct = 1;
1691 if (empty($canchangeproduct)) {
1692 $productstatic->id = $objp->fk_product;
1693 $productstatic->type = $objp->ptype;
1694 $productstatic->ref = $objp->pref;
1695 $productstatic->entity = $objp->pentity;
1696 print $productstatic->getNomUrl(1,
'', 32);
1697 print $objp->label ?
' - '.dol_trunc($objp->label, 32) :
'';
1698 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1700 $senderissupplier = 0;
1701 if (empty($senderissupplier)) {
1702 print
$form->select_produits((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1704 $form->select_produits_fournisseurs((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1709 print $objp->label ? $objp->label.
'<br>' :
'';
1710 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1714 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1716 if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1717 $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1719 $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1720 $doleditor =
new DolEditor(
'product_desc', $objp->description,
'', 92,
'dolibarr_details',
'',
false,
true, $enable, $nbrows,
'90%');
1721 $doleditor->Create();
1726 print
'<td class="right">';
1727 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);
1731 print
'<td class="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).
'"></td>';
1739 print
'<td class="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.
'"></td>';
1743 print
'<td class="left">';
1744 print
$form->selectUnits($objp->fk_unit,
"unit");
1749 print
'<td class="nowrap right"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.
'">%</td>';
1751 if (!empty($usemargins)) {
1752 print
'<td class="right">';
1753 if ($objp->fk_product) {
1754 print
'<select id="fournprice" name="fournprice"></select>';
1756 print
'<input id="buying_price" type="text" size="5" name="buying_price" value="'.price($objp->pa_ht, 0,
'', 0).
'"></td>';
1758 print
'<td class="center">';
1759 print
'<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans(
"Modify").
'">';
1760 print
'<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1765 if (
isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1773 print
'<tr class="oddeven">';
1774 print
'<td colspan="'.$colspan.
'">';
1775 print $langs->trans(
"DateStartPlanned").
' ';
1776 print
$form->selectDate($db->jdate($objp->date_start),
"date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1),
"update");
1777 print
' '.$langs->trans(
"DateEndPlanned").
' ';
1778 print
$form->selectDate($db->jdate($objp->date_end),
"date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1),
"update");
1782 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1784 $line->id = $objp->rowid;
1785 $line->fetch_optionals();
1786 print $line->showOptionals($extrafields,
'edit', array(
'style'=>
'class="oddeven"',
'colspan'=>$colspan),
'',
'', 1);
1795 if ($object->statut > 0) {
1797 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1798 $moreparam =
'style="display: none;"';
1800 print
'<tr class="oddeven" '.$moreparam.
'>';
1801 print
'<td class="tdhrthin" colspan="'.($conf->margin->enabled ? 7 : 6).
'"><hr class="opacitymedium tdhrthin"></td>';
1814 if ($action ==
'deleteline' && !$_REQUEST[
"cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1815 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid'), $langs->trans(
"DeleteContractLine"), $langs->trans(
"ConfirmDeleteContractLine"),
"confirm_deleteline",
'', 0, 1);
1816 if ($ret ==
'html') {
1817 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1824 if ($action ==
'move' && !$_REQUEST[
"cancel"] && $user->rights->contrat->creer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1825 $arraycontractid = array();
1826 foreach ($arrayothercontracts as $contractcursor) {
1827 $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1831 $formquestion = array(
1832 'text' => $langs->trans(
"ConfirmMoveToAnotherContractQuestion"),
1833 array(
'type' =>
'select',
'name' =>
'newcid',
'values' => $arraycontractid));
1835 print
$form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid',
'int'), $langs->trans(
"MoveToAnotherContract"), $langs->trans(
"ConfirmMoveToAnotherContract"),
"confirm_move", $formquestion);
1836 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1842 if ($action ==
'active' && !$cancel && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1845 $comment =
GETPOST(
'comment',
'alpha');
1846 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);
1847 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1853 if ($action ==
'closeline' && !$cancel && $user->rights->contrat->activer && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1856 $comment =
GETPOST(
'comment',
'alpha');
1858 if (empty($dateactend)) {
1859 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEndReal")),
null,
'errors');
1861 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);
1863 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1868 if ($object->statut > 0) {
1869 print
'<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1871 print
'<tr class="oddeven" '.$moreparam.
'>';
1872 print
'<td><span class="valignmiddle hideonsmartphone">'.$langs->trans(
"ServiceStatus").
':</span> '.$object->lines[$cursorline - 1]->getLibStatut(4).
'</td>';
1873 print
'<td width="30" class="right">';
1874 if ($user->socid == 0) {
1875 if ($object->statut > 0 && $action !=
'activateline' && $action !=
'unactivateline') {
1876 $tmpaction =
'activateline';
1877 $tmpactionpicto =
'play';
1878 $tmpactiontext = $langs->trans(
"Activate");
1879 if ($objp->statut == 4) {
1880 $tmpaction =
'unactivateline';
1881 $tmpactionpicto =
'playstop';
1882 $tmpactiontext = $langs->trans(
"Disable");
1884 if (($tmpaction ==
'activateline' && $user->rights->contrat->activer) || ($tmpaction ==
'unactivateline' && $user->rights->contrat->desactiver)) {
1885 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'&action='.$tmpaction.
'">';
1886 print
img_picto($tmpactiontext, $tmpactionpicto);
1894 print
'<tr class="oddeven" '.$moreparam.
'>';
1898 if (!$objp->date_start_real) {
1899 print $langs->trans(
"DateStartReal").
': ';
1900 if ($objp->date_start_real) {
1903 print $langs->trans(
"ContractStatusNotRunning");
1907 if ($objp->date_start_real && !$objp->date_end_real) {
1908 print $langs->trans(
"DateStartReal").
': ';
1912 if ($objp->date_start_real && $objp->date_end_real) {
1913 print $langs->trans(
"DateStartReal").
': ';
1915 print
' - ';
1916 print $langs->trans(
"DateEndReal").
': ';
1919 if (!empty($objp->comment)) {
1920 print
" - ".$objp->comment;
1924 print
'<td class="center"> </td>';
1931 if ($user->rights->contrat->activer && $action ==
'activateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1932 print
'<form name="active" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.
GETPOST(
'ligne',
'int').
'&action=active" method="post">';
1933 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1935 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1938 $dateactstart = $objp->date_start;
1941 } elseif (!$dateactstart) {
1942 $dateactstart = time();
1945 $dateactend = $objp->date_end;
1948 } elseif (!$dateactend) {
1949 if ($objp->fk_product > 0) {
1951 $product->fetch($objp->fk_product);
1952 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
1956 print
'<tr class="oddeven">';
1957 print
'<td class="nohover">'.$langs->trans(
"DateServiceActivate").
'</td><td class="nohover">';
1958 print
$form->selectDate($dateactstart,
'', $usehm, $usehm,
'',
"active", 1, 0);
1960 print
'<td class="nohover">'.$langs->trans(
"DateEndPlanned").
'</td><td class="nohover">';
1961 print
$form->selectDate($dateactend,
"end", $usehm, $usehm,
'',
"active", 1, 0);
1963 print
'<td class="center nohover">';
1968 print
'<tr class="oddeven">';
1969 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>';
1970 print
'<td class="nohover right">';
1971 print
'<input type="submit" class="button" name="activate" value="'.$langs->trans(
"Activate").
'"> ';
1972 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1981 if ($user->rights->contrat->activer && $action ==
'unactivateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1985 print
'<!-- Form to disabled a line -->'.
"\n";
1986 print
'<form name="closeline" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'" method="post">';
1988 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1989 print
'<input type="hidden" name="action" value="closeline">';
1991 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
'" width="100%">';
1994 $dateactstart = $objp->date_start_real;
1997 } elseif (!$dateactstart) {
1998 $dateactstart = time();
2001 $dateactend = $objp->date_end_real;
2004 } elseif (!$dateactend) {
2005 if ($objp->fk_product > 0) {
2007 $product->fetch($objp->fk_product);
2008 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2012 if ($dateactend > $now) {
2016 print
'<tr class="oddeven"><td colspan="2" class="nohover">';
2017 if ($objp->statut >= 4) {
2018 if ($objp->statut == 4) {
2019 print $langs->trans(
"DateEndReal").
' ';
2020 print
$form->selectDate($dateactend,
"end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1),
"closeline", 1, 1);
2024 print
'<td class="center nohover">';
2027 print
'<tr class="oddeven">';
2028 print
'<td class="nohover">'.$langs->trans(
"Comment").
'</td><td class="nohover"><input class="quatrevingtpercent" type="text" class="flat" name="comment" value="'.
dol_escape_htmltag(
GETPOST(
'comment',
'alpha')).
'"></td>';
2029 print
'<td class="nohover right">';
2030 print
'<input type="submit" class="button" name="close" value="'.$langs->trans(
"Disable").
'"> ';
2031 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2045 if ($user->rights->contrat->creer && ($object->statut == 0)) {
2049 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'#add' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2050 <input type="hidden" name="token" value="'.
newToken().
'">
2051 <input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">
2052 <input type="hidden" name="mode" value="">
2053 <input type="hidden" name="id" value="'.$object->id.
'">
2056 print
'<div class="div-table-responsive-no-min">';
2057 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2060 if ($action !=
'editline') {
2061 $forcetoshowtitlelines = 1;
2062 if (empty($object->multicurrency_code)) {
2063 $object->multicurrency_code = $conf->currency;
2069 $reshook = $hookmanager->executeHooks(
'formAddObjectLine',
$parameters, $object, $action);
2070 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2071 if (empty($reshook))
2072 $object->formAddObjectLine(1, $mysoc, $soc);
2083 if (
GETPOST(
'modelselected')) {
2084 $action =
'presend';
2090 if ($user->socid == 0 && $action !=
'presend' && $action !=
'editline') {
2091 print
'<div class="tabsAction">';
2094 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons',
$parameters, $object, $action);
2096 if (empty($reshook)) {
2100 'class' =>
'classfortooltip'
2105 if (empty($user->socid)) {
2106 if ($object->statut == 1) {
2107 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) {
2108 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle',
'',
true, $params);
2110 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
2115 if ($object->statut == 0 && $nbofservices) {
2116 if ($user->rights->contrat->creer) {
2117 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
2119 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2120 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default',
'#',
'',
false, $params);
2123 if ($object->statut == 1) {
2124 if ($user->rights->contrat->creer) {
2125 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
2127 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2128 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
2132 if (
isModEnabled(
'commande') && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) {
2133 $langs->load(
"orders");
2134 if ($user->rights->commande->creer) {
2135 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);
2137 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2138 print
dolGetButtonAction($langs->trans(
'CreateOrder'),
'',
'default',
'#',
'',
false, $params);
2143 $langs->load(
"bills");
2144 if ($user->rights->facture->creer) {
2145 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);
2147 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2148 print
dolGetButtonAction($langs->trans(
'CreateBill'),
'',
'default',
'#',
'',
false, $params);
2152 if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {
2153 if ($user->rights->contrat->activer) {
2154 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=activate&token='.
newToken(),
'',
true, $params);
2156 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default',
'#',
'',
false, $params);
2159 if ($object->nbofservicesclosed < $nbofservices) {
2160 if ($user->rights->contrat->desactiver) {
2161 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=close&token='.
newToken(),
'',
true, $params);
2163 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default',
'#',
'',
false, $params);
2175 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) {
2176 if ($action ==
'showclosedlines') {
2177 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>';
2179 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>';
2184 if ($user->rights->contrat->creer) {
2185 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&token='.
newToken(),
'',
true, $params);
2189 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete, $params);
2195 if ($action !=
'presend') {
2196 print
'<div class="fichecenter"><div class="fichehalfleft">';
2202 $filedir = $conf->contrat->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2203 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2204 $genallowed = $user->rights->contrat->lire;
2205 $delallowed = $user->rights->contrat->creer;
2208 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);
2212 $linktoelem =
$form->showLinkToObjectBlock($object,
null, array(
'contrat'));
2213 $somethingshown =
$form->showLinkedObjectBlock($object, $linktoelem);
2216 if ($object->statut != Contrat::STATUS_DRAFT &&
getDolGlobalString(
'CONTRACT_ALLOW_ONLINESIGN')) {
2217 print
'<br><!-- Link to sign -->';
2218 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2220 print showOnlineSignatureUrl(
'contract', $object->ref).
'<br>';
2223 print
'</div><div class="fichehalfright">';
2227 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/agenda.php?id='.$object->id);
2231 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2233 $somethingshown =
$formactions->showactions($object,
'contract', $socid, 1,
'listactions', $MAXEVENT,
'', $morehtmlcenter);
2235 print
'</div></div>';
2239 $modelmail =
'contract';
2240 $defaulttopic =
'SendContractRef';
2241 $diroutput = $conf->contrat->multidir_output[$object->entity];
2242 $trackid =
'con'.$object->id;
2244 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
2258 <script
type=
"text/javascript">
2259 $(document).ready(
function() {
2260 var idprod = $(
"input[name='idprod']").val();
2261 var fournprice = $(
"input[name='fournprice']").val();
2262 var token =
'<?php echo currentToken(); ?>';
2264 $.post(
'<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2268 if (data.length > 0) {
2271 $(data).each(
function() {
2272 options +=
'<option value="'+this.
id+
'" price="'+this.
price+
'"';
2273 if (fournprice > 0) {
2274 if (this.
id == fournprice) {
2275 options +=
' selected';
2276 $(
"#buying_price").val(this.price);
2280 options +=
'>'+this.label+
'</option>';
2282 options +=
'<option value=null'+(trouve?
'':
' selected')+
'><?php echo $langs->trans("InputPrice"); ?></option>';
2283 $(
"#fournprice").html(options);
2285 $(
"#buying_price").hide();
2286 $(
"#fournprice").show();
2289 $(
"#buying_price").show();
2291 $(
"#fournprice").change(
function() {
2292 var selval = $(
this).find(
'option:selected').attr(
"price");
2294 $(
"#buying_price").val(selval).hide();
2296 $(
'#buying_price').show();
2300 $(
"#fournprice").hide();
2301 $(
'#buying_price').show();
2307 $(
"#fournprice").hide();
2308 $(
'#buying_price').show();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage contracts.
Class to manage lines of contracts.
Class to manage a WYSIWYG editor.
Class to manage products or services.
File of class to manage predefined price products or services by customer.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
contract_prepare_head(Contrat $object)
Prepare array with list of tabs.
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_move($srcfile, $destfile, $newmask=0, $overwriteifexists=1, $testvirus=0, $indexdatabase=1)
Move a file into another name.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formated for view output Used into pdf and HTML pages.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
img_down($titlealt='default', $selected=0, $moreclass='')
Show down arrow logo.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Fonction qui renvoie si tva doit etre tva percue recuperable.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
isModEnabled($module)
Is Dolibarr module enabled.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
$formconfirm
if ($action == 'delbookkeepingyear') {
if(preg_match('/crypted:/i', $dolibarr_main_db_pass)||!empty($dolibarr_main_db_encrypted_pass)) $conf db type
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.