00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 include_once("postgres.php");
00023 require_once("class_document.php");
00040 function GetTvaRate($p_cn,$p_tva_id) {
00041
00042 if (strlen(trim($p_tva_id))==0) return 0;
00043
00044
00045 $Res=ExecSql($p_cn,"select tva_id,tva_rate,tva_label from tva_rate where tva_id=".$p_tva_id);
00046 if (pg_NumRows($Res) == 0 ) return null;
00047
00048 $r=pg_fetch_array($Res,0);
00049 return $r;
00050
00051 }
00069 function ComputeTotalVat($p_cn, $a_fiche,$a_quant,$a_price,$ap_vat,$all=false ) {
00070 echo_debug('user_common.php',__LINE__,"ComputeTotalVat $a_fiche $a_quant $a_price");
00071 foreach ( $a_fiche as $t=>$el) {
00072 echo_debug('user_common.php',__LINE__,"t $t e $el");
00073 }
00074 $r=null;
00075
00076
00077 foreach ( $a_fiche as $idx=>$element) {
00078 echo_debug ('user_common.php',__LINE__,"idx $idx element $element");
00079
00080 if ( strlen(trim($element))==0) continue;
00081
00082
00083 if ( $ap_vat != null and
00084 isNumber($ap_vat[$idx])== 1 and $ap_vat[$idx] != -1 )
00085 {
00086 $tva_id=$ap_vat[$idx];
00087 echo_debug('user_common',__LINE__,' tva_id is given');
00088 echo_debug('user_common',__LINE__,$ap_vat);
00089 }
00090 else
00091 {
00092 $tva_id=GetFicheAttribut($p_cn,$element,ATTR_DEF_TVA);
00093 echo_debug('user_common',__LINE__,'retrieve tva_id');
00094 }
00095 echo_debug('user_common',__LINE__,"tva id $tva_id");
00096 if ( $tva_id == null ) continue;
00097
00098 $a_vat=GetTvaRate($p_cn,$tva_id);
00099
00100
00101 if ( $a_vat != null and $a_vat['tva_id'] != "" )
00102 {
00103 $flag=true;
00104 $a=$a_vat['tva_id'];
00105
00106 $vat_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx],2);
00107
00108
00109 if ( $all == false )
00110 {
00111
00112
00113 $nd1=0;
00114
00115 $nd=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA_NON_DEDUCTIBLE);
00116 if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 )
00117 {
00118 $nd_amount=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2);
00119
00120 $vat_amount=$vat_amount-$nd_amount;
00121 echo_debug('user_common.php',__LINE__,
00122 "A - TVA Attr fiche [$nd] nd amount [ $nd_amount ]".
00123 "vat amount [ $vat_amount]");
00124 $flag=false;
00125
00126 $nd1=$nd;
00127 }
00128
00129 $nd=GetFicheAttribut($p_cn,$a_fiche[$idx],ATTR_DEF_TVA_NON_DEDUCTIBLE_RECUP);
00130 if ( $nd != null && strlen(trim($nd)) != 0 && $nd != 0 )
00131 {
00132 $nd_amount2=round($a_price[$idx]*$a_vat['tva_rate']*$a_quant[$idx]*$nd,2);
00133
00134 $vat_amount=$vat_amount-$nd_amount2;
00135
00136 if ( ($nd+$nd1) == 1)
00137 $vat_amount=0;
00138 echo_debug('user_common.php',__LINE__,
00139 "B - TVA Attr fiche [$nd] nd amount [ $nd_amount2 ]".
00140 "vat amount [ $vat_amount]");
00141
00142 $flag=false;
00143 }
00144 }
00145
00146 $r[$a]=isset ( $r[$a] )?$r[$a]+$vat_amount:$vat_amount;
00147 }
00148
00149 }
00150 echo_debug('user_common.php',__LINE__," return ".var_export($r,true));
00151 return $r;
00152
00153
00154 }
00155
00172 function ComputeVat($p_cn, $p_fiche,$p_quant,$p_price,$p_vat )
00173 {
00174 echo_debug('user_common.php',__LINE__,"function ComputeVat($p_cn,$p_fiche,$p_quant,$p_price,$p_vat )");
00175
00176 if ( $p_vat != null and isNumber($p_vat)== 1 and $p_vat != -1)
00177 $tva_id=$p_vat;
00178 else
00179 $tva_id=GetFicheAttribut($p_cn,$p_fiche,ATTR_DEF_TVA);
00180
00181 echo_debug('user_common',__LINE__,"ComputeVat tva id = $tva_id");
00182 if ( $tva_id == null ) return -1;
00183
00184 $a_vat=GetTvaRate($p_cn,$tva_id);
00185 $vat_amount=null;
00186
00187 if ( $a_vat != null and $a_vat['tva_id'] != "" )
00188 {
00189 $a=$a_vat['tva_id'];
00190 $vat_amount=$p_price*$a_vat['tva_rate']*$p_quant;
00191 }
00192 echo_debug('user_common',__LINE__,'return '.round($vat_amount,2));
00193 return round($vat_amount,2);
00194
00195
00196 }
00197
00198
00211 function GetTvaPoste($p_cn,$p_tva_id,$p_cred) {
00212 $Res=ExecSql($p_cn,"select tva_poste from tva_rate where tva_id=$p_tva_id");
00213 if ( pg_NumRows($Res) == 0 ) return null;
00214 $a=pg_fetch_array($Res,0);
00215 list ($deb,$cred)=split(",",$a['tva_poste']);
00216 if ( $p_cred=='c' ) return $cred;
00217 if ($p_cred=='d') return $deb;
00218 echo_error ("Invalid $p_cred in GetTvaRate");
00219 return null;
00220 }
00221
00222
00223
00224
00244 function InsertJrnx($p_cn,$p_type,$p_user,$p_jrn,$p_poste,$p_date,$p_amount,$p_grpt,$p_periode,$p_qcode="")
00245 {
00246 echo_debug ('user_common.php',__LINE__,"InsertJrnx param
00247 type = $p_type p_user $p_user
00248 p_date $p_date p_poste $p_poste
00249 p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode");
00250
00251 if ( $p_amount == 0) return true;
00252
00253 $debit=($p_type=='c')?'false':'true';
00254
00255
00256 if ( $p_amount < 0 ) {
00257 $debit=($debit=='false')?'true':'false';
00258 }
00259
00260 $sql=sprintf("select insert_jrnx
00261 ('%s',abs(%.2f),%d,%d,%d,%s,'%s',%d,'%s')",
00262 $p_date,round($p_amount,2),$p_poste,$p_grpt,$p_jrn,$debit,$p_user,$p_periode,$p_qcode);
00263
00264 echo_debug('user_common.php',__LINE__,"InsertJrnx $sql");
00265 $Res=ExecSql($p_cn,$sql);
00266 if ( $Res==false) return $Res;
00267 return GetSequence($p_cn,'s_jrn_op');
00268
00269 }
00288 function InsertJrn($p_cn,$p_date,$p_echeance,$p_jrn,$p_comment,$p_amount,$p_grpt,$p_periode)
00289 {
00290 echo_debug ('user_common.php',__LINE__,"InsertJrn param
00291 p_date $p_date p_poste $p_comment p_amount $p_amount p_grpt = $p_grpt p_periode = $p_periode p_echeance = $p_echeance
00292 comment = $p_comment");
00293 $p_comment=FormatString($p_comment);
00294
00295 if ( $p_echeance == "" or $p_echeance==null) {
00296 $p_echeance='null';
00297 } else {
00298 $p_echeance=sprintf("to_date('%s','DD.MM.YYYY')",$p_echeance);
00299 }
00300 $sql=sprintf("insert into jrn (jr_def_id,jr_montant,jr_comment,jr_date,jr_ech,jr_grpt_id,jr_tech_per)
00301 values ( %d,abs(%.2f),'%s',to_date('%s','DD.MM.YYYY'),%s,%d,%d)",
00302 $p_jrn, round($p_amount,2),$p_comment,$p_date,$p_echeance,$p_grpt,$p_periode);
00303 echo_debug('user_common.php',__LINE__,"InsertJrn $sql");
00304 $Res=ExecSql($p_cn,$sql);
00305 if ( $Res == false) return false;
00306 return GetSequence($p_cn,'s_jrn');
00307 }
00322 function ListJrn($p_cn,$p_jrn,$p_where="",$p_array=null,$p_value=0,$p_paid=0)
00323 {
00324
00325 include_once("central_inc.php");
00326 $limit=($_SESSION['g_pagesize']!=-1)?" LIMIT ".$_SESSION['g_pagesize']:"";
00327 $offset=($_SESSION['g_pagesize']!=-1)?" OFFSET ".$p_value:"";
00328 if ( $p_array == null ) {
00329
00330
00331
00332 $sql="select jr_id ,
00333 jr_montant,
00334 jr_comment,
00335 jr_ech,
00336 to_char(jr_date,'DD.MM.YYYY') as jr_date,
00337 jr_date as jr_date_order,
00338 jr_grpt_id,
00339 jr_rapt,
00340 jr_internal,
00341 jrn_def_id,
00342 jrn_def_name,
00343 jrn_def_ech,
00344 jrn_def_type,
00345 jr_valid,
00346 jr_tech_per,
00347 jr_pj_name,
00348 p_closed
00349 from
00350 jrn
00351 join jrn_def on jrn_def_id=jr_def_id
00352 join parm_periode on p_id=jr_tech_per
00353 $p_where
00354 order by jr_date_order asc,jr_internal asc";
00355 }
00356 if ( $p_array != null ) {
00357
00358 foreach ( $p_array as $key=>$element) {
00359 ${"l_$key"}=$element;
00360 }
00361 $sql="select jr_id ,
00362 jr_montant,
00363 jr_comment,
00364 jr_ech,
00365 to_char(jr_date,'DD.MM.YYYY') as jr_date,
00366 jr_date as jr_date_order,
00367 jr_grpt_id,
00368 jr_rapt,
00369 jr_internal,
00370 jrn_def_id,
00371 jrn_def_name,
00372 jrn_def_ech,
00373 jrn_def_type,
00374 jr_valid,
00375 jr_tech_per,
00376 jr_pj_name,
00377 p_closed
00378 from
00379 jrn join jrn_def on jrn_def_id=jr_def_id
00380 join parm_periode on p_id=jr_tech_per
00381 ";
00382 $jrn_sql=($p_jrn =0)?"1=1":"jrn_def_id=$p_jrn ";
00383 $l_and=" where ";
00384
00385 if ( ereg("^[0-9]+$", $l_s_montant) || ereg ("^[0-9]+\.[0-9]+$", $l_s_montant) )
00386 {
00387 $sql.=$l_and." jr_montant $l_mont_sel $l_s_montant";
00388 $l_and=" and ";
00389 }
00390
00391 if ( isDate($l_date_start) != null )
00392 {
00393 $sql.=$l_and." jr_date >= to_date('".$l_date_start."','DD.MM.YYYY')";
00394 $l_and=" and ";
00395 }
00396 if ( isDate($l_date_end) != null ) {
00397 $sql.=$l_and." jr_date <= to_date('".$l_date_end."','DD.MM.YYYY')";
00398 $l_and=" and ";
00399 }
00400
00401 $l_s_comment=FormatString($l_s_comment);
00402 if ( $l_s_comment != null )
00403 {
00404 $sql.=$l_and." upper(jr_comment) like upper('%".$l_s_comment."%') ";
00405 $l_and=" and ";
00406 }
00407
00408 $l_s_internal=FormatString($l_s_internal);
00409 if ( $l_s_internal != null ) {
00410 $sql.=$l_and." jr_internal like ('%$l_s_internal%') ";
00411 $l_and=" and ";
00412 }
00413
00414 $l_poste=FormatString($l_poste);
00415 if ( $l_poste != null ) {
00416 $sql.=$l_and." jr_grpt_id in (select j_grpt
00417 from jrnx where j_poste = $l_poste) ";
00418 $l_and=" and ";
00419 }
00420
00421 if ( $l_qcode != null )
00422 {
00423 $sql.=$l_and." jr_grpt_id in ( select j_grpt from
00424 jrnx where j_qcode = '$l_qcode')";
00425 $l_and=" and ";
00426 }
00427
00428 $User=new cl_user(DbConnect());
00429 $User->Check();
00430 if ( $User->admin == 0 )
00431 {
00432 $sql.=$l_and." jr_def_id in ( select uj_jrn_id ".
00433 " from user_sec_jrn where ".
00434 " uj_login='".$_SESSION['g_user']."'".
00435 " and uj_priv in ('R','W'))";
00436 }
00437 $sql.=" order by jr_date_order asc";
00438 }
00439
00440 $count=CountSql($p_cn,$sql);
00441
00442 $sql.=$limit.$offset;
00443
00444
00445 $Res=ExecSql($p_cn,$sql);
00446
00447
00448
00449
00450 $r="";
00451 $r.=JS_VIEW_JRN_DETAIL;
00452 $r.=JS_VIEW_JRN_CANCEL;
00453 $r.=JS_VIEW_JRN_MODIFY;
00454
00455 $Max=pg_NumRows($Res);
00456
00457
00458 if ($Max==0) return array(0,"Aucun enregistrement trouvé");
00459
00460 $r.='<table style="width:100%;border:solid blue 2px ;border-style:outset;">';
00461 $l_sessid=$_REQUEST['PHPSESSID'];
00462 $r.="<tr class=\"even\">";
00463 $r.="<th> Internal </th>";
00464 $r.="<th> Date </th>";
00465 $r.="<th> Echéance </th>";
00466 $r.="<th> Description</th>";
00467 $r.="<th> Montant </th>";
00468
00469 if ( $p_paid != 0 )
00470 {
00471 $r.="<th> Payé</th>";
00472 }
00473 $r.="<th>Op. Concernée</th>";
00474 $r.="<th>Document</th>";
00475 $r.="</tr>";
00476
00477 for ($i=0; $i < $Max;$i++) {
00478
00479
00480
00481 $row=pg_fetch_array($Res,$i);
00482
00483 if ( $i % 2 == 0 ) $tr='<TR class="odd">';
00484 else $tr='<TR class="even">';
00485 $r.=$tr;
00486
00487
00488 $r.="<TD>";
00489 $r.=sprintf('<A class="detail" HREF="javascript:modifyOperation(\'%s\',\'%s\',\'%s\')" >%s</A>',
00490 $row['jr_id'], $l_sessid, $p_jrn, $row['jr_internal']);
00491 $r.="</TD>";
00492
00493 $r.="<TD>";
00494 $r.=$row['jr_date'];
00495 $r.="</TD>";
00496
00497 $r.="<TD>";
00498 $r.=$row['jr_ech'];
00499 $r.="</TD>";
00500
00501
00502 $r.="<TD>";
00503 $r.=$row['jr_comment'];
00504 $r.="</TD>";
00505
00506
00507
00508
00509
00510 $jrn_prop=GetJrnProp($p_cn,$row['jrn_def_id'],1);
00511 $positive=0;
00512
00513
00514 if ( $jrn_prop['jrn_def_type'] == 'FIN' )
00515 {
00516 $positive = CountSql($p_cn,"select * from jrn inner join jrnx on jr_grpt_id=j_grpt ".
00517 " where jr_id=".$row['jr_id']." and (j_poste like '55%' or j_poste like '57%' )".
00518 " and j_debit='f'");
00519 }
00520 $r.="<TD align=\"right\">";
00521
00522 $r.=( $positive != 0 )?"<font color=\"red\"> - ".sprintf("%8.2f",$row['jr_montant'])."</font>":sprintf("%8.2f",$row['jr_montant']);
00523 $r.="</TD>";
00524
00525
00526
00527 if ( $p_paid !=0 )
00528 {
00529 $w=new widget("checkbox");
00530 $w->name="rd_paid".$row['jr_id'];
00531 $w->selected=($row['jr_rapt']=='paid')?true:false;
00532
00533 $w->readonly=( $p_paid == 2)?true:false;
00534 $h=new widget("hidden");
00535 $h->name="set_jr_id".$row['jr_id'];
00536 $r.='<TD>'.$w->IOValue().$h->IOValue().'</TD>';
00537 }
00538
00539
00540 $a=GetConcerned($p_cn,$row['jr_id']);
00541 $r.="<TD>";
00542 if ( $a != null ) {
00543
00544
00545 foreach ($a as $key => $element)
00546 {
00547 $r.= "<A class=\"detail\" HREF=\"javascript:viewDetail('".GetGrpt($p_cn,$element)."','$l_sessid')\" > ".GetInternal($p_cn,$element)."</A>";
00548 }
00549 }
00550 $r.="</TD>";
00551
00552 if ( $row['jr_valid'] == 'f' ) {
00553 $r.="<TD> Opération annulée</TD>";
00554 } else {
00555
00556
00557 $r.="<TD>";
00558
00559 $r.=sprintf('<input TYPE="BUTTON" VALUE="%s" onClick="cancelOperation(\'%s\',\'%s\',\'%s\')">',
00560 "Annuler",$row['jr_grpt_id'],$l_sessid,$p_jrn);
00561 $r.="</TD>";
00562 }
00563
00564 $r.="<TD>".sprintf('<A class="detail" HREF="show_pj.php?jrn=%s&jr_grpt_id=%s">%s</A>',
00565 $p_jrn,
00566 $row['jr_grpt_id'],
00567 $row['jr_pj_name'])."</TD>";
00568
00569
00570 $r.="</tr>";
00571
00572 }
00573 $r.="</table>";
00574
00575 return array ($count,$r);
00576 }
00577
00578
00579
00596 function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)
00597 {
00598 echo_debug('user_common.php',__LINE__,"function InsertStockGoods($p_cn,$p_j_id,$p_good,$p_quant,$p_type)");
00599
00600 $code_marchandise=GetFicheAttribut($p_cn,$p_good,ATTR_DEF_STOCK);
00601 $sql="select f_id from vw_poste_qcode where j_qcode='$p_good'";
00602 $Res=ExecSql($p_cn,$sql);
00603 $r=pg_fetch_array($Res,0);
00604 $f_id=$r['f_id'];
00605 $Res=ExecSql($p_cn,"insert into stock_goods (
00606 j_id,
00607 f_id,
00608 sg_code,
00609 sg_quantity,
00610 sg_type ) values (
00611 $p_j_id,
00612 $f_id,
00613 '$code_marchandise',
00614 $p_quant, '$p_type')
00615 ");
00616 return $Res;
00617 }
00631 function withStock($p_cn,$p_f_id)
00632 {
00633 $a=getFicheAttribut($p_cn,$p_f_id, ATTR_DEF_STOCK);
00634 if ( $a == "1" ) return true;
00635 return false;
00636
00637 }
00654 function VerifyOperationDate($p_cn,$p_periode,$p_date) {
00655
00656
00657 if ( isDate($p_date) == null ) {
00658 echo_error("Invalid date $p_date");
00659 echo_debug('user_common.php',__LINE__,"Invalid date $p_date");
00660 echo "<SCRIPT> alert('INVALID DATE $p_date !!!!');</SCRIPT>";
00661 return null;
00662 }
00663
00664 list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00665
00666
00667 echo_debug ("date start periode $l_date_start date fin periode $l_date_end date demandée $p_date");
00668 if ( cmpDate($p_date,$l_date_start)<0 ||
00669 cmpDate($p_date,$l_date_end)>0 )
00670 {
00671 $msg="Not in the active periode please change your preference";
00672 echo_error($msg); echo_error($msg);
00673 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00674 return null;
00675 }
00676
00677 if ( PeriodeClosed ($p_cn,$p_periode)=='t' )
00678 {
00679 $msg="This periode is closed please change your preference";
00680 echo_error($msg); echo_error($msg);
00681 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00682 return null;
00683 }
00684 return $p_date;
00685 }
00686
00699 function InsertRapt($p_cn,$jr_id,$jr_id2) {
00700 if ( isNumber($jr_id) == 0 || isNumber($jr_id2) == 0 )
00701 {
00702 echo_error(" InsertRapt : invalid jr_id $jr_id, jr_id2 $jr_id2");
00703 echo_debug('user_common.php',__LINE__," InsertRapt : invalid jr_id $jr_id, jr_id2 $jr_id2");
00704 return false;
00705 }
00706
00707 if ( CountSql($p_cn,"select jra_id from jrn_rapt where jra_concerned=$jr_id and jr_id=$jr_id2
00708 union
00709 select jra_id from jrn_rapt where jra_concerned=$jr_id2 and jr_id=$jr_id ") ==0)
00710 {
00711
00712 $Res=ExecSql($p_cn,"insert into jrn_rapt(jr_id,jra_concerned) values ($jr_id,$jr_id2)");
00713 }
00714 return true;
00715 }
00727 function DeleteRapt($p_cn,$jr_id,$jr_id2) {
00728 echo_debug('user_common.php',__LINE__,"DeleteRapt($p_cn,$jr_id,$jr_id2) ");
00729 if ( isNumber($jr_id) == 0 or
00730 isNumber($jr_id2) == 0 )
00731 {
00732 echo_error(" InsertRapt : invalid jr_id jr_id = $jr_id jr_id2 = $jr_id2");
00733 return;
00734 }
00735
00736 if ( CountSql($p_cn,"select jra_id from jrn_rapt where jra_concerned=$jr_id and jr_id=$jr_id2
00737 union
00738 select jra_id from jrn_rapt where jra_concerned=$jr_id2 and jr_id=$jr_id ") !=0)
00739 {
00740
00741 $Res=ExecSql($p_cn,"delete from jrn_rapt where (jra_concerned=$jr_id2 and jr_id=$jr_id) or
00742 (jra_concerned=$jr_id and jr_id=$jr_id2) ");
00743 }
00744 }
00745
00758 function GetConcerned ($p_cn, $jr_id) {
00759 $sql=" select jr_id as cn from jrn_rapt where jra_concerned=$jr_id
00760 union
00761 select jra_concerned as cn from jrn_rapt where jr_id=$jr_id";
00762 $Res=ExecSql($p_cn,$sql);
00763
00764
00765 $n=pg_NumRows($Res);
00766
00767 if ($n ==0 ) return null;
00768
00769
00770 for ($i=0;$i<$n;$i++) {
00771 $l=pg_fetch_array($Res,$i);
00772 $r[$i]=$l['cn'];
00773 }
00774 return $r;
00775 }
00789 function GetGrpt($p_cn,$p_jr_id)
00790 {
00791 $Res=ExecSql($p_cn,"select jr_grpt_id from jrn where jr_id=".$p_jr_id);
00792 if ( pg_NumRows($Res) == 0 ) {
00793 return null;
00794 }
00795 $r=pg_fetch_array($Res,0);
00796 return $r['jr_grpt_id'];
00797 }
00811 function UpdateComment ($p_cn,$p_jr_id,$p_comment) {
00812 $p_comment=FormatString($p_comment);
00813 $Res=ExecSql($p_cn,"update jrn set jr_comment='".$p_comment."'
00814 where jr_id = $p_jr_id");
00815
00816 }
00817
00831 function isValid ($p_cn,$p_grpt_id) {
00832 $Res=ExecSql($p_cn,"select jr_valid from jrn where jr_grpt_id=$p_grpt_id");
00833
00834 if ( ( $M = pg_NumRows($Res)) == 0 ) return 0;
00835
00836 $a=pg_fetch_array($Res,0);
00837
00838 if ( $a['jr_valid'] == 't') return 1;
00839 if ( $a['jr_valid'] == 'f') return 0;
00840
00841 echo_error ("Invalid result = ".$a['result']);
00842
00843
00844 }
00845
00858 function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1)
00859 {
00860 echo_debug('user_common',__LINE__,"function jrn_navigation_bar($p_offset,$p_line,$p_size=0,$p_page=1)");
00861
00862
00863 if ( $_SESSION['g_pagesize'] == -1 ) return "";
00864 if ( $p_size==0) {
00865 $p_size= $_SESSION['g_pagesize'];
00866 }
00867
00868 if ( $p_line == 0 ) return "";
00869
00870
00871 $url="";
00872 $and="";
00873 $get=$_GET;
00874 if ( isset ($get) ) {
00875 foreach ($get as $name=>$value ) {
00876
00877 if ( ! in_array($name,array('offset','step','page','size'))) {
00878 $url.=$and.$name."=".$value;
00879 $and="&";
00880 }
00881 }
00882 }
00883
00884 $nb_page=($p_line-($p_line%$p_size))/$p_size;
00885 echo_debug('user_common',__LINE__,"nb_page = $nb_page");
00886
00887 if ( $p_line % $p_size != 0 ) $nb_page+=1;
00888
00889
00890 if ( $nb_page == 1) return "";
00891
00892 $r="";
00893
00894 if ($p_page !=1) {
00895 $e=$p_page-1;
00896 $step=$_SESSION['g_pagesize'];
00897 $offset=($e-1)*$step;
00898
00899 $r='<A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'">';
00900 $r.="Précédent";
00901 $r.="</A> ";
00902 }
00903
00904
00905
00906
00907
00908 $start_bar=($p_page < 11 )?1:$p_page-10;
00909 $end_bar =($p_page < 11 )?20:$p_page+10;
00910 $end_bar =($end_bar > $nb_page )?$nb_page:$end_bar;
00911
00912
00913 for ($e=$start_bar;$e<=$end_bar;$e++) {
00914
00915 if ( $e != $p_page ) {
00916 $step=$_SESSION['g_pagesize'];
00917 $offset=($e-1)*$step;
00918 $go=sprintf($_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step");
00919 $r.=sprintf('<A class="mtitle" HREF="%s" CLASS="one">%d</A> ',$go,$e);
00920 } else {
00921 $r.="<b> $e </b>";
00922 }
00923 }
00924
00925
00926 if ($p_page !=$nb_page) {
00927
00928 $e=$p_page+1;
00929 $step=$_SESSION['g_pagesize'];
00930 $offset=($e-1)*$step;
00931
00932 $r.=' <A class="mtitle" href="'.$_SERVER['PHP_SELF']."?".$url."&offset=$offset&step=$step&page=$e&size=$step".'">';
00933 $r.="Suivant";
00934 $r.="</A>";
00935 }
00936
00937
00938 return $r;
00939 }
00940
00941
00949 function CheckPoste($p_cn,$qcode)
00950 {
00951
00952 $poste=GetFicheAttribut($p_cn,$qcode,ATTR_DEF_ACCOUNT);
00953 echo_debug('poste.php',__LINE__,"poste value = ".$poste."size = ".strlen(trim($poste)));
00954 if ( $poste == null )
00955 {
00956 $msg="La fiche ".$qcode." n\'a pas de poste comptable";
00957 echo_error($msg); echo_debug('poste.php',__LINE__,$msg);
00958 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00959 return null;
00960
00961 }
00962 if ( strlen(trim($poste))==0 )
00963 {
00964 $msg="La fiche ".$qcode." n\'a pas de poste comptable";
00965 echo_error($msg); echo_debug('poste.php',__LINE__,$msg);
00966 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00967 return null;
00968 }
00969
00970 if ( CountSql($p_cn,
00971 "select * from tmp_pcmn where pcm_val=$poste") == 0 )
00972 {
00973 $msg=" Le poste comptable $poste de la fiche ".$qcode." n\'existe pas";
00974 echo_error($msg); echo_debug('poste.php',__LINE__,$msg);
00975 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00976 return null;
00977
00978 }
00979 return 1;
00980 }
00981 ?>