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