/*
 * 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.payroll;

import com.arrebol.apc.model.admin.ExpenseCompany;
import com.arrebol.apc.model.core.HumanResource;
import com.arrebol.apc.model.core.Office;
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.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_PAYROLL")
public class Payroll implements Serializable {

    @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_human_resource",
            referencedColumnName = "id",
            nullable = false
    )
    private HumanResource humanResource;

    @ManyToOne(fetch = FetchType.LAZY, optional = false)
    @JoinColumn(
            name = "id_office",
            referencedColumnName = "id",
            nullable = false
    )
    private Office office;

    @Enumerated(EnumType.STRING)
    @Column(name = "active_status", nullable = false)
    private ActiveStatus activeStatus;

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

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

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

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

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

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

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

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

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

    @Column(name = "total_days_salary", nullable = false)
    private Integer totalDaysSalary;

    @Column(name = "total_days_bonus", nullable = false)
    private Integer totalDaysBonus;

    @Column(name = "comments_discounts", length = 200)
    private String commentsDiscounts;

    @Column(name = "comments_increases", length = 200)
    private String commentsIncreases;

    @Column(name = "observation", length = 200)
    private String observation;

    @Column(name = "created_by", nullable = false, length = 36)
    private String createdBy;

    @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;

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

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

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

    public String getId() {
        return id;
    }

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

    public HumanResource getHumanResource() {
        return humanResource;
    }

    public void setHumanResource(HumanResource humanResource) {
        this.humanResource = humanResource;
    }

    public Office getOffice() {
        return office;
    }

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

    public ActiveStatus getActiveStatus() {
        return activeStatus;
    }

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

    public BigDecimal getSalary() {
        return salary;
    }

    public void setSalary(BigDecimal salary) {
        this.salary = salary;
    }

    public BigDecimal getImss() {
        return imss;
    }

    public void setImss(BigDecimal imss) {
        this.imss = imss;
    }

    public BigDecimal getAdvance() {
        return advance;
    }

    public void setAdvance(BigDecimal advance) {
        this.advance = advance;
    }

    public BigDecimal getTotalBonusNewCustomer() {
        return totalBonusNewCustomer;
    }

    public void setTotalBonusNewCustomer(BigDecimal totalBonusNewCustomer) {
        this.totalBonusNewCustomer = totalBonusNewCustomer;
    }

    public BigDecimal getTotalBonusColocation() {
        return totalBonusColocation;
    }

    public void setTotalBonusColocation(BigDecimal totalBonusColocation) {
        this.totalBonusColocation = totalBonusColocation;
    }

    public BigDecimal getTotalBonusMora() {
        return totalBonusMora;
    }

    public void setTotalBonusMora(BigDecimal totalBonusMora) {
        this.totalBonusMora = totalBonusMora;
    }

    public BigDecimal getDiscounts() {
        return discounts;
    }

    public void setDiscounts(BigDecimal discounts) {
        this.discounts = discounts;
    }

    public BigDecimal getIncreases() {
        return increases;
    }

    public void setIncreases(BigDecimal increases) {
        this.increases = increases;
    }

    public BigDecimal getTotalPayment() {
        return totalPayment;
    }

    public void setTotalPayment(BigDecimal totalPayment) {
        this.totalPayment = totalPayment;
    }

    public Integer getTotalDaysSalary() {
        return totalDaysSalary;
    }

    public void setTotalDaysSalary(Integer totalDaysSalary) {
        this.totalDaysSalary = totalDaysSalary;
    }

    public Integer getTotalDaysBonus() {
        return totalDaysBonus;
    }

    public void setTotalDaysBonus(Integer totalDaysBonus) {
        this.totalDaysBonus = totalDaysBonus;
    }

    public String getCommentsDiscounts() {
        return commentsDiscounts;
    }

    public void setCommentsDiscounts(String commentsDiscounts) {
        this.commentsDiscounts = commentsDiscounts;
    }

    public String getCommentsIncreases() {
        return commentsIncreases;
    }

    public void setCommentsIncreases(String commentsIncreases) {
        this.commentsIncreases = commentsIncreases;
    }

    public String getObservation() {
        return observation;
    }

    public void setObservation(String observation) {
        this.observation = observation;
    }

    public String getCreatedBy() {
        return createdBy;
    }

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

    public Date getCreatedOn() {
        return 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;
    }
    
    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 BigDecimal getBoxed() {
        return boxed;
    }

    public void setBoxed(BigDecimal boxed) {
        this.boxed = boxed;
    }

    public BigDecimal getSaving() {
        return saving;
    }

    public void setSaving(BigDecimal saving) {
        this.saving = saving;
    }

    public BigDecimal getPaymentToDebt() {
        return paymentToDebt;
    }

    public void setPaymentToDebt(BigDecimal paymentToDebt) {
        this.paymentToDebt = paymentToDebt;
    }

    public BigDecimal summaryPerceptions() {
        return salary.add(totalBonusNewCustomer).add(totalBonusColocation).add(totalBonusMora).add(increases);
    }

    public String conditionEnabled() {
        if (getActiveStatus() == ActiveStatus.DISABLED) {
            return "grayRow";
        } else {
            return null;
        }
    }

    public boolean getActive() {
        if (activeStatus == ActiveStatus.ENEBLED) {
            return true;
        } else {
            return false;
        }

    }
}
