dolibarr 25.0.0-alpha
defaultaccounts.php
Go to the documentation of this file.
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-2025 Alexandre Spangaro <alexandre@inovea-conseil.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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
10 * Copyright (C) 2025 Vincent de Grandporé <vincent@de-grandpre.quebec>
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 3 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program. If not, see <https://www.gnu.org/licenses/>.
24 *
25 */
26
32require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
44
45// Load translation files required by the page
46$langs->loadLangs(array("compta", "bills", "admin", "accountancy", "salaries", "trips", "loan"));
47
48// Security check
49if (!$user->hasRight('accounting', 'chartofaccount')) {
51}
52
53$action = GETPOST('action', 'aZ09');
54
55
56$list_account_main = array(
57 'ACCOUNTING_ACCOUNT_CUSTOMER',
58 'ACCOUNTING_ACCOUNT_SUPPLIER',
59 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
60);
61
62if (isModEnabled('expensereport')) {
63 $list_account_main[] = 'ACCOUNTING_ACCOUNT_EXPENSEREPORT';
64}
65
66$list_account = array();
67
68$list_account[] = '---Product---';
69$list_account[] = 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT';
70if ($mysoc->isInEEC()) {
71 $list_account[] = 'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT';
72}
73$list_account[] = 'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT';
74$list_account[] = 'ACCOUNTING_PRODUCT_BUY_ACCOUNT';
75if ($mysoc->isInEEC()) {
76 $list_account[] = 'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT';
77}
78$list_account[] = 'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT';
79
80$list_account[] = '---Service---';
81$list_account[] = 'ACCOUNTING_SERVICE_SOLD_ACCOUNT';
82if ($mysoc->isInEEC()) {
83 $list_account[] = 'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT';
84}
85$list_account[] = 'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT';
86$list_account[] = 'ACCOUNTING_SERVICE_BUY_ACCOUNT';
87if ($mysoc->isInEEC()) {
88 $list_account[] = 'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT';
89}
90$list_account[] = 'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT';
91
92$list_account[] = '---Others---';
93$list_account[] = 'ACCOUNTING_VAT_SOLD_ACCOUNT';
94$list_account[] = 'ACCOUNTING_VAT_BUY_ACCOUNT';
95
96/*if ($mysoc->useRevenueStamp()) {
97 $list_account[] = 'ACCOUNTING_REVENUESTAMP_SOLD_ACCOUNT';
98 $list_account[] = 'ACCOUNTING_REVENUESTAMP_BUY_ACCOUNT';
99}*/
100
101$list_account[] = 'ACCOUNTING_VAT_PAY_ACCOUNT';
102
103$list_account[] = 'ACCOUNTING_LT1_SOLD_ACCOUNT';
104$list_account[] = 'ACCOUNTING_LT1_BUY_ACCOUNT';
105$list_account[] = 'ACCOUNTING_LT1_PAY_ACCOUNT';
106$list_account[] = 'ACCOUNTING_LT2_SOLD_ACCOUNT';
107$list_account[] = 'ACCOUNTING_LT2_BUY_ACCOUNT';
108$list_account[] = 'ACCOUNTING_LT2_PAY_ACCOUNT';
109
110if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
111 $list_account[] = 'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_CREDIT';
112 $list_account[] = 'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_DEBIT';
113 $list_account[] = 'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_CREDIT';
114 $list_account[] = 'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_DEBIT';
115 $list_account[] = 'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_CREDIT';
116 $list_account[] = 'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_DEBIT';
117}
118if (isModEnabled('bank')) {
119 $list_account[] = 'ACCOUNTING_ACCOUNT_TRANSFER_CASH';
120}
121if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY')) {
122 $list_account[] = 'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY';
123}
124if (isModEnabled('don')) {
125 $list_account[] = 'DONATION_ACCOUNTINGACCOUNT';
126}
127if (isModEnabled('member')) {
128 $list_account[] = 'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT';
129}
130if (isModEnabled('loan')) {
131 $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL';
132 $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INTEREST';
133 $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE';
134}
135$list_account[] = 'ACCOUNTING_ACCOUNT_SUSPENSE';
136if (isModEnabled('invoice') || isModEnabled('supplier_invoice')) {
137 $list_account[] = '---Discounts---';
138 $list_account[] = 'ACCOUNTING_ACCOUNT_DISCOUNT_GRANTED';
139 $list_account[] = 'ACCOUNTING_ACCOUNT_DISCOUNT_RECEIVED';
140}
141if (isModEnabled('societe')) {
142 $list_account[] = '---Deposits---';
143}
144
145/*
146 * Actions
147 */
148
149$error = 0;
150
151if ($action == 'update') {
152 // Process $list_account_main
153 foreach ($list_account_main as $constname) {
154 $constvalue = GETPOST($constname, 'alpha');
155
156 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
157 $error++;
158 }
159 }
160 // Process $list_account
161 foreach ($list_account as $constname) {
162 $reg = array();
163 if (preg_match('/---(.*)---/', $constname, $reg)) { // This is a separator
164 continue;
165 }
166
167 $constvalue = GETPOST($constname, 'alpha');
168
169 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
170 $error++;
171 }
172 }
173
174 $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT';
175 $constvalue = GETPOSTINT($constname);
176 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
177 $error++;
178 }
179
180 $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT';
181 $constvalue = GETPOSTINT($constname);
182 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
183 $error++;
184 }
185
186 $constname = 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT';
187 $constvalue = GETPOSTINT($constname);
188 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
189 $error++;
190 }
191
192
193 if (!$error) {
194 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
195 } else {
196 setEventMessages($langs->trans("Error"), null, 'errors');
197 }
198}
199
200if ($action == 'setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT') {
201 $setDisableAuxiliaryAccountOnCustomerDeposit = GETPOSTINT('value');
202 $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnCustomerDeposit, 'yesno', 0, '', $conf->entity);
203 if (!($res > 0)) {
204 $error++;
205 }
206
207 if (!$error) {
208 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
209 } else {
210 setEventMessages($langs->trans("Error"), null, 'mesgs');
211 }
212}
213
214if ($action == 'setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT') {
215 $setDisableAuxiliaryAccountOnSupplierDeposit = GETPOSTINT('value');
216 $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnSupplierDeposit, 'yesno', 0, '', $conf->entity);
217 if (!($res > 0)) {
218 $error++;
219 }
220
221 if (!$error) {
222 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
223 } else {
224 setEventMessages($langs->trans("Error"), null, 'mesgs');
225 }
226}
227
228
229/*
230 * View
231 */
232
233$form = new Form($db);
234$formaccounting = new FormAccounting($db);
235
236$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
237
238llxHeader('', $langs->trans('MenuDefaultAccounts'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_defaultaccounts');
239
240$linkback = '';
241print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
242
243print '<div class="info">'.$langs->trans("DefaultBindingDesc").'</div>';
244print '<br>';
245
246print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
247print '<input type="hidden" name="token" value="'.newToken().'">';
248print '<input type="hidden" name="action" value="update">';
249
250
251// Define main accounts for thirdparty
252
253print '<div class="div-table-responsive-no-min">';
254print '<table class="noborder centpercent">';
255print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
256
257foreach ($list_account_main as $key) {
258 print '<tr class="oddeven value">';
259 // Param
260 $label = $langs->trans($key);
261 $keydesc = $key.'_Desc';
262
263 $htmltext = $langs->trans($keydesc);
264 print '<td class="fieldrequired">';
265 if ($key == 'ACCOUNTING_ACCOUNT_CUSTOMER') {
266 print img_picto('', 'company', 'class="pictofixedwidth"');
267 } elseif ($key == 'ACCOUNTING_ACCOUNT_SUPPLIER') {
268 print img_picto('', 'company', 'class="pictofixedwidth"');
269 } else {
270 print img_picto('', 'user', 'class="pictofixedwidth"');
271 }
272 print $form->textwithpicto($label, $htmltext);
273 print '</td>';
274 // Value
275 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
276 $key_value = getDolGlobalString($key);
277 print $formaccounting->select_account($key_value, $key, 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accountsmain', '1', 2);
278 print '</td>';
279 print '</tr>';
280}
281print "</table>\n";
282print "</div>\n";
283
284print '<br>';
285
286print '<div class="div-table-responsive-no-min">';
287print '<table class="noborder centpercent">';
288
289foreach ($list_account as $key) {
290 $reg = array();
291 if (preg_match('/---(.*)---/', $key, $reg)) {
292 print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
293 } else {
294 print '<tr class="oddeven value">';
295 // Param
296 $label = $langs->trans($key);
297 print '<td>';
298 if (preg_match('/^ACCOUNTING_PRODUCT/', $key)) {
299 print img_picto('', 'product', 'class="pictofixedwidth"');
300 } elseif (preg_match('/^ACCOUNTING_SERVICE/', $key)) {
301 print img_picto('', 'service', 'class="pictofixedwidth"');
302 } elseif (preg_match('/^ACCOUNTING_VAT_PAY_ACCOUNT/', $key)) {
303 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
304 } elseif (preg_match('/^ACCOUNTING_LT1_PAY_ACCOUNT/', $key)) {
305 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
306 } elseif (preg_match('/^ACCOUNTING_LT2_PAY_ACCOUNT/', $key)) {
307 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
308 } elseif (preg_match('/^ACCOUNTING_VAT/', $key)) {
309 print img_picto('', 'vat', 'class="pictofixedwidth"');
310 } elseif (preg_match('/^ACCOUNTING_LT/', $key)) {
311 print img_picto('', 'vat', 'class="pictofixedwidth"');
312 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_CUSTOMER/', $key)) {
313 print img_picto('', 'bill', 'class="pictofixedwidth"');
314 } elseif (preg_match('/^LOAN_ACCOUNTING_ACCOUNT/', $key)) {
315 print img_picto('', 'loan', 'class="pictofixedwidth"');
316 } elseif (preg_match('/^DONATION_ACCOUNTING/', $key)) {
317 print img_picto('', 'donation', 'class="pictofixedwidth"');
318 } elseif (preg_match('/^ADHERENT_SUBSCRIPTION/', $key)) {
319 print img_picto('', 'member', 'class="pictofixedwidth"');
320 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_TRANSFER/', $key)) {
321 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
322 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_SUSPENSE/', $key)) {
323 print img_picto('', 'question', 'class="pictofixedwidth"');
324 }
325 // Note: account for revenue stamp are store into dictionary of revenue stamp. There is no default value.
326 print $label;
327 print '</td>';
328 // Value
329 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
330 print $formaccounting->select_account(getDolGlobalString($key), $key, 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
331 print '</td>';
332 print '</tr>';
333 }
334}
335
336
337// Customer deposit account
338print '<tr class="oddeven value">';
339// Param
340print '<td>';
341print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT');
342print '</td>';
343// Value
344print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
345print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
346print '</td>';
347print '</tr>';
348
349// customer deposit account for VAT
350print '<tr class="oddeven value">';
351// Param
352print '<td>';
353print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT');
354print '</td>';
355// Value
356print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
357print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
358print '</td>';
359print '</tr>';
360
361if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') != '-1') {
362 print '<tr class="oddeven">';
363 print '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnCustomerDeposit") . '</td>';
364 if (getDolGlobalInt('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
365 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
366 print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning');
367 print '</a></td>';
368 } else {
369 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
370 print img_picto($langs->trans("Disabled"), 'switch_off');
371 print '</a></td>';
372 }
373 print '</tr>';
374}
375
376// Supplier deposit account
377print '<tr class="oddeven value">';
378// Param
379print '<td>';
380print img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT');
381print '</td>';
382// Value
383print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
384print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
385print '</td>';
386print '</tr>';
387
388if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') != '-1') {
389 print '<tr class="oddeven">';
390 print '<td>' . img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnSupplierDeposit") . '</td>';
391 if (getDolGlobalInt('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
392 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
393 print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning');
394 print '</a></td>';
395 } else {
396 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
397 print img_picto($langs->trans("Disabled"), 'switch_off');
398 print '</a></td>';
399 }
400 print '</tr>';
401}
402
403print "</table>\n";
404print "</div>\n";
405
406print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
407
408print '</form>';
409
410// End of page
411llxFooter();
412$db->close();
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class to manage generation of HTML components for accounting management.
Class to manage generation of HTML components Only common components must be here.
global $mysoc
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.