This repository has been archived on 2024-11-28. You can view files and clone it, but cannot push or open issues or pull requests.
LuisLeon_FactuGES2/Source/Modulos/Banca electronica/Utiles/CVBUtils.pas

116 lines
2.8 KiB
ObjectPascal
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

unit CVBUtils;
interface
uses SysUtils;
function Trim(const cString: string): string;
function Replicate(c: char; nLen: integer): string;
function Ajusta(sCampo, sOrientacion: string; iLongitud: integer; sRelleno: char): string;
function Modulo9710(const ANumber : string) : Integer;
function AjustaCIF(sCampo: string): string;
function ReplaceAccents(AText : String) : string;
implementation
uses
Dialogs;
const
SansAccents : array[#0..#255] of Char
= #0#1#2#3#4#5#6#7#8#9#10#11#12#13#14#15#16#17#18#19#20#21#22#23#24#25#26#27#28#29#30#31 +
' !"#$%&''()*+,-./0123456789:;<=>?' +
'@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_'+
'`abcdefghijklmnopqrstuvwxyz{|}~'#127 +
'€'#129'ƒ„…†‡ˆ‰SŒ'#141'Ž'#143#144'“”•˜™sœ'#157'zY' +
#160'¡¢£¤¥¦§¨©ª«¬*®¯°±²³´µ¶·¸¹º»¼½¾¿' +
'AAAAAAÆCEEEEIIIIDNOOOOO×OUUUUYÞß' +
'aaaaaaæceeeeiiiidnooooo÷ouuuuyþy';
function ReplaceAccents(AText : String) : string;
var
i : integer;
p : pchar;
begin
Result := AText;
if Result='' then
exit;
p := @Result[1];
for i:=1 to Length(Result) do
begin
p^ := SansAccents[p^];
inc(p);
end;
end;
function AjustaCIF(sCampo: string): string;
// Quita cualquier carácter no válido del cif,nif
var
iX: integer;
begin
Result := '';
sCampo := UpperCase(sCampo);
if length(sCampo) < 1 then
sCampo := '0';
for iX := 0 to length(sCampo) do
if (sCampo[iX] in ['0'..'9', 'A'..'Z']) then
Result := Result + sCampo[iX];
end;
function Trim(const cString: string): string;
begin
Result := TrimLeft(TrimRight(cString));
end;
function Replicate(c: char; nLen: integer): string;
begin
Result := stringOfChar(c, nLen);
end;
function Ajusta(sCampo, sOrientacion: string; iLongitud: integer; sRelleno: char): string;
begin
sCampo := Trim(sCampo);
if uppercase(sOrientacion) = 'I' then
Result := Replicate(sRelleno, iLongitud - Length(sCampo)) + sCampo
else
Result := sCampo + Replicate(sRelleno, iLongitud - Length(sCampo));
if length(Result) > iLongitud then
Result := copy(Result, 1, iLongitud);
end;
function Modulo9710(const ANumber : string) : Integer;
const
m36:string = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
var
i, p : Integer;
begin
Result := 0;
for i := 1 to Length(ANumber) do
begin
p := Pos(ANumber[i], m36) ;
if p = 0 then
raise Exception.CreateFmt('Modulo97(%s): invalid data', [ANumber]);
Dec(p);
if p > 9 then
begin
Result := Result * 10 + (p div 10);
p := p mod 10;
end;
Result := Result * 10 + p;
Result := Result mod 97;
end;
Result := 98 - Result;
end;
end.