diff --git a/html/js/update_pcmn.js b/html/js/update_pcmn.js index 30ac891e0..1fe128002 100644 --- a/html/js/update_pcmn.js +++ b/html/js/update_pcmn.js @@ -24,9 +24,9 @@ * */ -function PcmnUpdate(p_value,p_lib,p_parent,p_sessid,p_dossier) +function PcmnUpdate(p_value,p_lib,p_parent,p_type,p_sessid,p_dossier) { - var win=window.open('line_update.php?l='+p_value+'&n='+p_lib+'&p='+p_parent+'&PHPSESSID='+p_sessid+'&gDossier='+p_dossier,'Modifie','toolbar=no,width=500,height=400,scrollbars=yes,resizable=yes'); + var win=window.open('line_update.php?l='+p_value+'&n='+p_lib+'&p='+p_parent+'&m'+p_type+'&PHPSESSID='+p_sessid+'&gDossier='+p_dossier,'Modifie','toolbar=no,width=500,height=400,scrollbars=yes,resizable=yes'); } function RefreshMe() { diff --git a/html/line_update.php b/html/line_update.php index af3cc0d16..8b337c22e 100644 --- a/html/line_update.php +++ b/html/line_update.php @@ -24,33 +24,30 @@ include_once ("ac_common.php"); require_once('class_dossier.php'); $gDossier=dossier::id(); - include_once ("postgres.php"); include_once("check_priv.php"); - +require_once ('class_acc_account.php'); /* Admin. Dossier */ $rep=DbConnect(); include_once ("class_user.php"); $User=new User($rep); $User->Check(); html_page_start($User->theme,"onLoad='window.focus();'"); - -$User->can_request(DbConnect($gDossier),MPCMN); +$cn=DbConnect($gDossier); +$User->can_request($cn,MPCMN); include ("user_menu.php"); - /* Modif d'une ligne */ if ( isset ($_POST["update"] ) ) { - foreach ($_POST as $name => $element) { - echo_debug('line_update.php',__LINE__,"name $name $element"); - } + echo JS_UPDATE_PCMN; - $cn=DbConnect($gDossier); + $p_val=trim($_POST["p_val"]); - $p_lib=FormatString($_POST["p_name"]); - $p_parent=trim($_POST["p_val_parent"]); + $p_lib=FormatString($_POST["p_lib"]); + $p_parent=trim($_POST["p_parent"]); $old_line=trim($_POST["p_old"]); + $p_type=$_POST['p_type']; // Check if p_parent and p_val are number if ( ! is_numeric($p_val) || ! is_numeric($p_parent) ) { // not number no update @@ -80,7 +77,7 @@ if ( isset ($_POST["update"] ) ) { echo ''; } else { - $Ret=ExecSql($cn,"update tmp_pcmn set pcm_val=$p_val, pcm_lib='$p_lib',pcm_val_parent=$p_parent where pcm_val=$old_line"); + $Ret=ExecSql($cn,"update tmp_pcmn set pcm_val=$p_val, pcm_lib='$p_lib',pcm_val_parent=$p_parent,pcm_type='$p_type' where pcm_val=$old_line"); } } else { echo ''; @@ -96,27 +93,19 @@ if ( isset ($_POST["update"] ) ) { ?>
- - -Numéro de classe ',$l); -echo ""; -printf('',urldecode($n)); -echo ""; -printf ('',$p); -echo dossier::hidden(); +pcm_val=$_GET['l']; + $acc->pcm_val_parent=$_GET['p']; + $acc->pcm_lib=$_GET['n']; + $acc->pcm_type=(isset ($_GET['m']))?$_GET['m']:""; + echo $acc->form(true); ?> - -
Libellé
Classe Parent
-',$l); ?> +',$acc->pcm_val); ?>
diff --git a/include/class_acc_account.php b/include/class_acc_account.php index 3aea9f7b9..2dc56cf92 100644 --- a/include/class_acc_account.php +++ b/include/class_acc_account.php @@ -22,66 +22,27 @@ * \brief Manage the account */ /*! - * \brief Manage the account + * \brief Manage the account from the table tmp_pcmn */ require_once ('postgres.php'); require_once ('class_dossier.php'); +require_once ('class_widget.php'); class Acc_Account { var $db; /*! \enum $db database connection */ - var $id; /*! \enum $id poste_id (pcm_val)*/ - var $label; /*! \enum $label label of the poste */ - var $parent; /*! \enum $parent parent account */ - var $row; /*! \enum $row double array see get_row */ - function __construct ($p_cn,$p_id) { + var $pcm_val; + var $pcm_type; + var $pcm_parent; + var $pcm_lib; + function __construct ($p_cn,$p_id=0) { $this->db=$p_cn; - $this->id=$p_id; + $this->pcm_val=$p_id; } - - /*! - * \brief Get data for poste - * - * \param $p_from periode from - * \param $p_to end periode - * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal) - * (tot_deb,tot_credit - * - */ - function get_row($p_from,$p_to) - { - $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); - - - $Res=ExecSql($this->db,"select to_char(j_date,'DD.MM.YYYY') as j_date,". - "case when j_debit='t' then j_montant else 0 end as deb_montant,". - "case when j_debit='f' then j_montant else 0 end as cred_montant,". - " jr_comment as description,jrn_def_name as jrn_name,". - "j_debit, jr_internal ". - " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ". - " left join jrn on jr_grpt_id=j_grpt". - " where j_poste=".$this->id." and ".$periode. - " order by j_date::date"); - $array=array(); - $tot_cred=0.0; - $tot_deb=0.0; - $Max=pg_NumRows($Res); - if ( $Max == 0 ) return null; - for ($i=0;$i<$Max;$i++) { - $array[]=pg_fetch_array($Res,$i); - if ($array[$i]['j_debit']=='t') { - $tot_deb+=$array[$i]['deb_montant'] ; - } else { - $tot_cred+=$array[$i]['cred_montant'] ; - } - } - $this->row=$array; - return array($array,$tot_deb,$tot_cred); -} /*!\brief Return the name of a account * it doesn't change any data member * \return string with the pcm_lib */ - function get_name() { + function get_lib() { $ret=pg_exec($this->db, "select pcm_lib from tmp_pcmn where pcm_val=".$this->id); @@ -99,250 +60,66 @@ class Acc_Account { */ function load() { - $ret=ExecSql($this->db,"select pcm_lib,pcm_val_parent from + $ret=ExecSql($this->db,"select pcm_lib,pcm_val_parent,pcm_type from tmp_pcmn where pcm_val=".$this->id); $r=pg_fetch_all($ret); if ( ! $r ) return false; - $this->label=$r[0]['pcm_lib']; - $this->parent=$r[0]['pcm_val_parent']; + $this->pcm_lib=$r[0]['pcm_lib']; + $this->pcm_val_parent=$r[0]['pcm_val_parent']; + $this->pcm_type=$r[0]['pcm_type']; return true; } - /*!\brief Get all the value for this object from the database - * the data member are set - * \return false if this account doesn't exist otherwise true - */ - function get() - { - echo "OBSOLETE Acc_Account->get(), a remplacer par Acc_Account->load()"; - return $this->load(); - } - - /*! - * \brief give the balance of an account - * - * \return - * balance of the account - * - */ -function get_solde($p_cond=" true ") { - $Res=ExecSql($this->db,"select sum(deb) as sum_deb, sum(cred) as sum_cred from - ( select j_poste, - case when j_debit='t' then j_montant else 0 end as deb, - case when j_debit='f' then j_montant else 0 end as cred - from jrnx join tmp_pcmn on j_poste=pcm_val - where - j_poste like ('$this->id'::text) and - $p_cond - ) as m "); - $Max=pg_NumRows($Res); - if ($Max==0) return 0; - $r=pg_fetch_array($Res,0); - - return abs($r['sum_deb']-$r['sum_cred']); -} - /*! - * \brief give the balance of an account - * \return - * balance of the account - * - */ -function get_solde_detail($p_cond="") { - - if ( $p_cond != "") $p_cond=" and ".$p_cond; - $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from - ( select j_poste, - case when j_debit='t' then j_montant else 0 end as deb, - case when j_debit='f' then j_montant else 0 end as cred - from jrnx join tmp_pcmn on j_poste=pcm_val - where - j_poste like ('$this->id'::text) - $p_cond - ) as m "; - - $Res=ExecSql($this->db,$sql); - $Max=pg_NumRows($Res); - if ($Max==0) return 0; - $r=pg_fetch_array($Res,0); - // if p_start is < p_end the query returns null to avoid any problem - // we set it to 0 - if ($r['sum_deb']=='') - $r['sum_deb']=0.0; - if ($r['sum_cred']=='') - $r['sum_cred']=0.0; - - return array('debit'=>$r['sum_deb'], - 'credit'=>$r['sum_cred'], - 'solde'=>abs($r['sum_deb']-$r['sum_cred'])); -} -/*! - * \brief isTva tell is a poste is used for VAT - * \param none - * - * - * \return 1 is Yes otherwise 0 - */ - function isTVA() - { - // Load TVA array - $a_TVA=get_array($this->db,'select tva_poste - from tva_rate'); - foreach ( $a_TVA as $line_tva) - { - if ( $line_tva['tva_poste'] == '' ) - continue; - list($tva_deb,$tva_cred)=split(',',$line_tva['tva_poste']); - if ( $this->id == $tva_deb || - $this->id == $tva_cred ) - { - return 1; - } - } - return 0; - - } -/*! - * \brief HtmlTable, display a HTML of a poste for the asked period - * \param none - * - * \return none - */ - - - function HtmlTable() - { - $this->get_name(); - - list($array,$tot_deb,$tot_cred)=$this->get_row( $_POST['from_periode'], - $_POST['to_periode'] - ); - - if ( count($this->row ) == 0 ) - return; - - $rep=""; - - echo '

'.$this->id." ".$this->name.'

'; - echo ""; - echo "". - "". - "". - "". - "". - "". - ""; - - foreach ( $this->row as $op ) { - echo "". - "". - "". - "". - "". - "". - ""; + function form($p_table=true){ + $array=array( + array('label'=>'Actif','value'=>'ACT'), + array('label'=>'Passif','value'=>'PAS'), + array('label'=>'Actif c. inverse','value'=>'ACTINV'), + array('label'=>'Passif c.inverse','value'=>'PASINV'), + array('label'=>'Produit','value'=>'PRO'), + array('label'=>'Charge','value'=>'CHA'), + array('label'=>'Non defini','value'=>'CON') + ); + $wType=new widget("select"); + $wType->name='p_type'; + $wType->value=$array; - } - $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur"; - $diff=round(abs($tot_deb-$tot_cred),2); - echo "". - "". - "". - "". - "". - "". - ""; + if ( ! $p_table ) { + $ret=' + + + +
Code interne Date Description Débit Crédit
".$op['jr_internal']."".$op['j_date']."".$op['description']."".$op['deb_montant']."".$op['cred_montant']."
$solde_type$diff$tot_deb$tot_cred
+ + + + + +'; - echo "
"; - - return; - } - - /*! - * \brief Display HTML Table Header (button) - * - * \return none - */ - function HtmlTableHeader() - { - $submit=new widget(); - $hid=new widget("hidden"); - echo '
'; - echo ""; - echo ''; - - echo '"; - - echo '"; - - echo '"; - echo "
'. - dossier::hidden(). - $submit->Submit('bt_other',"Autre poste"). - $hid->IOValue("type","poste").$hid->IOValue('p_action','impress')."
'. - dossier::hidden(). - $submit->Submit('bt_pdf',"Export PDF"). - $hid->IOValue("type","poste"). - $hid->IOValue('p_action','impress'). - $hid->IOValue("poste_id",$_POST['poste_id']). - $hid->IOValue("from_periode",$_POST['from_periode']). - $hid->IOValue("to_periode",$_POST['to_periode']); - if (isset($_POST['poste_fille'])) - echo $hid->IOValue('poste_fille','on'); - echo "
'. - dossier::hidden(). - $submit->Submit('bt_csv',"Export CSV"). - $hid->IOValue("type","poste"). - $hid->IOValue('p_action','impress'). - $hid->IOValue("poste_id",$_POST['poste_id']). - $hid->IOValue("from_periode",$_POST['from_periode']). - $hid->IOValue("to_periode",$_POST['to_periode']); - if (isset($_POST['poste_fille'])) - echo $hid->IOValue('poste_fille','on'); - - echo "
"; - echo '
'; - - } -/*! - * \brief verify that the poste belong to a ledger - * - * \return 0 ok, -1 no - */ - function belong_ledger($p_jrn) { - $filter=getDbValue($this->db,"select jrn_def_class_cred from jrn_def where jrn_def_id=$p_jrn"); - if ( trim ($filter) == '') - return 0; - - $valid_cred=split(" ",$filter); - $sql="select count(*) as poste from tmp_pcmn where "; - // Creation query - $or=""; - $SqlFilter=""; - foreach ( $valid_cred as $item_cred) { - if ( strlen (trim($item_cred))) { - if ( strstr($item_cred,"*") == true ) { - $item_cred=strtr($item_cred,"*","%"); - $SqlItem="$or pcm_val like '$item_cred'"; - $or=" or "; - } else { - $SqlItem="$or pcm_val = '$item_cred' "; - $or=" or "; - } - $SqlFilter=$SqlFilter.$SqlItem; - } - }//foreach - $sql.=$SqlFilter.' and pcm_val='.$this->id; - $max=getDbValue($this->db,$sql); - if ($max > 0 ) - return 0; - else - return -1; - } + $ret.=$wType->IOValue().''; + return $ret; + } + else { + $ret=''; + $ret.=sprintf ('',$this->pcm_val); + $ret.=""; + $ret.=sprintf('',urldecode($this->pcm_lib)); + $ret.= ""; + $ret.=sprintf ('',$this->pcm_val_parent); + $ret.=''; + $wType->selected=$this->pcm_type; + $ret.=""; + $ret.= ''; + $ret.="
Numéro de classe
Libellé
Classe Parent
Type de poste '.$wType->IOValue().'
"; + $ret.=dossier::hidden(); + return $ret; + } + } + /*!\brief for developper only during test */ static function test_me() { $cn=DbConnect(dossier::id()); - $a=new Acc_Account($cn,550); - echo ' Journal 4 '.$a->belong_ledger(4); } } diff --git a/include/class_acc_account_ledger.php b/include/class_acc_account_ledger.php new file mode 100644 index 000000000..a612d5cd6 --- /dev/null +++ b/include/class_acc_account_ledger.php @@ -0,0 +1,352 @@ +db=$p_cn; + $this->id=$p_id; + } + + /*! + * \brief Get data for poste + * + * \param $p_from periode from + * \param $p_to end periode + * \return double array (j_date,deb_montant,cred_montant,description,jrn_name,j_debit,jr_internal) + * (tot_deb,tot_credit + * + */ + function get_row($p_from,$p_to) + { + $periode=sql_filter_per($this->db,$p_from,$p_to,'p_id','jr_tech_per'); + + + $Res=ExecSql($this->db,"select to_char(j_date,'DD.MM.YYYY') as j_date,". + "case when j_debit='t' then j_montant else 0 end as deb_montant,". + "case when j_debit='f' then j_montant else 0 end as cred_montant,". + " jr_comment as description,jrn_def_name as jrn_name,". + "j_debit, jr_internal ". + " from jrnx left join jrn_def on jrn_def_id=j_jrn_def ". + " left join jrn on jr_grpt_id=j_grpt". + " where j_poste=".$this->id." and ".$periode. + " order by j_date::date"); + $array=array(); + $tot_cred=0.0; + $tot_deb=0.0; + $Max=pg_NumRows($Res); + if ( $Max == 0 ) return null; + for ($i=0;$i<$Max;$i++) { + $array[]=pg_fetch_array($Res,$i); + if ($array[$i]['j_debit']=='t') { + $tot_deb+=$array[$i]['deb_montant'] ; + } else { + $tot_cred+=$array[$i]['cred_montant'] ; + } + } + $this->row=$array; + return array($array,$tot_deb,$tot_cred); +} + /*!\brief Return the name of a account + * it doesn't change any data member + * \return string with the pcm_lib + */ + function get_name() { + $ret=pg_exec($this->db, + "select pcm_lib from tmp_pcmn where + pcm_val=".$this->id); + if ( pg_NumRows($ret) != 0) { + $r=pg_fetch_array($ret); + $this->name=$r['pcm_lib']; + } else { + $this->name="Poste inconnu"; + } + return $this->name; + } + /*!\brief Get all the value for this object from the database + * the data member are set + * \return false if this account doesn't exist otherwise true + */ + function load() + { + $ret=ExecSql($this->db,"select pcm_lib,pcm_val_parent from + tmp_pcmn where pcm_val=".$this->id); + $r=pg_fetch_all($ret); + + if ( ! $r ) return false; + $this->label=$r[0]['pcm_lib']; + $this->parent=$r[0]['pcm_val_parent']; + return true; + + } + /*!\brief Get all the value for this object from the database + * the data member are set + * \return false if this account doesn't exist otherwise true + */ + function get() + { + echo "OBSOLETE Acc_Account_Ledger->get(), a remplacer par Acc_Account_Ledger->load()"; + return $this->load(); + } + + /*! + * \brief give the balance of an account + * + * \return + * balance of the account + * + */ +function get_solde($p_cond=" true ") { + $Res=ExecSql($this->db,"select sum(deb) as sum_deb, sum(cred) as sum_cred from + ( select j_poste, + case when j_debit='t' then j_montant else 0 end as deb, + case when j_debit='f' then j_montant else 0 end as cred + from jrnx join tmp_pcmn on j_poste=pcm_val + where + j_poste like ('$this->id'::text) and + $p_cond + ) as m "); + $Max=pg_NumRows($Res); + if ($Max==0) return 0; + $r=pg_fetch_array($Res,0); + + return abs($r['sum_deb']-$r['sum_cred']); +} + /*! + * \brief give the balance of an account + * \return + * balance of the account + * + */ +function get_solde_detail($p_cond="") { + + if ( $p_cond != "") $p_cond=" and ".$p_cond; + $sql="select sum(deb) as sum_deb, sum(cred) as sum_cred from + ( select j_poste, + case when j_debit='t' then j_montant else 0 end as deb, + case when j_debit='f' then j_montant else 0 end as cred + from jrnx join tmp_pcmn on j_poste=pcm_val + where + j_poste like ('$this->id'::text) + $p_cond + ) as m "; + + $Res=ExecSql($this->db,$sql); + $Max=pg_NumRows($Res); + if ($Max==0) { + return array('debit'=>0, + 'credit'=>0, + 'solde'=>0) ; + } + $r=pg_fetch_array($Res,0); + // if p_start is < p_end the query returns null to avoid any problem + // we set it to 0 + if ($r['sum_deb']=='') + $r['sum_deb']=0.0; + if ($r['sum_cred']=='') + $r['sum_cred']=0.0; + + return array('debit'=>$r['sum_deb'], + 'credit'=>$r['sum_cred'], + 'solde'=>abs($r['sum_deb']-$r['sum_cred'])); +} +/*! + * \brief isTva tell is a poste is used for VAT + * \param none + * + * + * \return 1 is Yes otherwise 0 + */ + function isTVA() + { + // Load TVA array + $a_TVA=get_array($this->db,'select tva_poste + from tva_rate'); + foreach ( $a_TVA as $line_tva) + { + if ( $line_tva['tva_poste'] == '' ) + continue; + list($tva_deb,$tva_cred)=split(',',$line_tva['tva_poste']); + if ( $this->id == $tva_deb || + $this->id == $tva_cred ) + { + return 1; + } + } + return 0; + + } +/*! + * \brief HtmlTable, display a HTML of a poste for the asked period + * \param none + * + * \return none + */ + + + function HtmlTable() + { + $this->get_name(); + + list($array,$tot_deb,$tot_cred)=$this->get_row( $_POST['from_periode'], + $_POST['to_periode'] + ); + + if ( count($this->row ) == 0 ) + return; + + $rep=""; + + echo '

'.$this->id." ".$this->name.'

'; + echo ""; + echo "". + "". + "". + "". + "". + "". + ""; + + foreach ( $this->row as $op ) { + echo "". + "". + "". + "". + "". + "". + ""; + + } + $solde_type=($tot_deb>$tot_cred)?"solde débiteur":"solde créditeur"; + $diff=round(abs($tot_deb-$tot_cred),2); + echo "". + "". + "". + "". + "". + "". + ""; + + echo "
Code interne Date Description Débit Crédit
".$op['jr_internal']."".$op['j_date']."".$op['description']."".$op['deb_montant']."".$op['cred_montant']."
$solde_type$diff$tot_deb$tot_cred
"; + + return; + } + + /*! + * \brief Display HTML Table Header (button) + * + * \return none + */ + function HtmlTableHeader() + { + $submit=new widget(); + $hid=new widget("hidden"); + echo '
'; + echo ""; + echo ''; + + echo '"; + + echo '"; + + echo '"; + echo "
'. + dossier::hidden(). + $submit->Submit('bt_other',"Autre poste"). + $hid->IOValue("type","poste").$hid->IOValue('p_action','impress')."
'. + dossier::hidden(). + $submit->Submit('bt_pdf',"Export PDF"). + $hid->IOValue("type","poste"). + $hid->IOValue('p_action','impress'). + $hid->IOValue("poste_id",$_POST['poste_id']). + $hid->IOValue("from_periode",$_POST['from_periode']). + $hid->IOValue("to_periode",$_POST['to_periode']); + if (isset($_POST['poste_fille'])) + echo $hid->IOValue('poste_fille','on'); + echo "
'. + dossier::hidden(). + $submit->Submit('bt_csv',"Export CSV"). + $hid->IOValue("type","poste"). + $hid->IOValue('p_action','impress'). + $hid->IOValue("poste_id",$_POST['poste_id']). + $hid->IOValue("from_periode",$_POST['from_periode']). + $hid->IOValue("to_periode",$_POST['to_periode']); + if (isset($_POST['poste_fille'])) + echo $hid->IOValue('poste_fille','on'); + + echo "
"; + echo '
'; + + } +/*! + * \brief verify that the poste belong to a ledger + * + * \return 0 ok, -1 no + */ + function belong_ledger($p_jrn) { + $filter=getDbValue($this->db,"select jrn_def_class_cred from jrn_def where jrn_def_id=$p_jrn"); + if ( trim ($filter) == '') + return 0; + + $valid_cred=split(" ",$filter); + $sql="select count(*) as poste from tmp_pcmn where "; + // Creation query + $or=""; + $SqlFilter=""; + foreach ( $valid_cred as $item_cred) { + if ( strlen (trim($item_cred))) { + if ( strstr($item_cred,"*") == true ) { + $item_cred=strtr($item_cred,"*","%"); + $SqlItem="$or pcm_val like '$item_cred'"; + $or=" or "; + } else { + $SqlItem="$or pcm_val = '$item_cred' "; + $or=" or "; + } + $SqlFilter=$SqlFilter.$SqlItem; + } + }//foreach + $sql.=$SqlFilter.' and pcm_val='.$this->id; + $max=getDbValue($this->db,$sql); + if ($max > 0 ) + return 0; + else + return -1; + } + static function test_me() { + $cn=DbConnect(dossier::id()); + $a=new Acc_Account_Ledger($cn,550); + echo ' Journal 4 '.$a->belong_ledger(4); + + } +} diff --git a/include/class_acc_bilan.php b/include/class_acc_bilan.php index f3268d625..ef86f5387 100644 --- a/include/class_acc_bilan.php +++ b/include/class_acc_bilan.php @@ -31,6 +31,7 @@ require_once ('class_widget.php'); require_once ('class_dossier.php'); require_once ('impress_inc.php'); require_once ('header_print.php'); +require_once ('class_acc_account_ledger.php'); class Acc_Bilan { var $db; /*!< database connection */ @@ -79,9 +80,139 @@ class Acc_Bilan { $r.=$mod->IOValue('b_id'); $r.=""; $r.= ''; - $r.= $w->Submit('result','Impression'); return $r; } + /*!\brief check and warn if an accound has the wrong saldo + * \param $p_message legend of the fieldset + * \param $p_type type of the Acccount ACT actif, ACTINV... + * \param $p_type the saldo must debit or credit + */ + private function warning($p_message,$p_type,$p_deb) { + $sql="select pcm_val,pcm_lib from tmp_pcmn where pcm_type='$p_type'"; + $res=ExecSql($this->db,$sql); + if ( pg_NumRows($res) ==0 ) + return; + $count=0; + $aRows=pg_fetch_all($res); + $ret=""; + + foreach ($aRows as $line) { + /* set the periode filter */ + $sql=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per'); + + $obj=new Acc_Account_Ledger($this->db,$line['pcm_val']); + $solde=$obj->get_solde_detail($sql); + $solde_signed=$solde['debit']-$solde['credit']; + if ( + ($solde_signed < 0 && $p_deb == 'D' ) || + ($solde_signed > 0 && $p_deb == 'C' ) + ) { + $ret.= '
  • Erreur pour le compte '.$line['pcm_val']. + $line['pcm_lib']. + " D: ".$solde['debit']. + " C: ".$solde['credit']." diff ".$solde['solde']; + $count++; + } + + } + + echo '
    '; + echo ''.$p_message.''; + if ( $count <> 0 ) { + echo '
      '.$ret.'
    '; + echo 'Nbre erreur : '.$count.''; + } else + echo " Pas d'anomalie détectée"; + echo '
    '; + + + } + /*!\brief verify that the saldo is good for the type of account */ + function verify() { + echo '

    Comptes normaux

    '; + $this->warning('Actif avec un solde crediteur','ACT','D'); + $this->warning('Passif avec un solde debiteur','PAS','C'); + $this->warning('Compte de resultat : Charge avec un solde crediteur','CHA','D'); + $this->warning('Compte de resultat : produit avec un solde debiteur','PRO','C'); + echo '
    '; + echo '

    Comptes inverses

    '; + $this->warning('Compte inverse : actif avec un solde debiteur','ACTINV','C'); + $this->warning('Compte inverse : passif avec un solde crediteur','PASINV','D'); + $this->warning('Compte inverse : Charge avec un solde debiteur','CHAINV','C'); + $this->warning('Compte inverse : produit avec un solde crediteur','PROINV','D'); + echo '

    Solde

    '; + /* set the periode filter */ + $sql_periode=sql_filter_per($this->db,$this->from,$this->to,'p_id','j_tech_per'); + /* debit Actif */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='t' and (pcm_type='ACT' or pcm_type='ACTINV')"; + $sql.="and $sql_periode"; + $debit_actif=getDbValue($this->db,$sql); + + /* Credit Actif */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='f' and (pcm_type='ACT' or pcm_type='ACTINV')"; + + $sql.="and $sql_periode"; + + $credit_actif=getDbValue($this->db,$sql); + $total_actif=abs($debit_actif-$credit_actif); + echo 'Total actif '.$total_actif; + echo '
    '; + /* debit passif */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='t' and (pcm_type='PAS' or pcm_type='PASINV') "; + $sql.="and $sql_periode"; + + $debit_passif=getDbValue($this->db,$sql); + + /* Credit Actif */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='f' and (pcm_type='PAS' or pcm_type='PASINV') "; + $sql.="and $sql_periode"; + $credit_passif=getDbValue($this->db,$sql); + $total_passif=abs($debit_passif-$credit_passif); + echo 'Total passif '.$total_passif; + echo '
    '; + /* debit charge */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='t' and (pcm_type='CHA' or pcm_type='CHAINV')"; + $sql.="and $sql_periode"; + $debit_charge=getDbValue($this->db,$sql); + + /* Credit charge */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='f' and (pcm_type='CHA' or pcm_type='CHAINV')"; + $sql.="and $sql_periode"; + $credit_charge=getDbValue($this->db,$sql); + $total_charge=abs($debit_charge-$credit_charge); + echo 'Total charge '.$total_charge; + echo '
    '; + + /* debit prod */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='t' and (pcm_type='PRO' or pcm_type='PROINV')"; + $sql.="and $sql_periode"; + $debit_pro=getDbValue($this->db,$sql); + + /* Credit prod */ + $sql="select sum(j_montant) from jrnx join tmp_pcmn on (j_poste=pcm_val)". + " where j_debit='f' and (pcm_type='PRO' or pcm_type='PROINV')"; + $sql.="and $sql_periode"; + $credit_pro=getDbValue($this->db,$sql); + $total_pro=abs($debit_pro-$credit_pro); + echo 'Total produit '.$total_pro; + echo '
    '; + if ( $total_actif != $total_passif ) { + $diff=$total_actif-$total_passif; + echo 'Difference Actif - Passif = '.$diff.''; + echo '
    '; + } + $diff=$total_pro-$total_charge; + echo ''; + echo "Difference Produit - Charge ".$diff; + echo ''; + } /*! * \brief get data from the $_GET * diff --git a/include/class_acc_ledger.php b/include/class_acc_ledger.php index 211802e79..d121a20c9 100644 --- a/include/class_acc_ledger.php +++ b/include/class_acc_ledger.php @@ -25,7 +25,7 @@ require_once ('class_dossier.php'); require_once ('class_own.php'); require_once ('class_anc_operation.php'); require_once ('class_acc_operation.php'); -require_once ('class_acc_account.php'); +require_once ('class_acc_account_ledger.php'); require_once ('class_pre_op_advanced.php'); require_once ('jrn.php'); require_once ('class_acexception.php'); @@ -472,7 +472,7 @@ class Acc_Ledger { $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']); + $poste=new Acc_Account_Ledger($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 ) @@ -812,7 +812,7 @@ class Acc_Ledger { } if ( trim(${'qc_'.$i})=="" && trim(${'poste'.$i}) != "") { - $oposte=new Acc_Account($this->db,${'poste'.$i}); + $oposte=new Acc_Account_Ledger($this->db,${'poste'.$i}); $strPoste=$oposte->id; $ret.="".${"poste".$i}." - ". $oposte->get_name().$hidden->IOValue('poste'.$i,${'poste'.$i}). @@ -1040,7 +1040,7 @@ class Acc_Ledger { // Check if the account is permitted if ( isset (${'poste'.$i})) { - $p=new Acc_Account($this->db,${'poste'.$i}); + $p=new Acc_Account_Ledger($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); } diff --git a/include/class_admin.php b/include/class_admin.php index fb1f21aaa..724a8f80c 100644 --- a/include/class_admin.php +++ b/include/class_admin.php @@ -24,7 +24,7 @@ require_once("class_parm_code.php"); require_once("class_widget.php"); require_once('class_fiche.php'); -require_once('class_acc_account.php'); +require_once('class_acc_account_ledger.php'); require_once('user_common.php'); /*! \file * \brief Derived from class fiche Administration are a specific kind of card diff --git a/include/class_bud_synthese_acc.php b/include/class_bud_synthese_acc.php index ffe2cf2b9..72537904c 100644 --- a/include/class_bud_synthese_acc.php +++ b/include/class_bud_synthese_acc.php @@ -28,7 +28,7 @@ */ require_once ('class_bud_synthese.php'); require_once ('class_anc_account.php'); -require_once ('class_acc_account.php'); +require_once ('class_acc_account_ledger.php'); require_once ("class.ezpdf.php"); require_once ('header_print.php'); @@ -167,7 +167,7 @@ class Bud_Synthese_Acc extends Bud_Synthese { foreach ($aBudCard as $rBudCard) { $line=array(); echo_debug(__FILE__.':'.__LINE__.'- load ','bud_card',$rBudCard); - $acc_account=new Acc_Account($this->cn,$rBudCard['pcm_val']); + $acc_account=new Acc_Account_Ledger($this->cn,$rBudCard['pcm_val']); $acc_account->load(); $line['acc_name']=$acc_account->label; $line['acc_amount']=$acc_account->get_solde($per_acc); diff --git a/include/class_bud_synthese_anc.php b/include/class_bud_synthese_anc.php index 22c286817..c76ed4b0a 100644 --- a/include/class_bud_synthese_anc.php +++ b/include/class_bud_synthese_anc.php @@ -28,7 +28,7 @@ */ require_once ('class_bud_synthese.php'); require_once ('class_anc_account.php'); -require_once ('class_acc_account.php'); +require_once ('class_acc_account_ledger.php'); class Bud_Synthese_Anc extends Bud_Synthese { @@ -184,7 +184,7 @@ class Bud_Synthese_Anc extends Bud_Synthese { } $sub['amount']=$sub['unit']*$line['price_unit']; $sub['amount_unit']=$periode; - $acc_account=new Acc_Account($this->cn,$pcm_val); + $acc_account=new Acc_Account_Ledger($this->cn,$pcm_val); $acc_account->load(); $sub['acc_name']=$acc_account->label; $sub['acc_amount']=$acc_account->get_solde($per_acc); diff --git a/include/class_bud_synthese_group.php b/include/class_bud_synthese_group.php index 03e79f74c..c80d12859 100644 --- a/include/class_bud_synthese_group.php +++ b/include/class_bud_synthese_group.php @@ -29,7 +29,7 @@ */ require_once ('class_widget.php'); require_once ('class_bud_synthese.php'); -require_once ('class_acc_account.php'); +require_once ('class_acc_account_ledger.php'); require_once ('class_bud_hypo.php'); class Bud_Synthese_Group extends Bud_Synthese { @@ -220,7 +220,7 @@ class Bud_Synthese_Group extends Bud_Synthese { // Add amount from Accountancy $tmp=$array; - $acc=new Acc_Account($this->cn,0); + $acc=new Acc_Account_Ledger($this->cn,0); // $key is the pcm_val and the amount is an array of amount // (index = periode) foreach ($array as $key=>$amount) { diff --git a/include/class_bud_synthese_hypo.php b/include/class_bud_synthese_hypo.php index c703dea7f..9d4f86557 100644 --- a/include/class_bud_synthese_hypo.php +++ b/include/class_bud_synthese_hypo.php @@ -28,7 +28,7 @@ * synthese */ require_once ('class_bud_synthese.php'); -require_once ('class_acc_account.php'); +require_once ('class_acc_account_ledger.php'); class Bud_Synthese_Hypo extends Bud_Synthese { /* function __construct($p_cn) { */ @@ -145,7 +145,7 @@ Array $line['total_row']+=$line[$groupe]; } // total CE - $acc_account=new Acc_Account($this->cn,$pcm_val); + $acc_account=new Acc_Account_Ledger($this->cn,$pcm_val); $acc_account->load(); $line['acc_name']=$acc_account->label; $line['acc_amount']=$acc_account->get_solde($per_acc); diff --git a/include/class_customer.php b/include/class_customer.php index 9fc3d9f9c..ac69ffaa2 100644 --- a/include/class_customer.php +++ b/include/class_customer.php @@ -24,7 +24,7 @@ require_once("class_parm_code.php"); require_once("class_widget.php"); require_once('class_fiche.php'); -require_once('class_acc_account.php'); +require_once('class_acc_account_ledger.php'); require_once('user_common.php'); /*! \file * \brief Derived from class fiche Customer are a specific kind of card @@ -246,7 +246,7 @@ where " ".$client->strAttribut(ATTR_DEF_PAYS). ""; - $post=new Acc_Account($this->cn,$client->strAttribut(ATTR_DEF_ACCOUNT)); + $post=new Acc_Account_Ledger($this->cn,$client->strAttribut(ATTR_DEF_ACCOUNT)); /* Filter on the default year */ $User=new User($this->cn); $filter_year=" j_tech_per in (select p_id from parm_periode ". diff --git a/include/class_document.php b/include/class_document.php index 60f654196..427e93cd0 100644 --- a/include/class_document.php +++ b/include/class_document.php @@ -19,7 +19,7 @@ /* $Revision$ */ // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr require_once('class_own.php'); -require_once('class_acc_account.php'); +require_once('class_acc_account_ledger.php'); require_once('class_action.php'); /*! \file * \brief Class Document corresponds to the table document diff --git a/include/class_supplier.php b/include/class_supplier.php index a36d5c91b..bf56b9809 100644 --- a/include/class_supplier.php +++ b/include/class_supplier.php @@ -24,7 +24,7 @@ require_once("class_parm_code.php"); require_once("class_widget.php"); require_once('class_fiche.php'); -require_once('class_acc_account.php'); +require_once('class_acc_account_ledger.php'); require_once('user_common.php'); /*! \file * \brief Derived from class fiche Supplier are a specific kind of card @@ -129,7 +129,7 @@ class Supplier extends fiche{ " ".$supplier->strAttribut(ATTR_DEF_PAYS). ""; - $post=new Acc_Account($this->cn,$supplier->strAttribut(ATTR_DEF_ACCOUNT)); + $post=new Acc_Account_Ledger($this->cn,$supplier->strAttribut(ATTR_DEF_ACCOUNT)); /* Filter on the default year */ $User=new User($this->cn); $filter_year=" j_tech_per in (select p_id from parm_periode ". diff --git a/include/impress_bilan.inc.php b/include/impress_bilan.inc.php index 794a28d5c..af6d1730b 100644 --- a/include/impress_bilan.inc.php +++ b/include/impress_bilan.inc.php @@ -38,10 +38,33 @@ include_once("postgres.php"); //----------------------------------------------------- $filter_year=" where p_exercice='".$User->get_exercice()."'"; $bilan=new Acc_Bilan($cn); -echo '
    '; -echo '
    '; +echo '
    '; + +echo ''; +echo widget::hidden('p_action','impress'); +echo widget::hidden('type','bilan'); +echo dossier::hidden(); echo $bilan->display_form ($filter_year); +echo widget::submit_button('verif','Verification comptabilite'); echo ''; + + + +if ( isset($_GET['verif'])) { + echo '

    Etape 2 :Impression

    '; + $bilan->get_request_get(); + $bilan->verify(); + require_once ('verif_bilan.inc.php'); + echo '
    '; + echo dossier::hidden(); + echo widget::hidden('b_id',$bilan->id); + + echo widget::hidden('from_periode',$bilan->from); + echo widget::hidden('to_periode',$bilan->to); + echo widget::submit_button('Impression','Impression'); + echo '
    '; + + } echo ' Attention : si le bilan n\'est pas équilibré.
    Vérifiez
    • L\'affectation du résultat est fait
    • Vos comptes actifs ont un solde débiteur (sauf les comptes dit inversés)
    • diff --git a/include/impress_fiche.inc.php b/include/impress_fiche.inc.php index 4cf29302b..39bf1c0b8 100644 --- a/include/impress_fiche.inc.php +++ b/include/impress_fiche.inc.php @@ -30,7 +30,7 @@ if ( isset ($_REQUEST['fd_id'])) { // if amount requested $with_amount= (isset($_REQUEST['with_amount']))?true:false; if ($with_amount) - include_once("class_acc_account.php"); + include_once("class_acc_account_ledger.php"); echo '
      '; $submit=new widget(); diff --git a/include/impress_inc.php b/include/impress_inc.php index bdc50faa5..00ca6cf31 100644 --- a/include/impress_inc.php +++ b/include/impress_inc.php @@ -549,7 +549,7 @@ function ParseFormula($p_cn,$p_label,$p_formula,$p_start,$p_end,$p_eval=true,$p_ else $cond="( j_date >= to_date('$p_start','DD.MM.YYYY') and j_date <= to_date('$p_end','DD.MM.YYYY'))"; - include_once("class_acc_account.php"); + include_once("class_acc_account_ledger.php"); while (ereg("(\[[0-9]*%*D*C*\])",$p_formula,$e) == true) { // remove the [ ] @@ -602,7 +602,7 @@ function ParseFormula($p_cn,$p_label,$p_formula,$p_start,$p_end,$p_eval=true,$p_ } // Get sum of account - $P=new Acc_Account($p_cn,$e[0]); + $P=new Acc_Account_Ledger($p_cn,$e[0]); echo_debug(__FILE__.":".__LINE__." condition is $cond"); $detail=$P->get_solde_detail($cond); diff --git a/include/param_pcmn.inc.php b/include/param_pcmn.inc.php index f33d1a6bd..f62a5d308 100644 --- a/include/param_pcmn.inc.php +++ b/include/param_pcmn.inc.php @@ -21,8 +21,8 @@ /*! \file * \brief concerns the management of the "Plan Comptable" */ +require_once ('class_acc_account.php'); include_once ("ac_common.php"); -html_page_start($_SESSION['g_theme']); require_once("constant.php"); require_once('class_dossier.php'); $gDossier=dossier::id(); @@ -90,10 +90,11 @@ if (isset ($_GET['action'])) { } // isset action //----------------------------------------------------- /* Ajout d'une ligne */ -if ( isset ( $_POST["Add"] ) ) { +if ( isset ( $_POST["Ajout"] ) ) { 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)); @@ -123,7 +124,7 @@ if ( isset ( $_POST["Add"] ) ) { } else { - $Ret=ExecSql($cn,"insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent) values ('$p_val','$p_lib',$p_parent)"); + $Ret=ExecSql($cn,"insert into tmp_pcmn (pcm_val,pcm_lib,pcm_val_parent,pcm_type) values ('$p_val','$p_lib',$p_parent,'$p_type')"); } } } else { @@ -132,7 +133,7 @@ if ( isset ( $_POST["Add"] ) ) { } } -$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"); +$Ret=ExecSql($cn,"select pcm_val,pcm_lib,pcm_val_parent,pcm_type from tmp_pcmn where substr(pcm_val::text,1,1)='".$_SESSION['g_start']."' order by pcm_val::text"); $MaxRow=pg_NumRows($Ret); ?> @@ -148,19 +149,14 @@ echo dossier::hidden(); Classe Libellé Parent + Type - +form(false); +?> - - - - - - - - - - + '; } - echo " $td"; + echo " "; + echo "$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 ''; + echo "$td"; + printf ("", + $A['pcm_val'], + FormatString($A['pcm_lib']), + $A['pcm_val_parent'], + $A['pcm_type'], + $_REQUEST['PHPSESSID'], + dossier::id()); echo $A['pcm_lib']; - echo ''; - echo ""; echo $td; echo $A['pcm_val_parent']; echo ''; + echo "$td"; + echo $A['pcm_type']; + echo ""; + echo $td; printf ('Delete',$A['pcm_val'],$str_dossier); echo ""; + echo ""; }