start();
// include the right format for CSV --> given by the
';
}
}
/*!\brief ConfirmCSV shows the operation which are going to be transfered
*
* \param $p_cn database conx
* \param $periode user's periode
*/
function ConfirmTransfert($p_cn,$periode)
{
$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=$p_cn->exec_sql($sql);
$val = Database::fetch_array($Res);
if ( $val == false )
{
alert (_('Vous devez selectionner votre période dans vos préférences'));
exit();
}
$start ="to_date('".$val['p_start']."','DD-MM-YYYY')";
$end = "to_date('".$val['p_end']."','DD-MM-YYYY')";
$sql = "select code,to_char(date_exec,'DD.MM.YYYY') as date_exec, ".
" montant,num_compte,poste_comptable,bq_account,jrn,detail,jr_rapt ".
" from import_tmp where
status = 'w' AND date_exec BETWEEN ".$start." and ".$end;
$Res=$p_cn->exec_sql($sql);
$Num=Database::num_row($Res);
echo $Num." "._("opérations à transfèrer")."
";
if ( $Num == 0 ) return;
for ( $i=0;$i<$Num;$i++)
{
$val = Database::fetch_array($Res,$i);
echo '';
}
echo '';
}
/*!\brief Transfert data into the ledger
* set the column import_tmp.status to w (wait) if the account is not correct
* otherwise transfert it to the ledger and set the column import_tmp.status
* to t (transfert)
* \param $p_cn connx
* \param $periode periode
*/
function TransferCSV($p_cn, $periode)
{
//on obtient la période courante
$User=new User($p_cn);
$periode = $User->get_periode();
// 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=$p_cn->exec_sql($sql);
$val = Database::fetch_array($Res);
if ( $val == false )
{
alert (_('Vous devez selectionner votre période dans vos préférences'));
exit();
}
$start ="to_date('".$val['p_start']."','DD-MM-YYYY')";
$end = "to_date('".$val['p_end']."','DD-MM-YYYY')";
$sql = "select code,to_char(date_exec,'DD.MM.YYYY') as date_exec, ".
" montant,num_compte,poste_comptable,bq_account,jrn,detail,jr_rapt,it_pj ".
" from import_tmp where ".
" status= 'w' AND date_exec BETWEEN ".$start." and ".$end;
try
{
$p_cn->start();
$ResAll=$p_cn->exec_sql($sql);
$Max=Database::num_row($ResAll);
echo $Max." opérations à transférer.
";
for ($i = 0;$i < $Max;$i++)
{
$val=Database::fetch_array($ResAll,$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'];
$oJrn=new Acc_Ledger($p_cn,$jrn);
$detail=$val['detail'];
$jr_rapt=$val['jr_rapt'];
// Retrieve the account thx the quick code
$f=new Fiche($p_cn);
$quick_code=$poste_comptable;
$f->get_by_qcode($poste_comptable,false);
$poste_comptable=$f->strAttribut(ATTR_DEF_ACCOUNT);
$f->get_by_qcode($bq_account);
$bq_poste=$f->strAttribut(ATTR_DEF_ACCOUNT);
// Vérification que le poste comptable trouvé existe
if ( $poste_comptable == NOTFOUND || strlen(trim($poste_comptable))==0)
$test=0;
else
{
$sqltest = "select * from tmp_pcmn WHERE pcm_val=$1";
$Restest=$p_cn->exec_sql($sqltest,array($poste_comptable));
$test=Database::num_row($Restest);
}
// Test it
if($test == 0)
{
$sqlupdate = "update import_tmp set status='n' WHERE code=$1 or num_compte is null";
$Resupdate=$p_cn->exec_sql($sqlupdate,array($code));
echo _("Poste comptable erronné pour l'opération ").$num_compte."-".$code.", ".("réinitialisation du poste comptable")."
";
continue;
}
// Finances
$seq=$p_cn->get_next_seq('s_grpt');
$p_user = $_SESSION['g_user'];
$acc_op=new Acc_Operation($p_cn);
$acc_op->amount=$montant;
$acc_op->desc=$detail;
$acc_op->type="d";
$acc_op->date=$date_exec;
$acc_op->user=$p_user;
$acc_op->poste=$bq_poste;
$acc_op->grpt=$seq;
$acc_op->jrn=$jrn;
$acc_op->periode=$periode;
$acc_op->qcode=$bq_account;
$acc_op->mt=$_REQUEST['mt'];
$r=$acc_op->insert_jrnx();
$acc_op->type="c";
$acc_op->poste=$poste_comptable;
$acc_op->amount=$montant;
$acc_op->qcode=$quick_code;
$r=$acc_op->insert_jrnx();
//remove annoying double-quote
$num_compte=str_replace('"','',$num_compte);
$code=str_replace('\"','',$code);
$acc_op->comment=$detail.$num_compte." ".$code;
$jr_id=$acc_op->insert_jrn();
$sql="update jrn set jr_pj_number=$1 where jr_id=$2";
$p_cn->exec_sql($sql,array($val['it_pj'],$jr_id));
$internal=$oJrn->compute_internal_code($seq);
$Res=$p_cn->exec_sql("update jrn set jr_internal=$1 where jr_id = $2",array($internal,$jr_id));
// insert rapt
$acc_reconc=new Acc_Reconciliation($p_cn);
$acc_reconc->set_jr_id=$jr_id;
$acc_reconc->insert($jr_rapt);
echo _("Tranfert de l'opération ").$code._(" effectué")."
";
$sql2 = "update import_tmp set status='t' where code='".$code."'";
$Res2=$p_cn->exec_sql($sql2);
}
}
catch (Exception $e)
{
$p_cn->rollback();
echo ''.
'Erreur dans '.__FILE__.':'.__LINE__.
' Message = '.$e->getMessage().
'';
}
$p_cn->commit();
}
/*!
* \brief ShowForm for getting data about
* the bank transfert in cvs
*
* \param $p_cn database connection
*/
function ShowFormTransfert($p_cn)
{
$w=new ISelect();
echo '';
}
?>