/*
 * Arrebol Consultancy copyright.
 * 
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.apc.model.admin;

import com.arrebol.apc.model.catalog.RouteCtlg;
import com.arrebol.apc.model.core.Office;
import com.arrebol.apc.model.core.User;
import com.arrebol.apc.model.enums.ActiveStatus;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author Oscar Armando Vargas Cardenas <oscar.vargas@arrebol.com.mx>
 */
@Entity
@Table(name = "APC_CLOSING_DAY")
public class ClosingDay implements Serializable{

    private static final long serialVersionUID = 347958707624227979L;
    
    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "id", length = 36)
    private String id;
    
    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(
            name = "id_user",
            referencedColumnName = "id",
            nullable = false
    )
    private User user;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(
            name = "id_office",
            referencedColumnName = "id",
            nullable = false
    )
    private Office office;
    
    @Column(name = "amount_paid", nullable = false)
    private BigDecimal amountPaid;
    
    @Column(name = "amount_expected", nullable = false)
    private BigDecimal amountExpected;
    
    @Column(name = "comments", length = 250)
    private String comments;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "active_status", nullable = false)
    private ActiveStatus activeStatus;
    
    @Column(name = "created_by", nullable = false, length = 36)
    private String createdBy;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(
            name = "id_route",
            referencedColumnName = "id",
            nullable = true
    )
    private RouteCtlg routeCtlg;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_on", length = 19)
    private Date createdOn;

    @Column(name = "last_updated_by", length = 36)
    private String lastUpdatedBy;

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "last_updated_on", length = 19)
    private Date lastUpdatedOn;

    public ClosingDay() {
    }

    public ClosingDay(String id) {
        this.id = id;
    }

    public ClosingDay(String id, User user, Office office, BigDecimal amountPaid, BigDecimal amountExpected, ActiveStatus activeStatus, String comments, String createdBy, Date createdOn) {
        this.id = id;
        this.user = user;
        this.office = office;
        this.amountPaid = amountPaid;
        this.amountExpected = amountExpected;
        this.activeStatus = activeStatus;
        this.createdBy = createdBy;
        this.createdOn = createdOn;
        this.comments = comments;
    }

    public ClosingDay(String id, User user, Office office, BigDecimal amountPaid, BigDecimal amountExpected, String comments, ActiveStatus activeStatus, String createdBy) {
        this.id = id;
        this.user = user;
        this.office = office;
        this.amountPaid = amountPaid;
        this.amountExpected = amountExpected;
        this.activeStatus = activeStatus;
        this.createdBy = createdBy;
        this.createdOn = new Date();
        this.comments = comments;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public Office getOffice() {
        return office;
    }

    public void setOffice(Office office) {
        this.office = office;
    }

    public BigDecimal getAmountPaid() {
        return amountPaid;
    }

    public void setAmountPaid(BigDecimal amountPaid) {
        this.amountPaid = amountPaid;
    }

    public BigDecimal getAmountExpected() {
        return amountExpected;
    }

    public void setAmountExpected(BigDecimal amountExpected) {
        this.amountExpected = amountExpected;
    }

    public BigDecimal getDiferencia(){
        BigDecimal diferencia = amountPaid.subtract(amountExpected);
        
        return diferencia;
    }
    
    public ActiveStatus getActiveStatus() {
        return activeStatus;
    }

    public void setActiveStatus(ActiveStatus activeStatus) {
        this.activeStatus = activeStatus;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

    public void setCreatedOn(Date createdOn) {
        this.createdOn = createdOn;
    }

    public String getLastUpdatedBy() {
        return lastUpdatedBy;
    }

    public void setLastUpdatedBy(String lastUpdatedBy) {
        this.lastUpdatedBy = lastUpdatedBy;
    }

    public Date getLastUpdatedOn() {
        return lastUpdatedOn;
    }

    public void setLastUpdatedOn(Date lastUpdatedOn) {
        this.lastUpdatedOn = lastUpdatedOn;
    } 

    public String getComments() {
        return comments;
    }

    public void setComments(String comments) {
        this.comments = comments;
    }
    
    public RouteCtlg getRouteCtlg() {
        return routeCtlg;
    }

    public void setRouteCtlg(RouteCtlg routeCtlg) {
        this.routeCtlg = routeCtlg;
    }
    
    public String conditionEnabled()   {
        if(getActiveStatus() == ActiveStatus.DISABLED)
            return "grayRow";
        else
            return null;
    }
    
    public boolean conditionEnabledBool() {
        if (getActiveStatus() == ActiveStatus.DISABLED) {
            return false;
        } else {
            return true;
        }
    }
    
    public boolean getActive() {
        return activeStatus == ActiveStatus.ENEBLED;

    }
}
