Task #0001530: Réécriture PRINTJRN : export CSV

This commit is contained in:
Dany De Bontridder 2018-01-23 22:09:17 +01:00
parent d7f716059f
commit 51b1978eb8
4 changed files with 337 additions and 121 deletions

View file

@ -2629,9 +2629,12 @@ class Acc_Ledger extends jrn_def_sql
*
* \return an Array with the asked data
*/
function get_rowSimple($p_from, $p_to, $trunc=0, $p_limit=-1, $p_offset=-1)
function get_rowSimple($p_from, $p_to, $pa_ledger=[],$trunc=0,$p_limit=-1,$p_offset=-1)
{
$alh_generic=new Acc_Ledger_History_Generic($this->db, [$this->id], $p_from, $p_to, "A");
if ( empty($pa_ledger) ) {
$pa_ledger=[$this->id];
}
$alh_generic=new Acc_Ledger_History_Generic($this->db, $pa_ledger, $p_from, $p_to, "A");
$alh_generic->get_rowSimple($trunc,$p_limit,$p_offset);
$data=$alh_generic->get_data();
return $data;

View file

@ -34,6 +34,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
{
private $data; //!< array of rows
/**
* Constructor
* @param Database $cn
@ -43,6 +44,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
* @param type $p_mode
* @example acc_ledger_historyTest.php
*/
function __construct(Database $cn, $pa_ledger, $p_from, $p_to, $p_mode)
{
parent::__construct($cn, $pa_ledger, $p_from, $p_to, $p_mode);
@ -411,7 +413,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
function get_rowSimple($trunc=0, $p_limit=-1, $p_offset=-1)
{
global $g_user;
$jrn=" jrn_def_id in (".join($this->ma_ledger, ",").")" ;
$jrn=" jrn_def_id in (".join($this->ma_ledger, ",").")";
$periode=sql_filter_per($this->db, $this->m_from, $this->m_to, 'p_id',
'jr_tech_per');
@ -500,7 +502,8 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
jr_pj_number,
j_qcode,
jrn_def_type,
jr_rapt as oc, j_tech_per as periode
jr_rapt as oc, j_tech_per as periode,
j_id
from jrnx left join jrn on
jr_grpt_id=j_grpt
left join tmp_pcmn on pcm_val=j_poste
@ -605,6 +608,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
$this->data=array($array, $tot_deb, $tot_cred);
return $Max;
}
/**
* display in html the detail the list of operation
*/
@ -612,6 +616,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
{
$this->export_accounting_html();
}
/**
* display in html with extended detail the list of operation
*/
@ -619,12 +624,13 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
{
$this->export_accounting_html();
}
/**
* display in html the accounting of the list of operations
*/
public function export_accounting_html()
{
$this->get_row();
echo '<TABLE class="result">';
// detailled printing
@ -661,6 +667,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
echo _("solde débiteur:").$this->data[1]."<br>";
echo _("solde créditeur:").$this->data[2];
}
/**
* @brief list operation on one line per operation
*/
@ -733,6 +740,7 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
echo '</tr>';
echo "</table>";
}
/**
* To get data
* @return array of rows
@ -741,4 +749,55 @@ class Acc_Ledger_History_Generic extends Acc_Ledger_History
{
return $this->data;
}
/**
* export CSV
*/
function export_csv()
{
$export=new Noalyss_Csv(_('journal'));
$export->send_header();
$this->get_row();
$title=array();
$title[]=_("operation");
$title[]=_("N° Pièce");
$title[]=_("Interne");
$title[]=_("Date");
$title[]=_("Poste");
$title[]=_("QuickCode");
$title[]=_("Libellé");
$title[]=_("Débit");
$title[]=_("Crédit");
$export->write_header($title);
if (count($this->data)==0)
exit;
$old_id="";
/**
* @todo add table headers
*/
foreach ($this->data[0] as $idx=>$op)
{
// should clean description : remove <b><i> tag and '; char
$desc=$op['description'];
$desc=str_replace("<b>", "", $desc);
$desc=str_replace("</b>", "", $desc);
$desc=str_replace("<i>", "", $desc);
$desc=str_replace("</i>", "", $desc);
if ($op['j_id']!="")
$old_id=$op['j_id'];
$export->add($old_id, "text");
$export->add($op['jr_pj_number']);
$export->add($op['internal']);
$export->add($op['j_date']);
$export->add($op['poste']);
$export->add($op['j_qcode']);
$export->add($desc);
$export->add($op['deb_montant'], "number");
$export->add($op['cred_montant'], "number");
$export->write();
}
}
}

View file

@ -224,5 +224,93 @@ class Acc_Ledger_History_Sale extends Acc_Ledger_History
{
return $this->data;
}
/**
* export in csv with detail VAT
*/
function export_csv()
{
$export=new Noalyss_Csv(_('journal'));
$export->send_header();
$this->get_row();
$this->prepare_reconcile_date();
$this->add_vat_info();
$own=new Noalyss_Parameter_Folder($this->db);
$title=array();
$title[]=_('Date');
$title[]=_("Paiement");
$title[]=_("operation");
$title[]=_("Pièce");
$title[]=_("Fournisseur");
$title[]=_("Note");
$title[]=_("interne");
$title[]=_("HTVA");
$title[]=_("TVA");
$title[]=_("TVA annulée");
if ( $own->MY_TVA_USE=='Y')
{
$a_Tva=$this->db->get_array("select tva_id,tva_label from tva_rate order by tva_rate,tva_label,tva_id");
foreach($a_Tva as $line_tva)
{
$title[]="Tva ".$line_tva['tva_label'];
}
}
$title[]=_("TVAC/TTC");
$title[]=_("opérations liées");
$export->write_header($title);
foreach ($this->data as $line)
{
$export->add($line['jr_date']);
$export->add($line['jr_date_paid']);
$export->add($line['jr_id']);
$export->add($line['jr_pj_number']);
$export->add($line['name']." ".
$line["first_name"]." ".
$line["qcode"]); // qp_supplier
$export->add($line['jr_comment']);
$export->add($line['jr_internal']);
$export->add($line['novat'],"number");
$export->add($line['vat'],"number");
$export->add($line['tva_sided'],"number");
$a_tva_amount=array();
//- set all TVA to 0
foreach ($a_Tva as $l) {
$t_id=$l["tva_id"];
$a_tva_amount[$t_id]=0;
}
foreach ($line['detail_vat'] as $lineTVA)
{
$idx_tva=$lineTVA['qs_vat_code'];
$a_tva_amount[$idx_tva]=$lineTVA['vat_amount'];
}
if ($own->MY_TVA_USE == 'Y' )
{
foreach ($a_Tva as $line_tva)
{
$a=$line_tva['tva_id'];
$export->add($a_tva_amount[$a],"number");
}
}
$export->add($line['tvac'],"number");
/**
* Retrieve payment if any
*/
$ret_reconcile=$this->db->execute('reconcile_date',array($line['jr_id']));
$max=Database::num_row($ret_reconcile);
if ($max > 0) {
for ($e=0;$e<$max;$e++) {
$row=Database::fetch_array($ret_reconcile, $e);
$export->add($row['jr_date']);
$export->add($row['jr_internal']);
}
}
$export->write();
}
}
}