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

import com.arrebol.taxiservicios.controller.connection.ConnectionManager;
import com.arrebol.taxiservicios.controller.util.HibernateUtil;
import com.arrebol.taxiservicios.model.view.report.DailyMoney;
import com.arrebol.taxiservicios.model.view.report.DailySale;
import java.io.Serializable;
import java.util.List;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author Picasso
 */
public class DailyMoneyController extends ConnectionManager implements Serializable {

    /**
     *
     * @return
     */
    public DailyMoney getReportDailyMoney() {
        logger.info("findAllDailyMoneyToday");

        DailyMoney dailyMoney = null;
        Transaction transaction = null;

        try {
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
            transaction = session.beginTransaction();

            CriteriaBuilder builder = session.getCriteriaBuilder();
            CriteriaQuery<DailyMoney> query = builder.createQuery(DailyMoney.class);

            Root<DailyMoney> root = query.from(DailyMoney.class);

            query.select(root);

            dailyMoney = session.createQuery(query).getSingleResult();

            transaction.commit();
            logger.info("Report daily money " + dailyMoney);
        } catch (HibernateException e) {
            rollback(transaction);
            logger.error("Can not load list of of daily money", e);
        } catch (Exception e) {
            rollback(transaction);
            logger.error("Method findAllDailyMoneyToday", e);
        }

        return dailyMoney;
    }

    private static final long serialVersionUID = 3680049238403721378L;

    final Logger logger = LogManager.getLogger(DailyMoneyController.class);

    public DailyMoneyController() {
    }

}
