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

@ -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();
?>