SimpleProduct.java

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tradecloud.domain.model.hfcmanagement;

import com.tradecloud.common.base.PersistenceBase;
import com.tradecloud.domain.common.Currency;
import org.hibernate.annotations.ForeignKey;
import org.hibernate.annotations.NaturalId;
import org.springframework.stereotype.Component;

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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import java.math.BigDecimal;

/**
 *
 */
@Entity
@Table(name = "simpleProduct", uniqueConstraints = {@UniqueConstraint(columnNames = {"description", "hfcReference"})})
@Access(javax.persistence.AccessType.FIELD)
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "SimpleProduct")
@Component(value = "simpleProduct")
public class SimpleProduct extends PersistenceBase {

    private static final long serialVersionUID = 1L;
    @NaturalId
    private String hfcReference;
    @XmlElement
    @NotNull
    private BigDecimal marginPercentage;
    @XmlElement
    @NotNull
    private BigDecimal foreignUnitPrice;
    @XmlElement
    private BigDecimal dutyPercentage;
    @XmlElement
    private BigDecimal elc;
    @XmlElement
    private BigDecimal conversionRate;
    @XmlElement
    @NaturalId
    private String description;
    @XmlElement
    private BigDecimal sellingPriceExcl;
    @XmlElement
    private BigDecimal sellingPriceIncl;
    @ManyToOne
    @JoinColumn(name = "currency_code")
    @ForeignKey(name = "fk_currency")
    @XmlElement
    private Currency currency;
    @XmlElement
    private boolean calcSellingPrice = true;
    @XmlElement
    private boolean calcMarginPercentage;
    @XmlElement
    private boolean calcForeignUnitPrice;

    public BigDecimal getMarginPercentage() {
        return marginPercentage;
    }

    public void setMarginPercentage(BigDecimal marginPercentage) {
        this.marginPercentage = marginPercentage;
    }

    public BigDecimal getForeignUnitPrice() {
        return foreignUnitPrice;
    }

    public void setForeignUnitPrice(BigDecimal foreignUnitPrice) {
        this.foreignUnitPrice = foreignUnitPrice;
    }

    public BigDecimal getDutyPercentage() {
        return dutyPercentage;
    }

    public void setDutyPercentage(BigDecimal dutyPercentage) {
        this.dutyPercentage = dutyPercentage;
    }

    public BigDecimal getElc() {
        return elc;
    }

    public void setElc(BigDecimal elc) {
        this.elc = elc;
    }

    public BigDecimal getConversionRate() {
        return conversionRate;
    }

    public void setConversionRate(BigDecimal conversionRate) {
        this.conversionRate = conversionRate;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public BigDecimal getSellingPriceExcl() {
        return sellingPriceExcl;
    }

    public void setSellingPriceExcl(BigDecimal sellingPriceExcl) {
        this.sellingPriceExcl = sellingPriceExcl;
    }

    public BigDecimal getSellingPriceIncl() {
        return sellingPriceIncl;
    }

    public void setSellingPriceIncl(BigDecimal sellingPriceIncl) {
        this.sellingPriceIncl = sellingPriceIncl;
    }

    public Currency getCurrency() {
        return currency;
    }

    public void setCurrency(Currency currency) {
        this.currency = currency;
    }

    public Boolean getCalcSellingPrice() {
        return calcSellingPrice;
    }

    public void setCalcSellingPrice(Boolean calcSellingPrice) {
        this.calcSellingPrice = calcSellingPrice;
    }

    public Boolean getCalcMarginPercentage() {
        return calcMarginPercentage;
    }

    public void setCalcMarginPercentage(Boolean calcMarginPercentage) {
        this.calcMarginPercentage = calcMarginPercentage;
    }

    public Boolean getCalcForeignUnitPrice() {
        return calcForeignUnitPrice;
    }

    public void setCalcForeignUnitPrice(Boolean calcForeignUnitPrice) {
        this.calcForeignUnitPrice = calcForeignUnitPrice;
    }

    public String getHfcReference() {
        return hfcReference;
    }

    public void setHfcReference(String hfcReference) {
        this.hfcReference = hfcReference;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + (this.hfcReference != null ? this.hfcReference.hashCode() : 0);
        hash = 59 * hash + (this.description != null ? this.description.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final SimpleProduct other = (SimpleProduct) obj;
        if ((this.hfcReference == null) ? (other.hfcReference != null) : !this.hfcReference.equals(other.hfcReference)) {
            return false;
        }
        if ((this.description == null) ? (other.description != null) : !this.description.equals(other.description)) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "SimpleProduct [hfcReference=" + hfcReference + ", marginPercentage=" + marginPercentage + ", " +
                "" + "" + "" + "foreignUnitPrice=" + foreignUnitPrice + ", dutyPercentage=" + dutyPercentage + ", elc=" + elc + ", " +
                "" + "" + "" + "conversionRate=" + conversionRate + ", description=" + description + ", sellingPriceExcl=" + sellingPriceExcl + ", " +
                "" + "" + "" + "sellingPriceIncl=" + sellingPriceIncl + ", currency=" + currency + ", calcSellingPrice=" + calcSellingPrice + ", " +
                "" + "" + "" + "calcMarginPercentage=" + calcMarginPercentage + ", calcForeignUnitPrice=" + calcForeignUnitPrice + "]";
    }

    public String toStringHeadingsForCsv() {

        return "Product description,Foreign price per unit,ELC per unit,Selling price per unit Excl VAT,Selling price per unit Incl VAT," +
                "" + "" + "" + "Margin Percentage";

    }

    public String toStringForCsv() {
        return description + "##" + foreignUnitPrice + "##" + elc + "##" + sellingPriceExcl + "##" + sellingPriceIncl + "##" + marginPercentage;
    }

}