  <?php 
    $this->load->view('templates/header');
    $action                     = (isset($_GET['action'])) ? $_GET['action'] : "";
    $start_date    = (isset($_GET['start_date'])) ? $_GET['start_date'] : '';    
    $end_date    = (isset($_GET['end_date'])) ? $_GET['end_date'] : '';    
    $acc_id      = (isset($_GET['acc_id'])) ? $_GET['acc_id'] : 0;    
  ?>
    <script>
        var link = "report";
        var sub_link = "purchase_report";
    </script>
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>PURCHASE<small>REPORT</small></h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li class="active">Purchase Report</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('report/Reportctrl/purchase_report')?>" 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">
                                        <input type="text" class="form-control floating-input" name="start_date" id="start_date" value="<?php echo $start_date ?>" placeholder="" autocomplete="off"/>
                                        <label>START DATE</label>
                                    </div>
                                    <div class="col-md-1 col-sm-1 floating-label">
                                        <input type="text" class="form-control floating-input" name="end_date" id="end_date" value="<?php echo $end_date ?>" placeholder="" autocomplete="off"/>
                                        <label>END DATE</label>
                                    </div>                                  

                                    <div class="col-md-2 col-sm-2 floating-label">
                                        <?php echo form_dropdown('', $data['account_data'], $acc_id,'id="acc_id" name="acc_id" class="form-control floating-select flexselect" ');?>
                                        <label>SUPPLIER</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('report/Reportctrl/purchase_report?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 target="_blank" href="<?php echo base_url('report/Reportctrl/purchase_report_print?start_date='.$start_date.'&end_date='.$end_date.'&acc_id='.$acc_id); ?>" class="btn btn-primary"><i class="fa fa-print" aria-hidden="true"></i>
                                            Print
                                        </a>
                                    </div>
                                    <div class="col-md-1 col-sm-1">
                                       
                                        <a target="_blank" href="<?php echo base_url('report/Reportctrl/purchase_report_print?submit=excel&start_date='.$start_date.'&end_date='.$end_date.'&acc_id='.$acc_id); ?>" class="btn btn-success"><i class="fa fa-print" aria-hidden="true"></i>
                                            Excel
                                        </a>
                                    </div>
                                    <div class="col-md-1 col-sm-1 ">
                                        <label for="inputEmail3" class="col-sm-1 control-label control-label_custom" style="width:100%;">
                                            Count :
                                            <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">
                            <thead>
                                <tr>
                                    <th width="5%">#</th>
                                    <th>INV NO</th>
                                    <th>INV DATE</th>    
                                    <th>CUSTOMER NAME</th> 
                                    <th>TOTAL QTY</th>
                                    <th>TOTAL RATE</th>
                                    <th>TOTAL CGST</th>
                                    <th>TOTAL SGST</th>
                                    <th>TOTAL IGST</th>
                                    <th>TOTAL AMT</th>
                                </tr>
                            </thead>
                            <tbody>
                        <?php
                            if(!empty($data['purchase_data'])):
                            foreach ($data['purchase_data'] as $key => $value):
                                $user       =  $value['acc_name'];           
                                $entry_no   =  $value['per_entry_no'];
                                $entry_date =  date('d-m-Y', strtotime($value['per_invoice_date']));

                                $total_qty   = $value['per_total_qty'];
                                $total_rate   = $value['per_total_rate'];
                                $total_cgst   = $value['per_total_cgst'];
                                $total_sgst   = $value['per_total_sgst'];
                                $total_igst   = $value['per_total_igst'];
                                $total_amt   = $value['per_total_amt'];
                        ?>
                            <tr>
                                <td><?php echo $key+1 ?></td>                                
                                <td><?php echo $entry_no; ?></td>
                                <td><?php echo $entry_date; ?></td>
                                <td><?php echo $user; ?></td>
                                <td><?php echo $total_qty; ?></td>
                                <td><?php echo $total_rate; ?></td>
                                <td><?php echo $total_cgst; ?></td>
                                <td><?php echo $total_sgst; ?></td>
                                <td><?php echo $total_igst; ?></td>
                                <td><?php echo $total_amt; ?></td>
                            </tr> 
                        <?php
                            endforeach;
                            else:
                        ?>
                            <tr>
                                <td colspan="10" align="center" style="color: red;">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 type="text/javascript" >
       disable_enable_background(false)
   </script> 