<?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" || $allPermissions["products"]["read"]==1){ ?>
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary">
                <div class="box-header">

            
        <?php if($session_id=="1" || $allPermissions["products"]["create"]==1){ ?> 
                <a  href="products-add.php" class="btn btn-success btn-sm pull-right"><i class="fa fa-plus-circle"></i> Add New Products</a>
        <?php } ?>
        <span class="btn btn-default btn-sm pull-right filter" style="margin-right: 5px;"> Show/Hide Filter</span>
        
        
                    <h3 class="box-title">Products List</h3>
                </div>
                <div class="box-body">
                    
                    
<div class="row" id="filter">
    
    <div class="col-sm-3" hidden>
        <div class="form-group">
            <label class="control-label" for="status">Status</label>
            <select name="status" class="form-control select2" style="width:100%" id="status">
                <option value="1">Active</option>
                <option value="0">In-Active</option>
                <option value="">All Status</option>
            </select>
        </div>
    </div>
    
    <div class="col-sm-3">
        <div class="form-group">
            <label class="control-label" for="product_type">Product Type</label>
            <select name="product_type" class="form-control select2" style="width:100%" id="product_type">
                <option value="">All Types</option>
                <option value="1">Plain</option>
                <option value="2">Stone</option>
            </select>
        </div>
    </div>
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="required" for="category_id">Category</label>                                   
            <select name="category_id" class="form-control select2" style="width:100%" id="category_id" required="required">
                <option value="">All Category</option>
                <?php $statement = $pdo->prepare("SELECT * FROM `tbl_category` where status=1");
                    $statement->execute();
                    $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); 
                    foreach ($location_result as $result) { ?>
                        <option value="<?=$result['id']?>"><?=$result['name']?></option>
                <?php  }  ?>
            </select>
        </div>
    </div>
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="required" for="purity_id">Purity</label>                                   
            <select name="purity_id" class="form-control select2" style="width:100%" id="purity_id" required="required">
                <option value="">All Purity</option>
                <?php $statement = $pdo->prepare("SELECT p.*,tbl_ids_products.name as product_name FROM `tbl_ids_purity` p
                                    LEFT JOIN tbl_ids_products ON tbl_ids_products.id=p.product_ids WHERE p.status=1");
                    $statement->execute();
                    $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); 
                    foreach ($location_result as $result) { ?>
                        <option value="<?=$result['id']?>"><?=$result['name']?> - <?=$result['product_name']?></option>
                <?php  }  ?>
            </select>
        </div>
    </div>
    

    
    <div class="col-sm-3">
        <div class="form-group">
            <label class="control-label" for="stock_quantity">Stock Quantity</label>
            <select name="stock_quantity" class="form-control select2" style="width:100%" id="stock_quantity">
                <option value="1">Stock Quantity</option>
                <option value="2">Saled Quantity</option>
                <option value="">All Status</option>
            </select>
        </div>
    </div>
    
    
    <div class="col-md-3">
        <div class="form-group">
            <label class="required" for="location_id">Locations</label>                                   
            <select name="location_id" class="form-control select2" style="width:100%" id="location_id" required="required">
                <option value="">All Locations</option>
                <?php 
                    $statement = $pdo->prepare("SELECT bb.* FROM `tbl_business_branch` bb WHERE bb.status=1 $branch_conditions");
                    $statement->execute();
                    $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); 
                    foreach ($location_result as $result) { ?>
                        <option value="<?=$result['id']?>"><?=$result['location_name']?></option>
                <?php  }  ?>
            </select>
        </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="20" class="p0"><input type="text" class="form-control b0" name="search_table" id="search_table"  placeholder="Search Here" style="width:100%;background-color: darkblue;color: white;"></td>
                                </tr>
                                <tr class="active">
                                    <th style="min-width:150px !important;">&nbsp;&nbsp;&nbsp;&nbsp;Actions&nbsp;&nbsp;&nbsp;&nbsp;</th>
                                    <th>S.No</th>
                                    <th style="min-width:150px;">Product&nbsp;Name</th>
                                    <th style="min-width:80px;">Product&nbsp;HSN</th>
                                    <th>Quantity</th>
                                    <th>Product&nbsp;Type</th>
                                    <th style="min-width:250px;">Category&nbsp;-&nbsp;Sub&nbsp;Category</th>
                                    <th style="min-width:250px;">Location&nbsp;Details</th>
                                    <th style="min-width:70px !important;">Cross&nbsp;Wt</th>
                                    <th style="min-width:70px;">Stone&nbsp;Wt</th>
                                    <th style="min-width:70px;">Net&nbsp;Wt</th>
                                    <th style="min-width:70px;">Tag&nbsp;Wt</th>
                                    <th style="min-width:70px;">Touch</th>
                                    <th style="min-width:150px;">Purchase&nbsp;Price</th>
                                    <th style="min-width:100px;">Purity</th>
                                    <th style="min-width:100px !important;">Wastage</th>
                                    <th style="min-width:120px !important;">Sales Status</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr>
                                    <td colspan="20" 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 status = $('#status').val();
              var product_type = $('#product_type').val();
              var category_id = $('#category_id').val();
              var purity_id = $('#purity_id').val();
              var stock_quantity = $('#stock_quantity').val();
              var location_id = $('#location_id').val();
              
              
              
            var table = $('#StData').DataTable({

                    'ajax' : { 
                        url: 'data-tables/products-data-table.php', 
                        data:{search:search_table, status:status, product_type:product_type, category_id:category_id, purity_id:purity_id, stock_quantity:stock_quantity, location_id:location_id}, 
                        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();
        });
        
        $('#status, #product_type, #category_id, #purity_id, #stock_quantity, #location_id').change(function() {
            emp_data();
        });

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