Fala Pessoal, blz?
com muito orgulho venho aqui dizer que consegui a pré-homologação do TEF dedicado utilizando o V&SPague(Foreground) junto ao Moisés, todo desenvolvimento foi muito tranquilo e só tive que alterar algumas coisinhas bobas para poder concluir o processo. Gostaria de agradecer a iniciativa desse projeto fantástico e a toda comunidade que posta suas duvidas que vira uma fonte de conhecimento público.
Abaixo segue as alterações que fiz, deixo disponível para o Daniel verificar e postar para todos.
ps: todas alteracoes feitas por mim estão com a tag #Ricardo para facilitar a localização das alterações.
Unit uACBrTEFDClass
//Qndo é feito transacao ADM(impressao), deve ser enviado confirmação antes da impressao conforme orientações do Moises e exclusao do arquivo de pendencias.
procedure TACBrTEFDClass.ImprimirRelatorio;
function isCancelamento(acbr : TACBrTEFD) : boolean; {#Ricardo - Metodo para verificar se é transacao ADM e enviar confirmacao antes da impressao }
var
aArq : TStringList;
iX : Integer;
sLinha : String;
begin
result := false;
aArq := TStringList.create;
try
if fileExists( acbr.Resp.ArqBackup ) then
begin
aArq.LoadFromFile(acbr.Resp.ArqBackup);
for iX := 0 to aArq.Count -1 do
begin
sLinha := aArq.Strings[iX];
if pos('ADMINISTRACAO CANCELAR', upperCase(sLinha)) > 0 then
begin
self.CNF;
result := true;
break;
end;
end;
end;
Finally
freeAndNil(aArq);
if result then
DeleteFile( acbr.Resp.ArqBackup ) ;
End;
end;
Var
I : Integer;
TempoInicio : TDateTime ;
ImpressaoOk, RemoverMsg, GerencialAberto : Boolean ;
Est : AnsiChar ;
ArqBackup : String ;
ImagemComprovante : TStringList ;
bCancelamento : boolean;
begin
VerificarIniciouRequisicao;
if Resp.QtdLinhasComprovante < 1 then
exit ;
GravaLog( Name +' ImprimirRelatorio: '+Req.Header );
CopiarResposta ;
if Self is TACBrTEFDVeSPague then
bCancelamento := isCancelamento( TACBrTEFD( Owner ) );
ImpressaoOk := False ;
RemoverMsg := False ;
TempoInicio := now ;
with TACBrTEFD( Owner ) do
begin
try
BloquearMouseTeclado( True );
while not ImpressaoOk do
begin
try
try
Est := EstadoECF;
if Est <> 'L' then
begin
{ Fecha Vinculado ou Gerencial ou Cupom, se ficou algum aberto por Desligamento }
case Est of
'C' : ComandarECF( opeFechaVinculado );
'G','R' : ComandarECF( opeFechaGerencial );
'V','P','N' : ComandarECF( opeCancelaCupom );
end;
if EstadoECF <> 'L' then
raise EACBrTEFDECF.Create( ACBrStr('ECF não está LIVRE') ) ;
end;
GerencialAberto := False ;
TempoInicio := now ;
if Self.Resp.TextoEspecialOperador <> '' then
begin
RemoverMsg := True ;
DoExibeMsg( opmExibirMsgOperador, Self.Resp.TextoEspecialOperador ) ;
end;
if Self.Resp.TextoEspecialCliente <> '' then
begin
RemoverMsg := True ;
DoExibeMsg( opmExibirMsgCliente, Self.Resp.TextoEspecialCliente ) ;
end;
I := 1 ;
while I <= self.NumVias do
begin
if I = 1 then
ImagemComprovante := Self.Resp.ImagemComprovante1aVia
else
ImagemComprovante := Self.Resp.ImagemComprovante2aVia ;
if ImagemComprovante.Count > 0 then
begin
if not GerencialAberto then
begin
ComandarECF( opeAbreGerencial ) ;
GerencialAberto := True;
end
else
begin
if I <> 1 then
ComandarECF( opePulaLinhas ) ;
DoExibeMsg( opmDestaqueVia, 'Destaque a '+IntToStr(I)+'ª Via') ;
end ;
ECFImprimeVia( trGerencial, I, ImagemComprovante )
end ;
Inc( I ) ;
end;
if GerencialAberto then
ComandarECF( opeFechaGerencial );
ImpressaoOk := True ;
finally
{ Removendo a mensagem do Operador }
if RemoverMsg then
begin
{ Verifica se Mensagem Ficou pelo menos por 5 segundos }
if ImpressaoOk then
begin
while SecondsBetween(now,TempoInicio) < 5 do
begin
Sleep(EsperaSleep) ;
Application.ProcessMessages;
end;
end;
DoExibeMsg( opmRemoverMsgOperador, '' ) ;
DoExibeMsg( opmRemoverMsgCliente, '' ) ;
end;
end;
except
on EACBrTEFDECF do ImpressaoOk := False ;
else
raise ;
end;
if not ImpressaoOk then
begin
if DoExibeMsg( opmYesNo, 'Impressora não responde'+sLineBreak+
'Tentar novamente ?') <> mrYes then
break ;
end;
end;
finally
{ Enviando CNF ou NCN e apagando Arquivo de Backup }
//#Ricardo 04/05/2011 - Se for cancelamento deve ser enviado antes da impressao.
if (not bCancelamento) then
begin
ArqBackup := Resp.ArqBackup ;
while FileExists( ArqBackup ) do
begin
try
if ImpressaoOk then
self.CNF
else
self.NCN ;
except
end;
DeleteFile( ArqBackup ) ;
end ;
end;
BloquearMouseTeclado( False );
end ;
if not ImpressaoOk then
raise EACBrTEFDECF.Create( ACBrStr('Impressão de Relatório Falhou' ) ) ;
end;
end;
unit ACBrTEFDVeSPague
//alterado verificacao do retorno deve ser incluido o 3(cancelado pelo operador) para nao prosseguir a avaliacao.
procedure TACBrTEFDVeSPague.AvaliaErro( Retorno : Integer) ;
var
Erro : String;
begin
// 0, 1 : Tudo Ok
// 9 : Interrompido, deve ser tratado pela função chamadora, (chame ExibirMensagens)
if Retorno in [0,1,9,3] then // #Ricardo 22/12/2010 , o Codigo 3 é qndo é cancelado pelo operador.
exit ;
if RespVS.IsColeta then
Erro := RespVS.GetParamString('automacao_coleta_mensagem')
else
Erro := RespVS.GetParamString('mensagem');
if Erro = '' then
begin
Case Retorno of
2 : Erro := 'Sequencial Inválido' ;
// 3, 4 : Não são utilizados
5 : Erro := 'Parâmetros insuficientes ou inválidos' ;
// 6, 7 : Não são utilizados
8 : Erro := 'Tempo limite de espera excedido' ;
end ;
end ;
if Erro <> '' then
raise EACBrTEFDSTSInvalido.Create( ACBrStr(Erro) );
{ if RespVS.Sequencial <> ReqVS.Sequencial then
raise EACBrTEFDSTSInvalido.Create( ACBrStr('Sequencia da Resposta inválida') );}
end ;
//Alterada mensagem de transacao pendente conforme solicitado por moises
procedure TACBrTEFDVeSPague.VerificarTransacoesPendentesClass;
Var
ArquivosVerficar : TStringList ;
ArqMask : String;
Retorno: Integer;
MsgPendencias: WideString;
perguntou: Boolean;
begin
if not fExecutandoVerificacaoTransacoesPendentes then
begin
fExecutandoVerificacaoTransacoesPendentes:=true;
GravaLog( Name +' VerificarTransacoesPendentesClass ');
//exibe as pendencias
ArquivosVerficar := TStringList.Create;
MsgPendencias := EmptyStr;
try
ArquivosVerficar.Clear;
{ Achando Arquivos de Backup deste GP }
ArqMask := TACBrTEFD(Owner).PathBackup + PathDelim + 'ACBr_' + Self.Name + '_*.tef' ;
FindFiles( ArqMask, ArquivosVerficar, True );
{ Adicionando Arquivo de Resposta deste GP (se ainda não foi apagado) }
if FileExists( ArqResp ) then
ArquivosVerficar.Add( ArqResp );
{ Monta a mensagem de todos os arquivos encontrados }
if ArquivosVerficar.Count > 0 then
begin
MsgPendencias := 'Transações TEF a seguir estão PENDENTES:'+SLineBreak+SLineBreak;
end
;
while ArquivosVerficar.Count > 0 do
begin
if not FileExists( ArquivosVerficar[ 0 ] ) then
begin
ArquivosVerficar.Delete( 0 );
Continue;
end;
Resp.LeArquivo( ArquivosVerficar[ 0 ] );
{ Verificando se essa Resposta já foi cancela em outro arquivo }
MsgPendencias := MsgPendencias+'Rede: '+Resp.Rede+SLineBreak+'NSU: '+Resp.NSU+SLineBreak+'Valor: '+FloatToStrF(Resp.ValorTotal, ffCurrency, 18, 2)+SLineBreak+SLineBreak;
ArquivosVerficar.Delete( 0 );
end;
finally
ArquivosVerficar.Free;
end;
//verifica pendencias
if MsgPendencias <> EmptyStr then
begin
Retorno := 0;
perguntou:=false;
while Retorno <> 1 do
begin
try
if (not perguntou) and (fDesabilitarBotaoConfirma) then
begin
//MsgPendencias := MsgPendencias+'Favor realizar o DESFAZIMENTO no menu administrativo que será aberto a seguir.';
TACBrTEFD(Owner).DoExibeMsg( opmOK,'Há pelo menos uma transação pendente e deverá ser desfeita!' {MsgPendencias}); { #Ricardo 05/05/2011 - Mensagem apresentada deve ser essa conforme exigido no roteiro}
fTinhaPendencias:=True;
perguntou:=true;
end;
if fDesabilitarBotaoConfirma then
TransacaoOpcao:='Confirmar';
try
FazerRequisicao( fTransacaoPendente, 'ADM') ;
except on e:Exception do
begin
MessageDlg('Erro no tratamento e transações pendentes: '+#13+e.Message,mtError,[mbOK],0);
end;
end;
if RespVS.Servico = 'executar' then
begin
Retorno := RespVS.Retorno;
end;
except on e:Exception do
begin
if RespVS.Retorno<>3 then
MessageDlg('Erro no tratamento e transações pendentes: '+#13+e.Message,mtError,[mbOK],0);
perguntou:=false;
end;
end;
if RespVS.IsColeta then Retorno := 0;
if RespVS.GetParamString('mensagem') = 'Nao ha transacoes pendentes para este terminal.' then
begin
Retorno := 1;
end
;
// ShowMessage('Retorno: '+IntToStr(Retorno));
try
ProcessarResposta ; { Faz a Impressão e / ou exibe Mensagem ao Operador }
except on e:Exception do
begin
if e.message<>'Nenhuma Requisição Iniciada' then
MessageDlg('Erro no tratamento e transações pendentes: '+#13+e.Message,mtError,[mbOK],0);
end;
end;
sleep(250);
end
;
if Retorno = 0 then Retorno := ContinuarRequisicao( True ) ; { True = Imprimir Comprovantes agora }
end
;
//apaga os arquivos de backup das pendencias
ArquivosVerficar := TStringList.Create;
try
ArquivosVerficar.Clear;
{ Achando Arquivos de Backup deste GP }
ArqMask := TACBrTEFD(Owner).PathBackup + PathDelim + 'ACBr_' + Self.Name + '_*.tef' ;
FindFiles( ArqMask, ArquivosVerficar, True );
{ Adicionando Arquivo de Resposta deste GP (se ainda não foi apagado) }
if FileExists( ArqResp ) then
ArquivosVerficar.Add( ArqResp );
{ Apaga todos os arquivos encontrados }
while ArquivosVerficar.Count > 0 do
begin
if not FileExists( ArquivosVerficar[ 0 ] ) then
begin
ArquivosVerficar.Delete( 0 );
Continue;
end;
DeleteFile( PWideChar(ArquivosVerficar[ 0 ]) );
ArquivosVerficar.Delete( 0 );
end;
finally
ArquivosVerficar.Free;
end;
fExecutandoVerificacaoTransacoesPendentes:=false;
end;
end;