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

class Saleslog extends MY_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('sales/saleslog_model');
    }

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

    //  COLUNM NAMES


    // GET FOOD COSTING
    function getsalelog() {
        
         $paymenttype = $this->input->post('paymenttype');
         $datefrom = $this->input->post('datefrom');
         $dateto = $this->input->post('dateto');
         //$data['productsale'] = $this->saleslog_model->getsalelog($datefrom, $dateto, $paymenttype);
        $data['data'] = $this->saleslog_model->getsalelog($datefrom, $dateto, $paymenttype);
        echo json_encode($data);
         //print_r($data['productsale']); die();
        /* ?>

           <table class="table table-striped table-hover table-bordered" id="simpledatatable">
                                        <thead>
                                            <tr role="row">
                                                <th>
                                                    ID
                                                </th>
                                                <th>
                                                   RECEIPT NO
                                                </th>
                                                <th>
                                                    DATE
                                                </th>
                                    
                                                   <th>
                                                 CUSTOMER
                                                </th>
                                                   <th>
                                                 TOTAL
                                                </th>
                                            </tr>
                                        </thead>
                                                              
          <tbody>
         <tr><td colspan="6">Item: <?php echo count($data['productsale']);?></td></tr>
          <?php $i=1; 
          $totalcount = 0;
          foreach($data['productsale'] as $productsale1) { ?>            
               <tr>
                   <td><?php echo $i;?></td>
                   <td><?php echo $productsale1->RECEIPT;?></td>
                   <td><?php echo $productsale1->DATE;?></td>
                   <td><?php echo $productsale1->CUSTOMER;?></td>
                   <td><?php echo $productsale1->TOTAL;?></td>
                 </tr>
          <?php $i++; 
          $totalcount = $totalcount + $productsale1->TOTAL;
        }  ?>
        <tr>
                   <td colspan="4">Total:</td>
                   <td><?php echo $totalcount;?></td>
        </tr>
             </tbody>
                                    </table>
        

            <?php*/
    }

 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="saleslog.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.
 */


