diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 9c4a95c7c52..490b5cf1ea3 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -58,7 +58,7 @@ class ProductFournisseur extends Product var $fourn_remise_percent; // discount for quantity (percent) var $fourn_remise; // discount for quantity (amount) var $product_fourn_id; // supplier id - var $fk_availability; // availability delay + var $fk_availability; // availability delay - visible/used if option FOURN_PRODUCT_AVAILABILITY is on (duplicate information compared to delivery delay) var $fourn_unitprice; var $fourn_tva_npr; @@ -370,7 +370,8 @@ class ProductFournisseur extends Product //$this->fourn_tva_npr = $obj->fourn_tva_npr; // TODO this field not exist in llx_product_fournisseur_price. We should add it ? $this->fk_supplier_price_expression = $obj->fk_supplier_price_expression; - if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) { + if (empty($ignore_expression) && !empty($this->fk_supplier_price_expression)) + { $priceparser = new PriceParser($this->db); $price_result = $priceparser->parseProductSupplier($this->fk_product, $this->fk_supplier_price_expression, $this->fourn_qty, $this->fourn_tva_tx); if ($price_result >= 0) { diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index b739ccc4d9e..0f7a8f942e5 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -65,8 +65,12 @@ $result=restrictedArea($user,'produit|service&fournisseur',$fieldvalue,'product& // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('pricesuppliercard','globalcard')); -$product = new ProductFournisseur($db); -$product->fetch($id,$ref); + +$object = new ProductFournisseur($db); +if ($id > 0 || $ref) +{ + $object->fetch($id,$ref); +} $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); @@ -82,22 +86,18 @@ if (! $sortorder) $sortorder="ASC"; if ($cancel) $action=''; $parameters=array('socid'=>$socid, 'id_prod'=>$id); -$reshook=$hookmanager->executeHooks('doActions',$parameters,$product,$action); // Note that $action and $object may have been modified by some hooks +$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); if (empty($reshook)) { if ($action == 'remove_pf') { - $product = new ProductFournisseur($db); - if ($product->fetch($id) > 0) + if ($rowid) { - if ($rowid) - { - $result=$product->remove_product_fournisseur_price($rowid); - $action = ''; - setEventMessage($langs->trans("PriceRemoved")); - } + $result=$object->remove_product_fournisseur_price($rowid); + $action = ''; + setEventMessage($langs->trans("PriceRemoved")); } } @@ -159,34 +159,26 @@ if (empty($reshook)) } } - $product = new ProductFournisseur($db); - $result=$product->fetch($id); - if ($result <= 0) - { - $error++; - setEventMessages($product->error, $product->errors, 'errors'); - } - if (! $error) { $db->begin(); if (! $error) { - $ret=$product->add_fournisseur($user, $id_fourn, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice + $ret=$object->add_fournisseur($user, $id_fourn, $ref_fourn, $quantity); // This insert record with no value for price. Values are update later with update_buyprice if ($ret == -3) { $error++; - $product->fetch($product->product_id_already_linked); - $productLink = $product->getNomUrl(1,'supplier'); + $object->fetch($object->product_id_already_linked); + $productLink = $object->getNomUrl(1,'supplier'); setEventMessage($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct",$productLink), 'errors'); } else if ($ret < 0) { $error++; - setEventMessage($product->error, 'errors'); + setEventMessage($object->error, 'errors'); } } @@ -195,14 +187,14 @@ if (empty($reshook)) $supplier=new Fournisseur($db); $result=$supplier->fetch($id_fourn); if (isset($_POST['ref_fourn_price_id'])) - $product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']); + $object->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']); - $ret=$product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days); + $ret=$object->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days); if ($ret < 0) { $error++; - setEventMessage($product->error, $product->errors, 'errors'); + setEventMessage($object->error, $object->errors, 'errors'); } else { @@ -217,11 +209,11 @@ if (empty($reshook)) } } if (! $error && ! empty($conf->dynamicprices->enabled)) { - $ret=$product->setPriceExpression($price_expression); + $ret=$object->setPriceExpression($price_expression); if ($ret < 0) { $error++; - setEventMessage($product->error, 'errors'); + setEventMessage($object->error, 'errors'); } } } @@ -251,23 +243,20 @@ if (empty($reshook)) $form = new Form($db); -if ($id || $ref) +if ($id > 0 || $ref) { if ($action <> 're-edit') { - $product = new ProductFournisseur($db); - $result = $product->fetch($id,$ref); - //$result = $product->fetch_fourn_data($_REQUEST["id_fourn"]); - llxHeader("","",$langs->trans("CardProduct".$product->type)); + llxHeader("","",$langs->trans("CardProduct".$object->type)); } if ($result) { if ($action <> 'edit' && $action <> 're-edit') { - $head=product_prepare_head($product); - $titre=$langs->trans("CardProduct".$product->type); - $picto=($product->type== Product::TYPE_SERVICE?'service':'product'); + $head=product_prepare_head($object); + $titre=$langs->trans("CardProduct".$object->type); + $picto=($object->type== Product::TYPE_SERVICE?'service':'product'); dol_fiche_head($head, 'suppliers', $titre, 0, $picto); @@ -276,18 +265,18 @@ if ($id || $ref) // Reference print '