From cfd5f40683b18766fbca6eebb6ddf6678c167dfa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 13 Jul 2010 23:36:53 +0000 Subject: [PATCH] Move not stable ecotax feature as a module. --- htdocs/admin/dict.php | 2 +- htdocs/commande/class/commande.class.php | 5 +- .../interface_all_Demo.class.php-NORUN | 20 ++ ...terface_modCommande_Ecotax.class.php-NORUN | 296 ------------------ htdocs/install/upgrade2.php | 1 + htdocs/product/admin/produit.php | 15 - 6 files changed, 25 insertions(+), 314 deletions(-) delete mode 100644 htdocs/includes/triggers/interface_modCommande_Ecotax.class.php-NORUN diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 5bbf5646513..353ff5d3cb5 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -235,7 +235,7 @@ $tabcond[10]= true; $tabcond[11]= true; $tabcond[12]= $conf->facture->enabled||$conf->fournisseur->enabled; $tabcond[13]= $conf->facture->enabled||$conf->fournisseur->enabled; -$tabcond[14]= $conf->product->enabled&&$conf->global->PRODUIT_USE_ECOTAXE; +$tabcond[14]= $conf->product->enabled&&$conf->ecotax->enabled; $tabcond[15]= true; $tabcond[16]= $conf->societe->enabled; $tabcond[17]= $conf->deplacement->enabled; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 43d193d40f6..4079430e51f 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -41,6 +41,7 @@ class Commande extends CommonObject var $element='commande'; var $table_element='commande'; var $table_element_line = 'commandedet'; + var $class_element_line = 'OrderLine'; var $fk_element = 'fk_commande'; var $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe @@ -903,7 +904,7 @@ class Commande extends CommonObject $line->product_type=$type; // \TODO Ne plus utiliser - $line->price=$price; + $line->price=$price; $line->remise=$remise; $line->date_start=$date_start; @@ -1059,7 +1060,7 @@ class Commande extends CommonObject $this->total_ht = $obj->total_ht; $this->total_tva = $obj->total_tva; $this->total_localtax1 = $obj->total_localtax1; - $this->total_localtax2 = $obj->total_localtax2; + $this->total_localtax2 = $obj->total_localtax2; $this->total_ttc = $obj->total_ttc; $this->date = $this->db->jdate($obj->date_commande); $this->date_commande = $this->db->jdate($obj->date_commande); diff --git a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN index effdfeaae65..64153ce2e3a 100644 --- a/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN +++ b/htdocs/includes/triggers/interface_all_Demo.class.php-NORUN @@ -199,6 +199,14 @@ class InterfaceDemo dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } elseif ($action == 'ORDER_SENTBYMAIL') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEORDER_INSERT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEORDER_DELETE') { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } @@ -246,6 +254,14 @@ class InterfaceDemo { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } + elseif ($action == 'LINEPROPAL_INSERT') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } + elseif ($action == 'LINEPROPAL_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } // Contracts elseif ($action == 'CONTRACT_CREATE') @@ -302,6 +318,10 @@ class InterfaceDemo { dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); } + elseif ($action == 'LINEBILL_DELETE') + { + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); + } // Payments elseif ($action == 'PAYMENT_CUSTOMER_CREATE') diff --git a/htdocs/includes/triggers/interface_modCommande_Ecotax.class.php-NORUN b/htdocs/includes/triggers/interface_modCommande_Ecotax.class.php-NORUN deleted file mode 100644 index fbf2263d55f..00000000000 --- a/htdocs/includes/triggers/interface_modCommande_Ecotax.class.php-NORUN +++ /dev/null @@ -1,296 +0,0 @@ - - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - */ - -/** - \file htdocs/includes/triggers/interface_modCommande_Ecotax.class.php - \ingroup core - \brief Ajout Ecotax sur produit d'un certaine categorie -*/ - - -/** - \class InterfaceEcotax - \brief Classe des fonctions triggers des actions personalisees du workflow -*/ - -class InterfaceEcotax -{ - var $db; - var $error; - - /** - * \brief Constructeur. - * \param DB Handler d'acces base - */ - function InterfaceEcotax($DB) - { - $this->db = $DB ; - - $this->name = preg_replace('/^Interface/i','',get_class($this)); - $this->family = "facture"; - $this->description = "Les triggers de ce composant calculent le ecotax du produit si le produit est membre d'une categorie speciale (par default: 'Ecotax', change le valeur du variable \$ecotax dans le trigger pour accomoder votre choix)."; - $this->revision = explode(' ','$Revision$'); - $this->version = $this->revision[1]; - } - - /** - * \brief Renvoi nom du lot de triggers - * \return string Nom du lot de triggers - */ - function getName() - { - return $this->name; - } - - /** - * \brief Renvoi descriptif du lot de triggers - * \return string Descriptif du lot de triggers - */ - function getDesc() - { - return $this->description; - } - /** - * \brief Renvoi version du lot de triggers - * \return string Version du lot de triggers - */ - function getVersion() - { - global $langs; - $langs->load("admin"); - - if ($this->version == 'experimental') return $langs->trans("Experimental"); - elseif ($this->version == 'dolibarr') return DOL_VERSION; - elseif ($this->version) return $this->version; - else return $langs->trans("Unknown"); - } - - /** - * \brief Fonction appelee lors du declenchement d'un evenement Dolibarr. - * D'autres fonctions run_trigger peuvent etre presentes dans includes/triggers - * \param action Code de l'evenement - * \param object Objet concern - * \param user Objet user - * \param lang Objet lang - * \param conf Objet conf - * \return int <0 si ko, 0 si aucune action faite, >0 si ok - */ - function run_trigger($action,$object,$user,$langs,$conf) - { - if ($action == 'LINEORDER_INSERT') - { - return $this->_add_replace_ecotax($action,$object,$user,$langs,$conf); - } - if ($action == 'LINEORDER_DELETE') - { - return $this->_add_replace_ecotax($action,$object,$user,$langs,$conf); - } - // Renvoi 0 car aucune action de faite - return 0; - } - - - function _add_replace_ecotax($action,$object,$user,$langs,$conf) - { - // The next 3 parameter can be replaced at will: - $desc = "Ecotax"; // the description on the invoice (recupel in Belgium) - $txtva = 21; // the default tax percentage - $ecocat = "Ecotax"; // the category products must be in for ecotax to apply - - // Ajoute une ligne de ecotax automatiquement - // - dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->fk_commande); - - - /* - * Calcul le ecotax, dependant du prix - * - */ - $sql = "SELECT fd.price, fd.qty, fd.fk_product"; - $sql.= " FROM ".MAIN_DB_PREFIX."commandedet as fd"; - $sql.= " WHERE fd.fk_commande = '".$object->fk_commande."'"; - $sql.= " AND fd.special_code = '0'"; - - $resql = $this->db->query($sql) ; - - $eco = 0; - if ($resql) - { - while ( $row = $this->db->fetch_row($resql) ) - { - $price=$row[0]; - $qty=$row[1]; - $prod_id=$row[2]; - if ($this->_is_in_cat($ecocat,$prod_id)) { - if ($price<=100) { - $eco+=5*$qty; - } elseif ($price>100 && $price<=300) { - $eco+=10*$qty; - } else { - $eco+=15*$qty; - } - } - } - } - else - { - dol_syslog("Trigger '".$this->name."' in action '$action' [2] SQL ERROR "); - } - /* - * - * - */ - - /* - * Detecte si la ligne existe - * - */ - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commandedet "; - $sql.= " WHERE fk_commande = '".$object->fk_commande."'"; - $sql.= " AND special_code = 2;"; - - $resql = $this->db->query($sql) ; - - if ($resql) - { - $exists = $this->db->num_rows($resql); - $this->db->free($resql); - } - else - { - dol_syslog("Trigger '".$this->name."' in action '$action' [3] SQL ERROR $sql"); - } - /* - * Nombre de ligne de commande - * - */ - $sql = "SELECT MAX(rang) FROM ".MAIN_DB_PREFIX."commandedet"; - $sql.= " WHERE fk_commande=".$object->fk_commande.";"; - - $resql = $this->db->query($sql) ; - $num_lignes=0; - if ($resql) - { - while ( $row = $this->db->fetch_row($resql) ) - { - $num_lignes = $row[0]; - } - } - else - { - dol_syslog("Trigger '".$this->name."' in action '$action' [4] SQL ERROR "); - } - - /* - * Calcul les ecotax - */ - $rang = $num_lignes + 1; - - // Tout a 0 tant que l'on ne sait pas calculer - $total_ht = $eco; - $total_tva = $eco*$txtva/100; - $total_ttc = $total_ht+$total_ttc; - - if ($exists > 0) - { - // Mets a jour la ligne - $sql = "UPDATE ".MAIN_DB_PREFIX."commandedet"; - $sql.= " SET description ='".addslashes($desc)."'"; - $sql.= ", rang='".$rang."'"; - $sql.= " WHERE fk_commande=".$object->fk_commande; - $sql.= " AND special_code=2;"; - - $resql = $this->db->query($sql) ; - - if ($resql) - { - return 2; - } - else - { - dol_syslog("Trigger '".$this->name."' in action '$action' [5] SQL ERROR $sql"); - } - } - else - { - // Insertion dans base de la ligne - // See class OrderLine - // we don't use the class OrderLine for insert, because - // then the trigger would be called again ... and again ... and ... - $sql = "INSERT INTO ".MAIN_DB_PREFIX."commandedet"; - $sql.= " (fk_commande, description, qty, tva_tx,"; - $sql.= " fk_product, remise_percent, subprice, price, remise, fk_remise_except,"; - $sql.= " marge_tx, marque_tx, rang, info_bits, total_ht, total_tva, total_ttc, special_code)"; - $sql.= " VALUES (".$object->fk_commande.","; - $sql.= " '".addslashes($desc)."',"; - $sql.= " '1',"; - $sql.= " '".price2num($txtva)."',"; - $sql.= 'null,'; - $sql.= " '0',"; - $sql.= " '".price2num($total_ht)."',"; - $sql.= " '".price2num($total_ht)."',"; - $sql.= " 0,0,0,0,"; - $sql.= ' '.$rang.',0,'; - $sql.= " '".price2num($total_ht)."',"; - $sql.= " '".price2num($total_tva)."',"; - $sql.= " '".price2num($total_ttc)."'"; - $sql.= ",2);"; - - $resql = $this->db->query($sql) ; - - if ($resql) - { - return 1; - } - else - { - dol_syslog("Trigger '".$this->name."' in action '$action' [5] SQL ERROR $sql"); - } - } - } - - function _is_in_cat($ecocat,$product_id) { - /* - * See if the product is in the ecotax category - * Stop and return 0 if the product is not in it - */ - require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php"); - if (!isset($product_id) || empty($product_id)) { - return 0; - } - $c = new Categorie($this->db); - $cats = array(); - $cats = $c->containing($product_id,0); - $found=0; - if (count($cats)==0) { - return 0; - } - foreach ($cats as $cat) { - if ($cat->label===$ecocat) { - $found=1; - } - } - if ($found==0) { - return 0; - } - return 1; - } -} -?> diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 34e951332af..29c40292f49 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -1730,6 +1730,7 @@ function migrate_delete_old_files($db,$langs,$conf) DOL_DOCUMENT_ROOT.'/includes/modules/modComptabiliteExpert.class.php', DOL_DOCUMENT_ROOT.'/includes/triggers/interface_modPhenix_Phenixsynchro.class.php', DOL_DOCUMENT_ROOT.'/includes/triggers/interface_modWebcalendar_webcalsynchro.class.php', + DOL_DOCUMENT_ROOT.'/includes/triggers/interface_modCommande_Ecotax.class.php', ); foreach ($filetodeletearray as $filetodelete) diff --git a/htdocs/product/admin/produit.php b/htdocs/product/admin/produit.php index 30944485976..64825b0bd2f 100644 --- a/htdocs/product/admin/produit.php +++ b/htdocs/product/admin/produit.php @@ -216,21 +216,6 @@ print ''; print ''; */ -// Utilisation de l'ecotaxe -$var=!$var; -print "
"; -print ''; -print ""; -print ""; -print ''.$langs->trans("UseEcoTaxeAbility").''; -print ''; -print $html->selectyesno("activate_useecotaxe",$conf->global->PRODUIT_USE_ECOTAXE,1); -print ''; -print ''; -print ""; -print ''; -print '
'; - if ($conf->global->PRODUCT_CANVAS_ABILITY) { // Add canvas feature