#10 replace import bank by plugin

This commit is contained in:
Dany De Bontridder 2011-06-29 16:50:38 +00:00
parent 592f551bc5
commit ccc0ce7d48
10 changed files with 2 additions and 1099 deletions

View file

@ -1,127 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*! \file
* \brief This file must be included to parse the CVS from the CBC Bank
*/
//-----------------------------------------------------
// Bank Argenta
//-----------------------------------------------------
$line=0;
$p_cn->set_encoding('latin1');
while (($data = fgetcsv($handle, 2000,"!")) !== FALSE)
{
$num = count($data);
for ($c=0; $c < $num; $c++)
{
if ( $line==1)
{
$row=explode(';',$data[$c]);
$num_compte=$row[1];
}
if ( $line < 2 )
continue;
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
$row=explode(';',$data[$c]);
echo 'ici sizeof $row = '.sizeof($row);
if ( sizeof ($row) < 9 )
continue;
$date_exec=$row[5];
$date_val=$row[5];
$code=$row[1]."/".$row[0];
// remove first the thousand sep.
$montant=str_replace('.','',$row[3]);
// replace the coma by a period
$montant=str_replace(',','.',$montant);
// remove the sign
$montant=str_replace('+','',$montant);
$devise=$row[4];
$compte_ordre=$row[6];
$detail='virement du compte:'.$compte_ordre.trim($row[2]).' '.trim($row[7]).' '.trim($row[8]).' '.trim($row[9]);
//----------------------------------------------------
// Skip dubbel
//----------------------------------------------------
$code=FormatString($code);
$num_compte=FormatString($num_compte);
if ( $p_cn->count_sql(utf8_encode("select * from import_tmp where code='$code' and num_compte='$num_compte' limit 2")) != 0 )
{
/* Skip it it already encoded */
echo "Doublon éliminé ".$detail;
echo "<br>";
continue;
}
echo "Ajout de $detail";
echo "<br>";
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
compte_ordre,
num_compte,
detail,
bq_account ,
jrn,
status)
values ('$code',
to_date('$date_exec','DD-MM-YYYY'),
to_date('$date_exec','DD-MM-YYYY'),
$montant,
'$devise',
'".addslashes($compte_ordre)."',
'".$num_compte."',
'".addslashes($detail)." ',
'$p_bq_account',
$p_jrn,
'n')";
try
{
$p_cn->exec_sql($Sql);
}
catch(Exception $e)
{
echo(__FILE__.":".__LINE__." Erreur : ".$e->getCode()." msg ".$e->getMessage());
rollback($p_cn);
break;
}
} // for ($c=0;$c<$num;$c++)
$line++;
} // file is read
fclose($handle);
$p_cn->commit();
?>

View file

@ -1,96 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*! \file
* \brief This file must be included to parse the CVS from the CBC Bank
*/
//-----------------------------------------------------
// Bank CBC
//-----------------------------------------------------
$row=1;
$p_cn->start();
$p_cn->set_encoding('latin1');
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
{
$num = count($data);
for ($c=0; $c < $num; $c++)
{
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
$row=explode(';',$data[$c]);
if ( sizeof ($row) < 13 )
continue;
$num_compte=$row[0];
$date_exec=$row[3];
$date_val=$row[4];
// remove first the thousand sep.
$montant=str_replace('.','',$row[6]);
// replace the coma by a period
$montant=str_replace(',','.',$montant);
// remove the sign
$montant=str_replace('+','',$montant);
$devise=$row[1];
$compte_ordre=$row[0];
$detail=trim($row[7]).' '.trim($row[8]).' '.trim($row[9]).' '.trim($row[10]);
if ( myereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[7],$r) )
{
$compte_ordre=$r[0];
}
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
compte_ordre,
detail,
bq_account ,
jrn,
status)
values (nextval('s_cbc'),
to_date('$date_exec','YYYYMMDD'),
to_date('$date_exec','YYYYMMDD'),
$montant,
'$devise',
'".addslashes($compte_ordre)."',
'".addslashes($detail).$num_compte." ',
'$p_bq_account',
$p_jrn,
'n')";
try
{
$p_cn->exec_sql($Sql) ;
}
catch(Exception $e)
{
$p_cn->rollback();
break;
}
} // for ($c=0;$c<$num;$c++)
$row++;
} // file is read
fclose($handle);
echo "Encore rien désolé";
?>

View file

