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