diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 8f96a3e13cd..e0e0e8439c1 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -717,15 +717,41 @@ class Product extends CommonObject return -1; } else - return 1; - - + { + return 1; + } } } /** - * \brief Lit le prix pratiqu� 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� du produit diff --git a/htdocs/product/price.php b/htdocs/product/price.php index b7b7f754d25..91a15d02916 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -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='
'.$productstatic->error.'
'; +} + /* - * 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 ''; // MultiPrix if($conf->global->PRODUIT_MULTIPRICES) { - for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) - { - print ''.$langs->trans("SellingPrice").' '.$i.''; + for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) + { + print ''.$langs->trans("SellingPrice").' '.$i.''; - if ($product->multiprices_base_type["$i"] == 'TTC') - { - print ''.price($product->multiprices_ttc["$i"]); - } - else - { - print ''.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 ''; - } + if ($product->multiprices_base_type["$i"] == 'TTC') + { + print ''.price($product->multiprices_ttc["$i"]); + } + else + { + print ''.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 ''; + } } // Prix else @@ -199,7 +208,7 @@ print $product->getLibStatut(2); print ''; print "\n"; - + print "\n"; @@ -210,14 +219,14 @@ print "\n"; /* */ /* ************************************************************************** */ -if (! $_GET["action"]) +if (empty($_GET["action"]) || $_GET["action"]=='delete') { print "\n
\n"; - if ($user->rights->produit->modifier || $user->rights->produit->creer) - { - print ''.$langs->trans("UpdatePrice").''; - } + if ($user->rights->produit->modifier || $user->rights->produit->creer) + { + print ''.$langs->trans("UpdatePrice").''; + } print "\n
\n"; } @@ -238,12 +247,20 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) print ''; print ''; + // Price base + print ''; + print ''; + print ''; + // Price print ''; - if ($product->price_base_type == 'TTC') { print ''; - - print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); print ''; - + // VAT print ''; - + print ''; print '
'; + print $langs->trans('PriceBase'); + print ''; + print $html->select_PriceBaseType($product->price_base_type, "price_base_type"); + print '
'; $text=$langs->trans('SellingPrice'); print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1); print ''; @@ -252,10 +269,10 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) { print ''; } - - print '
' ; - $text=$langs->trans('MinPrice') ; - print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1); + + print '
' ; + $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 ''; @@ -264,147 +281,145 @@ if ($_GET["action"] == 'edit_price' && $user->rights->produit->creer) { print ''; } - print '
'.$langs->trans("VATRate").''; print $html->select_tva("tva_tx",$product->tva_tx,$mysoc,''); print '
 '; print '
'; print ''; } else - { + { for($i=1;$i<=$conf->global->PRODUIT_MULTIPRICES_LIMIT;$i++) - { - print '
'; - print ''; - print ''; - print ''; - print ''; - - if ($product->multiprices_base_type["$i"] == 'TTC') - { - print ''; + { + print ''; + print ''; + print ''; + print '
'; - $text=$langs->trans('SellingPrice').' '.$i; - print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1); - print ''; - } - else - { - print ''; - } - - print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i); - print '
'; + print ''; + + if ($product->multiprices_base_type["$i"] == 'TTC') + { + print ''; - print ''; + + // VAT + print ''; + + print ''; + print '
'; + $text=$langs->trans('SellingPrice').' '.$i; + print $html->textwithhelp($text,$langs->trans("PrecisionUnitIsLimitedToXDecimals",$conf->global->MAIN_MAX_DECIMALS_UNIT),$direction=1,$usehelpcursor=1); + print ''; + } + else + { + print ''; + } + + print $html->select_PriceBaseType($product->multiprices_base_type["$i"], "multiprices_base_type_".$i); + print '
' ; - $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 ''; + print '
' ; + $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 ''; + } + else + { + print ''; + } + print ''.$langs->trans("VATRate").''; + print $html->select_tva("tva_tx_".$i,$product->multiprices_tva_tx["$i"],$mysoc,''); + print '
 '; + print '
'; + print '
'; } - else - { - print ''; - } - print ''; - - // VAT - print ''.$langs->trans("VATRate").''; - print $html->select_tva("tva_tx_".$i,$product->multiprices_tva_tx["$i"],$mysoc,''); - print ''; - - print ' '; - print ''; - print ''; - print ''; - } - } + } } // 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 '
'; + if ($num > 0) + { + print '
'; - print ''; + print '
'; + + print ''; + print ''; - print ''; - print ''; - if($conf->global->PRODUIT_MULTIPRICES) { print ''; } - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - $var=True; - $i = 0; - while ($i < $num) + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + if ($user->rights->produit->creer) print ''; + print ''; + + $var=True; + $i = 0; + while ($i < $num) { $objp = $db->fetch_object($result); $var=!$var; print ""; // Date print ""; - - // catégorie de Prix + + // Price level if ($conf->global->PRODUIT_MULTIPRICES) { print ""; @@ -414,22 +429,37 @@ if ($result) print '"; print '"; print '"; - print ''; - print ''; + print ''; + print ''; // User print ''; + + // Action + if ($user->rights->produit->creer) + { + print ''; + } + print "\n"; $i++; } - $db->free($result); - print "
'.$langs->trans("AppliedPricesFrom").'
'.$langs->trans("AppliedPricesFrom").''.$langs->trans("MultiPriceLevelsName").''.$langs->trans("PriceBase").''.$langs->trans("VAT").''.$langs->trans("HT").''.$langs->trans("TTC").''.$langs->trans("MinPrice").' '.$langs->trans("HT").''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''.$langs->trans("ChangedBy").'
'.$langs->trans("PriceBase").''.$langs->trans("VAT").''.$langs->trans("HT").''.$langs->trans("TTC").''.$langs->trans("MinPrice").' '.$langs->trans("HT").''.$langs->trans("MinPrice").' '.$langs->trans("TTC").''.$langs->trans("ChangedBy").' 
".dolibarr_print_date($objp->dp,"dayhour")."".$objp->price_level."'.vatrate($objp->tva_tx,true)."'.price($objp->price)."'.price($objp->price_ttc)."'.price($objp->price_min).''.price($objp->price_min_ttc).''.price($objp->price_min).''.price($objp->price_min_ttc).''.img_object($langs->trans("ShowUser"),'user').' '.$objp->login.''; + if ($i > 0) + { + print 'id.'&lineid='.$objp->rowid.'">'; + print img_delete(); + print ''; + } + else print ' '; // Can not delete last price (it's current price) + print '
"; - print "
"; - } + $db->free($result); + print ""; + print "
"; + } } else { - dolibarr_print_error($db); + dolibarr_print_error($db); }