<?php

	include('views/_header_shop.tpl.php');

	// IF A CUSTOMER'S VALID QR CODE IS SCANNED, LET'S GET THEIR INFO
	if ($_SESSION['order_type']) {
		if ($_SESSION['order_type'] !== "Dine-in") {
			$clean_table_number = 0;
		}
	}

	$customer_id = filter_var($_GET['uid'], FILTER_SANITIZE_STRING);
	//$table_number = filter_var($_GET['tbl'], FILTER_SANITIZE_STRING);
	//$clean_table_number = mysqli_real_escape_string($table_number);
	//$clean_table_number = intval($table_number);
	$clean_customer_id = intval($customer_id);
	
	//////////////////////////////////////////////////////////////////

	if (isset($_GET['nb'])) {
		$new_balance = $_GET['nb'];
		$balance_label = "<span style='font-weight:600; color:#00cb15'>New</span> Balance:";
	}

	if (isset($_GET['reg_ok'])) {
		$msg = '';
	}

	if (isset($_GET['msg'])) {
		$msg = htmlentities(strip_tags($_GET['msg']));
	}

?>


<style>
	body, #wrapper { background:#fff; }
	div.spacer { padding-top: 55px; }
	#mmen, .bottomtray { display:none !important; }
	.btn, .btn a, .btn a:active, .btn a:visited { border-radius: 50px; -moz-border-radius: 50px; -webkit-border-radius: 50px; margin:10px;
	font-size:14px !important; font-weight:300 !important; height:20px !important; line-height:20px !important; width:130px; padding:10px 15px !important; }
	.btn-red { 
		border-radius: 50px; -moz-border-radius: 50px; -webkit-border-radius: 50px;
	}
	.btn-blue {  background:#005493; border-radius: 50px; -moz-border-radius: 50px; -webkit-border-radius: 50px; }
	.delete-admin { background:#cd1000; } 
	.adminred { background:#cd1000; color:#fff; }
	.nonadmin { background:#ddd; color:#aaa; }

	.dash_digits {
	    font-size:48px;
	    color:#00b100;
	    font-weight:800;
	    margin:0 0 0 0 ;
	    padding: 0 0 0 0;
	}
	.dash_total { display:inline-block;}
	.dash_totaldiv {
	      display:inline-block;
	      height:77px;
	      margin: 0 20px;
	      border-left: 1.5px solid;
	      border-top: 0;
	      border-bottom: 0;
	      border-image: linear-gradient(to bottom, rgba(255, 255, 255, 0) 0%, rgba(226, 226, 226, 1) 48%, rgba(255, 255, 255, 0) 100%);
	      border-image-slice: 1;            
	}
	.ewalletinfo { float:left; display:inline-block; width:50%; text-align: center; font-weight:500; font-size:15px; line-height:29px; 
		border:1px solid #ddd; -webkit-box-sizing: border-box; -moz-box-sizing: border-box; box-sizing: border-box; padding: 15px 25px; 
	}
	input[type="tel"] {
		border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px;
	}
	input[type="submit"] {
		background:#3478f6; color:#fff; border:0px; height:50px;  font-size:20px; font-weight:600; padding:0px 25px;
		border-radius: 8px; -moz-border-radius: 8px; -webkit-border-radius: 8px;
	}	
	
</style>

<div class="form form-profile aif" style='width:auto; padding-top:10px; min-height:900px;'>   
	
		<center><img src="/static/system/ewallet_logo_339.png" alt="E-Wallet" style="max-width:300px; width:70%; margin-bottom:5px"  /></center>
		
		<h2 style="display:none; font-size:33px; font-weight:300; color:#000; text-align:center; margin:5px 0 10px;">
				E-Wallet Payments
		</h2>	
		
		<div style="text-align: center; font-weight:300; font-size:17px; line-height:25px;">
			Scan a Customer&rsquo;s unique QR Code to take secure payment for any purchase.
		</div>

		<?php
		if (isset($msg) && $msg=="Payment Successful!") {
			echo "<div id='errordiv' style='text-align:center; line-height:29px; background:#fff; color:#00cb15; 
			margin:15px 5px 15px 5px; border:3px dotted #000; border-radius: 50px; -moz-border-radius: 50px; 
			-webkit-border-radius: 50px; padding:7px 5px 7px; font-weight:600; font-size:22px;'>$msg</div>";
		} else {
			echo "<div id='errordiv' style='text-align:center; line-height:29px; background:#fff; color:#1a9dff;
			margin:15px 5px 15px 5px; border:3px dotted #000; border-radius: 50px; -moz-border-radius: 50px;
			-webkit-border-radius: 50px; padding:7px 5px 7px; font-weight:500; font-size:18px;'>$msg</div>";
		}	
		?>	        

        <?php if ($_SESSION['user']['is_admin']) { ?>

		<div style="text-align: center; font-weight:300; font-size:17px; line-height:35px; margin-bottom:7px;">
			Customer: <span style="font-weight:600; color:#000;"><?= $customer['name']; ?></span><br />
			
			<?php if(isset($new_balance)){ echo $balance_label; } else { echo "Balance:"; } ?> <span 
			style="font-size:28px; font-weight:600; color:#00cb15;"><?php echo "$" . number_format(($customer['virtual_balance']/100),2,'.',''); ?></span>
			<br />
				<form method="post" enctype="multipart/form-data">
					<center>Amount Due:</center>
					<div style="width:195px; height:90px; margin:0 auto; border:0px solid #ccc; padding:0 0 5px; text-align:left;">				
							<div style="height:35px; width:25px; float:left; text-align:center; padding:15px 0; margin-top:3px; font-size:32px; font-weight:600;">
								$
							</div> 
							<input type="tel" class="currency" name="amount_due" placeholder="0.00" inputmode="decimal" step=".01"
							style="border:0px; background:#eee;  font-size:32px; font-weight:600; color:#00cb15; 
							width:120px; margin-right:-40px; text-align:center; height:40px; padding:15px 10px;">	
					</div>
					
					<input type="hidden" name="uid" value="<?= $customer['id']; ?>">
					<input type="submit" Value="Take Payment" 
					style="max-width:186px; margin:0 auto; font-weight:300; font-size:17px" class="btn-black">
				
				</form>
				<div class="clear"></div>
			
				<div class="btn-blackXXX" style="max-width:186px; margin:0 auto; padding-top:15px">
					<a href="/admin/dash" title="Start Over" style="line-height:50px;">&laquo; Back</a> &nbsp;|&nbsp;
					<a href="/admin/scan" title="Start Over" style="line-height:50px;">Start Over</a>
				</div>
					
		</div><!-- END OF CUSTOMER INFO -->
		<?php } ?>
			
		<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
	
</div>		

<script type="text/javascript" defer>
    setTimeout(function() {
        //do something special
        
      }, 5000);    
      // END TIMEOUT
    
$(document).ready(function() {
   // alert('hi alert');
   $(".currencyMask").change(function () {
            if (!$.isNumeric($(this).val()))
                $(this).val('0').trigger('change');

            $(this).val(parseFloat($(this).val(), 10).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").toString());
        });
 });
 </script>
                            
<script type="text/javascript" defer>
    // mini jQuery plugin that formats to two decimal places
    (function($) {
        $.fn.currencyFormat = function() {
            this.each( function( i ) {
                $(this).change( function( e ){
                    if( isNaN( parseFloat( this.value ) ) ) return;
                    this.value = parseFloat(this.value).toFixed(2);
                });
            });
            return this; //for chaining
        }
    })( jQuery );

    // apply the currencyFormat behaviour to elements with 'currency' as their class
    $( function() {
        $('.currency').currencyFormat();
    });

    // COUNTER FUNCTION  
    $({ Counter: 0 }).animate({
      Counter: $('.animatednumber').text().replace(/,/g, ''),
    }, {
      duration: 4000,
      easing: 'swing',
      step: function(now) {
        $('.animatednumber').text(commaSeparateNumber(Math.round(now*1)/1));
      }
    });
    
    // COUNTER FUNCTION  
    $({ Counter: 0 }).animate({
      Counter: $('.animatednumber2').text().replace(/,/g, ''),
    }, {
      duration: 4000,
      easing: 'swing',
      step: function(now) {
        $('.animatednumber2').text(commaSeparateNumber(Math.round(now*1)/1));
      }
    });    
    
    // COMMA SEPARATED FUNCTION
    function commaSeparateNumber(val){
        while (/(\d+)(\d{3})/.test(val.toString())){
          val = val.toString().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
        }
        return val;
    }  
</script>


<style>
.admintable td, .admintable th {
    padding: 3px;
    border:solid #eee 1px;
}
</style>
<?php
include 'views/_footer_shop.tpl.php';
?>