diff --git a/local/modules/NoVatForCompanies/Config/config.xml b/local/modules/NoVatForCompanies/Config/config.xml new file mode 100644 index 00000000..cb8a66c2 --- /dev/null +++ b/local/modules/NoVatForCompanies/Config/config.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/local/modules/NoVatForCompanies/Config/module.xml b/local/modules/NoVatForCompanies/Config/module.xml new file mode 100644 index 00000000..b1e83460 --- /dev/null +++ b/local/modules/NoVatForCompanies/Config/module.xml @@ -0,0 +1,26 @@ + + + NoVatForCompanies\NoVatForCompanies + + No french VAT for non-french companies + + + Pas de TVA pour les entreprises hors France + + + en_US + fr_FR + + 0.1 + + + + + + + classic + 2.3.0 + other + diff --git a/local/modules/NoVatForCompanies/EventListeners/NoVatListener.php b/local/modules/NoVatForCompanies/EventListeners/NoVatListener.php new file mode 100644 index 00000000..e7952d3d --- /dev/null +++ b/local/modules/NoVatForCompanies/EventListeners/NoVatListener.php @@ -0,0 +1,60 @@ + + */ +class NoVatListener implements EventSubscriberInterface +{ + /** @var Request */ + protected $request; + + /** @var TaxEngine */ + protected $taxEngine; + + /** + * TaxEventManager constructor. + * @param Request $request + * @param TaxEngine $taxEngine + */ + public function __construct(Request $request, TaxEngine $taxEngine) + { + $this->request = $request; + $this->taxEngine = $taxEngine; + } + + public function injectRequestInTaxType() + { + PricePercentTaxType::setRequest($this->request); + + $this->taxEngine->addTaxTypeDirectory( + 'NoVatForCompanies\TaxType', + __DIR__ . DS . ".." . DS . "TaxType" + ); + } + + public static function getSubscribedEvents() + { + return array( + KernelEvents::CONTROLLER => array('injectRequestInTaxType', 164) + ); + } +} diff --git a/local/modules/NoVatForCompanies/I18n/en_US.php b/local/modules/NoVatForCompanies/I18n/en_US.php new file mode 100644 index 00000000..0b4fa142 --- /dev/null +++ b/local/modules/NoVatForCompanies/I18n/en_US.php @@ -0,0 +1,4 @@ + 'The displayed english string', +); diff --git a/local/modules/NoVatForCompanies/I18n/fr_FR.php b/local/modules/NoVatForCompanies/I18n/fr_FR.php new file mode 100644 index 00000000..24d6032c --- /dev/null +++ b/local/modules/NoVatForCompanies/I18n/fr_FR.php @@ -0,0 +1,6 @@ + 'TVA française', + 'vat_zero' => 'Sans TVA', + 'tax_label' => 'Pourcentage du prix du produit - pour les professionnels en Europe', +); diff --git a/local/modules/NoVatForCompanies/NoVatForCompanies.php b/local/modules/NoVatForCompanies/NoVatForCompanies.php new file mode 100644 index 00000000..448ff84b --- /dev/null +++ b/local/modules/NoVatForCompanies/NoVatForCompanies.php @@ -0,0 +1,21 @@ +/local/modules/``` directory and be sure that the name of the module is NoVatForCompanies. +* Activate it in your thelia administration panel + +### Composer + +Add it in your main thelia composer.json file + +``` +composer require your-vendor/no-vat-for-companies-module:~1.0 +``` + +## Usage + +Explain here how to use your module, how to configure it, etc. + +## Hook + +If your module use one or more hook, fill this part. Explain which hooks are used. + + +## Loop + +If your module declare one or more loop, describe them here like this : + +[loop name] + +### Input arguments + +|Argument |Description | +|--- |--- | +|**arg1** | describe arg1 with an exemple. | +|**arg2** | describe arg2 with an exemple. | + +### Output arguments + +|Variable |Description | +|--- |--- | +|$VAR1 | describe $VAR1 variable | +|$VAR2 | describe $VAR2 variable | + +### Exemple + +Add a complete exemple of your loop + +## Other ? + +If you have other think to put, feel free to complete your readme as you want. diff --git a/local/modules/NoVatForCompanies/TaxType/PricePercentTaxType.php b/local/modules/NoVatForCompanies/TaxType/PricePercentTaxType.php new file mode 100644 index 00000000..9ae0cb83 --- /dev/null +++ b/local/modules/NoVatForCompanies/TaxType/PricePercentTaxType.php @@ -0,0 +1,78 @@ + + */ +class PricePercentTaxType extends BaseTaxType +{ + /** @var Request */ + protected static $request; + + public static function setRequest(Request $request) + { + self::$request = $request; + } + + public function pricePercentRetriever() + { + /** @var Session $session */ + $session = self::$request->getSession(); + + if (null !== $customer = $session->getCustomerUser()) { + + $reseller = $customer->getReseller(); + $company = AddressQuery::create()->filterByCustomerId($customer->getId())->findOneByIsDefault(1)->getCompany(); + + // Ne sont soumis à une TVA réduite que les pros en Europe (hors France) possédant une n° de TVA intracommunautaire + if (null == $reseller && null == $company) return ($this->getRequirement("percent_france") * 0.01); + if (null == CustomerVatNumberQuery::create()->findOneById($customer->getId())) return ($this->getRequirement("percent_france") * 0.01); + } + + return ($this->getRequirement("percent_zero") * 0.01); + } + + public function getRequirementsDefinition() + { + return array( + new TaxTypeRequirementDefinition( + 'percent_france', + new FloatType(), + Translator::getInstance()->trans("vat_france", array(), NoVatForCompanies::DOMAIN_NAME) + ), + new TaxTypeRequirementDefinition( + 'percent_zero', + new FloatType(), + Translator::getInstance()->trans("vat_zero", array(), NoVatForCompanies::DOMAIN_NAME) + ) + ); + } + + public function getTitle() + { + return Translator::getInstance()->trans("tax_label", array(), NoVatForCompanies::DOMAIN_NAME); + } +} diff --git a/local/modules/NoVatForCompanies/composer.json b/local/modules/NoVatForCompanies/composer.json new file mode 100644 index 00000000..96419120 --- /dev/null +++ b/local/modules/NoVatForCompanies/composer.json @@ -0,0 +1,11 @@ +{ + "name": "your-vendor/no-vat-for-companies-module", + "license": "LGPL-3.0+", + "type": "thelia-module", + "require": { + "thelia/installer": "~1.1" + }, + "extra": { + "installer-name": "NoVatForCompanies" + } +} \ No newline at end of file