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

class Data_surya extends CI_Controller {
	public function __construct() {
        parent::__construct();
    }

	public function get_data_product_type(){
		$limit = 20;
		$q = $this->input->get("term");
		$page = $this->input->get("page");
		$parent = $this->input->get('parent');

		$offset = ($page - 1) * $limit;

		$this->db->where('idoutlet', $parent);
		$this->db->order_by("product_name");
		if (strlen($q) > 0) {
			$this->db->like("product_name", $q);
		}
		$this->db->select("idproduct as id, product_name as text");
		$this->db->where('status', '1');

		$data = $this->db->get("product", $limit, $offset);

		$this->db->where('idoutlet', $parent);
		if (strlen($q) > 0) {
			$this->db->like("product_name", $q);
		}
		$this->db->where('status', '1');
		$cdata = $this->db->get("product");
		$count = $cdata->num_rows();

		$endCount = $offset + $limit;
		$morePages = $endCount < $count;

		$results = array(
		  "results" => $data->result_array(),
		  "pagination" => array(
		  	"more" => $morePages
		  )
		);
		echo json_encode($results);
	}

	public function get_data_hue(){
		$limit = 20;
		$q = $this->input->get("term");
		$page = $this->input->get("page");

		$offset = ($page - 1) * $limit;
		
		$this->db->order_by("hue_name");
		if (strlen($q) > 0) {
			$this->db->like("hue_name", $q);
		}
		$this->db->select("idhue as id, hue_name as text");
		$this->db->where('status', '1');

		$data = $this->db->get("hue", $limit, $offset);

		if (strlen($q) > 0) {
			$this->db->like("hue_name", $q);
		}
		$this->db->where('status', '1');
		$cdata = $this->db->get("hue");
		$count = $cdata->num_rows();

		$endCount = $offset + $limit;
		$morePages = $endCount < $count;

		$results = array(
		  "results" => $data->result_array(),
		  "pagination" => array(
		  	"more" => $morePages
		  )
		);
		echo json_encode($results);
	}

	public function get_data_colour(){
		$limit = 20;
		$q = $this->input->get("term");
		$page = $this->input->get("page");

		$offset = ($page - 1) * $limit;
		
		$this->db->order_by("colour_name");
		if (strlen($q) > 0) {
			$this->db->like("colour_name", $q);
		}
		$this->db->select("idcolour as id, colour_name as text");
		$this->db->where('status', '1');

		$data = $this->db->get("colour", $limit, $offset);

		if (strlen($q) > 0) {
			$this->db->like("colour_name", $q);
		}
		$this->db->where('status', '1');
		$cdata = $this->db->get("colour");
		$count = $cdata->num_rows();

		$endCount = $offset + $limit;
		$morePages = $endCount < $count;

		$results = array(
		  "results" => $data->result_array(),
		  "pagination" => array(
		  	"more" => $morePages
		  )
		);
		echo json_encode($results);
	}

	public function get_data_payment(){
		$limit = 20;
		$q = $this->input->get("term");
		$page = $this->input->get("page");

		$offset = ($page - 1) * $limit;
		
		$this->db->order_by("payment_type_name");
		if (strlen($q) > 0) {
			$this->db->like("payment_type_name", $q);
		}
		$this->db->select("idpayment_type as id, payment_type_name as text");
		$this->db->where('status', '1');

		$data = $this->db->get("payment_type", $limit, $offset);

		if (strlen($q) > 0) {
			$this->db->like("payment_type_name", $q);
		}
		$this->db->where('status', '1');
		$cdata = $this->db->get("payment_type");
		$count = $cdata->num_rows();

		$endCount = $offset + $limit;
		$morePages = $endCount < $count;

		$results = array(
		  "results" => $data->result_array(),
		  "pagination" => array(
		  	"more" => $morePages
		  )
		);
		echo json_encode($results);
	}

	public function get_data_driver(){
		$limit = 20;
		$q = $this->input->get("term");
		$page = $this->input->get("page");

		$offset = ($page - 1) * $limit;
		
		$this->db->order_by("name");
		$this->db->where('idrole', 3);
		if (strlen($q) > 0) {
			$this->db->like("name", $q);
		}
		$this->db->select("iduser as id, name as text");
		$this->db->where('status', '1');

		$data = $this->db->get("user", $limit, $offset);

		if (strlen($q) > 0) {
			$this->db->like("name", $q);
		}
		$this->db->where('status', '1');
		$this->db->where('idrole', 3);
		$cdata = $this->db->get("user");
		$count = $cdata->num_rows();

		$endCount = $offset + $limit;
		$morePages = $endCount < $count;

		$results = array(
		  "results" => $data->result_array(),
		  "pagination" => array(
		  	"more" => $morePages
		  )
		);
		echo json_encode($results);
	}

	public function get_data_production(){
		$limit = 20;
		$q = $this->input->get("term");
		$page = $this->input->get("page");

		$offset = ($page - 1) * $limit;
		
		$this->db->order_by("name");
		$this->db->where('idrole', 4);
		if (strlen($q) > 0) {
			$this->db->like("name", $q);
		}
		$this->db->select("iduser as id, name as text");
		$this->db->where('status', '1');

		$data = $this->db->get("user", $limit, $offset);

		if (strlen($q) > 0) {
			$this->db->like("name", $q);
		}
		$this->db->where('status', '1');
		$this->db->where('idrole', 4);
		$cdata = $this->db->get("user");
		$count = $cdata->num_rows();

		$endCount = $offset + $limit;
		$morePages = $endCount < $count;

		$results = array(
		  "results" => $data->result_array(),
		  "pagination" => array(
		  	"more" => $morePages
		  )
		);
		echo json_encode($results);
	}

	public function get_data_cashier(){
		$limit = 20;
		$q = $this->input->get("term");
		$page = $this->input->get("page");

		$offset = ($page - 1) * $limit;
		
		$this->db->order_by("name");
		$this->db->where('idrole', 2);
		if (strlen($q) > 0) {
			$this->db->like("name", $q);
		}
		$this->db->select("iduser as id, name as text");
		$this->db->where('status', '1');

		$data = $this->db->get("user", $limit, $offset);

		if (strlen($q) > 0) {
			$this->db->like("name", $q);
		}
		$this->db->where('status', '1');
		$this->db->where('idrole', 2);
		$cdata = $this->db->get("user");
		$count = $cdata->num_rows();

		$endCount = $offset + $limit;
		$morePages = $endCount < $count;

		$results = array(
		  "results" => $data->result_array(),
		  "pagination" => array(
		  	"more" => $morePages
		  )
		);
		echo json_encode($results);
	}

		
}