2004-10-19 22:35:36 +02:00
|
|
|
<?php
|
2005-08-07 01:23:05 +02:00
|
|
|
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
2008-12-05 12:51:16 +01:00
|
|
|
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
|
2015-06-14 17:18:45 +02:00
|
|
|
* Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
|
2015-03-03 06:32:46 +01:00
|
|
|
* Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
|
2015-04-18 23:11:17 +02:00
|
|
|
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
|
2015-04-12 20:24:22 +02:00
|
|
|
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
|
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
|
2013-01-16 15:36:08 +01:00
|
|
|
* 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
|
|
|
*/
|
2004-10-10 15:53:57 +02:00
|
|
|
|
2005-04-27 23:57:59 +02:00
|
|
|
/**
|
2016-10-22 13:20:14 +02:00
|
|
|
* \file htdocs/compta/bank/transfer.php
|
2009-08-07 20:39:01 +02:00
|
|
|
* \ingroup banque
|
|
|
|
|
* \brief Page de saisie d'un virement
|
|
|
|
|
*/
|
2004-10-10 15:53:57 +02:00
|
|
|
|
2013-04-15 13:11:29 +02:00
|
|
|
require('../../main.inc.php');
|
2012-08-22 23:11:24 +02:00
|
|
|
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';
|
|
|
|
|
|
2018-05-27 09:40:17 +02:00
|
|
|
// Load translation files required by the page
|
2017-09-25 18:11:03 +02:00
|
|
|
$langs->loadLangs(array("banks", "categories", "multicurrency"));
|
2006-09-16 01:05:25 +02:00
|
|
|
|
2007-12-14 10:35:15 +01:00
|
|
|
if (! $user->rights->banque->transfer)
|
2003-11-05 10:59:16 +01:00
|
|
|
accessforbidden();
|
|
|
|
|
|
2012-03-08 12:20:47 +01:00
|
|
|
$action = GETPOST('action','alpha');
|
2017-07-07 20:24:39 +02:00
|
|
|
$error = 0;
|
2012-03-08 12:20:47 +01:00
|
|
|
|
2004-10-10 15:53:57 +02:00
|
|
|
|
|
|
|
|
/*
|
2013-04-15 13:11:29 +02:00
|
|
|
* Actions
|
2004-10-10 15:53:57 +02:00
|
|
|
*/
|
2013-04-15 13:11:29 +02:00
|
|
|
|
2012-03-08 12:20:47 +01:00
|
|
|
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
|
|
|
|
2012-03-08 12:20:47 +01:00
|
|
|
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
|
|
|
|
|
$label = GETPOST('label','alpha');
|
2018-04-07 12:28:10 +02:00
|
|
|
$amount= GETPOST('amount','alpha');
|
|
|
|
|
$amountto= GETPOST('amountto','alpha');
|
2006-04-02 04:18:06 +02:00
|
|
|
|
2006-09-16 01:05:25 +02:00
|
|
|
if (! $label)
|
|
|
|
|
{
|
2017-07-10 13:48:22 +02:00
|
|
|
$error++;
|
2015-10-17 16:18:33 +02:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Description")), null, 'errors');
|
2006-09-16 01:05:25 +02:00
|
|
|
}
|
|
|
|
|
if (! $amount)
|
|
|
|
|
{
|
2017-07-07 20:24:39 +02:00
|
|
|
$error++;
|
2015-10-17 16:18:33 +02:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("Amount")), null, 'errors');
|
2006-09-16 01:05:25 +02:00
|
|
|
}
|
2012-03-08 12:20:47 +01:00
|
|
|
if (! GETPOST('account_from','int'))
|
2007-11-23 23:47:50 +01:00
|
|
|
{
|
2017-07-07 20:24:39 +02:00
|
|
|
$error++;
|
2015-10-17 16:18:33 +02:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TransferFrom")), null, 'errors');
|
2007-11-23 23:47:50 +01:00
|
|
|
}
|
2012-03-08 12:20:47 +01:00
|
|
|
if (! GETPOST('account_to','int'))
|
2007-11-23 23:47:50 +01:00
|
|
|
{
|
2017-07-07 20:24:39 +02:00
|
|
|
$error++;
|
2015-10-17 16:18:33 +02:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TransferTo")), null, 'errors');
|
2007-11-23 23:47:50 +01:00
|
|
|
}
|
2006-09-16 01:05:25 +02:00
|
|
|
if (! $error)
|
2006-04-02 04:18:06 +02:00
|
|
|
{
|
2012-08-22 23:11:24 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
2007-10-30 00:11:42 +01:00
|
|
|
|
|
|
|
|
$accountfrom=new Account($db);
|
2012-03-08 12:20:47 +01:00
|
|
|
$accountfrom->fetch(GETPOST('account_from','int'));
|
2006-04-02 04:18:06 +02:00
|
|
|
|
2007-10-30 00:11:42 +01:00
|
|
|
$accountto=new Account($db);
|
2012-03-08 12:20:47 +01:00
|
|
|
$accountto->fetch(GETPOST('account_to','int'));
|
2006-04-02 04:18:06 +02:00
|
|
|
|
2017-11-06 21:37:19 +01:00
|
|
|
if ($accountto->currency_code == $accountfrom->currency_code)
|
|
|
|
|
{
|
2017-07-06 13:40:26 +02:00
|
|
|
$amountto=$amount;
|
2017-11-06 21:37:19 +01:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-06 13:40:26 +02:00
|
|
|
if (! $amountto)
|
|
|
|
|
{
|
2017-07-10 13:48:22 +02:00
|
|
|
$error++;
|
2017-07-06 13:40:26 +02:00
|
|
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AmountTo")), null, 'errors');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (($accountto->id != $accountfrom->id) && empty($error))
|
2007-10-30 00:11:42 +01:00
|
|
|
{
|
2007-11-23 16:10:31 +01:00
|
|
|
$db->begin();
|
2009-08-07 20:39:01 +02:00
|
|
|
|
2008-05-14 01:21:28 +02:00
|
|
|
$bank_line_id_from=0;
|
|
|
|
|
$bank_line_id_to=0;
|
|
|
|
|
$result=0;
|
2009-08-07 20:39:01 +02:00
|
|
|
|
2008-05-14 01:21:28 +02:00
|
|
|
// By default, electronic transfert from bank to bank
|
2017-07-03 14:36:50 +02:00
|
|
|
$typefrom='PRE';
|
2008-05-14 01:21:28 +02:00
|
|
|
$typeto='VIR';
|
2016-03-02 11:08:57 +01:00
|
|
|
if ($accountto->courant == Account::TYPE_CASH || $accountfrom->courant == Account::TYPE_CASH)
|
2008-05-14 01:21:28 +02:00
|
|
|
{
|
2016-10-22 13:20:14 +02:00
|
|
|
// This is transfer of change
|
2008-05-14 01:21:28 +02:00
|
|
|
$typefrom='LIQ';
|
|
|
|
|
$typeto='LIQ';
|
|
|
|
|
}
|
2009-08-07 20:39:01 +02:00
|
|
|
|
2008-05-14 01:21:28 +02:00
|
|
|
if (! $error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1*price2num($amount), '', '', $user);
|
|
|
|
|
if (! ($bank_line_id_from > 0)) $error++;
|
2017-07-06 13:40:26 +02:00
|
|
|
if (! $error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amountto), '', '', $user);
|
2008-05-14 01:21:28 +02:00
|
|
|
if (! ($bank_line_id_to > 0)) $error++;
|
2009-08-07 20:39:01 +02:00
|
|
|
|
2008-05-14 01:21:28 +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
|
|
|
|
2008-05-14 01:21:28 +02:00
|
|
|
if (! $error)
|
2007-11-23 16:10:31 +01:00
|
|
|
{
|
2018-04-07 12:28:10 +02:00
|
|
|
$mesgs = $langs->trans("TransferFromToDone", '<a href="bankentries_list.php?id='.$accountfrom->id.'&sortfield=b.datev,b.dateo,b.rowid&sortorder=desc">'.$accountfrom->label."</a>", '<a href="bankentries_list.php?id='.$accountto->id.'">'.$accountto->label."</a>", $amount, $langs->transnoentities("Currency".$conf->currency));
|
2015-11-11 12:27:09 +01:00
|
|
|
setEventMessages($mesgs, null, 'mesgs');
|
2007-11-23 16:10:31 +01:00
|
|
|
$db->commit();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2015-11-11 12:27:09 +01:00
|
|
|
setEventMessages($accountfrom->error.' '.$accountto->error, null, 'errors');
|
2007-11-23 16:10:31 +01:00
|
|
|
$db->rollback();
|
|
|
|
|
}
|
2006-04-02 04:18:06 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2017-07-07 20:24:39 +02:00
|
|
|
$error++;
|
2015-11-11 12:27:09 +01:00
|
|
|
setEventMessages($langs->trans("ErrorFromToAccountsMustDiffers"), null, 'errors');
|
2006-04-02 04:18:06 +02:00
|
|
|
}
|
|
|
|
|
}
|
2004-06-11 02:54:19 +02:00
|
|
|
}
|
2002-06-20 15:23:17 +02:00
|
|
|
|
2006-04-02 04:18:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2015-11-11 12:27:09 +01:00
|
|
|
* View
|
2006-04-02 04:18:06 +02:00
|
|
|
*/
|
2009-08-07 20:39:01 +02:00
|
|
|
|
2006-04-02 04:18:06 +02:00
|
|
|
llxHeader();
|
2017-07-06 13:40:26 +02:00
|
|
|
print ' <script type="text/javascript">
|
|
|
|
|
$(document).ready(function () {
|
|
|
|
|
$(".selectbankaccount").change(function() {
|
2018-04-07 12:28:10 +02:00
|
|
|
console.log("We change bank account");
|
|
|
|
|
init_page();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function init_page() {
|
|
|
|
|
console.log("Set fields according to currency");
|
2017-07-06 13:40:26 +02:00
|
|
|
var account1 = $("#selectaccount_from").val();
|
|
|
|
|
var account2 = $("#selectaccount_to").val();
|
|
|
|
|
var currencycode1="";
|
|
|
|
|
var currencycode2="";
|
|
|
|
|
|
|
|
|
|
$.get("'.DOL_URL_ROOT.'/core/ajax/getaccountcurrency.php", {id: account1})
|
|
|
|
|
.done(function( data ) {
|
|
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
var item= $.parseJSON(data);
|
|
|
|
|
if (item.num==-1) {
|
|
|
|
|
console.error("Error: "+item.error);
|
|
|
|
|
} else if (item.num!==0) {
|
|
|
|
|
currencycode1 = item.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.get("'.DOL_URL_ROOT.'/core/ajax/getaccountcurrency.php", {id: account2})
|
|
|
|
|
.done(function( data ) {
|
|
|
|
|
if (data != null)
|
|
|
|
|
{
|
|
|
|
|
var item=$.parseJSON(data);
|
|
|
|
|
if (item.num==-1) {
|
|
|
|
|
console.error("Error: "+item.error);
|
|
|
|
|
} else if (item.num!==0) {
|
|
|
|
|
currencycode2 = item.value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currencycode2!==currencycode1 && currencycode2!=="" && currencycode1!=="") {
|
|
|
|
|
$(".multicurrency").show();
|
|
|
|
|
} else {
|
|
|
|
|
$(".multicurrency").hide();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.error("Error: Ajax url has returned an empty page. Should be an empty json array.");
|
|
|
|
|
}
|
|
|
|
|
}).fail(function( data ) {
|
|
|
|
|
console.error("Error: has returned an empty page. Should be an empty json array.");
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
console.error("Error: has returned an empty page. Should be an empty json array.");
|
|
|
|
|
}
|
|
|
|
|
}).fail(function( data ) {
|
|
|
|
|
console.error("Error: has returned an empty page. Should be an empty json array.");
|
|
|
|
|
});
|
2018-04-07 12:28:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
init_page();
|
2017-07-06 13:40:26 +02:00
|
|
|
});
|
|
|
|
|
</script>';
|
|
|
|
|
|
2011-11-08 10:18:45 +01:00
|
|
|
$form=new Form($db);
|
2006-04-02 04:18:06 +02:00
|
|
|
|
2012-03-08 12:20:47 +01:00
|
|
|
$account_from='';
|
|
|
|
|
$account_to='';
|
|
|
|
|
$label='';
|
|
|
|
|
$amount='';
|
|
|
|
|
|
2018-04-07 12:28:10 +02:00
|
|
|
if ($error)
|
2012-03-08 12:20:47 +01:00
|
|
|
{
|
|
|
|
|
$account_from = GETPOST('account_from','int');
|
|
|
|
|
$account_to = GETPOST('account_to','int');
|
|
|
|
|
$label = GETPOST('label','alpha');
|
2018-04-07 12:28:10 +02:00
|
|
|
$amount = GETPOST('amount','alpha');
|
2012-03-08 12:20:47 +01:00
|
|
|
}
|
2006-04-02 04:18:06 +02:00
|
|
|
|
2016-07-30 17:28:18 +02:00
|
|
|
print load_fiche_titre($langs->trans("MenuBankInternalTransfer"), '', 'title_bank.png');
|
2002-06-20 15:23:17 +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
|
|
|
|
2016-10-22 13:20:14 +02:00
|
|
|
print '<form name="add" method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
2009-05-17 10:01:54 +02:00
|
|
|
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
2002-05-11 20:53:13 +02:00
|
|
|
|
2003-05-16 12:48:34 +02:00
|
|
|
print '<input type="hidden" name="action" value="add">';
|
2002-05-11 20:53:13 +02:00
|
|
|
|
2004-10-10 15:53:57 +02:00
|
|
|
print '<table class="noborder" width="100%">';
|
2004-02-15 04:05:16 +01:00
|
|
|
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>';
|
2017-09-25 18:11:03 +02:00
|
|
|
print '<td style="display:none" class="multicurrency">'.$langs->trans("AmountToOthercurrency").'</td>';
|
2004-02-15 04:05:16 +01:00
|
|
|
print '</tr>';
|
2005-05-11 02:58:27 +02:00
|
|
|
|
|
|
|
|
$var=false;
|
2017-04-14 13:02:29 +02:00
|
|
|
print '<tr class="oddeven"><td>';
|
2017-09-25 18:11:03 +02:00
|
|
|
$form->select_comptes($account_from, 'account_from', 0, '', 1, '', empty($conf->multicurrency->enabled)?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";
|
2017-09-25 18:11:03 +02:00
|
|
|
$form->select_comptes($account_to, 'account_to', 0, '', 1, '', empty($conf->multicurrency->enabled)?0:1);
|
2007-11-23 23:47:50 +01:00
|
|
|
print "</td>\n";
|
2002-05-11 20:53:13 +02:00
|
|
|
|
2003-05-16 12:48:34 +02:00
|
|
|
print "<td>";
|
2016-03-25 15:53:44 +01:00
|
|
|
$form->select_date((! empty($dateo)?$dateo:''),'','','','','add');
|
2003-05-16 12:48:34 +02:00
|
|
|
print "</td>\n";
|
2018-04-07 12:28:10 +02:00
|
|
|
print '<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.dol_escape_htmltag($label).'"></td>';
|
|
|
|
|
print '<td><input name="amount" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amount).'"></td>';
|
|
|
|
|
print '<td style="display:none" class="multicurrency"><input name="amountto" class="flat" type="text" size="6" value="'.dol_escape_htmltag($amountto).'"></td>';
|
2003-05-16 12:48:34 +02:00
|
|
|
|
2004-10-10 15:53:57 +02:00
|
|
|
print "</table>";
|
|
|
|
|
|
2014-11-25 20:13:43 +01:00
|
|
|
print '<br><div class="center"><input type="submit" class="button" value="'.$langs->trans("Add").'"></div>';
|
2002-05-11 20:53:13 +02:00
|
|
|
|
2004-10-10 15:53:57 +02:00
|
|
|
print "</form>";
|
2002-05-11 20:53:13 +02:00
|
|
|
|
2011-08-27 16:24:16 +02:00
|
|
|
llxFooter();
|
2015-12-11 14:19:38 +01:00
|
|
|
$db->close();
|