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

class Staff extends CI_Controller
{
    // Session Authoriesed
    public function __construct()
    {
        parent::__construct();

        $admin = $this
            ->session
            ->userdata('staff');
        $column['id'] = $admin['id'];
        $table = 'tbl_user';

        // loading common model
        $this
            ->load
            ->model('Common_model');
        $result = $this
            ->Common_model
            ->Result($column, $table);
        if ($result['password'] == $admin['password'])
        {
            $login = true;
        }
        else
        {
            $login = false;
        }

        if (empty($admin) || $login == false)
        {
            $this
                ->session
                ->set_flashdata('msg', 'Your Session Has Been Expired');
            redirect(base_url() . 'staff/login');
        }

        // loading common model
        $this
            ->load
            ->model('Common_model');
        $this
            ->load
            ->helper('common_helper');
           
    }






    public function index()
    {
        // we are setting data for get site data
        $column['id'] = '1';
        $table = 'tbl_settings';

        // we are getting results from common modal
        $result = $this
            ->Common_model
            ->Result($column, $table);

        // we are setting result in data array as $data
        $data['data'] = $result;
        $data['page'] = 'Staff';

        // 		getting product data
       $table6='tbl_user';
        $result6 = $this
            ->Common_model
            ->Resultss($table6);


        $data['user'] = $result6;
      

        // we are loading admin dashboard
        $this
            ->load
            ->view('staff/staff/list', $data);
    }

 
 public function stock($id) {
        	$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Staff Stock';
		
		$table2 = 'tbl_user';
		$column2['id'] = $id;
        // we are getting results from common modal
		$result2 = $this->Common_model->Result($column2,$table2);
		
		
		
		$table21 = 'tbl_product';
	    $result21 = $this->Common_model->Results($table21);
	    
	    
	    $table211 = 'tbl_product_size';
	    $result211 = $this->Common_model->Results($table211);
	    
	    
	    $table212 = ' tbl_size';
	    $result212 = $this->Common_model->Results($table212);
		
	
		
	    $tablecolor = ' tbl_color';
	    $resultablecolor = $this->Common_model->Results($tablecolor);
	
		$data['user'] = $result2;
		$data['product'] = $result21;
		$data['product_size'] = json_encode($result211);
	
		$data['color'] = json_encode($resultablecolor);
		$data['size_name'] = json_encode($result212);
		
        // we are loading admin dashboard
		$this->load->view('staff/staff/stock',$data);
    }
    
    
  





 public function invoice($id) {
        	$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Staff Stock';
		
		$table2 = 'tbl_user';
		$column2['id'] = $id;
        // we are getting results from common modal
		$result2 = $this->Common_model->Result($column2,$table2);
		
		
		
		$table21 = 'tbl_product';
	    $result21 = $this->Common_model->Results($table21);
	    
	    
	    $table211 = 'tbl_product_size';
	    $result211 = $this->Common_model->Results($table211);
	    
	    
	    $table212 = ' tbl_size';
	    $result212 = $this->Common_model->Results($table212);
		
	
		
	    $tablecolor = ' tbl_color';
	    $resultablecolor = $this->Common_model->Results($tablecolor);
	
		$data['user'] = $result2;
		$data['product'] = $result21;
		$data['product_size'] = json_encode($result211);
	
		$data['color'] = json_encode($resultablecolor);
		$data['size_name'] = json_encode($result212);
		
        // we are loading admin dashboard
		$this->load->view('staff/staff/invoice',$data);
    }





public function invoice_list($id)
{
    
        	$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Invoice List';
		
		$table2 = 'tbl_user';
		$column2['id'] = $id;
        // we are getting results from common modal
		$result2 = $this->Common_model->Result($column2,$table2);
		
		
		
		$table21 = 'tbl_product';
	    $result21 = $this->Common_model->Results($table21);
	    
	    
	    $table211 = 'tbl_product_size';
	    $result211 = $this->Common_model->Results($table211);
	    
	    
	    $table212 = ' tbl_size';
	    $result212 = $this->Common_model->Results($table212);
		
	
		
	    $tablecolor = ' tbl_color';
	    $resultablecolor = $this->Common_model->Results($tablecolor);
	
		$data['user'] = $result2;
		$data['product'] = $result21;
		$data['product_size'] = json_encode($result211);
	
		$data['color'] = json_encode($resultablecolor);
		$data['size_name'] = json_encode($result212);
		
        // we are loading admin dashboard
		$this->load->view('staff/staff/invoice_list',$data);
    
  
}



public function payment()
{
    $bill_no=$_POST['bill_no'];
    $user_id=$_POST['user_id'];
    $payid=$_POST['payid'];
    $paid=$_POST['paid'];
    
       date_default_timezone_set('Asia/Kolkata');
        $addon=date('Y-m-d H:i:s');
    
    
     $queryd1 = $this->db->query("SELECT SUM(paid) AS rrt FROM staff_payment where bill_no='$bill_no'");
     $rowd1 = $queryd1->row(); 
     $all_paid=$rowd1->rrt+0;
     
     $queryd11 = $this->db->query("SELECT * FROM staff_bill_list where user_id='$user_id' AND bill_no='$bill_no'");
     $rowd11 = $queryd11->row(); 
     $dues=$rowd11->total;
     
     $due=$dues-$all_paid;
     $ndue=$due-$paid;
  
  if($payid=='')  
  {
            $this->session->set_flashdata('error','Something went Wrong.');
		    
  }
  else
  {
   $data=[
       'user_id'=>$user_id,
       'payid'=>$payid,
       'bill_no'=>$bill_no,
       'pre_amt'=>$due,
       'paid'=>$paid,
       'dues'=>$ndue,
       'addon'=>$addon,
       'status'=>1 
       ];
       
       
        $this->session->set_flashdata('success','SUCCESS!! Payment Successfully Completed.');
		   
    $this->db->insert('staff_payment',$data); 
  }
    
     redirect(base_url('staff/staff/payment_list/'.$user_id.'/'.$bill_no)); 
}




  public function payment_list($id,$bill_no)
  {
      
    
        	$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Payment List';
		
		$table2 = 'tbl_user';
		$column2['id'] = $id;
        // we are getting results from common modal
		$result2 = $this->Common_model->Result($column2,$table2);
		
		
		
	
	
		$data['user'] = $result2;
		$data['bill_no'] = $bill_no;
	
	

		
        // we are loading admin dashboard
		$this->load->view('staff/staff/payment_list',$data);
    
  

  }




  public function print_pay($id,$bill_no)
  {
      
    
        	$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Print Payment';
		
		$table2 = 'tbl_user';
		$column2['id'] = $id;
        // we are getting results from common modal
		$result2 = $this->Common_model->Result($column2,$table2);
		
		
		
	
	
		$data['user'] = $result2;
		$data['payid'] = $bill_no;
	
	

		
        // we are loading admin dashboard
		$this->load->view('staff/staff/print_pay',$data);
    
  

  }

public function order_list($id,$bill_no)
{
  
      
    
        	$column['id'] = '1';
		$table = 'tbl_settings';
		
        // we are getting results from common modal
		$result = $this->Common_model->Result($column,$table);
		
        // we are setting result in data array as $data
		$data['data'] = $result;
		$data['page'] = 'Print Bill';
		
		$table2 = 'tbl_user';
		$column2['id'] = $id;
        // we are getting results from common modal
		$result2 = $this->Common_model->Result($column2,$table2);
		
		
		
	
	
		$data['user'] = $result2;
		$data['payid'] = $bill_no;
	
	

		
        // we are loading admin dashboard
		$this->load->view('staff/staff/order_list',$data);
    
  

    
}


}