<?php
class Invoice_model extends Crud_model
{

public function get_bill($entered_str)
	{
		$json_data 		=	array(0=>array('id'=>'','text'=>"Select Branch Name"));
		$condition		=	array();
		if($entered_str) 
			$condition["branch_name LIKE "] = "%$entered_str%";
		$drpdwn_data	=	$this->select_data(PORT_TBL,$select='branch_id,branch_name',$condition, 0, array(),'branch_name',"ASC",'', 0, null);
		$i=1;
		foreach($drpdwn_data as $row)
		{
			$json_data[$i]['id']	=	$row['branch_id'];
			$json_data[$i]['text']  = 	$row['branch_name'];
			$i++;
		}	
		$data['results'] = $json_data;
		return json_encode($data);
	}

	public function get_branch($entered_str)
	{
		$json_data 		=	array(0=>array('id'=>'','text'=>"Select Branch"));
		$condition		=	array();
		
		if($entered_str) 
			$condition["branch_name LIKE "] = "%$entered_str%";
		$drpdwn_data   	=	$this->select_data(BRANCH_TBL,$select='branch_id,branch_name',$condition,0, array(),'branch_name',"ASC",'', 0, null);
		$i=1;
		foreach($drpdwn_data as $row)
		{
			$json_data[$i]['id']	=	$row['branch_id'];
			$json_data[$i]['text']  = 	$row['branch_name'];
			$i++;
		}	
		$data['results'] = $json_data;
		return json_encode($data);
	}


	public function get_company($entered_str)
	{
		$json_data 		=	array(0=>array('id'=>'','text'=>"Select Company"));
		$condition		=	array();
		
		if($entered_str) 
			$condition["cmp_name LIKE "] = "%$entered_str%";
		$drpdwn_data   	=	$this->select_data(COMPANY_TBL,$select='cmp_id,cmp_name',$condition,0, array(),'cmp_name',"ASC",'', 0, null);
		$i=1;
		foreach($drpdwn_data as $row)
		{
			$json_data[$i]['id']	=	$row['cmp_id'];
			$json_data[$i]['text']  = 	$row['cmp_name'];
			$i++;
		}	
		$data['results'] = $json_data;
		return json_encode($data);
	}

	public function get_consignor($entered_str){
		$json_data 		=	array(0=>array('id'=>'','text'=>"Select Consignor"));
		$condition		=	array();
		
		if($entered_str) 
			$condition["consignor_name LIKE "] = "%$entered_str%";
		$drpdwn_data   	=	$this->select_data(CONSIGNOR_TBL,$select='consignor_id,consignor_name',$condition,0, array(),'consignor_name',"ASC",'', 0, null);
		$i=1;
		foreach($drpdwn_data as $row)
		{
			$json_data[$i]['id']	=	$row['consignor_id'];
			$json_data[$i]['text']  = 	$row['consignor_name'];
			$i++;
		}	
		$data['results'] = $json_data;
		return json_encode($data);
	}
	public function get_consignee($entered_str){
			$json_data 		=	array(0=>array('id'=>'','text'=>"Select Consignee"));
			$condition		=	array();
			
			if($entered_str) 
				$condition["consignee_name LIKE "] = "%$entered_str%";
			$drpdwn_data   	=	$this->select_data(CONSIGNEE_TBL,$select='consignee_id,consignee_name',$condition,0, array(),'consignee_name',"ASC",'', 0, null);
			$i=1;
			foreach($drpdwn_data as $row)
			{
				$json_data[$i]['id']	=	$row['consignee_id'];
				$json_data[$i]['text']  = 	$row['consignee_name'];
				$i++;
			}	
			$data['results'] = $json_data;
			return json_encode($data);
		}

	public function get_customer($entered_str){
			$json_data 		=	array(0=>array('id'=>'','text'=>"Select Customer"));
			$condition		=	array();
			
			if($entered_str) 
				$condition["customer_name LIKE "] = "%$entered_str%";
			$drpdwn_data   	=	$this->select_data(CUSTOMER_TBL,$select='customer_id,customer_name',$condition,0, array(),'customer_name',"ASC",'', 0, null);
			$i=1;
			foreach($drpdwn_data as $row)
			{
				$json_data[$i]['id']	=	$row['customer_id'];
				$json_data[$i]['text']  = 	$row['customer_name'];
				$i++;
			}	
			$data['results'] = $json_data;
			return json_encode($data);
		}

