closure.php 3.7 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. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
  28. // Load translation files required by the page
  29. $langs->loadLangs(array("compta", "admin", "accountancy"));
  30. // Security check
  31. if (!$user->hasRight('accounting', 'chartofaccount')) {
  32. accessforbidden();
  33. }
  34. $action = GETPOST('action', 'aZ09');
  35. $list_account_main = array(
  36. 'ACCOUNTING_RESULT_PROFIT',
  37. 'ACCOUNTING_RESULT_LOSS'
  38. );
  39. /*
  40. * Actions
  41. */
  42. if ($action == 'update') {
  43. $error = 0;
  44. $defaultjournal = GETPOST('ACCOUNTING_CLOSURE_DEFAULT_JOURNAL', 'alpha');
  45. if (!empty($defaultjournal)) {
  46. if (!dolibarr_set_const($db, 'ACCOUNTING_CLOSURE_DEFAULT_JOURNAL', $defaultjournal, 'chaine', 0, '', $conf->entity)) {
  47. $error++;
  48. }
  49. } else {
  50. $error++;
  51. }
  52. foreach ($list_account_main as $constname) {
  53. $constvalue = GETPOST($constname, 'alpha');
  54. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  55. $error++;
  56. }
  57. }
  58. if (!$error) {
  59. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  60. } else {
  61. setEventMessages($langs->trans("Error"), null, 'errors');
  62. }
  63. }
  64. /*
  65. * View
  66. */
  67. $form = new Form($db);
  68. $formaccounting = new FormAccounting($db);
  69. llxHeader();
  70. $linkback = '';
  71. print load_fiche_titre($langs->trans('MenuClosureAccounts'), $linkback, 'title_accountancy');
  72. print '<span class="opacitymedium">'.$langs->trans("DefaultClosureDesc").'</span><br>';
  73. print '<br>';
  74. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  75. print '<input type="hidden" name="token" value="'.newToken().'">';
  76. print '<input type="hidden" name="action" value="update">';
  77. // Define main accounts for closure
  78. print '<table class="noborder centpercent">';
  79. foreach ($list_account_main as $key) {
  80. print '<tr class="oddeven value">';
  81. // Param
  82. $label = $langs->trans($key);
  83. $keydesc = $key.'_Desc';
  84. $htmltext = $langs->trans($keydesc);
  85. print '<td class="fieldrequired" width="50%">';
  86. print $form->textwithpicto($label, $htmltext);
  87. print '</td>';
  88. // Value
  89. print '<td>'; // Do not force class=right, or it align also the content of the select box
  90. print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1);
  91. print '</td>';
  92. print '</tr>';
  93. }
  94. // Journal
  95. print '<tr class="oddeven">';
  96. print '<td width="50%">'.$langs->trans("ACCOUNTING_CLOSURE_DEFAULT_JOURNAL").'</td>';
  97. print '<td>';
  98. $defaultjournal = $conf->global->ACCOUNTING_CLOSURE_DEFAULT_JOURNAL;
  99. print $formaccounting->select_journal($defaultjournal, "ACCOUNTING_CLOSURE_DEFAULT_JOURNAL", 9, 1, 0, 0);
  100. print '</td></tr>';
  101. print "</table>\n";
  102. print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Modify').'"></div>';
  103. print '</form>';
  104. // End of page
  105. llxFooter();
  106. $db->close();