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

class Product_Discount extends CI_Controller {

    var $main_menu_name = "";
	var $sub_menu_name = "";

    public function __construct()
     {
            parent::__construct();
            $this->load->model('category_models');
			$this->load->model('Common_Model');
			$this->load->model('Sequerty_Model');
		 	$this->load->model('Product_Discount_Model');
     }


	public function index()
	{
		$data['main_menu_name'] = $this->main_menu_name;
		$data['sub_menu_name'] = $this->sub_menu_name;
        $this->load->view('product_category',$data);
	}

    public function add_category()
    {
        $data['id'] = 1;
        $this->load->view('models/create_category',$data);
    }
    public function edit_discount($discount_id)
    {
        $data['discount_details'] = $this->Product_Discount_Model->get_discount_detals_by_product_dis_id($discount_id);
        $this->load->view('product_discount/create_discount',$data);
    }

    public function update_discount()
    {		
		$dicount_tble_id=$this->input->post('dicount_tble_id');
		$start_ds=$this->input->post('start_ds');
		$end_ds=$this->input->post('end_ds');
		$discount=$this->input->post('discount');
		$is_precentage=$this->input->post('is_precentage');
		
		$data=array(
		'start_range_value'=>$start_ds,
		'end_range_value'=>$end_ds,
		'discount_value'=>$discount,
		'is_precentage'=>$is_precentage,	
		);
               if ($this->Product_Discount_Model->insert_update_master_table($data,$dicount_tble_id)) {

                       $st = array('status' =>1,'validation' =>'Done!');
                       echo json_encode($st);
               } else {

                       $st = array('status' =>0,'validation' =>'error occurred please contact your system administrator');
                       echo json_encode($st);
			   }    
    }

  
  public function enable_discount()
	{		
		$product_id=$this->input->get('id');
		
		$data=array(
		'product_id'=>$product_id,
		'invoice_type_id'=>1,
		'start_range_value'=>0,
		'end_range_value'=>0,
		'discount_value'=>0,
		'is_precentage'=>0,	
		);		
		$result=$this->Product_Discount_Model->insert_update_master_table($data,'');
		$data=array(
		'product_id'=>$product_id,
		'invoice_type_id'=>2,
		'start_range_value'=>0,
		'end_range_value'=>0,
		'discount_value'=>0,
		'is_precentage'=>0,	
		);		
		$result=$this->Product_Discount_Model->insert_update_master_table($data,'');	

		$data=array(
		'product_id'=>$product_id,
		'invoice_type_id'=>3,
		'start_range_value'=>0,
		'end_range_value'=>0,
		'discount_value'=>0,
		'is_precentage'=>0,	
		);		
		$result=$this->Product_Discount_Model->insert_update_master_table($data,'');	


		if($result==true)
		{
		$st = array('error'=>0,'status' =>1,'message'=>"Done");	
		}
		else
		{
		$st = array('error'=>1,'status' =>0,'message'=>"Error ! Data not saved");		
		}
           echo json_encode($st);
	}
    //sub category module function end

}