Can delete a price line log

This commit is contained in:
Laurent Destailleur 2008-10-25 12:14:16 +00:00
parent def9892548
commit 51160ac2e0
2 changed files with 210 additions and 154 deletions

View File

@ -717,15 +717,41 @@ class Product extends CommonObject
return -1; return -1;
} }
else else
return 1; {
return 1;
}
} }
} }
/** /**
* \brief Lit le prix pratiqu<EFBFBD> par un fournisseur * \brief Delete a price line
* \param user Object user
* \param rowid Line id to delete
* \return int <0 if KO, >0 if OK
*/
function log_price_delete($user,$rowid)
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."product_price";
$sql.= " WHERE rowid=".$rowid;
dolibarr_syslog("Product::log_price_delete sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
return 1;
}
else
{
$this->error=$this->db->lasterror();
return -1;
}
}
/**
* \brief Lit le prix pratique par un fournisseur
* On renseigne le couple prodfournprice/qty ou le triplet qty/product_id/fourn_ref) * On renseigne le couple prodfournprice/qty ou le triplet qty/product_id/fourn_ref)
* \param prodfournprice Id du tarif = rowid table product_fournisseur_price * \param prodfournprice Id du tarif = rowid table product_fournisseur_price
* \param qty Quantit<EFBFBD> du produit * \param qty Quantit<EFBFBD> du produit

View File

@ -21,11 +21,11 @@
*/ */
/** /**
\file htdocs/product/price.php \file htdocs/product/price.php
\ingroup product \ingroup product
\brief Page de la fiche produit \brief Page de la fiche produit
\version $Id$ \version $Id$
*/ */
require("./pre.inc.php"); require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
@ -43,8 +43,7 @@ accessforbidden();
* Actions * Actions
*/ */
if ($_POST["action"] == 'update_price' && if ($_POST["action"] == 'update_price' && ! $_POST["cancel"] && $user->rights->produit->creer)
! $_POST["cancel"] && $user->rights->produit->creer)
{ {
$product = new Product($db); $product = new Product($db);
@ -61,7 +60,7 @@ if ($_POST["action"] == 'update_price' &&
{ {
if($_POST["price_".$i]) if($_POST["price_".$i])
{ {
// le prix 1 est considéré comme le prix de base du produit // le prix 1 est considere comme le prix de base du produit
if ($i == 1) if ($i == 1)
{ {
$newprice=price2num($_POST["price_".$i],'MU'); $newprice=price2num($_POST["price_".$i],'MU');
@ -70,9 +69,9 @@ if ($_POST["action"] == 'update_price' &&
} }
else else
{ {
$product->multiprices["$i"] = price2num($_POST["price_".$i],'MU'); $product->multiprices["$i"] = price2num($_POST["price_".$i],'MU');
$product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i]; $product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i];
$product->multiprices_vat_rate["$i"] = $_POST["tva_tx_".$i]; $product->multiprices_vat_rate["$i"] = $_POST["tva_tx_".$i];
} }
} }
else else
@ -106,10 +105,18 @@ if ($_POST["action"] == 'update_price' &&
} }
} }
if ($_GET["action"] == 'delete' && $user->rights->produit->creer)
{
$productstatic = new Product($db);
$result=$productstatic->log_price_delete($user,$_GET["lineid"]);
if ($result < 0) $mesg='<div class="error">'.$productstatic->error.'</div>';
}
/* /*
* Affiche historique prix * View
*/ */
$html = new Form($db); $html = new Form($db);
$product = new Product($db); $product = new Product($db);
@ -118,6 +125,8 @@ if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
llxHeader("","",$langs->trans("CardProduct".$product->type)); llxHeader("","",$langs->trans("CardProduct".$product->type));
if ($mesg) print $mesg;
$head=product_prepare_head($product, $user); $head=product_prepare_head($product, $user);
$titre=$langs->trans("CardProduct".$product->type); $titre=$langs->trans("CardProduct".$product->type);
dolibarr_fiche_head($head, 'price', $titre); dolibarr_fiche_head($head, 'price', $titre);
@ -140,29 +149,29 @@ print '</tr>';
// MultiPrix // MultiPrix
if($conf->global->PRODUIT_MULTIPRICES) if($conf->global->PRODUIT_MULTIPRICES)
{ {
for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{ {
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>'; print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
if ($product->multiprices_base_type["$i"] == 'TTC') if ($product->multiprices_base_type["$i"] == 'TTC')
{ {
print '<td>'.price($product->multiprices_ttc["$i"]); print '<td>'.price($product->multiprices_ttc["$i"]);
} }
else else
{ {
print '<td>'.price($product->multiprices["$i"]); print '<td>'.price($product->multiprices["$i"]);
} }
if ($product->multiprices_base_type["$i"]) if ($product->multiprices_base_type["$i"])
{ {
print ' '.$langs->trans($product->multiprices_base_type["$i"]); print ' '.$langs->trans($product->multiprices_base_type["$i"]);
} }
else else
{ {
print ' '.$langs->trans($product->price_base_type); print ' '.$langs->trans($product->price_base_type);
} }
print '</td></tr>'; print '</td></tr>';
} }
} }
// Prix // Prix
else else
@ -210,14 +219,14 @@ print "</div>\n";
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
if (! $_GET["action"]) if (empty($_GET["action"]) || $_GET["action"]=='delete')
{ {
print "\n<div class=\"tabsAction\">\n"; print "\n<div class=\"tabsAction\">\n";
if ($user->rights->produit->modifier || $user->rights->produit->creer) if ($user->rights->produit->modifier || $user->rights->produit->creer)
{ {
print '<a class="butAction" href="'.DOL_URL_ROOT.'/product/price.php?action=edit_price&amp;id='.$product->id.'">'.$langs->trans("UpdatePrice").'</a>'; print '<a class="butAction" 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";
} }
@ -238,12 +247,20 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
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%">';
// Price base
print '<tr><td width="15%">';
print $langs->trans('PriceBase');
print '</td>';
print '<td>';
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td>';
print '</tr>';
// Price // Price
print '<tr><td width="15%">'; print '<tr><td width="15%">';
$text=$langs->trans('SellingPrice'); $text=$langs->trans('SellingPrice');
print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1); print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
print '</td>'; print '</td>';
if ($product->price_base_type == 'TTC') if ($product->price_base_type == 'TTC')
{ {
print '<td><input name="price" size="10" value="'.price($product->price_ttc).'">'; print '<td><input name="price" size="10" value="'.price($product->price_ttc).'">';
@ -253,9 +270,9 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
print '<td><input name="price" size="10" value="'.price($product->price).'">'; print '<td><input name="price" size="10" value="'.price($product->price).'">';
} }
print '<tr><td>' ; print '<tr><td>' ;
$text=$langs->trans('MinPrice') ; $text=$langs->trans('MinPrice') ;
print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1); print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
if ($product->price_base_type == 'TTC') if ($product->price_base_type == 'TTC')
{ {
print '<td><input name="price_min" size="10" value="'.price($product->price_min_ttc).'">'; print '<td><input name="price_min" size="10" value="'.price($product->price_min_ttc).'">';
@ -264,9 +281,6 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
{ {
print '<td><input name="price_min" size="10" value="'.price($product->price_min).'">'; print '<td><input name="price_min" size="10" value="'.price($product->price_min).'">';
} }
print '</td>';
print $html->select_PriceBaseType($product->price_base_type, "price_base_type");
print '</td></tr>'; print '</td></tr>';
// VAT // VAT
@ -280,123 +294,124 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
print '</form>'; print '</form>';
} }
else else
{ {
for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
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="15%">';
$text=$langs->trans('SellingPrice').' '.$i;
print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
print '</td>';
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices_ttc["$i"]).'">';
}
else
{
print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices["$i"]).'">';
}
print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i);
print '</td>';
print '<tr><td>' ;
$text=$langs->trans('MinPrice') ;
print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
if ($product->price_base_type == 'TTC')
{ {
print '<td><input name="price_min" size="10" value="'.price($product->price_min_ttc).'">'; print '<form action="price.php?id='.$product->id.'" method="post">';
} print '<input type="hidden" name="action" value="update_price">';
else print '<input type="hidden" name="id" value="'.$product->id.'">';
{ print '<table class="border" width="100%">';
print '<td><input name="price_min" size="10" value="'.price($product->price_min).'">'; print '<tr><td width="15%">';
} $text=$langs->trans('SellingPrice').' '.$i;
print '</td>'; print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
print '</td>';
// VAT if ($product->multiprices_base_type["$i"] == 'TTC')
print '<td width="20%">'.$langs->trans("VATRate").'</td><td>'; {
print $html->select_tva("tva_tx_".$i,$product->multiprices_tva_tx["$i"],$mysoc,''); print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices_ttc["$i"]).'">';
print '</td></tr>'; }
else
{
print '<td><input name="price_'.$i.'" size="10" value="'.price($product->multiprices["$i"]).'">';
}
print '<tr><td colspan="2" align="center"><input type="submit" class="button" value="'.$langs->trans("Save").'">&nbsp;'; print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i);
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'"></td></tr>'; print '</td>';
print '</table>';
print '</form>'; print '<tr><td>' ;
} $text=$langs->trans('MinPrice') ;
} print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
if ($product->price_base_type == 'TTC')
{
print '<td><input name="price_min" size="10" value="'.price($product->price_min_ttc).'">';
}
else
{
print '<td><input name="price_min" size="10" value="'.price($product->price_min).'">';
}
print '</td>';
// VAT
print '<td width="20%">'.$langs->trans("VATRate").'</td><td>';
print $html->select_tva("tva_tx_".$i,$product->multiprices_tva_tx["$i"],$mysoc,'');
print '</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 // Liste des evolutions du prix
if($conf->global->PRODUIT_MULTIPRICES) if($conf->global->PRODUIT_MULTIPRICES)
{ {
$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx,"; $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx,";
$sql.= " p.price_level,"; $sql.= " p.price_level,";
$sql.= " ".$db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; $sql.= " ".$db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login";
$sql.= " FROM ".MAIN_DB_PREFIX."product_price as p, ".MAIN_DB_PREFIX."user as u"; $sql.= " FROM ".MAIN_DB_PREFIX."product_price as p, ".MAIN_DB_PREFIX."user as u";
$sql.= " WHERE fk_product = ".$product->id; $sql.= " WHERE fk_product = ".$product->id;
$sql.= " AND p.fk_user_author = u.rowid "; $sql.= " AND p.fk_user_author = u.rowid ";
$sql.= " ORDER BY p.price_level ASC, p.date_price DESC"; $sql.= " ORDER BY p.price_level ASC, p.date_price DESC";
} }
else else
{ {
$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx,"; $sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx,";
$sql.= " p.price_min, p.price_min_ttc,"; $sql.= " p.price_min, p.price_min_ttc,";
$sql.= " ".$db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login"; $sql.= " ".$db->pdate("p.date_price")." as dp, u.rowid as user_id, u.login";
$sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."product_price as p "; $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."product_price as p ";
$sql.= " WHERE p.fk_product = ".$product->id; $sql.= " WHERE p.fk_product = ".$product->id;
$sql.= " AND p.fk_user_author = u.rowid"; $sql.= " AND p.fk_user_author = u.rowid";
$sql.= " ORDER BY p.date_price DESC"; $sql.= " ORDER BY p.date_price DESC";
} }
//$sql .= $db->plimit(); //$sql .= $db->plimit();
$result = $db->query($sql) ; $result = $db->query($sql) ;
if ($result) if ($result)
{ {
$num = $db->num_rows($result); $num = $db->num_rows($result);
if (! $num) if (! $num)
{ {
$db->free($result) ; $db->free($result) ;
// Il doit au moins y avoir la ligne de prix initial. // Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre à niveau (pb vieilles versions) // On l'ajoute donc pour remettre a niveau (pb vieilles versions)
$product->update_price($product->id, $product->price, 'HT' ,$user,$newprice_min); $product->update_price($product->id, $product->price, 'HT', $user, $newprice_min);
$result = $db->query($sql) ; $result = $db->query($sql) ;
$num = $db->num_rows($result); $num = $db->num_rows($result);
} }
if ($num > 0) if ($num > 0)
{ {
print '<br>'; print '<br>';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">'; print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>'; print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
if($conf->global->PRODUIT_MULTIPRICES) if($conf->global->PRODUIT_MULTIPRICES)
{ {
print '<td>'.$langs->trans("MultiPriceLevelsName").'</td>'; print '<td>'.$langs->trans("MultiPriceLevelsName").'</td>';
} }
print '<td align="center">'.$langs->trans("PriceBase").'</td>'; print '<td align="center">'.$langs->trans("PriceBase").'</td>';
print '<td align="right">'.$langs->trans("VAT").'</td>'; print '<td align="right">'.$langs->trans("VAT").'</td>';
print '<td align="right">'.$langs->trans("HT").'</td>'; print '<td align="right">'.$langs->trans("HT").'</td>';
print '<td align="right">'.$langs->trans("TTC").'</td>'; print '<td align="right">'.$langs->trans("TTC").'</td>';
print '<td align="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>'; print '<td align="right">'.$langs->trans("MinPrice").' '.$langs->trans("HT").'</td>';
print '<td align="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>'; print '<td align="right">'.$langs->trans("MinPrice").' '.$langs->trans("TTC").'</td>';
print '<td align="right">'.$langs->trans("ChangedBy").'</td>'; print '<td align="right">'.$langs->trans("ChangedBy").'</td>';
print '</tr>'; if ($user->rights->produit->creer) print '<td align="right">&nbsp;</td>';
print '</tr>';
$var=True; $var=True;
$i = 0; $i = 0;
while ($i < $num) while ($i < $num)
{ {
$objp = $db->fetch_object($result); $objp = $db->fetch_object($result);
$var=!$var; $var=!$var;
@ -404,7 +419,7 @@ if ($result)
// Date // Date
print "<td>".dolibarr_print_date($objp->dp,"dayhour")."</td>"; print "<td>".dolibarr_print_date($objp->dp,"dayhour")."</td>";
// catégorie de Prix // Price level
if ($conf->global->PRODUIT_MULTIPRICES) if ($conf->global->PRODUIT_MULTIPRICES)
{ {
print "<td>".$objp->price_level."</td>"; print "<td>".$objp->price_level."</td>";
@ -414,22 +429,37 @@ if ($result)
print '<td align="right">'.vatrate($objp->tva_tx,true)."</td>"; print '<td align="right">'.vatrate($objp->tva_tx,true)."</td>";
print '<td align="right">'.price($objp->price)."</td>"; print '<td align="right">'.price($objp->price)."</td>";
print '<td align="right">'.price($objp->price_ttc)."</td>"; print '<td align="right">'.price($objp->price_ttc)."</td>";
print '<td align="right">'.price($objp->price_min).'</td>'; print '<td align="right">'.price($objp->price_min).'</td>';
print '<td align="right">'.price($objp->price_min_ttc).'</td>'; print '<td align="right">'.price($objp->price_min_ttc).'</td>';
// User // User
print '<td align="right"><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$objp->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.'</a></td>'; print '<td align="right"><a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$objp->user_id.'">'.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.'</a></td>';
// Action
if ($user->rights->produit->creer)
{
print '<td align="right">';
if ($i > 0)
{
print '<a href="'.$_SERVER["PHP_SELF"].'?action=delete&amp;id='.$product->id.'&amp;lineid='.$objp->rowid.'">';
print img_delete();
print '</a>';
}
else print '&nbsp;'; // Can not delete last price (it's current price)
print '</td>';
}
print "</tr>\n"; print "</tr>\n";
$i++; $i++;
} }
$db->free($result); $db->free($result);
print "</table>"; print "</table>";
print "<br>"; print "<br>";
} }
} }
else else
{ {
dolibarr_print_error($db); dolibarr_print_error($db);
} }