00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 include_once("jrn.php");
00024 include_once("preference.php");
00025 include_once("user_common.php");
00026 require_once('class_user.php');
00027 require_once('class_widget.php');
00028 require_once('class_fiche.php');
00043 function ImportCSV($p_cn,$file,$p_bq_account,$p_format_csv,$p_jrn)
00044 {
00045 if(!$handle = fopen($file, "r")) {
00046 print 'could not open file. quitting';
00047 die;
00048 }
00049
00050 StartSql($p_cn);
00051
00052
00053
00054 include($p_format_csv);
00055
00056
00057 echo "Importation terminée.";
00058
00059
00060 Commit($p_cn);
00061
00062 }
00066 function UpdateCSV($p_cn){
00067 $code=$_POST['code'];
00068 $count=$_POST['count'];
00069 $poste=$_POST['poste'.$count];
00070 $sql = "update import_tmp set poste_comptable='".$poste."' ,status='w' where code='".$code."'";
00071 $Res=ExecSql($p_cn,$sql);
00072 }
00073
00074
00075
00076
00085 function ShowBox($p_val,$counter,$p_cn,$p_form='form'){
00086
00087 $w=new widget('js_search_only');
00088 $w->name='poste'.$counter;
00089 $w->extra='cred';
00090 $w->extra2=$p_val['jrn'];
00091 $w->label='';
00092 $w->table=0;
00093 if ( $p_form == 'remove' )
00094 $w->readonly=true;
00095
00096 $s=new widget('span');
00097
00098 if ( isset($p_val['poste_comptable']))
00099 {
00100 $w->value=$p_val['poste_comptable'];
00101 $cn=DbConnect($_SESSION['g_dossier']);
00102 $f=new fiche($p_cn);
00103 $f->GetByQCode($p_val['poste_comptable']);
00104 $s->value=$f->strAttribut(ATTR_DEF_NAME);
00105 }
00106 echo '<input type="hidden" name="code" value="'.$p_val['code'].'">';
00107 echo '<input type="hidden" name="count" value="'.$counter.'">';
00108 echo '<table border="1" width="500">';
00109 echo '<tr><td width="200">'.$p_val['code'].'</td><td width="200">'.$p_val['date_exec'].'</td><td width="100">'.$p_val['montant'].' EUR</td><tr/>';
00110 echo "<tr><td> Journal : ".GetJrnName($p_cn,$p_val['jrn'])."</TD><TD>poste comptable Destination : ".$p_val['bq_account']."</td><tr>";
00111 echo '<tr><td height="50" colspan="3">'.$p_val['detail'].'</td><tr/>';
00112 echo '<tr><td>'.$w->IOValue().' '.$s->IOValue('poste'.$counter.'_label').'</td>';
00113 echo "<td>n° compte : ".$p_val['num_compte']."</td>";
00114 if ( $p_form == 'form') {
00115 echo '<td><input type="submit" value="Modifier">';
00116 echo '<input type="submit" name="trashit" value="Effacer.."></td><tr/>';
00117 }
00118 if ($p_form == 'remove' )
00119 echo '<td><input type="submit" value="Enlever"></td><tr/>';
00120
00121 echo '</table>';
00122
00123 }
00128 function RemoveCSV($cn)
00129 {
00130 $sql="update import_tmp set poste_comptable=null,status='n' where code='".$_POST['code']."'";
00131 ExecSql($cn,$sql);
00132 }
00133
00137 function VerifImport($p_cn){
00138 $sql = "select * from import_tmp where status='n' ".
00139 " order by date_exec,code";
00140 $Res=ExecSql($p_cn,$sql);
00141 $Num=pg_NumRows($Res);
00142 echo $Num." opérations à complèter.<br/><br/>";
00143 $i=1;
00144
00145 echo JS_SEARCH_CARD;
00146 while($val = pg_fetch_array($Res)){
00147 echo '<form METHOD="POST" action="import.php?action=verif">';
00148 ShowBox($val,$i,$p_cn,'form');
00149 echo '</form>';
00150 $i++;
00151 }
00152
00153 }
00159 function ConfirmTransfert($p_cn,$periode){
00160 $sql = "select to_char(p_start,'DD-MM-YYYY') as p_start,to_char(p_end,'DD-MM-YYYY') as p_end".
00161 " from parm_periode where p_id = '".$periode."'";
00162 $Res=ExecSql($p_cn,$sql);
00163 $val = pg_fetch_array($Res);
00164 if ( $val == false )
00165 {
00166 echo "<script>".
00167 "alert ('Vous devez selectionner votre période dans vos préférences');".
00168 "</script>";
00169 exit();
00170 }
00171 $start ="to_date('".$val['p_start']."','DD-MM-YYYY')";
00172 $end = "to_date('".$val['p_end']."','DD-MM-YYYY')";
00173
00174 $sql = "select code,to_char(date_exec,'DD.MM.YYYY') as date_exec, ".
00175 " montant,num_compte,poste_comptable,bq_account,jrn,detail ".
00176 " from import_tmp where
00177 status = 'w' AND date_exec BETWEEN ".$start." and ".$end;
00178
00179
00180
00181 $Res=ExecSql($p_cn,$sql);
00182 $Num=pg_NumRows($Res);
00183 echo $Num." opérations à transfèrer.<br/><br/>";
00184 if ( $Num == 0 ) return;
00185 $i=1;
00186 while($val = pg_fetch_array($Res)){
00187
00188 echo '<form method="post" action="import.php">';
00189 echo '<input type="hidden" name="action" value="remove">';
00190 ShowBox($val,$i,$p_cn,'remove');
00191 echo '</form>';
00192 $i++;
00193 }
00194 echo '<form method="post" action="import.php">';
00195 echo '<input type="hidden" name="action" value="transfer">';
00196 echo '<input type="submit" name="sub" value="Commencer le transfert">';
00197 echo '</form>';
00198
00199 }
00200
00209 function TransferCSV($p_cn, $periode){
00210
00211 $User=new cl_user($p_cn);
00212 $periode = $User->GetPeriode();
00213
00214 $sql = "select to_char(p_start,'DD-MM-YYYY') as p_start,to_char(p_end,'DD-MM-YYYY') as p_end".
00215 " from parm_periode where p_id = '".$periode."'";
00216 $Res=ExecSql($p_cn,$sql);
00217 $val = pg_fetch_array($Res);
00218 if ( $val == false )
00219 {
00220 echo "<script>".
00221 "alert ('Vous devez selectionner votre période dans vos préférences');".
00222 "</script>";
00223 exit();
00224 }
00225 $start ="to_date('".$val['p_start']."','DD-MM-YYYY')";
00226 $end = "to_date('".$val['p_end']."','DD-MM-YYYY')";
00227
00228 $sql = "select code,to_char(date_exec,'DD.MM.YYYY') as date_exec, ".
00229 " montant,num_compte,poste_comptable,bq_account,jrn,detail ".
00230 " from import_tmp where ".
00231 " status= 'w' AND date_exec BETWEEN ".$start." and ".$end;
00232 $Res=ExecSql($p_cn,$sql);
00233
00234
00235 $Max=pg_NumRows($Res);
00236 echo $Max." opérations à transférer.<br/>";
00237 StartSql($p_cn);
00238
00239 for ($i = 0;$i < $Max;$i++) {
00240 $val=pg_fetch_array($Res,$i);
00241
00242 $code=$val['code']; $date_exec=$val['date_exec']; $montant=$val['montant']; $num_compte=$val['num_compte'];
00243 $poste_comptable=$val['poste_comptable'];$bq_account=$val['bq_account'];
00244 $jrn=$val['jrn']; $detail=$val['detail'];
00245
00246
00247 $f=new fiche($p_cn);
00248 $f->GetByQCode($poste_comptable,false);
00249 $poste_comptable=$f->strAttribut(ATTR_DEF_ACCOUNT);
00250
00251
00252 if ( $poste_comptable == '- ERROR -')
00253 $test=0;
00254 else
00255 {
00256 $sqltest = "select * from tmp_pcmn WHERE pcm_val='".$poste_comptable."'";
00257
00258 $Restest=ExecSql($p_cn,$sqltest);
00259 $test=pg_NumRows($Restest);
00260 }
00261
00262
00263 if($test == 0) {
00264 $sqlupdate = "update import_tmp set status='n' WHERE code='".$code."' AND num_compte='".$num_compte."' or num_compte is null";
00265 $Resupdate=ExecSql($p_cn,$sqlupdate);
00266 echo "Poste comptable erronné pour l'opération ".$num_compte."-".$code.", réinitialisation du poste comptable<br/>";
00267 continue;
00268 }
00269
00270
00271
00272
00273 $seq=NextSequence($p_cn,'s_grpt');
00274 $p_user = $_SESSION['g_user'];
00275
00276 $r=InsertJrnx($p_cn,"d",$p_user,$jrn,$bq_account,$date_exec,$montant,$seq,$periode);
00277 if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __LINE__");}
00278
00279 $r=InsertJrnx($p_cn,"c",$p_user,$jrn,$poste_comptable,$date_exec,$montant,$seq,$periode);
00280 if ( $r == false) { $Rollback($p_cn);exit("error 'import_inc.php' __LINE__");}
00281
00282
00283 $num_compte=str_replace('"','',$num_compte);
00284 $code=str_replace('\"','',$code);
00285 if ( strlen(trim($num_compte)) == 0 )
00286 $num_compte=$val['detail'];
00287
00288 $r=InsertJrn($p_cn,$date_exec,NULL,$jrn,$detail.$num_compte." ".$code,$montant,$seq,$periode);
00289 if ( $r == false ) { Rollback($p_cn); exit(" Error 'import_inc.php' __LINE__");}
00290
00291 SetInternalCode($p_cn,$seq,$jrn);
00292
00293
00294 echo "Tranfer de l'opération ".$code." effectué<br/>";
00295 $sql2 = "update import_tmp set status='t' where code='".$code."'";
00296 $Res2=ExecSql($p_cn,$sql2);
00297
00298
00299 }
00300 Commit($p_cn);
00301
00302 }
00313 function ShowFormTransfert($p_cn){
00314 $w=new widget("select");
00315 echo '<FORM METHOD="POST" action="import.php?action=import" enctype="multipart/form-data">';
00316 echo '<INPUT TYPE="file" name="fupload" size="20"><br>';
00317
00318 $jrn=make_array ($p_cn,"select jrn_def_id,jrn_def_name from jrn_def where jrn_def_type='FIN';");
00319 $w->label='Journal';
00320 echo $w->label." :".$w->IOValue('import_jrn',$jrn)."<br>";
00321
00322 $bq=make_array($p_cn,"select pcm_val,pcm_lib from tmp_pcmn where pcm_val like '550%'");
00323 $w->label='Banque';
00324 echo "Compte en banque :".$w->IOValue('import_bq',$bq)."<br>";
00325 $format_csv=make_array($p_cn,"select include_file,name from format_csv_banque;");
00326 $w->label="Format import";
00327 echo $w->label.$w->IOValue('format_csv',$format_csv).'<br>';
00328 echo '<INPUT TYPE="SUBMIT" Value="Import fiche">';
00329 echo '</FORM>';
00330 }
00331
00337 function DropRecord($p_cn,$p_code)
00338 {
00339 ExecSql($p_cn,"update import_tmp set status='d' where code='".$p_code."'");
00340 }
00341
00342 ?>