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

import com.arrebol.taxiservicios.beans.TaxiGenericBean;
import com.arrebol.taxiservicios.controller.sp.report.ReportSundayPaymentController;
import com.arrebol.taxiservicios.model.sp.report.SundayPayment;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.view.ViewScoped;
import javax.inject.Named;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 *
 * @author Oscar Vargas
 */
@Named
@ViewScoped
public class ReportSundayPaymentBean extends TaxiGenericBean implements Serializable {

    public void updateReport() {
        LOG.info("updateReport");
        try {
            setReport(
                    getController().callReportSundayPaymentQueryMySQL(DATE_FORMAT.format(getStartDate()), DATE_FORMAT.format(getEndDate()))
            );
        } catch (Exception e) {
            LOG.error("updateReport", e);
        }
    }

    @PostConstruct
    public void init() {
        LOG.info("init");
        try {
            loadBundlePropertyFile();
            setController(new ReportSundayPaymentController());
            setReport(
                    getController().callReportSundayPaymentQueryMySQL(DATE_FORMAT.format(getStartDate()), DATE_FORMAT.format(getEndDate()))
            );
        } catch (Exception e) {
            LOG.error("init", e);
        }
    }

    private static final long serialVersionUID = 6394938203433032821L;
    private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");

    final Logger LOG = LogManager.getLogger(ReportSundayPaymentBean.class);

    private ReportSundayPaymentController controller;
    private List<SundayPayment> report;
    private Date startDate;
    private Date endDate;

    public ReportSundayPaymentBean() {
    }

    public ReportSundayPaymentController getController() {
        return controller;
    }

    public void setController(ReportSundayPaymentController controller) {
        this.controller = controller;
    }

    public List<SundayPayment> getReport() {
        return report;
    }

    public void setReport(List<SundayPayment> report) {
        this.report = report;
    }

    public Date getStartDate() {
        if (null == startDate) {
            startDate = new Date();
        }

        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        if (null == endDate) {
            endDate = new Date();
        }
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }

}