	public function get_notify($entered_str){
				$json_data 		=	array(0=>array('id'=>'','text'=>"Select Notify Name"));
				$condition		=	array();
				
				if($entered_str) 
					$condition["notify_name LIKE "] = "%$entered_str%";
				$drpdwn_data   	=	$this->select_data(NOTIFY_TBL,$select='notify_id,notify_name',$condition,0, array(),'notify_name',"ASC",'', 0, null);
				$i = 1;
				foreach($drpdwn_data as $row)
				{
					$json_data[$i]['id']	=	$row['notify_id'];
					$json_data[$i]['text']  = 	$row['notify_name'];
					$i++;
				}	
				$data['results'] = $json_data;
				return json_encode($data);
			}
	public function get_portname($entered_str){
					$json_data 		=	array(0=>array('id'=>'','text'=>"Select Port Name"));
					$condition		=	array();
					
					if($entered_str) 
						$condition["port_of_dis_name LIKE "] = "%$entered_str%";
					$drpdwn_data   	=	$this->select_data(PORT_TBL,$select='port_of_dis_id,port_of_dis_name',$condition,0, array(),'port_of_dis_name',"ASC",'', 0, null);
					$i=1;
					foreach($drpdwn_data as $row)
					{
						$json_data[$i]['id']	=	$row['port_of_dis_id'];
						$json_data[$i]['text']  = 	$row['port_of_dis_name'];
						$i++;
					}	
					$data['results'] = $json_data;
					return json_encode($data);
				}
				
				public function select_invoice_new_details($limit, $start, $search_data=array()){



		//$bill_id              = $search_data['bill_id'];
		$bill_from_date    = $search_data['bill_from_date'];
		$bill_to_date          = $search_data['bill_to_date'];


		$this->db->select('i.id,i.invoice_no,c.consignor_name,cu.customer_name,i.type');
		$this->db->from('invoice i');
	    $this->db->join('invoice_details d', 'd.invoice_id = i.id', 'left');
	    $this->db->join('consignor c', 'c.consignor_id = i.shipper', 'left');
	    $this->db->join('customer cu', 'cu.customer_id = i.customer', 'left');
        $this->db->group_by('i.id');
	    $this->db->order_by('i.id','desc');
		if($this->input->post('r')==0)
		{
			$this->db->where('i.status',1);
		}
		else
		{
			$this->db->where('i.status',0);
		}

	    if($bill_id!=''){
			$this->db->where('i.id',$bill_id);
			
		}
		
		if($bill_from_date != '' && $bill_to_date != '') 
				{
					
					$this->db->where('i.invoice_date >=',$bill_from_date);
					  $this->db->where('i.invoice_date <=',$bill_to_date);
			//$this->db->where('i.invoice_date',$bill_created_date);
			
		}

        $this->db->limit($limit, $start);

	    $result = $this->db->get()->result_array();
	    return $result;
	}
	public function get_driver($entered_str)
	{
		//$emp_id 		= 	$this->session->userdata('user_id');
		//$companies      =   get_Havepermission_company($emp_id)['cmp_id'];

		$json_data 		=	array(0=>array('id'=>'','text'=>"Select Invoice"));
		
		$select 		= 'id,old_invoice_no';
		if($entered_str)
			$conditions[]   = "old_invoice_no LIKE '%$entered_str%'";
		//if($this->session->userdata('usr_type')!=0)
		//{
			//$company_id 	= $this->session->userdata('company_id');
			//$conditions[]   = "cmp_id = '$company_id'";
		//}

		//$conditions[]   =  "cmp_id IN ($companies)";
		$orderfield 	= 'old_invoice_no';
		$order 			= 'ASC' ;
		$groupfield 	= '';
		$limit 			= '';
		$limit_offset 	= '';		
		$drpdwn_data 	= $this->Invoice_model->get_Alldriver($select,$conditions,$orderfield,$order,$groupfield,$limit,$limit_offset);


		$i=1;
		foreach($drpdwn_data as $row)
		{
			$json_data[$i]['id']	=	$row['id'];
			$json_data[$i]['text']  = 	$row['old_invoice_no'];
			$i++;
		}	
		$data['results'] = $json_data;
		return json_encode($data);
	}			
	public function get_Alldriver($select='*',$conditions,$orderfield='id',$order='DESC',$groupfield,$limit=null,$limit_offset=null)
{
    //get main CodeIgniter object
    $CI =& get_instance();       
    //load databse library
    $CI->load->database();

    //select data
    $CI->db->select($select);
    //where condition
    if(count($conditions)>0 && $conditions!='')
    {
        foreach($conditions as $condition)
            $CI->db->where($condition);
    }
    $CI->db->where('status',0);
	// $CI->db->where('emp_designation_id',2);
    //order by
    if($orderfield!='')
        $CI->db->order_by($orderfield,$order);
    //group by
    if($groupfield!='')
        $CI->db->group_by($groupfield);
    //limit
    if($limit!=''&&$limit_offset!='')
        $CI->db->limit($limit,$limit_offset);
    //execute
    $query = $CI->db->get('invoice');
    //check data
    if($query->num_rows() > 0)
    {
        //return result data
        $result = $query->result_array();
        return $result;
    }
    else
    {
        //no data
        return array();
    }
}		

