<?php  include "header.php";?>

  
<div class="content-wrapper">
    
        <!--<section class="content-header">
            <h1>Users List</h1>
            <ol class="breadcrumb">
                <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active"> Users List</li>            
            </ol>
        </section>-->

        <div class="clearfix"></div>
        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            
            <?php if(isset($_SESSION['message']) && $_SESSION['message']!=""){ ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?=$_SESSION['message'];?>
            </div>
            <?php  unset($_SESSION['message']); } ?>
            
            
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            <?php } if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> Warning</h4>
                <?= $warning; ?>
            </div>
            <?php } if ($message) { ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $site_name; ?>
            </div>
            <?php } ?>
        </div>
        




<section class="content">
    <?php if($session_id==1 || $session_user_type==1 || $allPermissions['expenses']['read']==1){ ?>
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary" style="box-shadow: rgba(14, 30, 37, 0.12) 0px 2px 4px 0px, rgba(14, 30, 37, 0.32) 0px 2px 16px 0px;">
                <div class="box-header">

            
        <?php if($session_id==1 || $session_user_type==1 || $allPermissions['expenses']['create']==1){ ?>
                <a  href="expenses_add.php" class="btn btn-success btn-sm pull-right"><i class="fa fa-plus-circle"></i> Add New Expenses</a>
        <?php } ?>
        <span class="btn btn-default btn-sm pull-right filter" style="margin-right: 5px;"> Show/Hide Filter</span>
        
        
                    <h3 class="box-title">Expenses List</h3>
                </div>
                <div class="box-body">
                    
                    
    <div class="row" id="filter">
    
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="" for="exp_category">Expenses Category</label>                                   
            <select name="exp_category" class="form-control select2" style="width:100%" id="exp_category" required="required">
                <option value="">All Expenses Category</option>
                <?php $statement = $pdo->prepare("SELECT * FROM `tbl_exp_category` where status=1");
                    $statement->execute(array());
                    $resultsss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                    foreach ($resultsss as $ress) { ?>
                        <option value="<?=$ress['id']?>"><?=$ress['name']?></option>
                <?php  }  ?>
            </select>
        </div>
    </div>
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="" for="payment_type">Payment Type</label>                                   
            <select name="payment_type" class="form-control select2" style="width:100%" id="payment_type" required="required">
                <option value="">All Payment Type</option>
                <?php $statement = $pdo->prepare("SELECT * FROM `tbl_payment_type` where status=1");
                    $statement->execute(array());
                    $resultsss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                    foreach ($resultsss as $ress) { ?>
                        <option value="<?=$ress['id']?>"><?=$ress['name']?></option>
                <?php  }  ?>
            </select>
        </div>
    </div>
    
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="" for="start_date">Start Date</label>                                   
            <input type="date" name="start_date" class="form-control" style="width:100%" id="start_date" value="<?=$startMonthDate?>" required="required">
        </div>
    </div>
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="" for="end_date">End Date</label>                                   
            <input type="date" name="end_date" class="form-control" style="width:100%" id="end_date" value="<?=$endMonthDate?>" required="required">
        </div>
    </div>
    
    
    
    </div>


<div class="clearfix"></div>


                    <div class="table-responsive">
                        <table id="StData" class="table table-striped table-bordered table-condensed table-hover" style="margin-bottom:5px;">
                            <thead>
                                <tr>
                                    <td colspan="13" class="p0"><input type="text" class="form-control b0" name="search_table" id="search_table" value="" placeholder="Search Here" style="width:100%;background-color: darkblue;color: white;"></td>
                                </tr>
                                <tr class="active">
                                    <th style="min-width:150px;">Actions</th>
                                    <th>S.No</th>
                                    <th style="min-width:150px;">Expenses Name</th>
                                    <th style="min-width:150px;">Expenses Category</th>
                                    <th style="min-width:100px;">Date</th>
                                    <th style="min-width:100px;">Amount</th>
                                    <th style="min-width:150px;">Payment Type</th>
                                    <th style="min-width:150px;">Reference</th>
                                    <th style="min-width:150px;">Notes</th>
                                    <th style="min-width:100px;">Created&nbsp;By</th>
                                    <th style="min-width:100px;">Updated&nbsp;By</th>
                                    <th style="min-width:150px;">Created At</th>
                                    <th style="min-width:150px;">Updated At</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="13" class="dataTables_empty"><center> Loading Pls Wait Data</center></td>
                                </tr>
                            </tbody>
                            
                        </table>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
<?php }else{ ?>

<?=$page_not_access?>

<?php } ?>
</section>

<?php include "footer.php";?>
<script>
    $(document).ready(function(){
       /* $('#filter').hide();*/
        $('.filter').click(function(){
            $("#filter").slideToggle();
            return false;
        });
    });
</script>

<script type="text/javascript">
<?php
$data_table = "var search_table = $('#search_table').val();
              var exp_category = $('#exp_category').val();
              var payment_type = $('#payment_type').val();
              var start_date = $('#start_date').val();
              var end_date = $('#end_date').val();
              
              
            var table = $('#StData').DataTable({

                    'ajax' : { 
                        url: 'data-tables/expenses_data_table.php', 
                        data:{search:search_table, exp_category:exp_category, start_date:start_date, end_date:end_date, payment_type:payment_type}, 
                        type: 'POST'},
                        bFilter: true,
                        bDestroy: true,
                        searching: true,
                    'buttons': [
                    { extend: 'copyHtml5', 'footer': false, exportOptions: { columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'excelHtml5', 'footer': false, exportOptions: { columns: [0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'csvHtml5', 'footer': false, exportOptions: { columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'pdfHtml5', orientation: 'landscape', pageSize: 'A4', 'footer': false,
                    exportOptions: { columns: [ 0, 1, 2, 3, 4, 5, 6, 7, 8 ] } },
                    { extend: 'colvis', text: 'Columns'},
                    ]

                });";

?>
    $(document).ready(function() {        
        emp_data();
        function emp_data(){
            <?=$data_table?>
        }
        
        $('#search_table').keyup(function() {  
            emp_data();
            document.getElementById("search_table").focus();
        });
        
        $('#exp_category, #start_date, #end_date, #payment_type').change(function() {
            emp_data();
        });

    });
    function delete_Details(id){
            var result = confirm("Confirm Want to Hard Delete This Expenses?");
            if (result) {
                    $.ajax({
                    type: 'POST',
                    url: 'api/delete.php',
                    data: {type:'expenses_delete',delete_id:id},                  
                    success: function(response) {
                        console.log(response); 
                        emp_datas();
                    }
                });
            }
    }

    function emp_datas(){
            <?=$data_table?>
    }
</script>