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