static function getRemise(&$PDOdb, $type, $total, $zip = '', $fk_shipment_mode = 0, $fk_soc = 0) { global $db, $conf; if (!empty($conf->global->REMISE_USE_THIRDPARTY_DISCOUNT) && !empty($fk_soc)) { dol_include_once('/societe/class/societe.class.php'); $s = new Societe($db); $s->fetch($fk_soc); return $s->array_options['options_remsup']; } $TRemise = TRemise::getAll($PDOdb, $type, true, !empty($zip), !empty($fk_shipment_mode)); $remise_used = 0; $find = false; if (!empty($TRemise)) { foreach ($TRemise as &$remise) { if ($type === 'WEIGHT' && $total >= $remise['palier'] && ($remise['remise'] > $remise_used || empty($remise_used))) { if (!empty($zip) && !empty($remise['zip']) && strpos($zip, $remise['zip']) === 0) { $remise_used = $remise['remise']; $find = true; break; } else { if (empty($zip) && empty($remise['zip'])) { // pas de remise associée au code poste trouvé avant $find = true; $remise_used = $remise['remise']; break; } } } else { if ($type === 'AMOUNT') { if ($total >= $remise['palier'] && ($remise['remise'] > $remise_used || empty($remise_used))) { $remise_used = $remise['remise']; $find = true; } } } } } if (!$find && !empty($zip)) { return TRemise::getRemise($PDOdb, $type, $total); } else { return $remise_used; } }
/** * Function called when a Dolibarrr business event is done. * All functions "run_trigger" are triggered if file * is inside directory core/triggers * * @param string $action Event action code * @param Object $object Object * @param User $user Object user * @param Translate $langs Object langs * @param conf $conf Object conf * @return int <0 if KO, 0 if no triggered ran, >0 if OK */ public function run_trigger($action, $object, $user, $langs, $conf) { // Put here code you want to execute when a Dolibarr business events occurs. // Data and type of action are stored into $object and $action // Users if ($action == 'ORDER_VALIDATE' || $action == 'PROPAL_VALIDATE' || $action == 'BILL_VALIDATE') { global $db, $conf; $langs->load('remise@remise'); $object->fetch_optionals($object->id); /*echo "<pre>"; print_r($object); echo "</pre>";*/ dol_include_once('core/lib/admin.lib.php'); define('INC_FROM_DOLIBARR', true); dol_include_once('/remise/config.php'); dol_include_once('/remise/class/remise.class.php'); $PDOdb = new TPDOdb(); // On récupère les remises définis dans la configuration du module $remiseAlreadyInDoc = TRemise::alreadyAdded($object); $fk_product = $conf->global->REMISE_ID_SERVICE_TO_USE; if (!$remiseAlreadyInDoc && !empty($fk_product) && $object->array_options['options_use_remise'] === 'Oui') { dol_include_once('/product/class/product.class.php', 'Product'); $total = TRemise::getTotal($object); $remise_used_montant = TRemise::getRemise($PDOdb, 'AMOUNT', $total, '', 0, $object->socid); $remise_used_weight = 0; if ($conf->global->REMISE_USE_WEIGHT) { $total_weight = TRemise::getTotalWeight($object); $remise_used_weight = TRemise::getRemise($PDOdb, 'WEIGHT', $total_weight, $object->client->zip); } $remise_used = max($remise_used_weight, $remise_used_montant); $p = new Product($db); $p->fetch($fk_product); $object->statut = 0; $object->brouillon = 1; $used_tva = $object->client->tva_assuj == 1 ? $p->tva_tx : 0; if (empty($conf->global->REMISE_USE_THIRDPARTY_DISCOUNT)) { if ($object->element == 'commande' && (double) DOL_VERSION == 3.6) { // Les paramètres sont tous dans le même ordre dans doulibarr 3.6 $object->addline("Remise de " . $remise_used . ' %', $total * $remise_used / 100 * -1, 1, $used_tva, 0, 0, $fk_product, 0, 0, 0, 'HT', 0, '', '', $p->type); } else { if ($object->element == 'propal') { $object->addline("Remise de " . $remise_used . ' %', $total * $remise_used / 100 * -1, 1, $used_tva, 0, 0, $fk_product, 0, 'HT', 0, 0, $p->type); } else { if ($object->element == 'commande') { $object->addline("Remise de " . $remise_used . ' %', $total * $remise_used / 100 * -1, 1, $used_tva, 0, 0, $fk_product); } } } } else { if (!empty($remise_used)) { $object->addline("Remise de " . price($remise_used) . ' %', $total * $remise_used / 100 * -1, 1, $used_tva, 0, 0, $fk_product); } } // setEventMessage($langs->trans('PortTaxAdded').' : '.price($remise_used).$conf->currency.' '.$langs->trans('VAT').' '.$used_tva.'%' ); // Je vire cette partie, ça empêche le passage d'autres trigger sur la validation puisque du coup statut = 1... //$object->fetch($object->id); //$object->statut = 1; // TODO AA à quoi ça sert... Puisqu'il n'ya pas de save... :-| } dol_syslog("Trigger '" . $this->name . "' for action '{$action}' launched by " . __FILE__ . ". id=" . $object->id); } return 0; }