card.php 67 KB

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