'; $image_desc=''; $image_sel_desc=''; $image_sel_asc=''; $sort_date=" $image_ascDate $image_desc"; $sort_description=" $image_ascDescription $image_desc"; $sort_amount=" $image_ascMontant $image_desc"; $sort_echeance=" $image_ascEchéance $image_desc "; $own=new Own($p_cn); // if an order is asked if ( isset ($_GET['o']) ) { switch ($_GET['o']) { case 'da': // date asc $sort_date="$image_sel_asc Date $image_desc"; $order=" order by jr_date_order asc "; break; case 'dd': $sort_date=" $image_asc Date $image_sel_desc"; // date desc $order=" order by jr_date_order desc "; break; case 'ma': // montant asc $sort_amount=" $image_sel_asc Montant $image_desc"; $order=" order by jr_montant asc "; break; case 'md': // montant desc $sort_amount=" $image_ascMontant $image_sel_desc"; $order=" order by jr_montant desc "; break; case 'ca': // jr_comment asc $sort_description=" $image_sel_asc Description $image_desc"; $order=" order by jr_comment asc "; break; case 'cd': // jr_comment desc $sort_description=" $image_ascDescription $image_sel_desc"; $order=" order by jr_comment desc "; break; case 'ea': // jr_comment asc $sort_echeance=" $image_sel_asc Echeance $image_desc"; $order=" order by jr_ech asc "; break; case 'ed': // jr_comment desc $sort_echeance=" $image_asc Echeance $image_sel_desc"; $order=" order by jr_ech desc "; break; } } // set a filter for the FIN $a_parm_code=get_array($p_cn,"select p_value from parm_code where p_code in ('BANQUE','COMPTE_COURANT','CAISSE')"); $sql_fin="("; $or=""; foreach ($a_parm_code as $code) { $sql_fin.="$or j_poste::text like '".$code['p_value']."%'"; $or=" or "; } $sql_fin.=")"; if ( $p_array == null ) { $sql="select jr_id , jr_montant, jr_comment, to_char(jr_ech,'DD.MM.YYYY') as jr_ech, to_char(jr_date,'DD.MM.YYYY') as jr_date, jr_date as jr_date_order, jr_grpt_id, jr_rapt, jr_internal, jrn_def_id, jrn_def_name, jrn_def_ech, jrn_def_type, jr_valid, jr_tech_per, jr_pj_name, p_closed from jrn join jrn_def on jrn_def_id=jr_def_id join parm_periode on p_id=jr_tech_per $p_where $order"; } if ( $p_array != null ) { // Construction Query foreach ( $p_array as $key=>$element) { ${"l_$key"}=$element; } $sql="select jr_id , jr_montant, jr_comment, jr_ech, to_char(jr_date,'DD.MM.YYYY') as jr_date, jr_date as jr_date_order, jr_grpt_id, jr_rapt, jr_internal, jrn_def_id, jrn_def_name, jrn_def_ech, jrn_def_type, jr_valid, jr_tech_per, jr_pj_name, p_closed from jrn join jrn_def on jrn_def_id=jr_def_id join parm_periode on p_id=jr_tech_per "; $jrn_sql=($p_jrn =0)?"1=1":"jrn_def_id=$p_jrn "; $l_and=" where "; // amount // remove space $l_s_montant=trim($l_s_montant); // replace comma by dot $l_s_montant=str_replace(',','.',$l_s_montant); $l_st_montant=trim($l_st_montant); // replace comma by dot $l_st_montant=str_replace(',','.',$l_st_montant); $done_comp=0; echo_debug('user_common',__LINE__,"l_s_montant $l_s_montant"); /* -------------------------------------------------------------------------- */ /* if both amount are the same then we need to search into the detail */ /* -------------------------------------------------------------------------- */ if ( ( ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant)) && ( ereg("^[0-9]+$", $l_st_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_st_montant) ) ) { if ( bccomp($l_s_montant,$l_st_montant,2) == 0 ) { $sql .= $l_and. 'jr_grpt_id in ( select distinct j_grpt from jrnx where j_montant = '.$l_s_montant.')'; $l_and=" and "; $done_comp=1; } } /*------------------------------------------------------------------------------* * If amount are different the range is about the total of the operation *------------------------------------------------------------------------------*/ if ( $done_comp==0 && (ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant) )) { $sql.=$l_and." jr_montant >= $l_s_montant"; $l_and=" and "; } if ( $done_comp==0 && (ereg("^[0-9]+$", $l_st_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_st_montant) )) { $sql.=$l_and." jr_montant <= $l_st_montant"; $l_and=" and "; } // date if ( isDate($l_date_start) != null ) { $sql.=$l_and." jr_date >= to_date('".$l_date_start."','DD.MM.YYYY')"; $l_and=" and "; } if ( isDate($l_date_end) != null ) { $sql.=$l_and." jr_date <= to_date('".$l_date_end."','DD.MM.YYYY')"; $l_and=" and "; } // comment $l_s_comment=FormatString($l_s_comment); if ( $l_s_comment != null ) { $sql.=$l_and." upper(jr_comment) like upper('%".$l_s_comment."%') "; $l_and=" and "; } // internal $l_s_internal=FormatString($l_s_internal); if ( $l_s_internal != null ) { $sql.=$l_and." jr_internal like upper('%$l_s_internal%') "; $l_and=" and "; } // Poste $l_poste=FormatString($l_poste); if ( $l_poste != null ) { $sql.=$l_and." jr_grpt_id in (select j_grpt from jrnx where j_poste::text like '$l_poste' ) "; $l_and=" and "; } // Quick Code if ( $l_qcode != null ) { $l_qcode=FormatString($l_qcode); $sql.=$l_and." jr_grpt_id in ( select j_grpt from jrnx where trim(j_qcode) = upper(trim('$l_qcode')))"; $l_and=" and "; } // if not admin check filter $User=new User(DbConnect()); $User->Check(); if ( $User->admin == 0 ) { $sql.=$l_and." jr_def_id in ( select uj_jrn_id ". " from user_sec_jrn where ". " uj_login='".$_SESSION['g_user']."'". " and uj_priv in ('R','W'))"; } $sql.=$order; }// p_array != null // Count $count=CountSql($p_cn,$sql); // Add the limit $sql.=$limit.$offset; // Execute SQL stmt $Res=ExecSql($p_cn,$sql); //starting from here we can refactor, so that instead of returning the generated HTML, //this function returns a tree structure. $r=""; $r.=JS_VIEW_JRN_CANCEL; $r.=JS_VIEW_JRN_MODIFY; $Max=pg_NumRows($Res); //TODO: correct this message. if ($Max==0) return array(0,"Aucun enregistrement trouvé"); $r.=''; $l_sessid=$_REQUEST['PHPSESSID']; $r.=""; $r.=""; $r.=$sort_date; $r.=$sort_echeance; $r.=$sort_description; $r.=$sort_amount; // if $p_paid is not equal to 0 then we have a paid column if ( $p_paid != 0 ) { $r.=""; } $r.=""; $r.=""; $r.=""; // Total Amount $tot=0.0; $gDossier=dossier::id(); for ($i=0; $i < $Max;$i++) { $row=pg_fetch_array($Res,$i); if ( $i % 2 == 0 ) $tr=''; else $tr=''; $r.=$tr; //internal code // button modify $r.=""; // date $r.=""; // echeance $r.=""; // comment $r.=""; // Amount // If the ledger is financial : // the credit must be negative and written in red $positive=0; // Check ledger type : if ( $row['jrn_def_type'] == 'FIN' ) { $positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ". " where jr_id=".$row['jr_id']." and $sql_fin ". " and j_debit='f'"); } $r.=""; // Show the paid column if p_paid is not null if ( $p_paid !=0 ) { $w=new widget("checkbox"); $w->name="rd_paid".$row['jr_id']; $w->selected=($row['jr_rapt']=='paid')?true:false; // if p_paid == 2 then readonly $w->readonly=( $p_paid == 2)?true:false; $h=new widget("hidden"); $h->name="set_jr_id".$row['jr_id']; $r.=''; if ( $row['jr_rapt']=='paid') $amount_paid+=$row['jr_montant']; else $amount_unpaid+=$row['jr_montant']; } // Rapprochement $a=GetConcerned($p_cn,$row['jr_id']); $r.=""; if ( $row['jr_valid'] == 'f' ) { $r.=""; } else if ( $own->MY_STRICT=='N' ) { // all operations can be removed either by setting to 0 the amount // or by writing the opposite operation if the period is closed $r.=""; } // else //document if ( $row['jr_pj_name'] != "") { $image=''; $r.=""; } else $r.=""; // end row $r.=""; } $amount_paid=round($amount_paid,4); $amount_unpaid=round($amount_unpaid,4); $tot=round($tot,4); $r.=""; $r.=''; $r.='"; $r.=""; if ( $p_paid != 0 ) { $r.=""; $r.=''; $r.='"; $r.=""; $r.=""; $r.=''; $r.='"; $r.=""; } $r.="
Internal PayéOp. ConcernéeDocument
"; // If url contains // $href=basename($_SERVER['PHP_SELF']); echo_debug(__FILE__,__LINE__,"href = $href"); switch ($href) { // user_jrn.php case 'compta.php': $vue="E"; //Expert View break; case 'commercial.php': $vue="S"; //Simple View break; case 'recherche.php': $vue=(isset($_GET['expert']))?'E':'S'; break; default: echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri'); exit (-1); } //DEBUG // $r.=$l_sessid; $r.=sprintf('%s', $row['jr_id'], $l_sessid,$gDossier, $p_jrn,$vue, $row['jr_internal']); $r.=""; $r.=$row['jr_date']; $r.=""; $r.=$row['jr_ech']; $r.=""; $r.=h($row['jr_comment']); $r.=""; $tot=($positive != 0)?$tot-$row['jr_montant']:$tot+$row['jr_montant']; //STAN $positive always == 0 $r.=( $positive != 0 )?" - ".sprintf("%8.2f",$row['jr_montant'])."":sprintf("%8.2f",$row['jr_montant']); $r.="'.$w->IOValue().$h->IOValue().'"; if ( $a != null ) { foreach ($a as $key => $element) { $operation=new Acc_Operation($p_cn); $operation->jr_id=$element; $l_amount=getDbValue($p_cn,"select jr_montant from jrn ". " where jr_id=$element"); $r.= " ".$operation->get_internal()." [ $l_amount € ]"; }//for }// if ( $a != null ) { $r.=" Opération annulée"; // cancel operation $r.=sprintf('', "Annuler",$row['jr_grpt_id'],$l_sessid,$gDossier,$p_jrn); $r.="".sprintf('%s', $p_jrn, $row['jr_grpt_id'], $str_dossier, $_REQUEST['PHPSESSID'], $image) ."
Total'.$tot."
Payé'.$amount_paid."
Non payé'.$amount_unpaid."
"; return array ($count,$r); } /*! InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c'); ************************************************** *\brief Insert data into stock_goods, * * \param $p_cn database connection * * \param $p_j_id the j_id * \param $p_good the goods * \param $p_quant quantity * \param $p_type c for credit or d for debit * * \return none * \note Link to jrn gives the date */ function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type) { echo_debug('user_common.php',__LINE__,"function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)"); // Retrieve the good account for stock $code=new fiche($p_cn); $code->get_by_qcode($p_good); $code_marchandise=$code->strAttribut(ATTR_DEF_STOCK); $p_good=FormatString($p_good); $sql="select f_id from vw_poste_qcode where j_qcode=upper('$p_good')"; $Res=ExecSql($p_cn,$sql); $r=pg_fetch_array($Res,0); $f_id=$r['f_id']; $user=new User($p_cn); $exercice=$user->get_exercice(); if ( $exercice == 0 ) throw Exception ('Annee invalide erreur'); $Res=ExecSql($p_cn,"insert into stock_goods ( j_id, f_id, sg_code, sg_quantity, sg_type,sg_exercice ) values ( $p_j_id, $f_id, '$code_marchandise', $p_quant, '$p_type',$exercice) "); return $Res; } /*! ************************************************** *\brief Insert into jrn_rapt the concerned operations * * * \param $p_cn database connection * \param $jr_id (jrn.jr_id) => jrn_rapt.jr_id * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned * * \return none * */ function InsertRapt($p_cn,$jr_id,$jr_id2) { if ( isNumber($jr_id) == 0 || isNumber($jr_id2) == 0 ) { echo_error(" InsertRapt : invalid jr_id $jr_id, jr_id2 $jr_id2"); echo_debug('user_common.php',__LINE__," InsertRapt : invalid jr_id $jr_id, jr_id2 $jr_id2"); return false; } // verify if exists if ( CountSql($p_cn,"select jra_id from jrn_rapt where jra_concerned=$jr_id and jr_id=$jr_id2 union select jra_id from jrn_rapt where jra_concerned=$jr_id2 and jr_id=$jr_id ") ==0) { // Ok we can insert $Res=ExecSql($p_cn,"insert into jrn_rapt(jr_id,jra_concerned) values ($jr_id,$jr_id2)"); } return true; } /*! DeleteRapt($p_cn,$jr_id,$jr_id2) ************************************************** *\brief Insert into jrn_rapt the concerned operations * * parm : * \param $p_cn database connection * \param $jr_id (jrn.jr_id) => jrn_rapt.jr_id * \param $jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned * * \return none */ function DeleteRapt($p_cn,$jr_id,$jr_id2) { echo_debug('user_common.php',__LINE__,"DeleteRapt($p_cn,$jr_id,$jr_id2) "); if ( isNumber($jr_id) == 0 or isNumber($jr_id2) == 0 ) { echo_error(" InsertRapt : invalid jr_id jr_id = $jr_id jr_id2 = $jr_id2"); return; } // verify if exists if ( CountSql($p_cn,"select jra_id from jrn_rapt where jra_concerned=$jr_id and jr_id=$jr_id2 union select jra_id from jrn_rapt where jra_concerned=$jr_id2 and jr_id=$jr_id ") !=0) { // Ok we can insert $Res=ExecSql($p_cn,"delete from jrn_rapt where (jra_concerned=$jr_id2 and jr_id=$jr_id) or (jra_concerned=$jr_id and jr_id=$jr_id2) "); } } /*! GetConcerned (p_cn ,jr_id) ************************************************** *\brief Return an array of the concerned operation * * *\param database connection *\param jrn.jr_id * \return array if something is found or null */ function GetConcerned ($p_cn, $jr_id) { echo_debug(__FILE__.":".__LINE__."Get Concerned"); $sql=" select jr_id as cn from jrn_rapt where jra_concerned=$jr_id union select jra_concerned as cn from jrn_rapt where jr_id=$jr_id"; $Res=ExecSql($p_cn,$sql); // If nothing is found return null $n=pg_NumRows($Res); if ($n ==0 ) return null; // put everything in an array for ($i=0;$i<$n;$i++) { $l=pg_fetch_array($Res,$i); $r[$i]=$l['cn']; } return $r; } /*! UpdateComment ($p_cn,$p_jr_id,$p_comment) ************************************************** *\brief Update comment in jrn * * parm : * - database conn. * - jrn.jr_id * - comment * gen : * - none * return: * - none */ function UpdateComment ($p_cn,$p_jr_id,$p_comment) { $p_comment=FormatString($p_comment); $Res=ExecSql($p_cn,"update jrn set jr_comment='".$p_comment."' where jr_id = $p_jr_id"); } /*! isValid ($p_cn, $p_grpt_id ************************************************** *\brief test if a jrn op is valid * * \param $p_cn db * \param $p_grpt_id * \return: * - 1 is valid * - 0 is not valid */ function isValid ($p_cn,$p_grpt_id) { $Res=ExecSql($p_cn,"select jr_valid from jrn where jr_grpt_id=$p_grpt_id"); if ( ( $M = pg_NumRows($Res)) == 0 ) return 0; $a=pg_fetch_array($Res,0); if ( $a['jr_valid'] == 't') return 1; if ( $a['jr_valid'] == 'f') return 0; echo_error ("Invalid result = ".$a['result']); } /*! ************************************************** *\brief * Create a navigation_bar (pagesize) * * \param $p_offset first record number * \param $p_line total of returned row * \param $p_size current g_pagesize user's preference * \param $p_page number of the page where the user is * \param $p_javascript javascript code to add * \note example : \verbatim $step=$_SESSION['g_pagesize']; $page=(isset($_GET['offset']))?$_GET['page']:1; $offset=(isset($_GET['offset']))?$_GET['offset']:0; list ($max_ligne,$list)=ListJrn($cn,$_GET['p_jrn'],$sql,null,$offset,1); $bar=jrn_navigation_bar($offset,$max_ligne,$step,$page); \endverbatim * \return string with the nav. bar */ function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1,$p_javascript="") { echo_debug('user_common',__LINE__,"function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1)"); // if the pagesize is unlimited return "" // in that case there is no nav. bar if ( $_SESSION['g_pagesize'] == -1 ) return ""; if ( $p_size==0) { $p_size= $_SESSION['g_pagesize']; } // if there is no row return an empty string if ( $p_line == 0 ) return ""; // Clean url, cut away variable coming frm here $url=cleanUrl(); // action to clean $url=str_replace('&p_action=delete','',$url); // compute max of page $nb_page=($p_line-($p_line%$p_size))/$p_size; echo_debug('user_common',__LINE__,"nb_page = $nb_page"); // if something remains if ( $p_line % $p_size != 0 ) $nb_page+=1; // if max page == 1 then return a empty string if ( $nb_page == 1) return ""; // restore the sort if ( isset($_GET['o'])) $url=$url.'&o='.$_GET['o']; $r=""; // previous if ($p_page !=1) { $e=$p_page-1; $step=$p_size; $offset=($e-1)*$step; $r=''; //$r.="Précédent"; $r.=''; $r.="  "; } //---------------------------------------------------------------------- // Create a partial bar // if current page < 11 show 1 to 20 // otherwise show $p_page -10 to $p_page + 10 //---------------------------------------------------------------------- $start_bar=($p_page < 11 )?1:$p_page-10; $end_bar =($p_page < 11 )?20:$p_page+10; $end_bar =($end_bar > $nb_page )?$nb_page:$end_bar; // Create the bar for ($e=$start_bar;$e<=$end_bar;$e++) { // do not included current page if ( $e != $p_page ) { $step=$p_size; $offset=($e-1)*$step; $go=$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step"; $r.=sprintf('%d ',$go,$p_javascript,$e); } else { $r.=" [ $e ] "; } //else } //for // next if ($p_page !=$nb_page) { // If we are not at the last page show the button next $e=$p_page+1; $step=$p_size; $offset=($e-1)*$step; $r.=' '; //$r.="Suivant"; $r.=''; $r.=""; } return $r; } /*! * \brief Clean the url, remove the $_GET offset,step, page and size * \param none * * \return the cleaned url */ function CleanUrl() { // Compute the url $url=""; $and=""; $get=$_GET; if ( isset ($get) ) { foreach ($get as $name=>$value ) { // we clean the parameter offset, step, page and size if ( ! in_array($name,array('offset','step','page','size','s','o'))) { $url.=$and.$name."=".$value; $and="&"; }// if }//foreach }// if return $url; } function get_redirect($p_string) { echo ' Connecting... '; } ?>