card.php 66 KB

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