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

user_form_ach.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
00024 require_once("constant.php");
00025 require_once("class_widget.php");
00026 require_once("preference.php");
00027 require_once("fiche_inc.php");
00028 require_once("user_common.php");
00029 require_once("class_parm_code.php");
00044 function FormAchInput($p_cn,$p_jrn,$p_periode,$p_array=null,$p_submit="",$pview_only=true,$p_article=1)
00045 { 
00046 echo_debug('user_form_ach.php',__LINE__,"Enter FormAchInput($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$pview_only,$p_article");
00047   if ( $p_array != null) {
00048     // array contains old value
00049     extract($p_array);
00050   }
00051   // The date
00052   list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00053   $op_date=( ! isset($e_date) ) ?substr($l_date_start,2,8):$e_date;
00054   $e_ech=(isset($e_ech))?$e_ech:"";
00055   $e_comm=(isset($e_comm))?$e_comm:"";
00056 
00057   // Save old value and set a new one
00058   echo_debug('user_form_ach.php',__LINE__,"form_input.php.FormSell_op_date is $op_date");
00059   $r="";
00060   if ( $pview_only == false) {
00061     $r.=JS_SEARCH_CARD;
00062     $r.=JS_SHOW_TVA;    
00063     $r.=JS_TVA;
00064     // Compute href
00065     $href=basename($_SERVER['SCRIPT_NAME']);
00066 
00067     switch ($href)
00068       {
00069         // user_jrn.php
00070       case 'user_jrn.php':
00071         $href="user_jrn.php?action=new&p_jrn=$p_jrn";
00072         break;
00073       case 'commercial.php':
00074         $href="commercial.php?p_action=depense&p_jrn=$p_jrn";
00075         break;
00076       default:
00077         echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri');
00078         exit (-1);
00079       }
00080       
00081 
00082     //    $r.="<FORM NAME=\"form_detail\"  enctype=\"multipart/form-data\" ACTION=\"user_jrn.php?action=new&p_jrn=$p_jrn\" METHOD=\"POST\">";
00083     $r.="<FORM NAME=\"form_detail\"  enctype=\"multipart/form-data\" ACTION=\"$href\" METHOD=\"POST\">";
00084   }
00085 
00086   $sql="select jrn_def_id as value,jrn_def_name as label from jrn_def where jrn_def_type='VEN'";
00087   $list=GetArray($p_cn,$sql);
00088   $r.='<TABLE>';
00089   // Date widget
00090   //--
00091   $Date=new widget("text");
00092   $Date->SetReadOnly($pview_only);
00093   $Date->table=1;
00094   $r.="<tr>";
00095   $r.=$Date->IOValue("e_date",$op_date,"Date");
00096   $r.="</tr>";
00097   // Payment limit widget
00098   //--
00099   $Echeance=new widget("text");
00100   $Echeance->SetReadOnly($pview_only);
00101   $Echeance->table=1;
00102   $r.="<tr>";
00103   $r.=$Echeance->IOValue("e_ech",$e_ech,"Echeance");
00104   $r.="</tr>";
00105   // Comment
00106   //--
00107   $Commentaire=new widget("text");
00108   $Commentaire->table=1;
00109   $Commentaire->SetReadOnly($pview_only);
00110   $Commentaire->size=80;
00111   $r.="<tr>";
00112   $r.=$Commentaire->IOValue("e_comm",$e_comm,"Description");
00113   $r.="</tr>";
00114   include_once("fiche_inc.php");
00115   // Display the supplier
00116   //--
00117   $fiche='cred';
00118   echo_debug('user_form_ach.php',__LINE__,"Fournisseurs Nombre d'enregistrement ".sizeof($fiche));
00119   // Save old value and set a new one
00120   $e_client=( isset ($e_client) )?$e_client:"";
00121 
00122   $e_client_label="";  
00123 
00124   // retrieve e_client_label
00125   if ( isNumber($e_client) == 1 ) {
00126     if ( isFicheOfJrn($p_cn,$p_jrn,$e_client,'cred') == 0 ) {
00127       $msg="Fiche inexistante !!! ";
00128       echo_error($msg); echo_error($msg);       
00129       //      echo "<SCRIPT>alert('$msg');</SCRIPT>";
00130       $e_client="";
00131     } else {
00132       $a_client=GetFicheAttribut($p_cn,$e_client);
00133       if ( $a_client != null)   
00134           $e_client_label=$a_client['vw_name']."  adresse ".$a_client['vw_addr']."  ".$a_client['vw_cp'];
00135     }
00136   }
00137   // widget search
00138   $W1=new widget("js_search");
00139   $W1->label="Fournisseur";
00140   $W1->name="e_client";
00141   $W1->value=$e_client;
00142   $W1->extra=$fiche;  // list of card
00143   $W1->extra2=$p_jrn;
00144   $r.="<TR>".$W1->IOValue();
00145   $client_label=new widget("span");
00146   $r.= $client_label->IOValue("e_client_label",$e_client_label)."</TD></TR>";
00147   $r.="</TABLE>";
00148   // Set correctly the REQUEST param for jrn_type 
00149   $h=new widget('hidden');
00150   $h->name='jrn_type';
00151   $h->value='ACH';
00152   $r.=$h->IOValue();
00153 
00154   // Record the current number of article
00155   $Hid=new widget('hidden');
00156   $r.=$Hid->IOValue("nb_item",$p_article);
00157   $e_comment=(isset($e_comment))?$e_comment:"";
00158 
00159 
00160   // Start the div for item to sell
00161   $r.="<DIV>";
00162   $r.='<H2 class="info">Articles</H2>';
00163   $r.='<TABLE>';
00164   $r.='<TR>';
00165   $r.="<th></th>";
00166   $r.="<th>Code</th>";
00167   $r.="<th>Dénomination</th>";
00168   $r.="<th>prix</th>";
00169   $r.="<th>tva</th>";
00170   $r.="<th>quantité</th>";
00171   $r.='</TR>';
00172   // For each article
00173   // compute amount
00174   // verify if card exists
00175   // retrieve vat label
00176   //--
00177   for ($i=0;$i< $p_article;$i++) {
00178     // Code id
00179     $march=(isset(${"e_march$i"}))?${"e_march$i"}:"";
00180     $march_sell=(isset(${"e_march".$i."_sell"}))?${"e_march".$i."_sell"}:"";
00181     $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
00182 
00183     $march_tva_label="";
00184     $march_label="";
00185 
00186     // If $march has a value
00187     if ( isFicheOfJrn($p_cn,$p_jrn,$march,'deb') == 0 ) {
00188         $msg="Fiche inexistante !!! ";
00189         echo_error($msg); echo_error($msg);     
00190         $march="";
00191     } else {
00192         // retrieve the tva label and name
00193       $a_fiche=GetFicheAttribut($p_cn, $march);
00194       if ( $a_fiche != null ) {
00195         if ( $march_tva_id == "" ) {
00196           $march_tva_id=$a_fiche['tva_id'];
00197           $march_tva_label=$a_fiche['tva_label'];
00198         }
00199         $march_label=$a_fiche['vw_name'];
00200       }
00201     }
00202   
00203     // Show input
00204 
00205     $W1=new widget("js_search");
00206     $W1->label="";
00207     $W1->name="e_march".$i;
00208     $W1->value=$march;
00209     $W1->extra='deb';  // credits
00210     $W1->extra2=$p_jrn;
00211     $W1->readonly=$pview_only;
00212     $r.="<TR>".$W1->IOValue()."</TD>";
00213     $Span=new widget ("span");
00214     $Span->SetReadOnly($pview_only);
00215     // card's name
00216     $r.="<TD>".$Span->IOValue("e_march".$i."_label",$march_label)."</TD>";
00217    // price
00218     $Price=new widget("text");
00219     $Price->SetReadOnly($pview_only);
00220     $Price->table=1;
00221     $r.=$Price->IOValue("e_march".$i."_sell",$march_sell);
00222     // vat label
00223     $select_tva=make_array($p_cn,"select tva_id,tva_label from tva_rate order by tva_id",1);
00224     $Tva=new widget("select");
00225     $Tva->table=1;
00226     $Tva->selected=$march_tva_id;
00227     $r.=$Tva->IOValue("e_march$i"."_tva_id",$select_tva);
00228 
00229     // quantity
00230     $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1";
00231     $Quantity=new widget("text");
00232     $Quantity->SetReadOnly($pview_only);
00233     $Quantity->table=1;
00234     $r.=$Quantity->IOValue("e_quant".$i,$quant);
00235     $r.='</TR>';
00236   }
00237 
00238 
00239 
00240   $r.="</TABLE>";
00241   $r.="<hr>";
00242 
00243   if ($pview_only == false ) {
00244     $r.=$p_submit;
00245     $r.="</DIV>";
00246     $r.="</FORM>";
00247   } else {
00248      $r.="</div>";
00249 
00250   }
00251 
00252 
00253 
00254   return $r;
00255 
00256 
00257 }
00270 function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number)
00271 {
00272   echo_debug('user_form_ach.php',__LINE__,"Enter form_verify_input $p_cn,$p_jrn,$p_periode,".var_export($p_array,true).",$p_number");
00273   foreach ($p_array as $name=>$content) {
00274     ${"$name"}=$content;
00275   }
00276   // Verify the date
00277   if ( isDate($e_date) == null ) 
00278     { 
00279       echo_error("Invalid date $e_date");
00280       echo_debug('user_form_ach.php',__LINE__,"Invalid date $e_date");
00281       echo "<SCRIPT> alert('INVALID DATE $e_date !!!!');</SCRIPT>";
00282       return null;
00283     }
00284 // Verify the quantity
00285   for ($o = 0;$o < $p_number; $o++) 
00286     {
00287       if ( isNumber(${"e_quant$o"}) == 0 ) 
00288         {
00289           echo_debug('user_form_ach.php',__LINE__,"invalid quantity ".${"e_quant$o"});
00290           echo_error("invalid quantity ".${"e_quant$o"});
00291           echo "<SCRIPT> alert('INVALID QUANTITY !!!');</SCRIPT>";
00292           return null;
00293         }       
00294     // check if vat is correct
00295     if ( strlen(trim(${"e_march$o"."_tva_id"})) !=0 
00296          and 
00297          ${"e_march$o"."_tva_id"} != "-1")
00298       {
00299       // vat is given we check it now check if valid
00300       if (isNumber(${"e_march$o"."_tva_id"}) == 0
00301                or CountSql($p_cn,"select tva_id from tva_rate where tva_id=".${"e_march$o"."_tva_id"}) ==0)
00302         {
00303           $msg="Invalid TVA !!! e_march".$o."_tva_id = ".${"e_march".$o."_tva_id"};
00304           echo_error($msg); echo_error($msg);   
00305           echo "<SCRIPT>alert('$msg');</SCRIPT>";
00306           return null;
00307         
00308         }
00309       }
00310     
00311     }
00312 
00313   // Verify the ech
00314  if (strlen($e_ech) != 0 and isNumber($e_ech)  == 0 and  isDate ($e_ech) == null ) 
00315    {
00316      $msg="Echeance invalide";
00317      echo_error($msg); echo_error($msg);        
00318      echo "<SCRIPT>alert('$msg');</SCRIPT>";
00319      return null;
00320    } 
00321  // Verify is a client is set
00322 //  if ( isNumber($e_client)    == 0) 
00323 //    {
00324 //      $msg="Client inexistant";
00325 //      echo_error($msg); echo_error($msg);     
00326 //      echo "<SCRIPT>alert('$msg');</SCRIPT>";
00327 //      return null;
00328 //    }
00329 
00330  // if ech is a number of days then compute date limit
00331  if ( strlen($e_ech) != 0 and isNumber($e_ech) == 1) 
00332    {
00333      list($day,$month,$year)=explode(".",$e_date);
00334      echo_debug('user_form_ach.php',__LINE__," date $e_date = $day.$month.$year");
00335      $p_ech=date('d.m.Y',mktime(0,0,0,$month,$day+$e_ech,$year));
00336      echo_debug('user_form_ach.php',__LINE__,"p_ech = $e_ech $p_ech");
00337      $e_ech=$p_ech;
00338      $wHidden=new widget("hidden");
00339      $data.=$wHidden->IOValue("e_ech",$e_ech);
00340 # $data.=InputType("","HIDDEN","e_ech",$e_ech);
00341    }
00342 
00343  // Check if the fiche is in the jrn
00344  if (IsFicheOfJrn($p_cn , $p_jrn, $e_client,'cred') == 0 ) 
00345    {
00346      $msg="Client invalid please recheck";
00347      echo_error($msg);
00348      echo "<SCRIPT>alert('$msg');</SCRIPT>";
00349      return null;
00350    }
00351 
00352  // check if all e_march are in fiche
00353   for ($i=0;$i<$p_number;$i++) 
00354     {
00355       if ( trim(${"e_march$i"})  == "" ) {
00356         // no goods to sell 
00357         continue;
00358     }
00359   
00360 //     // Check wether the f_id is a number
00361 //     if ( isNumber(${"e_march$i"}) == 0 ) {
00362 //       $msg="Fiche inexistante !!! ";
00363 //       echo_error($msg); echo_error($msg);    
00364 //       echo "<SCRIPT>alert('$msg');</SCRIPT>";
00365 //       return null;
00366 //     }
00367     // Check 
00368     if ( isFicheOfJrn($p_cn,$p_jrn,${"e_march$i"},'deb') == 0 ) {
00369       $msg="Fiche inexistante !!! ";
00370       echo_error($msg); echo_error($msg);       
00371       echo "<SCRIPT>alert('$msg');</SCRIPT>";
00372       return null;
00373     }
00374     // check if the  ATTR_DEF_ACCOUNT is set
00375     $poste=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_ACCOUNT);
00376     echo_debug('user_form_ach.php',__LINE__,"poste value = ".$poste."size = ".strlen(trim($poste)));
00377     if ( $poste == null ) 
00378       { 
00379         $msg="La fiche ".${"e_march$i"}." n\'a pas de poste comptable";
00380         echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);        
00381         echo "<SCRIPT>alert('$msg');</SCRIPT>";
00382         return null;
00383         
00384       }
00385     if ( strlen(trim($poste))==0 )
00386       {
00387         $msg="La fiche ".${"e_march$i"}." n\'a pas de poste comptable";
00388         echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);                
00389         echo "<SCRIPT>alert('$msg');</SCRIPT>";
00390         return null;
00391       }
00392     
00393     // Check if the percentage indicated in this field is valid
00394     $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
00395     if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
00396       {
00397         if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) 
00398           {
00399             $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide,il doit être compris entre 0 et 1";
00400                         echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);        
00401                         echo "<SCRIPT>alert('$msg');</SCRIPT>";
00402                         return null;
00403                 
00404                 }
00405         }
00406     // Check if the percentage indicated in this field is valid
00407     $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA_NON_DEDUCTIBLE);
00408     if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
00409       {
00410         if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) 
00411           {
00412             $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1";
00413             echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);    
00414             echo "<SCRIPT>alert('$msg');</SCRIPT>";
00415             return null;
00416             
00417           }
00418       } // Check if the percentage indicated in this field is valid
00419     $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
00420     if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
00421         {
00422           if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) 
00423             {
00424               $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1";
00425               echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);  
00426               echo "<SCRIPT>alert('$msg');</SCRIPT>";
00427               return null;
00428               
00429             }
00430         }
00431     
00432     }
00433 // Verify the userperiode
00434 
00435 // p_periode contient la periode par default
00436   list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00437   
00438   // Date dans la periode active
00439   echo_debug ('user_form_ach',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date");
00440   if ( cmpDate($e_date,$l_date_start)<0 || 
00441        cmpDate($e_date,$l_date_end)>0 )
00442     {
00443       $msg="Not in the active periode please change your preference";
00444       echo_error($msg); echo_error($msg);       
00445       echo "<SCRIPT>alert('$msg');</SCRIPT>";
00446       return null;
00447     }
00448     // Periode fermé
00449     if ( PeriodeClosed ($p_cn,$p_periode)=='t' )
00450       {
00451                 $msg="This periode is closed please change your preference";
00452                 echo_error($msg); echo_error($msg);     
00453                 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00454                 return null;
00455       }
00456     return true;
00457 }
00472 function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_piece=true)
00473 {
00474   $r="";
00475   $data="";
00476   // Keep all the data if hidden
00477   // and store the array in variables
00478   $hidden=new widget("hidden");
00479   foreach ($p_array as $name=>$content) {
00480     $data.=$hidden->IOValue($name,$content);
00481     ${"$name"}=$content;
00482   }
00483   
00484   // start table
00485   $r.='<TABLE>';
00486   // Show the Date
00487   $r.="<tr>";
00488   $r.="<TD>Date : $e_date</TD>";
00489   $r.="</tr>";
00490   // Show the customer Name
00491   $r.="<tr>";
00492   $r.="<TD>Client : ".getFicheName($p_cn,$e_client)."</TD>";
00493   $r.="</tr>";
00494   
00495   // show date limit
00496   $r.="<tr>";
00497   $r.="<TD> Echeance : $e_ech </TD>";
00498   $r.="</tr>";
00499   // Show desc
00500   $r.="<tr>";
00501   $r.="<TD> Description : $e_comm</TD>";
00502   $r.="</tr>";
00503   
00504   $sum_with_vat=0.0;
00505   $sum_march=0.0;
00506   // show all article, price vat and sum
00507   $r.="<TR>";
00508   $r.="<TH>Article</TH>";
00509   $r.="<TH>quantité</TH>";
00510   $r.="<TH>prix unit.</TH>";
00511   $r.="<TH>taux tva</TH>";
00512   $r.="<TH>Montant HTVA</TH>";
00513   $r.="<TH>Montant TVA</TH>";
00514   $r.="<TH>Total</TH>";
00515   $r.="</TR>";
00516   for ($i=0;$i<$p_number;$i++) 
00517     {
00518       if ( trim(${"e_march$i"})  == "" ) 
00519         {
00520           // no goods to sell 
00521           continue;
00522         }
00523       
00524       // Get the name
00525       $fiche_name=getFicheName($p_cn,${"e_march$i"});
00526       
00527       // Quantity
00528       $fiche_quant=${"e_quant$i"};
00529       
00530       // No  row if there is quantity
00531       if ( $fiche_quant == 0.0 ) continue;
00532       
00533 
00534       // If the price is not a number, retrieve the price from the database
00535       if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
00536         $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE);
00537       } else {
00538         $fiche_price=${"e_march$i"."_sell"};
00539       }
00540       
00541     
00542       // VAT 
00543       $vat=(isNumber(${"e_march$i"."_tva_id"})==0 || ${"e_march$i"."_tva_id"}==-1 )?getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA):${"e_march$i"."_tva_id"};
00544       
00545     // vat label
00546     // vat rate
00547       $a_vat=GetTvaRate($p_cn,$vat);
00548       if ( $a_vat == null ) 
00549         {
00550           $vat_label="";
00551           $vat_rate=0.0;
00552         } 
00553       else 
00554         { 
00555           $vat_label=$a_vat['tva_label'];
00556           $vat_rate=$a_vat['tva_rate'];
00557         }               
00558       
00559       // Total card without vat
00560       $fiche_sum=$fiche_price*$fiche_quant;
00561       // Sum of invoice
00562       $sum_march+=$fiche_sum;
00563       // vat of the card
00564       $fiche_amount_vat=$fiche_price*$fiche_quant*$vat_rate;
00565       // value card + vat
00566       $fiche_with_vat=$fiche_price*$fiche_quant*(1+$vat_rate);
00567       // Sum of invoice vat 
00568       $sum_with_vat+=$fiche_with_vat;
00569       // Show the data
00570       $r.='<TR>';
00571       $r.='<TD>'.$fiche_name.'</TD>';
00572       $r.='<TD ALIGN="CENTER">'.$fiche_quant.'</TD>';
00573       $r.='<TD ALIGN="right">'.$fiche_price.'</TD>';
00574       $r.="<TD  ALIGN=\"RIGHT\"> $vat_label </TD>";
00575       $r.='<TD  ALIGN="RIGHT">'.round($fiche_sum,2).'</TD>';
00576       $r.='<TD ALIGN="RIGHT">'.round($fiche_amount_vat,2).'</TD>';
00577       
00578       $r.='<TD>'.round($fiche_with_vat,2).'</TD>';
00579 
00580       $r.="</TR>";
00581     }
00582   
00583   // end table
00584   $r.='</TABLE> ';
00585   $r.='<DIV style="padding:30px;font-size:14px">';
00586   $r.="Total HTVA =".round( $sum_march,2)." <br>";
00587   $r.="Total = ".round($sum_with_vat,2);
00588 
00589  
00590   $r.="</DIV>";
00591   // Compute href
00592   $href=basename($_SERVER['SCRIPT_NAME']);
00593   switch ($href)
00594     {
00595       // user_jrn.php
00596     case 'user_jrn.php':
00597       $href="user_jrn.php?action=new&p_jrn=$p_jrn";
00598       break;
00599     case 'commercial.php':
00600       $href="commercial.php?p_action=depense&p_jrn=$p_jrn";
00601       break;
00602     default:
00603       echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri');
00604       exit (-1);
00605     }
00606 
00607   //  $r.='<FORM METHOD="POST" enctype="multipart/form-data" ACTION="user_jrn.php?action=new&p_jrn='.$p_jrn.'">';
00608   $r.='<FORM METHOD="POST" enctype="multipart/form-data" ACTION="'.$href.'">';
00609   // check for upload piece
00610   // Set correctly the REQUEST param for jrn_type 
00611   $h=new widget('hidden');
00612   $h->name='jrn_type';
00613   $h->value=$_REQUEST['jrn_type'];
00614   $r.=$h->IOValue();
00615 
00616   $file=new widget("file");
00617   $file->table=1;
00618   $r.="<hr>";
00619   $r.= "<table>"; 
00620   if ( $p_piece) $r.="<TR>".$file->IOValue("pj","","Pièce justificative")."</TR>";
00621   $r.="</table>";
00622   $r.="<hr>";
00623   
00624   $r.=$data;
00625   $r.=$p_submit;
00626   
00627   $r.='</FORM>';
00628   
00629   return $r;
00630   
00631 }
00632 
00662 function RecordSell($p_cn,$p_array,$p_user,$p_jrn)
00663 {
00664   echo_debug('user_form_ach',__LINE__,"function RecordSell($p_cn,$p_array,$p_user,$p_jrn)");
00665   foreach ( $p_array as $v => $e)
00666   {
00667     ${"$v"}=$e;
00668   }
00669 
00670   // Get the default period
00671   $periode=$p_user->GetPeriode();
00672   $amount=0.0;
00673   $amount_jrn=0.0;
00674   $sum_tva_nd=0.0;
00675   // Computing total customer
00676   for ($i=0;$i<$nb_item;$i++) {
00677     // store quantity & goods in array
00678     $a_good[$i]=${"e_march$i"};
00679     $a_quant[$i]=${"e_quant$i"};
00680     $a_price[$i]=0;
00681     $a_vat_good[$i]=${"e_march$i"."_tva_id"};
00682     // check wether the price is set or no
00683     if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
00684       if ( $a_good[$i] !="" ) {
00685              // If the price is not set we have to find it from the database
00686              $a_price[$i]=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE);
00687            } 
00688     } else {
00689       // The price is valid
00690       $a_price[$i]=${"e_march$i"."_sell"};
00691     }
00692     $cost=$a_price[$i]*$a_quant[$i];
00693     $amount+=$cost;
00694     $amount_jrn+=$cost;
00695     echo_debug('user_form_ach.php',__LINE__,'Total customer:'.$amount_jrn);
00696   }
00697   //  $amount_jrn=round(
00698   $comm=FormatString($e_comm);
00699 
00700   // Compute vat with ded
00701   echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat");
00702   $a_vat=ComputeTotalVat($p_cn,$a_good,$a_quant,$a_price,$a_vat_good,false);
00703         
00704   StartSql($p_cn);      
00705 
00706   // Compute the j_grpt
00707   $seq=NextSequence($p_cn,'s_grpt');
00708 
00709 
00710 
00711   // Credit = goods 
00712   for ( $i = 0; $i < $nb_item;$i++) {
00713 
00714     $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT);
00715           
00716     // don't record operation of 0
00717     if ( $a_price[$i]*$a_quant[$i] == 0 ) continue;
00718 
00719     $amount=$a_price[$i]*$a_quant[$i];
00720     // Put the non deductible part into a special account
00721     $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
00722     echo_debug('user_form_ach.php',__LINE__,"value non ded : $non_dedu");
00723     if ( $non_dedu != null && strlen(trim($non_dedu)) != 0)
00724       {
00725         $nd_amount=round($a_quant[$i]*$a_price[$i]*$non_dedu,2);
00726 
00727         // save it
00728           echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,'6740',$e_date,round($nd_amount,2),$seq,$periode);");
00729           $dna=new parm_code($p_cn,'DNA');
00730         $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$dna->p_value,$e_date,round($nd_amount,2),$seq,$periode);
00731         if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00732         $amount=$amount-$nd_amount;
00733       }
00734     // Put the non deductible part into a special account
00735     $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE);
00736     echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu");
00737     if ( $non_dedu != null && strlen(trim($non_dedu)) != 0)
00738       {
00739         $lvat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i],
00740                             $a_vat_good[$i] );
00741         $ded_vat=($lvat != null )?$lvat*$non_dedu:0;
00742         $ded_vat=round($ded_vat,2);
00743         $sum_tva_nd+=$ded_vat;
00744 
00745         // compute the NDA TVA
00746         $tva_dna=new parm_code($p_cn,'TVA_DNA');
00747         echo_debug('user_form_ach.php',__LINE__,
00748                    "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_dna->p_value.",$e_date,round($ded_vat,2),$seq,$periode);");
00749 
00750         $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_dna->p_value,$e_date,round($ded_vat,2),$seq,$periode);
00751         if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00752       }
00753     
00754     // Put the non deductible part into a special account
00755     $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
00756     echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu");
00757     if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
00758         {
00759           $lvat=ComputeVat($p_cn,       $a_good[$i],$a_quant[$i],$a_price[$i],
00760                            $a_vat_good[$i] );
00761           $ded_vat=($lvat != null )?$lvat*$non_dedu:0;
00762           
00763           $sum_tva_nd+=round($ded_vat,2);
00764 
00765           // Save it 
00766           $tva_ded_impot=new parm_code($p_cn,'TVA_DED_IMPOT');
00767           echo_debug('user_form_ach.php',__LINE__,
00768                      "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_ded_impot->p_value.",$e_date,round($ded_vat,2),$seq,$periode);");
00769 
00770           $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_ded_impot->p_value,$e_date,round($ded_vat,2),$seq,$periode);
00771           if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00772         }
00773 
00774 
00775 
00776 
00777     // record into jrnx
00778     echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);");
00779     $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);
00780     if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00781     // always save quantity but in withStock we can find what card need a stock management
00782     if (  InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c') == false ) {
00783       $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00784         echo_debug('user_form_ach.php',__LINE__,"value non ded : ".$a_good[$i]."is");           
00785 
00786   }
00787 
00788   
00789   // Insert Vat
00790   $sum_tva=0.0;
00791   if ( $a_vat  !=  null  ) // no vat
00792 
00793     {
00794 
00795       echo_debug('user_form_ach',__LINE__,'a_vat = '.var_export($a_vat,true));
00796       foreach ($a_vat as $tva_id => $tva_amount ) 
00797         {
00798           echo_debug('user_form_ach',__LINE__," tva_amount = $tva_amount tva_id=$tva_id");
00799           $poste=GetTvaPoste($p_cn,$tva_id,'d');
00800           if ($tva_amount == 0 ) continue;
00801           echo_debug('user_form_ach',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode);");
00802           $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode);
00803           if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");}
00804           $sum_tva+=round($tva_amount,2);
00805         }
00806     }
00807   echo_debug('user_form_ach.php',__LINE__,"echeance = $e_ech");
00808   echo_debug('user_form_ach.php',__LINE__,"sum_tva = $sum_tva");
00809   echo_debug('user_form_ach.php',__LINE__,"amount_jrn = $amount_jrn");
00810   echo_debug('user_form_ach.php',__LINE__,"sum_tva_nd = $sum_tva_nd");
00811 
00812   // Debit = client
00813   $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT);
00814   echo_debug('user_form_achat.php',__LINE__,"get e_client $e_client poste $poste");
00815   echo_debug('user_form_achat.php',__LINE__,"insert client");
00816 
00817   $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode);
00818   if ( $r == false) { $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00819 
00820   $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"--",round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode);
00821   if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");}
00822   // Set Internal code and Comment
00823   $internal=SetInternalCode($p_cn,$seq,$p_jrn);
00824   $comment=(FormatString($e_comm) == null )?$internal." Fournisseur : ".GetFicheName($p_cn,$e_client):FormatString($e_comm);
00825 
00826   // Update and set the invoice's comment 
00827   $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
00828   if ( $Res == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__"); };
00829 
00830   if ( isset ($_FILES))
00831     save_upload_document($p_cn,$seq);
00832 
00833 
00834   Commit($p_cn);
00835 
00836   return array($internal,$comment);
00837 }
00838 
00839 ?>