34require
"../main.inc.php";
35require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
36require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/lib/contract.lib.php';
38require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
44if (isModEnabled(
"propal")) {
45 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
47if (isModEnabled(
'project')) {
48 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
49 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
51require_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');
59$backtopage =
GETPOST(
'backtopage',
'alpha');
61$socid =
GETPOST(
'socid',
'int');
64$origin =
GETPOST(
'origin',
'alpha');
65$originid =
GETPOST(
'originid',
'int');
68$usehm = (!empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE) ? $conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
72 $socid = $user->socid;
77$hookmanager->initHooks(array(
'contractcard',
'globalcard'));
83if ($id > 0 || !empty($ref) && $action !=
'add') {
84 $ret = $object->fetch($id, $ref);
86 $ret = $object->fetch_thirdparty();
94$extrafields->fetch_name_optionals_label($object->table_element);
97$extralabelslines = $extrafields->fetch_name_optionals_label($object->table_element_line);
99$permissionnote = $user->hasRight(
'contrat',
'creer');
100$permissiondellink = $user->hasRight(
'contrat',
'creer');
101$permissiontodelete = ($user->hasRight(
'contrat',
'creer') && $object->statut == $object::STATUS_DRAFT) || $user->hasRight(
'contrat',
'supprimer');
102$permissiontoadd = $user->hasRight(
'contrat',
'creer');
103$permissiontoedit = $permissiontoadd;
111$parameters = array(
'socid' => $socid);
112$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
116if (empty($reshook)) {
117 $backurlforlist = DOL_URL_ROOT.
'/contrat/list.php';
119 if (empty($backtopage) || ($cancel && empty($id))) {
120 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
121 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
122 $backtopage = $backurlforlist;
124 $backtopage = DOL_URL_ROOT.
'/contrat/card.php?id='.((!empty($id) && $id > 0) ? $id :
'__ID__');
130 if (!empty($backtopageforcancel)) {
131 header(
"Location: ".$backtopageforcancel);
133 } elseif (!empty($backtopage)) {
134 header(
"Location: ".$backtopage);
140 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
142 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
144 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
146 if ($action ==
'confirm_active' && $confirm ==
'yes' && $user->rights->contrat->activer) {
156 $result = $object->active_line($user,
GETPOST(
'ligne',
'int'), $date_start, $date_end,
GETPOST(
'comment'));
159 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
164 } elseif ($action ==
'confirm_closeline' && $confirm ==
'yes' && $user->rights->contrat->activer) {
171 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEnd")),
null,
'errors');
174 $result = $object->close_line($user,
GETPOST(
'ligne',
'int'), $date_end, urldecode(
GETPOST(
'comment')));
176 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
185 if (
GETPOST(
'mode') ==
'predefined') {
197 $date_start_update =
'';
198 $date_end_update =
'';
199 $date_start_real_update =
'';
200 $date_end_real_update =
'';
201 if (
GETPOST(
'date_start_updatemonth') &&
GETPOST(
'date_start_updateday') &&
GETPOST(
'date_start_updateyear')) {
204 if (
GETPOST(
'date_end_updatemonth') &&
GETPOST(
'date_end_updateday') &&
GETPOST(
'date_end_updateyear')) {
207 if (
GETPOST(
'date_start_real_updatemonth') &&
GETPOST(
'date_start_real_updateday') &&
GETPOST(
'date_start_real_updateyear')) {
208 $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'));
210 if (
GETPOST(
'date_end_real_updatemonth') &&
GETPOST(
'date_end_real_updateday') &&
GETPOST(
'date_end_real_updateyear')) {
211 $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'));
218 if ($action ==
'add' && $user->hasRight(
'contrat',
'creer')) {
220 if (empty($datecontrat)) {
222 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
227 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
233 $ret = $extrafields->setOptionalsFromPost(
null, $object);
240 $object->socid = $socid;
241 $object->date_contrat = $datecontrat;
243 $object->commercial_suivi_id =
GETPOST(
'commercial_suivi_id',
'int');
244 $object->commercial_signature_id =
GETPOST(
'commercial_signature_id',
'int');
246 $object->note_private =
GETPOST(
'note_private',
'alpha');
247 $object->note_public =
GETPOST(
'note_public',
'alpha');
248 $object->fk_project =
GETPOST(
'projectid',
'int');
250 $object->ref =
GETPOST(
'ref',
'alpha');
251 $object->ref_customer =
GETPOST(
'ref_customer',
'alpha');
252 $object->ref_supplier =
GETPOST(
'ref_supplier',
'alpha');
255 if (!empty($origin) && !empty($originid)) {
257 $element = $subelement = $origin;
258 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
260 $subelement = $regs[2];
264 if ($element ==
'order') {
265 $element = $subelement =
'commande';
267 if ($element ==
'propal') {
268 $element =
'comm/propal'; $subelement =
'propal';
270 if ($element ==
'invoice' || $element ==
'facture') {
271 $element =
'compta/facture';
272 $subelement =
'facture';
275 $object->origin = $origin;
276 $object->origin_id = $originid;
279 $object->linked_objects[$object->origin] = $object->origin_id;
280 if (is_array($_POST[
'other_linked_objects']) && !empty($_POST[
'other_linked_objects'])) {
281 $object->linked_objects = array_merge($object->linked_objects, $_POST[
'other_linked_objects']);
284 $id = $object->create($user);
288 $classname = ucfirst($subelement);
289 $srcobject =
new $classname($db);
291 dol_syslog(
"Try to find source object origin=".$object->origin.
" originid=".$object->origin_id.
" to add lines");
292 $result = $srcobject->fetch($object->origin_id);
294 $srcobject->fetch_thirdparty();
295 $lines = $srcobject->lines;
296 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
297 $srcobject->fetch_lines();
298 $lines = $srcobject->lines;
302 $num = count($lines);
304 for ($i = 0; $i < $num; $i++) {
305 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
307 if ($product_type == 1 || (!empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0, 1)))) {
309 if ($lines[$i]->fk_product > 0) {
310 $product_static =
new Product($db);
313 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
315 $prod->id = $lines[$i]->fk_product;
316 $prod->getMultiLangs();
318 $outputlangs = $langs;
320 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
321 $newlang =
GETPOST(
'lang_id',
'aZ09');
323 if (empty($newlang)) {
324 $newlang = $srcobject->thirdparty->default_lang;
326 if (!empty($newlang)) {
328 $outputlangs->setDefaultLang($newlang);
331 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"libelle"])) ? $prod->multilangs[$outputlangs->defaultlang][
"libelle"] : $lines[$i]->product_label;
333 $label = $lines[$i]->product_label;
335 $desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->libelle) ?
dol_htmlentitiesbr($lines[$i]->desc) :
'';
341 $array_options = array();
343 if (method_exists($lines[$i],
'fetch_optionals')) {
344 $lines[$i]->fetch_optionals();
345 $array_options = $lines[$i]->array_options;
348 $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx.
' ('.$lines[$i]->vat_src_code.
')' : $lines[$i]->tva_tx;
351 $localtax1_tx =
get_localtax($txtva, 1, $object->thirdparty);
352 $localtax2_tx =
get_localtax($txtva, 2, $object->thirdparty);
354 $result = $object->addline(
356 $lines[$i]->subprice,
361 $lines[$i]->fk_product,
362 $lines[$i]->remise_percent,
363 $lines[$i]->date_start,
364 $lines[$i]->date_end,
367 $lines[$i]->info_bits,
368 $lines[$i]->fk_fournprice,
387 $parameters = array(
'objFrom' => $srcobject);
388 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $object, $action);
402 $result = $object->create($user);
404 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
412 } elseif ($action ==
'classin' && $user->hasRight(
'contrat',
'creer')) {
413 $object->setProject(
GETPOST(
'projectid'));
414 } elseif ($action ==
'addline' && $user->hasRight(
'contrat',
'creer')) {
418 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
421 $price_ht_devise =
'';
423 $price_ttc_devise =
'';
425 $rang = count($object->lines) + 1;
427 if (
GETPOST(
'price_ht') !==
'') {
430 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
433 if (
GETPOST(
'price_ttc') !==
'') {
436 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
440 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free') {
443 $idprod =
GETPOST(
'idprod',
'int');
445 if (!empty($conf->global->MAIN_DISABLE_FREE_LINES) && $idprod <= 0) {
446 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
451 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
454 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef), 2) : 0);
455 if (empty($remise_percent)) {
460 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
463 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
464 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
470 if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
471 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
476 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
477 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
479 if (is_array($extralabelsline)) {
481 foreach ($extralabelsline as $key => $value) {
482 unset($_POST[
"options_".$key]);
495 $prod->fetch($idprod);
504 $price_min = $prod->price_min;
505 $price_min_ttc = $prod->price_min_ttc;
508 if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) {
509 $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
510 $price_min_ttc = $prod->multiprices_min_ttc[$object->thirdparty->price_level];
511 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
513 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
517 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' => $object->thirdparty->id);
519 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
521 if (count($prodcustprice->lines) > 0) {
522 $price_min =
price($prodcustprice->lines[0]->price_min);
523 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
536 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
537 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $prod->tva_tx));
540 if (!empty($price_ht) || $price_ht ===
'0') {
542 $pu_ttc =
price2num($pu_ht * (1 + ($tmpvat / 100)),
'MU');
543 $price_base_type =
'HT';
544 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
546 $pu_ht =
price2num($pu_ttc / (1 + ($tmpvat / 100)),
'MU');
547 $price_base_type =
'TTC';
550 $desc = $prod->description;
553 if ($product_desc == $desc && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
557 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
558 $desc = $product_desc;
560 $desc =
dol_concatdesc($desc, $product_desc,
'', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
563 $fk_unit = $prod->fk_unit;
567 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
568 if (empty($tva_tx)) {
571 $tva_tx = str_replace(
'*',
'', $tva_tx);
572 $desc = $product_desc;
573 $fk_unit =
GETPOST(
'units',
'alpha');
574 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
575 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
577 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
580 if (!empty($price_ht) || $price_ht ===
'0') {
582 $pu_ttc =
price2num($pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
583 $price_base_type =
'HT';
584 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
586 $pu_ht =
price2num($pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
587 $price_base_type =
'TTC';
591 $localtax1_tx =
get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
592 $localtax2_tx =
get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
595 $fk_fournprice =
GETPOST(
'fournprice');
597 $pa_ht =
GETPOST(
'buying_price');
607 if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance))
608 || empty($conf->global->MAIN_USE_ADVANCED_PERMS)) && ($price_min && (
price2num($pu_ht) * (1 -
price2num($remise_percent) / 100) <
price2num($price_min)))) {
609 $object->error = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1, $conf->currency));
613 $result = $object->addline(
637 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE) && !empty($conf->global->CONTRACT_ADDON_PDF)) {
638 $outputlangs = $langs;
641 $newlang =
GETPOST(
'lang_id',
'aZ09');
644 $newlang = $object->thirdparty->default_lang;
646 if (!empty($newlang)) {
648 $outputlangs->setDefaultLang($newlang);
651 $ret = $object->fetch($id);
653 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
656 unset($_POST[
'prod_entry_mode']);
658 unset($_POST[
'qty']);
659 unset($_POST[
'type']);
660 unset($_POST[
'remise_percent']);
661 unset($_POST[
'price_ht']);
662 unset($_POST[
'multicurrency_price_ht']);
663 unset($_POST[
'price_ttc']);
664 unset($_POST[
'tva_tx']);
665 unset($_POST[
'product_ref']);
666 unset($_POST[
'product_label']);
667 unset($_POST[
'product_desc']);
668 unset($_POST[
'fournprice']);
669 unset($_POST[
'buying_price']);
670 unset($_POST[
'np_marginRate']);
671 unset($_POST[
'np_markRate']);
672 unset($_POST[
'dp_desc']);
673 unset($_POST[
'idprod']);
675 unset($_POST[
'date_starthour']);
676 unset($_POST[
'date_startmin']);
677 unset($_POST[
'date_startsec']);
678 unset($_POST[
'date_startday']);
679 unset($_POST[
'date_startmonth']);
680 unset($_POST[
'date_startyear']);
681 unset($_POST[
'date_endhour']);
682 unset($_POST[
'date_endmin']);
683 unset($_POST[
'date_endsec']);
684 unset($_POST[
'date_endday']);
685 unset($_POST[
'date_endmonth']);
686 unset($_POST[
'date_endyear']);
691 } elseif ($action ==
'updateline' && $user->hasRight(
'contrat',
'creer') && !
GETPOST(
'cancel',
'alpha')) {
695 if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
696 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
697 $action =
'editline';
698 $_GET[
'rowid'] =
GETPOST(
'elrowid');
704 if ($objectline->fetch(
GETPOST(
'elrowid',
'int')) < 0) {
708 $objectline->fetch_optionals();
710 $objectline->oldcopy =
dol_clone($objectline);
716 if ($date_start_real_update ==
'') {
717 $date_start_real_update = $objectline->date_start_real;
719 if ($date_end_real_update ==
'') {
720 $date_end_real_update = $objectline->date_end_real;
723 $vat_rate =
GETPOST(
'eltva_tx',
'alpha');
726 if (preg_match(
'/\*/', $vat_rate)) {
731 $vat_rate = str_replace(
'*',
'', $vat_rate);
732 $localtax1_tx =
get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
733 $localtax2_tx =
get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
740 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
741 $vat_src_code = $reg[1];
742 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
752 $fk_unit =
GETPOST(
'unit',
'alpha');
759 if ($remise_percent > 0) {
760 $remise = round(($price_ht * $remise_percent / 100), 2);
761 $price_ht = ($price_ht - $remise);
764 $objectline->fk_product =
GETPOST(
'idprod',
'int');
765 $objectline->description =
GETPOST(
'product_desc',
'restricthtml');
766 $objectline->price_ht = $price_ht;
769 $objectline->remise_percent = $remise_percent;
770 $objectline->tva_tx = ($txtva ? $txtva : 0);
771 $objectline->vat_src_code = $vat_src_code;
772 $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
773 $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
774 $objectline->date_start = $date_start_update;
775 $objectline->date_start_real = $date_start_real_update;
776 $objectline->date_end = $date_end_update;
777 $objectline->date_end_real = $date_end_real_update;
778 $objectline->fk_user_cloture = $user->id;
780 $objectline->pa_ht = $pa_ht;
781 $objectline->rang = $objectline->rang;
784 $objectline->fk_unit =
GETPOST(
'unit');
786 $objectline->fk_unit =
null;
790 $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
791 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
793 if (is_array($array_options) && count($array_options) > 0) {
795 foreach ($array_options as $key => $value) {
796 $objectline->array_options[$key] = $array_options[$key];
802 $result = $objectline->update($user);
805 $action =
'editline';
806 $_GET[
'rowid'] =
GETPOST(
'elrowid');
816 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
817 $result = $object->deleteline(
GETPOST(
'lineid',
'int'), $user);
820 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
825 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
826 $result = $object->validate($user);
830 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
831 $outputlangs = $langs;
834 $newlang =
GETPOST(
'lang_id',
'aZ09');
837 $newlang = $object->thirdparty->default_lang;
839 if (!empty($newlang)) {
841 $outputlangs->setDefaultLang($newlang);
843 $model = $object->model_pdf;
844 $ret = $object->fetch($id);
846 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
851 } elseif ($action ==
'reopen' && $user->hasRight(
'contrat',
'creer')) {
852 $result = $object->reopen($user);
856 } elseif ($action ==
'confirm_close' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
858 $result = $object->closeAll($user);
862 } elseif ($action ==
'confirm_activate' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
865 $comment =
GETPOST(
'comment',
'alpha');
866 $result = $object->activateAll($user, $date_start, 0, $comment, $date_end);
870 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'supprimer')) {
871 $result = $object->delete($user);
873 header(
"Location: list.php?restore_lastsearch_values=1");
878 } elseif ($action ==
'confirm_move' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
881 $result = $contractline->fetch(
GETPOSTINT(
'lineid'));
882 $contractline->fk_contrat =
GETPOSTINT(
'newcid');
883 $result = $contractline->update($user, 1);
885 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
891 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"RefNewContract")),
null,
'errors');
893 } elseif ($action ==
'update_extras') {
897 $ret = $extrafields->setOptionalsFromPost(
null, $object,
GETPOST(
'attribute',
'restricthtml'));
903 $result = $object->insertExtraFields(
'CONTRACT_MODIFY');
911 $action =
'edit_extras';
913 } elseif ($action ==
'setref_supplier') {
917 $result = $object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
920 $action =
'editref_supplier';
922 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
926 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
929 } elseif ($action ==
'setref_customer') {
933 $result = $object->setValueFrom(
'ref_customer',
GETPOST(
'ref_customer',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
936 $action =
'editref_customer';
938 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
942 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
945 } elseif ($action ==
'setref') {
947 $result = $object->fetch($id);
952 $old_ref = $object->ref;
954 $result = $object->setValueFrom(
'ref',
GETPOST(
'ref',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
959 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
960 $old_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($old_ref);
961 $new_filedir = $conf->contrat->multidir_output[$object->entity].
'/'.
dol_sanitizeFileName($object->ref);
966 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
970 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
973 } elseif ($action ==
'setdate_contrat') {
975 $result = $object->fetch($id);
980 $result = $object->setValueFrom(
'date_contrat', $datacontrat,
'',
null,
'date',
'', $user,
'CONTRACT_MODIFY');
983 $action =
'editdate_contrat';
985 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
989 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
995 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
998 $upload_dir = $conf->contrat->multidir_output[$object->entity];
999 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1002 $triggersendname =
'CONTRACT_SENTBYMAIL';
1004 $mode =
'emailfromcontract';
1005 $trackid =
'con'.$object->id;
1006 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1009 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->hasRight(
'contrat',
'creer')) {
1010 if ($action ==
'addcontact') {
1013 $result = $object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1016 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1019 if ($object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1020 $langs->load(
"errors");
1021 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1026 } elseif ($action ==
'swapstatut') {
1028 $result = $object->swapContactStatus(
GETPOST(
'ligne',
'int'));
1029 } elseif ($action ==
'deletecontact') {
1031 $result = $object->delete_contact(
GETPOST(
'lineid',
'int'));
1034 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$object->id);
1043 if ($action ==
'confirm_clone' && $confirm ==
'yes') {
1045 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1047 if ($object->id > 0) {
1048 $result = $object->createFromClone($user, $socid);
1050 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1053 if (count($object->errors) > 0) {
1069$help_url =
'EN:Module_Contracts|FR:Module_Contrat';
1071llxHeader(
'', $langs->trans(
"Contract"), $help_url);
1073$form =
new Form($db);
1075if (isModEnabled(
'project')) {
1080$module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON :
'mod_contract_serpis');
1081if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
1082 $module = substr($module, 0,
dol_strlen($module) - 4);
1086 $modCodeContract =
new $module();
1090if ($action ==
'create') {
1095 $soc->fetch($socid);
1101 $element = $subelement =
GETPOST(
'origin');
1102 if (preg_match(
'/^([^_]+)_([^_]+)/i',
GETPOST(
'origin'), $regs)) {
1103 $element = $regs[1];
1104 $subelement = $regs[2];
1107 if ($element ==
'project') {
1108 $projectid =
GETPOST(
'originid',
'int');
1111 if ($element ==
'order' || $element ==
'commande') {
1112 $element = $subelement =
'commande';
1114 if ($element ==
'propal') {
1115 $element =
'comm/propal'; $subelement =
'propal';
1117 if ($element ==
'invoice' || $element ==
'facture') {
1118 $element =
'compta/facture';
1119 $subelement =
'facture';
1124 $classname = ucfirst($subelement);
1125 $objectsrc =
new $classname($db);
1126 $objectsrc->fetch($originid);
1127 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1128 $objectsrc->fetch_lines();
1130 $objectsrc->fetch_thirdparty();
1133 $objectsrc->fetch_optionals();
1134 $object->array_options = $objectsrc->array_options;
1136 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1138 $soc = $objectsrc->thirdparty;
1140 $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private :
'');
1141 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public :
'');
1144 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1147 $projectid =
GETPOST(
'projectid',
'int');
1148 $note_private =
GETPOST(
"note_private");
1149 $note_public =
GETPOST(
"note_public");
1152 $object->date_contrat =
dol_now();
1154 print
'<form name="form_contract" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1155 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1156 print
'<input type="hidden" name="action" value="add">';
1157 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1158 print
'<input type="hidden" name="remise_percent" value="0">';
1159 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1163 print
'<table class="border centpercent">';
1166 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>';
1167 if (!empty($modCodeContract->code_auto)) {
1168 $tmpcode = $langs->trans(
"Draft");
1170 $tmpcode =
'<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(
GETPOST(
'ref') ?
GETPOST(
'ref') : $tmpcode).
'">';
1176 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
1177 print
'<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(
GETPOST(
'ref_customer',
'alpha')).
'"></td></tr>';
1180 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td>';
1181 print
'<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(
GETPOST(
'ref_supplier',
'alpha')).
'"></td></tr>';
1185 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1188 print $soc->getNomUrl(1);
1189 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1193 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
1194 print $form->select_company(
'',
'socid',
'',
'SelectThirdParty', 1, 0,
null, 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
1195 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>';
1202 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1203 if ($soc->remise_percent) {
1204 print $langs->trans(
"CompanyHasRelativeDiscount", $soc->remise_percent).
' ';
1206 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1208 $absolute_discount = $soc->getAvailableDiscounts();
1209 if ($absolute_discount) {
1210 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1212 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1218 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPFOLL").
'</span></td><td>';
1219 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1220 print $form->select_dolusers(
GETPOST(
"commercial_suivi_id") ?
GETPOST(
"commercial_suivi_id") : $user->id,
'commercial_suivi_id', 1,
'');
1224 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPSIGN").
'</span></td><td>';
1225 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1226 print $form->select_dolusers(
GETPOST(
"commercial_signature_id") ?
GETPOST(
"commercial_signature_id") : $user->id,
'commercial_signature_id', 1,
'');
1229 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Date").
'</span></td><td>';
1230 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
1231 print $form->selectDate($datecontrat,
'', 0, 0,
'',
"contrat");
1235 if (isModEnabled(
'project')) {
1236 $langs->load(
'projects');
1240 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
1241 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
1242 $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
"projectid", 0, 0, 1, 1);
1243 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>';
1247 print
'<tr><td>'.$langs->trans(
"NotePublic").
'</td><td class="tdtop">';
1248 $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%');
1249 print $doleditor->Create(1);
1252 if (empty($user->socid)) {
1253 print
'<tr><td>'.$langs->trans(
"NotePrivate").
'</td><td class="tdtop">';
1254 $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%');
1255 print $doleditor->Create(1);
1260 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="3"',
'cols' =>
'3');
1261 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $object, $action);
1262 print $hookmanager->resPrint;
1265 if (empty($reshook)) {
1266 print $object->showOptionals($extrafields,
'create', $parameters);
1273 print $form->buttonsSaveCancel(
"Create");
1275 if (is_object($objectsrc)) {
1276 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1277 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1279 if (empty($conf->global->CONTRACT_SUPPORT_PRODUCTS)) {
1280 print
'<br>'.$langs->trans(
"Note").
': '.$langs->trans(
"OnlyLinesWithTypeServiceAreUsed");
1289 if ($object->id > 0) {
1290 $object->fetch_thirdparty();
1292 $soc = $object->thirdparty;
1294 $result = $object->fetch_lines();
1299 $nbofservices = count($object->lines);
1301 $author =
new User($db);
1302 $author->fetch($object->user_author_id);
1304 $commercial_signature =
new User($db);
1305 $commercial_signature->fetch($object->commercial_signature_id);
1307 $commercial_suivi =
new User($db);
1308 $commercial_suivi->fetch($object->commercial_suivi_id);
1315 print
dol_get_fiche_head($head, $hselected, $langs->trans(
"Contract"), -1,
'contract');
1318 if ($action ==
'delete') {
1320 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"DeleteAContract"), $langs->trans(
"ConfirmDeleteAContract"),
"confirm_delete",
'', 0, 1);
1321 } elseif ($action ==
'valid') {
1323 $ref = substr($object->ref, 1, 4);
1324 if ($ref ==
'PROV' && !empty($modCodeContract->code_auto)) {
1325 $numref = $object->getNextNumRef($object->thirdparty);
1327 $numref = $object->ref;
1329 $text = $langs->trans(
'ConfirmValidateContract', $numref);
1330 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ValidateAContract"), $text,
"confirm_valid",
'', 0, 1);
1331 } elseif ($action ==
'close') {
1333 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"CloseAContract"), $langs->trans(
"ConfirmCloseContract"),
"confirm_close",
'', 0, 1);
1334 } elseif ($action ==
'activate') {
1335 $formquestion = array(
1336 array(
'type' =>
'date',
'name' =>
'd_start',
'label' => $langs->trans(
"DateServiceActivate"),
'value' =>
dol_now()),
1337 array(
'type' =>
'date',
'name' =>
'd_end',
'label' => $langs->trans(
"DateEndPlanned"),
'',
''),
1338 array(
'type' =>
'text',
'name' =>
'comment',
'label' => $langs->trans(
"Comment"),
'value' =>
'',
'',
'',
'class' =>
'minwidth300',
'moreattr'=>
'autofocus')
1340 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".$object->id, $langs->trans(
"ActivateAllOnContract"), $langs->trans(
"ConfirmActivateAllOnContract"),
"confirm_activate", $formquestion,
'yes', 1, 280);
1341 } elseif ($action ==
'clone') {
1342 $filter =
'(s.client:IN:1,2,3)';
1344 $formquestion = array(array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOST(
'socid',
'int'),
'socid', $filter)));
1345 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneContract', $object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1350 $parameters = array(
1351 'formConfirm' => $formconfirm,
1356 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters, $object, $action);
1357 if (empty($reshook)) {
1358 $formconfirm .= $hookmanager->resPrint;
1359 } elseif ($reshook > 0) {
1360 $formconfirm = $hookmanager->resPrint;
1368 if (!empty($object->brouillon) && $user->hasRight(
'contrat',
'creer')) {
1369 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="POST">';
1370 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1371 print
'<input type="hidden" name="action" value="setremise">';
1372 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1377 $linkback =
'<a href="'.DOL_URL_ROOT.
'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1381 if (!empty($modCodeContract->code_auto)) {
1382 $morehtmlref .= $object->ref;
1384 $morehtmlref .= $form->editfieldkey(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 3);
1385 $morehtmlref .= $form->editfieldval(
"",
'ref', $object->ref, $object, $user->rights->contrat->creer,
'string',
'', 0, 2);
1388 $morehtmlref .=
'<div class="refidno">';
1390 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1391 $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');
1393 $morehtmlref .=
'<br>';
1394 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'', 0, 1);
1395 $morehtmlref .= $form->editfieldval(
"RefSupplier",
'ref_supplier', $object->ref_supplier, $object, $user->rights->contrat->creer,
'string',
'',
null,
null,
'', 1,
'getFormatedSupplierRef');
1397 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1);
1398 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
1399 $morehtmlref .=
' (<a href="'.DOL_URL_ROOT.
'/contrat/list.php?socid='.$object->thirdparty->id.
'&search_name='.urlencode($object->thirdparty->name).
'">'.$langs->trans(
"OtherContracts").
'</a>)';
1402 if (isModEnabled(
'project')) {
1403 $langs->load(
"projects");
1404 $morehtmlref .=
'<br>';
1405 if ($permissiontoadd) {
1406 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1407 if ($action !=
'classify') {
1408 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.newToken().
'&id='.$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
1410 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.$object->id, $object->socid, $object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
1412 if (!empty($object->fk_project)) {
1414 $proj->fetch($object->fk_project);
1415 $morehtmlref .= $proj->getNomUrl(1);
1417 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
1422 $morehtmlref .=
'</div>';
1425 dol_banner_tab($object,
'ref', $linkback, 1,
'ref',
'none', $morehtmlref);
1428 print
'<div class="fichecenter">';
1429 print
'<div class="underbanner clearboth"></div>';
1432 print
'<table class="border tableforfield" width="100%">';
1435 print
'<tr><td class="titlefield">'.$langs->trans(
'Discount').
'</td><td colspan="3">';
1436 if ($object->thirdparty->remise_percent) {
1437 print $langs->trans(
"CompanyHasRelativeDiscount", $object->thirdparty->remise_percent).
'. ';
1439 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1441 $absolute_discount = $object->thirdparty->getAvailableDiscounts();
1442 if ($absolute_discount) {
1443 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1445 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1451 print
'<td class="titlefield">';
1452 print $form->editfieldkey(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer);
1454 print $form->editfieldval(
"Date",
'date_contrat', $object->date_contrat, $object, $user->rights->contrat->creer,
'datehourpicker');
1460 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1466 if (!empty($object->brouillon) && $user->hasRight(
'contrat',
'creer')) {
1472 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
1473 $blocname =
'contacts';
1474 $title = $langs->trans(
'ContactsAddresses');
1475 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1478 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
1479 $blocname =
'notes';
1480 $title = $langs->trans(
'Notes');
1481 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1485 $arrayothercontracts = $object->getListOfContracts(
'others');
1493 global $inputalsopricewithtax;
1494 $inputalsopricewithtax = 1;
1496 $productstatic =
new Product($db);
1499 if (isModEnabled(
'margin') && !empty($object->element) && in_array($object->element, array(
'facture',
'propal',
'commande'))) {
1507 print
'<div id="contrat-lines-container" id="contractlines" data-contractid="'.$object->id.
'" data-element="'.$object->element.
'" >';
1508 while ($cursorline <= $nbofservices) {
1509 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.
'" >';
1510 print
'<form name="update" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'" method="post">';
1511 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1512 print
'<input type="hidden" name="action" value="updateline">';
1513 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1514 print
'<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.
'">';
1515 print
'<input type="hidden" name="fournprice" value="'.(!empty($object->lines[$cursorline - 1]->fk_fournprice) ? $object->lines[$cursorline - 1]->fk_fournprice : 0).
'">';
1518 print
'<div class="div-table-responsive-no-min">';
1519 print
'<table class="notopnoleftnoright allwidth tableforservicepart1 centpercent">';
1521 $sql =
"SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,";
1522 $sql .=
" cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1523 $sql .=
" cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";
1524 $sql .=
" cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";
1525 $sql .=
" cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1526 $sql .=
" cd.fk_unit,";
1527 $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";
1528 $sql .=
" ,cd.rang";
1529 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
1530 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
1531 $sql .=
" WHERE cd.rowid = ".((int) $object->lines[$cursorline - 1]->id);
1533 $result = $db->query($sql);
1537 $objp = $db->fetch_object($result);
1540 print
'<tr class="liste_titre'.($cursorline ?
' liste_titre_add' :
'').
'">';
1541 print
'<td>'.$langs->trans(
"ServiceNb", $cursorline).
'</td>';
1542 print
'<td width="80" class="center">'.$langs->trans(
"VAT").
'</td>';
1543 print
'<td width="80" class="right">'.$langs->trans(
"PriceUHT").
'</td>';
1547 print
'<td width="30" class="center">'.$langs->trans(
"Qty").
'</td>';
1549 print
'<td width="30" class="left">'.$langs->trans(
"Unit").
'</td>';
1551 print
'<td width="50" class="right">'.$langs->trans(
"ReductionShort").
'</td>';
1552 if (isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1553 print
'<td width="50" class="right">'.$langs->trans(
"BuyingPrice").
'</td>';
1557 if ($nbofservices > 1 && $conf->browser->layout !=
'phone' && !empty($user->rights->contrat->creer)) {
1558 print
'<td width="30" class="linecolmove tdlineupdown center">';
1559 if ($cursorline > 1) {
1560 print
'<a class="lineupdown reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=up&token='.newToken().
'&rowid='.$objp->rowid.
'">';
1561 echo
img_up(
'default', 0,
'imgupforline');
1564 if ($cursorline < $nbofservices) {
1565 print
'<a class="lineupdown reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=down&token='.newToken().
'&rowid='.$objp->rowid.
'">';
1566 echo
img_down(
'default', 0,
'imgdownforline');
1571 print
'<td width="30"> </td>';
1579 if ($action !=
'editline' ||
GETPOST(
'rowid') != $objp->rowid) {
1581 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $objp->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1582 $moreparam =
'style="display: none;"';
1585 print
'<tr class="tdtop oddeven" '.$moreparam.
'>';
1588 if ($objp->fk_product > 0) {
1589 $productstatic->id = $objp->fk_product;
1590 $productstatic->type = $objp->ptype;
1591 $productstatic->ref = $objp->pref;
1592 $productstatic->entity = $objp->pentity;
1593 $productstatic->label = $objp->plabel;
1594 $productstatic->status = $objp->tosell;
1595 $productstatic->status_buy = $objp->tobuy;
1596 $productstatic->status_batch = $objp->tobatch;
1599 $text = $productstatic->getNomUrl(1,
'', 32);
1600 if ($objp->plabel) {
1602 $text .= $objp->plabel;
1604 $description = $objp->description;
1608 $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ?
'<br>'.
dol_htmlentitiesbr($objp->description) :
'';
1612 print $form->textwithtooltip($text, $description, 3,
'',
'', $cursorline, 3, (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
1616 print
'<td>'.img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->
description).
"</td>\n";
1619 print
'<td class="center">';
1620 print
vatrate($objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''),
'%', $objp->info_bits);
1623 print
'<td class="right">'.($objp->subprice !=
'' ?
price($objp->subprice) :
'').
"</td>\n";
1629 print
'<td class="center">'.$objp->qty.
'</td>';
1632 print
'<td class="left">'.$langs->trans($object->lines[$cursorline - 1]->getLabelOfUnit()).
'</td>';
1635 if ($objp->remise_percent > 0) {
1636 print
'<td class="right">'.$objp->remise_percent.
"%</td>\n";
1638 print
'<td> </td>';
1642 if (isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1643 print
'<td class="right nowraponall">'.price($objp->pa_ht).
'</td>';
1647 print
'<td class="nowraponall right">';
1648 if ($user->rights->contrat->creer && is_array($arrayothercontracts) && count($arrayothercontracts) && ($object->statut >= 0)) {
1649 print
'<!-- link to move service line into another contract -->';
1650 print
'<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=move&token='.newToken().
'&rowid='.$objp->rowid.
'">';
1651 print
img_picto($langs->trans(
"MoveToAnotherContract"),
'uparrow');
1654 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1655 print
'<a class="reposition marginrightonly editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=editline&token='.newToken().
'&rowid='.$objp->rowid.
'">';
1659 if ($user->rights->contrat->creer && ($object->statut >= 0)) {
1660 print
'<a class="reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&action=deleteline&token='.newToken().
'&rowid='.$objp->rowid.
'">';
1672 if (isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1677 if ($objp->subprice >= 0) {
1678 print
'<tr class="oddeven" '.$moreparam.
'>';
1679 print
'<td colspan="'.$colspan.
'">';
1682 print $langs->trans(
"DateStartPlanned").
': ';
1683 if ($objp->date_start) {
1686 if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now - $conf->contrat->services->inactifs->warning_delay)) {
1687 $warning_delay = $conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1688 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1689 print
" ".img_warning($textlate);
1692 print $langs->trans(
"Unknown");
1694 print
' - ';
1695 print $langs->trans(
"DateEndPlanned").
': ';
1696 if ($objp->date_end) {
1698 if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now - $conf->contrat->services->expires->warning_delay)) {
1699 $warning_delay = $conf->contrat->services->expires->warning_delay / 3600 / 24;
1700 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1701 print
" ".img_warning($textlate);
1704 print $langs->trans(
"Unknown");
1712 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1714 $line->id = $objp->rowid;
1715 $line->fetch_optionals();
1716 print $line->showOptionals($extrafields,
'view', array(
'class'=>
'oddeven',
'style'=>$moreparam,
'colspan'=>$colspan,
'tdclass' =>
'notitlefieldcreate'),
'',
'', 1);
1721 print
'<tr class="oddeven">';
1723 if ($objp->fk_product > 0) {
1724 $canchangeproduct = 1;
1725 if (empty($canchangeproduct)) {
1726 $productstatic->id = $objp->fk_product;
1727 $productstatic->type = $objp->ptype;
1728 $productstatic->ref = $objp->pref;
1729 $productstatic->entity = $objp->pentity;
1730 print $productstatic->getNomUrl(1,
'', 32);
1731 print $objp->label ?
' - '.dol_trunc($objp->label, 32) :
'';
1732 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1734 $senderissupplier = 0;
1735 if (empty($senderissupplier)) {
1736 print $form->select_produits((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1738 $form->select_produits_fournisseurs((!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0),
'idprod');
1743 print $objp->label ? $objp->label.
'<br>' :
'';
1744 print
'<input type="hidden" name="idprod" value="'.(!empty($object->lines[$cursorline - 1]->fk_product) ? $object->lines[$cursorline - 1]->fk_product : 0).
'">';
1748 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1750 if (!empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) {
1751 $nbrows = $conf->global->MAIN_INPUT_DESC_HEIGHT;
1753 $enable = (isset($conf->global->FCKEDITOR_ENABLE_DETAILS) ? $conf->global->FCKEDITOR_ENABLE_DETAILS : 0);
1754 $doleditor =
new DolEditor(
'product_desc', $objp->description,
'', 92,
'dolibarr_details',
'',
false,
true, $enable, $nbrows,
'90%');
1755 $doleditor->Create();
1760 print
'<td class="right">';
1761 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);
1765 print
'<td class="right"><input size="5" type="text" name="elprice" value="'.price($objp->subprice).
'"></td>';
1773 print
'<td class="center"><input size="2" type="text" name="elqty" value="'.$objp->qty.
'"></td>';
1777 print
'<td class="left">';
1778 print $form->selectUnits($objp->fk_unit,
"unit");
1783 print
'<td class="nowrap right"><input size="1" type="text" name="elremise_percent" value="'.$objp->remise_percent.
'">%</td>';
1785 if (!empty($usemargins)) {
1786 print
'<td class="right">';
1787 if ($objp->fk_product) {
1788 print
'<select id="fournprice" name="fournprice"></select>';
1790 print
'<input id="buying_price" type="text" size="5" name="buying_price" value="'.price($objp->pa_ht, 0,
'', 0).
'"></td>';
1792 print
'<td class="center">';
1793 print
'<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans(
"Modify").
'">';
1794 print
'<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1799 if (isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1807 print
'<tr class="oddeven">';
1808 print
'<td colspan="'.$colspan.
'">';
1809 print $langs->trans(
"DateStartPlanned").
' ';
1810 print $form->selectDate($db->jdate($objp->date_start),
"date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1),
"update");
1811 print
' '.$langs->trans(
"DateEndPlanned").
' ';
1812 print $form->selectDate($db->jdate($objp->date_end),
"date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1),
"update");
1816 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1818 $line->id = $objp->rowid;
1819 $line->fetch_optionals();
1820 print $line->showOptionals($extrafields,
'edit', array(
'style'=>
'class="oddeven"',
'colspan'=>$colspan,
'tdclass' =>
'notitlefieldcreate'),
'',
'', 1);
1829 if ($object->statut > 0) {
1831 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1832 $moreparam =
'style="display: none;"';
1839 if (isModEnabled(
'margin') && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) {
1843 print
'<tr class="oddeven" '.$moreparam.
'>';
1844 print
'<td class="tdhrthin" colspan="'.$colspan.
'"><hr class="opacitymedium tdhrthin"></td>';
1857 if ($action ==
'deleteline' && !$_REQUEST[
"cancel"] && $user->hasRight(
'contrat',
'creer') && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1858 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid'), $langs->trans(
"DeleteContractLine"), $langs->trans(
"ConfirmDeleteContractLine"),
"confirm_deleteline",
'', 0, 1);
1859 if ($ret ==
'html') {
1860 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1867 if ($action ==
'move' && !$_REQUEST[
"cancel"] && $user->hasRight(
'contrat',
'creer') && $object->lines[$cursorline - 1]->id ==
GETPOST(
'rowid')) {
1868 $arraycontractid = array();
1869 foreach ($arrayothercontracts as $contractcursor) {
1870 $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1874 $formquestion = array(
1875 'text' => $langs->trans(
"ConfirmMoveToAnotherContractQuestion"),
1876 array(
'type' =>
'select',
'name' =>
'newcid',
'values' => $arraycontractid));
1878 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".$object->id.
"&lineid=".
GETPOST(
'rowid',
'int'), $langs->trans(
"MoveToAnotherContract"), $langs->trans(
"ConfirmMoveToAnotherContract"),
"confirm_move", $formquestion);
1879 print
'<table class="notopnoleftnoright" width="100%"><tr class="oddeven" height="6"><td></td></tr></table>';
1883 if ($object->statut > 0) {
1884 print
'<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
1886 print
'<tr class="oddeven" '.$moreparam.
'>';
1887 print
'<td><span class="valignmiddle hideonsmartphone">'.$langs->trans(
"ServiceStatus").
':</span> '.$object->lines[$cursorline - 1]->getLibStatut(4).
'</td>';
1888 print
'<td width="30" class="right">';
1889 if ($user->socid == 0) {
1890 if ($object->statut > 0 && $action !=
'activateline' && $action !=
'unactivateline') {
1891 $tmpaction =
'activateline';
1892 $tmpactionpicto =
'play';
1893 $tmpactiontext = $langs->trans(
"Activate");
1894 if ($objp->statut == 4) {
1895 $tmpaction =
'unactivateline';
1896 $tmpactionpicto =
'playstop';
1897 $tmpactiontext = $langs->trans(
"Disable");
1899 if (($tmpaction ==
'activateline' && $user->rights->contrat->activer) || ($tmpaction ==
'unactivateline' && $user->rights->contrat->desactiver)) {
1900 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'&action='.$tmpaction.
'">';
1901 print
img_picto($tmpactiontext, $tmpactionpicto);
1909 print
'<tr class="oddeven" '.$moreparam.
'>';
1913 if (!$objp->date_start_real) {
1914 print $langs->trans(
"DateStartReal").
': ';
1915 if ($objp->date_start_real) {
1918 print $langs->trans(
"ContractStatusNotRunning");
1922 if ($objp->date_start_real && !$objp->date_end_real) {
1923 print $langs->trans(
"DateStartReal").
': ';
1927 if ($objp->date_start_real && $objp->date_end_real) {
1928 print $langs->trans(
"DateStartReal").
': ';
1930 print
' - ';
1931 print $langs->trans(
"DateEndReal").
': ';
1934 if (!empty($objp->comment)) {
1935 print
" - ".$objp->comment;
1939 print
'<td class="center"> </td>';
1946 if ($user->rights->contrat->activer && $action ==
'activateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
1947 print
'<form name="active" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
1948 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1949 print
'<input type="hidden" name="action" value="confirm_active">';
1950 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1951 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
1952 print
'<input type="hidden" name="ligne" value="'.GETPOST(
'ligne',
'int').
'">';
1953 print
'<input type="hidden" name="confirm" value="yes">';
1955 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
1958 $dateactstart = $objp->date_start;
1961 } elseif (!$dateactstart) {
1962 $dateactstart = time();
1965 $dateactend = $objp->date_end;
1968 } elseif (!$dateactend) {
1969 if ($objp->fk_product > 0) {
1971 $product->fetch($objp->fk_product);
1972 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
1976 print
'<tr class="oddeven">';
1977 print
'<td class="nohover">'.$langs->trans(
"DateServiceActivate").
'</td><td class="nohover">';
1978 print $form->selectDate($dateactstart,
'start', $usehm, $usehm,
'',
"active", 1, 0);
1980 print
'<td class="nohover">'.$langs->trans(
"DateEndPlanned").
'</td><td class="nohover">';
1981 print $form->selectDate($dateactend,
"end", $usehm, $usehm,
'',
"active", 1, 0);
1983 print
'<td class="center nohover">';
1988 print
'<tr class="oddeven">';
1989 print
'<td class="nohover">'.$langs->trans(
"Comment").
'</td><td colspan="3" class="nohover" colspan="'.(isModEnabled(
'margin') ? 4 : 3).
'"><input type="text" class="minwidth300" name="comment" value="'.
dol_escape_htmltag(
GETPOST(
"comment",
'alphanohtml')).
'"></td>';
1990 print
'<td class="nohover right">';
1991 print
'<input type="submit" class="button" name="activate" value="'.$langs->trans(
"Activate").
'"> ';
1992 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2001 if ($user->rights->contrat->activer && $action ==
'unactivateline' && $object->lines[$cursorline - 1]->id ==
GETPOST(
'ligne',
'int')) {
2005 print
'<!-- Form to disabled a line -->'.
"\n";
2006 print
'<form name="confirm_closeline" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&ligne='.$object->lines[$cursorline - 1]->id.
'" method="post">';
2007 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2008 print
'<input type="hidden" name="confirm" value="yes">';
2009 print
'<input type="hidden" name="action" value="confirm_closeline">';
2010 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2012 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
2015 $dateactstart = $objp->date_start_real;
2018 } elseif (!$dateactstart) {
2019 $dateactstart = time();
2022 $dateactend = $objp->date_end_real;
2025 } elseif (!$dateactend) {
2026 if ($objp->fk_product > 0) {
2028 $product->fetch($objp->fk_product);
2029 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2033 if ($dateactend > $now) {
2037 print
'<tr class="oddeven"><td colspan="2" class="nohover">';
2038 if ($objp->statut >= 4) {
2039 if ($objp->statut == 4) {
2040 print $langs->trans(
"DateEndReal").
' ';
2041 print $form->selectDate($dateactend,
"end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1),
"closeline", 1, 1);
2045 print
'<td class="center nohover">';
2048 print
'<tr class="oddeven">';
2049 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>';
2050 print
'<td class="nohover right">';
2051 print
'<input type="submit" class="button" name="close" value="'.$langs->trans(
"Disable").
'"> ';
2052 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2066 if ($user->rights->contrat->creer && ($object->statut == 0)) {
2070 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOST(
'lineid',
'int')).
'" method="POST">
2071 <input type="hidden" name="token" value="'.newToken().
'">
2072 <input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">
2073 <input type="hidden" name="mode" value="">
2074 <input type="hidden" name="id" value="'.$object->id.
'">
2075 <input type="hidden" name="page_y" value="">
2076 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
2079 print
'<div class="div-table-responsive-no-min">';
2080 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2083 if ($action !=
'editline') {
2084 $forcetoshowtitlelines = 1;
2085 if (empty($object->multicurrency_code)) {
2086 $object->multicurrency_code = $conf->currency;
2091 $parameters = array();
2092 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters, $object, $action);
2093 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
2094 if (empty($reshook))
2095 $object->formAddObjectLine(1, $mysoc, $soc);
2106 if (
GETPOST(
'modelselected')) {
2107 $action =
'presend';
2113 if ($user->socid == 0 && $action !=
'presend' && $action !=
'editline') {
2114 print
'<div class="tabsAction">';
2116 $parameters = array();
2117 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters, $object, $action);
2119 if (empty($reshook)) {
2123 'class' =>
'classfortooltip'
2128 if (empty($user->socid)) {
2129 if ($object->statut == 1) {
2130 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->contrat->creer)) {
2131 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=presend&token='.newToken().
'&mode=init#formmailbeforetitle',
'',
true, $params);
2133 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
2138 if ($object->statut == 0 && $nbofservices) {
2139 if ($user->rights->contrat->creer) {
2140 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=valid&token='.newToken(),
'',
true, $params);
2142 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2143 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default',
'#',
'',
false, $params);
2146 if ($object->statut == 1) {
2147 if ($user->rights->contrat->creer) {
2148 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=reopen&token='.newToken(),
'',
true, $params);
2150 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2151 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
2155 if (isModEnabled(
'commande') && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) {
2156 $langs->load(
"orders");
2157 if ($user->hasRight(
'commande',
'creer')) {
2158 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);
2160 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2161 print
dolGetButtonAction($langs->trans(
'CreateOrder'),
'',
'default',
'#',
'',
false, $params);
2165 if (isModEnabled(
'facture') && $object->statut > 0) {
2166 $langs->load(
"bills");
2167 if ($user->hasRight(
'facture',
'creer')) {
2168 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);
2170 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2171 print
dolGetButtonAction($langs->trans(
'CreateBill'),
'',
'default',
'#',
'',
false, $params);
2175 if ($object->nbofservicesclosed > 0 || $object->nbofserviceswait > 0) {
2176 if ($user->rights->contrat->activer) {
2177 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=activate&token='.newToken(),
'',
true, $params);
2179 print
dolGetButtonAction($langs->trans(
'ActivateAllContracts'),
'',
'default',
'#',
'',
false, $params);
2182 if ($object->nbofservicesclosed < $nbofservices) {
2183 if ($user->rights->contrat->desactiver) {
2184 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=close&token='.newToken(),
'',
true, $params);
2186 print
dolGetButtonAction($langs->trans(
'CloseAllContracts'),
'',
'default',
'#',
'',
false, $params);
2198 if (!empty($conf->global->CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT) && $object->nbofservicesclosed > 0) {
2199 if ($action ==
'showclosedlines') {
2200 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>';
2202 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>';
2207 if ($user->rights->contrat->creer) {
2208 print
dolGetButtonAction($langs->trans(
'ToClone'),
'',
'default', $_SERVER[
'PHP_SELF'].
'?id='.$object->id.
'&socid='.$object->socid.
'&action=clone&token='.newToken(),
'',
true, $params);
2212 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delete&token='.newToken(),
'', $permissiontodelete, $params);
2218 if ($action !=
'presend') {
2219 print
'<div class="fichecenter"><div class="fichehalfleft">';
2225 $filedir = $conf->contrat->multidir_output[$object->entity].
"/".
dol_sanitizeFileName($object->ref);
2226 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".$object->id;
2227 $genallowed = $user->hasRight(
'contrat',
'lire');
2228 $delallowed = $user->hasRight(
'contrat',
'creer');
2231 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);
2235 $linktoelem = $form->showLinkToObjectBlock($object,
null, array(
'contrat'));
2236 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2239 if ($object->statut != Contrat::STATUS_DRAFT &&
getDolGlobalString(
'CONTRACT_ALLOW_ONLINESIGN')) {
2240 print
'<br><!-- Link to sign -->';
2241 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2243 print showOnlineSignatureUrl(
'contract', $object->ref).
'<br>';
2246 print
'</div><div class="fichehalfright">';
2250 $morehtmlcenter =
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/agenda.php?id='.$object->id);
2254 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2256 $somethingshown =
$formactions->showactions($object,
'contract', $socid, 1,
'listactions', $MAXEVENT,
'', $morehtmlcenter);
2258 print
'</div></div>';
2262 $modelmail =
'contract';
2263 $defaulttopic =
'SendContractRef';
2264 $diroutput = $conf->contrat->multidir_output[$object->entity];
2265 $trackid =
'con'.$object->id;
2267 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
2278if (isModEnabled(
'margin') && $action ==
'editline') {
2281<script
type=
"text/javascript">
2282$(document).ready(
function() {
2283 var idprod = $(
"input[name='idprod']").val();
2284 var fournprice = $(
"input[name='fournprice']").val();
2285 var token =
'<?php echo currentToken(); ?>';
2287 $.post(
'<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2291 if (data.length > 0) {
2294 $(data).each(
function() {
2295 options +=
'<option value="'+this.
id+
'" price="'+this.
price+
'"';
2296 if (fournprice > 0) {
2297 if (this.
id == fournprice) {
2298 options +=
' selected';
2299 $(
"#buying_price").val(this.price);
2303 options +=
'>'+this.label+
'</option>';
2305 options +=
'<option value=null'+(trouve?
'':
' selected')+
'><?php echo $langs->trans("InputPrice"); ?></option>';
2306 $(
"#fournprice").html(options);
2308 $(
"#buying_price").hide();
2309 $(
"#fournprice").show();
2312 $(
"#buying_price").show();
2314 $(
"#fournprice").change(
function() {
2315 var selval = $(
this).find(
'option:selected').attr(
"price");
2317 $(
"#buying_price").val(selval).hide();
2319 $(
'#buying_price').show();
2323 $(
"#fournprice").hide();
2324 $(
'#buying_price').show();
2330 $(
"#fournprice").hide();
2331 $(
'#buying_price').show();
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.
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.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_move_dir($srcdir, $destdir, $overwriteifexists=1, $indexdatabase=1, $renamedircontent=1)
Move a directory 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.
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_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
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.
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).
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)
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
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.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
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.