38require
"../main.inc.php";
39require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
40require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
41require_once DOL_DOCUMENT_ROOT.
'/core/lib/contract.lib.php';
42require_once DOL_DOCUMENT_ROOT.
'/contrat/class/contrat.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/core/modules/contract/modules_contract.php';
44require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formfile.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
49if (isModEnabled(
"propal")) {
50 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
52if (isModEnabled(
'project')) {
53 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
54 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formprojet.class.php';
56require_once DOL_DOCUMENT_ROOT.
'/core/class/extrafields.class.php';
68$langs->loadLangs(array(
"contracts",
"orders",
"companies",
"bills",
"products",
'compta',
'propal'));
70$action =
GETPOST(
'action',
'aZ09');
71$confirm =
GETPOST(
'confirm',
'alpha');
72$cancel =
GETPOST(
'cancel',
'alpha');
73$backtopage =
GETPOST(
'backtopage',
'alpha');
78$origin =
GETPOST(
'origin',
'alpha');
92$usehm = (
getDolGlobalString(
'MAIN_USE_HOURMIN_IN_DATE_RANGE') ?
$conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE : 0);
96 $socid = $user->socid;
100$hookmanager->initHooks(array(
'contractcard',
'globalcard'));
109if ($id > 0 || !empty($ref) && $action !=
'add') {
110 $ret =
$object->fetch($id, $ref);
112 $ret =
$object->fetch_thirdparty();
120$extrafields->fetch_name_optionals_label(
$object->table_element);
123$extralabelslines = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
125$permissionnote = $user->hasRight(
'contrat',
'creer');
126$permissiondellink = $user->hasRight(
'contrat',
'creer');
127$permissiontodelete = ($user->hasRight(
'contrat',
'creer') &&
$object->status == $object::STATUS_DRAFT) || $user->hasRight(
'contrat',
'supprimer');
128$permissiontoadd = $user->hasRight(
'contrat',
'creer');
129$permissiontoedit = $permissiontoadd;
130$permissiontoactivate = $user->hasRight(
'contrat',
'activer');
136if (!(
$object->id > 0) && ($action ==
'view' || $action ==
'')) {
145$parameters = array(
'socid' => $socid);
146$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
150if (empty($reshook)) {
151 $backurlforlist = DOL_URL_ROOT.
'/contrat/list.php';
153 if (empty($backtopage) || ($cancel && empty($id))) {
154 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
155 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
156 $backtopage = $backurlforlist;
158 $backtopage = DOL_URL_ROOT.
'/contrat/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
164 if (!empty($backtopageforcancel)) {
165 header(
"Location: ".$backtopageforcancel);
167 } elseif (!empty($backtopage)) {
168 header(
"Location: ".$backtopage);
174 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
176 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
178 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
180 if ($action ==
'confirm_active' && $confirm ==
'yes' && $permissiontoactivate) {
193 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
198 } elseif ($action ==
'confirm_sign' && $confirm ==
'yes' && $user->hasRight(
'contract',
'creer')) {
199 $result =
$object->setSignedStatus($user,
GETPOSTINT(
'signed_status'), 0,
'CONTRACT_MODIFY');
201 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id);
206 } elseif ($action ==
'confirm_unsign' && $confirm ==
'yes' && $user->hasRight(
'contract',
'creer')) {
207 $result =
$object->setSignedStatus($user, Contrat::$SIGNED_STATUSES[
'STATUS_NO_SIGNATURE'], 0,
'CONTRACT_MODIFY');
209 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id);
214 } elseif ($action ==
'confirm_closeline' && $confirm ==
'yes' && $permissiontoactivate) {
221 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEnd")),
null,
'errors');
226 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
234 if (
GETPOST(
'mode') ==
'predefined') {
246 $date_start_update =
'';
247 $date_end_update =
'';
248 $date_start_real_update =
'';
249 $date_end_real_update =
'';
250 if (
GETPOST(
'date_start_updatemonth') &&
GETPOST(
'date_start_updateday') &&
GETPOST(
'date_start_updateyear')) {
253 if (
GETPOST(
'date_end_updatemonth') &&
GETPOST(
'date_end_updateday') &&
GETPOST(
'date_end_updateyear')) {
256 if (
GETPOST(
'date_start_real_updatemonth') &&
GETPOST(
'date_start_real_updateday') &&
GETPOST(
'date_start_real_updateyear')) {
259 if (
GETPOST(
'date_end_real_updatemonth') &&
GETPOST(
'date_end_real_updateday') &&
GETPOST(
'date_end_real_updateyear')) {
267 if ($action ==
'add' && $user->hasRight(
'contrat',
'creer')) {
269 if (empty($datecontrat)) {
271 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
276 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
282 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
290 $object->date_contrat = $datecontrat;
304 if (!empty($origin) && !empty($originid)) {
306 $element = $subelement = $origin;
307 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
309 $subelement = $regs[2];
313 if ($element ==
'order') {
314 $element = $subelement =
'commande';
316 if ($element ==
'propal') {
317 $element =
'comm/propal';
318 $subelement =
'propal';
320 if ($element ==
'invoice' || $element ==
'facture') {
321 $element =
'compta/facture';
322 $subelement =
'facture';
326 $object->origin_id = $originid;
331 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
338 $classname = ucfirst($subelement);
339 $srcobject =
new $classname($db);
340 '@phan-var-force Commande|Propal|Facture $srcobject';
343 $result = $srcobject->fetch(
$object->origin_id);
345 $srcobject->fetch_thirdparty();
346 $lines = $srcobject->lines;
347 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
348 $srcobject->fetch_lines();
349 $lines = $srcobject->lines;
353 $num = count($lines);
355 for ($i = 0; $i < $num; $i++) {
356 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
358 if ($product_type == 1 || (
getDolGlobalString(
'CONTRACT_SUPPORT_PRODUCTS') && in_array($product_type, array(0, 1)))) {
360 if ($lines[$i]->fk_product > 0) {
361 $product_static =
new Product($db);
366 $prod->id = $lines[$i]->fk_product;
367 $prod->getMultiLangs();
369 $outputlangs = $langs;
371 if (empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
372 $newlang =
GETPOST(
'lang_id',
'aZ09');
374 if (empty($newlang)) {
375 $newlang = $srcobject->thirdparty->default_lang;
377 if (!empty($newlang)) {
379 $outputlangs->setDefaultLang($newlang);
382 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"libelle"])) ? $prod->multilangs[$outputlangs->defaultlang][
"libelle"] : $lines[$i]->product_label;
384 $label = $lines[$i]->product_label;
386 $desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->label) ?
dol_htmlentitiesbr($lines[$i]->desc) :
'';
392 $array_options = array();
394 if (method_exists($lines[$i],
'fetch_optionals')) {
395 $lines[$i]->fetch_optionals();
396 $array_options = $lines[$i]->array_options;
399 $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx.
' ('.$lines[$i]->vat_src_code.
')' : $lines[$i]->tva_tx;
407 $lines[$i]->subprice,
412 $lines[$i]->fk_product,
413 $lines[$i]->remise_percent,
414 $lines[$i]->date_start,
415 $lines[$i]->date_end,
418 $lines[$i]->info_bits,
419 $lines[$i]->fk_fournprice,
438 $parameters = array(
'objFrom' => $srcobject);
439 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
453 $result =
$object->create($user);
455 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
463 } elseif ($action ==
'classin' && $user->hasRight(
'contrat',
'creer')) {
465 } elseif ($action ==
'addline' && $user->hasRight(
'contrat',
'creer')) {
469 $product_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
472 $price_ht_devise =
'';
474 $price_ttc_devise =
'';
476 $rang = count(
$object->lines) + 1;
478 if (
GETPOST(
'price_ht') !==
'') {
481 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
484 if (
GETPOST(
'price_ttc') !==
'') {
487 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
491 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free') {
497 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
502 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
505 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef),
'', 2) : 0);
506 if (empty($remise_percent)) {
511 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
514 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
515 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
521 if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
522 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
527 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
528 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
530 if (is_array($extralabelsline)) {
532 foreach ($extralabelsline as $key => $value) {
533 unset($_POST[
"options_".$key]);
542 $price_base_type =
'';
548 $prod->fetch($idprod);
557 $price_min = $prod->price_min;
558 $price_min_ttc = $prod->price_min_ttc;
562 $price_min = $prod->multiprices_min[
$object->thirdparty->price_level];
563 $price_min_ttc = $prod->multiprices_min_ttc[
$object->thirdparty->price_level];
566 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
570 $filter = array(
't.fk_product' => $prod->id,
't.fk_soc' =>
$object->thirdparty->id);
572 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
574 if (count($prodcustprice->lines) > 0) {
575 $price_min =
price($prodcustprice->lines[0]->price_min);
576 $price_min_ttc =
price($prodcustprice->lines[0]->price_min_ttc);
589 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
590 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
593 if (!empty($price_ht) || $price_ht ===
'0') {
595 $pu_ttc =
price2num((
float) $pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
596 $price_base_type =
'HT';
597 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
599 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
600 $price_base_type =
'TTC';
603 $desc = $prod->description;
611 $desc = $product_desc;
616 $fk_unit = $prod->fk_unit;
620 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
621 if (empty($tva_tx)) {
624 $tva_tx = str_replace(
'*',
'', $tva_tx);
625 $desc = $product_desc;
627 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
628 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
630 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
633 if (!empty($price_ht) || $price_ht ===
'0') {
635 $pu_ttc =
price2num((
float) $pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
636 $price_base_type =
'HT';
637 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
639 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
640 $price_base_type =
'TTC';
648 $fk_fournprice =
GETPOST(
'fournprice');
650 $pa_ht =
GETPOST(
'buying_price');
660 if (((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance'))
662 $object->error = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
691 $outputlangs = $langs;
694 $newlang =
GETPOST(
'lang_id',
'aZ09');
697 $newlang =
$object->thirdparty->default_lang;
699 if (!empty($newlang)) {
701 $outputlangs->setDefaultLang($newlang);
706 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
709 unset($_POST[
'prod_entry_mode']);
711 unset($_POST[
'qty']);
712 unset($_POST[
'type']);
713 unset($_POST[
'remise_percent']);
714 unset($_POST[
'price_ht']);
715 unset($_POST[
'multicurrency_price_ht']);
716 unset($_POST[
'price_ttc']);
717 unset($_POST[
'tva_tx']);
718 unset($_POST[
'product_ref']);
719 unset($_POST[
'product_label']);
720 unset($_POST[
'product_desc']);
721 unset($_POST[
'fournprice']);
722 unset($_POST[
'buying_price']);
723 unset($_POST[
'np_marginRate']);
724 unset($_POST[
'np_markRate']);
725 unset($_POST[
'dp_desc']);
726 unset($_POST[
'idprod']);
728 unset($_POST[
'date_starthour']);
729 unset($_POST[
'date_startmin']);
730 unset($_POST[
'date_startsec']);
731 unset($_POST[
'date_startday']);
732 unset($_POST[
'date_startmonth']);
733 unset($_POST[
'date_startyear']);
734 unset($_POST[
'date_endhour']);
735 unset($_POST[
'date_endmin']);
736 unset($_POST[
'date_endsec']);
737 unset($_POST[
'date_endday']);
738 unset($_POST[
'date_endmonth']);
739 unset($_POST[
'date_endyear']);
744 } elseif ($action ==
'updateline' && $user->hasRight(
'contrat',
'creer') && !
GETPOST(
'cancel',
'alpha')) {
748 if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
749 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
750 $action =
'editline';
756 if ($objectline->fetch($idline) < 0) {
760 $objectline->fetch_optionals();
762 $objectline->oldcopy =
dol_clone($objectline, 2);
770 if ($date_start_real_update ==
'') {
771 $date_start_real_update = $objectline->date_start_real;
773 if ($date_end_real_update ==
'') {
774 $date_end_real_update = $objectline->date_end_real;
777 $vat_rate =
GETPOST(
'eltva_tx',
'alpha');
780 if (preg_match(
'/\*/', $vat_rate)) {
785 $vat_rate = str_replace(
'*',
'', $vat_rate);
794 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
795 $vat_src_code = $reg[1];
796 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
813 if ($remise_percent > 0) {
814 $remise = round(((
float) $price_ht * (
float) $remise_percent / 100), 2);
817 $objectline->fk_product =
GETPOSTINT(
'idprod');
818 $objectline->description =
GETPOST(
'product_desc',
'restricthtml');
819 $objectline->price_ht = (float) $price_ht;
822 $objectline->remise_percent = $remise_percent;
823 $objectline->tva_tx = ($txtva ? $txtva : 0);
824 $objectline->vat_src_code = $vat_src_code;
825 $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
826 $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
827 $objectline->date_start = $date_start_update;
828 $objectline->date_start_real = $date_start_real_update;
829 $objectline->date_end = $date_end_update;
830 $objectline->date_end_real = $date_end_real_update;
831 $objectline->user_closing_id = $user->id;
833 $objectline->pa_ht = $pa_ht;
839 $objectline->fk_unit =
null;
843 $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
844 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
846 if (is_array($array_options) && count($array_options) > 0) {
848 foreach ($array_options as $key => $value) {
849 $objectline->array_options[$key] = $array_options[$key];
855 $result = $objectline->update($user);
858 $action =
'editline';
859 $_GET[
'rowid'] =
GETPOST(
'elrowid');
869 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
873 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
878 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
879 $result =
$object->validate($user);
884 $outputlangs = $langs;
887 $newlang =
GETPOST(
'lang_id',
'aZ09');
890 $newlang =
$object->thirdparty->default_lang;
892 if (!empty($newlang)) {
894 $outputlangs->setDefaultLang($newlang);
899 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
904 } elseif ($action ==
'reopen' && $user->hasRight(
'contrat',
'creer')) {
905 $result =
$object->reopen($user);
909 } elseif ($action ==
'confirm_close' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
911 $result =
$object->closeAll($user);
915 } elseif ($action ==
'confirm_activate' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
918 $comment =
GETPOST(
'comment',
'alpha');
919 $result =
$object->activateAll($user, $date_start, 0, $comment, $date_end);
923 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'supprimer')) {
924 $result =
$object->delete($user);
926 header(
"Location: list.php?restore_lastsearch_values=1");
931 } elseif ($action ==
'confirm_move' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
934 $result = $contractline->fetch(
GETPOSTINT(
'lineid'));
935 $contractline->fk_contrat =
GETPOSTINT(
'newcid');
936 $result = $contractline->update($user, 1);
938 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
944 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"RefNewContract")),
null,
'errors');
946 } elseif ($action ==
'update_extras' && $permissiontoadd) {
949 $attribute =
GETPOST(
'attribute',
'alphanohtml');
952 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute);
959 $result =
$object->updateExtraField($attribute,
'CONTRACT_MODIFY');
967 $action =
'edit_extras';
969 } elseif ($action ==
'setref_supplier' && $permissiontoadd) {
973 $result =
$object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
976 $action =
'editref_supplier';
978 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
982 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
985 } elseif ($action ==
'setref_customer' && $permissiontoadd) {
989 $result =
$object->setValueFrom(
'ref_customer',
GETPOST(
'ref_customer',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
992 $action =
'editref_customer';
994 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
998 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1001 } elseif ($action ==
'setref' && $permissiontoadd) {
1003 $result =
$object->fetch($id);
1010 $result =
$object->setValueFrom(
'ref',
GETPOST(
'ref',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
1013 $action =
'editref';
1015 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1022 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1026 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1029 } elseif ($action ==
'setdate_contrat' && $permissiontoadd) {
1031 $result =
$object->fetch($id);
1036 $result =
$object->setValueFrom(
'date_contrat', $datacontrat,
'',
null,
'date',
'', $user,
'CONTRACT_MODIFY');
1039 $action =
'editdate_contrat';
1041 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1045 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1051 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1055 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1058 $triggersendname =
'CONTRACT_SENTBYMAIL';
1060 $mode =
'emailfromcontract';
1061 $trackid =
'con'.$object->id;
1062 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1066 if ($action ==
'addcontact' && $user->hasRight(
'contrat',
'creer')) {
1069 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1072 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1075 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1076 $langs->load(
"errors");
1077 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1082 } elseif ($action ==
'swapstatut' && $user->hasRight(
'contrat',
'creer')) {
1085 } elseif ($action ==
'deletecontact' && $user->hasRight(
'contrat',
'creer')) {
1090 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1099 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
1101 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1104 $result =
$object->createFromClone($user, $socid);
1106 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1109 if (count(
$object->errors) > 0) {
1124$title =
$object->ref.
" - ".$langs->trans(
'Contract');
1125if ($action ==
'create') {
1126 $title = $langs->trans(
"NewContract");
1128$help_url =
'EN:Module_Contracts|FR:Module_Contrat|ES:Contratos_de_servicio';
1130llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-contrat page-card');
1132$form =
new Form($db);
1134if (isModEnabled(
'project')) {
1140if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
1141 $module = substr($module, 0,
dol_strlen($module) - 4);
1144$modCodeContract =
null;
1146 $modCodeContract =
new $module();
1147 '@phan-var-force ModelNumRefContracts $modCodeContract';
1151if ($action ==
'create') {
1157 $soc->fetch($socid);
1163 $element = $subelement =
GETPOST(
'origin');
1164 if (preg_match(
'/^([^_]+)_([^_]+)/i',
GETPOST(
'origin'), $regs)) {
1165 $element = $regs[1];
1166 $subelement = $regs[2];
1169 if ($element ==
'project') {
1173 if ($element ==
'order' || $element ==
'commande') {
1174 $element = $subelement =
'commande';
1176 if ($element ==
'propal') {
1177 $element =
'comm/propal';
1178 $subelement =
'propal';
1180 if ($element ==
'invoice' || $element ==
'facture') {
1181 $element =
'compta/facture';
1182 $subelement =
'facture';
1187 $classname = ucfirst($subelement);
1188 $objectsrc =
new $classname($db);
1189 '@phan-var-force Commande|Propal|Facture $objectsrc';
1190 $objectsrc->fetch($originid);
1191 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1192 $objectsrc->fetch_lines();
1194 $objectsrc->fetch_thirdparty();
1197 $objectsrc->fetch_optionals();
1198 $object->array_options = $objectsrc->array_options;
1200 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1202 $soc = $objectsrc->thirdparty;
1204 $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private :
'');
1205 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public :
'');
1208 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1212 $note_private =
GETPOST(
"note_private",
"alpha");
1213 $note_public =
GETPOST(
"note_public",
"alpha");
1218 print
'<form name="form_contract" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1219 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1220 print
'<input type="hidden" name="action" value="add">';
1221 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1222 print
'<input type="hidden" name="remise_percent" value="0">';
1223 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1227 print
'<table class="border centpercent">';
1230 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>';
1231 if (!empty($modCodeContract->code_auto)) {
1232 $tmpcode = $langs->trans(
"Draft");
1234 $tmpcode =
'<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(
GETPOST(
'ref') ?
GETPOST(
'ref') : $tmpcode).
'">';
1240 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
1241 print
'<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(
GETPOST(
'ref_customer',
'alpha')).
'"></td></tr>';
1244 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td>';
1245 print
'<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(
GETPOST(
'ref_supplier',
'alpha')).
'"></td></tr>';
1249 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1252 print $soc->getNomUrl(1);
1253 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1257 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
1258 print $form->select_company(
'',
'socid',
'',
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
1259 print
' <a href="'.DOL_URL_ROOT.
'/societe/card.php?action=create&customer=3&backtopage='.urlencode($_SERVER[
"PHP_SELF"].
'?action=create').
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
1266 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1267 if ($soc->remise_percent) {
1268 print $langs->trans(
"CompanyHasRelativeDiscount", $soc->remise_percent).
' ';
1270 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1272 $absolute_discount = $soc->getAvailableDiscounts();
1273 if ($absolute_discount) {
1274 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1276 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1282 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPFOLL").
'</span></td><td>';
1283 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1284 print $form->select_dolusers(
GETPOST(
"commercial_suivi_id") ?
GETPOST(
"commercial_suivi_id") : $user->id,
'commercial_suivi_id', 1,
'');
1288 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPSIGN").
'</span></td><td>';
1289 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1290 print $form->select_dolusers(
GETPOST(
"commercial_signature_id") ?
GETPOST(
"commercial_signature_id") : $user->id,
'commercial_signature_id', 1,
'');
1293 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Date").
'</span></td><td>';
1294 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
1295 print $form->selectDate($datecontrat,
'', 0, 0, 0,
"contrat");
1299 if (isModEnabled(
'project')) {
1300 $langs->load(
'projects');
1304 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
1305 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
1306 $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
"projectid", 0, 0, 1, 1);
1307 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>';
1311 print
'<tr><td>'.$langs->trans(
"NotePublic").
'</td><td class="tdtop">';
1312 $doleditor =
new DolEditor(
'note_public', $note_public,
'', 100,
'dolibarr_notes',
'In',
true,
true, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1313 print $doleditor->Create(1);
1316 if (empty($user->socid)) {
1317 print
'<tr><td>'.$langs->trans(
"NotePrivate").
'</td><td class="tdtop">';
1318 $doleditor =
new DolEditor(
'note_private', $note_private,
'', 100,
'dolibarr_notes',
'In',
true,
true, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1319 print $doleditor->Create(1);
1324 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="3"',
'cols' =>
'3');
1325 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
1326 print $hookmanager->resPrint;
1329 if (empty($reshook)) {
1330 print
$object->showOptionals($extrafields,
'create', $parameters);
1337 print $form->buttonsSaveCancel(
"Create");
1339 if (is_object($objectsrc)) {
1340 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1341 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1344 print
'<br>'.$langs->trans(
"Note").
': '.$langs->trans(
"OnlyLinesWithTypeServiceAreUsed");
1358 $result =
$object->fetch_lines();
1363 $nbofservices = count(
$object->lines);
1365 $author =
new User($db);
1366 $author->fetch(
$object->user_author_id);
1368 $commercial_signature =
new User($db);
1369 $commercial_signature->fetch(
$object->commercial_signature_id);
1371 $commercial_suivi =
new User($db);
1372 $commercial_suivi->fetch(
$object->commercial_suivi_id);
1379 print
dol_get_fiche_head($head, $hselected, $langs->trans(
"Contract"), -1,
'contract');
1382 if ($action ==
'delete') {
1384 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"DeleteAContract"), $langs->trans(
"ConfirmDeleteAContract"),
"confirm_delete",
'', 0, 1);
1385 } elseif ($action ==
'valid') {
1387 $ref = substr(
$object->ref, 1, 4);
1388 if ($ref ==
'PROV' && !empty($modCodeContract->code_auto)) {
1393 $text = $langs->trans(
'ConfirmValidateContract', $numref);
1394 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ValidateAContract"), $text,
"confirm_valid",
'', 0, 1);
1395 } elseif ($action ==
'close') {
1397 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"CloseAContract"), $langs->trans(
"ConfirmCloseContract"),
"confirm_close",
'', 0, 1);
1398 } elseif ($action ==
'activate') {
1399 $formquestion = array(
1400 array(
'type' =>
'date',
'name' =>
'd_start',
'label' => $langs->trans(
"DateServiceActivate"),
'value' =>
dol_now()),
1401 array(
'type' =>
'date',
'name' =>
'd_end',
'label' => $langs->trans(
"DateEndPlanned"), 0 =>
'', 1 =>
''),
1402 array(
'type' =>
'text',
'name' =>
'comment',
'label' => $langs->trans(
"Comment"),
'value' =>
'', 0 =>
'', 1 =>
'',
'class' =>
'minwidth300',
'moreattr' =>
'autofocus')
1404 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ActivateAllOnContract"), $langs->trans(
"ConfirmActivateAllOnContract"),
"confirm_activate", $formquestion,
'yes', 1, 280);
1405 } elseif ($action ==
'clone') {
1406 $filter =
'(s.client:IN:1,2,3)';
1408 $formquestion = array(array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter)));
1409 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneContract',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1410 } elseif ($action ==
'sign') {
1411 $text = $langs->trans(
'ConfirmSignContract');
1412 if (isModEnabled(
'notification')) {
1413 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1414 $notify =
new Notify($db);
1416 $text .= $notify->confirmMessage(
'CONTRACT_MODIFY',
$object->socid,
$object);
1421 'name' =>
'signed_status',
1422 'label' =>
'<span class="fieldrequired">'.$langs->trans(
'SignStatus').
'</span>',
1423 'values' =>
$object->getSignedStatusLocalisedArray()
1425 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'SignContract'), $text,
'confirm_sign', $formquestion, 0, 1);
1426 } elseif ($action ==
'unsign') {
1427 $text = $langs->trans(
'ConfirmUnsignContract');
1428 if (isModEnabled(
'notification')) {
1429 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1430 $notify =
new Notify($db);
1432 $text .= $notify->confirmMessage(
'CONTRACT_MODIFY',
$object->socid,
$object);
1434 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnsignContract'), $text,
'confirm_unsign',
'', 0, 1);
1439 $parameters = array(
1440 'formConfirm' => $formconfirm,
1445 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
1446 if (empty($reshook)) {
1447 $formconfirm .= $hookmanager->resPrint;
1448 } elseif ($reshook > 0) {
1449 $formconfirm = $hookmanager->resPrint;
1457 if (
$object->status == $object::STATUS_DRAFT && $user->hasRight(
'contrat',
'creer')) {
1458 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'" method="POST">';
1459 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1460 print
'<input type="hidden" name="action" value="setremise">';
1461 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1466 $linkback =
'<a href="'.DOL_URL_ROOT.
'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1470 if (!empty($modCodeContract->code_auto)) {
1473 $morehtmlref .= $form->editfieldkey(
"",
'ref',
$object->ref,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'', 0, 3);
1474 $morehtmlref .= $form->editfieldval(
"",
'ref',
$object->ref,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'',
null, 2);
1477 $morehtmlref .=
'<div class="refidno">';
1479 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_customer',
$object->ref_customer,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'', 0, 1);
1480 $morehtmlref .= $form->editfieldval(
"RefCustomer",
'ref_customer',
$object->ref_customer,
$object, $user->hasRight(
'contrat',
'creer'),
'string'.(isset(
$conf->global->THIRDPARTY_REF_INPUT_SIZE) ?
':' .
getDolGlobalString(
'THIRDPARTY_REF_INPUT_SIZE') :
''),
'', null, null,
'', 1,
'getFormatedCustomerRef');
1482 $morehtmlref .=
'<br>';
1483 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'', 0, 1);
1484 $morehtmlref .= $form->editfieldval(
"RefSupplier",
'ref_supplier',
$object->ref_supplier,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'',
null,
null,
'', 1,
'getFormatedSupplierRef');
1486 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1);
1488 $morehtmlref .=
' <span class="otherlink">(<a href="'.DOL_URL_ROOT.
'/contrat/list.php?socid='.
$object->thirdparty->id.
'&search_name='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherContracts").
'</a>)</span>';
1491 if (isModEnabled(
'project')) {
1492 $langs->load(
"projects");
1493 $morehtmlref .=
'<br>';
1494 if ($permissiontoadd) {
1495 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1496 if ($action !=
'classify') {
1497 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
1499 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid,
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
1501 if (!empty(
$object->fk_project)) {
1503 $proj->fetch(
$object->fk_project);
1504 $morehtmlref .= $proj->getNomUrl(1);
1506 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
1511 $morehtmlref .=
'</div>';
1514 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'none', $morehtmlref);
1517 print
'<div class="fichecenter">';
1518 print
'<div class="underbanner clearboth"></div>';
1521 print
'<table class="border tableforfield" width="100%">';
1524 print
'<tr><td class="titlefield">'.$langs->trans(
'Discount').
'</td><td colspan="3">';
1525 if (
$object->thirdparty->remise_percent) {
1526 print $langs->trans(
"CompanyHasRelativeDiscount",
$object->thirdparty->remise_percent).
'. ';
1528 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1530 $absolute_discount =
$object->thirdparty->getAvailableDiscounts();
1531 if ($absolute_discount) {
1532 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1534 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1540 print
'<td class="titlefield">';
1541 print $form->editfieldkey(
"Date",
'date_contrat',
$object->date_contrat,
$object, $user->hasRight(
'contrat',
'creer'));
1543 print $form->editfieldval(
"Date",
'date_contrat',
$object->date_contrat,
$object, $user->hasRight(
'contrat',
'creer'),
'datehourpicker');
1549 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1555 if (
$object->status == $object::STATUS_DRAFT && $user->hasRight(
'contrat',
'creer')) {
1562 $blocname =
'contacts';
1563 $title = $langs->trans(
'ContactsAddresses');
1564 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1568 $blocname =
'notes';
1569 $title = $langs->trans(
'Notes');
1570 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1574 $arrayothercontracts =
$object->getListOfContracts(
'others');
1582 global $inputalsopricewithtax;
1583 $inputalsopricewithtax = 1;
1585 $productstatic =
new Product($db);
1588 if (isModEnabled(
'margin') && !empty(
$object->element) && in_array(
$object->element, array(
'facture',
'propal',
'commande'))) {
1596 print
'<div id="contrat-lines-container" id="contractlines" data-contractid="'.$object->id.
'" data-element="'.
$object->element.
'" >';
1597 while ($cursorline <= $nbofservices) {
1598 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.
'" >';
1599 print
'<form name="update" id="addproduct" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'" method="post">';
1600 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1601 print
'<input type="hidden" name="action" value="updateline">';
1602 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1603 print
'<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.
'">';
1604 print
'<input type="hidden" name="fournprice" value="'.(!empty(
$object->lines[$cursorline - 1]->fk_fournprice) ?
$object->lines[$cursorline - 1]->fk_fournprice : 0).
'">';
1607 print
'<div class="div-table-responsive-no-min">';
1608 print
'<table class="notopnoleftnoright allwidth tableforservicepart1 centpercent">';
1610 $sql =
"SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.price_ht, cd.qty,";
1611 $sql .=
" cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1612 $sql .=
" cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";
1613 $sql .=
" cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";
1614 $sql .=
" cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1615 $sql .=
" cd.fk_unit,";
1616 $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";
1617 $sql .=
" ,cd.rang";
1618 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
1619 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
1620 $sql .=
" WHERE cd.rowid = ".((int)
$object->lines[$cursorline - 1]->id);
1622 $result = $db->query($sql);
1627 $objp = $db->fetch_object($result);
1630 print
'<tr class="liste_titre'.($cursorline ?
' liste_titre_add' :
'').
'">';
1631 print
'<td>'.$langs->trans(
"ServiceNb", $cursorline).
'</td>';
1632 print
'<td width="80" class="center">'.$langs->trans(
"VAT").
'</td>';
1633 print
'<td width="80" class="right">'.$langs->trans(
"PriceUHT").
'</td>';
1637 print
'<td width="30" class="center">'.$langs->trans(
"Qty").
'</td>';
1639 print
'<td width="30" class="left">'.$langs->trans(
"Unit").
'</td>';
1641 print
'<td width="50" class="right">'.$langs->trans(
"ReductionShort").
'</td>';
1643 print
'<td width="50" class="right">'.$langs->trans(
"BuyingPrice").
'</td>';
1647 if ($nbofservices > 1 &&
$conf->browser->layout !=
'phone' && $user->hasRight(
'contrat',
'creer')) {
1648 print
'<td width="30" class="linecolmove tdlineupdown center">';
1649 if ($cursorline > 1) {
1650 print
'<a class="lineupdown reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=up&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1651 echo
img_up(
'default', 0,
'imgupforline');
1654 if ($cursorline < $nbofservices) {
1655 print
'<a class="lineupdown reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=down&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1656 echo
img_down(
'default', 0,
'imgdownforline');
1661 print
'<td width="30"> </td>';
1669 if ($action !=
'editline' || $idline != $objp->rowid) {
1671 if (
getDolGlobalString(
'CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') && $objp->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1672 $moreparam =
'style="display: none;"';
1675 print
'<tr class="tdtop oddeven" '.$moreparam.
'>';
1678 if ($objp->fk_product > 0) {
1679 $productstatic->id = $objp->fk_product;
1680 $productstatic->type = $objp->ptype;
1681 $productstatic->ref = $objp->pref;
1682 $productstatic->entity = $objp->pentity;
1683 $productstatic->label = $objp->plabel;
1684 $productstatic->status = $objp->tosell;
1685 $productstatic->status_buy = $objp->tobuy;
1686 $productstatic->status_batch = $objp->tobatch;
1689 $text = $productstatic->getNomUrl(1,
'', 32);
1690 if ($objp->plabel) {
1692 $text .= $objp->plabel;
1694 $description = $objp->description;
1698 $text .= (!empty($objp->description) && $objp->description != $objp->plabel) ?
'<br>'.
dol_htmlentitiesbr($objp->description) :
'';
1702 print $form->textwithtooltip($text, $description, 3, 0, 0, $cursorline, 3, (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
1706 print
'<td>'.img_object($langs->trans(
"ShowProductOrService"), ($objp->product_type ?
'service' :
'product')).
' '.
dol_htmlentitiesbr($objp->
description).
"</td>\n";
1709 print
'<td class="center">';
1710 print
vatrate($objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''), true, $objp->info_bits);
1713 print
'<td class="right">'.($objp->subprice !=
'' ?
price($objp->subprice) :
'').
"</td>\n";
1719 print
'<td class="center">'.$objp->qty.
'</td>';
1722 print
'<td class="left">'.$langs->trans(
$object->lines[$cursorline - 1]->getLabelOfUnit()).
'</td>';
1725 if ($objp->remise_percent > 0) {
1726 print
'<td class="right">'.$objp->remise_percent.
"%</td>\n";
1728 print
'<td> </td>';
1733 print
'<td class="right nowraponall">'.price($objp->pa_ht).
'</td>';
1737 print
'<td class="nowraponall right">';
1738 if ($user->hasRight(
'contrat',
'creer') && is_array($arrayothercontracts) && count($arrayothercontracts) && (
$object->status >= 0)) {
1739 print
'<!-- link to move service line into another contract -->';
1740 print
'<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=move&token='.
newToken().
'&elrowid='.$objp->rowid.
'">';
1741 print
img_picto($langs->trans(
"MoveToAnotherContract"),
'uparrow');
1744 if ($user->hasRight(
'contrat',
'creer') && (
$object->statut >= 0)) {
1745 print
'<a class="reposition marginrightonly editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&elrowid='.$objp->rowid.
'">';
1749 if ($user->hasRight(
'contrat',
'creer') && (
$object->statut >= 0)) {
1750 print
'<a class="reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=deleteline&token='.
newToken().
'&elrowid='.$objp->rowid.
'">';
1767 if ($objp->subprice >= 0) {
1768 print
'<tr class="oddeven" '.$moreparam.
'>';
1769 print
'<td colspan="'.$colspan.
'">';
1772 print $langs->trans(
"DateStartPlanned").
': ';
1773 if ($objp->date_start) {
1776 if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now -
$conf->contrat->services->inactifs->warning_delay)) {
1777 $warning_delay =
$conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1778 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1779 print
" ".img_warning($textlate);
1782 print $langs->trans(
"Unknown");
1784 print
' - ';
1785 print $langs->trans(
"DateEndPlanned").
': ';
1786 if ($objp->date_end) {
1788 if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now -
$conf->contrat->services->expires->warning_delay)) {
1789 $warning_delay =
$conf->contrat->services->expires->warning_delay / 3600 / 24;
1790 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1791 print
" ".img_warning($textlate);
1794 print $langs->trans(
"Unknown");
1802 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1804 $line->id = $objp->rowid;
1805 $line->fetch_optionals();
1806 print $line->showOptionals($extrafields,
'view', array(
'class' =>
'oddeven',
'style' => $moreparam,
'colspan' => $colspan,
'tdclass' =>
'notitlefieldcreate'),
'',
'', 1);
1811 print
'<tr class="oddeven">';
1813 $currentLineProductId = GETPOSTISSET(
'idprod') ?
GETPOST(
'idprod') : (!empty(
$object->lines[$cursorline - 1]->fk_product) ?
$object->lines[$cursorline - 1]->fk_product : 0);
1814 if ($objp->fk_product > 0) {
1815 $canchangeproduct = 1;
1818 if (empty($canchangeproduct)) {
1819 $productstatic->id = $objp->fk_product;
1820 $productstatic->type = $objp->ptype;
1821 $productstatic->ref = $objp->pref;
1822 $productstatic->entity = $objp->pentity;
1823 print $productstatic->getNomUrl(1,
'', 32);
1824 print $objp->label ?
' - '.dol_trunc($objp->label, 32) :
'';
1825 print
'<input type="hidden" name="idprod" value="'.$currentLineProductId.
'">';
1827 $senderissupplier = 0;
1828 if (empty($senderissupplier)) {
1834 print $form->select_produits($currentLineProductId,
'idprod', $filtertype, 0, 0, 1, 2,
'', 0, array(), 0, 1, 0,
'minwidth250onall maxwidth500 widthcentpercentminusx');
1836 $form->select_produits_fournisseurs($currentLineProductId,
'idprod');
1841 print $objp->label ? $objp->label.
'<br>' :
'';
1842 print
'<input type="hidden" name="idprod" value="'.$currentLineProductId.
'">';
1846 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1851 $doleditor =
new DolEditor(
'product_desc', (GETPOSTISSET(
'product_desc') ?
GETPOST(
'product_desc') : $objp->
description),
'', 92,
'dolibarr_details',
'', false, true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_DETAILS'), $nbrows,
'90%');
1852 $doleditor->Create();
1857 print
'<td class="right">';
1858 print $form->load_tva(
"eltva_tx", $objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''), $mysoc,
$object->thirdparty, $currentLineProductId, $objp->info_bits, $objp->product_type, 0, 1);
1862 print
'<td class="right"><input class="width50" type="text" name="elprice" value="'.(GETPOSTISSET(
'elprice') ?
GETPOST(
'elprice') :
price($objp->subprice)).
'"></td>';
1870 print
'<td class="center"><input size="2" type="text" name="elqty" value="'.(GETPOSTISSET(
'elqty') ?
GETPOST(
'elqty') : $objp->qty).
'"></td>';
1874 print
'<td class="left">';
1875 print $form->selectUnits((GETPOSTISSET(
'unit') ?
GETPOSTINT(
'unit') : $objp->fk_unit),
"unit");
1880 print
'<td class="nowraponall right"><input size="1" type="text" name="elremise_percent" value="'.(GETPOSTISSET(
'elremise_percent') ?
GETPOST(
'elremise_percent') : $objp->remise_percent).
'">%</td>';
1882 if (!empty($usemargins)) {
1883 print
'<td class="right">';
1884 if ($objp->fk_product) {
1885 print
'<select id="fournprice" name="fournprice"></select>';
1887 print
'<input id="buying_price" type="text" class="width50" name="buying_price" value="'.price((GETPOSTISSET(
'buying_price') ?
GETPOST(
'buying_price') : $objp->pa_ht), 0,
'', 0).
'"></td>';
1889 print
'<td class="center">';
1890 print
'<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans(
"Modify").
'">';
1891 print
'<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1904 print
'<tr class="oddeven">';
1905 print
'<td colspan="'.$colspan.
'">';
1906 print $langs->trans(
"DateStartPlanned").
' ';
1907 print $form->selectDate($db->jdate($objp->date_start),
"date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1),
"update");
1908 print
' '.$langs->trans(
"DateEndPlanned").
' ';
1909 print $form->selectDate($db->jdate($objp->date_end),
"date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1),
"update");
1913 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1915 $line->id = $objp->rowid;
1916 $line->fetch_optionals();
1918 print $line->showOptionals($extrafields,
'edit', array(
'style' =>
'class="oddeven"',
'colspan' => $colspan,
'tdclass' =>
'notitlefieldcreate'),
'',
'', 1);
1929 if (
getDolGlobalString(
'CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') &&
$object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1930 $moreparam =
'style="display: none;"';
1941 print
'<tr class="oddeven" '.$moreparam.
'>';
1942 print
'<td class="tdhrthin" colspan="'.$colspan.
'"><hr class="opacitymedium tdhrthin"></td>';
1955 if ($action ==
'deleteline' && !$cancel && $user->hasRight(
'contrat',
'creer') &&
$object->lines[$cursorline - 1]->id == $idline) {
1956 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".((
int)
$object->id).
"&lineid=".((
int) $idline), $langs->trans(
"DeleteContractLine"), $langs->trans(
"ConfirmDeleteContractLine"),
"confirm_deleteline",
'', 0, 1);
1957 if ($ret ==
'html') {
1958 print
'<table class="notopnoleftnoright centpercent"><tr class="oddeven" height="6"><td></td></tr></table>';
1965 if ($action ==
'move' && !$cancel && $user->hasRight(
'contrat',
'creer') &&
$object->lines[$cursorline - 1]->id == $idline) {
1966 $arraycontractid = array();
1967 foreach ($arrayothercontracts as $contractcursor) {
1968 $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1972 $formquestion = array(
1973 'text' => $langs->trans(
"ConfirmMoveToAnotherContractQuestion"),
1974 0 => array(
'type' =>
'select',
'name' =>
'newcid',
'values' => $arraycontractid));
1976 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".((
int)
$object->id).
"&lineid=".((
int) $idline), $langs->trans(
"MoveToAnotherContract"), $langs->trans(
"ConfirmMoveToAnotherContract"),
"confirm_move", $formquestion,
'yes');
1977 print
'<table class="notopnoleftnoright centpercent"><tr class="oddeven" height="6"><td></td></tr></table>';
1982 print
'<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
1984 print
'<tr class="oddeven" '.$moreparam.
'>';
1985 print
'<td><span class="valignmiddle hideonsmartphone">'.$langs->trans(
"ServiceStatus").
':</span> '.
$object->lines[$cursorline - 1]->getLibStatut(4).
'</td>';
1986 print
'<td width="30" class="right">';
1987 if ($user->socid == 0) {
1988 if (
$object->statut > 0 && $action !=
'activateline' && $action !=
'unactivateline' && is_object($objp)) {
1989 $tmpaction =
'activateline';
1990 $tmpactionpicto =
'play';
1991 $tmpactiontext = $langs->trans(
"Activate");
1992 if ($objp->statut == 4) {
1993 $tmpaction =
'unactivateline';
1994 $tmpactionpicto =
'playstop';
1995 $tmpactiontext = $langs->trans(
"Disable");
1997 if (($tmpaction ==
'activateline' && $user->hasRight(
'contrat',
'activer')) || ($tmpaction ==
'unactivateline' && $user->hasRight(
'contrat',
'desactiver'))) {
1998 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&ligne='.
$object->lines[$cursorline - 1]->id.
'&action='.$tmpaction.
'&token='.
newToken().
'">';
1999 print
img_picto($tmpactiontext, $tmpactionpicto);
2007 print
'<tr class="oddeven" '.$moreparam.
'>';
2011 if (!$objp->date_start_real) {
2012 print $langs->trans(
"DateStartReal").
': ';
2013 if ($objp->date_start_real) {
2016 print $langs->trans(
"ContractStatusNotRunning");
2020 if ($objp->date_start_real && !$objp->date_end_real) {
2021 print $langs->trans(
"DateStartReal").
': ';
2025 if ($objp->date_start_real && $objp->date_end_real) {
2026 print $langs->trans(
"DateStartReal").
': ';
2028 print
' - ';
2029 print $langs->trans(
"DateEndReal").
': ';
2032 if (!empty($objp->comment)) {
2033 print
" - ".$objp->comment;
2037 print
'<td class="center"> </td>';
2044 if ($user->hasRight(
'contrat',
'activer') && $action ==
'activateline' &&
$object->lines[$cursorline - 1]->id ==
GETPOSTINT(
'ligne') && is_object($objp)) {
2045 print
'<form name="active" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
2046 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2047 print
'<input type="hidden" name="action" value="confirm_active">';
2048 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2049 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2050 print
'<input type="hidden" name="ligne" value="'.GETPOSTINT(
'ligne').
'">';
2051 print
'<input type="hidden" name="confirm" value="yes">';
2053 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
2056 $dateactstart = $objp->date_start;
2059 } elseif (!$dateactstart) {
2060 $dateactstart = time();
2063 $dateactend = $objp->date_end;
2066 } elseif (!$dateactend) {
2067 if ($objp->fk_product > 0) {
2069 $product->fetch($objp->fk_product);
2070 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2074 print
'<tr class="oddeven">';
2075 print
'<td class="nohover">'.$langs->trans(
"DateServiceActivate").
'</td><td class="nohover">';
2076 print $form->selectDate($dateactstart,
'start', $usehm, $usehm, 0,
"active", 1, 0);
2078 print
'<td class="nohover">'.$langs->trans(
"DateEndPlanned").
'</td><td class="nohover">';
2079 print $form->selectDate($dateactend,
"end", $usehm, $usehm, 0,
"active", 1, 0);
2081 print
'<td class="center nohover">';
2086 print
'<tr class="oddeven">';
2087 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>';
2088 print
'<td class="nohover right">';
2089 print
'<input type="submit" class="button" name="activate" value="'.$langs->trans(
"Activate").
'"> ';
2090 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2099 if ($user->hasRight(
'contrat',
'activer') && $action ==
'unactivateline' &&
$object->lines[$cursorline - 1]->id ==
GETPOSTINT(
'ligne') && is_object($objp)) {
2103 print
'<!-- Form to disabled a line -->'.
"\n";
2104 print
'<form name="confirm_closeline" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&ligne='.
$object->lines[$cursorline - 1]->id.
'" method="post">';
2105 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2106 print
'<input type="hidden" name="confirm" value="yes">';
2107 print
'<input type="hidden" name="action" value="confirm_closeline">';
2108 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2110 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
2113 $dateactstart = $objp->date_start_real;
2116 } elseif (!$dateactstart) {
2117 $dateactstart = time();
2120 $dateactend = $objp->date_end_real;
2123 } elseif (!$dateactend) {
2124 if ($objp->fk_product > 0) {
2126 $product->fetch($objp->fk_product);
2127 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2131 if ($dateactend > $now) {
2135 print
'<tr class="oddeven"><td colspan="2" class="nohover">';
2136 if ($objp->statut >= 4) {
2137 if ($objp->statut == 4) {
2138 print $langs->trans(
"DateEndReal").
' ';
2139 print $form->selectDate($dateactend,
"end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1),
"closeline", 1, 1);
2143 print
'<td class="center nohover">';
2146 print
'<tr class="oddeven">';
2147 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>';
2148 print
'<td class="nohover right">';
2149 print
'<input type="submit" class="button" name="close" value="'.$langs->trans(
"Disable").
'"> ';
2150 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2164 if ($user->hasRight(
'contrat',
'creer') && (
$object->statut == 0)) {
2168 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
2169 <input type="hidden" name="token" value="'.
newToken().
'">
2170 <input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">
2171 <input type="hidden" name="mode" value="">
2172 <input type="hidden" name="id" value="'.
$object->id.
'">
2173 <input type="hidden" name="page_y" value="">
2174 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
2177 print
'<div class="div-table-responsive-no-min">';
2178 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2181 if ($action !=
'editline') {
2182 $forcetoshowtitlelines = 1;
2183 if (empty(
$object->multicurrency_code)) {
2189 $parameters = array();
2190 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
2194 if (empty($reshook)) {
2195 $object->formAddObjectLine(1, $mysoc, $soc);
2207 if (
GETPOST(
'modelselected')) {
2208 $action =
'presend';
2214 if ($user->socid == 0 && $action !=
'presend' && $action !=
'editline') {
2215 print
'<div class="tabsAction">';
2217 $parameters = array();
2218 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2220 if (empty($reshook)) {
2224 'class' =>
'classfortooltip'
2229 if (empty($user->socid)) {
2230 if (
$object->status == $object::STATUS_VALIDATED) {
2231 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'contrat',
'creer'))) {
2232 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle',
'',
true, $params);
2234 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
2239 if (
$object->status == $object::STATUS_DRAFT && $nbofservices) {
2240 if ($user->hasRight(
'contrat',
'creer')) {
2241 unset($params[
'attr'][
'title']);
2242 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
2244 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2245 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default',
'#',
'',
false, $params);
2248 if (
$object->status == $object::STATUS_VALIDATED) {
2249 if ($user->hasRight(
'contrat',
'creer')) {
2250 unset($params[
'attr'][
'title']);
2251 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
2253 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2254 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
2259 $arrayofcreatebutton = array();
2260 if (isModEnabled(
'order') &&
$object->status > 0 &&
$object->nbofservicesclosed < $nbofservices) {
2261 $arrayofcreatebutton[] = array(
2262 'url' =>
'/commande/card.php?action=create&token='.
newToken().
'&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->thirdparty->id,
2263 'label' => $langs->trans(
'AddOrder'),
2265 'perm' => $user->hasRight(
'commande',
'creer') ?
true : false,
2269 if (isModEnabled(
'invoice') &&
$object->status > 0 && $soc->client > 0) {
2270 $arrayofcreatebutton[] = array(
2271 'url' =>
'/compta/facture/card.php?action=create&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->thirdparty->id,
2272 'label' => $langs->trans(
'CreateBill'),
2274 'perm' => $user->hasRight(
'facture',
'creer') ?
true : false,
2278 if (isModEnabled(
'supplier_invoice') &&
$object->status > 0 && $soc->fournisseur == 1) {
2279 $langs->load(
"suppliers");
2280 $arrayofcreatebutton[] = array(
2281 'url' =>
'/fourn/facture/card.php?action=create&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->thirdparty->id,
2282 'label' => $langs->trans(
'AddSupplierInvoice'),
2284 'perm' => $user->hasRight(
'fournisseur',
'facture',
'creer') ?
true : false,
2288 if (count($arrayofcreatebutton)) {
2289 unset($params[
'attr'][
'title']);
2290 print
dolGetButtonAction(
'', $langs->trans(
"Create"),
'default', $arrayofcreatebutton,
'',
true, $params);
2293 $arrayforbutaction = array();
2294 if (
$object->nbofservicesclosed > 0 ||
$object->nbofserviceswait > 0) {
2295 $arrayforbutaction[] = array(
2296 'url' =>
'/contrat/card.php?id='.
$object->id.
'&action=activate&token='.
newToken(),
2297 'label' => $langs->trans(
'ActivateAllContracts'),
2299 'perm' => $user->hasRight(
'contrat',
'activer'),
2303 if (
$object->nbofservicesclosed < $nbofservices) {
2304 $arrayforbutaction[] = array(
2305 'url' =>
'/contrat/card.php?id='.
$object->id.
'&action=close&token='.
newToken(),
2306 'label' => $langs->trans(
'CloseAllContracts'),
2308 'perm' => $user->hasRight(
'contrat',
'desactiver') ?
true : false,
2313 if (count($arrayforbutaction)) {
2314 unset($params[
'attr'][
'title']);
2315 print
dolGetButtonAction(
'', $langs->trans(
"Services"),
'default', $arrayforbutaction,
'',
true, $params);
2319 if ($action ==
'showclosedlines') {
2320 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>';
2322 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>';
2327 if (
$object->status > Contrat::STATUS_DRAFT) {
2328 if (
$object->signed_status != Contrat::$SIGNED_STATUSES[
'STATUS_SIGNED_ALL']) {
2329 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=sign&token=' .
newToken() .
'">' . $langs->trans(
"ContractSign") .
'</a></div>';
2331 print
'<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id .
'&action=unsign&token=' .
newToken() .
'">' . $langs->trans(
"ContractUnsign") .
'</a></div>';
2336 if ($user->hasRight(
'contrat',
'creer')) {
2337 unset($params[
'attr'][
'title']);
2342 unset($params[
'attr'][
'title']);
2343 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete, $params);
2349 if ($action !=
'presend') {
2350 print
'<div class="fichecenter"><div class="fichehalfleft">';
2357 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2358 $genallowed = $user->hasRight(
'contrat',
'lire');
2359 $delallowed = $user->hasRight(
'contrat',
'creer');
2362 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);
2366 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'contrat'), 1);
2367 $linktoelem = $tmparray[
'linktoelem'];
2368 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
2369 print $htmltoenteralink;
2371 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem);
2375 print
'<br><!-- Link to sign -->';
2376 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2378 print showOnlineSignatureUrl(
'contract',
$object->ref,
$object).
'<br>';
2381 print
'</div><div class="fichehalfright">';
2385 $morehtmlcenter =
'<div class="nowraponall">';
2386 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/contrat/messaging.php?id='.
$object->id);
2387 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/agenda.php?id='.
$object->id);
2388 $morehtmlcenter .=
'</div>';
2392 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2394 $somethingshown = $formactions->showactions(
$object,
'contract', $socid, 1,
'listactions', $MAXEVENT,
'', $morehtmlcenter);
2396 print
'</div></div>';
2400 $modelmail =
'contract';
2401 $defaulttopic =
'SendContractRef';
2402 $diroutput =
$conf->contrat->multidir_output[
$object->entity];
2403 $trackid =
'con'.$object->id;
2405 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
2416if (isModEnabled(
'margin') && $action ==
'editline') {
2417 print
"\n".
'<script type="text/javascript">'.
"\n";
2419 $(document).ready(
function() {
2420 var idprod = $(
"input[name='idprod']").val();
2421 var fournprice = $(
"input[name='fournprice']").val();
2422 var token =
'<?php echo currentToken(); ?>';
2424 $.post(
'<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2428 if (data.length > 0) {
2431 $(data).each(
function() {
2432 options +=
'<option value="'+this.
id+
'" price="'+this.
price+
'"';
2433 if (fournprice > 0) {
2434 if (this.
id == fournprice) {
2435 options +=
' selected';
2436 $(
"#buying_price").val(this.price);
2440 options +=
'>'+this.label+
'</option>';
2442 options +=
'<option value=null'+(trouve?
'':
' selected')+
'><?php echo $langs->trans("InputPrice"); ?></option>';
2443 $(
"#fournprice").html(options);
2445 $(
"#buying_price").hide();
2446 $(
"#fournprice").show();
2449 $(
"#buying_price").show();
2451 $(
"#fournprice").change(
function() {
2452 var selval = $(
this).find(
'option:selected').attr(
"price");
2454 $(
"#buying_price").val(selval).hide();
2456 $(
'#buying_price').show();
2460 $(
"#fournprice").hide();
2461 $(
'#buying_price').show();
2467 $(
"#fournprice").hide();
2468 $(
'#buying_price').show();
2472 print
"\n".
'<script type="text/javascript">'.
"\n";
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Class to manage lines of contracts.
Class to manage a WYSIWYG editor.
Class to manage the table of subscription to notifications.
File of class to manage predefined price products or services by customer.
Class to manage products or services.
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.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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 '.
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.
GETPOSTISARRAY($paramname, $method=0)
Return true if the parameter $paramname is submit from a POST OR GET as an array.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
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.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
img_up($titlealt='default', $selected=0, $moreclass='')
Show top arrow logo.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
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.