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