dolibarr  17.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-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 (isModEnabled('don')) {
88  $list_account[] = 'DONATION_ACCOUNTINGACCOUNT';
89 }
90 if (isModEnabled('adherent')) {
91  $list_account[] = 'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT';
92 }
93 if (isModEnabled('loan')) {
94  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL';
95  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INTEREST';
96  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE';
97 }
98 $list_account[] = 'ACCOUNTING_ACCOUNT_SUSPENSE';
99 if (isModEnabled('societe')) {
100  $list_account[] = '---Deposits---';
101 }
102 
103 /*
104  * Actions
105  */
106 if ($action == 'update') {
107  $error = 0;
108  // Process $list_account_main
109  foreach ($list_account_main as $constname) {
110  $constvalue = GETPOST($constname, 'alpha');
111 
112  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
113  $error++;
114  }
115  }
116  // Process $list_account
117  foreach ($list_account as $constname) {
118  $reg = array();
119  if (preg_match('/---(.*)---/', $constname, $reg)) { // This is a separator
120  continue;
121  }
122 
123  $constvalue = GETPOST($constname, 'alpha');
124 
125  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
126  $error++;
127  }
128  }
129 
130  $constname = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT';
131  $constvalue = GETPOST($constname, 'int');
132  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
133  $error++;
134  }
135 
136  $constname = 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT';
137  $constvalue = GETPOST($constname, 'int');
138  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
139  $error++;
140  }
141 
142 
143  if (!$error) {
144  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
145  } else {
146  setEventMessages($langs->trans("Error"), null, 'errors');
147  }
148 }
149 
150 if ($action == 'setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT') {
151  $setDisableAuxiliaryAccountOnCustomerDeposit = GETPOST('value', 'int');
152  $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnCustomerDeposit, 'yesno', 0, '', $conf->entity);
153  if (!($res > 0)) {
154  $error++;
155  }
156 
157  if (!$error) {
158  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
159  } else {
160  setEventMessages($langs->trans("Error"), null, 'mesgs');
161  }
162 }
163 
164 if ($action == 'setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT') {
165  $setDisableAuxiliaryAccountOnSupplierDeposit = GETPOST('value', 'int');
166  $res = dolibarr_set_const($db, "ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT", $setDisableAuxiliaryAccountOnSupplierDeposit, 'yesno', 0, '', $conf->entity);
167  if (!($res > 0)) {
168  $error++;
169  }
170 
171  if (!$error) {
172  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
173  } else {
174  setEventMessages($langs->trans("Error"), null, 'mesgs');
175  }
176 }
177 
178 
179 /*
180  * View
181  */
182 
183 $form = new Form($db);
184 $formaccounting = new FormAccounting($db);
185 
186 llxHeader();
187 
188 $linkback = '';
189 print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
190 
191 print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
192 print '<br>';
193 
194 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
195 print '<input type="hidden" name="token" value="'.newToken().'">';
196 print '<input type="hidden" name="action" value="update">';
197 
198 
199 // Define main accounts for thirdparty
200 
201 print '<div class="div-table-responsive-no-min">';
202 print '<table class="noborder centpercent">';
203 print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
204 
205 foreach ($list_account_main as $key) {
206  print '<tr class="oddeven value">';
207  // Param
208  $label = $langs->trans($key);
209  $keydesc = $key.'_Desc';
210 
211  $htmltext = $langs->trans($keydesc);
212  print '<td class="fieldrequired">';
213  if ($key == 'ACCOUNTING_ACCOUNT_CUSTOMER') {
214  print img_picto('', 'company', 'class="pictofixedwidth"');
215  } elseif ($key == 'ACCOUNTING_ACCOUNT_SUPPLIER') {
216  print img_picto('', 'company', 'class="pictofixedwidth"');
217  } else {
218  print img_picto('', 'user', 'class="pictofixedwidth"');
219  }
220  print $form->textwithpicto($label, $htmltext);
221  print '</td>';
222  // Value
223  print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
224  $key_value = getDolGlobalString($key);
225  print $formaccounting->select_account($key_value, $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accountsmain');
226  print '</td>';
227  print '</tr>';
228 }
229 print "</table>\n";
230 print "</div>\n";
231 
232 
233 print '<div class="div-table-responsive-no-min">';
234 print '<table class="noborder centpercent">';
235 
236 foreach ($list_account as $key) {
237  $reg = array();
238  if (preg_match('/---(.*)---/', $key, $reg)) {
239  print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
240  } else {
241  print '<tr class="oddeven value">';
242  // Param
243  $label = $langs->trans($key);
244  print '<td>';
245  if (preg_match('/^ACCOUNTING_PRODUCT/', $key)) {
246  print img_picto('', 'product', 'class="pictofixedwidth"');
247  } elseif (preg_match('/^ACCOUNTING_SERVICE/', $key)) {
248  print img_picto('', 'service', 'class="pictofixedwidth"');
249  } elseif (preg_match('/^ACCOUNTING_VAT_PAY_ACCOUNT/', $key)) {
250  print img_picto('', 'payment_vat', 'class="pictofixedwidth"');
251  } elseif (preg_match('/^ACCOUNTING_VAT/', $key)) {
252  print img_picto('', 'vat', 'class="pictofixedwidth"');
253  } elseif (preg_match('/^ACCOUNTING_ACCOUNT_CUSTOMER/', $key)) {
254  print img_picto('', 'bill', 'class="pictofixedwidth"');
255  } elseif (preg_match('/^LOAN_ACCOUNTING_ACCOUNT/', $key)) {
256  print img_picto('', 'loan', 'class="pictofixedwidth"');
257  } elseif (preg_match('/^DONATION_ACCOUNTING/', $key)) {
258  print img_picto('', 'donation', 'class="pictofixedwidth"');
259  } elseif (preg_match('/^ADHERENT_SUBSCRIPTION/', $key)) {
260  print img_picto('', 'member', 'class="pictofixedwidth"');
261  } elseif (preg_match('/^ACCOUNTING_ACCOUNT_TRANSFER/', $key)) {
262  print img_picto('', 'bank_account', 'class="pictofixedwidth"');
263  } elseif (preg_match('/^ACCOUNTING_ACCOUNT_SUSPENSE/', $key)) {
264  print img_picto('', 'question', 'class="pictofixedwidth"');
265  }
266  print $label;
267  print '</td>';
268  // Value
269  print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
270  print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
271  print '</td>';
272  print '</tr>';
273  }
274 }
275 
276 
277 // Customer deposit account
278 print '<tr class="oddeven value">';
279 // Param
280 print '<td>';
281 print img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT');
282 print '</td>';
283 // Value
284 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
285 print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
286 print '</td>';
287 print '</tr>';
288 
289 if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT') != '-1') {
290  print '<tr class="oddeven">';
291  print '<td>' . img_picto('', 'bill', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnCustomerDeposit") . '</td>';
292  if (getDolGlobalInt('ACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT')) {
293  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
294  print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning');
295  print '</a></td>';
296  } else {
297  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_CUSTOMER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
298  print img_picto($langs->trans("Disabled"), 'switch_off');
299  print '</a></td>';
300  }
301  print '</tr>';
302 }
303 
304 // Supplier deposit account
305 print '<tr class="oddeven value">';
306 // Param
307 print '<td>';
308 print img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT');
309 print '</td>';
310 // Value
311 print '<td class="right">'; // Do not force class=right, or it align also the content of the select box
312 print $formaccounting->select_account(getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT'), 'ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT', 1, '', 1, 1, 'minwidth100 maxwidth300 maxwidthonsmartphone', 'accounts');
313 print '</td>';
314 print '</tr>';
315 
316 if (isModEnabled('societe') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') && getDolGlobalString('ACCOUNTING_ACCOUNT_SUPPLIER_DEPOSIT') != '-1') {
317  print '<tr class="oddeven">';
318  print '<td>' . img_picto('', 'supplier_invoice', 'class="pictofixedwidth"') . $langs->trans("UseAuxiliaryAccountOnSupplierDeposit") . '</td>';
319  if (getDolGlobalInt('ACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT')) {
320  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=0">';
321  print img_picto($langs->trans("Activated"), 'switch_on', '', false, 0, 0, '', 'warning');
322  print '</a></td>';
323  } else {
324  print '<td class="right"><a class="reposition" href="' . $_SERVER['PHP_SELF'] . '?token=' . newToken() . '&action=setACCOUNTING_ACCOUNT_SUPPLIER_USE_AUXILIARY_ON_DEPOSIT&value=1">';
325  print img_picto($langs->trans("Disabled"), 'switch_off');
326  print '</a></td>';
327  }
328  print '</tr>';
329 }
330 
331 print "</table>\n";
332 print "</div>\n";
333 
334 print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Save').'"></div>';
335 
336 print '</form>';
337 
338 // End of page
339 llxFooter();
340 $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).
Definition: admin.lib.php:632
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
llxFooter()
Empty footer.
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.
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
getDolGlobalInt($key, $default=0)
Return 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)
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return 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.