index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <?php
  2. /* Copyright (C) 2013-2014 Olivier Geffroy <jeff@jeffinfo.com>
  3. * Copyright (C) 2013-2014 Florian Henry <florian.henry@open-concept.pro>
  4. * Copyright (C) 2013-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  5. * Copyright (C) 2014-2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  6. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  7. * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  9. * Copyright (C) 2017 Laurent Destailleur <eldy@destailleur.fr>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 3 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  23. */
  24. /**
  25. * \file htdocs/accountancy/admin/index.php
  26. * \ingroup Accountancy (Double entries)
  27. * \brief Setup page to configure accounting expert module
  28. */
  29. require '../../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("compta", "bills", "admin", "accountancy"));
  35. // Security access
  36. if (empty($user->rights->accounting->chartofaccount))
  37. {
  38. accessforbidden();
  39. }
  40. $action = GETPOST('action', 'aZ09');
  41. // Parameters ACCOUNTING_* and others
  42. $list = array(
  43. 'ACCOUNTING_LENGTH_GACCOUNT',
  44. 'ACCOUNTING_LENGTH_AACCOUNT',
  45. // 'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc
  46. // 'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', // adjust size displayed for select account description for dol_trunc
  47. );
  48. $list_binding = array(
  49. 'ACCOUNTING_DATE_START_BINDING',
  50. );
  51. /*
  52. * Actions
  53. */
  54. $accounting_mode = empty($conf->global->ACCOUNTING_MODE) ? 'RECETTES-DEPENSES' : $conf->global->ACCOUNTING_MODE;
  55. if ($action == 'update') {
  56. $error = 0;
  57. if (!$error)
  58. {
  59. foreach ($list as $constname)
  60. {
  61. $constvalue = GETPOST($constname, 'alpha');
  62. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  63. $error++;
  64. }
  65. }
  66. if ($error) {
  67. setEventMessages($langs->trans("Error"), null, 'errors');
  68. }
  69. foreach ($list_binding as $constname)
  70. {
  71. $constvalue = GETPOST($constname, 'alpha');
  72. if ($constname == 'ACCOUNTING_DATE_START_BINDING') {
  73. $constvalue = dol_mktime(12, 0, 0, GETPOST($constname.'month', 'int'), GETPOST($constname.'day', 'int'), GETPOST($constname.'year', 'int'));
  74. }
  75. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  76. $error++;
  77. }
  78. }
  79. if ($error) {
  80. setEventMessages($langs->trans("Error"), null, 'errors');
  81. }
  82. }
  83. if (!$error) {
  84. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  85. }
  86. }
  87. if ($action == 'setlistsorttodo') {
  88. $setlistsorttodo = GETPOST('value', 'int');
  89. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $setlistsorttodo, 'yesno', 0, '', $conf->entity);
  90. if (!$res > 0)
  91. $error++;
  92. if (!$error) {
  93. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  94. } else {
  95. setEventMessages($langs->trans("Error"), null, 'mesgs');
  96. }
  97. }
  98. if ($action == 'setlistsortdone') {
  99. $setlistsortdone = GETPOST('value', 'int');
  100. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_DONE", $setlistsortdone, 'yesno', 0, '', $conf->entity);
  101. if (!$res > 0)
  102. $error++;
  103. if (!$error) {
  104. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  105. } else {
  106. setEventMessages($langs->trans("Error"), null, 'mesgs');
  107. }
  108. }
  109. if ($action == 'setmanagezero') {
  110. $setmanagezero = GETPOST('value', 'int');
  111. $res = dolibarr_set_const($db, "ACCOUNTING_MANAGE_ZERO", $setmanagezero, 'yesno', 0, '', $conf->entity);
  112. if (!$res > 0)
  113. $error++;
  114. if (!$error) {
  115. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  116. } else {
  117. setEventMessages($langs->trans("Error"), null, 'mesgs');
  118. }
  119. }
  120. if ($action == 'setdisabledirectinput') {
  121. $setdisabledirectinput = GETPOST('value', 'int');
  122. $res = dolibarr_set_const($db, "BANK_DISABLE_DIRECT_INPUT", $setdisabledirectinput, 'yesno', 0, '', $conf->entity);
  123. if (!$res > 0)
  124. $error++;
  125. if (!$error) {
  126. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  127. } else {
  128. setEventMessages($langs->trans("Error"), null, 'mesgs');
  129. }
  130. }
  131. if ($action == 'setenabledraftexport') {
  132. $setenabledraftexport = GETPOST('value', 'int');
  133. $res = dolibarr_set_const($db, "ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL", $setenabledraftexport, 'yesno', 0, '', $conf->entity);
  134. if (!$res > 0)
  135. $error++;
  136. if (!$error) {
  137. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  138. } else {
  139. setEventMessages($langs->trans("Error"), null, 'mesgs');
  140. }
  141. }
  142. if ($action == 'setenablesubsidiarylist') {
  143. $setenablesubsidiarylist = GETPOST('value', 'int');
  144. $res = dolibarr_set_const($db, "ACCOUNTANCY_COMBO_FOR_AUX", $setenablesubsidiarylist, 'yesno', 0, '', $conf->entity);
  145. if (!$res > 0)
  146. $error++;
  147. if (!$error) {
  148. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  149. } else {
  150. setEventMessages($langs->trans("Error"), null, 'mesgs');
  151. }
  152. }
  153. if ($action == 'setdisablebindingonsales') {
  154. $setdisablebindingonsales = GETPOST('value', 'int');
  155. $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_SALES", $setdisablebindingonsales, 'yesno', 0, '', $conf->entity);
  156. if (!$res > 0)
  157. $error++;
  158. if (!$error) {
  159. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  160. } else {
  161. setEventMessages($langs->trans("Error"), null, 'mesgs');
  162. }
  163. }
  164. if ($action == 'setdisablebindingonpurchases') {
  165. $setdisablebindingonpurchases = GETPOST('value', 'int');
  166. $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_PURCHASES", $setdisablebindingonpurchases, 'yesno', 0, '', $conf->entity);
  167. if (!$res > 0)
  168. $error++;
  169. if (!$error) {
  170. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  171. } else {
  172. setEventMessages($langs->trans("Error"), null, 'mesgs');
  173. }
  174. }
  175. if ($action == 'setdisablebindingonexpensereports') {
  176. $setdisablebindingonexpensereports = GETPOST('value', 'int');
  177. $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS", $setdisablebindingonexpensereports, 'yesno', 0, '', $conf->entity);
  178. if (!$res > 0)
  179. $error++;
  180. if (!$error) {
  181. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  182. } else {
  183. setEventMessages($langs->trans("Error"), null, 'mesgs');
  184. }
  185. }
  186. /*
  187. * View
  188. */
  189. $form = new Form($db);
  190. $title = $langs->trans('ConfigAccountingExpert');
  191. llxHeader('', $title);
  192. $linkback = '';
  193. //$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
  194. print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'accountancy');
  195. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  196. print '<input type="hidden" name="token" value="'.newToken().'">';
  197. print '<input type="hidden" name="action" value="update">';
  198. // Default mode for calculating turnover (parameter ACCOUNTING_MODE)
  199. /*
  200. print '<table class="noborder centpercent">';
  201. print '<tr class="liste_titre">';
  202. print '<td>' . $langs->trans('OptionMode') . '</td><td>' . $langs->trans('Description') . '</td>';
  203. print "</tr>\n";
  204. print '<tr ' . $bc[false] . '><td width="200"><input type="radio" name="accounting_mode" value="RECETTES-DEPENSES"' . ($accounting_mode != 'CREANCES-DETTES' ? ' checked' : '') . '> ' . $langs->trans('OptionModeTrue') . '</td>';
  205. print '<td colspan="2">' . nl2br($langs->trans('OptionModeTrueDesc'));
  206. // Write info on way to count VAT
  207. // if (! empty($conf->global->MAIN_MODULE_COMPTABILITE))
  208. // {
  209. // // print "<br>\n";
  210. // // print nl2br($langs->trans('OptionModeTrueInfoModuleComptabilite'));
  211. // }
  212. // else
  213. // {
  214. // // print "<br>\n";
  215. // // print nl2br($langs->trans('OptionModeTrueInfoExpert'));
  216. // }
  217. print "</td></tr>\n";
  218. print '<tr ' . $bc[true] . '><td width="200"><input type="radio" name="accounting_mode" value="CREANCES-DETTES"' . ($accounting_mode == 'CREANCES-DETTES' ? ' checked' : '') . '> ' . $langs->trans('OptionModeVirtual') . '</td>';
  219. print '<td colspan="2">' . nl2br($langs->trans('OptionModeVirtualDesc')) . "</td></tr>\n";
  220. print "</table>\n";
  221. print '<br>';
  222. */
  223. // Params
  224. print '<table class="noborder centpercent">';
  225. print '<tr class="liste_titre">';
  226. print '<td colspan="2">'.$langs->trans('Options').'</td>';
  227. print "</tr>\n";
  228. // TO DO Mutualize code for yes/no constants
  229. /* Set this option as a hidden option but keep it for some needs.
  230. print '<tr>';
  231. print '<td>'.$langs->trans("ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL").'</td>';
  232. if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL)) {
  233. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setenabledraftexport&value=0">';
  234. print img_picto($langs->trans("Activated"), 'switch_on');
  235. print '</a></td>';
  236. } else {
  237. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setenabledraftexport&value=1">';
  238. print img_picto($langs->trans("Disabled"), 'switch_off');
  239. print '</a></td>';
  240. }
  241. print '</tr>';
  242. */
  243. print '<tr class="oddeven">';
  244. print '<td>'.$langs->trans("BANK_DISABLE_DIRECT_INPUT").'</td>';
  245. if (!empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
  246. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisabledirectinput&value=0">';
  247. print img_picto($langs->trans("Activated"), 'switch_on');
  248. print '</a></td>';
  249. } else {
  250. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisabledirectinput&value=1">';
  251. print img_picto($langs->trans("Disabled"), 'switch_off');
  252. print '</a></td>';
  253. }
  254. print '</tr>';
  255. print '<tr class="oddeven">';
  256. print '<td>'.$langs->trans("ACCOUNTANCY_COMBO_FOR_AUX").'</td>';
  257. if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
  258. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setenablesubsidiarylist&value=0">';
  259. print img_picto($langs->trans("Activated"), 'switch_on');
  260. print '</a></td>';
  261. } else {
  262. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setenablesubsidiarylist&value=1">';
  263. print img_picto($langs->trans("Disabled"), 'switch_off');
  264. print '</a></td>';
  265. }
  266. print '</tr>';
  267. print '<tr class="oddeven">';
  268. print '<td>'.$langs->trans("ACCOUNTING_MANAGE_ZERO").'</td>';
  269. if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
  270. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setmanagezero&value=0">';
  271. print img_picto($langs->trans("Activated"), 'switch_on');
  272. print '</a></td>';
  273. } else {
  274. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setmanagezero&value=1">';
  275. print img_picto($langs->trans("Disabled"), 'switch_off');
  276. print '</a></td>';
  277. }
  278. print '</tr>';
  279. // Param a user $user->rights->accounting->chartofaccount can access
  280. foreach ($list as $key)
  281. {
  282. print '<tr class="oddeven value">';
  283. if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO) && ($key == 'ACCOUNTING_LENGTH_GACCOUNT' || $key == 'ACCOUNTING_LENGTH_AACCOUNT')) continue;
  284. // Param
  285. $label = $langs->trans($key);
  286. print '<td>'.$label.'</td>';
  287. // Value
  288. print '<td class="right">';
  289. print '<input type="text" class="maxwidth100" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
  290. print '</td>';
  291. print '</tr>';
  292. }
  293. print '</table>';
  294. print '<br>';
  295. // Binding params
  296. print '<table class="noborder centpercent">';
  297. print '<tr class="liste_titre">';
  298. print '<td colspan="2">'.$langs->trans('BindingOptions').'</td>';
  299. print "</tr>\n";
  300. // TO DO Mutualize code for yes/no constants
  301. print '<tr class="oddeven">';
  302. print '<td>'.$langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO").'</td>';
  303. if (!empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO)) {
  304. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlistsorttodo&value=0">';
  305. print img_picto($langs->trans("Activated"), 'switch_on');
  306. print '</a></td>';
  307. } else {
  308. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlistsorttodo&value=1">';
  309. print img_picto($langs->trans("Disabled"), 'switch_off');
  310. print '</a></td>';
  311. }
  312. print '</tr>';
  313. print '<tr class="oddeven">';
  314. print '<td>'.$langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_DONE").'</td>';
  315. if (!empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE)) {
  316. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlistsortdone&value=0">';
  317. print img_picto($langs->trans("Activated"), 'switch_on');
  318. print '</a></td>';
  319. } else {
  320. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setlistsortdone&value=1">';
  321. print img_picto($langs->trans("Disabled"), 'switch_off');
  322. print '</a></td>';
  323. }
  324. print '</tr>';
  325. // Param a user $user->rights->accounting->chartofaccount can access
  326. foreach ($list_binding as $key)
  327. {
  328. print '<tr class="oddeven value">';
  329. // Param
  330. $label = $langs->trans($key);
  331. print '<td>'.$label.'</td>';
  332. // Value
  333. print '<td class="right">';
  334. if ($key == 'ACCOUNTING_DATE_START_BINDING') {
  335. print $form->selectDate(($conf->global->$key ? $db->idate($conf->global->$key) : -1), $key, 0, 0, 1);
  336. } else {
  337. print '<input type="text" class="maxwidth100" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
  338. }
  339. print '</td>';
  340. print '</tr>';
  341. }
  342. print '<tr class="oddeven">';
  343. print '<td>'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_SALES").'</td>';
  344. if (!empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_SALES)) {
  345. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablebindingonsales&value=0">';
  346. print img_picto($langs->trans("Activated"), 'switch_on');
  347. print '</a></td>';
  348. } else {
  349. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablebindingonsales&value=1">';
  350. print img_picto($langs->trans("Disabled"), 'switch_off');
  351. print '</a></td>';
  352. }
  353. print '</tr>';
  354. print '<tr class="oddeven">';
  355. print '<td>'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_PURCHASES").'</td>';
  356. if (!empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_PURCHASES)) {
  357. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablebindingonpurchases&value=0">';
  358. print img_picto($langs->trans("Activated"), 'switch_on');
  359. print '</a></td>';
  360. } else {
  361. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablebindingonpurchases&value=1">';
  362. print img_picto($langs->trans("Disabled"), 'switch_off');
  363. print '</a></td>';
  364. }
  365. print '</tr>';
  366. print '<tr class="oddeven">';
  367. print '<td>'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS").'</td>';
  368. if (!empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS)) {
  369. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablebindingonexpensereports&value=0">';
  370. print img_picto($langs->trans("Activated"), 'switch_on');
  371. print '</a></td>';
  372. } else {
  373. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?action=setdisablebindingonexpensereports&value=1">';
  374. print img_picto($langs->trans("Disabled"), 'switch_off');
  375. print '</a></td>';
  376. }
  377. print '</tr>';
  378. print '</table>';
  379. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
  380. print '</form>';
  381. // End of page
  382. llxFooter();
  383. $db->close();