noalyss Version-9
anc_group.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
20// Copyright Author Dany De Bontridder danydb@aevalys.eu
21
22/*!\file
23 * \brief class for the group of the analytic account
24 *
25 */
26require_once NOALYSS_INCLUDE.'/constant.php';
27
28/*! \brief class for the group of the analytic account
29 *
30 */
31class Anc_Group extends Anc_Print
32{
33 var $db;
34 var $ga_id;
36 var $pa_id;
37
38 function __construct ( $p_cn )
39 {
40 parent::__construct($p_cn);
41 $this->db=$p_cn;
42 $this->ga_id=null;
43 $this->ga_description=null;
44 $this->pa_id=null;
45 }
46 /*!
47 * \brief insert into the database an object
48 * \return message with error otherwise an empty string
49 */
50
51 function insert()
52 {
53 if (strlen ($this->ga_id) > 10 ) return '<span class="notice">'.
54 _('Taille de la code trop long maximum 10 caractères').'</span>';
55 $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) values ($1,$2,$3)";
56 try
57 {
58 $this->db->exec_sql($sql,[$this->ga_id,
59 $this->ga_description,
60 $this->pa_id]);
61 return true;
62 }
63 catch (Exception $a)
64 {
65 return '<span class="notice">Doublon !!</span>';
66 return false;
67 }
68 }
69 /*!
70 * \brief remove from the database
71 */
72
73 function remove()
74 {
75 $this->ga_id=noalyss_str_replace(' ','',$this->ga_id);
76 $this->ga_id=strtoupper($this->ga_id);
77 $sql=" delete from groupe_analytique where ga_id=$1";
78
79 $this->db->exec_sql($sql,array($this->ga_id));
80 }
81
82 /**
83 * @brief load the todo_list row thanks it's ID
84 * @return boolean true if found else false
85 */
86 function load():bool
87 {
88 $sql="select ga_id, ga_description,pa_id from groupe_analytique where".
89 " ga_id = $1";
90 $res=$this->db->exec_sql($sql,[$this->ga_id]);
92 if ( ! empty($array) )
93 {
94 $this->ga_id=$array['ga_id'];
95 $this->ga_description=$array['ga_description'];
96 $this->pa_id=$array['pa_id'];
97 return true;
98 }
99 return false;
100 }
101
102 /*!
103 * \brief fill the object thanks an array
104 * \param array
105 */
107 {
108 $this->ga_id=$p_array['ga_id'];
109 $this->pa_id=$p_array['pa_id'];
110 $this->ga_description=$p_array['ga_description'];
111 }
112 function myList()
113 {
114 $sql=" select ga_id,groupe_analytique.pa_id,pa_name,ga_description ".
115 " from groupe_analytique ".
116 " join plan_analytique using (pa_id)";
117 $r=$this->db->exec_sql($sql);
119 $res=array();
120 if ( ! empty($array))
121 {
122 foreach ($array as $m )
123 {
124 $obj= new Anc_Group($this->db);
125 $obj->get_from_array($m);
126 $obj->pa_name=$m['pa_name'];
127 $res[]=clone $obj;
128 }
129 }
130 return $res;
131 }
132
133 function set_sql_filter()
134 {
135 $sql="";
136 $and="and ";
137 if ( $this->from != "" )
138 {
139 $sql.=" $and oa_date >= to_date('".$this->from."','DD.MM.YYYY')";
140 $and=" and ";
141 }
142 if ( $this->to != "" )
143 {
144 $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')";
145 $and=" and ";
146 }
147 if ( $this->from_poste != "" )
148 {
149 $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')";
150 $and=" and ";
151 }
152 if ( $this->to_poste != "" )
153 {
154 $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')";
155 $and=" and ";
156 }
157 return $sql;
158
159 }
160
161 function get_result()
162 {
163 $filter_date=$this->set_sql_filter();
164
165 $sql="with m as (select po_id,
166 po_name,
167 po_description,
168 ga_id,
169 case when oa_debit = 't' then oa_amount
170 else 0
171 end as amount_deb,
172 case when oa_debit = 'f' then oa_amount
173 else 0
174 end as amount_cred,
175 oa_date
176 from operation_analytique
177join poste_analytique using (po_id)
178where pa_id=$1 $filter_date )
179select sum(amount_cred) as sum_cred, sum(amount_deb)as sum_deb,po_name,ga_id,ga_description,po_description
180from m left join groupe_analytique using (ga_id)
181group by ga_id,po_name,ga_description,po_description
182order by ga_description,po_name";
183 $ret=$this->db->get_array($sql,array($this->pa_id));
184
185 return $ret;
186 }
187
188 function display_html()
189 {
190 if ( $this->check() != 0)
191 {
192 alert('Désolé mais une des dates données n\'est pas valide');
193 return;
194 }
195
196 $array=$this->get_result();
197 if ( empty ($array) ) return "";
198 require_once NOALYSS_TEMPLATE.'/anc_balance_group.php';
199
200
201 }
202 /**
203 *@brief display the button export CSV
204 *@param $p_hidden is a string containing hidden items
205 *@return html string
206 */
207 function show_button($p_hidden="")
208 {
209 $r="";
210 $r.= '<form method="GET" action="export.php" style="display:inline">';
211 $r.= HtmlInput::hidden("act","CSV:AncBalGroup");
212 $r.= HtmlInput::hidden("to",$this->to);
213 $r.= HtmlInput::hidden("from",$this->from);
214 $r.= HtmlInput::hidden("pa_id",$this->pa_id);
215 $r.= HtmlInput::hidden("from_poste",$this->from_poste);
216 $r.= HtmlInput::hidden("to_poste",$this->to_poste);
217 $r.= $p_hidden;
218 $r.= dossier::hidden();
219 $r.=HtmlInput::submit('bt_csv',"Export en CSV");
220 $r.= '</form>';
221 return $r;
222 }
223 function export_csv()
224 {
225 $array=$this->get_result();
226 $cvs=new Noalyss_Csv ('anc-balance-group-export');
227 $cvs->send_header();
228 $cvs->write_header(array("groupe","activité","description","débit","credit","solde"));
229 bcscale(2);
230 for ($i=0;$i<count($array);$i++)
231 {
232 $cvs->add($array[$i]['ga_id']);
233 $cvs->add($array[$i]['po_name']);
234 $cvs->add($array[$i]['po_description']);
235 $cvs->add($array[$i]['sum_deb'],"number");
236 $cvs->add($array[$i]['sum_cred'],"number");
237 $cvs->add(bcsub($array[$i]['sum_cred'],$array[$i]['sum_deb']),"number");
238 $cvs->write();
239 }
240 }
241 static function test_me()
242 {
243
245 print_r($cn);
246 $o=new Anc_Group($cn);
247 $r=$o->myList();
248 print_r($r);
249 echo '<hr>';
250 print_r($o);
251 $o->ga_id="DD' dd dDD";
252 $o->ga_description="Test 1";
253 $o->remove();
254 // $o->insert();
255 $o->ga_id="DD";
256 $o->ga_description="Test 1";
257 $o->remove();
258
259 $r=$o->myList();
260 print_r($r);
261 }
262}
noalyss_str_replace($search, $replace, $string)
Definition: ac_common.php:1553
alert($p_msg, $buffer=false)
alert in javascript
Definition: ac_common.php:738
catch(Exception $exc) if(! $g_user->can_write_action($ag_id)) $r
$anc pa_id
$anc ga_id
$anc_grandlivre from_poste
$anc_grandlivre to
$anc_grandlivre to_poste
$anc_grandlivre from
class for the group of the analytic account
get_from_array($p_array)
fill the object thanks an array
insert()
insert into the database an object
load()
load the todo_list row thanks it's ID
show_button($p_hidden="")
display the button export CSV
static test_me()
set_sql_filter()
Set the filter (account_date)
__construct( $p_cn)
this class is the mother class for the CA printing
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 connect()
static hidden($p_name, $p_value, $p_id="")
static submit($p_name, $p_value, $p_javascript="", $p_class="smallbutton")
Manage the CSV : manage files and write CSV record.
$SecUser db