card.php 65 KB

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