From 5cbde1943286b82799be4e1573503baff0cf9c04 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 10 Sep 2010 09:52:08 +0000 Subject: [PATCH] Works on module hook integration --- htdocs/comm/propal/class/propal.class.php | 54 ++++++------------- htdocs/commande/class/commande.class.php | 36 ++++++++++--- htdocs/commande/fiche.php | 2 +- htdocs/core/tpl/freeproductline_view.tpl.php | 2 +- .../tpl/predefinedproductline_view.tpl.php | 2 +- .../interface_all_Demo.class.php-NORUN | 4 ++ 6 files changed, 53 insertions(+), 47 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 36c09de5ad0..94800573174 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -94,8 +94,6 @@ class Propal extends CommonObject var $lines = array(); var $line; - - var $clone_fromid; var $origin; var $origin_id; @@ -778,6 +776,12 @@ class Propal extends CommonObject $error=0; $object=new Propal($this->db); + + // Instantiate hooks of thirdparty module + if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) + { + $object->callHooks('objectcard'); + } $this->db->begin(); @@ -785,7 +789,6 @@ class Propal extends CommonObject $object->fetch($fromid); $object->id=0; $object->statut=0; - $object->clone_fromid=$fromid; require_once(DOL_DOCUMENT_ROOT ."/societe/class/societe.class.php"); $objsoc=new Societe($this->db); @@ -825,6 +828,16 @@ class Propal extends CommonObject if (! $error) { + // Hook of thirdparty module + if (! empty($object->hooks)) + { + foreach($object->hooks as $module) + { + $result = $module->createFromClone($object); + if ($result < 0) $error++; + } + } + // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($this->db); @@ -1353,41 +1366,6 @@ class Propal extends CommonObject } } - - /** - * \brief Cree une commande a partir de la proposition commerciale - * \param user Utilisateur - * \return int <0 si ko, >=0 si ok - * TODO move in triggers - */ - function create_commande($user) - { - global $conf; - - if ($conf->commande->enabled) - { - if ($this->statut == 2) - { - // Propale signee - include_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); - $commande = new Commande($this->db); - $result=$commande->create_from_propale($user, $this->id); - - // Ne pas passer par la commande provisoire - if ($conf->global->COMMANDE_VALID_AFTER_CLOSE_PROPAL == 1) - { - $commande->fetch($result); - $commande->valid($user); - } - - return $result; - } - else return 0; - } - else return 0; - } - - /** * \brief Set draft status * \param user Object user that modify diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index db5a553a726..9a673ee2e1c 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -77,6 +77,8 @@ class Commande extends CommonObject var $remise_absolue; var $modelpdf; var $info_bits; + var $rang; + var $special_code; var $source; // Origin of order var $origin; @@ -607,7 +609,9 @@ class Commande extends CommonObject 0, $this->lines[$i]->date_start, $this->lines[$i]->date_end, - $this->lines[$i]->product_type + $this->lines[$i]->product_type, + $this->lines[$i]->rang, + $this->lines[$i]->special_code ); if ($result < 0) { @@ -691,11 +695,17 @@ class Commande extends CommonObject */ function createFromClone($fromid,$invertdetail=0) { - global $user,$langs; + global $conf,$user,$langs; $error=0; $object=new Commande($this->db); + + // Instantiate hooks of thirdparty module + if (is_array($conf->hooks_modules) && !empty($conf->hooks_modules)) + { + $object->callHooks('objectcard'); + } $this->db->begin(); @@ -723,9 +733,22 @@ class Commande extends CommonObject if (! $error) { - - - + // Hook of thirdparty module + if (! empty($object->hooks)) + { + foreach($object->hooks as $module) + { + $result = $module->createFromClone($object); + if ($result < 0) $error++; + } + } + + // Appel des triggers + include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('ORDER_CLONE',$object,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // Fin appel triggers } // End @@ -1170,7 +1193,7 @@ class Commande extends CommonObject $this->lines=array(); $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.fk_commande, l.description, l.price, l.qty, l.tva_tx,'; - $sql.= ' l.localtax1_tx, l.localtax2_tx, l.fk_remise_except, l.remise_percent, l.subprice, l.marge_tx, l.marque_tx, l.rang, l.info_bits,'; + $sql.= ' l.localtax1_tx, l.localtax2_tx, l.fk_remise_except, l.remise_percent, l.subprice, l.marge_tx, l.marque_tx, l.rang, l.info_bits, l.special_code,'; $sql.= ' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,'; $sql.= ' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label'; $sql.= ' FROM '.MAIN_DB_PREFIX.'commandedet as l'; @@ -1216,6 +1239,7 @@ class Commande extends CommonObject $line->marque_tx = $objp->marque_tx; $line->rang = $objp->rang; $line->info_bits = $objp->info_bits; + $line->special_code = $objp->special_code; $line->ref = $objp->product_ref; $line->libelle = $objp->label; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index a12eb78e491..3c4d0481b28 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -484,7 +484,7 @@ if ($_POST['action'] == 'addline' && $user->rights->commande->creer) $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - commande_pdf_create($db, $commande->id, $commande->modelpdf, $outputlangs); + commande_pdf_create($db, $commande, $commande->modelpdf, $outputlangs); unset($_POST['qty']); unset($_POST['type']); diff --git a/htdocs/core/tpl/freeproductline_view.tpl.php b/htdocs/core/tpl/freeproductline_view.tpl.php index 48a606526ad..7ec7351f110 100644 --- a/htdocs/core/tpl/freeproductline_view.tpl.php +++ b/htdocs/core/tpl/freeproductline_view.tpl.php @@ -63,7 +63,7 @@ special_code == 3) { ?> trans('Option'); ?> - total_ht); ?> + total_ht); ?> statut == 0 && $user->rights->$element->creer) { ?> diff --git a/htdocs/core/tpl/predefinedproductline_view.tpl.php b/htdocs/core/tpl/predefinedproductline_view.tpl.php index 452d030e9f7..6b687b69bcb 100644 --- a/htdocs/core/tpl/predefinedproductline_view.tpl.php +++ b/htdocs/core/tpl/predefinedproductline_view.tpl.php @@ -56,7 +56,7 @@ special_code == 3) { ?> trans('Option'); ?> - total_ht); ?> + total_ht); ?> statut == 0 && $user->rights->$element->creer) { ?> diff --git a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN index bc69ddaca4e..b91a972a160 100644 --- a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN +++ b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN @@ -198,6 +198,10 @@ class InterfaceDemo { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } + elseif ($action == 'ORDER_CLONE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } elseif ($action == 'ORDER_VALIDATE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id);