db=$p_cn; $this->ga_id=null; $this->ga_description=null; $this->pa_id=null; } /*! * \brief insert into the database an object * \return message with error otherwise an empty string */ function insert() { if (strlen ($this->ga_id) > 10 ) return ''. _('Taille de la code trop long maximum 10 caractères').''; $sql=" insert into groupe_analytique (ga_id,ga_description,pa_id) values ('%s','%s',%d)"; $sql=sprintf($sql,Database::escape_string($this->ga_id), Database::escape_string($this->ga_description), $this->pa_id); try { $this->db->exec_sql($sql); } catch (Exception $a) { return 'Doublon !!'; } return ""; } /*! * \brief remove from the database */ function remove() { $this->ga_id=str_replace(' ','',$this->ga_id); $this->ga_id=strtoupper($this->ga_id); $sql=" delete from groupe_analytique where ga_id='".Database::escape_string($this->ga_id)."'"; $this->db->exec_sql($sql); } /*! * \brief load from the database and make an object */ function load() { $sql="select ga_id, ga_description,pa_id from groupe_analytique where". " ga_id = ".$this->ga_id; $res=$this->db->exec_sql($sql); $array=Database::fetch_all($res); if ( ! empty($array) ) { $this->ga_id=$array['ga_id']; $this->ga_description=$array['ga_description']; $this->pa_id=$array['pa_id']; } } /*! * \brief fill the object thanks an array * \param array */ function get_from_array($p_array) { $this->ga_id=$p_array['ga_id']; $this->pa_id=$p_array['pa_id']; $this->ga_description=$p_array['ga_description']; } function myList() { $sql=" select ga_id,groupe_analytique.pa_id,pa_name,ga_description ". " from groupe_analytique ". " join plan_analytique using (pa_id)"; $r=$this->db->exec_sql($sql); $array=Database::fetch_all($r); $res=array(); if ( ! empty($array)) { foreach ($array as $m ) { $obj= new Anc_Group($this->db); $obj->get_from_array($m); $obj->pa_name=$m['pa_name']; $res[]=clone $obj; } } return $res; } function set_sql_filter() { $sql=""; $and="and "; if ( $this->from != "" ) { $sql.=" $and oa_date >= to_date('".$this->from."','DD.MM.YYYY')"; $and=" and "; } if ( $this->to != "" ) { $sql.=" $and oa_date <= to_date('".$this->to."','DD.MM.YYYY')"; $and=" and "; } if ( $this->from_poste != "" ) { $sql.=" $and upper(po_name)>= upper('".$this->from_poste."')"; $and=" and "; } if ( $this->to_poste != "" ) { $sql.=" $and upper(po_name)<= upper('".$this->to_poste."')"; $and=" and "; } return $sql; } function get_result() { $filter_date=$this->set_sql_filter(); $sql="with m as (select po_id, po_name, po_description, ga_id, case when oa_debit = 't' then oa_amount else 0 end as amount_deb, case when oa_debit = 'f' then oa_amount else 0 end as amount_cred, oa_date from operation_analytique join poste_analytique using (po_id) where pa_id=$1 $filter_date ) select sum(amount_cred) as sum_cred, sum(amount_deb)as sum_deb,po_name,ga_id,ga_description,po_description from m left join groupe_analytique using (ga_id) group by ga_id,po_name,ga_description,po_description order by ga_description,po_name"; $ret=$this->db->get_array($sql,array($this->pa_id)); return $ret; } function display_html() { if ( $this->check() != 0) { alert('Désolé mais une des dates données n\'est pas valide'); return; } $array=$this->get_result(); if ( empty ($array) ) return ""; require_once NOALYSS_TEMPLATE.'/anc_balance_group.php'; } /** *@brief display the button export CSV *@param $p_hidden is a string containing hidden items *@return html string */ function show_button($p_hidden="") { $r=""; $r.= '
'; return $r; } function export_csv() { $array=$this->get_result(); $cvs=new Noalyss_Csv ('anc-balance-group-export'); $cvs->send_header(); $cvs->write_header(array("groupe","activité","description","débit","credit","solde")); bcscale(2); for ($i=0;$i