Création d'un module NoVatForCompanies pour gérer le cas de la TVA à 0% pour certains pros
This commit is contained in:
15
local/modules/NoVatForCompanies/Config/config.xml
Normal file
15
local/modules/NoVatForCompanies/Config/config.xml
Normal file
@@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<config xmlns="http://thelia.net/schema/dic/config"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/config http://thelia.net/schema/dic/config/thelia-1.0.xsd">
|
||||
|
||||
<services>
|
||||
<service id="NoVatForCompanies.listener" class="NoVatForCompanies\EventListeners\NoVatListener">
|
||||
<argument type="service" id="request"/>
|
||||
<argument type="service" id="thelia.taxEngine" />
|
||||
<tag name="kernel.event_subscriber"/>
|
||||
</service>
|
||||
</services>
|
||||
|
||||
</config>
|
||||
26
local/modules/NoVatForCompanies/Config/module.xml
Normal file
26
local/modules/NoVatForCompanies/Config/module.xml
Normal file
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module xmlns="http://thelia.net/schema/dic/module"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://thelia.net/schema/dic/module http://thelia.net/schema/dic/module/module-2_2.xsd">
|
||||
<fullnamespace>NoVatForCompanies\NoVatForCompanies</fullnamespace>
|
||||
<descriptive locale="en_US">
|
||||
<title>No french VAT for non-french companies</title>
|
||||
</descriptive>
|
||||
<descriptive locale="fr_FR">
|
||||
<title>Pas de TVA pour les entreprises hors France</title>
|
||||
</descriptive>
|
||||
<languages>
|
||||
<language>en_US</language>
|
||||
<language>fr_FR</language>
|
||||
</languages>
|
||||
<version>0.1</version>
|
||||
<authors>
|
||||
<author>
|
||||
<name></name>
|
||||
<email></email>
|
||||
</author>
|
||||
</authors>
|
||||
<type>classic</type>
|
||||
<thelia>2.3.0</thelia>
|
||||
<stability>other</stability>
|
||||
</module>
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* Copyright (c) Laurent LE CORRE */
|
||||
/* email : laurent@thecoredev.fr */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
|
||||
namespace NoVatForCompanies\EventListeners;
|
||||
|
||||
use NoVatForCompanies\TaxType\PricePercentTaxType;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\TaxEngine\TaxEngine;
|
||||
|
||||
|
||||
/**
|
||||
* Class NoVatListener
|
||||
* @package NoVatForCompanies\EventListeners
|
||||
* @author Laurent LE CORRE <laurent@thecoredev.fr>
|
||||
*/
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
4
local/modules/NoVatForCompanies/I18n/en_US.php
Normal file
4
local/modules/NoVatForCompanies/I18n/en_US.php
Normal file
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return array(
|
||||
// 'an english string' => 'The displayed english string',
|
||||
);
|
||||
6
local/modules/NoVatForCompanies/I18n/fr_FR.php
Normal file
6
local/modules/NoVatForCompanies/I18n/fr_FR.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
return array(
|
||||
'vat_france' => 'TVA française',
|
||||
'vat_zero' => 'Sans TVA',
|
||||
'tax_label' => 'Pourcentage du prix du produit - pour les professionnels en Europe',
|
||||
);
|
||||
21
local/modules/NoVatForCompanies/NoVatForCompanies.php
Normal file
21
local/modules/NoVatForCompanies/NoVatForCompanies.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* This file is part of the Thelia package. */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : dev@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
namespace NoVatForCompanies;
|
||||
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
class NoVatForCompanies extends BaseModule
|
||||
{
|
||||
/** @var string */
|
||||
const DOMAIN_NAME = 'novatforcompanies';
|
||||
}
|
||||
55
local/modules/NoVatForCompanies/Readme.md
Normal file
55
local/modules/NoVatForCompanies/Readme.md
Normal file
@@ -0,0 +1,55 @@
|
||||
# No Vat For Companies
|
||||
|
||||
Add a short description here. You can also add a screenshot if needed.
|
||||
|
||||
## Installation
|
||||
|
||||
### Manually
|
||||
|
||||
* Copy the module into ```<thelia_root>/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.
|
||||
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/*************************************************************************************/
|
||||
/* Copyright (c) Laurent LE CORRE */
|
||||
/* email : laurent@thecoredev.fr */
|
||||
/* */
|
||||
/* For the full copyright and license information, please view the LICENSE */
|
||||
/* file that was distributed with this source code. */
|
||||
/*************************************************************************************/
|
||||
|
||||
|
||||
namespace NoVatForCompanies\TaxType;
|
||||
|
||||
use CustomerVatNumber\Model\Base\CustomerVatNumberQuery;
|
||||
use NoVatForCompanies\NoVatForCompanies;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Model\Base\AddressQuery;
|
||||
use Thelia\Model\Base\TaxQuery;
|
||||
use Thelia\Model\Base\TaxRuleCountryQuery;
|
||||
use Thelia\TaxEngine\BaseTaxType;
|
||||
use Thelia\TaxEngine\TaxTypeRequirementDefinition;
|
||||
use Thelia\Type\FloatType;
|
||||
|
||||
/**
|
||||
* Class PricePercentTaxType
|
||||
* @package NoVatForCompanies\TaxType
|
||||
* @author Laurent LE CORRE <laurent@thecoredev.fr>
|
||||
*/
|
||||
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);
|
||||
}
|
||||
}
|
||||
11
local/modules/NoVatForCompanies/composer.json
Normal file
11
local/modules/NoVatForCompanies/composer.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user