From c7ca69bb28b303ce0b149488cae31927084270c3 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Sat, 6 Jan 2007 21:13:36 +0000 Subject: [PATCH] Add the simple operation for ledger VEN and ACH --- html/jrn_pdf.php | 53 +++++++++++++++++++--------- include/class_jrn.php | 28 ++++++++++----- include/impress_inc.php | 76 +++++++++++++++++++++++++++++++++++++++-- 3 files changed, 128 insertions(+), 29 deletions(-) diff --git a/html/jrn_pdf.php b/html/jrn_pdf.php index 7bfd84a53..94dcf7345 100644 --- a/html/jrn_pdf.php +++ b/html/jrn_pdf.php @@ -182,7 +182,7 @@ if ( ($jrn_type=='ACH' || $jrn_type=='VEN' ) && $_REQUEST['p_simple']== 1 ) $pdf->selectFont('./addon/fonts/Courier.afm'); $offset=0;$limit=30;$step=30; - $a_Tva=GetArray($cn,"select tva_id,tva_label from tva_rate where tva_rate != 0.0000 order by tva_id"); + $a_Tva=GetArray($cn,"select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 order by tva_id"); $col_tva="TVA "; $space=0; $total_HTVA=0.0; @@ -199,16 +199,14 @@ if ( ($jrn_type=='ACH' || $jrn_type=='VEN' ) && $_REQUEST['p_simple']== 1 ) $space=9; } + // if the period is centralized get the first amounts + if ( $l_centr==1) + list($total_TVAC,$total_HTVA)=GetRappelSimple($cn,$Jrn->id,$jrn_type,$_GET['from_periode'],&$rap_tva); + -// list($rap_deb,$rap_cred)=GetRappelSimple($cn, -// $first_id,$Jrn->id, -// $Exercice, -// FIRST, -// $filter, -// $l_centr -// ); while (1) { + $a=0; $a_jrn=$Jrn->GetRowSimple($_GET['from_periode'], $_GET['to_periode'], @@ -218,11 +216,22 @@ if ( ($jrn_type=='ACH' || $jrn_type=='VEN' ) && $_REQUEST['p_simple']== 1 ) $offset); if ( $a_jrn == null ) break; + // page Header + $t=sprintf("Rappel TVAC = %.2f HTVA= %.2f",$total_TVAC,$total_HTVA); + foreach($rap_tva as $idx=>$am) { + $t.=sprintf('[ %s = % .2f]',$idx,$am); + } + $pdf->ezText($t,9,array('justification'=>'left')); + $offset+=$step; - $first_id=$a_jrn[0]['jr_id']; - - $Exercice=GetExercice($cn,$a_jrn[0]['jr_tech_per']); - + //total page + $total_htva_page=0.0;$total_tvac_page=0.0; + foreach($a_Tva as $line_tva) + { + //initialize Amount TVA + $tmp1=$line_tva['tva_label']; + $page_tva[$tmp1]=0.0; + } $str_tva=""; @@ -249,18 +258,28 @@ if ( ($jrn_type=='ACH' || $jrn_type=='VEN' ) && $_REQUEST['p_simple']== 1 ) { $total_TVAC+=$row['TVAC']; $total_HTVA+=$row['HTVA']; + $total_tvac_page+=$row['TVAC']; + $total_htva_page+=$row['HTVA']; + foreach ($row['TVA'] as $line) { $tva_id=$line[1][1]; $rap_tva[$tva_id]+=$line[1][2]; + $page_tva[$tva_id]+=$line[1][2]; } } - - $t=sprintf("TVAC = %.2f HTVA= %.2f",$total_TVAC,$total_HTVA); - foreach($rap_tva as $idx=>$am) { - $t.=sprintf('[ %s ] % .2f',$idx,$am); + //total page + $t=sprintf("total page TVAC = %.2f HTVA= %.2f",$total_tvac_page,$total_htva_page); + foreach($page_tva as $idx=>$am) { + $t.=sprintf('[ %s = % .2f ]',$idx,$am); } - $pdf->ezText($t,12,array('justification'=>'right')); + $pdf->ezText($t,9,array('justification'=>'left')); + + $t=sprintf("total à reporter TVAC = %.2f HTVA= %.2f",$total_TVAC,$total_HTVA); + foreach($rap_tva as $idx=>$am) { + $t.=sprintf('[ %s = % .2f ]',$idx,$am); + } + $pdf->ezText($t,9,array('justification'=>'left')); // New Page $pdf->ezNewPage(); diff --git a/include/class_jrn.php b/include/class_jrn.php index 4301d56ba..dfe34300f 100644 --- a/include/class_jrn.php +++ b/include/class_jrn.php @@ -324,10 +324,13 @@ class jrn { // for type ACH and Ven we take more info if ( $type == 'ACH' || $type == 'VEN') { + $a_ParmCode=GetArray($this->db,'select p_code,p_value from parm_code'); + $a_TVA=GetArray($this->db,'select tva_id,tva_label,tva_poste + from tva_rate where tva_rate != 0 order by tva_id'); for ( $i=0;$i<$Max;$i++) { $array[$i]=pg_fetch_array($Res); - $p=$this->get_detail(&$array[$i],$type,$trunc); + $p=$this->get_detail(&$array[$i],$type,$trunc,$a_TVA,$a_ParmCode); } @@ -362,18 +365,25 @@ class jrn { * \param p_array the structure is set in GetRowSimple, this array is * modified, * \param $trunc if the data must be truncated, usefull for pdf export - *\param p_jrn_type is the type of the ledger (ACH or VEN) + * \param p_jrn_type is the type of the ledger (ACH or VEN) + * \param $a_TVA TVA Array (default null) + * \param $a_ParmCode Array (default null) * \return p_array */ - function get_detail($p_array,$p_jrn_type,$trunc=0) + function get_detail($p_array,$p_jrn_type,$trunc=0,$a_TVA=null,$a_ParmCode=null) { - // Load TVA array - $a_TVA=GetArray($this->db,'select tva_id,tva_label,tva_poste - from tva_rate where tva_rate != 0 order by tva_id'); + if ( $a_TVA == null ) + { + //Load TVA array + $a_TVA=GetArray($this->db,'select tva_id,tva_label,tva_poste + from tva_rate where tva_rate != 0 order by tva_id'); + } + if ( $a_ParmCode == null ) + { //Load Parm_code - $a_ParmCode=GetArray($this->db,'select p_code,p_value from parm_code'); - - // init + $a_ParmCode=GetArray($this->db,'select p_code,p_value from parm_code'); + } + // init $p_array['client']=""; $p_array['TVAC']=0; $p_array['TVA']=array(); diff --git a/include/impress_inc.php b/include/impress_inc.php index 2e9efe856..bb88fa80e 100644 --- a/include/impress_inc.php +++ b/include/impress_inc.php @@ -572,12 +572,82 @@ function GetDataGrpt($p_cn,$p_array) * * \return array sum(HTVA) sum(TVAC) sum (each TVA) */ -function GetRappelSimple ($p_cn,$p_jr_id,$p_jrn_id,$p_exercice,$which) +function GetRappelSimple ($p_cn,$p_jrn_id,$p_jrn_type,$p_from,$arap) { - $result=array(); + echo_debug("impress_inc",__LINE__,"function GetRappelSimple ($p_cn,$p_jrn_id,$p_jrn_type,$p_from,$arap) "); + if ( $p_jrn_type !='VEN' && $p_jrn_type != "ACH") + { + echo "ERREUR Journal invalide $p_jrn_type __FILE__ __LINE__"; + exit; + } + // find the last operation of the previous periode + $min=getDbValue($p_cn,"select max (c_id) from centralized where c_jrn_def=$p_jrn_id ". + " and c_date < (select p_start from parm_periode where p_id = $p_from)"); + if ($min == "" ) return 0; + // Find Exercice + $Exercice=GetExercice($p_cn,$p_from); + + $a_Tva=GetArray($p_cn,"select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0.0000 order by tva_id"); + + // Compute VAT + foreach ($a_Tva as $line_tva) + { + list ($deb,$cred)=split(',',$line_tva['tva_poste']); + if ( $p_jrn_type == 'ACH' ) + $ctva=$deb; + else + $ctva=$cred; + $sum_deb=getDbValue($p_cn,"select sum(j_montant) from (select distinct c_internal,j_montant ". + " from jrnx join centralized on (j_grpt=c_grp) ". + " where c_id < $min and j_poste = '$ctva' and j_debit='t' and ". + " c_jrn_def=$p_jrn_id and j_tech_per in ". + " (select p_id from parm_periode where p_exercice='$Exercice') ) as w"); + + $sum_cred=getDbValue($p_cn,"select sum(j_montant) from (select distinct c_internal,j_montant ". + " from jrnx join centralized on (j_grpt=c_grp) ". + " where c_id < $min and j_poste = '$ctva' and j_debit='f' and ". + " c_jrn_def=$p_jrn_id and j_tech_per in ". + " (select p_id from parm_periode where p_exercice='$Exercice') ) as w"); - return $result; + + $ix=$line_tva['tva_label']; + $arap[$ix]=($p_jrn_type=='ACH')?$sum_deb-$sum_cred:$sum_cred-$sum_deb; + } +// $camount=($p_jrn_type == 'ACH')?"4%":"4%"; +// $sum_htva_deb=getDbValue($p_cn,"select sum(j_montant) from (select distinct j_poste,c_internal,j_montant ". +// " from jrnx join centralized on (j_grpt=c_grp) ". +// " where c_id < $min and c_poste like '$camount' and j_debit='t' and ". +// " c_jrn_def=$p_jrn_id and j_tech_per in ". +// " (select p_id from parm_periode where p_exercice='$Exercice') ) as w"); + + +// echo $sum_htva_deb; + +// $sum_htva_cred=getDbValue($p_cn,"select sum(j_montant) from (select distinct j_poste,c_internal,j_montant ". +// " from jrnx join centralized on (j_grpt=c_grp) ". +// " where c_id < $min and c_poste like '$camount' and j_debit='f' and ". +// " c_jrn_def=$p_jrn_id and j_tech_per in ". +// " (select p_id from parm_periode where p_exercice='$Exercice') ) as w"); +// echo $sum_htva_cred; +// if ( $p_jrn_type == 'ACH' ) +// return $sum_htva_deb-$sum_htva_cred; +// else +// return $sum_htva_cred-$sum_htva_deb; +// Previous period + $previous=getDbValue($p_cn,"select max(p_id) from parm_periode where ". + "p_end < (select p_end from parm_periode where p_id=$p_from) ". + " and p_start <= (select p_start from parm_periode where p_id=$p_from)"); + + $j=new jrn($p_cn,$p_jrn_id); + $a=$j->GetRowSimple($previous,$previous,$cent='on'); + $total_tvac=0.0; + $total_htva=0.0; + foreach ($a as $line) { + $total_tvac+=$line['TVAC']; + $total_htva+=$line['HTVA']; + } + return array($total_tvac,$total_htva); } /*! * \brief Get the amount on each page