Add CBC Belgium

This commit is contained in:
sparkyx 2006-07-06 23:15:14 +00:00
parent cd91b783e5
commit bd3f33609b
9 changed files with 144 additions and 81 deletions

Binary file not shown.

View file

@ -939,6 +939,12 @@ CREATE SEQUENCE s_user_jrn
NO MAXVALUE
NO MINVALUE
CACHE 1;
CREATE SEQUENCE s_cbc
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
CREATE TABLE stock_goods (
sg_id integer DEFAULT nextval('s_stock_goods'::text) NOT NULL,
j_id integer,

View file

@ -1439,6 +1439,11 @@ CREATE SEQUENCE s_attr_def
NO MINVALUE
CACHE 1;
CREATE SEQUENCE s_cbc
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;

View file

@ -309,6 +309,11 @@ CREATE SEQUENCE s_central
NO MAXVALUE
NO MINVALUE
CACHE 1;
CREATE SEQUENCE s_cbc
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
CREATE SEQUENCE s_central_order
START WITH 1

View file

@ -556,4 +556,10 @@ insert into action values (30,'Module Gestion');
insert into format_csv_banque values ('Argenta Belgique','argenta_be.inc.php');
insert into format_csv_banque values ('CBC Belgique','cbc_be.inc.php');
CREATE SEQUENCE s_cbc
INCREMENT BY 1
NO MAXVALUE
NO MINVALUE
CACHE 1;
commit;

View file

@ -65,10 +65,10 @@ INSERT INTO format_csv_banque VALUES ('ING', 'ing_be.inc.php');
INSERT INTO format_csv_banque VALUES ('CBC', 'cbc_be.inc.php');
CREATE TABLE import_tmp (
code text,
date_exec date,
date_valeur date,
montant text,
code text not null,
date_exec date not null ,
date_valeur date not null,
montant number(20,4) not null default 0,
devise text,
compte_ordre text,
detail text,

View file

@ -181,6 +181,11 @@ td.selectedcell{
color:white;
}
td.mtitle a.mtitle {
text-decoration:none;
color:white;
}
a.mtitle {
text-decoration:none;
color:grey;

View file

@ -26,15 +26,37 @@
// Bank CBC
//-----------------------------------------------------
$row=1;
StartSql($p_cn);
while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
$num = count($data);
echo_debug('cbc_be',__LINE__,$num);
echo_debug('cbc_be',__LINE__,var_export($data,true));
for ($c=0; $c < $num; $c++) {
//-----------------------------------------------------
// Parsing CSV comes here
//-----------------------------------------------------
$row=split(';',$data[$c]);
echo_debug('cbc_be',__LINE__,'$row = '.var_export($row,true));
echo_debug('cbc_be',__LINE__,'sizeof($row)'.sizeof($row));
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=$row[7].$row[8].$row[9].$row[10];
if ( ereg('[0-9]{3}-[0-9]{7}-[0-9]{2}',$row[7],$r) )
{
$compte_ordre=$r[0];
}
//-----------------------------------------------------
// insert into import_tmp
//-----------------------------------------------------
@ -48,9 +70,9 @@ while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
bq_account ,
jrn,
ok)
values ('$code',
'$date_exec',
'$date_exec',
values (nextval('s_cbc'),
to_date('$date_exec','YYYYMMDD'),
to_date('$date_exec','YYYYMMDD'),
$montant,
'$devise',
'".addslashes($compte_ordre)."',
@ -58,6 +80,11 @@ while (($data = fgetcsv($handle, 2000,'!@')) !== FALSE) {
'$p_bq_account',
$p_jrn,
false)";
if ( ExecSql($p_cn,$Sql) == false )
{
Rollback($p_cn);
break;
}
} // for ($c=0;$c<$num;$c++)
$row++;
} // file is read

View file

@ -22,6 +22,7 @@
include_once("jrn.php");
include_once("preference.php");
include_once("user_common.php");
require_once('class_user.php');
/*!
**************************************************
* \brief Parse the file and insert the record
@ -85,90 +86,98 @@ function VerifImport($p_cn){
}
}
/*!\brief Transfert data into the ledger
* \param $p_cn connx
* \param $periode periode
*/
function TransferCSV($p_cn, $periode){
//on obtient la période courante
//$p_user = $_SESSION['g_user'];
//$periode = GetUserPeriode($p_cn,$p_user);
//$periode = $p_user->GetPeriode();
// on trouve les dates frontières de cette période
$sql = "select p_start,p_end from parm_periode where p_id = '".$periode."'";
$Res=ExecSql($p_cn,$sql);
$val = pg_fetch_array($Res);
$start = $val['p_start']; $end = $val['p_end'];
$sql = "select * from import_tmp where poste_comptable is not null and poste_comptable <> ''
AND ok <> TRUE AND date_exec BETWEEN '".$start."' and '".$end."'";
$Res=ExecSql($p_cn,$sql);
//echo "boucle: ".sizeof($Res)."<br/>";
//while($val = pg_fetch_array($Res)){
$Max=pg_NumRows($Res);
echo $Max." opérations à transférer.<br/>";
for ($i = 0;$i < $Max;$i++) {
$val=pg_fetch_array($Res,$i);
$code=$val['code']; $date_exec=$val['date_exec']; $montant=$val['montant']; $num_compte=$val['num_compte'];
$poste_comptable=$val['poste_comptable'];$bq_account=$val['bq_account'];
$jrn=$val['jrn'];
$User=new cl_user($p_cn);
$periode = $User->GetPeriode();
// on trouve les dates frontières de cette période
$sql = "select to_char(p_start,'DD-MM-YYYY') as p_start,to_char(p_end,'DD-MM-YYYY') as p_end".
" from parm_periode where p_id = '".$periode."'";
$Res=ExecSql($p_cn,$sql);
$val = pg_fetch_array($Res);
if ( $val == false )
{
echo "<script>".
"alert ('Vous devez selectionner votre période dans vos préférences');".
"</script>";
exit();
}
$start ="to_date('".$val['p_start']."','DD-MM-YYYY')";
$end = "to_date('".$val['p_end']."','DD-MM-YYYY')";
var_dump($val);
$sql = "select * from import_tmp where poste_comptable is not null and poste_comptable <> ''
and ok <> TRUE AND date_exec BETWEEN ".$start." and ".$end;
$Res=ExecSql($p_cn,$sql);
//echo "boucle: ".sizeof($Res)."<br/>";
//while($val = pg_fetch_array($Res)){
$Max=pg_NumRows($Res);
echo $Max." opérations à transférer.<br/>";
for ($i = 0;$i < $Max;$i++) {
$val=pg_fetch_array($Res,$i);
$code=$val['code']; $date_exec=$val['date_exec']; $montant=$val['montant']; $num_compte=$val['num_compte'];
$poste_comptable=$val['poste_comptable'];$bq_account=$val['bq_account'];
$jrn=$val['jrn'];
list($annee, $mois, $jour) = explode("-", $date_exec);
$date_exec = $jour.".".$mois.".".$annee;
// Vérification que le poste comptable trouvé existe
$sqltest = "select * from tmp_pcmn WHERE pcm_val='".$poste_comptable."'";
$Restest=ExecSql($p_cn,$sqltest);
$test=pg_NumRows($Restest);
if($test == 0) {
$sqlupdate = "update import_tmp set poste_comptable='' WHERE code='".$code."' AND num_compte='".$num_compte."'";
$Resupdate=ExecSql($p_cn,$sqlupdate);
echo "Poste comptable erronné pour l'opération ".$num_compte."-".$code.", réinitialisation du poste comptable<br/>";
} else {
// Finances
//$seq = GetNextId($p_cn,'j_grpt')+1;
$seq=NextSequence($p_cn,'s_grpt');
$p_user = $_SESSION['g_user'];
//$periode = GetUserPeriode($p_cn,$p_user);
//$periode = $User->GetPeriode();
StartSql($p_cn);
list($annee, $mois, $jour) = explode("-", $date_exec);
$date_exec = $jour.".".$mois.".".$annee;
// Vérification que le poste comptable trouvé existe
$sqltest = "select * from tmp_pcmn WHERE pcm_val='".$poste_comptable."'";
$Restest=ExecSql($p_cn,$sqltest);
$test=pg_NumRows($Restest);
if($test == 0) {
$sqlupdate = "update import_tmp set poste_comptable='' WHERE code='".$code."' AND num_compte='".$num_compte."'";
$Resupdate=ExecSql($p_cn,$sqlupdate);
echo "Poste comptable erronné pour l'opération ".$num_compte."-".$code.", réinitialisation du poste comptable<br/>";
} else {
// Finances
//$seq = GetNextId($p_cn,'j_grpt')+1;
$seq=NextSequence($p_cn,'s_grpt');
$p_user = $_SESSION['g_user'];
//$periode = GetUserPeriode($p_cn,$p_user);
//$periode = $User->GetPeriode();
StartSql($p_cn);
$r=InsertJrnx($p_cn,"d",$p_user,$jrn,$bq_account,$date_exec,$montant,$seq,$periode);
if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __LINE__");}
$r=InsertJrnx($p_cn,"c",$p_user,$jrn,$poste_comptable,$date_exec,$montant,$seq,$periode);
if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __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 'import_inc.php' __LINE__");}
//$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);
echo "Tranfer de l'opération ".$code." effectué<br/>";
$sql2 = "update import_tmp set ok=TRUE where code='".$code."'";
$Res2=ExecSql($p_cn,$sql2);
Commit($p_cn);
}
}
$r=InsertJrnx($p_cn,"d",$p_user,$jrn,$bq_account,$date_exec,$montant,$seq,$periode);
if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __LINE__");}
$r=InsertJrnx($p_cn,"c",$p_user,$jrn,$poste_comptable,$date_exec,$montant,$seq,$periode);
if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __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 'import_inc.php' __LINE__");}
//$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);
echo "Tranfer de l'opération ".$code." effectué<br/>";
$sql2 = "update import_tmp set ok=TRUE where code='".$code."'";
$Res2=ExecSql($p_cn,$sql2);
Commit($p_cn);
}
}
}
/*!
**************************************************
* \brief ShowForm for getting data about
* the bank transfert in cvs
*
* parm : database connection
* \param : database connection
* -
* gen :
* -
* return: none
* \return none
*/
function ShowFormTransfert($p_cn){