<?php

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

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



    function treatmentsDetails($earring = NULL)
    {
        if ($earring) {

            $query = $this->db->query("SELECT * FROM `vw_treatmentDetails` WHERE animalEarting = '$earring' and start_date BETWEEN (CURDATE() - INTERVAL 30 DAY) AND CURDATE();");
            $reponseDB = array(
                "status" => "success",
                "status_code" => 200,
                "message" => "Data loaded, successful",
                "validations" => null,
                "data" => $query->result()
            );
        } else {
            $query = $this->db->query("SELECT * FROM `vw_treatmentDetails` WHERE  start_date BETWEEN (CURDATE() - INTERVAL 30 DAY) AND CURDATE();");
            $reponseDB = array(
                "status" => "success",
                "status_code" => 200,
                "message" => "Data loaded, successful",
                "validations" => null,
                "data" => $query->result()
            );
        }
        return $reponseDB;
    }


    
    function treatmentsHistory($earring = NULL)
    {
        if ($earring) {

            $query = $this->db->query("SELECT * FROM `vw_treatmentDetails` WHERE animalEarting = '$earring' ");
            $reponseDB = array(
                "status" => "success",
                "status_code" => 200,
                "message" => "Data loaded, successful",
                "validations" => null,
                "data" => $query->result()
            );
        } else {
            $query = $this->db->query("SELECT * FROM `vw_treatmentDetails` WHERE  start_date BETWEEN (CURDATE() - INTERVAL 30 DAY) AND CURDATE();");
            $reponseDB = array(
                "status" => "success",
                "status_code" => 200,
                "message" => "Data loaded, successful",
                "validations" => null,
                "data" => $query->result()
            );
        }
        return $reponseDB;
    }
    

}
