closure.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. /* Copyright (C) 2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. *
  17. */
  18. /**
  19. * \file htdocs/accountancy/admin/closure.php
  20. * \ingroup Accountancy (Double entries)
  21. * \brief Setup page to configure accounting expert module
  22. */
  23. require '../../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array("compta", "admin", "accountancy"));
  29. // Security check
  30. if (empty($user->rights->accounting->chartofaccount)) {
  31. accessforbidden();
  32. }
  33. $action = GETPOST('action', 'aZ09');
  34. $list_account_main = array(
  35. 'ACCOUNTING_RESULT_PROFIT',
  36. 'ACCOUNTING_RESULT_LOSS'
  37. );
  38. /*
  39. * Actions
  40. */
  41. if ($action == 'update') {
  42. $error = 0;
  43. $defaultjournal = GETPOST('ACCOUNTING_CLOSURE_DEFAULT_JOURNAL', 'alpha');
  44. if (!empty($defaultjournal)) {
  45. if (!dolibarr_set_const($db, 'ACCOUNTING_CLOSURE_DEFAULT_JOURNAL', $defaultjournal, 'chaine', 0, '', $conf->entity)) {
  46. $error++;
  47. }
  48. } else {
  49. $error++;
  50. }
  51. foreach ($list_account_main as $constname) {
  52. $constvalue = GETPOST($constname, 'alpha');
  53. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  54. $error++;
  55. }
  56. }
  57. if (!$error) {
  58. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  59. } else {
  60. setEventMessages($langs->trans("Error"), null, 'errors');
  61. }
  62. }
  63. /*
  64. * View
  65. */
  66. $form = new Form($db);
  67. $formaccounting = new FormAccounting($db);
  68. llxHeader();
  69. $linkback = '';
  70. print load_fiche_titre($langs->trans('MenuClosureAccounts'), $linkback, 'title_accountancy');
  71. print '<span class="opacitymedium">'.$langs->trans("DefaultClosureDesc").'</span><br>';
  72. print '<br>';
  73. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  74. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  75. print '<input type="hidden" name="action" value="update">';
  76. // Define main accounts for closure
  77. print '<table class="noborder centpercent">';
  78. foreach ($list_account_main as $key) {
  79. print '<tr class="oddeven value">';
  80. // Param
  81. $label = $langs->trans($key);
  82. $keydesc = $key.'_Desc';
  83. $htmltext = $langs->trans($keydesc);
  84. print '<td class="fieldrequired" width="50%">';
  85. print $form->textwithpicto($label, $htmltext);
  86. print '</td>';
  87. // Value
  88. print '<td>'; // Do not force class=right, or it align also the content of the select box
  89. print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
  90. print '</td>';
  91. print '</tr>';
  92. }
  93. // Journal
  94. print '<tr class="oddeven">';
  95. print '<td width="50%">'.$langs->trans("ACCOUNTING_CLOSURE_DEFAULT_JOURNAL").'</td>';
  96. print '<td>';
  97. $defaultjournal = $conf->global->ACCOUNTING_CLOSURE_DEFAULT_JOURNAL;
  98. print $formaccounting->select_journal($defaultjournal, "ACCOUNTING_CLOSURE_DEFAULT_JOURNAL", 9, 1, 0, 0);
  99. print '</td></tr>';
  100. print "</table>\n";
  101. print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
  102. print '</form>';
  103. // End of page
  104. llxFooter();
  105. $db->close();