altocompta/include/class_periode.php
sparkyx 7327b49f16 Add centralized and closing periode to gestion module
Add security for module Budget
Add paid & unpaid to module "gestion"
Add Periode & Centra to module "Gestion"
Add Filter for gestion, security
Documentation
Close periode by ledger
2008-01-10 21:44:39 +00:00

238 lines
7.7 KiB
PHP

<?php
/*
* This file is part of PhpCompta.
*
* PhpCompta is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhpCompta is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpCompta; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/* $Revision$ */
// Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
/*!\file
* \brief For the periode table parm_periode and jrn_periode
*/
class Periode {
var $cn; /*!< database connection */
var $jrn_def_id; /*!< the jr, 0 means all the ledger*/
var $p_id; /*!< pk of parm_periode */
var $status; /*!< status is CL for closed, OP for
open and CE for centralized */
function __construct($p_cn) {
$this->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 '<TABLE ALIGN="CENTER">';
echo "</TR>";
echo '<TH> Date d&eacute;but </TH>';
echo '<TH> Date fin </TH>';
echo '<TH> Exercice </TH>';
echo "</TR>";
for ($i=0;$i<$Max;$i++) {
$l_line=pg_fetch_array($Res,$i);
echo '<TR>';
echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
echo '<TD ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
echo '<TD ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
if ( $l_line['p_closed'] == 't' ) {
$closed=($l_line['p_central']=='t')?'<TD>Centralis&eacute;e</TD>':'<TD>Ferm&eacute;e</TD>';
$change='<TD></TD>';
$remove='<TD></TD>';
} else {
$closed='<TD class="mtitle">';
$closed.='<A class="mtitle" HREF="?p_action=periode&action=closed&p_per='.$l_line['p_id'].'&'.$str_dossier.'"> Cloturer</A>';
$change='<TD class="mtitle">';
$change.='<A class="mtitle" HREF="?p_action=periode&action=change_per&p_per='.
$l_line['p_id']."&p_date_start=".$l_line['date_start'].
"&p_date_end=".$l_line['date_end']."&p_exercice=".
$l_line['p_exercice']."&$str_dossier\"> Changer</A>";
$remove='<TD class="mtitle">';
$remove.='<A class="mtitle" HREF="?p_action=periode&action=delete_per&p_per='.
$l_line['p_id']."&$str_dossier\"> Efface</A>";
}
echo "$closed";
echo $change;
echo $remove;
echo '</TR>';
}
echo '<TR> <FORM ACTION="?p_action=periode" METHOD="POST">';
echo dossier::hidden();
echo '<TD> <INPUT TYPE="text" NAME="p_date_start" SIZE="10"></TD>';
echo '<TD> <INPUT TYPE="text" NAME="p_date_end" SIZE="10"></TD>';
echo '<TD> <INPUT TYPE="text" NAME="p_exercice" SIZE="10"></TD>';
echo '<TD> <INPUT TYPE="SUBMIT" NAME="add_per" Value="Ajout"</TD>';
echo '<TD></TD>';
echo '<TD></TD>';
echo '</FORM></TR>';
echo '</TABLE>';
} 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 '<h2> Journal '.$jrn_name.'</h2>';
echo '<TABLE ALIGN="CENTER">';
echo "</TR>";
echo '<TH> Date d&eacute;but </TH>';
echo '<TH> Date fin </TH>';
echo '<TH> Exercice </TH>';
echo "</TR>";
for ($i=0;$i<$Max;$i++) {
$l_line=pg_fetch_array($Res,$i);
echo '<TR>';
echo '<TD ALIGN="CENTER"> '.$l_line['date_start'].'</TD>';
echo '<TD ALIGN="CENTER"> '.$l_line['date_end'].'</TD>';
echo '<TD ALIGN="CENTER"> '.$l_line['p_exercice'].'</TD>';
if ( $l_line['status'] != 'OP' ) {
$closed=($l_line['status']=='CE')?'<TD>Centralisée</TD>':'<TD>Ferm&eacute;e</TD>';
} else {
$closed='<TD class="mtitle">';
$closed.='<A class="mtitle" HREF="?p_action=periode&action=closed&p_per='.$l_line['p_id'].'&'.$str_dossier.'&jrn_def_id='.$this->jrn_def_id.'"> Cloturer</A>';
$closed.='</td>';
}
echo "$closed";
echo '</TR>';
}
echo '</TABLE>';
}
}
static function test_me() {
$cn=DbConnect(dossier::id());
$obj=new Periode($cn);
$obj->set_jrn(1);
$obj->display_form_periode();
}
}