line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::TinyERP::NotaFiscal; |
2
|
3
|
|
|
3
|
|
20
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
83
|
|
3
|
3
|
|
|
3
|
|
18
|
use warnings; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
67
|
|
4
|
3
|
|
|
3
|
|
2452
|
use IO::Socket::SSL; |
|
3
|
|
|
|
|
254912
|
|
|
3
|
|
|
|
|
27
|
|
5
|
3
|
|
|
3
|
|
646
|
use Scalar::Util (); |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
63
|
|
6
|
3
|
|
|
3
|
|
1535
|
use Furl; |
|
3
|
|
|
|
|
66582
|
|
|
3
|
|
|
|
|
115
|
|
7
|
3
|
|
|
3
|
|
1372
|
use JSON::MaybeXS qw( decode_json encode_json ); |
|
3
|
|
|
|
|
16898
|
|
|
3
|
|
|
|
|
2046
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
1
|
|
|
1
|
0
|
4
|
my ($class, $parent) = @_; |
11
|
1
|
|
|
|
|
4
|
my $token = \$parent->{token}; |
12
|
1
|
|
|
|
|
5
|
Scalar::Util::weaken($token); |
13
|
1
|
|
|
|
|
11
|
bless { |
14
|
|
|
|
|
|
|
parent_token => $token, |
15
|
|
|
|
|
|
|
ua => Furl->new( |
16
|
|
|
|
|
|
|
timeout => 30, |
17
|
|
|
|
|
|
|
ssl_opts => { |
18
|
|
|
|
|
|
|
SSL_verify_mode => SSL_VERIFY_PEER(), |
19
|
|
|
|
|
|
|
}, |
20
|
|
|
|
|
|
|
), |
21
|
|
|
|
|
|
|
}, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub _post { |
25
|
0
|
|
|
0
|
|
0
|
my ($self, $url, $params) = @_; |
26
|
|
|
|
|
|
|
my $res = $self->{ua}->post($url, undef, { |
27
|
0
|
|
|
|
|
0
|
token => ${$self->{parent_token}}, |
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
formato => 'json', |
29
|
|
|
|
|
|
|
%$params, |
30
|
|
|
|
|
|
|
}); |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
0
|
if ($res->is_success) { |
33
|
0
|
|
|
|
|
0
|
my $content = decode_json($res->decoded_content); |
34
|
0
|
|
|
|
|
0
|
return $content->{retorno}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
else { |
37
|
0
|
|
|
|
|
0
|
return; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub pesquisar { |
42
|
4
|
|
|
4
|
1
|
3843
|
my ($self, $params) = @_; |
43
|
4
|
100
|
100
|
|
|
54
|
die 'pesquisar() precisa de HASHREF como argumento' |
|
|
|
100
|
|
|
|
|
44
|
|
|
|
|
|
|
unless $params and ref $params and ref $params eq 'HASH'; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
5
|
return $self->_post('https://api.tiny.com.br/api2/notas.fiscais.pesquisa.php', $params); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub obter { |
50
|
3
|
|
|
3
|
1
|
2727
|
my ($self, $id) = @_; |
51
|
3
|
100
|
100
|
|
|
38
|
die 'obter() precisa de argumento "id" numérico' |
52
|
|
|
|
|
|
|
unless $id && $id =~ /^\d+$/; |
53
|
|
|
|
|
|
|
|
54
|
1
|
|
|
|
|
7
|
return $self->_post('https://api.tiny.com.br/api2/nota.fiscal.obter.php', { |
55
|
|
|
|
|
|
|
id => $id, |
56
|
|
|
|
|
|
|
}); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub obter_xml { |
60
|
1
|
|
|
1
|
1
|
1373
|
die 'obter_xml() nao foi implementado'; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub obter_link { |
64
|
3
|
|
|
3
|
1
|
3042
|
my ($self, $id) = @_; |
65
|
3
|
100
|
100
|
|
|
36
|
die 'obter_link() precisa de argumento "id" numérico' |
66
|
|
|
|
|
|
|
unless $id && $id =~ /^\d+$/; |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
7
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.fiscal.obter.link.php', { |
69
|
|
|
|
|
|
|
id => $id, |
70
|
|
|
|
|
|
|
}); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub incluir { |
74
|
4
|
|
|
4
|
1
|
3370
|
my ($self, $params) = @_; |
75
|
4
|
100
|
100
|
|
|
55
|
die 'incluir() precisa de HASHREF como argumento' |
|
|
|
100
|
|
|
|
|
76
|
|
|
|
|
|
|
unless $params and ref $params and ref $params eq 'HASH'; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
19
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.fiscal.incluir.php', { |
79
|
|
|
|
|
|
|
nota => encode_json({ nota_fiscal => $params }), |
80
|
|
|
|
|
|
|
}); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub emitir { |
84
|
3
|
|
|
3
|
1
|
2701
|
my ($self, $params) = @_; |
85
|
3
|
50
|
|
|
|
11
|
if (ref $params) { |
86
|
|
|
|
|
|
|
die 'emitir() precisa de id ou serie/numero da nota' |
87
|
|
|
|
|
|
|
unless ( |
88
|
|
|
|
|
|
|
($params->{id} && $params->{id} =~ /\A\d+\z/) |
89
|
|
|
|
|
|
|
|| ($params->{serie} && $params->{numero}) |
90
|
0
|
0
|
0
|
|
|
0
|
); |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
else { |
93
|
3
|
|
|
|
|
6
|
my $id = $params; |
94
|
3
|
100
|
100
|
|
|
37
|
die 'emitir() precisa de pelo menos um argumento "id" numérico' |
95
|
|
|
|
|
|
|
unless $id && $id =~ /^\d+$/; |
96
|
1
|
|
|
|
|
4
|
$params = { id => $id }; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
|
|
5
|
return $self->_post( 'https://api.tiny.com.br/api2/nota.fiscal.emitir.php', |
100
|
|
|
|
|
|
|
$params |
101
|
|
|
|
|
|
|
); |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
__END__ |