Exemple #1
0
 public function isValid($value, $context = null)
 {
     if (!empty($value)) {
         $this->vat = $value;
         $countryid = intval($context['country_id']);
         if ($countryid == 0) {
             $this->_error(self::ISNOTCOUNTRYID);
             return false;
         }
         $country = Countries::find($context['country_id']);
         if (!empty($country->code)) {
             $this->countryCode = $country->code;
         } else {
             return false;
         }
         if (Countries::isITbyId($countryid)) {
             if (!is_numeric($value) || strlen($value) != 11) {
                 $this->_error(self::INVALIDVAT);
                 return false;
             }
         } elseif (Countries::isUEbyId($countryid)) {
             return $this->eu_check();
         }
     }
     return true;
 }
Exemple #2
0
 /**
  * Check if the customer is subject to EU-VAT
  * TODO: add support for multiple invoicing addresses
  * 
  * @param integer $id
  * @return boolean
  * @throws Exception
  */
 public static function isVATFree($id)
 {
     if (!is_numeric($id)) {
         throw new Exception('Customer Id paramenter is mandatory');
     }
     $customer = self::getAllInfo($id);
     // tax free also means vat free
     if (!empty($customer['taxfree']) && $customer['taxfree']) {
         return true;
     }
     $Addresses = Addresses::findOneByUserId($id);
     if (!isset($Addresses->country_id) || !is_numeric($Addresses->country_id)) {
         return false;
     }
     if (empty($customer['vat'])) {
         /*
          * Private
          */
         //* EU country, VAT ok
         return !Countries::isUEbyId($Addresses->country_id);
     } else {
         /*
          * Company
          */
         //* TODO: 82 is Italy. This should not be hardcoded here.
         return $Addresses->country_id != 82 ? true : false;
     }
 }