<?php

include 'load.php';

date_default_timezone_set('Asia/Colombo');
$date = date('Y-m-d H:i:s');

$message='';

if (isset($_POST['pay_btn'])) {

$receipt_mobile='';
if (isset($_POST['receipt_mobile'])) {
$receipt_mobile =$_POST['receipt_mobile'];
}

$user_qury2=mysqli_query($conn,"SELECT * FROM `ormsreload` WHERE rid=(SELECT MAX(rid) FROM ormsreload);");
$user_resalt2=mysqli_fetch_array($user_qury2);
$refnumber = $user_resalt2['rid']+1;
$refno = "0000$refnumber";

$phoneNumber = ltrim($_POST['mobile'], '0');    

$mid ='NDIwNjAw';
$secretkey ='50b664cd0ad4ae4688a1';
$number =$phoneNumber;
$provider =$_POST['bill_type'];
$amount =$_POST['amount'];
$refno =$refno;
$rurl ='0';
$hashed = hash("sha512", "$mid|$number|$provider|$amount|$refno|$rurl|$secretkey");
$hashed =strtolower($hashed);

//getMyPKG
$q=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='$_SESSION[reid]'");
$PK=mysqli_fetch_array($q);
$PKID = $PK['pkgcount'];
//$customer = $PK['fullname'];
$customerbalance = $PK['balance'];

if ($customerbalance<=$amount){
	
$msg = 'Your Account Balance 0 Now';
$message='<div class="alert" role="alert" style="color: #ffffff;background-color: #ff4136; border-color: #ff4136;">
<i class="mdi mdi-check-decagram"></i>'.$msg.'</div>';

}else{

$q2=mysqli_query($conn,"SELECT TS.`scode`,TS.`scode`, pkgs.sid, pkgs.scode, pkgs.pkgcount,pkgs.scomission FROM ormsservices TS 
INNER JOIN pkgs ON TS.scode=pkgs.scode
WHERE pkgs.pkgcount='".$sellerpackage."' AND pkgs.scode ='".$provider."'");
$PK=mysqli_fetch_array($q2);
$comiz = $PK['scomission']; 

$dicountBal = $amount -($amount * $comiz/100);

//$url ='http://partner.datatouch.lk/api?action=recharge&format=&mid='.$mid.'&provider='.$provider.'&number='.$number.'&amount='.$amount.'&refno='.$refno.'&rurl='.$rurl.'&hash='.$hashed.'&value1='.$receipt_mobile.'';

$url ='http://partner.datatouch.lk/api/?action=recharge&format=&mid='.$mid.'&provider='.$provider.'&number='.$number.'&amount='.$amount.'&refno='.$refno.'&rurl='.$rurl.'&hash='.$hashed.'&value1='.$receipt_mobile.'';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

$headers = array();
$headers[] = 'Accept: application/json';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);

$body = file_get_contents($url);
$xml = simplexml_load_string($body);
$json = json_encode($xml);
$array = json_decode($json,TRUE);

if($array['Status']['@attributes']['reason']=='Duplicate Reference Number'){
$msg = ''.$phoneNumber.' Rs '.$amount.'.00 success recharged';
$message='<div class="alert" role="alert" style="color: #ffffff;background-color: #1bcfb4; border-color: #1bcfb4;">
<i class="mdi mdi-check-decagram"></i>'.$msg.'</div>';

header("refresh:2;receipt.php?reloadno=".$_POST['mobile']."&refnumber=".$refno.""); // redirects image view page after 5 seconds.

$query ="INSERT INTO `ormsreload` (`refno` ,`customer` ,`provider`, `number` , `amount`,`comiz`, `add_date`, `status`, `userid`, `addcustomer`) VALUES 
    ('".$refno."', '".$_SESSION['reid']."', '".$_POST['bill_type']."', '".$_POST['mobile']."','".$_POST['amount']."','".$comiz."', current_timestamp(), '1', '".$addbycustomer."','".$customer."')";

	$pay_qury=mysqli_query($conn,$query);
 
    $pay_qury=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='".$_SESSION['reid']."' LIMIT 1");

    $pay_resalt=mysqli_fetch_array($pay_qury);

    $balancenw =  $user_resalt['balance'] - $dicountBal;
  
    $blnc_qury=mysqli_query($conn,"UPDATE `ormsregister` SET `balance` = '".$balancenw."' WHERE `reid` = '".$_SESSION['reid']."'; ");

}else{

$message='<div class="alert" role="alert" style="color: #ffffff;background-color: #FF0000; border-color: #1bcfb4;">
<i class="mdi mdi-check-decagram"></i>'.$array['Status']['@attributes']['reason'].'</div>';

header("refresh:2;fail_receipt.php?reloadno=".$_POST['mobile']."&refnumber=".$refno."&fail=".$array['Status']['@attributes']['reason'].""); // redirects image view page after 5 seconds.

$query1 ="INSERT INTO `ormsreload` (`refno` ,`customer` ,`provider`, `number` , `amount`,`comiz`, `add_date`, `status`, `userid`, `addcustomer`) VALUES 
    ('".$refno."', '".$_SESSION['reid']."', '".$_POST['bill_type']."', '".$_POST['mobile']."','".$_POST['amount']."','".$comiz."', current_timestamp(), '0', '".$addbycustomer."','".$customer."')";

 $pay_qury1=mysqli_query($conn,$query1);
    
}

$_POST= array();


}
}

