1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* MIT License |
4
|
|
|
* |
5
|
|
|
* Copyright (c) 2016 MZ Desenvolvimento de Sistemas LTDA |
6
|
|
|
* |
7
|
|
|
* @author Francimar Alves <[email protected]> |
8
|
|
|
* |
9
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
10
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
11
|
|
|
* in the Software without restriction, including without limitation the rights |
12
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
13
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
14
|
|
|
* furnished to do so, subject to the following conditions: |
15
|
|
|
* |
16
|
|
|
* The above copyright notice and this permission notice shall be included in all |
17
|
|
|
* copies or substantial portions of the Software. |
18
|
|
|
* |
19
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
20
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
21
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
22
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
23
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
24
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
25
|
|
|
* SOFTWARE. |
26
|
|
|
* |
27
|
|
|
*/ |
28
|
|
|
namespace NFe\Task; |
29
|
|
|
|
30
|
|
|
use NFe\Common\Util; |
31
|
|
|
|
32
|
|
|
class Retorno extends Status |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
private $data_recebimento; |
36
|
|
|
|
37
|
28 |
|
public function __construct($retorno = array()) |
38
|
|
|
{ |
39
|
28 |
|
parent::__construct($retorno); |
40
|
28 |
|
} |
41
|
|
|
|
42
|
11 |
|
public function getDataRecebimento($normalize = false) |
43
|
|
|
{ |
44
|
11 |
|
if (!$normalize || is_null($this->data_recebimento)) { |
45
|
10 |
|
return $this->data_recebimento; |
46
|
|
|
} |
47
|
5 |
|
return Util::toDateTime($this->data_recebimento); |
48
|
|
|
} |
49
|
|
|
|
50
|
28 |
|
public function setDataRecebimento($data_recebimento) |
51
|
|
|
{ |
52
|
28 |
|
if (!is_null($data_recebimento) && !is_numeric($data_recebimento)) { |
53
|
15 |
|
$data_recebimento = strtotime($data_recebimento); |
54
|
15 |
|
} |
55
|
28 |
|
$this->data_recebimento = $data_recebimento; |
56
|
28 |
|
return $this; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Informa se a nota foi autorizada no prazo ou fora do prazo |
61
|
|
|
*/ |
62
|
8 |
|
public function isAutorizado() |
63
|
|
|
{ |
64
|
8 |
|
return in_array($this->getStatus(), array('100', '150')); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Informa se a nota está cancelada |
69
|
|
|
*/ |
70
|
1 |
|
public function isCancelado() |
71
|
|
|
{ |
72
|
1 |
|
return in_array($this->getStatus(), array('101', '151')); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Informa se o lote já foi processado e já tem um protocolo |
77
|
|
|
*/ |
78
|
7 |
|
public function isProcessado() |
79
|
|
|
{ |
80
|
7 |
|
return $this->getStatus() == '104'; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Informa se o lote foi recebido com sucesso |
85
|
|
|
*/ |
86
|
2 |
|
public function isRecebido() |
87
|
|
|
{ |
88
|
2 |
|
return in_array($this->getStatus(), array('103', '105')); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* Informa se a nota foi denegada |
93
|
|
|
*/ |
94
|
1 |
|
public function isDenegada() |
95
|
|
|
{ |
96
|
1 |
|
return in_array($this->getStatus(), array('110', '301', '302', '303')); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Informa se a nota da consulta não foi autorizada ou se não existe |
101
|
|
|
*/ |
102
|
1 |
|
public function isInexistente() |
103
|
|
|
{ |
104
|
1 |
|
return $this->getStatus() == '217'; |
105
|
|
|
} |
106
|
|
|
|
107
|
10 |
|
public function toArray($recursive = false) |
108
|
|
|
{ |
109
|
10 |
|
$retorno = parent::toArray($recursive); |
110
|
10 |
|
$retorno['data_recebimento'] = $this->getDataRecebimento($recursive); |
111
|
10 |
|
return $retorno; |
112
|
|
|
} |
113
|
|
|
|
114
|
28 |
|
public function fromArray($retorno = array()) |
115
|
|
|
{ |
116
|
28 |
|
if ($retorno instanceof Retorno) { |
117
|
1 |
|
$retorno = $retorno->toArray(); |
118
|
28 |
|
} elseif (!is_array($retorno)) { |
119
|
1 |
|
return $this; |
120
|
|
|
} |
121
|
28 |
|
parent::fromArray($retorno); |
122
|
28 |
|
if (isset($retorno['data_recebimento'])) { |
123
|
8 |
|
$this->setDataRecebimento($retorno['data_recebimento']); |
124
|
8 |
|
} else { |
125
|
28 |
|
$this->setDataRecebimento(null); |
126
|
|
|
} |
127
|
28 |
|
return $this; |
128
|
|
|
} |
129
|
|
|
|
130
|
5 |
|
public function getNode($name = null) |
131
|
|
|
{ |
132
|
5 |
|
$element = parent::getNode(is_null($name)?'':$name); |
133
|
5 |
|
$dom = $element->ownerDocument; |
|
|
|
|
134
|
5 |
|
$status = $element->getElementsByTagName('cStat')->item(0); |
135
|
5 |
|
if (!is_null($this->getDataRecebimento())) { |
136
|
4 |
|
Util::appendNode($element, 'dhRecbto', $this->getDataRecebimento(true), $status); |
137
|
4 |
|
} |
138
|
5 |
|
return $element; |
139
|
|
|
} |
140
|
|
|
|
141
|
17 |
|
public function loadNode($element, $name = null) |
142
|
|
|
{ |
143
|
17 |
|
$name = is_null($name)?'Retorno':$name; |
144
|
17 |
|
$retorno = parent::loadNode($element, $name); |
145
|
17 |
|
$this->setDataRecebimento(Util::loadNode($retorno, 'dhRecbto')); |
146
|
17 |
|
return $retorno; |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.