Go to the source code of this file.
Functions | |
FormAchInput ($p_cn, $p_jrn, $p_periode, $p_array=null, $p_submit="", $pview_only=true, $p_article=1) | |
Display the form for a sell Used to show detail, encode a new invoice or update one. | |
form_verify_input ($p_cn, $p_jrn, $p_periode, $p_array, $p_number) | |
verify if the data to insert are valid | |
FormAchView ($p_cn, $p_jrn, $p_periode, $p_array, $p_submit, $p_number, $p_piece=true) | |
Show the invoice before inserting it the database. | |
RecordSell ($p_cn, $p_array, $p_user, $p_jrn) | |
Record an invoice in the table jrn & jrnx. |
Definition in file user_form_ach.php.
|
verify if the data to insert are valid
Definition at line 270 of file user_form_ach.php. References $msg, CountSql(), echo_debug(), echo_error(), isDate(), isNumber(), and name. 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 $tot=0; 00285 // Verify the quantity 00286 for ($o = 0;$o < $p_number; $o++) 00287 { 00288 if ( isNumber(${"e_quant$o"}) == 0 ) 00289 { 00290 echo_debug('user_form_ach.php',__LINE__,"invalid quantity ".${"e_quant$o"}); 00291 echo_error("invalid quantity ".${"e_quant$o"}); 00292 echo "<SCRIPT> alert('INVALID QUANTITY !!!');</SCRIPT>"; 00293 return null; 00294 } 00295 // check if vat is correct 00296 if ( strlen(trim(${"e_march$o"."_tva_id"})) !=0 00297 and 00298 ${"e_march$o"."_tva_id"} != "-1") 00299 { 00300 // vat is given we check it now check if valid 00301 if (isNumber(${"e_march$o"."_tva_id"}) == 0 00302 or CountSql($p_cn,"select tva_id from tva_rate where tva_id=".${"e_march$o"."_tva_id"}) ==0) 00303 { 00304 $msg="Invalid TVA !!! e_march".$o."_tva_id = ".${"e_march".$o."_tva_id"}; 00305 echo_error($msg); echo_error($msg); 00306 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00307 return null; 00308 00309 } 00310 } 00311 if ( strlen(trim(${"e_march".$o."_sell"})) !=0 && isNumber(${"e_march".$o."_sell"}) == 0 ) 00312 { 00313 echo_debug('user_form_ach.php',__LINE__,"Prix invalide ".${"e_march$o"}); 00314 echo_error("Prix n'est pas un montant valide ".${"e_march$o"}); 00315 echo "<SCRIPT> alert('Prix ".${"e_march".$o."_sell"}." de la fiche ".${"e_march$o"}." n\'est pas un montant valide !!!');</SCRIPT>"; 00316 return null; 00317 00318 } 00319 $tot+=${"e_march".$o."_sell"}*${"e_quant$o"}; 00320 } 00321 00322 // if total amount == 0 we don't go further 00323 if ( $tot == 0 ) 00324 return null; 00325 00326 // Verify the ech 00327 if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null ) 00328 { 00329 $msg="Echeance invalide"; 00330 echo_error($msg); echo_error($msg); 00331 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00332 return null; 00333 } 00334 00335 // if ech is a number of days then compute date limit 00336 if ( strlen($e_ech) != 0 and isNumber($e_ech) == 1) 00337 { 00338 list($day,$month,$year)=explode(".",$e_date); 00339 echo_debug('user_form_ach.php',__LINE__," date $e_date = $day.$month.$year"); 00340 $p_ech=date('d.m.Y',mktime(0,0,0,$month,$day+$e_ech,$year)); 00341 echo_debug('user_form_ach.php',__LINE__,"p_ech = $e_ech $p_ech"); 00342 $e_ech=$p_ech; 00343 $wHidden=new widget("hidden"); 00344 $data.=$wHidden->IOValue("e_ech",$e_ech); 00345 00346 } 00347 00348 // Check if the fiche is in the jrn 00349 if (IsFicheOfJrn($p_cn , $p_jrn, $e_client,'cred') == 0 ) 00350 { 00351 $msg="Client invalid please recheck"; 00352 echo_error($msg); 00353 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00354 return null; 00355 } 00356 // Check if the customer card has a valid account 00357 if ( CheckPoste($p_cn,$e_client) == null ) 00358 return null; 00359 00360 // check if all e_march are in fiche 00361 for ($i=0;$i<$p_number;$i++) 00362 { 00363 if ( trim(${"e_march$i"}) == "" ) { 00364 // no goods to sell 00365 continue; 00366 } 00367 00368 // Check 00369 if ( isFicheOfJrn($p_cn,$p_jrn,${"e_march$i"},'deb') == 0 ) { 00370 $msg="Fiche inexistante !!! "; 00371 echo_error($msg); echo_error($msg); 00372 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00373 return null; 00374 } 00375 if ( CheckPoste($p_cn,${"e_march".$i}) == null ) 00376 return null; 00377 00378 // Check if the percentage indicated in this field is valid 00379 $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_DEPENSE_NON_DEDUCTIBLE); 00380 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) 00381 { 00382 if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) 00383 { 00384 $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide,il doit être compris entre 0 et 1"; 00385 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg); 00386 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00387 return null; 00388 00389 } 00390 } 00391 // Check if the percentage indicated in this field is valid 00392 $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA_NON_DEDUCTIBLE); 00393 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) 00394 { 00395 if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) 00396 { 00397 $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1"; 00398 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg); 00399 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00400 return null; 00401 00402 } 00403 } // Check if the percentage indicated in this field is valid 00404 $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP); 00405 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) 00406 { 00407 if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 ) 00408 { 00409 $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1"; 00410 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg); 00411 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00412 return null; 00413 00414 } 00415 } 00416 00417 } 00418 // Verify the userperiode 00419 00420 // p_periode contient la periode par default 00421 list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); 00422 00423 // Date dans la periode active 00424 echo_debug ('user_form_ach',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); 00425 if ( cmpDate($e_date,$l_date_start)<0 || 00426 cmpDate($e_date,$l_date_end)>0 ) 00427 { 00428 $msg="Not in the active periode please change your preference"; 00429 echo_error($msg); echo_error($msg); 00430 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00431 return null; 00432 } 00433 // Periode fermé 00434 if ( PeriodeClosed ($p_cn,$p_periode)=='t' ) 00435 { 00436 $msg="This periode is closed please change your preference"; 00437 echo_error($msg); echo_error($msg); 00438 echo "<SCRIPT>alert('$msg');</SCRIPT>"; 00439 return null; 00440 } 00441 return true; 00442 }
|
|
Display the form for a sell Used to show detail, encode a new invoice or update one.
Definition at line 44 of file user_form_ach.php. References $fiche, $h, $list, $msg, $p_jrn, $r, $sql, echo_debug(), echo_error(), exit, GetArray(), GetPeriode(), isNumber(), and make_array(). 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 }
|
|
Show the invoice before inserting it the database.
Definition at line 457 of file user_form_ach.php. References $data, $file, $h, $r, echo_error(), exit, getFicheAttribut(), getFicheName(), GetTvaRate(), isNumber(), METHOD, and name. 00458 { 00459 $r=""; 00460 $data=""; 00461 // Keep all the data if hidden 00462 // and store the array in variables 00463 $hidden=new widget("hidden"); 00464 foreach ($p_array as $name=>$content) { 00465 $data.=$hidden->IOValue($name,$content); 00466 ${"$name"}=$content; 00467 } 00468 00469 // start table 00470 $r.='<TABLE>'; 00471 // Show the Date 00472 $r.="<tr>"; 00473 $r.="<TD>Date : $e_date</TD>"; 00474 $r.="</tr>"; 00475 // Show the customer Name 00476 $r.="<tr>"; 00477 $r.="<TD>Client : ".getFicheName($p_cn,$e_client)."</TD>"; 00478 $r.="</tr>"; 00479 00480 // show date limit 00481 $r.="<tr>"; 00482 $r.="<TD> Echeance : $e_ech </TD>"; 00483 $r.="</tr>"; 00484 // Show desc 00485 $r.="<tr>"; 00486 $r.="<TD> Description : $e_comm</TD>"; 00487 $r.="</tr>"; 00488 00489 $sum_with_vat=0.0; 00490 $sum_march=0.0; 00491 // show all article, price vat and sum 00492 $r.="<TR>"; 00493 $r.="<TH>Article</TH>"; 00494 $r.="<TH>quantité</TH>"; 00495 $r.="<TH>prix unit.</TH>"; 00496 $r.="<TH>taux tva</TH>"; 00497 $r.="<TH>Montant HTVA</TH>"; 00498 $r.="<TH>Montant TVA</TH>"; 00499 $r.="<TH>Total</TH>"; 00500 $r.="</TR>"; 00501 for ($i=0;$i<$p_number;$i++) 00502 { 00503 if ( trim(${"e_march$i"}) == "" ) 00504 { 00505 // no goods to sell 00506 continue; 00507 } 00508 00509 // Get the name 00510 $fiche_name=getFicheName($p_cn,${"e_march$i"}); 00511 00512 // Quantity 00513 $fiche_quant=${"e_quant$i"}; 00514 00515 // No row if there is quantity 00516 if ( $fiche_quant == 0.0 ) continue; 00517 00518 00519 // If the price is not a number, retrieve the price from the database 00520 if ( isNumber(${"e_march$i"."_sell"}) == 0 ) { 00521 $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE); 00522 } else { 00523 $fiche_price=${"e_march$i"."_sell"}; 00524 } 00525 00526 00527 // VAT 00528 $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"}; 00529 00530 // vat label 00531 // vat rate 00532 $a_vat=GetTvaRate($p_cn,$vat); 00533 if ( $a_vat == null ) 00534 { 00535 $vat_label=""; 00536 $vat_rate=0.0; 00537 } 00538 else 00539 { 00540 $vat_label=$a_vat['tva_label']; 00541 $vat_rate=$a_vat['tva_rate']; 00542 } 00543 00544 // Total card without vat 00545 $fiche_sum=$fiche_price*$fiche_quant; 00546 // Sum of invoice 00547 $sum_march+=$fiche_sum; 00548 // vat of the card 00549 $fiche_amount_vat=$fiche_price*$fiche_quant*$vat_rate; 00550 // value card + vat 00551 $fiche_with_vat=$fiche_price*$fiche_quant*(1+$vat_rate); 00552 // Sum of invoice vat 00553 $sum_with_vat+=$fiche_with_vat; 00554 // Show the data 00555 $r.='<TR>'; 00556 $r.='<TD>'.$fiche_name.'</TD>'; 00557 $r.='<TD ALIGN="CENTER">'.$fiche_quant.'</TD>'; 00558 $r.='<TD ALIGN="right">'.$fiche_price.'</TD>'; 00559 $r.="<TD ALIGN=\"RIGHT\"> $vat_label </TD>"; 00560 $r.='<TD ALIGN="RIGHT">'.round($fiche_sum,2).'</TD>'; 00561 $r.='<TD ALIGN="RIGHT">'.round($fiche_amount_vat,2).'</TD>'; 00562 00563 $r.='<TD>'.round($fiche_with_vat,2).'</TD>'; 00564 00565 $r.="</TR>"; 00566 } 00567 00568 // end table 00569 $r.='</TABLE> '; 00570 $r.='<DIV style="padding:30px;font-size:14px">'; 00571 $r.="Total HTVA =".round( $sum_march,2)." <br>"; 00572 $r.="Total = ".round($sum_with_vat,2); 00573 00574 00575 $r.="</DIV>"; 00576 // Compute href 00577 $href=basename($_SERVER['SCRIPT_NAME']); 00578 switch ($href) 00579 { 00580 // user_jrn.php 00581 case 'user_jrn.php': 00582 $href="user_jrn.php?action=new&p_jrn=$p_jrn"; 00583 break; 00584 case 'commercial.php': 00585 $href="commercial.php?p_action=depense&p_jrn=$p_jrn"; 00586 break; 00587 default: 00588 echo_error('user_form_ach.php',__LINE__,'Erreur invalid request uri'); 00589 exit (-1); 00590 } 00591 00592 // $r.='<FORM METHOD="POST" enctype="multipart/form-data" ACTION="user_jrn.php?action=new&p_jrn='.$p_jrn.'">'; 00593 $r.='<FORM METHOD="POST" enctype="multipart/form-data" ACTION="'.$href.'">'; 00594 // check for upload piece 00595 // Set correctly the REQUEST param for jrn_type 00596 $h=new widget('hidden'); 00597 $h->name='jrn_type'; 00598 $h->value=$_REQUEST['jrn_type']; 00599 $r.=$h->IOValue(); 00600 00601 $file=new widget("file"); 00602 $file->table=1; 00603 $r.="<hr>"; 00604 $r.= "<table>"; 00605 if ( $p_piece) $r.="<TR>".$file->IOValue("pj","","Pièce justificative")."</TR>"; 00606 $r.="</table>"; 00607 $r.="<hr>"; 00608 00609 $r.=$data; 00610 $r.=$p_submit; 00611 00612 $r.='</FORM>'; 00613 00614 return $r; 00615 00616 }
|
|
Record an invoice in the table jrn & jrnx. parm :
$p_array contains all the invoice data e_date => e : 01.01.2003 e_client => e : 3 nb_item => e : 3 e_march0 => e : 6 e_quant0 => e : 0 e_march0_sell=>e:1 e_march1 => e : 6 e_quant1 => e : 2 e_march1_sell=>e:1 e_march2 => e : 7 e_quant2 => e : 3 e_march2_sell=>e:1 V : view_invoice => e : Voir cette facture V : record_invoice => e : Sauver
Definition at line 647 of file user_form_ach.php. References $comment, $e, $i, $poste, $r, $Res, $seq, Commit(), ComputeTotalVat(), ComputeVat(), echo_debug(), ExecSql(), exit, FormatString(), GetTvaPoste(), InsertJrn(), InsertJrnx(), InsertStockGoods(), isNumber(), NextSequence(), Rollback(), save_upload_document(), SetInternalCode(), and StartSql(). 00648 { 00649 echo_debug('user_form_ach',__LINE__,"function RecordSell($p_cn,$p_array,$p_user,$p_jrn)"); 00650 foreach ( $p_array as $v => $e) 00651 { 00652 ${"$v"}=$e; 00653 } 00654 00655 // Get the default period 00656 $periode=$p_user->GetPeriode(); 00657 $amount=0.0; 00658 $amount_jrn=0.0; 00659 $sum_tva_nd=0.0; 00660 // Computing total customer 00661 for ($i=0;$i<$nb_item;$i++) { 00662 // store quantity & goods in array 00663 $a_good[$i]=${"e_march$i"}; 00664 $a_quant[$i]=${"e_quant$i"}; 00665 $a_price[$i]=0; 00666 $a_vat_good[$i]=${"e_march$i"."_tva_id"}; 00667 // check wether the price is set or no 00668 if ( isNumber(${"e_march$i"."_sell"}) == 0 ) { 00669 if ( $a_good[$i] !="" ) { 00670 // If the price is not set we have to find it from the database 00671 $a_price[$i]=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE); 00672 } 00673 } else { 00674 // The price is valid 00675 $a_price[$i]=${"e_march$i"."_sell"}; 00676 } 00677 $cost=$a_price[$i]*$a_quant[$i]; 00678 $amount+=$cost; 00679 $amount_jrn+=$cost; 00680 echo_debug('user_form_ach.php',__LINE__,'Total customer:'.$amount_jrn); 00681 } 00682 // $amount_jrn=round( 00683 $comm=FormatString($e_comm); 00684 00685 // Compute vat with ded 00686 echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat"); 00687 $a_vat=ComputeTotalVat($p_cn,$a_good,$a_quant,$a_price,$a_vat_good,false); 00688 00689 StartSql($p_cn); 00690 00691 // Compute the j_grpt 00692 $seq=NextSequence($p_cn,'s_grpt'); 00693 00694 00695 00696 // Credit = goods 00697 for ( $i = 0; $i < $nb_item;$i++) { 00698 00699 $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT); 00700 00701 // don't record operation of 0 00702 if ( $a_price[$i]*$a_quant[$i] == 0 ) continue; 00703 00704 $amount=$a_price[$i]*$a_quant[$i]; 00705 // Put the non deductible part into a special account 00706 $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_DEPENSE_NON_DEDUCTIBLE); 00707 echo_debug('user_form_ach.php',__LINE__,"value non ded : $non_dedu"); 00708 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) 00709 { 00710 $nd_amount=round($a_quant[$i]*$a_price[$i]*$non_dedu,2); 00711 00712 // save it 00713 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);"); 00714 $dna=new parm_code($p_cn,'DNA'); 00715 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$dna->p_value,$e_date,round($nd_amount,2),$seq,$periode); 00716 if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} 00717 $amount=$amount-$nd_amount; 00718 } 00719 // Put the non deductible part into a special account 00720 $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE); 00721 echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu"); 00722 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0) 00723 { 00724 $lvat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i], 00725 $a_vat_good[$i] ); 00726 $ded_vat=($lvat != null )?$lvat*$non_dedu:0; 00727 $ded_vat=round($ded_vat,2); 00728 $sum_tva_nd+=$ded_vat; 00729 00730 // compute the NDA TVA 00731 $tva_dna=new parm_code($p_cn,'TVA_DNA'); 00732 echo_debug('user_form_ach.php',__LINE__, 00733 "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_dna->p_value.",$e_date,round($ded_vat,2),$seq,$periode);"); 00734 00735 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_dna->p_value,$e_date,round($ded_vat,2),$seq,$periode); 00736 if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} 00737 } 00738 00739 // Put the non deductible part into a special account 00740 $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP); 00741 echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu"); 00742 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 ) 00743 { 00744 $lvat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i], 00745 $a_vat_good[$i] ); 00746 $ded_vat=($lvat != null )?$lvat*$non_dedu:0; 00747 00748 $sum_tva_nd+=round($ded_vat,2); 00749 00750 // Save it 00751 $tva_ded_impot=new parm_code($p_cn,'TVA_DED_IMPOT'); 00752 echo_debug('user_form_ach.php',__LINE__, 00753 "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_ded_impot->p_value.",$e_date,round($ded_vat,2),$seq,$periode);"); 00754 00755 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_ded_impot->p_value,$e_date,round($ded_vat,2),$seq,$periode); 00756 if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} 00757 } 00758 00759 00760 00761 00762 // record into jrnx 00763 echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);"); 00764 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode); 00765 if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} 00766 // always save quantity but in withStock we can find what card need a stock management 00767 if ( InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c') == false ) { 00768 $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} 00769 echo_debug('user_form_ach.php',__LINE__,"value non ded : ".$a_good[$i]."is"); 00770 00771 } 00772 00773 00774 // Insert Vat 00775 $sum_tva=0.0; 00776 if ( $a_vat != null ) // no vat 00777 00778 { 00779 00780 echo_debug('user_form_ach',__LINE__,'a_vat = '.var_export($a_vat,true)); 00781 foreach ($a_vat as $tva_id => $tva_amount ) 00782 { 00783 echo_debug('user_form_ach',__LINE__," tva_amount = $tva_amount tva_id=$tva_id"); 00784 $poste=GetTvaPoste($p_cn,$tva_id,'d'); 00785 if ($tva_amount == 0 ) continue; 00786 echo_debug('user_form_ach',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode);"); 00787 $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode); 00788 if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");} 00789 $sum_tva+=round($tva_amount,2); 00790 } 00791 } 00792 echo_debug('user_form_ach.php',__LINE__,"echeance = $e_ech"); 00793 echo_debug('user_form_ach.php',__LINE__,"sum_tva = $sum_tva"); 00794 echo_debug('user_form_ach.php',__LINE__,"amount_jrn = $amount_jrn"); 00795 echo_debug('user_form_ach.php',__LINE__,"sum_tva_nd = $sum_tva_nd"); 00796 00797 // Debit = client 00798 $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT); 00799 echo_debug('user_form_achat.php',__LINE__,"get e_client $e_client poste $poste"); 00800 echo_debug('user_form_achat.php',__LINE__,"insert client"); 00801 00802 $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode); 00803 if ( $r == false) { $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");} 00804 00805 $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"--",round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode); 00806 if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");} 00807 // Set Internal code and Comment 00808 $internal=SetInternalCode($p_cn,$seq,$p_jrn); 00809 $comment=(FormatString($e_comm) == null )?$internal." Fournisseur : ".GetFicheName($p_cn,$e_client):FormatString($e_comm); 00810 00811 // Update and set the invoice's comment 00812 $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); 00813 if ( $Res == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__"); }; 00814 00815 if ( isset ($_FILES)) 00816 save_upload_document($p_cn,$seq); 00817 00818 00819 Commit($p_cn); 00820 00821 return array($internal,$comment); 00822 }
|