noalyss Version-9
ajax_periode.php
Go to the documentation of this file.
1<?php
2
3/*
4 * This file is part of NOALYSS.
5 *
6 * PhpCompta is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * NOALYSS is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PhpCompta; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20// Copyright (2016) Author Dany De Bontridder <dany@alchimerys.be>
21
22if (!defined('ALLOWED'))
23 die('Appel direct ne sont pas permis');
24
25/**
26 * @file
27 * @brief display or save a periode variable received $op, $cn $g_user
28 * variable :
29 * act
30 * - close : close a periode
31 * - reopen : reopen a periode
32 * - show : display a form for modifying / adding a period
33 * - remove : delete a period IF not used
34 *
35 * ledger_id is the SQL id of ledger
36 *
37 * p_id is either the SQL id of parm_periode of jrn_periode, depending if
38 * ledger_id == 0 or not
39 * The answer must be in JSON
40 */
41
44$a_answer['status']="NOK";
46try
47{
48// action to perform
49 $act=$http->request("act");
50// Periode id
51 $periode_id=$http->request("p_id", "number");
52// Ledger id
53 $ledger_id=$http->request("ledger_id", "number");
54// Name of the javascript variable
55 $js_var=$http->request("js_var");
56}
57catch (Exception $ex)
58{
59 $a_answer['content']=$ex->getMessage();
60 $jsson=json_encode($a_answer,
61 JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
62 header('Content-Type: application/json;charset=utf-8');
63 echo $jsson;
64 return;
65}
66/* we check the security */
67if ($g_user->check_module("PERIODE")==0)
68{
69 return;
70}
71
72switch ($act)
73{
74// Reopen a periode for specific ledger if ledger_id != 0, or all
75// the periodes if ledger_id=0
76 case 'reopen':
77 try
78 {
79 if ($ledger_id==0)
80 {
82 $per->set_ledger(0);
83 $per->reopen();
84 $parm_periode=new Parm_periode_SQL($cn, $periode_id);
85 ob_start();
86 Periode::display_row_global($parm_periode, 0, $js_var);
87 $a_answer['content']=ob_get_clean();
88 }
89 else
90 {
91 $id=$http->post("p_id", "number");
92 $jrn_periode=new Jrn_periode_SQL($cn, $p_id);
93 $per_led=new Periode_Ledger($jrn_periode);
94 $per_led->reopen();
95 ob_start();
96 $per_led_table=new Periode_Ledger_Table($periode_id);
97 $per_led_table->display_row($per_led_table->get_a_member(), 0,
98 $js_var);
99 $a_answer['content']=ob_get_clean();
100 }
101 $a_answer["status"]="OK";
102 }
103 catch (Exception $ex)
104 {
105 $a_answer['content']=$ex->getMessage();
106 }
107 break;
108// Close a periode for specific ledger if ledger_id != 0, or all
109// the periodes if ledger_id=0
110 case 'close':
111 try
112 {
113 if ($ledger_id==0)
114 {
116 $per->close();
117 $parm_periode=new Parm_periode_SQL($cn, $periode_id);
118 ob_start();
119 Periode::display_row_global($parm_periode, 0, $js_var);
120 $a_answer['content']=ob_get_clean();
121 }
122 else
123 {
124 $jrn_periode=new Jrn_periode_SQL($cn, $periode_id);
125 $per_led=new Periode_Ledger($jrn_periode);
126 $per_led->close();
127 ob_start();
128 $per_led_table=new Periode_Ledger_Table($periode_id);
129 $per_led_table->display_row($per_led_table->get_a_member(), 0,
130 $js_var);
131 $a_answer['content']=ob_get_clean();
132 }
133 $a_answer["status"]="OK";
134 }
135 catch (Exception $ex)
136 {
137 $a_answer['content']=$ex->getMessage();
138 }
139 break;
140// Add a new periode , only if ledger_id == 0
141 case 'show':
143 $per->load();
144
145 $p_exercice=new INum('p_exercice');
146 $limit=$per->get_date_limit($periode_id);
147 $p_exercice->value=$per->p_exercice;
148 $title=_('Modification période');
149 $title_par="<p>"._('Modifier les dates de début et fin de période').
150 "</p>";
151 $title_par.='<p class="notice">'._('Cela pourrait avoir un impact sur les opérations déjà existantes').'</p>';
152
153 $p_start=new IDate('p_start');
154 $p_start->value=$limit['p_start'];
155 $p_end=new IDate('p_end');
156 $p_end->value=$limit['p_end'];
157
158 $html='';
159 $html.=HtmlInput::title_box($title, 'mod_periode');
160 $html.=$title_par;
161 $html.=sprintf('<form method="post" id="mod_periode_frm" onsubmit="%s.save(\'mod_periode_frm\');return false;">',
162 $js_var); ;
163 $html.=HtmlInput::hidden("js_var", $js_var);
164 $html.=HtmlInput::hidden("periode_id", $periode_id);
165 $html.=HtmlInput::hidden("ledger_id", $ledger_id);
166 $html.=dossier::hidden();
167 $html.='<table>';
168
169 $html.=tr(td(_(' Début période : ')).td($p_start->input()));
170 $html.=tr(td(_(' Fin période : ')).td($p_end->input()));
171 $html.=tr(td(_(' Exercice : ')).td($p_exercice->input()));
172 $html.='</table>';
173 $html.=HtmlInput::submit('sauver', _('sauver'));
174 $html.=HtmlInput::button('close', _('fermer'),
175 'onclick="removeDiv(\'mod_periode\')"');
177 $html.='</form>';
178 $a_answer['status']="OK";
179 $a_answer['content']=$html;
180 break;
181// Save a modification of a periode
182// @todo must be adapted
183 case 'save':
185 $per->load();
186 try
187 {
188 $p_start=$http->post("p_start", "date");
189 $p_end=$http->post("p_end", "date");
190 $p_exercice=$http->post("p_exercice", "number");
192 {
193
194 $a_answer['content']=_('Erreur exercice invalide');
195 }
196 else
197 {
198 $sql="update parm_periode set p_start=to_date($1,'DD.MM.YYYY'),p_end=to_date($2,'DD.MM.YYYY'),p_exercice=$3,p_exercice_label=$5 where p_id=$4";
199 try
200 {
201 $cn->start();
202 $exercice_label=$cn->get_value("select distinct p_exercice_label from "
203 . " parm_periode where p_exercice=$1",
204 [$p_exercice]);
205 if (empty($exercice_label)) {
207 }
208 $cn->exec_sql($sql,
210 $a_answer["status"]="OK";
211 $cn->commit();
212 }
213 catch (Exception $e)
214 {
215 record_log($e);
216 $html=$e->getTrace();
217 throw $e;
218 }
219 $parm_periode=new Parm_periode_SQL($cn, $periode_id);
220 ob_start();
221 Periode::display_row_global($parm_periode, 0, $js_var);
222 $a_answer['content']=ob_get_clean();
223 }
224 }
225 catch (Exception $ex)
226 {
227 $html=$ex->getMessagei();
228 $a_answer['content']=$html;
229 }
230 break;
231 case "remove":
232 try
233 {
235 $per->verify_delete();
236 $per->delete();
237 $a_answer['status']="OK";
238 }
239 catch (Exception $ex)
240 {
241 $a_answer["content"]=$ex->getMessage();
242 }
243 break;
244
245 case 'insert_periode':
246 try
247 {
248 $p_start=$http->post("p_start", "date");
249 $p_end=$http->post("p_end", "date");
250 $p_exercice=$http->post("p_exercice", "number");
251 $exercice_label=$cn->get_value("select distinct p_exercice_label from parm_periode where p_exercice=$1",
252 [$p_exercice]);
253 if (empty($exercice_label)) {
255 }
256 $obj=new Periode($cn);
258 $parm_periode=new Parm_periode_SQL($cn, $p_id);
259 ob_start();
260 Periode::display_row_global($parm_periode, 0, $js_var);
261 $a_answer['content']=ob_get_clean();
262 $a_answer['status']="OK";
263 $a_answer['p_id']=$p_id;
264 $a_answer['status']="OK";
265 }
266 catch (Exception $e)
267 {
268 $a_answer['status']="NOK";
269 $a_answer['content']=$e->getMessage();
270 }
271 break;
272 default:
273 $a_answer['content']=_("Invalid command")."[$act]";
274 break;
275}
276
277$jsson=json_encode($a_answer,
278 JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_NUMERIC_CHECK);
279if (!headers_sent())
280 header('Content-Type: application/json;charset=utf-8');
281echo $jsson;
tr($p_string, $p_extra='')
Definition: ac_common.php:88
record_log($p_message)
Record an error message into the log file of the server.
Definition: ac_common.php:1342
td($p_string='', $p_extra='')
surround the string with td
Definition: ac_common.php:83
global $g_user
if no group available , then stop
if(headers_sent() &&DEBUGNOALYSS > 0) $html
$http
catch(Exception $ex) if( $g_user->check_module("PERIODE")==0) switch($act) $jsson
$a_answer
$err
$ledger_id
$js_var
$periode_id
$ex
Definition: balance.inc.php:45
static button($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
static hidden($p_name, $p_value, $p_id="")
static title_box($p_name, $p_div, $p_mod="close", $p_js="", $p_draggable="n", $p_enlarge='n')
Title for boxes, you can customize the symbol thanks symbol with the mode "custom".
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 : Input a date format dd.mm.yyyy The property title should be set to indicate what it is e...
Definition: idate.class.php:34
This class handles only the numeric input, the input will call a javascript to change comma to period...
Definition: inum.class.php:42
abstract of the table public.jrn_periode
ORM Manage the table public.parm_periode.
Display the periode per ledger: close : reopen ... the close , open must be done thanks Periode.
Manage the periode of a specif ledger, wrap the SQL Class Jrn_Periode_SQL.
For the periode tables parm_periode and jrn_periode.
static display_row_global(Parm_Periode_SQL $obj, $p_nb, $p_js)
Display each row for the global.
const COMPTA_MIN_YEAR
Definition: constant.php:141
const COMPTA_MAX_YEAR
Definition: constant.php:140
$p_end
$p_start
$p_exercice