From f8912267cb417c121391e1d4bb849c8952a7b652 Mon Sep 17 00:00:00 2001 From: Quentin Vial-Gouteyron Date: Tue, 13 Sep 2016 11:56:39 +0200 Subject: [PATCH 1/6] NEW Hook on stock product card --- htdocs/product/stock/product.php | 62 +++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 13 deletions(-) diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 2411dde51e4..801fc9efd86 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -63,12 +63,43 @@ if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit&stock',$id,'product&product','','',$fieldid); +$object = new Product($db); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels=$extrafields->fetch_name_optionals_label($object->table_element); + +if ($id > 0 || ! empty($ref)) +{ + $result = $object->fetch($id, $ref); + +} +$modulepart='product'; + +// Get object canvas (By default, this is not defined, so standard usage of dolibarr) +$canvas = !empty($object->canvas)?$object->canvas:GETPOST("canvas"); +$objcanvas=null; +if (! empty($canvas)) +{ + require_once DOL_DOCUMENT_ROOT.'/core/class/canvas.class.php'; + $objcanvas = new Canvas($db,$action); + $objcanvas->getCanvas('stockproduct','card',$canvas); +} + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('stockproductcard','globalcard')); + + /* * Actions */ if ($cancel) $action=''; +$parameters=array('id'=>$id, 'ref'=>$ref, 'objcanvas'=>$objcanvas); +$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'); + // Set stock limit if ($action == 'setseuil_stock_alerte') { @@ -664,28 +695,33 @@ else /* */ /* ************************************************************************** */ +$parameters=array(); -if (empty($action) && $object->id) +$reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook +if (empty($reshook)) { - print "
\n"; - if ($user->rights->stock->mouvement->creer) - { - print ''.$langs->trans("StockCorrection").''; - } - - //if (($user->rights->stock->mouvement->creer) && ! $object->hasbatch()) - if ($user->rights->stock->mouvement->creer) + if (empty($action) && $object->id) { - print ''.$langs->trans("StockTransfer").''; + print "
\n"; + + if ($user->rights->stock->mouvement->creer) + { + print ''.$langs->trans("StockCorrection").''; + } + + //if (($user->rights->stock->mouvement->creer) && ! $object->hasbatch()) + if ($user->rights->stock->mouvement->creer) + { + print ''.$langs->trans("StockTransfer").''; + } + + print '
'; } - print '
'; } - - /* * Stock detail (by warehouse). May go down into batch details. */ From 6d304f4a234b7ff9d145059bb40a61ce1321ffcd Mon Sep 17 00:00:00 2001 From: Quentin Vial-Gouteyron Date: Tue, 13 Sep 2016 14:56:57 +0200 Subject: [PATCH 2/6] NEW Hook formObjectOptions --- htdocs/product/stock/product.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 801fc9efd86..5a600707bc7 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -536,7 +536,11 @@ if ($id > 0 || $ref) print ''.$form->editfieldkey("StockLimit",'seuil_stock_alerte',$object->seuil_stock_alerte,$object,$user->rights->produit->creer).''; print $form->editfieldval("StockLimit",'seuil_stock_alerte',$object->seuil_stock_alerte,$object,$user->rights->produit->creer,'string'); print ''; - + + // Hook formObject + $parameters=array('colspan' => 3); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + // Desired stock print ''.$form->editfieldkey($form->textwithpicto($langs->trans("DesiredStock"), $langs->trans("DesiredStockDesc"), 1),'desiredstock',$object->desiredstock,$object,$user->rights->produit->creer); print ''; From 3d8f756646655dcb71058d55e4e0463355d91603 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 15 Sep 2016 10:51:48 +0200 Subject: [PATCH 3/6] prevent space separator in module definition If we type in definition of dictionnary "code,libelle, color" we can't insert/update value... propose to allow typing space bettween field (better lisibility) and remove space after --- htdocs/admin/dict.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 65d9514e796..eae25599075 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -580,7 +580,7 @@ if ($id == 10) // Actions add or modify an entry into a dictionary if (GETPOST('actionadd') || GETPOST('actionmodify')) { - $listfield=explode(',',$tabfield[$id]); + $listfield=explode(',', str_replace(' ', '',$tabfield[$id])); $listfieldinsert=explode(',',$tabfieldinsert[$id]); $listfieldmodify=explode(',',$tabfieldinsert[$id]); $listfieldvalue=explode(',',$tabfieldvalue[$id]); From 54756ef729860621a30de38833b94395c398131e Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Thu, 15 Sep 2016 23:45:13 +0200 Subject: [PATCH 4/6] Fix wrong trigger in supplier order --- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 2d2619fb203..2b979862d43 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -3089,7 +3089,7 @@ class CommandeFournisseurLigne extends CommonOrderLine if (! $error && ! $notrigger) { // Call trigger - $result=$this->call_trigger('LINEORDER_INSERT',$user); + $result=$this->call_trigger('LINEORDER_SUPPLIER_CREATE',$user); if ($result < 0) $error++; // End call triggers } From 1b05be0305365919cf3e85ea27c1a3499404f42c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josep=20Llu=C3=ADs?= Date: Fri, 16 Sep 2016 17:07:01 +0200 Subject: [PATCH 5/6] Minor fix: incorrect key translations "Post" key doesn't exist: Changed to "PostOrFunction" "Email" key doesn't exist: Changed to "EMail" "DateCreate" changed to "DateCreateShort" in $arrayfields (with the same key in print_liste_field_titre function) --- htdocs/contact/list.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 57d3cc52090..b8c96884e96 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -129,18 +129,18 @@ $fieldstosearchall = array( $arrayfields=array( 'p.lastname'=>array('label'=>$langs->trans("Lastname"), 'checked'=>1), 'p.firstname'=>array('label'=>$langs->trans("Firstname"), 'checked'=>1), - 'p.poste'=>array('label'=>$langs->trans("Post"), 'checked'=>1), + 'p.poste'=>array('label'=>$langs->trans("PostOrFunction"), 'checked'=>1), 'p.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0), 'p.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0), - 'p.phone'=>array('label'=>$langs->trans("PhonePro"), 'checked'=>1), + 'p.phone'=>array('label'=>$langs->trans("Phone"), 'checked'=>1), 'p.phone_perso'=>array('label'=>$langs->trans("PhonePerso"), 'checked'=>0), 'p.phone_mobile'=>array('label'=>$langs->trans("PhoneMobile"), 'checked'=>1), 'p.fax'=>array('label'=>$langs->trans("Fax"), 'checked'=>1), - 'p.email'=>array('label'=>$langs->trans("Email"), 'checked'=>1), + 'p.email'=>array('label'=>$langs->trans("EMail"), 'checked'=>1), 'p.skype'=>array('label'=>$langs->trans("Skype"), 'checked'=>1, 'enabled'=>(! empty($conf->skype->enabled))), 'p.thirdparty'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'enabled'=>empty($conf->global->SOCIETE_DISABLE_CONTACTS)), 'p.priv'=>array('label'=>$langs->trans("ContactVisibility"), 'checked'=>1, 'position'=>200), - 'p.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + 'p.datec'=>array('label'=>$langs->trans("DateCreationShort"), 'checked'=>0, 'position'=>500), 'p.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), 'p.statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), ); From 7fe0c4211c846ae8d5dd2394003b383941f95c12 Mon Sep 17 00:00:00 2001 From: Ion Agorria Date: Sat, 17 Sep 2016 02:35:02 +0200 Subject: [PATCH 6/6] Move order supplier deleteline code to line class --- .../class/fournisseur.commande.class.php | 111 +++++++++++------- 1 file changed, 70 insertions(+), 41 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 2d2619fb203..476bffaec8f 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1627,55 +1627,34 @@ class CommandeFournisseur extends CommonOrder * * @param int $idline Id of line to delete * @param int $notrigger 1=Disable call to triggers - * @return <0 if KO, >0 if OK + * @return int <0 if KO, >0 if OK */ public function deleteline($idline, $notrigger=0) { - global $user,$langs,$conf; - $error = 0; - - if ($this->statut != 0) + if ($this->statut == 0) { - return -1; - } + $line = new CommandeFournisseurLigne($this->db); - $this->db->begin(); + if ($line->fetch($idline) <= 0) + { + return 0; + } - if (! $notrigger) - { - // Call trigger - $result=$this->call_trigger('LINEORDER_SUPPLIER_DELETE',$user); - if ($result < 0) $error++; - // End call triggers - } - - if (! $error) - { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid = ".$idline; - $resql=$this->db->query($sql); - - dol_syslog(get_class($this)."::deleteline sql=".$sql); - if (! $resql) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - - if (! $error) - { - $result=$this->update_price(); - } - - if (! $error) - { - $this->db->commit(); - return 1; + if ($line->delete($notrigger) > 0) + { + $this->update_price(); + return 1; + } + else + { + $this->error = $line->error; + $this->errors = $line->errors; + return -1; + } } else - { - $this->db->rollback(); - return -1; + { + return -2; } } @@ -3202,5 +3181,55 @@ class CommandeFournisseurLigne extends CommonOrderLine return -1; } } + + /** + * Delete line in database + * + * @param int $notrigger 1=Disable call to triggers + * @return int <0 if KO, >0 if OK + */ + function delete($notrigger) + { + global $user; + + $error=0; + + $this->db->begin(); + + $sql = 'DELETE FROM '.MAIN_DB_PREFIX."commande_fournisseurdet WHERE rowid='".$this->rowid."';"; + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + + if (!$notrigger) + { + // Call trigger + $result=$this->call_trigger('LINEORDER_SUPPLIER_DELETE',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (!$error) + { + $this->db->commit(); + return 1; + } + + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->error=$this->db->lasterror(); + return -1; + } + } }