diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 4e221368a..1f465f926 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -3156,8 +3156,9 @@ class Acc_Ledger extends jrn_def_sql ',coalesce(sum(qp_nd_tva_recup),0)+coalesce(sum(qp_nd_tva),0) as tva_nd' . ',coalesce(sum(qp_vat_sided),0) as tva_np' . ' from quant_purchase join jrnx using(j_id) ' . - ' where j_tech_per >= $1 and j_tech_per < $2'; - $array = $this->db->get_array($sql, array($min->p_id, $p_to)); + ' where j_tech_per >= $1 and j_tech_per < $2'. + ' and j_jrn_def = $3'; + $array = $this->db->get_array($sql, array($min->p_id, $p_to,$this->idq)); $ret = $array[0]; /* retrieve all vat code */ @@ -3175,8 +3176,9 @@ class Acc_Ledger extends jrn_def_sql ',0 as tva_nd' . ',coalesce(sum(qs_vat_sided),0) as tva_np' . ' from quant_sold join jrnx using(j_id) ' . - ' where j_tech_per >= $1 and j_tech_per < $2'; - $array = $this->db->get_array($sql, array($min->p_id, $p_to)); + ' where j_tech_per >= $1 and j_tech_per < $2'. + ' and j_jrn_def = $3'; + $array = $this->db->get_array($sql, array($min->p_id, $p_to,$this->id)); $ret = $array[0]; /* retrieve all vat code */ $array = $this->db->get_array('select coalesce(sum(qs_vat),0) as sum_vat,tva_id @@ -3184,6 +3186,15 @@ class Acc_Ledger extends jrn_def_sql where tva_rate !=0 and j_tech_per >= $1 and j_tech_per < $2 group by tva_id', array($min->p_id, $p_to)); $ret['tva'] = $array; } + if ($this->type=="FIN") + { + /* get all amount exclude vat */ + $sql = "select coalesce(sum(qf_amount),0) as amount" . + ' from quant_fin join jrn using(jr_id) ' . + ' where jr_tech_per >= $1 and jr_tech_per < $2'. + ' and jr_def_id=$3'; + $ret = $this->db->get_array($sql, array($min->p_id, $p_to,$this->id)); + } return $ret; } diff --git a/include/class_print_ledger_fin.php b/include/class_print_ledger_fin.php index 8bed70426..787e9b99e 100644 --- a/include/class_print_ledger_fin.php +++ b/include/class_print_ledger_fin.php @@ -25,11 +25,23 @@ require_once('class_pdf.php'); class Print_Ledger_Financial extends PDF { - function __construct($p_cn,$p_jrn) + private $rap_amount; /* amount from begining exercice */ + private $tp_amount; /* amount total page */ + + function __construct($p_cn, Acc_Ledger $p_jrn) { parent::__construct($p_cn,'L','mm','A4'); $this->ledger=$p_jrn; $this->jrn_type=$p_jrn->get_type(); + + // report from begin exercice + $this->rap_amount=0; + + // total page + $this->tp_amount=0; + + $amount=$this->ledger->previous_amount($_GET['from_periode']); + $this->rap_amount=$amount[0]['amount']; } function Header() { @@ -38,7 +50,11 @@ class Print_Ledger_Financial extends PDF //Title $this->Cell(0,10,$this->dossier, 'B', 0, 'C'); //Line break - $this->Ln(20); + $this->SetFont('DejaVu', 'B', 7); + $this->Ln(10); + $this->Cell(100,6,_('report'),0,0,'R'); + $this->Cell(120,6,nbm($this->rap_amount),0,0,'R'); + $this->Ln(6); $this->SetFont('DejaVu', 'B', 7); $this->Cell(30,6,'Piece'); $this->Cell(10,6,'Date'); @@ -47,10 +63,19 @@ class Print_Ledger_Financial extends PDF $this->Cell(105,6,'Commentaire'); $this->Cell(15,6,'Montant'); $this->Ln(6); - + } function Footer() { + $this->SetFont('DejaVu', 'B', 7); + + $this->Cell(50,6,_('Total page'),0,0,'R'); + $this->Cell(50,6,nbm($this->tp_amount),0,0,'R'); + bcscale(2); + $this->rap_amount=bcadd($this->rap_amount,$this->tp_amount); + $this->Cell(50,6,_('Total à reporter'),0,0,'R'); + $this->Cell(50,6,nbm($this->rap_amount),0,0,'R'); + $this->tp_amount=0; //Position at 2 cm from bottom $this->SetY(-20); //Arial italic 8 @@ -71,6 +96,7 @@ class Print_Ledger_Financial extends PDF $_GET['to_periode']); $this->SetFont('DejaVu', '', 6); if ( $a_jrn == null ) return; + bcscale(2); for ( $i=0;$icn->get_value('select qf_amount from quant_fin where jr_id=$1',array( $row['id'])); $this->Cell(15,5,sprintf('%s',nbm($amount)),0,0,'R'); $this->Ln(5); + $this->tp_amount=bcadd($this->tp_amount,$amount); } } diff --git a/include/impress_jrn.inc.php b/include/impress_jrn.inc.php index 37c357ba2..86b27d837 100644 --- a/include/impress_jrn.inc.php +++ b/include/impress_jrn.inc.php @@ -267,7 +267,8 @@ if (isset($_REQUEST['bt_html'])) "Total opération" . ""; // set a filter for the FIN - $i = 0; + $i = 0;$tot_amount=0; + bcscale(2); foreach ($Row as $line) { $i++; @@ -297,14 +298,25 @@ if (isset($_REQUEST['bt_html'])) echo ""; echo ( $positive == 0 ) ? " - " . nbm($line['montant']) . "" : nbm($line['montant']); echo ""; + if ( $positive == 1 ) { + $tot_amount=bcadd($tot_amount,$line['montant']); + } else { + $tot_amount=bcsub($tot_amount,$line['montant']); + } } else { echo "" . nbm($line['montant']) . ""; + $tot_amount=bcadd($tot_amount,$line['montant']); } echo ""; } + echo ''; + echo ''._('Totaux').''; + echo td().td().td().td().td(); + echo ''.nbm($tot_amount).''; + echo ''; echo ""; } else { /*