Factorisation du code des onglets produits

Dbuggage fiche produits fournisseurs
Affichage du nombre de commande en cours d'un produit
This commit is contained in:
Laurent Destailleur 2006-08-01 23:54:39 +00:00
parent 2e643bfa7b
commit 377aecf983
7 changed files with 242 additions and 189 deletions

View File

@ -1136,19 +1136,19 @@ class Commande extends CommonObject
// Recherche total en stock pour chaque produit
if (sizeof($array_of_product))
{
$sql = "SELECT fk_product, sum(ps.reel)";
$sql = "SELECT fk_product, sum(ps.reel) as total";
$sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps";
$sql.= " WHERE ps.fk_product in (".join(',',$array_of_product).")";
$sql.= ' GROUP BY fk_product ';
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows();
$num = $this->db->num_rows($result);
$i = 0;
while ($i < $num)
{
$row = $this->db->fetch_row( $i);
$this->stocks[$row[0]] = $row[1];
$obj = $this->db->fetch_object($result);
$this->stocks[$obj->fk_product] = $obj->total;
$i++;
}
$this->db->free();
@ -1426,13 +1426,12 @@ class Commande extends CommonObject
}
}
/**
* \brief Renvoi la liste des commandes (éventuellement filtrée sur un user) dans un tableau
* \param brouillon 0=non brouillon, 1=brouillon
* \param user Objet user de filtre
* \return int -1 si erreur, tableau résultat si ok
*/
/**
* \brief Renvoi la liste des commandes (éventuellement filtrée sur un user) dans un tableau
* \param brouillon 0=non brouillon, 1=brouillon
* \param user Objet user de filtre
* \return int -1 si erreur, tableau résultat si ok
*/
function liste_array ($brouillon=0, $user='')
{
$ga = array();

View File

@ -438,16 +438,8 @@ if ($_GET["id"] > 0)
{
$objp = $db->fetch_object($resql);
print "<tr $bc[$var]>";
print '<td><a href="'.DOL_URL_ROOT.'/fourn/product/fiche.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</a></td>';
if ($objp->fk_product > 0)
{
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/fourn/product/fiche.php?id='.$objp->fk_product.'">'.stripslashes(nl2br($objp->description)).'</a></td>';
}
else
{
print "<td>".stripslashes(nl2br($objp->description))."</td>\n";
}
print '<td><a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</a></td>';
print "<td>".nl2br($objp->description)."</td>";
print '<td align="center">'.$objp->tva_tx.'%</td>';
print '<td align="center">'.$objp->qty.'</td>';
if ($objp->remise_percent > 0)

View File

@ -49,10 +49,11 @@ $types[1] = $langs->trans("Service");
if ($_GET["action"] == 'fastappro')
{
$product = new Product($db);
$product->fetch($_GET["id"]);
$result = $product->fastappro($user);
Header("Location: fiche.php?id=".$_GET["id"]);
$product = new Product($db);
$product->fetch($_GET["id"]);
$result = $product->fastappro($user);
Header("Location: fiche.php?id=".$_GET["id"]);
exit;
}
@ -572,27 +573,28 @@ else
print "\n<div class=\"tabsAction\">\n";
if ($_GET["action"] == '')
{
print '<a class="butAction" href="fiche.php?id='.$product->id.'&amp;action=ajout_fourn">'.$langs->trans("AddSupplier").'</a>';
if ($product->type == 0 && $user->rights->produit->commander && $num_fournisseur == 1)
if ($_GET["action"] == '')
{
print '<a class="tabAction" href="fiche.php?action=fastappro&amp;id='.$product->id.'">';
print $langs->trans("Order").'</a>';
if ( $user->rights->produit->creer)
{
print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Edit").'</a>';
}
if ($product->type == 0 && $conf->stock->enabled)
{
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/stock/product.php?id='.$product->id.'&amp;action=correction">'.$langs->trans("CorrectStock").'</a>';
}
print '<a class="butAction" href="fiche.php?id='.$product->id.'&amp;action=ajout_fourn">'.$langs->trans("AddSupplier").'</a>';
if ($product->type == 0 && $user->rights->commande->creer)
{
$langs->load('orders');
print '<a class="tabAction" href="fiche.php?action=fastappro&amp;id='.$product->id.'">';
print $langs->trans("CreateOrder").'</a>';
}
}
if ( $user->rights->produit->creer)
{
print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Edit").'</a>';
}
if ($product->type == 0 && $conf->stock->enabled)
{
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/stock/product.php?id='.$product->id.'&amp;action=correction">'.$langs->trans("CorrectStock").'</a>';
}
}
print "\n</div>\n";

View File

@ -1,4 +1,4 @@
<?php
<?php
/* Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
@ -26,22 +26,22 @@
\version $Revision$
Ensemble de fonctions de base de dolibarr sous forme d'include
*/
function product_prepare_head($product)
{
global $langs, $conf;
$h = 0;
$head = array();
*/
function product_prepare_head($product)
{
global $langs, $conf;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/product/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans("Card");
$head[$h][2] = 'card';
$head[$h][2] = 'card';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/price.php?id=".$product->id;
$head[$h][1] = $langs->trans("Price");
$head[$h][2] = 'price';
$head[$h][2] = 'price';
$h++;
//affichage onglet catégorie
@ -49,7 +49,7 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/categorie.php?id=".$product->id;
$head[$h][1] = $langs->trans('Categories');
$head[$h][2] = 'category';
$head[$h][2] = 'category';
$h++;
}
@ -61,30 +61,19 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/barcode.php?id=".$product->id;
$head[$h][1] = $langs->trans("BarCode");
$head[$h][2] = 'barcode';
$head[$h][2] = 'barcode';
$h++;
}
}
}
if($product->type == 0) // Si produit stockable
{
if ($conf->stock->enabled)
{
$head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
$head[$h][1] = $langs->trans("Stock");
$head[$h][2] = 'stock';
$h++;
}
}
// Multilangs
// Multilangs
// TODO Ecran a virer et à remplacer par
if($conf->global->MAIN_MULTILANGS)
{
$head[$h][0] = DOL_URL_ROOT."/product/traduction.php?id=".$product->id;
$head[$h][1] = $langs->trans("Translation");
$head[$h][2] = 'translation';
$head[$h][2] = 'translation';
$h++;
}
@ -92,13 +81,13 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/fournisseurs.php?id=".$product->id;
$head[$h][1] = $langs->trans("Suppliers");
$head[$h][2] = 'suppliers';
$head[$h][2] = 'suppliers';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('Statistics');
$head[$h][2] = 'stats';
$head[$h][2] = 'stats';
$h++;
// sousproduits
@ -106,27 +95,38 @@ function product_prepare_head($product)
{
$head[$h][0] = DOL_URL_ROOT."/product/sousproduits/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('AssociatedProducts');
$head[$h][2] = 'subproduct';
$head[$h][2] = 'subproduct';
$h++;
}
$head[$h][0] = DOL_URL_ROOT."/product/stats/facture.php?id=".$product->id;
$head[$h][1] = $langs->trans('Referers');
$head[$h][2] = 'referers';
$head[$h][2] = 'referers';
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$head[$h][2] = 'photos';
$head[$h][2] = 'photos';
$h++;
$head[$h][0] = DOL_URL_ROOT.'/product/document.php?id='.$product->id;
$head[$h][1] = $langs->trans('Documents');
$head[$h][2] = 'document';
$h++;
return $head;
}
$head[$h][2] = 'document';
$h++;
if($product->type == 0) // Si produit stockable
{
if ($conf->stock->enabled)
{
$head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
$head[$h][1] = $langs->trans("Stock");
$head[$h][2] = 'stock';
$h++;
}
}
return $head;
}
?>

