D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
rosario
/
adm
/
app
/
gre
/
Models
/
helper
/
Filename :
RoValCnpj.php
back
Copy
<?php namespace App\gre\Models\helper; if (!defined('URL')) { header("Location: /"); exit(); } /** * Description of GreValCpf * * @copyright (c) year, Carlos Marques - CM */ class RoValCnpj { private $Cnpj; private $Resultado; private $cnpj_len; function getResultado() { return $this->Resultado; } public function valCnpj($Cnpj) { $this->Cnpj= $Cnpj; if(strlen($this->Cnpj) !== 14) { $this->Cnpj = preg_filter("/[^0-9]/","", $this->Cnpj); } $this->Cnpj = str_pad($this->Cnpj, 14, '0', STR_PAD_LEFT); // $this->Resultado = $this->Cnpj; $this->cnpj_len = ($this->Cnpj); if(strlen($this->Cnpj) !== 14 || $this->Cnpj == '00000000000000' || $this->Cnpj == '11111111111111' || $this->Cnpj == '22222222222222' || $this->Cnpj == '33333333333333' || $this->Cnpj == '44444444444444' || $this->Cnpj == '55555555555555' || $this->Cnpj == '66666666666666' || $this->Cnpj == '77777777777777' || $this->Cnpj == '88888888888888' || $this->Cnpj == '99999999999999' ){ $_SESSION['msg'] = "<div class='alert alert-danger'>Erro: CNPJ invalido !</div>"; $this->Resultado = false; }else{ $j = 5; $k = 6; $soma1 = 0; $soma2 = 0; for ($i = 0; $i < 13; $i++) { $j = $j == 1 ? 9 : $j; $k = $k == 1 ? 9 : $k; $soma2 += ($this->Cnpj{$i} * $k); if ($i < 12) { $soma1 += ($this->Cnpj{$i} * $j); } $k--; $j--; } $digito1 = $soma1 % 11 < 2 ? 0 : 11 - $soma1 % 11; $digito2 = $soma2 % 11 < 2 ? 0 : 11 - $soma2 % 11; $this->Resultado = true; if (($this->Cnpj{12} != $digito1) or ($this->Cnpj{13} != $digito2)){ $_SESSION['msg'] = "<div class='alert alert-danger' role='alert'> Erro: CNPJ Inválido !!! <button type='button' class='close' data-dismiss='alert' aria-label='Close'> <span aria-hidden='true'>×</span></button> </div>"; $this->Resultado = false; } } } }