Fix: Postgresql compatibility

This commit is contained in:
eldy 2011-09-20 23:44:40 +02:00
parent 991f80a00d
commit 7cdfc2618a

View File

@ -16,170 +16,177 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
/* /**
* \files htdocs/societe/class/companybankaccount.class.php * \file htdocs/societe/class/companybankaccount.class.php
* \ingroup societe * \ingroup societe
* \brief File of class to manage bank accounts description of third parties * \brief File of class to manage bank accounts description of third parties
* \version $Id: companybankaccount.class.php,v 1.11 2011/07/31 23:22:58 eldy Exp $
*/ */
require_once(DOL_DOCUMENT_ROOT ."/compta/bank/class/account.class.php"); require_once(DOL_DOCUMENT_ROOT ."/compta/bank/class/account.class.php");
/** /**
* \brief Class to manage bank accounts description of third parties * \brief Class to manage bank accounts description of third parties
*/ */
class CompanyBankAccount extends Account class CompanyBankAccount extends Account
{ {
var $rowid; var $rowid;
var $socid; var $socid;
var $bank; var $bank;
var $courant; var $courant;
var $clos; var $clos;
var $code_banque; var $code_banque;
var $code_guichet; var $code_guichet;
var $number; var $number;
var $cle_rib; var $cle_rib;
var $bic; var $bic;
var $iban; var $iban;
var $iban_prefix; // deprecated var $iban_prefix; // deprecated
var $proprio; var $proprio;
var $adresse_proprio; var $adresse_proprio;
/** /**
* Constructor * Constructor
*/
function CompanyBankAccount($DB)
{
$this->db = $DB;
$this->socid = 0;
$this->clos = 0;
$this->solde = 0;
$this->error_number = 0;
return 1;
}
/**
* Create bank information record
* *
*/ * @param DoliDB $DB Database handler
function create() */
{ function CompanyBankAccount($DB)
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, datec) values ($this->socid, ".$this->db->idate(mktime()).")"; {
$this->db = $DB;
$this->socid = 0;
$this->clos = 0;
$this->solde = 0;
$this->error_number = 0;
return 1;
}
/**
* Create bank information record
*
* @return int <0 if KO, >= 0 if OK
*/
function create()
{
$now=dol_now();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, datec) values ($this->socid, '".$this->db->idate($now)."')";
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
{ {
if ($this->db->affected_rows($resql)) if ($this->db->affected_rows($resql))
{ {
return 1; return 1;
} }
} }
else else
{ {
print $this->db->error(); print $this->db->error();
return 0; return 0;
} }
} }
/** /**
* * Update bank account
* *
*/ * @param User $user Object user
function update($user='') * @return int <=0 if KO, >0 if OK
{ */
function update($user='')
{
$sql = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."societe_rib";
$sql .= " WHERE fk_soc = ".$this->socid;
$sql = "SELECT fk_soc FROM ".MAIN_DB_PREFIX."societe_rib"; $result = $this->db->query($sql);
$sql .= " WHERE fk_soc = ".$this->socid; if ($result)
{
if ($this->db->num_rows($result) == 0)
{
$this->create();
}
}
else
{
dol_print_error($this->db);
return 0;
}
$result = $this->db->query($sql); $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET ";
if ($result) $sql .= " bank = '" .$this->db->escape($this->bank)."'";
{ $sql .= ",code_banque='".$this->code_banque."'";
if ($this->db->num_rows($result) == 0) $sql .= ",code_guichet='".$this->code_guichet."'";
{ $sql .= ",number='".$this->number."'";
$this->create(); $sql .= ",cle_rib='".$this->cle_rib."'";
} $sql .= ",bic='".$this->bic."'";
} $sql .= ",iban_prefix = '".$this->iban_prefix."'";
else $sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'";
{ $sql .= ",proprio = '".$this->db->escape($this->proprio)."'";
dol_print_error($this->db); $sql .= ",adresse_proprio = '".$this->db->escape($this->adresse_proprio)."'";
return 0; $sql .= " WHERE fk_soc = ".$this->socid;
}
$sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET "; $result = $this->db->query($sql);
$sql .= " bank = '" .$this->db->escape($this->bank)."'"; if ($result)
$sql .= ",code_banque='".$this->code_banque."'"; {
$sql .= ",code_guichet='".$this->code_guichet."'"; return 1;
$sql .= ",number='".$this->number."'"; }
$sql .= ",cle_rib='".$this->cle_rib."'"; else
$sql .= ",bic='".$this->bic."'"; {
$sql .= ",iban_prefix = '".$this->iban_prefix."'"; dol_print_error($this->db);
$sql .= ",domiciliation='".$this->db->escape($this->domiciliation)."'"; return 0;
$sql .= ",proprio = '".$this->db->escape($this->proprio)."'"; }
$sql .= ",adresse_proprio = '".$this->db->escape($this->adresse_proprio)."'"; }
$sql .= " WHERE fk_soc = ".$this->socid;
$result = $this->db->query($sql); /**
if ($result) * Load record from database
{ *
return 1; * @param int $id Id of record
} * @param int $socid Id of company
else * @return int <0 if KO, >0 if OK
{ */
dol_print_error($this->db); function fetch($id,$socid=0)
return 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, adresse_proprio";
* Load record from database $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib";
* @param id Id of record if ($id) $sql.= " WHERE rowid = ".$id;
* @param socid Id of company if ($socid) $sql.= " WHERE fk_soc = ".$socid;
*/
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, adresse_proprio"; $resql = $this->db->query($sql);
$sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; if ($resql)
if ($id) $sql.= " WHERE rowid = ".$id; {
if ($socid) $sql.= " WHERE fk_soc = ".$socid; if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$resql = $this->db->query($sql); $this->id = $obj->rowid;
if ($resql)
{
if ($this->db->num_rows($resql))
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid;
$this->socid = $obj->fk_soc; $this->socid = $obj->fk_soc;
$this->bank = $obj->bank; $this->bank = $obj->bank;
$this->courant = $obj->courant; $this->courant = $obj->courant;
$this->clos = $obj->clos; $this->clos = $obj->clos;
$this->code_banque = $obj->code_banque; $this->code_banque = $obj->code_banque;
$this->code_guichet = $obj->code_guichet; $this->code_guichet = $obj->code_guichet;
$this->number = $obj->number; $this->number = $obj->number;
$this->cle_rib = $obj->cle_rib; $this->cle_rib = $obj->cle_rib;
$this->bic = $obj->bic; $this->bic = $obj->bic;
$this->iban = $obj->iban; $this->iban = $obj->iban;
$this->iban_prefix = $obj->iban; // deprecated $this->iban_prefix = $obj->iban; // deprecated
$this->domiciliation = $obj->domiciliation; $this->domiciliation = $obj->domiciliation;
$this->proprio = $obj->proprio; $this->proprio = $obj->proprio;
$this->adresse_proprio = $obj->adresse_proprio; $this->adresse_proprio = $obj->adresse_proprio;
} }
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
} }
else else
{ {
dol_print_error($this->db); dol_print_error($this->db);
return -1; return -1;
} }
} }
} }