From b965103fc3c5e0cd69469eb9d5662ef1016102c8 Mon Sep 17 00:00:00 2001 From: Peter Fontaine Date: Wed, 13 Nov 2013 15:40:17 +0100 Subject: [PATCH] Multiple Bank Account Number for Third Party --- .../install/mysql/migration/3.4.0-3.5.0.sql | 4 + .../install/mysql/tables/llx_societe_rib.sql | 2 + htdocs/langs/en_US/banks.lang | 6 +- htdocs/langs/fr_FR/banks.lang | 4 + .../class/companybankaccount.class.php | 106 +++++-- htdocs/societe/class/societe.class.php | 31 +- htdocs/societe/rib.php | 300 ++++++++++++++---- 7 files changed, 377 insertions(+), 76 deletions(-) diff --git a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql index 81a61afbd81e7..1d2d3bea1d8c5 100755 --- a/htdocs/install/mysql/migration/3.4.0-3.5.0.sql +++ b/htdocs/install/mysql/migration/3.4.0-3.5.0.sql @@ -348,3 +348,7 @@ ALTER TABLE llx_user ADD skype VARCHAR(255) AFTER job; ALTER TABLE llx_socpeople ADD skype VARCHAR(255) AFTER jabberid; ALTER TABLE llx_societe ADD skype VARCHAR(255) AFTER email; ALTER TABLE llx_adherent ADD skype VARCHAR(255) AFTER email; + +-- multi-rib +ALTER TABLE llx_societe_rib ADD default_rib TINYINT NOT NULL DEFAULT 0 AFTER owner_address; +UPDATE llx_societe_rib SET default_rib = 1; diff --git a/htdocs/install/mysql/tables/llx_societe_rib.sql b/htdocs/install/mysql/tables/llx_societe_rib.sql index a526d5b82d759..d928da868edce 100644 --- a/htdocs/install/mysql/tables/llx_societe_rib.sql +++ b/htdocs/install/mysql/tables/llx_societe_rib.sql @@ -2,6 +2,7 @@ -- Copyright (C) 2000-2004 Rodolphe Quiedeville -- Copyright (C) 2005-2009 Regis Houssin -- Copyright (C) 2012 Juanjo Menent +-- Copyright (C) 2013 Peter Fontaine -- -- 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 @@ -35,6 +36,7 @@ create table llx_societe_rib domiciliation varchar(255), proprio varchar(60), owner_address varchar(255), + default_rib tinyint NOT NULL DEFAULT 0, import_key varchar(14) -- import key diff --git a/htdocs/langs/en_US/banks.lang b/htdocs/langs/en_US/banks.lang index 4d504db97943b..3503ff11e62f1 100644 --- a/htdocs/langs/en_US/banks.lang +++ b/htdocs/langs/en_US/banks.lang @@ -149,4 +149,8 @@ InputReceiptNumber=Choose the bank statement related with the conciliation. Use EventualyAddCategory=Eventually, specify a category in which to classify the records ToConciliate=To conciliate? ThenCheckLinesAndConciliate=Then, check the lines present in the bank statement and click -BankDashboard=Bank accounts summary \ No newline at end of file +BankDashboard=Bank accounts summary +DefaultRIB=Default BAN +AllRIB=All BAN +LabelRIB=BAN Label +NoBANRecord=No BAN record diff --git a/htdocs/langs/fr_FR/banks.lang b/htdocs/langs/fr_FR/banks.lang index 2105cce24e14a..29440edd862ea 100644 --- a/htdocs/langs/fr_FR/banks.lang +++ b/htdocs/langs/fr_FR/banks.lang @@ -150,3 +150,7 @@ EventualyAddCategory=Eventuellement, saisissez une catégorie dans laquelle clas ToConciliate=A rapprocher ? ThenCheckLinesAndConciliate=Ensuite, cochez les lignes présentes sur le relevé et cliquez sur BankDashboard=Synthèse comptes bancaires +DefaultRIB=RIB par défaut +AllRIB=Tous les RIB +LabelRIB=Nom du RIB +NoBANRecord=Aucun RIB enregistré diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index ce637588d8a67..7b80b80f0bdca 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -2,6 +2,7 @@ /* Copyright (C) 2004 Rodolphe Quiedeville * Copyright (C) 2010 Laurent Destailleur * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013 Peter Fontaine * * 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 @@ -34,6 +35,7 @@ class CompanyBankAccount extends Account var $rowid; var $socid; + var $label; var $bank; var $courant; var $clos; @@ -46,6 +48,7 @@ class CompanyBankAccount extends Account var $iban_prefix; // deprecated var $proprio; var $owner_address; + var $default_rib; /** * Constructor @@ -60,6 +63,7 @@ function __construct($db) $this->clos = 0; $this->solde = 0; $this->error_number = 0; + $this->default_rib = 0; return 1; } @@ -79,6 +83,8 @@ function create() { if ($this->db->affected_rows($resql)) { + $this->default_rib = 1; + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib"); return 1; } } @@ -97,21 +103,25 @@ function create() */ function update($user='') { - $sql = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."societe_rib"; - $sql .= " WHERE fk_soc = ".$this->socid; +// $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib"; +// $sql .= " WHERE rowid = ".$this->id; +// +// $result = $this->db->query($sql); +// if ($result) +// { +// if ($this->db->num_rows($result) == 0) +// { +// $this->create(); +// } +// } +// else +// { +// dol_print_error($this->db); +// return 0; +// } - $result = $this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result) == 0) - { - $this->create(); - } - } - else - { - dol_print_error($this->db); - return 0; + if (!$this->id) { + $this->create(); } $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET "; @@ -125,7 +135,12 @@ function update($user='') $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'"; $sql .= ",proprio = '".$this->db->escape($this->proprio)."'"; $sql .= ",owner_address = '".$this->db->escape($this->owner_address)."'"; - $sql .= " WHERE fk_soc = ".$this->socid; + $sql .= ",default_rib = ".$this->default_rib; + if (trim($this->label) != '') + $sql .= ",label = '".$this->db->escape($this->label)."'"; + else + $sql .= ",label = NULL"; + $sql .= " WHERE rowid = ".$this->id; $result = $this->db->query($sql); if ($result) @@ -150,10 +165,10 @@ function fetch($id,$socid=0) { if (empty($id) && empty($socid)) return -1; - $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio, owner_address"; + $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio, owner_address, default_rib, label"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; if ($id) $sql.= " WHERE rowid = ".$id; - if ($socid) $sql.= " WHERE fk_soc = ".$socid; + if ($socid) $sql.= " WHERE fk_soc = ".$socid." AND default_rib = 1"; $resql = $this->db->query($sql); if ($resql) @@ -175,6 +190,8 @@ function fetch($id,$socid=0) $this->domiciliation = $obj->domiciliation; $this->proprio = $obj->proprio; $this->owner_address = $obj->owner_address; + $this->label = $obj->label; + $this->default_rib = $obj->default_rib; } $this->db->free($resql); @@ -192,13 +209,15 @@ function fetch($id,$socid=0) * * @return string RIB */ - function getRibLabel() + function getRibLabel($displayriblabel = true) { global $langs; - + if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib) { - $rib = $this->code_banque." ".$this->code_guichet." ".$this->number; + if ($this->label && $displayriblabel) + $rib = $this->label." : "; + $rib.= $this->code_banque." ".$this->code_guichet." ".$this->number; $rib.=($this->cle_rib?" (".$this->cle_rib.")":""); } else @@ -208,6 +227,53 @@ function getRibLabel() return $rib; } + + /** + * Set RIB as Default + * + * @param int $id RIB id + * @return int 0 if KO, 1 if OK + */ + function setAsDefault($id) + { + if ($id) { + $sql1 = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."societe_rib"; + $sql1.= " WHERE rowid = ".$id; + + $result1 = $this->db->query($sql1); + if ($result1) { + if ($this->db->num_rows($result1) == 0) { + return 0; + } else { + $obj = $this->db->fetch_object($result1); + $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0 "; + $sql2.= "WHERE fk_soc = ".$obj->fk_soc; + + $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1 "; + $sql3.= "WHERE rowid = ".$id; + + $this->db->begin(); + + $result2 = $this->db->query($sql2); + $result3 = $this->db->query($sql3); + + if (!$result2 || !$result3) { + dol_print_error($this->db); + $this->db->rollback(); + return 0; + } else { + $this->db->commit(); + return 1; + } + } + } else { + dol_print_error($this->db); + return 0; + } + } else { + return 0; + } + } } ?> diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index e79242d35a941..fc3e7b94ca352 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -8,7 +8,8 @@ * Copyright (C) 2008 Patrick Raguin * Copyright (C) 2010-2011 Juanjo Menent * Copyright (C) 2013 Florian Henry - * Copyright (C) 2013 Alexandre Spangaro + * Copyright (C) 2013 Alexandre Spangaro + * Copyright (C) 2013 Peter Fontaine * * 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 @@ -1753,6 +1754,34 @@ function display_rib() return $bac->getRibLabel(); } + /** + * Return Array of RIB + * + * @return array|int 0 if KO, Array of CompanyBanckAccount if OK + */ + function get_all_rib() + { + require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE fk_soc = ".$this->id; + $result = $this->db->query($sql); + if (!$result) { + $this->error++; + $this->errors[] = $this->db->lasterror; + return 0; + } else { + $num_rows = $this->db->num_rows($result); + $rib_array = array(); + if ($num_rows) { + while ($obj = $this->db->fetch_object($result)) { + $rib = new CompanyBankAccount($this->db); + $rib->fetch($obj->rowid); + $rib_array[] = $rib; + } + } + return $rib_array; + } + } + /** * Attribut un code client a partir du module de controle des codes. * Return value is stored into this->code_client diff --git a/htdocs/societe/rib.php b/htdocs/societe/rib.php index e85845c6a59a6..b3432d105a836 100644 --- a/htdocs/societe/rib.php +++ b/htdocs/societe/rib.php @@ -3,6 +3,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2013 Peter Fontaine * * 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 @@ -52,6 +53,8 @@ // Modification $account = new CompanyBankAccount($db); + $account->fetch($_POST["id"]); + $account->socid = $soc->id; $account->bank = $_POST["bank"]; @@ -76,11 +79,59 @@ } else { - $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu + $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id; + header('Location: '.$url); + exit; } } +if ($_POST["action"] == 'add' && ! $_POST["cancel"]) +{ + // Ajout + $account = new CompanyBankAccount($db); + + $account->socid = $soc->id; + + $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_prefix = $_POST["iban_prefix"]; + $account->domiciliation = $_POST["domiciliation"]; + $account->proprio = $_POST["proprio"]; + $account->owner_address = $_POST["owner_address"]; + + $result = $account->update($user); + if (! $result) + { + $message=$account->error; + $_GET["action"]='create'; // Force chargement page création + } + else + { + $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id; + header('Location: '.$url); + exit; + } +} +if ($_GET['action'] == 'setasdefault') +{ + $account = new CompanyBankAccount($db); + $res = $account->setAsDefault($_GET['ribid']); + if ($res) { + $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id; + header('Location: '.$url); + exit; + } else { + $message=$db->lasterror; + } +} /* * View @@ -93,7 +144,10 @@ dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); $account = new CompanyBankAccount($db); -$account->fetch(0,$soc->id); +if (!$_GET['id']) + $account->fetch(0,$soc->id); +else + $account->fetch($_GET['id']); if (empty($account->socid)) $account->socid=$soc->id; @@ -104,10 +158,14 @@ /* */ /* ************************************************************************** */ -if ($_GET["socid"] && $_GET["action"] != 'edit') +if ($_GET["socid"] && $_GET["action"] != 'edit' && $_GET["action"] != "create") { + print_titre($langs->trans("DefaultRIB")); print ''; + print ''; + print ''; + print ''; print ''; @@ -165,6 +223,54 @@ print '
'.$langs->trans("RIBControlError").'
'; } + print "
"; + + print_titre($langs->trans("AllRIB")); + + $rib_list = $soc->get_all_rib(); + $var = false; + if (is_array($rib_list)) { + print '
'.$langs->trans("LabelRIB").''.$account->label.'
'.$langs->trans("Bank").''.$account->bank.'
'; + + print ''; + print_liste_field_titre($langs->trans("LabelRIB")); + print_liste_field_titre($langs->trans("Bank")); + print_liste_field_titre($langs->trans("RIB")); + print_liste_field_titre($langs->trans("DefaultRIB")); + print ''; + print ''; + + foreach ($rib_list as $rib) { + print ""; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $var = !$var; + } + + if (count($rib_list) == 0) { + print ''; + } + + print '
'.$rib->label.''.$rib->bank.''.$rib->getRibLabel(false).''; + if (!$rib->default_rib) { + print ''; + print img_picto($langs->trans("Disabled"),'switch_off'); + print ''; + } else { + print img_picto($langs->trans("Enabled"),'switch_on'); + } + print ''; + print ''; + print img_picto($langs->trans("Modify"),'edit'); + print ''; + print '
'.$langs->trans("NoBANRecord").'
'; + } else { + dol_print_error($db); + } } /* ************************************************************************** */ @@ -176,31 +282,34 @@ if ($_GET["socid"] && $_GET["action"] == 'edit' && $user->rights->societe->creer) { - $form = new Form($db); + $form = new Form($db); - dol_htmloutput_mesg($message); + dol_htmloutput_mesg($message); - print '
'; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; - print ''; + print '
'; - print ''; - print ''; + print ''; + print ''; - // BBAN - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; + print ''; + print ''; - print ''; - print ''; - print ''; - } + // BBAN + if ($account->useDetailedBBAN() == 1) + { + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + } if ($account->useDetailedBBAN() == 2) { print ''; @@ -208,52 +317,135 @@ print ''; } - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; - if ($account->useDetailedBBAN() == 1) - { - print ''; - print ''; - print ''; - } + if ($account->useDetailedBBAN() == 1) + { + print ''; + print ''; + print ''; + } - // IBAN - print ''; - print ''; + // IBAN + print ''; + print ''; - print ''; - print ''; + print ''; + print ''; - print '"; + print '"; - print ''; - print ''; - print "\n"; + print ''; + print ''; + print "\n"; - print '"; + print '"; + + print '
'.$langs->trans("Bank").'
'.$langs->trans("LabelRIB").'
'.$langs->trans("BankCode").'
'.$langs->trans("Bank").'
'.$langs->trans("DeskCode").'
'.$langs->trans("BankCode").'
'.$langs->trans("DeskCode").'
'.$langs->trans("BankCode").'
'.$langs->trans("BankAccountNumber").'
'.$langs->trans("BankAccountNumber").'
'.$langs->trans("BankAccountNumberKey").'
'.$langs->trans("BankAccountNumberKey").'
'.$langs->trans("IBAN").'
'.$langs->trans("IBAN").'
'.$langs->trans("BIC").'
'.$langs->trans("BIC").'
'.$langs->trans("BankAccountDomiciliation").''; - print "
'.$langs->trans("BankAccountDomiciliation").''; + print "
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; - print "
'.$langs->trans("BankAccountOwnerAddress").''; + print "

'; + + print '
'; + print '   '; + print '
'; + + print '
'; +} + + +/* ************************************************************************** */ +/* */ +/* Création */ +/* */ +/* ************************************************************************** */ + +if ($_GET["socid"] && $_GET["action"] == 'create' && $user->rights->societe->creer) +{ + + $form = new Form($db); + + dol_htmloutput_mesg($message); + + print '
'; + print ''; + print ''; + print ''; + + + print ''; + print ''; + + print ''; + print ''; + + // BBAN + if ($account->useDetailedBBAN() == 1) + { + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + } + if ($account->useDetailedBBAN() == 2) + { + print ''; + print ''; + print ''; + } + + print ''; + print ''; + print ''; + + if ($account->useDetailedBBAN() == 1) + { + print ''; + print ''; + print ''; + } + + // IBAN + print ''; + print ''; + + print ''; + print ''; + + print '"; + + print ''; + print ''; + print "\n"; + + print '"; - print '
'.$langs->trans("LabelRIB").'
'.$langs->trans("Bank").'
'.$langs->trans("BankCode").'
'.$langs->trans("DeskCode").'
'.$langs->trans("BankCode").'
'.$langs->trans("BankAccountNumber").'
'.$langs->trans("BankAccountNumberKey").'
'.$langs->trans("IBAN").'
'.$langs->trans("BIC").'
'.$langs->trans("BankAccountDomiciliation").''; + print "
'.$langs->trans("BankAccountOwner").'
'.$langs->trans("BankAccountOwnerAddress").''; + print "

'; + print '
'; - print '
'; - print '   '; - print '
'; + print '
'; + print '   '; + print '
'; - print '
'; + print ''; } dol_fiche_end(); -if ($_GET["socid"] && $_GET["action"] != 'edit') +if ($_GET["socid"] && $_GET["action"] != 'edit' && $_GET["action"] != 'create') { /* * Barre d'actions @@ -262,7 +454,7 @@ if ($user->rights->societe->creer) { - print ''.$langs->trans("Modify").''; + print ''.$langs->trans("Add").''; } print '';