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

class Staff_model extends CI_Model {

  ////////////////////////////
 //ADD CUSTOMER ON ADD PAGE//
////////////////////////////

public function create($options)
    {
        $this->db->insert('kns1_staff', $options);
        return $this->db->insert_id();    
    }

  ///////////////////////////////////
 //GET ALL CUSTOMERS ON INDEX PAGE//
///////////////////////////////////
 
public function get_all($limit = NULL, $offset = NULL)
    {
        $this->db->order_by('id', 'DESC');
        $query = $this->db->get('kns1_staff', $limit, $offset);
        return $query->result();
    }

  ///////////////////////////////////
 //GET CUSTOMER BY ID ON VIEW PAGE//
///////////////////////////////////

public function get_all_by($id)
    {
        $this->db->where('id', $id);
        $query = $this->db->get('kns1_staff');
        return $query->row();
    }

  ///////////////////////////////////////////
 //GET CUSTOMER BY ID ON ADD DELIVERY PAGE//
///////////////////////////////////////////

public function get_by_staff($id)
    {
        $this->db->where('id', $id);
        $query = $this->db->get('kns1_staff');
        return $query->result();
    }

  //////////////////////////////////////////
 //UPDATE CUSTOMER'S DETAILS ON VIEW PAGE//
//////////////////////////////////////////

 public function view($id, $options)
    {
        $this->db->where('id', $id);
        $this->db->update('kns1_staff', $options);
        return $id;
    }

  ////////////////
 //DELETE Staff//
////////////////

public function destroy($id)
    {
        $this->db->where('id', $id);
        $this->db->delete('kns1_staff');
        return $this->db->affected_rows();
    }


  ///////////////////////////////////////////
 //GET CUSTOMER BY TYPE//
///////////////////////////////////////////




    public function getNameBy($id)
    {
        $this->db->select(' staff_name');
        $this->db->where('id', $id);
        $query = $this->db->get('kns1_staff');
        if($query->row()) {
            return $query->row()->  staff_name;
        }
    }





    // public function get_all_array($limit = NULL, $offset = NULL)
    // {
    //     $this->db->select('customer_name, phone, address');
    //     $this->db->order_by('id', 'ASC');
    //     $this->db->where('YEAR(`created_at`)', $_SESSION['qurbani_year']);
    //     $query = $this->db->get('kns1_customers', $limit, $offset)->result_array();
    //     return $query;
    // }




//     public function last_month_bill($id, $options)
//     {
//         $this->db->where('id', $id);
//         $this->db->where('YEAR(`created_at`)', $_SESSION['qurbani_year']);
//         $this->db->update('kns1_customers', $options);
//         return $id;
//     }

//     public function add_invoice($id, $options)
//     {
//         $this->db->where('customer_id', $id);
//         // $this->db->where('YEAR(`created_at`)', $_SESSION['qurbani_year']);
//          $this->db->insert('kns1_invoice', $options);
//         return $this->db->insert_id();
//     }



//     public function my_firs_join()
//     {

//         $this->db->select('*');
//         $this->db->from('kns1_customers');
//         $this->db->join('kns1_delivery','kns1_customers.id = kns1_delivery.customer_id');
//         return $this->db->get();
//     }

//     public function my_scond_join()
//     {

//         $this->db->select('*');
//         $this->db->from('kns1_customers');
//         $this->db->join('kns1_payment','kns1_customers.id = kns1_payment.pay_customer_id');
//         return $this->db->get();
//     }

//      public function client_invoice_join()
//     {

//         $this->db->select('*');
//         $this->db->from('kns1_customers');
//         $this->db->join('kns1_invoice','kns1_customers.id = kns1_invoice.bill_customer_id');
//         return $this->db->get();
//     }

//     public function customer_count()
//     {
//         return  $this->db->count_all('kns1_customers');       
//     }




// public function customer_count_cod()
//     {
// return $this->db
//        ->where('type','G')
//        ->count_all_results('kns1_customers');  
//     }


// public function customer_count_monthly()
//     {
// return $this->db
//        ->where('type','Monthly')
//        ->count_all_results('kns1_customers');  
//     }


}


