00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
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
00048 include($p_format_csv);
00049
00050
00051 echo "Importation terminée.";
00052
00053
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
00092
00093
00094
00095
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
00105
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
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
00129
00130
00131 $seq=NextSequence($p_cn,'s_grpt');
00132 $p_user = $_SESSION['g_user'];
00133
00134
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
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
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
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
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 ?>