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');
74$backtopageforcancel =
GETPOST(
'backtopageforcancel',
'alpha');
79$origin =
GETPOST(
'origin',
'alpha');
82$attribute =
GETPOST(
'attribute',
'aZ09');
98 $socid = $user->socid;
102$hookmanager->initHooks(array(
'contractcard',
'globalcard'));
111if ($id > 0 || !empty($ref) && $action !=
'add') {
112 $ret =
$object->fetch($id, $ref);
114 $ret =
$object->fetch_thirdparty();
122$extrafields->fetch_name_optionals_label(
$object->table_element);
125$extralabelslines = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
127$permissionnote = $user->hasRight(
'contrat',
'creer');
128$permissiondellink = $user->hasRight(
'contrat',
'creer');
129$permissiontodelete = ($user->hasRight(
'contrat',
'creer') &&
$object->status == $object::STATUS_DRAFT) || $user->hasRight(
'contrat',
'supprimer');
130$permissiontoadd = $user->hasRight(
'contrat',
'creer');
131$permissiontoedit = $permissiontoadd;
132$permissiontoactivate = $user->hasRight(
'contrat',
'activer');
133$permissiontodisable = $user->hasRight(
'contrat',
'desactiver');
134$permissiontoeditextra = $permissiontoadd;
135if (
GETPOST(
'attribute',
'aZ09') && isset($extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')])) {
137 $permissiontoeditextra =
dol_eval((
string) $extrafields->attributes[
$object->table_element][
'perms'][
GETPOST(
'attribute',
'aZ09')]);
145if (!(
$object->id > 0) && ($action ==
'view' || $action ==
'')) {
154$parameters = array(
'socid' => $socid);
155$reshook = $hookmanager->executeHooks(
'doActions', $parameters,
$object, $action);
159if (empty($reshook)) {
160 $backurlforlist = DOL_URL_ROOT.
'/contrat/list.php';
162 if (empty($backtopage) || ($cancel && empty($id))) {
163 if (empty($backtopage) || ($cancel && strpos($backtopage,
'__ID__'))) {
164 if (empty($id) && (($action !=
'add' && $action !=
'create') || $cancel)) {
165 $backtopage = $backurlforlist;
167 $backtopage = DOL_URL_ROOT.
'/contrat/card.php?id='.((!empty($id) &&
$id > 0) ? $id :
'__ID__');
173 if (!empty($backtopageforcancel)) {
174 header(
"Location: ".$backtopageforcancel);
176 } elseif (!empty($backtopage)) {
177 header(
"Location: ".$backtopage);
183 include DOL_DOCUMENT_ROOT.
'/core/actions_setnotes.inc.php';
185 include DOL_DOCUMENT_ROOT.
'/core/actions_dellink.inc.php';
187 include DOL_DOCUMENT_ROOT.
'/core/actions_lineupdown.inc.php';
189 if ($action ==
'confirm_active' && $confirm ==
'yes' && $permissiontoactivate) {
202 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
207 } elseif ($action ==
'confirm_sign' && $confirm ==
'yes' && $user->hasRight(
'contract',
'creer')) {
208 $result =
$object->setSignedStatus($user,
GETPOSTINT(
'signed_status'), 0,
'CONTRACT_MODIFY');
210 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id);
215 } elseif ($action ==
'confirm_unsign' && $confirm ==
'yes' && $user->hasRight(
'contract',
'creer')) {
216 $result =
$object->setSignedStatus($user, Contrat::$SIGNED_STATUSES[
'STATUS_NO_SIGNATURE'], 0,
'CONTRACT_MODIFY');
218 header(
'Location: ' . $_SERVER[
"PHP_SELF"] .
'?id=' .
$object->id);
223 } elseif ($action ==
'confirm_closeline' && $confirm ==
'yes' && $permissiontodisable) {
230 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateEnd")),
null,
'errors');
235 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
243 if (
GETPOST(
'mode') ==
'predefined') {
255 $date_start_update =
'';
256 $date_end_update =
'';
257 $date_start_real_update =
'';
258 $date_end_real_update =
'';
259 if (
GETPOST(
'date_start_updatemonth') &&
GETPOST(
'date_start_updateday') &&
GETPOST(
'date_start_updateyear')) {
262 if (
GETPOST(
'date_end_updatemonth') &&
GETPOST(
'date_end_updateday') &&
GETPOST(
'date_end_updateyear')) {
265 if (
GETPOST(
'date_start_real_updatemonth') &&
GETPOST(
'date_start_real_updateday') &&
GETPOST(
'date_start_real_updateyear')) {
268 if (
GETPOST(
'date_end_real_updatemonth') &&
GETPOST(
'date_end_real_updateday') &&
GETPOST(
'date_end_real_updateyear')) {
276 if ($action ==
'add' && $user->hasRight(
'contrat',
'creer')) {
278 if (empty($datecontrat)) {
280 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
285 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
291 $ret = $extrafields->setOptionalsFromPost(
null,
$object);
299 $object->date_contrat = $datecontrat;
313 if (!empty($origin) && !empty($originid)) {
315 $element = $subelement = $origin;
316 if (preg_match(
'/^([^_]+)_([^_]+)/i', $origin, $regs)) {
318 $subelement = $regs[2];
322 if ($element ==
'order') {
323 $element = $subelement =
'commande';
325 if ($element ==
'propal') {
326 $element =
'comm/propal';
327 $subelement =
'propal';
329 if ($element ==
'invoice' || $element ==
'facture') {
330 $element =
'compta/facture';
331 $subelement =
'facture';
335 $object->origin_id = $originid;
340 $object->linked_objects = array_merge(
$object->linked_objects,
GETPOST(
'other_linked_objects',
'array:int'));
347 $classname = ucfirst($subelement);
348 $srcobject =
new $classname($db);
349 '@phan-var-force Commande|Propal|Facture $srcobject';
352 $result = $srcobject->fetch(
$object->origin_id);
354 $srcobject->fetch_thirdparty();
355 $lines = $srcobject->lines;
356 if (empty($lines) && method_exists($srcobject,
'fetch_lines')) {
357 $srcobject->fetch_lines();
358 $lines = $srcobject->lines;
362 $num = count($lines);
364 for ($i = 0; $i < $num; $i++) {
365 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
367 if ($product_type == 1 || (
getDolGlobalString(
'CONTRACT_SUPPORT_PRODUCTS') && in_array($product_type, array(0, 1)))) {
369 if ($lines[$i]->fk_product > 0) {
370 $product_static =
new Product($db);
375 $prod->id = $lines[$i]->fk_product;
376 $prod->getMultiLangs();
378 $outputlangs = $langs;
380 if (
GETPOST(
'lang_id',
'aZ09')) {
381 $newlang =
GETPOST(
'lang_id',
'aZ09');
383 if (empty($newlang)) {
384 $newlang = $srcobject->thirdparty->default_lang;
386 if (!empty($newlang)) {
388 $outputlangs->setDefaultLang($newlang);
391 $label = (!empty($prod->multilangs[$outputlangs->defaultlang][
"libelle"])) ? $prod->multilangs[$outputlangs->defaultlang][
"libelle"] : $lines[$i]->product_label;
393 $label = $lines[$i]->product_label;
395 $desc = ($lines[$i]->desc && $lines[$i]->desc != $lines[$i]->label) ?
dol_htmlentitiesbr($lines[$i]->desc) :
'';
401 $array_options = array();
403 if (method_exists($lines[$i],
'fetch_optionals')) {
404 $lines[$i]->fetch_optionals();
405 $array_options = $lines[$i]->array_options;
408 $txtva = $lines[$i]->vat_src_code ? $lines[$i]->tva_tx.
' ('.$lines[$i]->vat_src_code.
')' : $lines[$i]->tva_tx;
416 $lines[$i]->subprice,
421 $lines[$i]->fk_product,
422 $lines[$i]->remise_percent,
423 $lines[$i]->date_start,
424 $lines[$i]->date_end,
427 $lines[$i]->info_bits,
428 $lines[$i]->fk_fournprice,
431 (
int) $lines[$i]->fk_unit,
447 $parameters = array(
'objFrom' => $srcobject);
448 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
462 $result =
$object->create($user);
464 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
472 } elseif ($action ==
'classin' && $user->hasRight(
'contrat',
'creer')) {
474 } elseif ($action ==
'addline' && $user->hasRight(
'contrat',
'creer')) {
478 $line_desc = (GETPOSTISSET(
'dp_desc') ?
GETPOST(
'dp_desc',
'restricthtml') :
'');
481 $price_ht_devise =
'';
483 $price_ttc_devise =
'';
485 $rang = count(
$object->lines) + 1;
487 if (
GETPOST(
'price_ht') !==
'') {
490 if (
GETPOST(
'multicurrency_price_ht') !==
'') {
493 if (
GETPOST(
'price_ttc') !==
'') {
496 if (
GETPOST(
'multicurrency_price_ttc') !==
'') {
500 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free') {
506 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ProductOrService")),
null,
'errors');
511 $tva_tx =
GETPOST(
'tva_tx',
'alpha');
514 $remise_percent = (GETPOSTISSET(
'remise_percent'.$predef) ?
price2num(
GETPOST(
'remise_percent'.$predef),
'', 2) : 0);
515 if (empty($remise_percent)) {
520 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Qty")),
null,
'errors');
523 if (
GETPOST(
'prod_entry_mode',
'alpha') ==
'free' && (empty($idprod) || $idprod < 0) && empty($line_desc)) {
524 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Description")),
null,
'errors');
530 if (!empty($date_start) && !empty($date_end) && $date_start > $date_end) {
531 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
536 $extralabelsline = $extrafields->fetch_name_optionals_label(
$object->table_element_line);
537 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
539 if (is_array($extralabelsline)) {
541 foreach ($extralabelsline as $key => $value) {
542 unset($_POST[
"options_".$key]);
551 $price_base_type =
'';
557 $prod->fetch($idprod);
566 $price_min = $prod->price_min;
567 $price_min_ttc = $prod->price_min_ttc;
571 $price_min = $prod->multiprices_min[
$object->thirdparty->price_level];
572 $price_min_ttc = $prod->multiprices_min_ttc[
$object->thirdparty->price_level];
575 require_once DOL_DOCUMENT_ROOT.
'/product/class/productcustomerprice.class.php';
579 $filter = array(
't.fk_product' => (
string) $prod->id,
't.fk_soc' => (
string)
$object->thirdparty->id);
581 $result = $prodcustprice->fetchAll(
'',
'', 0, 0, $filter);
583 if (count($prodcustprice->lines) > 0) {
584 $date_now = (int) floor(
dol_now() / 86400) * 86400;
585 foreach ($prodcustprice->lines as $k => $custprice_line) {
586 if ($custprice_line->date_begin <= $date_now && (empty($custprice_line->date_end) || $date_now <= $custprice_line->date_end)) {
587 $price_min =
price($custprice_line->price_min);
588 $price_min_ttc =
price($custprice_line->price_min_ttc);
604 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
605 $tmpprodvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', (
string) $prod->tva_tx));
608 if (!empty($price_ht) || $price_ht ===
'0') {
610 $pu_ttc =
price2num((
float) $pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
611 $price_base_type =
'HT';
612 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
614 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
615 $price_base_type =
'TTC';
618 $desc = $prod->description;
628 $fk_unit = $prod->fk_unit;
632 $tva_npr = (preg_match(
'/\*/', $tva_tx) ? 1 : 0);
633 if (empty($tva_tx)) {
636 $tva_tx = str_replace(
'*',
'', $tva_tx);
639 $pu_ht_devise =
price2num($price_ht_devise,
'MU');
640 $pu_ttc_devise =
price2num($price_ttc_devise,
'MU');
642 $tmpvat =
price2num(preg_replace(
'/\s*\(.*\)/',
'', $tva_tx));
645 if (!empty($price_ht) || $price_ht ===
'0') {
647 $pu_ttc =
price2num((
float) $pu_ht * (1 + ((
float) $tmpvat / 100)),
'MU');
648 $price_base_type =
'HT';
649 } elseif (!empty($price_ttc) || $price_ttc ===
'0') {
651 $pu_ht =
price2num((
float) $pu_ttc / (1 + ((
float) $tmpvat / 100)),
'MU');
652 $price_base_type =
'TTC';
660 $fk_fournprice =
GETPOST(
'fournprice');
662 $pa_ht =
GETPOST(
'buying_price');
672 if (((
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && !$user->hasRight(
'produit',
'ignore_price_min_advance'))
674 $object->error = $langs->trans(
"CantBeLessThanMinPrice",
price(
price2num($price_min,
'MU'), 0, $langs, 0, 0, -1,
$conf->currency));
692 (
int) $fk_fournprice,
703 $outputlangs = $langs;
706 $newlang =
GETPOST(
'lang_id',
'aZ09');
709 $newlang =
$object->thirdparty->default_lang;
711 if (!empty($newlang)) {
713 $outputlangs->setDefaultLang($newlang);
718 $object->generateDocument(
$object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
721 unset($_POST[
'prod_entry_mode']);
723 unset($_POST[
'qty']);
724 unset($_POST[
'type']);
725 unset($_POST[
'remise_percent']);
726 unset($_POST[
'price_ht']);
727 unset($_POST[
'multicurrency_price_ht']);
728 unset($_POST[
'price_ttc']);
729 unset($_POST[
'tva_tx']);
730 unset($_POST[
'product_ref']);
731 unset($_POST[
'product_label']);
732 unset($_POST[
'product_desc']);
733 unset($_POST[
'fournprice']);
734 unset($_POST[
'buying_price']);
735 unset($_POST[
'np_marginRate']);
736 unset($_POST[
'np_markRate']);
737 unset($_POST[
'dp_desc']);
738 unset($_POST[
'idprod']);
740 unset($_POST[
'date_starthour']);
741 unset($_POST[
'date_startmin']);
742 unset($_POST[
'date_startsec']);
743 unset($_POST[
'date_startday']);
744 unset($_POST[
'date_startmonth']);
745 unset($_POST[
'date_startyear']);
746 unset($_POST[
'date_endhour']);
747 unset($_POST[
'date_endmin']);
748 unset($_POST[
'date_endsec']);
749 unset($_POST[
'date_endday']);
750 unset($_POST[
'date_endmonth']);
751 unset($_POST[
'date_endyear']);
756 } elseif ($action ==
'updateline' && $user->hasRight(
'contrat',
'creer') && !
GETPOST(
'cancel',
'alpha')) {
760 if (!empty($date_start_update) && !empty($date_end_update) && $date_start_update > $date_end_update) {
761 setEventMessages($langs->trans(
"Error").
': '.$langs->trans(
"DateStartPlanned").
' > '.$langs->trans(
"DateEndPlanned"),
null,
'errors');
762 $action =
'editline';
768 if ($objectline->fetch($idline) < 0) {
772 $objectline->fetch_optionals();
774 $objectline->oldcopy =
dol_clone($objectline, 2);
782 if ($date_start_real_update ==
'') {
783 $date_start_real_update = $objectline->date_start_real;
785 if ($date_end_real_update ==
'') {
786 $date_end_real_update = $objectline->date_end_real;
789 $vat_rate =
GETPOST(
'eltva_tx',
'alpha');
792 if (preg_match(
'/\*/', $vat_rate)) {
797 $vat_rate = str_replace(
'*',
'', $vat_rate);
806 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
807 $vat_src_code = $reg[1];
808 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
824 $objectline->fk_product =
GETPOSTINT(
'idprod');
825 $objectline->description =
GETPOST(
'product_desc',
'restricthtml');
828 $objectline->remise_percent = $remise_percent;
829 $objectline->tva_tx = ($txtva ? $txtva : 0);
830 $objectline->vat_src_code = $vat_src_code;
831 $objectline->localtax1_tx = is_numeric($localtax1_tx) ? $localtax1_tx : 0;
832 $objectline->localtax2_tx = is_numeric($localtax2_tx) ? $localtax2_tx : 0;
833 $objectline->date_start = $date_start_update;
834 $objectline->date_start_real = $date_start_real_update;
835 $objectline->date_end = $date_end_update;
836 $objectline->date_end_real = $date_end_real_update;
837 $objectline->user_closing_id = $user->id;
839 $objectline->pa_ht = $pa_ht;
845 $objectline->fk_unit =
null;
849 $extralabelsline = $extrafields->fetch_name_optionals_label($objectline->table_element);
850 $array_options = $extrafields->getOptionalsFromPost(
$object->table_element_line, $predef);
852 if (is_array($array_options) && count($array_options) > 0) {
854 foreach ($array_options as $key => $value) {
855 $objectline->array_options[$key] = $array_options[$key];
861 $result = $objectline->update($user);
864 $action =
'editline';
865 $_GET[
'rowid'] =
GETPOST(
'elrowid');
875 } elseif ($action ==
'confirm_deleteline' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
879 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
884 } elseif ($action ==
'confirm_valid' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
885 $result =
$object->validate($user);
890 $outputlangs = $langs;
893 $newlang =
GETPOST(
'lang_id',
'aZ09');
896 $newlang =
$object->thirdparty->default_lang;
898 if (!empty($newlang)) {
900 $outputlangs->setDefaultLang($newlang);
905 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
910 } elseif ($action ==
'reopen' && $user->hasRight(
'contrat',
'creer')) {
911 $result =
$object->reopen($user);
915 } elseif ($action ==
'confirm_close' && $confirm ==
'yes' && $permissiontodisable) {
917 $result =
$object->closeAll($user);
921 } elseif ($action ==
'confirm_activate' && $confirm ==
'yes' && $permissiontoactivate) {
924 $comment =
GETPOST(
'comment',
'alpha');
925 $result =
$object->activateAll($user, $date_start, 0, $comment, $date_end);
929 } elseif ($action ==
'confirm_delete' && $confirm ==
'yes' && $permissiontodelete) {
930 $result =
$object->delete($user);
932 header(
"Location: list.php?restore_lastsearch_values=1");
937 } elseif ($action ==
'confirm_move' && $confirm ==
'yes' && $permissiontoedit) {
940 $result = $contractline->fetch(
GETPOSTINT(
'lineid'));
941 $contractline->fk_contrat =
GETPOSTINT(
'newcid');
942 $result = $contractline->update($user, 1);
944 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
950 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentities(
"RefNewContract")),
null,
'errors');
952 } elseif ($action ==
'update_extras' && $permissiontoeditextra) {
955 $attribute =
GETPOST(
'attribute',
'aZ09');
958 $ret = $extrafields->setOptionalsFromPost(
null,
$object, $attribute);
965 $result =
$object->updateExtraField($attribute,
'CONTRACT_MODIFY');
973 $action =
'edit_extras';
975 } elseif ($action ==
'setref_supplier' && $permissiontoadd) {
979 $result =
$object->setValueFrom(
'ref_supplier',
GETPOST(
'ref_supplier',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
982 $action =
'editref_supplier';
984 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
988 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
991 } elseif ($action ==
'setref_customer' && $permissiontoadd) {
995 $result =
$object->setValueFrom(
'ref_customer',
GETPOST(
'ref_customer',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
998 $action =
'editref_customer';
1000 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1004 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1007 } elseif ($action ==
'setref' && $permissiontoadd) {
1009 $result =
$object->fetch($id);
1016 $result =
$object->setValueFrom(
'ref',
GETPOST(
'ref',
'alpha'),
'',
null,
'text',
'', $user,
'CONTRACT_MODIFY');
1019 $action =
'editref';
1021 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1028 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1032 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1035 } elseif ($action ==
'setdate_contrat' && $permissiontoadd) {
1037 $result =
$object->fetch($id);
1042 $result =
$object->setValueFrom(
'date_contrat', $datacontrat,
'',
null,
'date',
'', $user,
'CONTRACT_MODIFY');
1045 $action =
'editdate_contrat';
1047 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1051 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".$id);
1057 include DOL_DOCUMENT_ROOT.
'/core/actions_printing.inc.php';
1061 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
1064 $triggersendname =
'CONTRACT_SENTBYMAIL';
1066 $mode =
'emailfromcontract';
1067 $trackid =
'con'.$object->id;
1068 include DOL_DOCUMENT_ROOT.
'/core/actions_sendmails.inc.php';
1072 if ($action ==
'addcontact' && $user->hasRight(
'contrat',
'creer')) {
1075 $result =
$object->add_contact($contactid, $typeid,
GETPOST(
"source",
'aZ09'));
1078 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1081 if (
$object->error ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
1082 $langs->load(
"errors");
1083 setEventMessages($langs->trans(
"ErrorThisContactIsAlreadyDefinedAsThisType"),
null,
'errors');
1088 } elseif ($action ==
'swapstatut' && $user->hasRight(
'contrat',
'creer')) {
1091 } elseif ($action ==
'deletecontact' && $user->hasRight(
'contrat',
'creer')) {
1096 header(
"Location: ".$_SERVER[
'PHP_SELF'].
"?id=".
$object->id);
1105 if ($action ==
'confirm_clone' && $confirm ==
'yes' && $user->hasRight(
'contrat',
'creer')) {
1107 setEventMessages($langs->trans(
"NoCloneOptionsSpecified"),
null,
'errors');
1110 $result =
$object->createFromClone($user, $socid);
1112 header(
"Location: ".$_SERVER[
'PHP_SELF'].
'?id='.$result);
1115 if (count(
$object->errors) > 0) {
1130$title =
$object->ref.
" - ".$langs->trans(
'Contract');
1131if ($action ==
'create') {
1132 $title = $langs->trans(
"NewContract");
1134$help_url =
'EN:Module_Contracts|FR:Module_Contrat|ES:Contratos_de_servicio';
1136llxHeader(
'', $title, $help_url,
'', 0, 0,
'',
'',
'',
'mod-contrat page-card');
1138$form =
new Form($db);
1140if (isModEnabled(
'project')) {
1146if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
1147 $module = substr($module, 0,
dol_strlen($module) - 4);
1150$modCodeContract =
null;
1152 $modCodeContract =
new $module();
1153 '@phan-var-force ModelNumRefContracts $modCodeContract';
1157if ($action ==
'create') {
1163 $soc->fetch($socid);
1169 $element = $subelement =
GETPOST(
'origin');
1170 if (preg_match(
'/^([^_]+)_([^_]+)/i',
GETPOST(
'origin'), $regs)) {
1171 $element = $regs[1];
1172 $subelement = $regs[2];
1175 if ($element ==
'project') {
1179 if ($element ==
'order' || $element ==
'commande') {
1180 $element = $subelement =
'commande';
1182 if ($element ==
'propal') {
1183 $element =
'comm/propal';
1184 $subelement =
'propal';
1186 if ($element ==
'invoice' || $element ==
'facture') {
1187 $element =
'compta/facture';
1188 $subelement =
'facture';
1193 $classname = ucfirst($subelement);
1194 $objectsrc =
new $classname($db);
1195 '@phan-var-force Commande|Propal|Facture $objectsrc';
1196 $objectsrc->fetch($originid);
1197 if (empty($objectsrc->lines) && method_exists($objectsrc,
'fetch_lines')) {
1198 $objectsrc->fetch_lines();
1200 $objectsrc->fetch_thirdparty();
1203 $objectsrc->fetch_optionals();
1204 $object->array_options = $objectsrc->array_options;
1206 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project :
'');
1208 $soc = $objectsrc->thirdparty;
1210 $note_private = (!empty($objectsrc->note_private) ? $objectsrc->note_private :
'');
1211 $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public :
'');
1214 $srccontactslist = $objectsrc->liste_contact(-1,
'external', 1);
1218 $note_private =
GETPOST(
"note_private",
"alpha");
1219 $note_public =
GETPOST(
"note_public",
"alpha");
1224 print
'<form name="form_contract" action="'.$_SERVER[
"PHP_SELF"].
'" method="post">';
1225 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1226 print
'<input type="hidden" name="action" value="add">';
1227 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">'.
"\n";
1228 print
'<input type="hidden" name="remise_percent" value="0">';
1229 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1233 print
'<table class="border centpercent">';
1236 print
'<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans(
'Ref').
'</td><td>';
1237 if (!empty($modCodeContract->code_auto)) {
1238 $tmpcode = $langs->trans(
"Draft");
1240 $tmpcode =
'<input name="ref" class="maxwidth100" maxlength="128" value="'.dol_escape_htmltag(
GETPOST(
'ref') ?
GETPOST(
'ref') : $tmpcode).
'">';
1246 print
'<tr><td>'.$langs->trans(
'RefCustomer').
'</td>';
1247 print
'<td><input type="text" class="maxwidth150" name="ref_customer" id="ref_customer" value="'.dol_escape_htmltag(
GETPOST(
'ref_customer',
'alpha')).
'"></td></tr>';
1250 print
'<tr><td>'.$langs->trans(
'RefSupplier').
'</td>';
1251 print
'<td><input type="text" class="maxwidth150" name="ref_supplier" id="ref_supplier" value="'.dol_escape_htmltag(
GETPOST(
'ref_supplier',
'alpha')).
'"></td></tr>';
1255 print
'<td class="fieldrequired">'.$langs->trans(
'ThirdParty').
'</td>';
1258 print $soc->getNomUrl(1);
1259 print
'<input type="hidden" name="socid" value="'.$soc->id.
'">';
1263 print
img_picto(
'',
'company',
'class="pictofixedwidth"');
1264 print $form->select_company(
'',
'socid',
'',
'SelectThirdParty', 1, 0, array(), 0,
'minwidth300 widthcentpercentminusxx maxwidth500');
1265 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>';
1272 print
'<tr><td>'.$langs->trans(
'Discounts').
'</td><td>';
1273 if ($soc->remise_percent) {
1274 print $langs->trans(
"CompanyHasRelativeDiscount", $soc->remise_percent).
' ';
1276 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1278 $absolute_discount = $soc->getAvailableDiscounts();
1279 if ($absolute_discount) {
1280 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1282 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1288 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPFOLL").
'</span></td><td>';
1289 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1290 print $form->select_dolusers(
GETPOST(
"commercial_suivi_id") ?
GETPOST(
"commercial_suivi_id") : $user->id,
'commercial_suivi_id', 1, null);
1294 print
'<tr><td class="nowrap"><span class="fieldrequired">'.$langs->trans(
"TypeContact_contrat_internal_SALESREPSIGN").
'</span></td><td>';
1295 print
img_picto(
'',
'user',
'class="pictofixedwidth"');
1296 print $form->select_dolusers(
GETPOST(
"commercial_signature_id") ?
GETPOST(
"commercial_signature_id") : $user->id,
'commercial_signature_id', 1, null);
1299 print
'<tr><td><span class="fieldrequired">'.$langs->trans(
"Date").
'</span></td><td>';
1300 print
img_picto(
'',
'action',
'class="pictofixedwidth"');
1301 print $form->selectDate($datecontrat,
'', 0, 0, 0,
"contrat");
1305 if (isModEnabled(
'project')) {
1306 $langs->load(
'projects');
1310 print
'<tr><td>'.$langs->trans(
"Project").
'</td><td>';
1311 print
img_picto(
'',
'project',
'class="pictofixedwidth"');
1312 $formproject->select_projects(($soc->id > 0 ? $soc->id : -1), $projectid,
"projectid", 0, 0, 1, 1);
1313 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>';
1317 print
'<tr><td>'.$langs->trans(
"NotePublic").
'</td><td class="tdtop">';
1318 $doleditor =
new DolEditor(
'note_public', (
string) $note_public,
'', 100,
'dolibarr_notes',
'In',
true,
true, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3,
'90%');
1319 print $doleditor->Create(1);
1322 if (empty($user->socid)) {
1323 print
'<tr><td>'.$langs->trans(
"NotePrivate").
'</td><td class="tdtop">';
1324 $doleditor =
new DolEditor(
'note_private', (
string) $note_private,
'', 100,
'dolibarr_notes',
'In',
true,
true, !
getDolGlobalString(
'FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3,
'90%');
1325 print $doleditor->Create(1);
1330 $parameters = array(
'objectsrc' => $objectsrc,
'colspan' =>
' colspan="3"',
'cols' =>
'3');
1331 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters,
$object, $action);
1332 print $hookmanager->resPrint;
1335 if (empty($reshook)) {
1336 print
$object->showOptionals($extrafields,
'create', $parameters);
1343 print $form->buttonsSaveCancel(
"Create");
1345 if (is_object($objectsrc)) {
1346 print
'<input type="hidden" name="origin" value="'.$objectsrc->element.
'">';
1347 print
'<input type="hidden" name="originid" value="'.$objectsrc->id.
'">';
1350 print
'<br>'.$langs->trans(
"Note").
': '.$langs->trans(
"OnlyLinesWithTypeServiceAreUsed");
1364 $result =
$object->fetch_lines();
1369 $nbofservices = count(
$object->lines);
1371 $author =
new User($db);
1372 $author->fetch(
$object->user_author_id);
1374 $commercial_signature =
new User($db);
1375 $commercial_signature->fetch(
$object->commercial_signature_id);
1377 $commercial_suivi =
new User($db);
1378 $commercial_suivi->fetch(
$object->commercial_suivi_id);
1385 print
dol_get_fiche_head($head, $hselected, $langs->trans(
"Contract"), -1,
'contract');
1388 if ($action ==
'delete') {
1390 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"DeleteAContract"), $langs->trans(
"ConfirmDeleteAContract"),
"confirm_delete",
'', 0, 1);
1391 } elseif ($action ==
'valid') {
1393 $ref = substr(
$object->ref, 1, 4);
1394 if ($ref ==
'PROV' && !empty($modCodeContract->code_auto)) {
1399 $text = $langs->trans(
'ConfirmValidateContract', $numref);
1400 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ValidateAContract"), $text,
"confirm_valid",
'', 0, 1);
1401 } elseif ($action ==
'close') {
1403 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"CloseAContract"), $langs->trans(
"ConfirmCloseContract"),
"confirm_close",
'', 0, 1);
1404 } elseif ($action ==
'activate') {
1405 $formquestion = array(
1406 array(
'type' =>
'date',
'name' =>
'd_start',
'label' => $langs->trans(
"DateServiceActivate"),
'value' =>
dol_now()),
1407 array(
'type' =>
'date',
'name' =>
'd_end',
'label' => $langs->trans(
"DateEndPlanned"), 0 =>
'', 1 =>
''),
1408 array(
'type' =>
'text',
'name' =>
'comment',
'label' => $langs->trans(
"Comment"),
'value' =>
'', 0 =>
'', 1 =>
'',
'class' =>
'minwidth300',
'moreattr' =>
'autofocus')
1410 $formconfirm = $form->formconfirm($_SERVER[
'PHP_SELF'].
"?id=".
$object->id, $langs->trans(
"ActivateAllOnContract"), $langs->trans(
"ConfirmActivateAllOnContract"),
"confirm_activate", $formquestion,
'yes', 1, 280);
1411 } elseif ($action ==
'clone') {
1412 $filter =
'(s.client:IN:1,2,3)';
1414 $formquestion = array(array(
'type' =>
'other',
'name' =>
'socid',
'label' => $langs->trans(
"SelectThirdParty"),
'value' => $form->select_company(
GETPOSTINT(
'socid'),
'socid', $filter)));
1415 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'ToClone'), $langs->trans(
'ConfirmCloneContract',
$object->ref),
'confirm_clone', $formquestion,
'yes', 1);
1416 } elseif ($action ==
'sign') {
1417 $text = $langs->trans(
'ConfirmSignContract');
1418 if (isModEnabled(
'notification')) {
1419 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1420 $notify =
new Notify($db);
1422 $text .= $notify->confirmMessage(
'CONTRACT_MODIFY',
$object->socid,
$object);
1427 'name' =>
'signed_status',
1428 'label' =>
'<span class="fieldrequired">'.$langs->trans(
'SignStatus').
'</span>',
1429 'values' =>
$object->getSignedStatusLocalisedArray()
1431 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'SignContract'), $text,
'confirm_sign', $formquestion, 0, 1);
1432 } elseif ($action ==
'unsign') {
1433 $text = $langs->trans(
'ConfirmUnsignContract');
1434 if (isModEnabled(
'notification')) {
1435 require_once DOL_DOCUMENT_ROOT.
'/core/class/notify.class.php';
1436 $notify =
new Notify($db);
1438 $text .= $notify->confirmMessage(
'CONTRACT_MODIFY',
$object->socid,
$object);
1440 $formconfirm = $form->formconfirm($_SERVER[
"PHP_SELF"].
'?id='.
$object->id, $langs->trans(
'UnsignContract'), $text,
'confirm_unsign',
'', 0, 1);
1445 $parameters = array(
1446 'formConfirm' => $formconfirm,
1451 $reshook = $hookmanager->executeHooks(
'formConfirm', $parameters,
$object, $action);
1452 if (empty($reshook)) {
1453 $formconfirm .= $hookmanager->resPrint;
1454 } elseif ($reshook > 0) {
1455 $formconfirm = $hookmanager->resPrint;
1463 if (
$object->status == $object::STATUS_DRAFT && $user->hasRight(
'contrat',
'creer')) {
1464 print
'<form action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'" method="POST">';
1465 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1466 print
'<input type="hidden" name="action" value="setremise">';
1467 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1472 $linkback =
'<a href="'.DOL_URL_ROOT.
'/contrat/list.php?restore_lastsearch_values=1'.(!empty($socid) ?
'&socid='.$socid :
'').
'">'.$langs->trans(
"BackToList").
'</a>';
1476 if (!empty($modCodeContract->code_auto)) {
1479 $morehtmlref .= $form->editfieldkey(
"",
'ref',
$object->ref,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'', 0, 3);
1480 $morehtmlref .= $form->editfieldval(
"",
'ref',
$object->ref,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'',
null,
'2');
1483 $morehtmlref .=
'<div class="refidno">';
1485 $morehtmlref .= $form->editfieldkey(
"RefCustomer",
'ref_customer',
$object->ref_customer,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'', 0, 1);
1486 $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');
1488 $morehtmlref .=
'<br>';
1489 $morehtmlref .= $form->editfieldkey(
"RefSupplier",
'ref_supplier',
$object->ref_supplier,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'', 0, 1);
1490 $morehtmlref .= $form->editfieldval(
"RefSupplier",
'ref_supplier',
$object->ref_supplier,
$object, $user->hasRight(
'contrat',
'creer'),
'string',
'',
null,
null,
'', 1,
'getFormatedSupplierRef');
1492 $morehtmlref .=
'<br>'.$object->thirdparty->getNomUrl(1);
1494 $morehtmlref .=
' <span class="otherlink valignmiddle">(<a href="'.DOL_URL_ROOT.
'/contrat/list.php?socid='.
$object->thirdparty->id.
'&search_name='.urlencode(
$object->thirdparty->name).
'">'.$langs->trans(
"OtherContracts").
'</a>)</span>';
1497 if (isModEnabled(
'project')) {
1498 $langs->load(
"projects");
1499 $morehtmlref .=
'<br>';
1500 if ($permissiontoadd) {
1501 $morehtmlref .=
img_picto($langs->trans(
"Project"),
'project',
'class="pictofixedwidth"');
1502 if ($action !=
'classify') {
1503 $morehtmlref .=
'<a class="editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?action=classify&token='.
newToken().
'&id='.
$object->id.
'">'.
img_edit($langs->transnoentitiesnoconv(
'SetProject')).
'</a> ';
1505 $morehtmlref .= $form->form_project($_SERVER[
'PHP_SELF'].
'?id='.
$object->id,
$object->socid, (
string)
$object->fk_project, ($action ==
'classify' ?
'projectid' :
'none'), 0, 0, 0, 1,
'',
'maxwidth300');
1507 if (!empty(
$object->fk_project)) {
1509 $proj->fetch(
$object->fk_project);
1510 $morehtmlref .= $proj->getNomUrl(1);
1512 $morehtmlref .=
'<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).
'</span>';
1517 $morehtmlref .=
'</div>';
1520 dol_banner_tab(
$object,
'ref', $linkback, 1,
'ref',
'none', $morehtmlref);
1523 print
'<div class="fichecenter">';
1524 print
'<div class="underbanner clearboth"></div>';
1527 print
'<table class="border tableforfield" width="100%">';
1530 print
'<tr><td class="titlefield">'.$langs->trans(
'Discount').
'</td><td colspan="3">';
1531 if (
$object->thirdparty->remise_percent) {
1532 print $langs->trans(
"CompanyHasRelativeDiscount",
$object->thirdparty->remise_percent).
'. ';
1534 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoRelativeDiscount").
'. </span>';
1536 $absolute_discount =
$object->thirdparty->getAvailableDiscounts();
1537 if ($absolute_discount) {
1538 print $langs->trans(
"CompanyHasAbsoluteDiscount",
price($absolute_discount), $langs->trans(
"Currency".$conf->currency)).
'.';
1540 print
'<span class="hideonsmartphone">'.$langs->trans(
"CompanyHasNoAbsoluteDiscount").
'.</span>';
1546 print
'<td class="titlefield">';
1547 print $form->editfieldkey(
"Date",
'date_contrat',
$object->date_contrat,
$object, $user->hasRight(
'contrat',
'creer'));
1549 print $form->editfieldval(
"Date",
'date_contrat',
$object->date_contrat,
$object, $user->hasRight(
'contrat',
'creer'),
'datehourpicker');
1554 include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
1560 if (
$object->status == $object::STATUS_DRAFT && $user->hasRight(
'contrat',
'creer')) {
1567 $blocname =
'contacts';
1568 $title = $langs->trans(
'ContactsAddresses');
1569 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1573 $blocname =
'notes';
1574 $title = $langs->trans(
'Notes');
1575 include DOL_DOCUMENT_ROOT.
'/core/tpl/bloc_showhide.tpl.php';
1579 $arrayothercontracts =
$object->getListOfContracts(
'others');
1587 global $inputalsopricewithtax;
1588 $inputalsopricewithtax = 1;
1590 $productstatic =
new Product($db);
1593 if (isModEnabled(
'margin') && !empty(
$object->element) && in_array(
$object->element, array(
'facture',
'propal',
'commande'))) {
1597 $parameters = array(
'nbOfLines' => &$nbofservices);
1598 $reshook = $hookmanager->executeHooks(
'printObjectLinesBlock', $parameters,
$object, $action);
1599 if (empty($reshook)) {
1603 print
'<div id="contrat-lines-container" id="contractlines" data-contractid="'.$object->id.
'" data-element="'.
$object->element.
'" >';
1604 while ($cursorline <= $nbofservices) {
1605 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.
'" >';
1606 print
'<form name="update" id="addproduct" action="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'" method="post">';
1607 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1608 print
'<input type="hidden" name="action" value="updateline">';
1609 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
1610 print
'<input type="hidden" name="elrowid" value="'.$object->lines[$cursorline - 1]->id.
'">';
1611 print
'<input type="hidden" name="fournprice" value="'.(!empty(
$object->lines[$cursorline - 1]->fk_fournprice) ?
$object->lines[$cursorline - 1]->fk_fournprice : 0).
'">';
1614 print
'<div class="div-table-responsive-no-min">';
1615 print
'<table class="notopnoleftnoright allwidth tableforservicepart1 centpercent">';
1617 $sql =
"SELECT cd.rowid, cd.statut, cd.label as label_det, cd.fk_product, cd.product_type, cd.description, cd.qty,";
1618 $sql .=
" cd.tva_tx, cd.vat_src_code, cd.remise_percent, cd.info_bits, cd.subprice, cd.multicurrency_subprice,";
1619 $sql .=
" cd.date_ouverture_prevue as date_start, cd.date_ouverture as date_start_real,";
1620 $sql .=
" cd.date_fin_validite as date_end, cd.date_cloture as date_end_real,";
1621 $sql .=
" cd.commentaire as comment, cd.fk_product_fournisseur_price as fk_fournprice, cd.buy_price_ht as pa_ht,";
1622 $sql .=
" cd.fk_unit,";
1623 $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";
1624 $sql .=
" ,cd.rang";
1625 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
1626 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON cd.fk_product = p.rowid";
1627 $sql .=
" WHERE cd.rowid = ".((int)
$object->lines[$cursorline - 1]->id);
1629 $result = $db->query($sql);
1634 $objp = $db->fetch_object($result);
1637 print
'<tr class="liste_titre'.($cursorline ?
' liste_titre_add' :
'').
'">';
1638 print
'<td>'.$langs->trans(
"ServiceNb", $cursorline).
'</td>';
1639 print
'<td width="80" class="center">'.$langs->trans(
"VAT").
'</td>';
1640 print
'<td width="80" class="right">'.$langs->trans(
"PriceUHT").
'</td>';
1644 print
'<td width="30" class="center">'.$langs->trans(
"Qty").
'</td>';
1646 print
'<td width="30" class="left">'.$langs->trans(
"Unit").
'</td>';
1648 print
'<td width="50" class="right">'.$langs->trans(
"ReductionShort").
'</td>';
1650 print
'<td width="50" class="right">'.$langs->trans(
"BuyingPrice").
'</td>';
1654 if ($nbofservices > 1 &&
$conf->browser->layout !=
'phone' && $user->hasRight(
'contrat',
'creer')) {
1655 print
'<td width="30" class="linecolmove tdlineupdown center">';
1656 if ($cursorline > 1) {
1657 print
'<a class="lineupdown reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=up&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1658 echo
img_up(
'default', 0,
'imgupforline');
1661 if ($cursorline < $nbofservices) {
1662 print
'<a class="lineupdown reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=down&token='.
newToken().
'&rowid='.$objp->rowid.
'">';
1663 echo
img_down(
'default', 0,
'imgdownforline');
1668 print
'<td width="30"> </td>';
1676 if ($action !=
'editline' || $idline != $objp->rowid) {
1678 if (
getDolGlobalString(
'CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') && $objp->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1679 $moreparam =
'style="display: none;"';
1683 $line->id = $objp->rowid;
1687 print
'<tr class="tdtop oddeven" '.$moreparam.
'>';
1690 print
'<td class="linecoldescription minwidth300imp">';
1692 print
'<div id="line_'.$line->rowid.
'"></div>';
1693 if ($objp->fk_product > 0) {
1694 $productstatic->id = $objp->fk_product;
1695 $productstatic->type = $objp->ptype;
1696 $productstatic->ref = $objp->pref;
1697 $productstatic->entity = $objp->pentity;
1698 $productstatic->label = $objp->plabel;
1699 $productstatic->status = $objp->tosell;
1700 $productstatic->status_buy = $objp->tobuy;
1701 $productstatic->status_batch = $objp->tobatch;
1703 $text = $productstatic->getNomUrl(1,
'', 32);
1704 if ($objp->plabel) {
1706 $text .= $objp->plabel;
1708 $description = $objp->description;
1711 print (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
'') . $text;
1713 print $form->textwithpicto(
'', $description);
1716 print $form->textwithtooltip($text, $description, 3, 0,
'',
'', 0, (!empty($line->fk_parent_line) ?
img_picto(
'',
'rightarrow') :
''));
1720 if ($line->fk_product > 0 &&
getDolGlobalInt(
'PRODUIT_DESC_IN_FORM_ACCORDING_TO_DEVICE')) {
1721 print (!empty($line->description) && $line->description != $line->plabel) ? (($line->date_start || $line->date_end) ?
'' :
'<br>').
'<br>'.
dol_htmlentitiesbr($line->
description) :
'';
1729 print
'<td class="center">';
1730 print
vatrate($objp->tva_tx.($objp->vat_src_code ? (
' ('.$objp->vat_src_code.
')') :
''), true, $objp->info_bits);
1733 print
'<td class="right">'.($objp->subprice !=
'' ?
price($objp->subprice) :
'').
"</td>\n";
1739 print
'<td class="center">'.$objp->qty.
'</td>';
1742 print
'<td class="left">'.$object->lines[$cursorline - 1]->getLabelOfUnit(
'long', $langs).
'</td>';
1745 if ($objp->remise_percent > 0) {
1746 print
'<td class="right">'.$objp->remise_percent.
"%</td>\n";
1748 print
'<td> </td>';
1753 print
'<td class="right nowraponall">'.price($objp->pa_ht).
'</td>';
1757 print
'<td class="nowraponall right">';
1758 if ($user->hasRight(
'contrat',
'creer') && is_array($arrayothercontracts) && count($arrayothercontracts) && (
$object->status >= 0)) {
1759 print
'<!-- link to move service line into another contract -->';
1760 print
'<a class="reposition marginrightonly" style="padding-left: 5px;" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=move&token='.
newToken().
'&elrowid='.$objp->rowid.
'">';
1761 print
img_picto($langs->trans(
"MoveToAnotherContract"),
'uparrow');
1764 if ($user->hasRight(
'contrat',
'creer') && (
$object->statut >= 0)) {
1765 print
'<a class="reposition marginrightonly editfielda" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=editline&token='.
newToken().
'&elrowid='.$objp->rowid.
'">';
1769 if ($user->hasRight(
'contrat',
'creer') && (
$object->statut >= 0)) {
1770 print
'<a class="reposition marginrightonly" href="'.$_SERVER[
'PHP_SELF'].
'?id='.
$object->id.
'&action=deleteline&token='.
newToken().
'&elrowid='.$objp->rowid.
'">';
1787 if ($objp->subprice >= 0) {
1788 print
'<tr class="oddeven" '.$moreparam.
'>';
1789 print
'<td colspan="'.$colspan.
'">';
1792 print $langs->trans(
"DateStartPlanned").
': ';
1793 if ($objp->date_start) {
1796 if ($objp->statut == 0 && $db->jdate($objp->date_start) < ($now -
$conf->contrat->services->inactifs->warning_delay)) {
1797 $warning_delay =
$conf->contrat->services->inactifs->warning_delay / 3600 / 24;
1798 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1799 print
" ".img_warning($textlate);
1802 print $langs->trans(
"Unknown");
1804 print
' - ';
1805 print $langs->trans(
"DateEndPlanned").
': ';
1806 if ($objp->date_end) {
1808 if ($objp->statut == 4 && $db->jdate($objp->date_end) < ($now -
$conf->contrat->services->expires->warning_delay)) {
1809 $warning_delay =
$conf->contrat->services->expires->warning_delay / 3600 / 24;
1810 $textlate = $langs->trans(
"Late").
' = '.$langs->trans(
"DateReference").
' > '.$langs->trans(
"DateToday").
' '.(ceil($warning_delay) >= 0 ?
'+' :
'').ceil($warning_delay).
' '.$langs->trans(
"days");
1811 print
" ".img_warning($textlate);
1814 print $langs->trans(
"Unknown");
1822 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1824 $line->id = $objp->rowid;
1825 $line->fetch_optionals();
1826 print $line->showOptionals($extrafields,
'view', array(
'class' =>
'oddeven',
'style' => $moreparam,
'colspan' => $colspan,
'tdclass' =>
'notitlefieldcreate'),
'',
'',
'1');
1831 print
'<tr class="oddeven">';
1833 $currentLineProductId = GETPOSTISSET(
'idprod') ?
GETPOST(
'idprod') : (!empty(
$object->lines[$cursorline - 1]->fk_product) ?
$object->lines[$cursorline - 1]->fk_product : 0);
1834 if ($objp->fk_product > 0) {
1835 $canchangeproduct = 1;
1838 if (empty($canchangeproduct)) {
1839 $productstatic->id = $objp->fk_product;
1840 $productstatic->type = $objp->ptype;
1841 $productstatic->ref = $objp->pref;
1842 $productstatic->entity = $objp->pentity;
1843 print $productstatic->getNomUrl(1,
'', 32);
1844 print $objp->label ?
' - '.dol_trunc($objp->label, 32) :
'';
1845 print
'<input type="hidden" name="idprod" value="'.$currentLineProductId.
'">';
1847 $senderissupplier = 0;
1848 if (empty($senderissupplier)) {
1854 print $form->select_produits($currentLineProductId,
'idprod', $filtertype, 0, 0, 1, 2,
'', 0, array(), 0, 1, 0,
'minwidth250onall maxwidth500 widthcentpercentminusx');
1856 $form->select_produits_fournisseurs($currentLineProductId,
'idprod');
1861 print $objp->label ? $objp->label.
'<br>' :
'';
1862 print
'<input type="hidden" name="idprod" value="'.$currentLineProductId.
'">';
1866 require_once DOL_DOCUMENT_ROOT.
'/core/class/doleditor.class.php';
1871 $doleditor =
new DolEditor(
'product_desc', (GETPOSTISSET(
'product_desc') ?
GETPOST(
'product_desc') : $objp->
description),
'', 92,
'dolibarr_details',
'', false, true,
getDolGlobalInt(
'FCKEDITOR_ENABLE_DETAILS'), $nbrows,
'90%');
1872 $doleditor->Create();
1877 print
'<td class="right">';
1878 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, false, 1);
1882 print
'<td class="right"><input class="width50" type="text" name="elprice" value="'.(GETPOSTISSET(
'elprice') ?
GETPOST(
'elprice') :
price($objp->subprice)).
'"></td>';
1890 print
'<td class="center"><input size="2" type="text" name="elqty" value="'.(GETPOSTISSET(
'elqty') ?
GETPOST(
'elqty') : $objp->qty).
'"></td>';
1894 print
'<td class="left">';
1895 print $form->selectUnits((GETPOSTISSET(
'unit') ?
GETPOSTINT(
'unit') : $objp->fk_unit),
"unit");
1900 print
'<td class="nowraponall right"><input size="1" type="text" name="elremise_percent" value="'.(GETPOSTISSET(
'elremise_percent') ?
GETPOST(
'elremise_percent') : $objp->remise_percent).
'">%</td>';
1902 if (!empty($usemargins)) {
1903 print
'<td class="right">';
1904 if ($objp->fk_product) {
1905 print
'<select id="fournprice" name="fournprice"></select>';
1907 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>';
1909 print
'<td class="center">';
1910 print
'<input type="submit" class="button margintoponly marginbottomonly" name="save" value="'.$langs->trans(
"Modify").
'">';
1911 print
'<br><input type="submit" class="button margintoponly marginbottomonly button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
1924 print
'<tr class="oddeven">';
1925 print
'<td colspan="'.$colspan.
'">';
1926 print $langs->trans(
"DateStartPlanned").
' ';
1927 print $form->selectDate($db->jdate($objp->date_start),
"date_start_update", $usehm, $usehm, ($db->jdate($objp->date_start) > 0 ? 0 : 1),
"update");
1928 print
' '.$langs->trans(
"DateEndPlanned").
' ';
1929 print $form->selectDate($db->jdate($objp->date_end),
"date_end_update", $usehm, $usehm, ($db->jdate($objp->date_end) > 0 ? 0 : 1),
"update");
1933 if (is_array($extralabelslines) && count($extralabelslines) > 0) {
1935 $line->id = $objp->rowid;
1936 $line->fetch_optionals();
1938 print $line->showOptionals($extrafields,
'edit', array(
'style' =>
'class="oddeven"',
'colspan' => $colspan,
'tdclass' =>
'notitlefieldcreate'),
'',
'',
'1');
1949 if (
getDolGlobalString(
'CONTRACT_HIDE_CLOSED_SERVICES_BY_DEFAULT') &&
$object->lines[$cursorline - 1]->statut == ContratLigne::STATUS_CLOSED && $action !=
'showclosedlines') {
1950 $moreparam =
'style="display: none;"';
1961 print
'<tr class="oddeven" '.$moreparam.
'>';
1962 print
'<td class="tdhrthin" colspan="'.$colspan.
'"><hr class="opacitymedium tdhrthin"></td>';
1975 if ($action ==
'deleteline' && !$cancel && $user->hasRight(
'contrat',
'creer') &&
$object->lines[$cursorline - 1]->id == $idline) {
1976 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".((
int)
$object->id).
"&lineid=".((
int) $idline), $langs->trans(
"DeleteContractLine"), $langs->trans(
"ConfirmDeleteContractLine"),
"confirm_deleteline",
'', 0, 1);
1977 if ($ret ==
'html') {
1978 print
'<table class="notopnoleftnoright centpercent"><tr class="oddeven" height="6"><td></td></tr></table>';
1985 if ($action ==
'move' && !$cancel && $user->hasRight(
'contrat',
'creer') &&
$object->lines[$cursorline - 1]->id == $idline) {
1986 $arraycontractid = array();
1987 foreach ($arrayothercontracts as $contractcursor) {
1988 $arraycontractid[$contractcursor->id] = $contractcursor->ref;
1992 $formquestion = array(
1993 'text' => $langs->trans(
"ConfirmMoveToAnotherContractQuestion"),
1994 0 => array(
'type' =>
'select',
'name' =>
'newcid',
'values' => $arraycontractid));
1996 print $form->formconfirm($_SERVER[
"PHP_SELF"].
"?id=".((
int)
$object->id).
"&lineid=".((
int) $idline), $langs->trans(
"MoveToAnotherContract"), $langs->trans(
"ConfirmMoveToAnotherContract"),
"confirm_move", $formquestion,
'yes');
1997 print
'<table class="notopnoleftnoright centpercent"><tr class="oddeven" height="6"><td></td></tr></table>';
2002 print
'<table class="notopnoleftnoright tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
2004 print
'<tr class="oddeven" '.$moreparam.
'>';
2005 print
'<td><span class="valignmiddle hideonsmartphone">'.$langs->trans(
"ServiceStatus").
':</span> '.
$object->lines[$cursorline - 1]->getLibStatut(4).
'</td>';
2006 print
'<td width="30" class="right">';
2007 if ($user->socid == 0) {
2008 if (
$object->status > 0 && $action !=
'activateline' && $action !=
'unactivateline' && is_object($objp)) {
2009 $tmpaction =
'activateline';
2010 $tmpactionpicto =
'play';
2011 $tmpactiontext = $langs->trans(
"Activate");
2012 if ($objp->statut == 4) {
2013 $tmpaction =
'unactivateline';
2014 $tmpactionpicto =
'playstop';
2015 $tmpactiontext = $langs->trans(
"Disable");
2017 if (($tmpaction ==
'activateline' && $user->hasRight(
'contrat',
'activer')) || ($tmpaction ==
'unactivateline' && $user->hasRight(
'contrat',
'desactiver'))) {
2018 print
'<a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&ligne='.
$object->lines[$cursorline - 1]->id.
'&action='.$tmpaction.
'&token='.
newToken().
'">';
2019 print
img_picto($tmpactiontext, $tmpactionpicto);
2027 print
'<tr class="oddeven" '.$moreparam.
'>';
2031 if (!$objp->date_start_real) {
2032 print $langs->trans(
"DateStartReal").
': ';
2033 if ($objp->date_start_real) {
2036 print $langs->trans(
"ContractStatusNotRunning");
2040 if ($objp->date_start_real && !$objp->date_end_real) {
2041 print $langs->trans(
"DateStartReal").
': ';
2045 if ($objp->date_start_real && $objp->date_end_real) {
2046 print $langs->trans(
"DateStartReal").
': ';
2048 print
' - ';
2049 print $langs->trans(
"DateEndReal").
': ';
2052 if (!empty($objp->comment)) {
2053 print
" - ".$objp->comment;
2057 print
'<td class="center"> </td>';
2064 if ($permissiontoactivate && $action ==
'activateline' &&
$object->lines[$cursorline - 1]->id ==
GETPOSTINT(
'ligne') && is_object($objp)) {
2065 print
'<form name="active" action="'.$_SERVER[
"PHP_SELF"].
'" method="POST">';
2066 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2067 print
'<input type="hidden" name="action" value="confirm_active">';
2068 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2069 print
'<input type="hidden" name="id" value="'.$object->id.
'">';
2070 print
'<input type="hidden" name="ligne" value="'.GETPOSTINT(
'ligne').
'">';
2071 print
'<input type="hidden" name="confirm" value="yes">';
2073 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
2076 $dateactstart = $objp->date_start;
2079 } elseif (!$dateactstart) {
2080 $dateactstart = time();
2083 $dateactend = $objp->date_end;
2086 } elseif (!$dateactend) {
2087 if ($objp->fk_product > 0) {
2089 $product->fetch($objp->fk_product);
2090 if (!empty($product->duration_value) && !empty($product->duration_unit)) {
2091 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2096 print
'<tr class="oddeven">';
2097 print
'<td class="nohover">'.$langs->trans(
"DateServiceActivate").
'</td><td class="nohover">';
2098 print $form->selectDate($dateactstart,
'start', $usehm, $usehm, 0,
"active", 1, 0);
2100 print
'<td class="nohover">'.$langs->trans(
"DateEndPlanned").
'</td><td class="nohover">';
2101 print $form->selectDate($dateactend,
"end", $usehm, $usehm, 0,
"active", 1, 0);
2103 print
'<td class="center nohover">';
2108 print
'<tr class="oddeven">';
2109 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>';
2110 print
'<td class="nohover right">';
2111 print
'<input type="submit" class="button" name="activate" value="'.$langs->trans(
"Activate").
'"> ';
2112 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2122 if ($permissiontodisable && $action ==
'unactivateline' &&
$object->lines[$cursorline - 1]->id ==
GETPOSTINT(
'ligne') && is_object($objp)) {
2123 print
'<!-- Form to disabled a line -->'.
"\n";
2124 print
'<form name="confirm_closeline" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&ligne='.
$object->lines[$cursorline - 1]->id.
'" method="post">';
2125 print
'<input type="hidden" name="token" value="'.newToken().
'">';
2126 print
'<input type="hidden" name="confirm" value="yes">';
2127 print
'<input type="hidden" name="action" value="confirm_closeline">';
2128 print
'<input type="hidden" name="backtopage" value="'.$backtopage.
'">';
2130 print
'<table class="noborder tableforservicepart2'.($cursorline < $nbofservices ?
' boxtablenobottom' :
'').
' centpercent">';
2133 $dateactstart = $objp->date_start_real;
2136 } elseif (!$dateactstart) {
2137 $dateactstart = time();
2140 $dateactend = $objp->date_end_real;
2143 } elseif (!$dateactend) {
2144 if ($objp->fk_product > 0) {
2146 $product->fetch($objp->fk_product);
2147 $dateactend =
dol_time_plus_duree(time(), $product->duration_value, $product->duration_unit);
2151 if ($dateactend > $now) {
2155 print
'<tr class="oddeven"><td colspan="2" class="nohover">';
2156 if ($objp->statut >= 4) {
2157 if ($objp->statut == 4) {
2158 print $langs->trans(
"DateEndReal").
' ';
2159 print $form->selectDate($dateactend,
"end", $usehm, $usehm, ($objp->date_end_real > 0 ? 0 : 1),
"closeline", 1, 1);
2163 print
'<td class="center nohover">';
2166 print
'<tr class="oddeven">';
2167 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>';
2168 print
'<td class="nohover right">';
2169 print
'<input type="submit" class="button" name="close" value="'.$langs->trans(
"Disable").
'"> ';
2170 print
'<input type="submit" class="button button-cancel" name="cancel" value="'.$langs->trans(
"Cancel").
'">';
2185 if ($user->hasRight(
'contrat',
'creer') && (
$object->status == 0)) {
2189 print
' <form name="addproduct" id="addproduct" action="'.$_SERVER[
"PHP_SELF"].
'?id='.
$object->id.(($action !=
'editline') ?
'' :
'#line_'.
GETPOSTINT(
'lineid')).
'" method="POST">
2190 <input type="hidden" name="token" value="'.
newToken().
'">
2191 <input type="hidden" name="action" value="'.(($action !=
'editline') ?
'addline' :
'updateline').
'">
2192 <input type="hidden" name="mode" value="">
2193 <input type="hidden" name="id" value="'.
$object->id.
'">
2194 <input type="hidden" name="page_y" value="">
2195 <input type="hidden" name="backtopage" value="'.$backtopage.
'">
2198 print
'<div class="div-table-responsive-no-min">';
2199 print
'<table id="tablelines" class="noborder noshadow" width="100%">';
2202 if ($action !=
'editline') {
2203 $forcetoshowtitlelines = 1;
2204 if (empty(
$object->multicurrency_code)) {
2210 $parameters = array();
2211 $reshook = $hookmanager->executeHooks(
'formAddObjectLine', $parameters,
$object, $action);
2215 if (empty($reshook)) {
2216 $object->formAddObjectLine(1, $mysoc, $soc);
2228 if (
GETPOST(
'modelselected')) {
2229 $action =
'presend';
2235 if ($user->socid == 0 && $action !=
'presend' && $action !=
'editline') {
2236 print
'<div class="tabsAction">';
2238 $parameters = array();
2239 $reshook = $hookmanager->executeHooks(
'addMoreActionsButtons', $parameters,
$object, $action);
2241 if (empty($reshook)) {
2245 'class' =>
'classfortooltip'
2250 if (empty($user->socid)) {
2251 if (
$object->status == $object::STATUS_VALIDATED) {
2252 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || $user->hasRight(
'contrat',
'creer'))) {
2253 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=presend&token='.
newToken().
'&mode=init#formmailbeforetitle',
'',
true, $params);
2255 print
dolGetButtonAction(
'', $langs->trans(
'SendMail'),
'default',
'#',
'',
false, $params);
2260 if (
$object->status == $object::STATUS_DRAFT && $nbofservices) {
2261 if ($user->hasRight(
'contrat',
'creer')) {
2262 unset($params[
'attr'][
'title']);
2263 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=valid&token='.
newToken(),
'',
true, $params);
2265 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2266 print
dolGetButtonAction($langs->trans(
'Validate'),
'',
'default',
'#',
'',
false, $params);
2269 if (
$object->status == $object::STATUS_VALIDATED) {
2270 if ($user->hasRight(
'contrat',
'creer')) {
2271 unset($params[
'attr'][
'title']);
2272 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=reopen&token='.
newToken(),
'',
true, $params);
2274 $params[
'attr'][
'title'] = $langs->trans(
"NotEnoughPermissions");
2275 print
dolGetButtonAction($langs->trans(
'Modify'),
'',
'default',
'#',
'',
false, $params);
2280 $arrayofcreatebutton = array();
2281 if (isModEnabled(
'order') &&
$object->status > 0 &&
$object->nbofservicesclosed < $nbofservices) {
2282 $arrayofcreatebutton[] = array(
2283 'url' =>
'/commande/card.php?action=create&token='.
newToken().
'&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->thirdparty->id,
2284 'label' => $langs->trans(
'AddOrder'),
2286 'perm' => $user->hasRight(
'commande',
'creer') ?
true : false,
2290 if (isModEnabled(
'invoice') &&
$object->status > 0 && $soc->client > 0) {
2291 $arrayofcreatebutton[] = array(
2292 'url' =>
'/compta/facture/card.php?action=create&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->thirdparty->id,
2293 'label' => $langs->trans(
'CreateBill'),
2295 'perm' => $user->hasRight(
'facture',
'creer') ?
true : false,
2299 if (isModEnabled(
'supplier_invoice') &&
$object->status > 0 && $soc->fournisseur == 1) {
2300 $langs->load(
"suppliers");
2301 $arrayofcreatebutton[] = array(
2302 'url' =>
'/fourn/facture/card.php?action=create&origin='.
$object->element.
'&originid='.
$object->id.
'&socid='.
$object->thirdparty->id,
2303 'label' => $langs->trans(
'AddSupplierInvoice'),
2305 'perm' => $user->hasRight(
'fournisseur',
'facture',
'creer') ?
true : false,
2309 if (count($arrayofcreatebutton)) {
2310 unset($params[
'attr'][
'title']);
2311 print
dolGetButtonAction(
'', $langs->trans(
"Create"),
'default', $arrayofcreatebutton,
'',
true, $params);
2314 $arrayforbutaction = array();
2315 $arrayforbutaction[] = array(
2316 'url' =>
'/contrat/card.php?id='.
$object->id.
'&action=activate&token='.
newToken(),
2317 'label' => $langs->trans(
'ActivateAllContracts'),
2319 'perm' => (
$object->nbofservicesclosed > 0 ||
$object->nbofserviceswait > 0) ? $permissiontoactivate : -1,
2322 $arrayforbutaction[] = array(
2323 'url' =>
'/contrat/card.php?id='.
$object->id.
'&action=close&token='.
newToken(),
2324 'label' => $langs->trans(
'CloseAllContracts'),
2326 'perm' => (
$object->nbofservicesclosed < $nbofservices) ? $permissiontodisable : -1,
2330 if (count($arrayforbutaction)) {
2331 unset($params[
'attr'][
'title']);
2332 print
dolGetButtonAction(
'', $langs->trans(
"Services"),
'default', $arrayforbutaction,
'',
true, $params);
2336 if ($action ==
'showclosedlines') {
2337 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>';
2339 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>';
2344 if (
getDolGlobalString(
'CONTRACT_SHOW_SIGNATURE_STATUS_WITH_SERVICE_STATUS') &&
$object->status > Contrat::STATUS_DRAFT) {
2345 if (
$object->signed_status != Contrat::$SIGNED_STATUSES[
'STATUS_SIGNED_ALL']) {
2346 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>';
2348 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>';
2353 if ($user->hasRight(
'contrat',
'creer')) {
2354 unset($params[
'attr'][
'title']);
2359 unset($params[
'attr'][
'title']);
2360 print
dolGetButtonAction($langs->trans(
'Delete'),
'',
'delete', $_SERVER[
"PHP_SELF"].
'?id='.
$object->id.
'&action=delete&token='.
newToken(),
'', $permissiontodelete, $params);
2366 if ($action !=
'presend') {
2367 print
'<div class="fichecenter"><div class="fichehalfleft">';
2374 $urlsource = $_SERVER[
"PHP_SELF"].
"?id=".
$object->id;
2375 $genallowed = $user->hasRight(
'contrat',
'lire');
2376 $delallowed = $user->hasRight(
'contrat',
'creer');
2379 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);
2383 $tmparray = $form->showLinkToObjectBlock(
$object, array(), array(
'contrat'), 1);
2384 $linktoelem = $tmparray[
'linktoelem'];
2385 $htmltoenteralink = $tmparray[
'htmltoenteralink'];
2386 print $htmltoenteralink;
2388 $somethingshown = $form->showLinkedObjectBlock(
$object, $linktoelem);
2392 print
'<br><!-- Link to sign -->';
2393 require_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
2395 print showOnlineSignatureUrl(
'contract',
$object->ref,
$object).
'<br>';
2398 print
'</div><div class="fichehalfright">';
2402 $morehtmlcenter =
'<div class="nowraponall">';
2403 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'FullConversation'),
'',
'fa fa-comments imgforviewmode', DOL_URL_ROOT.
'/contrat/messaging.php?id='.
$object->id);
2404 $morehtmlcenter .=
dolGetButtonTitle($langs->trans(
'SeeAll'),
'',
'fa fa-bars imgforviewmode', DOL_URL_ROOT.
'/contrat/agenda.php?id='.
$object->id);
2405 $morehtmlcenter .=
'</div>';
2409 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formactions.class.php';
2411 $somethingshown = $formactions->showactions(
$object,
'contract', $socid, 1,
'listactions', $MAXEVENT,
'', $morehtmlcenter);
2413 print
'</div></div>';
2417 $modelmail =
'contract';
2418 $defaulttopic =
'SendContractRef';
2419 $diroutput =
$conf->contrat->multidir_output[
$object->entity];
2420 $trackid =
'con'.$object->id;
2422 include DOL_DOCUMENT_ROOT.
'/core/tpl/card_presend.tpl.php';
2433if (isModEnabled(
'margin') && $action ==
'editline') {
2434 print
"\n".
'<script type="text/javascript">'.
"\n";
2436 $(document).ready(
function() {
2437 var idprod = $(
"input[name='idprod']").val();
2438 var fournprice = $(
"input[name='fournprice']").val();
2439 var token =
'<?php echo currentToken(); ?>';
2441 $.post(
'<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {
2445 if (data.length > 0) {
2448 $(data).each(
function() {
2449 options +=
'<option value="'+this.
id+
'" price="'+this.
price+
'"';
2450 if (fournprice > 0) {
2451 if (this.
id == fournprice) {
2452 options +=
' selected';
2453 $(
"#buying_price").val(this.price);
2457 options +=
'>'+this.label+
'</option>';
2459 options +=
'<option value=null'+(trouve?
'':
' selected')+
'><?php echo $langs->trans("InputPrice"); ?></option>';
2460 $(
"#fournprice").html(options);
2462 $(
"#buying_price").hide();
2463 $(
"#fournprice").show();
2466 $(
"#buying_price").show();
2468 $(
"#fournprice").change(
function() {
2469 var selval = $(
this).find(
'option:selected').attr(
"price");
2471 $(
"#buying_price").val(selval).hide();
2473 $(
'#buying_price').show();
2477 $(
"#fournprice").hide();
2478 $(
'#buying_price').show();
2484 $(
"#fournprice").hide();
2485 $(
'#buying_price').show();
2489 print
"\n".
'<script type="text/javascript">'.
"\n";
$id
Support class for third parties, contacts, members, users or resources.
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, $morecssdiv='')
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_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.