	public function select_max_bill_no($branch_id){

		$this->db->select_max('bill_no');
		$this->db->from('bill_details');		
		$this->db->where('bill_brnch_id',$branch_id);
		$result = $this->db->get()->result_array();
		return $result;
	}

	public function select_invoice_details($limit, $start, $search_data=array()){



		$bill_id              = $search_data['bill_id'];
		$bill_created_date    = $search_data['bill_created_date'];
		$bill_status          = $search_data['bill_status'];


		$this->db->select('i.id,i.invoice_no,c.consignor_name,cu.customer_name,i.type');
		$this->db->from('invoice i');
	    $this->db->join('invoice_details d', 'd.invoice_id = i.id', 'left');
	    $this->db->join('consignor c', 'c.consignor_id = i.shipper', 'left');
	    $this->db->join('customer cu', 'cu.customer_id = i.customer', 'left');
        $this->db->group_by('i.id');
	    $this->db->order_by('i.id','desc');


	    if($bill_id!=''){
			$this->db->where('i.id',$bill_id);
			
		}
		
		if($bill_created_date!=''){
			$this->db->where('i.invoice_date',$bill_created_date);
			
		}

        $this->db->limit($limit, $start);

	    $result = $this->db->get()->result_array();
	    return $result;
	}


	public function search_record_count($search_data=array()){

		$bill_id              = $search_data['bill_id'];
		$bill_created_date    = $search_data['bill_created_date'];
		$bill_status          = $search_data['bill_status'];


		$this->db->select('i.invoice_no,c.consignor_name,cu.customer_name');
		$this->db->from('invoice i');
	    $this->db->join('invoice_details d', 'd.invoice_id = i.id', 'left');
	    $this->db->join('consignor c', 'c.consignor_id = i.shipper', 'left');
	    $this->db->join('customer cu', 'cu.customer_id = i.customer', 'left');
        $this->db->group_by('i.id');
	    $this->db->order_by('i.id','desc');


	    if($bill_id!=''){
			$this->db->where('i.id',$bill_id);
			
		}
		
		if($bill_created_date!=''){
			$this->db->where('i.invoice_date',$bill_created_date);
			
		}

   		$query = $this->db->get();
        return $query->num_rows();
	}
	
	public function search_record_count_new($search_data=array()){

		
		$bill_from_date    = $search_data['bill_from_date'];
		$bill_to_date          = $search_data['bill_to_date'];


		$this->db->select('i.invoice_no,c.consignor_name,cu.customer_name');
		$this->db->from('invoice i');
	    $this->db->join('invoice_details d', 'd.invoice_id = i.id', 'left');
	    $this->db->join('consignor c', 'c.consignor_id = i.shipper', 'left');
	    $this->db->join('customer cu', 'cu.customer_id = i.customer', 'left');
        $this->db->group_by('i.id');
	    $this->db->order_by('i.id','desc');
		
		if($this->input->post('r')==0)
		{
			$this->db->where('i.status',1);
		}
		else
		{
			$this->db->where('i.status',0);
		}

	    if($bill_id!=''){
			$this->db->where('i.id',$bill_id);
			
		}
		
		if($bill_from_date != '' && $bill_to_date != '') 
				{
					
					$this->db->where('i.invoice_date >=',$bill_from_date);
					  $this->db->where('i.invoice_date <=',$bill_to_date);
			//$this->db->where('i.invoice_date',$bill_created_date);
			
		}

   		$query = $this->db->get();
        return $query->num_rows();
	}
	
	
	
	


	 public function record_count() 
    {
        return $this->db->count_all('bill_details');
    }

	public function changestatus($id){

		$this->db->set('bill_status', '1');
		$this->db->where('bill_id', $id);
		$this->db->update('bill_details');
	}



