card.php 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702
  1. <?php
  2. /* Copyright (C) 2002-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2020 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  7. * Copyright (C) 2014-2018 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 2014-2018 Charlene Benke <charlies@patas-monkey.com>
  9. * Copyright (C) 2015-2016 Abbes Bahfir <bafbes@gmail.com>
  10. * Copyright (C) 2018 Philippe Grand <philippe.grand@atoo-net.com>
  11. * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/fichinter/card.php
  28. * \brief Page of intervention
  29. * \ingroup ficheinter
  30. */
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/modules/fichinter/modules_fichinter.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  37. if (!empty($conf->projet->enabled)) {
  38. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
  40. }
  41. if ($conf->contrat->enabled) {
  42. require_once DOL_DOCUMENT_ROOT."/core/class/html.formcontract.class.php";
  43. require_once DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php";
  44. }
  45. if (!empty($conf->global->FICHEINTER_ADDON) && is_readable(DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.".php")) {
  46. require_once DOL_DOCUMENT_ROOT."/core/modules/fichinter/mod_".$conf->global->FICHEINTER_ADDON.'.php';
  47. }
  48. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  49. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  50. // Load translation files required by the page
  51. $langs->loadLangs(array('bills', 'companies', 'interventions', 'stocks'));
  52. $id = GETPOST('id', 'int');
  53. $ref = GETPOST('ref', 'alpha');
  54. $socid = (int) GETPOST('socid', 'int');
  55. $contratid = (int) GETPOST('contratid', 'int');
  56. $action = GETPOST('action', 'alpha');
  57. $cancel = GETPOST('cancel', 'alpha');
  58. $confirm = GETPOST('confirm', 'alpha');
  59. $mesg = GETPOST('msg', 'alpha');
  60. $origin = GETPOST('origin', 'alpha');
  61. $originid = (GETPOST('originid', 'int') ?GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility
  62. $note_public = GETPOST('note_public', 'restricthtml');
  63. $lineid = GETPOST('line_id', 'int');
  64. $error = 0;
  65. //PDF
  66. $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  67. $hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  68. $hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  69. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  70. $hookmanager->initHooks(array('interventioncard', 'globalcard'));
  71. $object = new Fichinter($db);
  72. $extrafields = new ExtraFields($db);
  73. $extrafields->fetch_name_optionals_label($object->table_element);
  74. // Load object
  75. if ($id > 0 || !empty($ref)) {
  76. $ret = $object->fetch($id, $ref);
  77. if ($ret > 0) {
  78. $ret = $object->fetch_thirdparty();
  79. }
  80. if ($ret < 0) {
  81. dol_print_error('', $object->error);
  82. }
  83. }
  84. // Security check
  85. if ($user->socid) {
  86. $socid = $user->socid;
  87. }
  88. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  89. $permissionnote = $user->rights->ficheinter->creer; // Used by the include of actions_setnotes.inc.php
  90. $permissiondellink = $user->rights->ficheinter->creer; // Used by the include of actions_dellink.inc.php
  91. /*
  92. * Actions
  93. */
  94. $parameters = array('socid'=>$socid);
  95. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  96. if ($reshook < 0) {
  97. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  98. }
  99. if (empty($reshook)) {
  100. $backurlforlist = DOL_URL_ROOT.'/fichinter/list.php';
  101. if (empty($backtopage) || ($cancel && empty($id))) {
  102. if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
  103. if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
  104. $backtopage = $backurlforlist;
  105. } else {
  106. $backtopage = DOL_URL_ROOT.'/fichinter/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
  107. }
  108. }
  109. }
  110. if ($cancel) {
  111. if (!empty($backtopageforcancel)) {
  112. header("Location: ".$backtopageforcancel);
  113. exit;
  114. } elseif (!empty($backtopage)) {
  115. header("Location: ".$backtopage);
  116. exit;
  117. }
  118. $action = '';
  119. }
  120. include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once
  121. include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once
  122. // Action clone object
  123. if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->ficheinter->creer) {
  124. if (1 == 0 && !GETPOST('clone_content') && !GETPOST('clone_receivers')) {
  125. setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
  126. } else {
  127. if ($object->id > 0) {
  128. // Because createFromClone modifies the object, we must clone it so that we can restore it later
  129. $orig = clone $object;
  130. $result = $object->createFromClone($user, $socid);
  131. if ($result > 0) {
  132. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  133. exit;
  134. } else {
  135. setEventMessages($object->error, $object->errors, 'errors');
  136. $object = $orig;
  137. $action = '';
  138. }
  139. }
  140. }
  141. }
  142. if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->ficheinter->creer) {
  143. $result = $object->setValid($user);
  144. if ($result >= 0) {
  145. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  146. // Define output language
  147. $outputlangs = $langs;
  148. $newlang = '';
  149. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  150. $newlang = GETPOST('lang_id', 'aZ09');
  151. }
  152. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  153. $newlang = $object->thirdparty->default_lang;
  154. }
  155. if (!empty($newlang)) {
  156. $outputlangs = new Translate("", $conf);
  157. $outputlangs->setDefaultLang($newlang);
  158. }
  159. $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
  160. }
  161. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  162. exit;
  163. } else {
  164. $mesg = $object->error;
  165. }
  166. } elseif ($action == 'confirm_modify' && $confirm == 'yes' && $user->rights->ficheinter->creer) {
  167. $result = $object->setDraft($user);
  168. if ($result >= 0) {
  169. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  170. // Define output language
  171. $outputlangs = $langs;
  172. $newlang = '';
  173. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  174. $newlang = GETPOST('lang_id', 'aZ09');
  175. }
  176. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  177. $newlang = $object->thirdparty->default_lang;
  178. }
  179. if (!empty($newlang)) {
  180. $outputlangs = new Translate("", $conf);
  181. $outputlangs->setDefaultLang($newlang);
  182. }
  183. $result = fichinter_create($db, $object, (!GETPOST('model', 'alpha')) ? $object->model_pdf : GETPOST('model', 'alpha'), $outputlangs);
  184. }
  185. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  186. exit;
  187. } else {
  188. $mesg = $object->error;
  189. }
  190. } elseif ($action == 'add' && $user->rights->ficheinter->creer) {
  191. $selectedLines = GETPOST('toselect', 'array');
  192. $object->socid = $socid;
  193. $object->duration = (int) GETPOST('duration', 'int');
  194. $object->fk_project = (int) GETPOST('projectid', 'int');
  195. $object->fk_contrat = (int) GETPOST('contratid', 'int');
  196. $object->author = $user->id;
  197. $object->description = GETPOST('description', 'restricthtml');
  198. $object->ref = $ref;
  199. $object->model_pdf = GETPOST('model', 'alpha');
  200. $object->note_private = GETPOST('note_private', 'restricthtml');
  201. $object->note_public = GETPOST('note_public', 'restricthtml');
  202. if ($object->socid > 0) {
  203. // If creation from another object of another module (Example: origin=propal, originid=1)
  204. if (!empty($origin) && !empty($originid)) {
  205. // Parse element/subelement (ex: project_task)
  206. $regs = array();
  207. $element = $subelement = GETPOST('origin', 'alphanohtml');
  208. if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
  209. $element = $regs[1];
  210. $subelement = $regs[2];
  211. }
  212. // For compatibility
  213. if ($element == 'order') {
  214. $element = $subelement = 'commande';
  215. }
  216. if ($element == 'propal') {
  217. $element = 'comm/propal'; $subelement = 'propal';
  218. }
  219. if ($element == 'contract') {
  220. $element = $subelement = 'contrat';
  221. }
  222. $object->origin = $origin;
  223. $object->origin_id = $originid;
  224. // Possibility to add external linked objects with hooks
  225. $object->linked_objects[$object->origin] = $object->origin_id;
  226. if (is_array($_POST['other_linked_objects']) && !empty($_POST['other_linked_objects'])) {
  227. $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
  228. }
  229. // Extrafields
  230. // Fill array 'array_options' with data from add form
  231. $ret = $extrafields->setOptionalsFromPost(null, $object);
  232. if ($ret < 0) {
  233. $error++;
  234. $action = 'create';
  235. }
  236. //$array_options = $extrafields->getOptionalsFromPost($object->table_element);
  237. //$object->array_options = $array_options;
  238. $id = $object->create($user);
  239. if ($id > 0) {
  240. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  241. $classname = ucfirst($subelement);
  242. $srcobject = new $classname($db);
  243. dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines");
  244. $result = $srcobject->fetch($object->origin_id);
  245. if ($result > 0) {
  246. $srcobject->fetch_thirdparty();
  247. $lines = $srcobject->lines;
  248. if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
  249. $srcobject->fetch_lines();
  250. $lines = $srcobject->lines;
  251. }
  252. if (is_array($lines)) {
  253. $num = count($lines);
  254. for ($i = 0; $i < $num; $i++) {
  255. if (!in_array($lines[$i]->id, $selectedLines)) {
  256. continue; // Skip unselected lines
  257. }
  258. $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : Product::TYPE_PRODUCT);
  259. if ($product_type == Product::TYPE_SERVICE || !empty($conf->global->FICHINTER_PRINT_PRODUCTS)) { //only services except if config includes products
  260. $duration = 3600; // Default to one hour
  261. // Predefined products & services
  262. if ($lines[$i]->fk_product > 0) {
  263. $prod = new Product($db);
  264. $prod->id = $lines[$i]->fk_product;
  265. // Define output language
  266. if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
  267. $prod->getMultiLangs();
  268. // We show if duration is present on service (so we get it)
  269. $prod->fetch($lines[$i]->fk_product);
  270. $outputlangs = $langs;
  271. $newlang = '';
  272. if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  273. $newlang = GETPOST('lang_id', 'aZ09');
  274. }
  275. if (empty($newlang)) {
  276. $newlang = $srcobject->thirdparty->default_lang;
  277. }
  278. if (!empty($newlang)) {
  279. $outputlangs = new Translate("", $conf);
  280. $outputlangs->setDefaultLang($newlang);
  281. }
  282. $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label;
  283. } else {
  284. $prod->fetch($lines[$i]->fk_product);
  285. $label = $lines[$i]->product_label;
  286. }
  287. if ($prod->duration_value && $conf->global->FICHINTER_USE_SERVICE_DURATION) {
  288. switch ($prod->duration_unit) {
  289. default:
  290. case 'h':
  291. $mult = 3600;
  292. break;
  293. case 'd':
  294. $mult = 3600 * 24;
  295. break;
  296. case 'w':
  297. $mult = 3600 * 24 * 7;
  298. break;
  299. case 'm':
  300. $mult = (int) 3600 * 24 * (365 / 12); // Average month duration
  301. break;
  302. case 'y':
  303. $mult = 3600 * 24 * 365;
  304. break;
  305. }
  306. $duration = $prod->duration_value * $mult * $lines[$i]->qty;
  307. }
  308. $desc = $lines[$i]->product_ref;
  309. $desc .= ' - ';
  310. $desc .= $label;
  311. $desc .= '<br>';
  312. }
  313. // Common part (predefined or free line)
  314. $desc .= dol_htmlentitiesbr($lines[$i]->desc);
  315. $desc .= '<br>';
  316. $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')';
  317. $timearray = dol_getdate(dol_now());
  318. $date_intervention = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
  319. if ($product_type == Product::TYPE_PRODUCT) {
  320. $duration = 0;
  321. }
  322. $predef = '';
  323. // Extrafields
  324. $extrafields->fetch_name_optionals_label($object->table_element_line);
  325. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
  326. $result = $object->addline(
  327. $user,
  328. $id,
  329. $desc,
  330. $date_intervention,
  331. $duration,
  332. $array_options
  333. );
  334. if ($result < 0) {
  335. $error++;
  336. break;
  337. }
  338. }
  339. }
  340. }
  341. } else {
  342. $mesg = $srcobject->error;
  343. $error++;
  344. }
  345. } else {
  346. $mesg = $object->error;
  347. $error++;
  348. }
  349. } else {
  350. // Fill array 'array_options' with data from add form
  351. $ret = $extrafields->setOptionalsFromPost(null, $object);
  352. if ($ret < 0) {
  353. $error++;
  354. $action = 'create';
  355. }
  356. if (!$error) {
  357. // Extrafields
  358. $array_options = $extrafields->getOptionalsFromPost($object->table_element);
  359. $object->array_options = $array_options;
  360. $result = $object->create($user);
  361. if ($result > 0) {
  362. $id = $result; // Force raffraichissement sur fiche venant d'etre cree
  363. } else {
  364. $langs->load("errors");
  365. setEventMessages($object->error, $object->errors, 'errors');
  366. $action = 'create';
  367. }
  368. }
  369. }
  370. } else {
  371. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty"));
  372. $action = 'create';
  373. }
  374. } elseif ($action == 'update' && $user->rights->ficheinter->creer) {
  375. $object->socid = $socid;
  376. $object->fk_project = (int) GETPOST('projectid', 'int');
  377. $object->fk_contrat = (int) GETPOST('contratid', 'int');
  378. $object->author = $user->id;
  379. $object->description = GETPOST('description', 'restricthtml');
  380. $object->ref = $ref;
  381. $result = $object->update($user);
  382. if ($result < 0) {
  383. setEventMessages($object->error, $object->errors, 'errors');
  384. }
  385. } elseif ($action == 'classin' && $user->rights->ficheinter->creer) {
  386. // Set into a project
  387. $result = $object->setProject(GETPOST('projectid', 'int'));
  388. if ($result < 0) {
  389. dol_print_error($db, $object->error);
  390. }
  391. } elseif ($action == 'setcontract' && $user->rights->contrat->creer) {
  392. // Set into a contract
  393. $result = $object->set_contrat($user, GETPOST('contratid', 'int'));
  394. if ($result < 0) {
  395. dol_print_error($db, $object->error);
  396. }
  397. } elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->ficheinter->supprimer) {
  398. $result = $object->delete($user);
  399. if ($result < 0) {
  400. setEventMessages($object->error, $object->errors, 'errors');
  401. }
  402. header('Location: '.DOL_URL_ROOT.'/fichinter/list.php?leftmenu=ficheinter&restore_lastsearch_values=1');
  403. exit;
  404. } elseif ($action == 'setdescription' && $user->rights->ficheinter->creer) {
  405. $result = $object->set_description($user, GETPOST('description'));
  406. if ($result < 0) {
  407. dol_print_error($db, $object->error);
  408. }
  409. } elseif ($action == "addline" && $user->rights->ficheinter->creer) {
  410. // Add line
  411. if (!GETPOST('np_desc', 'restricthtml') && empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) {
  412. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description"));
  413. $error++;
  414. }
  415. if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && !GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int')) {
  416. $mesg = $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Duration"));
  417. $error++;
  418. }
  419. if (empty($conf->global->FICHINTER_WITHOUT_DURATION) && GETPOST('durationhour', 'int') >= 24 && GETPOST('durationmin', 'int') > 0) {
  420. $mesg = $langs->trans("ErrorValueTooHigh");
  421. $error++;
  422. }
  423. if (!$error) {
  424. $db->begin();
  425. $desc = GETPOST('np_desc', 'restricthtml');
  426. $date_intervention = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
  427. $duration = empty($conf->global->FICHINTER_WITHOUT_DURATION) ? convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int')) : 0;
  428. // Extrafields
  429. $extrafields->fetch_name_optionals_label($object->table_element_line);
  430. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  431. $result = $object->addline(
  432. $user,
  433. $id,
  434. $desc,
  435. $date_intervention,
  436. $duration,
  437. $array_options
  438. );
  439. // Define output language
  440. $outputlangs = $langs;
  441. $newlang = '';
  442. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  443. $newlang = GETPOST('lang_id', 'aZ09');
  444. }
  445. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  446. $newlang = $object->thirdparty->default_lang;
  447. }
  448. if (!empty($newlang)) {
  449. $outputlangs = new Translate("", $conf);
  450. $outputlangs->setDefaultLang($newlang);
  451. }
  452. if ($result >= 0) {
  453. $db->commit();
  454. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  455. fichinter_create($db, $object, $object->model_pdf, $outputlangs);
  456. }
  457. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  458. exit;
  459. } else {
  460. $mesg = $object->error;
  461. $db->rollback();
  462. }
  463. }
  464. } elseif ($action == 'classifybilled' && $user->rights->ficheinter->creer) {
  465. // Classify Billed
  466. $result = $object->setStatut(Fichinter::STATUS_BILLED);
  467. if ($result > 0) {
  468. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  469. exit;
  470. } else {
  471. setEventMessages($object->error, $object->errors, 'errors');
  472. }
  473. } elseif ($action == 'classifyunbilled' && $user->rights->ficheinter->creer) {
  474. // Classify unbilled
  475. $result = $object->setStatut(Fichinter::STATUS_VALIDATED);
  476. if ($result > 0) {
  477. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  478. exit;
  479. } else {
  480. $mesg = $object->error;
  481. }
  482. } elseif ($action == 'classifydone' && $user->rights->ficheinter->creer) {
  483. // Classify Done
  484. $result = $object->setStatut(Fichinter::STATUS_CLOSED);
  485. if ($result > 0) {
  486. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  487. exit;
  488. } else {
  489. setEventMessages($object->error, $object->errors, 'errors');
  490. }
  491. } elseif ($action == 'confirm_reopen' && $user->rights->ficheinter->creer) {
  492. // Reopen
  493. $result = $object->setStatut(Fichinter::STATUS_VALIDATED);
  494. if ($result > 0) {
  495. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  496. exit;
  497. } else {
  498. $mesg = $object->error;
  499. }
  500. } elseif ($action == 'updateline' && $user->rights->ficheinter->creer && GETPOST('save', 'alpha') == $langs->trans("Save")) {
  501. // Mise a jour d'une ligne d'intervention
  502. $objectline = new FichinterLigne($db);
  503. if ($objectline->fetch($lineid) <= 0) {
  504. dol_print_error($db);
  505. exit;
  506. }
  507. if ($object->fetch($objectline->fk_fichinter) <= 0) {
  508. dol_print_error($db);
  509. exit;
  510. }
  511. $object->fetch_thirdparty();
  512. $desc = GETPOST('np_desc', 'restricthtml');
  513. $date_inter = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
  514. $duration = convertTime2Seconds(GETPOST('durationhour', 'int'), GETPOST('durationmin', 'int'));
  515. $objectline->datei = $date_inter;
  516. $objectline->desc = $desc;
  517. $objectline->duration = $duration;
  518. // Extrafields
  519. $extrafields->fetch_name_optionals_label($object->table_element_line);
  520. $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
  521. $objectline->array_options = $array_options;
  522. $result = $objectline->update($user);
  523. if ($result < 0) {
  524. dol_print_error($db);
  525. exit;
  526. }
  527. // Define output language
  528. $outputlangs = $langs;
  529. $newlang = '';
  530. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  531. $newlang = GETPOST('lang_id', 'aZ09');
  532. }
  533. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  534. $newlang = $object->thirdparty->default_lang;
  535. }
  536. if (!empty($newlang)) {
  537. $outputlangs = new Translate("", $conf);
  538. $outputlangs->setDefaultLang($newlang);
  539. }
  540. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  541. fichinter_create($db, $object, $object->model_pdf, $outputlangs);
  542. }
  543. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  544. exit;
  545. } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->ficheinter->creer) {
  546. // Supprime une ligne d'intervention AVEC confirmation
  547. $objectline = new FichinterLigne($db);
  548. if ($objectline->fetch($lineid) <= 0) {
  549. dol_print_error($db);
  550. exit;
  551. }
  552. $result = $objectline->deleteline($user);
  553. if ($object->fetch($objectline->fk_fichinter) <= 0) {
  554. dol_print_error($db);
  555. exit;
  556. }
  557. // Define output language
  558. $outputlangs = $langs;
  559. $newlang = '';
  560. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  561. $newlang = GETPOST('lang_id', 'aZ09');
  562. }
  563. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  564. $newlang = $object->thirdparty->default_lang;
  565. }
  566. if (!empty($newlang)) {
  567. $outputlangs = new Translate("", $conf);
  568. $outputlangs->setDefaultLang($newlang);
  569. }
  570. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  571. fichinter_create($db, $object, $object->model_pdf, $outputlangs);
  572. }
  573. } elseif ($action == 'up' && $user->rights->ficheinter->creer) {
  574. // Set position of lines
  575. $object->line_up($lineid);
  576. // Define output language
  577. $outputlangs = $langs;
  578. $newlang = '';
  579. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  580. $newlang = GETPOST('lang_id', 'aZ09');
  581. }
  582. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  583. $newlang = $object->thirdparty->default_lang;
  584. }
  585. if (!empty($newlang)) {
  586. $outputlangs = new Translate("", $conf);
  587. $outputlangs->setDefaultLang($newlang);
  588. }
  589. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  590. fichinter_create($db, $object, $object->model_pdf, $outputlangs);
  591. }
  592. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
  593. exit;
  594. } elseif ($action == 'down' && $user->rights->ficheinter->creer) {
  595. $object->line_down($lineid);
  596. // Define output language
  597. $outputlangs = $langs;
  598. $newlang = '';
  599. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
  600. $newlang = GETPOST('lang_id', 'aZ09');
  601. }
  602. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
  603. $newlang = $object->thirdparty->default_lang;
  604. }
  605. if (!empty($newlang)) {
  606. $outputlangs = new Translate("", $conf);
  607. $outputlangs->setDefaultLang($newlang);
  608. }
  609. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
  610. fichinter_create($db, $object, $object->model_pdf, $outputlangs);
  611. }
  612. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'#'.$lineid);
  613. exit;
  614. }
  615. // Actions when printing a doc from card
  616. include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
  617. // Actions to send emails
  618. $triggersendname = 'FICHINTER_SENTBYMAIL';
  619. $autocopy = 'MAIN_MAIL_AUTOCOPY_FICHINTER_TO';
  620. $trackid = 'int'.$object->id;
  621. include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
  622. // Actions to build doc
  623. $upload_dir = $conf->ficheinter->dir_output;
  624. $permissiontoadd = $user->rights->ficheinter->creer;
  625. include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
  626. if ($action == 'update_extras') {
  627. $object->oldcopy = dol_clone($object);
  628. // Fill array 'array_options' with data from update form
  629. $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
  630. if ($ret < 0) {
  631. $error++;
  632. }
  633. if (!$error) {
  634. // Actions on extra fields
  635. $result = $object->insertExtraFields('INTERVENTION_MODIFY');
  636. if ($result < 0) {
  637. $error++;
  638. }
  639. }
  640. if ($error) {
  641. $action = 'edit_extras';
  642. }
  643. }
  644. if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->ficheinter->creer) {
  645. if ($action == 'addcontact') {
  646. if ($result > 0 && $id > 0) {
  647. $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
  648. $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
  649. $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
  650. }
  651. if ($result >= 0) {
  652. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  653. exit;
  654. } else {
  655. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
  656. $langs->load("errors");
  657. $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
  658. } else {
  659. $mesg = $object->error;
  660. }
  661. }
  662. } elseif ($action == 'swapstatut') {
  663. // bascule du statut d'un contact
  664. $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
  665. } elseif ($action == 'deletecontact') {
  666. // Efface un contact
  667. $result = $object->delete_contact(GETPOST('lineid', 'int'));
  668. if ($result >= 0) {
  669. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  670. exit;
  671. } else {
  672. dol_print_error($db);
  673. }
  674. }
  675. }
  676. }
  677. /*
  678. * View
  679. */
  680. $form = new Form($db);
  681. $formfile = new FormFile($db);
  682. if ($conf->contrat->enabled) {
  683. $formcontract = new FormContract($db);
  684. }
  685. if (!empty($conf->projet->enabled)) {
  686. $formproject = new FormProjets($db);
  687. }
  688. $help_url = 'EN:Module_Interventions';
  689. llxHeader('', $langs->trans("Intervention"), $help_url);
  690. if ($action == 'create') {
  691. // Create new intervention
  692. $soc = new Societe($db);
  693. print load_fiche_titre($langs->trans("AddIntervention"), '', 'intervention');
  694. if ($error > 0) {
  695. dol_htmloutput_errors($mesg);
  696. } else {
  697. dol_htmloutput_mesg($mesg);
  698. }
  699. if ($socid) {
  700. $res = $soc->fetch($socid);
  701. }
  702. if (GETPOST('origin', 'alphanohtml') && GETPOST('originid', 'int')) {
  703. // Parse element/subelement (ex: project_task)
  704. $regs = array();
  705. $element = $subelement = GETPOST('origin', 'alphanohtml');
  706. if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin', 'alphanohtml'), $regs)) {
  707. $element = $regs[1];
  708. $subelement = $regs[2];
  709. }
  710. if ($element == 'project') {
  711. $projectid = GETPOST('originid', 'int');
  712. } else {
  713. // For compatibility
  714. if ($element == 'order' || $element == 'commande') {
  715. $element = $subelement = 'commande';
  716. }
  717. if ($element == 'propal') {
  718. $element = 'comm/propal'; $subelement = 'propal';
  719. }
  720. if ($element == 'contract') {
  721. $element = $subelement = 'contrat';
  722. }
  723. dol_include_once('/'.$element.'/class/'.$subelement.'.class.php');
  724. $classname = ucfirst($subelement);
  725. $objectsrc = new $classname($db);
  726. $objectsrc->fetch(GETPOST('originid'));
  727. if (empty($objectsrc->lines) && method_exists($objectsrc, 'fetch_lines')) {
  728. $objectsrc->fetch_lines();
  729. $lines = $objectsrc->lines;
  730. }
  731. $objectsrc->fetch_thirdparty();
  732. $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
  733. $soc = $objectsrc->thirdparty;
  734. $note_private = (!empty($objectsrc->note) ? $objectsrc->note : (!empty($objectsrc->note_private) ? $objectsrc->note_private : GETPOST('note_private', 'restricthtml')));
  735. $note_public = (!empty($objectsrc->note_public) ? $objectsrc->note_public : GETPOST('note_public', 'restricthtml'));
  736. // Replicate extrafields
  737. $objectsrc->fetch_optionals();
  738. $object->array_options = $objectsrc->array_options;
  739. // Object source contacts list
  740. $srccontactslist = $objectsrc->liste_contact(-1, 'external', 1);
  741. }
  742. } else {
  743. $projectid = GETPOST('projectid', 'int');
  744. }
  745. if (!$conf->global->FICHEINTER_ADDON) {
  746. dol_print_error($db, $langs->trans("Error")." ".$langs->trans("Error_FICHEINTER_ADDON_NotDefined"));
  747. exit;
  748. }
  749. $object->date = dol_now();
  750. $obj = $conf->global->FICHEINTER_ADDON;
  751. $obj = "mod_".$obj;
  752. //$modFicheinter = new $obj;
  753. //$numpr = $modFicheinter->getNextValue($soc, $object);
  754. if ($socid > 0) {
  755. $soc = new Societe($db);
  756. $soc->fetch($socid);
  757. print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  758. print '<input type="hidden" name="token" value="'.newToken().'">';
  759. print '<input type="hidden" name="socid" value='.$soc->id.'>';
  760. print '<input type="hidden" name="action" value="add">';
  761. print dol_get_fiche_head('');
  762. print '<table class="border centpercent">';
  763. print '<tr><td class="fieldrequired titlefieldcreate">'.$langs->trans("ThirdParty").'</td><td>'.$soc->getNomUrl(1).'</td></tr>';
  764. // Ref
  765. print '<tr><td class="fieldrequired">'.$langs->trans('Ref').'</td><td>'.$langs->trans("Draft").'</td></tr>';
  766. // Description (must be a textarea and not html must be allowed (used in list view)
  767. print '<tr><td class="tdtop">'.$langs->trans("Description").'</td>';
  768. print '<td>';
  769. print '<textarea name="description" class="quatrevingtpercent" rows="'.ROWS_3.'">'.GETPOST('description').'</textarea>';
  770. print '</td></tr>';
  771. // Project
  772. if (!empty($conf->projet->enabled)) {
  773. $formproject = new FormProjets($db);
  774. $langs->load("project");
  775. print '<tr><td>'.$langs->trans("Project").'</td><td>';
  776. /* Fix: If a project must be linked to any companies (suppliers or not), project must be not be set as limited to customer but must be not linked to any particular thirdparty
  777. if ($societe->fournisseur==1)
  778. $numprojet=select_projects(-1, GETPOST("projectid", 'int'), 'projectid');
  779. else
  780. $numprojet=select_projects($societe->id, GETPOST("projectid", 'int'), 'projectid');
  781. */
  782. $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid');
  783. if ($numprojet == 0) {
  784. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$soc->id.'&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddProject").'"></span></a>';
  785. }
  786. print '</td></tr>';
  787. }
  788. // Contract
  789. if ($conf->contrat->enabled) {
  790. $langs->load("contracts");
  791. print '<tr><td>'.$langs->trans("Contract").'</td><td>';
  792. $numcontrat = $formcontract->select_contract($soc->id, GETPOST('contratid', 'int'), 'contratid', 0, 1, 1);
  793. if ($numcontrat == 0) {
  794. print ' &nbsp; <a href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$soc->id.'&action=create"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddContract").'"></span></a>';
  795. }
  796. print '</td></tr>';
  797. }
  798. // Model
  799. print '<tr>';
  800. print '<td>'.$langs->trans("DefaultModel").'</td>';
  801. print '<td>';
  802. $liste = ModelePDFFicheinter::liste_modeles($db);
  803. print $form->selectarray('model', $liste, $conf->global->FICHEINTER_ADDON_PDF);
  804. print "</td></tr>";
  805. // Public note
  806. print '<tr>';
  807. print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
  808. print '<td>';
  809. $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
  810. print $doleditor->Create(1);
  811. //print '<textarea name="note_public" cols="80" rows="'.ROWS_3.'">'.$note_public.'</textarea>';
  812. print '</td></tr>';
  813. // Private note
  814. if (empty($user->socid)) {
  815. print '<tr>';
  816. print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
  817. print '<td>';
  818. $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
  819. print $doleditor->Create(1);
  820. //print '<textarea name="note_private" cols="80" rows="'.ROWS_3.'">'.$note_private.'</textarea>';
  821. print '</td></tr>';
  822. }
  823. // Other attributes
  824. $parameters = array();
  825. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  826. print $hookmanager->resPrint;
  827. if (empty($reshook)) {
  828. print $object->showOptionals($extrafields, 'create');
  829. }
  830. // Show link to origin object
  831. if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
  832. $newclassname = $classname;
  833. if ($newclassname == 'Propal') {
  834. $newclassname = 'CommercialProposal';
  835. }
  836. print '<tr><td>'.$langs->trans($newclassname).'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
  837. // Amount
  838. /* Hide amount because we only copy services so amount may differ than source
  839. print '<tr><td>' . $langs->trans('AmountHT') . '</td><td>' . price($objectsrc->total_ht) . '</td></tr>';
  840. print '<tr><td>' . $langs->trans('AmountVAT') . '</td><td>' . price($objectsrc->total_tva) . "</td></tr>";
  841. if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE
  842. {
  843. print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax1) . "</td></tr>";
  844. }
  845. if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF
  846. {
  847. print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td><td>' . price($objectsrc->total_localtax2) . "</td></tr>";
  848. }
  849. print '<tr><td>' . $langs->trans('AmountTTC') . '</td><td>' . price($objectsrc->total_ttc) . "</td></tr>";
  850. if (!empty($conf->multicurrency->enabled))
  851. {
  852. print '<tr><td>' . $langs->trans('MulticurrencyAmountHT') . '</td><td>' . price($objectsrc->multicurrency_total_ht) . '</td></tr>';
  853. print '<tr><td>' . $langs->trans('MulticurrencyAmountVAT') . '</td><td>' . price($objectsrc->multicurrency_total_tva) . "</td></tr>";
  854. print '<tr><td>' . $langs->trans('MulticurrencyAmountTTC') . '</td><td>' . price($objectsrc->multicurrency_total_ttc) . "</td></tr>";
  855. }
  856. */
  857. }
  858. print '</table>';
  859. if (is_object($objectsrc)) {
  860. print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
  861. print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
  862. } elseif ($origin == 'project' && !empty($projectid)) {
  863. print '<input type="hidden" name="projectid" value="'.$projectid.'">';
  864. }
  865. print dol_get_fiche_end();
  866. print $form->buttonsSaveCancel("CreateDraftIntervention");
  867. // Show origin lines
  868. if (!empty($origin) && !empty($originid) && is_object($objectsrc)) {
  869. $title = $langs->trans('Services');
  870. print load_fiche_titre($title);
  871. print '<table class="noborder centpercent">';
  872. $objectsrc->printOriginLinesList(empty($conf->global->FICHINTER_PRINT_PRODUCTS) ? 'services' : ''); // Show only service, except if option FICHINTER_PRINT_PRODUCTS is on
  873. print '</table>';
  874. }
  875. print '</form>';
  876. } else {
  877. print '<form name="fichinter" action="'.$_SERVER['PHP_SELF'].'" method="POST">';
  878. print '<input type="hidden" name="token" value="'.newToken().'">';
  879. print '<input type="hidden" name="action" value="create">'; // We go back to create action
  880. print dol_get_fiche_head('');
  881. if (is_object($objectsrc)) {
  882. print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
  883. print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
  884. } elseif ($origin == 'project' && !empty($projectid)) {
  885. print '<input type="hidden" name="projectid" value="'.$projectid.'">';
  886. }
  887. print '<table class="border centpercent">';
  888. print '<tr><td class="fieldrequired">'.$langs->trans("ThirdParty").'</td><td>';
  889. print $form->select_company('', 'socid', '', 'SelectThirdParty', 1, 0, null, 0, 'minwidth300');
  890. print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
  891. print '</td></tr>';
  892. print '</table>';
  893. print dol_get_fiche_end();
  894. print $form->buttonsSaveCancel("CreateDraftIntervention");
  895. print '</form>';
  896. }
  897. } elseif ($id > 0 || !empty($ref)) {
  898. /*
  899. * Affichage en mode visu
  900. */
  901. $object->fetch($id, $ref);
  902. $object->fetch_thirdparty();
  903. $soc = new Societe($db);
  904. $soc->fetch($object->socid);
  905. if ($error > 0) {
  906. dol_htmloutput_errors($mesg);
  907. } else {
  908. dol_htmloutput_mesg($mesg);
  909. }
  910. $head = fichinter_prepare_head($object);
  911. print dol_get_fiche_head($head, 'card', $langs->trans("InterventionCard"), -1, 'intervention');
  912. $formconfirm = '';
  913. // Confirm deletion of intervention
  914. if ($action == 'delete') {
  915. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteIntervention'), $langs->trans('ConfirmDeleteIntervention'), 'confirm_delete', '', 0, 1);
  916. }
  917. // Confirm validation
  918. if ($action == 'validate') {
  919. // on verifie si l'objet est en numerotation provisoire
  920. $ref = substr($object->ref, 1, 4);
  921. if ($ref == 'PROV') {
  922. $numref = $object->getNextNumRef($soc);
  923. if (empty($numref)) {
  924. $error++;
  925. setEventMessages($object->error, $object->errors, 'errors');
  926. }
  927. } else {
  928. $numref = $object->ref;
  929. }
  930. $text = $langs->trans('ConfirmValidateIntervention', $numref);
  931. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateIntervention'), $text, 'confirm_validate', '', 1, 1);
  932. }
  933. // Confirm back to draft
  934. if ($action == 'modify') {
  935. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ModifyIntervention'), $langs->trans('ConfirmModifyIntervention'), 'confirm_modify', '', 0, 1);
  936. }
  937. // Confirm back to open
  938. if ($action == 'reopen') {
  939. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReopenIntervention', $object->ref), 'confirm_reopen', '', 0, 1);
  940. }
  941. // Confirm deletion of line
  942. if ($action == 'ask_deleteline') {
  943. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&line_id='.$lineid, $langs->trans('DeleteInterventionLine'), $langs->trans('ConfirmDeleteInterventionLine'), 'confirm_deleteline', '', 0, 1);
  944. }
  945. // Clone confirmation
  946. if ($action == 'clone') {
  947. // Create an array for form
  948. $formquestion = array(
  949. // 'text' => $langs->trans("ConfirmClone"),
  950. // array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' =>
  951. // 1),
  952. // array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value'
  953. // => 1),
  954. array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid', 'int'), 'socid', '', '', 0, 0, null, 0, 'minwidth200')));
  955. // Paiement incomplet. On demande si motif = escompte ou autre
  956. $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneIntervention', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
  957. }
  958. if (!$formconfirm) {
  959. $parameters = array('formConfirm' => $formconfirm, 'lineid'=>$lineid);
  960. $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  961. if (empty($reshook)) {
  962. $formconfirm .= $hookmanager->resPrint;
  963. } elseif ($reshook > 0) {
  964. $formconfirm = $hookmanager->resPrint;
  965. }
  966. }
  967. // Print form confirm
  968. print $formconfirm;
  969. // Intervention card
  970. $linkback = '<a href="'.DOL_URL_ROOT.'/fichinter/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
  971. $morehtmlref = '<div class="refidno">';
  972. // Ref customer
  973. //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', 0, 1);
  974. //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->fichinter->creer, 'string', '', null, null, '', 1);
  975. // Thirdparty
  976. $morehtmlref .= $langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
  977. // Project
  978. if (!empty($conf->projet->enabled)) {
  979. $langs->load("projects");
  980. $morehtmlref .= '<br>'.$langs->trans('Project').' ';
  981. if ($user->rights->ficheinter->creer) {
  982. if ($action != 'classify') {
  983. $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
  984. }
  985. if ($action == 'classify') {
  986. //$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
  987. $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
  988. $morehtmlref .= '<input type="hidden" name="action" value="classin">';
  989. $morehtmlref .= '<input type="hidden" name="token" value="'.newToken().'">';
  990. $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
  991. $morehtmlref .= '<input type="submit" class="button button-edit valignmiddle" value="'.$langs->trans("Modify").'">';
  992. $morehtmlref .= '</form>';
  993. } else {
  994. $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
  995. }
  996. } else {
  997. if (!empty($object->fk_project)) {
  998. $proj = new Project($db);
  999. $proj->fetch($object->fk_project);
  1000. $morehtmlref .= ' : '.$proj->getNomUrl(1);
  1001. if ($proj->title) {
  1002. $morehtmlref .= ' - '.$proj->title;
  1003. }
  1004. } else {
  1005. $morehtmlref .= '';
  1006. }
  1007. }
  1008. }
  1009. $morehtmlref .= '</div>';
  1010. dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
  1011. print '<div class="fichecenter">';
  1012. print '<div class="fichehalfleft">';
  1013. print '<div class="underbanner clearboth"></div>';
  1014. print '<table class="border tableforfield" width="100%">';
  1015. if (!empty($conf->global->FICHINTER_USE_PLANNED_AND_DONE_DATES)) {
  1016. // Date Start
  1017. print '<tr><td class="titlefield">'.$langs->trans("Dateo").'</td>';
  1018. print '<td>';
  1019. print $object->dateo ? dol_print_date($object->dateo, 'daytext') : '&nbsp;';
  1020. print '</td>';
  1021. print '</tr>';
  1022. // Date End
  1023. print '<tr><td>'.$langs->trans("Datee").'</td>';
  1024. print '<td>';
  1025. print $object->datee ? dol_print_date($object->datee, 'daytext') : '&nbsp;';
  1026. print '</td>';
  1027. print '</tr>';
  1028. // Date Terminate/close
  1029. print '<tr><td>'.$langs->trans("Datet").'</td>';
  1030. print '<td>';
  1031. print $object->datet ? dol_print_date($object->datet, 'daytext') : '&nbsp;';
  1032. print '</td>';
  1033. print '</tr>';
  1034. }
  1035. // Description (must be a textarea and not html must be allowed (used in list view)
  1036. print '<tr><td class="titlefield">';
  1037. print $form->editfieldkey("Description", 'description', $object->description, $object, $user->rights->ficheinter->creer, 'textarea');
  1038. print '</td><td>';
  1039. print $form->editfieldval("Description", 'description', $object->description, $object, $user->rights->ficheinter->creer, 'textarea:8:80');
  1040. print '</td>';
  1041. print '</tr>';
  1042. // Contract
  1043. if ($conf->contrat->enabled) {
  1044. $langs->load('contracts');
  1045. print '<tr>';
  1046. print '<td>';
  1047. print '<table class="nobordernopadding centpercent"><tr><td>';
  1048. print $langs->trans('Contract');
  1049. print '</td>';
  1050. if ($action != 'contrat') {
  1051. print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=contrat&amp;id='.$object->id.'">';
  1052. print img_edit($langs->trans('SetContract'), 1);
  1053. print '</a></td>';
  1054. }
  1055. print '</tr></table>';
  1056. print '</td><td>';
  1057. if ($action == 'contrat') {
  1058. $formcontract = new Formcontract($db);
  1059. $formcontract->formSelectContract($_SERVER["PHP_SELF"].'?id='.$object->id, $object->socid, $object->fk_contrat, 'contratid', 0, 1, 1);
  1060. } else {
  1061. if ($object->fk_contrat) {
  1062. $contratstatic = new Contrat($db);
  1063. $contratstatic->fetch($object->fk_contrat);
  1064. //print '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$selected.'">'.$projet->title.'</a>';
  1065. print $contratstatic->getNomUrl(0, '', 1);
  1066. } else {
  1067. print "&nbsp;";
  1068. }
  1069. }
  1070. print '</td>';
  1071. print '</tr>';
  1072. }
  1073. // Other attributes
  1074. $cols = 2;
  1075. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1076. print '</table>';
  1077. print '</div>';
  1078. print '<div class="fichehalfright">';
  1079. print '<div class="underbanner clearboth"></div>';
  1080. print '<table class="border tableforfield centpercent">';
  1081. if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  1082. // Duration
  1083. print '<tr><td class="titlefield">'.$langs->trans("TotalDuration").'</td>';
  1084. print '<td>'.convertSecondToTime($object->duration, 'all', $conf->global->MAIN_DURATION_OF_WORKDAY).'</td>';
  1085. print '</tr>';
  1086. }
  1087. print "</table>";
  1088. print '</div>';
  1089. print '</div>';
  1090. print '<div class="clearboth"></div><br>';
  1091. if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
  1092. $blocname = 'contacts';
  1093. $title = $langs->trans('ContactsAddresses');
  1094. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1095. }
  1096. if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
  1097. $blocname = 'notes';
  1098. $title = $langs->trans('Notes');
  1099. include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
  1100. }
  1101. // Line of interventions
  1102. if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  1103. print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" name="addinter" method="post">';
  1104. print '<input type="hidden" name="token" value="'.newToken().'">';
  1105. print '<input type="hidden" name="id" value="'.$object->id.'">';
  1106. if ($action == 'editline') {
  1107. print '<input type="hidden" name="action" value="updateline">';
  1108. print '<input type="hidden" name="line_id" value="'.GETPOST('line_id', 'int').'">';
  1109. } else {
  1110. print '<input type="hidden" name="action" value="addline">';
  1111. }
  1112. // Intervention lines
  1113. $sql = 'SELECT ft.rowid, ft.description, ft.fk_fichinter, ft.duree, ft.rang,';
  1114. $sql .= ' ft.date as date_intervention';
  1115. $sql .= ' FROM '.MAIN_DB_PREFIX.'fichinterdet as ft';
  1116. $sql .= ' WHERE ft.fk_fichinter = '.((int) $object->id);
  1117. if (!empty($conf->global->FICHINTER_HIDE_EMPTY_DURATION)) {
  1118. $sql .= ' AND ft.duree <> 0';
  1119. }
  1120. $sql .= ' ORDER BY ft.rang ASC, ft.date ASC, ft.rowid';
  1121. $resql = $db->query($sql);
  1122. if ($resql) {
  1123. $num = $db->num_rows($resql);
  1124. $i = 0;
  1125. if ($num) {
  1126. print '<br>';
  1127. print '<table class="noborder centpercent">';
  1128. print '<tr class="liste_titre">';
  1129. // No.
  1130. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  1131. print '<td width="5" class="center linecolnum"></td>';
  1132. }
  1133. print '<td class="liste_titre">'.$langs->trans('Description').'</td>';
  1134. print '<td class="liste_titre center">'.$langs->trans('Date').'</td>';
  1135. print '<td class="liste_titre right">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ? $langs->trans('Duration') : '').'</td>';
  1136. print '<td class="liste_titre">&nbsp;</td>';
  1137. print '<td class="liste_titre">&nbsp;</td>';
  1138. print "</tr>\n";
  1139. }
  1140. while ($i < $num) {
  1141. $objp = $db->fetch_object($resql);
  1142. // Ligne en mode visu
  1143. if ($action != 'editline' || GETPOST('line_id', 'int') != $objp->rowid) {
  1144. print '<tr class="oddeven">';
  1145. // No.
  1146. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  1147. print '<td class="center linecolnum">'.($i + 1).'</td>';
  1148. }
  1149. print '<td>';
  1150. print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
  1151. print dol_htmlentitiesbr($objp->description);
  1152. // Date
  1153. print '<td class="center" width="150">'.(empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR) ?dol_print_date($db->jdate($objp->date_intervention), 'dayhour') : dol_print_date($db->jdate($objp->date_intervention), 'day')).'</td>';
  1154. // Duration
  1155. print '<td class="right" width="150">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ?convertSecondToTime($objp->duree) : '').'</td>';
  1156. print "</td>\n";
  1157. // Icon to edit and delete
  1158. if ($object->statut == 0 && $user->rights->ficheinter->creer) {
  1159. print '<td class="center">';
  1160. print '<a class="editfielda marginrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&line_id='.$objp->rowid.'#'.$objp->rowid.'">';
  1161. print img_edit();
  1162. print '</a>';
  1163. print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteline&token='.newToken().'&line_id='.$objp->rowid.'">';
  1164. print img_delete();
  1165. print '</a></td>';
  1166. print '<td class="center">';
  1167. if ($num > 1) {
  1168. if ($i > 0) {
  1169. print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=up&token='.newToken().'&line_id='.$objp->rowid.'">';
  1170. print img_up();
  1171. print '</a>';
  1172. }
  1173. if ($i < $num - 1) {
  1174. print '<a class="marginleftonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=down&token='.newToken().'&line_id='.$objp->rowid.'">';
  1175. print img_down();
  1176. print '</a>';
  1177. }
  1178. }
  1179. print '</td>';
  1180. } else {
  1181. print '<td colspan="2">&nbsp;</td>';
  1182. }
  1183. print '</tr>';
  1184. $line = new FichinterLigne($db);
  1185. $line->fetch($objp->rowid);
  1186. $extrafields->fetch_name_optionals_label($line->table_element);
  1187. $line->fetch_optionals();
  1188. print $line->showOptionals($extrafields, 'view', array('colspan'=>5));
  1189. }
  1190. // Line in update mode
  1191. if ($object->statut == 0 && $action == 'editline' && $user->rights->ficheinter->creer && GETPOST('line_id', 'int') == $objp->rowid) {
  1192. print '<tr class="oddeven nohover">';
  1193. // No.
  1194. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  1195. print '<td class="center linecolnum">'.($i + 1).'</td>';
  1196. }
  1197. print '<td>';
  1198. print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne
  1199. // Editeur wysiwyg
  1200. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1201. $doleditor = new DolEditor('np_desc', $objp->description, '', 164, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, '90%');
  1202. $doleditor->Create();
  1203. print '</td>';
  1204. // Date d'intervention
  1205. print '<td class="center nowrap">';
  1206. if (!empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
  1207. print $form->selectDate($db->jdate($objp->date_intervention), 'di', 0, 0, 0, "date_intervention");
  1208. } else {
  1209. print $form->selectDate($db->jdate($objp->date_intervention), 'di', 1, 1, 0, "date_intervention");
  1210. }
  1211. print '</td>';
  1212. // Duration
  1213. print '<td class="right">';
  1214. if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) {
  1215. $selectmode = 'select';
  1216. if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) {
  1217. $selectmode = 'text';
  1218. }
  1219. $form->select_duration('duration', $objp->duree, 0, $selectmode);
  1220. }
  1221. print '</td>';
  1222. print '<td class="center" colspan="5" valign="center">';
  1223. print '<input type="submit" class="button buttongen marginbottomonly button-save" name="save" value="'.$langs->trans("Save").'">';
  1224. print '<input type="submit" class="button buttongen marginbottomonly button-cancel" name="cancel" value="'.$langs->trans("Cancel").'"></td>';
  1225. print '</tr>'."\n";
  1226. $line = new FichinterLigne($db);
  1227. $line->fetch($objp->rowid);
  1228. $extrafields->fetch_name_optionals_label($line->table_element);
  1229. $line->fetch_optionals();
  1230. print $line->showOptionals($extrafields, 'edit', array('colspan'=>5));
  1231. }
  1232. $i++;
  1233. }
  1234. $db->free($resql);
  1235. // Add new line
  1236. if ($object->statut == 0 && $user->rights->ficheinter->creer && $action <> 'editline' && empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  1237. if (!$num) {
  1238. print '<br>';
  1239. print '<table class="noborder centpercent">';
  1240. print '<tr class="liste_titre">';
  1241. // No.
  1242. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  1243. print '<td width="5" class="center linecolnum"></td>';
  1244. }
  1245. print '<td>';
  1246. print '<a name="add"></a>'; // ancre
  1247. print $langs->trans('Description').'</td>';
  1248. print '<td class="center">'.$langs->trans('Date').'</td>';
  1249. print '<td class="right">'.(empty($conf->global->FICHINTER_WITHOUT_DURATION) ? $langs->trans('Duration') : '').'</td>';
  1250. print '<td colspan="3">&nbsp;</td>';
  1251. print "</tr>\n";
  1252. }
  1253. print '<tr class="oddeven nohover">'."\n";
  1254. // No.
  1255. if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) {
  1256. print '<td class="center linecolnum">'.($i + 1).'</td>';
  1257. }
  1258. print '<td>';
  1259. // editeur wysiwyg
  1260. if (empty($conf->global->FICHINTER_EMPTY_LINE_DESC)) {
  1261. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1262. $doleditor = new DolEditor('np_desc', GETPOST('np_desc', 'restricthtml'), '', 100, 'dolibarr_details', '', false, true, $conf->global->FCKEDITOR_ENABLE_DETAILS, ROWS_2, '90%');
  1263. $doleditor->Create();
  1264. }
  1265. print '</td>';
  1266. // Date intervention
  1267. print '<td class="center nowrap">';
  1268. $now = dol_now();
  1269. $timearray = dol_getdate($now);
  1270. if (!GETPOST('diday', 'int')) {
  1271. $timewithnohour = dol_mktime(0, 0, 0, $timearray['mon'], $timearray['mday'], $timearray['year']);
  1272. } else {
  1273. $timewithnohour = dol_mktime(GETPOST('dihour', 'int'), GETPOST('dimin', 'int'), 0, GETPOST('dimonth', 'int'), GETPOST('diday', 'int'), GETPOST('diyear', 'int'));
  1274. }
  1275. if (!empty($conf->global->FICHINTER_DATE_WITHOUT_HOUR)) {
  1276. print $form->selectDate($timewithnohour, 'di', 0, 0, 0, "addinter");
  1277. } else {
  1278. print $form->selectDate($timewithnohour, 'di', 1, 1, 0, "addinter");
  1279. }
  1280. print '</td>';
  1281. // Duration
  1282. print '<td class="right">';
  1283. if (empty($conf->global->FICHINTER_WITHOUT_DURATION)) {
  1284. $selectmode = 'select';
  1285. if (!empty($conf->global->INTERVENTION_ADDLINE_FREEDUREATION)) {
  1286. $selectmode = 'text';
  1287. }
  1288. $form->select_duration('duration', (!GETPOST('durationhour', 'int') && !GETPOST('durationmin', 'int')) ? 3600 : (60 * 60 * GETPOST('durationhour', 'int') + 60 * GETPOST('durationmin', 'int')), 0, $selectmode);
  1289. }
  1290. print '</td>';
  1291. print '<td class="center" valign="middle" colspan="3"><input type="submit" class="button button-add" value="'.$langs->trans('Add').'" name="addline"></td>';
  1292. print '</tr>';
  1293. //Line extrafield
  1294. $lineadd = new FichinterLigne($db);
  1295. $extrafields->fetch_name_optionals_label($lineadd->table_element);
  1296. print $lineadd->showOptionals($extrafields, 'edit', array('colspan'=>5));
  1297. if (!$num) {
  1298. print '</table>';
  1299. }
  1300. }
  1301. if ($num) {
  1302. print '</table>';
  1303. }
  1304. } else {
  1305. dol_print_error($db);
  1306. }
  1307. print '</form>'."\n";
  1308. }
  1309. print dol_get_fiche_end();
  1310. print "\n";
  1311. /*
  1312. * Actions buttons
  1313. */
  1314. print '<div class="tabsAction">';
  1315. $parameters = array();
  1316. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
  1317. // modified by hook
  1318. if (empty($reshook)) {
  1319. if ($user->socid == 0) {
  1320. if ($action != 'editdescription' && ($action != 'presend')) {
  1321. // Validate
  1322. if ($object->statut == Fichinter::STATUS_DRAFT && (count($object->lines) > 0 || !empty($conf->global->FICHINTER_DISABLE_DETAILS))) {
  1323. if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->ficheinter_advance->validate)) {
  1324. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=validate">'.$langs->trans("Validate").'</a></div>';
  1325. } else {
  1326. print '<div class="inline-block divButActionRefused"><span class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NotEnoughPermissions")).'">'.$langs->trans("Validate").'</span></div>';
  1327. }
  1328. }
  1329. // Modify
  1330. if ($object->statut == Fichinter::STATUS_VALIDATED && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->ficheinter->ficheinter_advance->unvalidate))) {
  1331. print '<div class="inline-block divButAction"><a class="butAction" href="card.php?id='.$object->id.'&action=modify">';
  1332. if (empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  1333. print $langs->trans("Modify");
  1334. } else {
  1335. print $langs->trans("SetToDraft");
  1336. }
  1337. print '</a></div>';
  1338. }
  1339. // Reopen
  1340. if ($object->statut >= Fichinter::STATUS_CLOSED) {
  1341. if ($user->rights->ficheinter->creer) {
  1342. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans('Reopen').'</a></div>';
  1343. } else {
  1344. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('Reopen').'</a></div>';
  1345. }
  1346. }
  1347. // Send
  1348. if (empty($user->socid)) {
  1349. if ($object->statut > Fichinter::STATUS_DRAFT) {
  1350. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->ficheinter->ficheinter_advance->send) {
  1351. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=presend&token='.newToken().'&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a></div>';
  1352. } else {
  1353. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">'.$langs->trans('SendMail').'</a></div>';
  1354. }
  1355. }
  1356. }
  1357. // Create intervention model
  1358. if ($conf->global->MAIN_FEATURES_LEVEL >= 1 && $object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer && (count($object->lines) > 0)) {
  1359. print '<div class="inline-block divButAction">';
  1360. print '<a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card-rec.php?id='.$object->id.'&action=create">'.$langs->trans("ChangeIntoRepeatableIntervention").'</a>';
  1361. print '</div>';
  1362. }
  1363. // Proposal
  1364. if ($conf->service->enabled && !empty($conf->propal->enabled) && $object->statut > Fichinter::STATUS_DRAFT) {
  1365. $langs->load("propal");
  1366. if ($object->statut < Fichinter::STATUS_BILLED) {
  1367. if ($user->rights->propal->creer) {
  1368. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddProp").'</a></div>';
  1369. } else {
  1370. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddProp").'</a></div>';
  1371. }
  1372. }
  1373. }
  1374. // Invoicing
  1375. if (!empty($conf->facture->enabled) && $object->statut > Fichinter::STATUS_DRAFT) {
  1376. $langs->load("bills");
  1377. if ($object->statut < Fichinter::STATUS_BILLED) {
  1378. if ($user->rights->facture->creer) {
  1379. print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&amp;origin='.$object->element.'&amp;originid='.$object->id.'&amp;socid='.$object->socid.'">'.$langs->trans("AddBill").'</a></div>';
  1380. } else {
  1381. print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="'.$langs->trans("NotEnoughPermissions").'">'.$langs->trans("AddBill").'</a></div>';
  1382. }
  1383. }
  1384. if (!empty($conf->global->FICHINTER_CLASSIFY_BILLED)) { // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
  1385. if ($object->statut != Fichinter::STATUS_BILLED) {
  1386. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifybilled&token='.newToken().'">'.$langs->trans("InterventionClassifyBilled").'</a></div>';
  1387. } else {
  1388. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifyunbilled&token='.newToken().'">'.$langs->trans("InterventionClassifyUnBilled").'</a></div>';
  1389. }
  1390. }
  1391. }
  1392. // Done
  1393. if (empty($conf->global->FICHINTER_CLASSIFY_BILLED) && $object->statut > Fichinter::STATUS_DRAFT && $object->statut < Fichinter::STATUS_CLOSED) {
  1394. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=classifydone&token='.newToken().'">'.$langs->trans("InterventionClassifyDone").'</a></div>';
  1395. }
  1396. // Clone
  1397. if ($user->rights->ficheinter->creer) {
  1398. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&socid='.$object->socid.'&action=clone&token='.newToken().'&object=ficheinter">'.$langs->trans("ToClone").'</a></div>';
  1399. }
  1400. // Delete
  1401. if (($object->statut == Fichinter::STATUS_DRAFT && $user->rights->ficheinter->creer) || $user->rights->ficheinter->supprimer) {
  1402. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken().'"';
  1403. print '>'.$langs->trans('Delete').'</a></div>';
  1404. }
  1405. }
  1406. }
  1407. }
  1408. print '</div>';
  1409. if ($action != 'presend') {
  1410. print '<div class="fichecenter"><div class="fichehalfleft">';
  1411. /*
  1412. * Built documents
  1413. */
  1414. $filename = dol_sanitizeFileName($object->ref);
  1415. $filedir = $conf->ficheinter->dir_output."/".$filename;
  1416. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  1417. $genallowed = $user->rights->ficheinter->lire;
  1418. $delallowed = $user->rights->ficheinter->creer;
  1419. print $formfile->showdocuments('ficheinter', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang);
  1420. // Show links to link elements
  1421. $linktoelem = $form->showLinkToObjectBlock($object, null, array('fichinter'));
  1422. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  1423. print '</div><div class="fichehalfright">';
  1424. // List of actions on element
  1425. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  1426. $formactions = new FormActions($db);
  1427. $somethingshown = $formactions->showactions($object, 'fichinter', $socid, 1);
  1428. print '</div></div>';
  1429. }
  1430. // Select mail models is same action as presend
  1431. if (GETPOST('modelselected')) {
  1432. $action = 'presend';
  1433. }
  1434. // Presend form
  1435. $modelmail = 'fichinter_send';
  1436. $defaulttopic = 'SendInterventionRef';
  1437. $diroutput = $conf->ficheinter->dir_output;
  1438. $trackid = 'int'.$object->id;
  1439. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1440. }
  1441. llxFooter();
  1442. $db->close();