<?php
defined('BASEPATH') OR exit('No direct script access allowed');
Class Quotation Extends MY_Controller{
	function __construct()
	{
		parent::__construct();	
		$this->load->model('admin_api/Quotation_model');
		$this->config->load('my_constants');
	}

	public function add_quotation()
	{
		$data['active_quotation'] = 'open';
		$data['title'] = 'quotation List';
		$data['header_title'] = 'quotation';
		$data['quotation_info'] = $this->Quotation_model->get_quotation_list();
		$data['product_info'] = $this->Quotation_model->get_product_list();
		//print_r($data['package_info']);exit();
		$data['main_content'] = 'admin/Quotation/add_quotation';
        $this->load->view('admin/includes/template', $data);
	}	

	public function view_tender($tender_id)
	{
		//echo $tender_id;
		$data['active_quotation'] = 'open';
		$data['title'] = 'quotation List';
		$data['header_title'] = 'quotation';
		$data['quotation_info'] = $this->Quotation_model->get_tender_details($tender_id);
	//	print_r($data['quotation_info']);
		//print_r($data['package_info']);exit();
		//$data['main_content'] = 'admin/Quotation/add_quotation';
      //  $this->load->view('admin/includes/template', $data);
	  			$this->load->view('admin/Quotation/view_tender', $data);

	}	
	
	public function tender_list()
	{
		$data['active_tender'] = 'open';
		$data['title'] = 'Tender List';
		$data['header_title'] = 'Tender';
		$data['tender_info'] = $this->Quotation_model->get_tender_list();
		//print_r($data['package_info']);exit();
		$data['main_content'] = 'admin/Quotation/tender_list';
        $this->load->view('admin/includes/template', $data);
	}

	
	
	public function save_quotation()
	{
		$post_data = $this->input->post();
			$query=$this->Quotation_model->save_quotation($post_data);
			if($query){
				$this->session->set_flashdata('success_message', 'quotation Added successfully!');

				redirect('admin/Quotation/add_quotation','refresh');
			}else{
				$this->session->set_flashdata('failure_message', 'You are fail to Add quotation!');
				redirect('admin/Quotation/add_quotation','refresh');
			}
	}
	
	
	

	public function delete_quotation($id=NULL)
	{
	
	//	$post_data = $this->input->post();
			$query=$this->Quotation_model->delete_quotation($id);
			if($query){
				$this->session->set_flashdata('success_message', 'Master Product Deleted successfully!');

				redirect('admin/Quotation/add_quotation','refresh');
			}else{
				$this->session->set_flashdata('failure_message', 'You are fail to Deleted Master Product!');
				redirect('admin/Quotation/add_quotation','refresh');
			}
	}
	

	
	
	public function auo_product3()
		{
			$db = get_instance()->db->conn_id;
			$type = $_POST['type'];
			$name = $_POST['name_startsWith'];
			$category = $_POST["category"];
			//echo $category
		//	echo $_POST["id"];
	$query = "SELECT component,price from component  where IsActive=0 and category='$category' and UPPER($type) LIKE '".strtoupper($name)."%'";
	
	$result = mysqli_query($db, $query);
	$data = array();
	while ($row = mysqli_fetch_assoc($result)) {
		$component=$row['component'];
		$price=$row['price'];
		
	$name = $component.'|'.$price;
		
		array_push($data, $name);
	}	
	echo json_encode($data);
		}

	
	
	
	public function edit_tender($tender_id)
	{
	    
		$data['active_quotation'] = 'open';
		$data['title'] = 'quotation edit';
		$data['header_title'] = 'quotation';
		$data['quotation_info'] = $this->Quotation_model->get_quotation_list();
		$data['product_info'] = $this->Quotation_model->get_product_list();
		$data['tender_info'] = $this->Quotation_model->get_tender_info($tender_id);
		//print_r($data['package_info']);exit();
		$data['main_content'] = 'admin/Quotation/edit_quotation';
        $this->load->view('admin/includes/template', $data);
	}	
	
	public function update_quotation()
	{
		$post_data = $this->input->post();
			$query=$this->Quotation_model->update_quotation($post_data);
			if($query){
				$this->session->set_flashdata('success_message', 'Quotation Updated successfully!');

				redirect('admin/Quotation/tender_list','refresh');
			}else{
				$this->session->set_flashdata('failure_message', 'You are fail to Updated Quotation!');
				redirect('admin/Quotation/edit_tender','refresh');
			}
	}
	
}?>