From 7327b49f160ce28a12ba7d3853f53b113877eb3b Mon Sep 17 00:00:00 2001 From: sparkyx Date: Thu, 10 Jan 2008 21:44:39 +0000 Subject: [PATCH] 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 --- include/bank.inc.php | 12 +- include/ca_group.inc.php | 2 +- include/central_inc.php | 10 +- include/class_acc_ledger.php | 2167 +++++++++++++++--------------- include/class_anc_group.php | 5 +- include/class_bud_card.php | 25 + include/class_periode.php | 238 ++++ include/class_user.php | 14 + include/constant.php | 6 +- include/depense.inc.php | 97 +- include/dossier.inc.php | 1 + include/facture.inc.php | 96 +- include/modele.inc.php | 6 + include/param_jrn.inc.php | 52 + include/param_jrn_add.inc.php | 193 +++ include/param_jrn_detail.inc.php | 268 ++++ include/param_pcmn.inc.php | 205 +++ include/param_sec.inc.php | 275 ++++ include/param_user.inc.php | 272 ++++ include/periode.inc.php | 51 +- include/preference.php | 67 - include/quick_writing.inc.php | 16 +- include/user_action_ach.php | 1 + include/user_action_ods.php | 19 + include/user_action_ven.php | 2 +- include/user_common.php | 8 - include/user_form_ach.php | 38 +- include/user_form_fin.php | 19 +- include/user_form_ods.php | 18 +- include/user_form_ven.php | 35 +- include/user_menu.php | 52 +- sql/upgrade.sql | 126 ++ 32 files changed, 3131 insertions(+), 1265 deletions(-) create mode 100644 include/class_periode.php create mode 100644 include/param_jrn.inc.php create mode 100644 include/param_jrn_add.inc.php create mode 100644 include/param_jrn_detail.inc.php create mode 100644 include/param_pcmn.inc.php create mode 100644 include/param_sec.inc.php create mode 100644 include/param_user.inc.php diff --git a/include/bank.inc.php b/include/bank.inc.php index 1b960edfe..9f81a2af7 100644 --- a/include/bank.inc.php +++ b/include/bank.inc.php @@ -123,11 +123,6 @@ if ( $sub_action == "solde" ) // if ( $sub_action == "list") { - // Check privilege - if ( CheckJrn($gDossier,$_SESSION['g_user'],$p_jrn) < 1 ) { - NoAccess(); - exit -1; - } // show the menu with the list item selected echo '
'; echo ShowMenuJrnUser($gDossier,'FIN',0,'Liste'. @@ -186,10 +181,13 @@ if ( $sub_action == "list") $filter_per=" and jr_tech_per in (select p_id from parm_periode where p_exercice=". $User->get_exercice().")"; } + /* security */ + $available_ledger=" and ".$User->get_ledger_sql(); // Show list of sell // Date - date of payment - Customer - amount - $sql=SQL_LIST_ALL_INVOICE.$filter_per." and jr_def_type='FIN'" ; + $sql=SQL_LIST_ALL_INVOICE.$filter_per." and jr_def_type='FIN'". + " $available_ledger" ; $step=$_SESSION['g_pagesize']; $page=(isset($_GET['offset']))?$_GET['page']:1; $offset=(isset($_GET['offset']))?$_GET['offset']:0; @@ -202,7 +200,7 @@ if ( $sub_action == "list") $l=" and jr_grpt_id in (select j_grpt from jrnx where j_qcode='$qcode') "; } - list($max_line,$list)=ListJrn($cn,0,"where jrn_def_type='FIN' $filter_per $l " + list($max_line,$list)=ListJrn($cn,0,"where jrn_def_type='FIN' $filter_per $l $available_ledger " ,null,$offset,0); $bar=jrn_navigation_bar($offset,$max_line,$step,$page); diff --git a/include/ca_group.inc.php b/include/ca_group.inc.php index c54e64ad8..1241566af 100644 --- a/include/ca_group.inc.php +++ b/include/ca_group.inc.php @@ -48,7 +48,7 @@ if ( isset ($_POST['remove'])) { if ( isset($_POST['add'])) { $obj=new Anc_Group($cn); $obj->get_from_array($_POST); - $obj->insert(); + echo $obj->insert(); } $array=$r->myList(); diff --git a/include/central_inc.php b/include/central_inc.php index 3e4f17497..73e3b9fae 100644 --- a/include/central_inc.php +++ b/include/central_inc.php @@ -87,11 +87,11 @@ $sql="insert into centralized( c_j_id, $Res2=ExecSql($p_cn,$sql); $MaxLine=pg_NumRows($Res2); - $jrn_def_id=$row['jrn_def_id']; + $jrn_def_id=$row['jrn_def_id']; /* if seq doesn't exist create it */ - if ( exist_sequence($p_cn,'s_jrn_'.$jr_def_id) == false ) { - create_sequence($p_cn,'s_jrn_'.$jr_def_id); - } + if ( exist_sequence($p_cn,'s_jrn_'.$jrn_def_id) == false ) { + create_sequence($p_cn,'s_jrn_'.$jrn_def_id); + } for ($e=0;$e < $MaxLine;$e++) { // each line is updated with a sequence @@ -100,7 +100,7 @@ $sql="insert into centralized( c_j_id, $sql=sprintf ("update jrn set jr_opid = (select nextval('s_jrn_%d')) where jr_id =%d", - $jr_def_id, + $jrn_def_id, $jr_id); $Ret=ExecSql($p_cn,$sql); diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index ebace2523..228fd4bec 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -30,6 +30,7 @@ require_once ('class_pre_op_advanced.php'); require_once ('jrn.php'); require_once ('class_acexception.php'); require_once ('class_acc_reconciliation.php'); +require_once ('class_periode.php'); /*!\file * \brief Class for jrn, class acc_ledger for manipulating the ledger */ @@ -38,111 +39,111 @@ require_once ('class_acc_reconciliation.php'); * */ class Acc_Ledger { -var $id; /*!< jrn_def.jrn_def_id */ -var $name; /*!< jrn_def.jrn_def_name */ -var $db; /*!< database connextion */ -var $row; /*!< row of the ledger */ -var $type; /*!< type of the ledger ACH ODS FIN - VEN or GL */ -var $nb; /*!< default number of rows by - default 10 */ + var $id; /*!< jrn_def.jrn_def_id */ + var $name; /*!< jrn_def.jrn_def_name */ + var $db; /*!< database connextion */ + var $row; /*!< row of the ledger */ + var $type; /*!< type of the ledger ACH ODS FIN + VEN or GL */ + var $nb; /*!< default number of rows by + default 10 */ -function Acc_Ledger ($p_cn,$p_id){ -$this->id=$p_id; -$this->db=$p_cn; -$this->row=null; -$this->nb=10; -} -/*! -* \brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL -* -*/ -function get_type() { -if ( $this->id==0 ) { -$this->name=" Grand Livre "; -$this->type="GL"; -return "GL"; -} + function Acc_Ledger ($p_cn,$p_id){ + $this->id=$p_id; + $this->db=$p_cn; + $this->row=null; + $this->nb=10; + } + /*! + * \brief Return the type of a ledger (ACH,VEN,ODS or FIN) or GL + * + */ + function get_type() { + if ( $this->id==0 ) { + $this->name=" Grand Livre "; + $this->type="GL"; + return "GL"; + } -$Res=ExecSql($this->db,"select jrn_def_type from ". - " jrn_def where jrn_def_id=". - $this->id); -$Max=pg_NumRows($Res); -if ($Max==0) return null; -$ret=pg_fetch_array($Res,0); -$this->type=$ret['jrn_def_type']; -return $ret['jrn_def_type']; -} -/*! -* \brief Return the name of a ledger -* -*/ -function get_name() { -if ( $this->id==0 ) { -$this->name=" Grand Livre "; -return $this->name; -} + $Res=ExecSql($this->db,"select jrn_def_type from ". + " jrn_def where jrn_def_id=". + $this->id); + $Max=pg_NumRows($Res); + if ($Max==0) return null; + $ret=pg_fetch_array($Res,0); + $this->type=$ret['jrn_def_type']; + return $ret['jrn_def_type']; + } + /*! + * \brief Return the name of a ledger + * + */ + function get_name() { + if ( $this->id==0 ) { + $this->name=" Grand Livre "; + return $this->name; + } + + $Res=ExecSql($this->db,"select jrn_def_name from ". + " jrn_def where jrn_def_id=". + $this->id); + $Max=pg_NumRows($Res); + if ($Max==0) return null; + $ret=pg_fetch_array($Res,0); + $this->name=$ret['jrn_def_name']; + return $ret['jrn_def_name']; + } + + + /*! \function get_row + * \brief Get The data + * + * + * \param p_from from periode + * \param p_to to periode + * \param $p_cent (on or off) + * \param p_limit starting line + * \param p_offset number of lines + * + * gen : + * - none + * \return Array with the asked data + * + */ + function get_row($p_from,$p_to,$cent='off',$p_limit=-1,$p_offset=-1) { -$Res=ExecSql($this->db,"select jrn_def_name from ". - " jrn_def where jrn_def_id=". - $this->id); -$Max=pg_NumRows($Res); -if ($Max==0) return null; -$ret=pg_fetch_array($Res,0); -$this->name=$ret['jrn_def_name']; -return $ret['jrn_def_name']; -} + echo_debug('class_acc_ledger.php',__LINE__,"get_row ( $p_from,$p_to,$cent,$p_limit,$p_offset)"); + + $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); + + $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; + // retrieve the type + $this->get_type(); + // Grand livre == 0 + if ( $this->id != 0 ) { - -/*! \function get_row -* \brief Get The data -* -* -* \param p_from from periode -* \param p_to to periode -* \param $p_cent (on or off) -* \param p_limit starting line -* \param p_offset number of lines -* -* gen : -* - none -* \return Array with the asked data -* -*/ -function get_row($p_from,$p_to,$cent='off',$p_limit=-1,$p_offset=-1) { - -echo_debug('class_acc_ledger.php',__LINE__,"get_row ( $p_from,$p_to,$cent,$p_limit,$p_offset)"); - -$periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); - -$cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; -// retrieve the type -$this->get_type(); -// Grand livre == 0 -if ( $this->id != 0 ) { - -if ( $cent=='off' ) { - echo_debug('class_acc_ledger.php',__LINE__,"journaux non centralisé"); - // Journaux non centralisés - $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, + if ( $cent=='off' ) { + echo_debug('class_acc_ledger.php',__LINE__,"journaux non centralisé"); + // Journaux non centralisés + $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, jr_internal, case j_debit when 't' then j_montant::text else ' ' end as deb_montant, case j_debit when 'f' then j_montant::text else ' ' end as cred_montant, j_debit as debit,j_poste as poste,jr_montant , ". - "pcm_lib as description,j_grpt as grp, + "pcm_lib as description,j_grpt as grp, jr_comment||' ('||jr_internal||')' as jr_comment , j_qcode, jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ". - "jr_grpt_id=j_grpt ". - " left join tmp_pcmn on pcm_val=j_poste ". - " where j_jrn_def=".$this->id. - " and ".$periode." order by j_date::date asc,jr_internal,j_debit desc ". - $cond_limite); -}else { -// Journaux centralisés -// echo'class_acc_ledger.php',__LINE__,"journaux centralisé"; -$Sql="select jr_opid as j_id, + "jr_grpt_id=j_grpt ". + " left join tmp_pcmn on pcm_val=j_poste ". + " where j_jrn_def=".$this->id. + " and ".$periode." order by j_date::date asc,jr_internal,j_debit desc ". + $cond_limite); + }else { + // Journaux centralisés + // echo'class_acc_ledger.php',__LINE__,"journaux centralisé"; + $Sql="select jr_opid as j_id, c_order as int_j_id, to_char (c_date,'DD.MM.YYYY') as j_date , c_internal as jr_internal, @@ -164,34 +165,34 @@ $Sql="select jr_opid as j_id, left join tmp_pcmn on pcm_val=c_poste left join jrn on jr_grpt_id=c_grp where ". - " c_jrn_def=".$this->id." and ". - $periode." order by c_order "; -$Res=ExecSql($this->db,$Sql.$cond_limite); + " c_jrn_def=".$this->id." and ". + $periode." order by c_order "; + $Res=ExecSql($this->db,$Sql.$cond_limite); -} -} else { -// Grand Livre -if ( $cent == 'off') { -echo_debug('class_acc_ledger.php',__LINE__,"Grand livre non centralisé"); -// Non centralisé -$Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, + } + } else { + // Grand Livre + if ( $cent == 'off') { + echo_debug('class_acc_ledger.php',__LINE__,"Grand livre non centralisé"); + // Non centralisé + $Res=ExecSql($this->db,"select j_id,j_id as int_j_id,to_char(j_date,'DD.MM.YYYY') as j_date, jr_internal, case j_debit when 't' then j_montant::text else ' ' end as deb_montant, case j_debit when 'f' then j_montant::text else ' ' end as cred_montant, j_debit as debit,j_poste as poste,". - "pcm_lib as description,j_grpt as grp, + "pcm_lib as description,j_grpt as grp, jr_comment||' ('||jr_internal||')' as jr_comment, jr_montant, j_qcode, jr_rapt as oc, j_tech_per as periode from jrnx left join jrn on ". - "jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste where ". - " ".$periode." order by j_date::date,j_grpt,j_debit desc ". - $cond_limite); + "jr_grpt_id=j_grpt left join tmp_pcmn on pcm_val=j_poste where ". + " ".$periode." order by j_date::date,j_grpt,j_debit desc ". + $cond_limite); -} else { -echo_debug('class_acc_ledger.php',__LINE__,"Grand livre centralisé"); -// Centralisé -$Sql="select jr_c_opid as j_id, + } else { + echo_debug('class_acc_ledger.php',__LINE__,"Grand livre centralisé"); + // Centralisé + $Sql="select jr_c_opid as j_id, c_order as int_j_id, c_j_id, to_char (c_date,'DD.MM.YYYY') as j_date , @@ -208,137 +209,137 @@ $Sql="select jr_c_opid as j_id, c_rapt as oc, c_periode as periode from centralized left join jrn on ". - "jr_grpt_id=c_grp left join tmp_pcmn ". - " on (pcm_val=c_poste) ". - " join jrnx on (j_id=c_j_id)". - " where ". - $periode." order by c_order "; -$Res=ExecSql($this->db,$Sql.$cond_limite); -} // Grand Livre -} + "jr_grpt_id=c_grp left join tmp_pcmn ". + " on (pcm_val=c_poste) ". + " join jrnx on (j_id=c_j_id)". + " where ". + $periode." order by c_order "; + $Res=ExecSql($this->db,$Sql.$cond_limite); + } // Grand Livre + } -$array=array(); -$Max=pg_NumRows($Res); -if ($Max==0) return null; -$case=""; -$tot_deb=0; -$tot_cred=0; -$row=pg_fetch_all($Res); -for ($i=0;$i<$Max;$i++) { -$fiche=new fiche($this->db); -$line=$row[$i]; -$mont_deb=($line['deb_montant']!=0)?sprintf("% 8.2f",$line['deb_montant']):""; -$mont_cred=($line['cred_montant']!=0)?sprintf("% 8.2f",$line['cred_montant']):""; -$jr_montant=($line['jr_montant']!=0)?sprintf("% 8.2f",$line['jr_montant']):""; -$tot_deb+=$line['deb_montant']; -$tot_cred+=$line['cred_montant']; -$tot_op=$line['jr_montant']; -echo_debug('class_acc_ledger.php',__LINE__," get_row : mont_Deb ".$mont_deb); -echo_debug('class_acc_ledger.php',__LINE__," get_row : mont_cred ".$mont_cred); + $array=array(); + $Max=pg_NumRows($Res); + if ($Max==0) return null; + $case=""; + $tot_deb=0; + $tot_cred=0; + $row=pg_fetch_all($Res); + for ($i=0;$i<$Max;$i++) { + $fiche=new fiche($this->db); + $line=$row[$i]; + $mont_deb=($line['deb_montant']!=0)?sprintf("% 8.2f",$line['deb_montant']):""; + $mont_cred=($line['cred_montant']!=0)?sprintf("% 8.2f",$line['cred_montant']):""; + $jr_montant=($line['jr_montant']!=0)?sprintf("% 8.2f",$line['jr_montant']):""; + $tot_deb+=$line['deb_montant']; + $tot_cred+=$line['cred_montant']; + $tot_op=$line['jr_montant']; + echo_debug('class_acc_ledger.php',__LINE__," get_row : mont_Deb ".$mont_deb); + echo_debug('class_acc_ledger.php',__LINE__," get_row : mont_cred ".$mont_cred); -/* Check first if there is a quickcode */ -if ( strlen(trim($line['j_qcode'])) != 0 ) -{ -if ( $fiche->get_by_qcode($line['j_qcode'],false) == 0 ) - { - $line['description']=$fiche->strAttribut(ATTR_DEF_NAME); - } -} -if ( $case != $line['grp'] ) { -$case=$line['grp']; - // for financial, we show if the amount is or not in negative - if ( $this->type=='FIN') { - echo_debug(__FILE__,__LINE__,"Journal FIN"); - $eMax=(($i+20) < $Max)?$i+20:$Max; - // check in $row if the BQE is in deb or cred - for ($e=$i;$e<$Max;$e++) { - echo_debug(__FILE__,__LINE__,$row[$e]); - if ( $row[$e]['grp'] != $case ) continue; - if ( strlen(trim($row[$e]['j_qcode'])) == 0 ) continue; + /* Check first if there is a quickcode */ + if ( strlen(trim($line['j_qcode'])) != 0 ) + { + if ( $fiche->get_by_qcode($line['j_qcode'],false) == 0 ) + { + $line['description']=$fiche->strAttribut(ATTR_DEF_NAME); + } + } + if ( $case != $line['grp'] ) { + $case=$line['grp']; + // for financial, we show if the amount is or not in negative + if ( $this->type=='FIN') { + echo_debug(__FILE__,__LINE__,"Journal FIN"); + $eMax=(($i+20) < $Max)?$i+20:$Max; + // check in $row if the BQE is in deb or cred + for ($e=$i;$e<$Max;$e++) { + echo_debug(__FILE__,__LINE__,$row[$e]); + if ( $row[$e]['grp'] != $case ) continue; + if ( strlen(trim($row[$e]['j_qcode'])) == 0 ) continue; - $f=new fiche($this->db); - $f->get_by_qcode($row[$e]['j_qcode'],false); - echo_debug(__FILE__,__LINE__,$f); - if ( $f->get_fiche_def_ref_id() == FICHE_TYPE_FIN ) { - $tot_op=($row[$e]['debit'] == 't')?$jr_montant:" - ".$jr_montant; - break; + $f=new fiche($this->db); + $f->get_by_qcode($row[$e]['j_qcode'],false); + echo_debug(__FILE__,__LINE__,$f); + if ( $f->get_fiche_def_ref_id() == FICHE_TYPE_FIN ) { + $tot_op=($row[$e]['debit'] == 't')?$jr_montant:" - ".$jr_montant; + break; + } } } + $array[]=array ( + 'int_j_id' => $line['int_j_id'], + 'j_id'=>$line['j_id'], + 'j_date' => $line['j_date'], + 'internal'=>$line['jr_internal'], + 'deb_montant'=>'', + 'cred_montant'=>' ', + 'description'=>''.$line['jr_comment'].' ['.$tot_op.'] ', + 'poste' => $line['oc'], + 'qcode' => $line['j_qcode'], + 'periode' =>$line['periode'] ); + + $array[]=array ( + 'int_j_id' => $line['int_j_id'], + 'j_id'=>'', + 'j_date' => '', + 'internal'=>'', + 'deb_montant'=>$mont_deb, + 'cred_montant'=>$mont_cred, + 'description'=>$line['description'], + 'poste' => $line['poste'], + 'qcode' => $line['j_qcode'], + 'periode' => $line['periode'] + ); + + }else { + $array[]=array ( + 'int_j_id' => $line['int_j_id'], + 'j_id'=>'', + 'j_date' => '', + 'internal'=>'', + 'deb_montant'=>$mont_deb, + 'cred_montant'=>$mont_cred, + 'description'=>$line['description'], + 'poste' => $line['poste'], + 'qcode' => $line['j_qcode'], + 'periode' => $line['periode']); + + } + + + } + echo_debug('class_acc_ledger.php',__LINE__,"Total debit $tot_deb,credit $tot_cred"); + $this->row=$array; + $a=array($array,$tot_deb,$tot_cred); + return $a; } -$array[]=array ( - 'int_j_id' => $line['int_j_id'], - 'j_id'=>$line['j_id'], - 'j_date' => $line['j_date'], - 'internal'=>$line['jr_internal'], - 'deb_montant'=>'', - 'cred_montant'=>' ', - 'description'=>''.$line['jr_comment'].' ['.$tot_op.'] ', - 'poste' => $line['oc'], - 'qcode' => $line['j_qcode'], - 'periode' =>$line['periode'] ); + /* \brief Get simplified row from ledger + * + * \param from periode + * \param to periode + * \param centralized (on or off) + * \param p_limit starting line + * \param p_offset number of lines + * \param trunc if data must be truncated (pdf export) + * + * \return an Array with the asked data + */ + function get_rowSimple($p_from,$p_to,$cent='off',$trunc=0,$p_limit=-1,$p_offset=-1) + { + // Grand-livre : id= 0 + //--- + $jrn=($this->id == 0 )?"":"and jrn_def_id = ".$this->id; + // Non Centralise si cent=off + //-- + if ($cent=='off') + {// Non centralisé -$array[]=array ( - 'int_j_id' => $line['int_j_id'], - 'j_id'=>'', - 'j_date' => '', - 'internal'=>'', - 'deb_montant'=>$mont_deb, - 'cred_montant'=>$mont_cred, - 'description'=>$line['description'], - 'poste' => $line['poste'], - 'qcode' => $line['j_qcode'], - 'periode' => $line['periode'] - ); + $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); -}else { -$array[]=array ( - 'int_j_id' => $line['int_j_id'], - 'j_id'=>'', - 'j_date' => '', - 'internal'=>'', - 'deb_montant'=>$mont_deb, - 'cred_montant'=>$mont_cred, - 'description'=>$line['description'], - 'poste' => $line['poste'], - 'qcode' => $line['j_qcode'], - 'periode' => $line['periode']); - -} - - -} -echo_debug('class_acc_ledger.php',__LINE__,"Total debit $tot_deb,credit $tot_cred"); -$this->row=$array; -$a=array($array,$tot_deb,$tot_cred); -return $a; -} -/* \brief Get simplified row from ledger -* -* \param from periode -* \param to periode -* \param centralized (on or off) -* \param p_limit starting line -* \param p_offset number of lines -* \param trunc if data must be truncated (pdf export) -* -* \return an Array with the asked data -*/ -function get_rowSimple($p_from,$p_to,$cent='off',$trunc=0,$p_limit=-1,$p_offset=-1) -{ -// Grand-livre : id= 0 -//--- -$jrn=($this->id == 0 )?"":"and jrn_def_id = ".$this->id; -// Non Centralise si cent=off -//-- -if ($cent=='off') -{// Non centralisé - - $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); - - $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; - //--- - $sql=" + $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; + //--- + $sql=" SELECT jrn.jr_id as jr_id , jrn.jr_id as num , jrn.jr_def_id as jr_def_id, @@ -352,18 +353,18 @@ if ($cent=='off') jrn.jr_tech_per FROM jrn join jrn_def on (jrn_def_id=jr_def_id) WHERE $periode $jrn order by jr_date $cond_limite"; -} -else -{ + } + else + { - $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); + $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); -$cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; - //Centralisé - //--- - $id=($this->id == 0 ) ?"jr_c_opid as num":"jr_opid as num"; + $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; + //Centralisé + //--- + $id=($this->id == 0 ) ?"jr_c_opid as num":"jr_opid as num"; - $sql=" + $sql=" SELECT jrn.jr_id as jr_id , $id , jrn.jr_def_id as jr_def_id, @@ -380,255 +381,255 @@ $cond_limite=($p_limit!=-1)?" limit ".$p_limit." offset ".$p_offset:""; $periode $jrn and jr_opid is not null order by jr_date $cond_limite"; -}// end else $cent=='off' -//load all data into an array -//--- + }// end else $cent=='off' + //load all data into an array + //--- -$Res=ExecSql($this->db,$sql); -$Max=pg_NumRows($Res); -if ( $Max == 0 ) -{ - return null; -} -$type=$this->get_type(); -// for type ACH and Ven we take more info -if ( $type == 'ACH' || $type == 'VEN') -{ -$a_ParmCode=get_array($this->db,'select p_code,p_value from parm_code'); -$a_TVA=get_array($this->db,'select tva_id,tva_label,tva_poste + $Res=ExecSql($this->db,$sql); + $Max=pg_NumRows($Res); + if ( $Max == 0 ) + { + return null; + } + $type=$this->get_type(); + // for type ACH and Ven we take more info + if ( $type == 'ACH' || $type == 'VEN') + { + $a_ParmCode=get_array($this->db,'select p_code,p_value from parm_code'); + $a_TVA=get_array($this->db,'select tva_id,tva_label,tva_poste from tva_rate where tva_rate != 0 order by tva_id'); - for ( $i=0;$i<$Max;$i++) - { - $array[$i]=pg_fetch_array($Res); - $p=$this->get_detail($array[$i],$type,$trunc,$a_TVA,$a_ParmCode); + for ( $i=0;$i<$Max;$i++) + { + $array[$i]=pg_fetch_array($Res); + $p=$this->get_detail($array[$i],$type,$trunc,$a_TVA,$a_ParmCode); - } - -} -else -{ - $array=pg_fetch_all($Res); - -} - -return $array; -}// end function get_rowSimple - -/*! -* \brief get_detail gives the detail of row -* this array must contains at least the field -* -* the following field will be added -* -* -* \param p_array the structure is set in get_rowSimple, this array is -* modified, -* \param $trunc if the data must be truncated, usefull for pdf export -* \param p_jrn_type is the type of the ledger (ACH or VEN) -* \param $a_TVA TVA Array (default null) -* \param $a_ParmCode Array (default null) -* \return p_array -*/ -function get_detail(&$p_array,$p_jrn_type,$trunc=0,$a_TVA=null,$a_ParmCode=null) -{ -if ( $a_TVA == null ) -{ -//Load TVA array -$a_TVA=get_array($this->db,'select tva_id,tva_label,tva_poste - from tva_rate where tva_rate != 0 order by tva_id'); -} -if ( $a_ParmCode == null ) -{ -//Load Parm_code -$a_ParmCode=get_array($this->db,'select p_code,p_value from parm_code'); -} -// init -$p_array['client']=""; -$p_array['TVAC']=0; -$p_array['TVA']=array(); -$p_array['AMOUNT_TVA']=0.0; -// -// Retrieve data from jrnx -$sql="select j_poste,j_montant, j_debit,j_qcode from jrnx where ". - " j_grpt=".$p_array['grpt_id']; -$Res2=ExecSql($this->db,$sql); -$data_jrnx=pg_fetch_all($Res2); -$c=0; - -// Parse data from jrnx and fill diff. field -foreach ( $data_jrnx as $code ) { - $idx_tva=0; - echo_debug('class_acc_ledger',__LINE__,'Code is'); - echo_debug('class_acc_ledger',__LINE__,$code); - $poste=new Acc_Account($this->db,$code['j_poste']); - - // if card retrieve name if the account is not a VAT account - if ( strlen(trim($code['j_qcode'] )) != 0 && $poste->isTva() == 0 ) - { - echo_debug('class_acc_ledger',__LINE__,'fiche_def = '.$code['j_qcode']); - $fiche=new fiche($this->db); - $fiche->get_by_qcode(trim($code['j_qcode']),false); - $fiche_def_id=$fiche->get_fiche_def_ref_id(); - // Customer or supplier - if ( $fiche_def_id == FICHE_TYPE_CLIENT || - $fiche_def_id == FICHE_TYPE_FOURNISSEUR ) - { - echo_debug('class_acc_ledger',__LINE__,$code['j_qcode'].'est F ou C'); - $p_array['TVAC']=$code['j_montant']; - - $p_array['client']=($trunc==0)?$fiche->get_name():substr($fiche->get_name(),0,20); - $p_array['reversed']=false; - if ( $fiche_def_id == FICHE_TYPE_CLIENT && $code['j_debit']=='f') - { - $p_array['reversed']=true; - $p_array['TVAC']*=-1; - - } - if ( $fiche_def_id == FICHE_TYPE_FOURNISSEUR && $code['j_debit']=='t') - { - $p_array['reversed']=true; - $p_array['TVAC']*=-1; } + + } + else + { + $array=pg_fetch_all($Res); + + } + + return $array; + }// end function get_rowSimple + + /*! + * \brief get_detail gives the detail of row + * this array must contains at least the field + * + * the following field will be added + * + * + * \param p_array the structure is set in get_rowSimple, this array is + * modified, + * \param $trunc if the data must be truncated, usefull for pdf export + * \param p_jrn_type is the type of the ledger (ACH or VEN) + * \param $a_TVA TVA Array (default null) + * \param $a_ParmCode Array (default null) + * \return p_array + */ + function get_detail(&$p_array,$p_jrn_type,$trunc=0,$a_TVA=null,$a_ParmCode=null) + { + if ( $a_TVA == null ) + { + //Load TVA array + $a_TVA=get_array($this->db,'select tva_id,tva_label,tva_poste + from tva_rate where tva_rate != 0 order by tva_id'); + } + if ( $a_ParmCode == null ) + { + //Load Parm_code + $a_ParmCode=get_array($this->db,'select p_code,p_value from parm_code'); + } + // init + $p_array['client']=""; + $p_array['TVAC']=0; + $p_array['TVA']=array(); + $p_array['AMOUNT_TVA']=0.0; + // + // Retrieve data from jrnx + $sql="select j_poste,j_montant, j_debit,j_qcode from jrnx where ". + " j_grpt=".$p_array['grpt_id']; + $Res2=ExecSql($this->db,$sql); + $data_jrnx=pg_fetch_all($Res2); + $c=0; + + // Parse data from jrnx and fill diff. field + foreach ( $data_jrnx as $code ) { + $idx_tva=0; + echo_debug('class_acc_ledger',__LINE__,'Code is'); + echo_debug('class_acc_ledger',__LINE__,$code); + $poste=new Acc_Account($this->db,$code['j_poste']); + + // if card retrieve name if the account is not a VAT account + if ( strlen(trim($code['j_qcode'] )) != 0 && $poste->isTva() == 0 ) + { + echo_debug('class_acc_ledger',__LINE__,'fiche_def = '.$code['j_qcode']); + $fiche=new fiche($this->db); + $fiche->get_by_qcode(trim($code['j_qcode']),false); + $fiche_def_id=$fiche->get_fiche_def_ref_id(); + // Customer or supplier + if ( $fiche_def_id == FICHE_TYPE_CLIENT || + $fiche_def_id == FICHE_TYPE_FOURNISSEUR ) + { + echo_debug('class_acc_ledger',__LINE__,$code['j_qcode'].'est F ou C'); + $p_array['TVAC']=$code['j_montant']; + + $p_array['client']=($trunc==0)?$fiche->get_name():substr($fiche->get_name(),0,20); + $p_array['reversed']=false; + if ( $fiche_def_id == FICHE_TYPE_CLIENT && $code['j_debit']=='f') + { + $p_array['reversed']=true; + $p_array['TVAC']*=-1; + + } + if ( $fiche_def_id == FICHE_TYPE_FOURNISSEUR && $code['j_debit']=='t') + { + $p_array['reversed']=true; + $p_array['TVAC']*=-1; + } - } else { - // if we use the ledger ven / ach for others card than supplier and customer - if ( $fiche_def_id != FICHE_TYPE_VENTE && - $fiche_def_id != FICHE_TYPE_ACH_MAR && - $fiche_def_id != FICHE_TYPE_ACH_SER ) { - echo_debug('class_acc_ledger',__LINE__,$code['j_qcode']."n 'est PAS F ou C"); - $p_array['TVAC']=$code['j_montant']; + } else { + // if we use the ledger ven / ach for others card than supplier and customer + if ( $fiche_def_id != FICHE_TYPE_VENTE && + $fiche_def_id != FICHE_TYPE_ACH_MAR && + $fiche_def_id != FICHE_TYPE_ACH_SER ) { + echo_debug('class_acc_ledger',__LINE__,$code['j_qcode']."n 'est PAS F ou C"); + $p_array['TVAC']=$code['j_montant']; - $p_array['client']= ($trunc==0)?$fiche->get_name():substr($fiche->get_name(),0,20); - $p_array['reversed']=false; - if ($p_jrn_type == 'ACH' && $code['j_debit']=='t') - { - $p_array['reversed']=true; - $p_array['TVAC']*=-1; + $p_array['client']= ($trunc==0)?$fiche->get_name():substr($fiche->get_name(),0,20); + $p_array['reversed']=false; + if ($p_jrn_type == 'ACH' && $code['j_debit']=='t') + { + $p_array['reversed']=true; + $p_array['TVAC']*=-1; - } - if ($p_jrn_type == 'VEN' && $code['j_debit']=='f') - { - $p_array['reversed']=true; - $p_array['TVAC']*=-1; - } + } + if ($p_jrn_type == 'VEN' && $code['j_debit']=='f') + { + $p_array['reversed']=true; + $p_array['TVAC']*=-1; + } + } } } - } - echo_debug('class_acc_ledger',__LINE__,$a_TVA); - // if TVA, load amount, tva id and rate in array - foreach ( $a_TVA as $line_tva) - { - echo_debug('class_acc_ledger',__LINE__,'ICI'); - echo_debug('class_acc_ledger',__LINE__,'Montant TVA = '.$p_array['AMOUNT_TVA']); - list($tva_deb,$tva_cred)=split(',',$line_tva['tva_poste']); - if ( $code['j_poste'] == $tva_deb || - $code['j_poste'] == $tva_cred ) + echo_debug('class_acc_ledger',__LINE__,$a_TVA); + // if TVA, load amount, tva id and rate in array + foreach ( $a_TVA as $line_tva) + { + echo_debug('class_acc_ledger',__LINE__,'ICI'); + echo_debug('class_acc_ledger',__LINE__,'Montant TVA = '.$p_array['AMOUNT_TVA']); + list($tva_deb,$tva_cred)=split(',',$line_tva['tva_poste']); + if ( $code['j_poste'] == $tva_deb || + $code['j_poste'] == $tva_cred ) + { + + // For the reversed operation + if ( $p_jrn_type == 'ACH' && $code['j_debit'] == 'f') { - - // For the reversed operation - if ( $p_jrn_type == 'ACH' && $code['j_debit'] == 'f') - { - $code['j_montant']=-1*$code['j_montant']; - } - if ( $p_jrn_type == 'VEN' && $code['j_debit'] == 't') - { - $code['j_montant']=-1*$code['j_montant']; - } - - $p_array['AMOUNT_TVA']+=$code['j_montant']; - - $p_array['TVA'][$c]=array($idx_tva,array($line_tva['tva_id'],$line_tva['tva_label'],$code['j_montant'])); - echo_debug('class_acc_ledger',__LINE__,'Montant TVA = '.$p_array['AMOUNT_TVA']); - $c++; - - $idx_tva++; + $code['j_montant']=-1*$code['j_montant']; } - } + if ( $p_jrn_type == 'VEN' && $code['j_debit'] == 't') + { + $code['j_montant']=-1*$code['j_montant']; + } + + $p_array['AMOUNT_TVA']+=$code['j_montant']; + + $p_array['TVA'][$c]=array($idx_tva,array($line_tva['tva_id'],$line_tva['tva_label'],$code['j_montant'])); + echo_debug('class_acc_ledger',__LINE__,'Montant TVA = '.$p_array['AMOUNT_TVA']); + $c++; + + $idx_tva++; + } + } - // isDNA - // If operation is reversed then amount are negatif + // isDNA + // If operation is reversed then amount are negatif -} -$p_array['TVAC']=sprintf('% 10.2f',$p_array['TVAC']); -$p_array['HTVA']=sprintf('% 10.2f',$p_array['TVAC']-$p_array['AMOUNT_TVA']); -$r=""; -$a_tva_amount=array(); -// inline TVA (used for the PDF) -foreach ($p_array['TVA'] as $linetva) - { - foreach ($a_TVA as $tva) + } + $p_array['TVAC']=sprintf('% 10.2f',$p_array['TVAC']); + $p_array['HTVA']=sprintf('% 10.2f',$p_array['TVAC']-$p_array['AMOUNT_TVA']); + $r=""; + $a_tva_amount=array(); + // inline TVA (used for the PDF) + foreach ($p_array['TVA'] as $linetva) { - if ( $tva['tva_id'] == $linetva[1][0] ) - { - $a=$tva['tva_id']; - $a_tva_amount[$a]=$linetva[1][2]; - } + foreach ($a_TVA as $tva) + { + if ( $tva['tva_id'] == $linetva[1][0] ) + { + $a=$tva['tva_id']; + $a_tva_amount[$a]=$linetva[1][2]; + } + } } - } -foreach ($a_TVA as $line_tva) - { - $a=$line_tva['tva_id']; - if ( isset($a_tva_amount[$a])) + foreach ($a_TVA as $line_tva) { - $tmp=sprintf("% 10.2f",$a_tva_amount[$a]); - // $r.=str_repeat("_",10-strlen($tmp)).$tmp." "; - // $r.=str_repeat(" ",10-strlen($tmp)).$tmp." "; - $r.="$tmp"; + $a=$line_tva['tva_id']; + if ( isset($a_tva_amount[$a])) + { + $tmp=sprintf("% 10.2f",$a_tva_amount[$a]); + // $r.=str_repeat("_",10-strlen($tmp)).$tmp." "; + // $r.=str_repeat(" ",10-strlen($tmp)).$tmp." "; + $r.="$tmp"; + } + else + $r.=sprintf("% 10.2f",0); + // $r.=str_repeat(" ",6)."0.00 "; + // $r.=str_repeat("_",6)."0.00 "; + //$r.=" 0.00"; } - else - $r.=sprintf("% 10.2f",0); - // $r.=str_repeat(" ",6)."0.00 "; - // $r.=str_repeat("_",6)."0.00 "; - //$r.=" 0.00"; - } -$p_array['TVA_INLINE']=$r; + $p_array['TVA_INLINE']=$r; -return $p_array; -} // retrieve data from jrnx -/*! -* \brief Get the properties of a journal -* -* parm : -* - p_dossier the folder id -* - p_jrn the jrn id -* gen : -* - none -* return: -* - an array containing properties -* -*/ -function get_propertie() -{ - if ( $this->id == 0 ) return; + return $p_array; + } // retrieve data from jrnx + /*! + * \brief Get the properties of a journal + * + * parm : + * - p_dossier the folder id + * - p_jrn the jrn id + * gen : + * - none + * return: + * - an array containing properties + * + */ + function get_propertie() + { + if ( $this->id == 0 ) return; - $Res=ExecSql($this->db,"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type, + $Res=ExecSql($this->db,"select jrn_Def_id,jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_def_type, jrn_deb_max_line,jrn_cred_max_line,jrn_def_ech,jrn_def_ech_lib,jrn_def_code, jrn_def_fiche_deb,jrn_def_fiche_deb from jrn_Def where jrn_def_id=".$this->id); - $Count=pg_NumRows($Res); - if ( $Count == 0 ) { - echo '

Param�tres journaux non trouv�s

'; - return null; + $Count=pg_NumRows($Res); + if ( $Count == 0 ) { + echo '

Param�tres journaux non trouv�s

'; + return null; + } + return pg_fetch_array($Res,0); } - return pg_fetch_array($Res,0); -} /*! \function GetDefLine * \brief Get the number of lines of a journal @@ -637,654 +638,670 @@ function get_propertie() * \return an integer */ function GetDefLine() - { - $sql_cred='jrn_deb_max_line'; - $sql="select jrn_deb_max_line as value from jrn_def where jrn_def_id=".$this->id; - $r=ExecSql($this->db,$sql); - $Res=pg_fetch_all($r); - echo_debug('class_acc_ledger',__LINE__,$Res); - if ( sizeof($Res) == 0 ) return 1; - return $Res[0]['value']; - } - /*!\brief get the saldo of a ledger for a specific period - * \param $p_from start period - * \param $p_to end period - * \param $p_cent 1 for a centralized period otherwise 0 + { + $sql_cred='jrn_deb_max_line'; + $sql="select jrn_deb_max_line as value from jrn_def where jrn_def_id=".$this->id; + $r=ExecSql($this->db,$sql); + $Res=pg_fetch_all($r); + echo_debug('class_acc_ledger',__LINE__,$Res); + if ( sizeof($Res) == 0 ) return 1; + return $Res[0]['value']; + } + /*!\brief get the saldo of a ledger for a specific period + * \param $p_from start period + * \param $p_to end period + * \param $p_cent 1 for a centralized period otherwise 0 */ - function get_solde($p_from,$p_to,$p_cent) { - $ledger=""; - if ( $this->id != 0 && $p_cent=='off') { - $ledger=" and j_jrn_def = ".$this->id; - } + function get_solde($p_from,$p_to,$p_cent) { + $ledger=""; + if ( $this->id != 0 && $p_cent=='off') { + $ledger=" and j_jrn_def = ".$this->id; + } - if ( $this->id != 0 && $p_cent=='on') { - $ledger=" and c_jrn_def = ".$this->id; - } + if ( $this->id != 0 && $p_cent=='on') { + $ledger=" and c_jrn_def = ".$this->id; + } - // we ask for a specific ledger - if ( $p_cent == 'off') { - $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_tech_per'); - $sql='select j_montant as montant,j_debit as deb from jrnx where ' - .$periode.$ledger; - }else { - $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','c_periode'); - $sql='select c_montant as montant,c_debit as deb from centralized where ' - .$periode.$ledger; - } - $ret=ExecSql($this->db,$sql); - $array=pg_fetch_all($ret); - $deb=0.0; - $cred=0.0; - foreach ($array as $line) { + // we ask for a specific ledger + if ( $p_cent == 'off') { + $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','j_tech_per'); + $sql='select j_montant as montant,j_debit as deb from jrnx where ' + .$periode.$ledger; + }else { + $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','c_periode'); + $sql='select c_montant as montant,c_debit as deb from centralized where ' + .$periode.$ledger; + } + $ret=ExecSql($this->db,$sql); + $array=pg_fetch_all($ret); + $deb=0.0; + $cred=0.0; + foreach ($array as $line) { - if ( $line['deb']=='t' ) - $deb+=$line['montant']; - else - $cred+=$line['montant']; - } - $response=array($deb,$cred); - return $response; - } - /*! - * \brief Show a select list of the ledger you can access in - * writing, the security is taken in care but show the readable AND - * writable ledger - * \param - * \param - * \param - * - * - * \return object widget select - */ - function select_ledger() { - $user=new cl_user($this->db); - $array=$user->get_ledger(); - $idx=0; - $ret=array(); + if ( $line['deb']=='t' ) + $deb+=$line['montant']; + else + $cred+=$line['montant']; + } + $response=array($deb,$cred); + return $response; + } + /*! + * \brief Show a select list of the ledger you can access in + * writing, the security is taken in care but show the readable AND + * writable ledger + * \param + * \param + * \param + * + * + * \return object widget select + */ + function select_ledger() { + $user=new cl_user($this->db); + $array=$user->get_ledger(); + $idx=0; + $ret=array(); - foreach ( $array as $value) { - $ret[$idx]['value']=$value['jrn_def_id']; - $ret[$idx]['label']=$value['jrn_def_name']; - $idx++; - } + foreach ( $array as $value) { + $ret[$idx]['value']=$value['jrn_def_id']; + $ret[$idx]['label']=$value['jrn_def_name']; + $idx++; + } - $select=new widget("select"); - $select->name='p_jrn'; - $select->value=$ret; - $select->selected=$this->id; - return $select; - } -/*! - * \brief retrieve the jrn_def_fiche and return them into a array - * index deb, cred - * \param - * \param - * \param - * - * - * \return return an array ('deb'=> ,'cred'=>) - */ - function get_fiche_def() { - $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ". - " from jrn_def where ". - " jrn_def_id = ".$this->id; + $select=new widget("select"); + $select->name='p_jrn'; + $select->value=$ret; + $select->selected=$this->id; + return $select; + } + /*! + * \brief retrieve the jrn_def_fiche and return them into a array + * index deb, cred + * \param + * \param + * \param + * + * + * \return return an array ('deb'=> ,'cred'=>) + */ + function get_fiche_def() { + $sql="select jrn_def_fiche_deb as deb,jrn_def_fiche_cred as cred ". + " from jrn_def where ". + " jrn_def_id = ".$this->id; - $r=ExecSql($this->db,$sql); + $r=ExecSql($this->db,$sql); - $res=pg_fetch_all($r); - if ( empty($res) ) return null; + $res=pg_fetch_all($r); + if ( empty($res) ) return null; - return $res[0]; - } -/*! - * \brief retrieve the jrn_def_class_deb and return it - * - * \param - * \param - * \param - * - * - * \return return an string - */ - function get_class_def() { - $sql="select jrn_def_class_deb ". - " from jrn_def where ". - " jrn_def_id = ".$this->id; + return $res[0]; + } + /*! + * \brief retrieve the jrn_def_class_deb and return it + * + * \param + * \param + * \param + * + * + * \return return an string + */ + function get_class_def() { + $sql="select jrn_def_class_deb ". + " from jrn_def where ". + " jrn_def_id = ".$this->id; - $r=ExecSql($this->db,$sql); + $r=ExecSql($this->db,$sql); - $res=pg_fetch_all($r); + $res=pg_fetch_all($r); - if ( empty($res) ) return null; + if ( empty($res) ) return null; - return $res[0]; - } + return $res[0]; + } -/*! - * \brief show the result of the array - * \param $p_array array from the form - * \param - * \param - * - * - * \return string - */ - function show_summary($p_array) { - $this->id=$p_array['p_jrn']; - if ( empty($p_array)) return 'Aucun résultat'; - extract($p_array); - $ret=""; - $ret.=""; - $ret.=""; - $ret.=""; - $ret.='
Date : $date
Description $desc
'; - $ret.=""; - $ret.=""; - $ret.=""; - $ret.=""; - $ret.=""; - $ret.=""; - $own=new own($this->db); - $hidden=new widget('hidden'); - $ret.=$hidden->IOValue('date',$date); - $ret.=$hidden->IOValue('desc',$desc); - // For predefined operation - $ret.=$hidden->IOValue('e_comm',$desc); - $ret.=$hidden->IOValue('jrn_type',$this->get_type()); - $ret.=$hidden->IOValue('p_jrn',$this->id); - $ret.=$hidden->IOValue('nb_item',$this->nb); - if ( $this->with_concerned==true) { - $ret.=$hidden->IOValue('jrn_concerned',$jrn_concerned); - } - $ret.=dossier::hidden(); - $count=0; - for ($i=0;$i<$this->nb;$i++) { - $ret.=""; - if ( trim(${'qc_'.$i})!="") { - $oqc=new fiche($this->db); - $oqc->get_by_qcode(${'qc_'.$i},false); - $strPoste=$oqc->strAttribut(ATTR_DEF_ACCOUNT); - $ret.="'; - } - - if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) != "") { - $oposte=new Acc_Account($this->db,${'poste'.$i}); - $strPoste=$oposte->id; - $ret.="'; - } - - if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) == "") - continue; - - $ret.=""; - $ret.=""; - // CA - - if ( $own->MY_ANALYTIC!='nu') // use of AA - { - if ( ereg("^[6,7]+",$strPoste)) { - // show form - $op=new Anc_Operation($this->db); - $null=($own->MY_ANALYTIC=='op')?1:0; - $ret.=''; - $count++; - } - - } - - - - $ret.=""; - } - $ret.="
Quick Code ou "; - $ret.="Poste Montant Débit
".${'qc_'.$i}.' - '. - $oqc->strAttribut(ATTR_DEF_NAME).$hidden->IOValue('qc_'.$i,${'qc_'.$i}). - '".${"poste".$i}." - ". - $oposte->get_name().$hidden->IOValue('poste'.$i,${'poste'.$i}). - '".${"amount".$i}.$hidden->IOValue('amount'.$i,${'amount'.$i}).""; - $ret.=(isset(${"ck$i"}))?"D":"C"; - $ret.=(isset(${"ck$i"}))?$hidden->IOValue('ck'.$i,${'ck'.$i}):""; - $ret.="'; - $ret.=$op->display_form_plan(null,$null,1,$count,round(${'amount'.$i},2)); - $ret.='
"; - return $ret; - } - - /*! - * \brief Show the form to encode your operation - * \param $p_array if you correct or use a predef operation - * \param $p_readonly 1 for readonly 0 for writable - * \param - * - * - * \return a string containing the form - */ - function show_form($p_array=null,$p_readonly=0) - { - if ( $p_readonly == 1 ) - return $this->show_summary($p_array); - - if ( $p_array != null ) - extract($p_array); - - $ret=""; - // Load the javascript - $ret.=JS_SEARCH_CARD; - $ret.=JS_SEARCH_POSTE; - $ret.=JS_AJAX_FICHE; - // - $ret.=""; - $ret.= ''; - - $ret.= ''; - - $ret.= '
'; - $wDate=new widget('js_date','Date','date'); - $wDate->table=1; - $wDate->readonly=$p_readonly; - $wDate->value=(isset($date))?$date:''; - - $ret.=$wDate->IOValue(); - $ret.= '
'; - $wDescription=new widget('text',"Description",'desc'); - $wDescription->readonly=$p_readonly; - $wDescription->table=1; - $wDescription->value=(isset($desc))?$desc:''; - $ret.=$wDescription->IOValue(); - $ret.= '
'; - - // $nb_row=(isset($nb))?$nb:$this->GetDefLine(); - $nb_row=$this->nb; - $hidden=new widget('hidden','nb','nb'); - $hidden->value=$nb_row; - $ret.=$hidden->IOValue(); - $ret.=dossier::hidden(); - $ret.=$hidden->IOValue('p_jrn',$this->id); - $ret.=$hidden->IOValue('jrn_type',$this->get_type()); - $ret.=''; - $ret.=''. - ''. - ''. - ''. - ''. - ''; - - for ($i = 0 ;$i<$nb_row;$i++){ - // Quick Code - $quick_code=new widget('js_search'); - $quick_code->name='qc_'.$i; - $quick_code->value=(isset(${'qc_'.$i}))?${'qc_'.$i}:""; - $quick_code->readonly=$p_readonly; - $quick_code->extra2=$this->id; - $quick_code->extra='filter'; - $qc_span=new widget('span','','qc_'.$i.'_label'); - - // Account - $poste=new widget('js_search_poste'); - $poste->name='poste'.$i; - $poste->value=(isset(${'poste'.$i}))?${"poste".$i}:''; - $poste->readonly=$p_readonly; - $poste->extra=$this->id; - $poste->extra2=$this->get_class_def(); - - - $poste_span=new widget('span','','poste'.$i.'_label'); - - // Amount - $amount=new widget('text'); - $amount->name='amount'.$i; - $amount->value=(isset(${'amount'.$i}))?${"amount".$i}:''; - $amount->readonly=$p_readonly; - $amount->javascript=' onChange="checkTotalDirect()"'; - // D/C - $deb=new widget('checkbox'); - $deb->name='ck'.$i; - $deb->selected=(isset(${'ck'.$i}))?true:false; - $deb->readonly=$p_readonly; - $deb->javascript=' onChange="checkTotalDirect()"'; - - $ret.=''; - $ret.=''; - $ret.=''; - $ret.=''; - $ret.=''; - $ret.=''; - $ret.=''; - $ret.=''; - // If readonly == 1 then show CA - } - $ret.='
QuickcodePoste MontantDébit
'.$quick_code->IOValue().''.$qc_span->IOValue().''.$poste->IOValue().''.$poste_span->IOValue().''.$amount->IOValue().''.$deb->IOValue().'
'; - if ( isset ($this->with_concerned) && $this->with_concerned==true) { - $oRapt=new Acc_Reconciliation($this->db); - $w=$oRapt->widget(); - $w->name='jrn_concerned'; - $w->value=(isset($jrn_concerned))?$jrn_concerned:""; - $ret.="Réconciliation/rapprochements : ".$w->IOValue(); - } - return $ret; - } -/*! - * \brief verify that the operation can be saved - * \param $p_array array of data same layout that the $_POST from show_form - * - * - * \return the return value are 0 ok,1 incorrect balance, 2 date - * invalid, 3 invalid amount, 4 the card is not in the range of - * permitted card, 5 not in the user's period, 6 closed period - * - */ - function verify($p_array) - { - extract ($p_array); - $user=new cl_user($this->db); - - $tot_cred=0;$tot_deb=0; - // Check the periode and the date - if ( isDate($date) == null ) { - throw new AcException('Date invalide', 2); - } - list ($l_date_start,$l_date_end)=get_periode($this->db,$user->get_periode()); - - // Date dans la periode active - if ( cmpDate($date,$l_date_start)<0 || - cmpDate($date,$l_date_end)>0 ) - { - throw new AcException('Pas dans la periode active',5); - } - // Periode ferm� - if ( PeriodeClosed ($this->db,$user->get_periode())=='t' ) - { - return new AcException('Periode fermee',6); + /*! + * \brief show the result of the array + * \param $p_array array from the form + * \param + * \param + * + * + * \return string + */ + function show_summary($p_array) { + $this->id=$p_array['p_jrn']; + if ( empty($p_array)) return 'Aucun résultat'; + extract($p_array); + $ret=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.='
Date : $date
Description $desc
'; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $ret.=""; + $own=new own($this->db); + $hidden=new widget('hidden'); + $ret.=$hidden->IOValue('date',$date); + $ret.=$hidden->IOValue('desc',$desc); + // For predefined operation + $ret.=$hidden->IOValue('e_comm',$desc); + $ret.=$hidden->IOValue('jrn_type',$this->get_type()); + $ret.=$hidden->IOValue('p_jrn',$this->id); + $ret.=$hidden->IOValue('nb_item',$this->nb); + if ( $this->with_concerned==true) { + $ret.=$hidden->IOValue('jrn_concerned',$jrn_concerned); + } + $ret.=dossier::hidden(); + $count=0; + for ($i=0;$i<$this->nb;$i++) { + $ret.=""; + if ( trim(${'qc_'.$i})!="") { + $oqc=new fiche($this->db); + $oqc->get_by_qcode(${'qc_'.$i},false); + $strPoste=$oqc->strAttribut(ATTR_DEF_ACCOUNT); + $ret.="'; } - for ($i=0;$i<$this->nb;$i++) - { - $err=0; + if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) != "") { + $oposte=new Acc_Account($this->db,${'poste'.$i}); + $strPoste=$oposte->id; + $ret.="'; + } - // Check the balance - if ( ! isset (${'amount'.$i})) - continue; + if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) == "") + continue; - if ( isNumber(${'amount'.$i} ) == 0 ) - throw new AcException('Montant invalide',3); + $ret.=""; + $ret.=""; + // CA - $amount=round(${'amount'.$i},2); - $tot_deb+=(isset(${'ck'.$i}))?$amount:0; - $tot_cred+=(! isset(${'ck'.$i}))?$amount:0; - - // Check if the card is permitted - if ( isset (${'qc_'.$i}) && trim(${'qc_'.$i}) !="") { - $f=new fiche($this->db); - $f->quick_code=${'qc_'.$i}; - - if ( $f->belong_ledger($p_jrn) < 0 ) - throw new AcException("La fiche quick_code = ". - $f->quick_code." n\'est pas dans ce journal",4); - } - - // Check if the account is permitted - if ( isset (${'poste'.$i})) { - $p=new Acc_Account($this->db,${'poste'.$i}); - if ( $p->belong_ledger ($p_jrn) < 0 ) - throw new AcException("Le poste ".$p->id." n\'est pas dans ce journal",5); - } - - - } - if ( $tot_deb != $tot_cred ) - throw new AcException("Balance incorrecte debit = $tot_deb credit=$tot_cred ",1); - - } -/*! - * \brief - * - * \param $p_grpt id in jr_grpt_ - * - * \return string internal_code - * - - * - */ -function compute_internal_code($p_grpt) -{ -if ( $this->id==0) return; - $num = NextSequence($this->db,'s_internal'); - $num=strtoupper(hexdec($num)); - $atype=$this->get_propertie(); - $type=$atype['jrn_def_code']; - $internal_code=sprintf("%d%s-%s",dossier::id(),$type,$num); - echo_debug (__FILE__,__LINE__,"internal_code = $internal_code"); - return $internal_code; -} - - /*! - * \brief save the operation into the jrnx,jrn, , - * CA and pre_def - * \param $p_array - * - * \return array with [0] = false if failed otherwise true, [1] error - * code - */ - function save ($p_array) { - extract ($p_array); - try { - $this->verify($p_array); - - StartSql($this->db) ; - - $seq=NextSequence($this->db,'s_grpt'); - $internal=$this->compute_internal_code($seq); - - $group=NextSequence($this->db,"s_oa_group"); - $own=new own($this->db); - $tot_amount=0; - - $count=0; - for ($i=0;$i<$this->nb;$i++) - { - if ( ! isset (${'qc_'.$i}) && ! isset(${'poste'.$i})) - continue; - $acc_op=new Acc_Operation($this->db); - $quick_code=""; - // First we save the jrnx - if ( isset(${'qc_'.$i})) { - $qc=new fiche($this->db); - $qc->get_by_qcode(${'qc_'.$i},false); - $poste=$qc->strAttribut(ATTR_DEF_ACCOUNT); - $quick_code=${'qc_'.$i}; - } - else { - $poste=${'poste'.$i}; - } - $acc_op->date=$date; - $acc_op->desc=$desc; - $acc_op->amount=round(${'amount'.$i},2); - $acc_op->grpt=$seq; - $acc_op->poste=$poste; - $acc_op->jrn=$this->id; - $acc_op->type=(isset (${'ck'.$i}))?'d':'c'; - $acc_op->qcode=$quick_code; - $j_id=$acc_op->insert_jrnx(); - $tot_amount+=round($acc_op->amount,2); + if ( $own->MY_ANALYTIC!='nu') // use of AA + { + if ( ereg("^[6,7]+",$strPoste)) { + // show form + $op=new Anc_Operation($this->db); + $null=($own->MY_ANALYTIC=='op')?1:0; + $ret.=''; + $count++; + } - if ( $own->MY_ANALYTIC != "nu" ) - { - if ( ereg("^[6,7]+",$poste)) { - - // for each item, insert into operation_analytique */ - $op=new Anc_Operation($this->db); - $op->oa_group=$group; - $op->j_id=$j_id; - $op->oa_date=$date; - $op->oa_debit=($acc_op->type=='d' )?'t':'f'; - $op->oa_description=$desc; - $op->save_form_plan($p_array,$count); - $count++; - } - } - } - $acc_end=new Acc_Operation($this->db); - $acc_end->date=$date; - $acc_end->desc=$desc; - $acc_end->grpt=$seq; - $acc_end->jrn=$this->id; - $jr_id= $acc_end->insert_jrn(); - if ($jr_id == false ) - throw new Exception('Balance incorrecte'); + } - ExecSql($this->db,"update jrn set jr_internal='".$internal."' where ". - " jr_grpt_id = ".$seq); - // Save now the predef op - //------------------------ - if ( isset($save_opd)) { - $opd=new Pre_Op_Advanced($this->db); - $opd->name=(trim($desc)=='')?$internal:$desc; - $opd->get_post(); - $opd->save(); - } - if ( isset($this->with_concerned) && $this->with_concerned==true) { - $orap=new acc_reconciliation($this->db); - $orap->jr_id=$jr_id; - $orap->insert($jrn_concerned); - } + $ret.=""; + } + $ret.="
Quick Code ou "; + $ret.="Poste Montant Débit
".${'qc_'.$i}.' - '. + $oqc->strAttribut(ATTR_DEF_NAME).$hidden->IOValue('qc_'.$i,${'qc_'.$i}). + '".${"poste".$i}." - ". + $oposte->get_name().$hidden->IOValue('poste'.$i,${'poste'.$i}). + '".${"amount".$i}.$hidden->IOValue('amount'.$i,${'amount'.$i}).""; + $ret.=(isset(${"ck$i"}))?"D":"C"; + $ret.=(isset(${"ck$i"}))?$hidden->IOValue('ck'.$i,${'ck'.$i}):""; + $ret.="'; + $ret.=$op->display_form_plan(null,$null,1,$count,round(${'amount'.$i},2)); + $ret.='
"; + return $ret; + } + + /*! + * \brief Show the form to encode your operation + * \param $p_array if you correct or use a predef operation + * \param $p_readonly 1 for readonly 0 for writable + * \param + * + * + * \return a string containing the form + */ + function show_form($p_array=null,$p_readonly=0) + { + if ( $p_readonly == 1 ) + return $this->show_summary($p_array); - } + if ( $p_array != null ) + extract($p_array); - catch (AcException $a) { - throw $a; - } - catch (Exception $e) { - Rollback($this->db); - echo 'OPERATION ANNULEE '; - echo '
'; - echo __FILE__.__LINE__.$e->getMessage(); - exit(); - } - Commit($this->db); - return true; - } + $ret=""; + // Load the javascript + $ret.=JS_SEARCH_CARD; + $ret.=JS_SEARCH_POSTE; + $ret.=JS_AJAX_FICHE; + // + $ret.=""; + $ret.= ''; - } - /*! - * \brief this function is intended to test this class - * \param - * \param - * \param - * - * - * \return - */ - static function test_me() - { - echo Acc_Reconciliation::$javascript; - html_page_start(); - $cn=DbConnect(dossier::id()); - $_SESSION['g_user']='phpcompta'; - $_SESSION['g_pass']='phpcompta'; + $ret.= ''; - $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1; - $a=new Acc_Ledger($cn,$id); - $a->with_concerned=true; - // Vide - echo ''; - echo $a->select_ledger()->IOValue(); - echo widget::submit_button('go','Test it'); - echo ''; - if ( isset($_POST['go'])) { - echo "Ok "; - echo ''; - echo $a->show_form(); - echo widget::submit_button('post_id','Try me'); - echo ''; - // Show the predef operation - // Don't forget the p_jrn - echo ''; - echo dossier::hidden(); - echo ''; - $op=new Pre_operation($cn); - $op->p_jrn=$id; - $op->od_direct='t'; - if ($op->count() != 0 ) - echo widget::submit_button('use_opd','Utilisez une op.prédéfinie'); - echo $op->show_button(); - echo ''; - exit(); - } - - if ( isset($_POST['post_id' ])) { - echo ''; - echo $a->show_form($_POST,1); - echo widget::submit_button('save_it',"Sauver"); - echo ''; - exit(); - } - if ( isset($_POST['save_it' ])) { - print 'saving'; - $array=$_POST; - $array['save_opd']=1; - try { - $a->save($array); - } catch (AcException $e) { - echo '"; - echo ''; + $ret.= '
'; + $wDate=new widget('js_date','Date','date'); + $wDate->table=1; + $wDate->readonly=$p_readonly; + $wDate->value=(isset($date))?$date:''; - /*! - * \brief get all the data from request and build the object - * \param - * \param - * \param - * - * - * \return - */ - function get_request() - { - $this->id=$_REQUEST['p_jrn']; + $ret.=$wDate->IOValue(); + $ret.= '
'; + $wDescription=new widget('text',"Description",'desc'); + $wDescription->readonly=$p_readonly; + $wDescription->table=1; + $wDescription->value=(isset($desc))?$desc:''; + $ret.=$wDescription->IOValue(); + $ret.= '
'; - echo $a->show_form($_POST); - echo widget::submit_button('post_id','Try me'); - echo ''; - - } - exit(); - } - // The GET at the end because automatically repost when you don't - // specify the url in the METHOD field - if ( isset ($_GET['use_opd'])) { - $op=new Pre_op_advanced($cn); - $op->set_od_id($_REQUEST['pre_def']); - //$op->p_jrn=$id; + // $nb_row=(isset($nb))?$nb:$this->GetDefLine(); + $nb_row=$this->nb; + $hidden=new widget('hidden','nb','nb'); + $hidden->value=$nb_row; + $ret.=$hidden->IOValue(); + $ret.=dossier::hidden(); + $ret.=$hidden->IOValue('p_jrn',$this->id); + $ret.=$hidden->IOValue('jrn_type',$this->get_type()); + $ret.=''; + $ret.=''. + ''. + ''. + ''. + ''. + ''; - $p_post=$op->compute_array(); + for ($i = 0 ;$i<$nb_row;$i++){ + // Quick Code + $quick_code=new widget('js_search'); + $quick_code->name='qc_'.$i; + $quick_code->value=(isset(${'qc_'.$i}))?${'qc_'.$i}:""; + $quick_code->readonly=$p_readonly; + $quick_code->extra2=$this->id; + $quick_code->extra='filter'; + $qc_span=new widget('span','','qc_'.$i.'_label'); - echo ''; + // Account + $poste=new widget('js_search_poste'); + $poste->name='poste'.$i; + $poste->value=(isset(${'poste'.$i}))?${"poste".$i}:''; + $poste->readonly=$p_readonly; + $poste->extra=$this->id; + $poste->extra2=$this->get_class_def(); - echo $a->show_form($p_post); - echo widget::submit_button('post_id','Use predefined operation'); - echo ''; - exit(); - } + $poste_span=new widget('span','','poste'.$i.'_label'); - } + // Amount + $amount=new widget('text'); + $amount->name='amount'.$i; + $amount->value=(isset(${'amount'.$i}))?${"amount".$i}:''; + $amount->readonly=$p_readonly; + $amount->javascript=' onChange="checkTotalDirect()"'; + // D/C + $deb=new widget('checkbox'); + $deb->name='ck'.$i; + $deb->selected=(isset(${'ck'.$i}))?true:false; + $deb->readonly=$p_readonly; + $deb->javascript=' onChange="checkTotalDirect()"'; -/*! - * \brief retrieve the next number for this type of ledger - * \param p_cn connx - * \param p_type ledger type - * - * \return the number - * - * \todo this function show be a part of the acc_ledger_type class - * as soon as this class is created - * - */ -static function next_number($p_cn,$p_type) -{ + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + $ret.=''; + // If readonly == 1 then show CA + } + $ret.='
QuickcodePoste MontantDébit
'.$quick_code->IOValue().''.$qc_span->IOValue().''.$poste->IOValue().''.$poste_span->IOValue().''.$amount->IOValue().''.$deb->IOValue().'
'; + if ( isset ($this->with_concerned) && $this->with_concerned==true) { + $oRapt=new Acc_Reconciliation($this->db); + $w=$oRapt->widget(); + $w->name='jrn_concerned'; + $w->value=(isset($jrn_concerned))?$jrn_concerned:""; + $ret.="Réconciliation/rapprochements : ".$w->IOValue(); + } + return $ret; + } + + /*!\brief + * check if the current ledger is closed + *\return 1 for yes, otherwise 0 + *\see Periode::is_closed + */ + function is_closed($p_periode) { + $per=new Periode($this->db); + $per->set_jrn($this->id); + $per->set_periode($p_periode); + $ret=$per->is_closed(); + echo_debug(__FILE__.':'.__LINE__.'- is_closed','return',$ret); + return $ret; + + } + /*! + * \brief verify that the operation can be saved + * \param $p_array array of data same layout that the $_POST from show_form + * + * + * \return the return value are 0 ok,1 incorrect balance, 2 date + * invalid, 3 invalid amount, 4 the card is not in the range of + * permitted card, 5 not in the user's period, 6 closed period + * + */ + function verify($p_array) + { + extract ($p_array); + $user=new cl_user($this->db); + $tot_cred=0;$tot_deb=0; + // Check the periode and the date + if ( isDate($date) == null ) { + throw new AcException('Date invalide', 2); + } + list ($l_date_start,$l_date_end)=get_periode($this->db,$user->get_periode()); - $Ret=CountSql($p_cn,"select * from jrn_def where jrn_def_type='".$p_type."'"); - return $Ret+1; -} + // Date dans la periode active + if ( cmpDate($date,$l_date_start)<0 || + cmpDate($date,$l_date_end)>0 ) + { + throw new AcException('Pas dans la periode active',5); + } + // Periode ferme + if ( $this->is_closed($user->get_periode())==1 ) + { + echo_debug(__FILE__.':'.__LINE__.'- verify',' the periode is closed '); + throw new AcException('Periode fermee',6); + } + + for ($i=0;$i<$this->nb;$i++) + { + $err=0; + + // Check the balance + if ( ! isset (${'amount'.$i})) + continue; + + if ( isNumber(${'amount'.$i} ) == 0 ) + throw new AcException('Montant invalide',3); + + $amount=round(${'amount'.$i},2); + $tot_deb+=(isset(${'ck'.$i}))?$amount:0; + $tot_cred+=(! isset(${'ck'.$i}))?$amount:0; + + // Check if the card is permitted + if ( isset (${'qc_'.$i}) && trim(${'qc_'.$i}) !="") { + $f=new fiche($this->db); + $f->quick_code=${'qc_'.$i}; + + if ( $f->belong_ledger($p_jrn) < 0 ) + throw new AcException("La fiche quick_code = ". + $f->quick_code." n\'est pas dans ce journal",4); + } + + // Check if the account is permitted + if ( isset (${'poste'.$i})) { + $p=new Acc_Account($this->db,${'poste'.$i}); + if ( $p->belong_ledger ($p_jrn) < 0 ) + throw new AcException("Le poste ".$p->id." n\'est pas dans ce journal",5); + } + + + } + if ( $tot_deb != $tot_cred ) + throw new AcException("Balance incorrecte debit = $tot_deb credit=$tot_cred ",1); + + } + /*! + * \brief + * + * \param $p_grpt id in jr_grpt_ + * + * \return string internal_code + * - + * + */ + function compute_internal_code($p_grpt) + { + if ( $this->id==0) return; + $num = NextSequence($this->db,'s_internal'); + $num=strtoupper(hexdec($num)); + $atype=$this->get_propertie(); + $type=$atype['jrn_def_code']; + $internal_code=sprintf("%d%s-%s",dossier::id(),$type,$num); + echo_debug (__FILE__,__LINE__,"internal_code = $internal_code"); + return $internal_code; + } + + /*! + * \brief save the operation into the jrnx,jrn, , + * CA and pre_def + * \param $p_array + * + * \return array with [0] = false if failed otherwise true, [1] error + * code + */ + function save ($p_array) { + extract ($p_array); + try { + $this->verify($p_array); + + StartSql($this->db) ; + + $seq=NextSequence($this->db,'s_grpt'); + $internal=$this->compute_internal_code($seq); + + $group=NextSequence($this->db,"s_oa_group"); + $own=new own($this->db); + $tot_amount=0; + + $count=0; + for ($i=0;$i<$this->nb;$i++) + { + if ( ! isset (${'qc_'.$i}) && ! isset(${'poste'.$i})) + continue; + $acc_op=new Acc_Operation($this->db); + $quick_code=""; + // First we save the jrnx + if ( isset(${'qc_'.$i})) { + $qc=new fiche($this->db); + $qc->get_by_qcode(${'qc_'.$i},false); + $poste=$qc->strAttribut(ATTR_DEF_ACCOUNT); + $quick_code=${'qc_'.$i}; + } + else { + $poste=${'poste'.$i}; + } + $acc_op->date=$date; + $acc_op->desc=$desc; + $acc_op->amount=round(${'amount'.$i},2); + $acc_op->grpt=$seq; + $acc_op->poste=$poste; + $acc_op->jrn=$this->id; + $acc_op->type=(isset (${'ck'.$i}))?'d':'c'; + $acc_op->qcode=$quick_code; + $j_id=$acc_op->insert_jrnx(); + $tot_amount+=round($acc_op->amount,2); + + if ( $own->MY_ANALYTIC != "nu" ) + { + if ( ereg("^[6,7]+",$poste)) { + + // for each item, insert into operation_analytique */ + $op=new Anc_Operation($this->db); + $op->oa_group=$group; + $op->j_id=$j_id; + $op->oa_date=$date; + $op->oa_debit=($acc_op->type=='d' )?'t':'f'; + $op->oa_description=$desc; + $op->save_form_plan($p_array,$count); + $count++; + } + } + } + $acc_end=new Acc_Operation($this->db); + $acc_end->date=$date; + $acc_end->desc=$desc; + $acc_end->grpt=$seq; + $acc_end->jrn=$this->id; + $jr_id= $acc_end->insert_jrn(); + if ($jr_id == false ) + throw new Exception('Balance incorrecte'); + + ExecSql($this->db,"update jrn set jr_internal='".$internal."' where ". + " jr_grpt_id = ".$seq); + + // Save now the predef op + //------------------------ + if ( isset($save_opd)) { + $opd=new Pre_Op_Advanced($this->db); + $opd->name=(trim($desc)=='')?$internal:$desc; + $opd->get_post(); + $opd->save(); + } + + if ( isset($this->with_concerned) && $this->with_concerned==true) { + $orap=new acc_reconciliation($this->db); + $orap->jr_id=$jr_id; + $orap->insert($jrn_concerned); + } + + } + + catch (AcException $a) { + throw $a; + } + catch (Exception $e) { + Rollback($this->db); + echo 'OPERATION ANNULEE '; + echo '
'; + echo __FILE__.__LINE__.$e->getMessage(); + exit(); + } + Commit($this->db); + return true; + } + + /*! + * \brief get all the data from request and build the object + * \param + * \param + * \param + * + * + * \return + */ + function get_request() + { + $this->id=$_REQUEST['p_jrn']; + + } + + /*! + * \brief retrieve the next number for this type of ledger + * \param p_cn connx + * \param p_type ledger type + * + * \return the number + * + * \todo this function show be a part of the acc_ledger_type class + * as soon as this class is created + * + */ + static function next_number($p_cn,$p_type) + { + + $Ret=CountSql($p_cn,"select * from jrn_def where jrn_def_type='".$p_type."'"); + return $Ret+1; + } + /*! + * \brief this function is intended to test this class + * \param + * \param + * \param + * + * + * \return + */ + static function test_me() + { + echo Acc_Reconciliation::$javascript; + html_page_start(); + $cn=DbConnect(dossier::id()); + $_SESSION['g_user']='phpcompta'; + $_SESSION['g_pass']='phpcompta'; + + $id=(isset ($_REQUEST['p_jrn']))?$_REQUEST['p_jrn']:-1; + $a=new Acc_Ledger($cn,$id); + $a->with_concerned=true; + // Vide + echo '
'; + echo $a->select_ledger()->IOValue(); + echo widget::submit_button('go','Test it'); + echo '
'; + if ( isset($_POST['go'])) { + echo "Ok "; + echo '
'; + echo $a->show_form(); + echo widget::submit_button('post_id','Try me'); + echo '
'; + // Show the predef operation + // Don't forget the p_jrn + echo '
'; + echo dossier::hidden(); + echo ''; + $op=new Pre_operation($cn); + $op->p_jrn=$id; + $op->od_direct='t'; + if ($op->count() != 0 ) + echo widget::submit_button('use_opd','Utilisez une op.prédéfinie'); + echo $op->show_button(); + echo '
'; + exit(); + } + + if ( isset($_POST['post_id' ])) { + echo '
'; + echo $a->show_form($_POST,1); + echo widget::submit_button('save_it',"Sauver"); + echo '
'; + exit(); + } + if ( isset($_POST['save_it' ])) { + print 'saving'; + $array=$_POST; + $array['save_opd']=1; + try { + $a->save($array); + } catch (AcException $e) { + echo '"; + echo '
'; + + echo $a->show_form($_POST); + echo widget::submit_button('post_id','Try me'); + echo '
'; + + } + exit(); + } + // The GET at the end because automatically repost when you don't + // specify the url in the METHOD field + if ( isset ($_GET['use_opd'])) { + $op=new Pre_op_advanced($cn); + $op->set_od_id($_REQUEST['pre_def']); + //$op->p_jrn=$id; + + $p_post=$op->compute_array(); + + echo '
'; + + echo $a->show_form($p_post); + echo widget::submit_button('post_id','Use predefined operation'); + echo '
'; + exit(); + + } + + } + } diff --git a/include/class_anc_group.php b/include/class_anc_group.php index de0d55dd0..b208372e7 100644 --- a/include/class_anc_group.php +++ b/include/class_anc_group.php @@ -46,6 +46,7 @@ class Anc_Group { } /*! * \brief insert into the database an object + * \return message with error otherwise an empty string */ function insert() { @@ -56,9 +57,9 @@ class Anc_Group { try { ExecSql($this->db,$sql); } catch (Exception $a) { - echo 'Doublon !!'; + return 'Doublon !!'; } - + return ""; } /*! * \brief remove from the database diff --git a/include/class_bud_card.php b/include/class_bud_card.php index c984d6f12..26a94de53 100644 --- a/include/class_bud_card.php +++ b/include/class_bud_card.php @@ -45,6 +45,9 @@ class Bud_Card { $this->bc_id=$id; $this->db=$p_cn; } + /*!\brief insert a record into the table bud_card + *\return return the string Sauve or throw an exception + */ function add () { if ( isNumber($this->bc_price_unit) == false ) $this->bc_price_unit=0; @@ -72,6 +75,9 @@ class Bud_Card { return 'Sauve'; } + /*!\brief update the table bud_card + *\return return the string Sauve or throw an exception + */ function update() { if ( $this->bc_id == 0) return; @@ -113,11 +119,20 @@ class Bud_Card { /* if ( $this->bc_id == null ) */ /* throw new Exception(__FILE__.":".__LINE__." bc ne peut pas etre nul"); */ } + + /*!\brief delete from bud_card the bc_id must be set + * + *\return Efface + */ function delete() { ExecSql($this->db,"delete from bud_card where bc_id=".$this->bc_id); return 'Efface'; } + /*!\brief load a bud_card from the database + * + * + */ function load() { if ( $this->bc_id == 0 ) return ; @@ -133,6 +148,11 @@ class Bud_Card { $this->get_from_array($a); } + /*!\brief return a list of all the record of all the budcard + *\param $p_cn connection + *\param $p_bh_id the hypothese id + *\return an array of Bud_Card objects + */ static function get_list($p_cn,$p_bh_id) { $sql="select * from bud_card where bh_id = $p_bh_id"; $r=ExecSql($p_cn,$sql); @@ -150,6 +170,11 @@ class Bud_Card { } return $result; } + + /*!\brief return a string with the form + * + *\return string + */ function form() { $wCode=new widget("text","Code","bc_code",$this->bc_code); diff --git a/include/class_periode.php b/include/class_periode.php new file mode 100644 index 000000000..db614b077 --- /dev/null +++ b/include/class_periode.php @@ -0,0 +1,238 @@ +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'].'CentraliséeFermée'; + $closed.=' Cloturer'; + $closed.='
'; + + } + } + static function test_me() { + $cn=DbConnect(dossier::id()); + $obj=new Periode($cn); + $obj->set_jrn(1); + $obj->display_form_periode(); + } +} diff --git a/include/class_user.php b/include/class_user.php index 64c3982a7..aa432bb11 100644 --- a/include/class_user.php +++ b/include/class_user.php @@ -165,6 +165,20 @@ jrn_def_name,jrn_def_class_deb,jrn_def_class_cred,jrn_type_id,jrn_desc,uj_priv, $array=pg_fetch_all($res); return $array; } + + /*!\brief return an sql condition for filtering the permitted ledger + * + *\return string + */ + function get_ledger_sql() { + $aLedger=$this->get_ledger(); + $sql=" jrn_def_id in ("; + foreach ($aLedger as $row) { + $sql.=$row['jrn_def_id'].','; + } + $sql.='-1)'; + return $sql; + } /*! ************************************************** * \brief Check if an user is an admin diff --git a/include/constant.php b/include/constant.php index 2a8e06f77..9aac33569 100644 --- a/include/constant.php +++ b/include/constant.php @@ -72,6 +72,7 @@ define("CLIENT",22); // Module Client define("SUPPL",24); // Module Fournisseur define("ADMIN",26); // Module Administration define("SEC_GESTION",30); // Module Gestion +define ('BUDGET',60); define ("FICHE_WRITE",15); define ("STOCK_WRITE",17); @@ -240,11 +241,12 @@ define ("JS_PROTOTYPE_JS",' + Un paramètre manque'; + } + else { + if ( $_POST['p_ech'] == 'no' ) { + $p_ech='false'; + $p_ech_lib='null'; + } else { + $p_ech='true'; + $p_ech_lib="'".$_POST['p_ech_lib']."'"; + } + + if ( strlen(trim($_POST['p_jrn_deb_max_line'])) == 0 || + (string) (int)$_POST['p_jrn_deb_max_line'] != (string)$_POST['p_jrn_deb_max_line'] || + $_POST['p_jrn_deb_max_line'] <= 0 + ) + $l_deb_max_line=1; + else + $l_deb_max_line=$_POST['p_jrn_deb_max_line']; + + $l_cred_max_line=$l_deb_max_line; + + $p_jrn_name=$_POST['p_jrn_name']; + if (strlen(trim($p_jrn_name))==0) return; + $p_jrn_name=FormatString($p_jrn_name); + $p_jrn_fiche_deb=""; + $p_jrn_fiche_cred=""; + + if ( isset ($_POST["FICHEDEB"])) { + $p_jrn_fiche_deb=join(",",$_POST["FICHEDEB"]); + } + if ( isset ($_POST["FICHECRED"])) { + $p_jrn_fiche_cred=join(",",$_POST["FICHECRED"]); + } + $Sql=sprintf("update jrn_def set jrn_def_name='%s',jrn_def_class_deb='%s',jrn_def_class_cred='%s', + jrn_deb_max_line=%s,jrn_cred_max_line=%s,jrn_def_ech=%s,jrn_def_ech_lib=%s,jrn_def_fiche_deb='%s', + jrn_def_fiche_cred='%s' + where jrn_def_id=%s", + $p_jrn_name,$_POST['p_jrn_class_deb'],$_POST['p_jrn_class_deb'], + $l_deb_max_line,$l_cred_max_line, + $p_ech,$p_ech_lib, + $p_jrn_fiche_deb,$p_jrn_fiche_cred, + $_GET['p_jrn'] + ); + echo_debug($Sql); + $Res=ExecSql($cn,$Sql); + } +} +echo ''; +?> + + +"; +echo '
'; +echo '

'.$l_line['jrn_def_name'].'

'; +echo '
'; +echo widget::hidden('p_jrn',$_GET['p_jrn']); +echo widget::hidden('p_action','jrn'); +echo widget::hidden('sa','detail'); + +echo dossier::hidden(); +echo ''; +echo ''; + +echo ''; +echo ''; +echo ''; +echo ''; + +echo ''; +echo ''; +echo ''; +echo ''; + +echo ''; +echo ''; +echo ''; +echo ''; + +/*echo ''; +echo ''; +echo ''; +echo ''; +*/ + +echo ''; +echo ''; +if ( $l_line['jrn_def_ech'] == 't' ) { + echo ''; +} +if ( $l_line['jrn_def_ech'] == 'f' ) { + echo ''; +} +echo ''; + +echo ''; +echo ''; +echo ''; +echo ''; + +echo ''; +echo ''; +echo ''; +echo ''; +echo ""; + + +?> + +'; +// Get all the fiches +echo '

Fiches

'; +$Res=ExecSql($cn,"select fd_id,fd_label from fiche_def order by fd_label"); +$num=pg_NumRows($Res); + +$rdeb=split(',',$l_line['jrn_def_fiche_deb']); + +$rcred=split(',',$l_line['jrn_def_fiche_cred']); +echo '
Nom journal
Postes utilisables journal (débit/crédit) '.$search.'
Nombre de lignes par défaut
Postes utilisables journal (crédit) '.$search.'
Date d\'échéance Oui'; + echo 'Non Oui'; + echo 'Non
Libellé echéance
Type de journal '; +$Res=ExecSql($cn,"select jrn_type_id,jrn_desc from jrn_type where ". + "trim(jrn_type_id)=trim('".$l_line['jrn_def_type']."')"); +$Max=pg_NumRows($Res); + +for ($i=0;$i<$Max;$i++) { + $Line=pg_fetch_array($Res,$i); + + echo_debug('jrn_detail.php',__LINE__,"jrn type !".$Line['jrn_type_id']."!,!".$l_line['jrn_def_type']."!"); + printf (' %s',$Line['jrn_desc']); +} +echo '
Code ".$l_line['jrn_def_code']."
'; +echo ''; +echo ''; +echo ''; +echo ''; +// Show the fiche in deb section +for ($i=0;$i<$num;$i++) { + $res=pg_fetch_array($Res,$i); + $CHECKED=" unchecked"; + foreach ( $rdeb as $element) { + if ( $element == $res['fd_id'] ) { + $CHECKED="CHECKED"; + break; + } + } + echo ''; + printf ('', + $res['fd_id'],$CHECKED,$res['fd_label']); + $CHECKED=" unchecked"; + foreach ( $rcred as $element) { + if ( $element == $res['fd_id'] ) { + $CHECKED="CHECKED"; + break; + } + } + + printf ('', + $res['fd_id'],$CHECKED,$res['fd_label']); + echo ''; +} + + +?> +
+
Fiches Débit Fiches Crédit
%s %s
+ + +
+ + + + +
+'; +echo "
"; +html_page_stop(); +?> diff --git a/include/param_pcmn.inc.php b/include/param_pcmn.inc.php new file mode 100644 index 000000000..d38e07bd7 --- /dev/null +++ b/include/param_pcmn.inc.php @@ -0,0 +1,205 @@ +Check(); + + +include_once ("user_menu.php"); +include_once ("check_priv.php"); + + +$cn=DbConnect($gDossier); + + +echo JS_UPDATE_PCMN; +/* Store the p_start parameter */ +if ( ! isset ( $_SESSION['g_start']) ) { + $_SESSION['g_start']=""; + +} +if ( isset ($_GET['p_start'])) { + $g_start=$_GET['p_start']; + $_SESSION["g_start"]=$g_start; + +} + +echo '
'; + +echo '
'; +$User->can_request($cn,MPCMN); + + +echo ''; +echo '
'; +/* Analyse ce qui est demandé */ +/* Effacement d'une ligne */ +if (isset ($_GET['action'])) { +//----------------------------------------------------- +// Action == remove a line + if ( $_GET['action']=="del" ) { + if ( isset ($_GET['l']) ) { + /* Ligne a enfant*/ + $R=ExecSql($cn,"select pcm_val from tmp_pcmn where pcm_val_parent=".$_GET['l']); + if ( pg_NumRows($R) != 0 ) { + echo ""; + } else { + /* Vérifier que le poste n'est pas utilisé qq part dans les journaux */ + $Res=ExecSql($cn,"select * from jrnx where j_poste=".$_GET['l']); + if ( pg_NumRows($R) != 0 ) { + echo ""; + } + else { + $Del=ExecSql($cn,"delete from tmp_pcmn where pcm_val=".$_GET['l']); + } // if pg_NumRows + } // if pg_NumRows + } // isset ($l) + } //$action == del +} // isset action +//----------------------------------------------------- +/* Ajout d'une ligne */ +if ( isset ( $_POST["Add"] ) ) { + extract ($_POST); + $p_val=trim($p_val); + $p_parent=trim($p_parent); + if ( isset ( $p_val) && isset ( $p_lib ) && isNumber($p_val) && isNumber($p_parent) ) { + $p_val=trim($p_val); + $p_lib=FormatString(trim($p_lib)); + $p_parent=$_POST["p_parent"]; + if ( strlen ($p_val) != 0 && strlen ($p_lib) != 0 ) { + if (strlen ($p_val) == 1 ) { + $p_parent=0; + } else { + if ( strlen(trim($p_parent))==0 && + (string) $p_parent != (string)(int) $p_parent) { + $p_parent=substr($p_val,0,strlen($p_val)-1); + } + echo_debug('pcmn_update.php',__LINE__,"Ajout valeur = $p_val parent = $p_parent"); + } + /* Parent existe */ + $Ret=ExecSql($cn,"select pcm_val from tmp_pcmn where pcm_val=$p_parent"); + if ( pg_NumRows($Ret) == 0 ) { + echo ''; + } else { + // Check if the account already exists + + $Count=CountSql($cn,"select * from tmp_pcmn where pcm_val='".$p_val."'"); + if ( $Count != 0 ) + { + // Alert message account already exists + echo ''; + + } else + { + $Ret=ExecSql($cn,"insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent) values ('$p_val','$p_lib',$p_parent)"); + } + } + } else { + echo '

Valeurs invalides

'; + } + } +} + +$Ret=ExecSql($cn,"select pcm_val,pcm_lib,pcm_val_parent from tmp_pcmn where substr(pcm_val::text,1,1)='".$_SESSION['g_start']."' order by pcm_val::text"); +$MaxRow=pg_NumRows($Ret); + +?> + +
+ + + + + + + + + + + + + +'; + } else { + $td=' $td"; + echo $A['pcm_val']; + + echo " $td"; + // printf ("",$A['pcm_val'],urlencode($A['pcm_lib']),$A['pcm_val_parent']); + printf ("", + $A['pcm_val'], + FormatString($A['pcm_lib']), + $A['pcm_val_parent'], + $_REQUEST['PHPSESSID'], + dossier::id()); + echo $A['pcm_lib']; + echo ''; + echo ""; + + echo $td; + echo $A['pcm_val_parent']; + echo ''; + + echo $td; + printf ('Delete',$A['pcm_val'],$str_dossier); + echo ""; + + echo ""; +} +echo "
Classe Libellé Parent
+ + + + + + + +
'; + } + echo "
"; +echo "
"; +echo "
"; +html_page_stop(); +?> diff --git a/include/param_sec.inc.php b/include/param_sec.inc.php new file mode 100644 index 000000000..9253f9b3c --- /dev/null +++ b/include/param_sec.inc.php @@ -0,0 +1,275 @@ +Check(); + +include_once ("user_menu.php"); + +$cn_dossier=DbConnect($gDossier); + +if ( $User->check_action($cn_dossier,GJRN) == 0 ) { + /* Cannot Access */ + NoAccess(); + exit -1; + } + +$cn=DbConnect(); +$User=ExecSql($cn,"select use_id,use_first_name,use_name,use_login from ac_users natural join jnt_use_dos where use_login != 'phpcompta' and dos_id=".$gDossier); +$MaxUser=pg_NumRows($User); + + +echo '
'; + +echo ''; +for ($i = 0;$i < $MaxUser;$i++) { + $l_line=pg_fetch_array($User,$i); + // echo ''; + if ( $i % 3 == 0 && $i != 0) + echo ""; + + printf ('', + $l_line['use_id'], + $l_line['use_first_name'], + $l_line['use_name'], + $l_line['use_login'] ); + +} +echo ""; +echo '
%s %s ( %s )
'; +$action=""; + +if ( isset ($_GET["action"] )) { + $action=$_GET["action"]; + +} + +// session_register set to off, so variable are undefined +foreach ($_GET as $name=>$value) + ${"$name"}=$value; + +if ( $action == "change_jrn" ) { + // Check if the user can access that folder + if ( CheckDossier($_GET['login'],$gDossier) == 0 ) { + echo "

Cet utilisateur ne peut pas accéder ce dossier

"; + $action=""; + return; + } + $login=$_GET['login']; + $jrn=$_GET['jrn']; + $access=$_GET['access']; + $l_Db=sprintf("dossier%d",$gDossier); + echo_debug('user_sec.php',__LINE__,"select * from user_sec_jrn where uj_login='$login' and uj_jrn_id=$jrn"); + $cn_dossier=DbConnect($gDossier); + $l2_Res=ExecSql($cn_dossier, + "select * from user_sec_jrn where uj_login='$login' and uj_jrn_id=$jrn"); + $l2_count=pg_NumRows($l2_Res); + if ( $l2_count == 1 ) { + $Res=ExecSql($cn_dossier,"update user_sec_jrn set uj_priv='$access' where uj_login='$login' and uj_jrn_id=$jrn"); + } else { + $Res=ExecSql($cn_dossier,"insert into user_sec_jrn(uj_login,uj_jrn_id,uj_priv) values( '$login' ,$jrn,'$access')"); + } + + $action="view"; +} +if ( $action == "change_act" ) { + // Check if the user can access that folder + if ( CheckDossier($_GET['login'],$gDossier) == 0 ) { + echo "

he cannot access this folder

"; + $action=""; + return; + } + $l_Db=sprintf("dossier%d",$gDossier); + $cn_dossier=DbConnect($gDossier); + if ( $_GET['access']==0) { + echo_debug('user_sec.php',__LINE__,"delete right"); + $Res=ExecSql($cn_dossier, + "delete from user_sec_act where ua_login='".$_GET['login']."' and ua_act_id=$act"); + } else { + echo_debug('user_sec.php',__LINE__,"insert right"); + if ( CountSql($cn_dossier,"select * from user_sec_act where ua_login='$login' and ua_act_id=$act") < 1 ) + { + $Res=ExecSql($cn_dossier, + "insert into user_sec_act(ua_login,ua_act_id) values( '$login' ,$act)"); + } + } + $action="view"; +} +// Action == View detail for users +if ( $action == "view" ) { + $l_Db=sprintf("dossier%d",$gDossier); + $cn_dossier=DbConnect($gDossier); + $cn=DbConnect(); + $User=ExecSql($cn, + "select use_id,use_first_name,use_name,use_login + from ac_users where use_id=".$_GET['user_id']); + $MaxUser=pg_NumRows($User); + if ( $MaxUser == 0 ) return; + $l2_line=pg_fetch_array($User,0); + + printf ('

Détail utilisateur %s %s (%s)

', + $l2_line['use_first_name'], + $l2_line['use_name'], + $l2_line['use_login']); + // Check if the user can access that folder + if ( CheckDossier($l2_line['use_login'],$gDossier) == 0 ) { + echo "

he cannot access this folder

"; + $action=""; + return; + } + // Print button + + $sHref=sprintf ('sec_pdf.php?p_action=sec&user_id=%s&'.$str_dossier , + $l2_line['use_id'] + ); + echo widget::button_href('Imprime',$sHref); + // Show access for journal + $Res=ExecSql($cn_dossier,"select jrn_def_id,jrn_def_name from jrn_def "); + $admin=CheckIsAdmin($l2_line['use_login']); + + echo ''; + $MaxJrn=pg_NumRows($Res); + for ( $i =0 ; $i < $MaxJrn; $i++ ) { + $l_line=pg_fetch_array($Res,$i); + echo ' '; + if ( $i == 0 ) echo '';else echo ""; + echo ""; + + $l_change="action=change_jrn&jrn=$l_line[jrn_def_id]&login=$l2_line[use_login]&user_id=$l2_line[use_id]"; + + if ( $admin == 0) { + $right= CheckJrn($gDossier,$l2_line['use_login'],$l_line['jrn_def_id'] ); + echo_debug('user_sec.php',__LINE__,"Privilege is $right"); + } else $right = 3; + if ( $right == 0 ) { + echo ""; + echo ''; + echo ''; + + } + if ( $right == 1 ) { + echo ''; + echo ""; + echo ''; + } + if ( $right == 2 ) { + echo ''; + echo ''; + + echo ""; + + } + if ( $right == 3 ) { + echo ''; + echo ''; + + echo ""; + + } + + + + echo ''; + } + + // Priv. for actions + $Res=ExecSql($cn_dossier, + "select ac_id, ac_description from action order by ac_id "); + + $MaxJrn=pg_NumRows($Res); + + for ( $i =0 ; $i < $MaxJrn; $i++ ) { + $l_line=pg_fetch_array($Res,$i); + echo ' '; + if ( $i == 0 ) echo ''; + if ($i != 0 && $l_line['ac_id'] != 50 && $l_line['ac_id']!=60) echo ""; + if ( $l_line['ac_id'] == 50 ) + echo ''; + + if ( $l_line['ac_id'] == 60 ) + echo ''; + + echo ""; + + $l_change="action=change_act&act=".$l_line['ac_id']."&login=".$l2_line['use_login']."&user_id=".$l2_line['use_id']; + if ( $admin ==0 ) { + $right=check_action($gDossier,$l2_line['use_login'],$l_line['ac_id']); + } else { + $right = 2; + } + if ( $right == 0 ) { + echo ""; + $l_change=$l_change."&access=1"; + echo ''; + } + if ( $right == 1) { + $l_change=$l_change."&access=0"; + echo ''; + echo ""; + + } + if ( $right == 2) { + + echo ''; + echo ""; + + } + + + echo ''; + } + + echo '
Journal $l_line[jrn_def_name] "; + echo "Pas d'accès"; + echo " Lecture Ecriture Pas d\'accès"; + echo "Lecture "; + echo " Ecriture Pas d\'accès Lecture"; + echo "Ecriture "; + echo " Pas d\'accès Lecture "; + echo "Ecriture "; + echo "
Action Compta. Analytique
Module Budget
". $l_line['ac_description']." "; + echo "Pas d'accès"; + echo " Accès Pas d\'accès "; + echo "Accès "; + echo " Change "; + echo "Accès "; + echo "
'; + echo widget::button_href('Imprime',$sHref); + +} +echo "
"; +html_page_stop(); +?> diff --git a/include/param_user.inc.php b/include/param_user.inc.php new file mode 100644 index 000000000..b411d35fc --- /dev/null +++ b/include/param_user.inc.php @@ -0,0 +1,272 @@ +Check(); + +include_once ("user_menu.php"); + +$cn_dossier=DbConnect($gDossier); + +if ( $User->check_action($cn_dossier,GJRN) == 0 ) { + /* Cannot Access */ + NoAccess(); + exit -1; + } + +$cn=DbConnect(); +$User=ExecSql($cn,"select use_id,use_first_name,use_name,use_login from ac_users natural join jnt_use_dos where use_login != 'phpcompta' and dos_id=".$gDossier); +$MaxUser=pg_NumRows($User); + + +echo '
'; + +echo ''; +for ($i = 0;$i < $MaxUser;$i++) { + $l_line=pg_fetch_array($User,$i); + // echo ''; + if ( $i % 3 == 0 && $i != 0) + echo ""; + + printf ('', + $l_line['use_id'], + $l_line['use_first_name'], + $l_line['use_name'], + $l_line['use_login'] ); + +} +echo ""; +echo '
%s %s ( %s )
'; +$action=""; + +if ( isset ($_GET["action"] )) { + $action=$_GET["action"]; + +} + +// session_register set to off, so variable are undefined +foreach ($_GET as $name=>$value) + ${"$name"}=$value; + +if ( $action == "change_jrn" ) { + // Check if the user can access that folder + if ( CheckDossier($_GET['login'],$gDossier) == 0 ) { + echo "

Cet utilisateur ne peut pas accéder ce dossier

"; + $action=""; + return; + } + $login=$_GET['login']; + $jrn=$_GET['jrn']; + $access=$_GET['access']; + $l_Db=sprintf("dossier%d",$gDossier); + echo_debug('user_sec.php',__LINE__,"select * from user_sec_jrn where uj_login='$login' and uj_jrn_id=$jrn"); + $cn_dossier=DbConnect($gDossier); + $l2_Res=ExecSql($cn_dossier, + "select * from user_sec_jrn where uj_login='$login' and uj_jrn_id=$jrn"); + $l2_count=pg_NumRows($l2_Res); + if ( $l2_count == 1 ) { + $Res=ExecSql($cn_dossier,"update user_sec_jrn set uj_priv='$access' where uj_login='$login' and uj_jrn_id=$jrn"); + } else { + $Res=ExecSql($cn_dossier,"insert into user_sec_jrn(uj_login,uj_jrn_id,uj_priv) values( '$login' ,$jrn,'$access')"); + } + + $action="view"; +} +if ( $action == "change_act" ) { + // Check if the user can access that folder + if ( CheckDossier($_GET['login'],$gDossier) == 0 ) { + echo "

he cannot access this folder

"; + $action=""; + return; + } + $l_Db=sprintf("dossier%d",$gDossier); + $cn_dossier=DbConnect($gDossier); + if ( $_GET['access']==0) { + echo_debug('user_sec.php',__LINE__,"delete right"); + $Res=ExecSql($cn_dossier, + "delete from user_sec_act where ua_login='".$_GET['login']."' and ua_act_id=$act"); + } else { + echo_debug('user_sec.php',__LINE__,"insert right"); + if ( CountSql($cn_dossier,"select * from user_sec_act where ua_login='$login' and ua_act_id=$act") < 1 ) + { + $Res=ExecSql($cn_dossier, + "insert into user_sec_act(ua_login,ua_act_id) values( '$login' ,$act)"); + } + } + $action="view"; +} +// Action == View detail for users +if ( $action == "view" ) { + $l_Db=sprintf("dossier%d",$gDossier); + $cn_dossier=DbConnect($gDossier); + $cn=DbConnect(); + $User=ExecSql($cn, + "select use_id,use_first_name,use_name,use_login + from ac_users where use_id=".$_GET['user_id']); + $MaxUser=pg_NumRows($User); + if ( $MaxUser == 0 ) return; + $l2_line=pg_fetch_array($User,0); + + printf ('

Détail utilisateur %s %s (%s)

', + $l2_line['use_first_name'], + $l2_line['use_name'], + $l2_line['use_login']); + // Check if the user can access that folder + if ( CheckDossier($l2_line['use_login'],$gDossier) == 0 ) { + echo "

he cannot access this folder

"; + $action=""; + return; + } + // Print button + + $sHref=sprintf ('sec_pdf.php?p_action=sec&user_id=%s&'.$str_dossier , + $l2_line['use_id'] + ); + echo widget::button_href('Imprime',$sHref); + // Show access for journal + $Res=ExecSql($cn_dossier,"select jrn_def_id,jrn_def_name from jrn_def "); + $admin=CheckIsAdmin($l2_line['use_login']); + + echo ''; + $MaxJrn=pg_NumRows($Res); + for ( $i =0 ; $i < $MaxJrn; $i++ ) { + $l_line=pg_fetch_array($Res,$i); + echo ' '; + if ( $i == 0 ) echo '';else echo ""; + echo ""; + + $l_change="action=change_jrn&jrn=$l_line[jrn_def_id]&login=$l2_line[use_login]&user_id=$l2_line[use_id]"; + + if ( $admin == 0) { + $right= CheckJrn($gDossier,$l2_line['use_login'],$l_line['jrn_def_id'] ); + echo_debug('user_sec.php',__LINE__,"Privilege is $right"); + } else $right = 3; + if ( $right == 0 ) { + echo ""; + echo ''; + echo ''; + + } + if ( $right == 1 ) { + echo ''; + echo ""; + echo ''; + } + if ( $right == 2 ) { + echo ''; + echo ''; + + echo ""; + + } + if ( $right == 3 ) { + echo ''; + echo ''; + + echo ""; + + } + + + + echo ''; + } + + // Priv. for actions + $Res=ExecSql($cn_dossier, + "select ac_id, ac_description from action order by ac_id "); + + $MaxJrn=pg_NumRows($Res); + + for ( $i =0 ; $i < $MaxJrn; $i++ ) { + $l_line=pg_fetch_array($Res,$i); + echo ' '; + if ( $i == 0 ) echo ''; + if ($i != 0 && $l_line['ac_id'] != 50) echo ""; + if ( $l_line['ac_id'] == 50 ) + echo ''; + + echo ""; + + $l_change="action=change_act&act=".$l_line['ac_id']."&login=".$l2_line['use_login']."&user_id=".$l2_line['use_id']; + if ( $admin ==0 ) { + $right=check_action($gDossier,$l2_line['use_login'],$l_line['ac_id']); + } else { + $right = 2; + } + if ( $right == 0 ) { + echo ""; + $l_change=$l_change."&access=1"; + echo ''; + } + if ( $right == 1) { + $l_change=$l_change."&access=0"; + echo ''; + echo ""; + + } + if ( $right == 2) { + + echo ''; + echo ""; + + } + + + echo ''; + } + + echo '
Journal $l_line[jrn_def_name] "; + echo "Pas d'accès"; + echo " Lecture Ecriture Pas d\'accès"; + echo "Lecture "; + echo " Ecriture Pas d\'accès Lecture"; + echo "Ecriture "; + echo " Pas d\'accès Lecture "; + echo "Ecriture "; + echo "
Action Compta. Analytique
". $l_line['ac_description']." "; + echo "Pas d'accès"; + echo " Accès Pas d\'accès "; + echo "Accès "; + echo " Change "; + echo "Accès "; + echo "
'; + echo widget::button_href('Imprime',$sHref); + +} +echo "
"; +html_page_stop(); +?> diff --git a/include/periode.inc.php b/include/periode.inc.php index 6b6829642..6e89f24b2 100644 --- a/include/periode.inc.php +++ b/include/periode.inc.php @@ -19,12 +19,10 @@ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr /*! \file - * \brief Still used ? - * \todo check if obsolete */ - - +require_once ('class_widget.php'); require_once("preference.php"); +require_once ('class_periode.php'); echo '
'; $cn=DbConnect($gDossier); //----------------------------------------------------- @@ -33,12 +31,13 @@ $cn=DbConnect($gDossier); $action=""; if ( isset($_REQUEST['action'])) $action=$_REQUEST['action']; - +$choose=(isset ($_GET['choose']))?$_GET['choose']:"no"; +if ($choose=='Valider') $choose='yes'; if ( $action=="change_per") { foreach($_GET as $key=>$element) ${"$key"}=$element; echo ""; - echo ''; + echo ''; echo dossier::hidden(); echo ' '; echo ''; @@ -47,11 +46,12 @@ if ( $action=="change_per") { echo ''; echo "
'; echo '
"; + // $choose="yes"; } if ( isset ($_POST["conf_chg_per"] ) ) { - foreach($_POST as $key=>$element) - ${"$key"}=$element; + extract($_POST); + if (isDate($p_date_start) == null || isDate($p_date_end) == null || strlen (trim($p_exercice)) == 0 || @@ -68,6 +68,7 @@ if ( isset ($_POST["conf_chg_per"] ) ) { " where p_id=".$p_per); + $choose="yes"; } if ( isset ($_POST["add_per"] )) { @@ -89,13 +90,19 @@ if ( isset ($_POST["add_per"] )) { $p_date_end, $p_exercice)); + $choose="yes"; } echo_debug('periode.inc',__LINE__,"Action $p_action"); if ( $action=="closed") { $p_per=$_GET['p_per']; - $Res=ExecSql($cn,"update parm_periode set p_closed=true where p_id=$p_per"); + $per=new Periode($cn); + $jrn_def_id=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0; + $per->set_jrn($jrn_def_id); + $per->set_periode($p_per); + $per->close(); + $choose="yes"; } if ( $action== "delete_per" ) { @@ -107,9 +114,29 @@ if ( $action== "delete_per" ) { { $Res=ExecSql($cn,"delete from parm_periode where p_id=$p_per"); } + $choose="yes"; } - - -ShowPeriode($cn); +if ( $choose=="yes" ) { + echo widget::button_href('Autre Journal ?','?choose=no&p_action=periode&gDossier='.dossier::id()); + $per=new Periode($cn); + $jrn=(isset($_GET['jrn_def_id']))?$_GET['jrn_def_id']:0; + $per->set_jrn($jrn); + + $per->display_form_periode(); + } else { + echo '
'; + echo dossier::hidden(); + $sel_jrn=make_array($cn,"select jrn_def_id, jrn_def_name from ". + " jrn_def order by jrn_def_name"); + $sel_jrn[]=array('value'=>0,'label'=>'Global : periode pour tous les journaux'); + $wSel=new widget("select"); + $wSel->value=$sel_jrn; + $wSel->name='jrn_def_id'; + echo "Choississez global ou uniquement le journal à fermer".$wSel->IOValue(); + echo widget::submit_button('choose','Valider'); + echo widget::hidden('p_action','periode'); + echo "
"; + echo '

Pour ajouter, effacer ou modifier une période, il faut choisir global

'; + } echo '
'; ?> diff --git a/include/preference.php b/include/preference.php index e80cd15f4..7a8209ea1 100644 --- a/include/preference.php +++ b/include/preference.php @@ -212,72 +212,5 @@ echo ' '; echo ''; echo ''; } -/*! - * \brief Show all the periode and their status - * - * \param $p_cn database connection - * - * \return nothing - * - * - */ -function ShowPeriode($p_cn) -{ - $str_dossier=dossier::get(); - // echo "

Période

"; - $Res=ExecSql($p_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 ''; - echo_debug('preference.php',__LINE__," closed : $l_line[p_closed]"); - 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 '
'; -} ?> diff --git a/include/quick_writing.inc.php b/include/quick_writing.inc.php index 6a3c5cb2f..1d2d357d0 100644 --- a/include/quick_writing.inc.php +++ b/include/quick_writing.inc.php @@ -78,6 +78,7 @@ function show_direct_form($cn,$ledger,$p_array) { } $ledger=new Acc_Ledger($cn,$id); + $ledger->with_concerned=true; // no ledger selected, propose one if ($id == -1 ) @@ -103,18 +104,23 @@ echo '
'; echo '

Journal : '.$ledger->get_name().'

'; echo widget::button_href('Autre journal','?p_action='.$_REQUEST['p_action'].'&'.dossier::get()); // User can write ? + if ( CheckJrn(dossier::id(),$_SESSION['g_user'],$id) != 2 ) { echo " "; exit -1; } - if ( isset($_GET['show_form']) || isset($_POST['correct_it']) ) { -$array=$_POST; -$default_periode=$User->get_periode(); -list($date,$devnull)=get_periode($cn,$default_periode); -$array['date']=$date; + $array=$_POST; + $default_periode=$User->get_periode(); + /* check if the ledger is closed */ + if ( $ledger->is_closed($default_periode)==1) { + echo '

Desole mais cette periode est fermee pour ce journal

'; + exit(); + } + list($date,$devnull)=get_periode($cn,$default_periode); + $array['date']=$date; show_direct_form($cn,$ledger,$array); exit(); } diff --git a/include/user_action_ach.php b/include/user_action_ach.php index 7df677df8..5b970f4cf 100644 --- a/include/user_action_ach.php +++ b/include/user_action_ach.php @@ -385,6 +385,7 @@ if ( $action == 'voir_jrn_non_paye' ) { echo $list2; echo $bar2; $hid=new widget(); + echo '
'; if ( $m != 0 ) echo $hid->Submit('paid','Mise à jour paiement'); echo ''; diff --git a/include/user_action_ods.php b/include/user_action_ods.php index 37b3a1478..61ab2445e 100644 --- a/include/user_action_ods.php +++ b/include/user_action_ods.php @@ -60,6 +60,25 @@ if ( $action=="use_opd" ) { echo '
'; echo $form; + //-------------------- + // predef op. + echo '
'; + $op=new Pre_operation($cn); + $op->p_jrn=$_GET['p_jrn']; + $op->od_direct='f'; + + $hid=new widget("hidden"); + echo $hid->IOValue("action","use_opd"); + echo dossier::hidden(); + echo $hid->IOValue("p_jrn",$_GET['p_jrn']); + echo $hid->IOValue("jrn_type","ODS"); + + if ($op->count() != 0 ) + echo widget::submit_button('use_opd','Utilisez une op.prédéfinie'); + echo $op->show_button(); + + echo '
'; + echo '
'; exit(); } diff --git a/include/user_action_ven.php b/include/user_action_ven.php index f9d2a3808..449526da6 100644 --- a/include/user_action_ven.php +++ b/include/user_action_ven.php @@ -384,7 +384,7 @@ if ( $action == 'voir_jrn_non_paye' ) { $hid->value=$jrn_type; echo $hid->IOValue(); - + echo '
'; if ( $m != 0 ) echo $hid->Submit('paid','Mise à jour paiement'); diff --git a/include/user_common.php b/include/user_common.php index 407f7c77f..1af9b7060 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -859,14 +859,6 @@ function VerifyOperationDate($p_cn,$p_periode,$p_date) { echo ""; return null; } - // Periode fermée - if ( PeriodeClosed ($p_cn,$p_periode)=='t' ) - { - $msg="This periode is closed please change your preference"; - echo_error($msg); echo_error($msg); - echo ""; - return null; - } return $p_date; } diff --git a/include/user_form_ach.php b/include/user_form_ach.php index e52bf6ada..16a167e92 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -33,6 +33,7 @@ require_once ('class_own.php'); require_once ('class_anc_operation.php'); require_once ('class_pre_op_ach.php'); require_once ('class_acc_ledger.php'); +require_once ('class_periode.php'); /*! * \brief Display the form for a sell @@ -172,11 +173,11 @@ echo_debug('user_form_ach.php',__LINE__,"Enter FormAchInput($p_cn,$p_jrn,$p_peri $r.=''; $r.=""; $r.="Code"; - $r.="Dénomination"; + $r.="Dénomination"; $r.="prix"; $r.="tva"; $r.="Montant TVA"; - $r.="quantité"; + $r.="quantité"; $r.=''; // For each article // compute amount @@ -360,7 +361,7 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) // compare hidden value and computed if ( round($ca_amount-$hidden_amount,2) != 0 ) { - $msg="Montant CA est différent total marchandise"; + $msg="Montant CA est différent total marchandise"; echo ""; @@ -436,7 +437,7 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) { if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) { - $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide,il doit être compris entre 0 et 1"; + $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide,il doit etre compris entre 0 et 1"; echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg); echo ""; return null; @@ -449,7 +450,7 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) { if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) { - $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1"; + $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit etre compris entre 0 et 1"; echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg); echo ""; return null; @@ -461,7 +462,7 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) { if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) { - $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1"; + $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit etre compris entre 0 et 1"; echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg); echo ""; return null; @@ -485,14 +486,19 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) echo ""; return null; } - // Periode fermé - if ( PeriodeClosed ($p_cn,$p_periode)=='t' ) - { - $msg="This periode is closed please change your preference"; - echo_error($msg); echo_error($msg); - echo ""; - return null; - } + // Periode ferm� + $per=new Periode($p_cn); + $per->set_jrn($p_jrn); + $per->set_periode($p_periode); + + // Periode fermé + if ( $per->is_open() == 0) + { + $msg="Cette periode est fermee pour ce journal"; + echo_error($msg); echo_error($msg); + echo ""; + return null; + } return true; } /*! @@ -572,7 +578,7 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi // show all article, price vat and sum $r.=""; $r.="Article"; - $r.="quantité"; + $r.="quantité"; $r.="prix unit."; $r.="taux tva"; $r.="Montant HTVA"; @@ -705,7 +711,7 @@ function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_pi $file->table=1; $r.="
"; $r.= ""; - if ( $p_piece) $r.="".$file->IOValue("pj","","Pièce justificative").""; + if ( $p_piece) $r.="".$file->IOValue("pj","","Pièce justificative").""; // propose to save the pre_operation if ( $p_piece ) { $chk=new widget('checkbox'); diff --git a/include/user_form_fin.php b/include/user_form_fin.php index f8d8052d3..f5f3e82fd 100644 --- a/include/user_form_fin.php +++ b/include/user_form_fin.php @@ -25,7 +25,7 @@ require_once("fiche_inc.php"); require_once("user_common.php"); require_once ('class_pre_operation.php'); require_once ('class_acc_ledger.php'); - +require_once ('class_periode.php'); /*! \file * \brief Functions for the financial ledger */ @@ -107,13 +107,16 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) return null; } // Periode ferm� - if ( PeriodeClosed ($p_cn,$p_periode)=='t' ) - { - $msg="This periode is closed please change your preference"; - echo_debug('user_form_fin.php',__LINE__,$msg); - echo ""; - return null; - } + $per=new Periode($p_cn); + $per->set_jrn($p_jrn); + $per->set_periode($p_periode); + if ( $per->is_open()==0 ) + { + $msg="Cette periode est fermee pour ce journal"; + echo_debug('user_form_fin.php',__LINE__,$msg); + echo ""; + return null; + } return true; } diff --git a/include/user_form_ods.php b/include/user_form_ods.php index 7e2e54f2e..c42143d67 100644 --- a/include/user_form_ods.php +++ b/include/user_form_ods.php @@ -30,7 +30,7 @@ require_once ('class_own.php'); require_once ('class_anc_operation.php'); require_once ('class_pre_op_ods.php'); require_once ('class_acc_ledger.php'); - +require_once ('class_periode.php'); /*! \file * \brief Functions for the ledger of misc. operation */ @@ -67,7 +67,19 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru // $e_date=( ! isset($e_date) ) ? // substr($l_date_start,2,8):$e_date; $e_date=( ! isset($e_date) ) ? $l_date_start:$e_date; - + $per=new Periode($p_cn); + $per->set_jrn($p_jrn); + $per->set_periode($p_periode); + + // Periode ferme + if ( $per->is_open()==0) + { + $msg="Cette periode est fermee pour ce journal"; + echo_error($msg); echo_error($msg); + echo ""; + return null; + } + // Verify if valid date if ( $flag==1 and VerifyOperationDate($p_cn,$p_periode,$e_date) == null) { if ( $pview_only == true) @@ -178,7 +190,7 @@ $r.="extra=$p_jrn; $W->extra2=$filter; // $r.=''.InputType("","js_search_poste","e_account".$i,$account,$pview_only,$filter); - $r.="".$W->IOValue("e_account".$i, $account); + $r.=""; //amount diff --git a/include/user_form_ven.php b/include/user_form_ven.php index 1a8371073..a5aaf882d 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -32,6 +32,8 @@ require_once ('class_anc_operation.php'); require_once ('class_pre_op_ven.php'); require_once ('class_own.php'); require_once ('class_acc_ledger.php'); +require_once ('class_periode.php'); + /*! FormVenInput * \brief Display the form for a sell * Used to show detail, encode a new invoice @@ -164,10 +166,10 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $r.=''; $r.=""; $r.=""; - $r.=""; + $r.=""; $r.=""; $r.=""; - $r.=""; + $r.=""; $r.=''; // For each article //-- @@ -332,8 +334,8 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) // compare hidden value and computed if ( round($ca_amount-$hidden_amount,2) != 0 ) { - $msg="Montant CA est différent total marchandise"; - $msg.="montant encodé $ca_amount marchandise $hidden_amount"; + $msg="Montant CA est différent total marchandise"; + $msg.="montant encodé $ca_amount marchandise $hidden_amount"; echo ""; return null; @@ -410,15 +412,20 @@ function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number) echo ""; return null; } + // Periode ferm� + $per=new Periode($p_cn); + $per->set_jrn($p_jrn); + $per->set_periode($p_periode); + // Periode ferme - if ( PeriodeClosed ($p_cn,$p_periode)=='t' ) - { - $msg="This periode is closed please change your preference"; - echo_error($msg); echo_error($msg); - echo ""; - return null; - } - return true; + if ( $per->is_open()==0) + { + $msg="Cette periode est fermee pour ce journal"; + echo_error($msg); echo_error($msg); + echo ""; + return null; + } + return true; } /*! FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='html',$p_comment='') ************************************************** @@ -499,7 +506,7 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' // show all article, price vat and sum $r.=""; $r.=""; - $r.=""; + $r.=""; $r.=""; $r.=""; $r.=""; @@ -621,7 +628,7 @@ function FormVenteView ($p_cn,$p_jrn,$p_periode,$p_array,$p_number,$p_doc='form' $file->table=1; $r.="
"; $r.= "
".$W->IOValue("e_account".$i, $account).''; //libelle $r.=" $lib
CodeDénominationDénominationprixtvaquantitéquantité
Articlequantitéquantitéprix unit.taux tvaMontant HTVA
"; - $r.="".$file->IOValue("pj","","Pièce justificative").""; + $r.="".$file->IOValue("pj","","Pièce justificative").""; $r.="
"; $r.="
"; diff --git a/include/user_menu.php b/include/user_menu.php index 22ecdc1ea..0fd38a01a 100644 --- a/include/user_menu.php +++ b/include/user_menu.php @@ -198,7 +198,7 @@ function ShowMenuCompta($p_high="") $r.='
'; $r.=' - + @@ -550,11 +550,11 @@ function ShowMenuAdvanced($default="") { // Show the left menu $left_menu=ShowItem(array( //('rapprt.php','Rapprochement'), - array('jrn_update.php?'.$str_dossier,'Journaux',"Gestion des journaux",1), + array('user_advanced.php?'.$str_dossier.'&p_action=preod','Ecritures definies',"",9), array('user_advanced.php?p_action=periode&'.$str_dossier,'Periode',"Gestion des periodes",2), - array('central.php?'.$str_dossier,'Centralise',"Centralisation",3), - array('pcmn_update.php?p_start=1&'.$str_dossier,'Plan Comptable',"Gestion Plan Comptable",4), + array('user_advanced.php?p_action=central&'.$str_dossier,'Centralise',"Centralisation",3), + array('compta.php?p_action=stock&'.$str_dossier,'Stock',"Gestion des stocks",5), array('form.php?'.$str_dossier,'Rapport',"Rapport",6), array('import.php?'.$str_dossier,'Import Banque',"Banque",7), @@ -697,18 +697,16 @@ function ShowMenuParam($p_action="") $s=dossier::get(); $sub_menu=ShowItem(array( - array('parametre.php?p_action=company&'.$s,'Sociétés'), - array('parametre.php?p_action=devise&'.$s,'Devises'), - array('parametre.php?p_action=tva&'.$s,'Tva'), - array('parametre.php?p_action=poste&'.$s,'Poste Comptable'), - array('parametre.php?p_action=fiche&'.$s,'Fiche'), - array('user_sec.php?'.$s,'Sécurité'), - array('parametre.php?p_action=document&'.$s,'Document'), - array('commercial.php?'.$s,"Gestion"), - array('user_compta.php?'.$s,"Comptabilité"), - - // array('login.php','Accueil',"Accueil"), - //array('logout.php','logout',"Sortie") + array('parametre.php?p_action=company&'.$s,'Sociétés','Parametre societe',1), + array('parametre.php?p_action=devise&'.$s,'Devises','Devise',2), + array('parametre.php?p_action=tva&'.$s,'Tva','Taux & poste pour la TVA',3), + array('parametre.php?p_action=poste&'.$s,'Poste Comptable','Poste comptable constant',4), + array('parametre.php?p_action=pcmn&'.$s,'Plan Comptable','Modification du plan comptable',11), + array('parametre.php?p_action=fiche&'.$s,'Fiche','Modifie les classe de base',5), + array('parametre.php?p_action=sec&'.$s,'Sécurité','securite',8), + array('parametre.php?p_action=document&'.$s,'Document','Facture, lettre de rappel, proposition...',7), + array('parametre.php?p_action=jrn&'.$s,'Journaux','Creation et modification de journaux',10) + ), 'H',"mtitle","mtitle",$p_action,' width="100%"'); return $sub_menu; @@ -730,7 +728,7 @@ function MenuJrn() { $str_dossier=dossier::get(); echo ''; - echo ''; + echo ''; include_once("postgres.php"); $Cn=DbConnect(dossier::id()); $Ret=ExecSql($Cn,"select jrn_def_id,jrn_def_name, @@ -740,7 +738,7 @@ function MenuJrn() for ($i=0;$i<$Max;$i++) { $l_line=pg_fetch_array($Ret,$i); - printf ('', + printf ('', $l_line['jrn_def_id'],$l_line['jrn_def_name']); } @@ -762,15 +760,15 @@ function ShowMenuPcmn($p_start=1) { $str_dossier="&".dossier::get(); echo '
Création
Création
%s
%s
'; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; echo "
1 Immobilisé
2 Actif a un an au plus
3 Stock et commande
4 Compte tiers
5 Actif
6 Charges
7 Produits
8 Hors Comptabilité
9 Hors Comptabilité
1 Immobilisé
2 Actif a un an au plus
3 Stock et commande
4 Compte tiers
5 Actif
6 Charges
7 Produits
8 Hors Comptabilité
9 Hors Comptabilité
"; } /*! diff --git a/sql/upgrade.sql b/sql/upgrade.sql index e85a935b9..6fe90b644 100644 --- a/sql/upgrade.sql +++ b/sql/upgrade.sql @@ -521,4 +521,130 @@ CREATE TRIGGER t_bud_detail_ins_upd +CREATE TABLE jrn_periode +( + jrn_def_id int4 NOT NULL, + p_id int4 NOT NULL, + status text, + CONSTRAINT jrn_periode_pk PRIMARY KEY (jrn_def_id, p_id), + CONSTRAINT jrn_per_jrn_def_id FOREIGN KEY (jrn_def_id) + REFERENCES jrn_def (jrn_def_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT jrn_periode_p_id FOREIGN KEY (p_id) + REFERENCES parm_periode (p_id) MATCH SIMPLE + ON UPDATE CASCADE ON DELETE CASCADE +); + +insert into jrn_periode(p_id,jrn_def_id,status) select p_id,jrn_def_id, + case when p_central='t' then 'CE' + when p_closed='t' then 'CL' + else 'OP' + end +from +parm_periode cross join jrn_def; + +CREATE OR REPLACE FUNCTION jrn_def_add() + RETURNS "trigger" AS +$BODY$begin +execute 'insert into jrn_periode(p_id,jrn_def_id,status) select p_id,'||NEW.jrn_def_id||', + case when p_central=true then ''CE'' + when p_closed=true then ''CL'' + else ''OP'' + end +from +parm_periode '; +return NEW; +end;$BODY$ + LANGUAGE 'plpgsql' VOLATILE; + +CREATE TRIGGER t_jrn_def_add_periode + AFTER INSERT + ON jrn_def + FOR EACH ROW + EXECUTE PROCEDURE jrn_def_add(); + +CREATE OR REPLACE FUNCTION jrn_check_periode() + RETURNS "trigger" AS +$BODY$ +declare +bClosed bool; +str_status text; +begin + +select p_closed into bClosed from parm_periode + where p_id=NEW.jr_tech_per; + +if bClosed = true then + raise exception 'Periode fermee'; +end if; + +select status into str_status from jrn_periode + where p_id =NEW.jr_tech_per and jrn_def_id=NEW.jr_def_id; + +if str_status <> 'OP' then + raise exception 'Periode fermee'; +end if; + +return NEW; +end;$BODY$ + LANGUAGE 'plpgsql' VOLATILE; + + +CREATE TRIGGER t_check_jrn + BEFORE INSERT OR DELETE + ON jrn + FOR EACH ROW + EXECUTE PROCEDURE jrn_check_periode(); + +drop TRIGGER tr_jrn_check_balance on jrn; + +CREATE OR REPLACE FUNCTION jrn_def_delete() + RETURNS "trigger" AS +$BODY$ +declare +nb numeric; +begin +select count(*) into nb from jrn where jr_def_id=OLD.jrn_def_id; + +if nb <> 0 then + raise exception 'EFFACEMENT INTERDIT: JOURNAL UTILISE'; +end if; +return OLD; +end;$BODY$ + LANGUAGE 'plpgsql' VOLATILE; + + +CREATE TRIGGER t_jrn_def_delete + BEFORE DELETE + ON jrn_def + FOR EACH ROW + EXECUTE PROCEDURE jrn_def_delete(); + +CREATE OR REPLACE FUNCTION proc_check_balance() + RETURNS "trigger" AS +$BODY$ +declare + diff numeric; + tt integer; +begin + if TG_OP = 'INSERT' or TG_OP='UPDATE' then + tt=NEW.jr_grpt_id; + diff:=check_balance(tt); + if diff != 0 then + raise exception 'balance error %',diff ; + end if; + return NEW; + end if; +end; +$BODY$ + LANGUAGE 'plpgsql' VOLATILE; + +CREATE TRIGGER t_check_balance + AFTER INSERT OR UPDATE + ON jrn + FOR EACH ROW + EXECUTE PROCEDURE proc_check_balance(); + +INSERT INTO "action" (ac_id, ac_description) VALUES (60, 'Module Budget'); + commit;