if (isset($_POST['pay_btn_utility'])) {

$receipt_mobile='';
if (isset($_POST['receipt_mobile'])) {
$receipt_mobile =$_POST['receipt_mobile'];
}

$user_qury2=mysqli_query($conn,"SELECT * FROM `ormsreload` WHERE  rid=(SELECT MAX(rid) FROM ormsreload);");
$user_resalt2=mysqli_fetch_array($user_qury2);
$refnumber = $user_resalt2['rid']+1;
$refno = "0000$refnumber";

$phoneNumber = ltrim($_POST['mobile'], '0');

$number =$phoneNumber;
$provider =$_POST['bill_type'];
$amount =$_POST['amount'];
$refno =$refno;

//getMyPKG
$q=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='$_SESSION[reid]'");
$PK=mysqli_fetch_array($q);
$PKID = $PK['pkgcount'];
//$customer = $PK['fullname'];
$customerbalance = $PK['balance'];

if ($customerbalance<=$amount){
	
$msg = 'Your Account Balance 0 Now';
$message='<div class="alert" role="alert" style="color: #ffffff;background-color: #ff4136; border-color: #ff4136;">
<i class="mdi mdi-check-decagram"></i>'.$msg.'</div>';

}else{

//getMyPKG
$PKID = $PK['pkgcount'];
//acoording to pkg comiz
$q2=mysqli_query($conn,"SELECT TS.`scode`,TS.`scode`, pkgs.sid, pkgs.pkgcount,pkgs.scomission FROM ormsservices TS INNER JOIN pkgs ON TS.sid=pkgs.sid
WHERE pkgs.pkgcount='".$PKID."' AND pkgs.scode ='".$provider."' ");
$PK=mysqli_fetch_array($q2);
$comiz = $PK['scomission'];

$dicountBal = $amount -($amount * $comiz/100);

if ($provider="CEB"){

$msg = ''.$phoneNumber.' Rs '.$amount.'.00 success ceb payment';
$message='<div class="alert" role="alert" style="color: #ffffff;background-color: #1bcfb4; border-color: #1bcfb4;">
<i class="mdi mdi-check-decagram"></i>'.$msg.'</div>';

header("refresh:2;receipt.php?reloadno=".$_POST['mobile']."&refnumber=".$refno.""); // redirects image view page after 5 seconds.

$query ="INSERT INTO `ormsreload` (`refno` ,`customer` ,`provider`, `number` , `amount`,`comiz`, `add_date`, `status`, `userid`, `addcustomer`) VALUES 
    ('".$refno."', '".$_SESSION['reid']."', '".$_POST['bill_type']."', '".$_POST['mobile']."','".$_POST['amount']."','".$comiz."', current_timestamp(), '3', '".$addbycustomer."','".$customer."')";

	$pay_qury=mysqli_query($conn,$query);
 
    $pay_qury=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='".$_SESSION['reid']."' LIMIT 1");

    $pay_resalt=mysqli_fetch_array($pay_qury);

    $balancenw =  $user_resalt['balance'] - $dicountBal;

	$blnc_qury=mysqli_query($conn,"UPDATE `ormsregister` SET `balance` = '".$balancenw."' WHERE `reid` = '".$_SESSION['reid']."'; ");

}else if ($provider="LECO"){
	
$msg = ''.$phoneNumber.' Rs '.$amount.'.00 success your leco payment';
$message='<div class="alert" role="alert" style="color: #ffffff;background-color: #1bcfb4; border-color: #1bcfb4;">
<i class="mdi mdi-check-decagram"></i>'.$msg.'</div>';

header("refresh:2;receipt.php?reloadno=".$_POST['mobile']."&refnumber=".$refno.""); // redirects image view page after 5 seconds.

$query ="INSERT INTO `ormsreload` (`refno` ,`customer` ,`provider`, `number` , `amount`,`comiz`, `add_date`, `status`, `userid`, `addcustomer`) VALUES 
    ('".$refno."', '".$_SESSION['reid']."', '".$_POST['bill_type']."', '".$_POST['mobile']."','".$_POST['amount']."','".$comiz."', current_timestamp(), '3', '".$addbycustomer."','".$customer."')";

	$pay_qury=mysqli_query($conn,$query);
 
    $pay_qury=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='".$_SESSION['reid']."' LIMIT 1");

    $pay_resalt=mysqli_fetch_array($user_qury);

    $balancenw =  $user_resalt['balance'] - $dicountBal;

	$blnc_qury=mysqli_query($conn,"UPDATE `ormsregister` SET `balance` = '".$balancenw."' WHERE `reid` = '".$_SESSION['reid']."'; ");
	
}else if ($provider="NWS"){
	
$msg = ''.$phoneNumber.' Rs '.$amount.'.00 success your water bill payment';
$message='<div class="alert" role="alert" style="color: #ffffff;background-color: #1bcfb4; border-color: #1bcfb4;">
<i class="mdi mdi-check-decagram"></i>'.$msg.'</div>';

header("refresh:2;receipt.php?reloadno=".$_POST['mobile']."&refnumber=".$refno.""); // redirects image view page after 5 seconds.

$query ="INSERT INTO `ormsreload` (`refno` ,`customer` ,`provider`, `number` , `amount`,`comiz`, `add_date`, `status`, `userid`, `addcustomer`) VALUES 
    ('".$refno."', '".$_SESSION['reid']."', '".$_POST['bill_type']."', '".$_POST['mobile']."','".$_POST['amount']."','".$comiz."', current_timestamp(), '3', '".$addbycustomer."','".$customer."')";

	$pay_qury=mysqli_query($conn,$query);
 
    $pay_qury=mysqli_query($conn,"SELECT * FROM ormsregister WHERE reid='".$_SESSION['reid']."' LIMIT 1");

    $upay_resalt=mysqli_fetch_array($pay_qury);

    $balancenw =  $user_resalt['balance'] - $dicountBal;

	$blnc_qury=mysqli_query($conn,"UPDATE `ormsregister` SET `balance` = '".$balancenw."' WHERE `reid` = '".$_SESSION['reid']."'; ");
	
}
}
}

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

<head>
	
	<meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>Recharge | Recharge and Billing System | ORMS | Dashbaord</title>
    <?php
	require_once 'headercss.php';
	?>

</head>

<body>

    <!--**********************************
        Main wrapper start
    ***********************************-->
    <div id="main-wrapper">

    <?php
	require_once 'header.php';
	?>

        <!--**********************************
            Sidebar start
        ***********************************-->
        <div class="deznav">
            <div class="deznav-scroll">
	<?php

	require_once 'sidebarmenu.php';

	?>
            </div>
        </div>
        <!--**********************************
            Sidebar end
        ***********************************-->
		
        <!--**********************************
            Content body start
        ***********************************-->
        <div class="content-body">
            <!-- row -->
            <div class="container-fluid">
				<div class="row">
				<div class="col-xl-12 col-xxl-12 col-sm-12">
				<div class="alert alert-danger bg-danger text-white" role="alert">
				<strong>Alert!</strong> ඔබගේ ගිනුම තහවුරු කිරීම අසම්පුර්නයි.<a href="identity_verify.php" class="btn btn-success float-right" style="background-color:#0847cb;font-weight:bold;font-size:18px;color:#ffffff;padding:4px 4px;">සම්පුර්න කරන්න</a>
				</div>
				</div>
				</div> 
                <div class="row page-titles mx-0">
                    <div class="col-sm-6 p-md-0">
                        <div class="welcome-text">
                            <h4>Recharge</h4>
                        </div>
                    </div>
                    <div class="col-sm-6 p-md-0 justify-content-sm-end mt-2 mt-sm-0 d-flex">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="home.php">Home</a></li>
							<li class="breadcrumb-item active"><a href="javascript:void(0);">Pay Desk</a></li>
                            <li class="breadcrumb-item active"><a href="javascript:void(0);">Recharge</a></li>
                        </ol>
                    </div>
                </div>
				
<?php 
	
	if ($_GET['service']=="MOBILE"){
	?>
<div class="container" style="max-width: 33rem;">
			<div class="card">
				<div class="card-body">
					<h2 class="text-center">MOBILE RECHARGE</h2>
					<hr>
					<?=$message?>
					<form autocomplete="off" class="p-2 mt-4" action="./recharge.php?service=MOBILE" method="post" id="relod_frm" onsubmit="return confirm('Are you sure you want to confirm?');">
						
						<div class="form-group text-center">
							<img id="d" height="50" id="dialogimg" class="m-2" src="../images/dialog.png" alt="Dialog">
							<img id="m" height="50" id="mobitelimg" class="m-2" src="../images/mobitel.png" alt="Mobitel">
							<img id="h" height="50" id="hutchimg" class="m-2" src="../images/hutch2.png" alt="Hutch">
							<!-- <img height="50" id="hutchimg" class="m-2" src="../images/hutch8.png" alt="Hutch"> -->
							<img id="a" height="50" id="airtelimg" class="m-2" src="../images/airtel.png" alt="Airtel">
						</div>

                        <div class="form-group niftra-field-icon">
                            <input type="tel" class="form-control" id="txtMobile" name="mobile" placeholder="Enter Mobile Number" minlength="9" maxlength="10" required="">
                        </div>
						
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="txtAmount" name="amount" placeholder="Enter Amount" required="">
                            <input type="text" name="bill_type" hidden id="code" value="post">

						</div>
						<fieldset class="mt-4" style="font-size: 20px;">
							<div class="row text-center">
								<div class="col-md-6" id="prepaid_div">
									<input type="radio" name="radio" id="prepaid" value="pre">
									<label for="prepaid" class="mr-4">PrePaid</label>
								</div>
								<div class="col-md-6" id="postpaid_div">
									<input type="radio" name="radio" id="postpaid" value="post">
									<label for="postpaid">PostPaid</label>
								</div>
							</div>
						</fieldset>
						<div class="row mt-4">
							<a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
							<input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="RECHARGE">
						</div>
					</form>
				</div>
			</div>
		</div>
	<?php
	}else if ($_GET['service']=="UTILITIES"){
	?>
				
		
		<div class="container" style="max-width: 33rem;">
			<div class="card">
				<div class="card-body">
					<h2 class="text-center">UTILITY PAYMENTS</h2>
					<hr>
					<?=$message?>
					<div class="text-center">
						<img height="50" class="m-2" src="../images/ceb.png" alt="CEB">
						<img height="50" class="m-2" src="../images/leco.png" alt="LECO">
						<img height="50" class="m-2" src="../images/water.png" alt="Water">
					</div>
					<form autocomplete="off" class="p-2 mt-4" action="./recharge.php?service=UTILITIES" method="post" id="bill_frm" onsubmit="return confirm('Are you sure you want to confirm?');">
						<div class="form-group niftra-field-icon">
							<select class="form-control" id="bill_type" name="bill_type" required="" onchange="cal_credit_amount()">
								<option value="">Select a Bill Type</option>
								<option value="CEB">Ceylon Electricity Board</option>
								<option value="LECO">Lanka Electricity Company</option>
								<option value="NWS">National Water Supply and Drainage Board</option>
							</select>
						</div>
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="mobile" name="mobile" placeholder="Enter Account Number" required="">
						</div>
						<div class="form-group niftra-field-icon">
							<input type="number" class="form-control" id="amount" name="amount" placeholder="Enter Amount" onchange="cal_credit_amount()" required="">
						</div>
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="receipt_mobile" name="receipt_mobile" placeholder="Mobile Number to Send Receipt" minlength="9" maxlength="10" required="">
						</div>
						<div class="form-group text-center mt-3">
							<p><span id="amount_tot"></span></p>
						</div>
						<div class="row mt-4">
							<a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
<!-- 							<button type="submit" class="btn btn-success col-md-9" onclick="pay()">PAY</button>
 -->							<input class="btn btn-success col-md-9" type="submit" name="pay_btn_utility" value="Pay">

						</div>
					</form>
				</div>
			</div>
		</div>
	<?php
	}else if ($_GET['service']=="INTERNET"){
	?>	
		<div class="container" style="max-width: 33rem;">
      <div class="card">
        <div class="card-body">
          <h2 class="text-center">INTERNET BILL</h2>
          <hr>
          <?=$message?>
          <div class="form-group text-center">
            <img height="50" class="m-2" src="../images/df.png" alt="Dialog4g">
            <img height="50" class="m-2" src="../images/slt.png" alt="slt">
            <img height="50" class="m-2" src="../images/lankabell.png" alt="Lanka Bell 4G">
          </div>
          <form class="p-2 mt-4" method="post" action="./recharge.php?service=INTERNET" id="bill_frm" onsubmit="return confirm('Are you sure you want to confirm?');">
            <div class="form-group niftra-field-icon">
              <select class="form-control" name="bill_type" id="bill_type" required="">
                <option value="">Select Bill Type</option>
                <option value="SLT">SLT Broadband</option>
                <option value="DHP">Dialog 4G Broadband - Prepaid</option>
                <option value="DHC">Dialog 4G Broadband - Postpaid</option>
                <option value="LBE">Lanka Bell 4G LTE</option>
              </select>
            </div>
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="mobile" name="mobile" placeholder="Enter Phone Number" minlength="9" maxlength="10" required="">
            </div>
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
            </div>
            <div class="row mt-5">
              <a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
              <!-- <input class="btn btn-success col-md-9" type="button" name="pay_btn" value="PAY">
 -->              <input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">

            </div>
          </form>
        
      </div>
    </div>
  </div>
  <?php
	}else if ($_GET['service']=="LAND LINE"){
	?>
  <div class="container" style="max-width: 33rem;">
      <div class="card">
        <div class="card-body">
          <h2 class="text-center">LAND LINE BILL</h2>
          <hr>
          <?=$message?>
          <div class="form-group text-center">
              <img height="50" class="m-2" src="../images/df.png" alt="Dialog4g">
              <img height="50" class="m-2" src="../images/slt.png" alt="slt">
              <img height="50" class="m-2" src="../images/lankabell.png" alt="Lanka Bell">
            </div>
          <form class="p-2 mt-4" action="./recharge.php?service=LAND LINE" method="post" id="bill_frm">
            <div class="form-group">
              <select class="form-control" name="bill_type" id="bill_type" onchange="show_receipt()" required="" onsubmit="return confirm('Are you sure you want to confirm?');">
                <option value="">Select Bill Type</option>
                <option value="DCM">Dialog CDMA</option>
				<option value="SLT">SLT</option>
                <option value="LBE">Lanka Bell CDMA</option>
              </select>
            </div>
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="mobile" name="mobile" placeholder="Enter Phone Number" minlength="9" maxlength="10" required="">
            </div>
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
            </div>
            <div class="form-group niftra-field-icon" id="receipt_mob_div" style="display:none;">
              <input type="tel" class="form-control" id="receipt_mobile" name="receipt_mobile" placeholder="Mobile Number to Send Receipt" minlength="9" maxlength="10">
            </div>
            <div class="row mt-5">
              <a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
             <!--  <input class="btn btn-success col-md-9" type="button" name="pay_btn" value="PAY"> -->
             <input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">

            </div>
          </form>
        
      </div>
    </div>
  </div>
 <?php
	}else if ($_GET['service']=="TELEVISION"){
	?> 
  <div class="container" style="max-width: 33rem;">
			<div class="card">
				<div class="card-body">
					<h2 class="text-center">TELEVISION BILL</h2>
					<hr>
					<?=$message?>
					<div class="text-center">
						<img height="50" class="m-2" src="../images/dtv.png" alt="Dialog Television">
						<img height="50" class="m-2" src="../images/peotv.png" alt="PEO TV">
					</div>

					<form class="p-2 mt-4" action="./recharge.php?service=TELEVISION" method="post" id="bill_frm">
						<div class="form-group">
							<select class="form-control" name="bill_type" id="bill_type" onchange="show_receipt()" required="" onsubmit="return confirm('Are you sure you want to confirm?');">
								<option value="">Select a Bill Type</option>
								<optgroup label="Sri Lankan Providers">
									<option value="PDTV">Dialog TV - Prepaid</option>
									<option value="DTV">Dialog TV - Postpaid</option>
									<option value="SLTB">PEO TV</option>
								</optgroup>
								<optgroup label="Indian Providers">
									<option value="DAT">Airtel TV</option>
									<option value="DDH">Dish TV - India</option>
									<option value="DSD">Sun Direct</option>
									<option value="DTS">Tata Sky</option>
									<option value="TVL">TV Lanka</option>
									<option value="DVD">Videocon D2h</option>
								</optgroup>
							</select>
						</div>
						<div class="form-group niftra-field-icon">
							<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Enter Account Number" required="">
						</div>
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
						</div>
						<div class="form-group niftra-field-icon" id="receipt_mob_div">
							<input type="tel" class="form-control" id="receipt_mobile" name="receipt_mobile" placeholder="Mobile Number to Send Receipt" minlength="9" maxlength="10" required="">
						</div>
						<div class="row mt-5">
							<a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
							<input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">

						</div>
					</form>
					<!-- <form class="p-2 mt-4" action="./recharge.php?service=LAND LINE" method="post" id="bill_frm">
						<div class="form-group">
							<select class="form-control" name="bill_type" id="bill_type" onchange="show_receipt()" required="">
								<option value="">Select a Bill Type</option>
								<optgroup label="Sri Lankan Providers">
									<option value="DTVP">Dialog TV - Prepaid</option>
									<option value="DTVB">Dialog TV - Postpaid</option>
									<option value="SLTB">PEO TV</option>
								</optgroup>
								<optgroup label="Indian Providers">
									<option value="ATLT">Airtel TV</option>
									<option value="DIHT">Dish TV - India</option>
									<option value="SUDT">Sun Direct</option>
									<option value="TAST">Tata Sky</option>
									<option value="TVLT">TV Lanka</option>
									<option value="VCDT">Videocon D2h</option>
								</optgroup>
							</select>
						</div>
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="mobile" name="mobile" placeholder="Enter Account Number" required="">
						</div>
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
						</div>
						<div class="form-group niftra-field-icon" id="receipt_mob_div" style="display:none;">
							<input type="tel" class="form-control" id="receipt_mobile" name="receipt_mobile" placeholder="Mobile Number to Send Receipt" minlength="9" maxlength="10" required="">
						</div>
						<div class="form-group text-center mt-3" id="amount_tot_div" style="display:none;">
							<p><span id="amount_tot"></span></p>
						</div>
						<div class="row mt-5">
							<a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
							<input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">


						</div>
					</form> -->
				</div>
			</div>
		</div>
	<?php
	}else if ($_GET['service']=="WALLETS"){
	?>	
		<div class="container" style="max-width: 33rem;">
      <div class="card">
        <div class="card-body">
          <h2 class="text-center">WALLET RECHARGE</h2>
          <hr>
          <?=$message?>
          <div class="text-center">
            <img height="50" class="m-2" src="../images/ezcash.png" alt="EzCash">
            <img height="50" class="m-2" src="../images/mcash.png" alt="mCash">
          </div>
          <form class="p-2 mt-4" action="./recharge.php?service=WALLETS" method="post" id="wallet_frm" onsubmit="return confirm('Are you sure you want to confirm?');">
            <div class="form-group niftra-field-icon">
              <select class="custom-select" id="bill_type" name="bill_type" required="">
                <option value="">Select a Mobile Wallet</option>
                <option value="ETP">EzCash Topup</option>
                <option value="MCT">mCash Topup</option>
                <option value="EZWD">EzCash Withdraw</option>
                <option value="IKM">IKMAN</option> 
              </select>
            </div>
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="mobile" name="mobile" placeholder="Enter Mobile Number" minlength="9" maxlength="10" required="">
            </div>
            <div class="form-group niftra-field-icon">
              <input type="text" class="form-control" id="otp" name="otp" placeholder="Enter OTP" style="display:none;">
            </div>
            <input type="hidden" name="reference" id="reference" value="">
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
            </div>
            <div class="row mt-5">
              <a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
              <button class="btn btn-primary col-md-9" type="button" id="btnvalidate" onclick="ValidateMcash()" style="display:none;">Validate</button>
              <input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">

            </div>
          </form>
        
      </div>
    </div>
  </div>
 <?php
	}else if ($_GET['service']=="INSURANCE"){
	?> 
  <div class="container" style="max-width: 33rem;">
			<div class="card">
				<div class="card-body">
					<h2 class="text-center text-uppercase">Insurance Payments</h2>
					<hr>
					<?=$message?>
					<form class="p-2 mt-4" action="./recharge.php?service=INSURANCE" method="post" id="bill_frm" onsubmit="return confirm('Are you sure you want to confirm?');">
						<div class="form-group">
							<select class="form-control" name="bill_type" id="bill_type" required="">
								<option value="">Select Your Insurance Company</option>
								<option value="AIA">AIA Insuarance Lanka</option>
								<option value="ALI">Allianz Life</option>
								<option value="ATI">Amana Takaful</option>
								<option value="AL">Assetline Leasing</option>
								<option value="CLI">COOPLIFE INSURANCE</option>
								<option value="EZL">EZ LOAN</option>
								<option value="FALI">Fairfirst Insurance</option>
								<option value="HNB">HNB Assurance</option>
								<option value="JSI">Janashakthi Life</option>
								<option value="LP">LESI PAY</option>
								<option value="LOA">LOLC Life Assuarance</option>
								<option value="NSD">NSB Deposit</option>
								<option value="SALI">Sanasa Life</option>
								<option value="SLIC">Softlogic Life</option>
								<option value="SLI">Sri Lanka Insurance</option>
								<option value="UNA">Union Assurance</option>
							</select>
						</div>
						<div class="form-group niftra-field-icon">
							<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Enter Account Number" required="">
						</div>
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
						</div>
						<div class="form-group niftra-field-icon" id="receipt_mob_div">
							<input type="tel" class="form-control" id="receipt_mobile" name="receipt_mobile" placeholder="Mobile Number to Send Receipt" minlength="9" maxlength="10" required="">
						</div>
						<div class="row mt-5">
							<a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
							<input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">

						</div>
					</form>
				
			</div>
		</div>
	</div>
<?php
	}elseif ($_GET['service']=="FINANCE"){
	?>	
	<div class="container" style="max-width: 33rem;">
			<div class="card">
				<div class="card-body">
					<h2 class="text-center text-uppercase">Finance Payments</h2>
					<hr>
					<?=$message?>
					<form class="p-2 mt-4" action="./recharge.php?service=FINANCE" method="post" id="bill_frm" onsubmit="return confirm('Are you sure you want to confirm?');">
						<div class="form-group">
							<select class="form-control" name="bill_type" id="bill_type" required="">
								<option value="">Select A Finance Company</option>
								<option value="ARPF">Arpico Finance</option>
								<option value="AASF">Asia Asset Finance</option>
								<option value="ASTL">Assetline Leasing</option>
								<option value="ASMF">Associated Motor Finance</option>
								<option value="BIMF">Bimputh Finance</option>
								<option value="CENF">Central Finance</option>
								<option value="CDBF">Citizens Development Business Finance (CDB)</option>
								<option value="DIAF">Dialog Finance</option>
								<option value="DILP">Dialog LesiPay</option>
								<option value="FINF">Fintrex Finance</option>
								<option value="HNBF">HNB Finance</option>
								<option value="ORIF">Orient Finance</option>
								<option value="SENF">Senkadagala Finance</option>
								<option value="SOLF">Softlogic Finance</option>
							</select>
						</div>
						<div class="form-group niftra-field-icon">
							<input type="text" class="form-control" id="mobile" name="mobile" placeholder="Enter Account Number" required="">
						</div>
						<div class="form-group niftra-field-icon">
							<input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
						</div>
						<div class="form-group niftra-field-icon" id="receipt_mob_div">
							<input type="tel" class="form-control" id="receipt_mobile" name="receipt_mobile" placeholder="Mobile Number to Send Receipt" minlength="9" maxlength="10" required="">
						</div>
						<div class="row mt-5">
							<a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
							<input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">
						</div>
					</form>
				</div>
			</div>
		</div>
<?php
}elseif ($_GET['service']=="TAXI"){
?>		
		<div class="container" style="max-width: 33rem;">
      <div class="card">
        <div class="card-body">
          <h2 class="text-center text-uppercase">TAXI Payments</h2>
          <hr>
          <?=$message?>
          <div class="text-center">
            <img height="50" class="m-2" src="../images/pickme-driver.png" alt="PickMe Driver">
            <img height="50" class="m-2" src="../images/uber-eats.png" alt="Uber Eats Driver">
            <img height="50" class="m-2" src="../images/uber-driver.png" alt="Uber Taxi Driver">
          </div>
          <form class="p-2 mt-4" action="./recharge.php?service=TAXI" method="post" id="bill_frm">
            <div class="form-group">
              <select class="form-control" name="bill_type" id="bill_type" required="" onsubmit="return confirm('Are you sure you want to confirm?');">
                <option value="">Select A Taxi Service</option>
                <option value="PIC">PickMe Taxi Driver</option>
                <option value="PF">PickMe Driver</option>
                <option value="UBE">Uber Taxi Driver</option>
              </select>
            </div>
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="mobile" name="mobile" placeholder="Enter Account Number" required="">
            </div>
            <div class="form-group niftra-field-icon">
              <input type="tel" class="form-control" id="amount" name="amount" placeholder="Enter Amount" required="">
            </div>
            <div class="form-group niftra-field-icon" id="receipt_mob_div">
              <input type="tel" class="form-control" id="receipt_mobile" name="receipt_mobile" placeholder="Mobile Number to Send Receipt" minlength="9" maxlength="10" required="">
            </div>
            <div class="row mt-5">
              <a class="btn btn-secondary col-md-3" href="pay_desk.php">BACK</a>
              <input class="btn btn-success col-md-9" type="submit" name="pay_btn" value="Pay">
            </div>
          </form>
        
      </div>
    </div>
  </div>
<?php
}
?>		
        </div>
        </div>
        <!--**********************************
            Content body end
        ***********************************-->

		<?php
		require_once 'footer.php';
		?>

		<!--**********************************
           Support ticket button start
        ***********************************-->

        <!--**********************************
           Support ticket button end
        ***********************************-->


    </div>
    <!--**********************************
        Main wrapper end
    ***********************************-->

    <?php
	require_once 'footerjs.php';
	?>
    
	
	<script>

    $('#txtMobile').keyup(function(event) {
        var number = $('#txtMobile').val();
        var code = $('#txtMobile').val().slice(0, 3)
        console.log("code", code);
        console.log(number);
        if (code=='077'||code=='074'||code=='076') {
        $('#d').show();
        $('#m').hide();
        $('#a').hide();
        $('#h').hide();
        }
        else if(code=='071'||code=='070'){
        $('#d').hide();
        $('#m').show();
        $('#a').hide();
        $('#h').hide();

        }
        else if(code=='075'){

        $('#d').hide();
        $('#m').hide();
        $('#a').show();
        $('#h').hide();
        }
        else if(code=='078'||code=='072'){
        $('#d').hide();
        $('#m').hide();
        $('#a').hide();
        $('#h').show();
        }
        /* Act on the event */
    });

    // var radio = $("input[name='radio']:checked").val();
    // console.log("radio", radio);

    $("input[name='radio']").change(function(event) {
    var radio = $("input[name='radio']:checked").val();
    console.log("radio", radio);

           var number = $('#txtMobile').val();

           var code = $('#txtMobile').val().slice(0, 3)
           console.log("code", code);
           console.log(number);

           if (code=='077'||code=='074'||code=='076'&&radio=='pre') {
           $('#code').val('DAR');
           }
           else if(code=='077'||code=='074'||code=='076'&&radio=='post'){
           $('#code').val('DIA');
           }

           if (code=='071'||code=='070'&&radio=='pre') {
           $('#code').val('PID');
           }
           else if(code=='071'||code=='070'&&radio=='post'){
           $('#code').val('MOB');
           }


           if (code=='075'&&radio=='pre') {
           $('#code').val('RA');
           }
           else if(code=='075'&&radio=='post'){
           $('#code').val('PAR');
           }

           if (code=='078'||code=='072'&&radio=='pre') {
           $('#code').val('HUT');
           }
           else if(code=='078'||code=='072'&&radio=='post'){
           $('#code').val('PHUT');
           }
    });

    // $('#prepaid').change(function(event) {
    //     /* Act on the event */
    //     var check = $('#prepaid').is(':checked');
    //     console.log("check", check);
    //     if(check){
    //        $('#prepaid').attr("checked",false);
    //     }else{
    //         $('#prepaid').attr("checked",true);
    //     }
    // });

    // $('#postpaid').change(function(event) {
    //     /* Act on the event */
    // });


function exportTableToExcel(tableID, filename = ''){
    var downloadLink;
    var dataType = 'application/vnd.ms-excel';
    var tableSelect = document.getElementById(tableID);
    var tableHTML = tableSelect.outerHTML.replace(/ /g, '%20');
    
    // Specify file name
    filename = filename?filename+'.xls':'excel_data.xls';
    
    // Create download link element
    downloadLink = document.createElement("a");
    
    document.body.appendChild(downloadLink);
    
    if(navigator.msSaveOrOpenBlob){
        var blob = new Blob(['\ufeff', tableHTML], {
            type: dataType
        });
        navigator.msSaveOrOpenBlob( blob, filename);
    }else{
        // Create a link to the file
        downloadLink.href = 'data:' + dataType + ', ' + tableHTML;
    
        // Setting the file name
        downloadLink.download = filename;
        
        //triggering the function
        downloadLink.click();
    }
}
</script>

<script>

$(document).ready(function(){

    loadGallery(true, 'a.thumbnail');

    //This function disables buttons when needed
    function disableButtons(counter_max, counter_current){
        $('#investow-previous-image, #investow-next-image').investow();
        if(counter_max == counter_current){
            $('#investow-next-image').hide();
        } else if (counter_current == 1){
            $('#investow-previous-image').hide();
        }
    }

    /**
     *
     * @param setIDs        Sets IDs when DOM is loaded. If using a PHP counter, set to false.
     * @param setClickAttr  Sets the attribute for the click handler.
     */

    function loadGallery(setIDs, setClickAttr){
        var current_image,
            selector,
            counter = 0;

        $('#investow-next-image, #investow-previous-image').click(function(){
            if($(this).attr('id') == 'investow-previous-image'){
                current_image--;
            } else {
                current_image++;
            }

            selector = $('[data-image-id="' + current_image + '"]');
            updateGallery(selector);
        });

        function updateGallery(selector) {
            var $sel = selector;
            current_image = $sel.data('image-id');
            $('#image-gallery-caption').text($sel.data('caption'));
            $('#image-gallery-title').text($sel.data('title'));
            $('#image-gallery-image').attr('src', $sel.data('image'));
            disableButtons(counter, $sel.data('image-id'));
        }

        if(setIDs == true){
            $('[data-image-id]').each(function(){
                counter++;
                $(this).attr('data-image-id',counter);
            });
        }
        $(setClickAttr).on('click',function(){
            updateGallery($(this));
        });
    }
});
</script>

</body>
</html>