noalyss Version-9
periode.inc.php
Go to the documentation of this file.
1<?php
2/*
3 * This file is part of NOALYSS.
4 *
5 * NOALYSS is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * NOALYSS is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with NOALYSS; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19// Copyright Author Dany De Bontridder danydb@aevalys.eu
20/*! \file
21 * \brief add, modify, close or delete a period
22 */
23if (!defined('ALLOWED'))
24 die('Appel direct ne sont pas permis');
26echo '<div class="content">';
28//-----------------------------------------------------
29// Periode
30//-----------------------------------------------------
32
33$p_ledger_id=$http->request("jrn_def_id", "number", 0);
34?>
35<script>
36 var jsper = new Periode(<?php echo $p_ledger_id; ?>);
37 jsper.set_callback("ajax_misc.php");
38 jsper.set_js_obj_name("jsper");
39 jsper.set_dossier('<?php echo Dossier::id(); ?>');
40
41</script>
42<?php
43//-------------------------------------------------------------------
44//Modify exercice label
45//-------------------------------------------------------------------
46if ( isset($_POST['mod_exercice_label_bt'])) {
47 $err = 0;
48 $p_exercice_label=$http->post("p_exercice_label");
49 $p_exercice=$http->post("p_exercice");
50 if (empty(trim($p_exercice_label))) {
51 echo_warning(_("Libellé exercice ne peut pas être vide"));
52 $err =1;
53 }
54 if ($err == 0 && $cn->get_value("select count(*) from parm_periode where p_exercice_label=$1 and p_exercice <>$2",
55 [$p_exercice_label,$p_exercice]) > 0)
56 {
57 echo_warning(_("Le même libellé ne peut pas être utilisé pour 2 exercices"));
58 $err=1;
59 }
60
61 if ($err == 0) {
62 try
63 {
64 $cn->start();
65 /**
66 * @todo
67 * Rewrite : split table parm_periode into parm_periode and parm_exercice
68 * disabling temporarily a trigger is not the right solution ,
69 * but make the trigger more flexible and less secure
70 * is worst. The trigger is disable in a transaction means it is still enable
71 * for other session.
72 */
73 $cn->exec_sql("alter table parm_periode disable trigger parm_periode_check_periode_trg");
74 $cn->exec_sql("update parm_periode set p_exercice_label=$1 where p_exercice=$2",
75 [$p_exercice_label,$p_exercice]);
76 $cn->exec_sql("alter table parm_periode enable trigger parm_periode_check_periode_trg");
77 $cn->commit();
78
79 }
80 catch (Exception $exc)
81 {
82 echo_warning( $exc->getMessage());
83 error_log($exc->getTraceAsString());
84 $cn->rollback();
85 }
86
87 }
88}
89//--------------------------------------------------------------------
90// Add an exercice
91// receive nb_exercice
92//--------------------------------------------------------------------
93if (isset($_POST['add_exercice']))
94{
95 $obj=new Periode($cn);
96 try
97 {
98 $p_exercice=$http->post("p_exercice", "number");
99 $p_exercice_label=$http->post("p_exercice_label", "string");
100 $p_year=$http->post("p_year", "number");
101 $nb_month=$http->post("nb_month", "number");
102 $from_month=$http->post("from_month", "number");
103 $day_opening=$http->post("day_opening", "string", 0);
104 $day_closing=$http->post("day_closing", "string", 0);
105 $exercice=new Periode($cn);
106 $exercice->insert_exercice($p_exercice, $p_year, $from_month, $nb_month,
107 $day_opening, $day_closing,$p_exercice_label);
108 }
109 catch (Exception $ex)
110 {
111 echo_warning($ex->getMessage());
112 }
113}
114//-------------------------------------------------------------------
115// Select a ledger or global
116//-------------------------------------------------------------------
117echo '<form method="GET" >';
118echo dossier::hidden();
119$sel_jrn=$cn->make_array("select jrn_def_id, jrn_def_name from ".
120 " jrn_def order by jrn_def_name");
121$sel_jrn[]=array('value'=>0, 'label'=>_('Global : periode pour tous les journaux'));
124$wSel->name='jrn_def_id';
126echo _("Choisissez global ou uniquement le journal à fermer").$wSel->input();
127echo HtmlInput::hidden('ac', $http->request('ac'));
128// display a filter by exercice
129echo _("Montrer l'exercice");
130$max_exercice=$cn->get_value("select max(p_exercice) from parm_periode");
131$p_exercice=$http->request("p_exercice_sel","string",$max_exercice);
133$js_close_selected="jsper.close_selected()";
134
135echo HtmlInput::submit('choose', 'Valider');
136echo "</form>";
137
138echo HtmlInput::button_action(_("Fermer les périodes sélectionnées"),
140
141/*
142 * Display all the periode for all ledgers
143 */
144if ($p_ledger_id==0)
145{
146 echo HtmlInput::button_action(_("Ajout exercice"),
147 "\$('exercice_add').show()");
148//-------------------------------------------------------------------
149// Add a new Exercice
150//-------------------------------------------------------------------
151 echo '<div id="exercice_add" style="display:none" class="inner_box">';
153 echo '</div>';
154//-------------------------------------------------------------------
155// Add a new Periode
156//-------------------------------------------------------------------
157 echo HtmlInput::button_action(_("Ajout période"), "\$('periode_add').show()");
158 echo '<div id="periode_add" style="display:none;width:auto" class="inner_box">';
160 echo '</div>';
161//-------------------------------------------------------------------
162// Change label of Exercice
163//-------------------------------------------------------------------
164 echo HtmlInput::button_action(_("Modifie libellé exercice"), "\$('exercice_label_div').show()");
165 echo '<div id="exercice_label_div" style="display:none;width:60ch" class="inner_box">';
167 echo '</div>';
168
169//-------------------------------------------------------------------
170// List of Periode
171//-------------------------------------------------------------------
172 $periode=new Parm_Periode_SQL($cn);
174}
175else
176{
177 echo '<p class="info">'._("Pour ajouter, effacer ou modifier une période, il faut choisir global").'</p>';
179 echo h2($ledger->get_name());
180
182 $ret=$periode_ledger->get_resource_periode_ledger($p_ledger_id);
183 $periode_ledger->display_table($ret, "jsper");
184}
185
186echo '</div>';
187?>
188<script>
189 Periode.filter_exercice('periode_tbl');
190 activate_checkbox_range("sel_per_close_ck");
191</script>
h2($p_string, $p_class="", $raw="")
Definition: ac_common.php:68
echo_warning($p_string)
warns
Definition: ac_common.php:589
$err
catch(Exception $e) $exercice
$input_from id
Definition: balance.inc.php:63
$ex
Definition: balance.inc.php:45
static connect()
static button_action($action, $javascript, $id=NULL, $p_class="button", $p_symbole="")
button Html with javascript
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
manage the http input (get , post, request) and extract from an array
Html Input , create a tag <SELECT> ... </SELECT> if readonly == true then display the label correspon...
Display the periode per ledger: close : reopen ... the close , open must be done thanks Periode.
For the periode tables parm_periode and jrn_periode.
static form_exercice_add()
display a form (method POST) to input a new exercice variable in the FORM
static form_periode_add($p_js_var)
Display a form for the input of a new periode.
static form_exercice_label()
form to change the label of exercice
static filter_exercice($p_sel)
static display_periode_global($p_js)
Display a table with all the periode.
$_POST['ac']
Definition: do.php:310
$gDossier
Definition: periode.inc.php:25
$p_exercice
$cn
Definition: periode.inc.php:27
$p_ledger_id
Definition: periode.inc.php:33
$ledger
$wSel
$http
Definition: periode.inc.php:31
$max_exercice
$js_close_selected
$periode_ledger
$sel_jrn
$ret