Fix: Débuggage de la gestion des fournisseurs, photos et prix sur les produits

This commit is contained in:
Laurent Destailleur 2005-06-11 11:39:38 +00:00
parent dffa43b161
commit 4644cd7d09
5 changed files with 687 additions and 589 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -216,30 +216,6 @@ if ($_GET["action"] == 'remove_fourn')
} }
} }
if ($_POST["action"] == 'update_price' &&
$_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer)
{
$product = new Product($db);
$result = $product->fetch($_GET["id"]);
$product->price = ereg_replace(" ","",$_POST["price"]);
if ( $product->update_price($product->id, $user) > 0 )
{
$_GET["action"] = '';
$mesg = 'Fiche mise à jour';
}
else
{
$_GET["action"] = 'edit_price';
$mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error;
}
}
if ($_POST["cancel"] == $langs->trans("Cancel")) if ($_POST["cancel"] == $langs->trans("Cancel"))
{ {
$action = ''; $action = '';
@ -252,8 +228,7 @@ llxHeader("","",$langs->trans("CardProduct0"));
/* /*
* Création du produit * Action création du produit
*
*/ */
if ($_GET["action"] == 'create' && $user->rights->produit->creer) if ($_GET["action"] == 'create' && $user->rights->produit->creer)
{ {
@ -322,8 +297,8 @@ if ($_GET["action"] == 'create' && $user->rights->produit->creer)
print '</table>'; print '</table>';
print '</form>'; print '</form>';
} }
else
{
/* /*
* Fiche produit * Fiche produit
*/ */
@ -356,6 +331,10 @@ else
$head[$h][1] = $langs->trans("Price"); $head[$h][1] = $langs->trans("Price");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
if($product->type == 0) if($product->type == 0)
{ {
if ($conf->stock->enabled) if ($conf->stock->enabled)
@ -373,10 +352,6 @@ else
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('Statistics'); $head[$h][1] = $langs->trans('Statistics');
$h++; $h++;
@ -388,30 +363,16 @@ else
print($mesg); print($mesg);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print "<tr>"; print "<tr>";
print '<td width="20%">'.$langs->trans("Ref").'</td><td width="40%">'.$product->ref.'</td>'; print '<td width="10%">'.$langs->trans("Ref").'</td><td colspan="2" width="40%">'.$product->ref.'</td>';
print '<td width="40%">'; print '</tr>';
if ($product->envente) print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td>';
{ print '</tr>';
print $langs->trans("OnSell");
}
else
{
print $langs->trans("NotOnSell");
}
print '</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td></tr>';
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>'.price($product->price).'</td>';
if ($product->type == 0)
{
$nblignefour=4;
}
else
{
$nblignefour=4;
}
print '<td valign="top" rowspan="'.$nblignefour.'">'; // Prix
print $langs->trans("Suppliers").' [<a href="fiche.php?id='.$product->id.'&amp;action=ajout_fourn">'.$langs->trans("Add").'</a>]'; print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>'.price($product->price).'</td>';
if ($product->type == 0) $nbligne=5;
else $nbligne=5;
print '<td valign="top" rowspan="'.$nbligne.'">';
$sql = "SELECT s.nom, s.idp"; $sql = "SELECT s.nom, s.idp";
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf"; $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf";
@ -424,6 +385,7 @@ else
$num_fournisseur = $db->num_rows($result); $num_fournisseur = $db->num_rows($result);
$i = 0; $i = 0;
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Suppliers").'</td></tr>';
$var=True; $var=True;
while ($i < $num_fournisseur) while ($i < $num_fournisseur)
{ {
@ -439,7 +401,12 @@ else
print '</table>'; print '</table>';
$db->free($result); $db->free($result);
} }
print '</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>';
if ($product->envente) print $langs->trans("OnSell");
else print $langs->trans("NotOnSell");
print '</td></tr>'; print '</td></tr>';
$langs->load("bills"); $langs->load("bills");
@ -486,29 +453,8 @@ else
print "</div>\n"; print "</div>\n";
} }
/*
* Edition du prix
*
*/
if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
{
print '<div class="titre">'.$langs->trans("NewPrice").'</div>';
print '<form action="fiche.php?id='.$product->id.'" method="post">';
print '<input type="hidden" name="action" value="update_price">';
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans('SellingPrice').'</td><td><input name="price" size="10" value="'.price($product->price).'"></td></tr>';
print '<tr><td colspan="3" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
/* /*
* Ajouter un fournisseur * Ajouter un fournisseur
*
*/ */
if ($_GET["action"] == 'ajout_fourn' && $user->rights->produit->creer) if ($_GET["action"] == 'ajout_fourn' && $user->rights->produit->creer)
{ {
@ -519,25 +465,12 @@ else
print '<input type="hidden" name="action" value="add_fourn">'; print '<input type="hidden" name="action" value="add_fourn">';
print '<input type="hidden" name="id" value="'.$product->id.'">'; print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%"><tr>'; print '<table class="border" width="100%"><tr>';
print '<td>'.$langs->trans("Suppliers").'</td><td><select name="id_fourn">'; print '<td>'.$langs->trans("Suppliers").'</td><td>';
$sql = "SELECT s.idp, s.nom, s.ville FROM ".MAIN_DB_PREFIX."societe as s WHERE s.fournisseur=1"; $html=new Form($db);
$sql .= " ORDER BY lower(s.nom)"; $html->select_societes('','id_fourn','fournisseur=1');
$result=$db->query($sql); print '</td><td>'.$langs->trans("Ref").'</td>';
if ($result)
{
$num = $db->num_rows($result);
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($result);
print '<option value="'.$obj->idp.'">'.$obj->nom . ($obj->ville?" ($obj->ville)":"");
$i++;
}
}
print '</select></td><td>'.$langs->trans("Ref").'</td>';
print '<td><input name="ref_fourn" size="25" value=""></td></tr>'; print '<td><input name="ref_fourn" size="25" value=""></td></tr>';
print '<tr><td colspan="4" align="center">'; print '<tr><td colspan="4" align="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;'; print '<input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;';
@ -545,37 +478,10 @@ else
print '</table>'; print '</table>';
print '</form>'; print '</form>';
} }
/*
* Ajouter une photo
*
*/
if ($_GET["action"] == 'ajout_photo' && $conf->upload && $user->rights->produit->creer && $product->isproduct)
{
print_titre($langs->trans("AddPhoto"));
print '<form name="userfile" action="fiche.php" enctype="multipart/form-data" METHOD="POST">';
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%"><tr>';
print '<td>'.$langs->trans("File").' ('.$langs->trans("Size").' <= '.$conf->maxfilesize.')</td>';
print '<td><input type="file" class="flat" name="photofile"></td></tr>';
print '<tr><td colspan="4" align="center">';
print '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"> &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
} }
/* /*
*
* Fiche en mode edition * Fiche en mode edition
*
*/ */
if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer) if (($_GET["action"] == 'edit' || $_GET["action"] == 're-edit') && $user->rights->produit->creer)
{ {
@ -591,7 +497,7 @@ else
print '<input type="hidden" name="id" value="'.$product->id.'">'; print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print "<tr>".'<td width="20%">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" size="20" value="'.$product->ref.'"></td></tr>'; print "<tr>".'<td width="20%">'.$langs->trans("Ref").'</td><td colspan="2"><input name="ref" size="20" value="'.$product->ref.'"></td></tr>';
print '<td>'.$langs->trans("Label").'</td><td colspan="2"><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>'; print '<td>'.$langs->trans("Label").'</td><td><input name="libelle" size="40" value="'.$product->libelle.'"></td></tr>';
$langs->load("bills"); $langs->load("bills");
print '<tr><td>'.$langs->trans("VATRate").'</td><td colspan="2">'; print '<tr><td>'.$langs->trans("VATRate").'</td><td colspan="2">';
@ -651,7 +557,6 @@ else
{ {
print $langs->trans("ErrorUnknown"); print $langs->trans("ErrorUnknown");
} }
}
/* ************************************************************************** */ /* ************************************************************************** */
@ -670,31 +575,34 @@ if ($_GET["action"] == '')
print $langs->trans("Order").'</a>'; print $langs->trans("Order").'</a>';
} }
if ( $user->rights->produit->creer && $product->isproduct && $conf->upload)
{
print '<a class="tabAction" href="fiche.php?action=ajout_photo&amp;id='.$product->id.'">';
print $langs->trans("AddPhoto").'</a>';
}
if ( $user->rights->produit->creer)
{
print '<a class="tabAction" href="fiche.php?action=edit_price&amp;id='.$product->id.'">';
print $langs->trans("UpdatePrice").'</a>';
}
if ( $user->rights->produit->creer) if ( $user->rights->produit->creer)
{ {
print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Edit").'</a>'; print '<a class="tabAction" href="fiche.php?action=edit&amp;id='.$product->id.'">'.$langs->trans("Edit").'</a>';
} }
if ($user->rights->produit->modifier || $user->rights->produit->creer)
{
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/price.php?action=edit_price&amp;id='.$product->id.'">'.$langs->trans("UpdatePrice").'</a>';
} }
print "\n</div>\n"; if ( $user->rights->produit->creer && $conf->upload)
{
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/photos.php?action=ajout_photo&amp;id='.$product->id.'">';
print $langs->trans("AddPhoto").'</a>';
}
if ($user->rights->produit->modifier || $user->rights->produit->creer)
{
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$product->id.'&amp;action=ajout_fourn">';
print $langs->trans("AddSupplier").'</a>';
}
}
print "\n</div><br>\n";
/* /*
* Photo * Photo
*
*/ */
if ($_GET["id"] && $_GET["action"]=='') if ($_GET["id"] && $_GET["action"]=='')
{ {
@ -914,5 +822,5 @@ if ($_GET["id"] && $_GET["action"] == '' && $product->envente)
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -33,27 +33,56 @@ require("../propal.class.php");
require("../facture.class.php"); require("../facture.class.php");
$langs->load("products"); $langs->load("products");
$langs->load("suppliers");
$user->getrights('produit'); $user->getrights('produit');
$user->getrights('propale'); $user->getrights('propale');
$user->getrights('facture'); $user->getrights('facture');
$mesg = ''; $mesg = '';
if (!$user->rights->produit->lire) if (! $user->rights->produit->lire) accessforbidden();
{
accessforbidden();
}
$types[0] = $langs->trans("Product"); $types[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service"); $types[1] = $langs->trans("Service");
/*
* Actions
*/
if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel")) if ($_POST["action"] == 'updateprice' && $_POST["cancel"] <> $langs->trans("Cancel"))
{ {
$product = new Product($db); $product = new Product($db);
if( $product->fetch($_GET["id"]) ) if( $product->fetch($_GET["id"]) )
{ {
$product->update_buyprice($_POST["id_fourn"], $_POST["qty"], $_POST["price"], $user); $db->begin();
$error=0;
if ($_POST["ref_fourn"]) {
$ret=$product->add_fournisseur($user, $_POST["id_fourn"], $_POST["ref_fourn"]);
if ($ret < 0) {
$error++;
$mesg='<div class="error">'.$product->error.'</div>';
}
}
if ($_POST["qty"]) {
$ret=$product->update_buyprice($_POST["id_fourn"], $_POST["qty"], $_POST["price"], $user);
if ($ret < 0) {
$error++;
$mesg='<div class="error">'.$product->error.'</div>';
}
}
if (! $error)
{
$db->commit();
}
else {
$db->rollback();
}
} }
} }
@ -61,6 +90,7 @@ if ($_POST["cancel"] == $langs->trans("Cancel"))
{ {
$action = ''; $action = '';
Header("Location: fournisseurs.php?id=".$_GET["id"]); Header("Location: fournisseurs.php?id=".$_GET["id"]);
exit;
} }
@ -87,13 +117,16 @@ if ($_GET["id"])
/* /*
* En mode visu * En mode visu
*/ */
// Zone recherche // Zone recherche
/* Deja présent dans menu gauche
print '<div class="formsearch">'; print '<div class="formsearch">';
print '<form action="liste.php" method="post">'; print '<form action="liste.php" method="post">';
print '<input type="hidden" name="type" value="'.$product->type.'">'; print '<input type="hidden" name="type" value="'.$product->type.'">';
print $langs->trans("Ref").': <input class="flat" type="text" size="10" name="sref">&nbsp;<input class="flat" type="submit" value="'.$langs->trans("Go").'"> &nbsp;'; print $langs->trans("Ref").': <input class="flat" type="text" size="10" name="sref">&nbsp;<input class="flat" type="submit" value="'.$langs->trans("Go").'"> &nbsp;';
print $langs->trans("Label").': <input class="flat" type="text" size="20" name="snom">&nbsp;<input class="flat" type="submit" value="'.$langs->trans("Go").'">'; print $langs->trans("Label").': <input class="flat" type="text" size="20" name="snom">&nbsp;<input class="flat" type="submit" value="'.$langs->trans("Go").'">';
print '</form></div>'; print '</form></div>';
*/
$h=0; $h=0;
@ -105,6 +138,10 @@ if ($_GET["id"])
$head[$h][1] = $langs->trans("Price"); $head[$h][1] = $langs->trans("Price");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
if($product->type == 0) if($product->type == 0)
{ {
if ($conf->stock->enabled) if ($conf->stock->enabled)
@ -123,10 +160,6 @@ if ($_GET["id"])
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('Statistics'); $head[$h][1] = $langs->trans('Statistics');
$h++; $h++;
@ -135,107 +168,55 @@ if ($_GET["id"])
dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref);
print($mesg); print($mesg);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td>'.$product->ref.'</td>'; print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="2">'.$product->ref.'</td></tr>';
print '<td align="right">'.$langs->trans("Status").' : ';
if ($product->envente)
{
print $langs->trans("OnSell");
}
else
{
print $langs->trans("NotOnSell");
}
print '</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td></tr>'; print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td></tr>';
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">'.price($product->price).'</td></tr>'; print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">'.price($product->price).'</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
if ($product->envente) print $langs->trans("OnSell");
else print $langs->trans("NotOnSell");
print '</td></tr>';
print '</table><br />'; print '</table><br />';
print '<table class="border" width="100%">';
if ($product->type == 0) print "</div>\n";
{
$nblignefour=4;
}
else
{
$nblignefour=4;
}
print '<tr class="liste_titre"><td valign="top">';
print $langs->trans("Suppliers").'</td>';
print '<td>'.$langs->trans("Ref").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td>';
print '<td align="right">'.$langs->trans("BuiingPrice").'</td>';
print '</tr>';
$sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity"; // Formulaire ajout prix
$sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; if ($_GET["action"] == 'add_price' && $user->rights->produit->creer)
$sql .= " , ".MAIN_DB_PREFIX."product_fournisseur as pf";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql .=" ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product";
$sql .=" WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id;
$sql .= " ORDER BY lower(s.nom), pfp.quantity";
if ( $db->query($sql) )
{
$num = $db->num_rows();
$i = 0;
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object();
$var=!$var;
print "<tr $bc[$var]>";
print '<td><a href="../fourn/fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
print '<td align="left">'.$objp->ref_fourn.'</td>';
print '<td align="center">';
print $objp->quantity;
print '</td>';
print '<td align="right">';
print price($objp->price);
print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=add_price&amp;id_fourn='.$objp->idp.'&amp;qty='.$objp->quantity.'">';
print img_edit(). "</a></td>";
print '</tr>';
if ($_GET["action"] == 'add_price'
&& $user->rights->produit->creer
&& $_GET["qty"] == $objp->quantity
&& $_GET["id_fourn"] == $objp->idp)
{ {
$langs->load("suppliers"); $langs->load("suppliers");
print '<div class="titre">'.$langs->trans("ChangeSupplierPrice").'</div>';
print '<table class="border" width="100%">';
print '<form action="fournisseurs.php?id='.$product->id.'" method="post">'; print '<form action="fournisseurs.php?id='.$product->id.'" method="post">';
print '<input type="hidden" name="action" value="updateprice">'; print '<input type="hidden" name="action" value="updateprice">';
print '<input type="hidden" name="id_fourn" value="'.$objp->idp.'">';
print '<tr><td colspan="2" align="right">Modifier le prix</td>'; if ($_GET["id_fourn"]) {
print '<input type="hidden" name="id_fourn" value="'.$_GET["id_fourn"].'">';
} else {
print '<tr><td>'.$langs->trans("Supplier").'</td><td colspan="3">';
$html=new Form($db);
$html->select_societes('','id_fourn','fournisseur=1');
print '</td></tr>';
print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="3">';
print '<input name="ref_fourn" size="25" value="">';
print '</td></tr>';
}
print '<td align="center"><input name="qty" size="5" value="'.$objp->quantity.'"></td>'; print '<tr><td>'.$langs->trans("Qty").'</td>';
print '<td><input name="price" size="8" value="'.price($objp->price).'"></td></tr>'; print '<td><input name="qty" size="5" value="'.$_GET["qty"].'"></td>';
print '<tr><td colspan="2">&nbsp;</td><td colspan="2" align="center"><input type="submit" value="'.$langs->trans("Save").'">&nbsp;'; print '<td>'.$langs->trans("Price").'</td><td><input name="price" size="8" value="'.price($objp->price).'"></td></tr>';
print '<tr><td colspan="4" align="center"><input type="submit" value="'.$langs->trans("Save").'">&nbsp;';
print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>'; print '<input type="submit" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</form>'; print '</form>';
print '</table>';
} }
$i++;
}
$db->free();
}
print '</td></tr>';
print "</table><br>\n";
print "</div>\n";
}
}
}
else
{
print $langs->trans("ErrorUnknown");
}
/* ************************************************************************** */ /* ************************************************************************** */
/* */ /* */
@ -245,9 +226,99 @@ else
print "\n<div class=\"tabsAction\">\n"; print "\n<div class=\"tabsAction\">\n";
if ($_GET["action"] != 'add_price') {
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$product->id.'&amp;action=add_price">';
print $langs->trans("AddSupplierPrice").'</a>';
}
print "\n</div>\n"; print "\n</div>\n";
print '<br>';
// Titre liste des fournisseurs
print '<table class="noborder" width="100%">';
if ($product->type == 0) $nblignefour=4;
else $nblignefour=4;
print '<tr class="liste_titre"><td valign="top">';
print $langs->trans("Suppliers").'</td>';
print '<td>'.$langs->trans("Ref").'</td>';
print '<td align="center">'.$langs->trans("Qty").'</td>';
print '<td align="right">'.$langs->trans("BuyingPrice").'</td>';
print '<td align="right">'.$langs->trans("UnitPrice").'</td>';
print '<td>&nbsp;</td>';
print '</tr>';
// Liste des fournisseurs
$sql = "SELECT s.nom, s.idp, pf.ref_fourn, pfp.price, pfp.quantity";
$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."product_fournisseur as pf";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
$sql.= " ON pf.fk_soc = pfp.fk_soc AND pf.fk_product = pfp.fk_product";
$sql.= " WHERE pf.fk_soc = s.idp AND pf.fk_product = ".$product->id;
$sql.= " ORDER BY lower(s.nom), pfp.quantity";
$resql=$db->query($sql);
if ($resql)
{
$num = $db->num_rows($resql);
$i = 0;
$var=True;
while ($i < $num)
{
$objp = $db->fetch_object($resql);
$var=!$var;
print "<tr $bc[$var]>";
print '<td><a href="../fourn/fiche.php?socid='.$objp->idp.'">'.$objp->nom.'</a></td>';
// Fournisseur
print '<td align="left">'.$objp->ref_fourn.'</td>';
// Quantité
print '<td align="center">';
print $objp->quantity;
print '</td>';
// Prix quantité
print '<td align="right">';
print $objp->price?price($objp->price):"";
print '</td>';
// Prix unitaire
print '<td align="right">';
print $objp->quantity?price($objp->price / $objp->quantity):"&nbsp;";
print '</td>';
print '<td>';
if ($user->rights->produit->modifier) {
print '<a href="fournisseurs.php?id='.$product->id.'&amp;action=add_price&amp;id_fourn='.$objp->idp.'&amp;qty='.$objp->quantity.'">'.img_edit()."</a>";
}
print '</td>';
print '</tr>';
$i++;
}
$db->free($resql);
}
else {
dolibarr_print_error($db);
}
print '</table>';
}
}
}
else
{
print $langs->trans("ErrorUnknown");
}
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -18,7 +18,6 @@
* *
* $Id$ * $Id$
* $Source$ * $Source$
*
*/ */
/** /**
@ -41,12 +40,12 @@ $mesg = '';
if (!$user->rights->produit->lire) accessforbidden(); if (!$user->rights->produit->lire) accessforbidden();
$types[0] = $langs->trans("Product"); $types[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service"); $types[1] = $langs->trans("Service");
/* /*
* * Actions
*/ */
if ( $_POST["sendit"] && defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1) if ( $_POST["sendit"] && defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1)
@ -63,24 +62,22 @@ if ( $_POST["sendit"] && defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1)
$product->add_photo($conf->produit->dir_output, $_FILES['photofile']); $product->add_photo($conf->produit->dir_output, $_FILES['photofile']);
} }
} }
/* /*
* *
*/ */
llxHeader("","",$langs->trans("CardProduct0")); llxHeader("","",$langs->trans("CardProduct0"));
/*
* Fiche produit
*/
if ($_GET["id"]) if ($_GET["id"])
{ {
$product = new Product($db); $product = new Product($db);
$result = $product->fetch($_GET["id"]); $result = $product->fetch($_GET["id"]);
if ($result) if ($result)
{ {
/* /*
* En mode visu * En mode visu
*/ */
@ -95,6 +92,11 @@ if ($_GET["id"])
$head[$h][1] = $langs->trans("Price"); $head[$h][1] = $langs->trans("Price");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$hselected = $h;
$h++;
if ($conf->stock->enabled) if ($conf->stock->enabled)
{ {
$head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id; $head[$h][0] = DOL_URL_ROOT."/product/stock/product.php?id=".$product->id;
@ -109,11 +111,6 @@ if ($_GET["id"])
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$hselected = $h;
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans('Statistics'); $head[$h][1] = $langs->trans('Statistics');
$h++; $h++;
@ -121,28 +118,76 @@ if ($_GET["id"])
dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref);
print($mesg); print($mesg);
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print "<tr>"; print '<tr>';
print '<td>'.$langs->trans("Ref").'</td><td>'.$product->ref.'</td>'; print '<td width="10%">'.$langs->trans("Ref").'</td><td colspan="2" width="40%">'.$product->ref.'</td>';
print '<td colspan="2">';
if ($product->envente)
{
print $langs->trans("OnSell");
}
else
{
print $langs->trans("NotOnSell");
}
print '</td></tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="3">'.$product->libelle.'</td>';
print '</tr>'; print '</tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td>';
print '</tr>';
// Prix
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">'.price($product->price).'</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
if ($product->envente) print $langs->trans("OnSell");
else print $langs->trans("NotOnSell");
print '</td></tr>';
print "</table><br>\n"; print "</table><br>\n";
print "</div>\n";
/* ************************************************************************** */
/* */
/* Barre d'action */
/* */
/* ************************************************************************** */
print "\n<div class=\"tabsAction\">\n";
if ($_GET["action"] != 'ajout_photo' && $user->rights->produit->creer && $conf->upload)
{
print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/photos.php?action=ajout_photo&amp;id='.$product->id.'">';
print $langs->trans("AddPhoto").'</a>';
}
print "\n</div>\n";
/*
* Ajouter une photo
*/
if ($_GET["action"] == 'ajout_photo' && $conf->upload && $user->rights->produit->creer)
{
print_titre($langs->trans("AddPhoto"));
print '<form name="userfile" action="'.DOL_URL_ROOT.'/product/photos.php?id='.$product->id.'" enctype="multipart/form-data" METHOD="POST">';
print '<input type="hidden" name="max_file_size" value="'.$conf->maxfilesize.'">';
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%"><tr>';
print '<td>'.$langs->trans("File").' ('.$langs->trans("Size").' <= '.$conf->maxfilesize.')</td>';
print '<td><input type="file" class="flat" name="photofile"></td></tr>';
print '<tr><td colspan="2" align="center">';
print '<input type="submit" class="button" name="sendit" value="'.$langs->trans("Upload").'"> &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
// Affiche photos // Affiche photos
if ($_GET["action"] != 'ajout_photo') {
print '<div class="photo">';
$nbphoto=$product->show_photos($conf->produit->dir_output,1); $nbphoto=$product->show_photos($conf->produit->dir_output,1);
if ($nbphoto < 1) print $langs->trans("NoPhotoYet")."<br><br>"; if ($nbphoto < 1) print $langs->trans("NoPhotoYet")."<br><br>";
print "</div>\n"; print '</div>';
}
} }
} }
else else
@ -154,5 +199,5 @@ else
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -42,11 +42,36 @@ $types[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service"); $types[1] = $langs->trans("Service");
/*
* Actions
*/
if ($_POST["action"] == 'update_price' &&
$_POST["cancel"] <> $langs->trans("Cancel") && $user->rights->produit->creer)
{
$product = new Product($db);
$result = $product->fetch($_GET["id"]);
$product->price = ereg_replace(" ","",$_POST["price"]);
if ( $product->update_price($product->id, $user) > 0 )
{
$_GET["action"] = '';
$mesg = 'Fiche mise à jour';
}
else
{
$_GET["action"] = 'edit_price';
$mesg = 'Fiche non mise à jour !' . "<br>" . $product->mesg_error;
}
}
/* /*
* * Affiche historique prix
*
*/ */
llxHeader("","",$langs->trans("Price")); llxHeader("","",$langs->trans("Price"));
@ -66,6 +91,10 @@ $head[$h][1] = $langs->trans("Price");
$hselected=$h; $hselected=$h;
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
if($product->type == 0) if($product->type == 0)
{ {
if ($conf->stock->enabled) if ($conf->stock->enabled)
@ -82,10 +111,6 @@ if ($conf->fournisseur->enabled) {
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans("Statistics"); $head[$h][1] = $langs->trans("Statistics");
$h++; $h++;
@ -93,64 +118,23 @@ $h++;
dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref);
print '<table class="border" width="100%">';
$sql = "SELECT p.rowid, p.price, ".$db->pdate("p.date_price")." as dp, u.login"; print '<tr>';
$sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, llx_user as u"; print '<td width="10%">'.$langs->trans("Ref").'</td><td colspan="2" width="40%">'.$product->ref.'</td>';
$sql .= " WHERE fk_product = ".$product->id; print '</tr>';
$sql .= " AND p.fk_user_author = u.rowid "; print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td>';
$sql .= " ORDER BY p.date_price DESC ";
$sql .= $db->plimit();
$result = $db->query($sql) ;
if ($result)
{
$num = $db->num_rows($result);
if (! $num)
{
$db->free($result) ;
// Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre à niveau pb vieilles versions
$product->update_price($product->id, $user);
$result = $db->query($sql) ;
$num = $db->num_rows($result);
}
if ($num > 0)
{
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
print '<td>'.$langs->trans("Price").'</td>';
print '<td>'.$langs->trans("ChangedBy").'</td>';
print '</tr>'; print '</tr>';
$var=True; // Prix
$i = 0; print '<tr><td>'.$langs->trans("SellingPrice").'</td><td colspan="2">'.price($product->price).'</td></tr>';
while ($i < $num)
{
$objp = $db->fetch_object($result);
$var=!$var;
print "<tr $bc[$var]>";
print "<td>".dolibarr_print_date($objp->dp,"%d %B %Y %H:%M:%S")."</td>";
print "<td>".price($objp->price)."</td>";
print "<td>".$objp->login."</td>";
print "</tr>\n"; // Statut
$i++; print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
} if ($product->envente) print $langs->trans("OnSell");
$db->free($result); else print $langs->trans("NotOnSell");
print "</table>"; print '</td></tr>';
print "<br>";
} print "</table><br>\n";
}
else
{
dolibarr_print_error($db);
}
print "</div>\n"; print "</div>\n";
@ -168,14 +152,94 @@ if ($_GET["action"] == '')
{ {
if ($user->rights->produit->modifier || $user->rights->produit->creer) if ($user->rights->produit->modifier || $user->rights->produit->creer)
{ {
print '<a class="tabAction" href="fiche.php?action=edit_price&amp;id='.$product->id.'">'.$langs->trans("UpdatePrice").'</a>'; print '<a class="tabAction" href="'.DOL_URL_ROOT.'/product/price.php?action=edit_price&amp;id='.$product->id.'">'.$langs->trans("UpdatePrice").'</a>';
} }
} }
print "\n</div>\n"; print "\n</div>\n";
/*
* Edition du prix
*/
if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
{
print '<div class="titre">'.$langs->trans("NewPrice").'</div>';
print '<form action="price.php?id='.$product->id.'" method="post">';
print '<input type="hidden" name="action" value="update_price">';
print '<input type="hidden" name="id" value="'.$product->id.'">';
print '<table class="border" width="100%">';
print '<tr><td width="20%">'.$langs->trans('SellingPrice').'</td><td><input name="price" size="10" value="'.price($product->price).'"></td></tr>';
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>';
print '</table>';
print '</form>';
}
// Liste des evolutions du prix
$sql = "SELECT p.rowid, p.price, ".$db->pdate("p.date_price")." as dp, u.login";
$sql .= " FROM ".MAIN_DB_PREFIX."product_price as p, llx_user as u";
$sql .= " WHERE fk_product = ".$product->id;
$sql .= " AND p.fk_user_author = u.rowid ";
$sql .= " ORDER BY p.date_price DESC ";
$sql .= $db->plimit();
$result = $db->query($sql) ;
if ($result)
{
$num = $db->num_rows($result);
if (! $num)
{
$db->free($result) ;
// Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre à niveau (pb vieilles versions)
$product->update_price($product->id, $user);
$result = $db->query($sql) ;
$num = $db->num_rows($result);
}
if ($num > 0)
{
print '<br>';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
print '<td>'.$langs->trans("Price").'</td>';
print '<td>'.$langs->trans("ChangedBy").'</td>';
print '</tr>';
$var=True;
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$var=!$var;
print "<tr $bc[$var]>";
print "<td>".dolibarr_print_date($objp->dp,"%d %b %Y %H:%M:%S")."</td>";
print "<td>".price($objp->price)."</td>";
print "<td>".$objp->login."</td>";
print "</tr>\n";
$i++;
}
$db->free($result);
print "</table>";
print "<br>";
}
}
else
{
dolibarr_print_error($db);
}
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (c) 2004 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (c) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -21,7 +21,7 @@
* *
*/ */
/*! /**
\file htdocs/product/stats/fiche.php \file htdocs/product/stats/fiche.php
\ingroup product \ingroup product
\brief Page des stats produits \brief Page des stats produits
@ -48,12 +48,12 @@ else
} }
llxHeader('','Statistiques produits'); llxHeader('',$langs->trans("Statistics"));
$mesg = ''; $mesg = '';
/* /*
*
* *
*/ */
@ -119,6 +119,10 @@ if ($_GET["id"])
$head[$h][1] = $langs->trans("Price"); $head[$h][1] = $langs->trans("Price");
$h++; $h++;
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
if($product->type == 0) if($product->type == 0)
{ {
if ($conf->stock->enabled) if ($conf->stock->enabled)
@ -136,10 +140,6 @@ if ($_GET["id"])
$h++; $h++;
} }
$head[$h][0] = DOL_URL_ROOT."/product/photos.php?id=".$product->id;
$head[$h][1] = $langs->trans("Photos");
$h++;
$head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id; $head[$h][0] = DOL_URL_ROOT."/product/stats/fiche.php?id=".$product->id;
$head[$h][1] = $langs->trans("Statistics"); $head[$h][1] = $langs->trans("Statistics");
$hselected=$h; $hselected=$h;
@ -149,11 +149,13 @@ if ($_GET["id"])
dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref); dolibarr_fiche_head($head, $hselected, $langs->trans("CardProduct".$product->type).' : '.$product->ref);
print '<table class="border" width="100%"><tr>'; print '<table class="border" width="100%">';
print '<td width="20%">'.$langs->trans("Ref").'</td>'; print '<tr>';
print '<td width="40%">'.$product->ref.'</td>'; print '<td width="10%">'.$langs->trans("Ref").'</td><td colspan="2" width="40%">'.$product->ref.'</td>';
print '<td>'.$langs->trans("Statistics").'</td></tr>'; print '</tr>';
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>'; print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td></tr>';
print '<tr><td>'.$langs->trans("SellingPrice").'</td><td>'.price($product->price).'</td>';
print '<td valign="top" rowspan="2">'; print '<td valign="top" rowspan="2">';
// Propals // Propals
if ($conf->propal->enabled) if ($conf->propal->enabled)
@ -175,7 +177,13 @@ if ($_GET["id"])
print '<a href="facture.php?id='.$product->id.'">'.$langs->trans("Bills").'</a> : '.$product->count_facture($socid); print '<a href="facture.php?id='.$product->id.'">'.$langs->trans("Bills").'</a> : '.$product->count_facture($socid);
} }
print '</td></tr>'; print '</td></tr>';
print '<tr><td>'.$langs->trans("CurrentPrice").'</td><td>'.price($product->price).'</td></tr>';
// Statut
print '<tr><td>'.$langs->trans("Status").'</td><td>';
if ($product->envente) print $langs->trans("OnSell");
else print $langs->trans("NotOnSell");
print '</td></tr>';
print "</table>"; print "</table>";
print '<br><table class="border" width="100%">'; print '<br><table class="border" width="100%">';
@ -249,7 +257,9 @@ else
dolibarr_print_error(); dolibarr_print_error();
} }
$db->close(); $db->close();
llxFooter("<em>Derni&egrave;re modification $Date$ r&eacute;vision $Revision$</em>"); llxFooter('$Date$ - $Revision$');
?> ?>