defaultaccounts.php 5.2 KB

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