
<?php

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

class customercategorysale extends MY_Controller {

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

    public function index() {
         $data['categories'] = $this->_getProdCategories();
        $this->load->view('settings/header');
        $this->load->view('sales/customercategorysale_view', $data);
        $this->load->view('settings/footer');
    }
 
    // GET FOOD COSTING
    function getcustomersale() {
         $this->load->model('sales/salereport_model');
         $productgroup = $this->input->post('productgroup');
         $category = $this->input->post('category');
         $products = $this->input->post('products');
         $datefrom = $this->input->post('datefrom');
         $dateto = $this->input->post('dateto');

       $this->load->model('sales/customercategorysale_model');
       echo  $this->customercategorysale_model->getcustomersale($datefrom, $dateto);

    }

 private function _getProdCategories($id = NULL) {
        $this->load->model('inventory/categories_model');
        $catarr = $this->categories_model->getproductcategories();

        $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;
    }
    function exportcsv()
{


        $file="salereport.csv";
            header("Content-Disposition: attachment; filename=" . urlencode($file));
            header("Content-Type: application/force-download");
            header("Content-Type: application/octet-stream");
            header("Content-Type: application/download");
            header("Content-Description: File Transfer");
            header("Content-type: application/csv");
            header("Pragma: no-cache");
            header("Expires: 0");

            $export= $this->input->post('exportdata');


$this->load->helper('download');
force_download($file, $export);
}

 
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


