<?php namespace App\Models;

use CodeIgniter\Database\ConnectionInterface;

class ClientsModel
{
    protected $db;

    public  function __construct(ConnectionInterface &$db)
    {
        $this->db =& $db;
    }

    /*
     * Get all rows from table
     */
    function getAll($id){
        $builder = $this->db->table('clients');
        $builder->where('empresa_id_client', $id);
        $builder->orderBy('id_client', 'DESC');
        $query = $builder->get()->getResult();
        return $query;
    }

    function getCount($id){
        $query = $this->db->query(" 
         SELECT count(id_client) as id FROM clients WHERE empresa_id_client = $id
         ")->getResult();
        return $query;
    }

}