
<?php

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

class salestotalregister extends MY_Controller {

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

    public function index() {
         $data['categories'] = $this->_getProdCategories();
        $this->load->view('settings/header');
        $this->load->view('sales/salestotalregister_view', $data);
        $this->load->view('settings/footer');
    }

    //  COLUNM NAMES


    // GET FOOD COSTING
    function getsalestotalregister() {
         $this->load->model('sales/salestotalregister_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/salestotalregister_model');
echo  $this->salestotalregister_model->getsalestotalregister($datefrom, $dateto);
//var_dump($b);
//$b= $this->salestotalregister_model->getsalestotalregister($datefrom, $dateto);
//var_dump($b);
    }

 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="salestotalregister.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);
}

 function getcolumns() {

        $params = $this->uri->segment(3);
        if ($params == 1 || $params == 0) {
            $data = '{"cnames": ["PRODUCT GROUP","CATEGORY","PRODUCT","PRICE","QUANTITY","TOTAL"], "url": "sales/salereport/getproductsale",
                "colModel": [
{"name":"REFERENCE","index":"REFERENCE","hidden":true, "width":"100", "sorttype":"date", "datefmt":"Y-mm-d"},
{"name":"CATEGORY","index":"CATEGORY", "width":"100", "sorttype":"date", "formatter":"date", "formatoptions": {"newformat":"d-M-Y"}},
{"name":"PRODUCT","index":"PRODUCT", "width":"100"},
{"name":"PRICE","index":"PRICE", "width":"100"},
{"name":"QUANTITY","index":"QUANTITY", "width":"100", "align":"center"},

{"name":"TOTAL","index":"TOTAL", "hidden":true,"width":"100", "align":"right"}
]}';
        } else if ($params ==42) {

            $data = '{"cnames": ["REQUIREDON","CATEGORY","PRODUCT","RQTY","QOH","UOM","POQTY","QTYSTS","TOTAL"], "url": "inventory/materialplanning/getlinesbycategory",
                "colModel": [
{"name":"REQUIREDON","index":"REQUIREDON", "width":"50", "sorttype":"date", "formatter":"date", "formatoptions": {"newformat":"d-M-Y"}},
{"name":"CATEGORY","index":"CATEGORY", "width":"70"},
{"name":"PRODUCT","index":"PRODUCT", "width":"100"},
{"name":"RQTY","index":"APPROVEDQUANTITY", "width":"25"},
{"name":"QOH","index":"QOH", "width":"25"},
{"name":"UOM","index":"UOM", "width":"35"},
{"name":"POQTY","index":"POQTY", "width":"25"},
{"name":"QTYSTS","index":"QTYSTS", "width":"35"},
{"name":"TOTAL","index":"TOTAL", "width":"70", "align":"right", "formatter":"currency", "formatoptions": {"thousandsSeparator":","}}
]}';
        } else if ($params == 93) {
            $data = '{"cnames": ["REQUIREDON","LOCATION","TOTAL"], "url": "inventory/materialplanning/getlinesbylocation",
                "colModel": [
{"name":"REQUIREDON","index":"REQUIREDON", "width":"100", "sorttype":"date", "formatter":"date", "formatoptions": {"newformat":"d-M-Y"}},
{"name":"CATEGORY","index":"LOCATIONNAME", "width":"100"},
{"name":"TOTAL","index":"TOTAL", "width":"100", "align":"right", "formatter":"currency", "formatoptions": {"thousandsSeparator":","}}
]}';
        } else {
            $data = '{"cnames": ["PRODUCT GROUP","CATEGORY","PRODUCT","PRICE","QUANTITY","TOTAL"], "url": "sales/salereport/getproductsale"}';
        }
      //  echo $data;
        var_dump($data);
    }
}
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


