<html lang="en" class="no-js">
<!--<![endif]-->
<!-- start: HEAD -->
<head>
<?php
header("Expires: Tue, 01 Jan 2000 00:00:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, max-age=0");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
?>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
</head>
    
    <body>
        
        
        <h1>Colse this window after file downloaded</h1>
        <hr>
         <?php foreach ($product_list as $products) {
            $length =  strlen($products->product_code);
            if($length!=7){
                echo "This product code not in correct  format for scale machine : <span style='color:red;'>".$products->product_code." </span> ".$products->product_name." ".$products->retail_cash."<br><br>";
            }
            $first_2digit=substr($products->product_code, 0, 2);
            if($first_2digit!="00"){
                continue;
            }
             ?> 
         <?php } ?>
        
        
        <hr>
        
       <script>
            
    function download(filename, text) {
    var element = document.createElement('a');
    element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
    element.setAttribute('download', filename);
    element.style.display = 'none';
    document.body.appendChild(element);
    element.click();
    document.body.removeChild(element);
    }
        //download("export_product.txt","<?php foreach ($product_list as $products) {  echo "#".$products->product_code."#".$products->product_name."#".$products->retail_cash;} ?>");
        
    
        
      $( document ).ready(function() {
          
         var content=""; 
         
         
         <?php foreach ($product_list as $products) {
            $length =  strlen($products->product_code);
            if($length!=7){
                continue;
            }
            $first_2digit=substr($products->product_code, 0, 2);
            if($first_2digit!="00"){
                continue;
            }
             ?> 
             content += "<?php echo$products->product_code."#".$products->product_name."#".$products->retail_cash ?>"+"\r\n";
         <?php } ?>
        download("SCALE.txt",content);
       });

      
       </script> 
       
      



    </body>
    
    
    
    
    
    
</html>