/*
 * 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.DateFormatModel;
import com.arrebol.apc.model.core.Office;
import com.arrebol.apc.model.core.User;
import java.io.Serializable;
import java.math.BigDecimal;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.persistence.Column;
import javax.persistence.Entity;
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 Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@Entity
@Table(name = "APC_MONEY_DAILY")
public class MoneyDaily extends DateFormatModel implements Serializable {

    private static final long serialVersionUID = 4622672186001211722L;

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

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

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

    @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 = "created_by", nullable = false, length = 36)
    private String createdBy;

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

    public MoneyDaily() {
    }

    public String getId() {
        return id;
    }

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

    public Date getMoneyDailyDate() {
        return moneyDailyDate;
    }

    public void setMoneyDailyDate(Date moneyDailyDate) {
        this.moneyDailyDate = moneyDailyDate;
    }

    public BigDecimal getAmount() {
        return amount;
    }

    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    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 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 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 "MoneyDaily{" + "moneyDailyDate=" + moneyDailyDate + '}';
    }

}
