<?php
include('db_con.php');
include('db_coni.php');
if (isset($_SESSION['user_id'])) {
        $user_type = $_SESSION['user_type'];
        $user_id = $_SESSION['user_id'];
        $user_name = $_SESSION['user_name'];
        $branch_id = $_SESSION['branch_id'];
        $branch_name = $_SESSION['branch_name'];
        $store_id = $_SESSION['store_id'];
        $store_name = $_SESSION['store_name'];
}else{
    header('Location: login');
    die();
}
$sql = "SELECT doc_status FROM user_rights WHERE user_id = '".$user_id."' and doc_name = 'jv'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $jv = $statement->fetchColumn();
            if($jv=='OFF'){header('Location: dashboard');}
$sql = "SELECT doc_status FROM user_rights WHERE user_id = '".$user_id."' and doc_name = 'jv_new'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $jv_new = $statement->fetchColumn();
$sql = "SELECT doc_status FROM user_rights WHERE user_id = '".$user_id."' and doc_name = 'jv_edit'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $jv_edit = $statement->fetchColumn();
            $sql = "SELECT doc_status FROM user_rights WHERE user_id = '".$user_id."' and doc_name = 'jv_delete'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $jv_delete = $statement->fetchColumn();
             $sql = "SELECT doc_status FROM user_rights WHERE user_id = '".$user_id."' and doc_name = 'jv_print'";
            $statement = $connect->prepare($sql);
            $statement->execute(); // no need to add `$sql` here, you can take that out
            $jv_print = $statement->fetchColumn();
$acc_name = '';
$dated = date('Y-m-d');
$query = "SELECT * FROM accounts WHERE status = 'Active' ORDER BY acc_name ASC";
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
foreach($result as $row)
{
 $acc_name .= '<option value="'.$row['acc_no'].'">'.$row['acc_name'].'</option>';
 
}
?>
<!DOCTYPE html>
<html>
<head>
  <?php include('include/head.php'); ?>
  
</head>
<body>
  <?php include('include/header.php'); ?>
  <?php include('include/sidebar.php'); ?>
<div class="main-container">
  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <div class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1 class="m-0 text-dark"></h1>
          </div><!-- /.col -->
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="#">GL</a></li>
              <li class="breadcrumb-item active">JVs </li>
            </ol>
          </div><!-- /.col -->
        </div><!-- /.row -->
      </div><!-- /.container-fluid -->
    </div>
    <!-- /.content-header -->
    <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- Small boxes (Stat box) -->
     <span id="alert_action"></span>
    <div class="row">
        <div class="col-12">
          <div class="card">
            <div class="card-header">
            <div class="row">
                          <div class="col-lg-10 col-md-10 col-sm-8 col-xs-6">
                              <h3 class="panel-title">JVs</h3>
                            </div>
                            <div class="col-lg-2 col-md-2 col-sm-4 col-xs-6" align="right">
                               <?php if($jv_new=='ON')
                            {
                               echo ' <a href="jv_new?add=1" class="btn btn-primary"><i class="fa fa-plus"></i> New Jv</a>';
                            }
                            ?>
                          </div>
                        </div>
            </div>
            <!-- /.card-header -->
            <div class="card-body">
              
                        <table width="100%" id="_dataTable" class="table table-bordered table-striped table-hover">
                          <thead>
                  <tr>
                    <th width="5%">ID</th>                    
                    <th width="10%">Date</th>
                     <th width="7%">No.</th>
                    <th width="10%">Source</th>
                    <th width="30%">Description</th>
                    <th width="20%">Created</th>
                    
                   
                                      
                  <?php if($jv_edit=='ON')
                  {
                    echo ' <th width="5%">Edit</th>';
                  
                  }
                  ?>
                  <?php if($jv_print=='ON')
                  {
                    echo '  <th width="5%">Print</th>';
                   
                  
                  }
                  ?>
                   <?php if($jv_delete=='ON')
                  {
                    echo '  <th width="5%">Delete</th>';
                   
                  
                  }
                  ?>
                  </tr>
                </thead>
                        </table>
                </div>
              </div>
          </div>
      </div>
             
        
        
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->
 
  <!-- /.content-wrapper -->
 
    </div>
    </div>
  <?php include('include/script.php'); ?>
  
</body>
</html>
 
<script>
$(document).ready(function(){
  
  var _dataTable = $('#_dataTable').DataTable({
    "processing": true,
    "serverSide": true,
    "order": [],
    "ajax":{
      url:"jv_fetch.php",
      type:"POST"
    },
    "columnDefs":[
      {
        "target":[2,3,4],
        "orderable":false
      }
    ],
    "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],
        "language": {
          "info": "_START_-_END_ of _TOTAL_ entries",
          searchPlaceholder: "Search"
        },
        dom: 'Bfrtip',
        buttons: [
        'copy', 'csv', 'pdf', 'print'
        ],
        "pageLength": 25
  });
  $(document).on('click', '.delete', function(){
    var jv_id = $(this).attr("id");
    
    var btn_action = "delete";
    if(confirm("Are you sure you want delete it permanently?"))
    {
      $.ajax({
        url:"jv_action.php",
        method:"POST",
        data:{jv_id:jv_id, btn_action:btn_action},
        success:function(data)
        {
          $('#alert_action').fadeIn().html('<div class="alert alert-info">'+data+'</div>');
          _dataTable.ajax.reload();
        }
      })
    }
    else
    {
      return false;
    }
  });
  
 
  
});
    
</script>
