<?php 
session_start();
require_once 'config.php';
require_once 'auth.php';
$MainPage="Report";
$Page = "OPD-Patient-Report";
?>
<!DOCTYPE html>

<html lang="en" class="default-style">

<head>
    <title><?php echo $Proj_Title; ?></title>

    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="" />
    <meta name="keywords" content="">
    <meta name="author" content="Codedthemes" />
    <?php include_once 'header_script.php'; ?>
    <link rel="stylesheet" href="assets/libs/datatable-buttons/buttons.dataTables.min.css">
</head>

<body>
  
    <!-- [ Layout wrapper ] Start -->
    <div class="layout-wrapper layout-1 layout-without-sidenav">
        <div class="layout-inner">
         
         <?php include 'sidenavi.php'; ?>

<div class="layout-container">
                 <div class="layout-content">

                    <!-- [ content ] Start -->
                    <div class="container-fluid flex-grow-1 container-p-y">
                     
<h4 class="font-weight-bold py-3 mb-0">OPD Patient Report</h4>
<div class="card mb-4">
<div class="card-body">
<div id="alert_message"></div>
<form id="validation-form" method="post" enctype="multipart/form-data" action="">
<div class="form-row">
<div class="form-group col-md-4">
<label class="form-label">Type</label>
<select class="form-control" style="width: 100%" name="Type" id="Type" >
    <option value="" selected="">All</option>
     
    <option <?php if($_REQUEST['Type'] == 1){?> selected <?php } ?> value="1">OPD</option>
    <option <?php if($_REQUEST['Type'] == 2){?> selected <?php } ?> value="2">OPD Receipt</option>
                               
  </select>
<div class="clearfix"></div>
</div>
<div class="form-group col-md-3">
<label class="form-label">From Date </label>
<input type="date" name="FromDate" id="FromDate" class="form-control" value="<?php echo $_POST['FromDate'] ?>" autocomplete="off" required>
</div>
<div class="form-group col-md-3">
<label class="form-label">To Date</label>
<input type="date" name="ToDate" id="ToDate" class="form-control" value="<?php echo $_POST['ToDate'] ?>" autocomplete="off" required>
</div>
<input type="hidden" name="Search" value="Search">
<div class="form-group col-md-2" style="padding-top:20px;">
<button type="button" name="submit" class="btn btn-primary btn-finish" onclick="patientReport()">Search</button>
</div>
</div>

</form>
</div>
</div>
                        <div class="row">
                            <!-- customar project  start -->
                            <div class="col-xl-12">
                                <div class="card">
                                    <div class="card-body">
                                        
                                      


  
                                    </div>
                                </div>
                            </div>
                            <!-- customar project  end -->
                        </div>
                    </div>
                    <!-- [ content ] End -->
                    <!-- [ Layout footer ] Start -->
                   <?php include 'footer.php'; ?>
                    <!-- [ Layout footer ] End -->
                </div>

                
                <!-- [ Layout content ] Start -->
            </div>
            <!-- [ Layout container ] End -->
        </div>
        <!-- Overlay -->
        <div class="layout-overlay layout-sidenav-toggle"></div>
    </div>


    <!-- [ Layout wrapper] End -->



<?php include_once 'footer_script.php'; ?>


   <script type="text/javascript">
 function patientReport(){
    var Type = $('#Type').val();
    var FromDate = $('#FromDate').val();
    var ToDate = $('#ToDate').val();
        setTimeout(function() {
            window.open(
              'view-opd-patient-report.php?Type='+Type+'&FromDate='+FromDate+"&ToDate="+ToDate, 'deletedPatients',
               'toolbar=1, scrollbars=1, location=1,statusbar=0, menubar=1, resizable=1, width=1500, height=1000'
           );
     }, 1);
    
 }
    $(document).ready(function() {
    $('#example').DataTable({
      
        "scrollX": true,
        dom: 'Bfrtip',
        buttons: [
            
            'excelHtml5'
           
        ]
    });
});
</script>

<script type="text/javascript">
    function isNumberKey(evt){ 
    var charCode = (evt.which) ? evt.which : evt.keyCode
        if (charCode != 46 && charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
  function getAge(val){
    var dob = new Date(val);  
    //calculate month difference from current date in time  
    var month_diff = Date.now() - dob.getTime();  
      
    //convert the calculated difference in date format  
    var age_dt = new Date(month_diff);   
      
    //extract year from date      
    var year = age_dt.getUTCFullYear();  
      
    //now calculate the age of the user  
    var age = Math.abs(year - 1970);  

    $('#Age').val(age);
    //alert(age);
  }

  $(document).ready(function(){

    $(document).on("change", "#ConsultantId", function(event){
  var val = this.value;
   var action = "getConsultantDetails";
    $.ajax({
    url:"ajax_files/ajax_queue_management.php",
    method:"POST",
    data : {action:action,id:val},
    dataType:"json",  
    success:function(data)
    {
        $('#ConsFees').val(data.Fees);
    }
    });

 });

    $(document).on("change", "#Consultant", function(event){
  var val = this.value;
   var action = "getConsultantDetails";
    $.ajax({
    url:"ajax_files/ajax_queue_management.php",
    method:"POST",
    data : {action:action,id:val},
    dataType:"json",  
    success:function(data)
    {
        $('#Fees').val(data.Fees);
    }
    });

 });

     $(document).on("change", "#PatientId", function(event){
  var val = this.value;
   var action = "getPatientDetails";
    $.ajax({
    url:"ajax_files/ajax_queue_management.php",
    method:"POST",
    data : {action:action,id:val},
    dataType:"json",  
    success:function(data)
    {
        //alert(data);
        $('#MRD_NO').val(data.MrdNo);
        $('#PatientName').val(data.PatientName);
      //$('#PartStateId').html(data);
    }
    });

 });

  $('#add_button').click(function(){
           $('.modal-title').html("Add <span class='font-weight-light'>Patient</span>");  
           $('#id').val('');
            $('#submit').text('Submit');
                     $('#Suffix').val(''); 
                     $('#Fname').val('');  
                     $('#Mname').val('');  
                     $('#Lname').val('');
                     $('#Gender').val(null).attr("selected",true);
                     $('#Dob').val(''); 
                     $('#Age').val('');
                     $('#Phone').val('');  
                     $('#Phone2').val(''); 
                     $('#Address').val(''); 
                     $('#City').val(null).attr("selected",true); 
                     $('#State').val(null).attr("selected",true);  
                     $('#Consultant').val(null).attr("selected",true);
                     $('#Fees').val('');
                     $('#PayMode').val(null).attr("selected",true);
                     $('#RefBy').val('');
          
      }) 

      $(document).on("click", ".update", function(event){
 event.preventDefault();
 event.stopPropagation();
 var id = $(this).attr("data-id");
 var action = "getPatientDetails";
 $.ajax({  
                url:"ajax_files/ajax_queue_management.php",  
                method:"POST",  
                data:{action:action,id:id},  
                dataType:"json",  
                success:function(data){  
                    
                     $('#id').val(data.id);
                     $('#MrdNo').val(data.MrdNo);
                     $('#Suffix').val(data.Suffix); 
                     $('#Fname').val(data.Fname);  
                     $('#Mname').val(data.Mname);  
                     $('#Lname').val(data.Lname);
                     $('#PatientName').val(data.PatientName);
                     $('#Gender').val(data.Gender).attr("selected",true);  ;
                     $('#Dob').val(data.Dob); 
                     $('#Age').val(data.Age);
                     $('#Phone').val(data.Phone);  
                     $('#Phone2').val(data.Phone2); 
                     $('#Address').val(data.Address); 
                     $('#City').val(data.City).attr("selected",true); 
                     $('#State').val(data.State).attr("selected",true);  
                     $('#Consultant').val(data.Consultant).attr("selected",true);
                     $('#Fees').val(data.Fees);
                     $('#PayMode').val(data.PayMode).attr("selected",true);
                     $('#RefBy').val(data.RefBy);
                     $('#Diagnosis').val(data.Diagnosis);
                
                     //$('#action').val('EditQueue'); 
                       $('#submit').text("Update");   
                       $('.insert_frm').modal('show');
                       $('.modal-title').html("Update <span class='font-weight-light'>Patient</span>"); 
                     
                }  
           });
});


       $(document).on("click", ".delete", function(event){
 event.preventDefault();
 var id = $(this).attr("data-id");
 var action = "delete";
 var ConsultantId = $('#ConsultantId').val();
 var FromDate = $('#FromDate').val();
 var ToDate = $('#ToDate').val();
 //alert(id);
   swal({
            title: "Are you sure?",
            text: "You will not be able to recover this Queue Record!",
            type: "warning",
            showCancelButton: true,
            confirmButtonClass: "btn-danger",
            confirmButtonText: "Yes, delete",
            cancelButtonText: "No, cancel",
            closeOnConfirm: false,
            closeOnCancel: false
        }, function(isConfirm) {
            if (isConfirm) {
                 $.ajax({  
                url:"ajax_files/ajax_queue_management.php",  
                method:"POST",  
                data:{action:action,id:id},  
               
                success:function(data){
              swal("Deleted!", "Record has been deleted.", "success");
              window.location.href="opd-patient-report.php?ConsultantId="+ConsultantId+"&FromDate="+FromDate+"&ToDate="+ToDate;
             
              

                     }  
           });
                
            } else {
                swal("Cancelled", "Record is safe :)", "error");
            }
        });

           
 });

      });
</script>
</body>

</html>
