  <?php 
    $this->load->view('templates/header');
    $role = $this->session->userdata("user_role_id");
    $action = (isset($_GET['action'])) ? $_GET['action'] : "";
    $search_value_entry_no  = (isset($_GET['search_value_entry_no'])) ? $_GET['search_value_entry_no'] : "";
    $search_value_v_type    = (isset($_GET['search_value_v_type'])) ? $_GET['search_value_v_type'] : "";
    $search_value_entry_date= (isset($_GET['search_value_entry_date'])) ? $_GET['search_value_entry_date'] : "";    
    $search_value_ac_type   = (isset($_GET['search_value_ac_type'])) ? $_GET['search_value_ac_type'] : "";    
    $search_value_party_name= (isset($_GET['search_value_party_name'])) ? $_GET['search_value_party_name'] : "";    
    $search_value_group     = (isset($_GET['search_value_group'])) ? $_GET['search_value_group'] : "";    
    $search_value_amt       = (isset($_GET['search_value_amt'])) ? $_GET['search_value_amt'] : "";    
    $search_value_chq_no    = (isset($_GET['search_value_chq_no'])) ? $_GET['search_value_chq_no'] : "";    
  ?>
    <script>
        var link = "voucher";
        var sub_link = "voucher_view";
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
       VOUCHER
        <small>Master</small>
      </h1>
      
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Voucher</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('voucher/voucherctrl/voucher_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">
                                        <label>Entry No</label>
                                        <input type="text" class="form-control floating-input " name="search_value_entry_no" value="<?php echo $search_value_entry_no ?>" placeholder=" " autocomplete="off"/>
                                        <!-- <span class="highlight"></span> -->
                                    </div>
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <label>Entry Date</label>
                                        <input type="text" class="form-control floating-input entry_date" id="" name="search_value_entry_date" value="<?php echo $search_value_entry_date ?>" placeholder=" " autocomplete="off"/>
                                        <!-- <span class="highlight"></span> -->
                                    </div>
                                    <div class="col-md-2 col-sm-2 floating-label">
                                        <label>Voucher Type</label>
                                        <?php echo form_dropdown('', $data['v_type'], $search_value_v_type,' name="search_value_v_type" class="form-control floating-select" ');?>
                                        <!-- <span class="highlight"></span> -->
                                    </div>
                                    <div class="col-md-1 col-sm-1 floating-label">                                        
                                        <label>Account</label>
                                       <?php echo form_dropdown('', $data['account_data'], $search_value_ac_type,' name="search_value_ac_type" class="form-control floating-select" ');?>
                                    </div>
                                    <div class="col-md-2 col-sm-2 floating-label">
                                        <label>Party Name</label>
                                        <input type="text" class="form-control floating-input" name="search_value_party_name" value="<?php echo $search_value_party_name ?>" placeholder=" " autocomplete="off"/>
                                        <!-- <span class="highlight"></span> -->
                                    </div>
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <label>Group</label>
                                        <?php echo form_dropdown('', $data['group_data'], $search_value_group,' name="search_value_group" class="form-control floating-select" ');?>
                                    </div>
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <label>Amount</label>
                                        <input type="text" class="form-control floating-input" name="search_value_amt" value="<?php echo $search_value_amt ?>" placeholder=" " autocomplete="off"/>
                                        <!-- <span class="highlight"></span> -->
                                    </div>
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <label>Cheque No</label>
                                        <input type="text" class="form-control floating-input" name="search_value_chq_no" value="<?php echo $search_value_chq_no ?>" placeholder=" " autocomplete="off"/>
                                        <!-- <span class="highlight"></span> -->
                                    </div> 
                                    <div class="col-md-1 col-sm-1 ">
                                        <input type="hidden" class="form-control" id="action" name="action" value="<?php echo $action ?>" />
                                        <button type="submit" class="btn btn-primary"><i class="fa fa-search" aria-hidden="true"></i>Search</button>                                        
                                    </div> 
                                    <div class="col-md-1 col-sm-1">
                                        <a href="<?php echo base_url('voucher/voucherctrl/voucher_master?action=view'); ?>" class="btn btn-primary" ><i class="fa fa-undo" aria-hidden="true"></i>
                                            Reset
                                        </a>
                                    </div>                                    
                                    <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" id="count_reload">
                                            <span id="total_rows">Cnt : <?php echo $total_rows;?></span>
                                        </label>                                
                                </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" id="table_tbody">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>Entry No</th>
                                    <th>Entry Date</th>    
                                    <th>Voucher Type</th>    
                                    <th>Account</th>
                                    <th>Party Name</th>
                                    <th>Group</th>
                                    <th>Amount</th>
                                    <th>Round Off</th>
                                    <th>Cheque No</th>
                                    <th>Print</th>
                                    <th>Edit</th>
                                    <th>Delete</th>
                                </tr>
                            </thead>
                            <tbody>
                        <?php
                            if(!empty($data['voucher_data'])):
                                foreach ($data['voucher_data'] as $key => $value):
                                    $vm_id = encrypt_decrypt("encrypt", $value['vm_id'], SECRET_KEY);
                        ?>
                                    <tr>
                                        <td><?php echo $key+1?></td>
                                        <td><?php echo $value['vm_entry_no']?></td>
                                        <td><?php echo date('d-m-Y', strtotime($value['vm_entry_date']));?></td>
                                        
                                        <td>
                                            <?php 
                                                if($value['vm_voucher_type'] == 1)
                                                    echo "PAYMENT";
                                                else if($value['vm_voucher_type'] == 2)
                                                    echo "RECEIPT";
                                                else
                                                    echo "OPENING";
                                                ?>
                                        </td>
                                        <td><?php echo $value['vm_cash_acc_id'];?></td>
                                        <td><?php echo $value['vm_grp_id'] == 5 ? $value['acc_name'] : $value['km_code'] ;?></td>
                                        <td><?php 
                                                if($value['vm_grp_id'] == 5)
                                                    echo "CUSTOMER";
                                                else if($value['vm_grp_id'] == 23)
                                                    echo "KARIGAR";
                                                else
                                                    echo "GENERAL";
                                                ?>                                                    
                                        </td>
                                        <td><i class="fa fa-inr"></i> <?php echo $value['vm_amount'];?></td>
                                        <td><i class="fa fa-inr"></i> <?php echo $value['vm_round_off'];?></td>
                                        <td><?php echo $value['vm_cheque_no'];?> </td>
                                        <?php if($value['vm_voucher_type'] == 1): // for payment ?>
                                        <td>
                                             <a target="blank" href="<?php echo base_url('voucher/voucherctrl/voucher_master?action=print&type=PAYMENT&id='.$vm_id.'')?>" class="glyphicon glyphicon-print" style="cursor:pointer;"></a>
                                        </td> 
                                         <?php else: ?>
                                        <td>
                                            <a target="blank" href="<?php echo base_url('voucher/voucherctrl/voucher_master?action=print&type=RECEIPT&id='.$vm_id)?>"><span class="glyphicon glyphicon-print" style="cursor:pointer;"></span></a>
                                        </td>
                                        <?php endif; ?>                                     
                                        <?php
                                            if($role == 1):
                                                if($value['vm_voucher_type'] == 1): // for payment 
                                        ?>
                                        <td>
                                             <a href="<?php echo base_url('voucher/voucherctrl/voucher_master?action=update&type=PAYMENT&id='.$vm_id.'')?>" class="glyphicon glyphicon-pencil" style="cursor:pointer;"></a>
                                        </td> 
                                         <?php
                                                else:
                                        ?>

                                        <td>
                                            <a href="<?php echo base_url('voucher/voucherctrl/voucher_master?action=update&type=RECEIPT&id='.$vm_id)?>"><span class="glyphicon glyphicon-pencil" style="cursor:pointer;"></span></a>
                                        </td>

                                        <?php
                                            endif;
                                        ?>                                     
                                        <td>                                      
                                            <!-- <span class="glyphicon glyphicon-trash" onClick="delete_voucher_item(<?php echo $value['vm_id']?>,'voucher_delete');" style="cursor:pointer;"></span> -->
                                            <a type="button" onclick="delete_voucher_item('<?php echo base_url('voucher/voucherctrl/voucher_delete/'.$value['vm_id']); ?>');">
                                                <i class="fa fa-trash"></i>
                                            </a>
                                        </td>
                                         <?php
                                            else:
                                        ?>
                                        <td></td>
                                        <td></td>
                                        <?php
                                            endif;
                                        ?>
                                    </tr> 
                        <?php
                                endforeach;
                            else:
                        ?>
                                <tr>
                                    <td colspan="20" align="center"><b>No Record Found !</b></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');
?>
<!-- Master JS files -->
    <script src="<?php echo assets('js/voucher/voucher.js')?>"></script>
   </body>
</html>