From 1532c3054c8917f7ff91146e9cd474a7bd726e4e Mon Sep 17 00:00:00 2001 From: sparkyx Date: Fri, 28 Oct 2005 12:53:55 +0000 Subject: [PATCH] Task #3840 Code Cleaning --- include/class_widget.php | 21 +++--- include/user_common.php | 140 +++++++++++++++++++------------------- include/user_form_ach.php | 36 +++++----- include/user_form_fin.php | 10 +-- include/user_form_ods.php | 5 +- include/user_form_ven.php | 43 ++++++++---- 6 files changed, 134 insertions(+), 121 deletions(-) diff --git a/include/class_widget.php b/include/class_widget.php index abad9e608..c0a8d23a3 100644 --- a/include/class_widget.php +++ b/include/class_widget.php @@ -53,21 +53,22 @@ class widget { function SetReadOnly($p_read) { $this->readonly=$p_read; } - /*+++ - function IOValue($p_name,$p_value="",$p_label="") { - purpose : create the INPUT tag - parameters: $p_name is the INPUT NAME - $p_value is the INPUT VALUE or an array for select - $p_label is the label of the INPUT - return : string containing the tag - +++*/ + /* function IOValue($p_name,$p_value="",$p_label="") + ***************************************************** + * purpose : create the corresponding INPUT tag + * + * parameters: $p_name is the INPUT NAME + * $p_value is the INPUT VALUE or an array for select + * $p_label is the label of the INPUT + * return : string containing the tag + */ function IOValue($p_name=null,$p_value=null,$p_label="") { - // echo __FILE__."p_value $p_value"; + if ( $p_name != null) $this->name=$p_name; $this->value=($p_value===null)?$this->value:$p_value; $this->label=($p_label == "")?$this->label:$p_label; - //echo "this->value =".$this->value; + // Input text type $disabled = $this->disabled ? "DISABLED" : ""; if (strtoupper($this->type)=="TEXT") { diff --git a/include/user_common.php b/include/user_common.php index 00a1e5b4a..33c27b29e 100644 --- a/include/user_common.php +++ b/include/user_common.php @@ -36,12 +36,15 @@ include_once("postgres.php"); */ function GetTvaRate($p_cn,$p_tva_id) { + // $p_tva_id is an empty string, returns 0 if (strlen(trim($p_tva_id))==0) return 0; -$Res=ExecSql($p_cn,"select tva_id,tva_rate,tva_label from tva_rate where tva_id=".$p_tva_id); -if (pg_NumRows($Res) == 0 ) return null; -$r=pg_fetch_array($Res,0); -return $r; + // Get vat info from the database + $Res=ExecSql($p_cn,"select tva_id,tva_rate,tva_label from tva_rate where tva_id=".$p_tva_id); + if (pg_NumRows($Res) == 0 ) return null; + + $r=pg_fetch_array($Res,0); + return $r; } /* function ComputeVat($p_cn,$a_fiche,$a_quant,$a_price,$ap_vat) @@ -53,10 +56,10 @@ return $r; * * parm : * - database connection - * - fiche id array - * - quantity array - * - price array - * - $ap_vat Array of tva id + * - fiche id array + * 1- quantity array + * - price array + * - $ap_vat Array of tva id * gen : * - * return: array @@ -69,6 +72,7 @@ echo_debug(__FILE__,__LINE__,"ComputeVat $a_fiche $a_quant $a_price"); } $r=null; // foreach goods +//-- foreach ( $a_fiche as $idx=>$element) { echo_debug ("idx $idx element $element"); // if the card id is null or empty @@ -369,68 +373,66 @@ function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null,$p_value=0) $r.=""; // echeance $r.=""; - $r.=$row['jr_ech']; - $r.=""; + $r.=$row['jr_ech']; + $r.=""; + + // comment + $r.=""; + $r.=$row['jr_comment']; + $r.=""; + + // Amount + // If the ledger is financial : + // the credit must be negative and written in red + // Get the jrn type + $jrn_prop=GetJrnProp($p_cn,$row['jrn_def_id'],1); + $positive=0; + if ( $positive=1 && $jrn_prop['jrn_def_type'] == 'FIN' ) { + $positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ". + " where jr_id=".$row['jr_id']." and (j_poste like '55%' or j_poste like '57%' )". + " and j_debit='f'"); + } + $r.=""; + $r.=( $positive != 0 )?" - ".sprintf("%8.2f",$row['jr_montant'])."":sprintf("%8.2f",$row['jr_montant']); + $r.=""; + + // Rapt + $a=GetConcerned($p_cn,$row['jr_id']); + $r.=""; + if ( $a != null ) { + // $r.="operation concernée "; + + foreach ($a as $key => $element) { + $r.= " ".GetInternal($p_cn,$element).""; -// comment - $r.=""; - $r.=$row['jr_comment']; - $r.=""; - -// Amount - // If the ledger is financial : - // the credit must be negative and written in red - // Get the jrn type - $jrn_prop=GetJrnProp($p_cn,$row['jrn_def_id'],1); - $positive=0; - if ( $positive=1 && $jrn_prop['jrn_def_type'] == 'FIN' ) { - $positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ". - " where jr_id=".$row['jr_id']." and (j_poste like '55%' or j_poste like '57%' )". - " and j_debit='f'"); - } - $r.=""; - $r.=( $positive != 0 )?" - ".sprintf("%8.2f",$row['jr_montant'])."":sprintf("%8.2f",$row['jr_montant']); - $r.=""; - -// Rapt - $a=GetConcerned($p_cn,$row['jr_id']); - $r.=""; - if ( $a != null ) { - // $r.="operation concernée "; - - foreach ($a as $key => $element) { - $r.= " ".GetInternal($p_cn,$element).""; - - }//for - }// if ( $a != null ) { - $r.=""; - //$l=user_jrn.php?action=update&line=91 - - if ( $row['jr_valid'] == 'f' ) { - $r.=" Opération annulée"; - } - else { - // if ( $row ['p_closed'] == 'f' && $p_jrn != 0 ) { - // TODO Add print - $r.=""; - // cancel operation - $r.=sprintf('', - "Annuler",$row['jr_grpt_id'],$l_sessid,$p_jrn); - $r.=""; - // } - } - //document - $r.="".sprintf('%s', - $p_jrn, - $row['jr_grpt_id'], - $row['jr_pj_name']).""; - -// end row - $r.=""; - - } -$r.=""; - + }//for + }// if ( $a != null ) { + $r.=""; + //$l=user_jrn.php?action=update&line=91 + + if ( $row['jr_valid'] == 'f' ) { + $r.=" Opération annulée"; + } else { + // all operations can be removed either by setting to 0 the amount + // or by writing the opposite operation if the period is closed + $r.=""; + // cancel operation + $r.=sprintf('', + "Annuler",$row['jr_grpt_id'],$l_sessid,$p_jrn); + $r.=""; + } // else + //document + $r.="".sprintf('%s', + $p_jrn, + $row['jr_grpt_id'], + $row['jr_pj_name']).""; + + // end row + $r.=""; + + } + $r.=""; + return array ($count,$r); } diff --git a/include/user_form_ach.php b/include/user_form_ach.php index 33128ff92..f0ea02745 100644 --- a/include/user_form_ach.php +++ b/include/user_form_ach.php @@ -29,15 +29,14 @@ require_once("user_common.php"); * or update one * * parm : - * - p_array which can be empty - * - the "journal" + * - $p_array which can be empty (normally = $_POST) + * - $p_jrn the ledger * - $p_periode = periode - * - view_only if we cannot change it (no right or centralized op) + * - $pview_only if we cannot change it (no right or centralized op) * - $p_article number of article * gen : * - * return: string with the form - * TODO Add in parameters the infos about the company for making the invoice */ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_only=true,$p_article=1) { @@ -51,7 +50,7 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ $op_date=( ! isset($e_date) ) ?substr($l_date_start,2,8):$e_date; $e_ech=(isset($e_ech))?$e_ech:""; $e_comm=(isset($e_comm))?$e_comm:""; - // $e_jrn=(isset($e_jrn))?$e_jrn:""; + // Save old value and set a new one echo_debug(__FILE__,__LINE__,"form_input.php.FormSell_op_date is $op_date"); $r=""; @@ -65,20 +64,24 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ $sql="select jrn_def_id as value,jrn_def_name as label from jrn_def where jrn_def_type='VEN'"; $list=GetArray($p_cn,$sql); $r.=''; - // $r.=''.InputType("Date ","Text","e_date",$op_date,$pview_only).''; + // Date widget + //-- $Date=new widget("text"); $Date->SetReadOnly($pview_only); $Date->table=1; $r.=""; $r.=$Date->IOValue("e_date",$op_date,"Date"); $r.=""; + // Payment limit widget + //-- $Echeance=new widget("text"); $Echeance->SetReadOnly($pview_only); $Echeance->table=1; $r.=""; $r.=$Echeance->IOValue("e_ech",$e_ech,"Echeance"); $r.=""; - + // Comment + //-- $Commentaire=new widget("text"); $Commentaire->table=1; $Commentaire->SetReadOnly($pview_only); @@ -87,9 +90,10 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ $r.=$Commentaire->IOValue("e_comm",$e_comm,"Description"); $r.=""; include_once("fiche_inc.php"); - // Display the customer + // Display the supplier + //-- $fiche='cred'; - echo_debug(__FILE__,__LINE__,"Client Nombre d'enregistrement ".sizeof($fiche)); + echo_debug(__FILE__,__LINE__,"Fournisseurs Nombre d'enregistrement ".sizeof($fiche)); // Save old value and set a new one $e_client=( isset ($e_client) )?$e_client:""; @@ -108,7 +112,7 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ $e_client_label=$a_client['vw_name']." adresse ".$a_client['vw_addr']." ".$a_client['vw_cp']; } } - + // widget search $W1=new widget("js_search"); $W1->label="Fournisseur"; $W1->name="e_client"; @@ -138,8 +142,11 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ $r.=""; $r.=""; $r.=''; - // $fiche=GetFicheJrn($p_cn,$p_jrn,'cred'); - // echo_debug(__FILE__,__LINE__,"Cred Nombre d'enregistrement ".sizeof($fiche)); + // For each article + // compute amount + // verify if card exists + // retrieve vat label + //-- for ($i=0;$i< $p_article;$i++) { // Code id $march=(isset(${"e_march$i"}))?${"e_march$i"}:""; @@ -169,7 +176,7 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ } } // Show input - // $r.=''.InputType("","js_search","e_march".$i,$march,$pview_only,'cred'); + $W1=new widget("js_search"); $W1->label=""; $W1->name="e_march".$i; @@ -181,13 +188,11 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ $Span=new widget ("span"); $Span->SetReadOnly($pview_only); // card's name - //$r.=InputType("","span", "e_march".$i."_label", $march_label,$pview_only); $r.=""; // price $Price=new widget("text"); $Price->SetReadOnly($pview_only); $Price->table=1; - //$r.=InputType("","text","e_march".$i."_sell",$march_sell,$pview_only); $r.=$Price->IOValue("e_march".$i."_sell",$march_sell); // vat label $select_tva=make_array($p_cn,"select tva_id,tva_label from tva_rate order by tva_id",1); @@ -201,7 +206,6 @@ function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_ $Quantity=new widget("text"); $Quantity->SetReadOnly($pview_only); $Quantity->table=1; - //$r.=InputType("","TEXT","e_quant".$i,$quant,$pview_only); $r.=$Quantity->IOValue("e_quant".$i,$quant); $r.=''; } diff --git a/include/user_form_fin.php b/include/user_form_fin.php index 44b21b070..7cee66115 100644 --- a/include/user_form_fin.php +++ b/include/user_form_fin.php @@ -113,7 +113,7 @@ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru } - // $r.=''.InputType("Banque","js_search","e_bank_account",$e_bank_account,$pview_only,FICHE_TYPE_FIN).''; + // search widget $W1=new widget("js_search"); $W1->readonly=$pview_only; $W1->label="Banque"; @@ -125,7 +125,6 @@ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $r.="
tvaquantité
".$Span->IOValue("e_march".$i."_label",$march_label)."
"; - // $r.= InputType("" ,"span" ,"e_bank_account_label",$e_bank_account_label,false).''; $Span=new widget ("span"); $Span->SetReadOnly($pview_only); $r.="".$Span->IOValue("e_bank_account_label",$e_bank_account_label).""; @@ -195,9 +194,7 @@ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $other=new widget("span"); $r.=""; $r.=$other->IOValue("e_other$i"."_label", $tiers_label); - // $r.=InputType("","span", "e_other$i"."_label", $tiers_label,$pview_only); // Comment - // $r.=InputType("","Text","e_other$i"."_comment",$tiers_comment,$pview_only); $wComment=new widget("text"); $wComment->table=1; $wComment->SetReadOnly($pview_only); @@ -207,10 +204,9 @@ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $wAmount->table=1; $wAmount->size=7; $wAmount->SetReadOnly($pview_only); - // $r.=InputType("","TEXT","e_other$i"."_amount",$tiers_amount,$pview_only); $r.=$wAmount->IOValue("e_other$i"."_amount",$tiers_amount); + // concerned ${"e_concerned".$i}=(isset(${"e_concerned".$i}))?${"e_concerned".$i}:""; - // $r.=InputType("","js_concerned","e_concerned".$i,${"e_concerned".$i},$pview_only); $wConcerned=new widget("js_concerned"); $wConcerned->SetReadOnly($pview_only); $r.=$wConcerned->IOValue("e_concerned".$i,${"e_concerned".$i}); @@ -306,7 +302,6 @@ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) { $amount+=${"e_other$i"."_amount"}; // Record a line for the bank - // $type=( ${"e_other$i"."_amount"} < 0 )?'d':'c'; // Compute the j_grpt $seq=NextSequence($p_cn,'s_grpt'); @@ -317,7 +312,6 @@ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) { // Record a line for the other account - // $type=( ${"e_other$i"."_amount"} < 0 )?'c':'d'; if ( ($j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round(${"e_other$i"."_amount"},2),$seq,$periode)) == false ) { $Rollback($p_cn);exit("error __FILE__ __LINE__");} diff --git a/include/user_form_ods.php b/include/user_form_ods.php index 567154178..75fb811cd 100644 --- a/include/user_form_ods.php +++ b/include/user_form_ods.php @@ -107,7 +107,7 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $sum_deb=0.0; $sum_cred=0.0; - + // for each good for ($i=0;$i< $p_article;$i++) { $account=(isset(${"e_account$i"}))?${"e_account$i"}:""; @@ -155,7 +155,6 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru //libelle $r.=" $lib "; //amount - // $r.=InputType("","text","e_account".$i."_amount",${"e_account$i"."_amount"},$pview_only); $wAmount=new widget("text"); $wAmount->table=1; $wAmount->SetReadOnly($pview_only); @@ -178,7 +177,7 @@ function FormODS($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru $r.=''; $sum_deb+=(${"e_account$i"."_type"}=='d')?${"e_account$i"."_amount"}:0; $sum_cred+=(${"e_account$i"."_type"}=='c')?${"e_account$i"."_amount"}:0; - } + } // End for $r.=""; diff --git a/include/user_form_ven.php b/include/user_form_ven.php index b5c7220f8..c9f340d90 100644 --- a/include/user_form_ven.php +++ b/include/user_form_ven.php @@ -1,4 +1,4 @@ -'; - // $r.=''.InputType("Date ","Text","e_date",$op_date,$pview_only).''; + // Date + //-- $Date=new widget("text"); $Date->SetReadOnly($pview_only); $Date->table=1; $r.=""; $r.=$Date->IOValue("e_date",$op_date,"Date"); $r.=""; + // Payment limit + //-- $Echeance=new widget("text"); $Echeance->SetReadOnly($pview_only); $Echeance->table=1; $r.=""; $r.=$Echeance->IOValue("e_ech",$e_ech,"Echeance"); $r.=""; - + // Comment + //-- $Commentaire=new widget("text"); $Commentaire->table=1; $Commentaire->SetReadOnly($pview_only); @@ -91,14 +95,16 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $r.=""; include_once("fiche_inc.php"); // Display the customer + //-- $fiche='deb'; echo_debug(__FILE__,__LINE__,"Client Nombre d'enregistrement ".sizeof($fiche)); // Save old value and set a new one + //-- $e_client=( isset ($e_client) )?$e_client:""; - $e_client_label=""; // retrieve e_client_label + //-- if ( isNumber($e_client) == 1 ) { if ( isFicheOfJrn($p_cn,$p_jrn,$e_client,'deb') == 0 ) { $msg="Fiche inexistante !!! "; @@ -141,10 +147,11 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $r.="tva"; $r.="quantité"; $r.=''; - // $fiche=GetFicheJrn($p_cn,$p_jrn,'cred'); - // echo_debug(__FILE__,__LINE__,"Cred Nombre d'enregistrement ".sizeof($fiche)); + // For each article + //-- for ($i=0;$i< $p_article;$i++) { - // Code id + // Code id, price & vat code + //-- $march=(isset(${"e_march$i"}))?${"e_march$i"}:""; $march_sell=(isset(${"e_march".$i."_sell"}))?${"e_march".$i."_sell"}:""; $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:""; @@ -153,6 +160,7 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $march_label=""; // If $march has a value + //-- if ( isNumber($march) == 1 ) { if ( isFicheOfJrn($p_cn,$p_jrn,$march,'cred') == 0 ) { $msg="Fiche inexistante !!! "; @@ -161,6 +169,7 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $march=""; } else { // retrieve the tva label and name + //-- $a_fiche=GetFicheAttribut($p_cn, $march); if ( $a_fiche != null ) { if ( $march_tva_id == "" ) { @@ -172,7 +181,7 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ } } // Show input - // $r.=''.InputType("","js_search","e_march".$i,$march,$pview_only,'cred'); + //-- $W1=new widget("js_search"); $W1->label=""; $W1->name="e_march".$i; @@ -183,16 +192,16 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $r.="".$W1->IOValue().""; $Span=new widget ("span"); $Span->SetReadOnly($pview_only); - // card's name - //$r.=InputType("","span", "e_march".$i."_label", $march_label,$pview_only); + // card's name, price + //-- $r.="".$Span->IOValue("e_march".$i."_label",$march_label).""; // price $Price=new widget("text"); $Price->SetReadOnly($pview_only); $Price->table=1; - //$r.=InputType("","text","e_march".$i."_sell",$march_sell,$pview_only); $r.=$Price->IOValue("e_march".$i."_sell",$march_sell); // vat label + //-- $select_tva=make_array($p_cn,"select tva_id,tva_label from tva_rate order by tva_id",1); $Tva=new widget("select"); $Tva->table=1; @@ -200,6 +209,7 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_ $r.=$Tva->IOValue("e_march$i"."_tva_id",$select_tva); // quantity + //-- $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"0"; $Quantity=new widget("text"); $Quantity->SetReadOnly($pview_only); @@ -562,13 +572,14 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) $periode=$p_user->GetPeriode(); $amount=0.0; // Computing total customer + //-- for ($i=0;$i<$nb_item;$i++) { // store quantity & goods in array $a_good[$i]=${"e_march$i"}; $a_quant[$i]=${"e_quant$i"}; $a_price[$i]=0; $a_vat[$i]=${"e_march$i"."_tva_id"}; - // check wether the price is set or no + // check whether the price is set or no if ( isNumber(${"e_march$i"."_sell"}) == 0 ) { if ( isNumber($a_good[$i]) == 1 ) { // If the price is not set we have to find it from the database @@ -579,10 +590,12 @@ function RecordInvoice($p_cn,$p_array,$p_user,$p_jrn) $a_price[$i]=${"e_march$i"."_sell"}; } $amount+=$a_price[$i]*$a_quant[$i]; - } - $comm=FormatString($e_comm); - $a_vat=ComputeVat($p_cn,$a_good,$a_quant,$a_price,$a_vat); + }// for + $comm=FormatString($e_comm); + // Compute VAT + //-- + $a_vat=ComputeVat($p_cn,$a_good,$a_quant,$a_price,$a_vat); $sum_vat=0.0; if ( $a_vat != null ){ foreach ( $a_vat as $element => $t) {