index.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  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", "other"));
  35. // Security access
  36. if (empty($user->rights->accounting->chartofaccount)) {
  37. accessforbidden();
  38. }
  39. $action = GETPOST('action', 'aZ09');
  40. // Parameters ACCOUNTING_* and others
  41. $list = array(
  42. 'ACCOUNTING_LENGTH_GACCOUNT',
  43. 'ACCOUNTING_LENGTH_AACCOUNT',
  44. // 'ACCOUNTING_LIMIT_LIST_VENTILATION' // there is already a global parameter to define the nb of records in lists, we must use it in priority. Having one parameter for nb of record for each page is deprecated.
  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. 'ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER'
  51. );
  52. /*
  53. * Actions
  54. */
  55. if ($action == 'update') {
  56. $error = 0;
  57. if (!$error) {
  58. foreach ($list as $constname) {
  59. $constvalue = GETPOST($constname, 'alpha');
  60. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  61. $error++;
  62. }
  63. }
  64. if ($error) {
  65. setEventMessages($langs->trans("Error"), null, 'errors');
  66. }
  67. foreach ($list_binding as $constname) {
  68. $constvalue = GETPOST($constname, 'alpha');
  69. if ($constname == 'ACCOUNTING_DATE_START_BINDING') {
  70. $constvalue = dol_mktime(12, 0, 0, GETPOST($constname.'month', 'int'), GETPOST($constname.'day', 'int'), GETPOST($constname.'year', 'int'));
  71. }
  72. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  73. $error++;
  74. }
  75. }
  76. if ($error) {
  77. setEventMessages($langs->trans("Error"), null, 'errors');
  78. }
  79. }
  80. if (!$error) {
  81. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  82. }
  83. }
  84. if ($action == 'setlistsorttodo') {
  85. $setlistsorttodo = GETPOST('value', 'int');
  86. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $setlistsorttodo, 'yesno', 0, '', $conf->entity);
  87. if (!($res > 0)) {
  88. $error++;
  89. }
  90. if (!$error) {
  91. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  92. } else {
  93. setEventMessages($langs->trans("Error"), null, 'mesgs');
  94. }
  95. }
  96. if ($action == 'setlistsortdone') {
  97. $setlistsortdone = GETPOST('value', 'int');
  98. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_DONE", $setlistsortdone, 'yesno', 0, '', $conf->entity);
  99. if (!($res > 0)) {
  100. $error++;
  101. }
  102. if (!$error) {
  103. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  104. } else {
  105. setEventMessages($langs->trans("Error"), null, 'mesgs');
  106. }
  107. }
  108. if ($action == 'setmanagezero') {
  109. $setmanagezero = GETPOST('value', 'int');
  110. $res = dolibarr_set_const($db, "ACCOUNTING_MANAGE_ZERO", $setmanagezero, 'yesno', 0, '', $conf->entity);
  111. if (!($res > 0)) {
  112. $error++;
  113. }
  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. }
  126. if (!$error) {
  127. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  128. } else {
  129. setEventMessages($langs->trans("Error"), null, 'mesgs');
  130. }
  131. }
  132. if ($action == 'setenabledraftexport') {
  133. $setenabledraftexport = GETPOST('value', 'int');
  134. $res = dolibarr_set_const($db, "ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL", $setenabledraftexport, 'yesno', 0, '', $conf->entity);
  135. if (!($res > 0)) {
  136. $error++;
  137. }
  138. if (!$error) {
  139. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  140. } else {
  141. setEventMessages($langs->trans("Error"), null, 'mesgs');
  142. }
  143. }
  144. if ($action == 'setenablesubsidiarylist') {
  145. $setenablesubsidiarylist = GETPOST('value', 'int');
  146. $res = dolibarr_set_const($db, "ACCOUNTANCY_COMBO_FOR_AUX", $setenablesubsidiarylist, 'yesno', 0, '', $conf->entity);
  147. if (!($res > 0)) {
  148. $error++;
  149. }
  150. if (!$error) {
  151. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  152. } else {
  153. setEventMessages($langs->trans("Error"), null, 'mesgs');
  154. }
  155. }
  156. if ($action == 'setdisablebindingonsales') {
  157. $setdisablebindingonsales = GETPOST('value', 'int');
  158. $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_SALES", $setdisablebindingonsales, 'yesno', 0, '', $conf->entity);
  159. if (!($res > 0)) {
  160. $error++;
  161. }
  162. if (!$error) {
  163. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  164. } else {
  165. setEventMessages($langs->trans("Error"), null, 'mesgs');
  166. }
  167. }
  168. if ($action == 'setdisablebindingonpurchases') {
  169. $setdisablebindingonpurchases = GETPOST('value', 'int');
  170. $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_PURCHASES", $setdisablebindingonpurchases, 'yesno', 0, '', $conf->entity);
  171. if (!($res > 0)) {
  172. $error++;
  173. }
  174. if (!$error) {
  175. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  176. } else {
  177. setEventMessages($langs->trans("Error"), null, 'mesgs');
  178. }
  179. }
  180. if ($action == 'setdisablebindingonexpensereports') {
  181. $setdisablebindingonexpensereports = GETPOST('value', 'int');
  182. $res = dolibarr_set_const($db, "ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS", $setdisablebindingonexpensereports, 'yesno', 0, '', $conf->entity);
  183. if (!($res > 0)) {
  184. $error++;
  185. }
  186. if (!$error) {
  187. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  188. } else {
  189. setEventMessages($langs->trans("Error"), null, 'mesgs');
  190. }
  191. }
  192. /*
  193. * View
  194. */
  195. $form = new Form($db);
  196. $title = $langs->trans('ConfigAccountingExpert');
  197. llxHeader('', $title);
  198. $linkback = '';
  199. //$linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans("BackToModuleList") . '</a>';
  200. print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'accountancy');
  201. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  202. print '<input type="hidden" name="token" value="'.newToken().'">';
  203. print '<input type="hidden" name="action" value="update">';
  204. // Params
  205. print '<table class="noborder centpercent">';
  206. print '<tr class="liste_titre">';
  207. print '<td colspan="2">'.$langs->trans('Options').'</td>';
  208. print "</tr>\n";
  209. // TO DO Mutualize code for yes/no constants
  210. /* Set this option as a hidden option but keep it for some needs.
  211. print '<tr>';
  212. print '<td>'.$langs->trans("ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL").'</td>';
  213. if (!empty($conf->global->ACCOUNTING_ENABLE_EXPORT_DRAFT_JOURNAL)) {
  214. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&enabledraftexport&value=0">';
  215. print img_picto($langs->trans("Activated"), 'switch_on');
  216. print '</a></td>';
  217. } else {
  218. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&enabledraftexport&value=1">';
  219. print img_picto($langs->trans("Disabled"), 'switch_off');
  220. print '</a></td>';
  221. }
  222. print '</tr>';
  223. */
  224. print '<tr class="oddeven">';
  225. print '<td>'.$langs->trans("BANK_DISABLE_DIRECT_INPUT").'</td>';
  226. if (!empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
  227. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disabledirectinput&value=0">';
  228. print img_picto($langs->trans("Activated"), 'switch_on');
  229. print '</a></td>';
  230. } else {
  231. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disabledirectinput&value=1">';
  232. print img_picto($langs->trans("Disabled"), 'switch_off');
  233. print '</a></td>';
  234. }
  235. print '</tr>';
  236. print '<tr class="oddeven">';
  237. print '<td>'.$langs->trans("ACCOUNTANCY_COMBO_FOR_AUX").'</td>';
  238. if (!empty($conf->global->ACCOUNTANCY_COMBO_FOR_AUX)) {
  239. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&enablesubsidiarylist&value=0">';
  240. print img_picto($langs->trans("Activated"), 'switch_on');
  241. print '</a></td>';
  242. } else {
  243. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&enablesubsidiarylist&value=1">';
  244. print img_picto($langs->trans("Disabled"), 'switch_off');
  245. print '</a></td>';
  246. }
  247. print '</tr>';
  248. print '<tr class="oddeven">';
  249. print '<td>'.$langs->trans("ACCOUNTING_MANAGE_ZERO").'</td>';
  250. if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
  251. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&managezero&value=0">';
  252. print img_picto($langs->trans("Activated"), 'switch_on');
  253. print '</a></td>';
  254. } else {
  255. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&managezero&value=1">';
  256. print img_picto($langs->trans("Disabled"), 'switch_off');
  257. print '</a></td>';
  258. }
  259. print '</tr>';
  260. // Param a user $user->rights->accounting->chartofaccount can access
  261. foreach ($list as $key) {
  262. print '<tr class="oddeven value">';
  263. if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO) && ($key == 'ACCOUNTING_LENGTH_GACCOUNT' || $key == 'ACCOUNTING_LENGTH_AACCOUNT')) {
  264. continue;
  265. }
  266. // Param
  267. $label = $langs->trans($key);
  268. print '<td>'.$label.'</td>';
  269. // Value
  270. print '<td class="right">';
  271. print '<input type="text" class="maxwidth100" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
  272. print '</td>';
  273. print '</tr>';
  274. }
  275. print '</table>';
  276. print '<br>';
  277. // Binding params
  278. print '<table class="noborder centpercent">';
  279. print '<tr class="liste_titre">';
  280. print '<td colspan="2">'.$langs->trans('BindingOptions').'</td>';
  281. print "</tr>\n";
  282. // TO DO Mutualize code for yes/no constants
  283. print '<tr class="oddeven">';
  284. print '<td>'.$langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO").'</td>';
  285. if (!empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO)) {
  286. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&listsorttodo&value=0">';
  287. print img_picto($langs->trans("Activated"), 'switch_on');
  288. print '</a></td>';
  289. } else {
  290. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&listsorttodo&value=1">';
  291. print img_picto($langs->trans("Disabled"), 'switch_off');
  292. print '</a></td>';
  293. }
  294. print '</tr>';
  295. print '<tr class="oddeven">';
  296. print '<td>'.$langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_DONE").'</td>';
  297. if (!empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE)) {
  298. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&listsortdone&value=0">';
  299. print img_picto($langs->trans("Activated"), 'switch_on');
  300. print '</a></td>';
  301. } else {
  302. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&listsortdone&value=1">';
  303. print img_picto($langs->trans("Disabled"), 'switch_off');
  304. print '</a></td>';
  305. }
  306. print '</tr>';
  307. // Param a user $user->rights->accounting->chartofaccount can access
  308. foreach ($list_binding as $key) {
  309. print '<tr class="oddeven value">';
  310. // Param
  311. $label = $langs->trans($key);
  312. print '<td>'.$label.'</td>';
  313. // Value
  314. print '<td class="right">';
  315. if ($key == 'ACCOUNTING_DATE_START_BINDING') {
  316. print $form->selectDate(($conf->global->$key ? $db->idate($conf->global->$key) : -1), $key, 0, 0, 1);
  317. } elseif ($key == 'ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER') {
  318. $array = array(0=>$langs->trans("PreviousMonth"), 1=>$langs->trans("CurrentMonth"), 2=>$langs->trans("Fiscalyear"));
  319. print $form->selectarray($key, $array, (isset($conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER) ? $conf->global->ACCOUNTING_DEFAULT_PERIOD_ON_TRANSFER : 0));
  320. } else {
  321. print '<input type="text" class="maxwidth100" id="'.$key.'" name="'.$key.'" value="'.$conf->global->$key.'">';
  322. }
  323. print '</td>';
  324. print '</tr>';
  325. }
  326. print '<tr class="oddeven">';
  327. print '<td>'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_SALES").'</td>';
  328. if (!empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_SALES)) {
  329. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disablebindingonsales&value=0">';
  330. print img_picto($langs->trans("Activated"), 'switch_on');
  331. print '</a></td>';
  332. } else {
  333. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disablebindingonsales&value=1">';
  334. print img_picto($langs->trans("Disabled"), 'switch_off');
  335. print '</a></td>';
  336. }
  337. print '</tr>';
  338. print '<tr class="oddeven">';
  339. print '<td>'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_PURCHASES").'</td>';
  340. if (!empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_PURCHASES)) {
  341. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disablebindingonpurchases&value=0">';
  342. print img_picto($langs->trans("Activated"), 'switch_on');
  343. print '</a></td>';
  344. } else {
  345. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disablebindingonpurchases&value=1">';
  346. print img_picto($langs->trans("Disabled"), 'switch_off');
  347. print '</a></td>';
  348. }
  349. print '</tr>';
  350. print '<tr class="oddeven">';
  351. print '<td>'.$langs->trans("ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS").'</td>';
  352. if (!empty($conf->global->ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS)) {
  353. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disablebindingonexpensereports&value=0">';
  354. print img_picto($langs->trans("Activated"), 'switch_on');
  355. print '</a></td>';
  356. } else {
  357. print '<td class="right"><a class="reposition" href="'.$_SERVER['PHP_SELF'].'?token='.newToken().'&disablebindingonexpensereports&value=1">';
  358. print img_picto($langs->trans("Disabled"), 'switch_off');
  359. print '</a></td>';
  360. }
  361. print '</tr>';
  362. print '</table>';
  363. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
  364. print '</form>';
  365. // End of page
  366. llxFooter();
  367. $db->close();