Last active
October 24, 2015 19:17
-
-
Save EliuTimana/8dff87840c22554f2abd to your computer and use it in GitHub Desktop.
Implementación del algoritmo para validación de formato de RUC en PHP | SUNAT Perú
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function validaRucAction(array $ruc){ | |
$values = array(5,4,3,2,7,6,5,4,3,2,0); | |
$sum = 0; | |
$valido = false; | |
for($i = 0; $i < strlen($ruc[0]); $i++){ | |
$sum += intval($ruc[0][$i]) * intval($values[$i]); | |
} | |
$res = intval($sum % 11); | |
$ultimo = 11 - $res; | |
if ($ultimo < 10) { | |
if ( $ultimo == intval(substr($ruc[0], -1)) ){ | |
$valido = true; | |
} | |
}else{ | |
$ultimo = intval($ultimo % 10); | |
if ( $ultimo == intval(substr($ruc[0], -1)) ){ | |
$valido = true; | |
} | |
} | |
return $valido; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment