-
-
Notifications
You must be signed in to change notification settings - Fork 357
/
Copy pathTicketReservation.java
260 lines (235 loc) · 9.81 KB
/
TicketReservation.java
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
/**
* This file is part of alf.io.
*
* alf.io is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* alf.io is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with alf.io. If not, see <http://www.gnu.org/licenses/>.
*/
package alfio.model;
import alfio.model.transaction.PaymentProxy;
import alfio.util.MonetaryUtil;
import ch.digitalfondue.npjt.ConstructorAnnotationRowMapper.Column;
import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import java.math.BigDecimal;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.*;
@Getter
public class TicketReservation implements PriceContainer {
public enum TicketReservationStatus {
PENDING,
IN_PAYMENT,
EXTERNAL_PROCESSING_PAYMENT,
WAITING_EXTERNAL_CONFIRMATION,
OFFLINE_PAYMENT,
DEFERRED_OFFLINE_PAYMENT,
/**
* Reservation is in the process of being finalized
*/
FINALIZING,
/**
* Special finalization status for OFFLINE payment
*/
OFFLINE_FINALIZING,
COMPLETE,
STUCK,
CANCELLED,
CREDIT_NOTE_ISSUED
}
private final String id;
private final Date validity;
private final TicketReservationStatus status;
private final String fullName;
private final String firstName;
private final String lastName;
private final String email;
private final String billingAddress;
private final ZonedDateTime confirmationTimestamp;
private final ZonedDateTime latestReminder;
private final PaymentProxy paymentMethod;
private final Boolean reminderSent;
private final Integer promoCodeDiscountId;
private final boolean automatic;
private final String userLanguage;
private final boolean directAssignmentRequested;
private final String invoiceNumber;
@JsonIgnore
private final String invoiceModel;
private final PriceContainer.VatStatus vatStatus;
private final String vatNr;
private final String vatCountryCode;
private final boolean invoiceRequested;
private final BigDecimal usedVatPercent;
private final Boolean vatIncluded;
private final ZonedDateTime creationTimestamp;
private final String customerReference;
private final ZonedDateTime registrationTimestamp;
private final int srcPriceCts;
private final int finalPriceCts;
private final int vatCts;
private final int discountCts;
private final String currencyCode;
public TicketReservation(@Column("id") String id,
@Column("validity") Date validity,
@Column("status") TicketReservationStatus status,
@Column("full_name") String fullName,
@Column("first_name") String firstName,
@Column("last_name") String lastName,
@Column("email_address") String email,
@Column("billing_address") String billingAddress,
@Column("confirmation_ts") ZonedDateTime confirmationTimestamp,
@Column("latest_reminder_ts") ZonedDateTime latestReminder,
@Column("payment_method") PaymentProxy paymentMethod,
@Column("offline_payment_reminder_sent") Boolean reminderSent,
@Column("promo_code_id_fk") Integer promoCodeDiscountId,
@Column("automatic") boolean automatic,
@Column("user_language") String userLanguage,
@Column("direct_assignment") boolean directAssignmentRequested,
@Column("invoice_number") String invoiceNumber,
@Column("invoice_model") String invoiceModel,
@Column("vat_status") PriceContainer.VatStatus vatStatus,
@Column("vat_nr") String vatNr,
@Column("vat_country") String vatCountryCode,
@Column("invoice_requested") boolean invoiceRequested,
@Column("used_vat_percent") BigDecimal usedVatPercent,
@Column("vat_included") Boolean vatIncluded,
@Column("creation_ts") ZonedDateTime creationTimestamp,
@Column("customer_reference") String customerReference,
@Column("registration_ts") ZonedDateTime registrationTimestamp,
@Column("src_price_cts") Integer srcPriceCts,
@Column("final_price_cts") Integer finalPriceCts,
@Column("vat_cts") Integer vatCts,
@Column("discount_cts") Integer discountCts,
@Column("currency_code") String currencyCode) {
this.id = id;
this.validity = validity;
this.status = status;
this.fullName = fullName;
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.billingAddress = billingAddress;
this.confirmationTimestamp = confirmationTimestamp;
this.latestReminder = latestReminder;
this.paymentMethod = paymentMethod;
this.reminderSent = reminderSent;
this.promoCodeDiscountId = promoCodeDiscountId;
this.automatic = automatic;
this.userLanguage = userLanguage;
this.directAssignmentRequested = directAssignmentRequested;
this.invoiceNumber = invoiceNumber;
this.invoiceModel = invoiceModel;
this.vatStatus = vatStatus;
this.vatNr = vatNr;
this.vatCountryCode = vatCountryCode;
this.invoiceRequested = invoiceRequested;
this.usedVatPercent = usedVatPercent;
this.vatIncluded = vatIncluded;
this.creationTimestamp = creationTimestamp;
this.registrationTimestamp = registrationTimestamp;
this.customerReference = customerReference;
this.srcPriceCts = Optional.ofNullable(srcPriceCts).orElse(0);
this.finalPriceCts = Optional.ofNullable(finalPriceCts).orElse(0);
this.vatCts = Optional.ofNullable(vatCts).orElse(0);
this.discountCts = Optional.ofNullable(discountCts).orElse(0);
this.currencyCode = currencyCode;
}
public boolean isStuck() {
return status == TicketReservationStatus.STUCK;
}
public boolean isReminderSent() {
return Optional.ofNullable(reminderSent).orElse(false);
}
public boolean getHasBillingAddress() {
return StringUtils.isNotBlank(billingAddress);
}
public Optional<ZonedDateTime> latestNotificationTimestamp(ZoneId zoneId) {
return Optional.ofNullable(latestReminder).map(d -> d.withZoneSameInstant(zoneId));
}
public String getFullName() {
return (firstName != null && lastName != null) ? (firstName + " " + lastName) : fullName;
}
public boolean getHasInvoiceNumber() {
return invoiceNumber != null;
}
public boolean getHasInvoiceOrReceiptDocument() {
return invoiceModel != null;
}
public boolean getHasBeenPaid() {
return status == TicketReservationStatus.COMPLETE && !EnumSet.of(PaymentProxy.NONE, PaymentProxy.ADMIN).contains(paymentMethod);
}
public boolean getHasVatNumber() {
return StringUtils.isNotEmpty(vatNr);
}
public List<String> getLineSplittedBillingAddress() {
if(billingAddress == null) {
return Collections.emptyList();
}
return Arrays.asList(StringUtils.split(billingAddress, '\n'));
}
public boolean isCancelled() {
return status == TicketReservationStatus.CANCELLED;
}
public String getPaidAmount() {
if(finalPriceCts > 0) {
return MonetaryUtil.formatCents(finalPriceCts, currencyCode);
}
return null;
}
public TicketReservation withVatStatus(PriceContainer.VatStatus vatStatus) {
if (this.vatStatus == vatStatus) {
return this;
}
return new TicketReservation(this.id,
this.validity,
this.status,
this.fullName,
this.firstName,
this.lastName,
this.email,
this.billingAddress,
this.confirmationTimestamp,
this.latestReminder,
this.paymentMethod,
this.reminderSent,
this.promoCodeDiscountId,
this.automatic,
this.userLanguage,
this.directAssignmentRequested,
this.invoiceNumber,
this.invoiceModel,
vatStatus,
this.vatNr,
this.vatCountryCode,
this.invoiceRequested,
this.usedVatPercent,
this.vatIncluded,
this.creationTimestamp,
this.customerReference,
this.registrationTimestamp,
this.srcPriceCts,
this.finalPriceCts,
this.vatCts,
this.discountCts,
this.currencyCode);
}
@Override
public Optional<BigDecimal> getOptionalVatPercentage() {
return Optional.ofNullable(usedVatPercent);
}
public boolean isPendingOfflinePayment() {
return status == TicketReservationStatus.OFFLINE_PAYMENT
|| status == TicketReservationStatus.DEFERRED_OFFLINE_PAYMENT;
}
}