001package io.konik.csv.model; 002 003import java.math.BigDecimal; 004import java.util.Arrays; 005import java.util.Date; 006import java.util.LinkedList; 007import java.util.List; 008 009import com.google.common.base.Objects; 010import com.neovisionaries.i18n.CountryCode; 011import com.neovisionaries.i18n.CurrencyCode; 012 013import io.konik.zugferd.unece.codes.Reference; 014import io.konik.zugferd.unece.codes.UnitOfMeasurement; 015 016/** 017 * Object representation of a single row in CSV file containing {@link io.konik.zugferd.Invoice}s 018 */ 019public final class Row { 020 021 private Header header = new Header(); 022 023 private TradeParty recipient = new TradeParty(); 024 025 private TradeParty issuer = new TradeParty(); 026 027 private List<Item> items = new LinkedList<Item>(); 028 029 private String comments = ""; 030 031 private String paymentReference = ""; 032 033 private File file = new File(); 034 035 public Header getHeader() { 036 return header; 037 } 038 039 public void setHeader(Header header) { 040 this.header = header; 041 } 042 043 public TradeParty getRecipient() { 044 return recipient; 045 } 046 047 public void setRecipient(TradeParty recipient) { 048 this.recipient = recipient; 049 } 050 051 public TradeParty getIssuer() { 052 return issuer; 053 } 054 055 public void setIssuer(TradeParty issuer) { 056 this.issuer = issuer; 057 } 058 059 public List<Item> getItems() { 060 return items; 061 } 062 063 public void setItems(List<Item> items) { 064 this.items = items; 065 } 066 067 public String getComments() { 068 return comments; 069 } 070 071 public void setComments(String comments) { 072 this.comments = comments; 073 } 074 075 public String getPaymentReference() { 076 return paymentReference; 077 } 078 079 public void setPaymentReference(String paymentReference) { 080 this.paymentReference = paymentReference; 081 } 082 083 public File getFile() { 084 return file; 085 } 086 087 public void setFile(File file) { 088 this.file = file; 089 } 090 091 @Override 092 public boolean equals(Object o) { 093 if (this == o) return true; 094 if (!(o instanceof Row)) return false; 095 Row row = (Row) o; 096 return Objects.equal(header, row.header) && Objects.equal(recipient, row.recipient) 097 && Objects.equal(issuer, row.issuer) && Objects.equal(items, row.items) 098 && Objects.equal(comments, row.comments) && Objects.equal(paymentReference, row.paymentReference) 099 && Objects.equal(file, row.file); 100 } 101 102 @Override 103 public int hashCode() { 104 return Objects.hashCode(header, recipient, issuer, items, comments, paymentReference, file); 105 } 106 107 @Override 108 public String toString() { 109 return "Row {" + "header=" + header + ", recipient=" + recipient + ", issuer=" + issuer + ", items=" + items 110 + ", comments='" + comments + '\'' + ", paymentReference='" + paymentReference + '\'' + ", file=" + file 111 + '}'; 112 } 113 114 public static final class Header { 115 private String invoiceNumber = ""; 116 private String type = ""; 117 private Date issued; 118 private Date dueDate; 119 private String note = ""; 120 private String reference = ""; 121 private String customerNumber = ""; 122 private CurrencyCode currency = CurrencyCode.EUR; 123 124 public String getInvoiceNumber() { 125 return invoiceNumber; 126 } 127 128 public Header setInvoiceNumber(String invoiceNumber) { 129 this.invoiceNumber = invoiceNumber; 130 return this; 131 } 132 133 public String getType() { 134 return type; 135 } 136 137 public Header setType(String type) { 138 this.type = type; 139 return this; 140 } 141 142 public Date getIssued() { 143 return issued; 144 } 145 146 public Header setIssued(Date issued) { 147 this.issued = issued; 148 return this; 149 } 150 151 public Date getDueDate() { 152 return dueDate; 153 } 154 155 public Header setDueDate(Date dueDate) { 156 this.dueDate = dueDate; 157 return this; 158 } 159 160 public String getNote() { 161 return note; 162 } 163 164 public Header setNote(String note) { 165 this.note = note; 166 return this; 167 } 168 169 public String getReference() { 170 return reference; 171 } 172 173 public Header setReference(String reference) { 174 this.reference = reference; 175 return this; 176 } 177 178 public String getCustomerNumber() { 179 return customerNumber; 180 } 181 182 public Header setCustomerNumber(String customerNumber) { 183 this.customerNumber = customerNumber; 184 return this; 185 } 186 187 public CurrencyCode getCurrency() { 188 return currency; 189 } 190 191 public Header setCurrency(CurrencyCode currency) { 192 this.currency = currency; 193 return this; 194 } 195 196 @Override 197 public boolean equals(Object o) { 198 if (this == o) return true; 199 if (!(o instanceof Header)) return false; 200 Header header = (Header) o; 201 return Objects.equal(invoiceNumber, header.invoiceNumber) && Objects.equal(type, header.type) 202 && Objects.equal(issued, header.issued) && Objects.equal(dueDate, header.dueDate) 203 && Objects.equal(note, header.note) && Objects.equal(reference, header.reference) 204 && Objects.equal(customerNumber, header.customerNumber) && Objects.equal(currency, header.currency); 205 } 206 207 @Override 208 public int hashCode() { 209 return Objects.hashCode(invoiceNumber, type, issued, dueDate, note, reference, customerNumber, currency); 210 } 211 212 @Override 213 public String toString() { 214 return "Header{" + "invoiceNumber='" + invoiceNumber + '\'' + ", type='" + type + '\'' + ", issued=" + issued 215 + ", dueDate=" + dueDate + ", note='" + note + '\'' + ", reference='" + reference + '\'' 216 + ", customerNumber='" + customerNumber + '\'' + ", currency=" + currency + '}'; 217 } 218 } 219 220 public static class Tax { 221 private String number = ""; 222 private Reference type = Reference.FC; 223 224 public Tax() { 225 } 226 227 public Tax(String number, Reference type) { 228 this.number = number; 229 this.type = type; 230 } 231 232 public String getNumber() { 233 return number; 234 } 235 236 public Tax setNumber(String number) { 237 this.number = number; 238 return this; 239 } 240 241 public Reference getType() { 242 return type; 243 } 244 245 public Tax setType(Reference type) { 246 this.type = type; 247 return this; 248 } 249 250 @Override 251 public boolean equals(Object o) { 252 if (this == o) return true; 253 if (!(o instanceof Tax)) return false; 254 Tax tax = (Tax) o; 255 return Objects.equal(number, tax.number) && Objects.equal(type, tax.type); 256 } 257 258 @Override 259 public int hashCode() { 260 return Objects.hashCode(number, type); 261 } 262 263 @Override 264 public String toString() { 265 return "Tax{" + "number='" + number + '\'' + ", type=" + type + '}'; 266 } 267 } 268 269 public static class TradeParty { 270 private String name = ""; 271 private String contactName = ""; 272 private String addressLine1 = ""; 273 private String addressLine2 = ""; 274 private String city = ""; 275 private String postcode = ""; 276 private CountryCode countryCode; 277 private String email = ""; 278 private List<Tax> taxes = new LinkedList<Tax>(); 279 private BankInformation bankInfo = new BankInformation(); 280 281 public String getName() { 282 return name; 283 } 284 285 public TradeParty setName(String name) { 286 this.name = name; 287 return this; 288 } 289 290 public String getContactName() { 291 return contactName; 292 } 293 294 public TradeParty setContactName(String contactName) { 295 this.contactName = contactName; 296 return this; 297 } 298 299 public String getAddressLine1() { 300 return addressLine1; 301 } 302 303 public TradeParty setAddressLine1(String addressLine1) { 304 this.addressLine1 = addressLine1; 305 return this; 306 } 307 308 public String getAddressLine2() { 309 return addressLine2; 310 } 311 312 public TradeParty setAddressLine2(String addressLine2) { 313 this.addressLine2 = addressLine2; 314 return this; 315 } 316 317 public String getCity() { 318 return city; 319 } 320 321 public TradeParty setCity(String city) { 322 this.city = city; 323 return this; 324 } 325 326 public String getPostcode() { 327 return postcode; 328 } 329 330 public TradeParty setPostcode(String postcode) { 331 this.postcode = postcode; 332 return this; 333 } 334 335 public String getEmail() { 336 return email; 337 } 338 339 public TradeParty setEmail(String email) { 340 this.email = email; 341 return this; 342 } 343 344 public List<Tax> getTaxes() { 345 return taxes; 346 } 347 348 public void setTaxes(List<Tax> taxes) { 349 this.taxes = taxes; 350 } 351 352 public TradeParty addTax(Tax tax) { 353 this.taxes.add(tax); 354 return this; 355 } 356 357 public TradeParty addTax(Tax... tax) { 358 this.taxes.addAll(Arrays.asList(tax)); 359 return this; 360 } 361 362 public BankInformation getBankInfo() { 363 return bankInfo; 364 } 365 366 public TradeParty setBankInfo(BankInformation bankInfo) { 367 this.bankInfo = bankInfo; 368 return this; 369 } 370 371 public CountryCode getCountryCode() { 372 return countryCode; 373 } 374 375 public TradeParty setCountryCode(CountryCode countryCode) { 376 this.countryCode = countryCode; 377 return this; 378 } 379 380 @Override 381 public boolean equals(Object o) { 382 if (this == o) return true; 383 if (!(o instanceof TradeParty)) return false; 384 TradeParty that = (TradeParty) o; 385 return Objects.equal(name, that.name) && Objects.equal(contactName, that.contactName) 386 && Objects.equal(addressLine1, that.addressLine1) && Objects.equal(addressLine2, that.addressLine2) 387 && Objects.equal(city, that.city) && Objects.equal(postcode, that.postcode) 388 && Objects.equal(countryCode, that.countryCode) && Objects.equal(email, that.email) 389 && Objects.equal(taxes, that.taxes) && Objects.equal(bankInfo, that.bankInfo); 390 } 391 392 @Override 393 public int hashCode() { 394 return Objects.hashCode(name, contactName, addressLine1, addressLine2, city, postcode, countryCode, email, 395 taxes, bankInfo); 396 } 397 398 @Override 399 public String toString() { 400 return "TradeParty{" + "name='" + name + '\'' + ", contactName='" + contactName + '\'' + ", addressLine1='" 401 + addressLine1 + '\'' + ", addressLine2='" + addressLine2 + '\'' + ", city='" + city + '\'' 402 + ", postcode='" + postcode + '\'' + ", countryCode=" + countryCode + ", email='" + email + '\'' 403 + ", taxes=" + taxes + ", bankInfo=" + bankInfo + '}'; 404 } 405 } 406 407 public static class Item { 408 private String name = ""; 409 private BigDecimal quantity = BigDecimal.ZERO; 410 private UnitOfMeasurement unit = UnitOfMeasurement.UNIT; 411 private BigDecimal unitPrice = BigDecimal.ZERO; 412 private BigDecimal taxPercent = BigDecimal.ZERO; 413 414 public String getName() { 415 return name; 416 } 417 418 public Item setName(String name) { 419 this.name = name; 420 return this; 421 } 422 423 public BigDecimal getQuantity() { 424 return quantity; 425 } 426 427 public Item setQuantity(BigDecimal quantity) { 428 this.quantity = quantity; 429 return this; 430 } 431 432 public UnitOfMeasurement getUnit() { 433 return unit; 434 } 435 436 public Item setUnit(UnitOfMeasurement unit) { 437 this.unit = unit; 438 return this; 439 } 440 441 public BigDecimal getUnitPrice() { 442 return unitPrice; 443 } 444 445 public Item setUnitPrice(BigDecimal unitPrice) { 446 this.unitPrice = unitPrice; 447 return this; 448 } 449 450 public BigDecimal getTaxPercent() { 451 return taxPercent; 452 } 453 454 public Item setTaxPercent(BigDecimal taxPercent) { 455 this.taxPercent = taxPercent; 456 return this; 457 } 458 459 @Override 460 public String toString() { 461 return "Item {" + "type='" + name + '\'' + ", quantity=" + quantity + ", unit=" + unit + ", unitPrice=" 462 + unitPrice + ", taxPercent=" + taxPercent + '}'; 463 } 464 465 @Override 466 public boolean equals(Object o) { 467 if (this == o) return true; 468 if (!(o instanceof Item)) return false; 469 Item item = (Item) o; 470 return Objects.equal(name, item.name) && Objects.equal(quantity, item.quantity) 471 && Objects.equal(unit, item.unit) && Objects.equal(unitPrice, item.unitPrice) 472 && Objects.equal(taxPercent, item.taxPercent); 473 } 474 475 @Override 476 public int hashCode() { 477 return Objects.hashCode(name, quantity, unit, unitPrice, taxPercent); 478 } 479 } 480 481 public static class BankInformation { 482 private String bankName = ""; 483 private String bic = ""; 484 private String iban = ""; 485 486 public String getBankName() { 487 return bankName; 488 } 489 490 public BankInformation setBankName(String bankName) { 491 this.bankName = bankName; 492 return this; 493 } 494 495 public String getBic() { 496 return bic; 497 } 498 499 public BankInformation setBic(String bic) { 500 this.bic = bic; 501 return this; 502 } 503 504 public String getIban() { 505 return iban; 506 } 507 508 public BankInformation setIban(String iban) { 509 this.iban = iban; 510 return this; 511 } 512 513 @Override 514 public String toString() { 515 return "BankInformation {" + "bankName='" + bankName + '\'' + ", bic='" + bic + '\'' + ", iban='" + iban + '\'' 516 + '}'; 517 } 518 519 @Override 520 public boolean equals(Object o) { 521 if (this == o) return true; 522 if (!(o instanceof BankInformation)) return false; 523 BankInformation that = (BankInformation) o; 524 return Objects.equal(bankName, that.bankName) && Objects.equal(bic, that.bic) 525 && Objects.equal(iban, that.iban); 526 } 527 528 @Override 529 public int hashCode() { 530 return Objects.hashCode(bankName, bic, iban); 531 } 532 } 533 534 public static class File { 535 private String input = ""; 536 private String output = ""; 537 538 public String getInput() { 539 return input; 540 } 541 542 public File setInput(String input) { 543 this.input = input; 544 return this; 545 } 546 547 public String getOutput() { 548 return output; 549 } 550 551 public File setOutput(String output) { 552 this.output = output; 553 return this; 554 } 555 556 @Override 557 public boolean equals(Object o) { 558 if (this == o) return true; 559 if (!(o instanceof File)) return false; 560 File file = (File) o; 561 return Objects.equal(input, file.input) && Objects.equal(output, file.output); 562 } 563 564 @Override 565 public int hashCode() { 566 return Objects.hashCode(input, output); 567 } 568 569 @Override 570 public String toString() { 571 return "File {" + "input='" + input + '\'' + ", output='" + output + '\'' + '}'; 572 } 573 } 574}