forked from JoseQuintas/sefazclass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.prg
174 lines (153 loc) · 6.47 KB
/
test.prg
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
REQUEST HB_CODEPAGE_PTISO
#include "inkey.ch"
#include "set.ch"
#include "hbgtinfo.ch"
PROCEDURE Main
LOCAL nOpc := 1, GetList := {}, cTexto := "", nOpcTemp
LOCAL cCnpj := Space(14), cChave := Space(44), cCertificado := "", cUF := "SP", cXmlRetorno
LOCAL oSefaz
SetupHarbour()
SetMode( 33, 80 )
// Set( _SET_CODEPAGE, "PTISO" )
SetColor( "W/B,N/W,,,W/B" )
oSefaz := SefazClass():New()
oSefaz:cUF := "SP"
DO WHILE .T.
CLS
@ 0,0 SAY ""
@ Row() + 1, 5 PROMPT "Sair"
@ Row() + 1, 5 PROMPT "Seleciona certificado"
@ Row() + 1, 5 PROMPT "UF Default"
@ Row() + 1, 5 PROMPT "Consulta Status NFE"
@ Row() + 1, 5 PROMPT "Consulta Cadastro"
@ Row() + 1, 5 PROMPT "Protocolo NFE"
@ Row() + 1, 5 PROMPT "Protocolo CTE"
@ Row() + 1, 5 PROMPT "Protocolo MDFE"
// @ Row() + 1, 5 PROMPT "Consulta Destinadas"
MENU TO nOpc
nOpcTemp := 1
DO CASE
CASE LastKey() == K_ESC .OR. nOpc == nOpcTemp++
EXIT
CASE nOpc == nOpcTemp++
oSefaz:cCertificado := CapicomEscolheCertificado()
wapi_MessageBox( , oSefaz:cCertificado )
LOOP
CASE nOpc == nOpcTemp++
Scroll( 8, 0, MaxRow(), MaxCol(), 0 )
@ 8, 0 SAY "Qual UF:" GET oSefaz:cUF PICTURE "@!"
READ
CASE nOpc == nOpcTemp++
cXmlRetorno := oSefaz:NfeStatus()
wapi_MessageBox( , oSefaz:cXmlSoap, "XML enviado" )
wapi_MessageBox( , oSefaz:cXmlRetorno, "XML retornado" )
cTexto := "Tipo Ambiente:" + XmlNode( cXmlRetorno, "tpAmb" ) + HB_EOL()
cTexto += "Versão Aplicativo:" + XmlNode( cXmlRetorno, "verAplic" ) + HB_EOL()
cTexto += "Status:" + XmlNode( cXmlRetorno, "cStat" ) + HB_EOL()
cTexto += "Motivo:" + XmlNode( cXmlRetorno, "xMotivo" ) + HB_EOL()
cTexto += "UF:" + XmlNode( cXmlRetorno, "cUF" ) + HB_EOL()
cTexto += "Data/Hora:" + XmlNode( cXmlRetorno, "dhRecbto" ) + HB_EOL()
cTexto += "Tempo Médio:" + XmlNode( cXmlRetorno, "tMed" ) + HB_EOL()
wapi_MessageBox( , cTexto, "Informação Extraída" )
CASE nOpc == nOpcTemp++
Scroll( 8, 0, MaxRow(), MaxCol(), 0 )
@ 8, 0 SAY "UF" GET cUF PICTURE "@!"
@ 9, 0 SAY "CNPJ" GET cCnpj PICTURE "@R 99.999.999/9999-99"
READ
IF LastKey() == K_ESC
LOOP
ENDIF
Scroll( 8, 0, MaxRow(), MaxCol(), 0 )
oSefaz:cProjeto := "nfe"
cXmlRetorno := oSefaz:NfeCadastro( cCnpj, cUF )
wapi_MessageBox( , oSefaz:cXmlSoap, "XML Enviado" )
wapi_MessageBox( , oSefaz:cXmlRetorno, "XML Retornado" )
cTexto := "versao: " + XmlNode( cXmlRetorno, "versao" ) + HB_EOL()
cTexto += "Aplicativo:" + XmlNode( cXmlRetorno, "verAplic" ) + HB_EOL()
cTexto += "Status: " + XmlNode( cXmlRetorno, "cStat" ) + HB_EOL()
cTexto += "Motivo: " + XmlNode( cXmlRetorno, "xMotivo" ) + HB_EOL()
cTexto += "UF: " + XmlNode( cXmlRetorno, "UF" ) + HB_EOL()
cTexto += "IE: " + XmlNode( cXmlRetorno, "IE" ) + HB_EOL()
cTexto += "CNPJ: " + XmlNode( cXmlRetorno, "CNPJ" ) + HB_EOL()
cTexto += "CPF: " + XmlNode( cXmlRetorno, "CPF" ) + HB_EOL()
cTexto += "Data/Hora: " + XmlNode( cXmlRetorno, "dhCons" ) + HB_EOL()
cTexto += "UF: " + XmlNode( cXmlRetorno, "cUF" ) + HB_EOL()
cTexto += "Nome(1): " + XmlNode( cXmlRetorno, "xNome" ) + HB_EOL()
cTexto += "CNAE(1): " + XmlNode( cXmlRetorno, "CNAE" ) + HB_EOL()
cTexto += "Lograd(1): " + XmlNode( cXmlRetorno, "xLgr" ) + HB_EOL()
cTexto += "nro(1): " + XmlNode( cXmlRetorno, "nro" ) + HB_EOL()
cTexto += "Compl(1): " + XmlNode( cXmlRetorno, "xCpl" ) + HB_EOL()
cTexto += "Bairro(1): " + XmlNode( cXmlRetorno, "xBairro" ) + HB_EOL()
cTexto += "Cod.Mun(1):" + XmlNode( cXmlRetorno, "cMun" ) + HB_EOL()
cTexto += "Municip(1):" + XmlNode( cXmlRetorno, "xMun" ) + HB_EOL()
cTexto += "CEP(1): " + XmlNode( cXmlRetorno, "CEP" ) + HB_EOL()
cTexto += "Etc pode ter vários endereços..."
wapi_MessageBox( , cTexto, "Informação Extraída" )
CASE nOpc == nOpcTemp++
Scroll( 8, 0, MaxRow(), MaxCol(), 0 )
@ 8, 1 GET cChave PICTURE "@R 99-99/99-99.999.999/9999-99.99.999.999999999.9.99999999.9"
READ
IF LastKey() == K_ESC
EXIT
ENDIF
oSefaz:NfeConsulta( cChave )
wapi_MessageBox( , oSefaz:cXmlSoap )
wapi_MessageBox( , oSefaz:cXmlRetorno )
CASE nOpc == nOpcTemp++
Scroll( 8, 0, MaxRow(), MaxCol(), 0 )
@ 8, 1 GET cChave PICTURE "@R 99-99/99-99.999.999/9999-99.99.999.999999999.9.99999999.9"
READ
IF LastKey() == K_ESC
EXIT
ENDIF
oSefaz:CteConsulta( cChave, cCertificado )
wapi_MessageBox( , oSefaz:cXmlSoap )
wapi_MessageBox( , oSefaz:cXmlRetorno )
CASE nOpc == nOpcTemp++
Scroll( 8, 0, MaxRow(), MaxCol(), 0 )
@ 8, 1 GET cChave PICTURE "@R 99-99/99-99.999.999/9999-99.99.999.999999999.9.99999999.9"
READ
IF LastKey() == K_ESC
EXIT
ENDIF
oSefaz:MDFeConsulta( cChave, cCertificado )
wapi_MessageBox( , oSefaz:cXmlSoap )
wapi_MessageBox( , oSefaz:cXmlRetorno )
CASE nOpc == nOpcTemp
Scroll( 8, 0, MaxRow(), MaxCol(), 0 )
@ 9, 1 GET cCnpj PICTURE "@9"
READ
IF LastKey() == K_ESC
EXIT
ENDIF
oSefaz:nfeDistribuicaoDFe( cCnpj, "0" )
wapi_MessageBox( , oSefaz:cXmlSoap )
wapi_MessageBox( , oSefaz:cXmlRetorno )
oSefaz:nfeConsultaDest( cCnpj, "0" )
wapi_MessageBox( , oSefaz:cXmlSoap )
wapi_MessageBox( , oSefaz:cXmlRetorno )
ENDCASE
ENDDO
RETURN
FUNCTION SetupHarbour()
#ifndef __XHARBOUR__
hb_gtInfo( HB_GTI_INKEYFILTER, { | nKey | MyInkeyFilter( nKey ) } ) // pra funcionar control-V
#endif
SET( _SET_EVENTMASK, INKEY_ALL - INKEY_MOVE )
SET CONFIRM ON
RETURN NIL
#ifndef __XHARBOUR__
// rotina do ctrl-v
FUNCTION MyInkeyFilter( nKey )
LOCAL nBits, lIsKeyCtrl
nBits := hb_GtInfo( HB_GTI_KBDSHIFTS )
lIsKeyCtrl := ( nBits == hb_BitOr( nBits, HB_GTI_KBD_CTRL ) )
SWITCH nKey
CASE K_CTRL_V
IF lIsKeyCtrl
hb_GtInfo( HB_GTI_CLIPBOARDPASTE )
RETURN 0
ENDIF
ENDSWITCH
RETURN nKey
#endif