Fix: Ajout protection pour eviter de creer un transfer d'un compte vers lui meme.
This commit is contained in:
parent
459eccec04
commit
4783e9eba1
@ -50,27 +50,28 @@ if ($_POST["action"] == 'add')
|
|||||||
if (! $label)
|
if (! $label)
|
||||||
{
|
{
|
||||||
$error=1;
|
$error=1;
|
||||||
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->trans("Label"))."</div>";
|
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"))."</div>";
|
||||||
}
|
}
|
||||||
if (! $amount)
|
if (! $amount)
|
||||||
{
|
{
|
||||||
$error=1;
|
$error=1;
|
||||||
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->trans("Amount"))."</div>";
|
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"))."</div>";
|
||||||
}
|
}
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
|
require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php');
|
||||||
|
|
||||||
$db->begin();
|
|
||||||
|
|
||||||
$accountfrom=new Account($db);
|
$accountfrom=new Account($db);
|
||||||
$accountfrom->fetch($_POST["account_from"]);
|
$accountfrom->fetch($_POST["account_from"]);
|
||||||
|
|
||||||
$bank_line_id_from = $accountfrom->addline($dateo, 'VIR', $label, -1*price2num($amount), '', '', $user);
|
|
||||||
|
|
||||||
$accountto=new Account($db);
|
$accountto=new Account($db);
|
||||||
$accountto->fetch($_POST["account_to"]);
|
$accountto->fetch($_POST["account_to"]);
|
||||||
|
|
||||||
|
if ($accountto->id != $accountfrom->id)
|
||||||
|
{
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$bank_line_id_from = $accountfrom->addline($dateo, 'VIR', $label, -1*price2num($amount), '', '', $user);
|
||||||
$bank_line_id_to = $accountto->addline($dateo, 'VIR', $label, price2num($amount), '', '', $user);
|
$bank_line_id_to = $accountto->addline($dateo, 'VIR', $label, price2num($amount), '', '', $user);
|
||||||
|
|
||||||
$result1=$accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
|
$result1=$accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
|
||||||
@ -78,7 +79,7 @@ if ($_POST["action"] == 'add')
|
|||||||
|
|
||||||
if ($result1 > 0 && $result2 > 0)
|
if ($result1 > 0 && $result2 > 0)
|
||||||
{
|
{
|
||||||
$mesg.="<div class=\"ok\">Le virement depuis « <a href=\"account.php?account=".$accountfrom->id."\">".$accountfrom->label."</a> » vers « <a href=\"account.php?account=".$accountto->id."\">".$accountto->label."</a> » de ".$amount." ".$langs->trans("Currency".$conf->monnaie)." a été créé.</div>";
|
$mesg.="<div class=\"ok\">Le virement depuis <a href=\"account.php?account=".$accountfrom->id."\">".$accountfrom->label."</a> vers <a href=\"account.php?account=".$accountto->id."\">".$accountto->label."</a> de ".$amount." ".$langs->trans("Currency".$conf->monnaie)." a ete cree.</div>";
|
||||||
$db->commit();
|
$db->commit();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -87,6 +88,11 @@ if ($_POST["action"] == 'add')
|
|||||||
$db->rollback();
|
$db->rollback();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg.="<div class=\"error\">".$langs->trans("ErrorFromToAccountsMustDiffers")."</div>";
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user