<?php
if($_GET)
{
    $bill_id     =   $_GET['bill_id'];
}
else
{
    $bill_id     =   '';
}
?>
<div style="color:green;text-align:center" class="success"><strong><?php if($this->session->flashdata('msg')){ echo $this->session->flashdata('msg');} ?></strong></div>
<div class="box-body">
	<form role="form" id="bill_search" name="bill_search" action="<?php echo base_url();?>Invoice/generate_invoice" method="post">
     <div class="row"> 
       <div class="col-md-3">
           <div class="form-group">
               <label>Bill No</label>
                   <select class="form-control select2" name="bill_id" id="bill_id">
                   <option value=''>Invoice No</option>
                   <?php foreach($invno as $billnos) {

                     $selected = $billnos['id'] == $search_data['id'] ? 'selected' : '';
                      ?>
                       <option value="<?php echo $billnos['id'];?>"<?php echo $selected; ?>><?php echo $billnos['invoice_no'];?></option>
                       <?php } ?>
                   </select>
            </div>
          </div>
          <div class="col-md-3">
           <div class="form-group">
                  <label>Bill Date</label>
                  <input type="date" class="form-control" name="bill_created_date" value="<?php echo $search_data['bill_created_date'];?>">
            </div>
            </div>

        <div class="col-md-1">

        </div>
        
        <div class="col-md-2">
            <div class="form-group">
              	<button class="btn btn-block btn-warning" name="search" value="search"><b>Search</b></button> 
              	<a href="<?php echo base_url();?>Invoice/add_invoice" class="btn btn-block btn-info"><b>Add Invoice</b></a>
            </div>
        </div>
    </div> 
    </form>
</div>
<!-- /.box-header -->
<div class="box-body"> 
     <table id="example2" class="table table-bordered table-hover">
        <thead>
            <tr>
                <th style="width: 10%">#</th>
                <th style="width: 26%">Invoice No</th>               
                <th style="width: 27%">Shipper/Exporter</th>              
                <th style="width: 27%">Customer</th>
                <th style="width: 15%">Edit Invoice</th>

                <th style="width: 5%">PDF</th>
			
            </tr>
        </thead>
        <tbody> 
       <?php $page_num=0;if(count($invoice_details)!=0)
        {        	
          $count = $this->uri->segment(3);
        	foreach($invoice_details as $row)
        	{
            $count++;
          ?> 

	    		<tr>
	    			<td><?php echo $count;?></td>
	    			<td><?php echo $row['invoice_no'];?></td>	    			
	    			<td><?php echo $row['consignor_name'];?></td>
            <td><?php echo $row['customer_name'];?></td>
        <td class="status_text">
          
          <button  id="editInvoice" type="button" class="btn btn-success btn-xs" onclick="window.location.href='<?php echo base_url();?>Invoice/edit_invoice/<?php echo $row['id'];?>'"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>&nbsp;EDIT</button>
  
         </td>
	    	<td class="status_text">
               <?php if($row['type']==0) { ?>
			   <button  id="pdfDownload" type="button" class="btn btn-primary btn-xs" onclick="window.location.href='<?php echo base_url();?>Invoice/pdf_Invoice/<?php echo $row['id'];?>'"><i class="fa fa-file-pdf-o" aria-hidden="true"></i>&nbsp;PDF</button>

			   <?php } else { ?>
				  <button  id="pdfDownload" type="button" class="btn btn-success btn-xs" onclick="window.location.href='<?php echo base_url();?>Invoice/pdf_Invoice_imp/<?php echo $row['id'];?>'"><i class="fa fa-file-pdf-o" aria-hidden="true"></i>&nbsp;PDF</button>

         <?php }  ?>
            </td>
         

          </tr>
        	<?php }
        }?>
         </tbody>
    </table>
    <p><?php echo $links; ?></p>
</div> 

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">


jQuery(function()
  {
    eventHandler();      
  });


var eventHandler = function()
  {
      jQuery(document).on('click','.printButton',printButton);
      jQuery(document).on('click','.printbutton_aftr_approval',printbutton_aftr_approval);
  };
  function printButton()
  {
    var count  = this.id;
    $.get('<?php echo base_url();?>Generate_bill/get_bill_details/'+count, function(data)
    {
        var contents = data;
        var frame1 = $('<iframe />');
        frame1[0].name = "frame1";
        frame1.css({ "position": "absolute", "top": "-1000000px" });
        $("body").append(frame1);
        var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
        frameDoc.document.open();
        frameDoc.document.write(contents);
        frameDoc.document.close();
        setTimeout(function () 
        {
            window.frames["frame1"].focus();
            window.frames["frame1"].print();
            frame1.remove();
        }, 1000);
    });
  }

   function printbutton_aftr_approval()
  {
    var count  = this.id;
    $.get('<?php echo base_url();?>Generate_bill/get_bill_details_after_approval/'+count, function(data)
    {
        var contents = data;
        var frame1 = $('<iframe />');
        frame1[0].name = "frame1";
        frame1.css({ "position": "absolute", "top": "-1000000px" });
        $("body").append(frame1);
        var frameDoc = frame1[0].contentWindow ? frame1[0].contentWindow : frame1[0].contentDocument.document ? frame1[0].contentDocument.document : frame1[0].contentDocument;
        frameDoc.document.open();
        frameDoc.document.write(contents);
        frameDoc.document.close();
        setTimeout(function () 
        {
            window.frames["frame1"].focus();
            window.frames["frame1"].print();
            frame1.remove();
        }, 1000);
    });
  }

</script>