From d0e21b1064653eae481c9e74515adc20ec5244a2 Mon Sep 17 00:00:00 2001 From: sparkyx Date: Mon, 27 Mar 2006 21:38:33 +0000 Subject: [PATCH] =?UTF-8?q?task=20#4898,=20Import=20CSV=20op=C3=A9ration?= =?UTF-8?q?=20banquaire=20Add=20FORTIS=20Banque=20Add=20trigger=20to=20rem?= =?UTF-8?q?ove=20disturbing=20double=20quote?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- html/admin/sql/patch/upgrade8.sql | 30 +++++++++++++++++++++++++----- include/fortis_be.inc.php | 13 +++++++++---- include/import_inc.php | 26 ++++++++++++++++++++------ 3 files changed, 54 insertions(+), 15 deletions(-) diff --git a/html/admin/sql/patch/upgrade8.sql b/html/admin/sql/patch/upgrade8.sql index 8fae913ea..dc656bc06 100644 --- a/html/admin/sql/patch/upgrade8.sql +++ b/html/admin/sql/patch/upgrade8.sql @@ -18,9 +18,9 @@ create table format_csv_banque name text primary key, include_file text not null ); -drop trigger trim_space on format_csv_banque; - -drop function trim_space_format_csv_banque(); +-- drop trigger trim_space on format_csv_banque; +-- +-- drop function trim_space_format_csv_banque(); create function trim_space_format_csv_banque() returns trigger as $trim$ declare @@ -58,10 +58,30 @@ CREATE TABLE import_tmp ( num_compte text, poste_comptable text, ok boolean DEFAULT false, - bq_account integer, - jrn integer + bq_account integer not null, + jrn integer not null ); +create function trim_cvs_quote() returns trigger as $trim$ +declare + modified import_tmp%ROWTYPE; +begin + modified.code=new.code; + modified.montant=new.montant; + modified.date_exec=new.date_exec; + modified.date_valeur=new.date_valeur; + modified.devise=replace(new.devise,'"',''); + modified.poste_comptable=replace(new.poste_comptable,'"',''); + modified.compte_ordre=replace(NEW.COMPTE_ORDRE,'"',''); + modified.detail=replace(NEW.DETAIL,'"',''); + modified.num_compte=replace(NEW.NUM_COMPTE,'"',''); + modified.bq_account=NEW.bq_account; + modified.jrn=NEW.jrn; + modified.ok=new.ok; + return modified; +end; +$trim$ language plpgsql; +create trigger trim_quote before insert or update on import_tmp FOR EACH ROW execute procedure trim_cvs_quote(); update version set val=9; diff --git a/include/fortis_be.inc.php b/include/fortis_be.inc.php index d244a38aa..abcbee25c 100644 --- a/include/fortis_be.inc.php +++ b/include/fortis_be.inc.php @@ -8,7 +8,8 @@ if ( $row>1) { $code=""; $date_exec=""; $date_valeur=""; $montant=""; $devise=""; $compte_ordre=""; $detail=""; $num_compte=""; $iduser=""; list($code, $date_exec, $date_valeur, $montant, $devise, $compte_ordre, $detail, $num_compte) = split(";", $data[$c]); - + echo "line : $row > ".$data[$c]."
"; + //corrige un bug de date $date_exec = str_replace(chr(34),"", $date_exec); @@ -34,11 +35,14 @@ if ( $row>1) { $montant = str_replace(",", ".", $montant); $montant = str_replace("+", "", $montant); + $montant = str_replace("\"", "", $montant); + $detail=str_replace("\"","",$detail); + $sql = "select * from import_tmp where code='".$code."' and - num_compte='".$p_bq_account."'"; + num_compte='".$num_compte."'"; $Res=ExecSql($p_cn,$sql); $Num=pg_NumRows($Res); @@ -55,7 +59,7 @@ if ( $row>1) { detail, num_compte, bq_account , - jrn + jrn, ok) values ('$code', '$date_exec', @@ -64,7 +68,8 @@ if ( $row>1) { '$devise', '".addslashes($compte_ordre)."', '".addslashes($detail)."', - '$p_bq_account', + '$num_compte', + $p_bq_account, $p_jrn, false)"; diff --git a/include/import_inc.php b/include/import_inc.php index 0f532d92d..f0ea4817c 100644 --- a/include/import_inc.php +++ b/include/import_inc.php @@ -44,8 +44,11 @@ function ImportCSV($p_cn,$file,$p_bq_account,$p_format_csv,$p_jrn) print 'could not open file. quitting'; die; } + +StartSql($p_cn); + $row = 1; - while (($data = fgetcsv($handle, 2000, '#@!')) !== FALSE) { + while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) { $num = count($data); for ($c=0; $c < $num; $c++) { // include the right format for CSV --> given by the
@@ -56,6 +59,16 @@ function ImportCSV($p_cn,$file,$p_bq_account,$p_format_csv,$p_jrn) } echo "Importation terminée."; fclose($handle); +// if importation succeeds then we can commit the change +Commit($p_cn); +/* Done by trigger +// clean all the double quote +$sql="update import_tmp set + compte_ordre=replace(compte_ordre,'\"',''), + detail=replace(detail,'\"',''), + num_compte=replace(num_compte,'\"','');"; +ExecSql($p_cn,$sql);*/ + } function UpdateCSV($p_cn, $code, $poste){ @@ -130,15 +143,16 @@ function TransferCSV($p_cn, $periode){ //$periode = GetUserPeriode($p_cn,$p_user); //$periode = $User->GetPeriode(); StartSql($p_cn); - -// if($num_compte == '001-3983978-70') $r=InsertJrnx($p_cn,"d",$p_user,$p_jrn,'55000001',$date_exec,$montant,$seq,$periode); -// elseif ($num_compte == '360-1062770-44' ) $r=InsertJrnx($p_cn,"d",$p_user,$p_jrn,'55000002',$date_exec,$montant,$seq,$periode); -// elseif ($num_compte == '671-9032279-01' ) $r=InsertJrnx($p_cn,"d",$p_user,$p_jrn,'55000003',$date_exec,$montant,$seq,$periode); + $r=InsertJrnx($p_cn,"d",$p_user,$jrn,$bq_account,$date_exec,$montant,$seq,$periode); if ( $r == false) { $Rollback($p_cn);exit("error __FILE__ __LINE__");} $r=InsertJrnx($p_cn,"c",$p_user,$jrn,$poste_comptable,$date_exec,$montant,$seq,$periode); if ( $r == false) { $Rollback($p_cn);exit("error __FILE__ __LINE__");} + + //remove annoying double-quote + $num_compte=str_replace('"','',$num_compte); + $code=str_replace('\"','',$code); $r=InsertJrn($p_cn,$date_exec,NULL,$jrn,$num_compte." ".$code,$montant,$seq,$periode); if ( $r == false ) { Rollback($p_cn); exit(" Error __FILE__ __LINE__");} @@ -146,12 +160,12 @@ function TransferCSV($p_cn, $periode){ //$sql = "insert into jrn (jr_def_id,jr_montant,jr_comment,jr_date,jr_grpt_id,jr_tech_per) values ( ".$p_jrn.", abs(".round($montant,2)."), '".$num_compte." ".$code."','".$date_valeur."','".$seq."','".$periode."')"; SetInternalCode($p_cn,$seq,$jrn); - Commit($p_cn); echo "Tranfer de l'opération ".$code." effectué
"; $sql2 = "update import_tmp set ok=TRUE where code='".$code."'"; $Res2=ExecSql($p_cn,$sql2); + Commit($p_cn); } } }