<?php

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

class Closingstock extends MY_Controller {

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

    public function index() {
          $data['location'] = $this->_getLocations();
        $this->load->view('settings/header');
        $this->load->view('inventory/closingstock_view', $data);
        $this->load->view('settings/footer');
    }
    //GET STOCK DIARY
    public function getclosingstock() {
        
        $mcategory = $this->input->post('mcategory');
        $products = $this->input->post('products');
        $datefrom = $this->input->post('datefrom');
        $dateto = $this->input->post('dateto');
        $this->load->model('inventory/closingstock_model');
        echo $this->closingstock_model->getclosingstock($mcategory, $products, $datefrom, $dateto );
}

    //PRINT CURRENT INVENTORY
    public function printcurrentstock() {
        /*$this->load->helper('dompdf');
        $this->load->helper('file');
        $this->load->model('inventory/currentinventory_model');
        $this->load->library('session');
        $location = $this->session->userdata('location');
        $mcategory = $this->session->userdata('mcategory');
        $products = $this->session->userdata('products');
        if ($products) {
            $this->load->model('inventory/products_model');
            $products = $this->products_model->getpidbn($products);
        } else {
            $products = null;
        }
        $data['inventorylines'] = $this->currentinventory_model->getcurrentstockdetailsprint($location,$mcategory,$products);
        $this->load->model('settings/companyinfo_model');
        $data['location'] = $location;
        $data['companyinfo'] = $this->companyinfo_model->getcompanyinfo('0');  
        $html = $this->load->view('reports/inventory/currentinventory_print', $data, true);
        $ss=count($data);
        pdf_create($html, 'STOCKCURRENT', false);*/
        
         $this->load->library('session');
        $product = $this->session->userdata('PRODUCT');
        $productgroups = $this->session->userdata('PRODUCTGROUPS');
        $warehouse = $this->session->userdata('WAREHOUSE');
        $category = $this->session->userdata('CATEGORY');
        $array_items = array('PRODUCT' => '','PRODUCTGROUPS' => '', 'WAREHOUSE' => '', 'CATEGORY' => '');
        $this->session->unset_userdata($array_items);
        //$product='milk';
        $this->load->helper('dompdf');
        $this->load->helper('file');
        $this->load->model('settings/companyinfo_model');      
        $this->load->model('reports/inventory_model');
         $data['companyinfo'] = $this->companyinfo_model->getcompanyinfo('0');
         $data['reportdata']= $this->inventory_model->getinventorylinesbyid($warehouse, $category, $product,$productgroups);
        $this->load->model('reports/report_model');
        $data['columns'] = $this->report_model->getcolumns('INVENTORY');
        $data['reporttitle'] = 'Current Inventory';
        $html = $this->load->view('reports/report_template1_print', $data, true);
        pdf_create($html, 'STOCKCURRENT', false);
        
        
   }

   function setparamsinsessionforprintcurrentstock()
   {
        $location = $this->input->post('location');           
        $mcategory = $this->input->post('mcategory');
        $products = $this->input->post('products');
        $this->load->library('session');
        $this->session->set_userdata('location',  $this->input->post('location'));
        $this->session->set_userdata('mcategory',  $this->input->post('mcategory'));
        $this->session->set_userdata('products',  $this->input->post('products'));
        return 1;
    }
    
    //GET LOCATION LIST
    private function _getLocations($id = NULL) {
        $this->load->model('inventory/products_model');
        $catarr = $this->products_model->getLocations();
        $data = '<option value="">Select</option>';
        for ($i = 0; $i < count($catarr); $i++) {
        if ($id != NULL && $id == $catarr[$i]->ID)
            $data .= "<option id=\"option_custom\" selected=\"yes\" value=\"" . $catarr[$i]->ID . "\">" . $catarr[$i]->NAME . "</option>\n";
        else
            $data .= "<option id=\"option_custom\" value=\"" . $catarr[$i]->ID . "\">" . $catarr[$i]->NAME . "</option>\n";
        }
        return $data;
    }   


}