<?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 pls_withdraw.id  as d, pls_member.names,pls_member.mem,amount,description,w_option,date,served_by FROM pls_withdraw JOIN pls_member ON pls_withdraw.member=pls_member.id  where pls_withdraw.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("WITHDRAWS \n");
                $printer -> selectPrintMode();

                $printer -> setEmphasis(false);
                $printer -> feed(1);
               
                /* BARCODE   */
                $printer -> setBarcodeHeight(80);
                $printer->  setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
                $printer -> barcode(" {$d} ");
                $printer -> feed(); 
       
        
                /*  RECEIPT BODY  */
                $printer -> setJustification(Printer::JUSTIFY_LEFT);
                $printer -> text(" MEMBER  NO  : {$mem}\n");
                $printer -> feed(1);
                $printer -> text(" MEMBER NAME : {$names} \n ");
                $printer -> feed(1);
                $printer -> text(" DATE        : {$date}  \n ");
                $printer -> feed(1);
                $printer -> text(" MODE        : {$s_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();
                header("location:../withdraw");
                             
                             }


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

                $data = $conn->query("SELECT pls_withdraw.id  as d, pls_member.names,pls_member.mem,amount,description,w_option,date,served_by FROM pls_withdraw JOIN pls_member ON pls_withdraw.member=pls_member.id  where pls_withdraw.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(" WITHDRAWS \n");
                $printer -> selectPrintMode();

                $printer -> setEmphasis(false);
                $printer -> feed(1);
               
                /* BARCODE   */
                $printer -> setBarcodeHeight(80);
                $printer->  setBarcodeTextPosition(Printer::BARCODE_TEXT_BELOW);
                $printer -> barcode(" {$d} ");
                $printer -> feed(); 
       
        
                /*  RECEIPT BODY  */
                $printer -> setJustification(Printer::JUSTIFY_LEFT);
                $printer -> text(" MEMBER  NO  : {$mem}\n");
                $printer -> feed(1);
                $printer -> text(" MEMBER NAME : {$names} \n ");
                $printer -> feed(1);
                $printer -> text(" DATE        : {$date}  \n ");
                $printer -> feed(1);
                $printer -> text(" MODE        : {$w_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:../withdraw.php"); 

?>
