Example #1
0
function unidades_g($tabla, $id_, $unidad, $descripcion, $decimales)
{
    $s_ = "select * from unidades where unidad = '{$unidad}' and id!='{$id_}'";
    $r_ = mysql_query($s_);
    if (mysql_num_rows($r_) <= 0) {
        if ($id_ == '') {
            $s_1 = "insert into unidades values('', '{$unidad}', '{$descripcion}', '{$decimales}')";
        }
        if ($id_ != '') {
            $s_1 = "update unidades set unidad='{$unidad}', descripcion='{$descripcion}', decimales='{$decimales}' where id='{$id_}'";
        }
        $r_1 = mysql_query($s_1);
        echo "<script>alert('Registro almacenado');</script>";
        unidades($tabla, '', '', '', '');
    } else {
        echo "<script>alert('Ese registro ya existe');</script>";
        unidades($tabla, $id_, $unidad, $descripcion, $decimales);
    }
}
function valorEnLetras($x)
{
    if ($x < 0) {
        $signo = "menos ";
    } else {
        $signo = "";
    }
    $x = abs($x);
    $C1 = $x;
    $G6 = floor($x / 1000000);
    // 7 y mas
    $E7 = floor($x / 100000);
    $G7 = $E7 - $G6 * 10;
    // 6
    $E8 = floor($x / 1000);
    $G8 = $E8 - $E7 * 100;
    // 5 y 4
    $E9 = floor($x / 100);
    $G9 = $E9 - $E8 * 10;
    //  3
    $E10 = floor($x);
    $G10 = $E10 - $E9 * 100;
    // 2 y 1
    $G11 = round(($x - $E10) * 100, 0);
    // Decimales
    //////////////////////
    $H6 = unidades($G6);
    if ($G7 == 1 and $G8 == 0) {
        $H7 = "Cien ";
    } else {
        $H7 = decenas($G7);
    }
    $H8 = unidades($G8);
    if ($G9 == 1 and $G10 == 0) {
        $H9 = "Cien ";
    } else {
        $H9 = decenas($G9);
    }
    $H10 = unidades($G10);
    if ($G11 < 10) {
        $H11 = "0" . $G11;
    } else {
        $H11 = $G11;
    }
    /////////////////////////////
    if ($G6 == 0) {
        $I6 = " ";
    } elseif ($G6 == 1) {
        $I6 = "Millón ";
    } else {
        $I6 = "Millones ";
    }
    if ($G8 == 0 and $G7 == 0) {
        $I8 = " ";
    } else {
        $I8 = "Mil ";
    }
    $C3 = $signo . $H6 . $I6 . $H7 . $H8 . $I8 . $H9 . $H10;
    return $C3;
    //Retornar el resultado
}
 function evalua($valor)
 {
     if ($valor == 0) {
         return 'cero';
     }
     $decimales = 0;
     $letras = '';
     while ($valor != 0) {
         // Validamos si supera los 100 millones
         if ($valor >= 1000000000) {
             return 'L&iacute;mite de aplicaci&oacute;n exedido.';
         }
         //Centenas de Millón
         if ($valor < 1000000000 and $valor >= 100000000) {
             if (intval($valor / 100000000) == 1 and $valor - intval($valor / 100000000) * 100000000 < 1000000) {
                 $letras .= (string) 'cien millones ';
             } else {
                 $letras .= $this->centenas(intval($valor / 100000000));
                 if (intval($valor / 100000000) != 1 and intval($valor / 100000000) != 5 and intval($valor / 100000000) != 7 and intval($valor / 100000000) != 9) {
                     $letras .= (string) 'ciento ';
                 } else {
                     $letras .= (string) ' ';
                 }
             }
             $valor = $valor - Intval($valor / 100000000) * 100000000;
         }
         //Decenas de Millón
         if ($valor < 100000000 and $valor >= 10000000) {
             if (intval($valor / 1000000) < 16) {
                 $tempo = $this->decenas(intval($valor / 1000000));
                 $letras .= (string) $tempo;
                 $letras .= (string) ' millones ';
                 $valor = $valor - intval($valor / 1000000) * 1000000;
             } else {
                 $letras .= $this->decenas(intval($valor / 10000000) * 10);
                 $valor = $valor - intval($valor / 10000000) * 10000000;
                 if ($valor > 1000000) {
                     $letras .= $letras . ' y ';
                 }
             }
         }
         //Unidades de Millon
         if ($valor < 10000000 and $valor >= 1000000) {
             $tempo = intval($valor / 1000000);
             if ($tempo == 1) {
                 $letras .= (string) ' un mill&oacute;n ';
             } else {
                 $tempo = unidades(intval($valor / 1000000));
                 $letras .= (string) $tempo;
                 $letras .= (string) " millones ";
             }
             $valor = $valor - intval($valor / 1000000) * 1000000;
         }
         //Centenas de Millar
         if ($valor < 1000000 and $valor >= 100000) {
             $tempo = intval($valor / 100000);
             $tempo2 = $valor - $tempo * 100000;
             if ($tempo == 1 and $tempo2 < 1000) {
                 $letras .= (string) 'cien mil ';
             } else {
                 $tempo = $this->centenas(intval($valor / 100000));
                 $letras .= (string) $tempo;
                 $tempo = intval($valor / 100000);
                 if ($tempo != 1 and $tempo != 5 and $tempo != 7 and $tempo != 9) {
                     $letras .= (string) 'ciento ';
                 } else {
                     $letras .= (string) ' ';
                 }
             }
             $valor = $valor - intval($valor / 100000) * 100000;
         }
         //Decenas de Millar
         if ($valor < 100000 and $valor >= 10000) {
             $tempo = intval($valor / 1000);
             if ($tempo < 16) {
                 $tempo = $this->decenas(intval($valor / 1000));
                 $letras .= (string) $tempo;
                 $letras .= (string) ' mil ';
                 $valor = $valor - intval($valor / 1000) * 1000;
             } else {
                 $tempo = $this->decenas(intval($valor / 10000) * 10);
                 $letras .= (string) $tempo;
                 $valor = $valor - intval($valor / 10000) * 10000;
                 if ($valor > 1000) {
                     $letras .= (string) ' y ';
                 } else {
                     $letras .= (string) ' mil ';
                 }
             }
         }
         //Unidades de Millar
         if ($valor < 10000 and $valor >= 1000) {
             $tempo = intval($valor / 1000);
             if ($tempo == 1) {
                 $letras .= (string) '';
             } else {
                 $tempo = $this->unidades(intval($valor / 1000));
                 $letras .= (string) $tempo;
             }
             $letras .= (string) ' mil ';
             $valor = $valor - intval($valor / 1000) * 1000;
         }
         //Centenas
         if ($valor < 1000 and $valor > 99) {
             if (intval($valor / 100) == 1 and $valor - intval($valor / 100) * 100 < 1) {
                 $letras .= 'cien ';
             } else {
                 $temp = intval($valor / 100);
                 $l2 = $this->centenas($temp);
                 $letras .= (string) $l2;
                 if (intval($valor / 100) != 1 and intval($valor / 100) != 5 and intval($valor / 100) != 7 and intval($valor / 100) != 9) {
                     $letras .= 'ciento ';
                 } else {
                     $letras .= (string) ' ';
                 }
             }
             $valor = $valor - intval($valor / 100) * 100;
         }
         //Decenas
         if ($valor < 100 and $valor > 9) {
             if ($valor < 16) {
                 $tempo = $this->decenas(intval($valor));
                 $letras .= $tempo;
                 $Numer = $valor - Intval($valor);
             } else {
                 $tempo = $this->decenas(Intval($valor / 10) * 10);
                 $letras .= (string) $tempo;
                 $valor = $valor - Intval($valor / 10) * 10;
                 if ($valor > 0.99) {
                     $letras .= (string) ' y ';
                 }
             }
         }
         //Unidades
         if ($valor < 10 and $valor > 0.99) {
             $tempo = $this->unidades(intval($valor));
             $letras .= (string) $tempo;
             $valor = $valor - intval($valor);
         }
         //Decimales
         if ($decimales <= 0) {
             if ($letras != "Error en Conversi&oacute;n a Letras" and strlen(trim($letras)) > 0) {
                 $letras .= (string) ' ';
             }
         }
         return $letras;
     }
 }