00001 <?
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 require_once("class_widget.php");
00022 require_once("constant.php");
00023 require_once("preference.php");
00024 require_once("fiche_inc.php");
00025 require_once("user_common.php");
00043 function form_verify_input($p_cn,$p_jrn,$p_periode,$p_array,$p_number)
00044 {
00045 foreach ($p_array as $name=>$content) {
00046 ${"$name"}=$content;
00047 }
00048
00049 if ( isDate($e_date) == null ) {
00050 echo_error("Invalid date $e_date");
00051 echo_debug('user_form_fin.php',__LINE__,"Invalid date $e_date");
00052 echo "<SCRIPT> alert('INVALID DATE $e_date !!!!');</SCRIPT>";
00053 return null;
00054 }
00055
00056
00057
00058 if (IsFicheOfJrn($p_cn , $p_jrn, $e_bank_account,'deb') == 0 )
00059 {
00060 $msg="Mauvais compte en banque";
00061 echo_error($msg);echo_debug('user_form_fin.php',__LINE__,$msg);
00062 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00063 return null;
00064 }
00065
00066
00067 for ($i=0;$i<$p_number;$i++) {
00068 if ( trim(${"e_other$i"}) == "" ) {
00069
00070 continue;
00071 }
00072
00073 if ( isNumber(${"e_other".$i."_amount"}) == 0) {
00074 $msg="Montant invalide !!! ";
00075 echo_error($msg); echo_debug('user_form_fin.php',__LINE__,$msg);
00076 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00077 return null;
00078 }
00079
00080 if ( isFicheOfJrn($p_cn,$p_jrn,${"e_other$i"},'cred') == 0 ) {
00081 $msg="Fiche inexistante !!! ";
00082 echo_error($msg);echo_debug('user_form_fin.php',__LINE__,$msg);
00083 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00084 return null;
00085 }
00086
00087 $poste=GetFicheAttribut($p_cn,${"e_other$i"},ATTR_DEF_ACCOUNT);
00088 if ( $poste == null )
00089 {
00090 $msg="La fiche ".${"e_other$i"}." n\'a pas de poste comptable";
00091 echo_error($msg); echo_debug('user_form_fin.php',__LINE__,$msg);
00092 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00093 return null;
00094
00095 }
00096 if ( strlen(trim($poste))==0 )
00097 {
00098 $msg="La fiche ".${"e_other$i"}." n\'a pas de poste comptable";
00099 echo_error($msg); echo_debug('user_form_fin.php',__LINE__,$msg);
00100 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00101 }
00102
00103 }
00104
00105
00106
00107 list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00108
00109
00110 echo_debug ('user_form_fin',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date");
00111 if ( cmpDate($e_date,$l_date_start)<0 ||
00112 cmpDate($e_date,$l_date_end)>0 )
00113 {
00114 $msg="Not in the active periode please change your preference";
00115 echo_error($msg); echo_error($msg);
00116 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00117 return null;
00118 }
00119
00120 if ( PeriodeClosed ($p_cn,$p_periode)=='t' )
00121 {
00122 $msg="This periode is closed please change your preference";
00123 echo_error($msg); echo_error($msg);
00124 echo "<SCRIPT>alert('$msg');</SCRIPT>";
00125 return null;
00126 }
00127 return true;
00128 }
00129
00130
00147 function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=true,$p_item=4,$p_save=false)
00148 {
00149 include_once("poste.php");
00150 if ( $p_array != null ) {
00151
00152 foreach ( $p_array as $a=>$v) {
00153 ${"$a"}=$v;
00154 }
00155 }
00156
00157 list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode);
00158 $flag=(isset($e_date))?1:0;
00159 $e_date=( ! isset($e_date) ) ? substr($l_date_start,2,8):$e_date;
00160
00161
00162 if ($flag ==1 and VerifyOperationDate($p_cn,$p_periode,$e_date) == null) {
00163 $e_date=substr($l_date_start,2,8);
00164 }
00165
00166
00167 $e_comment=(isset($e_comment))?$e_comment:"";
00168
00169 $r="";
00170 if ( $pview_only == false) {
00171 $r.=JS_SEARCH_CARD;
00172 $r.=JS_CONCERNED_OP;
00173 }
00174
00175 $r.="<FORM NAME=\"form_detail\" enctype=\"multipart/form-data\" ACTION=\"user_jrn.php?action=new&p_jrn=$p_jrn\" METHOD=\"POST\">";
00176 $r.='<TABLE>';
00177 $Date=new widget("text");
00178 $Date->SetReadOnly($pview_only);
00179 $Date->table=1;
00180 $r.="<tr>";
00181 $r.=$Date->IOValue("e_date",$e_date,"Date");
00182 $r.="</tr>";
00183
00184
00185 include_once("fiche_inc.php");
00186 $r.='<INPUT TYPE="HIDDEN" name="nb_item" value="'.$p_item.'">';
00187
00188
00189
00190 $e_bank_account=( isset ($e_bank_account) )?$e_bank_account:"";
00191 $e_bank_account_label="";
00192
00193
00194 if ( $e_bank_account != "" ) {
00195 $a_client=GetFicheAttribut($p_cn,$e_bank_account);
00196 if ( $a_client != null)
00197 $e_bank_account_label=$a_client['vw_name']." adresse ".$a_client['vw_addr']." ".$a_client['vw_cp'];
00198 }
00199
00200 $W1=new widget("js_search");
00201 $W1->readonly=$pview_only;
00202 $W1->label="Banque";
00203 $W1->name="e_bank_account";
00204 $W1->value=$e_bank_account;
00205 $W1->extra=FICHE_TYPE_FIN;
00206 $W1->extra2=$p_jrn;
00207 $r.="<TR>".$W1->IOValue()."</TD>";
00208
00209 $r.="</TABLE>";
00210
00211 $Span=new widget ("span");
00212 $Span->SetReadOnly($pview_only);
00213 $r.="<TD>".$Span->IOValue("e_bank_account_label",$e_bank_account_label)."</TD>";
00214
00215
00216
00217
00218 if ( $pview_only == true ) {
00219 $solde=GetSolde($p_cn,GetFicheAttribut($p_cn,$e_bank_account,ATTR_DEF_ACCOUNT));
00220 $r.=" <b> Solde = ".$solde." </b>";
00221 $new_solde=$solde;
00222 }
00223
00224
00225 $r.="<DIV>";
00226 $r.='<H2 class="info">Actions</H2>';
00227 $r.='<TABLE>';
00228 $r.="<TR>";
00229 $r.="<th></TH>";
00230 $r.="<th>code</TH>";
00231 $r.="<th>Dénomination</TH>";
00232 $r.="<th>Description</TH>";
00233 $r.="<th>Montant</TH>";
00234 $r.='<th colspan="2"> Op. Concerné</th>';
00235 $r.="</TR>";
00236
00237 for ($i=0; $i < $p_item; $i++) {
00238 $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:"";
00239 $tiers_label="";
00240 $tiers_amount=(isset(${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0;
00241
00242 $tiers_comment=(isset (${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:"";
00243
00244 if ( $tiers != "" )
00245 {
00246
00247 $a_fiche=GetFicheAttribut($p_cn, $tiers);
00248 if ( $a_fiche != null ) {
00249 $tiers_label=$a_fiche['vw_name'];
00250 }
00251 }
00252 ${"e_other$i"."_amount"}=(isset (${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0;
00253
00254 $W1=new widget("js_search");
00255 $W1->label="";
00256 $W1->name="e_other".$i;
00257 $W1->value=$tiers;
00258 $W1->extra='cred';
00259 $W1->extra2=$p_jrn;
00260 $W1->readonly=$pview_only;
00261 $r.="<TR>".$W1->IOValue()."</TD>";
00262
00263 $other=new widget("span");
00264 $r.="<TD>";
00265 $r.=$other->IOValue("e_other$i"."_label", $tiers_label);
00266
00267 $wComment=new widget("text");
00268 $wComment->table=1;
00269 $wComment->SetReadOnly($pview_only);
00270 $r.=$wComment->IOValue("e_other$i"."_comment",$tiers_comment);
00271
00272 $wAmount=new widget("text");
00273 $wAmount->table=1;
00274 $wAmount->size=7;
00275 $wAmount->SetReadOnly($pview_only);
00276 $r.=$wAmount->IOValue("e_other$i"."_amount",$tiers_amount);
00277
00278 ${"e_concerned".$i}=(isset(${"e_concerned".$i}))?${"e_concerned".$i}:"";
00279 $wConcerned=new widget("js_concerned");
00280 $wConcerned->SetReadOnly($pview_only);
00281 $r.=$wConcerned->IOValue("e_concerned".$i,${"e_concerned".$i});
00282 $r.='</TR>';
00283
00284
00285 if ( $pview_only == true)
00286 $new_solde=($p_save==false)?$new_solde+$tiers_amount:$new_solde-$tiers_amount;
00287 }
00288
00289 $r.="</TABLE>";
00290
00291 if ( $pview_only==true && $p_save==false) {
00292
00293 $file=new widget("file");
00294 $file->table=1;
00295 $r.="<hr>";
00296 $r.= "<table>";
00297 $r.="<TR>".$file->IOValue("pj","","Pièce justificative")."</TR>";
00298 $r.="</table>";
00299 $r.="<hr>";
00300 }
00301
00302 $h=new widget('hidden');
00303 $h->name='jrn_type';
00304 $h->value=$_REQUEST['jrn_type'];
00305 $r.=$h->IOValue();
00306
00307 $r.=$p_submit;
00308 $r.="</DIV>";
00309 $r.="</FORM>";
00310
00311
00312
00313 if ( $pview_only==true) {
00314
00315 if ( $p_save == false) {
00316 $r.=" <b> Ancien Solde = ".$solde." </b><br>";
00317 $r.=" <b> Nouveau Solde = ".$new_solde." </b><br>";
00318 }
00319
00320 if ($p_save == true ) {
00321 $r.=" <b> Ancien Solde = ".$new_solde." </b><br>";
00322 $r.=" <b> Nouveau Solde = ".$solde." </b><br>";
00323 }
00324 }
00325
00326 return $r;
00327
00328
00329 }
00330
00349 function RecordFin($p_cn,$p_array,$p_user,$p_jrn) {
00350 echo_debug('user_form_fin.php',__LINE__,"RecordFin");
00351 foreach ( $p_array as $v => $e)
00352 {
00353 ${"$v"}=$e;
00354 }
00355
00356 $periode=$p_user->GetPeriode();
00357
00358
00359
00360 if ( isDate($e_date) == null ) {
00361 echo_error("Invalid date $e_date");
00362 echo_debug('user_form_fin.php',__LINE__,"Invalid date $e_date");
00363 echo "<SCRIPT> alert('INVALID DATE $e_date !!!!');</SCRIPT>";
00364 return null;
00365 }
00366
00367
00368 $poste_bq=GetFicheAttribut($p_cn,$e_bank_account,ATTR_DEF_ACCOUNT);
00369 StartSql($p_cn);
00370 $amount=0.0;
00371
00372 for ( $i = 0; $i < $nb_item;$i++) {
00373
00374
00375 if ( ${"e_other$i"."_amount"} == 0 ) continue;
00376 $poste=GetFicheAttribut($p_cn,${"e_other$i"},ATTR_DEF_ACCOUNT);
00377
00378 $amount+=${"e_other$i"."_amount"};
00379
00380
00381
00382 $seq=NextSequence($p_cn,'s_grpt');
00383
00384 if ( InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste_bq,$e_date,round(${"e_other$i"."_amount"},2),$seq,$periode) == false ) {
00385 $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");
00386 }
00387
00388
00389
00390 if ( ($j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date,round(${"e_other$i"."_amount"},2),$seq,$periode)) == false )
00391 { $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");}
00392
00393 echo_debug('user_form_fin.php',__LINE__," $j_id=InsertJrnx($p_cn,'d',$p_user,$p_jrn,$poste,$e_date,".${"e_other$i"}."_amount".",$seq,$periode);");
00394
00395 if ( ($jr_id=InsertJrn($p_cn,$e_date,'',$p_jrn,FormatString(${"e_other$i"."_comment"}),
00396 round(${"e_other$i"."_amount"},2),$seq,$periode))==false) {
00397 $Rollback($p_cn);exit("error 'user_form_fin.php' __LINE__");}
00398
00399 if ( isNumber(${"e_concerned".$i}) == 1 ) {
00400
00401 InsertRapt($p_cn,$jr_id,${"e_concerned$i"});
00402 }
00403
00404
00405
00406 $internal_code=SetInternalCode($p_cn,$seq,$p_jrn);
00407 $comment=$internal_code." client : ".GetFicheName($p_cn,$e_bank_account);
00408 if ( FormatString(${"e_other$i"."_comment"}) == null ) {
00409
00410 $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq);
00411 }
00412
00413 }
00414 if ( isset ($_FILES))
00415 save_upload_document($p_cn,$seq);
00416
00417 Commit($p_cn);
00418 }
00419 ?>