Beispiel #1
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();
 }
Beispiel #2
0
 /**
  * Transforma um valor fracionado em texto.
  * @return type
  * @throws \Exception 
  */
 public function toWords()
 {
     $currency = $this->getValue();
     list($integer, $decimal) = $this->explodeNumber($currency);
     $scale = mb_strlen($decimal);
     if (!$this->allowScales->contains($scale)) {
         throw new \Exception("a escala deve ser igual a dois ou três.");
     }
     $valueToWords = new \Sped\Commons\StringHelper();
     $this->setThousandth($decimal, $scale);
     $inteiroToWords = $this->integerToWord($integer);
     $decimalToWords = $this->decimalToWord($decimal);
     if ($inteiroToWords->length === 0 || $decimalToWords->length === 0) {
         $valueToWords->append($inteiroToWords)->append($decimalToWords);
     } else {
         $valueToWords->append($inteiroToWords)->append(' e ')->append($decimalToWords);
     }
     return $valueToWords->toString();
 }