$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.="
";
// 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 ( trim(${"e_concerned".$i}) != "" ) {
if ( strpos(${"e_concerned".$i},',') !== 0 )
{
$aRapt=split(',',${"e_concerned".$i});
foreach ($aRapt as $rRapt) {
if ( isNumber($rRapt) == 1 )
{
InsertRapt($p_cn,$jr_id,$rRapt);
}
}
} else
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
// Save pre_operatoin
// Save the operation
if ( isset($_POST['opd_save']) && $_POST['opd_save']=='on' ){
echo_debug(__FILE__.':'.__LINE__.'- ','save opd');
$opd=new Pre_op_fin($p_cn);
$opd->get_post();
$opd->operation->name=$_POST['predef'];
$opd->save();
echo_debug(__FILE__.':'.__LINE__.'- ',"opd = ",$opd);
}
}
catch (Exception $e)
{
echo ''.
'Erreur dans l\'enregistrement '.
__FILE__.':'.__LINE__.' '.
$e->getMessage();
Rollback($p_cn);
exit();
}
Commit($p_cn);
return $internal_code;
}
?>