
<?php include '../au.com.gateway.client/GatewayClient.php'; ?>
<?php include '../au.com.gateway.client.config/ClientConfig.php'; ?>
<?php include '../au.com.gateway.client.component/RequestHeader.php'; ?>
<?php include '../au.com.gateway.client.component/CreditCard.php'; ?>
<?php include '../au.com.gateway.client.component/TransactionAmount.php'; ?>
<?php include '../au.com.gateway.client.component/Redirect.php'; ?>
<?php include '../au.com.gateway.client.facade/BaseFacade.php'; ?>
<?php include '../au.com.gateway.client.facade/Payment.php'; ?>
<?php include '../au.com.gateway.client.root/PaycorpRequest.php'; ?>
<?php include '../au.com.gateway.client.root/PaycorpResponse.php'; ?>
<?php include '../au.com.gateway.client.payment/PaymentCompleteRequest.php'; ?>
<?php include '../au.com.gateway.client.payment/PaymentCompleteResponse.php'; ?>
<?php include '../au.com.gateway.client.utils/IJsonHelper.php'; ?>
<?php include '../au.com.gateway.client.helpers/PaymentCompleteJsonHelper.php'; ?>
<?php include '../au.com.gateway.client.utils/HmacUtils.php'; ?>
<?php include '../au.com.gateway.client.utils/CommonUtils.php'; ?>
<?php include '../au.com.gateway.client.utils/RestClient.php'; ?>
<?php include '../au.com.gateway.client.enums/TransactionType.php'; ?>
<?php include '../au.com.gateway.client.enums/Version.php'; ?>
<?php include '../au.com.gateway.client.enums/Operation.php'; ?>
<?php include '../au.com.gateway.client.facade/Vault.php'; ?>
<?php include '../au.com.gateway.client.facade/Report.php'; ?>
<?php include '../au.com.gateway.client.facade/AmexWallet.php'; ?>
<?php require '../../PHPMailer-master/PHPMailerAutoload.php'; ?>

<?php
date_default_timezone_set('Asia/Colombo');
error_reporting(E_ALL);
ini_set('display_errors', 1);

$servername = "localhost";
$username = "kumbukri_krdbuse";
$password = "Q(T8d76#Abt3";
$dbname = "kumbukri_testkrdb";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$transactionAmount = new TransactionAmount();
$transactionAmount->getCurrency();

//echo '<pre>';
//var_dump($transactionAmount->getCurrency());
//die('haha');


$authToken = '41543216-9d01-427d-9403-9224fa2edaa4';
if($_GET['clientRef'] == '4udrJwNzTWqb428I'){
    $clientId = 14000048;
}else{
    $clientId = 14000048;
}

/*------------------------------------------------------------------------------
STEP1: Build ClientConfig object
------------------------------------------------------------------------------*/
$clientConfig = new ClientConfig();
$clientConfig->setServiceEndpoint("https://combank.paycorp.com.au/rest/service/proxy");
//$clientConfig->setAuthToken("41543216-9d01-427d-9403-9224fa2edaa4");
$clientConfig->setAuthToken($authToken);
//$clientConfig->setHmacSecret("4udrJwNzTWqb428I");
$clientConfig->setHmacSecret($_GET['clientRef']);
$clientConfig->setValidateOnly(FALSE);
/*------------------------------------------------------------------------------
STEP2: Build Client object
------------------------------------------------------------------------------*/
$client = new GatewayClient($clientConfig);
/*------------------------------------------------------------------------------
STEP3: Build PaymentCompleteRequest object
------------------------------------------------------------------------------*/
$completeRequest = new PaymentCompleteRequest();
//$completeRequest->setClientId(14000048);
$completeRequest->setClientId($clientId);
//$completeRequest->setClientId('11000010');
$completeRequest->setReqid($_GET['reqid']);

/******************$redirect = new Redirect();
$redirect->setReturnUrl("http://sandbox.kumbukriver.com/payment/receiptPage");
$redirect->setReturnMethod("POST");
$completeRequest->setRedirect($redirect);****************/

