Merge pull request #7122 from atm-florian/develop_fixtransfert
NEW : Can transfer from bank account to bank account with different currencies
This commit is contained in:
commit
fcdbc66bb1
@ -925,7 +925,8 @@ class Account extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
$this->error=$this->db->lasterror;
|
||||
$this->errors[]=$this->error;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,14 +44,14 @@ $error = 0;
|
||||
* Actions
|
||||
*/
|
||||
|
||||
if ($action == 'add_confirm')
|
||||
if ($action == 'add')
|
||||
{
|
||||
$langs->load("errors");
|
||||
|
||||
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
|
||||
$label = GETPOST('label','alpha');
|
||||
$amount= GETPOST('amount');
|
||||
$amount_to= GETPOST('amount_to');
|
||||
$amountto= GETPOST('amountto');
|
||||
|
||||
if (! $label)
|
||||
{
|
||||
@ -83,7 +83,17 @@ if ($action == 'add_confirm')
|
||||
$accountto=new Account($db);
|
||||
$accountto->fetch(GETPOST('account_to','int'));
|
||||
|
||||
if ($accountto->id != $accountfrom->id)
|
||||
if ($accountto->currency_code == $accountfrom->currency_code) {
|
||||
$amountto=$amount;
|
||||
} else {
|
||||
if (! $amountto)
|
||||
{
|
||||
$error++;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AmountTo")), null, 'errors');
|
||||
}
|
||||
}
|
||||
|
||||
if (($accountto->id != $accountfrom->id) && empty($error))
|
||||
{
|
||||
$db->begin();
|
||||
|
||||
@ -103,8 +113,7 @@ if ($action == 'add_confirm')
|
||||
|
||||
if (! $error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1*price2num($amount), '', '', $user);
|
||||
if (! ($bank_line_id_from > 0)) $error++;
|
||||
if ((! $error) && ($accountto->currency_code == $accountfrom->currency_code)) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount), '', '', $user);
|
||||
if ((! $error) && ($accountto->currency_code != $accountfrom->currency_code)) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount_to), '', '', $user);
|
||||
if (! $error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amountto), '', '', $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');
|
||||
@ -114,7 +123,7 @@ if ($action == 'add_confirm')
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$mesgs = $langs->trans("TransferFromToDone","<a href=\"card.php?id=".$accountfrom->id."\">".$accountfrom->label."</a>","<a href=\"card.php?id=".$accountto->id."\">".$accountto->label."</a>",$amount,$langs->transnoentities("Currency".$conf->currency));
|
||||
$mesgs = $langs->trans("TransferFromToDone","<a href=\"bankentries.php?id=".$accountfrom->id."\">".$accountfrom->label."</a>","<a href=\"bankentries.php?id=".$accountto->id."\">".$accountto->label."</a>",$amount,$langs->transnoentities("Currency".$conf->currency));
|
||||
setEventMessages($mesgs, null, 'mesgs');
|
||||
$db->commit();
|
||||
}
|
||||
@ -139,6 +148,58 @@ if ($action == 'add_confirm')
|
||||
*/
|
||||
|
||||
llxHeader();
|
||||
print ' <script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$(".selectbankaccount").change(function() {
|
||||
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.");
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$form=new Form($db);
|
||||
|
||||
@ -146,9 +207,8 @@ $account_from='';
|
||||
$account_to='';
|
||||
$label='';
|
||||
$amount='';
|
||||
$amount_to='';
|
||||
|
||||
if ($error)
|
||||
if($error)
|
||||
{
|
||||
$account_from = GETPOST('account_from','int');
|
||||
$account_to = GETPOST('account_to','int');
|
||||
@ -164,12 +224,12 @@ print "<br><br>";
|
||||
print '<form name="add" method="post" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
||||
|
||||
print '<input type="hidden" name="action" value="add_confirm">';
|
||||
print '<input type="hidden" name="action" value="add">';
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td>'.$langs->trans("TransferFrom").'</td><td>'.$langs->trans("TransferTo").'</td><td>'.$langs->trans("Date").'</td>';
|
||||
print '<td>'.$langs->trans("Description").'</td><td>'.$langs->trans("Amount").'</td>';
|
||||
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 '<td style="display:none" class="multicurrency">'.$langs->trans("AmountTo").'</td>';
|
||||
print '</tr>';
|
||||
|
||||
$var=false;
|
||||
@ -186,6 +246,8 @@ $form->select_date((! empty($dateo)?$dateo:''),'','','','','add');
|
||||
print "</td>\n";
|
||||
print '<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.$label.'"></td>';
|
||||
print '<td><input name="amount" class="flat" type="text" size="6" value="'.$amount.'"></td>';
|
||||
print '<td style="display:none" class="multicurrency"><input name="amountto" class="flat" type="text" size="6" value="'.$amountto.'"></td>';
|
||||
|
||||
print "</table>";
|
||||
|
||||
print '<br><div class="center"><input type="submit" class="button" value="'.$langs->trans("Add").'"></div>';
|
||||
|
||||
60
htdocs/core/ajax/getaccountcurrency.php
Normal file
60
htdocs/core/ajax/getaccountcurrency.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
|
||||
*
|
||||
* 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
|
||||
* (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, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* \file htdocs/core/ajax/vatrates.php
|
||||
* \brief File to load vat rates combobox
|
||||
*/
|
||||
|
||||
if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
|
||||
if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
|
||||
//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
|
||||
if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
|
||||
//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
|
||||
//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
|
||||
|
||||
require '../../main.inc.php';
|
||||
|
||||
$id = GETPOST('id','int');
|
||||
|
||||
/*
|
||||
* View
|
||||
*/
|
||||
|
||||
top_httphead();
|
||||
|
||||
//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
|
||||
|
||||
// Load original field value
|
||||
if (! empty($id))
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
$account=new Account($db);
|
||||
$result = $account->fetch($id);
|
||||
if ($result<0) {
|
||||
$return['value'] = '';
|
||||
$return['num'] = $result;
|
||||
$return['error'] = $account->errors[0];
|
||||
} else {
|
||||
$return['value'] = $account->currency_code;
|
||||
$return['num'] = $result;
|
||||
$return['error'] = '';
|
||||
}
|
||||
|
||||
echo json_encode($return);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user