package com.arrebol.taxiservicios.model.admin;

import com.arrebol.taxiservicios.model.catalog.BankCard;
import com.arrebol.taxiservicios.model.catalog.ExpenseIncomeCatalog;
import com.arrebol.taxiservicios.model.catalog.Location;
import com.arrebol.taxiservicios.model.core.Person;
import com.arrebol.taxiservicios.model.core.User;
import com.arrebol.taxiservicios.model.enums.BasicType;
import com.arrebol.taxiservicios.model.enums.ExpenseStatusType;
import com.arrebol.taxiservicios.model.enums.ExpenseType;
import com.arrebol.taxiservicios.model.stocktaking.ServiceOrder;
import com.arrebol.taxiservicios.model.view.report.PaymentClient;
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Objects;
import java.util.logging.Level;
import java.util.logging.Logger;

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

    private static final long serialVersionUID = -1674727568589909283L;

    private String id;
    private String folio;
    private Double payment;
    private Date paymentDate;
    private String description;
    private ExpenseType type;
    private ExpenseStatusType status;
    private Taxi taxi;
    private Person driver;
    private User createdBy;
    private Date createdOn;
    private User lastUpdatedBy;
    private Date lastUpdatedOn;
    private Double amountMenudeo;
    private Location location;
    
    private Location locationSend;
    private BasicType paid;
    private BasicType finance;
    private PaymentClient paymentClient;
    private Date financeDate;
    private PaymentClient paymentClientFinance;
    private BasicType commercialInvoiceStatus;
    private ExpenseIncomeCatalog idExpenseType;
    private BankCard bankCard;
    private ExpenseStatusType depositStatus;
    private ServiceOrder serviceOrder;

    /**
     * Default constructor.
     */
    public Expense() {
    }

    public Expense(String id, String folio, Double payment, Date paymentDate, String description,
            ExpenseType type, ExpenseStatusType status, Taxi taxi) {

        this.id = id;
        this.folio = folio;
        this.payment = payment;
        this.paymentDate = paymentDate;
        this.description = description;
        this.type = type;
        this.status = status;
        this.taxi = taxi;
    }

    public Expense(String id, String folio, Double payment, Date paymentDate, String description, ExpenseType type, ExpenseStatusType status, Taxi taxi, ExpenseIncomeCatalog idExpenseType) {
        this.id = id;
        this.folio = folio;
        this.payment = payment;
        this.paymentDate = paymentDate;
        this.description = description;
        this.type = type;
        this.status = status;
        this.taxi = taxi;
        this.idExpenseType = idExpenseType;
    }    
    
    public Expense(Double payment) {

        this.payment = payment;

    }

    public Location getLocation() {
        return location;
    }

    public void setLocation(Location location) {
        this.location = location;
    }

    public String getId() {
        return id;
    }

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

    public String getFolio() {
        return folio;
    }

    public void setFolio(String folio) {
        this.folio = folio;
    }

    public Double getPayment() {
        return payment;
    }

    public void setPayment(Double payment) {
        this.payment = payment;
    }

    public Date getPaymentDate() {
        return paymentDate;
    }

    public void setPaymentDate(Date paymentDate) {
        this.paymentDate = paymentDate;
    }

    public String getDescription() {
        return description;
    }

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

    public ExpenseType getType() {
        return type;
    }

    public void setType(ExpenseType type) {
        this.type = type;
    }

    public ExpenseStatusType getStatus() {
        return status;
    }

    public void setStatus(ExpenseStatusType status) {
        this.status = status;
    }

    public Taxi getTaxi() {
        return taxi;
    }

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

    public Person getDriver() {
        return driver;
    }

    public void setDriver(Person driver) {
        this.driver = driver;
    }

    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 Location getLocationSend() {
        return locationSend;
    }

    public void setLocationSend(Location locationSend) {
        this.locationSend = locationSend;
    }

    public BasicType getPaid() {
        return paid;
    }

    public void setPaid(BasicType paid) {
        this.paid = paid;
    }

    public BasicType getFinance() {
        return finance;
    }

    public void setFinance(BasicType finance) {
        this.finance = finance;
    }

    public PaymentClient getPaymentClient() {
        return paymentClient;
    }

    public void setPaymentClient(PaymentClient paymentClient) {
        this.paymentClient = paymentClient;
    }
    
    public String getTypeString(){
        return type.getType();
    
    }

    public Date getFinanceDate() {
        return financeDate;
    }

    public void setFinanceDate(Date financeDate) {
        this.financeDate = financeDate;
    }

    public PaymentClient getPaymentClientFinance() {
        return paymentClientFinance;
    }

    public void setPaymentClientFinance(PaymentClient paymentClientFinance) {
        this.paymentClientFinance = paymentClientFinance;
    }

    public BasicType getCommercialInvoiceStatus() {
        return commercialInvoiceStatus;
    }

    public void setCommercialInvoiceStatus(BasicType commercialInvoiceStatus) {
        this.commercialInvoiceStatus = commercialInvoiceStatus;
    }
            

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

    public Double getAmountMenudeo() {
        return amountMenudeo;
    }

    public void setAmountMenudeo(Double amountMenudeo) {
        this.amountMenudeo = amountMenudeo;
    }

    public ExpenseIncomeCatalog getIdExpenseType() {
        return idExpenseType;
    }

    public void setIdExpenseType(ExpenseIncomeCatalog idExpenseType) {
        this.idExpenseType = idExpenseType;
    }
    

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Expense other = (Expense) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }
    
    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(Expense.class.getName()).log(Level.SEVERE, null, ex);
        }
        return action;
    }

    @Override
    public String toString() {
        return folio + " "+amountMenudeo + " " + description + " " + type;
    }

    public ServiceOrder getServiceOrder() {
        return serviceOrder;
    }

    public void setServiceOrder(ServiceOrder serviceOrder) {
        this.serviceOrder = serviceOrder;
    }

    public BankCard getBankCard() {
        return bankCard;
    }

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

    public ExpenseStatusType getDepositStatus() {
        return depositStatus;
    }

    public void setDepositStatus(ExpenseStatusType depositStatus) {
        this.depositStatus = depositStatus;
    }
    
    
    
    
}
