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