Merge pull request #5424 from atm-florian/dev_fix5353

NEW #5353 IBAN and BIC should be now always mandatory for all country regarding accounting managment
This commit is contained in:
Laurent Destailleur 2016-07-26 15:57:56 +02:00 committed by GitHub
commit 6d0ebbc4a3
9 changed files with 304 additions and 190 deletions

View File

@ -187,7 +187,9 @@
<severity>0</severity> <severity>0</severity>
</rule> </rule>
<rule ref="PEAR.Commenting.ClassComment.MissingTag" /> <rule ref="PEAR.Commenting.ClassComment.MissingTag">
<severity>0</severity>
</rule>
<rule ref="PEAR.Commenting.ClassComment.MissingAuthorTag"> <rule ref="PEAR.Commenting.ClassComment.MissingAuthorTag">
<severity>0</severity> <severity>0</severity>

View File

@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
* Class Skeleton_Class * Class Skeleton_Class
* *
* Put here description of your class * Put here description of your class
*
* @see CommonObject * @see CommonObject
*/ */
class Skeleton_Class extends CommonObject class Skeleton_Class extends CommonObject

View File

@ -258,6 +258,10 @@ class Account extends CommonObject
$string .= $this->code_guichet.' '; $string .= $this->code_guichet.' ';
} elseif ($val == 'BankAccountNumberKey') { } elseif ($val == 'BankAccountNumberKey') {
$string .= $this->cle_rib.' '; $string .= $this->cle_rib.' ';
}elseif ($val == 'BIC') {
$string .= $this->bic.' ';
}elseif ($val == 'IBAN') {
$string .= $this->iban.' ';
} }
} }
@ -1293,6 +1297,55 @@ class Account extends CommonObject
return 0; return 0;
} }
/**
* Return 1 is IBAN is need for UE country
*
* @return int 1 yes / 0 No
*/
function needIBAN()
{
$country_code=$this->getCountryCode();
$country_code_in_EEC=array(
'AT', // Austria
'BE', // Belgium
'BG', // Bulgaria
'CY', // Cyprus
'CZ', // Czech republic
'DE', // Germany
'DK', // Danemark
'EE', // Estonia
'ES', // Spain
'FI', // Finland
'FR', // France
'GB', // United Kingdom
'GR', // Greece
'HR', // Croatia
'NL', // Holland
'HU', // Hungary
'IE', // Ireland
'IM', // Isle of Man - Included in UK
'IT', // Italy
'LT', // Lithuania
'LU', // Luxembourg
'LV', // Latvia
'MC', // Monaco - Included in France
'MT', // Malta
//'NO', // Norway
'PL', // Poland
'PT', // Portugal
'RO', // Romania
'SE', // Sweden
'SK', // Slovakia
'SI', // Slovenia
'UK', // United Kingdom
//'CH', // Switzerland - No. Swizerland in not in EEC
);
if (in_array($country_code,$country_code_in_EEC)) return 1; // France, Spain, Gabon, ...
return 0;
}
/** /**
* Load miscellaneous information for tab "Info" * Load miscellaneous information for tab "Info"
* *
@ -1323,18 +1376,26 @@ class Account extends CommonObject
$detailedBBAN = $this->useDetailedBBAN(); $detailedBBAN = $this->useDetailedBBAN();
if ($detailedBBAN == 0) { if ($detailedBBAN == 0) {
return array( $fieldarray= array(
'BankAccountNumber' 'BankAccountNumber'
); );
} elseif ($detailedBBAN == 2) { } elseif ($detailedBBAN == 2) {
return array( $fieldarray= array(
'BankCode', 'BankCode',
'BankAccountNumber' 'BankAccountNumber'
); );
} else {
$fieldarray=self::getAccountNumberOrder();
}
if ($this->needIBAN()) {
$fieldarray[]='IBAN';
$fieldarray[]='BIC';
} }
//Get the order the properties are shown //Get the order the properties are shown
return self::getAccountNumberOrder(); return $fieldarray;
} }
/** /**
@ -1352,10 +1413,10 @@ class Account extends CommonObject
global $conf; global $conf;
$fieldlists = array( $fieldlists = array(
'BankCode', 'BankCode',
'DeskCode', 'DeskCode',
'BankAccountNumber', 'BankAccountNumber',
'BankAccountNumberKey' 'BankAccountNumberKey'
); );
if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) { if (!empty($conf->global->BANK_SHOW_ORDER_OPTION)) {

View File

@ -706,8 +706,12 @@ function pdf_bank(&$pdf,$outputlangs,$curx,$cury,$account,$onlynumber=0,$default
// Key // Key
$tmplength = 13; $tmplength = 13;
$content = $account->cle_rib; $content = $account->cle_rib;
}elseif ($val == 'IBAN' || $val == 'BIC') {
// Key
$tmplength = 0;
$content = '';
} else { } else {
dol_print_error($this->db, 'Unexpected value for getFieldsToShow: '.$val); dol_print_error($account->db, 'Unexpected value for getFieldsToShow: '.$val);
break; break;
} }

View File

@ -200,7 +200,7 @@ class mailing_advthirdparties extends MailingTargets
* For example if this selector is used to extract 500 different * For example if this selector is used to extract 500 different
* emails from a text file, this function must return 500. * emails from a text file, this function must return 500.
* *
* @param string $sql Sql request to use * @param string $sql Not use here
* @return int Nb of recipients * @return int Nb of recipients
*/ */
function getNbOfRecipients($sql='') function getNbOfRecipients($sql='')

