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