<?php

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

class Sales extends MY_Controller {

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

     public function index() {       
          $data['template'] = 'reports/reports_sales_view';
          $this->load->view('template',$data);
    }
     function closedcash()
    {
    
          $data['template'] = 'reports/sales/closedcash_view';
          $this->load->view('template',$data);
    }
      public function printclosedcash() {
            $this->load->library('session');
            $datefrom = $this->session->userdata('DATEFROM');
            $dateto = $this->session->userdata('DATETO');
            $hostsequence = $this->session->userdata('SEQUENCE');
             
            $array_items = array('DATEFROM' => '','DATETO' => '','SEQUENCE' => '',);
                  $this->session->unset_userdata($array_items);

        $this->load->helper('dompdf');
        $this->load->helper('file');
        $this->load->model('settings/companyinfo_model');
        $this->load->model('reports/sales_model');
        $data['companyinfo'] = $this->companyinfo_model->getcompanyinfo('1');
        $data['reportdata'] = $this->sales_model->getclosedcash($datefrom,$dateto,$hostsequence);
        $this->load->model('reports/report_model');
        $data['columns'] = $this->report_model->getcolumns('CLOSEDCASH');
        $data['reporttitle'] = 'Closed Cash';
         $html = $this->load->view('reports/report_template1_print', $data, true);
         echo $html;
             // pdf_create($html, 'CLOSEDCASH', false);

    }
    
       function setparamsinsessionforclosedcash()
    {
       $this->load->library('session');
        $this->session->set_userdata('DATEFROM',  $this->input->post('DATEFROM'));
       $this->session->set_userdata('DATETO',  $this->input->post('DATETO'));
       $this->session->set_userdata('SEQUENCE',  $this->input->post('SEQUENCE'));
       return 1;
    }



    function saleslog()
    {

          $data['template'] = 'reports/sales/saleslog_view';
          $this->load->view('template',$data);
    }
       public function printsaleslog() {
               $this->load->library('session');
               $datefrom = $this->session->userdata('DATEFROM');
            $dateto = $this->session->userdata('DATETO');
          
            $array_items = array('DATEFROM' => '','DATETO' => '');
         
        $this->session->unset_userdata($array_items);
         $this->load->helper('dompdf');
            $this->load->helper('file');
           $this->load->model('settings/companyinfo_model');
           $this->load->model('reports/sales_model');
          $data['companyinfo'] = $this->companyinfo_model->getcompanyinfo('1');
         $data['reportdata'] = $this->sales_model->getsaleslog($datefrom,$dateto);
//   var_dump($data);
         $this->load->model('reports/report_model');
        $data['columns'] = $this->report_model->getcolumns('SALESLOG');
        $data['reporttitle'] = 'Sales Log';
        $html = $this->load->view('reports/report_template1_print', $data, true);
        echo $html;
           //  pdf_create($html, 'SALESLOG', false);

    }
       function setparamsinsessionforsaleslog()
    {
       $this->load->library('session');
        $this->session->set_userdata('DATEFROM',  $this->input->post('DATEFROM'));
       $this->session->set_userdata('DATETO',  $this->input->post('DATETO'));
       return 1;
    }
 function productsales()
    {
    
          $data['template'] = 'reports/sales/productsales_view';
          $this->load->view('template',$data);
    }
 public function printproductsales() {

          $this->load->library('session');
      $product = $this->session->userdata('PRODUCT');
       $category = $this->session->userdata('CATEGORY');
         $productgroups = $this->session->userdata('PRODUCTGROUPS');
         $datefrom = $this->session->userdata('DATEFROM');
         $dateto = $this->session->userdata('DATETO');
//       var_dump($product);
//        var_dump($category);
        $array_items = array('PRODUCT' => '','CATEGORY' => '','PRODUCTGROUPS' =>'','DATEFROM' => '','DATETO' => '');
        $this->session->unset_userdata($array_items);

         $this->load->helper('dompdf');
            $this->load->helper('file');
           $this->load->model('settings/companyinfo_model');
           $this->load->model('reports/sales_model');
        $data['companyinfo'] = $this->companyinfo_model->getcompanyinfo('1');
        
    $data['reportdata']= $this->sales_model->getproductsales($category, $product,$productgroups,$datefrom,$dateto);
    $this->load->model('reports/report_model');
$data['columns'] = $this->report_model->getcolumns('PRODUCTSALES');
$data['reporttitle'] = 'Product Sales';
        $html = $this->load->view('reports/report_template1_print', $data, true);
        echo $html;
        //pdf_create($html, 'PRODUCTSALES', false);
    }
   
