<?php

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

class Uniformreport extends Admin_Controller {

    function __construct() {
        parent::__construct();
        $this->session->set_userdata('top_menu', 'Uniform Stock Management');
        $this->session->set_userdata('sub_menu', 'uniformreport/index');
        $data['title_list'] = 'Uniform Stock Management';
        
    }

    function index() {
        if (!$this->rbac->hasPrivilege('class', 'can_view')) {
            access_denied();
           
        }
      
          // Get filter inputs (from POST)
          $filter_from_date = $this->input->post('filter_from_date');
          $filter_to_date = $this->input->post('filter_to_date');
          $filter_start_item = $this->input->post('filter_start_item');
          $filter_end_item = $this->input->post('filter_end_item');
          
            // Reformat dates to 'YYYY-MM-DD' if they are not already in that format
          $filter_from_date = date('Y-m-d', strtotime($filter_from_date));
          $filter_to_date = date('Y-m-d', strtotime($filter_to_date));
  
          // Fetch item codes for the dropdown
          $data['itemCodes'] = $this->uniformpos_model->getItemCodes();  
  
          // Retrieve filtered stock data based on the filters
          if (!empty($filter_from_date) && !empty($filter_to_date) && !empty($filter_start_item) && !empty($filter_end_item)) {
              $data['unif_stock_mgnt'] = $this->uniformpos_model->getFilteredStockmgntData($filter_from_date,$filter_to_date,$filter_start_item, $filter_end_item);
          } else {
              $data['unif_stock_mgnt'] = []; // Empty data for the table if no filters applied
          } 
     // Fetch summary data from the mode
     $data['qnty_received'] = $this->uniformitem_model->getTotalUniformsReceived();
     $data['qnty_sold'] = $this->uniformitem_model->getTotalUniformsSold();
     $data['qnty_available'] = $this->uniformitem_model->getTotalUniformsAvailable();
	// $data['unif_stock_mgnt']=$this->uniformpos_model->selectuniformposreport();
        $this->load->view('layout/header', $data);
        $this->load->view('uniformreport/uniformreport', $data);
        $this->load->view('layout/footer', $data);
    }    
    
	function printUniformReport() {
        if (!$this->rbac->hasPrivilege('class', 'can_view')) {
            access_denied();
 
        }
		        $setting_result = $this->setting_model->get();
                $data['settinglist'] = $setting_result;
                // Load required models
                $data['qnty_received'] = $this->uniformitem_model->getTotalUniformsReceived();
                $data['qnty_sold'] = $this->uniformitem_model->getTotalUniformsSold();
                $data['qnty_available'] = $this->uniformitem_model->getTotalUniformsAvailable();
             
		
        $this->load->view('print/printUniformReport', $data);
    }
}

?>