given by the
name='poste'.$counter; $w->extra='filter'; $w->extra2='QuickCode'; $w->label=''; $w->table=0; if ( $p_form == 'remove' ) $w->readonly=true; $oJrn=new Acc_Ledger($p_cn,$p_val['jrn']); // widget concerned $wConcerned=new widget('js_concerned'); $wConcerned->name="e_concerned"+$counter; $wConcerned->extra=abs($p_val['montant']); $wConcerned->extra2='paid'; $wConcerned->label='op. concernée'; $wConcerned->table=0; $s=new widget('span'); // if in readonly retrieve the conc. ope if ( $p_form== 'remove') { $wConcerned->readonly=true; $wConcerned->value=$p_val['jr_rapt']; } if ( isset($p_val['poste_comptable'])) { $w->value=$p_val['poste_comptable']; $cn=DbConnect(dossier::id()); $f=new fiche($p_cn); $f->get_by_qcode($p_val['poste_comptable']); $s->value=$f->strAttribut(ATTR_DEF_NAME); } echo ''; echo ''; echo widget::hidden('p_jrn',$p_val['jrn']); echo ''; echo ''; echo ""; echo ''; echo ''; echo '"; echo ""; if ( $p_form == 'form') { $str_update=sprintf("import_update('%s','%s','%s');", $_REQUEST['PHPSESSID'], dossier::id(), $counter); $str_remove=sprintf("import_remove('%s','%s','%s');", $_REQUEST['PHPSESSID'], dossier::id(), $counter); echo ''; } if ($p_form == 'remove' ) { $str_notconfi=sprintf("import_not_confirmed('%s','%s','%s');", $_REQUEST['PHPSESSID'], dossier::id(), $counter); echo ''; } echo '
'.$p_val['code'].''.$p_val['date_exec'].''.$p_val['montant'].' EUR
Journal : ".$oJrn->get_name()."poste comptable Destination : ".$p_val['bq_account']."
'.$p_val['detail'].'
'.$wConcerned->IOValue("e_concerned".$counter).'
'.$w->IOValue().' '.$s->IOValue('poste'.$counter.'_label'). "n° compte : ".$p_val['num_compte']."'; echo ''. '
'; } /*!\brief Verify the import */ function VerifImport($p_cn){ $sql = "select * from import_tmp where status='n' ". " order by date_exec,code"; $Res=ExecSql($p_cn,$sql); $Num=pg_NumRows($Res); echo $Num." opérations à complèter.

"; $i=1; // include javascript for popup echo JS_SEARCH_CARD; echo JS_CONCERNED_OP; echo JS_AJAX_FICHE; echo JS_PROTOTYPE; while($val = pg_fetch_array($Res)){ echo ''; echo dossier::hidden(); ShowBox($val,$i,$p_cn,'form'); echo '
'; $i++; } } /*!\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=ExecSql($p_cn,$sql); $val = pg_fetch_array($Res); if ( $val == false ) { echo ""; 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=ExecSql($p_cn,$sql); $Num=pg_NumRows($Res); echo $Num." opérations à transfèrer.

"; if ( $Num == 0 ) return; $i=1; while($val = pg_fetch_array($Res)){ echo '
'; echo dossier::hidden(); echo ''; ShowBox($val,$i,$p_cn,'remove'); echo '
'; $i++; } echo '
'; echo dossier::hidden(); echo ''; 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=ExecSql($p_cn,$sql); $val = pg_fetch_array($Res); if ( $val == false ) { echo ""; 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; try { StartSql($p_cn); $ResAll=ExecSql($p_cn,$sql); $Max=pg_NumRows($ResAll); echo $Max." opérations à transférer.
"; for ($i = 0;$i < $Max;$i++) { $val=pg_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 == '- ERROR -') $test=0; else { $sqltest = "select * from tmp_pcmn WHERE pcm_val='".$poste_comptable."'"; $Restest=ExecSql($p_cn,$sqltest); $test=pg_NumRows($Restest); } // Test it if($test == 0) { $sqlupdate = "update import_tmp set status='n' WHERE code='".$code."' AND num_compte='".$num_compte."' or num_compte is null"; $Resupdate=ExecSql($p_cn,$sqlupdate); echo "Poste comptable erronné pour l'opération ".$num_compte."-".$code.", réinitialisation du poste comptable
"; continue; } // Finances $seq=NextSequence($p_cn,'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; $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(); $internal=$oJrn->compute_internal_code($seq); $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal."' where ". " jr_id = ".$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=ExecSql($p_cn,$sql2); } } catch (Exception $e) { Rollback($p_cn); echo ''. 'Erreur dans '.__FILE__.':'.__LINE__. ' Message = '.$e->getMessage(). ''; } Commit($p_cn); } /*! ************************************************** * \brief ShowForm for getting data about * the bank transfert in cvs * * \param $p_cn database connection * * \return none */ function ShowFormTransfert($p_cn){ $w=new widget("select"); echo '
'; echo dossier::hidden(); echo '
'; // ask for the journal target $jrn=make_array ($p_cn,"select jrn_def_id,jrn_def_name from jrn_def where jrn_def_type='FIN';"); $w->label='Journal'; echo $w->label." :".$w->IOValue('import_jrn',$jrn)."
"; // choose the bank account $banque=new Acc_Parm_Code($p_cn,'BANQUE'); $bq=make_array($p_cn,"select j_qcode,vw_name from vw_poste_qcode join vw_fiche_attr on (j_qcode=quick_code) where j_poste::text like '".$banque->p_value."%'"); $w->label='Banque'; echo "Compte en banque :".$w->IOValue('import_bq',$bq)."
"; $format_csv=make_array($p_cn,"select include_file,name from format_csv_banque;"); $w->label="Format import"; echo $w->label.$w->IOValue('format_csv',$format_csv).'
'; echo ''; echo '
'; } /*!\brief RemoveRow put a flag delete on a row of the table import_tmp * (import_tmp.status) * \param $p_cn database connection * \param $p_code import_tmp.code must be unique */ function DropRecord($p_cn,$p_code) { ExecSql($p_cn,"update import_tmp set status='d' where code='".$p_code."'"); } ?>