ALCHistoricalCostItem.java

package com.tradecloud.domain.model.hfcmanagement;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.common.Currency;
import com.tradecloud.domain.common.Incoterm;
import com.tradecloud.domain.item.Product;
import com.tradecloud.domain.model.organisationalunit.OrganisationalUnit;
import com.tradecloud.domain.model.shipment.ShippingMode;
import com.tradecloud.domain.place.PlaceOfDischarge;
import com.tradecloud.domain.place.PlaceOfLoading;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import java.math.BigDecimal;
import java.util.Date;

/**
 * @author pvzyl This class represents ALC costs calculated for shipments with orders in Redbox
 */
@Entity
@Table(name = "alchistoricalcostitem")
@Access(AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "ALCHistoricalCost")
public class ALCHistoricalCostItem extends PersistenceBase {

    /**
     *
     */
    private static final long serialVersionUID = 1L;
    /**
     *
     */

    @NotNull
    private String shipmentReference; // 1

    @NotNull
    private String orderReference; // 2

    @ManyToOne
    private OrganisationalUnit division;// 4
    @NotNull
    private Date grvDate;// 9

    @ManyToOne
    @NotNull
    private OrganisationalUnit department;// 12

    @ManyToOne
    @NotNull
    private Product product;

    private BigDecimal unitQuantity;// 14
    private BigDecimal alcPerUnit;// 15
    private BigDecimal forexUnitPrice;// 16
    @ManyToOne
    @NotNull
    private Currency purchasingCurrency;// 17

    @ManyToOne
    @NotNull
    private ProductGroup productGroup;

    @ManyToOne
    @NotNull
    private Incoterm incoterm;// 19

    /**
     * The place where the order is loaded. This should default to the place of loading configured in the client setup.
     */
    @ManyToOne
    @NotNull
    private PlaceOfLoading placeOfLoading;// 20

    /**
     * The place where the order is discharged. This should default to the place of discharge configured in the client setup. Also know as Place of
     * Docking
     */
    @ManyToOne
    @NotNull
    private PlaceOfDischarge placeOfDischarge; // 21
    /**
     * The shipping mode that will be used to deliver the order. This should default to the shipping mode configured in the client setup.
     */
    @Enumerated(value = EnumType.STRING)
    private ShippingMode shippingMode; // 22

    private BigDecimal supplyCostsTotalCC;// 23

    private BigDecimal customsAdValoremDuty;// 60
    private BigDecimal customsDuty;// 61
    private BigDecimal customsProvisionalAndPenaltyPayments;// 62
    private BigDecimal customsVat;// 63
    private BigDecimal customsOther;// 63

    public String getShipmentReference() {
        return shipmentReference;
    }

    public void setShipmentReference(String shipmentReference) {
        this.shipmentReference = shipmentReference;
    }

    public String getOrderReference() {
        return orderReference;
    }

    public void setOrderReference(String orderReference) {
        this.orderReference = orderReference;
    }

    public OrganisationalUnit getDivision() {
        return division;
    }

    public void setDivision(OrganisationalUnit division) {
        this.division = division;
    }

    public Date getGrvDate() {
        return grvDate;
    }

    public void setGrvDate(Date grvDate) {
        this.grvDate = grvDate;
    }

    public OrganisationalUnit getDepartment() {
        return department;
    }

