dolibarr  9.0.0
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-2017 Alexandre Spangaro <aspangaro@zendsi.com>
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 <http://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 (empty($user->rights->accounting->chartofaccount))
42 {
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 
55 $list_account = array (
56  'ACCOUNTING_PRODUCT_BUY_ACCOUNT',
57  'ACCOUNTING_PRODUCT_SOLD_ACCOUNT',
58  'ACCOUNTING_SERVICE_BUY_ACCOUNT',
59  'ACCOUNTING_SERVICE_SOLD_ACCOUNT',
60  'ACCOUNTING_VAT_BUY_ACCOUNT',
61  'ACCOUNTING_VAT_SOLD_ACCOUNT',
62  'ACCOUNTING_VAT_PAY_ACCOUNT',
63  'ACCOUNTING_ACCOUNT_SUSPENSE',
64  'ACCOUNTING_ACCOUNT_TRANSFER_CASH',
65  'DONATION_ACCOUNTINGACCOUNT',
66  'LOAN_ACCOUNTING_ACCOUNT_CAPITAL',
67  'LOAN_ACCOUNTING_ACCOUNT_INTEREST',
68  'LOAN_ACCOUNTING_ACCOUNT_INSURANCE'
69 );
70 
71 
72 /*
73  * Actions
74  */
75 
76 $accounting_mode = empty($conf->global->ACCOUNTING_MODE) ? 'RECETTES-DEPENSES' : $conf->global->ACCOUNTING_MODE;
77 
78 
79 if (GETPOST('change_chart', 'alpha'))
80 {
81  $chartofaccounts = GETPOST('chartofaccounts', 'int');
82 
83  if (! empty($chartofaccounts)) {
84 
85  if (! dolibarr_set_const($db, 'CHARTOFACCOUNTS', $chartofaccounts, 'chaine', 0, '', $conf->entity)) {
86  $error ++;
87  }
88  } else {
89  $error ++;
90  }
91 }
92 
93 if ($action == 'update') {
94  $error = 0;
95 
96  foreach ( $list_account_main as $constname ) {
97  $constvalue = GETPOST($constname, 'alpha');
98 
99  if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
100  $error ++;
101  }
102  }
103 
104  foreach ( $list_account as $constname ) {
105  $constvalue = GETPOST($constname, 'alpha');
106 
107  if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
108  $error ++;
109  }
110  }
111 
112  if (! $error) {
113  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
114  } else {
115  setEventMessages($langs->trans("Error"), null, 'errors');
116  }
117 }
118 
119 
120 /*
121  * View
122  */
123 
124 $form = new Form($db);
125 $formaccounting = new FormAccounting($db);
126 
127 llxHeader();
128 
129 $linkback = '';
130 print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
131 
132 print $langs->trans("DefaultBindingDesc").'<br>';
133 print '<br>';
134 
135 print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post">';
136 print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
137 print '<input type="hidden" name="action" value="update">';
138 
139 
140 // Define main accounts for thirdparty
141 
142 print '<table class="noborder" width="100%">';
143 
144 foreach ($list_account_main as $key) {
145 
146  print '<tr class="oddeven value">';
147  // Param
148  $label = $langs->trans($key);
149  $keydesc=$key.'_Desc';
150 
151  $htmltext = $langs->trans($keydesc);
152  print '<td class="fieldrequired" width="50%">';
153  print $form->textwithpicto($label, $htmltext);
154  print '</td>';
155  // Value
156  print '<td>'; // Do not force align=right, or it align also the content of the select box
157  print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
158  print '</td>';
159  print '</tr>';
160 }
161 
162 
163 print "</table>\n";
164 
165 
166 print '<br>';
167 
168 // Define default accounts
169 
170 print '<table class="noborder" width="100%">';
171 
172 foreach ($list_account as $key) {
173 
174  print '<tr class="oddeven value">';
175  // Param
176  $label = $langs->trans($key);
177  print '<td width="50%">' . $label . '</td>';
178  // Value
179  print '<td>'; // Do not force align=right, or it align also the content of the select box
180  print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
181  print '</td>';
182  print '</tr>';
183 }
184 
185 
186 print "</table>\n";
187 
188 
189 print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('Modify') . '" name="button"></div>';
190 
191 print '</form>';
192 
193 // End of page
194 llxFooter();
195 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
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:510
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
llxHeader()
Empty header.
Definition: wrapper.php:44
Class to manage generation of HTML components for accounting management.