<?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'];
               echo"$m";
             
            if(isset($m)) {
                            
             $data = $conn->query("SELECT pls_project_savings.id  as d, pls_project.name,pls_project.projectref,amount,description,s_option,date,served_by FROM pls_project_savings
             JOIN pls_project ON pls_project_savings.name=pls_project.id  where pls_project_savings.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(" PROJECT SAVINGS \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(" PROJECT  NO  : {$projectref}\n");
                $printer -> feed(1);
                $printer -> text(" PROJECT NAME : {$name} \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();
                             
                             }




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

                $data = $conn->query(" SELECT pls_project_savings.id  as d, pls_project.name,pls_project.projectref,amount,description,s_option,date,served_by FROM pls_project_savings
                JOIN pls_project ON pls_project_savings.name=pls_project.id  where pls_project_savings.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(" PROJECT SAVINGS \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(" PROJECT  NO  : {$projectref}\n");
                $printer -> feed(1);
                $printer -> text(" PROJECT NAME : {$name} \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();
    
} catch (Exception $e) {   echo "Couldn't print to this printer: " . $e -> getMessage() . "\n"; }
 

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

?>
