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';
33
34// Class
35require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
36require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
37require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
38
48// Load translation files required by the page
49$langs->loadLangs(array("compta", "bills", "admin", "accountancy", "salaries", "trips", "loan"));
50
51// Security check
52if (!$user->hasRight('accounting', 'chartofaccount')) {
54}
55
56$action = GETPOST('action', 'aZ09');
57
58
59$list_account_main = array(
60 'ACCOUNTING_ACCOUNT_CUSTOMER',
61 'ACCOUNTING_ACCOUNT_SUPPLIER',
62 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT',
63);
64
65if (isModEnabled('expensereport')) {
66 $list_account_main[] = 'ACCOUNTING_ACCOUNT_EXPENSEREPORT';
67}
68
69$list_account = array();
70
71$list_account[] = '---Product---';
72$list_account[] = 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT';
73if ($mysoc->isInEEC()) {
74 $list_account[] = 'ACCOUNTING_PRODUCT_SOLD_INTRA_ACCOUNT';
75}
76$list_account[] = 'ACCOUNTING_PRODUCT_SOLD_EXPORT_ACCOUNT';
77$list_account[] = 'ACCOUNTING_PRODUCT_BUY_ACCOUNT';
78if ($mysoc->isInEEC()) {
79 $list_account[] = 'ACCOUNTING_PRODUCT_BUY_INTRA_ACCOUNT';
80}
81$list_account[] = 'ACCOUNTING_PRODUCT_BUY_EXPORT_ACCOUNT';
82
83$list_account[] = '---Service---';
84$list_account[] = 'ACCOUNTING_SERVICE_SOLD_ACCOUNT';
85if ($mysoc->isInEEC()) {
86 $list_account[] = 'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT';
87}
88$list_account[] = 'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT';
89$list_account[] = 'ACCOUNTING_SERVICE_BUY_ACCOUNT';
90if ($mysoc->isInEEC()) {
91 $list_account[] = 'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT';
92}
93$list_account[] = 'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT';
94
95$list_account[] = '---Others---';
96$list_account[] = 'ACCOUNTING_VAT_SOLD_ACCOUNT';
97$list_account[] = 'ACCOUNTING_VAT_BUY_ACCOUNT';
98
99/*if ($mysoc->useRevenueStamp()) {
100 $list_account[] = 'ACCOUNTING_REVENUESTAMP_SOLD_ACCOUNT';
101 $list_account[] = 'ACCOUNTING_REVENUESTAMP_BUY_ACCOUNT';
102}*/
103
104$list_account[] = 'ACCOUNTING_VAT_PAY_ACCOUNT';
105
106$list_account[] = 'ACCOUNTING_LT1_SOLD_ACCOUNT';
107$list_account[] = 'ACCOUNTING_LT1_BUY_ACCOUNT';
108$list_account[] = 'ACCOUNTING_LT1_PAY_ACCOUNT';
109$list_account[] = 'ACCOUNTING_LT2_SOLD_ACCOUNT';
110$list_account[] = 'ACCOUNTING_LT2_BUY_ACCOUNT';
111$list_account[] = 'ACCOUNTING_LT2_PAY_ACCOUNT';
112
113if (getDolGlobalString('ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE')) {
114 $list_account[] = 'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_CREDIT';
115 $list_account[] = 'ACCOUNTING_VAT_BUY_REVERSE_CHARGES_DEBIT';
116 $list_account[] = 'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_CREDIT';
117 $list_account[] = 'ACCOUNTING_LT1_BUY_REVERSE_CHARGES_DEBIT';
118 $list_account[] = 'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_CREDIT';
119 $list_account[] = 'ACCOUNTING_LT2_BUY_REVERSE_CHARGES_DEBIT';
120}
121if (isModEnabled('bank')) {
122 $list_account[] = 'ACCOUNTING_ACCOUNT_TRANSFER_CASH';
123}
124if (getDolGlobalString('INVOICE_USE_RETAINED_WARRANTY')) {
125 $list_account[] = 'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY';
126}
127if (isModEnabled('don')) {
128 $list_account[] = 'DONATION_ACCOUNTINGACCOUNT';
129}
130if (isModEnabled('member')) {
131 $list_account[] = 'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT';
132}
133if (isModEnabled('loan')) {
134 $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL';
135 $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INTEREST';
136 $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE';
137}
138$list_account[] = 'ACCOUNTING_ACCOUNT_SUSPENSE';
139if (isModEnabled('invoice') || isModEnabled('supplier_invoice')) {
140 $list_account[] = '---Discounts---';
141 $list_account[] = 'ACCOUNTING_ACCOUNT_DISCOUNT_GRANTED';
142 $list_account[] = 'ACCOUNTING_ACCOUNT_DISCOUNT_RECEIVED';
143}
144if (isModEnabled('societe')) {
145 $list_account[] = '---Deposits---';
146}
147
148/*
149 * Actions
150 */
151
152$error = 0;
153
154if ($action == 'update') {
155 // Process $list_account_main
156 foreach ($list_account_main as $constname) {
157 $constvalue = GETPOST($constname, 'alpha');
158
159 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
160 $error++;
161 }
162 }
163 // Process $list_account
164 foreach ($list_account as $constname) {
165 $reg = array();
166 if (preg_match('/---(.*)---/', $constname, $reg)) { // This is a separator
167 continue;
168 }
169
170 $constvalue = GETPOST($constname, 'alpha');
171
172 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
173 $error++;
174 }
175 }
176
177 $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT';
178 $constvalue = GETPOSTINT($constname);
179 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
180 $error++;
181 }
182
183 $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT';
184 $constvalue = GETPOSTINT($constname);
185 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
186 $error++;
187 }
188
189 $constname = 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT';
190 $constvalue = GETPOSTINT($constname);
191 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
192 $error++;
193 }
194
195
196 if (!$error) {
197 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
198 } else {
199 setEventMessages($langs->trans("Error"), null, 'errors');
200 }
201}
202
203if ($action == 'setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT') {
204 $setDisableAuxiliaryAccountOnCustomerDeposit = GETPOSTINT('value');
205 $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnCustomerDeposit, 'yesno', 0, '', $conf->entity);
206 if (!($res > 0)) {
207 $error++;
208 }
209
210 if (!$error) {
211 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
212 } else {
213 setEventMessages($langs->trans("Error"), null, 'mesgs');
214 }
215}
216
217if ($action == 'setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT') {
218 $setDisableAuxiliaryAccountOnSupplierDeposit = GETPOSTINT('value');
219 $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnSupplierDeposit, 'yesno', 0, '', $conf->entity);
220 if (!($res > 0)) {
221 $error++;
222 }
223
224 if (!$error) {
225 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
226 } else {
227 setEventMessages($langs->trans("Error"), null, 'mesgs');
228 }
229}
230
231
232/*
233 * View
234 */
235
236$form = new Form($db);
237$formaccounting = new FormAccounting($db);
238
239$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
240
241llxHeader('', $langs->trans('MenuDefaultAccounts'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_defaultaccounts');
242
243$linkback = '';
244print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
245
246print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
247print '<br>';
248
249print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
250print '<input type="hidden" name="token" value="'.newToken().'">';
251print '<input type="hidden" name="action" value="update">';
252
253
254// Define main accounts for thirdparty
255
256print '<div class="div-table-responsive-no-min">';
257print '<table class="noborder centpercent">';
258print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
259
260foreach ($list_account_main as $key) {
261 print '<tr class="oddeven value">';
262 // Param
263 $label = $langs->trans($key);
264 $keydesc = $key.'_Desc';
265
266 $htmltext = $langs->trans($keydesc);
267 print '<td class="fieldrequired">';
268 if ($key == 'ACCOUNTING_ACCOUNT_CUSTOMER') {
269 print img_picto('', 'company', 'class="pictofixedwidth"');
270 } elseif ($key == 'ACCOUNTING_ACCOUNT_SUPPLIER') {
271 print img_picto('', 'company', 'class="pictofixedwidth"');
272 } else {
273 print img_picto('', 'user', 'class="pictofixedwidth"');
274 }
275 print $form->textwithpicto($label, $htmltext);
276 print '</td>';
277 // Value
278 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
279 $key_value = getDolGlobalString($key);
280 print $formaccounting->select_account($key_value, $key, 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accountsmain', '1', 2);
281 print '</td>';
282 print '</tr>';
283}
284print "</table>\n";
285print "</div>\n";
286
287
288print '<div class="div-table-responsive-no-min">';
289print '<table class="noborder centpercent">';
290
291foreach ($list_account as $key) {
292 $reg = array();
293 if (preg_match('/---(.*)---/', $key, $reg)) {
294 print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
295 } else {
296 print '<tr class="oddeven value">';
297 // Param
298 $label = $langs->trans($key);
299 print '<td>';
300 if (preg_match('/^ACCOUNTING_PRODUCT/', $key)) {
301 print img_picto('', 'product', 'class="pictofixedwidth"');
302 } elseif (preg_match('/^ACCOUNTING_SERVICE/', $key)) {
303 print img_picto('', 'service', 'class="pictofixedwidth"');
304 } elseif (preg_match('/^ACCOUNTING_VAT_PAY_ACCOUNT/', $key)) {
305 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
306 } elseif (preg_match('/^ACCOUNTING_LT1_PAY_ACCOUNT/', $key)) {
307 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
308 } elseif (preg_match('/^ACCOUNTING_LT2_PAY_ACCOUNT/', $key)) {
309 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
310 } elseif (preg_match('/^ACCOUNTING_VAT/', $key)) {
311 print img_picto('', 'vat', 'class="pictofixedwidth"');
312 } elseif (preg_match('/^ACCOUNTING_LT/', $key)) {
313 print img_picto('', 'vat', 'class="pictofixedwidth"');
314 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_CUSTOMER/', $key)) {
315 print img_picto('', 'bill', 'class="pictofixedwidth"');
316 } elseif (preg_match('/^LOAN_ACCOUNTING_ACCOUNT/', $key)) {
317 print img_picto('', 'loan', 'class="pictofixedwidth"');
318 } elseif (preg_match('/^DONATION_ACCOUNTING/', $key)) {
319 print img_picto('', 'donation', 'class="pictofixedwidth"');
320 } elseif (preg_match('/^ADHERENT_SUBSCRIPTION/', $key)) {
321 print img_picto('', 'member', 'class="pictofixedwidth"');
322 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_TRANSFER/', $key)) {
323 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
324 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_SUSPENSE/', $key)) {
325 print img_picto('', 'question', 'class="pictofixedwidth"');
326 }
327 // Note: account for revenue stamp are store into dictionary of revenue stamp. There is no default value.
328 print $label;
329 print '</td>';
330 // Value
331 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
332 print $formaccounting->select_account(getDolGlobalString($key), $key, 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
333 print '</td>';
334 print '</tr>';
335 }
336}
337
338
339// Customer deposit account
340print '<tr class="oddeven value">';
341// Param
342print '<td>';
343print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT');
344print '</td>';
345// Value
346print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
347print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
348print '</td>';
349print '</tr>';
350
351// customer deposit account for VAT
352print '<tr class="oddeven value">';
353// Param
354print '<td>';
355print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT');
356print '</td>';
357// Value
358print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
359print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT_FOR_VAT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
360print '</td>';
361print '</tr>';
362
363if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') != '-1') {
364 print '<tr class="oddeven">';
365 print '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnCustomerDeposit") . '</td>';
366 if (getDolGlobalInt('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
367 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
368 print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning');
369 print '</a></td>';
370 } else {
371 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
372 print img_picto($langs->trans("Disabled"), 'switch_off');
373 print '</a></td>';
374 }
375 print '</tr>';
376}
377
378// Supplier deposit account
379print '<tr class="oddeven value">';
380// Param
381print '<td>';
382print img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT');
383print '</td>';
384// Value
385print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
386print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
387print '</td>';
388print '</tr>';
389
390if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') != '-1') {
391 print '<tr class="oddeven">';
392 print '<td>' . img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnSupplierDeposit") . '</td>';
393 if (getDolGlobalInt('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
394 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
395 print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning');
396 print '</a></td>';
397 } else {
398 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
399 print img_picto($langs->trans("Disabled"), 'switch_off');
400 print '</a></td>';
401 }
402 print '</tr>';
403}
404
405print "</table>\n";
406print "</div>\n";
407
408print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
409
410print '</form>';
411
412// End of page
413llxFooter();
414$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:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
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.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.