<?php   require __DIR__ . '../autoload.php'; include_once('../db.php');  include_once('../check.php');  

       use Mike42\Escpos\Printer;
       use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
      
        // AUTOMATICALLY  PRINT RECEIPT 
              $m= $_GET['id'];

              if(isset($m)) {
                            
                $data = $conn->query("SELECT * FROM pls_operationfee where id='$m' ")->fetch(); extract($data);
                              
                $connector = new WindowsPrintConnector("POS80");
                $printer =   new Printer($connector);
                
                /* Header */
                $printer -> setJustification(Printer::JUSTIFY_CENTER);
                $printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
                $printer -> text(" PALS MATATU SACCO \n");
                $printer -> selectPrintMode();
                $printer -> text(" EMAIL: palsmatatusacco@gmail.com !\n ");
                $printer -> text(" PHONE: 0798 335 111/ 0711 249 002 \n ");
                $printer -> feed(1);
                $printer -> text("-------------------------\n");
             
    
                /* Title of receipt */
                $printer -> setEmphasis(true);
                $printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
                $printer -> text(" OPERATION FEE \n");
                $printer -> selectPrintMode();

                $printer -> setEmphasis(false);
                $printer -> feed(1);
               
                /* BARCODE   */
                $printer -> setBarcodeHeight(80);
                $printer->  setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
                $printer -> barcode(" {$id} ");
                $printer -> feed(1); 
       
        
                /*  RECEIPT BODY  */
                $printer -> setJustification(Printer::JUSTIFY_LEFT);
                $printer -> text(" VEHICLE     : {$vehicle} \n ");
                $printer -> feed(1);
                $printer -> text(" DATE        : {$date}  \n ");
                $printer -> feed(1);
                $printer -> text(" MODE        : {$v_option} \n ");
                $printer -> feed(1);  
                $printer -> text("-----------------------------------------------\n");
                
                $printer -> text(" AMOUNT      : {$amount} \n ");
           
                $printer -> feed(1);

                /* Footer */        
                $printer -> feed(2);
                $printer -> setJustification(Printer::JUSTIFY_CENTER);
                $printer -> text(" YOU WERE SERVED BY {$served_by}  \n");
                $printer -> cut();

                /* Close printer */
                $printer -> close();
                             
                             }



//RE-PRINT THE RECEIPT 

      if (filter_has_var(INPUT_POST, "edit"))
       try {
                $m =           htmlspecialchars ( strtoupper($_POST['edit']));

                $data = $conn->query("SELECT * FROM pls_operationfee where id='$m' ")->fetch();
                extract($data);
                               
               $connector = new WindowsPrintConnector("POS80");
               $printer =   new Printer($connector);
           
                /* Header */
                    $printer -> setJustification(Printer::JUSTIFY_CENTER);
                    $printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
                    $printer -> text(" PALS MATATU SACCO \n");
                    $printer -> selectPrintMode();
                    $printer -> text(" EMAIL: palsmatatusacco@gmail.com !\n ");
                    $printer -> text(" PHONE: 0798 335 111/ 0711 249 002 \n ");
                    $printer -> feed(1);
                    $printer -> text("-------------------------\n");
             
    
                /* Title of receipt */
                $printer -> setEmphasis(true);
                $printer -> selectPrintMode(Printer::MODE_DOUBLE_WIDTH);
                $printer -> text(" OPERATION FEE \n");
                $printer -> selectPrintMode();

                $printer -> setEmphasis(false);
                $printer -> feed(1);
               
                /* BARCODE   */
                $printer -> setBarcodeHeight(80);
                $printer->  setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
                $printer -> barcode(" {$id} ");
                $printer -> feed(1); 
       
        
                /*  RECEIPT BODY  */
                $printer -> setJustification(Printer::JUSTIFY_LEFT);
                $printer -> text(" VEHICLE     : {$vehicle} \n ");
                $printer -> feed(1);
                $printer -> text(" DATE        : {$date}  \n ");
                $printer -> feed(1);
                $printer -> text(" MODE        : {$v_option} \n ");
                $printer -> feed(1);  
                $printer -> text("-----------------------------------------------\n");
                
                $printer -> text(" AMOUNT      : {$amount} \n ");
           
                $printer -> feed(1);

                /* Footer */        
                $printer -> feed(2);
                $printer -> setJustification(Printer::JUSTIFY_CENTER);
                $printer -> text(" YOU WERE SERVED BY {$served_by}  \n");
                $printer -> cut();
    
                /* Close printer */
                $printer -> close();
    
         } catch (Exception $e) {   echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; }

 header("location:../operation.php"); 

?>
