예제 #1
0
 /**
  * Finds whether a variable is equals.
  * @param mixed $string
  * @return boolean
  */
 public function equalsTo($string)
 {
     if (!$string instanceof \Sped\Commons\StringHelper) {
         $strSecond = new \Sped\Commons\StringHelper($string);
     }
     return $this->getValue() === $strSecond->getValue();
 }
예제 #2
0
 /**
  * Retorna os digitos verificadores.
  * @return string
  */
 public function generateVerifierDigit()
 {
     $base = new \Sped\Commons\StringHelper($this->getBaseNumber());
     for ($n = 1; $n <= $this->getDigitsCount(); $n++) {
         $soma = 0;
         $mult = 2;
         for ($i = $base->length - 1; $i > -1; $i--) {
             $soma += $mult * intval($base->left($i, 1)->getValue());
             if (++$mult > $this->getMaxMultiplier()) {
                 $mult = 2;
             }
         }
         $base->concat($soma * 10 % 11 % 10);
     }
     return $base->right($this->getDigitsCount())->getValue();
 }
예제 #3
0
 /**
  * Validação genérica de vários tipos de números. Dentre eles: CPF, CNPJ, PIS.
  * @param \Sped\Commons\Documents\AbstractDocument $value Valor a ser validado.
  * @return boolean 
  */
 public function validate($value)
 {
     if (!$value instanceof \Sped\Commons\Documents\AbstractDocument) {
         throw new \Exception('O documento não é do tipo \\Sped\\Types\\AbstractDocument');
     }
     $this->setDocument($value);
     $base = new \Sped\Commons\StringHelper($value->getBaseNumber());
     for ($n = 1; $n <= $value->getDigitsCount(); $n++) {
         $soma = 0;
         $mult = 2;
         for ($i = $base->length - 1; $i > -1; $i--) {
             $soma += $mult * intval($base->substring($i, 1)->toString());
             if (++$mult > $value->getMaxMultiplier()) {
                 $mult = 2;
             }
         }
         $base->concat($soma * 10 % 11 % 10);
     }
     return $value->getValueUnmasked() === $base->toString();
 }
예제 #4
0
 /**
  * Define a zona (local) de votação.
  * @param string|int $zona
  * @return \Sped\Commons\Documents\TituloEleitoral 
  */
 public function setZona($zona)
 {
     $zona = new \Sped\Commons\StringHelper($zona);
     $this->secao = $zona->padLeft(0, 3)->getValue();
     return $this;
 }
예제 #5
0
 /**
  * Verifica se a descrição de milhar deve estar no singular ou no plural.
  * @param string $words
  * @return boolean 
  */
 protected function isThousands($words)
 {
     $numToWords = new \Sped\Commons\StringHelper($words);
     $tamanho = $this->thousands->count();
     for ($a = 2; $a < $tamanho; $a++) {
         if ($numToWords->endsWith($this->thousands->offsetGet($a))) {
             return true;
         }
     }
     for ($a = 2; $a < $tamanho; $a++) {
         if ($numToWords->endsWith($this->thousandsPlural->offsetGet($a))) {
             return true;
         }
     }
     return false;
 }
예제 #6
0
 /**
  * Gera o código número aleatório com base nas informações do XML.<br>
  * Este código deve ser de 8 dígitos.
  * @param \Sped\Schemas\V200\DocumentNFe $domNFe Objeto do XML.
  * @return string Código Númerico gerado aleatoriamente.
  */
 public function gerarCodigoNumerico(\Sped\Schemas\V200\DocumentNFe $domNFe)
 {
     $codigoNumerico = 0;
     $hasIndex = 0;
     $nfeHash = sha1($domNFe->getNFe()->C14N(FALSE, FALSE, NULL, NULL));
     $coeficientes = new \Sped\Commons\Collections\ArrayCollection(array(3, 2, 2, 2, 2, 2, 3));
     $iterator = $coeficientes->getIterator();
     foreach ($iterator as $index => $element) {
         $algarismoBytes = substr($nfeHash, $hasIndex, $hasIndex + $element);
         $somaBytes = self::somaBytes($algarismoBytes);
         $algarismo = self::somaInteiro($somaBytes);
         $codigoNumerico = $codigoNumerico + $algarismo * Math::pow(10.0, $index);
         $hasIndex += $element;
     }
     $codigoNumerico = new \Sped\Commons\StringHelper($codigoNumerico);
     return $codigoNumerico->padLeft('0', 8)->toString();
 }