package org.helianto.finance.domain;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;

import org.helianto.core.domain.Entity;
import org.helianto.core.internal.AbstractEventControl;
import org.helianto.core.number.Sequenceable;
import org.helianto.partner.domain.PrivateEntity;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * Finance base class.
 * 
 * @author mauriciofernandesdecastro
 */
@javax.persistence.Entity
@Table(name="fin_finance",
    uniqueConstraints = {@UniqueConstraint(columnNames={"entityId", "internalNumber"})}
)
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
    name="type",
    discriminatorType=DiscriminatorType.CHAR
)
@DiscriminatorValue("F")
public abstract class AbstractFinance 
	extends AbstractEventControl 
	implements Sequenceable
{
	
	private static final long serialVersionUID = 1L;
	
    @JsonIgnore 
    @ManyToOne
    @JoinColumn(name="privateEntityId", nullable=true)
	private PrivateEntity privateEntity;
	
	@Column(length=128)
	private String summary;
	
	private BigDecimal faceValue;
	
	@Transient
	private Integer privateEntityId;
	
    @Temporal(TemporalType.TIMESTAMP)
    private Date checkOutDate = null;
	
	/**
	 * Default constructor.
	 */
	public AbstractFinance() {
		super();
	}
	
	/**
	 * Key constructor.
	 * 
	 * @param entity
	 * @param internalNumber
	 */
	public AbstractFinance(Entity entity, long internalNumber) {
		this();
		setEntity(entity);
		setInternalNumber(internalNumber);
	}
	
    /**
     * Constructor.
     * 
     * @param entity
     * @param privateEntity
     * @param internalNumber
     */
    public AbstractFinance(Entity entity, PrivateEntity privateEntity, long internalNumber) {
		this(entity,internalNumber);
		setPrivateEntity(privateEntity);
	}
	
	public String getEntityAlias() {
		if (getPrivateEntity()!=null) {
			return getPrivateEntity().getEntityAlias();
		}
		return "";
	}
	
	/**
	 * Related private entity.
	 */
	public PrivateEntity getPrivateEntity() {
		return privateEntity;
	}
	public void setPrivateEntity(PrivateEntity privateEntity) {
		this.privateEntity = privateEntity;
	}
	
	public String getSummary() {
		return summary;
	}
	public void setSummary(String summary) {
		this.summary = summary;
	}
	
	/**
	 * Face value.
	 */
	public BigDecimal getFaceValue() {
		return faceValue;
	}
	public void setFaceValue(BigDecimal faceValue) {
		this.faceValue = faceValue;
	}
	
	/**
	 * Transient privateEntityId.
	 */
	public Integer getPrivateEntityId() {
		return privateEntityId;
	}
	public void setPrivateEntityId(Integer privateEntityId) {
		this.privateEntityId = privateEntityId;
	}
	
	/**
	 * Date which Resolution change to D(Done)
	 * i.e, paid({@link Payable}) or received({@link Receivable}). 
	 * Default it's null.
	 */
	public Date getCheckOutDate() {
		return checkOutDate;
	}
	public void setCheckOutDate(Date checkOutDate) {
		this.checkOutDate = checkOutDate;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((getEntity() == null) ? 0 : getEntity().hashCode());
		result = prime * result + (int) (getInternalNumber() ^ (getInternalNumber() >>> 32));
		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;
		AbstractFinance other = (AbstractFinance) obj;
		if (getEntity() == null) {
			if (other.getEntity() != null)
				return false;
		} else if (!getEntity().equals(other.getEntity()))
			return false;
		if (getInternalNumber() != other.getInternalNumber())
			return false;
		return true;
	}

}

@@ -1673,31 +1673,30 @@
 rivate Date 
-checkOu
+paymen
 tDate = null
@@ -3296,23 +3296,22 @@
 Date get
-CheckOu
+Paymen
 tDate() 
@@ -3321,23 +3321,22 @@
 %09return 
-checkOu
+paymen
 tDate;%0A%09
@@ -3357,15 +3357,14 @@
  set
-CheckOu
+Paymen
 tDat
@@ -3370,23 +3370,22 @@
 te(Date 
-checkOu
+paymen
 tDate) %7B
@@ -3396,23 +3396,22 @@
 his.
-checkOu
+paymen
 tDate = 
 chec
@@ -3410,15 +3410,14 @@
 e = 
-checkOu
+paymen
 tDat
@@ -3417,24 +3417,26 @@
 mentDate;%0A%09%7D
+%0A%09
 %0A%0A%09@Override

Change checkOutDate to paymentDate