/*------------------------------------------------------------------------------
STEP4: Process PaymentCompleteRequest object
------------------------------------------------------------------------------*/
$completeResponse = $client->payment()->complete($completeRequest);
/*------------------------------------------------------------------------------
STEP5: Process PaymentCompleteResponse object
------------------------------------------------------------------------------*/

    if($completeResponse){
        $x = $completeResponse->getextraData();
        $reservationid = (explode("-",$x[0]['ADD-KEY-2']));

        $sqlres = "SELECT reservation_id,title,name,address,contact,email,arrive_date,book_date,departure_date,nights,adults,children,baby,room_id,nationality,adult_rate,child_rate,baby_rate,additional_rate,status,paylink_hash,reason,user,is_agent,agent_presentage FROM reservation WHERE reservation_id =".$reservationid[0];
        $resultres = mysqli_query($conn, $sqlres);
        if (mysqli_num_rows($resultres) > 0) {
            $rowres = mysqli_fetch_assoc($resultres);
        }

        $inv = create_invoice($rowres['adults'], $rowres['adult_rate'], $rowres['children'], $rowres['child_rate'], $rowres['baby'], $rowres['baby_rate'], $rowres['additional_rate'], $rowres['nights']);
        if($rowres['is_agent'] != NULL){
            $discount = $inv['grand_total']/100*$rowres['agent_presentage'];
            $invoice_amount = $inv['grand_total']-$discount;
        }else{
            $invoice_amount = $inv['grand_total'];
        }

        $date = date('Y/m/d');
        $authCode = ($completeResponse->getauthCode() != '')? $completeResponse->getauthCode() : '';
        $cardExpiryMM = '';
        $cardExpiryYYYY = '';
        $card = $completeResponse->getcreditCard();
        $cardHolderName = ($card->getholderName() != '')? $card->getholderName() : '';
        $cardNo = ($card->getnumber() != '')? $card->getnumber() : '';
        $cardType = ($card->gettype() != '')? $card->gettype() : '';
        $expiry = ($card->getexpiry() != '')? $card->getexpiry() : '';
        $transaction = $completeResponse->gettransactionAmount();
        $metaData1 = ($transaction->getcurrency() != '')? $transaction->getcurrency() : '';
        $metaData2 = ($x[0]['ADD-KEY-2'] != '')? $x[0]['ADD-KEY-2'] : '';
        $paymentAmount = ($transaction->getpaymentAmount() != '')? $transaction->getpaymentAmount()/100 : '';
        $qc = '';
        $reqid = ($_GET['reqid'] != '')? $_GET['reqid'] : '';
        $responseCode = ($completeResponse->getresponseCode() != '')? $completeResponse->getresponseCode() : '';
        $responseText = ($completeResponse->getresponseText() != '')? $completeResponse->getresponseText() : '';
        $settlementDate = ($completeResponse->getsettlementDate() != '')? $completeResponse->getsettlementDate() : '';
        $token = ($completeResponse->gettoken() != '')? $completeResponse->gettoken() : '';
        $tokenReference = ($completeResponse->gettokenAuthTxnReference() != '')? $completeResponse->gettokenAuthTxnReference() : '';
        $tokenResponseText = ($completeResponse->gettokenAuthResponseText() != '')? $completeResponse->gettokenAuthResponseText() : '';
        $tokenized = ($completeResponse->gettokenized() != '')? $completeResponse->gettokenized() : '';
        $txnReference = ($completeResponse->gettxnReference() != '')? $completeResponse->gettxnReference() : '';
        $validationMessages = '';
        $reservation_id = ($reservationid[0] != '')? $reservationid[0] : '';
        $invoice_amount = $invoice_amount;
        $clientId = ($completeResponse->getclientId() != '')? $completeResponse->getclientId() : '';
        $clientIdHash = ($completeResponse->getclientIdHash() != '')? $completeResponse->getclientIdHash() : '';
        $transactionType = ($completeResponse->gettransactionType() != '')? $completeResponse->gettransactionType() : '';
        $clientRef = ($completeResponse->getclientRef() != '')? $completeResponse->getclientRef() : '';
        $cvcResponse = ($completeResponse->getcvcResponse() != '')? $completeResponse->getcvcResponse() : '';
        $addKey1 = ($x[0]['ADD-KEY-1'] != '')? $x[0]['ADD-KEY-1'] : '';

        $sqliid = "INSERT INTO transactions (date, authCode, cardHolderName, cardNo, cardType, expiry, metaData1, metaData2, paymentAmount, qc, reqid, responseCode, responseText, settlementDate, token, tokenReference, tokenResponseText, tokenized, txnReference, validationMessages, reservation_id, invoice_amount, clientId, clientIdHash, transactionType, clientRef, cvcResponse, addKey1) VALUES ('".mysqli_real_escape_string($conn, $date)."', '".mysqli_real_escape_string($conn, $authCode)."','".mysqli_real_escape_string($conn, $cardHolderName)."','".mysqli_real_escape_string($conn, $cardNo)."','".mysqli_real_escape_string($conn, $cardType)."','".mysqli_real_escape_string($conn, $expiry)."','".mysqli_real_escape_string($conn, $metaData1)."','".mysqli_real_escape_string($conn, $metaData2)."','".mysqli_real_escape_string($conn, $paymentAmount)."','".mysqli_real_escape_string($conn, $qc)."','".mysqli_real_escape_string($conn, $reqid)."','".mysqli_real_escape_string($conn, $responseCode)."','".mysqli_real_escape_string($conn, $responseText)."','".mysqli_real_escape_string($conn, $settlementDate)."','".mysqli_real_escape_string($conn, $token)."','".mysqli_real_escape_string($conn, $tokenReference)."','".mysqli_real_escape_string($conn, $tokenResponseText)."','".mysqli_real_escape_string($conn, $tokenized)."','".mysqli_real_escape_string($conn, $txnReference)."','".mysqli_real_escape_string($conn, $validationMessages)."','".mysqli_real_escape_string($conn, $reservation_id)."','".mysqli_real_escape_string($conn, $invoice_amount)."','".mysqli_real_escape_string($conn, $clientId)."','".mysqli_real_escape_string($conn, $clientIdHash)."','".mysqli_real_escape_string($conn, $transactionType)."','".mysqli_real_escape_string($conn, $clientRef)."','".mysqli_real_escape_string($conn, $cvcResponse)."','".mysqli_real_escape_string($conn, $addKey1)."')";
        if (mysqli_query($conn, $sqliid)) {
            $transaction_id = mysqli_insert_id($conn);

            if($transaction_id){
                if($completeResponse->getResponseCode() == 00){
                    $reservation_id = $reservation_id;
                    $payment_type = 3;
                    $amount = $paymentAmount;
                    $currency = $metaData1;
                    $transactionsid = $transaction_id;

                    $sqlpay = "INSERT INTO payment (reservation_id, payment_type, date, amount, currency, transactions_id) VALUES ('".mysqli_real_escape_string($conn, $reservation_id)."', '".mysqli_real_escape_string($conn, $payment_type)."', '".mysqli_real_escape_string($conn, $date)."', '".mysqli_real_escape_string($conn, $amount)."', '".mysqli_real_escape_string($conn, $currency)."', '".mysqli_real_escape_string($conn, $transactionsid)."')";
                    if(mysqli_query($conn, $sqlpay)){
                        $status = 3;
                        $sqlresup = "UPDATE reservation SET status = 3 WHERE reservation_id = '".$reservation_id."'";
                        if(mysqli_query($conn, $sqlresup)){
                            
                            for($i=0; $i<$rowres['nights']; $i++){
                                $next = date('Y-m-d', strtotime($rowres['arrive_date']. " + ".$i." days"));
                                $alldays[] = $next;
                            }
                            
                            foreach($alldays as $ad){
                                $sqlcalander = "INSERT INTO reservation_calender (reservation_id, room_type, reserved_date, availability) VALUES ('".mysqli_real_escape_string($conn, $rowres['reservation_id'])."', '".mysqli_real_escape_string($conn, $rowres['room_id'])."', '".mysqli_real_escape_string($conn, $ad)."', 1)";
                                if(mysqli_query($conn, $sqlcalander)){
                                    $sqlroom = "SELECT room_type FROM room_type WHERE type_id =".$rowres['room_id'];
                                    $resultroom = mysqli_query($conn, $sqlroom);
                                    if (mysqli_num_rows($resultroom) > 0) {
                                        $rowroom = mysqli_fetch_assoc($resultroom);
                                        $maildata_discount = 0;
                                        
                                        if($rowres['is_agent'] != NULL){
                                            $discount = $inv['grand_total']/100*$reservation[0]['agent_presentage'];
                                            $maildata_discount = $discount;
                                            $maildata_grand_total_final = $inv['grand_total']-$discount;
                                            $maildata_adultsno = $inv['adultsno'];
                                            $maildata_adults_total = $inv['adults_total'];
                                            $maildata_additional_persons = $inv['additional_persons'];
                                            $maildata_additional_persons_total = $inv['additional_persons_total'];
                                            $maildata_children_total = $inv['children_total'];
                                            $maildata_baby_total = $inv['baby_total'];
                                            $maildata_total = $inv['total'];
                                            $maildata_grand_total = $inv['grand_total'];
                                        }else{
                                            $maildata_adultsno = $inv['adultsno'];
                                            $maildata_adults_total = $inv['adults_total'];
                                            $maildata_additional_persons = $inv['additional_persons'];
                                            $maildata_additional_persons_total = $inv['additional_persons_total'];
                                            $maildata_children_total = $inv['children_total'];
                                            $maildata_baby_total = $inv['baby_total'];
                                            $maildata_total = $inv['total'];
                                            $maildata_grand_total = $inv['grand_total'];
                                            $maildata_grand_total_final = $inv['grand_total'];
                                        }
                                        
                                        $maildata_invno = $rowres['reservation_id'];
                                        $maildata_name = $rowres['title'].$rowres['name'];
                                        $maildata_email = $rowres['email'];
                                        $maildata_arrive_date = $rowres['arrive_date'];
                                        $maildata_book_date = $rowres['book_date'];
                                        $maildata_nights = $rowres['nights'];
                                        $maildata_currency = $metaData1;
                                        $maildata_children = $rowres['children'];
                                        $maildata_baby = $rowres['baby'];
                                        $maildata_room_type = $rowroom['room_type'];
                                        $maildata_adult_rate = $rowres['adult_rate'];
                                        $maildata_child_rate = $rowres['child_rate'];
                                        $maildata_baby_rate = $rowres['baby_rate'];
                                        $maildata_additional_rate = $rowres['additional_rate'];
                                             
                                        
                                        $content = file_get_contents("../../invoice.html","r") or die("<br>Error reading signup template file.");

                                        $content = str_replace("#maildata_invno#",$maildata_invno,$content);
                                        $content = str_replace("#maildata_name#",$maildata_name,$content);
                                        $content = str_replace("#maildata_email#",$maildata_email,$content);
                                        $content = str_replace("#maildata_arrive_date#",$maildata_arrive_date,$content);
                                        $content = str_replace("#maildata_book_date#",$maildata_book_date,$content);
                                        $content = str_replace("#maildata_nights#",$maildata_nights,$content);
                                        $content = str_replace("#maildata_currency#",$maildata_currency,$content);
                                        $content = str_replace("#maildata_children#",$maildata_children,$content);
                                        $content = str_replace("#maildata_baby#",$maildata_baby,$content);
                                        $content = str_replace("#maildata_room_type#",$maildata_room_type,$content);
                                        $content = str_replace("#maildata_adult_rate#",$maildata_adult_rate,$content);
                                        $content = str_replace("#maildata_child_rate#",$maildata_child_rate,$content);
                                        $content = str_replace("#maildata_baby_rate#",$maildata_baby_rate,$content);
                                        $content = str_replace("#maildata_additional_rate#",$maildata_additional_rate,$content);
                                        $content = str_replace("#maildata_adultsno#",$maildata_adultsno,$content);
                                        $content = str_replace("#maildata_adults_total#",$maildata_adults_total,$content);
                                        $content = str_replace("#maildata_additional_persons#",$maildata_additional_persons,$content);
                                        $content = str_replace("#maildata_additional_persons_total#",$maildata_additional_persons_total,$content);
                                        $content = str_replace("#maildata_children_total#",$maildata_children_total,$content);
                                        $content = str_replace("#maildata_baby_total#",$maildata_baby_total,$content);
                                        $content = str_replace("#maildata_total#",$maildata_total,$content);
                                        $content = str_replace("#maildata_grand_total#",$maildata_grand_total,$content);
                                        $content = str_replace("#maildata_discount#",$maildata_discount,$content);
                                        $content = str_replace("#maildata_grand_total_final#",$maildata_grand_total_final,$content);

                                        $mail = new PHPMailer;
                                        //$mail->SMTPDebug = 3;                               // Enable verbose debug output
                                        $mail->isSMTP();                                      // Set mailer to use SMTP
                                        $mail->Host = 'mail.kumbukriver.com';  // Specify main and backup SMTP servers
                                        $mail->SMTPAuth = true;                               // Enable SMTP authentication
                                        $mail->Username = 'noreply@kumbukriver.com';                 // SMTP username
                                        $mail->Password = 'DjmeWJ2Q';                           // SMTP password
                                        $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
                                        $mail->Port = 25;                                    // TCP port to connect to

                                        $mail->From = 'noreply@kumbukriver.com';
                                        $mail->FromName = 'www.kumbukriver.com';
                                        $mail->addAddress('reservations@kumbukriver.com');     // Add a recipient
                                        $mail->addAddress($rowres['email']);
                                        $mail->addAddress('kumbukriver74@gmail.com');               // Name is optional
                                        //$mail->addReplyTo('info@example.com', 'Information');
                                        $mail->addCC('waruna.the7thfrontier@gmail.com');
                                        //$mail->addBCC('bcc@example.com');

                                        $mail->addAttachment('/var/tmp/file.tar.gz');         // Add attachments
                                        $mail->addAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
                                        $mail->isHTML(true);                                  // Set email format to HTML

                                        $mail->Subject = 'KumbukRiver - Invoice : '.$rowres['email'];
                                        //$mail->Body    = $mailStr;
                                        $mail->Body    = $content;
                                        //$mail->MsgHTML($content);
                                        $mail->AltBody = 'To view the message, please use an HTML compatible email viewer!';

                                        if(!$mail->send()) {
                                            $success = false;
                                            //$message = 'It seems an error occurred in submitting your reservation form!. Please try again after refreshing your web-browser or please call / e-mail us for the required information. We sincerely apologise for any inconvenience caused!!';
                                        } else {
                                            $success = true;
                                            //$message = 'We have recieved your mail, One of our customer service representatives will contact you shortly.!';  
                                        }
                                        
                                        echo '<pre>';
                                        var_dump($success);
                                        die('lalala');
                                        

                                        
                                        
                                        
                                        /*$to = $rowres['email'].", reservations@kumbukriver.com";
                                        $subject = "Kumbuk River - Payment Completed";
                                        $message = "
                                        <html>
                                        <head>
                                        <title>Kumbuk River - Payment Completed Notis</title>
                                        </head>
                                        <body>
                                        <h4>Your Payment Completed !</h4>
                                        <h4>Thank You.</h4>
                                        </body>
                                        </html>
                                        ";
                                        $headers = "MIME-Version: 1.0" . "\r\n";
                                        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
                                        $headers .= 'From: <www.kumbukriver.com>' . "\r\n";
                                        $headers .= 'Cc: kumbukriver74@gmail.com' . "\r\n";
                                        $mail = mail($to,$subject,$message,$headers);
                                        
                                        if($mail){
                                            die('OK123');
                                        }*/
                                        
                                        
                                        /*$message = "<!DOCTYPE html>"
                                            ."<html>"
                                                ."<head>"
                                                    ."<title>Receipt</title>"
                                                ."</head>"
                                                ."<style>"
                                                    .".riform td{font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px; line-height: 1.42857143; padding: 8px; border-top: 1px solid #ddd;}"
                                                    ."h1{font-size: 36px; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-weight: 500; line-height: 1.1; color: inherit;}"
                                                    ."hr{margin-top: 0; margin-bottom: 5px; background-color: #EEEEEE; border: 0px; height: 1px;}"
                                                    ."h4{font-size: 18px; font-family: inherit; font-weight: 500; line-height: 1.1; color: #33336C; margin-top: 10px; margin-bottom: 10px; box-sizing: border-box; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;}"
                                                    ."p a{color: #337ab7; text-decoration: none; background-color: transparent; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px;}"
                                                ."</style>"
                                                ."<body style='border: 5px solid #ddd;'>"
                                                    ."<table width='730' align='center'>"
                                                        ."<tr style='background-color: #fff;'>"
                                                            ."<td>"
                                                                ."<table>"
                                                                    ."<tr>"
                                                                        ."<td width='80%' align='center'><h1>Receipt</h1></td>"
                                                                        ."<td width='20%' align='right'><img src='https://www.kumbukriver.com/assets/img/logo.png' style='width: 90%; padding: 5px 5px 0px 5px;' /></td>"
                                                                    ."</tr>"
                                                                ."</table>"
                                                            ."</td>"
                                                        ."</tr>"
                                                        ."<tr style='background-color: #EEEEEE;'>"
                                                            ."<td style='border-radius: 5px; padding: 10px;'>"
                                                                ."<table style='border-radius: 5px; font-weight: 500; line-height: 1.1; color: #33336C; margin-top: 10px; margin-bottom: 10px; box-sizing: border-box; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;'>"
                                                                    ."<tr>"
                                                                        ."<td width='365' align='left'>"
                                                                            ."<table>"
                                                                                ."<tr>"
                                                                                    ."<td style='font-weight: bold;'>Invoice No</td>"
                                                                                    ."<td>:</td>"
                                                                                    ."<td>KR/ $maildata_invno /16</td>"
                                                                                ."</tr>"
                                                                                ."<tr>"
                                                                                    ."<td style='font-weight: bold;'>Guest Name</td>"
                                                                                    ."<td>:</td>"
                                                                                    ."<td>  $maildata_name; </td>"
                                                                                ."</tr>"
                                                                                ."<tr>"
                                                                                    ."<td style='font-weight: bold;'>Room Type</td>"
                                                                                    ."<td>:</td>"
                                                                                    ."<td> $maildata_room_type; </td>"
                                                                                ."</tr>"
                                                                            ."</table>"
                                                                        ."</td>"
                                                                        ."<td width='365' align='right'>"
                                                                            ."<table>"
                                                                                ."<tr>"
                                                                                    ."<td style='font-weight: bold;'>Arrival Date</td>"
                                                                                    ."<td>:</td>"
                                                                                    ."<td> $maildata_arrive_date; </td>"
                                                                                ."</tr>"
                                                                                ."<tr>"
                                                                                    ."<td style='font-weight: bold;'>Book Date</td>"
                                                                                    ."<td>:</td>"
                                                                                    ."<td> $maildata_book_date; </td>"
                                                                                ."</tr>"
                                                                                ."<tr>"
                                                                                    ."<td style='font-weight: bold;'>&nbsp;</td>"
                                                                                    ."<td>&nbsp;</td>"
                                                                                    ."<td>&nbsp;</td>"
                                                                                ."</tr>"
                                                                            ."</table>"
                                                                        ."</td>"
                                                                    ."</tr>"
                                                                ."</table>"
                                                            ."</td>"
                                                        ."</tr>"
                                                        ."<tr style='background-color: #EEEEEE;'>"
                                                            ."<td style='border-radius: 5px; padding: 10px;'>"
                                                                ."<table style='width: 100%; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif; margin-top: 10px; margin-bottom: 10px;'>"
                                                                    ."<tr>"
                                                                        ."<th style='border-bottom: 2px solid black;'></th>"
                                                                        ."<th style='text-align:right; border-bottom: 2px solid black;'>Count</th>"
                                                                        ."<th style='text-align:right; border-bottom: 2px solid black;'>Price</th>"
                                                                        ."<th style='text-align:right; border-bottom: 2px solid black;'>Total(  $maildata_currency )</th>"
                                                                    ."</tr>"
                                                                    ."<tr>"
                                                                        ."<td style='border-bottom: 2px solid black;'>Adults</td>"
                                                                        ."<td style='text-align:right; border-bottom: 2px solid black;'> $maildata_adultsno; </td>"
                                                                        ."<td style='text-align:right; border-bottom: 2px solid black;'> $maildata_adult_rate  if($currency == 'LKR'){ '.00'; } </td>"
                                                                        ."<td style='text-align:right; border-bottom: 2px solid black;'> $maildata_adults_total;  if($currency == 'LKR'){ '.00'; } </td>"
                                                                    ."</tr>"
                                                                    if($children > 0){ 
                                                                    <tr>
                                                                        <td style="border-bottom: 2px solid black;">Children below the age of 10</td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_children; </td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_child_rate;  if($currency == 'LKR'){ echo '.00'; } </td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_children_total;  if($currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    } if($baby > 0){ 
                                                                    <tr>
                                                                        <td style="border-bottom: 2px solid black;">Babies</td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_baby; </td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_baby_rate;  if($currency == 'LKR'){ echo '.00'; } </td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_baby_total;  if($currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    } if($additional_persons > 0){ 
                                                                    <tr>
                                                                        <td style="border-bottom: 2px solid black;">Additional Persons</td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_additional_persons; </td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_additional_rate; if($currency == 'LKR'){ echo '.00'; } </td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_additional_persons_total; if($currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    } 
                                                                    <tr>
                                                                        <td style="">Total</td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right;"> echo $maildata_total;  if($maildata_currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td style="">Number Of Nights</td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_nights; </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right;"> echo $maildata_grand_total; if($maildata_currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td style="">Tax</td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right;">0 if($maildata_currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td style="">Service Charge</td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;">0 if($maildata_currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    if(isset($discount)){ 
                                                                    <tr>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right;"> echo $maildata_grand_total; if($maildata_currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td style="">Discount</td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right; border-bottom: 2px solid black;"> echo $maildata_discount; if($maildata_currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                    } 
                                                                    <tr style="font-weight:700;">
                                                                        <td style="font-size: 1.3em;">Grand Total</td>
                                                                        <td style=""></td>
                                                                        <td style=""></td>
                                                                        <td style="text-align:right; font-size: 1.3em; border-bottom:6px double black;"> if(isset($maildata_discount)){ echo $maildata_grand_total_final; }else{ echo $maildata_grand_total; } if($maildata_currency == 'LKR'){ echo '.00'; } </td>
                                                                    </tr>
                                                                </table>
                                                            </td>
                                                        </tr>
                                                        <tr style="background-color: #dff0d8;">
                                                            <td style="border-radius: 5px; padding: 10px; font-size: 14px; font-family: inherit; font-weight: 500; line-height: 1.1; color: #33336C; margin-top: 10px; margin-bottom: 10px; box-sizing: border-box; font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;">
                                                                <center>
                                                                    <h4 style="margin-bottom: 0px; font-size: 25px;">Congratulation...</h4>
                                                                    <h4 style="margin-bottom: 20px; margin-top: 5px">Your reservation is completed and we&#39;ll be waiting to welcome you</h4>
                                            
                                                                </center>
                                                            </td>
                                                        </tr>           
                                                        <tr>
                                                            <td><p><a href="https://www.kumbukriver.com/terms_and_conditions">Terms & Conditions</a> | <a href="https://kumbukriver.com/#enquire">Contact Us</a></p></td>
                                                        </tr>
                                                    </table>
                                                </body>
                                            </html>
                                            
                                            ";*/
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                            
                                        
                                        
                                        
                                        
                                        echo '<pre>';
                                        var_dump($rowroom);
                                        die('llaswe');
                                    }
                                }
                            }
                            
                            die('ssssswwwwwwww...');

                        }
                    }
                }else{
                    die($responseText);
                }
            }
        }
        
        $conn->close();
    }


