
 <?php
$nopos=$_GET['nopos'];
 ?>
 
 <script src="https://cdn.jsdelivr.net/npm/recta/dist/recta.js"></script>
<script>
//alert('tes');
let xhr = new XMLHttpRequest();

    // Making our connection  
    let url = 'https://dialey.angsoft.my.id/posheru/printpos_1_ajax.php?nopos=<?php echo $nopos;?>';
    xhr.open("GET", url, true);

    // function execute after request is successful 
    xhr.onreadystatechange = function () {
       if (this.readyState == 4 && this.status == 200) {
        var myArr = JSON.parse(this.responseText);
        myFunction(myArr);
        var printer = new Recta('1074241248', '1811')
      
        // for (i=0;i<myArr['data'].length;i++)
        // {
        //     console.log(myArr['data'][i].item_code);
        // }
 console.log(myArr['data']);
            printer.open().then(function () {
      
   
        printer.align('center')
        printer.text('------------------');
        printer.text(myArr['ntoko']);
        printer.bold(true)
        printer.text(myArr['atoko']);
        printer.bold(true)
        printer.text(myArr['hptoko']);
        printer.bold(true)
        printer.text(myArr['data'][0].notrans_link);
        printer.bold(true)
        printer.text('------------------');
      
         for (i=0;i<myArr['data'].length;i++)
        {
           // console.log(myArr['data'][i].item_code);
               
        printer.text(myArr['data'][i].item_desc);
        printer.bold(true)
        printer.text(myArr['data'][i].qty+'   '+myArr['data'][i].harga_jual)
       
        printer.bold(true)
     


        }
        printer.text('------------------');
        printer.bold(true)
        printer.text('Discount: '+myArr['disc']);
        printer.bold(true)
        printer.text('Total : '+myArr['total']);
        printer.bold(true)
        printer.text('------------------');
        printer.bold(true)
        printer.cut()
        printer.print()

    })
  
       
    }
       
    }
    // Sending our request 
    xhr.send();
    

    function myFunction(arr) {
    var out = "";
    var i;
    for(i = 0; i < arr.length; i++) {
        out += '<a href="' + arr[i].url + '">' +
        arr[i].display + '</a><br>';
    }
    document.getElementById("id01").innerHTML = out;
}

// fetch('https://dialey.angsoft.my.id/posheru/printpos_1_ajax.php?nopos=POS-1733371010348', {
//     method: 'POST'
// })
//    .then(response => response.json())
//    .then(json => console.log(JSON.stringify(json)))
   
  //console.log(json);

//   var printer = new Recta('1074241248', '1811')

 
//     printer.open().then(function () {
//       printer.align('center')
//         .text('Hello World !!')
//         .bold(true)
//         .text('This is bold text')
//         .bold(false)
//         .underline(true)
//         .text('This is underline text')
//         .underline(false)
//         .barcode('UPC-A', '123456789012')
//         .cut()
//         .print()
//     })
  

 </script>   

<p id="id01"></p>