<?php 
if(!isset($_SESSION)) { 
  session_start(); 
  include('../includes/dbcon.php');
}
if(empty($_SESSION['hrm_id'])):
header('Location:../index.php');
endif;


//$bank= trim($_POST['bank']);
//$tdate= trim($_POST['tdate']);

$bank = isset($_POST['bank']) ? trim($_POST['bank']) : '';
$tdate = isset($_POST['tdate']) ? trim($_POST['tdate']) : '';


if (!empty($bank) && !empty($tdate)) {

   // echo "Data received: Bank - $bank, Date - $tdate";
} else {
    
if(isset($_REQUEST['docid']))

  {
 
    $rid=$_GET['docid'];
    $stringParts = explode("*", $rid);
    $docid  = $stringParts[0];
    $loc_status= $stringParts[1];
    $tdate= $stringParts[2];

    //echo $loc_status;
    $bank= $loc_status;
    //if ($loc_status=="No"){
     // $cval=1;
    //}
   

//$ll=" update chqheader set deposit=1,
                      // dep_bank=$bank,
                       //dep_date=$tdate
    // where docid='$docid'";
     //echo $ll;

    mysqli_query($con,"update chqheader set deposit=1,
                       dep_bank=$bank,
                       dep_date='$tdate'
     where docid='$docid' ")or die(mysqli_error());
}



}


  $querydoc=mysqli_query($con,"select acc_name from account_master where acc_id=$bank ")or die(mysqli_error());

   while($row=mysqli_fetch_array($querydoc)){  

  $acc_name=$row['acc_name'];       

      

}

///////////////////////  Deposit Section ////////////////





/////////////////////// End of deposit section ////////////////////////


?>
<!DOCTYPE html>
<html lang="en">


<head>
  <!-- Required meta tags -->
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  <title>SalesHub | Cheque Deposit </title>
  <!-- plugins:css -->
  <?php include('../includes/commonheader.php');?>

</head>
<body>
 <?php include('../includes/header.php');?>
 <?php include('../includes/leftsidebar.php');?>
           <!-- partial -->
 <div class="main-panel">        
        <div class="content-wrapper">      
           


     <div class="col-22 grid-margin">
              <div class="card">
                <div class="card-body">
              
          <!--                
    <form class="needs-validation" novalidate method="post" action="receipt_new_add.php" enctype="multipart/form-data" onsubmit="return validateForm()">    --->               
                    <div class="row">                     
                      <div class="col-md-4">
                        <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Bank: </label>
                          <div class="col-sm-18">
                            <input type="text" class="form-control" id="rno" name="rno" value=<?php echo $acc_name ; ?> >
                            
                          </div>
                        </div>
                          </div>

<div class="col-md-4">                  
                          <div class="form-group row">
                          <label class="col-sm-3 col-form-label">Date </label>
                          <div class="col-sm-9">
                          <input type="date" class="form-control" name="cdate" value= <?php echo $tdate;?> >
                          </div> 

                          </div>  

                      </div>            



                        </div>
                    </div>
                </div>

         <div class="col-12 grid-margin">
              <div class="card">
                <div class="card-body">
                     Pending Deposits
<div class="table-responsive">
                    <table id="order-listing" class="table">
                       <thead>
  <tr class="bg-primary text-white">
   
    <th width="7%">#</th>
    <th width="10%">Receipt</th>
    <th width="10%">Date</th>
    <th width="10%">Chq No</th>
    <th width="10%">Chq Date</th> 
     <th width="4%">Chq Bank</th> 
    <th width="25%">Customer</th> 
    <th width="10%">Amount</th> 
    <th width="25%">Deposit</th>    

   
    </tr>
  </thead>
<tbody>
<?php
$rcount=0;

//echo$tt;

$sql="SELECT chqheader.docid,chqheader.docdate,chqheader.chqno,chqheader.amount ,chqheader.chqdate,
chqheader.chqbank,customer_master.cus_name,chqheader.deposit
FROM chqheader
LEFT JOIN customer_master ON chqheader.cus_id=customer_master.cus_id
WHERE deposit<>1 AND TYPE='Cheque' AND cancel<>1"  ;

$query=mysqli_query($con,$sql)or die(mysqli_error()); 

              while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
                $docid=$row['docid']; 
                $docdate=$row['docdate']; 
                $chqno=$row['chqno']; 
                $amount=$row['amount'];
                $chqdate=$row['chqdate'];
                $chqbank=$row['chqbank'];
                $cus_name=$row['cus_name']; 
                $deposit =$row['deposit'];  
                if ($deposit==1) {
                    $locactive="Yes";
                }
             
                if ($deposit==0) {
                    $locactive="No";
                }            
              ?>   

            <tr>       
            <td> <?php echo $rcount;   ?></td>
            <td> <?php echo $docid;   ?></td>   
             <td> <?php echo  $docdate;   ?></td>         
            <td><?php echo $chqno; ?></td>
             <td> <?php echo  $chqdate;   ?></td>  
               <td> <?php echo  $chqbank;   ?></td>  
              <td> <?php echo $cus_name;   ?></td>
            <td> <?php echo $amount;   ?></td>
           
           
           
   <td><?php if ($row['deposit']>0) { ?> &#10004;<?php } else { ?> &#10006; <?php } ?><a href="deposit_chq_new.php?docid=<?php echo $row['docid'];echo "*";echo $bank;echo "*";echo $tdate;?>"> Change</a></td>
            </tr>                
                    <?php }  ?>
                    </tbody>
                    </table>
                  </div>
 </div> </div> </div>


<!--------------------------------------------------------->
 <div class="col-12 grid-margin">
              <div class="card">
                <div class="card-body">
                     Deposited
<div class="table-responsive">
                    <table id="order-listing" class="table">
                       <thead>
  <tr class="bg-primary text-white">
   
    <th width="7%">#</th>
    <th width="10%">Receipt</th>
    <th width="10%">Date</th>
    <th width="10%">Chq No</th>
    <th width="10%">Chq Date</th> 
     <th width="4%">Chq Bank</th> 
    <th width="25%">Customer</th> 
    <th width="10%">Amount</th> 
    <th width="25%">Deposit</th>    

   
    </tr>
  </thead>
<tbody>
<?php
$rcount=0;

//echo$tt;

$sql="SELECT chqheader.docid,chqheader.docdate,chqheader.chqno,chqheader.amount ,chqheader.chqdate,
chqheader.chqbank,customer_master.cus_name,chqheader.deposit,
account_master.acc_name
FROM chqheader
LEFT JOIN customer_master ON chqheader.cus_id=customer_master.cus_id
LEFT JOIN account_master ON account_master.acc_id=chqheader.dep_bank
WHERE deposit<>0 AND TYPE='Cheque' AND cancel<>1 AND acc_id=$bank   AND dep_date='$tdate' "  ;

$query=mysqli_query($con,$sql)or die(mysqli_error()); 

              while($row=mysqli_fetch_array($query)){   $rcount=$rcount+1;
                $docid=$row['docid']; 
                $docdate=$row['docdate']; 
                $chqno=$row['chqno']; 
                $amount=$row['amount'];
                $chqdate=$row['chqdate'];
                $chqbank=$row['chqbank'];
                $cus_name=$row['cus_name']; 
                $deposit =$row['deposit'];  
                if ($deposit==1) {
                    $locactive="Yes";
                }
             
                if ($deposit==0) {
                    $locactive="No";
                }            
              ?>   

            <tr>       
            <td> <?php echo $rcount;   ?></td>
            <td> <?php echo $docid;   ?></td>   
             <td> <?php echo  $docdate;   ?></td>         
            <td><?php echo $chqno; ?></td>
             <td> <?php echo  $chqdate;   ?></td>  
               <td> <?php echo  $chqbank;   ?></td>  
              <td> <?php echo $cus_name;   ?></td>
            <td> <?php echo $amount;   ?></td>
             <td> <?php echo $locactive;   ?></td>
           
           
           
  
            </tr>                
                    <?php }  ?>
                    </tbody>
                    </table>
                  </div>
 </div> </div> </div>





        </div>  <!----- <div class="content-wrapper">------>
  </div>

 </div><!-----End of main panel--~~~~~~~~~~~~~~~~~~~~~~~--------------->
 </div><!-----Dont Delete this DIV--~~~~~~~~~~~~~~~~~~~~~~~--------------->
  <!-- container-scroller -->
<?php include('../includes/footer.php');?>
<?php include('../includes/commonjs.php');?>
 
</body>


</html>

<script>
    $( document ).ready(function() {
         // alert("Please Select Order Type");

    });



</script>

 <!-- End custom js for this page-->
  <script>
  $(function () {
    //Initialize Select2 Elements
    $('.select2').select2()

    //Initialize Select2 Elements
    $('.select2bs4').select2({
      theme: 'bootstrap4'
    })
  })

</script>



