001/*
002 * Copyright 2010-2013 Ning, Inc.
003 *
004 * Ning licenses this file to you under the Apache License, version 2.0
005 * (the "License"); you may not use this file except in compliance with the
006 * License.  You may obtain a copy of the License at:
007 *
008 *    http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
013 * License for the specific language governing permissions and limitations
014 * under the License.
015 */
016
017package com.ning.billing.recurly.model;
018
019import javax.xml.bind.annotation.XmlElement;
020import javax.xml.bind.annotation.XmlElementWrapper;
021import javax.xml.bind.annotation.XmlRootElement;
022
023import org.joda.time.DateTime;
024
025@XmlRootElement(name = "invoice")
026public class Invoice extends RecurlyObject {
027
028    @XmlElement(name = "account")
029    private Account account;
030
031    @XmlElement(name = "uuid")
032    private String uuid;
033
034    @XmlElement(name = "state")
035    private String state;
036
037    @XmlElement(name = "invoice_number")
038    private Integer invoiceNumber;
039
040    @XmlElement(name = "po_number")
041    private Integer poNumber;
042
043    @XmlElement(name = "vat_number")
044    private String vatNumber;
045
046    @XmlElement(name = "subtotal_in_cents")
047    private Integer subtotalInCents;
048
049    @XmlElement(name = "tax_in_cents")
050    private Integer taxInCents;
051
052    @XmlElement(name = "total_in_cents")
053    private Integer totalInCents;
054
055    @XmlElement(name = "currency")
056    private String currency;
057
058    @XmlElement(name = "created_at")
059    private DateTime createdAt;
060
061    @XmlElementWrapper(name = "line_items")
062    @XmlElement(name = "adjustment")
063    private Adjustments adjustments;
064
065    @XmlElementWrapper(name = "transactions")
066    @XmlElement(name = "transaction")
067    private Transactions transactions;
068
069    public Account getAccount() {
070        if (account != null && account.getCreatedAt() == null) {
071            account = fetch(account, Account.class);
072        }
073        return account;
074    }
075
076    public void setAccount(final Account account) {
077        this.account = account;
078    }
079
080    public String getUuid() {
081        return uuid;
082    }
083
084    public void setUuid(final Object uuid) {
085        this.uuid = stringOrNull(uuid);
086    }
087
088    public String getState() {
089        return state;
090    }
091
092    public void setState(final Object state) {
093        this.state = stringOrNull(state);
094    }
095
096    public Integer getInvoiceNumber() {
097        return invoiceNumber;
098    }
099
100    public void setInvoiceNumber(final Object invoiceNumber) {
101        this.invoiceNumber = integerOrNull(invoiceNumber);
102    }
103
104    public Integer getPoNumber() {
105        return poNumber;
106    }
107
108    public void setPoNumber(final Object poNumber) {
109        this.poNumber = integerOrNull(poNumber);
110    }
111
112    public String getVatNumber() {
113        return vatNumber;
114    }
115
116    public void setVatNumber(final String varNumber) {
117        this.vatNumber = stringOrNull(varNumber);
118    }
119
120    public Integer getSubtotalInCents() {
121        return subtotalInCents;
122    }
123
124    public void setSubtotalInCents(final Object subtotalInCents) {
125        this.subtotalInCents = integerOrNull(subtotalInCents);
126    }
127
128    public Integer getTaxInCents() {
129        return taxInCents;
130    }
131
132    public void setTaxInCents(final Object taxInCents) {
133        this.taxInCents = integerOrNull(taxInCents);
134    }
135
136    public Integer getTotalInCents() {
137        return totalInCents;
138    }
139
140    public void setTotalInCents(final Object totalInCents) {
141        this.totalInCents = integerOrNull(totalInCents);
142    }
143
144    public String getCurrency() {
145        return currency;
146    }
147
148    public void setCurrency(final Object currency) {
149        this.currency = stringOrNull(currency);
150    }
151
152    public DateTime getCreatedAt() {
153        return createdAt;
154    }
155
156    public void setCreatedAt(final Object createdAt) {
157        this.createdAt = dateTimeOrNull(createdAt);
158    }
159
160    public Adjustments getLineItems() {
161        return adjustments;
162    }
163
164    public void setLineItems(final Adjustments lineItems) {
165        this.adjustments = adjustments;
166    }
167
168    public Transactions getTransactions() {
169        return transactions;
170    }
171
172    public void setTransactions(final Transactions transactions) {
173        this.transactions = transactions;
174    }
175
176    @Override
177    public String toString() {
178        final StringBuilder sb = new StringBuilder();
179        sb.append("Invoice");
180        sb.append("{account=").append(account);
181        sb.append(", uuid='").append(uuid).append('\'');
182        sb.append(", state='").append(state).append('\'');
183        sb.append(", invoiceNumber=").append(invoiceNumber);
184        sb.append(", poNumber=").append(poNumber);
185        sb.append(", varNumber=").append(vatNumber);
186        sb.append(", subtotalInCents=").append(subtotalInCents);
187        sb.append(", taxInCents=").append(taxInCents);
188        sb.append(", totalInCents=").append(totalInCents);
189        sb.append(", currency='").append(currency).append('\'');
190        sb.append(", createdAt=").append(createdAt);
191        sb.append(", lineItems=").append(adjustments);
192        sb.append(", transactions=").append(transactions);
193        sb.append('}');
194        return sb.toString();
195    }
196
197    @Override
198    public boolean equals(final Object o) {
199        if (this == o) {
200            return true;
201        }
202        if (o == null || getClass() != o.getClass()) {
203            return false;
204        }
205
206        final Invoice invoice = (Invoice) o;
207
208        if (account != null ? !account.equals(invoice.account) : invoice.account != null) {
209            return false;
210        }
211        if (createdAt != null ? !createdAt.equals(invoice.createdAt) : invoice.createdAt != null) {
212            return false;
213        }
214        if (currency != null ? !currency.equals(invoice.currency) : invoice.currency != null) {
215            return false;
216        }
217        if (invoiceNumber != null ? !invoiceNumber.equals(invoice.invoiceNumber) : invoice.invoiceNumber != null) {
218            return false;
219        }
220        if (adjustments != null ? !adjustments.equals(invoice.adjustments) : invoice.adjustments != null) {
221            return false;
222        }
223        if (poNumber != null ? !poNumber.equals(invoice.poNumber) : invoice.poNumber != null) {
224            return false;
225        }
226        if (state != null ? !state.equals(invoice.state) : invoice.state != null) {
227            return false;
228        }
229        if (subtotalInCents != null ? !subtotalInCents.equals(invoice.subtotalInCents) : invoice.subtotalInCents != null) {
230            return false;
231        }
232        if (taxInCents != null ? !taxInCents.equals(invoice.taxInCents) : invoice.taxInCents != null) {
233            return false;
234        }
235        if (totalInCents != null ? !totalInCents.equals(invoice.totalInCents) : invoice.totalInCents != null) {
236            return false;
237        }
238        if (transactions != null ? !transactions.equals(invoice.transactions) : invoice.transactions != null) {
239            return false;
240        }
241        if (uuid != null ? !uuid.equals(invoice.uuid) : invoice.uuid != null) {
242            return false;
243        }
244        if (vatNumber != null ? !vatNumber.equals(invoice.vatNumber) : invoice.vatNumber != null) {
245            return false;
246        }
247
248        return true;
249    }
250
251    @Override
252    public int hashCode() {
253        int result = account != null ? account.hashCode() : 0;
254        result = 31 * result + (uuid != null ? uuid.hashCode() : 0);
255        result = 31 * result + (state != null ? state.hashCode() : 0);
256        result = 31 * result + (invoiceNumber != null ? invoiceNumber.hashCode() : 0);
257        result = 31 * result + (poNumber != null ? poNumber.hashCode() : 0);
258        result = 31 * result + (vatNumber != null ? vatNumber.hashCode() : 0);
259        result = 31 * result + (subtotalInCents != null ? subtotalInCents.hashCode() : 0);
260        result = 31 * result + (taxInCents != null ? taxInCents.hashCode() : 0);
261        result = 31 * result + (totalInCents != null ? totalInCents.hashCode() : 0);
262        result = 31 * result + (currency != null ? currency.hashCode() : 0);
263        result = 31 * result + (createdAt != null ? createdAt.hashCode() : 0);
264        result = 31 * result + (adjustments != null ? adjustments.hashCode() : 0);
265        result = 31 * result + (transactions != null ? transactions.hashCode() : 0);
266        return result;
267    }
268}