card.php 65 KB

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