dolibarr/htdocs/compta/bank/virement.php

182 lines
5.3 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
2002-12-22 03:32:07 +00:00
*
* 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.
2002-05-11 18:53:13 +00:00
*/
2005-04-27 21:57:59 +00:00
/**
\file htdocs/compta/bank/virement.php
\ingroup banque
\brief Page de saisie d'un virement
2008-04-07 01:16:52 +00:00
\version $Id$
*/
2003-09-11 20:18:51 +00:00
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/bank.lib.php");
2002-05-11 18:53:13 +00:00
2006-09-15 23:05:25 +00:00
$langs->load("banks");
if (! $user->rights->banque->transfer)
accessforbidden();
/*
* Action ajout d'un virement
*/
if ($_POST["action"] == 'add')
2002-12-22 03:32:07 +00:00
{
2007-11-23 22:47:50 +00:00
$langs->load("errors");
$mesg='';
$dateo = dolibarr_mktime(12,0,0,$_POST["remonth"],$_POST["reday"],$_POST["reyear"]);
$label = $_POST["label"];
$amount= $_POST["amount"];
2006-09-15 23:05:25 +00:00
if (! $label)
{
$error=1;
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Label"))."</div>";
2006-09-15 23:05:25 +00:00
}
if (! $amount)
{
$error=1;
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"))."</div>";
2006-09-15 23:05:25 +00:00
}
2007-11-23 22:47:50 +00:00
if (! $_POST['account_from'])
{
$error=1;
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("TransferFrom"))."</div>";
}
if (! $_POST['account_to'])
{
$error=1;
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("TransferTo"))."</div>";
}
2006-09-15 23:05:25 +00:00
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();
$error=0;
$bank_line_id_from=0;
$bank_line_id_to=0;
$result=0;
// By default, electronic transfert from bank to bank
$typefrom='PRE';
$typeto='VIR';
if ($accountto->courant == 2 || $accountfrom->courant == 2)
{
// This is transfert of change
$typefrom='LIQ';
$typeto='LIQ';
}
if (! $error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1*price2num($amount), '', '', $user);
if (! ($bank_line_id_from > 0)) $error++;
if (! $error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount), '', '', $user);
if (! ($bank_line_id_to > 0)) $error++;
if (! $error) $result=$accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
if (! ($result > 0)) $error++;
if (! $error) $result=$accountto->add_url_line($bank_line_id_to, $bank_line_id_from, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
if (! ($result > 0)) $error++;
if (! $error)
{
2007-11-23 22:47:50 +00:00
$mesg.="<div class=\"ok\">";
$mesg.=$langs->trans("TransferFromToDone","<a href=\"account.php?account=".$accountfrom->id."\">".$accountfrom->label."</a>","<a href=\"account.php?account=".$accountto->id."\">".$accountto->label."</a>",$amount,$langs->transnoentities("Currency".$conf->monnaie));
$mesg.="</div>";
$db->commit();
}
else
{
$mesg.="<div class=\"error\">".$accountfrom->error.' '.$accountto->error."</div>";
$db->rollback();
}
}
else
{
$mesg.="<div class=\"error\">".$langs->trans("ErrorFromToAccountsMustDiffers")."</div>";
}
}
}
2002-06-20 13:23:17 +00:00
/*
* Affichage
*/
llxHeader();
$html=new Form($db);
2006-09-15 23:05:25 +00:00
print_titre($langs->trans("BankTransfer"));
print '<br>';
2002-06-20 13:23:17 +00:00
if ($mesg) {
print "$mesg<br>";
2002-05-11 18:53:13 +00:00
}
2006-09-15 23:05:25 +00:00
print $langs->trans("TransferDesc");
print "<br><br>";
2002-05-11 18:53:13 +00:00
2006-03-01 16:59:18 +00:00
print "<form name='add' method=\"post\" action=\"virement.php\">";
2002-05-11 18:53:13 +00:00
print '<input type="hidden" name="action" value="add">';
2002-05-11 18:53:13 +00:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
2006-09-15 23:05:25 +00:00
print '<td>'.$langs->trans("TransferFrom").'</td><td>'.$langs->trans("TransferTo").'</td><td>'.$langs->trans("Date").'</td><td>'.$langs->trans("Description").'</td><td>'.$langs->trans("Amount").'</td>';
print '</tr>';
$var=false;
print '<tr '.$bc[$var].'><td>';
2007-11-23 22:47:50 +00:00
print $html->select_comptes($_POST['account_from'],'account_from',0,'',1);
print "</td>";
2002-05-11 18:53:13 +00:00
2007-11-23 22:47:50 +00:00
print "<td>\n";
print $html->select_comptes($_POST['account_to'],'account_to',0,'',1);
print "</td>\n";
2002-05-11 18:53:13 +00:00
print "<td>";
2007-11-23 22:47:50 +00:00
$html->select_date($dateo,'','','','','add');
print "</td>\n";
2007-11-23 22:47:50 +00:00
print '<td><input name="label" class="flat" type="text" size="40" value="'.$_POST["label"].'"></td>';
print '<td><input name="amount" class="flat" type="text" size="8" value="'.$_POST["amount"].'"></td>';
print "</table>";
2005-04-27 21:57:59 +00:00
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Add").'"></center>';
2002-05-11 18:53:13 +00:00
print "</form>";
2002-05-11 18:53:13 +00:00
$db->close();
2005-04-27 21:57:59 +00:00
llxFooter('$Date$ - $Revision$');
2002-05-11 18:53:13 +00:00
?>