<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>RawBT Test Print</title>
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <style>
        html {
            background-color: grey;
            padding: 32px;
        }

        body {
            max-width: 640px;
            margin: 0 auto;
            padding: 32px;
            background-color: white;
        }
    	img {
    	  max-width:100%;
    	}
        button {
            background-color: #6e89ff;
            color: white;
            padding: 16px;
            border: none;
        }

        pre {
            background-color: #f0f0f0;
            border-left: #6e89ff solid 3px;
	    overflow-x:scroll;	
        }

        p {
            text-align: right;
        }

        a {
            color: #6e89ff;
            text-decoration: none;
        }
    </style>
    
    <script>

        function pc_print(data){
            data0="rawbt:test printer";
            data1="rawbt:data:text/plain;base64";
            data2="rawbt:data:text/plain;base64,'data'";
            data="intent:base64," +data.data+ "#Intent;scheme=rawbt;package=ru.a402d.rawbtprinter;end;";    
            alert(data);
        
    		var socket = new WebSocket("ws://127.0.0.1:40213/");
            socket.bufferType = "arraybuffer";
            socket.onerror = function(error) {
    		    alert("Error");
    		};			
    		socket.onopen = function() {
    			socket.send(data);
    			socket.close(1000, "Work complete");
    		};
        }		
        
    	function android_print(data){
            window.location.href = data;  
    	}
    
     // for php demo call
        function ajax_print(url, btn) {
                b = $(btn);
                b.attr('data-old', b.text());
                b.text('wait');
                $.get(url, function (data) {
            		var ua = navigator.userAgent.toLowerCase();
            		var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
        	
            		if(isAndroid) {
            		    android_print(data);
            		}else{
            		    pc_print(data);
            		}
                        }).fail(function () {
                            alert("ajax error");
                        }).always(function () {
                            b.text(b.attr('data-old'));
                    })
            }
            
        function tescetak(){
            window.location="{{ DIR_APP }}setting/tescetak";
        }

        function tesPrint(){
            
            var ua = navigator.userAgent.toLowerCase();
            var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
                	
            if(isAndroid) {
                var tpdevice='android';
            }else{
                var tpdevice='pclaptop';
            }
            
            $.ajax({
                url : "{{ DIR_APP }}setting/tescetak",
                type : "GET",
                dataType : "JSON",
                success : function(data){
                     if(tpdevice=='android'){
                        window.location.href=data.data;
                    }else{
                		var socket = new WebSocket("ws://127.0.0.1:40213/");        /* harus dijalankan dulu dari rawbt.bat */
                        socket.bufferType = "arraybuffer";
                        socket.onerror = function(error) {
                		    alert("Error");
                	    };			
                		socket.onopen = function() {
                			socket.send(data.data);
                			socket.close(1000, "Work complete");
                		};                    
                    }
                    
                    location.reload();
        
                },
                error : function(){
                    alert("error print...");
                }
            });
        }


        function cetakBarcode(){
            
            var ua = navigator.userAgent.toLowerCase();
            var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
                	
            if(isAndroid) {
                var tpdevice='android';
            }else{
                var tpdevice='pclaptop';
            }
            
            $.ajax({
                url : "{{ DIR_APP }}kanvas/tescetakbarcode",
                type : "GET",
                dataType : "JSON",
                success : function(data){
                     if(tpdevice=='android'){
                        window.location.href=data.data;
                    }else{
                		var socket = new WebSocket("ws://127.0.0.1:40213/");        /* harus dijalankan dulu dari rawbt.bat */
                        socket.bufferType = "arraybuffer";
                        socket.onerror = function(error) {
                		    alert("Error");
                	    };			
                		socket.onopen = function() {
                			socket.send(data.data);
                			socket.close(1000, "Work complete");
                		};                    
                    }
                    
                    location.reload();
        
                },
                error : function(){
                    alert("error print...");
                }
            });
        }

            
    </script>
</head>
<body>
    
<!-- <a href="https://rawbt.ru/" title ="RawBT app site" ><img src="resources/rawbtlogo.png" alt="black&white logo RawBT ESC/POS thermal printer driver"></a> -->
<h4>RawBT & Mike42/escpos-php</h4>
To print a check from the site you need to install:
<h5>Android smartphone</h5>

<!--<a href="https://play.google.com/store/apps/details?id=ru.a402d.rawbtprinter">RawBT ESC/POS thermal printer driver</a>-->

<h5>Personal computer</h5>
<a href="https://github.com/402d/rawbt_ws_server/releases">Websoket Server for ESC/POS Printers</a> 
<br/>
<br/>
<br/>

<br>
<button  onclick="tesPrint()"> test print dot matrix</button>
<!--button  onclick="cetakBarcode()"> test print barcode</button-->
<a href="{{ route('home') }}"> back to dashboard</a>

<br/>
<br/>
<br/>


</body>
</html>