  <?php 
    $this->load->view('templates/header');
    $role       = $this->session->userdata("user_role_id");
    $action     = (isset($_GET['action'])) ? $_GET['action'] : "";
    $date_from  = isset($_GET['date_from']) && !empty($_GET['date_from']) ? $_GET['date_from'] : '';
    $date_to    = isset($_GET['date_to']) && !empty($_GET['date_to']) ? $_GET['date_to'] : '';
    $group      = isset($_GET['group']) && !empty($_GET['group']) ? $_GET['group'] : '';
    $accounts   = isset($_GET['accounts']) && !empty($_GET['accounts']) ? $_GET['accounts'] : 0;
    $modes      = isset($_GET['modes']) && !empty($_GET['modes']) ? $_GET['modes'] : '';
    $amt_from   = isset($_GET['amt_from']) && !empty($_GET['amt_from']) ? $_GET['amt_from'] : '';
    $amt_to     = isset($_GET['amt_to']) && !empty($_GET['amt_to']) ? $_GET['amt_to'] : '';
  ?>
    <script>
        var link = "voucher";
        var sub_link = "receipt";
    </script>
    <!-- Content Header (Page header) -->
    <form class="form-horizontal" action="<?php echo base_url('voucher/receipt')?>" method="get">
        <section class="content-header">
            <div class="row">
                <div class="col-md-4">
                    <p style="font-size: 20px;font-weight: bold;">
                        RECEIPT 
                        <small>VOUCHER (<span id="count_reload"><i id="total_rows"><?php echo $total_rows;?></i></span>)</small> 
                    </p>
                </div>
                <div class="col-md-2 col-md-offset-6 col-xs-12">
                    <span>
                        <button type="submit" class="btn btn-success" id="btn_search"><i class="fa fa-search" aria-hidden="true"></i></button>
                        <a href="<?php echo base_url('voucher/receipt?action=view'); ?>" class="btn btn-danger"><i class="fa fa-refresh" aria-hidden="true"></i></a>
                        <a href="<?php echo base_url('voucher/receipt?action=add'); ?>" class="btn btn-warning"><i class="glyphicon glyphicon-plus" aria-hidden="true"></i></a>
                    </span>
                </div>
            </div>
        </section>
        <!-- Main content -->
        <section class="content">
            <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>
                                    <input type="hidden" class="form-control" id="action" name="action" value="<?php echo $action ?>" />
                                    <tr>
                                        <td width="5%" colspan="2">
                                            <label>VOUCHER NO</label>
                                            <select class="form-control floating-select" id="entry_no" name="entry_no">
                                                <?php if(isset($data['search']['entry_no']) && !empty($data['search']['entry_no'])): ?>
                                                    <option value="<?php echo $data['search']['entry_no']['value']; ?>" selected>
                                                        <?php echo $data['search']['entry_no']['text']; ?> 
                                                    </option>
                                                <?php endif; ?>
                                            </select>
                                        </td>
                                        <td width="15%">
                                            <label>VOUCHER DATE <small>(FROM & TO)</small></label>
                                            <div style="display: flex; justify-content: space-between;">
                                                <input type="text" class="form-control floating-input date_plug" name="date_from" id="date_from" placeholder="FROM" autocomplete="off" value="<?php echo $date_from; ?>">
                                                <input type="text" class="form-control floating-input date_plug" name="date_to" id="date_to" placeholder="TO" autocomplete="off" value="<?php echo $date_to; ?>">
                                            </div>
                                        </td>
                                        <!-- <td width="10%">
                                            <label>GROUP</label>
                                            <?php echo form_dropdown('', ['' => 'ALL', 'CUSTOMER' => 'CUSTOMER', 'KARIGAR' => 'KARIGAR'], $group,'id="group" name="group" class="form-control" onchange="trigger_search()"');?>
                                        </td>
                                        <td width="10%">
                                            <label>GROUP</label>
                                            <?php echo form_dropdown('', $data['accounts'], $accounts,'id="accounts" name="accounts" class="form-control" onchange="trigger_search()"');?>
                                        </td> -->
                                        <td width="20%">
                                            <label>PARTY NAME</label>
                                            <select class="form-control floating-select" id="_party_id" name="_party_id">
                                                <?php if(isset($data['search']['_party_id']) && !empty($data['search']['_party_id'])): ?>
                                                    <option value="<?php echo $data['search']['_party_id']['value']; ?>" selected>
                                                        <?php echo $data['search']['_party_id']['text']; ?> 
                                                    </option>
                                                <?php endif; ?>
                                            </select>
                                        </td>
                                        <td width="10%">
                                            <label>MODE</label>
                                            <?php echo form_dropdown('', $data['modes'], $modes,'id="modes" name="modes" class="form-control" onchange="trigger_search()"');?>
                                        </td>
                                        <td width="12%">
                                            <label>PAID AMT <small>(FROM & TO)</small></label>
                                            <div style="display: flex; justify-content: space-between;">
                                                <input type="number" class="form-control floating-input" name="amt_from" id="amt_from" placeholder="FROM" autocomplete="off" value="<?php echo $amt_from; ?>">
                                                <input type="number" class="form-control floating-input" name="amt_to" id="amt_to" placeholder="TO" autocomplete="off" value="<?php echo $amt_to; ?>">
                                            </div>
                                        </td>
                                    </tr>
                                    <tr>
                                        <th width="3%">#</th>
                                        <th width="10%">VOUCHER NO</th>
                                        <th width="10%">VOUCHER DATE</th>
                                        <th width="10%">GROUP</th>
                                        <th>PARTY NAME</th>
                                        <th width="10%">PAYMENT MODE</th>
                                        <th width="10%">PAID AMT</th>
                                        <!-- <th width="3%">PRINT</th>  -->
                                        <th width="3%">EDIT</th> 
                                        <th width="4%">DELETE</th>
                                    </tr>
                                </thead>
                                <tbody>
                            <?php
                                if(!empty($data)):
                                $sr_no = 1;
                                foreach ($data['data'] as $key => $value):
                            ?>
                                    <tr>
                                        <td><?php echo $sr_no; ?></td>
                                        <td><?php echo $value['vm_entry_no']; ?></td>
                                        <td><?php echo date('d-m-Y', strtotime($value['vm_entry_date'])); ?></td>
                                        <td><?php echo strtoupper($value['vm_group']); ?></td>
                                        <td><?php echo $value['vm_group'] == 'KARIGAR' ? strtoupper($value['km_name']) : strtoupper($value['customer_name']); ?></td>
                                        <td><?php echo $value['vm_mode']; ?></td>
                                        <td><?php echo round(($value['vm_total_amt']), 2); ?></td>
                                        <!-- <td>
                                            <a target="blank" href="<?php echo base_url('voucher/receipt?action=print&id='.$value['vm_id'])?>" class="glyphicon glyphicon-print" style="cursor:pointer;"></a>
                                        </td> -->
                                        <td>
                                            <a href="<?php echo base_url('voucher/receipt?action=edit&id='.$value['vm_id'])?>" class="glyphicon glyphicon-pencil" style="cursor:pointer;"></a>
                                        </td>
                                        <td>
                                            <a type="button" onclick="delete_receipt('<?php echo base_url('voucher/receipt/remove/'.$value['vm_id']); ?>');">
                                                <i class="fa fa-trash"></i>
                                            </a>
                                        </td>
                                    </tr> 
                            <?php
                                    $sr_no++;
                                endforeach;
                                else:
                            ?>
                                <tr>
                                    <td colspan="15" align="center" ><b style="color: red;">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>
    </form>
 
<?php 
    $this->load->view('templates/footer');
?>
<!-- Master JS files -->
    <script src="<?php echo assets('js/voucher/receipt.js')?>"></script>
   </body>
</html>