<?php
session_start();
include "../config/config.php";
$id = $_GET['id'];
?>

<?php
    $statement = $pdo->prepare("SELECT *,(SELECT name FROM tbl_users WHERE tbl_users.id=e.created_by) as created_user_name FROM `tbl_payment` e where e.id=".$id);
    $statement->execute();
    $emp_data = $statement->fetchAll(PDO::FETCH_ASSOC);
    $totalData = $statement->rowCount();
    if($totalData==1){
        foreach($emp_data as $data){
            $amount = $data['amount'];
            $date = date("d-m-Y", strtotime($data['payment_date']));
            $created_user_name = $data['created_user_name'];
            $created_at = date("d-m-Y h:i A", strtotime($data['created_at']));
            $verified_status = $data['verified_status'];
            
            if($data['verified_status']==1){
                $status = "Pending";
            }else if($data['verified_status']==2){
                $status = "Accepted";
            }else if($data['verified_status']==3){
                $status = "Rejected";
            }
            
        }
    }
?>

<div class="modal-dialog" role="document">
    <div class="modal-content">
        <form id="form_details">
      <div class="modal-header">
        <h4 class="modal-title" id="exampleModalLabel">Update Payments</h4>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true"><i class="fa fa-times" style="margin-top: -23px; font-size: 28px;"></i></span>
        </button>
      </div>
       
           
        <input name="ids" value="<?=$id?>" hidden>
        
           
      <div class="modal-body">
        <div class="row">
            
            
            <div class="col-md-6" style="padding-top: 25px;">
                <label>Payment Amount: <i class='fa fa-inr'></i> <?=$amount?></label>
            </div>
            <div class="col-md-6" style="padding-top: 25px;">
                <label>Payment Date: <?=$date?></label>
            </div>
            
            
            
            <div class="col-md-12" style="padding-top: 8px;">
                <label>Created Users: <?=$created_user_name?></label><br>
                <label>Created Date & Time: <?=$created_at?></label><br>
                <label>Approval Status: <?=$status?></label>
            </div>
            <div class="col-md-12" style="padding-top: 8px;">
                <label>Approval Status</label>
                <select name="approval_status" class="form-control select2" id="approval_status" style="width: 100%;">
                    <option value="2" <?php if($verified_status==1){echo "selected";}?>>Accepted</option>
                    <option value="3" <?php if($verified_status==2){echo "selected";}?>>Rejected</option>
                </select>
            </div>
            
            
            
            <!--<div class="col-md-12" style="padding-top: 8px;">
                <label>Reference</label>
                <input type="text" name="reference"  placeholder="Reference No" class="form-control"  id="reference" />
            </div>
            <div class="col-md-12" style="padding-top: 8px;">
                <label>Notes</label>
                <textarea name="notes" id="notes" placeholder="Notes" rows="4" class="form-control"></textarea>
            </div>-->
            
        </div>
      </div>
      
      
      
      <div class="modal-footer">
        <button type="button" class="btn btn-danger pull-left" data-dismiss="modal"><i class="fa fa-times"></i> Close</button>
        <button type="submit" class="btn btn-success" id="submit"><i class="fa fa-save"></i> Save</button>
      </div>
       </form>  
    </div>
</div>

<script>
$(document).ready(function(){
    $('#form_details').on('submit', function(e){
        e.preventDefault();
        console.log("Submitted");
                var formData = new FormData(this);
                formData.append('type', 'update_payments_approval');
                    $.ajax({
                            url: 'apis/payments.php',
                            type: 'post',
                            dataType: 'json',
                            data: formData,
                            cache: false,
                            contentType: false,
                            processData: false,
                            enctype: 'multipart/form-data',
                            success: function (response) {
                                if(response['status']==200){
                                     alert(response['message']);
                                     location.reload();
                                     
                                }else{
                                    alert(response['message']);
                                }
                            }
                    });
    });
});
</script>