00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00049 extract($p_array);
00050 }
00051
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
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 $r.="<FORM NAME=\"form_detail\" enctype=\"multipart/form-data\" ACTION=\"user_jrn.php?action=new&p_jrn=$p_jrn\" METHOD=\"POST\">";
00065 }
00066
00067 $sql="select jrn_def_id as value,jrn_def_name as label from jrn_def where jrn_def_type='VEN'";
00068 $list=GetArray($p_cn,$sql);
00069 $r.='<TABLE>';
00070
00071
00072 $Date=new widget("text");
00073 $Date->SetReadOnly($pview_only);
00074 $Date->table=1;
00075 $r.="<tr>";
00076 $r.=$Date->IOValue("e_date",$op_date,"Date");
00077 $r.="</tr>";
00078
00079
00080 $Echeance=new widget("text");
00081 $Echeance->SetReadOnly($pview_only);
00082 $Echeance->table=1;
00083 $r.="<tr>";
00084 $r.=$Echeance->IOValue("e_ech",$e_ech,"Echeance");
00085 $r.="</tr>";
00086
00087
00088 $Commentaire=new widget("text");
00089 $Commentaire->table=1;
00090 $Commentaire->SetReadOnly($pview_only);
00091 $Commentaire->size=80;
00092 $r.="<tr>";
00093 $r.=$Commentaire->IOValue("e_comm",$e_comm,"Description");
00094 $r.="</tr>";
00095 include_once("fiche_inc.php");
00096
00097
00098 $fiche='cred';
00099 echo_debug('user_form_ach.php',__LINE__,"Fournisseurs Nombre d'enregistrement ".sizeof($fiche));
00100
00101 $e_client=( isset ($e_client) )?$e_client:"";
00102
00103 $e_client_label="";
00104
00105
00106 if ( isNumber($e_client) == 1 ) {
00107 if ( isFicheOfJrn($p_cn,$p_jrn,$e_client,'cred') == 0 ) {
00108 $msg="Fiche inexistante !!! ";
00109 echo_error($msg); echo_error($msg);
00110
00111 $e_client="";
00112 } else {
00113 $a_client=GetFicheAttribut($p_cn,$e_client);
00114 if ( $a_client != null)
00115 $e_client_label=$a_client['vw_name']." adresse ".$a_client['vw_addr']." ".$a_client['vw_cp'];
00116 }
00117 }
00118
00119 $W1=new widget("js_search");
00120 $W1->label="Fournisseur";
00121 $W1->name="e_client";
00122 $W1->value=$e_client;
00123 $W1->extra=$fiche;
00124 $W1->extra2=$p_jrn;
00125 $r.="<TR>".$W1->IOValue();
00126 $client_label=new widget("span");
00127 $r.= $client_label->IOValue("e_client_label",$e_client_label)."</TD></TR>";
00128 $r.="</TABLE>";
00129
00130 $h=new widget('hidden');
00131 $h->name='jrn_type';
00132 $h->value=$_REQUEST['jrn_type'];
00133 $r.=$h->IOValue();
00134
00135
00136 $Hid=new widget('hidden');
00137 $r.=$Hid->IOValue("nb_item",$p_article);
00138 $e_comment=(isset($e_comment))?$e_comment:"";
00139
00140
00141
00142 $r.="<DIV>";
00143 $r.='<H2 class="info">Articles</H2>';
00144 $r.='<TABLE>';
00145 $r.='<TR>';
00146 $r.="<th></th>";
00147 $r.="<th>Code</th>";
00148 $r.="<th>Dénomination</th>";
00149 $r.="<th>prix</th>";
00150 $r.="<th>tva</th>";
00151 $r.="<th>quantité</th>";
00152 $r.='</TR>';
00153
00154
00155
00156
00157
00158 for ($i=0;$i< $p_article;$i++) {
00159
00160 $march=(isset(${"e_march$i"}))?${"e_march$i"}:"";
00161 $march_sell=(isset(${"e_march".$i."_sell"}))?${"e_march".$i."_sell"}:"";
00162 $march_tva_id=(isset(${"e_march$i"."_tva_id"}))?${"e_march$i"."_tva_id"}:"";
00163
00164 $march_tva_label="";
00165 $march_label="";
00166
00167
00168 if ( isFicheOfJrn($p_cn,$p_jrn,$march,'deb') == 0 ) {
00169 $msg="Fiche inexistante !!! ";
00170 echo_error($msg); echo_error($msg);
00171 $march="";
00172 } else {
00173
00174 $a_fiche=GetFicheAttribut($p_cn, $march);
00175 if ( $a_fiche != null ) {
00176 if ( $march_tva_id == "" ) {
00177 $march_tva_id=$a_fiche['tva_id'];
00178 $march_tva_label=$a_fiche['tva_label'];
00179 }
00180 $march_label=$a_fiche['vw_name'];
00181 }
00182 }
00183
00184
00185
00186 $W1=new widget("js_search");
00187 $W1->label="";
00188 $W1->name="e_march".$i;
00189 $W1->value=$march;
00190 $W1->extra='deb';
00191 $W1->extra2=$p_jrn;
00192 $W1->readonly=$pview_only;
00193 $r.="<TR>".$W1->IOValue()."</TD>";
00194 $Span=new widget ("span");
00195 $Span->SetReadOnly($pview_only);
00196
00197 $r.="<TD>".$Span->IOValue("e_march".$i."_label",$march_label)."</TD>";
00198
00199 $Price=new widget("text");
00200 $Price->SetReadOnly($pview_only);
00201 $Price->table=1;
00202 $r.=$Price->IOValue("e_march".$i."_sell",$march_sell);
00203
00204 $select_tva=make_array($p_cn,"select tva_id,tva_label from tva_rate order by tva_id",1);
00205 $Tva=new widget("select");
00206 $Tva->table=1;
00207 $Tva->selected=$march_tva_id;
00208 $r.=$Tva->IOValue("e_march$i"."_tva_id",$select_tva);
00209
00210
00211 $quant=(isset(${"e_quant$i"}))?${"e_quant$i"}:"1";
00212 $Quantity=new widget("text");
00213 $Quantity->SetReadOnly($pview_only);
00214 $Quantity->table=1;
00215 $r.=$Quantity->IOValue("e_quant".$i,$quant);
00216 $r.='</TR>';
00217 }
00218
00219
00220
00221 $r.="</TABLE>";
00222 $r.="<hr>";
00223
00224 if ($pview_only == false ) {
00225 $r.=$p_submit;
00226 $r.="</DIV>";
00227 $r.="</FORM>";
00228 } else {
00229 $r.="</div>";
00230
00231 }
00232
00233
00234
00235 return $r;
00236
00237
00238 }
00251 function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number)
00252 {
00253 echo_debug('user_form_ach.php',__LINE__,"Enter form_verify_input $p_cn,$p_jrn,$p_periode,".var_export($p_array,true).",$p_number");
00254 foreach ($p_array as $name=>$content) {
00255 ${"$name"}=$content;
00256 }
00257
00258 if ( isDate($e_date) == null )
00259 {
00260 echo_error("Invalid date $e_date");
00261 echo_debug('user_form_ach.php',__LINE__,"Invalid date $e_date");
00262 echo "<SCRIPT> alert('INVALID DATE $e_date !!!!');</SCRIPT>";
00263 return null;
00264 }
00265
00266 for ($o = 0;$o < $p_number; $o++)
00267 {
00268 if ( isNumber(${"e_quant$o"}) == 0 )
00269 {
00270 echo_debug('user_form_ach.php',__LINE__,"invalid quantity ".${"e_quant$o"});
00271 echo_error("invalid quantity ".${"e_quant$o"});
00272 echo "<SCRIPT> alert('INVALID QUANTITY !!!');</SCRIPT>";
00273 return null;
00274 }
00275
00276 if ( strlen(trim(${"e_march$o"."_tva_id"})) !=0
00277 and
00278 ${"e_march$o"."_tva_id"} != "-1")
00279 {
00280
00281 if (isNumber(${"e_march$o"."_tva_id"}) == 0
00282 or CountSql($p_cn,"select tva_id from tva_rate where tva_id=".${"e_march$o"."_tva_id"}) ==0)
00283 {
00284 $msg="Invalid TVA !!! e_march".$o."_tva_id = ".${"e_march".$o."_tva_id"};
00285 echo_error($msg); echo_error($msg);
00286 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00287 return null;
00288
00289 }
00290 }
00291
00292 }
00293
00294
00295 if (strlen($e_ech) != 0 and isNumber($e_ech) == 0 and isDate ($e_ech) == null )
00296 {
00297 $msg="Echeance invalide";
00298 echo_error($msg); echo_error($msg);
00299 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00300 return null;
00301 }
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312 if ( strlen($e_ech) != 0 and isNumber($e_ech) == 1)
00313 {
00314 list($day,$month,$year)=explode(".",$e_date);
00315 echo_debug('user_form_ach.php',__LINE__," date $e_date = $day.$month.$year");
00316 $p_ech=date('d.m.Y',mktime(0,0,0,$month,$day+$e_ech,$year));
00317 echo_debug('user_form_ach.php',__LINE__,"p_ech = $e_ech $p_ech");
00318 $e_ech=$p_ech;
00319 $wHidden=new widget("hidden");
00320 $data.=$wHidden->IOValue("e_ech",$e_ech);
00321 # $data.=InputType("","HIDDEN","e_ech",$e_ech);
00322 }
00323
00324
00325 if (IsFicheOfJrn($p_cn , $p_jrn, $e_client,'cred') == 0 )
00326 {
00327 $msg="Client invalid please recheck";
00328 echo_error($msg);
00329 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00330 return null;
00331 }
00332
00333
00334 for ($i=0;$i<$p_number;$i++)
00335 {
00336 if ( trim(${"e_march$i"}) == "" ) {
00337
00338 continue;
00339 }
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349 if ( isFicheOfJrn($p_cn,$p_jrn,${"e_march$i"},'deb') == 0 ) {
00350 $msg="Fiche inexistante !!! ";
00351 echo_error($msg); echo_error($msg);
00352 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00353 return null;
00354 }
00355
00356 $poste=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_ACCOUNT);
00357 echo_debug('user_form_ach.php',__LINE__,"poste value = ".$poste."size = ".strlen(trim($poste)));
00358 if ( $poste == null )
00359 {
00360 $msg="La fiche ".${"e_march$i"}." n\'a pas de poste comptable";
00361 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);
00362 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00363 return null;
00364
00365 }
00366 if ( strlen(trim($poste))==0 )
00367 {
00368 $msg="La fiche ".${"e_march$i"}." n\'a pas de poste comptable";
00369 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);
00370 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00371 return null;
00372 }
00373
00374
00375 $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
00376 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
00377 {
00378 if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 )
00379 {
00380 $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide,il doit être compris entre 0 et 1";
00381 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);
00382 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00383 return null;
00384
00385 }
00386 }
00387
00388 $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA_NON_DEDUCTIBLE);
00389 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
00390 {
00391 if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 )
00392 {
00393 $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1";
00394 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);
00395 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00396 return null;
00397
00398 }
00399 }
00400 $non_dedu=GetFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
00401 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0 )
00402 {
00403 if ( isNumber($non_dedu) == 0 || $non_dedu > 1.00 )
00404 {
00405 $msg="La fiche ".${"e_march$i"}." a un pourcentage invalide, il doit être compris entre 0 et 1";
00406 echo_error($msg); echo_debug('user_form_ach.php',__LINE__,$msg);
00407 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00408 return null;
00409
00410 }
00411 }
00412
00413 }
00414
00415
00416
00417 list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00418
00419
00420 echo_debug ('user_form_ach',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date");
00421 if ( cmpDate($e_date,$l_date_start)<0 ||
00422 cmpDate($e_date,$l_date_end)>0 )
00423 {
00424 $msg="Not in the active periode please change your preference";
00425 echo_error($msg); echo_error($msg);
00426 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00427 return null;
00428 }
00429
00430 if ( PeriodeClosed ($p_cn,$p_periode)=='t' )
00431 {
00432 $msg="This periode is closed please change your preference";
00433 echo_error($msg); echo_error($msg);
00434 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00435 return null;
00436 }
00437 return true;
00438 }
00453 function FormAchView ($p_cn,$p_jrn,$p_periode,$p_array,$p_submit,$p_number,$p_piece=true)
00454 {
00455 $r="";
00456 $data="";
00457
00458
00459 $hidden=new widget("hidden");
00460 foreach ($p_array as $name=>$content) {
00461 $data.=$hidden->IOValue($name,$content);
00462 ${"$name"}=$content;
00463 }
00464
00465
00466 $r.='<TABLE>';
00467
00468 $r.="<tr>";
00469 $r.="<TD>Date : $e_date</TD>";
00470 $r.="</tr>";
00471
00472 $r.="<tr>";
00473 $r.="<TD>Client : ".getFicheName($p_cn,$e_client)."</TD>";
00474 $r.="</tr>";
00475
00476
00477 $r.="<tr>";
00478 $r.="<TD> Echeance : $e_ech </TD>";
00479 $r.="</tr>";
00480
00481 $r.="<tr>";
00482 $r.="<TD> Description : $e_comm</TD>";
00483 $r.="</tr>";
00484
00485 $sum_with_vat=0.0;
00486 $sum_march=0.0;
00487
00488 $r.="<TR>";
00489 $r.="<TH>Article</TH>";
00490 $r.="<TH>quantité</TH>";
00491 $r.="<TH>prix unit.</TH>";
00492 $r.="<TH>taux tva</TH>";
00493 $r.="<TH>Montant HTVA</TH>";
00494 $r.="<TH>Montant TVA</TH>";
00495 $r.="<TH>Total</TH>";
00496 $r.="</TR>";
00497 for ($i=0;$i<$p_number;$i++)
00498 {
00499 if ( trim(${"e_march$i"}) == "" )
00500 {
00501
00502 continue;
00503 }
00504
00505
00506 $fiche_name=getFicheName($p_cn,${"e_march$i"});
00507
00508
00509 $fiche_quant=${"e_quant$i"};
00510
00511
00512 if ( $fiche_quant == 0.0 ) continue;
00513
00514
00515
00516 if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
00517 $fiche_price=getFicheAttribut($p_cn,${"e_march$i"},ATTR_DEF_PRIX_VENTE);
00518 } else {
00519 $fiche_price=${"e_march$i"."_sell"};
00520 }
00521
00522
00523
00524 $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"};
00525
00526
00527
00528 $a_vat=GetTvaRate($p_cn,$vat);
00529 if ( $a_vat == null )
00530 {
00531 $vat_label="";
00532 $vat_rate=0.0;
00533 }
00534 else
00535 {
00536 $vat_label=$a_vat['tva_label'];
00537 $vat_rate=$a_vat['tva_rate'];
00538 }
00539
00540
00541 $fiche_sum=$fiche_price*$fiche_quant;
00542
00543 $sum_march+=$fiche_sum;
00544
00545 $fiche_amount_vat=$fiche_price*$fiche_quant*$vat_rate;
00546
00547 $fiche_with_vat=$fiche_price*$fiche_quant*(1+$vat_rate);
00548
00549 $sum_with_vat+=$fiche_with_vat;
00550
00551 $r.='<TR>';
00552 $r.='<TD>'.$fiche_name.'</TD>';
00553 $r.='<TD ALIGN="CENTER">'.$fiche_quant.'</TD>';
00554 $r.='<TD ALIGN="right">'.$fiche_price.'</TD>';
00555 $r.="<TD ALIGN=\"RIGHT\"> $vat_label </TD>";
00556 $r.='<TD ALIGN="RIGHT">'.round($fiche_sum,2).'</TD>';
00557 $r.='<TD ALIGN="RIGHT">'.round($fiche_amount_vat,2).'</TD>';
00558
00559 $r.='<TD>'.round($fiche_with_vat,2).'</TD>';
00560
00561 $r.="</TR>";
00562 }
00563
00564
00565 $r.='</TABLE> ';
00566 $r.='<DIV style="padding:30px;font-size:14px">';
00567 $r.="Total HTVA =".round( $sum_march,2)." <br>";
00568 $r.="Total = ".round($sum_with_vat,2);
00569
00570
00571 $r.="</DIV>";
00572
00573 $r.='<FORM METHOD="POST" enctype="multipart/form-data" ACTION="user_jrn.php?action=new&p_jrn='.$p_jrn.'">';
00574
00575
00576 $h=new widget('hidden');
00577 $h->name='jrn_type';
00578 $h->value=$_REQUEST['jrn_type'];
00579 $r.=$h->IOValue();
00580
00581 $file=new widget("file");
00582 $file->table=1;
00583 $r.="<hr>";
00584 $r.= "<table>";
00585 if ( $p_piece) $r.="<TR>".$file->IOValue("pj","","Pièce justificative")."</TR>";
00586 $r.="</table>";
00587 $r.="<hr>";
00588
00589 $r.=$data;
00590 $r.=$p_submit;
00591
00592 $r.='</FORM>';
00593
00594 return $r;
00595
00596 }
00597
00627 function RecordSell($p_cn,$p_array,$p_user,$p_jrn)
00628 {
00629 echo_debug('user_form_ach',__LINE__,"function RecordSell($p_cn,$p_array,$p_user,$p_jrn)");
00630 foreach ( $p_array as $v => $e)
00631 {
00632 ${"$v"}=$e;
00633 }
00634
00635
00636 $periode=$p_user->GetPeriode();
00637 $amount=0.0;
00638 $amount_jrn=0.0;
00639 $sum_tva_nd=0.0;
00640
00641 for ($i=0;$i<$nb_item;$i++) {
00642
00643 $a_good[$i]=${"e_march$i"};
00644 $a_quant[$i]=${"e_quant$i"};
00645 $a_price[$i]=0;
00646 $a_vat_good[$i]=${"e_march$i"."_tva_id"};
00647
00648 if ( isNumber(${"e_march$i"."_sell"}) == 0 ) {
00649 if ( $a_good[$i] !="" ) {
00650
00651 $a_price[$i]=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_PRIX_VENTE);
00652 }
00653 } else {
00654
00655 $a_price[$i]=${"e_march$i"."_sell"};
00656 }
00657 $cost=$a_price[$i]*$a_quant[$i];
00658 $amount+=$cost;
00659 $amount_jrn+=$cost;
00660 echo_debug('user_form_ach.php',__LINE__,'Total customer:'.$amount_jrn);
00661 }
00662
00663 $comm=FormatString($e_comm);
00664
00665
00666 echo_debug('user_form_achat.php',__LINE__,"Call ComputeTotalVat");
00667 $a_vat=ComputeTotalVat($p_cn,$a_good,$a_quant,$a_price,$a_vat_good,false);
00668
00669 StartSql($p_cn);
00670
00671
00672 $seq=NextSequence($p_cn,'s_grpt');
00673
00674
00675
00676
00677 for ( $i = 0; $i < $nb_item;$i++) {
00678
00679 $poste=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_ACCOUNT);
00680
00681
00682 if ( $a_price[$i]*$a_quant[$i] == 0 ) continue;
00683
00684 $amount=$a_price[$i]*$a_quant[$i];
00685
00686 $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_DEPENSE_NON_DEDUCTIBLE);
00687 echo_debug('user_form_ach.php',__LINE__,"value non ded : $non_dedu");
00688 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0)
00689 {
00690 $nd_amount=round($a_quant[$i]*$a_price[$i]*$non_dedu,2);
00691
00692
00693 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);");
00694 $dna=new parm_code($p_cn,'DNA');
00695 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$dna->p_value,$e_date,round($nd_amount,2),$seq,$periode);
00696 if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00697 $amount=$amount-$nd_amount;
00698 }
00699
00700 $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE);
00701 echo_debug('user_form_ach.php',__LINE__,"TVA value non ded : $non_dedu");
00702 if ( $non_dedu != null && strlen(trim($non_dedu)) != 0)
00703 {
00704 $lvat=ComputeVat($p_cn, $a_good[$i],$a_quant[$i],$a_price[$i],
00705 $a_vat_good[$i] );
00706 $ded_vat=($lvat != null )?$lvat*$non_dedu:0;
00707 $ded_vat=round($ded_vat,2);
00708 $sum_tva_nd+=$ded_vat;
00709
00710
00711 $tva_dna=new parm_code($p_cn,'TVA_DNA');
00712 echo_debug('user_form_ach.php',__LINE__,
00713 "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_dna->p_value.",$e_date,round($ded_vat,2),$seq,$periode);");
00714
00715 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_dna->p_value,$e_date,round($ded_vat,2),$seq,$periode);
00716 if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00717 }
00718
00719
00720 $non_dedu=GetFicheAttribut($p_cn,$a_good[$i],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
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
00728 $sum_tva_nd+=round($ded_vat,2);
00729
00730
00731 $tva_ded_impot=new parm_code($p_cn,'TVA_DED_IMPOT');
00732 echo_debug('user_form_ach.php',__LINE__,
00733 "InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,".$tva_ded_impot->p_value.",$e_date,round($ded_vat,2),$seq,$periode);");
00734
00735 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$tva_ded_impot->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
00740
00741
00742
00743 echo_debug('user_form_ach.php',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);");
00744 $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($amount,2),$seq,$periode);
00745 if ( $j_id == false) { Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00746
00747 if ( InsertStockGoods($p_cn,$j_id,$a_good[$i],$a_quant[$i],'c') == false ) {
00748 $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00749 echo_debug('user_form_ach.php',__LINE__,"value non ded : ".$a_good[$i]."is");
00750
00751 }
00752
00753
00754
00755 $sum_tva=0.0;
00756 if ( $a_vat != null )
00757
00758 {
00759
00760 echo_debug('user_form_ach',__LINE__,'a_vat = '.var_export($a_vat,true));
00761 foreach ($a_vat as $tva_id => $tva_amount )
00762 {
00763 echo_debug('user_form_ach',__LINE__," tva_amount = $tva_amount tva_id=$tva_id");
00764 $poste=GetTvaPoste($p_cn,$tva_id,'d');
00765 if ($tva_amount == 0 ) continue;
00766 echo_debug('user_form_ach',__LINE__,"InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode);");
00767 $r=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,round($tva_amount,2),$seq,$periode);
00768 if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");}
00769 $sum_tva+=round($tva_amount,2);
00770 }
00771 }
00772 echo_debug('user_form_ach.php',__LINE__,"echeance = $e_ech");
00773 echo_debug('user_form_ach.php',__LINE__,"sum_tva = $sum_tva");
00774 echo_debug('user_form_ach.php',__LINE__,"amount_jrn = $amount_jrn");
00775 echo_debug('user_form_ach.php',__LINE__,"sum_tva_nd = $sum_tva_nd");
00776
00777
00778 $poste=GetFicheAttribut($p_cn,$e_client,ATTR_DEF_ACCOUNT);
00779 echo_debug('user_form_achat.php',__LINE__,"get e_client $e_client poste $poste");
00780 echo_debug('user_form_achat.php',__LINE__,"insert client");
00781
00782 $r=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode);
00783 if ( $r == false) { $Rollback($p_cn);exit("error 'user_form_ach.php' __LINE__");}
00784
00785 $r=InsertJrn($p_cn,$e_date,$e_ech,$p_jrn,"--",round($amount_jrn+$sum_tva+$sum_tva_nd,2),$seq,$periode);
00786 if ( $r == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__");}
00787
00788 $internal=SetInternalCode($p_cn,$seq,$p_jrn);
00789 $comment=(FormatString($e_comm) == null )?$internal." client : ".GetFicheName($p_cn,$e_client):FormatString($e_comm);
00790
00791
00792 $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
00793 if ( $Res == false ) { Rollback($p_cn); exit(" Error 'user_form_ach.php' __LINE__"); };
00794
00795 if ( isset ($_FILES))
00796 save_upload_document($p_cn,$seq);
00797
00798
00799 Commit($p_cn);
00800
00801 return $comment;
00802 }
00803
00804 ?>