compta.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013-2017 Philippe Grand <philippe.grand@atoo-net.com>
  7. * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
  8. * Copyright (C) 2020 Maxime DEMAREST <maxime@indelog.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 <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/admin/compta.php
  25. * \ingroup compta
  26. * \brief Page to setup accountancy module
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('admin', 'compta', 'accountancy'));
  33. if (!$user->admin) {
  34. accessforbidden();
  35. }
  36. $action = GETPOST('action', 'aZ09');
  37. // Other parameters ACCOUNTING_*
  38. $list = array(
  39. 'ACCOUNTING_PRODUCT_BUY_ACCOUNT',
  40. 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT',
  41. 'ACCOUNTING_SERVICE_BUY_ACCOUNT',
  42. 'ACCOUNTING_SERVICE_SOLD_ACCOUNT',
  43. 'ACCOUNTING_VAT_SOLD_ACCOUNT',
  44. 'ACCOUNTING_VAT_BUY_ACCOUNT',
  45. 'ACCOUNTING_ACCOUNT_CUSTOMER',
  46. 'ACCOUNTING_ACCOUNT_SUPPLIER'
  47. );
  48. /*
  49. * Actions
  50. */
  51. $accounting_mode = !getDolGlobalString('ACCOUNTING_MODE') ? 'RECETTES-DEPENSES' : $conf->global->ACCOUNTING_MODE;
  52. if ($action == 'update') {
  53. $error = 0;
  54. $accounting_modes = array(
  55. 'RECETTES-DEPENSES',
  56. 'CREANCES-DETTES'
  57. );
  58. $accounting_mode = GETPOST('accounting_mode', 'alpha');
  59. if (in_array($accounting_mode, $accounting_modes)) {
  60. if (!dolibarr_set_const($db, 'ACCOUNTING_MODE', $accounting_mode, 'chaine', 0, '', $conf->entity)) {
  61. $error++;
  62. }
  63. } else {
  64. $error++;
  65. }
  66. foreach ($list as $constname) {
  67. $constvalue = GETPOST($constname, 'alpha');
  68. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  69. $error++;
  70. }
  71. }
  72. $report_include_varpay = GETPOST('ACCOUNTING_REPORTS_INCLUDE_VARPAY', 'alpha');
  73. if (!empty($report_include_varpay)) {
  74. if ($report_include_varpay == 'yes') {
  75. if (!dolibarr_set_const($db, 'ACCOUNTING_REPORTS_INCLUDE_VARPAY', 1, 'chaine', 0, '', $conf->entity)) {
  76. $error++;
  77. }
  78. }
  79. }
  80. if ($report_include_varpay == 'no') {
  81. if (!dolibarr_del_const($db, 'ACCOUNTING_REPORTS_INCLUDE_VARPAY', $conf->entity)) {
  82. $error++;
  83. }
  84. }
  85. $report_include_loan = GETPOST('ACCOUNTING_REPORTS_INCLUDE_LOAN', 'alpha');
  86. if (!empty($report_include_loan)) {
  87. if ($report_include_loan == 'yes') {
  88. if (!dolibarr_set_const($db, 'ACCOUNTING_REPORTS_INCLUDE_LOAN', 1, 'chaine', 0, '', $conf->entity)) {
  89. $error++;
  90. }
  91. }
  92. }
  93. if ($report_include_loan == 'no') {
  94. if (!dolibarr_del_const($db, 'ACCOUNTING_REPORTS_INCLUDE_LOAN', $conf->entity)) {
  95. $error++;
  96. }
  97. }
  98. if (!$error) {
  99. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  100. } else {
  101. setEventMessages($langs->trans("Error"), null, 'errors');
  102. }
  103. }
  104. /*
  105. * View
  106. */
  107. llxHeader();
  108. $form = new Form($db);
  109. $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  110. print load_fiche_titre($langs->trans('ComptaSetup'), $linkback, 'title_setup');
  111. print '<br>';
  112. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  113. print '<input type="hidden" name="token" value="'.newToken().'">';
  114. print '<input type="hidden" name="action" value="update">';
  115. print '<table class="noborder centpercent">';
  116. // case of the parameter ACCOUNTING_MODE
  117. print '<tr class="liste_titre">';
  118. print '<td>'.$langs->trans('OptionMode').'</td><td>'.$langs->trans('Description').'</td>';
  119. print "</tr>\n";
  120. print '<tr class="oddeven"><td width="200"><input type="radio" name="accounting_mode" value="RECETTES-DEPENSES"'.($accounting_mode != 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeTrue').'</td>';
  121. print '<td colspan="2">'.nl2br($langs->trans('OptionModeTrueDesc'));
  122. print "</td></tr>\n";
  123. print '<tr class="oddeven"><td width="200"><input type="radio" name="accounting_mode" value="CREANCES-DETTES"'.($accounting_mode == 'CREANCES-DETTES' ? ' checked' : '').'> '.$langs->trans('OptionModeVirtual').'</td>';
  124. print '<td colspan="2">'.nl2br($langs->trans('OptionModeVirtualDesc'))."</td></tr>\n";
  125. print "</table>\n";
  126. print "<br>\n";
  127. print '<table class="noborder centpercent">';
  128. print '<tr class="liste_titre">';
  129. print '<td colspan="3">'.$langs->trans('OtherOptions').'</td>';
  130. print "</tr>\n";
  131. foreach ($list as $key) {
  132. print '<tr class="oddeven value">';
  133. // Param
  134. $libelle = $langs->trans($key);
  135. print '<td><label for="'.$key.'">'.$libelle.'</label></td>';
  136. // Value
  137. print '<td>';
  138. print '<input type="text" size="20" id="'.$key.'" name="'.$key.'" value="'.getDolGlobalString($key).'">';
  139. print '</td></tr>';
  140. }
  141. // Option to include various payment in results
  142. print '<tr class="oddeven value">'."\n";
  143. print '<td><label for="ACCOUNTING_REPORTS_INCLUDE_VARPAY">'.$langs->trans('IncludeVarpaysInResults').'</label></td>'."\n";
  144. print '<td class="center">'."\n";
  145. print $form->selectyesno('ACCOUNTING_REPORTS_INCLUDE_VARPAY', (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_VARPAY')));
  146. print '</td></tr>';
  147. // Option to include loan in results
  148. print '<tr class="oddeven value">'."\n";
  149. print '<td><label for="ACCOUNTING_REPORTS_INCLUDE_LOAN">'.$langs->trans('IncludeLoansInResults').'</label></td>'."\n";
  150. print '<td class="center">'."\n";
  151. print $form->selectyesno('ACCOUNTING_REPORTS_INCLUDE_LOAN', (getDolGlobalString('ACCOUNTING_REPORTS_INCLUDE_LOAN')));
  152. print '</td></tr>';
  153. print "</table>\n";
  154. print '<br><br><div style="text-align:center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Modify').'"></div>';
  155. print '</form>';
  156. // End of page
  157. llxFooter();
  158. $db->close();