diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php
index 0b4307f8a98..c84e7f47482 100644
--- a/htdocs/compta/bank/card.php
+++ b/htdocs/compta/bank/card.php
@@ -34,6 +34,7 @@ require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
$langs->load("banks");
+$langs->load("bills");
$langs->load("categories");
$langs->load("companies");
$langs->load("compta");
@@ -70,7 +71,7 @@ if ($_POST["action"] == 'add')
$account->clos = $_POST["clos"];
$account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1;
$account->url = $_POST["url"];
-
+
$account->bank = trim($_POST["bank"]);
$account->code_banque = trim($_POST["code_banque"]);
$account->code_guichet = trim($_POST["code_guichet"]);
@@ -94,8 +95,8 @@ if ($_POST["action"] == 'add')
$account->state_id = $_POST["account_state_id"];
$account->country_id = $_POST["account_country_id"];
- $account->min_allowed = $_POST["account_min_allowed"];
- $account->min_desired = $_POST["account_min_desired"];
+ $account->min_allowed = GETPOST("account_min_allowed",'int');
+ $account->min_desired = GETPOST("account_min_desired",'int');
$account->comment = trim($_POST["account_comment"]);
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number))
@@ -169,8 +170,8 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"])
$account->state_id = $_POST["account_state_id"];
$account->country_id = $_POST["account_country_id"];
- $account->min_allowed = $_POST["account_min_allowed"];
- $account->min_desired = $_POST["account_min_desired"];
+ $account->min_allowed = GETPOST("account_min_allowed",'int');
+ $account->min_desired = GETPOST("account_min_desired",'int');
$account->comment = trim($_POST["account_comment"]);
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number))
@@ -251,9 +252,6 @@ if ($action == 'create')
document.formsoc.action.value="create";
document.formsoc.submit();
});
- })'."\n";
-
- print 'jQuery(document).ready(function () {
jQuery("#selectaccount_country_id").change(function() {
document.formsoc.action.value="create";
document.formsoc.submit();
@@ -275,7 +273,7 @@ if ($action == 'create')
// Label
print '
'.$langs->trans("LabelBankCashAccount").' ';
- print ' ';
+ print ' ';
// Type
print ''.$langs->trans("AccountType").' ';
@@ -299,15 +297,17 @@ if ($action == 'create')
print $form->selectarray("clos",array(0=>$account->status[0],1=>$account->status[1]),(isset($_POST["clos"])?$_POST["clos"]:$account->clos));
print ' ';
- // Country
- print ''.$langs->trans("BankAccountCountry").' ';
- print '';
+ // Country
$selectedcode='';
if (isset($_POST["account_country_id"]))
{
$selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$account->country_code;
}
else if (empty($selectedcode)) $selectedcode=$mysoc->country_code;
+ $account->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
+
+ print ' '.$langs->trans("BankAccountCountry").' ';
+ print '';
print $form->select_country($selectedcode,'account_country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print ' ';
@@ -333,10 +333,10 @@ if ($action == 'create')
print '';
// Editor wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- $doleditor=new DolEditor('account_comment',$account->comment,'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,10,70);
+ $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$account->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,4,70);
$doleditor->Create();
print ' ';
-
+
// Other attributes
$parameters=array('colspan' => 3);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$account,$action); // Note that $action and $object may have been modified by hook
@@ -353,7 +353,7 @@ if ($action == 'create')
// Sold
print ''.$langs->trans("InitialBankBalance").' ';
- print ' solde)).'"> ';
+ print ' solde)).'"> ';
print ''.$langs->trans("Date").' ';
print '';
@@ -445,10 +445,10 @@ if ($action == 'create')
if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
// IBAN
- print ' '.$langs->trans($ibankey).' ';
+ print ''.$langs->trans($ibankey).' ';
print ' ';
- print ''.$langs->trans($bickey).' ';
+ print ''.$langs->trans($bickey).' ';
print ' ';
print ''.$langs->trans("BankAccountDomiciliation").' ';
@@ -468,25 +468,25 @@ if ($action == 'create')
print '';
print ' ';
}
-
+
print '';
@@ -599,7 +599,7 @@ else
print " \n";
print ''.$langs->trans("Comment").' ';
- print ''.$account->comment.' ';
+ print ''.dol_htmlentitiesbr($account->comment).' ';
// Other attributes
$parameters=array('colspan' => 3);
@@ -612,11 +612,11 @@ else
print '';
print ' ';
-
+
if ($account->type == 0 || $account->type == 1)
{
print '';
-
+
print ''.$langs->trans("BankName").' ';
print ''.$account->bank.' ';
@@ -783,7 +783,7 @@ else
document.formsoc.submit();
});
})'."\n";
-
+
print 'jQuery(document).ready(function () {
jQuery("#selectaccount_country_id").change(function() {
document.formsoc.action.value="edit";
@@ -834,11 +834,13 @@ else
// Country
$account->country_id=$account->country_id?$account->country_id:$mysoc->country_id;
- print ''.$langs->trans("Country").' ';
- print '';
$selectedcode=$account->country_code;
if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"];
else if (empty($selectedcode)) $selectedcode=$mysoc->country_code;
+ $account->country_code = getCountry($selectedcode, 2); // Force country code on account to have following field on bank fields matching country rules
+
+ print ' '.$langs->trans("Country").' ';
+ print '';
print $form->select_country($selectedcode,'account_country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print ' ';
@@ -881,7 +883,7 @@ else
print '';
// Editor wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
- $doleditor=new DolEditor('account_comment',(isset($_POST["account_comment"])?$_POST["account_comment"]:$account->comment),'',200,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,10,70);
+ $doleditor=new DolEditor('account_comment',(GETPOST("account_comment")?GETPOST("account_comment"):$account->comment),'',90,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,4,70);
$doleditor->Create();
print ' ';
@@ -898,7 +900,7 @@ else
if ($_POST["type"] == 0 || $_POST["type"] == 1)
{
print '';
-
+
// If bank account
print ''.$langs->trans("BankName").' ';
print ' ';
diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php
index 98ef24e177d..cfbda320fb7 100644
--- a/htdocs/compta/bank/class/account.class.php
+++ b/htdocs/compta/bank/class/account.class.php
@@ -468,7 +468,7 @@ class Account extends CommonObject
$this->error=$this->db->lasterror();
return -3;
}
-
+
// Actions on extra fields (by external module or standard code)
$hookmanager->initHooks(array('bankdao'));
$parameters=array('id'=>$this->id);
@@ -513,8 +513,6 @@ class Account extends CommonObject
global $langs,$conf, $hookmanager;
// Clean parameters
- if (! $this->min_allowed) $this->min_allowed=0;
- if (! $this->min_desired) $this->min_desired=0;
$this->state_id = ($this->state_id?$this->state_id:$this->state_id);
$this->country_id = ($this->country_id?$this->country_id:$this->country_id);
@@ -544,7 +542,7 @@ class Account extends CommonObject
$sql.= ",url = ".($this->url?"'".$this->url."'":"null");
$sql.= ",account_number = '".$this->account_number."'";
$sql.= ",accountancy_journal = '".$this->accountancy_journal."'";
-
+
$sql.= ",bank = '".$this->db->escape($this->bank)."'";
$sql.= ",code_banque='".$this->code_banque."'";
$sql.= ",code_guichet='".$this->code_guichet."'";
@@ -558,8 +556,8 @@ class Account extends CommonObject
$sql.= ",currency_code = '".$this->currency_code."'";
- $sql.= ",min_allowed = '".price2num($this->min_allowed)."'";
- $sql.= ",min_desired = '".price2num($this->min_desired)."'";
+ $sql.= ",min_allowed = ".($this->min_allowed != '' ? price2num($this->min_allowed) : "null");
+ $sql.= ",min_desired = ".($this->min_desired != '' ? price2num($this->min_desired) : "null");
$sql.= ",comment = '".$this->db->escape($this->comment)."'";
$sql.= ",state_id = ".($this->state_id>0?"'".$this->state_id."'":"null");
@@ -572,7 +570,7 @@ class Account extends CommonObject
$result = $this->db->query($sql);
if ($result)
{
-
+
// Actions on extra fields (by external module or standard code)
$hookmanager->initHooks(array('bankdao'));
$parameters=array('id'=>$this->id);
@@ -589,8 +587,8 @@ class Account extends CommonObject
}
}
else if ($reshook < 0) return -1;
-
-
+
+
return 1;
}
else
@@ -736,15 +734,15 @@ class Account extends CommonObject
$this->min_allowed = $obj->min_allowed;
$this->min_desired = $obj->min_desired;
$this->comment = $obj->comment;
-
+
// Retreive all extrafield for thirdparty
// fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels);
-
-
+
+
return 1;
}
else
@@ -776,7 +774,7 @@ class Account extends CommonObject
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql);
if ($result) {
-
+
// Remove extrafields
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
{
@@ -787,7 +785,7 @@ class Account extends CommonObject
dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
}
}
-
+
return 1;
}
else {
@@ -1076,7 +1074,7 @@ class Account extends CommonObject
*
* @return int 0=No bank code need + Account number is enough
* 1=Need 2 fields for bank code: Bank, Desk (France, Spain, ...) + Account number and key
- * 2=Neek 1 field for bank code: Bank only (Sort code for Great Britain, BSB for Australia) + Account number
+ * 2=Need 1 field for bank code: Bank only (Sort code for Great Britain, BSB for Australia) + Account number
*/
function useDetailedBBAN()
{