NEW : Can transmer from bank account to bank account with different
currency
This commit is contained in:
parent
e7e4252244
commit
ffb8c684d0
@ -39,7 +39,7 @@ class Account extends CommonObject
|
||||
public $element = 'bank_account';
|
||||
public $table_element = 'bank_account';
|
||||
public $picto = 'account';
|
||||
|
||||
|
||||
/**
|
||||
* @var int Use id instead of rowid
|
||||
* @deprecated
|
||||
@ -538,7 +538,7 @@ class Account extends CommonObject
|
||||
$now=dol_now();
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_account (";
|
||||
$sql.= "datec";
|
||||
$sql.= ", ref";
|
||||
@ -619,14 +619,14 @@ class Account extends CommonObject
|
||||
$result=$this->insertExtraFields();
|
||||
if ($result < 0) $error++;
|
||||
}
|
||||
|
||||
|
||||
if (! $error && ! $notrigger)
|
||||
{
|
||||
// Call trigger
|
||||
$result=$this->call_trigger('BANKACCOUNT_CREATE',$user);
|
||||
if ($result < 0) $error++;
|
||||
// End call triggers
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -670,9 +670,9 @@ class Account extends CommonObject
|
||||
global $langs,$conf, $hookmanager;
|
||||
|
||||
$error=0;
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
// Clean parameters
|
||||
$this->state_id = ($this->state_id?$this->state_id:$this->state_id);
|
||||
$this->country_id = ($this->country_id?$this->country_id:$this->country_id);
|
||||
@ -739,7 +739,7 @@ class Account extends CommonObject
|
||||
if ($result < 0) $error++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (! $error && ! $notrigger)
|
||||
{
|
||||
// Call trigger
|
||||
@ -754,7 +754,7 @@ class Account extends CommonObject
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_print_error($this->db);
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
@ -906,7 +906,7 @@ class Account extends CommonObject
|
||||
|
||||
$this->date_creation = $this->db->jdate($obj->date_creation);
|
||||
$this->date_update = $this->db->jdate($obj->date_update);
|
||||
|
||||
|
||||
// Retreive all extrafield for thirdparty
|
||||
// fetch optionals attributes and labels
|
||||
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
|
||||
@ -923,7 +923,8 @@ class Account extends CommonObject
|
||||
}
|
||||
else
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
$this->error=$this->db->lasterror;
|
||||
$this->errors[]=$this->error;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -983,15 +984,15 @@ class Account extends CommonObject
|
||||
global $conf;
|
||||
|
||||
$error=0;
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
|
||||
// Delete link between tag and bank account
|
||||
if (! $error)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_account";
|
||||
$sql.= " WHERE fk_account = ".$this->id;
|
||||
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if (!$resql)
|
||||
{
|
||||
@ -999,15 +1000,15 @@ class Account extends CommonObject
|
||||
$this->error = "Error ".$this->db->lasterror();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_account";
|
||||
$sql.= " WHERE rowid = ".$this->rowid;
|
||||
|
||||
|
||||
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
|
||||
$result = $this->db->query($sql);
|
||||
if ($result)
|
||||
if ($result)
|
||||
{
|
||||
// Remove extrafields
|
||||
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
|
||||
@ -1020,13 +1021,13 @@ class Account extends CommonObject
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else
|
||||
{
|
||||
$error++;
|
||||
$this->error = "Error ".$this->db->lasterror();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
@ -1433,7 +1434,7 @@ class Account extends CommonObject
|
||||
* - DeskCode
|
||||
*
|
||||
* Some countries show less or more bank account properties to the user
|
||||
*
|
||||
*
|
||||
* @param int $includeibanbic 1=Return also key for IBAN and BIC
|
||||
* @return array
|
||||
* @see useDetailedBBAN
|
||||
@ -1554,7 +1555,7 @@ class AccountLine extends CommonObject
|
||||
var $element='bank';
|
||||
var $table_element='bank';
|
||||
var $picto = 'generic';
|
||||
|
||||
|
||||
var $id;
|
||||
var $ref;
|
||||
var $datec;
|
||||
@ -1842,7 +1843,7 @@ class AccountLine extends CommonObject
|
||||
function update_conciliation(User $user, $cat)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
// Check statement field
|
||||
@ -1854,7 +1855,7 @@ class AccountLine extends CommonObject
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."bank SET";
|
||||
$sql.= " rappro = 1";
|
||||
$sql.= ", num_releve = '".$this->db->escape($this->num_releve)."'";
|
||||
@ -2042,7 +2043,7 @@ class AccountLine extends CommonObject
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Return label of status (activity, closed)
|
||||
*
|
||||
@ -2053,7 +2054,7 @@ class AccountLine extends CommonObject
|
||||
{
|
||||
return $this->LibStatut($this->status,$mode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Renvoi le libelle d'un statut donne
|
||||
*
|
||||
@ -2097,6 +2098,6 @@ class AccountLine extends CommonObject
|
||||
if ($statut==1) return $langs->trans("InActivity").' '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -50,6 +50,7 @@ if ($action == 'add')
|
||||
$dateo = dol_mktime(12,0,0,GETPOST('remonth','int'),GETPOST('reday','int'),GETPOST('reyear','int'));
|
||||
$label = GETPOST('label','alpha');
|
||||
$amount= GETPOST('amount');
|
||||
$amountto= GETPOST('amountto');
|
||||
|
||||
if (! $label)
|
||||
{
|
||||
@ -71,6 +72,9 @@ if ($action == 'add')
|
||||
$error=1;
|
||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("TransferTo")), null, 'errors');
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
|
||||
@ -81,7 +85,18 @@ if ($action == 'add')
|
||||
$accountto=new Account($db);
|
||||
$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();
|
||||
|
||||
@ -102,7 +117,7 @@ if ($action == 'add')
|
||||
|
||||
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 (! $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');
|
||||
@ -137,6 +152,61 @@ if ($action == 'add')
|
||||
|
||||
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);
|
||||
|
||||
$account_from='';
|
||||
@ -165,6 +235,7 @@ 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><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;
|
||||
@ -181,6 +252,7 @@ $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>";
|
||||
|
||||
|
||||
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