card.php 64 KB

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