/** * @param TaxRuleEvent $event */ public function setDefault(TaxRuleEvent $event) { if (null !== ($taxRule = TaxRuleQuery::create()->findPk($event->getId()))) { TaxRuleQuery::create()->update(array("IsDefault" => 0)); $taxRule->setIsDefault(1)->save(); $event->setTaxRule($taxRule); } }
public function setDefaultAction() { if (null !== ($response = $this->checkAuth($this->resourceCode, array(), AccessManager::UPDATE))) { return $response; } $setDefaultEvent = new TaxRuleEvent(); $taxRuleId = $this->getRequest()->attributes->get('tax_rule_id'); $setDefaultEvent->setId($taxRuleId); $this->dispatch(TheliaEvents::TAX_RULE_SET_DEFAULT, $setDefaultEvent); return $this->redirectToListTemplate(); }
protected function hydrateI18nEvent(array $i18nRow, TaxRuleEvent $event) { $event->setLocale($i18nRow["locale"])->setTitle($i18nRow["title"])->setDescription($i18nRow["description"]); }
public function importTaxes() { $taux_tvas = $this->t1db->query_list("select distinct tva from produit"); $taux_tvas_vp = $this->t1db->query_list("select distinct tva from venteprod"); foreach ($taux_tvas_vp as $tvp) { $found = false; foreach ($taux_tvas as $tv) { if ($tvp->tva == $tv->tva) { $found = true; break; } } if (!$found) { $taux_tvas[] = $tvp; } } $langs = LangQuery::create()->find(); $defaultCountry = CountryQuery::create()->findOneByByDefault(true); $first = true; foreach ($taux_tvas as $taux_tva) { $ppe = new PricePercentTaxType(); $ppe->setPercentage($taux_tva->tva); $taxEvent = new TaxEvent(); $taxEvent->setLocale($langs[0]->getLocale())->setTitle("TVA {$taux_tva->tva}%")->setDescription("This tax was imported from Thelia 1 using TVA {$taux_tva->tva}%")->setType(get_class($ppe))->setRequirements($ppe->getRequirements()); $this->dispatcher->dispatch(TheliaEvents::TAX_CREATE, $taxEvent); $taxEvent->setId($taxEvent->getTax()->getId()); Tlog::getInstance()->info("Created tax ID=" . $taxEvent->getTax()->getId() . " for TVA {$taux_tva->tva}"); for ($idx = 1; $idx < count($langs); $idx++) { $taxEvent->setLocale($langs[$idx]->getLocale())->setTitle("TVA {$taux_tva->tva}%"); $this->dispatcher->dispatch(TheliaEvents::TAX_UPDATE, $taxEvent); } $taxRuleEvent = new TaxRuleEvent(); $taxRuleEvent->setLocale($langs[0]->getLocale())->setTitle("Tax rule for TVA {$taux_tva->tva}%")->setDescription("This tax rule was created from Thelia 1 using TVA {$taux_tva->tva}%")->setCountryList(array($defaultCountry->getId()))->setTaxList(json_encode(array($taxEvent->getTax()->getId()))); $this->dispatcher->dispatch(TheliaEvents::TAX_RULE_CREATE, $taxRuleEvent); $taxRuleEvent->setId($taxRuleEvent->getTaxRule()->getId()); $this->dispatcher->dispatch(TheliaEvents::TAX_RULE_TAXES_UPDATE, $taxRuleEvent); Tlog::getInstance()->info("Created tax rule ID=" . $taxRuleEvent->getTaxRule()->getId() . " for TVA {$taux_tva->tva}"); for ($idx = 1; $idx < count($langs); $idx++) { $taxRuleEvent->setLocale($langs[$idx]->getLocale())->setTitle("Tax rule for TVA {$taux_tva->tva}%"); $this->dispatcher->dispatch(TheliaEvents::TAX_RULE_UPDATE, $taxRuleEvent); } if ($first) { // Set the first created tax rule as the default tax. $this->dispatcher->dispatch(TheliaEvents::TAX_RULE_SET_DEFAULT, $taxRuleEvent); } $this->tax_corresp->addEntry(1000 * $taux_tva->tva, $taxRuleEvent->getTaxRule()->getId()); $first = false; } }