Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/08/2011, 10:57
Avatar de andresdzphp
andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 8 meses
Puntos: 793
Respuesta: Digito Verificacion Colombia

No lo probé mucho pero con las pruebas que hice funcionó.

Código PHP:
Ver original
  1. <?php
  2. function calcularDV($nit) {
  3.     if (! is_numeric($nit)) {
  4.         return false;
  5.     }
  6.  
  7.     $arr = array(1 => 3, 4 => 17, 7 => 29, 10 => 43, 13 => 59, 2 => 7, 5 => 19,
  8.     8 => 37, 11 => 47, 14 => 67, 3 => 13, 6 => 23, 9 => 41, 12 => 53, 15 => 71);
  9.     $x = 0;
  10.     $y = 0;
  11.     $z = strlen($nit);
  12.     $dv = '';
  13.    
  14.     for ($i=0; $i<$z; $i++) {
  15.         $y = substr($nit, $i, 1);
  16.         $x += ($y*$arr[$z-$i]);
  17.     }
  18.    
  19.     $y = $x%11;
  20.    
  21.     if ($y > 1) {
  22.         $dv = 11-$y;
  23.         return $dv;
  24.     } else {
  25.         $dv = $y;
  26.         return $dv;
  27.     }
  28.    
  29. }
  30. //Se debe ingresar el NIT sin comas puntos etc...
  31. echo 'El digito de verificación es: ' . calcularDV(800197268);
  32. ?>
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP