<?php 

include("db_connection.php");
$Mainclass=new DB_Controller();
$Order_Id = $_REQUEST['Order_Id'];

$total_cond = "Order_No ='".$Order_Id."'";
$master  = $Mainclass->Fetch_individual_data("gold_billing_order_master","Donation,Round_Off,Payment_Date,Net_Total",$total_cond);
$customer  = $Mainclass->Fetch_individual_data("order_address_master_gold","Salutation,Customer_Name,Contact",$total_cond);
$bill_amount =$master['Net_Total']+$master['Donation']+$master['Round_Off'];


$date2 = strtotime(date('Y-m-d H:i:s')); 
$date1 = strtotime($master['Payment_Date']);  
  
// Formulate the Difference between two dates 
$diff = abs($date2 - $date1);  
  
  
// To get the year divide the resultant date into 
// total seconds in a year (365*60*60*24) 
$years = floor($diff / (365*60*60*24));  
  
  
// To get the month, subtract it with years and 
// divide the resultant date into 
// total seconds in a month (30*60*60*24) 
$months = floor(($diff - $years * 365*60*60*24) 
                               / (30*60*60*24));  
  
  
// To get the day, subtract it with years and  
// months and divide the resultant date into 
// total seconds in a days (60*60*24) 
$days = floor(($diff - $years * 365*60*60*24 -  
             $months*30*60*60*24)/ (60*60*24)); 
  
  
// To get the hour, subtract it with years,  
// months & seconds and divide the resultant 
// date into total seconds in a hours (60*60) 
$hours = floor(($diff - $years * 365*60*60*24  
       - $months*30*60*60*24 - $days*60*60*24) 
                                   / (60*60));  
  
  
// To get the minutes, subtract it with years, 
// months, seconds and hours and divide the  
// resultant date into total seconds i.e. 60 
$minutes = floor(($diff - $years * 365*60*60*24  
         - $months*30*60*60*24 - $days*60*60*24  
                          - $hours*60*60)/ 60);  
  
  
// To get the minutes, subtract it with years, 
// months, seconds, hours and minutes  
$seconds = floor(($diff - $years * 365*60*60*24  
         - $months*30*60*60*24 - $days*60*60*24 
                - $hours*60*60 - $minutes*60));

?>

                <div class="modal-header">
                    <h5 class="modal-title" id="cancelBillModalLabel">Cancel Bill</h5>
                    <button type="button" class="close close-btn" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form>
                        <div class="form-group">
                            <label for="customerNameStatic">Customer Name :</label> <?php echo $customer['Salutation']; ?>  <?php echo $customer['Customer_Name']; ?>
                          
                            
                        </div>
                        <div class="form-group">
                            <label for="billDateStatic">Date :</label> <?php echo date('d-M-Y',strtotime($master['Payment_Date'])); ?>
                 
                            
                        </div>
                        <div class="form-group">
                            <label for="billAmountStatic">Bill Amount(In Rs.) :</label> <?php echo number_format($bill_amount,2);?>
                         
                        </div>
                        <div class="form-group">
                            <label for="cancellationReason">Cancellation Reason</label>
                            <textarea class="form-control" id="cancellationReason" rows="4" placeholder="Enter reason for cancellation" ></textarea>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <?php 
                    
                    if($days==0 && $hours==0 && $minutes<=30) {
                        
                    ?>
                    <button type="button" class="btn btn-secondary close-btn" data-dismiss="modal">Close</button>
                    <button type="button" class="btn btn-danger" onclick="cancel_bill('<?php echo $Order_Id ;?>')">Submit Cancellation</button>

                    <?php 
                    
                } 
                    else {

                    ?>

                    <div class="text text-danger text-center" style="text-align:center;">Bill Cancellation Time has Expired.</div>
                     
                    <?php  

                    }
                    ?>
                </div>