function create_invoice($adults, $adult_rate, $children, $child_rate, $baby, $baby_rate, $additional_rate, $nights){
        $additional_persons = '0';
        $additional_persons_total = 0;

        if($adults>2){//check any aditional persons
            $additional_persons = $adults - 2;//number of aditional persons
            $additional_persons_total = $additional_rate * $additional_persons;//aditional persons totle price
            $adultsno = 2;//number of adults
            $adults_total = $adult_rate * $adultsno;//adults totle price
        }else{
            //elseif($adults <= 2){//check only adults
            $adults = 2;
            $adults_total = $adult_rate * $adults;//adults totle price
            $adultsno = $adults;//number of adults
            //}
        }

        $children_total = $child_rate * $children;//children totle price
        $baby_total = $baby_rate * $baby;//baby totle price
        $total = $adults_total + $children_total + $baby_total + $additional_persons_total;//total 
        $grand_total = $total * $nights;//full amount
        
        $return['adultsno'] = $adultsno;
        $return['adults_total'] = $adults_total;
        $return['additional_persons'] = $additional_persons;
        $return['additional_persons_total'] = $additional_persons_total;
        $return['children_total'] = $children_total;
        $return['baby_total'] = $baby_total;
        $return['total'] = $total;
        $return['grand_total'] = $grand_total;
        return $return;
    }
?>


<!--$message = '<!DOCTYPE html>'
                                                . '<html>'
                                                . '<head>'
                                                . '<title>Receipt</title>'
                                                . '<body style="border: 5px solid #ddd;">'
                                                . '<table width="730" align="center">'
                                                . '<tr style="background-color: #fff;">'
                                                . '<td>'
                                                . '<table>'
                                                . ''
                                                . ''
                                                . ''
                                                . ''
                                                . '</table>'
                                                . '</td>'
                                                . '</tr>'
                                                . ''
                                                . ''
                                                . ''
                                                . ''
                                                . ''
                                                . '<table>'
                                                . '</body>'
                                                . '</head>'
                                                . '</html>';-->