dolibarr 24.0.0-beta
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_SUPPLIER_DEPOSIT';
184 $constvalue = GETPOSTINT($constname);
185 if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
186 $error++;
187 }
188
189
190 if (!$error) {
191 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
192 } else {
193 setEventMessages($langs->trans("Error"), null, 'errors');
194 }
195}
196
197if ($action == 'setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT') {
198 $setDisableAuxiliaryAccountOnCustomerDeposit = GETPOSTINT('value');
199 $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnCustomerDeposit, 'yesno', 0, '', $conf->entity);
200 if (!($res > 0)) {
201 $error++;
202 }
203
204 if (!$error) {
205 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
206 } else {
207 setEventMessages($langs->trans("Error"), null, 'mesgs');
208 }
209}
210
211if ($action == 'setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT') {
212 $setDisableAuxiliaryAccountOnSupplierDeposit = GETPOSTINT('value');
213 $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnSupplierDeposit, 'yesno', 0, '', $conf->entity);
214 if (!($res > 0)) {
215 $error++;
216 }
217
218 if (!$error) {
219 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
220 } else {
221 setEventMessages($langs->trans("Error"), null, 'mesgs');
222 }
223}
224
225
226/*
227 * View
228 */
229
230$form = new Form($db);
231$formaccounting = new FormAccounting($db);
232
233$help_url = 'EN:Module_Double_Entry_Accounting#Setup|FR:Module_Comptabilit&eacute;_en_Partie_Double#Configuration';
234
235llxHeader('', $langs->trans('MenuDefaultAccounts'), $help_url, '', 0, 0, '', '', '', 'mod-accountancy page-admin_defaultaccounts');
236
237$linkback = '';
238print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
239
240print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
241print '<br>';
242
243print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
244print '<input type="hidden" name="token" value="'.newToken().'">';
245print '<input type="hidden" name="action" value="update">';
246
247
248// Define main accounts for thirdparty
249
250print '<div class="div-table-responsive-no-min">';
251print '<table class="noborder centpercent">';
252print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
253
254foreach ($list_account_main as $key) {
255 print '<tr class="oddeven value">';
256 // Param
257 $label = $langs->trans($key);
258 $keydesc = $key.'_Desc';
259
260 $htmltext = $langs->trans($keydesc);
261 print '<td class="fieldrequired">';
262 if ($key == 'ACCOUNTING_ACCOUNT_CUSTOMER') {
263 print img_picto('', 'company', 'class="pictofixedwidth"');
264 } elseif ($key == 'ACCOUNTING_ACCOUNT_SUPPLIER') {
265 print img_picto('', 'company', 'class="pictofixedwidth"');
266 } else {
267 print img_picto('', 'user', 'class="pictofixedwidth"');
268 }
269 print $form->textwithpicto($label, $htmltext);
270 print '</td>';
271 // Value
272 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
273 $key_value = getDolGlobalString($key);
274 print $formaccounting->select_account($key_value, $key, 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accountsmain', '1', 2);
275 print '</td>';
276 print '</tr>';
277}
278print "</table>\n";
279print "</div>\n";
280
281
282print '<div class="div-table-responsive-no-min">';
283print '<table class="noborder centpercent">';
284
285foreach ($list_account as $key) {
286 $reg = array();
287 if (preg_match('/---(.*)---/', $key, $reg)) {
288 print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
289 } else {
290 print '<tr class="oddeven value">';
291 // Param
292 $label = $langs->trans($key);
293 print '<td>';
294 if (preg_match('/^ACCOUNTING_PRODUCT/', $key)) {
295 print img_picto('', 'product', 'class="pictofixedwidth"');
296 } elseif (preg_match('/^ACCOUNTING_SERVICE/', $key)) {
297 print img_picto('', 'service', 'class="pictofixedwidth"');
298 } elseif (preg_match('/^ACCOUNTING_VAT_PAY_ACCOUNT/', $key)) {
299 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
300 } elseif (preg_match('/^ACCOUNTING_LT1_PAY_ACCOUNT/', $key)) {
301 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
302 } elseif (preg_match('/^ACCOUNTING_LT2_PAY_ACCOUNT/', $key)) {
303 print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
304 } elseif (preg_match('/^ACCOUNTING_VAT/', $key)) {
305 print img_picto('', 'vat', 'class="pictofixedwidth"');
306 } elseif (preg_match('/^ACCOUNTING_LT/', $key)) {
307 print img_picto('', 'vat', 'class="pictofixedwidth"');
308 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_CUSTOMER/', $key)) {
309 print img_picto('', 'bill', 'class="pictofixedwidth"');
310 } elseif (preg_match('/^LOAN_ACCOUNTING_ACCOUNT/', $key)) {
311 print img_picto('', 'loan', 'class="pictofixedwidth"');
312 } elseif (preg_match('/^DONATION_ACCOUNTING/', $key)) {
313 print img_picto('', 'donation', 'class="pictofixedwidth"');
314 } elseif (preg_match('/^ADHERENT_SUBSCRIPTION/', $key)) {
315 print img_picto('', 'member', 'class="pictofixedwidth"');
316 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_TRANSFER/', $key)) {
317 print img_picto('', 'bank_account', 'class="pictofixedwidth"');
318 } elseif (preg_match('/^ACCOUNTING_ACCOUNT_SUSPENSE/', $key)) {
319 print img_picto('', 'question', 'class="pictofixedwidth"');
320 }
321 // Note: account for revenue stamp are store into dictionary of revenue stamp. There is no default value.
322 print $label;
323 print '</td>';
324 // Value
325 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
326 print $formaccounting->select_account(getDolGlobalString($key), $key, 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
327 print '</td>';
328 print '</tr>';
329 }
330}
331
332
333// Customer deposit account
334print '<tr class="oddeven value">';
335// Param
336print '<td>';
337print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT');
338print '</td>';
339// Value
340print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
341print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
342print '</td>';
343print '</tr>';
344
345if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') != '-1') {
346 print '<tr class="oddeven">';
347 print '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnCustomerDeposit") . '</td>';
348 if (getDolGlobalInt('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
349 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
350 print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning');
351 print '</a></td>';
352 } else {
353 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
354 print img_picto($langs->trans("Disabled"), 'switch_off');
355 print '</a></td>';
356 }
357 print '</tr>';
358}
359
360// Supplier deposit account
361print '<tr class="oddeven value">';
362// Param
363print '<td>';
364print img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT');
365print '</td>';
366// Value
367print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
368print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT', 1, [], 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
369print '</td>';
370print '</tr>';
371
372if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') != '-1') {
373 print '<tr class="oddeven">';
374 print '<td>' . img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnSupplierDeposit") . '</td>';
375 if (getDolGlobalInt('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
376 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
377 print img_picto($langs->trans("Activated"), 'switch_on', '', 0, 0, 0, '', 'warning');
378 print '</a></td>';
379 } else {
380 print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
381 print img_picto($langs->trans("Disabled"), 'switch_off');
382 print '</a></td>';
383 }
384 print '</tr>';
385}
386
387print "</table>\n";
388print "</div>\n";
389
390print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
391
392print '</form>';
393
394// End of page
395llxFooter();
396$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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.