Add a new VMS Keytrade from jch

This commit is contained in:
Dany De Bontridder 2009-10-28 21:55:29 +00:00
parent a32bd28a69
commit 5cba85b50e
4 changed files with 136 additions and 41 deletions

View file

@ -0,0 +1,7 @@
begin;
INSERT INTO format_csv_banque(name, include_file) VALUES('VMS Keytrade', 'keytrade_be.inc.php');
update version set val=59;
commit;

View file

@ -26,7 +26,7 @@
require_once ('config.inc.php');
require_once('constant.security.php');
define ("DBVERSION",58);
define ("DBVERSION",59);
define ("MAX_COMPTE",4);
define ('MAX_BUD_DETAIL',20);

128
include/keytrade_be.inc.php Normal file
View file

@ -0,0 +1,128 @@
<?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;
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=split(';',$data[$c]);
echo_debug('keytrade',__LINE__,'$row = '.var_export($row,true));
echo_debug('keytrade',__LINE__,'sizeof($row)'.sizeof($row));
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
{
ExecSql($p_cn,$Sql,'latin1');
}
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

@ -1,40 +0,0 @@
begin;
DROP FUNCTION tva_insert (text,numeric,text,text);
CREATE FUNCTION tva_insert(text, numeric, text, text) RETURNS integer
AS $_$
declare
l_tva_id integer;
p_tva_label alias for $1;
p_tva_rate alias for $2;
p_tva_comment alias for $3;
p_tva_poste alias for $4;
debit text;
credit text;
nCount integer;
begin
if length(trim(p_tva_label)) = 0 then
return 3;
end if;
if length(trim(p_tva_poste)) != 0 then
if position (',' in p_tva_poste) = 0 then return 4; end if;
debit = split_part(p_tva_poste,',',1);
credit = split_part(p_tva_poste,',',2);
select count(*) into nCount from tmp_pcmn where pcm_val=debit::poste_comptable;
if nCount = 0 then return 4; end if;
select count(*) into nCount from tmp_pcmn where pcm_val=credit::poste_comptable;
if nCount = 0 then return 4; end if;
end if;
select into l_tva_id nextval('s_tva') ;
insert into tva_rate(tva_id,tva_label,tva_rate,tva_comment,tva_poste)
values (l_tva_id,p_tva_label,p_tva_rate,p_tva_comment,p_tva_poste);
return 0;
end;
$_$
LANGUAGE plpgsql;
commit;