    public void setDepartment(OrganisationalUnit department) {
        this.department = department;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public BigDecimal getUnitQuantity() {
        return unitQuantity;
    }

    public void setUnitQuantity(BigDecimal unitQuantity) {
        this.unitQuantity = unitQuantity;
    }

    public BigDecimal getAlcPerUnit() {
        return alcPerUnit;
    }

    public void setAlcPerUnit(BigDecimal alcPerUnit) {
        this.alcPerUnit = alcPerUnit;
    }

    public BigDecimal getForexUnitPrice() {
        return forexUnitPrice;
    }

    public void setForexUnitPrice(BigDecimal forexUnitPrice) {
        this.forexUnitPrice = forexUnitPrice;
    }

    public Currency getPurchasingCurrency() {
        return purchasingCurrency;
    }

    public void setPurchasingCurrency(Currency purchasingCurrency) {
        this.purchasingCurrency = purchasingCurrency;
    }

    public ProductGroup getProductGroup() {
        return productGroup;
    }

    public void setProductGroup(ProductGroup productGroup) {
        this.productGroup = productGroup;
    }

    public Incoterm getIncoterm() {
        return incoterm;
    }

    public void setIncoterm(Incoterm incoterm) {
        this.incoterm = incoterm;
    }

    public PlaceOfLoading getPlaceOfLoading() {
        return placeOfLoading;
    }

    public void setPlaceOfLoading(PlaceOfLoading placeOfLoading) {
        this.placeOfLoading = placeOfLoading;
    }

    public PlaceOfDischarge getPlaceOfDischarge() {
        return placeOfDischarge;
    }

    public void setPlaceOfDischarge(PlaceOfDischarge placeOfDischarge) {
        this.placeOfDischarge = placeOfDischarge;
    }

    public ShippingMode getShippingMode() {
        return shippingMode;
    }

    public void setShippingMode(ShippingMode shippingMode) {
        this.shippingMode = shippingMode;
    }

    public BigDecimal getSupplyCostsTotalCC() {
        return supplyCostsTotalCC;
    }

    public void setSupplyCostsTotalCC(BigDecimal supplyCostsTotalCC) {
        this.supplyCostsTotalCC = supplyCostsTotalCC;
    }

    public BigDecimal getCustomsAdValoremDuty() {
        return customsAdValoremDuty;
    }

    public void setCustomsAdValoremDuty(BigDecimal customsAdValoremDuty) {
        this.customsAdValoremDuty = customsAdValoremDuty;
    }

    public BigDecimal getCustomsDuty() {
        return customsDuty;
    }

    public void setCustomsDuty(BigDecimal customsDuty) {
        this.customsDuty = customsDuty;
    }

    public BigDecimal getCustomsProvisionalAndPenaltyPayments() {
        return customsProvisionalAndPenaltyPayments;
    }

    public void setCustomsProvisionalAndPenaltyPayments(BigDecimal customsProvisionalAndPenaltyPayments) {
        this.customsProvisionalAndPenaltyPayments = customsProvisionalAndPenaltyPayments;
    }

    public BigDecimal getCustomsVat() {
        return customsVat;
    }

    public void setCustomsVat(BigDecimal customsVat) {
        this.customsVat = customsVat;
    }

    public BigDecimal getCustomsOther() {
        return customsOther;
    }

    public void setCustomsOther(BigDecimal customsOther) {
        this.customsOther = customsOther;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = super.hashCode();
        result = prime * result + ((product == null) ? 0 : product.hashCode());
        result = prime * result + ((orderReference == null) ? 0 : orderReference.hashCode());
        result = prime * result + ((shipmentReference == null) ? 0 : shipmentReference.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj)
            return true;
        if (!super.equals(obj))
            return false;
        if (getClass() != obj.getClass())
            return false;
        ALCHistoricalCostItem other = (ALCHistoricalCostItem) obj;
        if (product == null) {
            if (other.product != null)
                return false;
        } else if (!product.equals(other.product))
            return false;
        if (orderReference == null) {
            if (other.orderReference != null)
                return false;
        } else if (!orderReference.equals(other.orderReference))
            return false;
        if (shipmentReference == null) {
            if (other.shipmentReference != null)
                return false;
        } else if (!shipmentReference.equals(other.shipmentReference))
            return false;
        return true;
    }

    @Override
    public String toString() {
        String productString = (product == null) ? "null" : product.toString();
        return "ALCHistoricalCostItem [shipmentReference=" + shipmentReference + ", orderReference=" + orderReference + ", division=" + division
                + ", grvDate=" + grvDate + ", department=" + department + ", product=" + productString + ", unitQuantity=" + unitQuantity
                + ", alcPerUnit=" + alcPerUnit + ", forexUnitPrice=" + forexUnitPrice + ", purchasingCurrency=" + purchasingCurrency
                + ", productGroup=" + productGroup + ", incoterm=" + incoterm + ", placeOfLoading=" + placeOfLoading + ", placeOfDischarge="
                + placeOfDischarge + ", shippingMode=" + shippingMode + ", supplyCostsTotalCC=" + supplyCostsTotalCC + ", customsAdValoremDuty="
                + customsAdValoremDuty + ", customsDuty=" + customsDuty + ", " + "customsProvisionalAndPenaltyPayments="
                + customsProvisionalAndPenaltyPayments + ", customsVat=" + customsVat + ", customsOther=" + customsOther + "]";
    }

    public String toStringHeadingsForCsv() {
        return "shipmentReference" + ", orderReference" + ", division" + ", grvDate" + ", department" + ", itemReference" + ", unitQuantity"
                + ", alcPerUnit" + ", forexUnitPrice" + ", purchasingCurrency" + ", productGroup" + ", incoterm" + ", placeOfLoading"
                + ", placeOfDischarge" + ", shippingMode" + ", supplyCostsTotalCC" + ", customsAdValoremDuty" + ", customsDuty" + ", "
                + "customsProvisionalAndPenaltyPayments" + ", customsVat" + ", customsOther" + ", countryoforigin";
    }

    public String toStringForCsv() {
        String itemReference = (product == null) ? "null" : product.getCode();
        return "" + shipmentReference + "," + orderReference + "," + (division.getName() + "-" + division.getTier()) + "," + grvDate + ","
                + (department.getName() + "-" + department.getTier()) + ", " + itemReference + "," + unitQuantity + "," + alcPerUnit + ","
                + forexUnitPrice + ", " + purchasingCurrency.getCode() + ", " + productGroup.getDescription() + ", " + incoterm + ","
                + placeOfLoading.getName() + "," + placeOfDischarge.getName() + "," + shippingMode + ", " + supplyCostsTotalCC + ","
                + customsAdValoremDuty + "," + customsDuty + ", " + "" + customsProvisionalAndPenaltyPayments + ", " + customsVat + ","
                + customsOther + "," + (product != null ? product.getCountryOfOrigin().getName() : null);
    }

}