diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 43b6dace19c..b0cf86403be 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -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"'); }*/ } - + } diff --git a/htdocs/compta/bank/transfer.php b/htdocs/compta/bank/transfer.php index 73e94a3d197..7c8d4a1826a 100644 --- a/htdocs/compta/bank/transfer.php +++ b/htdocs/compta/bank/transfer.php @@ -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 ' '; + + $form=new Form($db); $account_from=''; @@ -165,6 +235,7 @@ print ''; print ''; print ''; print ''; +print ''; print ''; $var=false; @@ -181,6 +252,7 @@ $form->select_date((! empty($dateo)?$dateo:''),'','','','','add'); print "\n"; print ''; print ''; +print ''; print "
'.$langs->trans("TransferFrom").''.$langs->trans("TransferTo").''.$langs->trans("Date").''.$langs->trans("Description").''.$langs->trans("Amount").'
"; diff --git a/htdocs/core/ajax/getaccountcurrency.php b/htdocs/core/ajax/getaccountcurrency.php new file mode 100644 index 00000000000..40e52672c0e --- /dev/null +++ b/htdocs/core/ajax/getaccountcurrency.php @@ -0,0 +1,60 @@ + + * + * 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 . + */ + +/** + * \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 ''."\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); +} +