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

user_form_fin.php

Go to the documentation of this file.
00001 <?
00002 /*
00003  *   This file is part of PhpCompta.
00004  *
00005  *   PhpCompta is free software; you can redistribute it and/or modify
00006  *   it under the terms of the GNU General Public License as published by
00007  *   the Free Software Foundation; either version 2 of the License, or
00008  *   (at your option) any later version.
00009  *
00010  *   PhpCompta is distributed in the hope that it will be useful,
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *   GNU General Public License for more details.
00014  *
00015  *   You should have received a copy of the GNU General Public License
00016  *   along with PhpCompta; if not, write to the Free Software
00017  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 */
00019 /* $Revision$ */
00020 // Copyright Author Dany De Bontridder ddebontridder@yahoo.fr
00021 require_once("class_widget.php");
00022 require_once("constant.php");
00023 require_once("preference.php");
00024 require_once("fiche_inc.php");
00025 require_once("user_common.php");
00042 function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number)
00043 {
00044   foreach ($p_array as $name=>$content) {
00045     ${"$name"}=$content;
00046   }
00047   // Verify the date
00048   if ( isDate($e_date) == null ) { 
00049           echo_error("Invalid date $e_date");
00050           echo_debug('user_form_fin.php',__LINE__,"Invalid date $e_date");
00051           echo "<SCRIPT> alert('INVALID DATE $e_date !!!!');</SCRIPT>";
00052           return null;
00053                 }
00054 
00055 
00056  // Check if the fiche is in the jrn
00057  if (IsFicheOfJrn($p_cn , $p_jrn, $e_bank_account,'deb') == 0 ) 
00058    {
00059      $msg="Mauvais compte en banque";
00060      echo_error($msg);echo_debug('user_form_fin.php',__LINE__,$msg);    
00061      echo "<SCRIPT>alert('$msg');</SCRIPT>";
00062      return null;
00063    }
00064 
00065  // check if all e_march are in fiche
00066   for ($i=0;$i<$p_number;$i++) {
00067     if ( trim(${"e_other$i"})  == "" ) {
00068       // nothing to do
00069       continue;
00070     }
00071         // Check amount
00072     if ( isNumber(${"e_other".$i."_amount"}) == 0) {
00073                 $msg="Montant invalide !!! ";
00074                 echo_error($msg); echo_debug('user_form_fin.php',__LINE__,$msg);        
00075                 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00076                 return null;
00077         }
00078     // Check 
00079     if ( isFicheOfJrn($p_cn,$p_jrn,${"e_other$i"},'cred') == 0 ) {
00080       $msg="Fiche inexistante !!! ";
00081       echo_error($msg);echo_debug('user_form_fin.php',__LINE__,$msg);   
00082       echo "<SCRIPT>alert('$msg');</SCRIPT>";
00083       return null;
00084     }
00085         // check if the  ATTR_DEF_ACCOUNT is set
00086         $poste=GetFicheAttribut($p_cn,${"e_other$i"},ATTR_DEF_ACCOUNT);
00087         if ( $poste == null ) 
00088         {       
00089                 $msg="La fiche ".${"e_other$i"}." n\'a pas de poste comptable";
00090                 echo_error($msg); echo_debug('user_form_fin.php',__LINE__,$msg);        
00091                 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00092                 return null;
00093         
00094         }
00095         if ( strlen(trim($poste))==0 )
00096         {
00097                 $msg="La fiche ".${"e_other$i"}." n\'a pas de poste comptable";
00098                 echo_error($msg); echo_debug('user_form_fin.php',__LINE__,$msg);        
00099                 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00100         }
00101 
00102   }
00103 // Verify the userperiode
00104 
00105 // p_periode contient la periode par default
00106   list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00107   
00108   // Date dans la periode active
00109   echo_debug ('user_form_fin',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date");
00110   if ( cmpDate($e_date,$l_date_start)<0 || 
00111        cmpDate($e_date,$l_date_end)>0 )
00112     {
00113       $msg="Not in the active periode please change your preference";
00114       echo_error($msg); echo_error($msg);       
00115       echo "<SCRIPT>alert('$msg');</SCRIPT>";
00116       return null;
00117     }
00118     // Periode ferm� 
00119     if ( PeriodeClosed ($p_cn,$p_periode)=='t' )
00120       {
00121                 $msg="This periode is closed please change your preference";
00122                 echo_error($msg); echo_error($msg);     
00123                 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00124                 return null;
00125       }
00126     return true;
00127 }
00128 
00129 
00146 function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=true,$p_item=4,$p_save=false)
00147 { 
00148   include_once("poste.php");
00149   if ( $p_array != null ) {
00150     // array contains old value
00151     foreach ( $p_array as $a=>$v) {
00152       ${"$a"}=$v;
00153     }
00154   }
00155   // The date
00156   list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00157   $flag=(isset($e_date))?1:0;
00158   $e_date=( ! isset($e_date) ) ? substr($l_date_start,2,8):$e_date;
00159 
00160   // Comment
00161   $e_comment=(isset($e_comment))?$e_comment:"";
00162 
00163   $r="";
00164   if ( $pview_only == false) {
00165     $r.=JS_SEARCH_CARD;
00166     $r.=JS_CONCERNED_OP;
00167   }
00168   // Compute href
00169   $href=$_SERVER['SCRIPT_NAME'];
00170   switch ($href)
00171     {
00172       // user_jrn.php module "Comptable"
00173     case '/user_jrn.php':
00174       $href="user_jrn.php?action=new&p_jrn=$p_jrn";
00175       break;
00176       // commercial.php  module "Gestion"
00177     case '/commercial.php':
00178       $href="commercial.php?p_action=bank&p_jrn=$p_jrn";
00179       break;
00180     default:
00181       echo_error('user_form_fin.php',__LINE__,'Erreur invalid request uri');
00182       exit (-1);
00183     }
00184 
00185   $r.="<FORM NAME=\"form_detail\" enctype=\"multipart/form-data\" ACTION=\"$href\" METHOD=\"POST\">";
00186   $r.='<TABLE>';
00187   $Date=new widget("text");
00188   $Date->SetReadOnly($pview_only);
00189   $Date->table=1;
00190   $r.="<tr>";
00191   $r.=$Date->IOValue("e_date",$e_date,"Date");
00192   $r.="</tr>";
00193 
00194 
00195   include_once("fiche_inc.php");
00196   $r.='<INPUT TYPE="HIDDEN" name="nb_item" value="'.$p_item.'">';
00197 
00198   // bank_account operation
00199   // Save old value and set a new one
00200   $e_bank_account=( isset ($e_bank_account) )?$e_bank_account:"";
00201   $e_bank_account_label="";  
00202 
00203     // retrieve e_bank_account_label
00204   if ( $e_bank_account != ""  ) {
00205       $a_client=GetFicheAttribut($p_cn,$e_bank_account);
00206       if ( $a_client != null)   
00207         $e_bank_account_label=$a_client['vw_name']."  adresse ".$a_client['vw_addr']."  ".$a_client['vw_cp'];
00208           }  
00209   //  search widget
00210     $W1=new widget("js_search");
00211     $W1->readonly=$pview_only;
00212     $W1->label="Banque";
00213     $W1->name="e_bank_account";
00214     $W1->value=$e_bank_account;
00215     $W1->extra=FICHE_TYPE_FIN;  // credits
00216     $W1->extra2=$p_jrn;
00217     $r.="<TR>".$W1->IOValue()."</TD>";
00218 
00219     $r.="</TABLE>";
00220   
00221     $Span=new widget ("span");
00222     $Span->SetReadOnly($pview_only);
00223     $r.="<TD>".$Span->IOValue("e_bank_account_label",$e_bank_account_label)."</TD>";
00224 
00225   
00226   // ComputeBanqueSaldo
00227   // 
00228   if ( $pview_only == true ) {
00229     $solde=GetSolde($p_cn,GetFicheAttribut($p_cn,$e_bank_account,ATTR_DEF_ACCOUNT));
00230     $r.=" <b> Solde = ".$solde." </b>";
00231     $new_solde=$solde;
00232   }
00233 
00234   // Start the div for item to move money
00235   $r.="<DIV>";
00236   $r.='<H2 class="info">Actions</H2>';
00237   $r.='<TABLE>';
00238   $r.="<TR>";
00239   $r.="<th></TH>";
00240   $r.="<th>code</TH>";
00241   $r.="<th>D&eacute;nomination</TH>";
00242   $r.="<th>Description</TH>";
00243   $r.="<th>Montant</TH>";
00244   $r.='<th colspan="2"> Op. Concern&eacute;</th>';
00245   $r.="</TR>";
00246   // Parse each " tiers" 
00247     for ($i=0; $i < $p_item; $i++) {
00248       $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:"";
00249       $tiers_label="";
00250       $tiers_amount=(isset(${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0;
00251   
00252       $tiers_comment=(isset (${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:"";
00253     // If $tiers has a value
00254     if ( $tiers != ""  ) 
00255         {
00256                 // retrieve the tva label and name
00257                 $a_fiche=GetFicheAttribut($p_cn, $tiers);
00258                 if ( $a_fiche != null ) {
00259                 $tiers_label=$a_fiche['vw_name'];
00260                 }
00261         }
00262     ${"e_other$i"."_amount"}=(isset (${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0;
00263 
00264     $W1=new widget("js_search");
00265     $W1->label="";
00266     $W1->name="e_other".$i;
00267     $W1->value=$tiers;
00268     $W1->extra='cred';  // credits
00269     $W1->extra2=$p_jrn;
00270     $W1->readonly=$pview_only;
00271     $r.="<TR>".$W1->IOValue()."</TD>";
00272     // label
00273     $other=new widget("span");
00274     $r.="<TD>";
00275     $r.=$other->IOValue("e_other$i"."_label", $tiers_label);
00276     // Comment
00277     $wComment=new widget("text");
00278     $wComment->table=1;
00279     $wComment->SetReadOnly($pview_only);
00280     $r.=$wComment->IOValue("e_other$i"."_comment",$tiers_comment);
00281     // amount
00282     $wAmount=new widget("text");
00283     $wAmount->table=1;
00284     $wAmount->size=7;
00285     $wAmount->SetReadOnly($pview_only);
00286     $r.=$wAmount->IOValue("e_other$i"."_amount",$tiers_amount);
00287     // concerned
00288     ${"e_concerned".$i}=(isset(${"e_concerned".$i}))?${"e_concerned".$i}:"";
00289     $wConcerned=new widget("js_concerned");
00290     $wConcerned->SetReadOnly($pview_only);
00291     $r.=$wConcerned->IOValue("e_concerned".$i,${"e_concerned".$i});
00292     $r.='</TR>';
00293    // if not recorded the new amount must be recalculate
00294    // if recorded the old amount is recalculated
00295     if ( $pview_only == true)      
00296       $new_solde=($p_save==false)?$new_solde+$tiers_amount:$new_solde-$tiers_amount;
00297  }
00298 
00299 $r.="</TABLE>";
00300 
00301  if ( $pview_only==true && $p_save==false) {
00302    // check for upload piece
00303    $file=new widget("file");
00304    $file->table=1;
00305    $r.="<hr>";
00306    $r.= "<table>"; 
00307    $r.="<TR>".$file->IOValue("pj","","Pi&egrave;ce justificative")."</TR>";
00308    $r.="</table>";
00309    $r.="<hr>";
00310  }
00311  // Set correctly the REQUEST param for jrn_type 
00312  $h=new widget('hidden');
00313  $h->name='jrn_type';
00314  $h->value='FIN';
00315  $r.=$h->IOValue();
00316 
00317 $r.=$p_submit;
00318 $r.="</DIV>";
00319 $r.="</FORM>";
00320 
00321 // if view_only is true
00322 //Put the new saldo here (old saldo - operation)
00323  if ( $pview_only==true)  {
00324    // if not recorded the new amount must be recalculate
00325    if ( $p_save == false) {
00326      $r.=" <b> Ancien Solde = ".$solde." </b><br>";
00327      $r.=" <b> Nouveau Solde = ".$new_solde." </b><br>";
00328    }
00329    // if recorded the old amount is recalculated
00330    if ($p_save == true ) {
00331      $r.=" <b> Ancien Solde = ".$new_solde." </b><br>";
00332      $r.=" <b> Nouveau Solde = ".$solde." </b><br>";
00333    }
00334  }
00335  
00336 return $r;
00337 
00338 
00339 }
00340 
00358 function RecordFin($p_cn,$p_array,$p_user,$p_jrn) {
00359   echo_debug('user_form_fin.php',__LINE__,"RecordFin");
00360   foreach ( $p_array as $v => $e)
00361   {
00362     ${"$v"}=$e;
00363   }
00364   // Get the default period
00365   $periode=$p_user->GetPeriode();
00366   
00367   // Debit = banque
00368   $poste_bq=GetFicheAttribut($p_cn,$e_bank_account,ATTR_DEF_ACCOUNT);
00369   StartSql($p_cn);
00370   $amount=0.0;  
00371   // Credit = goods 
00372   for ( $i = 0; $i < $nb_item;$i++) {
00373     // if tiers is set and amount != 0 insert it into the database 
00374     // and quit the loop ?
00375     if ( ${"e_other$i"."_amount"} == 0 ) continue;
00376     $poste=GetFicheAttribut($p_cn,${"e_other$i"},ATTR_DEF_ACCOUNT);
00377 
00378     $amount+=${"e_other$i"."_amount"};
00379     // Record a line for the bank
00380     // Compute the j_grpt
00381     $seq=NextSequence($p_cn,'s_grpt');
00382 
00383     if ( InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste_bq,$e_date,round(${"e_other$i"."_amount"},2),$seq,$periode) == false ) {
00384       $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");
00385     }
00386 
00387 
00388     // Record a line for the other account
00389     if ( ($j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round(${"e_other$i"."_amount"},2),$seq,$periode)) == false )
00390       { $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");}
00391 
00392     echo_debug('user_form_fin.php',__LINE__,"   $j_id=InsertJrnx($p_cn,'d',$p_user,$p_jrn,$poste,$e_date,".${"e_other$i"}."_amount".",$seq,$periode);");
00393 
00394     if ( ($jr_id=InsertJrn($p_cn,$e_date,'',$p_jrn,FormatString(${"e_other$i"."_comment"}),
00395                            round(${"e_other$i"."_amount"},2),$seq,$periode))==false) {
00396       $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");}
00397   
00398     if ( isNumber(${"e_concerned".$i}) == 1 ) {
00399 
00400       InsertRapt($p_cn,$jr_id,${"e_concerned$i"});
00401     }
00402 
00403 
00404   // Set Internal code and Comment
00405     $internal_code=SetInternalCode($p_cn,$seq,$p_jrn);
00406     $comment=$internal_code."  compte : ".GetFicheName($p_cn,$e_bank_account);
00407     if ( FormatString(${"e_other$i"."_comment"}) == null ) {
00408       // Update comment if comment is blank
00409       $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
00410     }
00411     if ( $i == 0 )
00412       {
00413         // first record we upload the files and
00414         // keep variable to update other row of jrn
00415         if ( isset ($_FILES))
00416           $oid=save_upload_document($p_cn,$seq);
00417 
00418       } else {
00419         if ( sizeof($_FILES) != 0 ) 
00420           {
00421             ExecSql($p_cn,"update jrn set jr_pj=".$oid.", jr_pj_name='".$_FILES['pj']['name']."', ".
00422                 "jr_pj_type='".$_FILES['pj']['type']."'  where jr_grpt_id=$seq");
00423           }
00424       }
00425     
00426   } // for nbitem
00427 
00428   Commit($p_cn);
00429   return $internal_code;
00430 }
00431 ?>

Generated on Tue Jun 27 01:39:28 2006 for phpcompta by  doxygen 1.4.4