
<?php

defined('BASEPATH') or exit('No direct script access allowed');

class EggProduction extends CI_Model
{
    function __construct()
    {
        parent::__construct();
    }

    function getEggProduction($start, $end, $rodeo = NULL)
    {
        if ($rodeo) {
            $query = $this->db->query("SELECT * FROM vw_eggProduction WHERE 
                                    (date_productions BETWEEN '$start' AND '$end') AND id_rodeo='$rodeo'");
        } else {
            $query = $this->db->query("SELECT * FROM vw_eggProduction WHERE 
                                    (date_productions BETWEEN '$start' AND '$end')");
        }
        $reponseDB = array(
            "status" => "success",
            "status_code" => 200,
            "message" => "Data loaded, successful",
            "validations" => null,
            "data" => $query->result()
        );
        return $reponseDB;
    }

    function getEggProductionAll($page = NULL, $limit = NULL){
        if ($page != NULL && $limit != NULL) {
            $page_num = max(0, ($page - 1) * $limit);
            $query = $this->db->query("SELECT *  FROM `vw_production` WHERE status=1 LIMIT {$page_num}, {$limit} ");
        } else {
            $query = $this->db->query("SELECT *  FROM `vw_production` WHERE status=1");
        }
        $reponseDB = array(
            "status" => "success",
            "status_code" => 200,
            "message" => "Data loaded, successful",
            "validations" => null,
            "data" => $query->result()
        );

        return $reponseDB;
    }
}
