From 9c8f8b483f799e09bb74e130af4e319cda9ecefe Mon Sep 17 00:00:00 2001 From: Dany De Bontridder Date: Sat, 17 Jul 2010 16:49:54 +0000 Subject: [PATCH] fs#135 number in cvs are formatted thanks the function ac_common::nb, it wil help the users who are using excel --- html/bal_csv.php | 21 ++++++++++----------- html/form_csv.php | 4 ++-- html/jrn_csv.php | 24 +++++++++++------------- html/poste_csv.php | 12 ++++++------ include/ac_common.php | 10 ++++++++++ 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/html/bal_csv.php b/html/bal_csv.php index f61f0e67e..cca1647ce 100644 --- a/html/bal_csv.php +++ b/html/bal_csv.php @@ -69,16 +69,15 @@ $bal->to_poste=$_GET['to_poste']; $row=$bal->get_row($_GET['from_periode'], $_GET['to_periode']); - foreach ($row as $r) { - - echo $r['poste'].';'. - $r['label'].';'. - $r['sum_deb'].';'. - $r['sum_cred'].';'. - $r['solde_deb'].';'. - $r['solde_cred']; - printf("\n"); - } - +foreach ($row as $r) { + echo $r['poste'].';'. + $r['label'].';'. + nb($r['sum_deb']).';'. + nb($r['sum_cred']).';'. + nb($r['solde_deb']).';'. + nb($r['solde_cred']); + printf("\n"); +} + ?> diff --git a/html/form_csv.php b/html/form_csv.php index 04c0345c5..bcc42e9e5 100644 --- a/html/form_csv.php +++ b/html/form_csv.php @@ -61,7 +61,7 @@ if ( $_GET['p_step'] == 0 ) foreach ( $Form->row as $op ) { echo '"'.$op['desc'].'"'.";". - sprintf("%8.2f",$op['montant']). + nb($op['montant']). "\n"; } @@ -97,7 +97,7 @@ if ( $_GET['p_step'] == 0 ) $a++; foreach ($e as $elt) { - printf(";%s",$elt['montant']); + printf(";%s",nb($elt['montant'])); } printf("\n"); } diff --git a/html/jrn_csv.php b/html/jrn_csv.php index acd8697cc..8d937ecca 100644 --- a/html/jrn_csv.php +++ b/html/jrn_csv.php @@ -69,14 +69,14 @@ if ( $_GET['p_simple'] == 0 ) $desc=str_replace('"',"'",$desc); $desc=str_replace(";",",",$desc); - printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%8.4f;%8.4f\n", + printf("\"%s\";\"%s\";\"%s\";\"%s\";\"%s\";%s;%s\n", $op['j_id'], $op['internal'], $op['j_date'], $op['poste'], $desc, - $op['deb_montant'], - $op['cred_montant'] + nb($op['deb_montant']), + nb($op['cred_montant']) ); } @@ -118,17 +118,15 @@ if ( $_GET['p_simple'] == 0 ) // the credit must be negative and written in red // Get the jrn type if ( $line['jrn_def_type'] == 'FIN' ) { - $positive = $cn->count_sql("select * from jrn inner join jrnx on jr_grpt_id=j_grpt ". - " where jr_id=".$line['jr_id']." and $sql_fin ". - " and j_debit='f'"); + $positive = $cn->get_value("select qf_amount from quant_fin ". + " where jr_id=".$line['jr_id']); - - echo ( $positive != 0 )?sprintf("-%8.2f",$line['montant']):sprintf("%8.2f",$line['montant']); + echo nb($positive); echo ";"; } else { - printf("% 8.2f",$line['montant']).";"; + echo nb($line['montant']).";"; } printf("\r\n"); @@ -150,13 +148,13 @@ if ( $_GET['p_simple'] == 0 ) echo '"Date";"operation";"Client/Fourn.";"Commentaire";"inter.";"HTVA";'.$col_tva.'"TVAC"'."\n\r"; foreach ($Row as $line) { - printf('"%s";"%s";"%s";"%s";"%s";% 10.2f;', + printf('"%s";"%s";"%s";"%s";"%s";%s;', $line['date'], $line['num'], $line['client'], $line['comment'], $line['jr_internal'], - $line['HTVA']); + nb($line['HTVA'])); $a_tva_amount=array(); foreach ($line['TVA'] as $lineTVA) { @@ -175,12 +173,12 @@ if ( $_GET['p_simple'] == 0 ) { $a=$line_tva['tva_id']; if ( isset($a_tva_amount[$a])) - printf("% 8.2f;",$a_tva_amount[$a]); + echo nb($a_tva_amount[$a]); else printf("0;"); } } - printf("% 9.2f\r\n",$line['TVAC']); + echo nb ($line['TVAC']); } } } diff --git a/html/poste_csv.php b/html/poste_csv.php index 44eb1d2c2..f20317831 100644 --- a/html/poste_csv.php +++ b/html/poste_csv.php @@ -79,8 +79,8 @@ if ( ! isset ($_REQUEST['oper_detail'])) { '"'.$op['jr_internal'].'"'.";". '"'.$op['j_date_fmt'].'"'.";". '"'.$op['description']." ".$op['jr_pj_number'].'"'.";". - sprintf("%8.4f",$op['deb_montant']).";". - sprintf("%8.4f",$op['cred_montant']); + nb($op['deb_montant']).";". + nb($op['cred_montant']); printf("\n"); @@ -89,9 +89,9 @@ if ( ! isset ($_REQUEST['oper_detail'])) { $diff=abs($tot_deb-$tot_cred); printf( '"'."$solde_type".'"'.";". - sprintf("%8.4f",$diff).";". - sprintf("%8.4f",$tot_deb).";". - sprintf("%8.4f",$tot_cred)."\n"); + nb($diff).";". + nb($tot_deb).";". + nb($tot_cred)."\n"); } } else { /* detail of all operation */ @@ -132,7 +132,7 @@ if ( ! isset ($_REQUEST['oper_detail'])) { $r['jr_date'], $a['description'], $a['jr_pj_number'], - $r['j_montant'], + nb($r['j_montant']), $r['debit']); printf("\r\n"); diff --git a/include/ac_common.php b/include/ac_common.php index 53d495ea6..4bcc19438 100644 --- a/include/ac_common.php +++ b/include/ac_common.php @@ -43,6 +43,16 @@ function td($p_string='',$p_extra=''){ return ''.$p_string.''.$p_string.'';} /*!\brief escape correctly php string to javascript */ function j($p_string) { $a=preg_replace("/\r?\n/", "\\n", addslashes($p_string)); return $a;} +/** + * format the number for the CSV export + *@param $p_number number + */ +function nb($p_number) { + $r=sprintf('%.2f',$p_number); + $r=str_replace('.',',',$r); + return $r; +} + /*! * \brief log error into the /tmp/phpcompta_error.log it doesn't work on windows *