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

class Feao_ctrl extends user_icd_index {
 
	
	public function __construct(){
		parent::__construct(); 
		$data = array();
		$this->load->model('admin_model');
		$this->load->model('icd_model');		
	}
	 
	/*----------------- load finance_addition_list page -----------------*/
	public function finance_addition_list(){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/feao/finance_addition_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','1','','0');
		// echo $this->db->last_query();return;
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- load finance_addition_form page -----------------*/
	public function finance_addition_form($idl_id){		
		$data['sdata'] 			= array();
		$data['subview'] 		= 'icd/feao/finance_addition_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']['isl_list'] 		= $this->admin_model->get_result_array('icd_service_list');	
		$data['sdata']['idl_data'] 		= $this->icd_model->get_icd_details_list($idl_id,'1','1','1','','0');
		// echo $this->db->last_query();return;
		
		$data['sdata']['icdl_list'] 		= $this->icd_model->get_icdl_details_list($idl_id);
		$this->load->view('icd/common/icd_sidepanel',$data); 
	}

	/*----------------- update update_icdl_addition_details -----------------*/
	public function update_icdl_addition_details($idl_id){	
		// var_dump($_POST);return;	
		$data['idl_details']['idl_invoice_seq'] 		= $this->input->post('idl_invoice_seq');
		$data['idl_details']['idl_invoice_no'] 			= $this->input->post('idl_invoice_no');

		// if(isset($_POST['update'])){
			$data['idl_details']['idl_feao_id'] 			= $this->user['i_user_id'];
			$data['idl_details']['idl_feao_status'] 		= '1';
			$data['idl_details']['idl_feao_date'] 			= date("Y-m-d");		
		// }
		if(isset($_POST['final_update'])){
			$data['idl_details']['idl_fnl_update_feao_id'] 			= $this->user['i_user_id'];
			$data['idl_details']['idl_fnl_update_feao_status'] 		= '1';
			$data['idl_details']['idl_fnl_update_feao_date'] 		= date("Y-m-d");	
		}
		
		$edit_idl 			= $this->admin_model->update_data('icd_details_list','idl_id',$idl_id,$data['idl_details']);

		$icdl_id 			= $this->input->post('icdl_id');
		$icdl_levy 			= $this->input->post('icdl_levy');
		$icdl_addition 		= $this->input->post('icdl_addition');
		$icdl_sub_total 	= $this->input->post('icdl_sub_total');
		$icdl_vat 			= $this->input->post('icdl_vat');
		$icdl_total 		= $this->input->post('icdl_total'); 
		$icdl_debit_to 		= $this->input->post('icdl_debit_to');   
		

		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_addition'] 		=  $icdl_addition[$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];	
			$data['icdl_details']['icdl_debit_to'] 		=  $icdl_debit_to[$icdl_key];	
			$edit_icdl 									= $this->admin_model->update_data('icd_container_details_list','icdl_id',$icdl_row,$data['icdl_details']);	
		}
				
		if($edit_idl!='0'){
			$this->session->set_flashdata('tos_success', 'Details updated');
			redirect('icd/feao_ctrl/finance_addition_list');
		}else {
			$this->session->set_flashdata('tos_warning', 'There is no changes!...');
			redirect('icd/feao_ctrl/finance_addition_list');
		}			
				
	}
	
	
	
	
}
