Some fix after merging bank account number form

This commit is contained in:
Laurent Destailleur 2015-03-04 21:59:03 +01:00
parent 40adbe5a72
commit 8e29dcdb79
2 changed files with 44 additions and 44 deletions

View File

@ -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'; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
$langs->load("banks"); $langs->load("banks");
$langs->load("bills");
$langs->load("categories"); $langs->load("categories");
$langs->load("companies"); $langs->load("companies");
$langs->load("compta"); $langs->load("compta");
@ -70,7 +71,7 @@ if ($_POST["action"] == 'add')
$account->clos = $_POST["clos"]; $account->clos = $_POST["clos"];
$account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1; $account->rappro = (isset($_POST["norappro"]) && $_POST["norappro"])?0:1;
$account->url = $_POST["url"]; $account->url = $_POST["url"];
$account->bank = trim($_POST["bank"]); $account->bank = trim($_POST["bank"]);
$account->code_banque = trim($_POST["code_banque"]); $account->code_banque = trim($_POST["code_banque"]);
$account->code_guichet = trim($_POST["code_guichet"]); $account->code_guichet = trim($_POST["code_guichet"]);
@ -94,8 +95,8 @@ if ($_POST["action"] == 'add')
$account->state_id = $_POST["account_state_id"]; $account->state_id = $_POST["account_state_id"];
$account->country_id = $_POST["account_country_id"]; $account->country_id = $_POST["account_country_id"];
$account->min_allowed = $_POST["account_min_allowed"]; $account->min_allowed = GETPOST("account_min_allowed",'int');
$account->min_desired = $_POST["account_min_desired"]; $account->min_desired = GETPOST("account_min_desired",'int');
$account->comment = trim($_POST["account_comment"]); $account->comment = trim($_POST["account_comment"]);
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) 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->state_id = $_POST["account_state_id"];
$account->country_id = $_POST["account_country_id"]; $account->country_id = $_POST["account_country_id"];
$account->min_allowed = $_POST["account_min_allowed"]; $account->min_allowed = GETPOST("account_min_allowed",'int');
$account->min_desired = $_POST["account_min_desired"]; $account->min_desired = GETPOST("account_min_desired",'int');
$account->comment = trim($_POST["account_comment"]); $account->comment = trim($_POST["account_comment"]);
if ($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED && empty($account->account_number)) 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.action.value="create";
document.formsoc.submit(); document.formsoc.submit();
}); });
})'."\n";
print 'jQuery(document).ready(function () {
jQuery("#selectaccount_country_id").change(function() { jQuery("#selectaccount_country_id").change(function() {
document.formsoc.action.value="create"; document.formsoc.action.value="create";
document.formsoc.submit(); document.formsoc.submit();
@ -275,7 +273,7 @@ if ($action == 'create')
// Label // Label
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("LabelBankCashAccount").'</td>'; print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("LabelBankCashAccount").'</td>';
print '<td colspan="3"><input size="30" type="text" class="flat" name="label" value="'.$_POST["label"].'"></td></tr>'; print '<td colspan="3"><input size="30" type="text" class="flat" name="label" value="'.GETPOST("label").'"></td></tr>';
// Type // Type
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("AccountType").'</td>'; print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("AccountType").'</td>';
@ -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 $form->selectarray("clos",array(0=>$account->status[0],1=>$account->status[1]),(isset($_POST["clos"])?$_POST["clos"]:$account->clos));
print '</td></tr>'; print '</td></tr>';
// Country // Country
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("BankAccountCountry").'</td>';
print '<td colspan="3">';
$selectedcode=''; $selectedcode='';
if (isset($_POST["account_country_id"])) if (isset($_POST["account_country_id"]))
{ {
$selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$account->country_code; $selectedcode=$_POST["account_country_id"]?$_POST["account_country_id"]:$account->country_code;
} }
else if (empty($selectedcode)) $selectedcode=$mysoc->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 '<tr><td valign="top" class="fieldrequired">'.$langs->trans("BankAccountCountry").'</td>';
print '<td colspan="3">';
print $form->select_country($selectedcode,'account_country_id'); print $form->select_country($selectedcode,'account_country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td></tr>'; print '</td></tr>';
@ -333,10 +333,10 @@ if ($action == 'create')
print '<td colspan="3">'; print '<td colspan="3">';
// Editor wysiwyg // Editor wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; 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(); $doleditor->Create();
print '</td></tr>'; print '</td></tr>';
// Other attributes // Other attributes
$parameters=array('colspan' => 3); $parameters=array('colspan' => 3);
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$account,$action); // Note that $action and $object may have been modified by hook $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 // Sold
print '<tr><td valign="top" width="25%">'.$langs->trans("InitialBankBalance").'</td>'; print '<tr><td valign="top" width="25%">'.$langs->trans("InitialBankBalance").'</td>';
print '<td colspan="3"><input size="12" type="text" class="flat" name="solde" value="'.($_POST["solde"]?$_POST["solde"]:price2num($account->solde)).'"></td></tr>'; print '<td colspan="3"><input size="12" type="text" class="flat" name="solde" value="'.(GETPOST("solde")?GETPOST("solde"):price2num($account->solde)).'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("Date").'</td>'; print '<tr><td valign="top">'.$langs->trans("Date").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
@ -445,10 +445,10 @@ if ($action == 'create')
if ($account->getCountryCode() == 'IN') $bickey="SWIFT"; if ($account->getCountryCode() == 'IN') $bickey="SWIFT";
// IBAN // IBAN
print '<tr><td valign="top">'.$langs->trans($ibankey).'</td>'; print '<tr><td>'.$langs->trans($ibankey).'</td>';
print '<td colspan="3"><input size="34" maxlength="34" type="text" class="flat" name="iban" value="'.$account->iban.'"></td></tr>'; print '<td colspan="3"><input size="34" maxlength="34" type="text" class="flat" name="iban" value="'.$account->iban.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans($bickey).'</td>'; print '<tr><td>'.$langs->trans($bickey).'</td>';
print '<td colspan="3"><input size="11" maxlength="11" type="text" class="flat" name="bic" value="'.$account->bic.'"></td></tr>'; print '<td colspan="3"><input size="11" maxlength="11" type="text" class="flat" name="bic" value="'.$account->bic.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="3">'; print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="3">';
@ -468,25 +468,25 @@ if ($action == 'create')
print '</table>'; print '</table>';
print '<br>'; print '<br>';
} }
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// Accountancy code // Accountancy code
if (! empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED)) if (! empty($conf->global->MAIN_BANK_ACCOUNTANCY_CODE_ALWAYS_REQUIRED))
{ {
print '<tr><td valign="top" class="fieldrequired" width="25%">'.$langs->trans("AccountancyCode").'</td>'; print '<tr><td valign="top" class="fieldrequired" width="25%">'.$langs->trans("AccountancyCode").'</td>';
print '<td colspan="3"><input type="text" name="account_number" value="'.$account->account_number.'"></td></tr>'; print '<td colspan="3"><input type="text" name="account_number" value="'.(GETPOST("account_number")?GETPOST('account_number'):$account->account_number).'"></td></tr>';
} }
else else
{ {
print '<tr><td valign="top" width="25%">'.$langs->trans("AccountancyCode").'</td>'; print '<tr><td valign="top" width="25%">'.$langs->trans("AccountancyCode").'</td>';
print '<td colspan="3"><input type="text" name="account_number" value="'.$account->account_number.'"></td></tr>'; print '<td colspan="3"><input type="text" name="account_number" value="'.(GETPOST("account_number")?GETPOST('account_number'):$account->account_number).'"></td></tr>';
} }
// Accountancy journal // Accountancy journal
if (! empty($conf->accounting->enabled)) if (! empty($conf->accounting->enabled))
{ {
print '<tr><td valign="top">'.$langs->trans("AccountancyJournal").'</td>'; print '<tr><td valign="top">'.$langs->trans("AccountancyJournal").'</td>';
print '<td colspan="3"><input type="text" name="accountancy_journal" value="'.$account->accountancy_journal.'"></td></tr>'; print '<td colspan="3"><input type="text" name="accountancy_journal" value="'.(GETPOST("accountancy_journal")?GETPOST('accountancy_journal'):$account->accountancy_journal).'"></td></tr>';
} }
print '</table>'; print '</table>';
@ -599,7 +599,7 @@ else
print "</td></tr>\n"; print "</td></tr>\n";
print '<tr><td valign="top">'.$langs->trans("Comment").'</td>'; print '<tr><td valign="top">'.$langs->trans("Comment").'</td>';
print '<td colspan="3">'.$account->comment.'</td></tr>'; print '<td colspan="3">'.dol_htmlentitiesbr($account->comment).'</td></tr>';
// Other attributes // Other attributes
$parameters=array('colspan' => 3); $parameters=array('colspan' => 3);
@ -612,11 +612,11 @@ else
print '</table>'; print '</table>';
print '<br>'; print '<br>';
if ($account->type == 0 || $account->type == 1) if ($account->type == 0 || $account->type == 1)
{ {
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td valign="top" width="25%">'.$langs->trans("BankName").'</td>'; print '<tr><td valign="top" width="25%">'.$langs->trans("BankName").'</td>';
print '<td colspan="3">'.$account->bank.'</td></tr>'; print '<td colspan="3">'.$account->bank.'</td></tr>';
@ -783,7 +783,7 @@ else
document.formsoc.submit(); document.formsoc.submit();
}); });
})'."\n"; })'."\n";
print 'jQuery(document).ready(function () { print 'jQuery(document).ready(function () {
jQuery("#selectaccount_country_id").change(function() { jQuery("#selectaccount_country_id").change(function() {
document.formsoc.action.value="edit"; document.formsoc.action.value="edit";
@ -834,11 +834,13 @@ else
// Country // Country
$account->country_id=$account->country_id?$account->country_id:$mysoc->country_id; $account->country_id=$account->country_id?$account->country_id:$mysoc->country_id;
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("Country").'</td>';
print '<td colspan="3">';
$selectedcode=$account->country_code; $selectedcode=$account->country_code;
if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"]; if (isset($_POST["account_country_id"])) $selectedcode=$_POST["account_country_id"];
else if (empty($selectedcode)) $selectedcode=$mysoc->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 '<tr><td valign="top" class="fieldrequired">'.$langs->trans("Country").'</td>';
print '<td colspan="3">';
print $form->select_country($selectedcode,'account_country_id'); print $form->select_country($selectedcode,'account_country_id');
if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
print '</td></tr>'; print '</td></tr>';
@ -881,7 +883,7 @@ else
print '<td colspan="3">'; print '<td colspan="3">';
// Editor wysiwyg // Editor wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; 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(); $doleditor->Create();
print '</td></tr>'; print '</td></tr>';
@ -898,7 +900,7 @@ else
if ($_POST["type"] == 0 || $_POST["type"] == 1) if ($_POST["type"] == 0 || $_POST["type"] == 1)
{ {
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
// If bank account // If bank account
print '<tr><td valign="top" width="25%">'.$langs->trans("BankName").'</td>'; print '<tr><td valign="top" width="25%">'.$langs->trans("BankName").'</td>';
print '<td colspan="3"><input size="30" type="text" class="flat" name="bank" value="'.$account->bank.'"></td>'; print '<td colspan="3"><input size="30" type="text" class="flat" name="bank" value="'.$account->bank.'"></td>';

View File

@ -468,7 +468,7 @@ class Account extends CommonObject
$this->error=$this->db->lasterror(); $this->error=$this->db->lasterror();
return -3; return -3;
} }
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
$hookmanager->initHooks(array('bankdao')); $hookmanager->initHooks(array('bankdao'));
$parameters=array('id'=>$this->id); $parameters=array('id'=>$this->id);
@ -513,8 +513,6 @@ class Account extends CommonObject
global $langs,$conf, $hookmanager; global $langs,$conf, $hookmanager;
// Clean parameters // 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->state_id = ($this->state_id?$this->state_id:$this->state_id);
$this->country_id = ($this->country_id?$this->country_id:$this->country_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.= ",url = ".($this->url?"'".$this->url."'":"null");
$sql.= ",account_number = '".$this->account_number."'"; $sql.= ",account_number = '".$this->account_number."'";
$sql.= ",accountancy_journal = '".$this->accountancy_journal."'"; $sql.= ",accountancy_journal = '".$this->accountancy_journal."'";
$sql.= ",bank = '".$this->db->escape($this->bank)."'"; $sql.= ",bank = '".$this->db->escape($this->bank)."'";
$sql.= ",code_banque='".$this->code_banque."'"; $sql.= ",code_banque='".$this->code_banque."'";
$sql.= ",code_guichet='".$this->code_guichet."'"; $sql.= ",code_guichet='".$this->code_guichet."'";
@ -558,8 +556,8 @@ class Account extends CommonObject
$sql.= ",currency_code = '".$this->currency_code."'"; $sql.= ",currency_code = '".$this->currency_code."'";
$sql.= ",min_allowed = '".price2num($this->min_allowed)."'"; $sql.= ",min_allowed = ".($this->min_allowed != '' ? price2num($this->min_allowed) : "null");
$sql.= ",min_desired = '".price2num($this->min_desired)."'"; $sql.= ",min_desired = ".($this->min_desired != '' ? price2num($this->min_desired) : "null");
$sql.= ",comment = '".$this->db->escape($this->comment)."'"; $sql.= ",comment = '".$this->db->escape($this->comment)."'";
$sql.= ",state_id = ".($this->state_id>0?"'".$this->state_id."'":"null"); $sql.= ",state_id = ".($this->state_id>0?"'".$this->state_id."'":"null");
@ -572,7 +570,7 @@ class Account extends CommonObject
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) if ($result)
{ {
// Actions on extra fields (by external module or standard code) // Actions on extra fields (by external module or standard code)
$hookmanager->initHooks(array('bankdao')); $hookmanager->initHooks(array('bankdao'));
$parameters=array('id'=>$this->id); $parameters=array('id'=>$this->id);
@ -589,8 +587,8 @@ class Account extends CommonObject
} }
} }
else if ($reshook < 0) return -1; else if ($reshook < 0) return -1;
return 1; return 1;
} }
else else
@ -736,15 +734,15 @@ class Account extends CommonObject
$this->min_allowed = $obj->min_allowed; $this->min_allowed = $obj->min_allowed;
$this->min_desired = $obj->min_desired; $this->min_desired = $obj->min_desired;
$this->comment = $obj->comment; $this->comment = $obj->comment;
// Retreive all extrafield for thirdparty // Retreive all extrafield for thirdparty
// fetch optionals attributes and labels // fetch optionals attributes and labels
require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'); require_once(DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php');
$extrafields=new ExtraFields($this->db); $extrafields=new ExtraFields($this->db);
$extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true);
$this->fetch_optionals($this->id,$extralabels); $this->fetch_optionals($this->id,$extralabels);
return 1; return 1;
} }
else else
@ -776,7 +774,7 @@ class Account extends CommonObject
dol_syslog(get_class($this)."::delete", LOG_DEBUG); dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$result = $this->db->query($sql); $result = $this->db->query($sql);
if ($result) { if ($result) {
// Remove extrafields // Remove extrafields
if ((empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used 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); dol_syslog(get_class($this)."::delete error -4 ".$this->error, LOG_ERR);
} }
} }
return 1; return 1;
} }
else { else {
@ -1076,7 +1074,7 @@ class Account extends CommonObject
* *
* @return int 0=No bank code need + Account number is enough * @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 * 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() function useDetailedBBAN()
{ {