/** * Function called when module is enabled. * The init function add constants, boxes, permissions and menus * (defined in constructor) into Dolibarr database. * It also creates data directories * * @param string $options Options when enabling module ('', 'noboxes') * @return int 1 if OK, 0 if KO */ public function init($options = '') { global $db, $conf; $sql = array(); $result = $this->loadTables(); // Création extrafield pour choix si remise doit apparaitre sur doc. dol_include_once('/core/class/extrafields.class.php'); //function addExtraField($attrname, $label, $type, $pos, $size, $elementtype, $unique=0, $required=0,$default_value='', $param=0) $ext = new ExtraFields($db); $res = $ext->addExtraField("use_remise", 'Automatisation des remises', 'select', 0, "", 'propal', 0, 0, '', array("options" => array("Oui" => "Oui", "Non" => "Non"))); $res = $ext->addExtraField("use_remise", 'Automatisation des remises', 'select', 0, "", 'commande', 0, 0, '', array("options" => array("Oui" => "Oui", "Non" => "Non"))); $res = $ext->addExtraField("use_remise", 'Automatisation des remises', 'select', 0, "", 'facture', 0, 0, '', array("options" => array("Oui" => "Oui", "Non" => "Non"))); define('INC_FROM_DOLIBARR', true); dol_include_once('/remise/config.php'); dol_include_once('/remise/class/remise.class.php'); $PDOdb = new TPDOdb(); $o = new TRemise(); $o->init_db_by_vars($PDOdb); if (!empty($conf->global->REMISE_WEIGHT_ARRAY)) { $TRemise = unserialize($conf->global->REMISE_WEIGHT_ARRAY); foreach ($TRemise as $remise) { $o = new TRemise(); $o->palier = $remise['weight']; $o->remise = $remise['remise']; $o->zip = $remise['zip']; $o->type = 'WEIGHT'; $o->save($PDOdb); } dolibarr_del_const($db, 'REMISE_WEIGHT_ARRAY'); } if (!empty($conf->global->REMISE_ARRAY)) { $TRemise = unserialize($conf->global->REMISE_ARRAY); foreach ($TRemise as $palier => $remise) { $o = new TRemise(); $o->palier = $palier; $o->remise = $remise; $o->type = 'AMOUNT'; $o->save($PDOdb); } dolibarr_del_const($db, 'REMISE_ARRAY'); } return $this->_init($sql, $options); }