-
-
Notifications
You must be signed in to change notification settings - Fork 740
/
InvoiceItemBase.java
291 lines (249 loc) · 9.27 KB
/
InvoiceItemBase.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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
/*
* Copyright 2010-2014 Ning, Inc.
* Copyright 2014-2016 Groupon, Inc
* Copyright 2014-2016 The Billing Project, LLC
*
* The Billing Project licenses this file to you under the Apache License, version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/
package org.killbill.billing.invoice.model;
import java.math.BigDecimal;
import java.util.UUID;
import javax.annotation.Nullable;
import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.killbill.billing.catalog.api.Currency;
import org.killbill.billing.entity.EntityBase;
import org.killbill.billing.invoice.api.InvoiceItem;
import org.killbill.billing.invoice.api.InvoiceItemType;
import org.killbill.billing.util.currency.KillBillMoney;
public abstract class InvoiceItemBase extends EntityBase implements InvoiceItem {
/* Common to all items */
protected final UUID invoiceId;
protected final UUID accountId;
protected final UUID childAccountId;
protected final LocalDate startDate;
protected final LocalDate endDate;
protected final BigDecimal amount;
protected final Currency currency;
protected final String description;
/* Fixed and recurring specific */
protected final UUID subscriptionId;
protected final UUID bundleId;
/* Recurring specific */
protected final BigDecimal rate;
/* RepairAdjInvoiceItem */
protected final UUID linkedItemId;
public InvoiceItemBase(final UUID id, @Nullable final DateTime createdDate, final UUID invoiceId, final UUID accountId, @Nullable final UUID bundleId,
@Nullable final UUID subscriptionId, @Nullable final String description,
final LocalDate startDate, final LocalDate endDate, final BigDecimal amount, final BigDecimal rate, final Currency currency, final UUID reversedItemId) {
this(id, createdDate, invoiceId, accountId, null, bundleId, subscriptionId, description, startDate, endDate, amount, rate, currency, reversedItemId);
}
// For parent invoices
public InvoiceItemBase(final UUID id, @Nullable final DateTime createdDate, final UUID invoiceId, final UUID accountId, final UUID childAccountId,
final BigDecimal amount, final Currency currency, final String description) {
this(id, createdDate, invoiceId, accountId, childAccountId, null, null, description, null, null, amount, null, currency, null);
}
private InvoiceItemBase(final UUID id, @Nullable final DateTime createdDate, final UUID invoiceId, final UUID accountId, @Nullable final UUID childAccountId, @Nullable final UUID bundleId,
@Nullable final UUID subscriptionId, @Nullable final String description,
@Nullable final LocalDate startDate, final LocalDate endDate, final BigDecimal amount, final BigDecimal rate, final Currency currency,
final UUID reversedItemId) {
super(id, createdDate, createdDate);
this.invoiceId = invoiceId;
this.accountId = accountId;
this.childAccountId = childAccountId;
this.subscriptionId = subscriptionId;
this.bundleId = bundleId;
this.description = description;
this.startDate = startDate;
this.endDate = endDate;
this.amount = amount == null || currency == null ? amount : KillBillMoney.of(amount, currency);
this.currency = currency;
this.rate = rate;
this.linkedItemId = reversedItemId;
}
@Override
public UUID getInvoiceId() {
return invoiceId;
}
@Override
public UUID getBundleId() {
return bundleId;
}
@Override
public UUID getAccountId() {
return accountId;
}
@Override
public UUID getSubscriptionId() {
return subscriptionId;
}
@Override
public BigDecimal getAmount() {
return amount;
}
@Override
public LocalDate getStartDate() {
return startDate;
}
@Override
public LocalDate getEndDate() {
return endDate;
}
@Override
public Currency getCurrency() {
return currency;
}
@Override
public BigDecimal getRate() {
return rate;
}
@Override
public UUID getLinkedItemId() {
return linkedItemId;
}
@Override
public UUID getChildAccountId() {
return childAccountId;
}
@Override
public String getPlanName() {
return null;
}
@Override
public String getPrettyPlanName() {
return null;
}
@Override
public String getPhaseName() {
return null;
}
@Override
public String getPrettyPhaseName() {
return null;
}
@Override
public String getUsageName() {
return null;
}
@Override
public String getPrettyUsageName() {
return null;
}
@Override
public boolean equals(final Object o) {
if (!matches(o)) {
return false;
}
final InvoiceItemBase that = (InvoiceItemBase) o;
if (!super.equals(that)) {
return false;
}
if (invoiceId != null ? !invoiceId.equals(that.invoiceId) : that.invoiceId != null) {
return false;
}
if (linkedItemId != null ? !linkedItemId.equals(that.linkedItemId) : that.linkedItemId != null) {
return false;
}
if (description != null ? !description.equals(that.description) : that.description != null) {
return false;
}
return true;
}
@Override
public boolean matches(final Object o) {
if (this == o) {
return true;
}
if (!(o instanceof InvoiceItemBase)) {
return false;
}
final InvoiceItemBase that = (InvoiceItemBase) o;
if (accountId != null ? !accountId.equals(that.accountId) : that.accountId != null) {
return false;
}
if (childAccountId != null ? !childAccountId.equals(that.childAccountId) : that.childAccountId != null) {
return false;
}
if (bundleId != null ? !bundleId.equals(that.bundleId) : that.bundleId != null) {
return false;
}
if (subscriptionId != null ? !subscriptionId.equals(that.subscriptionId) : that.subscriptionId != null) {
return false;
}
if (safeCompareTo(startDate, that.startDate) != 0) {
return false;
}
if (safeCompareTo(endDate, that.endDate) != 0) {
return false;
}
if (safeCompareTo(amount, that.amount) != 0) {
return false;
}
if (safeCompareTo(rate, that.rate) != 0) {
return false;
}
if (currency != that.currency) {
return false;
}
return true;
}
@Override
public int hashCode() {
int result = super.hashCode();
result = 31 * result + (invoiceId != null ? invoiceId.hashCode() : 0);
result = 31 * result + (accountId != null ? accountId.hashCode() : 0);
result = 31 * result + (childAccountId != null ? childAccountId.hashCode() : 0);
result = 31 * result + (startDate != null ? startDate.hashCode() : 0);
result = 31 * result + (endDate != null ? endDate.hashCode() : 0);
result = 31 * result + (amount != null ? amount.hashCode() : 0);
result = 31 * result + (currency != null ? currency.hashCode() : 0);
result = 31 * result + (subscriptionId != null ? subscriptionId.hashCode() : 0);
result = 31 * result + (bundleId != null ? bundleId.hashCode() : 0);
result = 31 * result + (description != null ? description.hashCode() : 0);
result = 31 * result + (rate != null ? rate.hashCode() : 0);
result = 31 * result + (linkedItemId != null ? linkedItemId.hashCode() : 0);
return result;
}
@Override
public String toString() {
// Note: we don't use all fields here, as the output would be overwhelming
// (we output all invoice items as they are generated).
final StringBuilder sb = new StringBuilder();
sb.append(getInvoiceItemType());
sb.append("{");
if (startDate != null) {
sb.append("startDate=").append(startDate);
}
if (endDate != null) {
sb.append("endDate=").append(endDate);
}
if (amount != null) {
sb.append("amount=").append(amount);
}
if (rate != null) {
sb.append("rate=").append(rate);
}
if (subscriptionId != null) {
sb.append("subscriptionId=").append(subscriptionId);
}
if (linkedItemId != null) {
sb.append("linkedItemId=").append(linkedItemId);
}
sb.append('}');
return sb.toString();
}
@Override
public abstract InvoiceItemType getInvoiceItemType();
@Override
public abstract String getDescription();
}