/*
 * 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.taxiservicios.model.admin;

import com.arrebol.taxiservicios.model.catalog.BankCard;
import com.arrebol.taxiservicios.model.core.Person;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.ExpenseStatusType;
import com.arrebol.taxiservicios.model.enums.TransferType;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Picasso
 */
public class Sale implements Serializable {

    private static final long serialVersionUID = 6615352147107864705L;
    private String id;
    private Double payDay;
    private Double paySaving;
    private Date payDate;
    private String description;
    private Double accident;
    private Double payDayAsSpected;
    private Double paySavingAsSpected;
    private Double accidentAsSpected;
    private Double totalToPay;
    private Boolean active;
    private Person person;
    private Taxi taxi;
    private User createdBy;
    private Date createdOn;
    private User lastUpdatedBy;
    private Date lastUpdatedOn;
    private TransferType transfer;
    private Boolean garage;
    private Boolean nuevaAsignacion;
    private Boolean banca;
    private BankCard bankCard;
    private ExpenseStatusType status;

    public Sale() {
    }

    public Sale(Date payDate, Person person) {
        this.payDate = payDate;
        this.person = person;
    }

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

    public Sale(String id, Person person) {
        this.id = id;
        this.person = person;
    }

    public Sale(Double value) {
        this.payDay = value;
        this.paySaving = value;
        this.accident = value;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param taxi
     * @param description
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, Taxi taxi, String description) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.taxi = taxi;
        this.description = description;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param taxi
     * @param description
     * @param createdOn
     * @param createdBy
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, Taxi taxi, String description, Date createdOn, User createdBy) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.taxi = taxi;
        this.description = description;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param taxi
     * @param description
     * @param createdOn
     * @param createdBy
     * @param garage
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, Taxi taxi, String description, Date createdOn, User createdBy, Boolean garage) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.taxi = taxi;
        this.description = description;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
        this.garage = garage;
    }
    
    
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, Taxi taxi, String description, Date createdOn, User createdBy, Boolean garage, Person person) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.taxi = taxi;
        this.description = description;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
        this.garage = garage;
        this.person = person;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param description
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param description
     * @param person
     * @param createdOn
     * @param taxi
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Date createdOn, Taxi taxi) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.createdOn = createdOn;
        this.taxi = taxi;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param description
     * @param person
     * @param createdOn
     * @param taxi
     * @param garage
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Date createdOn, Taxi taxi, boolean garage) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.createdOn = createdOn;
        this.taxi = taxi;
        this.garage = garage;
    }
    
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Date createdOn, Taxi taxi, boolean garage, boolean nuevaAsignacion, boolean banca, double payDayAsSpected) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.createdOn = createdOn;
        this.taxi = taxi;
        this.garage = garage;
        this.nuevaAsignacion = nuevaAsignacion;
        this.banca = banca;
        this.payDayAsSpected = payDayAsSpected;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param description
     * @param person
     * @param createdOn
     * @param taxi
     * @param createdBy
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Date createdOn, Taxi taxi, User createdBy) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.createdOn = createdOn;
        this.taxi = taxi;
        this.createdBy = createdBy;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param description
     * @param person
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param description
     * @param person
     * @param taxi
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Taxi taxi) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.taxi = taxi;
    }

    /**
     *
     * @param id
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param accident
     * @param description
     * @param person
     * @param taxi
     * @param createdOn
     * @param createdBy
     */
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Taxi taxi, Date createdOn, User createdBy) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.taxi = taxi;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
    }
    
    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Taxi taxi, Date createdOn, User createdBy, ExpenseStatusType status) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.taxi = taxi;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
        this.status = status;
    }

    public Sale(String id, Double payDay, Double paySaving, Date payDate, Double accident, String description, Person person, Taxi taxi, Date createdOn, User createdBy, ExpenseStatusType status, BankCard bankCard) {
        this.id = id;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.accident = accident;
        this.description = description;
        this.person = person;
        this.taxi = taxi;
        this.createdOn = createdOn;
        this.createdBy = createdBy;
        this.status = status;
        this.bankCard = bankCard;
    }
    /**
     *
     * @param id
     * @param description
     * @param payDay
     * @param paySaving
     * @param payDate
     * @param active
     * @param person
     * @param createdBy
     * @param createdOn
     * @param lastUpdatedBy
     * @param lastUpdatedOn
     */
    public Sale(String id, String description, Double payDay, Double paySaving, Date payDate, Boolean active, Person person, User createdBy, Date createdOn, User lastUpdatedBy, Date lastUpdatedOn) {
        this.id = id;
        this.description = description;
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.payDate = payDate;
        this.active = active;
        this.person = person;
        this.createdBy = createdBy;
        this.createdOn = createdOn;
        this.lastUpdatedBy = lastUpdatedBy;
        this.lastUpdatedOn = lastUpdatedOn;
    }

    /**
     *
     * @param payDay
     * @param paySaving
     * @param accident
     * @param person
     * @param description
     */
    public Sale(Double payDay, Double paySaving, Double accident, Person person, String description) {
        this.payDay = payDay;
        this.paySaving = paySaving;
        this.accident = accident;
        this.person = person;
        this.description = description;
    }

    /**
     *
     * @param array
     */
    public Sale(Object[] array) {
        this.payDay = (Double) array[0];
        this.paySaving = (Double) array[1];
        this.accident = (Double) array[2];
        this.payDate = (Date) array[3];
        this.person = (Person) array[4];
        this.id = array[5].toString();
        this.taxi = (Taxi) array[6];
        this.description = (String) array[7];
    }

    public String getId() {
        return id;
    }

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

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Double getPayDay() {
        return payDay;
    }

    public void setPayDay(Double payDay) {
        this.payDay = payDay;
    }

    public Double getPaySaving() {
        return paySaving;
    }

    public void setPaySaving(Double paySaving) {
        this.paySaving = paySaving;
    }

    public Date getPayDate() {
        return payDate;
    }

    public void setPayDate(Date payDate) {
        this.payDate = payDate;
    }

    public Double getAccident() {
        return accident;
    }

    public void setAccident(Double accident) {
        this.accident = accident;
    }

    public Double getPayDayAsSpected() {
        return payDayAsSpected;
    }

    public void setPayDayAsSpected(Double payDayAsSpected) {
        this.payDayAsSpected = payDayAsSpected;
    }

    public Double getPaySavingAsSpected() {
        return paySavingAsSpected;
    }

    public void setPaySavingAsSpected(Double paySavingAsSpected) {
        this.paySavingAsSpected = paySavingAsSpected;
    }

    public Double getAccidentAsSpected() {
        return accidentAsSpected;
    }

    public void setAccidentAsSpected(Double accidentAsSpected) {
        this.accidentAsSpected = accidentAsSpected;
    }

    public Double getTotalToPay() {
        return totalToPay;
    }

    public void setTotalToPay(Double totalToPay) {
        this.totalToPay = totalToPay;
    }

    public Boolean getActive() {
        return active;
    }

    public void setActive(Boolean active) {
        this.active = active;
    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }

    public Taxi getTaxi() {
        return taxi;
    }

    public void setTaxi(Taxi taxi) {
        this.taxi = taxi;
    }

    public User getCreatedBy() {
        return createdBy;
    }

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

    public Date getCreatedOn() {
        return createdOn;
    }

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

    public User getLastUpdatedBy() {
        return lastUpdatedBy;
    }

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

    public Date getLastUpdatedOn() {
        return lastUpdatedOn;
    }

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

    public TransferType getTransfer() {
        return transfer;
    }

    public void setTransfer(TransferType transfer) {
        this.transfer = transfer;
    }

    public Boolean getGarage() {
        return garage;
    }

    public void setGarage(Boolean garage) {
        this.garage = garage;
    }

    public Boolean getNuevaAsignacion() {
        return nuevaAsignacion;
    }

    public void setNuevaAsignacion(Boolean nuevaAsignacion) {
        this.nuevaAsignacion = nuevaAsignacion;
    }

    public Boolean getBanca() {
        return banca;
    }

    public void setBanca(Boolean banca) {
        this.banca = banca;
    }

    public Date getPayDateFix() {
        if (payDate != null) {
            Calendar c = Calendar.getInstance();
            c.setTime(payDate);
            int hora = c.get(Calendar.HOUR_OF_DAY);
            if (hora < 18) {
                c.add(Calendar.HOUR, 6);
            }

            return c.getTime();
        }

        return new Date();
    }

    public boolean getAction(Date lastStableSmallBox) {
        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(lastStableSmallBox);

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

    public BankCard getBankCard() {
        return bankCard;
    }

    public void setBankCard(BankCard bankCard) {
        this.bankCard = bankCard;
    }

    public ExpenseStatusType getStatus() {
        return status;
    }

    public void setStatus(ExpenseStatusType status) {
        this.status = status;
    }
    
    public double getProductividad(float porcentaje)
    {
        if(payDay == 0F)
        {
          return 0F;  
        }
    
        double dif = payDay * (porcentaje/100);
        
        return (payDay - dif);
    }

    @Override
    public String toString() {
        return "Sale{" + "id=" + id + ", description=" + description + ", active=" + active + ", person=" + person + ", taxi=" + taxi + '}';
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 19 * hash + Objects.hashCode(this.id);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Sale other = (Sale) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

}
