noalyss Version-9
NOALYSS : serveur de comptabilité et ERP (2002)
Loading...
Searching...
No Matches
acc_report.class.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 Create, view, modify and parse report
22 */
23
24require_once NOALYSS_INCLUDE.'/database/form_detail_sql.class.php';
25require_once NOALYSS_INCLUDE.'/database/form_definition_sql.class.php';
26
27/*!
28 * \class Acc_Report
29 * \brief Class rapport Create, view, modify and parse report
30 */
31
33{
34
35 private $form_definition; /*!< form_definition_sql */
36 var $row;
37 var $nb;
38 var $id;
39 var $name;
40 /*!
41 \brief Constructor
42 */
43 function __construct($p_cn,$p_id=-1)
44 {
45 $this->form_definition=new Form_Definition_SQL($p_cn,$p_id);
46 }
47 public function get_form_definition()
48 {
50 }
51
53 {
54 $this->form_definition=$form_definition;
55 }
56
57 /*!\brief Return the report's name
58 */
59 function get_name()
60 {
61 return $this->form_definition->getp("fr_label");
62 }
63 /*!
64 * \brief return all the row and parse formula
65 * from a report
66 * \param $p_start start periode
67 * \param $p_end end periode
68 * \param $p_type_date type of the date : periode (or 0) or calendar (or 1)
69 */
70 function get_row($p_start,$p_end,$p_type_date)
71 {
72 if (DEBUGNOALYSS > 1) {
73 tracedebug("impress.debug.log",__FILE__."71.get_row({$p_start},{$p_end},{$p_type_date})");
74 }
75 $Res=$this->form_definition->cn->exec_sql("select fo_id ,
76 fo_fr_id,
77 fo_pos,
78 fo_label,
79 fo_formula,
80 fr_label from form_detail
81 inner join form_definition on fr_id=fo_fr_id
82 where fr_id =$1
83 order by fo_pos",array($this->form_definition->getp("fr_id")));
85 if ($Max==0)
86 {
87 $this->row=0;
88 return null;
89 }
90 $col=array();
91
92 if ( $p_type_date == '0' || $p_type_date=="periode") {
93 $type_date=0;
94 } elseif ($p_type_date == '1' || $p_type_date=="calendar") {
95 $type_date=1;
96 } else {
97 throw new Exception("ACR93:invalid type_date [ {$p_type_date} ] ");
98 }
99
100
101 for ($i=0;$i<$Max;$i++)
102 {
104
105 $col[]=Impress::parse_formula($this->form_definition->cn,
106 $l_line['fo_label'],
107 $l_line['fo_formula'],
108 $p_start,
109 $p_end,
110 true,
111 $type_date
112 );
113
114 } //for ($i
115 $this->row=$col;
116 return $col;
117 }
118
119 /*!
120 * \brief save into form and form_def
121 */
122 function save()
123 {
124 $this->form_definition->save();
125 }
126
127 /*!
128 * \brief the fr_id MUST be set before calling
129 */
130 function load():void
131 {
132 $this->form_definition->load();
133
134 }
135 function delete()
136 {
137 $this->form_definition->delete();
138 }
139 /*!
140 * \brief get a list from form_definition of all defined form
141 *
142 *\return array of object rapport
143 *
144 */
145 function get_list()
146 {
147 $sql="select fr_id,fr_label from form_definition order by fr_label";
148 $ret=$this->form_definition->cn->exec_sql($sql);
149 if ( Database::num_row($ret) == 0 ) return array();
151 $obj=array();
152 foreach ($array as $row)
153 {
154 $tmp=new Acc_Report($this->form_definition->cn);
155 $tmp->id=$row['fr_id'];
156 $tmp->name=$row['fr_label'];
157 $obj[]=clone $tmp;
158 }
159 return $obj;
160 }
161 /*!\brief To make a SELECT button with the needed value, it is used
162 *by the SELECT widget
163 *\return string with html code
164 */
165 function make_array()
166 {
167 $sql=$this->form_definition->cn->make_array("select fr_id,fr_label from form_definition order by fr_label");
168 return $sql;
169 }
170
171
172 /*!\brief write to a file the definition of a report
173 * \param p_file is the file name (default php://output)
174 */
175 function export_csv($p_file)
176 {
177 $this->load();
178
179 fputcsv($p_file,array($this->form_definition->getp("fr_label")));
180 $array=$this->form_definition->get_cn()->get_array("select fo_label,fo_pos,fo_formula
181 from form_detail
182 where fo_fr_id=$1
183 order by fo_pos"
184 ,array($this->form_definition->getp("fr_id"))
185 );
186
187 foreach ($array as $row)
188 {
189 fputcsv($p_file,array($row["fo_label"],
190 $row["fo_pos"],
191 $row["fo_formula"])
192 );
193 }
194
195 }
196 /*!\brief upload a definition of a report and insert it into the
197 * database
198 */
199 function upload()
200 {
201 if ( empty ($_FILES) ) return;
202 if ( noalyss_strlentrim($_FILES['report']['tmp_name'])== 0 )
203 {
204 alert("Nom de fichier est vide");
205 return;
206 }
207 $file_report=tempnam('tmp','file_report');
208 if ( move_uploaded_file($_FILES['report']['tmp_name'],$file_report))
209 {
210 // File is uploaded now we can try to parse it
211 $file=fopen($file_report,'r');
212 $data=fgetcsv($file);
213 if ( empty($data) ) return;
214 $array=array();
215 $cn=$this->form_definition->cn;
216 $id=$this->form_definition->getp("fr_id");
217 while($data=fgetcsv($file))
218 {
220 $obj->setp("fo_label",$data[0]);
221 $obj->setp("fo_pos",$data[1]);
222 $obj->set("fo_formula",$data[2]);
223 $obj->setp("fo_fr_id",$id);
224 $obj->insert();
225 }
226 }
227 }
228 /**
229 *@brief check if a report exist
230 *@param $p_id, optional, if given check the report with this fr_id
231 *@return return true if the report exist otherwise false
232 */
233 function exist($p_id=0)
234 {
235 $c=$this->form_definition->getp("fr_id");
236 if ( $p_id != 0 ) $c=$p_id;
237 $ret=$this->form_definition->cn->exec_sql("select fr_label from form_definition where fr_id=$1",array($c));
238 if (Database::num_row($ret) == 0) return false;
239 return true;
240 }
241 /**
242 * @brief display a form for creating a new report by importing it or set manually
243 */
244 function create()
245 {
246 require_once NOALYSS_INCLUDE."/template/acc_report-create.php";
247 }
248 /**
249 * @brief
250 * @param IText $name
251 */
253 {
254 $name=new IText("fr_name",$name);
255 $name->id="fr_name_inplace";
256
257 $iName=new Inplace_Edit($name);
258 $iName->set_callback("ajax_misc.php");
259 $iName->add_json_param("op", "report_definition");
260 $iName->add_json_param("sa", "change_name");
261 $iName->add_json_param("gDossier", Dossier::id());
262 $iName->add_json_param("p_id", $this->form_definition->getp("fr_id"));
263 return $iName;
264 }
265}
266
267?>
noalyss_strlentrim($p_string)
alert($p_msg, $buffer=false)
alert in javascript
Class rapport Create, view, modify and parse report.
exist($p_id=0)
check if a report exist
__construct($p_cn, $p_id=-1)
Constructor.
load()
the fr_id MUST be set before calling
save()
save into form and form_def
upload()
upload a definition of a report and insert it into the database
get_list()
get a list from form_definition of all defined form
get_name()
Return the report's name.
set_form_definition($form_definition)
export_csv($p_file)
write to a file the definition of a report
make_array()
To make a SELECT button with the needed value, it is used by the SELECT widget.
get_row($p_start, $p_end, $p_type_date)
return all the row and parse formula from a report
create()
display a form for creating a new report by importing it or set manually
static fetch_all($ret)
wrapper for the function pg_fetch_all
static fetch_array($ret, $p_indice=0, $p_mode=PGSQL_ASSOC)
wrapper for the function pg_fetch_array
static num_row($ret)
wrapper for the function pg_num_rows
ORM abstract of the table public.form_definition.
ORM abstract of the table public.form_detail.
Html Input.
static parse_formula($p_cn, $p_label, $p_formula, $p_start, $p_end, $p_eval=true, $p_type_date=0, $p_sql="")
Inplace_edit class for ajax update of HtmlInput object.
$c
Definition compute.php:48
if( $delta< 0) elseif( $delta==0)