Task #3840 Code Cleaning

This commit is contained in:
sparkyx 2005-10-28 12:53:55 +00:00
parent d1268fbe3f
commit 1532c3054c
6 changed files with 134 additions and 121 deletions

View file

@ -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") {

View file

@ -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.="</TD>";
// echeance
$r.="<TD>";
$r.=$row['jr_ech'];
$r.="</TD>";
$r.=$row['jr_ech'];
$r.="</TD>";
// comment
$r.="<TD>";
$r.=$row['jr_comment'];
$r.="</TD>";
// 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.="<TD align=\"right\">";
$r.=( $positive != 0 )?"<font color=\"red\"> - ".sprintf("%8.2f",$row['jr_montant'])."</font>":sprintf("%8.2f",$row['jr_montant']);
$r.="</TD>";
// Rapt
$a=GetConcerned($p_cn,$row['jr_id']);
$r.="<TD>";
if ( $a != null ) {
// $r.="operation concernée ";
foreach ($a as $key => $element) {
$r.= "<A class=\"detail\" HREF=\"javascript:viewDetail('".GetGrpt($p_cn,$element)."','$l_sessid')\" > ".GetInternal($p_cn,$element)."</A>";
// comment
$r.="<TD>";
$r.=$row['jr_comment'];
$r.="</TD>";
// 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.="<TD align=\"right\">";
$r.=( $positive != 0 )?"<font color=\"red\"> - ".sprintf("%8.2f",$row['jr_montant'])."</font>":sprintf("%8.2f",$row['jr_montant']);
$r.="</TD>";
// Rapt
$a=GetConcerned($p_cn,$row['jr_id']);
$r.="<TD>";
if ( $a != null ) {
// $r.="operation concernée ";
foreach ($a as $key => $element) {
$r.= "<A class=\"detail\" HREF=\"javascript:viewDetail('".GetGrpt($p_cn,$element)."','$l_sessid')\" > ".GetInternal($p_cn,$element)."</A>";
}//for
}// if ( $a != null ) {
$r.="</TD>";
//$l=user_jrn.php?action=update&line=91
if ( $row['jr_valid'] == 'f' ) {
$r.="<TD> Opération annulée</TD>";
}
else {
// if ( $row ['p_closed'] == 'f' && $p_jrn != 0 ) {
// TODO Add print
$r.="<TD>";
// cancel operation
$r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\',\'%s\')">',
"Annuler",$row['jr_grpt_id'],$l_sessid,$p_jrn);
$r.="</TD>";
// }
}
//document
$r.="<TD>".sprintf('<A class="detail" HREF="show_document.php?jrn=%s&jr_grpt_id=%s">%s</A>',
$p_jrn,
$row['jr_grpt_id'],
$row['jr_pj_name'])."</TD>";
// end row
$r.="</tr>";
}
$r.="</table>";
}//for
}// if ( $a != null ) {
$r.="</TD>";
//$l=user_jrn.php?action=update&line=91
if ( $row['jr_valid'] == 'f' ) {
$r.="<TD> Opération annulée</TD>";
} 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.="<TD>";
// cancel operation
$r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\',\'%s\')">',
"Annuler",$row['jr_grpt_id'],$l_sessid,$p_jrn);
$r.="</TD>";
} // else
//document
$r.="<TD>".sprintf('<A class="detail" HREF="show_document.php?jrn=%s&jr_grpt_id=%s">%s</A>',
$p_jrn,
$row['jr_grpt_id'],
$row['jr_pj_name'])."</TD>";
// end row
$r.="</tr>";
}
$r.="</table>";
return array ($count,$r);
}

View file

@ -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.='<TABLE>';
// $r.='<TR>'.InputType("Date ","Text","e_date",$op_date,$pview_only).'</TR>';
// Date widget
//--
$Date=new widget("text");
$Date->SetReadOnly($pview_only);
$Date->table=1;
$r.="<tr>";
$r.=$Date->IOValue("e_date",$op_date,"Date");
$r.="</tr>";
// Payment limit widget
//--
$Echeance=new widget("text");
$Echeance->SetReadOnly($pview_only);
$Echeance->table=1;
$r.="<tr>";
$r.=$Echeance->IOValue("e_ech",$e_ech,"Echeance");
$r.="</tr>";
// 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.="</tr>";
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.="<th>tva</th>";
$r.="<th>quantité</th>";
$r.='</TR>';
// $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.='<TR>'.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.="<TD>".$Span->IOValue("e_march".$i."_label",$march_label)."</TD>";
// 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.='</TR>';
}

View file

@ -113,7 +113,7 @@ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=tru
}
// $r.='<TR>'.InputType("Banque","js_search","e_bank_account",$e_bank_account,$pview_only,FICHE_TYPE_FIN).'</TR>';
// 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.="</TABLE>";
// $r.= InputType("" ,"span" ,"e_bank_account_label",$e_bank_account_label,false).'</TD>';
$Span=new widget ("span");
$Span->SetReadOnly($pview_only);
$r.="<TD>".$Span->IOValue("e_bank_account_label",$e_bank_account_label)."</TD>";
@ -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.="<TD>";
$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__");}

View file

@ -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.="<td> $lib </td>";
//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.='</TR>';
$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.="</TABLE>";

View file

@ -1,4 +1,4 @@
<?
w<?
/*
* This file is part of PhpCompta.
*
@ -68,20 +68,24 @@ function FormVenInput($p_cn,$p_jrn,$p_periode,$p_array=null,$pview_only=true,$p_
$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.='<TABLE>';
// $r.='<TR>'.InputType("Date ","Text","e_date",$op_date,$pview_only).'</TR>';
// Date
//--
$Date=new widget("text");
$Date->SetReadOnly($pview_only);
$Date->table=1;
$r.="<tr>";
$r.=$Date->IOValue("e_date",$op_date,"Date");
$r.="</tr>";
// Payment limit
//--
$Echeance=new widget("text");
$Echeance->SetReadOnly($pview_only);
$Echeance->table=1;
$r.="<tr>";
$r.=$Echeance->IOValue("e_ech",$e_ech,"Echeance");
$r.="</tr>";
// 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.="</tr>";
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.="<th>tva</th>";
$r.="<th>quantité</th>";
$r.='</TR>';
// $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.='<TR>'.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.="<TR>".$W1->IOValue()."</TD>";
$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.="<TD>".$Span->IOValue("e_march".$i."_label",$march_label)."</TD>";
// 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) {