	public function rejectstatus($id){

			$this->db->set('bill_status', '2');
			$this->db->where('bill_id', $id);
			$this->db->update('bill_details');
		}


	public function	get_branch_bill_no($id){
		$this->db->select('branch_bill_no');
		$this->db->from('branch');
		$this->db->where('branch_id',$id);
		 $result = $this->db->get()->row();
		    return json_encode($result);


	}
 
		public function get_bill_details($bill_id) // exp_por
		{

			$this->db->select('invoice_no,bill_no,shipping_bill_no,seal_no,job_no,point_of_discharge,place_of_receipt,ocean_vessel,ihc_usd,voyage,port_of_loading,place_of_delivery,invoice_date,exp_por,exp_pol,exp_pod,exp_volume,exp_fpd,exp_vessel,exp_voy,exp_sailing_date,exp_exchange_rate ,place_of_issue,date_of_issue,exp_container_no,exp_container_type,total_amount,sgst_amt,cgst_amt,igst_amt,tax_amount,grand_total,created_date,freight_payment,freight_charges,delivery_of_goods,gross_weight,c.cmp_name,b.branch_name,p.port_of_dis_name,cr.customer_name,cn.consignor_name,cn.consignor_addr1,cn.consignor_addr2,cn.consignor_addr3,cn.consignor_addr4,cn.consignor_con_no,cn.consignor_fax,cr.customer_addr1,cr.customer_addr2,cr.customer_addr3,cr.customer_addr4,cr.customer_con_no,cr.customer_fax,vessel_berth,tot_vol,import_total,ihc_applicable,ihc_sgst_amount,ihc_sgst_per,ihc_cgst_per,ihc_cgst_amount,ihc_sac,ihc_igst_per,ihc_igst_amount,ihc_tax_amnt,ihc_amount');

		    $this->db->from('invoice AS i');
		    // $this->db->join('invoice_details as d', 'd.invoice_id = i.id', 'left');		    
		    $this->db->join('branch AS b', 'b.branch_id = i.branch', 'left');
		    $this->db->join('company AS c', 'c.cmp_id = i.company', 'left');
		    $this->db->join('customer AS cr', 'cr.customer_id = i.customer', 'left');
            $this->db->join('consignor AS cn', 'cn.consignor_id = i.shipper', 'left');
		    $this->db->join('port_of_dis AS p', 'p.port_of_dis_id = i.point_of_discharge', 'left');
			$this->db->where('i.status',1);
			//$this->db->where('d.status',1);
		    $this->db->where('i.id',$bill_id);
		    $this->db->order_by('i.id','asc');
		    $result = $this->db->get()->row();
		    // echo $this->db->last_query();exit;
		    return $result;
		}
		
		
		public function getV2bill_details($bill_id)  
		{

			$this->db->select('invoice_no,bill_no,shipping_bill_no,seal_no,job_no,point_of_discharge,place_of_receipt,ocean_vessel,ihc_usd,voyage,port_of_loading,place_of_delivery,invoice_date,free_days,fpod ,place_of_issue,date_of_issue,container_no,arrival_date,total_amount,sgst_amt,cgst_amt,job_ref,   igst_amt,tax_amount,grand_total,created_date,freight_payment,freight_charges,delivery_of_goods,gross_weight,c.cmp_name,b.branch_name,p.port_of_dis_name,cr.customer_name,cn.consignor_name,cn.consignor_addr1,cn.consignor_addr2,cn.consignor_addr3,cn.consignor_addr4,cn.consignor_con_no,cn.consignor_fax,cr.customer_addr1,cr.customer_addr2,cr.customer_addr3,cr.customer_addr4,cr.customer_con_no,cr.customer_fax,vessel_berth,tot_vol,import_total,ihc_applicable,ihc_sgst_amount,ihc_sgst_per,ihc_cgst_per,ihc_cgst_amount,ihc_igst_per,ihc_igst_amount,ihc_tax_amnt,ihc_amount,ihc_sac,cr.pan_no,cr.gst,cr.iec,cr.state');

		    $this->db->from('invoice AS i');
		    // $this->db->join('invoice_details as d', 'd.invoice_id = i.id', 'left');		    
		    $this->db->join('branch AS b', 'b.branch_id = i.branch', 'left');
		    $this->db->join('company AS c', 'c.cmp_id = i.company', 'left');
		    $this->db->join('customer AS cr', 'cr.customer_id = i.customer', 'left');
            $this->db->join('consignor AS cn', 'cn.consignor_id = i.shipper', 'left');
		    $this->db->join('port_of_dis AS p', 'p.port_of_dis_id = i.point_of_discharge', 'left');
			$this->db->where('i.status',1);
			//$this->db->where('d.status',1);
		    $this->db->where('i.id',$bill_id);
		    $this->db->order_by('i.id','asc');
		    $result = $this->db->get()->row();
		    // echo $this->db->last_query();exit;
		    return $result;
		}
		public function get_invo_details($bill_id){
           //echo "here"; exit();
			$this->db->select('d.goods,d.sac,d.amount,d.status');
			$this->db->from('invoice_details as d');	
			$this->db->join('invoice AS i','d.invoice_id = i.id', 'left');	    
			$this->db->where('d.status',1);		
		    $this->db->where('d.invoice_id',$bill_id);
		 
		    $result = $this->db->get()->result_array();
		  //  echo $this->db->last_query(); //die();
		    //exit();
			return $result;
		
		}

