forked from mstahv/jpa-invoicer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoicer
163 lines (124 loc) · 3.9 KB
/
Invoicer
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
package org.example.backend;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Pattern;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
@Entity
@NamedQueries({})
@XmlRootElement
public class Invoicer extends AbstractEntity {
@OneToMany(mappedBy = "invoicer", fetch = FetchType.LAZY)
private List<Product> products = new ArrayList<>();
@Lob
@Basic(fetch=FetchType.EAGER)
private byte[] template;
@NotNull(message = "Name is required")
@Size(min = 3, max = 40, message = "name must be longer than 3 and less than 40 characters")
private String name;
@NotNull(message = "Address is required")
@Size(min = 1, max = 60, message = "Max 60 characters")
private String address;
@NotNull(message = "Phone is required")
@Size(min = 1, max = 60, message = "Max 60 characters")
private String phone;
@NotNull(message = "Email is required")
@Pattern(regexp = ".+@.+\\.[a-z]+", message = "Must be valid email")
@Size(min = 3, max = 40, message = "name must be longer than 3 and less than 40 characters")
private String email;
@NotNull
private String bankAccount;
private int nextInvoiceNumber = 1;
private int nextOrderNumber = 1;
@OneToMany(mappedBy = "invoicer")
private List<Invoice> invoices = new ArrayList<>();
@ManyToMany(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY)
private List<User> administrators = new ArrayList<>();
@XmlTransient
public byte[] getTemplate() {
return template;
}
public void setTemplate(byte[] template) {
this.template = template;
}
public int getNextInvoiceNumber() {
return nextInvoiceNumber;
}
public void setNextInvoiceNumber(int nextInvoiceNumber) {
this.nextInvoiceNumber = nextInvoiceNumber;
}
public String getBankAccount() {
return bankAccount;
}
public void setBankAccount(String bankAccount) {
this.bankAccount = bankAccount;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public List<Invoice> getInvoices() {
return invoices;
}
public void setInvoices(List<Invoice> invoices) {
this.invoices = invoices;
}
public List<User> getAdministrators() {
return administrators;
}
public void setAdministrators(List<User> administrators) {
this.administrators = administrators;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public List<Product> getProducts() {
return products;
}
public void setProducts(List<Product> products) {
this.products = products;
}
@Override
public String toString() {
return name;
}
public Integer getAndIcrementNextInvoiceNumber() {
return nextInvoiceNumber++;
}
public int getNextOrderNumber() {
return nextOrderNumber;
}
public void setNextOrderNumber(int nextOrderNumber) {
this.nextOrderNumber = nextOrderNumber;
}
public Integer getAndIcrementNextOrderNumber() {
return nextOrderNumber++;
}
}