closure.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <?php
  2. /* Copyright (C) 2019-2024 Alexandre Spangaro <aspangaro@easya.solutions>
  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. $accountinggroupsusedforbalancesheetaccount = GETPOST('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT', 'alphanohtml');
  53. if (!empty($accountinggroupsusedforbalancesheetaccount)) {
  54. if (!dolibarr_set_const($db, 'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT', $accountinggroupsusedforbalancesheetaccount, 'chaine', 0, '', $conf->entity)) {
  55. $error++;
  56. }
  57. } else {
  58. $error++;
  59. }
  60. $accountinggroupsusedforincomestatement = GETPOST('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT', 'alpha');
  61. if (!empty($accountinggroupsusedforincomestatement)) {
  62. if (!dolibarr_set_const($db, 'ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT', $accountinggroupsusedforincomestatement, 'chaine', 0, '', $conf->entity)) {
  63. $error++;
  64. }
  65. } else {
  66. $error++;
  67. }
  68. foreach ($list_account_main as $constname) {
  69. $constvalue = GETPOST($constname, 'alpha');
  70. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  71. $error++;
  72. }
  73. }
  74. if (!$error) {
  75. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  76. } else {
  77. setEventMessages($langs->trans("Error"), null, 'errors');
  78. }
  79. }
  80. /*
  81. * View
  82. */
  83. $form = new Form($db);
  84. $formaccounting = new FormAccounting($db);
  85. $title = $langs->trans('Closure');
  86. $help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
  87. llxHeader('', $title, $help_url);
  88. $linkback = '';
  89. print load_fiche_titre($langs->trans('MenuClosureAccounts'), $linkback, 'title_accountancy');
  90. print '<span class="opacitymedium">'.$langs->trans("DefaultClosureDesc").'</span><br>';
  91. print '<br>';
  92. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  93. print '<input type="hidden" name="token" value="'.newToken().'">';
  94. print '<input type="hidden" name="action" value="update">';
  95. // Define main accounts for closure
  96. print '<table class="noborder centpercent">';
  97. foreach ($list_account_main as $key) {
  98. print '<tr class="oddeven value">';
  99. // Param
  100. $label = $langs->trans($key);
  101. $keydesc = $key.'_Desc';
  102. $htmltext = $langs->trans($keydesc);
  103. print '<td class="fieldrequired" width="50%">';
  104. print $form->textwithpicto($label, $htmltext);
  105. print '</td>';
  106. // Value
  107. print '<td>'; // Do not force class=right, or it align also the content of the select box
  108. print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1);
  109. print '</td>';
  110. print '</tr>';
  111. }
  112. // Journal
  113. print '<tr class="oddeven">';
  114. print '<td class="fieldrequired">'.$langs->trans("ACCOUNTING_CLOSURE_DEFAULT_JOURNAL").'</td>';
  115. print '<td>';
  116. $defaultjournal = getDolGlobalString('ACCOUNTING_CLOSURE_DEFAULT_JOURNAL');
  117. print $formaccounting->select_journal($defaultjournal, "ACCOUNTING_CLOSURE_DEFAULT_JOURNAL", 9, 1, 0, 0);
  118. print '</td></tr>';
  119. // Accounting groups used for the balance sheet account
  120. print '<tr class="oddeven">';
  121. print '<td class="fieldrequired">'.$langs->trans("ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT").'</td>';
  122. print '<td>';
  123. print '<input type="text" size="100" id="ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT" name="ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT" value="' . dol_escape_htmltag(getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_BALANCE_SHEET_ACCOUNT')). '">';
  124. print '</td></tr>';
  125. // Accounting groups used for the income statement
  126. print '<tr class="oddeven">';
  127. print '<td class="fieldrequired">'.$langs->trans("ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT").'</td>';
  128. print '<td>';
  129. print '<input type="text" size="100" id="ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT" name="ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT" value="' . dol_escape_htmltag(getDolGlobalString('ACCOUNTING_CLOSURE_ACCOUNTING_GROUPS_USED_FOR_INCOME_STATEMENT')). '">';
  130. print '</td></tr>';
  131. print "</table>\n";
  132. print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Modify').'"></div>';
  133. print '</form>';
  134. // End of page
  135. llxFooter();
  136. $db->close();