		public function get_goods_details($bill_id){

			$this->db->select('total_amount,sgst_per,cgst_per,igst_per,sgst_amt,cgst_amt,igst_amt,tax_amount,grand_total,i.remarks');
		    $this->db->from('invoice AS i');
		    $this->db->join('invoice_details as d', 'd.invoice_id = i.id', 'left');		    
			$this->db->where('i.status',1);
			$this->db->where('d.status',1);
		    $this->db->where('i.id',$bill_id);
		    $this->db->order_by('i.id','asc');
		    $result = $this->db->get()->result_array();
		    //echo $this->db->last_query();exit;
		    return $result;
		}
		
		
		
		public function get_imp_details($bill_id)
		{

			$this->db->select('id,from_date,to_date,days,volume,usd_day,usd_total,ex_rate,total_rupees,invoice_id');
		    $this->db->from('invoice_import_details AS i');
			$this->db->where('i.status',1);
			//$this->db->where('d.status',1);
		    $this->db->where('i.invoice_id',$bill_id);
		    $this->db->order_by('i.id','asc');
		    $result = $this->db->get()->result_array();
		    // echo $this->db->last_query();exit;
		    return $result;
		}
		

		public function select_bill_no(){
			$this->db->select('invoice_no');
			$this->db->from('invoice AS inv');
			$this->db->join('branch AS br', 'br.branch_id = inv.branch', 'left');
		    $this->db->join('company AS c', 'c.cmp_id = inv.company', 'left');
	
			$result = $this->db->get()->result_array();
			// echo $this->db->last_query();exit;
	    	return $result;
		}
		public function select_act_bill_no(){
			$this->db->select('old_invoice_no,id');
			$this->db->from('invoice AS inv');
			$this->db->where('status',0);
			$this->db->join('branch AS br', 'br.branch_id = inv.branch', 'left');
		    $this->db->join('company AS c', 'c.cmp_id = inv.company', 'left');
	
			$result = $this->db->get()->result_array();
			// echo $this->db->last_query();exit;
	    	return $result;
		}

		public function select_brnach_name($bill_id){
			$this->db->select('b.branch_name');
			$this->db->from('bill_details as bill');
			$this->db->join('branch as b','b.branch_id = bill.bill_brnch_id','left');
			 $result = $this->db->get()->row();
		    return $result;
		}

		public function get_invoice_no($company_id,$branch_id,$type)
	{
		//Transaction No. generation		

		$prefix_result  =	$this->select_data(PREFIX_TBL,'prefix_id,prefix_name,current_no',array('prefix_company_id'=>$company_id,'prefix_branch_id'=>$branch_id,'type'=>$type,'delete_status'=>0), 1, array(),'prefix_id',"DESC",'','' ,'');	

		
		$prefix_name 	=	$prefix_result->prefix_name;
		$current_no 	=	$prefix_result->current_no;
		$transaction_no =	$prefix_name.' '.$current_no;


		
		$prefix_id 		=	$prefix_result->prefix_id;
		$current_no++;
		$this->save_data(PREFIX_TBL,array("current_no"=>$current_no),array('prefix_id'=>$prefix_id),$prefix_id);

		return $transaction_no;
	}


