NEW: add "productpricecard" hook and uniformize code

This commit is contained in:
Regis Houssin 2015-06-10 18:42:16 +02:00
parent 7f06727c56
commit e43d4a6239

View File

@ -2,7 +2,7 @@
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
* Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
* Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
@ -43,9 +43,12 @@ if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
$langs->load("products"); $langs->load("products");
$langs->load("bills"); $langs->load("bills");
$mesg=''; $error=0; $errors=array(); $_error=0;
$id = GETPOST('id', 'int'); $id = GETPOST('id', 'int');
$ref = GETPOST('ref', 'alpha'); $ref = GETPOST('ref', 'alpha');
$action = GETPOST('action', 'alpha'); $action = GETPOST('action', 'alpha');
$cancel = GETPOST('cancel', 'alpha');
$eid = GETPOST('eid', 'int'); $eid = GETPOST('eid', 'int');
// Security check // Security check
@ -54,25 +57,33 @@ $fieldtype = (! empty($ref) ? 'ref' : 'rowid');
if ($user->societe_id) $socid = $user->societe_id; if ($user->societe_id) $socid = $user->societe_id;
$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype); $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
if ($id > 0 || ! empty($ref))
{
$object = new Product($db); $object = new Product($db);
$object->fetch($id, $ref);
}
// Clean param // Clean param
if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5; if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_MULTIPRICES_LIMIT)) $conf->global->PRODUIT_MULTIPRICES_LIMIT = 5;
$error=0; // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('productpricecard','globalcard'));
/* /*
* Actions * Actions
*/ */
if (GETPOST("cancel")) $action=''; if ($cancel) $action='';
if ($action == 'update_price' && ! GETPOST("cancel") && ($user->rights->produit->creer || $user->rights->service->creer)) $parameters=array('id'=>$id, 'ref'=>$ref);
$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 == 'update_price' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer))
{ {
$result = $object->fetch($id);
$error=0;
$maxpricesupplier = $object->min_recommended_price(); $maxpricesupplier = $object->min_recommended_price();
$object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression $object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression
@ -167,9 +178,8 @@ if ($action == 'delete' && $user->rights->produit->supprimer)
* Price by quantity * Price by quantity
* *************************************************** * ***************************************************
*/ */
$error = 0;
if ($action == 'activate_price_by_qty') { // Activating product price by quantity add a new price, specified as by quantity if ($action == 'activate_price_by_qty') { // Activating product price by quantity add a new price, specified as by quantity
$result = $object->fetch($id);
$level = GETPOST('level'); $level = GETPOST('level');
$object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1); $object->updatePrice(0, $object->price_base_type, $user, $object->tva_tx, 0, $level, $object->tva_npr, 1);
@ -180,7 +190,6 @@ if ($action == 'edit_price_by_qty') { // Edition d'un prix par quantité
} }
if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par quantité if ($action == 'update_price_by_qty') { // Ajout / Mise à jour d'un prix par quantité
$result = $object->fetch($id);
// Récupération des variables // Récupération des variables
$rowid = GETPOST('rowid'); $rowid = GETPOST('rowid');
@ -251,15 +260,12 @@ if ($action == 'delete_all_price_by_qty') {
* Price by customer * Price by customer
* **************************************************** * ****************************************************
*/ */
if ($action == 'add_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { if ($action == 'add_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
$error=0;
$maxpricesupplier = $object->min_recommended_price(); $maxpricesupplier = $object->min_recommended_price();
$update_child_soc = GETPOST('updatechildprice'); $update_child_soc = GETPOST('updatechildprice');
$result = $object->fetch($id);
// add price by customer // add price by customer
$prodcustprice->fk_soc = GETPOST('socid', 'int'); $prodcustprice->fk_soc = GETPOST('socid', 'int');
$prodcustprice->fk_product = $object->id; $prodcustprice->fk_product = $object->id;
@ -303,11 +309,8 @@ if ($action == 'delete_customer_price' && ($user->rights->produit->supprimer ||
$action = ''; $action = '';
} }
if ($action == 'update_customer_price_confirm' && ! $_POST ["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { if ($action == 'update_customer_price_confirm' && !$cancel && ($user->rights->produit->creer || $user->rights->service->creer)) {
$result = $object->fetch($id);
$error=0;
$maxpricesupplier = $object->min_recommended_price(); $maxpricesupplier = $object->min_recommended_price();
$update_child_soc = GETPOST('updatechildprice'); $update_child_soc = GETPOST('updatechildprice');
@ -341,6 +344,8 @@ if ($action == 'update_customer_price_confirm' && ! $_POST ["cancel"] && ($user-
$action = ''; $action = '';
} }
} }
}
/* /*
* View * View
@ -348,9 +353,6 @@ if ($action == 'update_customer_price_confirm' && ! $_POST ["cancel"] && ($user-
$form = new Form($db); $form = new Form($db);
if (! empty($id) || ! empty($ref))
$result = $object->fetch($id, $ref);
llxHeader("", "", $langs->trans("CardProduct" . $object->type)); llxHeader("", "", $langs->trans("CardProduct" . $object->type));
$head = product_prepare_head($object); $head = product_prepare_head($object);