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

class Ppo_ctrl extends user_icd_index {
 
	
	public function __construct(){
		parent::__construct(); 
		$data = array();
		$this->load->model('admin_model');
		$this->load->model('icd_model');		
	}
	
	/*----------------- load finance_entry_approve_list page -----------------*/
	public function finance_entry_approve_list(){	 	
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/ppo/finance_entry_approve_list';		
		$data['active_cls'] 	= 'dash';	
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');			
		$data['sdata']['idl_list'] 		= $this->icd_model->get_icd_details_list('','1','1','0');
		
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- load port_entry_update page -----------------*/
	public function finance_entry_approve_form($idl_id){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/ppo/finance_entry_approve_form';		
		$data['active_cls'] 	= 'dash';			
		$data['url_list'] 		= $this->admin_model->get_result_array_with_one_where('user_role_list','url_status','1');				
		$data['sdata']['idl_data'] 		= $this->icd_model->get_icd_details_list($idl_id,'1','1','0');
		$data['sdata']['icdl_list'] 		= $this->icd_model->get_icdl_details_list($idl_id);
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- update icd details -----------------*/
	public function approve_icd_details($idl_id){	
		// var_dump($_POST);return;	
		$icdl_id 				= $this->input->post('icdl_id');
		$icdl_levy 				= $this->input->post('icdl_levy');
		$icdl_sub_total 		= $this->input->post('icdl_sub_total');
		$icdl_vat 				= $this->input->post('icdl_vat');
		$icdl_total 			= $this->input->post('icdl_total');

		foreach($icdl_id as $icdl_key=>$icdl_row){				
			$data['icdl_details']['icdl_id'] 					=  $icdl_row;
			$data['icdl_details']['icdl_levy'] 					=  $icdl_levy[$icdl_key];
			$data['icdl_details']['icdl_sub_total'] 			=  $icdl_sub_total[$icdl_key];
			$data['icdl_details']['icdl_vat'] 					=  $icdl_vat[$icdl_key];
			$data['icdl_details']['icdl_total'] 				=  $icdl_total[$icdl_key];
			$edit_icdl 											= $this->admin_model->update_data('icd_container_details_list','icdl_id',$icdl_row,$data['icdl_details']);	
		}

		$data['idl_details']['idl_ppo_id'] 			= $this->user['i_user_id'];
		$data['idl_details']['idl_ppo_status'] 		= '1';
		$data['idl_details']['idl_ppo_date'] 		= date("Y-m-d"); 
		
		$edit_idl 			= $this->admin_model->update_data('icd_details_list','idl_id',$idl_id,$data['idl_details']);

		
				
		if($edit_idl!='0'){
			$this->session->set_flashdata('tos_success', 'Details appoved');
			redirect('icd/icd_print_out_ctrl/finance_entry_approve_print_out/'.$idl_id);	
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/ppo_ctrl/finance_entry_approve_list');
		}			
				
	}
	
	
	
	
}
