All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mindee.product.invoice.InvoiceV4LineItem Maven / Gradle / Ivy

There is a newer version: 4.21.0
Show newest version
package com.mindee.product.invoice;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.mindee.parsing.SummaryHelper;
import com.mindee.parsing.standard.BaseField;
import com.mindee.parsing.standard.LineItemField;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;

/**
 * List of line item details.
 */
@Getter
@JsonIgnoreProperties(ignoreUnknown = true)
public class InvoiceV4LineItem extends BaseField implements LineItemField {

  /**
   * The item description.
   */
  @JsonProperty("description")
  String description;
  /**
   * The product code referring to the item.
   */
  @JsonProperty("product_code")
  String productCode;
  /**
   * The item quantity
   */
  @JsonProperty("quantity")
  Double quantity;
  /**
   * The item tax amount.
   */
  @JsonProperty("tax_amount")
  Double taxAmount;
  /**
   * The item tax rate in percentage.
   */
  @JsonProperty("tax_rate")
  Double taxRate;
  /**
   * The item total amount.
   */
  @JsonProperty("total_amount")
  Double totalAmount;
  /**
   * The item unit price.
   */
  @JsonProperty("unit_price")
  Double unitPrice;

  public boolean isEmpty() {
    return (
        (description == null || description.isEmpty())
        && (productCode == null || productCode.isEmpty())
        && quantity == null
        && taxAmount == null
        && taxRate == null
        && totalAmount == null
        && unitPrice == null
      );
  }

  /**
   * Output the line in a format suitable for inclusion in an rST table.
   */
  public String toTableLine() {
    Map printable = this.printableValues();
    return String.format("| %-36s ", printable.get("description"))
      + String.format("| %-12s ", printable.get("productCode"))
      + String.format("| %-8s ", printable.get("quantity"))
      + String.format("| %-10s ", printable.get("taxAmount"))
      + String.format("| %-12s ", printable.get("taxRate"))
      + String.format("| %-12s ", printable.get("totalAmount"))
      + String.format("| %-10s |", printable.get("unitPrice"));
  }

  @Override
  public String toString() {
    Map printable = this.printableValues();
    return String.format("Description: %s", printable.get("description"))
      + String.format(", Product code: %s", printable.get("productCode"))
      + String.format(", Quantity: %s", printable.get("quantity"))
      + String.format(", Tax Amount: %s", printable.get("taxAmount"))
      + String.format(", Tax Rate (%%): %s", printable.get("taxRate"))
      + String.format(", Total Amount: %s", printable.get("totalAmount"))
      + String.format(", Unit Price: %s", printable.get("unitPrice"));
  }

  private Map printableValues() {
    Map printable = new HashMap<>();

    String descriptionSummary = (this.description != null ? this.description : "");
    if (descriptionSummary.length() >= 36) {
      descriptionSummary = descriptionSummary.substring(0, 33) + "...";
    }
    printable.put("description", descriptionSummary);
    printable.put("productCode", SummaryHelper.formatForDisplay(this.productCode, null));
    printable.put(
        "quantity",
        SummaryHelper.formatAmount(this.quantity)
    );
    printable.put(
        "taxAmount",
        SummaryHelper.formatAmount(this.taxAmount)
    );
    printable.put(
        "taxRate",
        SummaryHelper.formatAmount(this.taxRate)
    );
    printable.put(
        "totalAmount",
        SummaryHelper.formatAmount(this.totalAmount)
    );
    printable.put(
        "unitPrice",
        SummaryHelper.formatAmount(this.unitPrice)
    );
    return printable;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy