$content) { ${"$name"}=$content; } // Verify the date if ( isDate($e_date) == null ) { echo_error('user_form_fin.php',__LINE__,"Invalid date $e_date"); echo ""; return null; } // Check if the fiche is in the jrn if (IsFicheOfJrn($p_cn , $p_jrn, $e_bank_account,'deb') == 0 ) { $msg="Mauvais compte en banque"; echo_error('user_form_fin.php',__LINE__,$msg); echo ""; return null; } // Check if the card has a valid account if ( CheckPoste($p_cn,$e_bank_account) == null ) return null; // check if all e_march are in fiche for ($i=0;$i<$p_number;$i++) { if ( trim(${"e_other$i"}) == "" ) { // nothing to do continue; } // Check amount if ( isNumber(${"e_other".$i."_amount"}) == 0) { $msg="Montant invalide !!! "; echo_error('user_form_fin.php',__LINE__,$msg); echo ""; return null; } // Check if ( isFicheOfJrn($p_cn,$p_jrn,${"e_other$i"},'cred') == 0 ) { $msg="Fiche inexistante !!! "; echo_error('user_form_fin.php',__LINE__,$msg); echo ""; return null; } // Check if the card has a valid account if ( CheckPoste($p_cn,${"e_other".$i}) == null ) return null; } // Verify the userperiode // p_periode contient la periode par default list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); // Date dans la periode active echo_debug ('user_form_fin',__LINE__,"date start periode $l_date_start date fin periode $l_date_end date demande $e_date"); if ( cmpDate($e_date,$l_date_start)<0 || cmpDate($e_date,$l_date_end)>0 ) { $msg="Not in the active periode please change your preference"; echo_debug('user_form_fin.php',__LINE__,$msg); echo ""; return null; } // Periode ferm� if ( PeriodeClosed ($p_cn,$p_periode)=='t' ) { $msg="This periode is closed please change your preference"; echo_debug('user_form_fin.php',__LINE__,$msg); echo ""; return null; } return true; } /*! * \brief Display the form for financial * Used to show detail, encode a new fin op * or update one * * \param $p_cn database connection * \param $p_jrn ledger id (jr_id) * \param $p_submit contains the submit string * \param $p_array (default=null) containing the $_POST * \param $p_view_only (default=true) true if we cannot change it (no right or centralized op) * \param $p_item number of article (default=4) * \param $p_save (default false) if the operation is already recorded * * * \return string with the form, in readonly or writable mode */ function FormFin($p_cn,$p_jrn,$p_periode,$p_submit,$p_array=null,$pview_only=true,$p_item=4,$p_save=false) { include_once("poste.php"); if ( $p_array != null ) { // array contains old value foreach ( $p_array as $a=>$v) { ${"$a"}=$v; } } // The date list ($l_date_start,$l_date_end)=GetPeriode($p_cn,$p_periode); $flag=(isset($e_date))?1:0; // $e_date=( ! isset($e_date) ) ? substr($l_date_start,2,8):$e_date; $e_date=( ! isset($e_date) ) ? $l_date_start:$e_date; // Comment $e_comment=(isset($e_comment))?$e_comment:""; $r=""; if ( $pview_only == false) { $r.=JS_SEARCH_CARD; $r.=JS_CONCERNED_OP; } // Compute href // $href=basename($_SERVER['PHP_SELF']); $href=basename($_SERVER['PHP_SELF']); switch ($href) { // user_jrn.php module "Comptable" case 'user_jrn.php': $href="user_jrn.php?action=new&p_jrn=$p_jrn"; break; // commercial.php module "Gestion" case 'commercial.php': $href="commercial.php?p_action=bank&p_jrn=$p_jrn"; break; default: echo_error('user_form_fin.php',__LINE__,'Erreur invalid request uri'); exit (-1); } $r.="
"; $r.=dossier::hidden(); $r.=''; $Date=new widget("js_date"); $Date->SetReadOnly($pview_only); $Date->table=1; $r.=""; $r.=$Date->IOValue("e_date",$e_date,"Date"); $r.=""; include_once("fiche_inc.php"); $r.=''; // bank_account operation // Save old value and set a new one $e_bank_account=( isset ($e_bank_account) )?$e_bank_account:""; $e_bank_account_label=""; // retrieve e_bank_account_label if ( $e_bank_account != "" ) { $a_client=GetFicheAttribut($p_cn,$e_bank_account); if ( $a_client != null) $e_bank_account_label=$a_client['vw_name']." adresse ".$a_client['vw_addr']." ".$a_client['vw_cp']; } // search widget $W1=new widget("js_search"); $W1->readonly=$pview_only; $W1->label="Banque"; $W1->name="e_bank_account"; $W1->value=$e_bank_account; $W1->extra=FICHE_TYPE_FIN; // credits $W1->extra2=$p_jrn; $r.="".$W1->IOValue().""; $Span=new widget ("span"); $Span->SetReadOnly($pview_only); $r.=""; $r.="
".$Span->IOValue("e_bank_account_label",$e_bank_account_label)."
"; // ComputeBanqueSaldo // if ( $pview_only == true ) { $solde=GetSolde($p_cn,GetFicheAttribut($p_cn,$e_bank_account,ATTR_DEF_ACCOUNT)); $r.=" Solde = ".$solde." "; $new_solde=$solde; } // Start the div for item to move money $r.="
"; $r.='

Actions

'; $r.=''; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=""; $r.=''; $r.=""; // Parse each " tiers" for ($i=0; $i < $p_item; $i++) { $tiers=(isset(${"e_other".$i}))?${"e_other".$i}:""; $tiers_label=""; $tiers_amount=(isset(${"e_other$i"."_amount"}))?round(${"e_other$i"."_amount"},2):0; $tiers_comment=(isset (${"e_other$i"."_comment"}))?${"e_other$i"."_comment"}:""; // If $tiers has a value if ( $tiers != "" ) { // retrieve the tva label and name $a_fiche=GetFicheAttribut($p_cn, $tiers); if ( $a_fiche != null ) { $tiers_label=$a_fiche['vw_name']; } } ${"e_other$i"."_amount"}=(isset (${"e_other$i"."_amount"}))?${"e_other$i"."_amount"}:0; $W1=new widget("js_search"); $W1->label=""; $W1->name="e_other".$i; $W1->value=$tiers; $W1->extra='cred'; // credits $W1->extra2=$p_jrn; $W1->readonly=$pview_only; $r.="".$W1->IOValue().""; // label $other=new widget("span"); $r.="'; // if not recorded the new amount must be recalculate // if recorded the old amount is recalculated if ( $pview_only == true) $new_solde=($p_save==false)?$new_solde+$tiers_amount:$new_solde-$tiers_amount; } $r.="
codeDénominationDescriptionMontant Op. Concerné
"; $r.=$other->IOValue("e_other$i"."_label", $tiers_label); // Comment $wComment=new widget("text"); $wComment->table=1; $wComment->SetReadOnly($pview_only); $r.=$wComment->IOValue("e_other$i"."_comment",$tiers_comment); // amount $wAmount=new widget("text"); $wAmount->table=1; $wAmount->size=7; $wAmount->SetReadOnly($pview_only); $r.=$wAmount->IOValue("e_other$i"."_amount",$tiers_amount); // concerned ${"e_concerned".$i}=(isset(${"e_concerned".$i}))?${"e_concerned".$i}:""; $wConcerned=new widget("js_concerned"); $wConcerned->SetReadOnly($pview_only); $wConcerned->extra=0; $wConcerned->table=1; $wConcerned->extra2='paid'; $r.=$wConcerned->IOValue("e_concerned".$i,${"e_concerned".$i}); $r.='
"; if ( $pview_only==true && $p_save==false) { // check for upload piece $file=new widget("file"); $file->table=1; $r.="
"; $r.= ""; $r.="".$file->IOValue("pj","","Pièce justificative").""; $r.="
"; $r.="
"; } // Set correctly the REQUEST param for jrn_type $h=new widget('hidden'); $h->name='jrn_type'; $h->value='FIN'; $r.=$h->IOValue(); $r.=$p_submit; $r.="
"; $r.="
"; // if view_only is true //Put the new saldo here (old saldo - operation) if ( $pview_only==true) { $solde=round($solde,2); $new_solde=round($new_solde,2); // if not recorded the new amount must be recalculate if ( $p_save == false) { $r.=" Ancien Solde = ".$solde."
"; $op=$new_solde-$solde; $r.=" Montant opération =".$op."
"; $r.=" Nouveau Solde = ".$new_solde."
"; } // if recorded the old amount is recalculated if ($p_save == true ) { $op=$solde-$new_solde; $r.=" Ancien Solde = ".$new_solde."
"; $r.=" Montant opération =".$op."
"; $r.=" Nouveau Solde = ".$solde."
"; } } return $r; } /*! ************************************************** * \brief Record an invoice in the table jrn & * jrnx * * * \param $p_cn Database connection * \param $p_array contains all the invoice data * e_date => e : 01.01.2003 * e_bank_account => e : 3 * \param $p_user userid * \param $p_jrn current folder (journal) * \param array e_other$i, e_other$i_amount, e_other$i_label * \return true on success * */ function RecordFin($p_cn,$p_array,$p_user,$p_jrn) { $internal_code=""; $oid=0; echo_debug('user_form_fin.php',__LINE__,"RecordFin"); foreach ( $p_array as $v => $e) { ${"$v"}=$e; } // Get the default period $periode=$p_user->GetPeriode(); // Debit = banque $poste_bq=GetFicheAttribut($p_cn,$e_bank_account,ATTR_DEF_ACCOUNT); try { StartSql($p_cn); $amount=0.0; // Credit = goods for ( $i = 0; $i < $nb_item;$i++) { // if tiers is set and amount != 0 insert it into the database // and quit the loop ? if ( ${"e_other$i"."_amount"} == 0 ) continue; $poste=GetFicheAttribut($p_cn,${"e_other$i"},ATTR_DEF_ACCOUNT); // round it ${"e_other$i"."_amount"}=round( ${"e_other$i"."_amount"},2); $amount+=${"e_other$i"."_amount"}; // Record a line for the bank // Compute the j_grpt $seq=NextSequence($p_cn,'s_grpt'); // Set Internal code and Comment $internal=SetInternalCode($p_cn,$seq,$p_jrn); InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste_bq,$e_date,round(${"e_other$i"."_amount"},2), $seq,$periode,$e_bank_account) ; // Record a line for the other account $j_id=InsertJrnx($p_cn,'c',$p_user->id,$p_jrn,$poste,$e_date, round(${"e_other$i"."_amount"},2),$seq,$periode,${"e_other$i"}); echo_debug('user_form_fin.php',__LINE__," $j_id=InsertJrnx($p_cn,'d',$p_user->id,$p_jrn,$poste,$e_date,".${"e_other$i"}."_amount".",$seq,$periode);"); $jr_id=InsertJrn($p_cn,$e_date,'',$p_jrn,FormatString(${"e_other$i"."_comment"}), $seq,$periode); if ( isNumber(${"e_concerned".$i}) == 1 ) { InsertRapt($p_cn,$jr_id,${"e_concerned$i"}); } // Set Internal code and Comment $Res=ExecSql($p_cn,"update jrn set jr_internal='".$internal."' where ". " jr_grpt_id = ".$seq); $comment=$internal_code." compte : ".GetFicheName($p_cn,$e_bank_account); if ( FormatString(${"e_other$i"."_comment"}) == null ) { // Update comment if comment is blank $Res=ExecSql($p_cn,"update jrn set jr_comment='".$comment."' where jr_grpt_id=".$seq); } if ( $i == 0 ) { // first record we upload the files and // keep variable to update other row of jrn if ( isset ($_FILES)) $oid=save_upload_document($p_cn,$seq); } else { if ( $oid != 0 ) { ExecSql($p_cn,"update jrn set jr_pj=".$oid.", jr_pj_name='".$_FILES['pj']['name']."', ". "jr_pj_type='".$_FILES['pj']['type']."' where jr_grpt_id=$seq"); } } } // for nbitem } catch (Exception $e) { echo ''. 'Erreur dans l\'enregistrement '. __FILE__.':'.__LINE__.' '. $e->getMessage(); Rollback($p_cn); exit(); } Commit($p_cn); return $internal_code; } ?>