View File

@ -964,14 +964,14 @@ class Product
/**
* \brief Charge tableau des stats commande pour le produit/service
* \param socid Id societe
* \return array Tableau des stats
* \brief Charge tableau des stats commande client pour le produit/service
* \param socid Id societe pour filtrer sur une société
* \param filtrestatut Id statut pour filtrer sur un statut
* \return array Tableau des stats
*/
function load_stats_commande($socid=0)
function load_stats_commande($socid=0,$filtrestatut='')
{
global $conf;
global $user;
global $conf,$user;
$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_customers, COUNT(DISTINCT c.rowid) as nb,";
$sql.= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
@ -980,12 +980,15 @@ class Product
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.rowid = cd.fk_commande AND cd.fk_product = ".$this->id;
if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
//$sql.= " AND c.fk_statut != 0";
if ($socid > 0)
{
$sql .= " AND c.fk_soc = $socid";
$sql.= " AND c.fk_soc = ".$socid;
}
if ($filtrestatut)
{
$sql.= " AND c.fk_statut = ".$filtrestatut;
}
$result = $this->db->query($sql) ;
if ( $result )
{
@ -1003,6 +1006,49 @@ class Product
}
}
/**
* \brief Charge tableau des stats commande fournisseur pour le produit/service
* \param socid Id societe pour filtrer sur une société
* \param filtrestatut Id statut pour filtrer sur un statut
* \return array Tableau des stats
*/
function load_stats_commande_fournisseur($socid=0,$filtrestatut='')
{
global $conf,$user;
$sql = "SELECT COUNT(DISTINCT c.fk_soc) as nb_suppliers, COUNT(DISTINCT c.rowid) as nb,";
$sql.= " COUNT(cd.rowid) as nb_rows, SUM(cd.qty) as qty";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd,";
$sql.= " ".MAIN_DB_PREFIX."commande_fournisseur as c";
if (!$user->rights->commercial->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= " WHERE c.rowid = cd.fk_commande AND cd.fk_product = ".$this->id;
if (!$user->rights->commercial->client->voir && !$socid) $sql .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id;
if ($socid > 0)
{
$sql.= " AND c.fk_soc = ".$socid;
}
if ($filtrestatut)
{
$sql.= " AND c.fk_statut = ".$filtrestatut;
}
$result = $this->db->query($sql) ;
if ( $result )
{
$obj=$this->db->fetch_object($result);
$this->stats_commande_fournisseur['suppliers']=$obj->nb_suppliers;
$this->stats_commande_fournisseur['nb']=$obj->nb;
$this->stats_commande_fournisseur['rows']=$obj->nb_rows;
$this->stats_commande_fournisseur['qty']=$obj->qty?$obj->qty:0;
return 1;
}
else
{
$this->error=$this->db->error();
return -1;
}
}
/**
* \brief Charge tableau des stats contrat pour le produit/service
* \param socid Id societe
@ -1360,61 +1406,55 @@ class Product
}
}
/**
* \brief Renvoie le nombre de fournisseurs
* \return int nombre de fournisseur
*/
function count_fournisseur()
{
$sql = "SELECT fk_soc";
$sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur as p";
$sql .= " WHERE p.fk_product = ".$this->id;
$result = $this->db->query($sql) ;
if ( $result )
/**
* \brief Renvoie la liste des fournisseurs du produit/service
* \return array Tableau des id de fournisseur
*/
function list_suppliers()
{
$num = $this->db->num_rows();
$list = array();
$sql = "SELECT fk_soc";
$sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur as p";
$sql.= " WHERE p.fk_product = ".$this->id;
$result = $this->db->query($sql);
if ($result)
{
$num = $this->db->num_rows($result);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($result);
$list[$i] = $obj->fk_soc;
$i++;
}
}
if ($num == 1)
{
$row = $this->db->fetch_row();
$this->fourn_appro_open = $row[0];
return 1;
}
else
{
return 0;
}
return $list;
}
else
/**
* \brief Saisie une commande fournisseur
* \param user Objet user de celui qui demande
* \param int <0 si ko, >0 si ok
*/
function fastappro($user)
{
return 0;
include_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php";
$list = $this->list_suppliers();
if (sizeof($list) > 0)
{
dolibarr_syslog("Product::fastappro");
$fournisseur = new Fournisseur($this->db);
$fournisseur->fetch($this->fourn_appro_open);
$fournisseur->ProductCommande($user, $this->id);
}
return 1;
}
}
/**
*
*
*/
function fastappro($user)
{
include_once DOL_DOCUMENT_ROOT."/fourn/fournisseur.class.php";
$nbf = $this->count_fournisseur();
if ($nbf == 1)
{
dolibarr_syslog("Product::fastappro");
$fournisseur = new Fournisseur($this->db);
$fournisseur->fetch($this->fourn_appro_open);
$fournisseur->ProductCommande($user, $this->id);
}
}
/**

View File

@ -353,24 +353,6 @@ if ($_POST["action"] == 'addinfacture' && $user->rights->facture->creer)
exit;
}
if ($_POST["action"] == 'add_fourn' && $_POST["cancel"] <> $langs->trans("Cancel"))
{
$product = new Product($db);
if( $product->fetch($_GET["id"]) )
{
if ($product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]) > 0)
{
$action = '';
$mesg = $langs->trans("SupplierAdded");
}
else
{
$action = '';
}
}
}
if ($_POST["cancel"] == $langs->trans("Cancel"))
{
$action = '';
@ -500,7 +482,7 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
}
/*
/**
* Fiche produit
*/
if ($_GET["id"] || $_GET["ref"])
@ -509,8 +491,15 @@ if ($_GET["id"] || $_GET["ref"])
if ($_GET["action"] <> 're-edit')
{
$product = new Product($db);
if ($_GET["ref"]) $result = $product->fetch('',$_GET["ref"]);
if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
if ($_GET["ref"])
{
$result = $product->fetch('',$_GET["ref"]);
$_GET["id"] = $product->id;
}
elseif ($_GET["id"])
{
$result = $product->fetch($_GET["id"]);
}
llxHeader("","",$langs->trans("CardProduct".$product->type));
}
@ -600,7 +589,7 @@ if ($_GET["id"] || $_GET["ref"])
// Stock
if ($product->type == 0 && $conf->stock->enabled)
{
print '<tr><td><a href="stock/product.php?id='.$product->id.'">'.$langs->trans("Stock").'</a></td>';
print '<tr><td>'.$langs->trans("Stock").'</td>';
if ($product->no_stock)
{
print "<td>Pas de définition de stock pour ce produit";
@ -762,12 +751,6 @@ print "\n<div class=\"tabsAction\">\n";
if ($_GET["action"] == '')
{
if ($product->type == 0 && $user->rights->produit->commander && $num_fournisseur == 1)
{
print '<a class="tabAction" href="fiche.php?action=fastappro&amp;id='.$product->id.'">';
print $langs->trans("Order").'</a>';
}
if ( $user->rights->produit->creer)
{
print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Edit").'</a>';
@ -775,9 +758,24 @@ if ($_GET["action"] == '')
print '<a class="tabAction" href="fiche.php?action=clone&amp;id='.$product->id.'">'.$langs->trans("CreateCopy").'</a>';
}
$prod_use = $product->verif_prod_use($product->id);
/*
if ($product->type == 0 && $user->rights->commande->creer)
{
$langs->load('orders');
print '<a class="tabAction" href="fiche.php?action=fastappro&amp;id='.$product->id.'">';
print $langs->trans("CreateCustomerOrder").'</a>';
}
if ($user->rights->produit->supprimer && $prod_use == 0)
if ($product->type == 0 && $user->rights->fournisseur->commande->creer)
{
$langs->load('orders');
print '<a class="tabAction" href="fiche.php?action=fastappro&amp;id='.$product->id.'">';
print $langs->trans("CreateSupplierOrder").'</a>';
}
*/
$product_is_used = $product->verif_prod_use($product->id);
if ($user->rights->produit->supprimer && ! $product_is_used)
{
print '<a class="butActionDelete" href="fiche.php?action=delete&amp;id='.$product->id.'">'.$langs->trans("Delete").'</a>';
}

View File

@ -40,9 +40,9 @@ $langs->load("bills");
$user->getrights('produit');
$mesg = '';
if (!$user->rights->produit->lire)
if (! $user->rights->produit->lire || ! $product->type == 0 || ! $conf->stock->enabled)
{
accessforbidden();
accessforbidden();
}
@ -142,32 +142,54 @@ if ($_GET["id"] || $_GET["ref"])
print $product->getLibStatut(2);
print '</td></tr>';
// TVA
$langs->load("bills");
print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.$product->tva_tx.'%</td></tr>';
// Stock
if ($product->type == 0 && $conf->stock->enabled)
print '<tr><td>'.$langs->trans("TotalStock").'</td>';
if ($product->no_stock)
{
print '<tr><td>'.$langs->trans("TotalStock").'</td>';
if ($product->no_stock)
print "<td>Pas de définition de stock pour ce produit";
}
else
{
if ($product->stock_reel <= $product->seuil_stock_alerte)
{
print "<td>Pas de définition de stock pour ce produit";
print '<td class="alerte">'.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte;
}
else
{
if ($product->stock_reel <= $product->seuil_stock_alerte)
{
print '<td class="alerte">'.$product->stock_reel.' Seuil : '.$product->seuil_stock_alerte;
}
else
{
print "<td>".$product->stock_reel;
}
print "<td>".$product->stock_reel;
}
print '</td></tr>';
}
print '</td></tr>';
// Nbre de commande clients en cours
if ($conf->commande->enabled)
{
$result=$product->load_stats_commande(0,'1');
if ($result < 0) dolibarr_print_error($db,$product->error);
print '<tr><td>'.$langs->trans("CustomersOrders").'</td>';
print '<td>';
print $product->stats_commande['qty'];
$result=$product->load_stats_commande(0,'0');
if ($result < 0) dolibarr_print_error($db,$product->error);
print ' ('.$langs->trans("Draft").': '.$product->stats_commande['qty'].')';
print '</td></tr>';
}
// Nbre de commande fournisseurs en cours
if ($conf->fournisseur->enabled)
{
$result=$product->load_stats_commande_fournisseur(0,'1');
if ($result < 0) dolibarr_print_error($db,$product->error);
print '<tr><td>'.$langs->trans("SuppliersOrders").'</td>';
print '<td>';
print $product->stats_commande_fournisseur['qty'];
$result=$product->load_stats_commande_fournisseur(0,'0');
if ($result < 0) dolibarr_print_error($db,$product->error);
print ' ('.$langs->trans("Draft").': '.$product->stats_commande_fournisseur['qty'].')';
print '</td></tr>';
}
print "</table>";
}