index.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * \file htdocs/accountancy/admin/index.php
  26. * \ingroup Advanced accountancy
  27. * \brief Setup page to configure accounting expert module
  28. */
  29. require '../../main.inc.php';
  30. // Class
  31. require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
  32. $langs->load("compta");
  33. $langs->load("bills");
  34. $langs->load("admin");
  35. $langs->load("accountancy");
  36. $langs->load("salaries");
  37. // Security check
  38. if (empty($user->admin))
  39. {
  40. accessforbidden();
  41. }
  42. $action = GETPOST('action', 'alpha');
  43. // Parameters ACCOUNTING_* and others
  44. $list = array (
  45. 'ACCOUNTING_LENGTH_GACCOUNT',
  46. 'ACCOUNTING_LENGTH_AACCOUNT' ,
  47. 'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc
  48. 'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', // adjust size displayed for select account description for dol_trunc
  49. );
  50. /*
  51. * Actions
  52. */
  53. $accounting_mode = defined('ACCOUNTING_MODE') ? ACCOUNTING_MODE : 'RECETTES-DEPENSES';
  54. if ($action == 'update') {
  55. $error = 0;
  56. $accounting_modes = array (
  57. 'RECETTES-DEPENSES',
  58. 'CREANCES-DETTES'
  59. );
  60. $accounting_mode = GETPOST('accounting_mode', 'alpha');
  61. if (in_array($accounting_mode, $accounting_modes)) {
  62. if (! dolibarr_set_const($db, 'ACCOUNTING_MODE', $accounting_mode, 'chaine', 0, '', $conf->entity)) {
  63. $error ++;
  64. }
  65. } else {
  66. $error ++;
  67. }
  68. if ($error) {
  69. setEventMessages($langs->trans("Error"), null, 'errors');
  70. }
  71. foreach ($list as $constname)
  72. {
  73. $constvalue = GETPOST($constname, 'alpha');
  74. if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  75. $error ++;
  76. }
  77. }
  78. if (! $error) {
  79. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  80. } else {
  81. setEventMessages($langs->trans("Error"), null, 'errors');
  82. }
  83. }
  84. // TO DO Mutualize code for yes/no constants
  85. if ($action == 'setlistsorttodo') {
  86. $setlistsorttodo = GETPOST('value', 'int');
  87. $res = dolibarr_set_const($db, "ACCOUNTING_LIST_SORT_VENTILATION_TODO", $setlistsorttodo, 'yesno', 0, '', $conf->entity);
  88. if (! $res > 0)
  89. $error ++;
  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. if (! $error) {
  102. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  103. } else {
  104. setEventMessages($langs->trans("Error"), null, 'mesgs');
  105. }
  106. }
  107. if ($action == 'setmanagezero') {
  108. $setmanagezero = GETPOST('value', 'int');
  109. $res = dolibarr_set_const($db, "ACCOUNTING_MANAGE_ZERO", $setmanagezero, 'yesno', 0, '', $conf->entity);
  110. if (! $res > 0)
  111. $error ++;
  112. if (! $error) {
  113. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  114. } else {
  115. setEventMessages($langs->trans("Error"), null, 'mesgs');
  116. }
  117. }
  118. if ($action == 'setdisabledirectinput') {
  119. $setdisabledirectinput = GETPOST('value', 'int');
  120. $res = dolibarr_set_const($db, "BANK_DISABLE_DIRECT_INPUT", $setdisabledirectinput, 'yesno', 0, '', $conf->entity);
  121. if (! $res > 0)
  122. $error ++;
  123. if (! $error) {
  124. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  125. } else {
  126. setEventMessages($langs->trans("Error"), null, 'mesgs');
  127. }
  128. }
  129. /*
  130. * View
  131. */
  132. llxHeader();
  133. $form = new Form($db);
  134. $linkback = '<a href="' . DOL_URL_ROOT . '/admin/modules.php">' . $langs->trans("BackToModuleList") . '</a>';
  135. print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'title_setup');
  136. $head = admin_accounting_prepare_head($accounting);
  137. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  138. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  139. print '<input type="hidden" name="action" value="update">';
  140. dol_fiche_head($head, 'general', $langs->trans("Configuration"), -1, 'cron');
  141. // Default mode for calculating turnover (parameter ACCOUNTING_MODE)
  142. print '<table class="noborder" width="100%">';
  143. print '<tr class="liste_titre">';
  144. print '<td>' . $langs->trans('OptionMode') . '</td><td>' . $langs->trans('Description') . '</td>';
  145. print "</tr>\n";
  146. 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>';
  147. print '<td colspan="2">' . nl2br($langs->trans('OptionModeTrueDesc'));
  148. // Write info on way to count VAT
  149. // if (! empty($conf->global->MAIN_MODULE_COMPTABILITE))
  150. // {
  151. // // print "<br>\n";
  152. // // print nl2br($langs->trans('OptionModeTrueInfoModuleComptabilite'));
  153. // }
  154. // else
  155. // {
  156. // // print "<br>\n";
  157. // // print nl2br($langs->trans('OptionModeTrueInfoExpert'));
  158. // }
  159. print "</td></tr>\n";
  160. 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>';
  161. print '<td colspan="2">' . nl2br($langs->trans('OptionModeVirtualDesc')) . "</td></tr>\n";
  162. print "</table>\n";
  163. print '<br>';
  164. // Others params
  165. print '<table class="noborder" width="100%">';
  166. print '<tr class="liste_titre">';
  167. print '<td colspan="2">' . $langs->trans('OtherOptions') . '</td>';
  168. print "</tr>\n";
  169. if (! empty($user->admin))
  170. {
  171. // TO DO Mutualize code for yes/no constants
  172. print '<tr class="oddeven">';
  173. print '<td>' . $langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_TODO") . '</td>';
  174. if (! empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_TODO)) {
  175. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsorttodo&value=0">';
  176. print img_picto($langs->trans("Activated"), 'switch_on');
  177. print '</a></td>';
  178. } else {
  179. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsorttodo&value=1">';
  180. print img_picto($langs->trans("Disabled"), 'switch_off');
  181. print '</a></td>';
  182. }
  183. print '</tr>';
  184. print '<tr class="oddeven">';
  185. print '<td>' . $langs->trans("ACCOUNTING_LIST_SORT_VENTILATION_DONE") . '</td>';
  186. if (! empty($conf->global->ACCOUNTING_LIST_SORT_VENTILATION_DONE)) {
  187. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsortdone&value=0">';
  188. print img_picto($langs->trans("Activated"), 'switch_on');
  189. print '</a></td>';
  190. } else {
  191. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setlistsortdone&value=1">';
  192. print img_picto($langs->trans("Disabled"), 'switch_off');
  193. print '</a></td>';
  194. }
  195. print '</tr>';
  196. print '<tr class="oddeven">';
  197. print '<td>' . $langs->trans("BANK_DISABLE_DIRECT_INPUT") . '</td>';
  198. if (! empty($conf->global->BANK_DISABLE_DIRECT_INPUT)) {
  199. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=0">';
  200. print img_picto($langs->trans("Activated"), 'switch_on');
  201. print '</a></td>';
  202. } else {
  203. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setdisabledirectinput&value=1">';
  204. print img_picto($langs->trans("Disabled"), 'switch_off');
  205. print '</a></td>';
  206. }
  207. print '</tr>';
  208. print '<tr class="oddeven">';
  209. print '<td>' . $langs->trans("ACCOUNTING_MANAGE_ZERO") . '</td>';
  210. if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
  211. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setmanagezero&value=0">';
  212. print img_picto($langs->trans("Activated"), 'switch_on');
  213. print '</a></td>';
  214. } else {
  215. print '<td align="right"><a href="' . $_SERVER['PHP_SELF'] . '?action=setmanagezero&value=1">';
  216. print img_picto($langs->trans("Disabled"), 'switch_off');
  217. print '</a></td>';
  218. }
  219. print '</tr>';
  220. }
  221. // Param a user $user->rights->accountancy->chartofaccount can access
  222. foreach ($list as $key)
  223. {
  224. print '<tr class="oddeven value">';
  225. if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO) && ($key == 'ACCOUNTING_LENGTH_GACCOUNT' || $key == 'ACCOUNTING_LENGTH_AACCOUNT')) continue;
  226. // Param
  227. $label = $langs->trans($key);
  228. print '<td>'.$label.'</td>';
  229. // Value
  230. print '<td align="right">';
  231. print '<input type="text" class="maxwidth100" id="' . $key . '" name="' . $key . '" value="' . $conf->global->$key . '">';
  232. print '</td>';
  233. print '</tr>';
  234. }
  235. print '</table>';
  236. dol_fiche_end();
  237. print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
  238. print '<br>';
  239. print '<br>';
  240. print '<div class="opacitymedium">'.$langs->trans("AccountancySetupDoneFromAccountancyMenu", $langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")).'</div>';
  241. print '<br>';
  242. print '</form>';
  243. llxFooter();
  244. $db->close();