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;
}
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)
* \param prodfournprice Id du tarif = rowid table product_fournisseur_price
* \param qty Quantit<EFBFBD> du produit

View File

@ -21,11 +21,11 @@
*/
/**
\file htdocs/product/price.php
\ingroup product
\brief Page de la fiche produit
\version $Id$
*/
\file htdocs/product/price.php
\ingroup product
\brief Page de la fiche produit
\version $Id$
*/
require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/product.lib.php");
@ -43,8 +43,7 @@ accessforbidden();
* Actions
*/
if ($_POST["action"] == 'update_price' &&
! $_POST["cancel"] && $user->rights->produit->creer)
if ($_POST["action"] == 'update_price' && ! $_POST["cancel"] && $user->rights->produit->creer)
{
$product = new Product($db);
@ -56,12 +55,12 @@ if ($_POST["action"] == 'update_price' &&
$newprice='';
$newpricebase='';
$newvat='';
for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$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)
{
$newprice=price2num($_POST["price_".$i],'MU');
@ -70,9 +69,9 @@ if ($_POST["action"] == 'update_price' &&
}
else
{
$product->multiprices["$i"] = price2num($_POST["price_".$i],'MU');
$product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i];
$product->multiprices_vat_rate["$i"] = $_POST["tva_tx_".$i];
$product->multiprices["$i"] = price2num($_POST["price_".$i],'MU');
$product->multiprices_base_type["$i"] = $_POST["multiprices_base_type_".$i];
$product->multiprices_vat_rate["$i"] = $_POST["tva_tx_".$i];
}
}
else
@ -90,10 +89,10 @@ if ($_POST["action"] == 'update_price' &&
$newpricebase=$_POST["price_base_type"];
$newvat=$_POST["tva_tx"];
}
$newprice_min = '' ;
$newprice_min = price2num($_POST["price_min"],'MU');
if ($product->update_price($product->id, $newprice, $newpricebase, $user, $newvat,$newprice_min) > 0)
{
$_GET["action"] = '';
@ -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);
$product = new Product($db);
@ -118,6 +125,8 @@ if ($_GET["id"]) $result = $product->fetch($_GET["id"]);
llxHeader("","",$langs->trans("CardProduct".$product->type));
if ($mesg) print $mesg;
$head=product_prepare_head($product, $user);
$titre=$langs->trans("CardProduct".$product->type);
dolibarr_fiche_head($head, 'price', $titre);
@ -140,29 +149,29 @@ print '</tr>';
// MultiPrix
if($conf->global->PRODUIT_MULTIPRICES)
{
for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++)
{
print '<tr><td>'.$langs->trans("SellingPrice").' '.$i.'</td>';
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print '<td>'.price($product->multiprices_ttc["$i"]);
}
else
{
print '<td>'.price($product->multiprices["$i"]);
}
if ($product->multiprices_base_type["$i"])
{
print ' '.$langs->trans($product->multiprices_base_type["$i"]);
}
else
{
print ' '.$langs->trans($product->price_base_type);
}
print '</td></tr>';
}
if ($product->multiprices_base_type["$i"] == 'TTC')
{
print '<td>'.price($product->multiprices_ttc["$i"]);
}
else
{
print '<td>'.price($product->multiprices["$i"]);
}
if ($product->multiprices_base_type["$i"])
{
print ' '.$langs->trans($product->multiprices_base_type["$i"]);
}
else
{
print ' '.$langs->trans($product->price_base_type);
}
print '</td></tr>';
}
}
// Prix
else
@ -199,7 +208,7 @@ print $product->getLibStatut(2);
print '</td></tr>';
print "</table>\n";
print "</div>\n";
@ -210,14 +219,14 @@ print "</div>\n";
/* */
/* ************************************************************************** */
if (! $_GET["action"])
if (empty($_GET["action"]) || $_GET["action"]=='delete')
{
print "\n<div class=\"tabsAction\">\n";
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>';
}
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 "\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 '<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
print '<tr><td width="15%">';
$text=$langs->trans('SellingPrice');
print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
print '</td>';
if ($product->price_base_type == 'TTC')
{
print '<td><input name="price" size="10" value="'.price($product->price_ttc).'">';
@ -252,10 +269,10 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
{
print '<td><input name="price" size="10" value="'.price($product->price).'">';
}
print '<tr><td>' ;
$text=$langs->trans('MinPrice') ;
print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1);
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).'">';
@ -264,147 +281,145 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer)
{
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>';
// VAT
print '<tr><td width="20%">'.$langs->trans("VATRate").'</td><td>';
print $html->select_tva("tva_tx",$product->tva_tx,$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>';
}
else
{
{
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 '<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 '<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>';
}
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
if($conf->global->PRODUIT_MULTIPRICES)
{
$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx,";
$sql.= " p.price_level,";
$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.= " WHERE fk_product = ".$product->id;
$sql.= " AND p.fk_user_author = u.rowid ";
$sql.= " ORDER BY p.price_level ASC, p.date_price DESC";
$sql = "SELECT p.rowid, p.price, p.price_ttc, p.price_base_type, p.tva_tx,";
$sql.= " p.price_level,";
$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.= " WHERE fk_product = ".$product->id;
$sql.= " AND p.fk_user_author = u.rowid ";
$sql.= " ORDER BY p.price_level ASC, p.date_price DESC";
}
else
{
$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.= " ".$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.= " WHERE p.fk_product = ".$product->id;
$sql.= " AND p.fk_user_author = u.rowid";
$sql.= " ORDER BY p.date_price DESC";
$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.= " ".$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.= " WHERE p.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);
$num = $db->num_rows($result);
if (! $num)
{
$db->free($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, $product->price, 'HT' ,$user,$newprice_min);
// Il doit au moins y avoir la ligne de prix initial.
// On l'ajoute donc pour remettre a niveau (pb vieilles versions)
$product->update_price($product->id, $product->price, 'HT', $user, $newprice_min);
$result = $db->query($sql) ;
$num = $db->num_rows($result);
}
$result = $db->query($sql) ;
$num = $db->num_rows($result);
}
if ($num > 0)
{
print '<br>';
if ($num > 0)
{
print '<br>';
print '<table class="noborder" width="100%">';
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
print '<tr class="liste_titre">';
print '<td>'.$langs->trans("AppliedPricesFrom").'</td>';
if($conf->global->PRODUIT_MULTIPRICES)
{
print '<td>'.$langs->trans("MultiPriceLevelsName").'</td>';
}
print '<td align="center">'.$langs->trans("PriceBase").'</td>';
print '<td align="right">'.$langs->trans("VAT").'</td>';
print '<td align="right">'.$langs->trans("HT").'</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("TTC").'</td>';
print '<td align="right">'.$langs->trans("ChangedBy").'</td>';
print '</tr>';
$var=True;
$i = 0;
while ($i < $num)
print '<td align="center">'.$langs->trans("PriceBase").'</td>';
print '<td align="right">'.$langs->trans("VAT").'</td>';
print '<td align="right">'.$langs->trans("HT").'</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("TTC").'</td>';
print '<td align="right">'.$langs->trans("ChangedBy").'</td>';
if ($user->rights->produit->creer) print '<td align="right">&nbsp;</td>';
print '</tr>';
$var=True;
$i = 0;
while ($i < $num)
{
$objp = $db->fetch_object($result);
$var=!$var;
print "<tr $bc[$var]>";
// Date
print "<td>".dolibarr_print_date($objp->dp,"dayhour")."</td>";
// catégorie de Prix
// Price level
if ($conf->global->PRODUIT_MULTIPRICES)
{
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">'.price($objp->price)."</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_ttc).'</td>';
print '<td align="right">'.price($objp->price_min).'</td>';
print '<td align="right">'.price($objp->price_min_ttc).'</td>';
// 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>';
// 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";
$i++;
}
$db->free($result);
print "</table>";
print "<br>";
}
$db->free($result);
print "</table>";
print "<br>";
}
}
else
{
dolibarr_print_error($db);
dolibarr_print_error($db);
}