Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

import_inc.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00021 // $Revision$
00022 include_once("jrn.php");
00023 include_once("preference.php");
00024 include_once("user_common.php");
00037 function ImportCSV($p_cn,$file,$p_bq_account,$p_format_csv,$p_jrn)
00038 {
00039         if(!$handle = fopen($file, "r")) {
00040                 print 'could not open file. quitting';
00041                 die;
00042         }
00043 
00044 StartSql($p_cn);
00045 
00046         
00047 // include the right format for CSV --> given by the <form
00048                 include($p_format_csv);
00049 
00050         
00051         echo "Importation terminée.";
00052 
00053 // if importation succeeds then we can commit the change
00054 Commit($p_cn);
00055 
00056 }
00060 function UpdateCSV($p_cn, $code, $poste){
00061         $sql = "update import_tmp set poste_comptable='".$poste."' where code='".$code."'";
00062         $Res=ExecSql($p_cn,$sql);
00063 }
00067 function VerifImport($p_cn){
00068         $sql = "select * from import_tmp where poste_comptable='' or poste_comptable is null";
00069         $Res=ExecSql($p_cn,$sql);
00070         $Num=pg_NumRows($Res);
00071         echo $Num." opérations à complèter.<br/><br/>";
00072         $i=1;
00073         while($val = pg_fetch_array($Res)){
00074                 echo '<form METHOD="POST" action="import.php?action=verif">';
00075                 echo '<input type="hidden" name="code" value="'.$val['code'].'">';
00076                 echo '<table border="1" width="500">';
00077                 echo '<tr><td width="200">'.$val['code'].'</td><td width="200">'.$val['date_exec'].'</td><td width="100">'.$val['montant'].' EUR</td><tr/>';
00078                 echo '<tr><td height="50" colspan="3">'.$val['detail'].'</td><tr/>';
00079                 echo '<tr><td>Poste Comptable : <input type="text" size="10" name="poste"></td>';
00080                 echo "<td>n° compte : ".$val['num_compte']."</td>";
00081                 echo '<td><input type="submit" value="modifier"></td><tr/>';
00082                 echo '</table>';
00083                 echo '</FORM>';
00084                 $i++;
00085         }
00086 }
00090 function TransferCSV($p_cn, $periode){
00091         //on obtient la période courante
00092         //$p_user = $_SESSION['g_user'];
00093         //$periode = GetUserPeriode($p_cn,$p_user);
00094         //$periode = $p_user->GetPeriode();
00095         // on trouve les dates frontières de cette période
00096         $sql = "select p_start,p_end from parm_periode where p_id = '".$periode."'";
00097         $Res=ExecSql($p_cn,$sql);
00098         $val = pg_fetch_array($Res);
00099         $start = $val['p_start'];   $end = $val['p_end'];
00100         
00101         $sql = "select * from import_tmp where poste_comptable is not null and  poste_comptable <> '' 
00102             AND ok <> TRUE AND date_exec BETWEEN '".$start."' and '".$end."'";
00103         $Res=ExecSql($p_cn,$sql);
00104         //echo "boucle: ".sizeof($Res)."<br/>";
00105         //while($val = pg_fetch_array($Res)){
00106         $Max=pg_NumRows($Res);
00107         echo $Max." opérations à transférer.<br/>";
00108         for ($i = 0;$i < $Max;$i++) {
00109                 $val=pg_fetch_array($Res,$i);
00110                 
00111                 $code=$val['code']; $date_exec=$val['date_exec']; $montant=$val['montant']; $num_compte=$val['num_compte']; 
00112                 $poste_comptable=$val['poste_comptable'];$bq_account=$val['bq_account'];
00113                 $jrn=$val['jrn'];
00114 
00115                 list($annee, $mois, $jour) = explode("-", $date_exec);
00116                 $date_exec = $jour.".".$mois.".".$annee;
00117 
00118                 // Vérification que le poste comptable trouvé existe
00119                 $sqltest = "select * from tmp_pcmn WHERE pcm_val='".$poste_comptable."'";
00120                 $Restest=ExecSql($p_cn,$sqltest);
00121                 $test=pg_NumRows($Restest);
00122                 if($test == 0) {
00123                         $sqlupdate = "update import_tmp set poste_comptable='' WHERE code='".$code."' AND num_compte='".$num_compte."'";
00124                         $Resupdate=ExecSql($p_cn,$sqlupdate);
00125                         echo "Poste comptable erronné pour l'opération ".$num_compte."-".$code.", réinitialisation du poste comptable<br/>";
00126                 } else {
00127 
00128                 // Finances
00129         
00130                 //$seq = GetNextId($p_cn,'j_grpt')+1;
00131                 $seq=NextSequence($p_cn,'s_grpt');
00132                 $p_user = $_SESSION['g_user'];
00133                 //$periode = GetUserPeriode($p_cn,$p_user);
00134                 //$periode = $User->GetPeriode();
00135                 StartSql($p_cn);
00136 
00137                 $r=InsertJrnx($p_cn,"d",$p_user,$jrn,$bq_account,$date_exec,$montant,$seq,$periode);
00138                 if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __LINE__");}
00139         
00140                 $r=InsertJrnx($p_cn,"c",$p_user,$jrn,$poste_comptable,$date_exec,$montant,$seq,$periode);
00141                 if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __LINE__");}
00142 
00143                 //remove annoying double-quote
00144                 $num_compte=str_replace('"','',$num_compte);
00145                 $code=str_replace('\"','',$code);
00146         
00147                 $r=InsertJrn($p_cn,$date_exec,NULL,$jrn,$num_compte." ".$code,$montant,$seq,$periode);
00148                 if ( $r == false ) { Rollback($p_cn); exit(" Error 'import_inc.php' __LINE__");}
00149                   
00150                 //$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."')";
00151                 SetInternalCode($p_cn,$seq,$jrn);
00152 
00153 
00154                 echo "Tranfer de l'opération ".$code." effectué<br/>";
00155                 $sql2 = "update import_tmp set ok=TRUE where code='".$code."'";
00156                 $Res2=ExecSql($p_cn,$sql2);
00157 
00158                 Commit($p_cn);
00159                 }
00160         }
00161 }
00174 function ShowFormTransfert($p_cn){
00175 $w=new widget("select");
00176   echo '<FORM METHOD="POST" action="import.php?action=import" enctype="multipart/form-data">';
00177   echo '<INPUT TYPE="file" name="fupload" size="20"><br>';
00178   // ask for the journal target 
00179   $jrn=make_array ($p_cn,"select jrn_def_id,jrn_def_name from jrn_def where jrn_def_type='FIN';");
00180   $w->label='Journal';
00181   echo $w->label." :".$w->IOValue('import_jrn',$jrn)."<br>";
00182   // choose the bank account
00183   $bq=make_array($p_cn,"select pcm_val,pcm_lib from tmp_pcmn where pcm_val like '550%'");
00184   $w->label='Banque';
00185   echo "Compte en banque :".$w->IOValue('import_bq',$bq)."<br>";
00186   $format_csv=make_array($p_cn,"select include_file,name from format_csv_banque;");
00187   $w->label="Format import";
00188   echo $w->label.$w->IOValue('format_csv',$format_csv).'<br>';
00189   echo '<INPUT TYPE="SUBMIT" Value="Import fiche">';
00190   echo '</FORM>';
00191 }
00192 ?>

Generated on Sat Jun 24 20:41:33 2006 for phpcompta by  doxygen 1.4.4