mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-02-20 13:46:52 +01:00
New: task #11243: Add best supplier price
This commit is contained in:
parent
0cb74a8895
commit
fe27643152
|
|
@ -1,6 +1,6 @@
|
|||
--------------------------------------------------------------
|
||||
English Dolibarr ChangeLog
|
||||
$Id: ChangeLog,v 1.426 2011/08/17 16:21:22 simnandez Exp $
|
||||
$Id: ChangeLog,v 1.427 2011/08/20 23:57:09 eldy Exp $
|
||||
--------------------------------------------------------------
|
||||
|
||||
***** ChangeLog for 3.2 compared to 3.1 *****
|
||||
|
|
@ -9,9 +9,12 @@ For users:
|
|||
- New: task #11243: Show quantity into stocks for each subproducts into the subproduct tab
|
||||
- New: Task #10500: Option to choose if professionnal id are unique
|
||||
- New: Add hide option FOURN_PRODUCT_AVAILABILITY
|
||||
- New: task #11123: Add best supplier price
|
||||
|
||||
For developers:
|
||||
- Qual: Removed no more used external libraries
|
||||
- Qual: Clean a lot of dead code
|
||||
|
||||
|
||||
***** ChangeLog for 3.1 compared to 3.0 *****
|
||||
WARNING: IE6 browser is no more supported in this version.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2006-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2009 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
|
||||
*
|
||||
* 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
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
* \file htdocs/fourn/class/fournisseur.product.class.php
|
||||
* \ingroup produit
|
||||
* \brief File of class to manage predefined suppliers products
|
||||
* \version $Id: fournisseur.product.class.php,v 1.9 2011/08/18 08:01:07 simnandez Exp $
|
||||
* \version $Id: fournisseur.product.class.php,v 1.10 2011/08/20 23:56:03 eldy Exp $
|
||||
*/
|
||||
|
||||
require_once DOL_DOCUMENT_ROOT."/product/class/product.class.php";
|
||||
|
|
@ -35,432 +35,573 @@ require_once DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.class.php";
|
|||
*/
|
||||
class ProductFournisseur extends Product
|
||||
{
|
||||
var $db ;
|
||||
var $db;
|
||||
var $error;
|
||||
|
||||
var $id ;
|
||||
var $fourn_ref;
|
||||
var $fourn;
|
||||
var $fourn_qty;
|
||||
var $product_fourn_id;
|
||||
var $product_fourn_price_id;
|
||||
var $fk_availability;
|
||||
var $product_fourn_price_id; // id of ligne product-supplier
|
||||
|
||||
function ProductFournisseur($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
var $id; // product id
|
||||
var $fourn_ref; // ref supplier
|
||||
var $fourn_qty; // quantity for price
|
||||
var $fourn_price; // price for quantity
|
||||
var $product_fourn_id; // supplier id
|
||||
var $fk_availability; // availability delay
|
||||
var $fourn_unitprice;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
function ProductFournisseur($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Remove all prices for this couple supplier-product
|
||||
* @param id_fourn Supplier Id
|
||||
* @return int < 0 if error, > 0 if ok
|
||||
*/
|
||||
function remove_fournisseur($id_fourn)
|
||||
{
|
||||
$ok=1;
|
||||
/**
|
||||
* Remove all prices for this couple supplier-product
|
||||
*
|
||||
* @param id_fourn Supplier Id
|
||||
* @return int < 0 if error, > 0 if ok
|
||||
*/
|
||||
function remove_fournisseur($id_fourn)
|
||||
{
|
||||
$ok=1;
|
||||
|
||||
$this->db->begin();
|
||||
$this->db->begin();
|
||||
|
||||
// Search all links
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
|
||||
// Search all links
|
||||
$sql = "SELECT rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// For each link, delete price line
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sql.= " WHERE fk_product_fournisseur = ".$obj->rowid;
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// For each link, delete price line
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sql.= " WHERE fk_product_fournisseur = ".$obj->rowid;
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql);
|
||||
$resql2=$this->db->query($sql);
|
||||
if (! $resql2)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur ".$this->error, LOG_ERR);
|
||||
$ok=0;
|
||||
}
|
||||
}
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql);
|
||||
$resql2=$this->db->query($sql);
|
||||
if (! $resql2)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur ".$this->error, LOG_ERR);
|
||||
$ok=0;
|
||||
}
|
||||
}
|
||||
|
||||
// Now delete all link supplier-product (they have no more childs)
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
|
||||
// Now delete all link supplier-product (they have no more childs)
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE fk_product = ".$this->id." AND fk_soc = ".$id_fourn;
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur ".$this->error, LOG_ERR);
|
||||
$ok=0;
|
||||
}
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur sql=".$sql);
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_fournisseur ".$this->error, LOG_ERR);
|
||||
$ok=0;
|
||||
}
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
dol_print_error($this->db);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
if ($ok)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
dol_print_error($this->db);
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Remove supplier product
|
||||
* @param rowid Product id
|
||||
* @return int < 0 if error, > 0 if ok
|
||||
*/
|
||||
function remove_product_fournisseur($rowid)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE rowid = ".$rowid;
|
||||
/**
|
||||
* Remove supplier product
|
||||
*
|
||||
* @param rowid Product id
|
||||
* @return int < 0 if error, > 0 if ok
|
||||
*/
|
||||
function remove_product_fournisseur($rowid)
|
||||
{
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE rowid = ".$rowid;
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a price for a couple supplier-product
|
||||
* @param rowid Line id of price
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function remove_product_fournisseur_price($rowid)
|
||||
{
|
||||
global $conf;
|
||||
/**
|
||||
* Remove a price for a couple supplier-product
|
||||
*
|
||||
* @param rowid Line id of price
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function remove_product_fournisseur_price($rowid)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$this->db->begin();
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sql.= " WHERE rowid = ".$rowid;
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
$sql.= " WHERE rowid = ".$rowid;
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// Remove all entries with no childs
|
||||
$sql = "SELECT pf.rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.fk_product_fournisseur = pf.rowid";
|
||||
$sql.= " WHERE pfp.rowid IS NULL";
|
||||
$sql.= " AND pf.entity = ".$conf->entity;
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
// Remove all entries with no childs
|
||||
$sql = "SELECT pf.rowid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON pfp.fk_product_fournisseur = pf.rowid";
|
||||
$sql.= " WHERE pfp.rowid IS NULL";
|
||||
$sql.= " AND pf.entity = ".$conf->entity;
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$ok=1;
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$ok=1;
|
||||
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$rowidpf=$obj->rowid;
|
||||
while ($obj=$this->db->fetch_object($resql))
|
||||
{
|
||||
$rowidpf=$obj->rowid;
|
||||
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE rowid = ".$rowidpf;
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE rowid = ".$rowidpf;
|
||||
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql2 = $this->db->query($sql);
|
||||
if (! $resql2)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
||||
$ok=0;
|
||||
}
|
||||
}
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price sql=".$sql);
|
||||
$resql2 = $this->db->query($sql);
|
||||
if (! $resql2)
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
||||
$ok=0;
|
||||
}
|
||||
}
|
||||
|
||||
if ($ok)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if ($ok)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->rollback();
|
||||
return -3;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->lasterror();
|
||||
dol_syslog("ProductFournisseur::remove_product_fournisseur_price ".$this->error,LOG_ERR);
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Modify the purchase price for a supplier
|
||||
* @param ref Supplier ref
|
||||
* @param qty Min quantity for which price is valid
|
||||
* @param buyprice Purchase price for the quantity min
|
||||
* @param user Object user user made changes
|
||||
*/
|
||||
function update($ref, $qty, $buyprice, $user)
|
||||
{
|
||||
$this->fourn_ref = $ref;
|
||||
/**
|
||||
* Modify the purchase price for a supplier
|
||||
*
|
||||
* @param qty Min quantity for which price is valid
|
||||
* @param buyprice Purchase price for the quantity min
|
||||
* @param user Object user user made changes
|
||||
* @param price_base_type HT or TTC
|
||||
* @param fourn Supplier
|
||||
* @param availability Product availability
|
||||
*/
|
||||
function update_buyprice($qty, $buyprice, $user, $price_base_type='HT', $fourn, $availability)
|
||||
{
|
||||
global $mysoc;
|
||||
|
||||
/* Mise a jour du prix */
|
||||
// Clean parameter
|
||||
$buyprice=price2num($buyprice);
|
||||
$qty=price2num($qty);
|
||||
if (empty($availability)) $availability=0;
|
||||
|
||||
$this->update_buyprice($qty, $buyprice, $user);
|
||||
$error=0;
|
||||
$this->db->begin();
|
||||
|
||||
/* Mise a jour de la reference */
|
||||
// Supprime prix courant du fournisseur pour cette quantite
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
if ($this->product_fourn_price_id)
|
||||
{
|
||||
$sql.= " WHERE rowid = ".$this->product_fourn_price_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql.= " WHERE fk_product_fournisseur = ".$this->product_fourn_id;
|
||||
$sql.= " AND quantity = ".$qty;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."product_fournisseur ";
|
||||
$sql .= " SET ref_fourn = '" . $this->fourn_ref ."'";
|
||||
$sql .= " WHERE fk_product = " . $this->id;
|
||||
$sql .=" AND fk_soc = ".$this->fourn->id;
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($price_base_type == 'TTC')
|
||||
{
|
||||
$ttx = get_default_tva($fourn,$mysoc,$this->id);
|
||||
$buyprice = $buyprice/(1+($ttx/100));
|
||||
}
|
||||
$unitBuyPrice = price2num($buyprice/$qty,'MU');
|
||||
|
||||
$resql = $this->db->query($sql) ;
|
||||
}
|
||||
$now=dol_now();
|
||||
|
||||
|
||||
/**
|
||||
* Modify the purchase price for a supplier
|
||||
* @param qty Min quantity for which price is valid
|
||||
* @param buyprice Purchase price for the quantity min
|
||||
* @param user Object user user made changes
|
||||
* @param price_base_type HT or TTC
|
||||
* @param fourn Supplier
|
||||
* @param availability Product availability
|
||||
*/
|
||||
function update_buyprice($qty, $buyprice, $user, $price_base_type='HT', $fourn,$availability)
|
||||
{
|
||||
global $mysoc;
|
||||
|
||||
$buyprice=price2num($buyprice);
|
||||
$qty=price2num($qty);
|
||||
|
||||
$error=0;
|
||||
$this->db->begin();
|
||||
|
||||
// Supprime prix courant du fournisseur pour cette quantite
|
||||
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_fournisseur_price";
|
||||
if ($this->product_fourn_price_id)
|
||||
{
|
||||
$sql.= " WHERE rowid = ".$this->product_fourn_price_id;
|
||||
}
|
||||
else
|
||||
{
|
||||
$sql.= " WHERE fk_product_fournisseur = ".$this->product_fourn_id;
|
||||
$sql.= " AND quantity = ".$qty;
|
||||
}
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($price_base_type == 'TTC')
|
||||
{
|
||||
$ttx = get_default_tva($fourn,$mysoc,$this->id);
|
||||
$buyprice = $buyprice/(1+($ttx/100));
|
||||
}
|
||||
$unitBuyPrice = price2num($buyprice/$qty,'MU');
|
||||
|
||||
$now=dol_now();
|
||||
|
||||
// Ajoute prix courant du fournisseur pour cette quantite
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
|
||||
$sql.= "datec, fk_product_fournisseur, fk_user, price, quantity, unitprice, fk_availability)";
|
||||
$sql.= " values('".$this->db->idate($now)."',";
|
||||
$sql.= " ".$this->product_fourn_id.",";
|
||||
$sql.= " ".$user->id.",";
|
||||
$sql.= " ".price2num($buyprice).",";
|
||||
$sql.= " ".$qty.",";
|
||||
$sql.= " ".$unitBuyPrice.",";
|
||||
$sql.= " ".$availability;
|
||||
// Ajoute prix courant du fournisseur pour cette quantite
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price(";
|
||||
$sql.= "datec, fk_product_fournisseur, fk_user, price, quantity, unitprice, fk_availability)";
|
||||
$sql.= " values('".$this->db->idate($now)."',";
|
||||
$sql.= " ".$this->product_fourn_id.",";
|
||||
$sql.= " ".$user->id.",";
|
||||
$sql.= " ".price2num($buyprice).",";
|
||||
$sql.= " ".$qty.",";
|
||||
$sql.= " ".$unitBuyPrice.",";
|
||||
$sql.= " ".$availability;
|
||||
$sql.=")";
|
||||
|
||||
dol_syslog("ProductFournisseur::update_buyprice sql=".$sql);
|
||||
if (! $this->db->query($sql))
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
dol_syslog("ProductFournisseur::update_buyprice sql=".$sql);
|
||||
if (! $this->db->query($sql))
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
// Ajoute modif dans table log
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log(";
|
||||
$sql.= "datec, fk_product_fournisseur,fk_user,price,quantity)";
|
||||
$sql.= "values('".$this->db->idate($now)."',";
|
||||
$sql.= " ".$this->product_fourn_id.",";
|
||||
$sql.= " ".$user->id.",";
|
||||
$sql.= " ".price2num($buyprice).",";
|
||||
$sql.= " ".$qty;
|
||||
if (! $error)
|
||||
{
|
||||
// Ajoute modif dans table log
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_fournisseur_price_log(";
|
||||
$sql.= "datec, fk_product_fournisseur,fk_user,price,quantity)";
|
||||
$sql.= "values('".$this->db->idate($now)."',";
|
||||
$sql.= " ".$this->product_fourn_id.",";
|
||||
$sql.= " ".$user->id.",";
|
||||
$sql.= " ".price2num($buyprice).",";
|
||||
$sql.= " ".$qty;
|
||||
$sql.=")";
|
||||
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
$resql=$this->db->query($sql);
|
||||
if (! $resql)
|
||||
{
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error()." sql=".$sql;
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error()." sql=".$sql;
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (! $error)
|
||||
{
|
||||
$this->db->commit();
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error()." sql=".$sql;
|
||||
$this->db->rollback();
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error()." sql=".$sql;
|
||||
$this->db->rollback();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Changes the purchase price for a supplier of the product in the reference supplier
|
||||
* @param id_fourn Supplier ID
|
||||
* @param product_fourn_ref Supplier ref product
|
||||
* @param qty Amount for which the price is valid
|
||||
* @param buyprice Purchase price for the quantity
|
||||
* @param user Object user user made changes
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function UpdateBuyPriceByFournRef($id_fourn, $product_fourn_ref, $qty, $buyprice, $user, $price_base_type='HT')
|
||||
{
|
||||
global $conf;
|
||||
/**
|
||||
* Changes the purchase price for a supplier of the product in the reference supplier
|
||||
*
|
||||
* @param id_fourn Supplier ID
|
||||
* @param product_fourn_ref Supplier ref product
|
||||
* @param qty Amount for which the price is valid
|
||||
* @param buyprice Purchase price for the quantity
|
||||
* @param user Object user user made changes
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function UpdateBuyPriceByFournRef($id_fourn, $product_fourn_ref, $qty, $buyprice, $user, $price_base_type='HT')
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$result=0;
|
||||
$result=0;
|
||||
|
||||
// Recherche id produit pour cette ref et fournisseur
|
||||
$sql = "SELECT fk_product";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE fk_soc = '".$id_fourn."'";
|
||||
$sql.= " AND ref_fourn = '".$product_fourn_ref."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
// Recherche id produit pour cette ref et fournisseur
|
||||
$sql = "SELECT fk_product";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur";
|
||||
$sql.= " WHERE fk_soc = '".$id_fourn."'";
|
||||
$sql.= " AND ref_fourn = '".$product_fourn_ref."'";
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
if ($this->db->query($sql))
|
||||
{
|
||||
if ($obj = $this->db->fetch_object($resql))
|
||||
{
|
||||
// Met a jour prix pour la qte
|
||||
$this->id = $obj->fk_product;
|
||||
$result = $this->update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type);
|
||||
}
|
||||
}
|
||||
$resql=$this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
if ($obj = $this->db->fetch_object($resql))
|
||||
{
|
||||
// Met a jour prix pour la qte
|
||||
$this->id = $obj->fk_product;
|
||||
$result = $this->update_buyprice($id_fourn, $qty, $buyprice, $user, $price_base_type);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Load information about a provider
|
||||
* @param fournid Supplier ID
|
||||
* @return int < 0 if error, > 0 if ok
|
||||
*/
|
||||
function fetch_fourn_data($fournid)
|
||||
{
|
||||
global $conf;
|
||||
/**
|
||||
* Load information about a provider
|
||||
*
|
||||
* @param fournid Supplier ID
|
||||
* @return int < 0 if error, > 0 if ok
|
||||
*/
|
||||
function fetch_fourn_data($fournid)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Check parameters
|
||||
if (empty($fournid)) return -1;
|
||||
// Check parameters
|
||||
if (empty($fournid)) return -1;
|
||||
|
||||
$sql = "SELECT rowid, ref_fourn";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur ";
|
||||
$sql.= " WHERE fk_product = ".$this->id;
|
||||
$sql.= " AND fk_soc = ".$fournid;
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
$sql = "SELECT rowid, ref_fourn";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur ";
|
||||
$sql.= " WHERE fk_product = ".$this->id;
|
||||
$sql.= " AND fk_soc = ".$fournid;
|
||||
$sql.= " AND entity = ".$conf->entity;
|
||||
|
||||
dol_syslog("Product::fetch_fourn_data sql=".$sql);
|
||||
$result = $this->db->query($sql) ;
|
||||
if ($result)
|
||||
{
|
||||
$result = $this->db->fetch_array($result);
|
||||
$this->ref_fourn = $result["ref_fourn"];
|
||||
$this->product_fourn_id = $result["rowid"];
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("ProductFournisseur::fetch_fourn_data error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
dol_syslog("Product::fetch_fourn_data sql=".$sql);
|
||||
$result = $this->db->query($sql) ;
|
||||
if ($result)
|
||||
{
|
||||
$result = $this->db->fetch_array($result);
|
||||
$this->ref_fourn = $result["ref_fourn"];
|
||||
$this->product_fourn_id = $result["rowid"];
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("ProductFournisseur::fetch_fourn_data error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the price information of a provider
|
||||
* @param rowid line id
|
||||
* @return int < 0 if KO, 0 if OK but not found, > 0 if OK
|
||||
*/
|
||||
function fetch_product_fournisseur_price($rowid)
|
||||
{
|
||||
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
|
||||
$sql.= ", pf.rowid as product_fourn_id, pf.fk_soc, pf.ref_fourn, pf.fk_product";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
||||
$sql.= " WHERE pfp.rowid = ".$rowid;
|
||||
$sql.= " AND pf.rowid = pfp.fk_product_fournisseur";
|
||||
/**
|
||||
* Loads the price information of a provider
|
||||
*
|
||||
* @param rowid line id
|
||||
* @return int < 0 if KO, 0 if OK but not found, > 0 if OK
|
||||
*/
|
||||
function fetch_product_fournisseur_price($rowid)
|
||||
{
|
||||
$sql = "SELECT pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
|
||||
$sql.= ", pf.rowid as product_fourn_id, pf.fk_soc, pf.ref_fourn, pf.fk_product";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
||||
$sql.= " WHERE pfp.rowid = ".$rowid;
|
||||
$sql.= " AND pf.rowid = pfp.fk_product_fournisseur";
|
||||
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur_price sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql) ;
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
$this->product_fourn_price_id = $rowid;
|
||||
$this->product_fourn_id = $obj->product_fourn_id;
|
||||
$this->fourn_ref = $obj->ref_fourn;
|
||||
$this->fourn_price = $obj->price;
|
||||
$this->fourn_qty = $obj->quantity;
|
||||
$this->fourn_unitprice = $obj->unitprice;
|
||||
$this->product_id = $obj->fk_product; // deprecated
|
||||
$this->fk_product = $obj->fk_product;
|
||||
$this->fk_availability = $obj->fk_availability;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur_price error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* List all supplier prices of a product
|
||||
*
|
||||
* @param rowid id du produit
|
||||
* @return table table de ProductFournisseur
|
||||
*/
|
||||
function fetch_product_fournisseur($prodid)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
// Suppliers list
|
||||
$sql = "SELECT s.nom as supplier_name, ";
|
||||
$sql.= " s.rowid as fourn_id,";
|
||||
$sql.= " pf.ref_fourn,";
|
||||
$sql.= " pfp.rowid as product_fourn_pri_id, ";
|
||||
$sql.= " pf.rowid as product_fourn_id, ";
|
||||
$sql.= " pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON pf.fk_soc = s.rowid ";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= " ON pf.rowid = pfp.fk_product_fournisseur";
|
||||
$sql.= " WHERE s.entity = ".$conf->entity;
|
||||
$sql.= " AND pf.fk_product = ".$prodid;
|
||||
$sql.= " ORDER BY s.nom, pfp.quantity";
|
||||
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur sql=".$sql, LOG_DEBUG);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
$prod_fourn = array();
|
||||
|
||||
while ($record = $this->db->fetch_array ($resql))
|
||||
{
|
||||
//define base attribute
|
||||
$prodfourn = new ProductFournisseur($this->db);
|
||||
|
||||
$prodfourn->product_fourn_price_id = $record["product_fourn_pri_id"];
|
||||
$prodfourn->product_fourn_id = $record["product_fourn_id"];
|
||||
$prodfourn->fourn_ref = $record["ref_fourn"];
|
||||
$prodfourn->fourn_price = $record["price"];
|
||||
$prodfourn->fourn_qty = $record["quantity"];
|
||||
$prodfourn->fourn_unitprice = $record["unitprice"];
|
||||
$prodfourn->fourn_id = $record["fourn_id"];
|
||||
$prodfourn->fourn_name = $record["supplier_name"];
|
||||
$prodfourn->fk_availability = $record["fk_availability"];
|
||||
$prodfourn->id = $prodid;
|
||||
|
||||
if (!isset($prodfourn->fourn_unitprice))
|
||||
{
|
||||
if ($prodfourn->fourn_qty!=0)
|
||||
{
|
||||
$prodfourn->fourn_unitprice = $prodfourn->fourn_price/$prodfourn->fourn_qty;
|
||||
}
|
||||
else
|
||||
{
|
||||
$prodfourn->fourn_unitprice="";
|
||||
}
|
||||
}
|
||||
|
||||
$prod_fourn[]=$prodfourn;
|
||||
}
|
||||
|
||||
$this->db->free($resql);
|
||||
return $prod_fourn;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Load properties for minimum price
|
||||
*
|
||||
* @param rowid Product id
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
function find_min_price_product_fournisseur($prodid)
|
||||
{
|
||||
global $conf;
|
||||
|
||||
$sql = "SELECT s.nom as supplier_name, ";
|
||||
$sql.= " s.rowid as fourn_id,";
|
||||
$sql.= " pf.ref_fourn,";
|
||||
$sql.= " pfp.rowid as product_fourn_pri_id, ";
|
||||
$sql.= " pf.rowid as product_fourn_id, ";
|
||||
$sql.= " pfp.price, pfp.quantity, pfp.unitprice";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= " INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur as pf ON pf.fk_soc = s.rowid ";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= " ON pf.rowid = pfp.fk_product_fournisseur";
|
||||
$sql.= " WHERE s.entity = ".$conf->entity;
|
||||
$sql.= " AND pf.fk_product = ".$prodid;
|
||||
$sql.= " ORDER BY pfp.unitprice";
|
||||
|
||||
dol_syslog(get_class($this)."::find_min_price_product_fournisseur sql=".$sql, LOG_DEBUG);
|
||||
|
||||
$resql = $this->db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$record = $this->db->fetch_array ($resql);
|
||||
$this->product_fourn_price_id = $record["product_fourn_pri_id"];
|
||||
$this->product_fourn_id = $record["product_fourn_id"];
|
||||
$this->fourn_ref = $record["ref_fourn"];
|
||||
$this->fourn_price = $record["price"];
|
||||
$this->fourn_qty = $record["quantity"];
|
||||
$this->fourn_unitprice = $record["unitprice"];
|
||||
$this->fourn_id = $record["fourn_id"];
|
||||
$this->fourn_name = $record["supplier_name"];
|
||||
$this->id = $prodid;
|
||||
$this->db->free($resql);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog(get_class($this)."::find_min_price_product_fournisseur error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function getSocNomUrl($withpicto=0)
|
||||
{
|
||||
$cust = new Fournisseur($this->db);
|
||||
$cust->fetch($this->fourn_id);
|
||||
|
||||
return $cust->getNomUrl($withpicto);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
function display_price_product_fournisseur()
|
||||
{
|
||||
global $langs;
|
||||
$langs->load("suppliers");
|
||||
$out=price($this->fourn_unitprice).' ('.$langs->trans("Supplier").': '.$this->getSocNomUrl(1).' / '.$langs->trans("SupplierRef").': '.$this->fourn_ref.')';
|
||||
return $out;
|
||||
}
|
||||
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur_price sql=".$sql, LOG_DEBUG);
|
||||
$resql = $this->db->query($sql) ;
|
||||
if ($resql)
|
||||
{
|
||||
$obj = $this->db->fetch_object($resql);
|
||||
if ($obj)
|
||||
{
|
||||
$this->product_fourn_price_id = $rowid;
|
||||
$this->product_fourn_id = $obj->product_fourn_id;
|
||||
$this->fourn_ref = $obj->ref_fourn;
|
||||
$this->fourn_price = $obj->price;
|
||||
$this->fourn_qty = $obj->quantity;
|
||||
$this->fourn_unitprice = $obj->unitprice;
|
||||
$this->product_id = $obj->fk_product; // deprecated
|
||||
$this->fk_product = $obj->fk_product;
|
||||
$this->fk_availability = $obj->fk_availability;
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->error=$this->db->error();
|
||||
dol_syslog("ProductFournisseur::fetch_product_fournisseur_price error=".$this->error, LOG_ERR);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
* \file htdocs/fourn/commande/fiche.php
|
||||
* \ingroup supplier, order
|
||||
* \brief Card supplier order
|
||||
* \version $Id: fiche.php,v 1.233 2011/08/04 21:46:51 eldy Exp $
|
||||
* \version $Id: fiche.php,v 1.234 2011/08/20 23:56:04 eldy Exp $
|
||||
*/
|
||||
|
||||
require("../../main.inc.php");
|
||||
|
|
@ -141,8 +141,8 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
|
|||
{
|
||||
$qty = $_POST['qty'] ? $_POST['qty'] : $_POST['pqty'];
|
||||
|
||||
$product = new ProductFournisseur($db);
|
||||
$idprod=$product->get_buyprice($_POST['idprodfournprice'], $qty);
|
||||
$productsupplier = new ProductFournisseur($db);
|
||||
$idprod=$productsupplier->get_buyprice($_POST['idprodfournprice'], $qty);
|
||||
|
||||
//$societe='';
|
||||
if ($object->socid)
|
||||
|
|
@ -153,20 +153,20 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
|
|||
|
||||
if ($idprod > 0)
|
||||
{
|
||||
$res=$product->fetch($idprod);
|
||||
$res=$productsupplier->fetch($idprod);
|
||||
|
||||
// cas special pour lequel on a les meme reference que le fournisseur
|
||||
// $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
|
||||
$label = $product->libelle;
|
||||
$label = $productsupplier->libelle;
|
||||
|
||||
$desc = $product->description;
|
||||
$desc.= $product->description && $_POST['np_desc'] ? "\n" : "";
|
||||
$desc = $productsupplier->description;
|
||||
$desc.= $productsupplier->description && $_POST['np_desc'] ? "\n" : "";
|
||||
$desc.= $_POST['np_desc'];
|
||||
|
||||
$remise_percent = $_POST["remise_percent"] ? $_POST["remise_percent"] : $_POST["p_remise_percent"];
|
||||
|
||||
$tva_tx = get_default_tva($societe,$mysoc,$product->id);
|
||||
$type = $product->type;
|
||||
$tva_tx = get_default_tva($societe,$mysoc,$productsupplier->id);
|
||||
$type = $productsupplier->type;
|
||||
|
||||
// Local Taxes
|
||||
$localtax1_tx= get_localtax($tva_tx, 1, $societe);
|
||||
|
|
@ -179,9 +179,9 @@ if ($action == 'addline' && $user->rights->fournisseur->commande->creer)
|
|||
$tva_tx,
|
||||
$localtax1_tx,
|
||||
$localtax2_tx,
|
||||
$product->id,
|
||||
$productsupplier->id,
|
||||
$_POST['idprodfournprice'],
|
||||
$product->fourn_ref,
|
||||
$productsupplier->fourn_ref,
|
||||
$remise_percent,
|
||||
'HT',
|
||||
$type
|
||||
|
|
@ -1542,5 +1542,5 @@ if ($id > 0 || ! empty($ref))
|
|||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date: 2011/08/04 21:46:51 $ - $Revision: 1.233 $');
|
||||
llxFooter('$Date: 2011/08/20 23:56:04 $ - $Revision: 1.234 $');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ ListOfSuppliers=List of suppliers
|
|||
ShowSupplier=Show supplier
|
||||
OrderDate=Order date
|
||||
BuyingPrice=Buying price
|
||||
BuyingPriceMin=Minimum buying price
|
||||
AddSupplierPrice=Add supplier price
|
||||
ChangeSupplierPrice=Change supplier price
|
||||
ErrorQtyTooLowForThisSupplier=Quantity too low for this supplier or no price defined on this product for this supplier
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ ListOfSuppliers=Liste des fournisseurs
|
|||
ShowSupplier=Afficher fournisseur
|
||||
OrderDate=Date commande
|
||||
BuyingPrice=Prix d'achat
|
||||
BuyingPriceMin=Prix d'achat minimum
|
||||
AddSupplierPrice=Ajouter prix fournisseur
|
||||
ChangeSupplierPrice=Modifier prix fournisseur
|
||||
ErrorSupplierCountryIsNotDefined=Le pays de ce fournisseur n'est pas défini. Corriger sur sa fiche.
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* $Id: list.tpl.php,v 1.4 2011/07/31 23:19:26 eldy Exp $
|
||||
* $Id: list.tpl.php,v 1.5 2011/08/20 23:56:03 eldy Exp $
|
||||
*/
|
||||
?>
|
||||
|
||||
|
|
@ -83,7 +83,7 @@
|
|||
<!-- FIELDS DATA -->
|
||||
|
||||
<?php
|
||||
$var=True;
|
||||
$var=true;
|
||||
foreach($datas as $line) {
|
||||
$var=!$var; ?>
|
||||
<tr <?php echo $bc[$var]; ?>>
|
||||
|
|
|
|||
|
|
@ -23,13 +23,13 @@
|
|||
* \file htdocs/product/fournisseurs.php
|
||||
* \ingroup product
|
||||
* \brief Page of tab suppliers for products
|
||||
* \version $Id: fournisseurs.php,v 1.99 2011/08/17 16:44:38 simnandez Exp $
|
||||
* \version $Id: fournisseurs.php,v 1.100 2011/08/20 23:56:04 eldy Exp $
|
||||
*/
|
||||
|
||||
require("../main.inc.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
|
||||
require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php");
|
||||
require_once DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php";
|
||||
require_once(DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php");
|
||||
|
||||
$langs->load("products");
|
||||
$langs->load("suppliers");
|
||||
|
|
@ -228,9 +228,20 @@ if ($_GET["id"] || $_GET["ref"])
|
|||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
// Libelle
|
||||
// Label
|
||||
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td></tr>';
|
||||
|
||||
// Minimum Price
|
||||
print '<tr><td>'.$langs->trans("BuyingPriceMin").'</td>';
|
||||
print '<td colspan="2">';
|
||||
$product_fourn = new ProductFournisseur($db);
|
||||
if ($product_fourn->find_min_price_product_fournisseur($product->id) > 0)
|
||||
{
|
||||
if (isset($product_fourn->fourn_unitprice)) print $product_fourn->display_price_product_fournisseur();
|
||||
else print $langs->trans("NotDefined");
|
||||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Status (to buy)
|
||||
print '<tr><td>'.$langs->trans("Status").' ('.$langs->trans("Buy").')'.'</td><td>';
|
||||
print $product->getLibStatut(2,1);
|
||||
|
|
@ -277,6 +288,7 @@ if ($_GET["id"] || $_GET["ref"])
|
|||
}
|
||||
print '</td></tr>';
|
||||
|
||||
// Ref supplier
|
||||
print '<tr><td>'.$langs->trans("SupplierRef").'</td><td colspan="3">';
|
||||
if ($_GET["rowid"])
|
||||
{
|
||||
|
|
@ -288,14 +300,16 @@ if ($_GET["id"] || $_GET["ref"])
|
|||
}
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
|
||||
//Availability
|
||||
|
||||
// Availability
|
||||
if(!empty($conf->global->FOURN_PRODUCT_AVAILABILITY))
|
||||
{
|
||||
print '<tr><td>'.$langs->trans("Availability").'</td><td colspan="3">';
|
||||
$html->select_availability($product->fk_availability,"oselDispo",1);
|
||||
print '</td></tr>'."\n";
|
||||
}
|
||||
|
||||
// Qty min
|
||||
print '<tr>';
|
||||
print '<td>'.$langs->trans("QtyMin").'</td>';
|
||||
print '<td>';
|
||||
|
|
@ -353,8 +367,8 @@ if ($_GET["id"] || $_GET["ref"])
|
|||
print '<table class="noborder" width="100%">';
|
||||
if ($product->isproduct()) $nblignefour=4;
|
||||
else $nblignefour=4;
|
||||
|
||||
$param="&id=".$product->id;
|
||||
|
||||
$param="&id=".$product->id;
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
|
||||
print '<td class="liste_titre">'.$langs->trans("SupplierRef").'</td>';
|
||||
|
|
@ -366,78 +380,60 @@ if ($_GET["id"] || $_GET["ref"])
|
|||
print '<td class="liste_titre"></td>';
|
||||
print "</tr>\n";
|
||||
|
||||
// Suppliers list
|
||||
$sql = "SELECT s.nom, s.rowid as socid,";
|
||||
$sql.= " pf.ref_fourn,";
|
||||
$sql.= " pfp.rowid, pfp.price, pfp.quantity, pfp.unitprice, pfp.fk_availability";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
|
||||
$sql.= ", ".MAIN_DB_PREFIX."product_fournisseur as pf";
|
||||
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
|
||||
$sql.= " ON pf.rowid = pfp.fk_product_fournisseur";
|
||||
$sql.= " WHERE pf.fk_soc = s.rowid";
|
||||
$sql.= " AND s.entity = ".$conf->entity;
|
||||
$sql.= " AND pf.fk_product = ".$product->id;
|
||||
//$sql.= " ORDER BY s.nom, pfp.quantity";
|
||||
$sql.= $db->order($sortfield,$sortorder);
|
||||
$resql=$db->query($sql);
|
||||
if ($resql)
|
||||
{
|
||||
$num = $db->num_rows($resql);
|
||||
$i = 0;
|
||||
$product_fourn = new ProductFournisseur($db);
|
||||
$product_fourn_list = $product_fourn->fetch_product_fournisseur($product->id);
|
||||
|
||||
$var=True;
|
||||
while ($i < $num)
|
||||
if (sizeof($product_fourn_list)>0)
|
||||
{
|
||||
$var=true;
|
||||
|
||||
foreach($product_fourn_list as $productfourn)
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
$var=!$var;
|
||||
|
||||
print "<tr $bc[$var]>";
|
||||
print '<td><a href="../fourn/fiche.php?socid='.$objp->socid.'">'.img_object($langs->trans("ShowCompany"),'company').' '.$objp->nom.'</a></td>';
|
||||
print "<tr ".$bc[$var].">";
|
||||
|
||||
print '<td>'.$productfourn->getSocNomUrl(1).'</td>';
|
||||
|
||||
// Supplier
|
||||
print '<td align="left">'.$objp->ref_fourn.'</td>';
|
||||
|
||||
print '<td align="left">'.$productfourn->fourn_ref.'</td>';
|
||||
|
||||
//Availability
|
||||
if(!empty($conf->global->FOURN_PRODUCT_AVAILABILITY))
|
||||
{
|
||||
$html->load_cache_availability();
|
||||
$availability= $html->cache_availability[$objp->fk_availability]['label'];
|
||||
$availability= $html->cache_availability[$productfourn->fk_availability]['label'];
|
||||
print '<td align="left">'.$availability.'</td>';
|
||||
}
|
||||
|
||||
// Quantity
|
||||
print '<td align="center">';
|
||||
print $objp->quantity;
|
||||
print $productfourn->fourn_qty;
|
||||
print '</td>';
|
||||
|
||||
// Price quantity
|
||||
print '<td align="right">';
|
||||
print $objp->price?price($objp->price):"";
|
||||
print $productfourn->fourn_price?price($productfourn->fourn_price):"";
|
||||
print '</td>';
|
||||
|
||||
// Unit price
|
||||
print '<td align="right">';
|
||||
print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" ");
|
||||
print price($productfourn->fourn_unitprice);
|
||||
//print $objp->unitprice? price($objp->unitprice) : ($objp->quantity?price($objp->price/$objp->quantity):" ");
|
||||
print '</td>';
|
||||
|
||||
// Modify-Remove
|
||||
print '<td align="center">';
|
||||
if ($user->rights->produit->creer || $user->rights->service->creer)
|
||||
{
|
||||
print '<a href="fournisseurs.php?id='.$product->id.'&socid='.$objp->socid.'&action=add_price&rowid='.$objp->rowid.'">'.img_edit()."</a>";
|
||||
print '<a href="fournisseurs.php?id='.$product->id.'&socid='.$objp->socid.'&action=remove_pf&rowid='.$objp->rowid.'">'.img_picto($langs->trans("Remove"),'disable.png').'</a>';
|
||||
print '<a href="fournisseurs.php?id='.$product->id.'&socid='.$productfourn->fourn_id.'&action=add_price&rowid='.$productfourn->product_fourn_price_id.'">'.img_edit()."</a>";
|
||||
print '<a href="fournisseurs.php?id='.$product->id.'&socid='.$productfourn->fourn_id.'&action=remove_pf&rowid='.$productfourn->product_fourn_price_id.'">'.img_picto($langs->trans("Remove"),'disable.png').'</a>';
|
||||
}
|
||||
|
||||
print '</td>';
|
||||
|
||||
print '</tr>';
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
$db->free($resql);
|
||||
}
|
||||
else {
|
||||
dol_print_error($db);
|
||||
}
|
||||
|
||||
print '</table>';
|
||||
|
|
@ -453,5 +449,5 @@ else
|
|||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date: 2011/08/17 16:44:38 $ - $Revision: 1.99 $');
|
||||
llxFooter('$Date: 2011/08/20 23:56:04 $ - $Revision: 1.100 $');
|
||||
?>
|
||||
|
|
@ -21,7 +21,7 @@
|
|||
* \file htdocs/product/liste.php
|
||||
* \ingroup produit
|
||||
* \brief Page to list products and services
|
||||
* \version $Id: liste.php,v 1.152 2011/07/31 23:19:25 eldy Exp $
|
||||
* \version $Id: liste.php,v 1.153 2011/08/20 23:56:04 eldy Exp $
|
||||
*/
|
||||
|
||||
require("../main.inc.php");
|
||||
|
|
@ -296,6 +296,7 @@ if ($resql)
|
|||
if ($conf->service->enabled && $type != 0) print_liste_field_titre($langs->trans("Duration"), $_SERVER["PHP_SELF"], "p.duration",$param,"",'align="center"',$sortfield,$sortorder);
|
||||
if (empty($conf->global->PRODUIT_MULTIPRICES)) print_liste_field_titre($langs->trans("SellingPrice"), $_SERVER["PHP_SELF"], "p.price",$param,"",'align="right"',$sortfield,$sortorder);
|
||||
if ($conf->stock->enabled && $user->rights->stock->lire && $type != 1) print '<td class="liste_titre" align="right">'.$langs->trans("PhysicalStock").'</td>';
|
||||
if ($conf->fournisseur->enabled && $user->rights->fournisseur->lire && $type != 1) print '<td class="liste_titre" align="right">'.$langs->trans("BuyingPriceMin").'</td>';
|
||||
print_liste_field_titre($langs->trans("Sell"), $_SERVER["PHP_SELF"], "p.tosell",$param,"",'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans("Buy"), $_SERVER["PHP_SELF"], "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder);
|
||||
print "</tr>\n";
|
||||
|
|
@ -341,6 +342,14 @@ if ($resql)
|
|||
print ' ';
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
// Minimum buying Price
|
||||
if ($conf->fournisseur->enabled && $user->rights->fournisseur->lire && $type != 1)
|
||||
{
|
||||
print '<td class="liste_titre">';
|
||||
print ' ';
|
||||
print '</td>';
|
||||
}
|
||||
|
||||
print '<td class="liste_titre">';
|
||||
print ' ';
|
||||
|
|
@ -355,7 +364,7 @@ if ($resql)
|
|||
|
||||
$product_static=new Product($db);
|
||||
|
||||
$var=True;
|
||||
$var=true;
|
||||
while ($i < min($num,$limit))
|
||||
{
|
||||
$objp = $db->fetch_object($resql);
|
||||
|
|
@ -438,6 +447,25 @@ if ($resql)
|
|||
print '<td> </td>';
|
||||
}
|
||||
}
|
||||
|
||||
// MinimumPrice
|
||||
if ($conf->fournisseur->enabled && $user->rights->fournisseur->lire && $type != 1)
|
||||
{
|
||||
if ($objp->fk_product_type != 1)
|
||||
{
|
||||
require_once(DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php");
|
||||
|
||||
$product_fourn = new ProductFournisseur($db);
|
||||
if ($product_fourn->find_min_price_product_fournisseur($objp->rowid))
|
||||
{
|
||||
print '<td align="right">'.$product_fourn->display_price_product_fournisseur().'</td>';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<td> </td>';
|
||||
}
|
||||
}
|
||||
|
||||
// Status (to buy)
|
||||
print '<td align="right" nowrap="nowrap">'.$product_static->LibStatut($objp->tosell,5,0).'</td>';
|
||||
|
|
@ -475,5 +503,5 @@ else
|
|||
|
||||
$db->close();
|
||||
|
||||
llxFooter('$Date: 2011/07/31 23:19:25 $ - $Revision: 1.152 $');
|
||||
llxFooter('$Date: 2011/08/20 23:56:04 $ - $Revision: 1.153 $');
|
||||
?>
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
/**
|
||||
* \file htdocs/user/class/user.class.php
|
||||
* \brief Fichier de la classe utilisateur
|
||||
* \version $Id: user.class.php,v 1.50 2011/08/20 16:59:18 eldy Exp $
|
||||
* \version $Id: user.class.php,v 1.51 2011/08/20 23:56:03 eldy Exp $
|
||||
*/
|
||||
|
||||
require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php");
|
||||
|
|
@ -118,6 +118,7 @@ class User extends CommonObject
|
|||
|
||||
/**
|
||||
* Load a user from database with its id or ref (login)
|
||||
*
|
||||
* @param id Si defini, id a utiliser pour recherche
|
||||
* @param login Si defini, login a utiliser pour recherche
|
||||
* @param sid Si defini, sid a utiliser pour recherche
|
||||
|
|
@ -145,7 +146,7 @@ class User extends CommonObject
|
|||
$sql.= " u.openid as openid";
|
||||
$sql.= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||
|
||||
if($conf->multicompany->enabled && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity)))
|
||||
if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && ! $user->entity)))
|
||||
{
|
||||
$sql.= " WHERE u.entity IS NOT NULL";
|
||||
}
|
||||
|
|
@ -154,12 +155,11 @@ class User extends CommonObject
|
|||
$sql.= " WHERE u.entity IN (0,".$conf->entity.")";
|
||||
}
|
||||
|
||||
if ($sid)
|
||||
if ($sid) // permet une recherche du user par son SID ActiveDirectory ou Samba
|
||||
{
|
||||
$sql.= " AND (u.ldap_sid = '".$sid."' OR u.login = '".$this->db->escape($login)."') LIMIT 1";
|
||||
}
|
||||
else if ($login)
|
||||
// permet une recherche du user par son SID ActiveDirectory ou Samba
|
||||
{
|
||||
$sql.= " AND u.login = '".$this->db->escape($login)."'";
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user