NEW : Can transmer from bank account to bank account with different
currency
This commit is contained in:
parent
e7e4252244
commit
ffb8c684d0
@ -923,7 +923,8 @@ class Account extends CommonObject
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
dol_print_error($this->db);
|
$this->error=$this->db->lasterror;
|
||||||
|
$this->errors[]=$this->error;
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -50,6 +50,7 @@ if ($action == 'add')
|
|||||||
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
|
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
|
||||||
$label = GETPOST('label','alpha');
|
$label = GETPOST('label','alpha');
|
||||||
$amount= GETPOST('amount');
|
$amount= GETPOST('amount');
|
||||||
|
$amountto= GETPOST('amountto');
|
||||||
|
|
||||||
if (! $label)
|
if (! $label)
|
||||||
{
|
{
|
||||||
@ -71,6 +72,9 @@ if ($action == 'add')
|
|||||||
$error=1;
|
$error=1;
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TransferTo")), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TransferTo")), null, 'errors');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (! $error)
|
if (! $error)
|
||||||
{
|
{
|
||||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||||
@ -81,7 +85,18 @@ if ($action == 'add')
|
|||||||
$accountto=new Account($db);
|
$accountto=new Account($db);
|
||||||
$accountto->fetch(GETPOST('account_to','int'));
|
$accountto->fetch(GETPOST('account_to','int'));
|
||||||
|
|
||||||
if (($accountto->id != $accountfrom->id) && ($accountto->currency_code == $accountfrom->currency_code))
|
if ($accountto->currency_code == $accountfrom->currency_code) {
|
||||||
|
$amountto=$amount;
|
||||||
|
} else {
|
||||||
|
if (! $amountto)
|
||||||
|
{
|
||||||
|
$error=1;
|
||||||
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("AmountTo")), null, 'errors');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (($accountto->id != $accountfrom->id) && empty($error))
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
@ -102,7 +117,7 @@ if ($action == 'add')
|
|||||||
|
|
||||||
if (! $error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1*price2num($amount), '', '', $user);
|
if (! $error) $bank_line_id_from = $accountfrom->addline($dateo, $typefrom, $label, -1*price2num($amount), '', '', $user);
|
||||||
if (! ($bank_line_id_from > 0)) $error++;
|
if (! ($bank_line_id_from > 0)) $error++;
|
||||||
if (! $error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amount), '', '', $user);
|
if (! $error) $bank_line_id_to = $accountto->addline($dateo, $typeto, $label, price2num($amountto), '', '', $user);
|
||||||
if (! ($bank_line_id_to > 0)) $error++;
|
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 (! $error) $result=$accountfrom->add_url_line($bank_line_id_from, $bank_line_id_to, DOL_URL_ROOT.'/compta/bank/ligne.php?rowid=', '(banktransfert)', 'banktransfert');
|
||||||
@ -137,6 +152,61 @@ if ($action == 'add')
|
|||||||
|
|
||||||
llxHeader();
|
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);
|
$form=new Form($db);
|
||||||
|
|
||||||
$account_from='';
|
$account_from='';
|
||||||
@ -165,6 +235,7 @@ print '<input type="hidden" name="action" value="add">';
|
|||||||
print '<table class="noborder" width="100%">';
|
print '<table class="noborder" width="100%">';
|
||||||
print '<tr class="liste_titre">';
|
print '<tr class="liste_titre">';
|
||||||
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>'.$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>';
|
print '</tr>';
|
||||||
|
|
||||||
$var=false;
|
$var=false;
|
||||||
@ -181,6 +252,7 @@ $form->select_date((! empty($dateo)?$dateo:''),'','','','','add');
|
|||||||
print "</td>\n";
|
print "</td>\n";
|
||||||
print '<td><input name="label" class="flat quatrevingtpercent" type="text" value="'.$label.'"></td>';
|
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><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 "</table>";
|
||||||
|
|
||||||
|
|||||||
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