<?php

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

class Expiryreport_model extends CI_Model {

    public function __construct() {
        parent::__construct();
    }

    public function getreport($product,$datefrom,$dateto) {
        
        $table_name = "STOCKCURRENT SC";
        $this->db->select("P.CODE, P.NAME, SC.UNITS, STR_TO_DATE(ASI.DESCRIPTION, '%d %M,%Y') EXPIRY", false)->from($table_name);
        if ($product) {
            $this->db->like("P.NAME", $product);
        }
        if ($datefrom && $dateto) {
            $this->db->where("STR_TO_DATE(ASI.DESCRIPTION, '%d %M,%Y') >=", $datefrom);
            $this->db->where("STR_TO_DATE(ASI.DESCRIPTION, '%d %M,%Y') <=", $dateto);
        } else if ($datefrom) {
            $this->db->where("STR_TO_DATE(ASI.DESCRIPTION, '%d %M,%Y') =", $datefrom);
        }
        $this->db->join('ATTRIBUTESETINSTANCE ASI', 'SC.ATTRIBUTESETINSTANCE_ID=ASI.ID');
        $this->db->join('PRODUCTS P', 'SC.PRODUCT=P.ID');
        $this->db->order_by("EXPIRY", 'ASC');
        return $this->db->get()->result();
    }

}