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"] ) ) { ?>
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 '| 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 " |
| Numéro de classe | ',$this->pcm_val); + $ret.=" |
| Libellé | ',urldecode($this->pcm_lib)); + $ret.= " |
| Classe Parent | ',$this->pcm_val_parent); + $ret.=' |
| Type de poste | "; + $ret.= ''.$wType->IOValue().' | '; + $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 | ". + "