From 3d94e3d80e2ae32f96fe3492912e6e1db142aafd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Oct 2015 12:01:17 +0200 Subject: [PATCH] FIX Editing a supplier price should keep the vat. --- .../fourn/class/fournisseur.product.class.php | 5 +- htdocs/product/fournisseurs.php | 150 +++++++++--------- 2 files changed, 76 insertions(+), 79 deletions(-) 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 ''; print ''.$langs->trans("Ref").''; - print $form->showrefnav($product,'ref','',1,'ref'); + print $form->showrefnav($object,'ref','',1,'ref'); print ''; print ''; // Label - print ''.$langs->trans("Label").''.$product->label.''; + print ''.$langs->trans("Label").''.$object->label.''; // Minimum Price print ''.$langs->trans("BuyingPriceMin").''; print ''; $product_fourn = new ProductFournisseur($db); - if ($product_fourn->find_min_price_product_fournisseur($product->id) > 0) + if ($product_fourn->find_min_price_product_fournisseur($object->id) > 0) { if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(); else print $langs->trans("NotDefined"); @@ -296,7 +285,7 @@ if ($id || $ref) // Status (to buy) print ''.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - print $product->getLibStatut(2,1); + print $object->getLibStatut(2,1); print ''; print ''; @@ -310,7 +299,7 @@ if ($id || $ref) if ($rowid) { - $product->fetch_product_fournisseur_price($rowid, 1); //Ignore the math expression when getting the price + $object->fetch_product_fournisseur_price($rowid, 1); //Ignore the math expression when getting the price print load_fiche_titre($langs->trans("ChangeSupplierPrice")); } else @@ -318,7 +307,7 @@ if ($id || $ref) print load_fiche_titre($langs->trans("AddSupplierPrice")); } - print '
'; + print ''; print ''; print ''; @@ -333,7 +322,7 @@ if ($id || $ref) $supplier->fetch($socid); print $supplier->getNomUrl(1); print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -344,13 +333,13 @@ if ($id || $ref) $events[]=array('method' => 'getVatRates', 'url' => dol_buildpath('/core/ajax/vatrates.php',1), 'htmlname' => 'tva_tx', 'params' => array()); print $form->select_company(GETPOST("id_fourn"),'id_fourn','fournisseur=1',1,0,0,$events); - $parameters=array('filtre'=>"fournisseur=1",'html_name'=>'id_fourn','selected'=>GETPOST("id_fourn"),'showempty'=>1,'prod_id'=>$product->id); - $reshook=$hookmanager->executeHooks('formCreateThirdpartyOptions',$parameters,$product,$action); + $parameters=array('filtre'=>"fournisseur=1",'html_name'=>'id_fourn','selected'=>GETPOST("id_fourn"),'showempty'=>1,'prod_id'=>$object->id); + $reshook=$hookmanager->executeHooks('formCreateThirdpartyOptions',$parameters,$object,$action); if (empty($reshook)) { if (empty($form->result)) { - print ' - '.$langs->trans("CreateDolibarrThirdPartySupplier").''; + print ' - '.$langs->trans("CreateDolibarrThirdPartySupplier").''; } } } @@ -360,7 +349,7 @@ if ($id || $ref) print ''.$langs->trans("SupplierRef").''; if ($rowid) { - print $product->fourn_ref; + print $object->fourn_ref; } else { @@ -374,7 +363,7 @@ if ($id || $ref) { $langs->load("propal"); print ''.$langs->trans("Availability").''; - $form->selectAvailabilityDelay($product->fk_availability,"oselDispo",1); + $form->selectAvailabilityDelay($object->fk_availability,"oselDispo",1); print ''."\n"; } @@ -385,8 +374,8 @@ if ($id || $ref) $quantity = GETPOST('qty') ? GETPOST('qty') : "1"; if ($rowid) { - print ''; - print $product->fourn_qty; + print ''; + print $object->fourn_qty; } else { @@ -402,15 +391,23 @@ if ($id || $ref) $mysoc2 = clone $mysoc; $mysoc2->name='Fictive seller with same country'; $mysoc2->tva_assuj=1; - $default_vat=get_default_tva($mysoc2, $mysoc, $product->id, 0); + $default_vat=get_default_tva($mysoc2, $mysoc, $object->id, 0); print ''.$langs->trans("VATRateForSupplierProduct").''; print ''; - //print $form->load_tva('tva_tx',$product->tva_tx,$supplier,$mysoc); // Do not use list here as it may be any vat rates for any country - if (! empty($socid)) // When update + //print $form->load_tva('tva_tx',$object->tva_tx,$supplier,$mysoc); // Do not use list here as it may be any vat rates for any country + if (! empty($rowid)) // If we have a supplier, it is an update, we must show the vat of current supplier price { - $default_vat=get_default_tva($supplier, $mysoc, $product->id); - if (empty($default_vat)) $default_vat=$product->tva_tx; + $tmpproductsupplier=new ProductFournisseur($db); + $tmpproductsupplier->fetch_product_fournisseur_price($rowid, 1); + $default_vat=$tmpproductsupplier->fourn_tva_tx; + } + else + { + if (empty($default_vat)) + { + $default_vat=$object->tva_tx; + } } print ''; print ''; @@ -424,7 +421,7 @@ if ($id || $ref) foreach ($price_expression->list_price_expression() as $entry) { $price_expression_list[$entry->id] = $entry->title; } - $price_expression_preselection = GETPOST('eid') ? GETPOST('eid') : ($product->fk_supplier_price_expression ? $product->fk_supplier_price_expression : '0'); + $price_expression_preselection = GETPOST('eid') ? GETPOST('eid') : ($object->fk_supplier_price_expression ? $object->fk_supplier_price_expression : '0'); print $form->selectarray('eid', $price_expression_list, $price_expression_preselection); print ' 
'.$langs->trans("PriceExpressionEditor").'
'; print ''; @@ -451,22 +448,21 @@ if ($id || $ref) // Price qty min print ''.$langs->trans("PriceQtyMin").''; - print ''; + print ''; print ' '; - print $form->selectPriceBaseType((GETPOST('price_base_type')?GETPOST('price_base_type'):$product->price_base_type), "price_base_type"); + print $form->selectPriceBaseType((GETPOST('price_base_type')?GETPOST('price_base_type'):'HT'), "price_base_type"); // We keep 'HT' here, price_base_type is not yet supported for supplier prices print ''; // Discount qty min print ''.$langs->trans("DiscountQtyMin").''; - print ' %'; + print ' %'; print ''; print ''; - - // Delai livraison jours + // Delivery delay in days print ''; print ''.$langs->trans('NbDaysToDelivery').''; - print ' '.$langs->trans('days').''; + print ' '.$langs->trans('days').''; print ''; // Charges ???? @@ -476,7 +472,7 @@ if ($id || $ref) { print ''; print ''.$langs->trans("Charges").''; - print ''; + print ''; print ''; print ''; } @@ -484,8 +480,8 @@ if ($id || $ref) if (is_object($hookmanager)) { - $parameters=array('id_fourn'=>$id_fourn,'prod_id'=>$product->id); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$product,$action); + $parameters=array('id_fourn'=>$id_fourn,'prod_id'=>$object->id); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); } print ''; @@ -508,12 +504,12 @@ if ($id || $ref) if ($action != 'add_price' && $action != 'updateprice') { $parameters=array(); - $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$product,$action); // Note that $action and $object may have been modified by hook + $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { if ($user->rights->produit->creer || $user->rights->service->creer) { - print ''; + print ''; print $langs->trans("AddSupplierPrice").''; } } @@ -527,19 +523,19 @@ if ($id || $ref) { // Suppliers list title print ''; - if ($product->isproduct()) $nblignefour=4; + if ($object->isproduct()) $nblignefour=4; else $nblignefour=4; - $param="&id=".$product->id; + $param="&id=".$object->id; print ''; print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("SupplierRef")); if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("VATRate")); - print_liste_field_titre($langs->trans("PriceQtyMinHT")); + print_liste_field_titre($langs->trans("VATRate"),$_SERVER["PHP_SELF"],'','',$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("PriceQtyMinHT"),$_SERVER["PHP_SELF"],'','',$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DiscountQtyMin")); + print_liste_field_titre($langs->trans("DiscountQtyMin"),$_SERVER["PHP_SELF"],'','',$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("NbDaysToDelivery"),$_SERVER["PHP_SELF"],"pfp.delivery_time_days","",$param,'align="right"',$sortfield,$sortorder); // Charges ???? @@ -551,7 +547,7 @@ if ($id || $ref) print "\n"; $product_fourn = new ProductFournisseur($db); - $product_fourn_list = $product_fourn->list_product_fournisseur_price($product->id, $sortfield, $sortorder); + $product_fourn_list = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder); if (count($product_fourn_list)>0) { @@ -631,16 +627,16 @@ if ($id || $ref) if (is_object($hookmanager)) { - $parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$product->id); - $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$product,$action); + $parameters=array('id_pfp'=>$productfourn->product_fourn_price_id,'id_fourn'=>$id_fourn,'prod_id'=>$object->id); + $reshook=$hookmanager->executeHooks('printObjectLine',$parameters,$object,$action); } // Modify-Remove print '';
'; if ($user->rights->produit->creer || $user->rights->service->creer) { - print ''.img_edit().""; - print ''.img_picto($langs->trans("Remove"),'disable.png').''; + print ''.img_edit().""; + print ''.img_picto($langs->trans("Remove"),'disable.png').''; } print '