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