defaultaccounts.php 13 KB

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