/*
 * 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.cosmodas.FacadeCosmos;

import com.cosmodas.EntCosmos.Top20;

import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 * @author obper
 */
@Stateless
public class Top20Facade extends AbstractFacade<Top20> implements Top20FacadeLocal {

    @PersistenceContext(unitName = "wcosmodasPersistent")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public Top20Facade() {
        super(Top20.class);
    }

    @Override
    public Double totalVenta() {

        String sql = "SELECT venta_total()";
        Query q = em.createNativeQuery(sql);
        List<Double> result = q.getResultList();
        Double rs = result.get(0);

        return rs;
    }

    @Override
    public Integer totalClienteConPedidos() {

        String sql = "SELECT pedidos_total()";
        Query q = em.createNativeQuery(sql);
        List<Integer> result = q.getResultList();
        Integer rs = result.get(0);

        return rs;
    }

    @Override
    public Integer totalClientesSinPedido() {

        String sql = "SELECT total_consultore_sin_pedidos()";
        Query q = em.createNativeQuery(sql);
        List<Integer> result = q.getResultList();
        Integer rs = result.get(0);

        return rs;
    }

}