@ -1,93 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision: 3151 $ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*! \file
* \brief This file must be included to parse the CVS from the CBC Bank
*/
//-----------------------------------------------------
// Bank CBC
//-----------------------------------------------------
$line=0;
$p_cn->start();
$p_cn->set_encoding('latin1');
while (($row = fgetcsv($handle, 2000,';')) !== FALSE)
{
$num = count($row);
if ( $num != 11 ) continue;
if ( $row[3] != 'EUR') continue;
$line++;
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
$num_compte=$row[0];
$date_exec=$row[5];
$date_val=$row[7];
// remove first the thousand sep.
$montant=str_replace(' ','',$row[8]);
// replace the coma by a period
$montant=str_replace(',','.',$montant);
// remove the sign
$montant=str_replace('+','',$montant);
$devise=$row[3];
$ref_extrait=$row[4].'-'.$line;
$detail=$line.'/'.$row[4].' '.$row[6];
$pj=$row[10];
//
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
detail,
bq_account ,
jrn,
status,
it_pj)
values ('$ref_extrait',
to_date('$date_exec','DD/MM/YYYY'),
to_date('$date_exec','DD/MM/YYYY'),
$montant,
'$devise',
'$detail',
'$p_bq_account',
$p_jrn,
'n',$pj)";
try
{
$p_cn->exec_sql($Sql) ;
}
catch(Exception $e)
{
$p_cn->rollback();
break;
}
} // file is read
fclose($handle);
if ($line ==0 )
echo "Encore rien désolé";
else
echo "$line lignes sont importées";
echo '<br>';
?>

View file

@ -1,149 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// Author DEXIA Adaptation Guy Moins
/*! \file
* \brief This file must be included to parse the CVS from the DEXIA Bank
*/
//-----------------------------------------------------
// Bank DEXIA
//-----------------------------------------------------
$LinesSkipped=0;
$LinesImported=0;
$LinesDup=0;
$row=1;
$p_cn->start();
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
{
$num = count($data);
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
$row=explode(';',$data[0]);
//to avoid a level of if
if (!(isset($row[2]))) $row[2]='';
// Skipping all the lines whith a blank operation reference ('numéro extrait')
if ( $row[2] == '' ||
!(myereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[0],$r)))
{
$LinesSkipped++;
continue;
}
// Alternative filter : import all the operations even without a reference
// !! Disable check of doubles as all the unreferenced operations have hte smae
//NULL' reference
// Just use the following test : if (
//!(myereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[0],$r)))
// Parsing the remaining lines
$num_compte=$row[3]; // Third party bank account
$date_exec=$row[1]; // Execution date of the operation
$date_val=$row[8]; // Effective date of the operation
// remove the thousand sep. ** UNUSED by DEXIA
//$montant=str_replace('.','',$row[9]);
// remove the sign ** UNUSED by DEXIA
//$montant=str_replace('+','',$montant);
// replace the coma by a period
$montant=str_replace(',','.',$row[9]); // Amount of the operation
$ref_extrait=$row[2]; // Operation reference
$devise=$row[10]; // Curency used
$compte_ordre=$row[0]; // Your own bank account
$detail=trim($row[4]).' '.trim($row[5]).' '.trim($row[6]).'
'.trim($row[7]);
//Details-Communicaion
//----------------------------------------------------
// Skip dubbel
//----------------------------------------------------
$Sql="select * from import_tmp where code='$ref_extrait' and
compte_ordre='$compte_ordre' limit 2";
if ( $p_cn->count_sql($Sql) > 0)
{
/* Skip it it already encoded */
echo "Double skipped : $ref_extrait $detail <BR>";
$LinesDup++;
continue;
}
//--------------------------------------------------------------------
// SQL request to insert into import_tmp
// Adapt the format of the import's date in the ** to_date ** function
//--------------------------------------------------------------------
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
compte_ordre,
detail,
num_compte,
bq_account ,
jrn,
status)
values ( '$ref_extrait',
to_date('$date_exec','DD/MM/YYYY'),
to_date('$date_val' ,'DD/MM/YYYY'),
$montant,
'$devise',
'" . addslashes($compte_ordre). "',
'".addslashes($detail)."','" .$num_compte." ',
'$p_bq_account',
$p_jrn,
'n')";
//-----------------------------------------------------
// Check if no need to rollback when executing the SQL
//-----------------------------------------------------
try
{
$p_cn->exec_sql($Sql);
}
catch (Exception $e)
{
$p_cn->rollback();
echo "Rollbacking : $ref_extrait $detail <BR>";
$LinesSkipped++;
continue;
}
//-----------------------------------------------------
// The import is OK
//-----------------------------------------------------
$LinesImported++;
$row++;
echo "Record imported: $ref_extrait $detail <BR>";
}
//-----------------------------------------------------
// Close and summary
//-----------------------------------------------------
fclose($handle);
echo "<BR><B>$LinesImported operation(s) imported, $LinesSkipped text or invalid
line(s) skipped, $LinesDup operation(s) skipped as already imported<BR>";
?>

