<?php 
include "config.php";
error_reporting(0);

?>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">

<link rel="stylesheet" href="th.css">
<script src="datatable/data.js" type="text/javascript"></script>
<script src="datatable/table.js" type="text/javascript"></script>
<script src="datatable/datatable.js"></script>
<link rel="stylesheet" href="datatable/data-boot.css">
<link href="javascript/select2.css" rel="stylesheet" >
<script src="javascript/selectt2.js"></script>
<style>
    
    #navbar
    {
        flex:15%;
        height:100%; 
        flex-direction:row;
        overflow:auto;
        
    }
    #content
    {
        flex:90%;
        overflow:auto;
        padding-left:10px;
        padding-right:10px;
    }
    #fullbody
    {
        display:flex;
        
         height:100%;         
    }
    label
    {
      font-size:20px;
    }
    .edit
    {
        font-size:18px;
        color:green;
        cursor:pointer;
    }
    .dele
    {
        font-size:18px;
        color:red;
        cursor:pointer;
    }
    .edit:hover
    {
        font-size:20px;
        
    }
    .dele:hover
    {
        font-size:20px;
        color:red;
        cursor:pointer;
        
    }
    td
    {
      text-align:center;
    }
    th
    {
      text-align:center;
    }
    .row input
    {
      height:30px;
    }
    .row select
    {
      height:35px;
    }
    .required
    {
        width:100%;
    }
    @media (max-width: 800px) {
        #fullbody
    {
        display:flex;
        flex-wrap: wrap;
                 
    }
        #navbar,#content {
    flex: 100%;
  }
}
</style>
<script>
$(document).ready( function () {
    $('#protable').DataTable();
} );
</script>
</head>
<body>
    
    <div id="fullbody"> 
<div id="navbar" class="bg-info"><?php include "navbar.php"?></div>
<div id="content">
<br>
<h3> Manage Advance</h3>
<br>
<?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='advanceentry'");
while($per=mysqli_fetch_array($usper))
{
          ?>
          <?php if($per['dataadd'] =='1'){ ?>
<input type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal" style="float:right;margin-right:0px;" value="+ Add"><?php }?>
<br><br>
<!-- table -->
<div>
<table class="table table-bordered table-hover " style="border:1px solid lightgrey" id="protable">
    <thead >
<tr>
  <th>Sno</th>
    <th>Code</th>
    <th>Name</th>
    <th>Cash</th>
    <th>Remarks</th>
    <?php if($per['dataedit'] =='1'){ ?><th>Edit</th><?php }?>
    
</tr>

    </thead>
    <tbody>
    <?php 
$advance=mysqli_query($connect,"select *,(select name from customerdetails where customerdetails.code=advance.customer && status!='deleted')as customername from advance where status!='deleted' order by concat(date,time) desc");
$sno=0;
while($advance_dis = mysqli_fetch_array($advance))
{
    $sno+=1;
?>


        <tr>
          <td><?php echo $sno ?></td>
        <td><?php echo $advance_dis['code'] ?></td>
    <td><?php echo $advance_dis['customername'] ?></td>
    <td><?php echo $advance_dis['advance'] ?></td>
    <td><?php echo $advance_dis['remark'] ?></td>
    <?php if($per['dataedit'] =='1'){ ?>  <td><a href="edit_advance.php?code=<?php echo $advance_dis['code'] ?>"><i class="fas fa-edit edit"></i></a></td><?php }?>
   
        </tr>
        <?php }}?>
    </tbody>



</table>

</div>
<!-- modal -->
<div class="modal fade" id="myModal">
    <div class="modal-dialog modal-dialog-centered modal-xl">
      <div class="modal-content">
      
        <!-- Modal Header -->
        <div class="modal-header">
          <h4 class="modal-title">Add Advance</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
            <!--  -->
            <form action="insertadvance.php" method="post">
              <!--  -->
              <?php
            $adv_count = mysqli_query($connect,"select count(code)as code from advance where advance.status !='deleted'");
        while($dis_count = mysqli_fetch_array($adv_count))
        {
            $advance_code = $dis_count['code']+1;
                     
		}
        
        ?>
              <div class="row">
                  <div class="col-sm-1"></div>
                  <div class="col-sm-2"><label>Code</label></div>
                  <div class="col-sm-3"><input type="text" class="required" name="code" value="<?php echo "ADV-".$advance_code ?>" placeholder="Enter Code" readonly></div>
              </div><br>
              <div class="row">
                  <div class="col-sm-1"></div>
                  <div class="col-sm-2"><label>Date</label></div>
                  <div class="col-sm-3"><input type="date" class="required" placeholder="Enter Date" name="date"></div>
              </div><br>
              <div class="row">
                  <div class="col-sm-1"></div>
                  <div class="col-sm-2"><label>Customer</label></div>
                  <div class="col-sm-3"><select class="form-control selectpro" id="customerAdd" name="customer" required><br>
              <option value="">--Select Customer--</option>
              <?php 
$cus=mysqli_query($connect,"select * from customerdetails where status !='deleted'");
while($cusshow = mysqli_fetch_array($cus))
{
?>
<option value="<?php echo $cusshow['code'] ?>"><?php  echo $cusshow['name'] ?></option>
        <?php }?>          
  
              </select></div>
              </div><br>
              <div class="row">
                  <div class="col-sm-1"></div>
                  <div class="col-sm-2"><label>Advance</label></div>
                  <div class="col-sm-3"><input type="text" class="required" placeholder="Enter Advance" name="advance"></div>
              </div><br>
              <div class="row">
                  <div class="col-sm-1"></div>
                  <div class="col-sm-2"><label>Remark</label></div>
                  <div class="col-sm-3"><textarea class="required" placeholder="Enter Remarks" name="remark"></textarea></div>
              </div><br>
        <!-- Modal footer -->
        <div class="modal-footer">
        <input type="button"  class="btn btn-success" id="ValidationButton" value="Add" >
        <input type="hidden"  class="btn btn-success" id="submitButton" data-toggle="modal" data-target="#addpro" value="Add" >
        </div>
        <!-- modal for add -->
<div class="modal fade" id="addpro">
    <div class="modal-dialog modal-sm">
      <div class="modal-content" style="background-color:rgba(77, 219, 106,0.9)">
      
        <!-- Modal Header -->
        
        
        <!-- Modal body -->
        <div class="modal-body">
          <span style="color:white"><i class="fas fa-check" style="font-size:24px"></i> Advance Have Been Created Successfully</span>
        </div>
        
        <!-- Modal footer -->
        <div class="modal-footer">
          <button type="submit" type="button" class="btn btn-warning" >Ok</button>
        </div>
        
      </div>
    </div>
  </div>
  
<!-- modal for add -->
      </div>
    </div>
  </div>
        </form>
        
<!-- modal -->


<!-- main-content-div -->
</div>
<!-- main-content-div -->
</div>
<script src="restriction/advance.js"></script>
<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
</body>