defaultaccounts.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  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 (!$user->hasRight('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. $constname = 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT';
  120. $constvalue = GETPOST($constname, 'int');
  121. if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
  122. $error++;
  123. }
  124. if (!$error) {
  125. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  126. } else {
  127. setEventMessages($langs->trans("Error"), null, 'errors');
  128. }
  129. }
  130. if ($action == 'setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT') {
  131. $setDisableAuxiliaryAccountOnCustomerDeposit = GETPOST('value', 'int');
  132. $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnCustomerDeposit, 'yesno', 0, '', $conf->entity);
  133. if (!($res > 0)) {
  134. $error++;
  135. }
  136. if (!$error) {
  137. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  138. } else {
  139. setEventMessages($langs->trans("Error"), null, 'mesgs');
  140. }
  141. }
  142. if ($action == 'setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT') {
  143. $setDisableAuxiliaryAccountOnSupplierDeposit = GETPOST('value', 'int');
  144. $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnSupplierDeposit, 'yesno', 0, '', $conf->entity);
  145. if (!($res > 0)) {
  146. $error++;
  147. }
  148. if (!$error) {
  149. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  150. } else {
  151. setEventMessages($langs->trans("Error"), null, 'mesgs');
  152. }
  153. }
  154. /*
  155. * View
  156. */
  157. $form = new Form($db);
  158. $formaccounting = new FormAccounting($db);
  159. llxHeader();
  160. $linkback = '';
  161. print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
  162. print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
  163. print '<br>';
  164. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  165. print '<input type="hidden" name="token" value="'.newToken().'">';
  166. print '<input type="hidden" name="action" value="update">';
  167. // Define main accounts for thirdparty
  168. print '<div class="div-table-responsive-no-min">';
  169. print '<table class="noborder centpercent">';
  170. print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
  171. foreach ($list_account_main as $key) {
  172. print '<tr class="oddeven value">';
  173. // Param
  174. $label = $langs->trans($key);
  175. $keydesc = $key.'_Desc';
  176. $htmltext = $langs->trans($keydesc);
  177. print '<td class="fieldrequired">';
  178. if ($key == 'ACCOUNTING_ACCOUNT_CUSTOMER') {
  179. print img_picto('', 'company', 'class="pictofixedwidth"');
  180. } elseif ($key == 'ACCOUNTING_ACCOUNT_SUPPLIER') {
  181. print img_picto('', 'company', 'class="pictofixedwidth"');
  182. } else {
  183. print img_picto('', 'user', 'class="pictofixedwidth"');
  184. }
  185. print $form->textwithpicto($label, $htmltext);
  186. print '</td>';
  187. // Value
  188. print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
  189. $key_value = getDolGlobalString($key);
  190. print $formaccounting->select_account($key_value, $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accountsmain');
  191. print '</td>';
  192. print '</tr>';
  193. }
  194. print "</table>\n";
  195. print "</div>\n";
  196. print '<div class="div-table-responsive-no-min">';
  197. print '<table class="noborder centpercent">';
  198. foreach ($list_account as $key) {
  199. $reg = array();
  200. if (preg_match('/---(.*)---/', $key, $reg)) {
  201. print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
  202. } else {
  203. print '<tr class="oddeven value">';
  204. // Param
  205. $label = $langs->trans($key);
  206. print '<td>';
  207. if (preg_match('/^ACCOUNTING_PRODUCT/', $key)) {
  208. print img_picto('', 'product', 'class="pictofixedwidth"');
  209. } elseif (preg_match('/^ACCOUNTING_SERVICE/', $key)) {
  210. print img_picto('', 'service', 'class="pictofixedwidth"');
  211. } elseif (preg_match('/^ACCOUNTING_VAT_PAY_ACCOUNT/', $key)) {
  212. print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
  213. } elseif (preg_match('/^ACCOUNTING_VAT/', $key)) {
  214. print img_picto('', 'vat', 'class="pictofixedwidth"');
  215. } elseif (preg_match('/^ACCOUNTING_ACCOUNT_CUSTOMER/', $key)) {
  216. print img_picto('', 'bill', 'class="pictofixedwidth"');
  217. } elseif (preg_match('/^LOAN_ACCOUNTING_ACCOUNT/', $key)) {
  218. print img_picto('', 'loan', 'class="pictofixedwidth"');
  219. } elseif (preg_match('/^DONATION_ACCOUNTING/', $key)) {
  220. print img_picto('', 'donation', 'class="pictofixedwidth"');
  221. } elseif (preg_match('/^ADHERENT_SUBSCRIPTION/', $key)) {
  222. print img_picto('', 'member', 'class="pictofixedwidth"');
  223. } elseif (preg_match('/^ACCOUNTING_ACCOUNT_TRANSFER/', $key)) {
  224. print img_picto('', 'bank_account', 'class="pictofixedwidth"');
  225. } elseif (preg_match('/^ACCOUNTING_ACCOUNT_SUSPENSE/', $key)) {
  226. print img_picto('', 'question', 'class="pictofixedwidth"');
  227. }
  228. print $label;
  229. print '</td>';
  230. // Value
  231. print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
  232. print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
  233. print '</td>';
  234. print '</tr>';
  235. }
  236. }
  237. // Customer deposit account
  238. print '<tr class="oddeven value">';
  239. // Param
  240. print '<td>';
  241. print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT');
  242. print '</td>';
  243. // Value
  244. print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
  245. print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
  246. print '</td>';
  247. print '</tr>';
  248. if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') != '-1') {
  249. print '<tr class="oddeven">';
  250. print '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnCustomerDeposit") . '</td>';
  251. if (getDolGlobalInt('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
  252. print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
  253. print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning');
  254. print '</a></td>';
  255. } else {
  256. print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
  257. print img_picto($langs->trans("Disabled"), 'switch_off');
  258. print '</a></td>';
  259. }
  260. print '</tr>';
  261. }
  262. // Supplier deposit account
  263. print '<tr class="oddeven value">';
  264. // Param
  265. print '<td>';
  266. print img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT');
  267. print '</td>';
  268. // Value
  269. print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
  270. print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
  271. print '</td>';
  272. print '</tr>';
  273. if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') != '-1') {
  274. print '<tr class="oddeven">';
  275. print '<td>' . img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnSupplierDeposit") . '</td>';
  276. if (getDolGlobalInt('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
  277. print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
  278. print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning');
  279. print '</a></td>';
  280. } else {
  281. print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
  282. print img_picto($langs->trans("Disabled"), 'switch_off');
  283. print '</a></td>';
  284. }
  285. print '</tr>';
  286. }
  287. print "</table>\n";
  288. print "</div>\n";
  289. print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
  290. print '</form>';
  291. // End of page
  292. llxFooter();
  293. $db->close();