Skip to content

Commit

Permalink
Multiple Bank Account Number for Third Party
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Fontaine committed Nov 13, 2013
1 parent 8c88b69 commit b965103
Show file tree
Hide file tree
Showing 7 changed files with 377 additions and 76 deletions.
4 changes: 4 additions & 0 deletions htdocs/install/mysql/migration/3.4.0-3.5.0.sql
Expand Up @@ -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;
2 changes: 2 additions & 0 deletions htdocs/install/mysql/tables/llx_societe_rib.sql
Expand Up @@ -2,6 +2,7 @@
-- Copyright (C) 2000-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
-- Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
--
-- 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
Expand Down Expand Up @@ -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


Expand Down
6 changes: 5 additions & 1 deletion htdocs/langs/en_US/banks.lang
Expand Up @@ -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
BankDashboard=Bank accounts summary
DefaultRIB=Default BAN
AllRIB=All BAN
LabelRIB=BAN Label
NoBANRecord=No BAN record
4 changes: 4 additions & 0 deletions htdocs/langs/fr_FR/banks.lang
Expand Up @@ -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é
106 changes: 86 additions & 20 deletions htdocs/societe/class/companybankaccount.class.php
Expand Up @@ -2,6 +2,7 @@
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
*
* 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
Expand Down Expand Up @@ -34,6 +35,7 @@ class CompanyBankAccount extends Account
var $rowid;
var $socid;

var $label;
var $bank;
var $courant;
var $clos;
Expand All @@ -46,6 +48,7 @@ class CompanyBankAccount extends Account
var $iban_prefix; // deprecated
var $proprio;
var $owner_address;
var $default_rib;

/**
* Constructor
Expand All @@ -60,6 +63,7 @@ function __construct($db)
$this->clos = 0;
$this->solde = 0;
$this->error_number = 0;
$this->default_rib = 0;
return 1;
}

Expand All @@ -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;
}
}
Expand All @@ -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 ";
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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);

Expand All @@ -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
Expand All @@ -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;
}
}
}

?>
31 changes: 30 additions & 1 deletion htdocs/societe/class/societe.class.php
Expand Up @@ -8,7 +8,8 @@
* Copyright (C) 2008 Patrick Raguin <patrick.raguin@auguria.net>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2013 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2013 Alexandre Spangaro <alexandre.spangaro@gmail.com>
* Copyright (C) 2013 Peter Fontaine <contact@peterfontaine.fr>
*
* 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b965103

Please sign in to comment.