defaultaccounts.php 13 KB

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