diff --git a/htdocs/product.class.php b/htdocs/product.class.php index cdaa78934d4..68b3d04d938 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -247,29 +247,26 @@ class Product * \brief Lit le prix d'achat pour un fournisseur * \param id_fourn Id du fournisseur * \param qty Quantite pour lequel le prix est valide - * + * \return int Renvoi prix */ function get_buyprice($fourn_id, $qty) { - $result = 0; - $sql = "SELECT pf.price"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf "; - $sql .= " WHERE pf.fk_soc = ".$fourn_id; - $sql .= " AND pf.fk_product =" .$this->id; - - // TODO Finir ce point - - $sql .= " AND quantity = 1"; - - $resql = $this->db->query($sql); - - if ( $resql ) - { - $row = $this->db->fetch_row($resql); - $this->buyprice = $row[0]; - - } - return $result; + $result = 0; + $sql = "SELECT pf.price"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pf "; + $sql.= " WHERE pf.fk_soc = ".$fourn_id; + $sql.= " AND pf.fk_product =" .$this->id; + $sql.= " AND quantity <= ".$qty; + $sql.= " ORDER BY quantity DESC"; + $sql.= " LIMIT 1"; + + $resql = $this->db->query($sql); + if ($resql) + { + $row = $this->db->fetch_row($resql); + $this->buyprice = $row[0]; + } + return $result; } @@ -769,16 +766,41 @@ class Product } + /** + * \brief Supprime un tarif fournisseur + * \param user utilisateur qui défait le lien + * \param id_fourn id du fournisseur + * \param qty quantité + * \return int < 0 si erreur, > 0 si ok + */ + + function remove_price($user, $id_fourn, $qty) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price"; + $sql.= " WHERE fk_product = $this->id AND fk_soc = $id_fourn and quantity = '".$qty."';"; + + if ($this->db->query($sql) ) + { + return 1; + } + else + { + dolibarr_print_error($this->db); + return -1; + } + } + /** * \brief Délie un fournisseur au produit/service * \param user utilisateur qui défait le lien * \param id_fourn id du fournisseur + * \return int < 0 si erreur, > 0 si ok */ function remove_fournisseur($user, $id_fourn) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur "; - $sql .= " WHERE fk_product = $this->id AND fk_soc = $id_fourn;"; + $sql.= " WHERE fk_product = $this->id AND fk_soc = $id_fourn;"; if ($this->db->query($sql) ) { @@ -913,23 +935,27 @@ class Product /** - * \brief Charge les informations relatives à un fournisseur - * \param id id du fournisseur + * \brief Charge les informations relatives à un fournisseur + * \param fournid id du fournisseur + * \return int < 0 si erreur, > 0 si ok */ - function fetch_fourn_data ($id) + function fetch_fourn_data($fournid) { - $sql = "SELECT rowid, ref_fourn"; - $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur "; - $sqL .= " WHERE fk_product = ".$this->id; - - $result = $this->db->query($sql) ; - - if ( $result ) - { - $result = $this->db->fetch_array(); - - $this->ref_fourn = $result["ref_fourn"]; - } + $sql = "SELECT rowid, ref_fourn"; + $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur "; + $sql.= " WHERE fk_product = ".$this->id; + $sql.= " AND fk_soc = ".$fournid; + $result = $this->db->query($sql) ; + + if ($result) + { + $result = $this->db->fetch_array(); + $this->ref_fourn = $result["ref_fourn"]; + return 1; + } + else { + return -1; + } } @@ -968,7 +994,7 @@ class Product */ function show_photo($sdir,$size=0) { - return $this->show_photos($sdir,$size,1); + return $this->show_photos($sdir,$size,1,0); } @@ -976,16 +1002,16 @@ class Product * \brief Affiche toutes les photos du produit (nbmax maximum) * \param sdir Répertoire à scanner * \param size 0=taille origine, 1 taille vignette - * \param nbmax Nombre maximum de photos + * \param nbmax Nombre maximum de photos (0=pas de max) + * \param nbbyrow Nombre vignettes par ligne (si mode vignette) * \return int Nombre de photos affichées */ - function show_photos($sdir,$size=0,$nbmax=0) + function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5) { - $nbphoto=0; - $pdir = get_exdir($this->id) . $this->id ."/photos/"; $dir = $sdir . '/'. $pdir; + $nbphoto=0; if (file_exists($dir)) { $handle=opendir($dir); @@ -999,12 +1025,19 @@ class Product { $nbphoto++; - if ($size == 1) { + if ($size == 1) { // Format vignette + // On determine nom du fichier vignette $photo_vignette=''; if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs)) { $photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0]; } + + if ($nbbyrow && $nbphoto == 1) print ''; + + if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print ''; + if ($nbbyrow) print ''; + if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; } - if ($size == 0) + if ($size == 0) // Format origine print ''; // On continue ou on arrete de boucler ? if ($nbmax && $nbphoto >= $nbmax) break; - else print ' '; } } + if ($nbbyrow && $size==1) + { + // Ferme tableau + while ($nbphoto % $nbbyrow) { + print ''; + $nbphoto++; + } + + if ($nbphoto) print '
'; + print ''; // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine @@ -1016,17 +1049,30 @@ class Product } print ''; + + if ($nbbyrow) print '
 
'; + } + closedir($handle); }