cn=$p_cn; } function set_jrn($p_jrn) { $this->jrn_def_id=$p_jrn; } function set_periode($pp_id){ $this->p_id=$pp_id; } function is_closed() { if ( $this->jrn_def_id != 0 ) $sql="select status from jrn_periode ". " where jrn_def_id=".$this->jrn_def_id. " and p_id =".$this->p_id; else $sql="select p_closed as status from parm_periode ". " where ". " p_id =".$this->p_id; $res=ExecSql($this->cn,$sql); $status=pg_fetch_result($res,0,0); echo_debug(__FILE__.':'.__LINE__.'- is_closed','return ',$status); if ( $status == 'CL' || $status=='t' ||$status=='CE') return 1; return 0; } function is_open() { if ( $this->jrn_def_id != 0 ) $sql="select status from jrn_periode ". " where jrn_def_id=".$this->jrn_def_id. " and p_id =".$this->p_id; else $sql="select p_closed as status from parm_periode ". " where ". " p_id =".$this->p_id; $res=ExecSql($this->cn,$sql); $status=pg_fetch_result($res,0,0); if ( $status == 'OP' || $status=='f' ) return 1; return 0; } function is_centralized() { if ( $this->jrn_def_id != 0 ) $sql="select status from jrn_periode ". " where jrn_def_id=".$this->jrn_def_id. " and p_id =".$this->p_id; else $sql="select p_centralized as status from parm_periode ". " where ". " p_id =".$this->p_id; $res=ExecSql($this->cn,$sql); $status=pg_fetch_result($res,0,0); if ( $status == 'CE' || $status=='t' ) return 1; return 0; } function close() { if ( $this->jrn_def_id == 0 ) { ExecSql($this->cn,"update parm_periode set p_closed=true where p_id=". $this->p_id); ExecSql($this->cn,"update jrn_periode set status='CL' ". " where p_id = ".$this->p_id); return; }else { ExecSql($this->cn,"update jrn_periode set status='CL' ". " where jrn_def_id=".$this->jrn_def_id." and ". " p_id = ".$this->p_id); /* if all ledgers have this periode closed then synchro with the table parm_periode */ $nJrn=CountSql( $this->cn,"select * from jrn_periode where ". " p_id=".$this->p_id); $nJrnPeriode=CountSql( $this->cn,"select * from jrn_periode where ". " p_id=".$this->p_id." and status='CL'"); if ( $nJrnPeriode==$nJrn) ExecSql($this->cn,"update parm_periode set p_closed=true where p_id=".$this->p_id); return; } } function centralized() { if ( $this->jrn_def_id == 0 ) { ExecSql($this->cn,"update parm_periode set p_central=true"); return; }else { ExecSql($this->cn,"update jrn_periode set status='CE' ". " where ". " p_id = ".$this->p_id); return; } } /*! * \brief Show all the periode and their status * * \param $p_cn database connection * * \return nothing * * */ function display_form_periode() { $str_dossier=dossier::get(); if ( $this->jrn_def_id==0 ) { $Res=ExecSql($this->cn,"select p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as date_end,p_central,p_closed,p_exercice from parm_periode order by p_start,p_end"); $Max=pg_NumRows($Res); echo ''; echo ""; echo ''; echo ''; echo ''; echo ""; for ($i=0;$i<$Max;$i++) { $l_line=pg_fetch_array($Res,$i); echo ''; echo ''; echo ''; echo ''; if ( $l_line['p_closed'] == 't' ) { $closed=($l_line['p_central']=='t')?'':''; $change=''; $remove=''; } else { $closed=''; } echo ''; echo dossier::hidden(); echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; echo '
Date début Date fin Exercice
'.$l_line['date_start'].' '.$l_line['date_end'].' '.$l_line['p_exercice'].'CentraliséeFermée'; $closed.=' Cloturer'; $change=''; $change.=' Changer"; $remove=''; $remove.=' Efface"; } echo "$closed"; echo $change; echo $remove; echo '
'; echo '
'; } else { $Res=ExecSql($this->cn,"select p_id,to_char(p_start,'DD.MM.YYYY') as date_start,to_char(p_end,'DD.MM.YYYY') as date_end,status,p_exercice from parm_periode join jrn_periode using (p_id) where jrn_def_id=".$this->jrn_def_id." order by p_start,p_end"); $Max=pg_NumRows($Res); $r=ExecSql($this->cn,'select jrn_Def_name from jrn_Def where jrn_Def_id='. $this->jrn_def_id); $jrn_name=pg_fetch_result($r,0,0); echo '

Journal '.$jrn_name.'

'; echo ''; echo ""; echo ''; echo ''; echo ''; echo ""; for ($i=0;$i<$Max;$i++) { $l_line=pg_fetch_array($Res,$i); echo ''; echo ''; echo ''; echo ''; if ( $l_line['status'] != 'OP' ) { $closed=($l_line['status']=='CE')?'':''; } else { $closed=''; } echo "$closed"; echo ''; } echo '
Date début Date fin Exercice
'.$l_line['date_start'].' '.$l_line['date_end'].' '.$l_line['p_exercice'].'CentraliseeFermée'; $closed.=' Cloturer'; $closed.='
'; } } function insert($p_date_start,$p_date_end,$p_exercice) { if (isDate($p_date_start) == null || isDate($p_date_end) == null || strlen (trim($p_exercice)) == 0 || (string) $p_exercice != (string)(int) $p_exercice) { return 1; } $p_id=NextSequence($this->cn,'s_periode'); $sql=sprintf(" insert into parm_periode(p_id,p_start,p_end,p_closed,p_exercice)". "values (%d,to_date('%s','DD.MM.YYYY'),to_date('%s','DD.MM.YYYY')". ",'f','%s')", $p_id, $p_date_start, $p_date_end, $p_exercice); try { StartSql($this->cn); $Res=ExecSql($this->cn,$sql); $Res=ExecSql($this->cn,"insert into jrn_periode (jrn_def_id,p_id,status) ". "select jrn_def_id,$p_id,'OP' from jrn_def"); Commit($this->cn); } catch (Exception $e) { Rollback($this->cn); echo_debug(__FILE__.':'.__LINE__.'- Periode insert','Exception ',$e); echo_debug(__FILE__.':'.__LINE__.'- Periode insert','Exception ',$e->getMessage()); return 1; } return 0; } static function test_me() { $cn=DbConnect(dossier::id()); $obj=new Periode($cn); $obj->set_jrn(1); $obj->display_form_periode(); } }