dolibarr  18.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-2020 Alexandre Spangaro <aspangaro@open-dsi.fr>
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 
30 require '../../main.inc.php';
31 
32 // Class
33 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
35 require_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
41 if (!$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';
58 if ($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';
63 if ($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';
70 if ($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';
75 if ($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_BUY_ACCOUNT';
82 $list_account[] = 'ACCOUNTING_VAT_SOLD_ACCOUNT';
83 $list_account[] = 'ACCOUNTING_VAT_PAY_ACCOUNT';
84 if (isModEnabled('banque')) {
85  $list_account[] = 'ACCOUNTING_ACCOUNT_TRANSFER_CASH';
86 }
87 if (!empty($conf->global->INVOICE_USE_RETAINED_WARRANTY)) {
88  $list_account[] = 'ACCOUNTING_ACCOUNT_CUSTOMER_RETAINED_WARRANTY';
89 }
90 if (isModEnabled('don')) {
91  $list_account[] = 'DONATION_ACCOUNTINGACCOUNT';
92 }
93 if (isModEnabled('adherent')) {
94  $list_account[] = 'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT';
95 }
96 if (isModEnabled('loan')) {
97  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL';
98  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INTEREST';
99  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE';
100 }
101 $list_account[] = 'ACCOUNTING_ACCOUNT_SUSPENSE';
102 if (isModEnabled('societe')) {
103  $list_account[] = '---Deposits---';
104 }
105 
106 /*
107  * Actions
108  */
109 if ($action == 'update') {
110  $error = 0;
111  // Process $list_account_main
112  foreach ($list_account_main as $constname) {
113  $constvalue = GETPOST($constname, 'alpha');
114 
115  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
116  $error++;
117  }
118  }
119  // Process $list_account
120  foreach ($list_account as $constname) {
121  $reg = array();
122  if (preg_match('/---(.*)---/', $constname, $reg)) { // This is a separator
123  continue;
124  }
125 
126  $constvalue = GETPOST($constname, 'alpha');
127 
128  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
129  $error++;
130  }
131  }
132 
133  $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT';
134  $constvalue = GETPOST($constname, 'int');
135  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
136  $error++;
137  }
138 
139  $constname = 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT';
140  $constvalue = GETPOST($constname, 'int');
141  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
142  $error++;
143  }
144 
145 
146  if (!$error) {
147  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
148  } else {
149  setEventMessages($langs->trans("Error"), null, 'errors');
150  }
151 }
152 
153 if ($action == 'setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT') {
154  $setDisableAuxiliaryAccountOnCustomerDeposit = GETPOST('value', 'int');
155  $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnCustomerDeposit, 'yesno', 0, '', $conf->entity);
156  if (!($res > 0)) {
157  $error++;
158  }
159 
160  if (!$error) {
161  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
162  } else {
163  setEventMessages($langs->trans("Error"), null, 'mesgs');
164  }
165 }
166 
167 if ($action == 'setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT') {
168  $setDisableAuxiliaryAccountOnSupplierDeposit = GETPOST('value', 'int');
169  $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnSupplierDeposit, 'yesno', 0, '', $conf->entity);
170  if (!($res > 0)) {
171  $error++;
172  }
173 
174  if (!$error) {
175  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
176  } else {
177  setEventMessages($langs->trans("Error"), null, 'mesgs');
178  }
179 }
180 
181 
182 /*
183  * View
184  */
185 
186 $form = new Form($db);
187 $formaccounting = new FormAccounting($db);
188 
189 llxHeader();
190 
191 $linkback = '';
192 print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
193 
194 print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
195 print '<br>';
196 
197 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
198 print '<input type="hidden" name="token" value="'.newToken().'">';
199 print '<input type="hidden" name="action" value="update">';
200 
201 
202 // Define main accounts for thirdparty
203 
204 print '<div class="div-table-responsive-no-min">';
205 print '<table class="noborder centpercent">';
206 print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
207 
208 foreach ($list_account_main as $key) {
209  print '<tr class="oddeven value">';
210  // Param
211  $label = $langs->trans($key);
212  $keydesc = $key.'_Desc';
213 
214  $htmltext = $langs->trans($keydesc);
215  print '<td class="fieldrequired">';
216  if ($key == 'ACCOUNTING_ACCOUNT_CUSTOMER') {
217  print img_picto('', 'company', 'class="pictofixedwidth"');
218  } elseif ($key == 'ACCOUNTING_ACCOUNT_SUPPLIER') {
219  print img_picto('', 'company', 'class="pictofixedwidth"');
220  } else {
221  print img_picto('', 'user', 'class="pictofixedwidth"');
222  }
223  print $form->textwithpicto($label, $htmltext);
224  print '</td>';
225  // Value
226  print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
227  $key_value = getDolGlobalString($key);
228  print $formaccounting->select_account($key_value, $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accountsmain');
229  print '</td>';
230  print '</tr>';
231 }
232 print "</table>\n";
233 print "</div>\n";
234 
235 
236 print '<div class="div-table-responsive-no-min">';
237 print '<table class="noborder centpercent">';
238 
239 foreach ($list_account as $key) {
240  $reg = array();
241  if (preg_match('/---(.*)---/', $key, $reg)) {
242  print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
243  } else {
244  print '<tr class="oddeven value">';
245  // Param
246  $label = $langs->trans($key);
247  print '<td>';
248  if (preg_match('/^ACCOUNTING_PRODUCT/', $key)) {
249  print img_picto('', 'product', 'class="pictofixedwidth"');
250  } elseif (preg_match('/^ACCOUNTING_SERVICE/', $key)) {
251  print img_picto('', 'service', 'class="pictofixedwidth"');
252  } elseif (preg_match('/^ACCOUNTING_VAT_PAY_ACCOUNT/', $key)) {
253  print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
254  } elseif (preg_match('/^ACCOUNTING_VAT/', $key)) {
255  print img_picto('', 'vat', 'class="pictofixedwidth"');
256  } elseif (preg_match('/^ACCOUNTING_ACCOUNT_CUSTOMER/', $key)) {
257  print img_picto('', 'bill', 'class="pictofixedwidth"');
258  } elseif (preg_match('/^LOAN_ACCOUNTING_ACCOUNT/', $key)) {
259  print img_picto('', 'loan', 'class="pictofixedwidth"');
260  } elseif (preg_match('/^DONATION_ACCOUNTING/', $key)) {
261  print img_picto('', 'donation', 'class="pictofixedwidth"');
262  } elseif (preg_match('/^ADHERENT_SUBSCRIPTION/', $key)) {
263  print img_picto('', 'member', 'class="pictofixedwidth"');
264  } elseif (preg_match('/^ACCOUNTING_ACCOUNT_TRANSFER/', $key)) {
265  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
266  } elseif (preg_match('/^ACCOUNTING_ACCOUNT_SUSPENSE/', $key)) {
267  print img_picto('', 'question', 'class="pictofixedwidth"');
268  }
269  print $label;
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  print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
274  print '</td>';
275  print '</tr>';
276  }
277 }
278 
279 
280 // Customer deposit account
281 print '<tr class="oddeven value">';
282 // Param
283 print '<td>';
284 print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT');
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('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
289 print '</td>';
290 print '</tr>';
291 
292 if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') != '-1') {
293  print '<tr class="oddeven">';
294  print '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnCustomerDeposit") . '</td>';
295  if (getDolGlobalInt('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
296  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
297  print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning');
298  print '</a></td>';
299  } else {
300  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
301  print img_picto($langs->trans("Disabled"), 'switch_off');
302  print '</a></td>';
303  }
304  print '</tr>';
305 }
306 
307 // Supplier deposit account
308 print '<tr class="oddeven value">';
309 // Param
310 print '<td>';
311 print img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT');
312 print '</td>';
313 // Value
314 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
315 print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
316 print '</td>';
317 print '</tr>';
318 
319 if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') != '-1') {
320  print '<tr class="oddeven">';
321  print '<td>' . img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnSupplierDeposit") . '</td>';
322  if (getDolGlobalInt('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
323  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
324  print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning');
325  print '</a></td>';
326  } else {
327  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
328  print img_picto($langs->trans("Disabled"), 'switch_off');
329  print '</a></td>';
330  }
331  print '</tr>';
332 }
333 
334 print "</table>\n";
335 print "</div>\n";
336 
337 print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
338 
339 print '</form>';
340 
341 // End of page
342 llxFooter();
343 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5363
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:530
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
img_picto
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Definition: functions.lib.php:4025
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:82
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:11317
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:147
dolibarr_set_const
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).
Definition: admin.lib.php:633
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8509
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
Definition: security.lib.php:1106
getDolGlobalInt
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
Definition: functions.lib.php:96