* Copyright (C) 2004-2007 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 * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** \file htdocs/compta/bank/virement.php \ingroup banque \brief Page de saisie d'un virement \version $Id$ */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php"); $langs->load("banks"); if (! $user->rights->banque->transfer) accessforbidden(); /* * Action ajout d'un virement */ if ($_POST["action"] == 'add') { $langs->load("errors"); $mesg=''; $dateo = dolibarr_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]); $label = $_POST["label"]; $amount= $_POST["amount"]; if (! $label) { $error=1; $mesg.="
".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"))."
"; } if (! $amount) { $error=1; $mesg.="
".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"))."
"; } if (! $_POST['account_from']) { $error=1; $mesg.="
".$langs->trans("ErrorFieldRequired",$langs->transnoentities("TransferFrom"))."
"; } if (! $_POST['account_to']) { $error=1; $mesg.="
".$langs->trans("ErrorFieldRequired",$langs->transnoentities("TransferTo"))."
"; } if (! $error) { require_once(DOL_DOCUMENT_ROOT.'/compta/bank/account.class.php'); $accountfrom=new Account($db); $accountfrom->fetch($_POST["account_from"]); $accountto=new Account($db); $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); $result1=$accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert'); $result2=$accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert'); if ($result1 > 0 && $result2 > 0) { $mesg.="
"; $mesg.=$langs->trans("TransferFromToDone","id."\">".$accountfrom->label."","id."\">".$accountto->label."",$amount,$langs->transnoentities("Currency".$conf->monnaie)); $mesg.="
"; $db->commit(); } else { $mesg.="
".$accountfrom->error.' '.$accountto->error."
"; $db->rollback(); } } else { $mesg.="
".$langs->trans("ErrorFromToAccountsMustDiffers")."
"; } } } /* * Affichage */ llxHeader(); $html=new Form($db); print_titre($langs->trans("BankTransfer")); print '
'; if ($mesg) { print "$mesg
"; } print $langs->trans("TransferDesc"); print "

"; print "
"; print ''; print ''; print ''; print ''; print ''; $var=false; print '"; print "\n"; print "\n"; print ''; print ''; print "
'.$langs->trans("TransferFrom").''.$langs->trans("TransferTo").''.$langs->trans("Date").''.$langs->trans("Description").''.$langs->trans("Amount").'
'; print $html->select_comptes($_POST['account_from'],'account_from',0,'',1); print "\n"; print $html->select_comptes($_POST['account_to'],'account_to',0,'',1); print ""; $html->select_date($dateo,'','','','','add'); print "
"; print '
'; print "
"; $db->close(); llxFooter('$Date$ - $Revision$'); ?>