delais.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005 Simon Tosser <simon@kornog-computing.com>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2022 Frédéric France <frederic.france@netlogic.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/admin/delais.php
  24. * \brief Page to setup late delays
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  29. // Load translation files required by the page
  30. $langs->load("admin");
  31. if (!$user->admin) {
  32. accessforbidden();
  33. }
  34. $action = GETPOST('action', 'aZ09');
  35. if (empty($action)) {
  36. $action = 'edit';
  37. }
  38. // Define list of managed delays
  39. $modules = array(
  40. 'agenda' => array(
  41. array(
  42. 'code' => 'MAIN_DELAY_ACTIONS_TODO',
  43. 'img' => 'action'
  44. )
  45. ),
  46. 'projet' => array(
  47. array(
  48. 'code' => 'MAIN_DELAY_PROJECT_TO_CLOSE',
  49. 'img' => 'project'
  50. ),
  51. array(
  52. 'code' => 'MAIN_DELAY_TASKS_TODO',
  53. 'img' => 'projecttask'
  54. )
  55. ),
  56. 'propal' => array(
  57. array(
  58. 'code' => 'MAIN_DELAY_PROPALS_TO_CLOSE',
  59. 'img' => 'propal'
  60. ),
  61. array(
  62. 'code' => 'MAIN_DELAY_PROPALS_TO_BILL',
  63. 'img' => 'propal'
  64. )
  65. ),
  66. 'commande' => array(
  67. array(
  68. 'code' => 'MAIN_DELAY_ORDERS_TO_PROCESS',
  69. 'img' => 'order'
  70. )
  71. ),
  72. 'facture' => array(
  73. array(
  74. 'code' => 'MAIN_DELAY_CUSTOMER_BILLS_UNPAYED',
  75. 'img' => 'bill'
  76. )
  77. ),
  78. 'fournisseur' => array(
  79. array(
  80. 'code' => 'MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS',
  81. 'img' => 'order'
  82. ),
  83. array(
  84. 'code' => 'MAIN_DELAY_SUPPLIER_BILLS_TO_PAY',
  85. 'img' => 'bill'
  86. )
  87. ),
  88. 'service' => array(
  89. array(
  90. 'code' => 'MAIN_DELAY_NOT_ACTIVATED_SERVICES',
  91. 'img' => 'service'
  92. ),
  93. array(
  94. 'code' => 'MAIN_DELAY_RUNNING_SERVICES',
  95. 'img' => 'service'
  96. )
  97. ),
  98. 'banque' => array(
  99. array(
  100. 'code' => 'MAIN_DELAY_TRANSACTIONS_TO_CONCILIATE',
  101. 'img' => 'account'
  102. ),
  103. array(
  104. 'code' => 'MAIN_DELAY_CHEQUES_TO_DEPOSIT',
  105. 'img' => 'account'
  106. )
  107. ),
  108. 'adherent' => array(
  109. array(
  110. 'code' => 'MAIN_DELAY_MEMBERS',
  111. 'img' => 'user'
  112. )
  113. ),
  114. 'expensereport' => array(
  115. array(
  116. 'code' => 'MAIN_DELAY_EXPENSEREPORTS',
  117. 'img' => 'trip'
  118. ),
  119. /* TODO Enable this
  120. array(
  121. 'code' => 'MAIN_DELAY_EXPENSEREPORTS_TO_PAY',
  122. 'img' => 'trip'
  123. )*/
  124. ),
  125. 'holiday' => array(
  126. array(
  127. 'code' => 'MAIN_DELAY_HOLIDAYS',
  128. 'img' => 'holiday'
  129. ),
  130. ),
  131. );
  132. $labelmeteo = array(0=>$langs->trans("No"), 1=>$langs->trans("Yes"), 2=>$langs->trans("OnMobileOnly"));
  133. if (!isset($conf->global->MAIN_DELAY_MEMBERS)) {
  134. $conf->global->MAIN_DELAY_MEMBERS = 0; // Must be same value than into conf.class.php
  135. }
  136. if (!isset($conf->global->MAIN_DELAY_ACTIONS_TODO)) {
  137. $conf->global->MAIN_DELAY_ACTIONS_TODO = 7; // Must be same value than into conf.class.php
  138. }
  139. if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
  140. $conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
  141. }
  142. if (!isset($conf->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS)) {
  143. $conf->global->MAIN_DELAY_SUPPLIER_ORDERS_TO_PROCESS = 7;
  144. }
  145. if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
  146. $conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
  147. }
  148. if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
  149. $conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
  150. }
  151. if (!isset($conf->global->MAIN_DELAY_ORDERS_TO_PROCESS)) {
  152. $conf->global->MAIN_DELAY_ORDERS_TO_PROCESS = 2;
  153. }
  154. /*
  155. * Actions
  156. */
  157. if ($action == 'update') {
  158. foreach ($modules as $module => $delays) {
  159. if (isModEnabled($module)) {
  160. foreach ($delays as $delay) {
  161. if (GETPOST($delay['code']) != '') {
  162. dolibarr_set_const($db, $delay['code'], GETPOST($delay['code']), 'chaine', 0, '', $conf->entity);
  163. }
  164. }
  165. }
  166. }
  167. dolibarr_set_const($db, "MAIN_DISABLE_METEO", GETPOST("MAIN_DISABLE_METEO"), 'chaine', 0, '', $conf->entity);
  168. dolibarr_set_const($db, "MAIN_USE_METEO_WITH_PERCENTAGE", GETPOST("MAIN_USE_METEO_WITH_PERCENTAGE"), 'chaine', 0, '', $conf->entity);
  169. // For update value with percentage
  170. $plus = '';
  171. if (getDolGlobalString('MAIN_USE_METEO_WITH_PERCENTAGE')) {
  172. $plus = '_PERCENTAGE';
  173. }
  174. // Update values
  175. for ($i = 0; $i < 4; $i++) {
  176. if (GETPOSTISSET('MAIN_METEO'.$plus.'_LEVEL'.$i)) {
  177. dolibarr_set_const($db, 'MAIN_METEO'.$plus.'_LEVEL'.$i, GETPOST('MAIN_METEO'.$plus.'_LEVEL'.$i, 'int'), 'chaine', 0, '', $conf->entity);
  178. }
  179. }
  180. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  181. $action = 'edit';
  182. }
  183. /*
  184. * View
  185. */
  186. $form = new Form($db);
  187. llxHeader();
  188. print load_fiche_titre($langs->trans("DelaysOfToleranceBeforeWarning"), '', 'title_setup');
  189. print '<span class="opacitymedium">'.$langs->transnoentities("DelaysOfToleranceDesc", img_warning('default', '', 'pictowarning nopaddingleft'));
  190. print " ".$langs->trans("OnlyActiveElementsAreShown", DOL_URL_ROOT.'/admin/modules.php')."</span><br>\n";
  191. print "<br>\n";
  192. if ($action == 'edit') {
  193. print '<form method="post" action="'.$_SERVER['PHP_SELF'].'" name="form_index">';
  194. print '<input type="hidden" name="token" value="'.newToken().'">';
  195. print '<input type="hidden" name="action" value="update">';
  196. print '<table class="noborder centpercent">';
  197. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("DelaysOfToleranceBeforeWarning").'</td>';
  198. print '<td class="right">'.$langs->trans("LateWarningAfter").'</td></tr>';
  199. foreach ($modules as $module => $delays) {
  200. if (isModEnabled($module)) {
  201. foreach ($delays as $delay) {
  202. $value = getDolGlobalInt($delay['code']);
  203. print '<tr class="oddeven">';
  204. print '<td width="20px">' . img_object('', $delay['img']) . '</td>';
  205. print '<td>' . $langs->trans('Delays_' . $delay['code']) . '</td><td class="nowraponall right">';
  206. print '<input class="right maxwidth75" type="number" name="' . $delay['code'] . '" value="' . $value . '"> ' . $langs->trans("days") . '</td></tr>';
  207. }
  208. }
  209. }
  210. print '</table>';
  211. print '<br>';
  212. // Show if meteo is enabled
  213. print '<table class="noborder centpercent">';
  214. print '<tr class="liste_titre"><td>'.$langs->trans("Option").'</td><td class="right">'.$langs->trans("Value").'</td></tr>';
  215. print '<tr class="oddeven">';
  216. print '<td>'.$langs->trans("MAIN_DISABLE_METEO").'</td><td class="right">';
  217. print $form->selectarray('MAIN_DISABLE_METEO', $labelmeteo, (!getDolGlobalString('MAIN_DISABLE_METEO') ? 0 : $conf->global->MAIN_DISABLE_METEO));
  218. print '</td></tr>';
  219. print '</table>';
  220. } else {
  221. /*
  222. * Show parameters
  223. */
  224. print '<table class="noborder centpercent">';
  225. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("DelaysOfToleranceBeforeWarning").'</td><td class="right">'.$langs->trans("Value").'</td></tr>';
  226. foreach ($modules as $module => $delays) {
  227. if (isModEnabled($module)) {
  228. foreach ($delays as $delay) {
  229. $value = getDolGlobalInt($delay['code']);
  230. print '<tr class="oddeven">';
  231. print '<td width="20px">' . img_object('', $delay['img']) . '</td>';
  232. print '<td>' . $langs->trans('Delays_' . $delay['code']) . '</td>';
  233. print '<td class="right">' . $value . ' ' . $langs->trans("days") . '</td></tr>';
  234. }
  235. }
  236. }
  237. print '</table>';
  238. print '<br>';
  239. // Show if meteo is enabled
  240. print '<table class="noborder centpercent">';
  241. print '<tr class="liste_titre"><td>'.$langs->trans("Option").'</td><td class="right">'.$langs->trans("Value").'</td></tr>';
  242. print '<tr class="oddeven">';
  243. print '<td>'.$langs->trans("MAIN_DISABLE_METEO").'</td><td class="center">';
  244. print $labelmeteo[getDolGlobalString('MAIN_DISABLE_METEO')];
  245. print '</td></tr>';
  246. print '</table>';
  247. }
  248. print '<br>';
  249. if (!getDolGlobalString('MAIN_DISABLE_METEO') || getDolGlobalInt('MAIN_DISABLE_METEO') != 1) {
  250. // Show logo for weather
  251. print '<span class="opacitymedium">'.$langs->trans("DescWeather").'</span> ';
  252. if ($action == 'edit') {
  253. $str_mode_std = $langs->trans('MeteoStdModEnabled').' : '.$langs->trans('MeteoUseMod', $langs->transnoentitiesnoconv('MeteoPercentageMod'));
  254. $str_mode_percentage = $langs->trans('MeteoPercentageModEnabled').' : '.$langs->trans('MeteoUseMod', $langs->transnoentitiesnoconv('MeteoStdMod'));
  255. if (!getDolGlobalString('MAIN_USE_METEO_WITH_PERCENTAGE')) {
  256. $str_mode_enabled = $str_mode_std;
  257. } else {
  258. $str_mode_enabled = $str_mode_percentage;
  259. }
  260. print '<br><a href="#" onclick="return false;" id="change_mode">'.$str_mode_enabled.'</a>';
  261. print '<input type="hidden" id="MAIN_USE_METEO_WITH_PERCENTAGE" name="MAIN_USE_METEO_WITH_PERCENTAGE" value="'.(getDolGlobalString('MAIN_USE_METEO_WITH_PERCENTAGE') ? $conf->global->MAIN_USE_METEO_WITH_PERCENTAGE : '').'" />';
  262. print '<br><br>';
  263. } else {
  264. if (!getDolGlobalString('MAIN_USE_METEO_WITH_PERCENTAGE')) {
  265. print $langs->trans('MeteoStdModEnabled');
  266. } else {
  267. print $langs->trans('MeteoPercentageModEnabled');
  268. }
  269. print '<br><br>';
  270. }
  271. $offset = 0;
  272. $cursor = 10; // By default
  273. //if (!empty($conf->global->MAIN_METEO_OFFSET)) $offset=$conf->global->MAIN_METEO_OFFSET;
  274. //if (!empty($conf->global->MAIN_METEO_GAP)) $cursor=$conf->global->MAIN_METEO_GAP;
  275. $level0 = $offset;
  276. if (getDolGlobalString('MAIN_METEO_LEVEL0')) {
  277. $level0 = $conf->global->MAIN_METEO_LEVEL0;
  278. }
  279. $level1 = $offset + $cursor;
  280. if (getDolGlobalString('MAIN_METEO_LEVEL1')) {
  281. $level1 = $conf->global->MAIN_METEO_LEVEL1;
  282. }
  283. $level2 = $offset + 2 * $cursor;
  284. if (getDolGlobalString('MAIN_METEO_LEVEL2')) {
  285. $level2 = $conf->global->MAIN_METEO_LEVEL2;
  286. }
  287. $level3 = $offset + 3 * $cursor;
  288. if (getDolGlobalString('MAIN_METEO_LEVEL3')) {
  289. $level3 = $conf->global->MAIN_METEO_LEVEL3;
  290. }
  291. $text = '';
  292. $options = 'class="valignmiddle" height="60px"';
  293. if ($action == 'edit') {
  294. print '<div id="standard" '.(!getDolGlobalString('MAIN_USE_METEO_WITH_PERCENTAGE') ? '' : 'style="display:none;"').'>';
  295. print '<div>';
  296. print '<div class="inline-block" style="padding-right: 20px">';
  297. print img_weather($text, 0, $options);
  298. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL0" value="'.$level0.'"/></td>';
  299. print '</div><div class="inline-block" style="padding-right: 20px">';
  300. print img_weather($text, 1, $options);
  301. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL1" value="'.$level1.'"/></td>';
  302. print '</div><div class="inline-block" style="padding-right: 20px">';
  303. print img_weather($text, 2, $options);
  304. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL2" value="'.$level2.'"/></td>';
  305. print '</div><div class="inline-block" style="padding-right: 20px">';
  306. print img_weather($text, 3, $options);
  307. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_LEVEL3" value="'.$level3.'"/></td>';
  308. print '</div>';
  309. print '</div>';
  310. print '</div>';
  311. print '<div id="percentage" '.(!getDolGlobalString('MAIN_USE_METEO_WITH_PERCENTAGE') ? 'style="display:none;"' : '').'>';
  312. print '<div>';
  313. print '<div class="inline-block" style="padding-right: 20px">';
  314. print img_weather($text, 0, $options);
  315. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL0" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL0').'"/>&nbsp;%</td>';
  316. print '</div><div class="inline-block" style="padding-right: 20px">';
  317. print img_weather($text, 1, $options);
  318. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL1" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL1').'"/>&nbsp;%</td>';
  319. print '</div><div class="inline-block" style="padding-right: 20px">';
  320. print img_weather($text, 2, $options);
  321. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL2" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL2').'"/>&nbsp;%</td>';
  322. print '</div><div class="inline-block" style="padding-right: 20px">';
  323. print img_weather($text, 3, $options);
  324. print ' &lt;= <input type="text" size="2" name="MAIN_METEO_PERCENTAGE_LEVEL3" value="'.getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL3').'"/>&nbsp;%</td>';
  325. print '</div>';
  326. print '</div>';
  327. print '</div>'; ?>
  328. <script type="text/javascript">
  329. $(document).ready(function() {
  330. $("#change_mode").click(function() {
  331. var use_percent = $("#MAIN_USE_METEO_WITH_PERCENTAGE");
  332. var str_mode_std = "<?php print $str_mode_std; ?>";
  333. var str_mode_percentage = "<?php print $str_mode_percentage; ?>";
  334. if(use_percent.val() == 1) {
  335. use_percent.val(0);
  336. $("#standard").show();
  337. $("#percentage").hide();
  338. $(this).html(str_mode_std);
  339. } else {
  340. use_percent.val(1);
  341. $("#standard").hide();
  342. $("#percentage").show();
  343. $(this).html(str_mode_percentage);
  344. }
  345. });
  346. });
  347. </script>
  348. <?php
  349. } else {
  350. if (getDolGlobalString('MAIN_USE_METEO_WITH_PERCENTAGE')) {
  351. print '<div>';
  352. print '<div class="inline-block" style="padding-right: 20px">';
  353. print img_weather($text, 0, $options);
  354. print ' &lt;= ' . getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL0').'&nbsp;%</td>';
  355. print '</div><div class="inline-block" style="padding-right: 20px">';
  356. print img_weather($text, 1, $options);
  357. print ' &lt;= ' . getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL1').'&nbsp;%</td>';
  358. print '</div><div class="inline-block" style="padding-right: 20px">';
  359. print img_weather($text, 2, $options);
  360. print ' &lt;= ' . getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL2').'&nbsp;%</td>';
  361. print '</div><div class="inline-block" style="padding-right: 20px">';
  362. print img_weather($text, 3, $options);
  363. print ' &lt;= ' . getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL3').'&nbsp;%</td>';
  364. print '</div><div class="inline-block" style="padding-right: 20px">';
  365. print img_weather($text, 4, $options);
  366. print ' &gt; ' . getDolGlobalString('MAIN_METEO_PERCENTAGE_LEVEL3').'&nbsp;%</td>';
  367. print '</div>';
  368. print '</div>';
  369. } else {
  370. print '<div>';
  371. print '<div class="inline-block" style="padding-right: 20px">';
  372. print img_weather($text, 0, $options);
  373. print ' &lt;= '.$level0;
  374. print '</div><div class="inline-block" style="padding-right: 20px">';
  375. print img_weather($text, 1, $options);
  376. print ' &lt;= '.$level1;
  377. print '</div><div class="inline-block" style="padding-right: 20px">';
  378. print img_weather($text, 2, $options);
  379. print ' &lt;= '.$level2;
  380. print '</div><div class="inline-block" style="padding-right: 20px">';
  381. print img_weather($text, 3, $options);
  382. print ' &lt;= '.$level3;
  383. print '</div><div class="inline-block" style="padding-right: 20px">';
  384. print img_weather($text, 4, $options);
  385. print ' &gt; '.$level3;
  386. print '</div>';
  387. print '</div>';
  388. }
  389. }
  390. }
  391. if ($action == 'edit') {
  392. print $form->buttonsSaveCancel("Save", '');
  393. print '</form>';
  394. } else {
  395. print '<br><br><div class="tabsAction">';
  396. print '<a class="butAction reposition" href="delais.php?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  397. print '</div>';
  398. }
  399. // End of page
  400. llxFooter();
  401. $db->close();