	public function get_invoice_no_curr($company_id,$branch_id,$type)
	{
		
		$prefix_result  =	$this->select_data(PREFIX_TBL,'prefix_id,prefix_name,current_no',array('prefix_company_id'=>$company_id,'prefix_branch_id'=>$branch_id,'type'=>$type,'delete_status'=>0), 1, array(),'prefix_id',"DESC",'','' ,'');	

		
		$prefix_name 	=	$prefix_result->prefix_name;
		
		
		$ttype         = $this->input->post("type");
		//if($ttype=='1') // IMPORT 
		//{
			$this->db->select('id,current_no');
			$this->db->from('current_no');
			$this->db->where('type',$ttype);
			$sql=$this->db->get()->row();
			
			$current_no=$sql->current_no;
			$id=$sql->id;
			
		//}
		
		$transaction_no =	$prefix_name.' '.$current_no;
		
		
		//$prefix_id 		=	$prefix_result->prefix_id;
		$current_no++;
		
		$this->db->set('current_no',$current_no);
		$this->db->where('id',$id);
		$this->db->update('current_no');
		
		//print_r($transaction_no);
		//die();
		
		//die();
		return $transaction_no;
	}
	
	public function edit_invoice_no($id)
	{
		$this->db->select('invoice_no');
		$this->db->where('id',$id);
	    $res =	$this->db->get('invoice');
		//$result = $this->db->get()->row();
		return $res->row();
		//$this->db->last_query();
		//exit();
	}
	public function get_invoice_id($invoice_no_search)
	{
		$this->db->select('*');
		$this->db->where('invoice_no',$invoice_no_search);
	    $res =	$this->db->get('invoice');
		//$result = $this->db->get()->row();
		return $res->row();
		//$this->db->last_query();
		//exit();
	}
	
	public function get_invoice_details($invoiceID)
	{

		$this->db->select('det.*');
		$this->db->from('invoice_details det');
		$this->db->join('invoice inv', 'inv.id = det.invoice_id', 'left');
		$this->db->where('det.status ', 1);
		$this->db->where('det.invoice_id', $invoiceID);
		$res2 = $this->db->get(); 

		//echo $this->db->last_query();die();
        return $res2->result_array();

		// exit();

	}
	public function get_invoice_import_details($invoiceID)
	{
		$this->db->select('ind.*');
		$this->db->from('invoice_import_details ind');
		$this->db->join('invoice inv', 'inv.id = ind.invoice_id', 'left');
		$this->db->where('ind.status', 1);
		$this->db->where('ind.invoice_id ', $invoiceID);
		$resl = $this->db->get(); 
        return $resl->result_array();
	 //echo $his->db->last_query(); die();
		//etxit();

	}
   public function invoice_log_data($invoice_no_search,$post_array,$created_by,$created_date)
     { 
	    $this->db->select('*');
		$this->db->where('invoice_no',$invoice_no_search);
	
		$query = $this->db->get('invoice');
		foreach ($query->result() as $row) {
			$row->post_data = $post_array;
			$row->created_by = $created_by;
			$row->created_date_time = $created_date;
			//echo "<pre>"; print_r($row); die();
		$this->db->insert('invoice_edit_log',$row);
		

		}
		
		//$this->db->last_query();
		return $query->row();
		
	 }

     public function change_status_detail($invoice_ids){

        $this->db->set('status', '0');
		$this->db->where('invoice_id',$invoice_ids);
		$this->db->update('invoice_details');
	
	   $this->db->last_query();
		//exit();

	 }
	 public function change_status_import($invoice_ids){
		
		$this->db->set('status', '0');
		$this->db->where('invoice_id',$invoice_ids);
		$this->db->update('invoice_import_details');
	
		$this->db->last_query();
		//exit();

	 }
   
	 public function invoice_log_detail($invoice_ids,$detail_array,$created_by,$created_date){

		$this->db->select('*');
		$this->db->where('invoice_id',$invoice_ids);
	
		$query = $this->db->get('invoice_details');
		foreach ($query->result() as $row) {
			$row->post_data = $detail_array;
			$row->created_by = $created_by;
			$row->created_date_time = $created_date;
			//echo "<pre>"; print_r($row); die();
		$this->db->insert('invoice_log_details',$row);
		
		}
		$this->db->last_query();
		return $query->row();

	 }
	
	 public function invoice_log_import($invoice_ids,$detail_array,$created_by,$created_date){

		$this->db->select('*');
		$this->db->where('invoice_id',$invoice_ids);
	
		$query = $this->db->get('invoice_import_details');
		foreach ($query->result() as $row) {
			$row->post_data = $detail_array;
			$row->created_by = $created_by;
			$row->created_date_time = $created_date;
			//echo "<pre>"; print_r($row); die();
		$this->db->insert('invoice_log_import',$row);
		
		}
		
		$this->db->last_query();
		return $query->row();

	 }

	
	

	
}
?>