git-svn-id: https://192.168.0.254/svn/Proyectos.Tecsitel_FactuGES/trunk@4 b68bf8ae-e977-074f-a058-3cfd71dd8f45
153 lines
3.9 KiB
ObjectPascal
153 lines
3.9 KiB
ObjectPascal
{
|
|
===============================================================================
|
|
Copyright (©) 2002. Rodax Software.
|
|
===============================================================================
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|
copyright. Este fichero sólo podrá ser copiado, distribuido y utilizado,
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|
acuerdo con los términos y condiciones establecidas en el acuerdo/contrato
|
|
bajo el que se suministra.
|
|
-----------------------------------------------------------------------------
|
|
Web: www.rodax-software.com
|
|
===============================================================================
|
|
Fecha primera versión: 01-11-2002
|
|
Versión actual: 1.0.0
|
|
Fecha versión actual: 01-11-2002
|
|
===============================================================================
|
|
Modificaciones:
|
|
|
|
Fecha Comentarios
|
|
---------------------------------------------------------------------------
|
|
===============================================================================
|
|
}
|
|
|
|
unit NumFunc;
|
|
|
|
interface
|
|
|
|
{ Funciones numéricas }
|
|
function ValidarIVA (IVA : String) : Boolean;
|
|
function ValidarDto (Dto : String) : Boolean;
|
|
function Redondear(x : Extended; d : Integer) : Extended;
|
|
function EsNumerico(Cadena: String) : Boolean;
|
|
function EsInteger(Codigo: String) : Boolean;
|
|
function EsSmallInt(Codigo: String) : Boolean;
|
|
|
|
function darPorcentaje(x1, x2: Double): Double;
|
|
|
|
implementation
|
|
|
|
uses
|
|
Math, SysUtils, StrFunc;
|
|
|
|
resourcestring
|
|
msgRangoNoValido = '%s no es un valor válido. Debe estar en el rango de 0 a 100.';
|
|
msgDtoNoValido = '%s no es un descuento válido.';
|
|
msgIVANoValido = '%s no es un valor para el IVA válido.';
|
|
|
|
function Redondear(x : Extended; d : Integer) : Extended;
|
|
// Redondear(123.456, 0) = 123.00
|
|
// Redondear(123.456, 2) = 123.46
|
|
// Redondear(123456, -3) = 123000
|
|
var
|
|
n: Extended;
|
|
begin
|
|
n := Power(10, d);
|
|
x := x * n;
|
|
Result := (Int(x) + Int(Frac(x) * 2)) / n;
|
|
end;
|
|
|
|
function EsNumerico(Cadena: String) : Boolean;
|
|
var
|
|
Codigo: Integer;
|
|
Valor: Double;
|
|
begin
|
|
Val(Cadena, Valor, Codigo);
|
|
Result := (Codigo = 0)
|
|
end;
|
|
|
|
function EsInteger(Codigo: String) : Boolean;
|
|
begin
|
|
//Comprueba que le numero es lo sufucientemente pequeño para ser un entero
|
|
try
|
|
Result:=True;
|
|
StrToInt(Codigo);
|
|
except
|
|
on E : EConvertError do begin
|
|
Result:=False;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function EsSmallInt(Codigo: String) : Boolean;
|
|
begin
|
|
//Comprueba que le numero es lo sufucientemente pequeño para ser un entero
|
|
try
|
|
Result:=(StrToInt(Codigo)<High(SmallInt));
|
|
except
|
|
on E : EConvertError do begin
|
|
Result:=False;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
function validarIVA (IVA : String) : Boolean;
|
|
begin
|
|
Result := False;
|
|
if (EsCadenaVacia(IVA)) then
|
|
begin
|
|
Result := True;
|
|
exit;
|
|
end;
|
|
try
|
|
if (StrToFloat(IVA) < 0) or (StrToFloat(IVA) > 100) then
|
|
begin
|
|
Result := False;
|
|
raise ERangeError.CreateFmt(msgRangoNoValido, [IVA]);
|
|
end;
|
|
Result := True;
|
|
except
|
|
on E : EConvertError do
|
|
raise EConvertError.CreateFmt(msgIVANoValido, [IVA]);
|
|
end;
|
|
end;
|
|
|
|
function validarDto (Dto : String) : Boolean;
|
|
begin
|
|
Result := False;
|
|
if (EsCadenaVacia(Dto)) then
|
|
begin
|
|
Result := True;
|
|
exit;
|
|
end;
|
|
try
|
|
if (StrToFloat(Dto) < 0) or (StrToFloat(Dto) > 100) then
|
|
begin
|
|
Result := False;
|
|
raise ERangeError.CreateFmt(msgRangoNoValido, [Dto]);
|
|
end;
|
|
Result := True;
|
|
except
|
|
on E : EConvertError do
|
|
raise EConvertError.CreateFmt(msgDtoNoValido, [Dto]);
|
|
end;
|
|
end;
|
|
|
|
function darPorcentaje(x1, x2: Double): Double;
|
|
//Formula
|
|
//x1 --- 100
|
|
//x2 --- X
|
|
//X = (x2 * 100)/x1
|
|
var
|
|
Aux: Double;
|
|
|
|
begin
|
|
Aux := x2 * 100;
|
|
if (x1 = 0)
|
|
then Aux := -1
|
|
else Aux := (Aux / x1);
|
|
Result := Aux;
|
|
end;
|
|
|
|
end.
|