Main Page | Namespace List | Class Hierarchy | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

user_common.php File Reference

Common functions. More...

Go to the source code of this file.

Functions

 GetTvaRate ($p_cn, $p_tva_id)
 Return the rate of the p_tva_id.
 ComputeTotalVat ($p_cn, $a_fiche, $a_quant, $a_price, $ap_vat, $all=false)
 Compute the vat, the fiche.f_id are in a_fiche the quantity in a_quant.
 ComputeVat ($p_cn, $p_fiche, $p_quant, $p_price, $p_vat)
 Compute the vat for only one elt, the fiche.f_id are in p_fiche the quantity in p_quant.
 GetTvaPoste ($p_cn, $p_tva_id, $p_cred)
 Get the account of tva_rate.tva_poste return the credit or the debit account.
 InsertJrnx ($p_cn, $p_type, $p_user, $p_jrn, $p_poste, $p_date, $p_amount, $p_grpt, $p_periode, $p_qcode="")
 Insert into the table Jrn.
 InsertJrn ($p_cn, $p_date, $p_echeance, $p_jrn, $p_comment, $p_amount, $p_grpt, $p_periode)
 Insert into the table Jrnx.
 ListJrn ($p_cn, $p_jrn, $p_where="", $p_array=null, $p_value=0, $p_paid=0)
 show all the lines of the asked jrn
 InsertStockGoods ($p_cn, $p_j_id, $p_good, $p_quant, $p_type)
 Insert data into stock_goods,.
 withStock ($p_cn, $p_f_id)
 return true if we manage stock for it value is stored in attr_value
 VerifyOperationDate ($p_cn, $p_periode, $p_date)
 Verify if the date is a valid date the date is in the default period the period is not closed.
 InsertRapt ($p_cn, $jr_id, $jr_id2)
 Insert into jrn_rapt the concerned operations.
 DeleteRapt ($p_cn, $jr_id, $jr_id2)
 Insert into jrn_rapt the concerned operations.
 GetConcerned ($p_cn, $jr_id)
 Return an array of the concerned operation.
 GetGrpt ($p_cn, $p_jr_id)
 Return the jr_grpt_id from jrn where jr_id = $p_jr_id.
 UpdateComment ($p_cn, $p_jr_id, $p_comment)
 Update comment in jrn.
 isValid ($p_cn, $p_grpt_id)
 test if a jrn op is valid
 jrn_navigation_bar ($p_offset, $p_line, $p_size=0, $p_page=1)
 Create a navigation_bar (pagesize).
 CheckPoste ($p_cn, $qcode)
 Verify that a fiche has a valid ledger. It must be verify before entering data into jrnx. Called from the form_verify_input.


Detailed Description

Common functions.

Definition in file user_common.php.


Function Documentation

CheckPoste p_cn,
qcode
 

Verify that a fiche has a valid ledger. It must be verify before entering data into jrnx. Called from the form_verify_input.

Parameters:
$p_cn database connx
$qcode the quick_code
Returns:
null if an error occurs + a alert message in javascript otherwise 1

Definition at line 949 of file user_common.php.

References $msg, $poste, CountSql(), echo_debug(), and echo_error().

Referenced by form_verify_input().

00950 {
00951     // check if the  ATTR_DEF_ACCOUNT is set
00952     $poste=GetFicheAttribut($p_cn,$qcode,ATTR_DEF_ACCOUNT);
00953     echo_debug('poste.php',__LINE__,"poste value = ".$poste."size = ".strlen(trim($poste)));
00954     if ( $poste == null ) 
00955       { 
00956         $msg="La fiche ".$qcode." n\'a pas de poste comptable";
00957         echo_error($msg); echo_debug('poste.php',__LINE__,$msg);        
00958         echo "<SCRIPT>alert('$msg');</SCRIPT>";
00959         return null;
00960         
00961       }
00962     if ( strlen(trim($poste))==0 )
00963       {
00964         $msg="La fiche ".$qcode." n\'a pas de poste comptable";
00965         echo_error($msg); echo_debug('poste.php',__LINE__,$msg);                
00966         echo "<SCRIPT>alert('$msg');</SCRIPT>";
00967         return null;
00968       }
00969     // Check that the account exists
00970     if ( CountSql($p_cn,
00971                   "select * from tmp_pcmn where pcm_val=$poste") == 0 )
00972       {
00973         $msg=" Le poste comptable $poste de la fiche ".$qcode." n\'existe pas";
00974         echo_error($msg); echo_debug('poste.php',__LINE__,$msg);                
00975         echo "<SCRIPT>alert('$msg');</SCRIPT>";
00976         return null; 
00977 
00978       }
00979     return  1; 
00980 }

ComputeTotalVat p_cn,
a_fiche,
a_quant,
a_price,
ap_vat,
all = false
 

Compute the vat, the fiche.f_id are in a_fiche the quantity in a_quant.

Parameters:
$p_cn database connection
$a_fiche fiche id array
$a_quantity array
$a_price array
$ap_vat Array of tva id
$all = false if we reduce VAT
Returns:
: array a[tva_id] = amount vat

Definition at line 69 of file user_common.php.

References $a, $flag, $idx, $r, $tva_id, echo_debug(), GetTvaRate(), and isNumber().

Referenced by RecordInvoice(), and RecordSell().

00069                                                                                 {
00070 echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_price");
00071  foreach ( $a_fiche as $t=>$el) {
00072    echo_debug('user_common.php',__LINE__,"t $t e $el");
00073  }
00074  $r=null;
00075 // foreach goods 
00076 //--
00077  foreach ( $a_fiche as $idx=>$element) {
00078    echo_debug ('user_common.php',__LINE__,"idx $idx element $element");
00079   // if the card id is null or empty 
00080     if (  strlen(trim($element))==0) continue;
00081    
00082     // Get the tva_id
00083     if ( $ap_vat != null and
00084          isNumber($ap_vat[$idx])== 1 and $ap_vat[$idx] != -1 ) 
00085       {
00086         $tva_id=$ap_vat[$idx];
00087         echo_debug('user_common',__LINE__,' tva_id is given');
00088         echo_debug('user_common',__LINE__,$ap_vat);
00089       }
00090     else
00091       {
00092         $tva_id=GetFicheAttribut($p_cn,$element,ATTR_DEF_TVA);
00093         echo_debug('user_common',__LINE__,'retrieve tva_id');
00094       }
00095     echo_debug('user_common',__LINE__,"tva id $tva_id");
00096     if ( $tva_id == null ) continue;
00097     // for each fiche find the tva_rate and tva_id
00098     $a_vat=GetTvaRate($p_cn,$tva_id);
00099    
00100         // Get the attribut price of the card(fiche)
00101         if ( $a_vat != null  and  $a_vat['tva_id'] != "" ) 
00102         {  
00103                 $flag=true;
00104                 $a=$a_vat['tva_id'];
00105                 // Compute vat for this item
00106                 $vat_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx],2);
00107         
00108                 // only the deductible vat
00109                  if ( $all == false ) 
00110                    {
00111                      //variable containing the nd part 
00112                      // used when a card has both special rule for vat 
00113                      $nd1=0;
00114                      // if a part is not deductible then reduce vat_amount
00115                      $nd=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA_NON_DEDUCTIBLE);
00116                      if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 )
00117                        {
00118                          $nd_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2);
00119                          // problem with round
00120                          $vat_amount=$vat_amount-$nd_amount;
00121                          echo_debug('user_common.php',__LINE__,
00122                                     "A - TVA Attr fiche [$nd] nd amount [ $nd_amount ]".
00123                                     "vat amount [ $vat_amount]");
00124                          $flag=false;
00125                          // save nd into nd1
00126                          $nd1=$nd;
00127                         }       
00128                         // if a part is not deductible then reduce vat_amount
00129                         $nd=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
00130                         if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 )
00131                         {
00132                           $nd_amount2=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2);
00133                          
00134                           $vat_amount=$vat_amount-$nd_amount2;
00135                           // when using both vat, their sum cannot exceed 1, if = 1 then vat = 0
00136                           if ( ($nd+$nd1) == 1)
00137                             $vat_amount=0;
00138                           echo_debug('user_common.php',__LINE__,
00139                                      "B - TVA Attr fiche [$nd] nd amount [ $nd_amount2 ]".
00140                                      "vat amount [ $vat_amount]");
00141                           
00142                           $flag=false;
00143                         }       
00144                 }
00145                  
00146                 $r[$a]=isset ( $r[$a] )?$r[$a]+$vat_amount:$vat_amount; 
00147         }
00148     
00149  }
00150  echo_debug('user_common.php',__LINE__," return ".var_export($r,true));
00151  return $r;
00152  
00153  
00154 }

ComputeVat p_cn,
p_fiche,
p_quant,
p_price,
p_vat
 

Compute the vat for only one elt, the fiche.f_id are in p_fiche the quantity in p_quant.

Parameters:
$p_cn database connection
$p_fiche fiche id int
$p_quantity int
$p_price float
$p_tva_id 
Returns:
the amount of vat

Definition at line 172 of file user_common.php.

References $a, $tva_id, echo_debug(), GetTvaRate(), and isNumber().

Referenced by RecordInvoice(), and RecordSell().

00173 {
00174   echo_debug('user_common.php',__LINE__,"function ComputeVat($p_cn,$p_fiche,$p_quant,$p_price,$p_vat )");
00175   // Get the tva_id
00176   if ( $p_vat != null and  isNumber($p_vat)== 1 and $p_vat != -1)
00177     $tva_id=$p_vat;
00178   else
00179     $tva_id=GetFicheAttribut($p_cn,$p_fiche,ATTR_DEF_TVA);
00180  
00181   echo_debug('user_common',__LINE__,"ComputeVat tva id = $tva_id"); 
00182   if ( $tva_id == null  ) return -1;
00183   // find the tva_rate and tva_id
00184   $a_vat=GetTvaRate($p_cn,$tva_id);
00185   $vat_amount=null;
00186   // Get the attribut price of the card(fiche)
00187   if ( $a_vat != null  and  $a_vat['tva_id'] != "" ) 
00188     {
00189       $a=$a_vat['tva_id'];
00190       $vat_amount=$p_price*$a_vat['tva_rate']*$p_quant;
00191     } 
00192   echo_debug('user_common',__LINE__,'return '.round($vat_amount,2));
00193   return round($vat_amount,2);
00194   
00195   
00196 }

DeleteRapt p_cn,
jr_id,
jr_id2
 

Insert into jrn_rapt the concerned operations.

DeleteRapt($p_cn,$jr_id,$jr_id2)

parm :

Parameters:
$p_cn database connection
$jr_id (jrn.jr_id) => jrn_rapt.jr_id
$jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
Returns:
none

Definition at line 727 of file user_common.php.

References $Res, CountSql(), echo_debug(), echo_error(), ExecSql(), and isNumber().

00727                                           {
00728   echo_debug('user_common.php',__LINE__,"DeleteRapt($p_cn,$jr_id,$jr_id2) ");
00729   if ( isNumber($jr_id)  == 0 or 
00730        isNumber($jr_id2) == 0 )
00731     {
00732       echo_error(" InsertRapt : invalid jr_id jr_id = $jr_id jr_id2 = $jr_id2");
00733       return;
00734     }
00735   // verify if exists
00736   if ( CountSql($p_cn,"select jra_id from jrn_rapt where jra_concerned=$jr_id and jr_id=$jr_id2
00737                    union
00738                  select jra_id from jrn_rapt where jra_concerned=$jr_id2 and jr_id=$jr_id ") !=0) 
00739     {
00740       // Ok we can insert 
00741       $Res=ExecSql($p_cn,"delete from jrn_rapt where (jra_concerned=$jr_id2 and jr_id=$jr_id) or 
00742                                (jra_concerned=$jr_id and jr_id=$jr_id2) ");
00743     }
00744 }

GetConcerned p_cn,
jr_id
 

Return an array of the concerned operation.

GetConcerned (p_cn ,jr_id)

parm :

  • database connection

jrn.jr_id gen :

  • none return:

array if something is found

Definition at line 758 of file user_common.php.

References $i, $l, $n, $r, $Res, $sql, and ExecSql().

Referenced by ListJrn(), and UpdateJrn().

00758                                       {
00759 $sql=" select jr_id as cn from jrn_rapt where jra_concerned=$jr_id
00760       union
00761        select jra_concerned as cn from jrn_rapt where jr_id=$jr_id";
00762  $Res=ExecSql($p_cn,$sql);
00763 
00764  // If nothing is found return null
00765  $n=pg_NumRows($Res);
00766 
00767  if ($n ==0 ) return null;
00768 
00769  // put everything in an array
00770  for ($i=0;$i<$n;$i++) {
00771    $l=pg_fetch_array($Res,$i);
00772    $r[$i]=$l['cn'];
00773  }
00774  return $r;
00775 }

GetGrpt p_cn,
p_jr_id
 

Return the jr_grpt_id from jrn where jr_id = $p_jr_id.

GetGrpt($p_cn,$p_jr_id)

parm :

  • $p_jr_id jrn.jr_id

$p_cn database connection gen :

  • none return:

return the jrn.jr_grpt_id or null

Definition at line 789 of file user_common.php.

References $r, $Res, and ExecSql().

Referenced by UpdateJrn().

00790 {
00791   $Res=ExecSql($p_cn,"select jr_grpt_id from jrn where jr_id=".$p_jr_id);
00792   if ( pg_NumRows($Res) == 0 ) {
00793     return null;
00794   }
00795   $r=pg_fetch_array($Res,0);
00796   return $r['jr_grpt_id'];
00797 }

GetTvaPoste p_cn,
p_tva_id,
p_cred
 

Get the account of tva_rate.tva_poste return the credit or the debit account.

Parameters:
$p_cn connection
$p_tva_id tva_rate.tva_id
$p_cred type ( d or credit)
Returns:
return the credit or the debit account null if error

Definition at line 211 of file user_common.php.

References $a, $Res, echo_error(), and ExecSql().

Referenced by RecordInvoice(), and RecordSell().

00211                                               {
00212         $Res=ExecSql($p_cn,"select tva_poste from tva_rate where tva_id=$p_tva_id");
00213         if ( pg_NumRows($Res) == 0 ) return null;
00214         $a=pg_fetch_array($Res,0);
00215         list ($deb,$cred)=split(",",$a['tva_poste']);
00216         if ( $p_cred=='c' ) return $cred;
00217         if ($p_cred=='d') return $deb;
00218         echo_error ("Invalid $p_cred in GetTvaRate");
00219         return null;
00220 }

GetTvaRate p_cn,
p_tva_id
 

Return the rate of the p_tva_id.

Parameters:
$p_cn database connection
$p_tva_id tva.tva_id
Returns:
an array containing the rate and the label the tva rate or null if a problem occured

Definition at line 40 of file user_common.php.

References $r, $Res, and ExecSql().

Referenced by ComputeTotalVat(), ComputeVat(), FormAchView(), FormVenteView(), and Document::Replace().

00040                                      {
00041   // $p_tva_id is an empty string, returns 0
00042   if (strlen(trim($p_tva_id))==0) return 0;
00043 
00044   // Get vat info from the database
00045   $Res=ExecSql($p_cn,"select tva_id,tva_rate,tva_label from tva_rate where tva_id=".$p_tva_id);
00046   if (pg_NumRows($Res) == 0 ) return null;
00047 
00048   $r=pg_fetch_array($Res,0);
00049   return $r;
00050 
00051 }

InsertJrn p_cn,
p_date,
p_echeance,
p_jrn,
p_comment,
p_amount,
p_grpt,
p_periode
 

Insert into the table Jrnx.

InsertJrn($p_cn,$p_date,$p_jrn,$p_comment,$p_amount,$p_grpt,$p_periode

parm :

  • $p_cn database connection

$p_date date

  • $p_jrn the current 'journal' (folder)
  • $p_poste the account
  • $p_amount amount to insert
  • $p_periode the concerned periode
  • $p_comment comment gen :
    • none return:

nothing

Definition at line 288 of file user_common.php.

References $Res, $sql, echo_debug(), ExecSql(), FormatString(), GetSequence(), and p_comment.

Referenced by RecordFin(), RecordInvoice(), RecordSell(), and TransferCSV().

00289 {
00290         echo_debug ('user_common.php',__LINE__,"InsertJrn param 
00291             p_date $p_date p_poste $p_comment p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode p_echeance = $p_echeance
00292 comment = $p_comment");
00293         $p_comment=FormatString($p_comment);
00294 
00295         if ( $p_echeance == "" or $p_echeance==null) {
00296                 $p_echeance='null';
00297         } else {
00298                 $p_echeance=sprintf("to_date('%s','DD.MM.YYYY')",$p_echeance);
00299         }
00300         $sql=sprintf("insert into jrn (jr_def_id,jr_montant,jr_comment,jr_date,jr_ech,jr_grpt_id,jr_tech_per)
00301                  values ( %d,abs(%.2f),'%s',to_date('%s','DD.MM.YYYY'),%s,%d,%d)",
00302                      $p_jrn, round($p_amount,2),$p_comment,$p_date,$p_echeance,$p_grpt,$p_periode);
00303         echo_debug('user_common.php',__LINE__,"InsertJrn $sql");
00304         $Res=ExecSql($p_cn,$sql);                                
00305         if ( $Res == false)  return false;
00306         return GetSequence($p_cn,'s_jrn');
00307 }

InsertJrnx p_cn,
p_type,
p_user,
p_jrn,
p_poste,
p_date,
p_amount,
p_grpt,
p_periode,
p_qcode = ""
 

Insert into the table Jrn.

InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_grpt,$p_periode

parm :

  • $p_cn database connection

$p_type debit or credit

  • $p_user the current user
  • $p_jrn the current 'journal' (folder)
  • $p_poste the account
  • $p_date
  • $p_amount amount to insert
  • $p_periode the concerned periode gen :
    • none return:

nothing

Definition at line 244 of file user_common.php.

References $Res, $sql, echo_debug(), ExecSql(), and GetSequence().

Referenced by RecordFin(), RecordInvoice(), RecordODS(), RecordSell(), and TransferCSV().

00245 {
00246   echo_debug ('user_common.php',__LINE__,"InsertJrnx param 
00247             type = $p_type p_user $p_user 
00248             p_date $p_date p_poste $p_poste 
00249             p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode");
00250 
00251   if ( $p_amount == 0) return true;
00252 
00253   $debit=($p_type=='c')?'false':'true';
00254 
00255   // if negative value the operation is inversed
00256   if ( $p_amount < 0 ) {
00257     $debit=($debit=='false')?'true':'false';
00258   }
00259 
00260   $sql=sprintf("select insert_jrnx
00261                  ('%s',abs(%.2f),%d,%d,%d,%s,'%s',%d,'%s')",
00262                   $p_date,round($p_amount,2),$p_poste,$p_grpt,$p_jrn,$debit,$p_user,$p_periode,$p_qcode);
00263 
00264   echo_debug('user_common.php',__LINE__,"InsertJrnx $sql");
00265   $Res=ExecSql($p_cn,$sql);
00266   if ( $Res==false) return $Res;
00267   return GetSequence($p_cn,'s_jrn_op');
00268 
00269 }

InsertRapt p_cn,
jr_id,
jr_id2
 

Insert into jrn_rapt the concerned operations.

Parameters:
$p_cn database connection
$jr_id (jrn.jr_id) => jrn_rapt.jr_id
$jr_id2 (jrn.jr_id) => jrn_rapt.jra_concerned
Returns:
none

Definition at line 699 of file user_common.php.

References $Res, CountSql(), echo_debug(), echo_error(), ExecSql(), and isNumber().

Referenced by RecordFin().

00699                                           {
00700   if ( isNumber($jr_id)  == 0 ||  isNumber($jr_id2) == 0 )
00701     {
00702       echo_error(" InsertRapt : invalid jr_id $jr_id, jr_id2 $jr_id2");
00703       echo_debug('user_common.php',__LINE__," InsertRapt : invalid jr_id $jr_id, jr_id2 $jr_id2");
00704       return false;
00705     }
00706   // verify if exists
00707   if ( CountSql($p_cn,"select jra_id from jrn_rapt where jra_concerned=$jr_id and jr_id=$jr_id2
00708                    union
00709                  select jra_id from jrn_rapt where jra_concerned=$jr_id2 and jr_id=$jr_id ") ==0) 
00710     {
00711       // Ok we can insert 
00712       $Res=ExecSql($p_cn,"insert into jrn_rapt(jr_id,jra_concerned) values ($jr_id,$jr_id2)");
00713     }
00714   return true;
00715 }

InsertStockGoods p_cn,
p_j_id,
p_good,
p_quant,
p_type
 

Insert data into stock_goods,.

InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c');

parm :

  • $p_cn database connection

$p_j_id the j_id

  • $p_goods the goods
  • $p_quant quantity
  • $p_type c for credit or d for debit gen :
    • none return: none TODO ADD A DATE !!!

Definition at line 596 of file user_common.php.

References $r, $Res, $sql, echo_debug(), ExecSql(), and f_id.

Referenced by RecordInvoice(), and RecordSell().

00597 {
00598   echo_debug('user_common.php',__LINE__,"function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)");
00599   // Retrieve the good account for stock
00600   $code_marchandise=GetFicheAttribut($p_cn,$p_good,ATTR_DEF_STOCK);
00601   $sql="select f_id from vw_poste_qcode where j_qcode='$p_good'";
00602   $Res=ExecSql($p_cn,$sql);
00603   $r=pg_fetch_array($Res,0);
00604   $f_id=$r['f_id'];
00605   $Res=ExecSql($p_cn,"insert into stock_goods (
00606                             j_id,
00607                             f_id,
00608                             sg_code, 
00609                             sg_quantity,
00610                              sg_type ) values (
00611                             $p_j_id,
00612                             $f_id,
00613                             '$code_marchandise',
00614                             $p_quant, '$p_type') 
00615                      ");
00616  return $Res;
00617 }

isValid p_cn,
p_grpt_id
 

test if a jrn op is valid

isValid ($p_cn, $p_grpt_id

parm :

  • db connection

p_grpt_id gen :

  • none return: 1 is valid 0 is not valid

Definition at line 831 of file user_common.php.

References $a, $Res, echo_error(), and ExecSql().

Referenced by cl_user::cl_user().

00831                                     {
00832   $Res=ExecSql($p_cn,"select jr_valid from jrn where jr_grpt_id=$p_grpt_id");
00833 
00834   if ( ( $M = pg_NumRows($Res)) == 0 ) return 0;
00835 
00836   $a=pg_fetch_array($Res,0);
00837 
00838   if ( $a['jr_valid'] == 't') return 1;
00839   if ( $a['jr_valid'] == 'f') return 0;
00840 
00841   echo_error ("Invalid result = ".$a['result']);
00842 
00843 
00844 }

jrn_navigation_bar p_offset,
p_line,
p_size = 0,
p_page = 1
 

Create a navigation_bar (pagesize).

jrn_navigation_bar

Parameters:
$p_offset first record number
$p_line total of returned row
$p_size current g_pagesize user's preference
$p_page number of the page where the user is
Returns:
string with the nav. bar

Definition at line 858 of file user_common.php.

References $_SESSION, $e, $go, $offset, $r, $step, $url, echo_debug(), name, size, and value.

Referenced by action::myList(), Supplier::Summary(), Customer::Summary(), contact::Summary(), Admin::Summary(), and ViewFiche().

00859 {
00860   echo_debug('user_common',__LINE__,"function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1)");
00861   // if the pagesize is unlimited return ""
00862   // in that case there is no nav. bar
00863   if ( $_SESSION['g_pagesize'] == -1  ) return "";
00864   if ( $p_size==0) {
00865     $p_size= $_SESSION['g_pagesize'];
00866   }
00867   // if there is no row return an empty string
00868   if ( $p_line == 0 ) return "";
00869 
00870   // Compute the url
00871   $url="";
00872   $and="";
00873   $get=$_GET;
00874   if ( isset ($get) ) {
00875     foreach ($get as $name=>$value ) {
00876       // we clean the parameter offset, step, page and size
00877       if (  ! in_array($name,array('offset','step','page','size'))) {
00878         $url.=$and.$name."=".$value;
00879         $and="&";
00880       }// if
00881     }//foreach
00882   }// if
00883   // compute max of page
00884   $nb_page=($p_line-($p_line%$p_size))/$p_size;
00885   echo_debug('user_common',__LINE__,"nb_page = $nb_page");
00886   // if something remains
00887   if ( $p_line % $p_size != 0 ) $nb_page+=1;
00888 
00889   // if max page == 1 then return a empty string
00890   if ( $nb_page == 1) return "";
00891 
00892   $r="";
00893   // previous
00894   if ($p_page !=1) {
00895     $e=$p_page-1;
00896     $step=$_SESSION['g_pagesize'];
00897     $offset=($e-1)*$step;
00898 
00899     $r='<A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'">';
00900     $r.="Pr&eacute;c&eacute;dent";
00901     $r.="</A>&nbsp;&nbsp;";
00902   }
00903   //----------------------------------------------------------------------
00904   // Create a partial bar 
00905   // if current page < 11 show 1 to 20 
00906   // otherwise            show $p_page -10 to $p_page + 10
00907   //----------------------------------------------------------------------
00908   $start_bar=($p_page < 11 )?1:$p_page-10;
00909   $end_bar  =($p_page < 11 )?20:$p_page+10;
00910   $end_bar  =($end_bar > $nb_page )?$nb_page:$end_bar;
00911 
00912   // Create the bar
00913   for ($e=$start_bar;$e<=$end_bar;$e++) {
00914     // do not included current page
00915     if ( $e != $p_page ) {
00916     $step=$_SESSION['g_pagesize'];
00917     $offset=($e-1)*$step;
00918     $go=sprintf($_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step");
00919     $r.=sprintf('<A class="mtitle" HREF="%s" CLASS="one">%d</A>&nbsp;',$go,$e);
00920     } else {
00921       $r.="<b> $e </b>";
00922     } //else
00923   } //for
00924   // next
00925   
00926   if ($p_page !=$nb_page) {
00927     // If we are not at the last page show the button next
00928     $e=$p_page+1;
00929     $step=$_SESSION['g_pagesize'];
00930     $offset=($e-1)*$step;
00931 
00932     $r.='&nbsp;<A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'">';
00933     $r.="Suivant";
00934     $r.="</A>";
00935   }
00936 
00937 
00938   return $r;
00939 }

ListJrn p_cn,
p_jrn,
p_where = "",
p_array = null,
p_value = 0,
p_paid = 0
 

show all the lines of the asked jrn

ListJrn($p_cn,$p_jrn,$p_wherel)

Parameters:
$p_cn database connection
$p_jrn jrn_id jrn.jrn_def_id
$p_where the sql query where clause
$p_array param. for a search
$p_value offset
$p_paid value : 0 nothing is shown, 1 check box; 2 check_box disable
Returns:
array (entryCount,generatedHTML);

Definition at line 322 of file user_common.php.

References $_SESSION, $a, $count, $h, $limit, $Max, $offset, $p_jrn, $r, $Res, $row, $sql, $tr, $User, $w, CountSql(), DbConnect(), ExecSql(), FormatString(), GetConcerned(), GetInternal(), GetJrnProp(), isDate(), and table.

00323 {
00324 
00325   include_once("central_inc.php");
00326   $limit=($_SESSION['g_pagesize']!=-1)?" LIMIT ".$_SESSION['g_pagesize']:"";
00327   $offset=($_SESSION['g_pagesize']!=-1)?" OFFSET ".$p_value:"";
00328   if ( $p_array == null ) {
00329 
00330   //que fait cette requête??? 
00331     
00332    $sql="select jr_id   ,
00333                         jr_montant,
00334                         jr_comment,
00335                         jr_ech,
00336                         to_char(jr_date,'DD.MM.YYYY') as jr_date,
00337                         jr_date as jr_date_order,
00338                         jr_grpt_id,
00339                         jr_rapt,
00340                         jr_internal,
00341                         jrn_def_id,
00342                         jrn_def_name,
00343                         jrn_def_ech,
00344                         jrn_def_type,
00345                         jr_valid,
00346                         jr_tech_per,
00347                         jr_pj_name,
00348                         p_closed
00349                        from 
00350                         jrn 
00351                             join jrn_def on jrn_def_id=jr_def_id 
00352                             join parm_periode on p_id=jr_tech_per
00353                        $p_where 
00354                          order by jr_date_order asc,jr_internal asc";
00355   }
00356   if ( $p_array != null ) {
00357     // Construction Query 
00358     foreach ( $p_array as $key=>$element) {
00359       ${"l_$key"}=$element;
00360     }
00361     $sql="select jr_id  ,
00362                 jr_montant,
00363                 jr_comment,
00364                 jr_ech,
00365                 to_char(jr_date,'DD.MM.YYYY') as jr_date,
00366                 jr_date as jr_date_order,
00367                 jr_grpt_id,
00368                 jr_rapt,
00369                 jr_internal,
00370                 jrn_def_id,
00371                 jrn_def_name,
00372                 jrn_def_ech,
00373                 jrn_def_type,
00374                 jr_valid,
00375                 jr_tech_per,
00376                 jr_pj_name,
00377                 p_closed
00378                       from 
00379                 jrn join jrn_def on jrn_def_id=jr_def_id 
00380                     join parm_periode on p_id=jr_tech_per
00381                 ";
00382     $jrn_sql=($p_jrn =0)?"1=1":"jrn_def_id=$p_jrn ";
00383     $l_and=" where ";
00384     // amount
00385     if ( ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant) ) 
00386     {
00387       $sql.=$l_and."  jr_montant $l_mont_sel $l_s_montant";
00388       $l_and=" and ";
00389     }
00390     // date
00391     if ( isDate($l_date_start) != null ) 
00392     {
00393       $sql.=$l_and." jr_date >= to_date('".$l_date_start."','DD.MM.YYYY')";
00394       $l_and=" and ";
00395     }
00396     if ( isDate($l_date_end) != null ) {
00397       $sql.=$l_and." jr_date <= to_date('".$l_date_end."','DD.MM.YYYY')";
00398       $l_and=" and ";
00399     }
00400     // comment
00401     $l_s_comment=FormatString($l_s_comment);
00402     if ( $l_s_comment != null ) 
00403     {
00404       $sql.=$l_and." upper(jr_comment) like upper('%".$l_s_comment."%') ";
00405       $l_and=" and ";
00406     }
00407     // internal
00408     $l_s_internal=FormatString($l_s_internal);
00409     if ( $l_s_internal != null ) {
00410       $sql.=$l_and."  jr_internal like ('%$l_s_internal%')  ";
00411       $l_and=" and ";
00412     }
00413     // Poste
00414     $l_poste=FormatString($l_poste);
00415     if ( $l_poste != null ) {
00416       $sql.=$l_and."  jr_grpt_id in (select j_grpt 
00417              from jrnx where j_poste = $l_poste)  ";
00418       $l_and=" and ";
00419     }
00420     // Quick Code
00421     if ( $l_qcode != null ) 
00422       {
00423         $sql.=$l_and."  jr_grpt_id in ( select j_grpt from 
00424              jrnx where j_qcode = '$l_qcode')";
00425         $l_and=" and ";
00426       }
00427     // if not admin check filter 
00428     $User=new cl_user(DbConnect());
00429     $User->Check();
00430     if ( $User->admin == 0 ) 
00431     {
00432       $sql.=$l_and." jr_def_id in ( select uj_jrn_id ".
00433         " from user_sec_jrn where ".
00434         " uj_login='".$_SESSION['g_user']."'".
00435         " and uj_priv in ('R','W'))";
00436     }
00437     $sql.=" order by jr_date_order asc";
00438   }// p_array != null
00439   // Count 
00440   $count=CountSql($p_cn,$sql);
00441   // Add the limit 
00442   $sql.=$limit.$offset;
00443 
00444   // Execute SQL stmt
00445   $Res=ExecSql($p_cn,$sql);
00446 
00447   //starting from here we can refactor, so that instead of returning the generated HTML, 
00448   //this function returns a tree structure.
00449   
00450   $r="";
00451   $r.=JS_VIEW_JRN_DETAIL;
00452   $r.=JS_VIEW_JRN_CANCEL;
00453   $r.=JS_VIEW_JRN_MODIFY;
00454 
00455   $Max=pg_NumRows($Res);
00456 
00457   //TODO: correct this message. 
00458   if ($Max==0) return array(0,"Aucun enregistrement trouvé");
00459 
00460   $r.='<table style="width:100%;border:solid blue 2px ;border-style:outset;">';
00461   $l_sessid=$_REQUEST['PHPSESSID'];
00462   $r.="<tr class=\"even\">";
00463  $r.="<th> Internal </th>";
00464   $r.="<th> Date </th>";
00465   $r.="<th> Echéance </th>";
00466   $r.="<th> Description</th>";
00467   $r.="<th> Montant </th>";
00468   // if $p_paid is not equal to 0 then we have a paid column
00469   if ( $p_paid != 0 ) 
00470     {
00471       $r.="<th> Pay&eacute;</th>";
00472     }
00473   $r.="<th>Op. Concernée</th>";
00474   $r.="<th>Document</th>";
00475   $r.="</tr>";
00476 
00477   for ($i=0; $i < $Max;$i++) {
00478 
00479     //STAN the rows here must be stored in an array
00480     
00481     $row=pg_fetch_array($Res,$i);
00482     
00483     if ( $i % 2 == 0 ) $tr='<TR class="odd">'; 
00484                 else $tr='<TR class="even">';
00485     $r.=$tr;
00486     //internal code
00487         // button  modify
00488     $r.="<TD>";
00489     $r.=sprintf('<A class="detail" HREF="javascript:modifyOperation(\'%s\',\'%s\',\'%s\')" >%s</A>',
00490                 $row['jr_id'], $l_sessid, $p_jrn, $row['jr_internal']);
00491     $r.="</TD>";
00492     // date
00493     $r.="<TD>";
00494     $r.=$row['jr_date'];
00495     $r.="</TD>";
00496     // echeance
00497     $r.="<TD>";
00498     $r.=$row['jr_ech'];
00499     $r.="</TD>";
00500     
00501     // comment
00502     $r.="<TD>";
00503     $r.=$row['jr_comment'];
00504     $r.="</TD>";
00505     
00506     // Amount
00507     // If the ledger is financial :
00508     // the credit must be negative and written in red
00509     // Get the jrn type
00510     $jrn_prop=GetJrnProp($p_cn,$row['jrn_def_id'],1);  
00511     $positive=0;
00512 
00513     // Check ledger type
00514      if (  $jrn_prop['jrn_def_type'] == 'FIN' ) 
00515      {
00516        $positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ".
00517                            " where jr_id=".$row['jr_id']." and (j_poste like '55%' or j_poste like '57%' )".
00518                            " and j_debit='f'");
00519      }
00520     $r.="<TD align=\"right\">";
00521     //STAN $positive always == 0
00522      $r.=( $positive != 0 )?"<font color=\"red\">  - ".sprintf("%8.2f",$row['jr_montant'])."</font>":sprintf("%8.2f",$row['jr_montant']);
00523     $r.="</TD>";
00524 
00525 
00526     // Show the paid column if p_paid is not null
00527     if ( $p_paid !=0 )
00528       {
00529         $w=new widget("checkbox");
00530         $w->name="rd_paid".$row['jr_id'];
00531         $w->selected=($row['jr_rapt']=='paid')?true:false;
00532         // if p_paid == 2 then readonly
00533         $w->readonly=( $p_paid == 2)?true:false;
00534         $h=new widget("hidden");
00535         $h->name="set_jr_id".$row['jr_id'];
00536         $r.='<TD>'.$w->IOValue().$h->IOValue().'</TD>';
00537       }
00538     
00539     // Rapprochement
00540     $a=GetConcerned($p_cn,$row['jr_id']);
00541     $r.="<TD>";
00542     if ( $a != null ) {
00543       // $r.="operation concernée ";
00544       
00545       foreach ($a as $key => $element) 
00546       {      
00547               $r.= "<A class=\"detail\" HREF=\"javascript:viewDetail('".GetGrpt($p_cn,$element)."','$l_sessid')\" > ".GetInternal($p_cn,$element)."</A>";
00548       }//for
00549     }// if ( $a != null ) {
00550     $r.="</TD>";
00551 
00552     if ( $row['jr_valid'] == 'f'  ) {
00553       $r.="<TD> Opération annulée</TD>";
00554     }    else {
00555       // all operations can be removed either by setting to 0 the amount
00556       // or by writing the opposite operation if the period is closed
00557       $r.="<TD>";
00558       // cancel operation
00559       $r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\',\'%s\')">',
00560                   "Annuler",$row['jr_grpt_id'],$l_sessid,$p_jrn);
00561       $r.="</TD>";
00562     } // else
00563     //document
00564     $r.="<TD>".sprintf('<A class="detail" HREF="show_pj.php?jrn=%s&jr_grpt_id=%s">%s</A>',
00565                        $p_jrn,
00566                        $row['jr_grpt_id'],
00567                        $row['jr_pj_name'])."</TD>";
00568     
00569     // end row
00570     $r.="</tr>";
00571     
00572   }
00573   $r.="</table>";
00574   
00575 return array ($count,$r);
00576 }

UpdateComment p_cn,
p_jr_id,
p_comment
 

Update comment in jrn.

UpdateComment ($p_cn,$p_jr_id,$p_comment)

parm :

  • database conn.
    • jrn.jr_id
    • comment gen :
  • none return:
    • none

Definition at line 811 of file user_common.php.

References $Res, ExecSql(), FormatString(), and p_comment.

00811                                                    {
00812   $p_comment=FormatString($p_comment);
00813   $Res=ExecSql($p_cn,"update jrn set jr_comment='".$p_comment."'
00814                                where jr_id = $p_jr_id"); 
00815 
00816 }

VerifyOperationDate p_cn,
p_periode,
p_date
 

Verify if the date is a valid date the date is in the default period the period is not closed.

VerifyOperationDate ($p_cn,$p_user,$p_date)

parm :

  • db connection

user

  • date gen :
    • none return:

null if error or date if ok

Definition at line 654 of file user_common.php.

References $msg, cmpDate(), echo_debug(), echo_error(), GetPeriode(), isDate(), and PeriodeClosed().

Referenced by FormODS().

00654                                                        {
00655 
00656   // Verify the date
00657   if ( isDate($p_date) == null ) { 
00658           echo_error("Invalid date $p_date");
00659           echo_debug('user_common.php',__LINE__,"Invalid date $p_date");
00660           echo "<SCRIPT> alert('INVALID DATE $p_date !!!!');</SCRIPT>";
00661           return null;
00662                 }
00663 // userPref contient la periode par default
00664     list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00665 
00666     // Date dans la periode active
00667     echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demandée $p_date");
00668     if ( cmpDate($p_date,$l_date_start)<0 || 
00669          cmpDate($p_date,$l_date_end)>0 )
00670       {
00671                   $msg="Not in the active periode please change your preference";
00672                         echo_error($msg); echo_error($msg);     
00673                         echo "<SCRIPT>alert('$msg');</SCRIPT>";
00674                         return null;
00675       }
00676     // Periode fermée 
00677     if ( PeriodeClosed ($p_cn,$p_periode)=='t' )
00678       {
00679                 $msg="This periode is closed please change your preference";
00680                 echo_error($msg); echo_error($msg);     
00681                 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00682                 return null;
00683       }
00684     return $p_date;
00685 }

withStock p_cn,
p_f_id
 

return true if we manage stock for it value is stored in attr_value

withStock($p_cn,$p_f_id)

parm :

  • $p_cn database connection

$p_f_id fiche.f_id gen :

  • none return: none

Definition at line 631 of file user_common.php.

References $a, and getFicheAttribut().

00632 {
00633   $a=getFicheAttribut($p_cn,$p_f_id, ATTR_DEF_STOCK);
00634   if ( $a == "1" ) return true;
00635   return false;
00636 
00637 }