dolibarr/htdocs/compta/bank/virement.php

197 lines
5.8 KiB
PHP
Raw Normal View History

<?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
2012-12-30 15:13:49 +01:00
* Copytight (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copytight (C) 2012 Juanjo Menent <jmenent@2byte.es>
2002-12-22 04:32:07 +01: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 3 of the License, or
2002-12-22 04:32:07 +01:00
* (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
2011-08-01 00:21:57 +02:00
* along with this program. If not, see <http://www.gnu.org/licenses/>.
2002-05-11 20:53:13 +02:00
*/
2005-04-27 23:57:59 +02:00
/**
2009-08-07 20:39:01 +02:00
* \file htdocs/compta/bank/virement.php
* \ingroup banque
* \brief Page de saisie d'un virement
*/
require('../../main.inc.php');
require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php';
2013-06-05 16:24:32 +02:00
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$langs->load("banks");
$langs->load("categories");
2006-09-16 01:05:25 +02:00
if (! $user->rights->banque->transfer)
accessforbidden();
$action = GETPOST('action','alpha');
/*
* Actions
*/
if ($action == 'add')
2002-12-22 04:32:07 +01:00
{
2007-11-23 23:47:50 +01:00
$langs->load("errors");
2009-08-07 20:39:01 +02:00
$mesg='';
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
$label = GETPOST('label','alpha');
$amount= GETPOST('amount','int');
2006-09-16 01:05:25 +02:00
if (! $label)
{
2009-08-07 20:39:01 +02:00
$error=1;
2011-07-04 12:34:56 +02:00
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description"))."</div>";
2006-09-16 01:05:25 +02:00
}
if (! $amount)
{
2009-08-07 20:39:01 +02:00
$error=1;
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount"))."</div>";
2006-09-16 01:05:25 +02:00
}
if (! GETPOST('account_from','int'))
2007-11-23 23:47:50 +01:00
{
2009-08-07 20:39:01 +02:00
$error=1;
2007-11-23 23:47:50 +01:00
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("TransferFrom"))."</div>";
}
if (! GETPOST('account_to','int'))
2007-11-23 23:47:50 +01:00
{
2009-08-07 20:39:01 +02:00
$error=1;
2007-11-23 23:47:50 +01:00
$mesg.="<div class=\"error\">".$langs->trans("ErrorFieldRequired",$langs->transnoentities("TransferTo"))."</div>";
}
2006-09-16 01:05:25 +02:00
if (! $error)
{
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
$accountfrom=new Account($db);
$accountfrom->fetch(GETPOST('account_from','int'));
$accountto=new Account($db);
$accountto->fetch(GETPOST('account_to','int'));
if ($accountto->id != $accountfrom->id)
{
$db->begin();
2009-08-07 20:39:01 +02:00
$error=0;
$bank_line_id_from=0;
$bank_line_id_to=0;
$result=0;
2009-08-07 20:39:01 +02:00
// 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';
}
2009-08-07 20:39:01 +02:00
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++;
2009-08-07 20:39:01 +02:00
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++;
2009-08-07 20:39:01 +02:00
if (! $error)
{
2007-11-23 23:47:50 +01: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->currency));
2007-11-23 23:47:50 +01:00
$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 15:23:17 +02:00
/*
* Affichage
*/
2009-08-07 20:39:01 +02:00
llxHeader();
$form=new Form($db);
$account_from='';
$account_to='';
$label='';
$amount='';
if($error)
{
$account_from = GETPOST('account_from','int');
$account_to = GETPOST('account_to','int');
$label = GETPOST('label','alpha');
$amount = GETPOST('amount','int');
}
print_fiche_titre($langs->trans("BankTransfer"));
2002-06-20 15:23:17 +02:00
2011-07-04 12:33:56 +02:00
dol_htmloutput_mesg($mesg);
2002-05-11 20:53:13 +02:00
2006-09-16 01:05:25 +02:00
print $langs->trans("TransferDesc");
print "<br><br>";
2002-05-11 20:53:13 +02:00
2006-03-01 17:59:18 +01:00
print "<form name='add' method=\"post\" action=\"virement.php\">";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
2002-05-11 20:53:13 +02:00
print '<input type="hidden" name="action" value="add">';
2002-05-11 20:53:13 +02:00
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
2006-09-16 01:05:25 +02: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>';
print $form->select_comptes($account_from,'account_from',0,'',1);
2007-11-23 23:47:50 +01:00
print "</td>";
2002-05-11 20:53:13 +02:00
2007-11-23 23:47:50 +01:00
print "<td>\n";
print $form->select_comptes($account_to,'account_to',0,'',1);
2007-11-23 23:47:50 +01:00
print "</td>\n";
2002-05-11 20:53:13 +02:00
print "<td>";
$form->select_date($dateo,'','','','','add');
print "</td>\n";
print '<td><input name="label" class="flat" type="text" size="40" value="'.$label.'"></td>';
print '<td><input name="amount" class="flat" type="text" size="8" value="'.$amount.'"></td>';
print "</table>";
2005-04-27 23:57:59 +02:00
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Add").'"></center>';
2002-05-11 20:53:13 +02:00
print "</form>";
2002-05-11 20:53:13 +02:00
$db->close();
llxFooter();
2002-05-11 20:53:13 +02:00
?>