defaultaccounts.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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-2020 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. accessforbidden();
  39. }
  40. $action = GETPOST('action', 'aZ09');
  41. $list_account_main = array(
  42. 'ACCOUNTING_ACCOUNT_CUSTOMER',
  43. 'ACCOUNTING_ACCOUNT_SUPPLIER',
  44. 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
  45. );
  46. $list_account = array();
  47. $list_account[] = '---Product---';
  48. $list_account[] = 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT';
  49. if ($mysoc->isInEEC()) {
  50. $list_account[] = 'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT';
  51. }
  52. $list_account[] = 'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT';
  53. $list_account[] = 'ACCOUNTING_PRODUCT_BUY_ACCOUNT';
  54. if ($mysoc->isInEEC()) {
  55. $list_account[] = 'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT';
  56. }
  57. $list_account[] = 'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT';
  58. $list_account[] = '---Service---';
  59. $list_account[] = 'ACCOUNTING_SERVICE_SOLD_ACCOUNT';
  60. if ($mysoc->isInEEC()) {
  61. $list_account[] = 'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT';
  62. }
  63. $list_account[] = 'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT';
  64. $list_account[] = 'ACCOUNTING_SERVICE_BUY_ACCOUNT';
  65. if ($mysoc->isInEEC()) {
  66. $list_account[] = 'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT';
  67. }
  68. $list_account[] = 'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT';
  69. $list_account[] = '---Others---';
  70. $list_account[] = 'ACCOUNTING_VAT_BUY_ACCOUNT';
  71. $list_account[] = 'ACCOUNTING_VAT_SOLD_ACCOUNT';
  72. $list_account[] = 'ACCOUNTING_VAT_PAY_ACCOUNT';
  73. if (isModEnabled('banque')) {
  74. $list_account[] = 'ACCOUNTING_ACCOUNT_TRANSFER_CASH';
  75. }
  76. if (isModEnabled('don')) {
  77. $list_account[] = 'DONATION_ACCOUNTINGACCOUNT';
  78. }
  79. if (isModEnabled('adherent')) {
  80. $list_account[] = 'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT';
  81. }
  82. if (isModEnabled('loan')) {
  83. $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL';
  84. $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INTEREST';
  85. $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE';
  86. }
  87. $list_account[] = 'ACCOUNTING_ACCOUNT_SUSPENSE';
  88. if (isModEnabled('societe')) {
  89. $list_account[] = '---Deposits---';
  90. }
  91. /*
  92. * Actions
  93. */
  94. if ($action == 'update') {
  95. $error = 0;
  96. // Process $list_account_main
  97. foreach ($list_account_main as $constname) {
  98. $constvalue = GETPOST($constname, 'alpha');
  99. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  100. $error++;
  101. }
  102. }
  103. // Process $list_account
  104. foreach ($list_account as $constname) {
  105. $reg = array();
  106. if (preg_match('/---(.*)---/', $constname, $reg)) { // This is a separator
  107. continue;
  108. }
  109. $constvalue = GETPOST($constname, 'alpha');
  110. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  111. $error++;
  112. }
  113. }
  114. $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT';
  115. $constvalue = GETPOST($constname, 'int');
  116. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  117. $error++;
  118. }
  119. if (!$error) {
  120. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  121. } else {
  122. setEventMessages($langs->trans("Error"), null, 'errors');
  123. }
  124. }
  125. if ($action == 'setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT') {
  126. $setDisableAuxiliaryAccountOnCustomerDeposit = GETPOST('value', 'int');
  127. $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnCustomerDeposit, 'yesno', 0, '', $conf->entity);
  128. if (!($res > 0)) {
  129. $error++;
  130. }
  131. if (!$error) {
  132. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  133. } else {
  134. setEventMessages($langs->trans("Error"), null, 'mesgs');
  135. }
  136. }
  137. /*
  138. * View
  139. */
  140. $form = new Form($db);
  141. $formaccounting = new FormAccounting($db);
  142. llxHeader();
  143. $linkback = '';
  144. print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
  145. print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
  146. print '<br>';
  147. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  148. print '<input type="hidden" name="token" value="'.newToken().'">';
  149. print '<input type="hidden" name="action" value="update">';
  150. // Define main accounts for thirdparty
  151. print '<div class="div-table-responsive-no-min">';
  152. print '<table class="noborder centpercent">';
  153. print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
  154. foreach ($list_account_main as $key) {
  155. print '<tr class="oddeven value">';
  156. // Param
  157. $label = $langs->trans($key);
  158. $keydesc = $key.'_Desc';
  159. $htmltext = $langs->trans($keydesc);
  160. print '<td class="fieldrequired">';
  161. if ($key == 'ACCOUNTING_ACCOUNT_CUSTOMER') {
  162. print img_picto('', 'company', 'class="pictofixedwidth"');
  163. } elseif ($key == 'ACCOUNTING_ACCOUNT_SUPPLIER') {
  164. print img_picto('', 'company', 'class="pictofixedwidth"');
  165. } else {
  166. print img_picto('', 'user', 'class="pictofixedwidth"');
  167. }
  168. print $form->textwithpicto($label, $htmltext);
  169. print '</td>';
  170. // Value
  171. print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
  172. $key_value = getDolGlobalString($key);
  173. print $formaccounting->select_account($key_value, $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accountsmain');
  174. print '</td>';
  175. print '</tr>';
  176. }
  177. print "</table>\n";
  178. print "</div>\n";
  179. print '<div class="div-table-responsive-no-min">';
  180. print '<table class="noborder centpercent">';
  181. foreach ($list_account as $key) {
  182. $reg = array();
  183. if (preg_match('/---(.*)---/', $key, $reg)) {
  184. print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
  185. } else {
  186. print '<tr class="oddeven value">';
  187. // Param
  188. $label = $langs->trans($key);
  189. print '<td>';
  190. if (preg_match('/^ACCOUNTING_PRODUCT/', $key)) {
  191. print img_picto('', 'product', 'class="pictofixedwidth"');
  192. } elseif (preg_match('/^ACCOUNTING_SERVICE/', $key)) {
  193. print img_picto('', 'service', 'class="pictofixedwidth"');
  194. } elseif (preg_match('/^ACCOUNTING_VAT_PAY_ACCOUNT/', $key)) {
  195. print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
  196. } elseif (preg_match('/^ACCOUNTING_VAT/', $key)) {
  197. print img_picto('', 'vat', 'class="pictofixedwidth"');
  198. } elseif (preg_match('/^ACCOUNTING_ACCOUNT_CUSTOMER/', $key)) {
  199. print img_picto('', 'bill', 'class="pictofixedwidth"');
  200. } elseif (preg_match('/^LOAN_ACCOUNTING_ACCOUNT/', $key)) {
  201. print img_picto('', 'loan', 'class="pictofixedwidth"');
  202. } elseif (preg_match('/^DONATION_ACCOUNTING/', $key)) {
  203. print img_picto('', 'donation', 'class="pictofixedwidth"');
  204. } elseif (preg_match('/^ADHERENT_SUBSCRIPTION/', $key)) {
  205. print img_picto('', 'member', 'class="pictofixedwidth"');
  206. } elseif (preg_match('/^ACCOUNTING_ACCOUNT_TRANSFER/', $key)) {
  207. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  208. } elseif (preg_match('/^ACCOUNTING_ACCOUNT_SUSPENSE/', $key)) {
  209. print img_picto('', 'question', 'class="pictofixedwidth"');
  210. }
  211. print $label;
  212. print '</td>';
  213. // Value
  214. print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
  215. print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
  216. print '</td>';
  217. print '</tr>';
  218. }
  219. }
  220. // Customer deposit account
  221. print '<tr class="oddeven value">';
  222. // Param
  223. print '<td>';
  224. print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT');
  225. print '</td>';
  226. // Value
  227. print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
  228. print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
  229. print '</td>';
  230. print '</tr>';
  231. if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') != '-1') {
  232. print '<tr class="oddeven">';
  233. print '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnCustomerDeposit") . '</td>';
  234. if (getDolGlobalInt('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
  235. print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
  236. print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning');
  237. print '</a></td>';
  238. } else {
  239. print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
  240. print img_picto($langs->trans("Disabled"), 'switch_off');
  241. print '</a></td>';
  242. }
  243. print '</tr>';
  244. }
  245. print "</table>\n";
  246. print "</div>\n";
  247. print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
  248. print '</form>';
  249. // End of page
  250. llxFooter();
  251. $db->close();