defaultaccounts.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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-2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
  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 <https://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * \file htdocs/accountancy/admin/defaultaccounts.php
  26. * \ingroup Accountancy (Double entries)
  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. require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php';
  33. require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("compta","bills","admin","accountancy","salaries","loan"));
  36. // Security check
  37. if (empty($user->rights->accounting->chartofaccount))
  38. {
  39. accessforbidden();
  40. }
  41. $action = GETPOST('action', 'aZ09');
  42. $list_account_main = array (
  43. 'ACCOUNTING_ACCOUNT_CUSTOMER',
  44. 'ACCOUNTING_ACCOUNT_SUPPLIER',
  45. 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
  46. );
  47. $list_account = array (
  48. 'ACCOUNTING_PRODUCT_BUY_ACCOUNT',
  49. 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT',
  50. 'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT',
  51. 'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT',
  52. 'ACCOUNTING_SERVICE_BUY_ACCOUNT',
  53. 'ACCOUNTING_SERVICE_SOLD_ACCOUNT',
  54. 'ACCOUNTING_VAT_BUY_ACCOUNT',
  55. 'ACCOUNTING_VAT_SOLD_ACCOUNT',
  56. 'ACCOUNTING_VAT_PAY_ACCOUNT',
  57. 'ACCOUNTING_ACCOUNT_SUSPENSE',
  58. 'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
  59. 'DONATION_ACCOUNTINGACCOUNT',
  60. 'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT',
  61. 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
  62. 'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
  63. 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE'
  64. );
  65. /*
  66. * Actions
  67. */
  68. $accounting_mode = empty($conf->global->ACCOUNTING_MODE) ? 'RECETTES-DEPENSES' : $conf->global->ACCOUNTING_MODE;
  69. if (GETPOST('change_chart', 'alpha'))
  70. {
  71. $chartofaccounts = GETPOST('chartofaccounts', 'int');
  72. if (! empty($chartofaccounts)) {
  73. if (! dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
  74. $error ++;
  75. }
  76. } else {
  77. $error ++;
  78. }
  79. }
  80. if ($action == 'update') {
  81. $error = 0;
  82. foreach ($list_account_main as $constname) {
  83. $constvalue = GETPOST($constname, 'alpha');
  84. if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  85. $error ++;
  86. }
  87. }
  88. foreach ($list_account as $constname) {
  89. $constvalue = GETPOST($constname, 'alpha');
  90. if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  91. $error ++;
  92. }
  93. }
  94. if (! $error) {
  95. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  96. } else {
  97. setEventMessages($langs->trans("Error"), null, 'errors');
  98. }
  99. }
  100. /*
  101. * View
  102. */
  103. $form = new Form($db);
  104. $formaccounting = new FormAccounting($db);
  105. llxHeader();
  106. $linkback = '';
  107. print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
  108. print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
  109. print '<br>';
  110. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  111. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  112. print '<input type="hidden" name="action" value="update">';
  113. // Define main accounts for thirdparty
  114. print '<table class="noborder" width="100%">';
  115. foreach ($list_account_main as $key) {
  116. print '<tr class="oddeven value">';
  117. // Param
  118. $label = $langs->trans($key);
  119. $keydesc=$key.'_Desc';
  120. $htmltext = $langs->trans($keydesc);
  121. print '<td class="fieldrequired" width="50%">';
  122. print $form->textwithpicto($label, $htmltext);
  123. print '</td>';
  124. // Value
  125. print '<td>'; // Do not force class=right, or it align also the content of the select box
  126. print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
  127. print '</td>';
  128. print '</tr>';
  129. }
  130. print "</table>\n";
  131. print '<br>';
  132. // Define default accounts
  133. print '<table class="noborder" width="100%">';
  134. foreach ($list_account as $key) {
  135. print '<tr class="oddeven value">';
  136. // Param
  137. $label = $langs->trans($key);
  138. print '<td width="50%">' . $label . '</td>';
  139. // Value
  140. print '<td>'; // Do not force class=right, or it align also the content of the select box
  141. print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
  142. print '</td>';
  143. print '</tr>';
  144. }
  145. print "</table>\n";
  146. print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
  147. print '</form>';
  148. // End of page
  149. llxFooter();
  150. $db->close();