-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFatura.java
More file actions
266 lines (234 loc) · 6.76 KB
/
Fatura.java
File metadata and controls
266 lines (234 loc) · 6.76 KB
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/**
* Classe que representa a fatura de uma entidade
*
* @author GC-JRI-RV
* @version 15/04/2018
*/
import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.ArrayList;
public class Fatura implements Serializable{
/** Nif do emitente */
private String nifEmitente;
/** Data da fatura */
private LocalDateTime data;
/** Nif do cliente */
private String nifCliente;
/** Descrição da fatura */
private String descricao;
/** Atividade económica da fatura */
private String atividade;
/** Atividades económicas anteriores */
private ArrayList<String> atividadesAnteriores;
/** Valor da fatura */
private double valor;
/**
* Construtor por omissão
*/
public Fatura(){
this.nifEmitente = "";
this.data = LocalDateTime.now();
this.nifCliente = "";
this.descricao = "";
this.atividade = "";
this.atividadesAnteriores = new ArrayList<String>();
this.valor = 0.0;
}
/**
* Construtor por parametro
* @param nifEmitente
* @param data
* @param nifCliente
* @param descricao
* @param atividade
* @param atividadesAnteriores
* @param valor
*/
public Fatura(String nifEmitente, LocalDateTime data, String nifCliente, String descricao, String atividade, ArrayList<String> atividadesAnteriores, double valor){
this.nifEmitente = nifEmitente;
this.data = data;
this.nifCliente = nifCliente;
this.descricao = descricao;
this.atividade = atividade;
this.atividadesAnteriores = new ArrayList<String>(atividadesAnteriores.size());
for (String s: atividadesAnteriores)
this.atividadesAnteriores.add(s);
this.valor = valor;
}
/**
* Contrutor por cópia
* @param f Fatura original
*/
public Fatura(Fatura f){
this.nifEmitente = f.getNIFEmitente();
this.data = f.getData();
this.nifCliente = f.getNIFCliente();
this.descricao = f.getDescricao();
this.atividade = f.getAtividade();
this.atividadesAnteriores = new ArrayList<String>(f.getAtividadesAnteriores().size());
for (String s: f.getAtividadesAnteriores())
this.atividadesAnteriores.add(s);
this.valor = f.getValor();
}
/**
* Devolve o nif do emitente
* @return nif
*/
public String getNIFEmitente(){
return this.nifEmitente;
}
/**
* Devolve a data da emissão
* @return data
*/
public LocalDateTime getData(){
return this.data;
}
/**
* Devolve o nif do cliente
* @return nif
*/
public String getNIFCliente(){
return this.nifCliente;
}
/**
* Devolve a descrição da fatura
* @return descrição
*/
public String getDescricao(){
return this.descricao;
}
/**
* Devolve a atividade económica
* @return atividade económica
*/
public String getAtividade(){
return this.atividade;
}
/**
* Devolve as atividades económicas anteriores
* @return atividades económicas anteriores
*/
public ArrayList<String> getAtividadesAnteriores() {
ArrayList<String> res = new ArrayList<String>(this.atividadesAnteriores.size());
for (String s: this.atividadesAnteriores)
res.add(s);
return res;
}
/**
* Devolve o valor
* @return valor
*/
public double getValor(){
return this.valor;
}
/**
* Atualiza valor de atividade
* @param atividade
*/
public void setAtividade(String atividade){
this.atividadesAnteriores.add(this.atividade);
this.atividade = atividade;
}
/**
* Define o nif do emitente
* @param nifEmitente
*/
public void setNIFEmitente(String nifEmitente){
this.nifEmitente = nifEmitente;
}
/**
* Define a data
* @param data
*/
public void setData(LocalDateTime data){
this.data = data;
}
/**
* Define o nif do cliente
* @param nifCliente
*/
public void setNIFCliente(String nifCliente){
this.nifCliente = nifCliente;
}
/**
* Define a descrição
* @param descrição
*/
public void setDescricao(String descricao){
this.descricao = descricao;
}
/**
* Define as atividades anteriores
* @param atividadesAnteriores
*/
public void setAtividadesAnteriores(ArrayList<String> atividadesAnteriores){
ArrayList<String> res = new ArrayList<String>(atividadesAnteriores.size());
for (String s: atividadesAnteriores)
res.add(s);
this.atividadesAnteriores = res;
}
/**
* Define o valor
* @param valor
*/
public void setValor(double valor){
this.valor = valor;
}
/**
* Diz se a fatura está pedente
* @return true se está pendente, false se não estiver
*/
public boolean estaPendente(){
return this.atividade.equals("");
}
/**
* Cria uma cópia do objecto
* @return cópia do objeto
*/
public Fatura clone(){
return new Fatura(this);
}
/**
* Verifica a igualdade de dois objectos
* @param o
* @return true se existe igualdade, false se não houver igualdade
*/
public boolean equals(Object o){
if(this == o)
return true;
if( (o == null) || (this.getClass() != o.getClass()))
return false;
Fatura f = (Fatura) o;
return(this.nifEmitente.equals(f.getNIFEmitente()) &&
this.data.equals(f.getData()) &&
this.nifCliente.equals(f.getNIFCliente()) &&
this.descricao.equals(f.getDescricao()) &&
this.atividade.equals(f.getAtividade()) &&
this.valor == f.getValor());
}
/**
* Contrói a fatura em String
* @return fatura em String
*/
public String toString(){
StringBuilder s = new StringBuilder();
s.append("Fatura emitida por " + this.nifEmitente + " em " + this.data.toLocalDate() + " às " + this.data.toLocalTime() + "\n");
s.append("Ao contribuinte " + this.nifCliente + " no valor de " + this.valor + "€\n");
s.append("Descrição: " + this.descricao + "\n");
if (this.estaPendente())
s.append("Atividade económica atual: (PENDENTE)\n");
else
s.append("Atividade económica atual: " + this.atividade + "\n");
if (this.atividadesAnteriores.size() > 0) {
s.append("Histórico de atividades económicas:\n");
for (String atv: this.atividadesAnteriores) {
if (atv.equals(""))
s.append("\t-> (PENDENTE)\n");
else
s.append("\t-> " + atv + "\n");
}
}
return s.toString();
}
}