       function setparamsinsessionforproductsales()
    {
        $this->load->library('session');
             $this->session->set_userdata('CATEGORY',  $this->input->post('CATEGORY'));
       $this->session->set_userdata('PRODUCT', $this->input->post('PRODUCT'));
       $this->session->set_userdata('PRODUCTGROUPS',  $this->input->post('PRODUCTGROUPS'));
       $this->session->set_userdata('DATEFROM',   $this->input->post('DATEFROM'));
          $this->session->set_userdata('DATETO',   $this->input->post('DATETO'));
               return 1;
    }

     function tariffsales()
    {
    
          $data['template'] = 'reports/sales/tariffsales_view';
          $this->load->view('template',$data);
    }
 /*public function printtariffsales() {
     $this->load->library('session');
            $tariff= $this->session->userdata('TARIFF');
               $datefrom = $this->session->userdata('DATEFROM');
            $dateto = $this->session->userdata('DATETO');

            $array_items = array('TARIFF' => '','DATEFROM' => '','DATETO' => '');
        $this->session->unset_userdata($array_items);
       
         $this->load->helper('dompdf');
            $this->load->helper('file');
           $this->load->model('settings/companyinfo_model');
           $this->load->model('reports/sales_model');
          $data['companyinfo'] = $this->companyinfo_model->getcompanyinfo('0');
         
          $data['reportdata'] = $this->sales_model->gettariffsales($tariff,$datefrom,$dateto);
         $this->load->model('reports/report_model');
        $data['columns'] = $this->report_model->getcolumns('TARIFFSALES');
        $data['reporttitle'] = 'Tariff Sales';
        $html = $this->load->view('reports/report_template1_print', $data, true);
        echo $html;
          /*$data['tariffsales'] = $this->sales_model->gettariffsales($tariff,$datefrom,$dateto);
          //  var_dump($data['companyinfo']);
        //  var_dump($data['tariffsales']);

         $html = $this->load->view('reports/sales/tariffsales_print', $data, true);
             //pdf_create($html, 'TARIFFSALES', false);*/

    //}
       function setparametersessionfortariffsales()
    {

       $this->load->library('session');

        $this->session->set_userdata('DATEFROM',  $this->input->post('DATEFROM'));
       $this->session->set_userdata('DATETO',  $this->input->post('DATETO'));
               return 1;
        }
      private function _getstation($id = NULL) {
        $this->load->model('reports/sales_model');
        $catarr = $this->sales_model->getstation();
        $data = '';
        for ($i = 0; $i < count($catarr); $i++) {
            if ($i != NULL && $i == $catarr[$i]->MONEY)
                $data .= "<option selected=\"yes\" value=\"" . $catarr[$i]->MONEY . "\">" . $catarr[$i]->HOST . "</option>\n";
            else
                $data .= "<option value=\"" . $catarr[$i]->MONEY . "\">" . $catarr[$i]->HOST . "</option>\n";
        }
        return $data;
    }
     public function printtariffsales() {

       $this->load->library('session');

               $datefrom = $this->session->userdata('DATEFROM');

            $dateto = $this->session->userdata('DATETO');

             $array_items = array('DATEFROM' => '','DATETO' => '');

        $this->session->unset_userdata($array_items);

      

         $this->load->helper('dompdf');

            $this->load->helper('file');

           $this->load->model('settings/companyinfo_model');

           $this->load->model('reports/sales_model');

          $data['companyinfo'] = $this->companyinfo_model->getcompanyinfo('1');

          
         $data['tariffsales'] = $this->sales_model->gettariffsales($datefrom,$dateto);

          //var_dump($data);
         $html = $this->load->view('reports/sales/tariffsales_print', $data, true);

         echo $html;

         //pdf_create($html, 'TARIFFSALES', false);

 

    }
       
}