Exemple #1
0
 /**
  * @param TaxEvent $event
  */
 public function delete(TaxEvent $event)
 {
     if (null !== ($tax = TaxQuery::create()->findPk($event->getId()))) {
         $tax->delete();
         $event->setTax($tax);
     }
 }
Exemple #2
0
 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;
     }
 }
 /**
  * Put in this method post object creation processing if required.
  *
  * @param  TaxEvent $createEvent the create event
  * @return Response a response, or null to continue normal processing
  */
 protected function performAdditionalCreateAction($createEvent)
 {
     return $this->generateRedirectFromRoute("admin.configuration.taxes.update", $this->getViewArguments(), $this->getRouteArguments($createEvent->getTax()->getId()));
 }