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

class Pos_response extends CI_Controller {

 public function __construct() {
        parent::__construct();
        date_default_timezone_set("Asia/Kolkata");
        $this->load->model('Pos_response_model');
         $this->load->helper('generals_helper');
        if(!$this->session->userdata('logged_in')) {
            redirect(base_url());
        }

         
    }



	public function responce($request_id){
		$template['page'] = 'Pos_response/list';
	    $template['menu'] = 'Pos Response Management';
	    $template['smenu'] = 'View Pos Responses';
	    $template['pTitle'] = "View Pos Responses";
	    $template['pDescription'] = "View and Manage Pos Responses";
	    $template['page_head'] = "Pos Response Management";
	    $template['datatable'] = 1;
	    $template['request_id'] = $request_id;
	    $template['requestData'] = $this->Pos_response_model->getPos_responseData(decode_param($request_id));
	    $template['pos_list'] = $this->Pos_response_model->get_all_Pos_response($template['requestData']['id'],'');
		$this->load->view('template',$template);
	}

	public function editMargins(){
		$respArr =array('status'=>'error');
		$data = $_POST;
		if(!isset($_POST['requestId']) || empty($_POST['requestId']) || !isset($_POST['respCode']) || empty($_POST['respCode'])){
			echo json_encode(array('status'=>'error'));exit;
		}
		$requestData = $this->Pos_response_model->getPos_responseData(decode_param($_POST['requestId']));
	    $pos_list = $this->Pos_response_model->get_all_Pos_response('',$_POST['respCode']);
	    echo json_encode(array('status'=>'success','reqDetails'=>$requestData,'posDetails'=>$pos_list));exit;
	}

	public function insertCustomMargin(){
		$respArr =array('status'=>'error');
		$data = $_POST;
		if(!isset($_POST['margin']) || empty($_POST['margin']) || !isset($_POST['respId']) || empty($_POST['respId']) || !isset($_POST['total']) || empty($_POST['total'])){
			echo json_encode($respArr);exit;
		}
		$requestData = $this->Pos_response_model->updatePosMargin($_POST);
		if(!$requestData){
			echo json_encode($respArr);	exit;
		}
	    echo json_encode(array('status'=>'success'));exit;
	}

	public function approve_quote(){
		$respArr =array('status'=>'error');
		$data = $_POST;
		if(!isset($_POST['selectedIds']) || empty($_POST['selectedIds']) || !isset($_POST['req_id']) || empty($_POST['req_id'])){
			echo json_encode($respArr);exit;
		}
		$requestData = $this->Pos_response_model->approve_quote($_POST);
		if(!$requestData){
			echo json_encode($respArr);	exit;
		}
	    echo json_encode(array('status'=>'success'));exit;
	}


	
}
?>