/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.arrebol.apc.model.views;

import com.arrebol.apc.model.admin.ExpenseCompany;
import com.arrebol.apc.model.enums.ActiveStatus;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.annotations.GenericGenerator;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "APC_LOAN_EMPLOYEE_VIEW")
public class LoanEmployeeView implements Serializable {

    private static final long serialVersionUID = 1L;

    public LoanEmployeeView() {
    }

    public LoanEmployeeView(String id, String name, String createdByName, String idUser, BigDecimal amountLoan, BigDecimal amountToPay, BigDecimal balance, BigDecimal totalAmountToPay, Date createdOn, int referenceNumber) {
        this.id = id;
        this.name = name;
        this.amountLoan = amountLoan;
        this.amountToPay = amountToPay;
        this.balance = balance;
        this.totalAmountToPay = totalAmountToPay;
        this.createdOn = createdOn;
        this.idUser = idUser;
        this.referenceNumber = referenceNumber;
        this.createdByName = createdByName;
    }

    @Id
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "id", length = 36)
    private String id;

    @Column(name = "name")
    private String name;
    
    @Column(name = "created_by_name")
    private String createdByName;

    @Column(name = "id_user", length = 36)
    private String idUser;

    @Column(name = "amount_loan", nullable = false)
    private BigDecimal amountLoan;

    @Column(name = "amount_to_pay", nullable = false)
    private BigDecimal amountToPay;

    @Column(name = "balance", nullable = false)
    private BigDecimal balance;
       
    @Column(name = "total_amount_to_pay", nullable = false)
    private BigDecimal totalAmountToPay;
    
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "created_on", length = 19)
    private Date createdOn;

    @Column(name = "reference_number")
    private int referenceNumber;
    
    @Enumerated(EnumType.STRING)
    @Column(name = "loan_employee_status", nullable = false)
    private ActiveStatus loanEmployeeStatus;

    public ActiveStatus getLoanEmployeeStatus() {
        return loanEmployeeStatus;
    }

    public void setLoanEmployeeStatus(ActiveStatus loanEmployeeStatus) {
        this.loanEmployeeStatus = loanEmployeeStatus;
    }

    public String getId() {
        return id;
    }

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

    public String getIdUser() {
        return idUser;
    }

    public void setIdIser(String idUser) {
        this.idUser = idUser;
    }

    public String getCreatedByName() {
        return createdByName;
    }

    public void setCreatedByName(String createdByName) {
        this.createdByName = createdByName;
    }
    
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public BigDecimal getAmountLoan() {
        return amountLoan;
    }

    public void setAmountLoan(BigDecimal amountLoan) {
        this.amountLoan = amountLoan;
    }

    public BigDecimal getAmountToPay() {
        return amountToPay;
    }

    public void setAmountToPay(BigDecimal amountToPay) {
        this.amountToPay = amountToPay;
    }

    public BigDecimal getBalance() {
        return balance;
    }

    public void setBalance(BigDecimal balance) {
        this.balance = balance;
    }
    
    public BigDecimal getTotalAmountToPay() {
        return totalAmountToPay;
    }

    public void setTotalAmountToPay(BigDecimal totalAmountToPay) {
        this.totalAmountToPay = totalAmountToPay;
    }

    public Date getCreatedOn() {
        return createdOn;
    }

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

    public int getReferenceNumber() {
        return referenceNumber;
    }

    public void setReferenceNumber(int referenceNumber) {
        this.referenceNumber = referenceNumber;
    }
    
    public String conditionEnabled() {
        if (getLoanEmployeeStatus() == ActiveStatus.DISABLED) {
            return "grayRow";
        } else {
            return null;
        }
    }

    public boolean getActive() {
        if (loanEmployeeStatus == ActiveStatus.ENEBLED) {
            return true;
        } else {
            return false;
        }
    }
    
    public boolean getAction(Date lastStableGeneralBox) {
        Date date = createdOn;
        boolean action = true;
        try {
            SimpleDateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd");

            String dateStr = dt1.format(date);
            date = dt1.parse(dateStr);

            action = date.after(lastStableGeneralBox);

        } catch (ParseException ex) {
            Logger.getLogger(ExpenseCompany.class.getName()).log(Level.SEVERE, null, ex);
        }
        return action;
    }

    @Override
    public String toString() {
        return "LoanEmployeeView{" + "id=" + id + ", name=" + name + "idUser=" + idUser + ", amountLoan=" + amountLoan + ", amountToPay=" + amountToPay + ", balance=" + balance + ", createdOn=" + createdOn + ", referenceNumber=" + referenceNumber + '}';
    }
}