View File

@ -233,7 +233,7 @@ class CompanyBankAccount extends Account
{ {
$rib = ''; $rib = '';
if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic ) {
if ($this->label && $displayriblabel) { if ($this->label && $displayriblabel) {
$rib = $this->label." : "; $rib = $this->label." : ";

View File

@ -2216,6 +2216,7 @@ class Societe extends CommonObject
function display_rib($mode='label') function display_rib($mode='label')
{ {
require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
$bac = new CompanyBankAccount($this->db); $bac = new CompanyBankAccount($this->db);
$bac->fetch(0,$this->id); $bac->fetch(0,$this->id);
@ -2227,6 +2228,7 @@ class Societe extends CommonObject
{ {
if (empty($bac->rum)) if (empty($bac->rum))
{ {
require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
$prelevement = new BonPrelevement($this->db); $prelevement = new BonPrelevement($this->db);
$bac->fetch_thirdparty(); $bac->fetch_thirdparty();
$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id); $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
@ -3499,13 +3501,11 @@ class Societe extends CommonObject
* Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some
* Because this function is meant to be executed within a transaction, we won't take care of it. * Because this function is meant to be executed within a transaction, we won't take care of it.
*/ */
$sql = 'SELECT rowid $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
FROM '.MAIN_DB_PREFIX.'societe_commerciaux $sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( ';
WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( $sql = ' SELECT fk_user ';
SELECT fk_user $sql = ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
FROM '.MAIN_DB_PREFIX.'societe_commerciaux $sql = ' WHERE fk_soc = '.(int) $origin_id.') ';
WHERE fk_soc = '.(int) $origin_id.'
);';
$query = $db->query($sql); $query = $db->query($sql);

View File

@ -59,43 +59,73 @@ if ($action == 'update' && ! $_POST["cancel"])
// Modification // Modification
$account = new CompanyBankAccount($db); $account = new CompanyBankAccount($db);
$account->fetch($id);
$account->socid = $object->id; if (! GETPOST('label'))
$account->bank = $_POST["bank"];
$account->label = $_POST["label"];
$account->courant = $_POST["courant"];
$account->clos = $_POST["clos"];
$account->code_banque = $_POST["code_banque"];
$account->code_guichet = $_POST["code_guichet"];
$account->number = $_POST["number"];
$account->cle_rib = $_POST["cle_rib"];
$account->bic = $_POST["bic"];
$account->iban = $_POST["iban"];
$account->domiciliation = $_POST["domiciliation"];
$account->proprio = $_POST["proprio"];
$account->owner_address = $_POST["owner_address"];
$account->frstrecur = GETPOST('frstrecur');
$result = $account->update($user);
if (! $result)
{ {
setEventMessages($account->error, $account->errors, 'errors'); setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Label")), null, 'errors');
$_GET["action"]='edit'; // Force chargement page edition $action='update';
$error++;
} }
else if (! GETPOST('bank'))
{ {
// If this account is the default bank account, we disable others setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankName")), null, 'errors');
if ($account->default_rib) $action='update';
$error++;
}
if ($account->needIBAN() == 1)
{
if (! GETPOST('iban'))
{ {
$account->setAsDefault($id); // This will make sure there is only one default rib setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors');
$action='update';
$error++;
}
if (! GETPOST('bic'))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors');
$action='update';
$error++;
} }
$url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id;
header('Location: '.$url);
exit;
} }
$account->fetch($id);
if (! $error)
{
$account->socid = $object->id;
$account->bank = GETPOST('bank','alpha');
$account->label = GETPOST('label','alpha');
$account->courant = GETPOST('courant','alpha');
$account->clos = GETPOST('clos','alpha');
$account->code_banque = GETPOST('code_banque','alpha');
$account->code_guichet = GETPOST('code_guichet','alpha');
$account->number = GETPOST('number','alpha');
$account->cle_rib = GETPOST('cle_rib','alpha');
$account->bic = GETPOST('bic','alpha');
$account->iban = GETPOST('iban','alpha');
$account->domiciliation = GETPOST('domiciliation','alpha');
$account->proprio = GETPOST('proprio','alpha');
$account->owner_address = GETPOST('owner_address','alpha');
$account->frstrecur = GETPOST('frstrecur','alpha');
$result = $account->update($user);
if (! $result)
{
setEventMessages($account->error, $account->errors, 'errors');
}
else
{
// If this account is the default bank account, we disable others
if ($account->default_rib)
{
$account->setAsDefault($id); // This will make sure there is only one default rib
}
$url=DOL_URL_ROOT.'/societe/rib.php?socid='.$object->id;
header('Location: '.$url);
exit;
}
}
} }
if ($action == 'add' && ! $_POST["cancel"]) if ($action == 'add' && ! $_POST["cancel"])
@ -114,6 +144,21 @@ if ($action == 'add' && ! $_POST["cancel"])
$action='create'; $action='create';
$error++; $error++;
} }
if ($account->needIBAN() == 1)
{
if (! GETPOST('iban'))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("IBAN")), null, 'errors');
$action='create';
$error++;
}
if (! GETPOST('bic'))
{
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BIC")), null, 'errors');
$action='create';
$error++;
}
}
if (! $error) if (! $error)
{ {
@ -122,19 +167,19 @@ if ($action == 'add' && ! $_POST["cancel"])
$account->socid = $object->id; $account->socid = $object->id;
$account->bank = $_POST["bank"]; $account->bank = GETPOST('bank','alpha');
$account->label = $_POST["label"]; $account->label = GETPOST('label','alpha');
$account->courant = $_POST["courant"]; $account->courant = GETPOST('courant','alpha');
$account->clos = $_POST["clos"]; $account->clos = GETPOST('clos','alpha');
$account->code_banque = $_POST["code_banque"]; $account->code_banque = GETPOST('code_banque','alpha');
$account->code_guichet = $_POST["code_guichet"]; $account->code_guichet = GETPOST('code_guichet','alpha');
$account->number = $_POST["number"]; $account->number = GETPOST('number','alpha');
$account->cle_rib = $_POST["cle_rib"]; $account->cle_rib = GETPOST('cle_rib','alpha');
$account->bic = $_POST["bic"]; $account->bic = GETPOST('bic','alpha');
$account->iban = $_POST["iban"]; $account->iban = GETPOST('iban','alpha');
$account->domiciliation = $_POST["domiciliation"]; $account->domiciliation = GETPOST('domiciliation','alpha');
$account->proprio = $_POST["proprio"]; $account->proprio = GETPOST('proprio','alpha');
$account->owner_address = $_POST["owner_address"]; $account->owner_address = GETPOST('owner_address','alpha');
$account->frstrecur = GETPOST('frstrecur'); $account->frstrecur = GETPOST('frstrecur');
$result = $account->update($user); // TODO Use create and include update into create method $result = $account->update($user); // TODO Use create and include update into create method
@ -265,35 +310,31 @@ if ($socid && $action != 'edit' && $action != "create")
$content = $account->number; $content = $account->number;
} elseif ($val == 'BankAccountNumberKey') { } elseif ($val == 'BankAccountNumberKey') {
$content = $account->cle_rib; $content = $account->cle_rib;
}elseif ($val == 'IBAN') {
$content = $account->iban;
if (! empty($account->iban)) {
if (! checkIbanForAccount($account)) {
$content.= img_picto($langs->trans("IbanNotValid"),'warning');
} else {
$content.= img_picto($langs->trans("IbanValid"),'info');
}
}
}elseif ($val == 'BIC') {
$content = $account->bic;
if (! empty($account->bic)) {
if (! checkSwiftForAccount($account)) {
$content.= img_picto($langs->trans("SwiftNotValid"),'warning');
} else {
$content.= img_picto($langs->trans("SwiftValid"),'info');
}
}
} }
print '<tr><td>'.$langs->trans($val).'</td>'; print '<tr><td>'.$langs->trans($val).'</td>';
print '<td colspan="3">'.$content.'</td>'; print '<td colspan="4">'.$content.'</td>';
print '</tr>'; print '</tr>';
} }
print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
print '<td colspan="4">'.$account->iban . '&nbsp;';
if (! empty($account->iban)) {
if (! checkIbanForAccount($account)) {
print img_picto($langs->trans("IbanNotValid"),'warning');
} else {
print img_picto($langs->trans("IbanValid"),'info');
}
}
print '</td></tr>';
print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
print '<td colspan="4">'.$account->bic.'&nbsp;';
if (! empty($account->bic)) {
if (! checkSwiftForAccount($account)) {
print img_picto($langs->trans("SwiftNotValid"),'warning');
} else {
print img_picto($langs->trans("SwiftValid"),'info');
}
}
print '</td></tr>';
print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">'; print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
print $account->domiciliation; print $account->domiciliation;
print "</td></tr>\n"; print "</td></tr>\n";
@ -432,6 +473,8 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
// Show fields of bank account // Show fields of bank account
foreach ($account->getFieldsToShow() as $val) { foreach ($account->getFieldsToShow() as $val) {
$require=false;
if ($val == 'BankCode') { if ($val == 'BankCode') {
$name = 'code_banque'; $name = 'code_banque';
$size = 8; $size = 8;
@ -448,20 +491,23 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer)
$name = 'cle_rib'; $name = 'cle_rib';
$size = 3; $size = 3;
$content = $account->cle_rib; $content = $account->cle_rib;
} elseif ($val == 'IBAN') {
$name = 'iban';
$size = 30;
$content = $account->iban;
if ($account->needIBAN()) $require=true;
} elseif ($val == 'BIC') {
$name = 'bic';
$size = 12;
$content = $account->bic;
if ($account->needIBAN()) $require=true;
} }
print '<tr><td>'.$langs->trans($val).'</td>'; print '<tr><td'.($require?' class="fieldrequired" ':'').'>'.$langs->trans($val).'</td>';
print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>'; print '<td><input size="'.$size.'" type="text" class="flat" name="'.$name.'" value="'.$content.'"></td>';
print '</tr>'; print '</tr>';
} }
// IBAN
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("IBAN").'</td>';
print '<td colspan="4"><input size="30" type="text" name="iban" value="'.$account->iban.'"></td></tr>';
print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("BIC").'</td>';
print '<td colspan="4"><input size="12" type="text" name="bic" value="'.$account->bic.'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">'; print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
print '<textarea name="domiciliation" rows="4" cols="40">'; print '<textarea name="domiciliation" rows="4" cols="40">';
print $account->domiciliation; print $account->domiciliation;
@ -527,6 +573,13 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
print '<tr><td class="fieldrequired">'.$langs->trans("Bank").'</td>'; print '<tr><td class="fieldrequired">'.$langs->trans("Bank").'</td>';
print '<td><input size="30" type="text" name="bank" value="'.GETPOST('bank').'"></td></tr>'; print '<td><input size="30" type="text" name="bank" value="'.GETPOST('bank').'"></td></tr>';
// IBAN
print '<tr><td valign="top" '.($account->needIBAN()?' class="fieldrequired" ':'').'>'.$langs->trans("IBAN").'</td>';
print '<td colspan="4"><input size="30" type="text" name="iban" value="'.GETPOST('iban').'"></td></tr>';
print '<tr><td valign="top" '.($account->needIBAN()?' class="fieldrequired" ':'').'>'.$langs->trans("BIC").'</td>';
print '<td colspan="4"><input size="12" type="text" name="bic" value="'.GETPOST('bic').'"></td></tr>';
// BBAN // BBAN
if ($account->useDetailedBBAN() == 1) if ($account->useDetailedBBAN() == 1)
{ {
@ -556,13 +609,6 @@ if ($socid && $action == 'create' && $user->rights->societe->creer)
print '</tr>'; print '</tr>';
} }
// IBAN
print '<tr><td valign="top">'.$langs->trans("IBAN").'</td>';
print '<td colspan="4"><input size="30" type="text" name="iban" value="'.GETPOST('iban').'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("BIC").'</td>';
print '<td colspan="4"><input size="12" type="text" name="bic" value="'.GETPOST('bic').'"></td></tr>';
print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">'; print '<tr><td valign="top">'.$langs->trans("BankAccountDomiciliation").'</td><td colspan="4">';
print '<textarea name="domiciliation" rows="4" cols="40">'; print '<textarea name="domiciliation" rows="4" cols="40">';
print GETPOST('domiciliation'); print GETPOST('domiciliation');