Ver Mensaje Individual
  #1  
Antiguo 24-07-2025
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is online now
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 19.437
Reputación: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Clase para generar huella en Delphi 12

Buenas, os comparto una clase para la generación de la huella en Delphi 12, teniendo en cuenta facturas F1 y de anulación, y si estamos en la península o en canarias.
Este código es autoría de [Eduardo Infante]. Me ha comentado que lo publicara en el club si lo veía útil.

Código Delphi [-]
unit uGenerarHuellaVerifactu;

interface

uses
    System.SysUtils, System.DateUtils, System.Hash;

type
    TTipoVerifactu = (tpAlta, tpAnulacion);

    TGenerarHuellaVerifactu = class
    public
        function GenerarHuellaVerifactu(const Tipo: TTipoVerifactu; const IDEmisor, NumSerie: string; 
                         const FechaExpedicion, FechaHora: TDateTime; const HuellaAnterior: string; const EsCanarias: Boolean; 
                         const TipoFactura: string = ''; const CuotaTotal: Double = 0.0; const ImporteTotal: Double = 0.0): string;
    end;

implementation

function TGenerarHuellaVerifactu.GenerarHuellaVerifactu(const Tipo: TTipoVerifactu; const IDEmisor, NumSerie: string; 
                         const FechaExpedicion, FechaHora: TDateTime; const HuellaAnterior: string; const EsCanarias: Boolean; 
                         const TipoFactura: string; const CuotaTotal: Double; const ImporteTotal: Double): string;
var
    InputStr: string;

    function FloatStr(Value: Double): string;
    var
        FS: TFormatSettings;
    begin
        FS := TFormatSettings.Create;
        FS.DecimalSeparator := '.';
        Result := FloatToStr(Value, FS);
    end;

    function FechaStr(const Fecha: TDateTime): string;
    begin
        Result := FormatDateTime('dd-mm-yyyy', Fecha);
    end;

    function FechaHoraStr(const FechaHora: TDateTime): string;
    var
        LocalHora: TDateTime;
        OffsetStr: string;
    begin
        if EsCanarias then begin
            LocalHora := FechaHora;
            OffsetStr := '+00:00';
        end
        else begin
            LocalHora := FechaHora + OneHour;
            OffsetStr := '+01:00';
        end;
        Result := FormatDateTime('yyyy-mm-dd"T"hh:nn:ss', LocalHora) + OffsetStr;
    end;

begin
    case Tipo of
        tpAlta:
            InputStr := 'IDEmisorFactura=' + Trim(IDEmisor) + '&' + 'NumSerieFactura=' + Trim(NumSerie) + '&' + 'FechaExpedicionFactura=' + 
                             FechaStr(FechaExpedicion) + '&' + 'TipoFactura=' + Trim(TipoFactura) + '&' + 'CuotaTotal=' + FloatStr(CuotaTotal) + '&' + 
                              'ImporteTotal=' + FloatStr(ImporteTotal) + '&' + 'Huella=' + Trim(HuellaAnterior) + '&' + 'FechaHoraHusoGenRegistro=' + 
                             FechaHoraStr(FechaHora);
        tpAnulacion:
            InputStr := 'IDEmisorFacturaAnulada=' + Trim(IDEmisor) + '&' + 'NumSerieFacturaAnulada=' + Trim(NumSerie) + '&' + 
                             'FechaExpedicionFacturaAnulada=' + FechaStr(FechaExpedicion) + '&' + 'Huella=' + Trim(HuellaAnterior) + '&' + 
                             'FechaHoraHusoGenRegistro=' + FechaHoraStr(FechaHora);
    else
        raise Exception.Create('Tipo de operación no soportado');
    end;

    Result := UpperCase(THashSHA2.GetHashString(InputStr, THashSHA2.TSHA2Version.SHA256));
end;

end.
__________________
Germán Estévez => Web/Blog
Guía de estilo, Guía alternativa
Utiliza TAG's en tus mensajes.
Contactar con el Clubdelphi

P.D: Más tiempo dedicado a la pregunta=Mejores respuestas.
Responder Con Cita