View file

@ -1,138 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// Author DEXIA Adaptation Guy Moins
/*! \file
* \brief This file must be included to parse the CVS from the DEXIA Bank
*/
//-----------------------------------------------------
// Bank DEXIA
//-----------------------------------------------------
$LinesSkipped=0;
$LinesImported=0;
$LinesDup=0;
$row=1;
$p_cn->start();
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
{
$num = count($data);
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
$row=explode(';',$data[0]);
//to avoid a level of if
if (!(isset($row[2]))) $row[2]='';
// Skipping all the lines whith a blank operation reference ('numéro extrait')
if ( $row[2] == '' || !(myereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[0],$r)))
{
$LinesSkipped++;
continue;
}
// Alternative filter : import all the operations even without a reference
// !! Disable check of doubles as all the unreferenced operations have hte smae 'NULL' reference
// Just use the following test : if ( !(myereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[0],$r)))
// Parsing the remaining lines
$num_compte=$row[3]; // Third party bank account
$date_exec=$row[1]; // Execution date of the operation
$date_val=$row[8]; // Effective date of the operation
$montant=str_replace(',','.',$row[9]); // Amount of the operation
$ref_extrait=$row[2]; // Operation reference
$devise=$row[10]; // Curency used
$compte_ordre=$row[0]; // Your own bank account
$detail=trim($row[4]).' '.trim($row[5]).' '.trim($row[6]).' '.trim($row[7]);
//Details-Communicaion
//----------------------------------------------------
// Skip dubbel
//----------------------------------------------------
$Sql="select * from import_tmp where code='$ref_extrait' and compte_ordre='$compte_ordre' limit 2";
if ( $p_cn->count_sql(utf8_encode($Sql)) > 0)
{
/* Skip it it already encoded */
echo "Double skipped : $ref_extrait $detail <BR>";
$LinesDup++;
continue;
}
//--------------------------------------------------------------------
// SQL request to insert into import_tmp
// Adapt the format of the import's date in the ** to_date ** function
//--------------------------------------------------------------------
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
compte_ordre,
detail,
num_compte,
bq_account ,
jrn,
status)
values ( '$ref_extrait',
to_date('$date_exec','DD/MM/YYYY'),
to_date('$date_val' ,'DD/MM/YYYY'),
$montant,
'$devise',
'" . addslashes($compte_ordre). "',
'".addslashes($detail)."','" .$num_compte." ',
'$p_bq_account',
$p_jrn,
'n')";
//-----------------------------------------------------
// Check if no need to rollback when executing the SQL
//-----------------------------------------------------
try
{
$p_cn->exec_sql($Sql,'latin1') ;
}
catch (Exception $e)
{
$p_cn->rollback();
echo "Rollbacking : $ref_extrait $detail <BR>";
$LinesSkipped++;
break;
}
//-----------------------------------------------------
// The import is OK
//-----------------------------------------------------
$LinesImported++;
$row++;
echo "Record imported: $ref_extrait $detail <BR>";
}
//-----------------------------------------------------
// Close and summary
//-----------------------------------------------------
fclose($handle);
echo "<BR><B>$LinesImported operation(s) imported, $LinesSkipped text or invalid line(s) skipped, $LinesDup operation(s) skipped as already imported<BR>";
?>

View file

@ -1,87 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// Author Olivier Dzwoniarkiewicz
/*! \file
* \brief File included to parse CSV from EUB Bank
*/
//-----------------------------------------------------
// Bank type = eub
//-----------------------------------------------------
$row=1;
$p_cn->set_encoding('latin1');
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
{
$num = count($data);
for ($c=0; $c < $num; $c++)
{
// first line is skipped
if ( $row > 1)
{
$code="";
$date_exec="";
$detail="";
$montant="";
list($code, $date_exec, $detail, $montant) = explode(";", $data[$c]);
$date_exec = str_replace("\t", "", $date_exec);
$date_exec = str_replace(" ", "", $date_exec);
list($annee,$mois,$jour) = explode("-", $date_exec);
$montant = str_replace(".", "", $montant);
$montant = str_replace(",", ".", $montant);
$montant = str_replace("+", "", $montant);
if($code < 10) $code = "000".$code;
if($code >= 10 and $code < 100) $code = "00".$code;
if($code >= 100) $code = "0".$code;
$code = $annee."-".$code;
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
detail,
num_compte,
bq_account ,
jrn,
status)
values ('$code',
'$date_exec',
'$date_exec',
'$montant',
'EUR',
'".addslashes($detail)."',
'$p_bq_account',
$p_jrn,
'n')";
$Res=$p_cn->exec_sql($Sql);
}
} // for ($c=0;$c<$num;$c++)
$row++;
} // file is read
fclose($handle);
?>

View file

@ -1,137 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// Author Olivier Dzwoniarkiewicz
/*! \file
* \brief File to include : parse the CSV file from fortis Bank Belgium
*/
//-----------------------------------------------------
// Fortis Bank
//-----------------------------------------------------
$row=1;
$must_field=7; // The mandatory number of fields
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
{
$num = count($data);
for ($c=0; $c < $num; $c++)
{
$nb_field=substr_count($data[$c],";");
// first line is skipped
if ( $row>1 && $nb_field == $must_field)
{
$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) = explode(";", $data[$c]);
echo "line : $row > ".$data[$c]."<hr>";
//corrige un bug de date
$date_exec = str_replace(chr(34),"", $date_exec);
// Si LTXXXXX ou LT XXXXX dans le détail
if ((myereg ("LT+([0-9]{5})", $detail, $regs)) || (myereg ("LT+[ ]+([0-9]{5})", $detail, $regs)))
{
$iduser = $regs[1];
}
// Si 00000XXXXXXX
if (myereg ("[0-9]{12}", $detail, $regs))
{
if($regs[0] != "000000000000")
{
$id = substr($regs[0], 5, 5);
$check = substr($regs[0], 10, 2);
if (($id % 97) == $check) $iduser = $id;
}
}
if($iduser != "" ) $poste_comptable = "400".$iduser;
else $poste_comptable = "";
list($jour,$mois,$annee) = explode("/", $date_exec);
$date_exec = $annee."-".$mois."-".$jour;
list($jour,$mois,$annee) = explode("/", $date_valeur);
$date_valeur = $annee."-".$mois."-".$jour;
$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='".$num_compte."'";
$sql=utf8_encode($sql);
$Res=$p_cn->exec_sql($sql);
$Num=Database::num_row($Res);
if($Num > 0 )
{
echo "Op&eacute;ration FORTIS ".$code." d&eacute;j&eagrave; import&eacute;e.<br/>";
}
else
{
$Sql="insert into import_tmp (code ,
date_exec ,
date_valeur,
montant,
devise,
compte_ordre,
detail,
num_compte,
bq_account ,
jrn,
status)
values ('$code',
'$date_exec',
'$date_exec',
'$montant',
'$devise',
'".addslashes($compte_ordre)."',
'".addslashes($detail)."',
'$num_compte',
'$p_bq_account',
$p_jrn,
'n')";
$Res=$p_cn->exec_sql($Sql);
}
}
} // for ($c=0;$c<$num;$c++)
$row++;
} // file is read
fclose($handle);
?>

View file

@ -1,143 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
// Author Olivier Dzwoniarkiewicz
/*! \file
* \brief File to be included to parse CSV from ING Belgium
*/
//-----------------------------------------------------
// Bank ING
//-----------------------------------------------------
$row=1;
$p_cn->set_encoding('latin1');
while (($data = fgetcsv($handle, 2000,'@')) !== FALSE)
{
$num = count($data);
for ($c=0; $c < $num; $c++)
{
// first line is skipped
if ( $row > 1 )
{
$code="";
$date_exec="";
$date_valeur="";
$montant="";
$devise="";
$compte_ordre="";
$detail="";
$num_compte="";
$iduser="";
list($num_compte, $code, $date_exec, $date_valeur, $montant, $devise, $montant2, $devise2, $rubriques, $detail, $zzz, $zzz, $date_comptable) = explode(";", $data[$c]);
# Bug CSV ING : "424 au lieu de 424
#"
$code = str_replace("\"", "", $code);
# Bug CSV ING : espace apres la date
$date_exec = str_replace(" ", "", $date_exec);
$date_valeur = str_replace(" ", "", $date_valeur);
$date_exec = str_replace("\"", "", $date_exec);
$date_valeur = str_replace("\"", "", $date_valeur);
$montant = str_replace("\"", "", $montant);
if ((myereg ("([0-9]{3})-([0-9]{7})-([0-9]{2})", $num_compte, $regs)))
{
$num_compte = $regs[0];
}
// Si LTXXXXX ou LT XXXXX dans le détail
if ((myereg ("LT+([0-9]{5})", $detail, $regs)) || (myereg ("LT+[ ]+([0-9]{5})", $detail, $regs)))
{
$iduser = $regs[1];
}
// Si XXXXXXXXXXXX
if (myereg ("[0-9]{12}", $detail, $regs))
{
if($regs[0] != "000000000000")
{
$id = substr($regs[0], 2, 5);
$longchiffre = substr($regs[0], 0, 10);
$check = substr($regs[0], 10, 2);
if (($longchiffre % 97) == $check) $iduser = $id;
}
}
if($iduser != "" ) $poste_comptable = "400".$iduser;
else $poste_comptable = "";
list($jour,$mois,$annee) = explode("/", $date_valeur);
$date_valeur = $annee."-".$mois."-".$jour;
list($jour,$mois,$annee) = explode("/", $date_exec);
$date_exec = $annee."-".$mois."-".$jour;
$montant = str_replace(",", ".", $montant);
$montant = str_replace("+", "", $montant);
if($code < 10) $code = "000".$code;
if($code >= 10 and $code < 100) $code = "00".$code;
if($code >= 100) $code = "0".$code;
$code = $annee."-".$code;
$sql = "select * from import_tmp where code='".$code."' and num_compte='".$num_compte."'";
$Res=$p_cn->exec_sql($sql);
$Num=Database::num_row($Res);
if($Num > 0)
{
echo "Op&eacute;ration FORTIS ".$code." d&eacute;j&eagrave; import&eacute;e.<br/>";
}
else
{
//echo $code." ".$date_exec." ".$date_valeur." ".$montant." ".$devise." ".$compte_ordre." detail ".$num_compte." <b>".$poste_comptable."</b><br/>";
//$Sql="insert into import_tmp values ('$code','$date_exec','$date_valeur','$montant','$devise','".addslashes($compte_ordre)."','".addslashes($detail)."','$num_compte','$poste_comptable')";
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
compte_ordre,
detail,
bq_account ,
jrn,
status)
values ('$code',
'$date_exec',
'$date_exec',
$montant,
'$devise',
'".addslashes($compte_ordre)."',
'".addslashes($detail).$num_compte." ',
'$p_bq_account',
$p_jrn,
'n')";
echo $sql;
$Res=$p_cn->exec_sql($Sql);
}
}
} // for ($c=0;$c<$num;$c++)
$row++;
} // file is read
fclose($handle);
?>

View file

@ -1,129 +0,0 @@
<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision: ??2162?? $ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*! \file
* \brief This file must be included to parse the CVS from the Keytrade Bank
*/
//-----------------------------------------------------
// Bank Keytrade
//-----------------------------------------------------
$line=0;
$p_cn->set_encoding('latin1');
while (($data = fgetcsv($handle, 2000,"!")) !== FALSE)
{
$num = count($data);
for ($c=0; $c < $num; $c++)
{
// skip the first line
if ( $line < 1 )
continue;
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
$row=explode(';',$data[$c]);
if ( sizeof ($row) < 7 )
continue;
// Your own bank account
$compte_ordre='';
// Execution date of the operation
$date_exec=str_replace('/','-',$row[0]);
// Operation reference, it must be unique, so we take the datum
// the line number and a random number
$r=rand(1,1000);
$code=$date_exec.'-'.$line.$r;
// Effective date of the operation
$date_val=str_replace('/','-',$row[1]);
// Third party bank account
$num_compte=$row[2];
//
$detail=trim($row[3]);
//
$signe=trim($row[4]);
//
// remove first the thousand sep.
$montant=str_replace('.','',$row[5]);
// replace the coma by a period
$montant=str_replace(',','.',$montant);
// remove the sign
//$montant=str_replace('+','',$montant);
// use the sign
if ($signe == '-')
$montant='-'.$montant;
// Curency used
$devise=trim($row[6]);
//----------------------------------------------------
// Skip dubbel impossible
//----------------------------------------------------
echo "Ajout de $detail";
echo "<br>";
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
$Sql="insert into import_tmp (code,
date_exec ,
date_valeur,
montant,
devise,
num_compte,
detail,
bq_account ,
jrn,
status)
values ('$code',
to_date('$date_exec','DD-MM-YYYY'),
to_date('$date_exec','DD-MM-YYYY'),
$montant,
'$devise',
'".$num_compte."',
'".addslashes($detail)." ',
'$p_bq_account',
$p_jrn,
'n')";
try
{
$p_cn->exec_sql($Sql);
}
catch(Exception $e)
{
echo(__FILE__.":".__LINE__." Erreur : ".$e->getCode()." msg ".$e->getMessage());
rollback($p_cn);
break;
}
} // for ($c=0;$c<$num;$c++)
$line++;
} // file is read
fclose($handle);
commit($p_cn);
?>

View file

@ -0,0 +1,2 @@
drop table public.import_tmp;
drop table public.format_csv_banque;