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