diff --git a/htdocs/compta/bank/virement.php b/htdocs/compta/bank/virement.php index 5d1522565fb..7530e9fc1f6 100644 --- a/htdocs/compta/bank/virement.php +++ b/htdocs/compta/bank/virement.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2005 Laurent Destailleur + * Copyright (C) 2004-2006 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,14 +18,13 @@ * * $Id$ * $Source$ - * */ /** - \file htdocs/compta/bank/virement.php - \ingroup banque - \brief Page de saisie d'un virement - \version $Revision$ + \file htdocs/compta/bank/virement.php + \ingroup banque + \brief Page de saisie d'un virement + \version $Revision$ */ require("./pre.inc.php"); @@ -36,53 +35,68 @@ $user->getrights('banque'); if (!$user->rights->banque->modifier) accessforbidden(); -llxHeader(); - -$html=new Form($db); - /* * Action ajout d'un virement */ if ($_POST["action"] == 'add') { - $mesg=''; - $dateo = $_POST["reyear"]."-".$_POST["remonth"]."-".$_POST["reday"]; - $label = $_POST["label"]; - $amount= $_POST["amount"]; - - if ($label && $amount) { + $mesg=''; + $dateo = $_POST["reyear"]."-".$_POST["remonth"]."-".$_POST["reday"]; + $label = $_POST["label"]; + $amount= $_POST["amount"]; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, datev, dateo, label, amount, fk_user_author,fk_account, fk_type)"; - $sql .= " VALUES (now(), '$dateo', '$dateo', '$label', (0 - $amount),$user->id, ".$_POST["account_from"].", 'VIR')"; - - $result = $db->query($sql); - if (!$result) - { - dolibarr_print_error($db); - } - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, datev, dateo, label, amount, fk_user_author,fk_account, fk_type)"; - $sql .= " VALUES (now(), '$dateo', '$dateo', '$label', $amount,$user->id, ".$_POST["account_to"].", 'VIR')"; - - $result = $db->query($sql); - if ($result) - { - $accountfrom=new Account($db); - $accountfrom->fetch($_POST["account_from"]); - $accountto=new Account($db); - $accountto->fetch($_POST["account_to"]); + if ($label && $amount) + { + $db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, datev, dateo, label, amount, fk_user_author,fk_account, fk_type)"; + $sql .= " VALUES (now(), '$dateo', '$dateo', '".addslashes($label)."', (0 - $amount),$user->id, ".$_POST["account_from"].", 'VIR')"; - $mesg.="
Le virement depuis « id."\">".$accountfrom->label." » vers « id."\">".$accountto->label." » de ".$amount." ".$langs->trans("Currency".$conf->monnaie)." a été créé.
"; - } - else { - dolibarr_print_error($db); - } - } else { - $mesg.="
Un libellé de virement et un montant non nul sont obligatoires.
"; - } + $result = $db->query($sql); + if (!$result) + { + $db->rollback(); + dolibarr_print_error($db); + } + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank (datec, datev, dateo, label, amount, fk_user_author,fk_account, fk_type)"; + $sql .= " VALUES (now(), '$dateo', '$dateo', '".addslashes($label)."', $amount,$user->id, ".$_POST["account_to"].", 'VIR')"; + + $result = $db->query($sql); + if ($result) + { + $accountfrom=new Account($db); + $accountfrom->fetch($_POST["account_from"]); + $accountto=new Account($db); + $accountto->fetch($_POST["account_to"]); + + $mesg.="
Le virement depuis « id."\">".$accountfrom->label." » vers « id."\">".$accountto->label." » de ".$amount." ".$langs->trans("Currency".$conf->monnaie)." a été créé.
"; + $db->commit(); + } + else + { + $mesg.="
".$db->lasterror()."
"; + $db->rollback(); + } + } + else + { + $mesg.="
Un libellé de virement et un montant non nul sont obligatoires.
"; + } } + + +/* + * Affichage + */ + +llxHeader(); + +$html=new Form($db); + + print_titre("Virement inter-compte"); print '
'; @@ -105,7 +119,7 @@ $var=false; print ''; print "