diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index acf708005d3..dec5ebfea57 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -63,7 +63,7 @@ class Categorie * Load category into memory from database * * @param int $id Id of category - * @param strin $label Label of category + * @param string $label Label of category * @return int <0 if KO, >0 if OK */ function fetch($id,$label='') @@ -86,20 +86,27 @@ class Categorie $resql = $this->db->query($sql); if ($resql) { - $res = $this->db->fetch_array($resql); - - $this->id = $res['rowid']; - $this->fk_parent = $res['fk_parent']; - $this->label = $res['label']; - $this->description = $res['description']; - $this->socid = $res['fk_soc']; - $this->visible = $res['visible']; - $this->type = $res['type']; - $this->entity = $res['entity']; - - $this->db->free($resql); - - return 1; + if ($this->db->num_rows($resql) > 0) + { + $res = $this->db->fetch_array($resql); + + $this->id = $res['rowid']; + $this->fk_parent = $res['fk_parent']; + $this->label = $res['label']; + $this->description = $res['description']; + $this->socid = $res['fk_soc']; + $this->visible = $res['visible']; + $this->type = $res['type']; + $this->entity = $res['entity']; + + $this->db->free($resql); + + return 1; + } + else + { + return 0; + } } else { diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 4fbc531707f..b1896db302a 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -446,12 +446,13 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.type, '; $sql.= ' f.datef as df'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql.= ' WHERE f.fk_soc = '.$facture->socid; + $sql.= ' WHERE f.entity = '.$conf->entity; + $sql.= ' AND f.fk_soc = '.$facture->socid; $sql.= ' AND f.paye = 0'; $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled if ($facture->type != 2) { - $sql .= ' AND type in (0,1,3)'; // Standard invoice, replacement, deposit + $sql .= ' AND type IN (0,1,3)'; // Standard invoice, replacement, deposit } else { diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index e08b736c7ad..7e380204640 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005-2012 Regis Houssin * * 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 @@ -36,8 +36,7 @@ $action=GETPOST("action"); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'tax', $langs->trans("SocialContribution"), '', 'charges'); - +$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index a397ca5c29c..2c5896bbee3 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -262,8 +262,12 @@ class ChargeSociales extends CommonObject */ function solde($year = 0) { - $sql = "SELECT sum(f.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."chargesociales as f WHERE paye = 0"; + global $conf; + + $sql = "SELECT SUM(f.amount) as amount"; + $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as f"; + $sql.= " WHERE f.entity = ".$conf->entity; + $sql.= " AND paye = 0"; if ($year) { $sql .= " AND f.datev >= '$y-01-01' AND f.datev <= '$y-12-31' "; @@ -300,8 +304,8 @@ class ChargeSociales extends CommonObject */ function set_paid($user) { - $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; - $sql.= " set paye=1"; + $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales SET"; + $sql.= " paye = 1"; $sql.= " WHERE rowid = ".$this->id; $return = $this->db->query($sql); if ($return) return 1; @@ -397,12 +401,14 @@ class ChargeSociales extends CommonObject */ function getSommePaiement() { - $table='paiementcharge'; - $field='fk_charge'; + global $conf; - $sql = 'SELECT sum(amount) as amount'; - $sql.= ' FROM '.MAIN_DB_PREFIX.$table; - $sql.= ' WHERE '.$field.' = '.$this->id; + $sql = 'SELECT SUM(amount) as amount'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'paiementcharge as pc'; + $sql.= ', '.MAIN_DB_PREFIX.'chargesociales as c'; + $sql.= ' WHERE c.entity = '.$conf->entity; + $sql.= ' AND pc.fk_charge = c.rowid'; + $sql.= ' AND pc.fk_charge = '.$this->id; dol_syslog(get_class($this)."::getSommePaiement sql=".$sql, LOG_DEBUG); $resql=$this->db->query($sql); diff --git a/htdocs/compta/sociales/info.php b/htdocs/compta/sociales/info.php index 08a14a16687..bc034de8171 100644 --- a/htdocs/compta/sociales/info.php +++ b/htdocs/compta/sociales/info.php @@ -35,7 +35,7 @@ $action=GETPOST("action"); // Security check $socid = GETPOST('socid','int'); if ($user->societe_id) $socid=$user->societe_id; -$result = restrictedArea($user, 'tax', $langs->trans("SocialContribution"), '', 'charges'); +$result = restrictedArea($user, 'tax', $id, 'chargesociales','charges'); /* diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index eec0b8b22cf..35fb8faec4e 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -265,30 +265,37 @@ class Entrepot extends CommonObject $result = $this->db->query($sql); if ($result) { - $obj=$this->db->fetch_object($result); + if ($this->db->num_rows($result) > 0) + { + $obj=$this->db->fetch_object($result); - $this->id = $obj->rowid; - $this->ref = $obj->rowid; - $this->libelle = $obj->label; - $this->description = $obj->description; - $this->statut = $obj->statut; - $this->lieu = $obj->lieu; - $this->address = $obj->address; - $this->cp = $obj->zip; // deprecated - $this->ville = $obj->town; // deprecated - $this->pays_id = $obj->country_id; // deprecated - $this->zip = $obj->zip; - $this->town = $obj->town; - $this->country_id = $obj->country_id; - - include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; - $tmp=getCountry($this->country_id,'all'); - $this->pays=$tmp['label']; // deprecated - $this->pays_code=$tmp['code']; // deprecated - $this->country=$tmp['label']; - $this->country_code=$tmp['code']; - - return 1; + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + $this->libelle = $obj->label; + $this->description = $obj->description; + $this->statut = $obj->statut; + $this->lieu = $obj->lieu; + $this->address = $obj->address; + $this->cp = $obj->zip; // deprecated + $this->ville = $obj->town; // deprecated + $this->pays_id = $obj->country_id; // deprecated + $this->zip = $obj->zip; + $this->town = $obj->town; + $this->country_id = $obj->country_id; + + include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + $tmp=getCountry($this->country_id,'all'); + $this->pays=$tmp['label']; // deprecated + $this->pays_code=$tmp['code']; // deprecated + $this->country=$tmp['label']; + $this->country_code=$tmp['code']; + + return 1; + } + else + { + return 0; + } } else {