add export CSV to ANC grand livre

This commit is contained in:
Dany De Bontridder 2011-11-17 14:20:15 +00:00
parent 30f962432d
commit dfe59ee4e7
6 changed files with 183 additions and 2 deletions

View file

@ -39,7 +39,7 @@ $act=$user->check_dossier($gDossier);
if ( $act=='X' || ! isset($_GET['act']) || $user->check_print($_GET['act'])==0 )
{
echo alert('Accès interdit');
redirect("do.php?".dossier::get());
redirect("do.php?".dossier::get());
exit();
}
@ -156,6 +156,9 @@ if ( $act=='X' || ! isset($_GET['act']) || $user->check_print($_GET['act'])==0 )
require_once 'export_bilan_oth.php';
exit();
break;
case 'CSV:AncGrandLivre':
require_once 'export_anc_grandlivre_csv.php';
break;
default:
alert('Action inconnue '.$_GET['act']);
exit();

View file

@ -24,6 +24,7 @@
* \brief show the Grand Livre for analytic
*/
require_once('class_anc_print.php');
require_once 'class_impress.php';
class Anc_GrandLivre extends Anc_Print
{
@ -63,7 +64,7 @@ class Anc_GrandLivre extends Anc_Print
left join jrn on (j_grpt=jr_grpt_id)
where $pa_id_cond oa_amount <> 0.0 $cond_poste
order by po_name,oa_date ,qcode,j_poste");
return $array;
}
@ -149,4 +150,71 @@ class Anc_GrandLivre extends Anc_Print
$r.= '</table>';
return $r;
}
/*!
* \brief Show the button to export in PDF or CSV
* \param $url_csv url of the csv
* \param $url_pdf url of the pdf
* \param $p_string hidden data to include in the form
*
*
* \return string with the button
*/
function show_button($p_string="")
{
$r="";
/* $r.= '<form method="GET" action="export.php" style="display:inline">';
$r.= $p_string;
$r.= dossier::hidden();
$r.= HtmlInput::hidden("to",$this->to);
$r.= HtmlInput::hidden("act","PDF:AncGrandLivre");
$r.= HtmlInput::hidden("from",$this->from);
$r.= HtmlInput::hidden("pa_id",$this->pa_id);
$r.= HtmlInput::hidden("from_poste",$this->from_poste);
$r.= HtmlInput::hidden("to_poste",$this->to_poste);
$r.=HtmlInput::submit('bt_pdf',"Export en PDF");
$r.= '</form>';
*/
$r.= '<form method="GET" action="export.php" style="display:inline">';
$r.= HtmlInput::hidden("act","CSV:AncGrandLivre");
$r.= HtmlInput::hidden("to",$this->to);
$r.= HtmlInput::hidden("from",$this->from);
$r.= HtmlInput::hidden("pa_id",$this->pa_id);
$r.= HtmlInput::hidden("from_poste",$this->from_poste);
$r.= HtmlInput::hidden("to_poste",$this->to_poste);
$r.= $p_string;
$r.= dossier::hidden();
$r.=HtmlInput::submit('bt_csv',"Export en CSV");
$r.= '</form>';
return $r;
}
function display_csv()
{
$r="";
//---Html
$array=$this->load();
if ( is_array($array) == false )
{
return $array;
}
if ( empty($array) )
{
$r.= _("aucune donnée");
return $r;
}
$ix=0;$prev='xx';
$tot_deb=$tot_cred=0;
$aheader=array();
$aheader=array("title"=>'Date','type'=>'string');
$aheader=array("title"=>'Poste','type'=>'string');
$aheader=array("title"=>'Quick_Code','type'=>'string');
$aheader=array("title"=>'libelle','type'=>'string');
$aheader=array("title"=>'Num.interne','type'=>'string');
$aheader=array("title"=>'Debit','type'=>'num');
$aheader=array("title"=>'Credit','type'=>'num');
Impress::array_to_csv($array, $aheader);
}
}

View file

@ -846,6 +846,45 @@ class Database
{
return pg_transaction_status($this->db);
}
/**
* with the handle of a successull query, echo each row into CSV and
* send it directly
* @param type $ret handle to a query
* @param type $aheader double array, each item of the array contains
* a key type (num) and a key title
*/
function query_to_csv($ret,$aheader)
{
$seq="";
for ($i=0;$i<count($i);$i++)
{
echo '"'.$aheader[$i]['title'].'"';
$seq=";";
}
printf("\n\r");
$seq="";
// fetch all the rows
for ($i=0;$i<count(Database::num_row($ret));$i++)
{
$row=Database::fetch_array($ret, $i);
$sep2="";
// for each rows, for each value
for ($e=0;$e<count($row);$e++)
{
switch ($aheader[$e]['type'])
{
case 'num':
echo nb($row[$e]).$sep2;
break;
default:
echo '"'.$row[$e].'"'.$sep2;
}
$sep2=";";
}
printf("\n\r");
}
}
}
/* test::test_me(); */

View file

@ -229,4 +229,43 @@ class Impress
return true;
}
}
/**
* with the handle of a successull query, echo each row into CSV and
* send it directly
* @param type $array of data
* @param type $aheader double array, each item of the array contains
* a key type (num) and a key title
*/
static function array_to_csv($array,$aheader)
{
$seq="";
for ($i=0;$i<count($i);$i++)
{
echo '"'.$aheader[$i]['title'].'"';
$seq=";";
}
printf("\n\r");
$seq="";
// fetch all the rows
for ($i=0;$i<count($array);$i++)
{
$row=$array[$i];
$sep2="";
// for each rows, for each value
for ($e=0;$e<count($row);$e++)
{
switch ($aheader[$e]['type'])
{
case 'num':
echo nb($row[$e]).$sep2;
break;
default:
echo '"'.$row[$e].'"'.$sep2;
}
$sep2=";";
}
printf("\n\r");
}
}
}

View file

@ -0,0 +1,17 @@
<?php
header('Pragma: public');
header('Content-type: application/csv');
header('Content-Disposition: attachment;filename="anc-grand-livre.csv"',FALSE);
require_once 'class_anc_grandlivre.php';
$cn=Dossier::connect();
$gl=new Anc_GrandLivre($cn);
$gl->get_request();
echo $gl->display_csv();
?>

15
sql/anc-grandlivre.sql Normal file
View file

@ -0,0 +1,15 @@
insert into menu_ref(me_code,me_menu,me_file,me_description,me_type)
values ('CSV:AncGrandLivre','Impression Grand-Livre',null,null,'PR');
CREATE TABLE profile_menu (
pm_id integer NOT NULL,
me_code text,
me_code_dep text,
p_id integer,
p_order integer,
p_type_display text NOT NULL,
pm_default integer
);
insert into profile_menu(me_code,me_code_dep,p_id,pm_default)
values ( 'CSV:AncGrandLivre', NULL, 1 , 'P', 0);