  <?php 
    $this->load->view('templates/header');
    $action                     = (isset($_GET['action'])) ? $_GET['action'] : "";
    $entry_no      = (isset($_GET['entry_no'])) ? $_GET['entry_no'] : 0;
    $entry_date    = (isset($_GET['entry_date'])) ? $_GET['entry_date'] : date('d-m-Y');
    $cust_id       = (isset($_GET['cust_id'])) ? $_GET['cust_id'] : 0;
    $search_value_broker_id     = (isset($_GET['search_value_broker_id'])) ? $_GET['search_value_broker_id'] : 0;

  ?>
    <script>
        var link = "invoice_section";
        var sub_link = "invoice";
    </script>
    
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1> IINVOICES</h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Invoices</a></li>
        <li class="active">View</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-md-12 col-sm-12">
                <div class="box box-primary">
                    <!-- <div class="box-body"> -->
                        <form class="form-horizontal" id="search_form" action="<?php echo base_url('invoice/invoicectrl/invoice_master/')?>" method="get">
                            <div class="panel panel-body remove-bottom">
                                <div class="form-group floating-form">
                                    
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['entry_no_drop_down'], $entry_no,'id="entry_no" name="entry_no" class="form-control floating-select flexselect" ');?>
                                        <label>IINVOICE NO</label>
                                    </div>

                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="text" class="form-control floating-input" name="entry_date" id="entry_date" value="<?php echo $entry_date ?>" placeholder=" " autocomplete="off"/>
                                        <label>IINVOICE DATE</label>
                                    </div>

                                    <div class="col-md-2 col-sm-1 floating-label">
                                        <?php echo form_dropdown('', $data['account_data'], $cust_id,'id="cust_id" name="cust_id" class="form-control floating-select flexselect" ');?>
                                        <label>CUSTOMER</label>
                                    </div>
                                    
                                    <div class="col-md-1 col-sm-1 ">
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i>Search</button>                                   
                                        <input type="hidden" class="form-control" id="action" name="action" value="<?php echo $action ?>" />     
                                    </div>

                                    <div class="col-md-1 col-sm-1">
                                        <a href="<?php echo base_url('invoice/invoicectrl/invoice_master?action=view'); ?>" class="btn btn-primary"><i class="fa fa-undo" aria-hidden="true"></i>
                                            Reset
                                        </a>
                                    </div>
                                    <div class="col-md-1 col-sm-1">
                                        <a href="<?php echo base_url('invoice/invoicectrl/invoice_master?action=add'); ?>" class="btn btn-primary">Add New</a>
                                    </div>
                                    <div class="col-md-2 col-sm-2 ">
                                        <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" style="width:90%;">
                                            Cnt :
                                            <span id="count_reload">                                                 
                                                <i id="total_rows"><?php echo $total_rows;?></i>
                                            </span>
                                        </label>                                        
                                    </div>                                    
                                </div>
                            </div>
                        </form>
                    <!-- </div> -->
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-md-12">     
                <div class="box">
                    <div class="box-body" id="table_reload">
                        <table class="table table-bordered table-striped hoverTable">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>INVOICE NO</th>
                                    <th>INVOICE DATE</th>    
                                    <th>CUSTOMER</th>
                                    <th>TOTAL QTY</th>
                                    <th>TOTAL AMT</th>
                                    <th>PRINT</th>    
                                    <th>ACTION</th>  
                                </tr>
                            </thead>
                            <tbody>
                        <?php 
                                if(!empty($data['inv_data'])):
                                foreach ($data['inv_data'] as $key => $value): 
                                    $inv_id      = encrypt_decrypt("encrypt", $value['inv_id'], SECRET_KEY);
                                    $entry_no   = $value['inv_entry_no'];
                                  if($value['inv_invoice_date'] == "0000-00-00" || $value['inv_invoice_date'] == "1970-01-01"){ $entry_date = ""; }else{ $entry_date = date('d-m-Y', strtotime($value['inv_invoice_date'])); }
                                    $customer   = strtoupper($value['acc_name']);
                                    $qty        = $value['inv_total_qty'];
                                    $amt        = number_format($value['inv_total_amt'],2);
                        ?>
                            <tr>
                                <td><?php echo $key+1?></td>                                
                                <td><?php echo $entry_no; ?></td>
                                <td><?php echo $entry_date; ?></td>
                                <td><?php echo $customer; ?></td>
                                <td><?php echo $qty; ?></td>
                                <td><?php echo $amt; ?></td>
                                <td><a href="<?php echo base_url('invoice/invoicectrl/invoice_master?action=print&id='.$inv_id); ?>" class="glyphicon glyphicon-print" target="_blank" width="1024" height="768"></a></td>
                                <td>
                                    <a href="<?php echo base_url('invoice/invoicectrl/invoice_master?action=edit&id='.$inv_id); ?>" class="glyphicon glyphicon-pencil"></a>
                                    &nbsp;&nbsp;&nbsp;
                                    <span class="glyphicon glyphicon-trash" style="cursor: pointer;" onClick="delete_invoice(<?php echo $value['inv_id']?>);"></span></td>
                            </tr> 
                        <?php
                            endforeach;
                            else:
                        ?>
                            <tr>
                                <td colspan="10" style="color:red;" align="center">No Record Found!</td>
                            </tr>
                        <?php
                            endif;
                        ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="text-right">
                <?= $this->pagination->create_links(); ?>
            </div>
        </div>
    </section>
    <?php 
    $this->load->view('templates/footer');
   ?>
    <script src="<?php echo assets('js/invoice.js')?>"></script> 
  