dolibarr  13.0.2
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 (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 $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 $list_account[] = '---Service---';
68 $list_account[] = 'ACCOUNTING_SERVICE_SOLD_ACCOUNT';
69 if ($mysoc->isInEEC()) {
70  $list_account[] = 'ACCOUNTING_SERVICE_SOLD_INTRA_ACCOUNT';
71 }
72 $list_account[] = 'ACCOUNTING_SERVICE_SOLD_EXPORT_ACCOUNT';
73 $list_account[] = 'ACCOUNTING_SERVICE_BUY_ACCOUNT';
74 if ($mysoc->isInEEC()) {
75  $list_account[] = 'ACCOUNTING_SERVICE_BUY_INTRA_ACCOUNT';
76 }
77 $list_account[] = 'ACCOUNTING_SERVICE_BUY_EXPORT_ACCOUNT';
78 $list_account[] = '---Others---';
79 $list_account[] = 'ACCOUNTING_VAT_BUY_ACCOUNT';
80 $list_account[] = 'ACCOUNTING_VAT_SOLD_ACCOUNT';
81 $list_account[] = 'ACCOUNTING_VAT_PAY_ACCOUNT';
82 $list_account[] = 'ACCOUNTING_ACCOUNT_SUSPENSE';
83 if ($conf->banque->enabled) {
84  $list_account[] = 'ACCOUNTING_ACCOUNT_TRANSFER_CASH';
85 }
86 if ($conf->don->enabled) {
87  $list_account[] = 'DONATION_ACCOUNTINGACCOUNT';
88 }
89 if ($conf->adherent->enabled) {
90  $list_account[] = 'ADHERENT_SUBSCRIPTION_ACCOUNTINGACCOUNT';
91 }
92 if ($conf->loan->enabled) {
93  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL';
94  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INTEREST';
95  $list_account[] = 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE';
96 }
97 if ($conf->societe->enabled) {
98  $list_account[] = 'ACCOUNTING_ACCOUNT_CUSTOMER_DEPOSIT';
99 }
100 
101 /*
102  * Actions
103  */
104 if ($action == 'update') {
105  $error = 0;
106 
107  foreach ($list_account_main as $constname) {
108  $constvalue = GETPOST($constname, 'alpha');
109 
110  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
111  $error++;
112  }
113  }
114 
115  foreach ($list_account as $constname) {
116  $reg = array();
117  if (preg_match('/---(.*)---/', $constname, $reg)) { // This is a separator
118  continue;
119  }
120 
121  $constvalue = GETPOST($constname, 'alpha');
122 
123  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
124  $error++;
125  }
126  }
127 
128  if (!$error) {
129  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
130  } else {
131  setEventMessages($langs->trans("Error"), null, 'errors');
132  }
133 }
134 
135 
136 /*
137  * View
138  */
139 
140 $form = new Form($db);
141 $formaccounting = new FormAccounting($db);
142 
143 llxHeader();
144 
145 $linkback = '';
146 print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy');
147 
148 print '<span class="opacitymedium">'.$langs->trans("DefaultBindingDesc").'</span><br>';
149 print '<br>';
150 
151 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
152 print '<input type="hidden" name="token" value="'.newToken().'">';
153 print '<input type="hidden" name="action" value="update">';
154 
155 
156 // Define main accounts for thirdparty
157 
158 print '<table class="noborder centpercent">';
159 print '<tr class="liste_titre"><td>'.$langs->trans("ThirdParties").' | '.$langs->trans("Users").'</td><td></td></tr>';
160 
161 foreach ($list_account_main as $key) {
162  print '<tr class="oddeven value">';
163  // Param
164  $label = $langs->trans($key);
165  $keydesc = $key.'_Desc';
166 
167  $htmltext = $langs->trans($keydesc);
168  print '<td class="fieldrequired" width="50%">';
169  print $form->textwithpicto($label, $htmltext);
170  print '</td>';
171  // Value
172  print '<td>'; // Do not force class=right, or it align also the content of the select box
173  print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
174  print '</td>';
175  print '</tr>';
176 }
177 
178 
179 foreach ($list_account as $key) {
180  $reg = array();
181  if (preg_match('/---(.*)---/', $key, $reg)) {
182  print '<tr class="liste_titre"><td>'.$langs->trans($reg[1]).'</td><td></td></tr>';
183  } else {
184  print '<tr class="oddeven value">';
185  // Param
186  $label = $langs->trans($key);
187  print '<td width="50%">'.$label.'</td>';
188  // Value
189  print '<td>'; // Do not force class=right, or it align also the content of the select box
190  print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1);
191  print '</td>';
192  print '</tr>';
193  }
194 }
195 
196 
197 print "</table>\n";
198 
199 
200 print '<div class="center"><input type="submit" class="button" value="'.$langs->trans('Modify').'" name="button"></div>';
201 
202 print '</form>';
203 
204 // End of page
205 llxFooter();
206 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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:575
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print
Draft customers invoices.
Definition: index.php:89
Class to manage generation of HTML components for accounting management.
llxFooter()
Empty footer.
Definition: wrapper.php:59