* @copyright 2007-2011 PrestaShop SA * @version Release: $Revision: 7541 $ * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_CAN_LOAD_FILES_')) exit; class VatNumber extends Module { public function __construct() { $this->name = 'vatnumber'; $this->tab = 'billing_invoicing'; $this->version = 1.0; $this->author = 'PrestaShop'; $this->need_instance = 0; parent::__construct(); $this->displayName = $this->l('European VAT number'); $this->description = $this->l('Enable entering of the VAT intra-community number when creating the address (You must fill in the company field to allow keyboarding VAT number)'); } public function install() { return (parent::install() AND Configuration::updateValue('VATNUMBER_MANAGEMENT', 1)); } public function uninstall() { return (parent::uninstall() AND Configuration::updateValue('VATNUMBER_MANAGEMENT', 0)); } public function enable() { parent::enable(); Configuration::updateValue('VATNUMBER_MANAGEMENT', 1); } public function disable() { parent::disable(); Configuration::updateValue('VATNUMBER_MANAGEMENT', 0); } public static function getPrefixIntracomVAT() { $intracom_array = array('AT'=>'AT', //Austria 'BE'=>'BE', //Belgium 'DK'=>'DK', //Denmark 'FI'=>'FI', //Finland 'FR'=>'FR', //France 'FX'=>'FR', //France m�tropolitaine 'DE'=>'DE', //Germany 'GR'=>'EL', //Greece 'IE'=>'IE', //Irland 'IT'=>'IT', //Italy 'LU'=>'LU', //Luxembourg 'NL'=>'NL', //Netherlands 'PT'=>'PT', //Portugal 'ES'=>'ES', //Spain 'SE'=>'SE', //Sweden 'GB'=>'GB', //United Kingdom 'CY'=>'CY', //Cyprus 'EE'=>'EE', //Estonia 'HU'=>'HU', //Hungary 'LV'=>'LV', //Latvia 'LT'=>'LT', //Lithuania 'MT'=>'MT', //Malta 'PL'=>'PL', //Poland 'SK'=>'SK', //Slovakia 'CZ'=>'CZ', //Czech Republic 'SI'=>'SI', //Slovenia 'RO'=>'RO', //Romania 'BG'=>'BG' //Bulgaria ); return $intracom_array; } public static function isApplicable($id_country) { $isApplicable = in_array(Country::getIsoById((int)$id_country), VatNumber::getPrefixIntracomVAT()); if ($isApplicable == "") { return 0; } return 1; } public static function WebServiceCheck($vatNumber) { if (empty($vatNumber)) return array(); $vatNumber = str_replace(' ', '', $vatNumber); $prefix = substr($vatNumber, 0, 2); if (array_search($prefix, self::getPrefixIntracomVAT()) === false) return array(Tools::displayError('Invalid VAT number')); $vat = substr($vatNumber, 2); $url = 'http://ec.europa.eu/taxation_customs/vies/viesquer.do?ms='.urlencode($prefix).'&iso='.urlencode($prefix).'&vat='.urlencode($vat); @ini_set('default_socket_timeout', 2); for ($i = 0; $i < 3; $i++) { if ($pageRes = file_get_contents($url)) { if (preg_match('/invalid VAT number/i', $pageRes)) { @ini_restore('default_socket_timeout'); return array(Tools::displayError('VAT number not found')); } elseif (preg_match('/valid VAT number/i', $pageRes)) { @ini_restore('default_socket_timeout'); return array(); } else ++$i; } else sleep(1); } ini_restore('default_socket_timeout'); return array(Tools::displayError('VAT number validation service unavailable')); } public function getContent() { global $cookie; if (Tools::isSubmit('submitVatNumber')) { if (Tools::getValue('vatnumber_country')) if (Configuration::updateValue('VATNUMBER_COUNTRY', (int)(Tools::getValue('vatnumber_country')))) echo $this->displayConfirmation($this->l('Your country has been updated.')); $check = (int)Tools::getValue('vatnumber_checking'); if (Configuration::get('VATNUMBER_CHECKING') != $check AND Configuration::updateValue('VATNUMBER_CHECKING', $check)) echo ($check ? $this->displayConfirmation($this->l('The check of the VAT number with the WebService is now enabled.')) : $this->displayConfirmation($this->l('The check of the VAT number with the WebService is now disabled.'))); } echo '
'.$this->displayName.'
 

'.$this->l('The verification by the webservice is slow. Enabling this option can slow down your shop.').'

 
'; } }