defaultaccounts.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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-2017 Alexandre Spangaro <aspangaro@zendsi.com>
  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 <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. /**
  25. * \file htdocs/accountancy/admin/defaultaccounts.php
  26. * \ingroup Advanced accountancy
  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_SERVICE_BUY_ACCOUNT',
  51. 'ACCOUNTING_SERVICE_SOLD_ACCOUNT',
  52. 'ACCOUNTING_VAT_BUY_ACCOUNT',
  53. 'ACCOUNTING_VAT_SOLD_ACCOUNT',
  54. 'ACCOUNTING_VAT_PAY_ACCOUNT',
  55. 'ACCOUNTING_ACCOUNT_SUSPENSE',
  56. 'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
  57. 'DONATION_ACCOUNTINGACCOUNT',
  58. 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
  59. 'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
  60. 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE'
  61. );
  62. /*
  63. * Actions
  64. */
  65. $accounting_mode = empty($conf->global->ACCOUNTING_MODE) ? 'RECETTES-DEPENSES' : $conf->global->ACCOUNTING_MODE;
  66. if (GETPOST('change_chart', 'alpha'))
  67. {
  68. $chartofaccounts = GETPOST('chartofaccounts', 'int');
  69. if (! empty($chartofaccounts)) {
  70. if (! dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
  71. $error ++;
  72. }
  73. } else {
  74. $error ++;
  75. }
  76. }
  77. if ($action == 'update') {
  78. $error = 0;
  79. foreach ( $list_account_main as $constname ) {
  80. $constvalue = GETPOST($constname, 'alpha');
  81. if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  82. $error ++;
  83. }
  84. }
  85. foreach ( $list_account as $constname ) {
  86. $constvalue = GETPOST($constname, 'alpha');
  87. if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  88. $error ++;
  89. }
  90. }
  91. if (! $error) {
  92. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  93. } else {
  94. setEventMessages($langs->trans("Error"), null, 'errors');
  95. }
  96. }
  97. /*
  98. * View
  99. */
  100. $form = new Form($db);
  101. $formaccounting = new FormAccounting($db);
  102. llxHeader();
  103. $linkback = '';
  104. print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
  105. print $langs->trans("DefaultBindingDesc").'<br>';
  106. print '<br>';
  107. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
  108. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  109. print '<input type="hidden" name="action" value="update">';
  110. // Define main accounts for thirdparty
  111. print '<table class="noborder" width="100%">';
  112. foreach ($list_account_main as $key) {
  113. print '<tr class="oddeven value">';
  114. // Param
  115. $label = $langs->trans($key);
  116. $keydesc=$key.'_Desc';
  117. $htmltext = $langs->trans($keydesc);
  118. print '<td class="fieldrequired" width="50%">';
  119. print $form->textwithpicto($label, $htmltext);
  120. print '</td>';
  121. // Value
  122. print '<td>'; // Do not force align=right, or it align also the content of the select box
  123. print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
  124. print '</td>';
  125. print '</tr>';
  126. }
  127. print "</table>\n";
  128. print '<br>';
  129. // Define default accounts
  130. print '<table class="noborder" width="100%">';
  131. foreach ($list_account as $key) {
  132. print '<tr class="oddeven value">';
  133. // Param
  134. $label = $langs->trans($key);
  135. print '<td width="50%">' . $label . '</td>';
  136. // Value
  137. print '<td>'; // Do not force align=right, or it align also the content of the select box
  138. print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
  139. print '</td>';
  140. print '</tr>';
  141. }
  142. print "</table>\n";
  143. print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
  144. print '</form>';
  145. // End of page
  146. llxFooter();
  147. $db->close();