dolibarr  16.0.5
closure.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2019 Alexandre Spangaro <aspangaro@open-dsi.fr>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <https://www.gnu.org/licenses/>.
16  *
17  */
18 
25 require '../../main.inc.php';
26 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
27 require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formaccounting.class.php';
29 
30 // Load translation files required by the page
31 $langs->loadLangs(array("compta", "admin", "accountancy"));
32 
33 // Security check
34 if (empty($user->rights->accounting->chartofaccount)) {
36 }
37 
38 $action = GETPOST('action', 'aZ09');
39 
40 
41 $list_account_main = array(
42  'ACCOUNTING_RESULT_PROFIT',
43  'ACCOUNTING_RESULT_LOSS'
44 );
45 
46 /*
47  * Actions
48  */
49 
50 if ($action == 'update') {
51  $error = 0;
52 
53  $defaultjournal = GETPOST('ACCOUNTING_CLOSURE_DEFAULT_JOURNAL', 'alpha');
54 
55  if (!empty($defaultjournal)) {
56  if (!dolibarr_set_const($db, 'ACCOUNTING_CLOSURE_DEFAULT_JOURNAL', $defaultjournal, 'chaine', 0, '', $conf->entity)) {
57  $error++;
58  }
59  } else {
60  $error++;
61  }
62 
63  foreach ($list_account_main as $constname) {
64  $constvalue = GETPOST($constname, 'alpha');
65  if (!dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) {
66  $error++;
67  }
68  }
69 
70  if (!$error) {
71  setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
72  } else {
73  setEventMessages($langs->trans("Error"), null, 'errors');
74  }
75 }
76 
77 
78 /*
79  * View
80  */
81 
82 $form = new Form($db);
83 $formaccounting = new FormAccounting($db);
84 
85 llxHeader();
86 
87 $linkback = '';
88 print load_fiche_titre($langs->trans('MenuClosureAccounts'), $linkback, 'title_accountancy');
89 
90 print '<span class="opacitymedium">'.$langs->trans("DefaultClosureDesc").'</span><br>';
91 print '<br>';
92 
93 print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
94 print '<input type="hidden" name="token" value="'.newToken().'">';
95 print '<input type="hidden" name="action" value="update">';
96 
97 // Define main accounts for closure
98 print '<table class="noborder centpercent">';
99 
100 foreach ($list_account_main as $key) {
101  print '<tr class="oddeven value">';
102  // Param
103  $label = $langs->trans($key);
104  $keydesc = $key.'_Desc';
105 
106  $htmltext = $langs->trans($keydesc);
107  print '<td class="fieldrequired" width="50%">';
108  print $form->textwithpicto($label, $htmltext);
109  print '</td>';
110  // Value
111  print '<td>'; // Do not force class=right, or it align also the content of the select box
112  print $formaccounting->select_account(getDolGlobalString($key), $key, 1, '', 1, 1);
113  print '</td>';
114  print '</tr>';
115 }
116 
117 // Journal
118 print '<tr class="oddeven">';
119 print '<td width="50%">'.$langs->trans("ACCOUNTING_CLOSURE_DEFAULT_JOURNAL").'</td>';
120 print '<td>';
121 $defaultjournal = $conf->global->ACCOUNTING_CLOSURE_DEFAULT_JOURNAL;
122 print $formaccounting->select_journal($defaultjournal, "ACCOUNTING_CLOSURE_DEFAULT_JOURNAL", 9, 1, 0, 0);
123 print '</td></tr>';
124 
125 print "</table>\n";
126 
127 print '<div class="center"><input type="submit" class="button button-edit" name="button" value="'.$langs->trans('Modify').'"></div>';
128 
129 print '</form>';
130 
131 // End of page
132 llxFooter();
133 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
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:484
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
FormAccounting
Class to manage generation of HTML components for accounting management.
Definition: html.formaccounting.class.php:33
getDolGlobalString
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
Definition: functions.lib.php:80
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:627
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:8137
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59