<?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>
<link rel="stylesheet" href="tablehead.css">
<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;
    }
    input[type="date"],input[type="text"]
{
    width:100%;
}
    .payment-radio
    {
        height:20px;
        width:20px;
    }
    .requiredvalue
{
    border-color: red;
}
    @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 ><?php include "navbar.php"?></div>
    <div id="fullbody"> 

<div id="content">
<br>
<h3> Manage Cash</h3>
<br>
<?php 
        $userall=$_SESSION['log'];
        $usper = mysqli_query($connect,"select * from userpermission where username = '$userall'  && filename='creditdetails'");
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>Date</th>
	 <th>Expense</th>
	 
    <th>Collected By</th>
    <th>Given By</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 * from cash_expense 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['date'] ?></td>
		 <td><?php echo $advance_dis['expense_name'] ?></td>
		 
    <td><?php echo $advance_dis['givento'] ?></td>
    <td><?php echo $advance_dis['givenby'] ?></td>
    <td><?php echo $advance_dis['given_amount'] ?></td>
  
    <td><?php echo $advance_dis['remark'] ?></td>
    <?php if($per['dataedit'] =='1'){ ?>  <td><a href="edit_exp_handling.php?code=<?php echo $advance_dis['code'] ?>"><i class="fas fa-edit edit"></i><?php } ?></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">Cash Handling</h4>
          <button type="button" class="close" data-dismiss="modal">&times;</button>
        </div>
        
        <!-- Modal body -->
        <div class="modal-body">
            <!--  -->
            <form action="insert_cashexpense.php" method="post">
              <!--  -->
              <?php
              include "financial_year_calculation.php";
            $adv_count = mysqli_query($connect,"select count(code)as code from cash_expense where status !='deleted'");
        while($dis_count = mysqli_fetch_array($adv_count))
        {
            $advance_code = $dis_count['code']+1;
            $year_code = substr($financialYearEnd,2);
		}
		
		 $givenamount = mysqli_query($connect,"select sum(given_amount)as receivedamount from cash_handling where status !='deleted' and givento='Office Expence'");
		 $ramount=mysqli_fetch_assoc($givenamount);
		 
		 $expamount = mysqli_query($connect,"select sum(given_amount)as expamount from cash_expense where status !='deleted'");
		 $eamount=mysqli_fetch_assoc($expamount);
		 $avail=$ramount['receivedamount']-$eamount['expamount'];
		 
        
        ?>
              <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 'CEXP'.$year_code.'-'.$advance_code ?>" placeholder="Enter Code" readonly></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>Available Balance</label></div>
                  <div class="col-sm-3"><input type="text" class="required" placeholder="Enter Date" name="avail_cash" value="<?php echo number_format($avail,2,'.','');?>" readonly></div>
                  <div class="col-sm-2"><label>Expense</label></div>
                  <div class="col-sm-3">
                  <select type="text" class="required"  name="expense_name" id="expense_name" >
                  <option value="">Select Option</option>
                  <?php
				  $sqlexpname=mysqli_query($connect,"select * from expensemaster where status!='deleted'");
				  while($rowexp=mysqli_fetch_array($sqlexpname))
				  {
				  ?>
                  <option><?php echo $rowexp['expensename'];?></option>
                   <?php
				   }
				   ?>
                  
                  </select>
                  
</div>
              </div><br>
              <div class="row">
                  <div class="col-sm-1"></div>
                  
                  <div class="col-sm-2"><label>Given Amount </label></div>
                  <div class="col-sm-3"><input type="number" class="required" placeholder="Enter Amount" name="given_amount" id="given_amount" ></div>
				  <div class="col-sm-2"><label>Given To</label></div>
                  <div class="col-sm-3">
				  <input type="text" class="required" placeholder="Enter Name" name="givento" id="givento" >
                  
                  
                  
</div>
              </div><br>
              
             
             <div class="row">
                  <div class="col-sm-1"></div>
                 <div class="col-sm-2"><label>Given By</label></div>
                  <div class="col-sm-3"><input type="text" class="required" placeholder="Enter Name" name="givenby" id="givenby" ></div>
                  <div class="col-sm-2"><label>Remark</label></div>
                  <div class="col-sm-3"><input class="required" placeholder="Enter Remarks" name="remark"></div>
              </div><br>
        <!-- Modal footer -->
        <div class="modal-footer">
        <input type="button"  class="btn btn-success" id="ValidationButton" value="Add" >
          <input type="hidden" id="submitButton"  class="btn btn-success" 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> Credit 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>
<!-- alert -->
<button type="button" class="btn btn-primary" id="alertPending" data-toggle="modal" data-target="#pendingLimit" style="display:none">
      </button>
  <!-- The Modal -->
  <div class="modal fade" id="pendingLimit">
    <div class="modal-dialog modal-lg">
     <div class="alert alert-danger alert-dismissible fade show">
    <button type="button" class="close"  data-dismiss="alert">&times;</button>
    <strong>Amount Exceeds</strong>
  </div>
  </div>
  </div>
        
<!-- alert -->
<script>
    $('.selectpro').select2({ width: '100%',height:'420px;' });
    
</script>
<script src="js/credit.js"></script>
<script src="restriction/credit.js"></script>
</body>