/*
 * 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.web.beans.admin;

import com.arrebol.apc.controller.GenericController;
import com.arrebol.apc.controller.admin.StatsGasolineController;
import com.arrebol.apc.model.views.StatsGasolineView;
import com.arrebol.apc.web.beans.Datatable;
import com.arrebol.apc.web.beans.GenericBean;
import java.io.Serializable;
import java.util.Calendar;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.application.FacesMessage;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.primefaces.event.ReorderEvent;
import org.primefaces.event.RowEditEvent;

/**
 *
 * @author David Rodriguez
 */
@Named("statsGasolineManager")
@ViewScoped
public class StatsGasolineBean extends GenericBean implements Serializable, Datatable {

    public void searchHistoricalAction() {
        try {
            if (getStarDate().after(getEndDate())) {
                showMessage(FacesMessage.SEVERITY_ERROR, getBundlePropertyFile().getString("generic.start.date"), getBundlePropertyFile().getString("generic.end.date.error"));
            } else {
                setGasoline(fillDatatableGasoline());
                setTotalGasoline(fillTotalGasoline());
            }
        } catch (Exception e) {
        }
    }

    public Double searchTotalGasolineAction() {
        try {
            if (getStarDate().after(getEndDate())) {
                showMessage(FacesMessage.SEVERITY_ERROR, getBundlePropertyFile().getString("generic.start.date"), getBundlePropertyFile().getString("generic.end.date.error"));
            } else {
                setTotalGasoline(fillTotalGasoline());
            }
        } catch (Exception e) {
        }
        return getTotalGasoline();
    }

    public StatsGasolineController getGasolineCtrl() {
        return gasolineCtrl;
    }

    public void setGasolineCtrl(StatsGasolineController gasolineCtrl) {
        this.gasolineCtrl = gasolineCtrl;
    }

    public GenericController getGenericCtrl() {
        return genericCtrl;
    }

    public void setGenericCtrl(GenericController genericCtrl) {
        this.genericCtrl = genericCtrl;
    }

    public List<StatsGasolineView> fillDatatableGasoline() {
        return getGasolineCtrl().fillGasolineDataTable(getStarDate(), getEndDate());
    }

    public Double fillTotalGasoline() {
        return getGasolineCtrl().fillTotalGasoline(getStarDate(), getEndDate());
    }

    public List<StatsGasolineView> getGasoline() {
        return gasoline;
    }

    public void setGasoline(List<StatsGasolineView> gasoline) {
        this.gasoline = gasoline;
    }

    public StatsGasolineView getSelectedGasoline() {
        return selectedGasoline;
    }

    public void setSelectedGasoline(StatsGasolineView selectedGasoline) {
        this.selectedGasoline = selectedGasoline;
    }

    public Double getTotalGasoline() {
        return totalGasoline;
    }

    public void setTotalGasoline(Double totalGasoline) {
        this.totalGasoline = totalGasoline;
    }

    private StatsGasolineController gasolineCtrl;
    private GenericController genericCtrl;
    private List<StatsGasolineView> gasoline;
    private StatsGasolineView selectedGasoline;
    private Double totalGasoline;

    @PostConstruct
    public void init() {
        loadBundlePropertyFile();
        initStartAndEndDates(Calendar.DAY_OF_WEEK, 2);

        gasolineCtrl = new StatsGasolineController();
        genericCtrl = new GenericController();
        gasoline = fillDatatableGasoline();
        totalGasoline = fillTotalGasoline();
    }

    @Override
    public void editRow(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowCancel(RowEditEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void onRowReorder(ReorderEvent event) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void addRow() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void deleteRow() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
}
