Esempio n. 1
3
<?php

/* Example print-outs using the older bit image print command */
require_once dirname(__FILE__) . "/../Escpos.php";
$printer = new Escpos();
try {
    $tux = new EscposImage("resources/tux.png");
    $printer->text("These example images are printed with the older\nbit image print command. You should only use\n\$p -> bitImage() if \$p -> graphics() does not\nwork on your printer.\n\n");
    $printer->bitImage($tux);
    $printer->text("Regular Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Escpos::IMG_DOUBLE_WIDTH);
    $printer->text("Wide Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Tall Tux (bit image).\n");
    $printer->feed();
    $printer->bitImage($tux, Escpos::IMG_DOUBLE_WIDTH | Escpos::IMG_DOUBLE_HEIGHT);
    $printer->text("Large Tux in correct proportion (bit image).\n");
} catch (Exception $e) {
    /* Images not supported on your PHP, or image file not found */
    $printer->text($e->getMessage() . "\n");
}
$printer->cut();
$printer->close();
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $rootPath = $this->getContainer()->get('kernel')->getRootDir() . '/../';
     require_once $rootPath . 'vendor/mike42/escpos-php/Escpos.php';
     $imagePath = $rootPath . 'resources/elephant-256x256.png';
     $img = new \EscposImage($imagePath);
     $connector = new \FilePrintConnector('/dev/usb/lp0');
     $printer = new \Escpos($connector);
     $printer->initialize();
     $printer->text('*************************\\n');
     $printer->text('Un petit elephant');
     $printer->feed(2);
     $printer->bitImage($img);
     $printer->feed(2);
     $printer->text('*************************\\n');
     /* Always close the printer! On some PrintConnectors, no actual
      * data is sent until the printer is closed. */
     $printer->close();
     return 0;
 }
Esempio n. 3
0
function printer()
{
    // Create QR code in temp file, and print it.
    $tmpfname = tempnam(sys_get_temp_dir(), "escpos-php");
    $tmpfname .= ".png";
    $url = "http://www.baidu.com";
    QRcode::png($url, $tmpfname, 'L', 5, 0);
    $img = new EscposImage($tmpfname);
    // Load image
    //$connector = new NetworkPrintConnector("192.168.6.100", 9100);
    $connector = new FilePrintConnector("/dev/usb/lp0");
    // Add connector to your printer here
    $printer = new Escpos($connector);
    $printer->bitImage($img);
    $printer->text($url . "\n");
    $printer->feed();
    $printer->cut();
    $printer->close();
}
Esempio n. 4
0
 function outprint($receipt, $pname, $noplate, $containerno, $invoiceno, $intime, $outtime, $hours, $charges)
 {
     require_once "assets/escpos-php/Escpos.php";
     try {
         // Enter the share name for your USB printer here
         $connector = new WindowsPrintConnector("epson");
         $printer = new Escpos($connector);
         /* Print top logo */
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         /* Name of shop */
         $printer->selectPrintMode(Escpos::MODE_DOUBLE_WIDTH);
         $printer->text("BILL/OUTPASS \n");
         $printer->text("\nNhavaSheva toll plaza\n");
         $printer->text("Operated By\n");
         $printer->text("Shree Sai Samartha\n");
         $printer->text("Enterprises Pay & Park\n");
         $printer->selectPrintMode();
         $printer->feed();
         /* Title of receipt */
         /* Items */
         $printer->setJustification(Escpos::JUSTIFY_LEFT);
         $printer->setEmphasis(true);
         $printer->setTextSize(2, 1);
         $printer->text("RECEIPT NO :" . $receipt . "\n");
         $printer->feed();
         $printer->setTextSize(2, 1);
         $printer->text("V. TYPE    :" . $pname . "\n");
         $printer->setTextSize(2, 2);
         $printer->text("V.NO       :" . $noplate . "\n");
         $printer->feed();
         $printer->setTextSize(2, 1);
         /*$printer -> text("IN DT:".date('d/m/y',strtotime($intime))."TM:".date('h:i:s',strtotime($intime))."\n");*/
         $printer->text("IN  :" . date('Y-m-d', strtotime($intime)) . " " . date('h:i:s', strtotime($intime)) . "\n");
         $printer->text("OUT :" . date('Y-m-d', strtotime($outtime)) . " " . date('h:i:s', strtotime($outtime)) . "\n");
         $printer->feed();
         $printer->text("DURATION : " . $hours . "\n");
         $printer->setTextSize(2, 2);
         $printer->feed();
         $printer->text("AMOUNT   : " . $charges);
         $printer->setTextSize(1, 1);
         $printer->setEmphasis(false);
         $printer->setEmphasis(true);
         $printer->setEmphasis(false);
         $printer->feed();
         /* Tax and total */
         /* Footer */
         $printer->feed(1);
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         $printer->text("THANK YOU! VISIT AGAIN!\n");
         //$printer -> feed(1);
         //$printer -> text(date('l jS \of F Y h:i:s A') . "\n");
         /* Cut the receipt and open the cash drawer */
         $printer->cut();
         $printer->pulse();
         $printer->close();
     } catch (Exception $e) {
         echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
     }
     /* A wrapper to do organise item names & prices into columns */
     /* Close printer */
 }
Esempio n. 5
0
 public static function pwresetReceipt(AccountOwner_model $owner, $password)
 {
     if (!isset(self::$conf['ip']) || self::$conf['ip'] == "0.0.0.0") {
         return false;
     }
     try {
         $connector = new NetworkPrintConnector(self::$conf['ip'], self::$conf['port']);
         $profile = SimpleCapabilityProfile::getInstance();
         $printer = new Escpos($connector, $profile);
         /* Header */
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         if (isset(self::$conf['logo']) && file_exists(self::$conf['logo'])) {
             try {
                 /* Include top image if set & available */
                 $logofile = self::$conf['logo'];
                 $ser = $logofile . ".ser";
                 if (file_exists($ser)) {
                     $img = unserialize(file_get_contents($ser));
                 } else {
                     $img = new EscposImage($logofile);
                     @file_put_contents($ser, serialize($img));
                     // Attempt to cache
                 }
                 $printer->bitImage($img);
             } catch (Exception $e) {
                 trigger_error($e->getMessage());
             }
         }
         $printer->setEmphasis(true);
         $printer->text(self::$conf['header'] . "\n");
         $printer->setEmphasis(false);
         $printer->feed();
         $printer->text("User Account Information\n");
         $printer->feed(2);
         $printer->setJustification(Escpos::JUSTIFY_LEFT);
         /* User info */
         $barcode = "";
         $seen = array();
         $printer->text("User Account:\n  " . $owner->owner_firstname . " " . $owner->owner_surname . "\n\n");
         $printer->text("Login name(s):\n");
         foreach ($owner->list_Account as $acct) {
             if (!isset($seen[$acct->account_login])) {
                 $printer->text("  " . $acct->account_login . "\n");
                 $seen[$acct->account_login] = true;
                 if (is_numeric($acct->account_login) && ($barcode == "" || strlen($acct->account_login) < strlen($barcode))) {
                     $barcode = $acct->account_login;
                 }
             }
         }
         $printer->feed();
         $printer->text("Password:\n  {$password}\n");
         $printer->feed(2);
         /* Footer */
         $printer->text(self::$conf['footer'] . "\n");
         $printer->feed();
         /* Barcode */
         if ($barcode != "") {
             $printer->setJustification(Escpos::JUSTIFY_CENTER);
             $printer->barcode($barcode, Escpos::BARCODE_CODE39);
             $printer->feed();
             $printer->text($barcode);
             $printer->feed(1);
             $printer->setJustification(Escpos::JUSTIFY_LEFT);
         }
         $printer->cut();
         $printer->close();
     } catch (Exception $e) {
         trigger_error($e->getMessage());
         // Should be logged some-place for troubleshooting.
         return false;
     }
 }
Esempio n. 6
-1
 function vehicle_print($data)
 {
     require_once "assets/escpos-php/Escpos.php";
     try {
         // Enter the share name for your USB printer here
         $connector = new WindowsPrintConnector("epson");
         $printer = new Escpos($connector);
         $age = array("Monday" => "35", "Tuesday" => "37", "Wednesday" => "43");
         $day = jddayofweek(cal_to_jd(CAL_GREGORIAN, date("m"), date("d"), date("Y")), 1);
         /* Print top logo */
         /*print report start*/
         $exceldata = "";
         $t_charges = 0;
         $total_hours = 0;
         foreach ($data->result_array() as $row) {
             $pid = $row['pid'];
             $vtype = $row['name'];
             $noplate = $row['noplate'];
             $intime = $row['intime'];
             if ($row['status'] == 0) {
                 $status = 'IN';
             }
             if ($row['status'] == 1) {
                 $status = 'OUT';
             }
             if (isset($row['outtime'])) {
                 $outtime = $row['outtime'];
                 $new_hours = $row['hours'];
                 $total_charges = $row['charges'];
             } else {
                 $in = $row['intime'];
                 $out = date('Y-m-d H:i:s', time());
                 $hour1 = 0;
                 $hour2 = 0;
                 $date1 = $in;
                 $date2 = $out;
                 $datetimeObj1 = new DateTime($date1);
                 $datetimeObj2 = new DateTime($date2);
                 $interval = $datetimeObj1->diff($datetimeObj2);
                 if ($interval->format('%a') > 0) {
                     $hour1 = $interval->format('%a') * 24;
                 }
                 if ($interval->format('%h') > 0) {
                     $hour2 = $interval->format('%h');
                 }
                 $hrs = $hour1 + $hour2;
                 $hrs = sprintf("%02d", $hrs);
                 $minutes = $interval->format('%i');
                 $minutes = sprintf("%02d", $minutes);
                 $secs = $interval->format('%s');
                 $secs = sprintf("%02d", $secs);
                 $new_hours = $hrs . ":" . $minutes . ":" . $secs;
                 $sql = "select charges from charges where typeid = (select id from parktype where name = '{$vtype}' )";
                 $query = $this->db->query($sql);
                 $result = $query->result();
                 $result1 = array();
                 foreach ($result as $key => $value) {
                     $result1['charges'] = $value->charges;
                 }
                 $charges = $result1['charges'];
                 $tot_str = $hrs . '.' . $minutes;
                 $hour_in_float = (double) $tot_str;
                 $total_charges = ceil($hour_in_float / 8) * $charges;
             }
             $to_seconds = $this->time_to_seconds($new_hours);
             /*******total hours calculation*****/
             $total_hours = $total_hours + $to_seconds;
             $hours = floor($total_hours / (60 * 60));
             $divisor_for_minutes = $total_hours % (60 * 60);
             $minutes = floor($divisor_for_minutes / 60);
             // extract the remaining seconds
             $divisor_for_seconds = $divisor_for_minutes % 60;
             $seconds = ceil($divisor_for_seconds);
             $t_hours_sec = (int) $hours . ':' . (int) $minutes . ':' . (int) $seconds;
             /***********average hours calculation*********/
             $ave_hours = $total_hours / count($data->result_array());
             $hours = floor($ave_hours / (60 * 60));
             $divisor_for_minutes = $ave_hours % (60 * 60);
             $minutes = floor($divisor_for_minutes / 60);
             $divisor_for_seconds = $divisor_for_minutes % 60;
             $seconds = ceil($divisor_for_seconds);
             $ave_sec = (int) $hours . ':' . (int) $minutes . ':' . (int) $seconds;
             /*****************/
             $exceldata[] = array($pid, $vtype, $noplate, $intime, $row['outtime'], $new_hours, $total_charges, $status);
             $charges = $total_charges;
             $charges_t = $charges_t + $charges;
             $ii = 1;
             $objPHPExcel->getActiveSheet()->getStyle('A' . $ii . ':H' . $ii)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
             $ii++;
         }
         $exceldata[] = array('', 'TOTAl :' . count($data->result_array()), 'Total Hours :', $t_hours_sec, 'average hours :', $ave_sec, 'Total Charges  :', $charges_t);
         //$exceldata[] = array('','','','','','average hours :'.$ave_sec,'','');
         $excel_c = count($data->result_array()) + 4;
         /*for($col = ord('A'.$excel_c); $col <= ord('F'.$excel_c); $col++){
              $objPHPExcel->getActiveSheet()->getStyle(chr($col))->getFont()->setSize(14);
               $objPHPExcel->getActiveSheet()->getStyle(chr($col))->getFont()->setBold(true);
               $objPHPExcel->getActiveSheet()->getStyle(chr($col))->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
           }*/
         //$objPHPExcel->getActiveSheet()->getColumnDimension('G'.$excel_c)->setWidth(20);
         $objPHPExcel->getActiveSheet()->getRowDimension($excel_c)->setRowHeight(20);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFill()->getStartColor()->setARGB('29bb04');
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFont()->setSize(14);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getFont()->setBold(true);
         $objPHPExcel->getActiveSheet()->getStyle('A' . $excel_c . ':H' . $excel_c)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
         //Fill data
         $objPHPExcel->getActiveSheet()->fromArray($exceldata, null, 'A4');
         /*print report end*/
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         /* Name of shop */
         $printer->selectPrintMode(Escpos::MODE_DOUBLE_WIDTH);
         $printer->text("RECEIPT\n");
         $printer->text("\nNhavaSheva toll plaza\n");
         $printer->text("Operated By\n");
         $printer->text("Shree Sai Samartha\n");
         $printer->text("Enterprises Pay & Park\n");
         $printer->selectPrintMode();
         $printer->feed();
         /* Title of receipt */
         /* Items */
         $printer->setJustification(Escpos::JUSTIFY_LEFT);
         $printer->setEmphasis(true);
         $printer->setTextSize(2, 1);
         $rr = "RECEIPT NO :" . $receipt . "\n";
         $printer->text($rr);
         //$printer -> feed();
         $printer->text("V. TYPE    :" . $parktype . "\n");
         $printer->feed();
         $printer->setTextSize(2, 2);
         $printer->text("V.NO       :" . $noplate . "\n");
         $printer->text("CO. NO     :" . $containerno . "\n");
         $printer->text("VO. NO     :" . $invoiceno . "\n");
         //$printer -> feed();
         //$printer -> setTextSize(2,1);
         $printer->text("IN  DT :" . date('d/m/Y', strtotime($intime)) . "\n");
         $printer->text("IN  TM :" . date('h:i:s', strtotime($intime)) . "\n");
         $printer->setTextSize(2, 2);
         $printer->setTextSize(1, 1);
         $printer->setEmphasis(false);
         $printer->feed();
         /* Tax and total */
         /* Footer */
         //$printer -> feed(1);
         $printer->setJustification(Escpos::JUSTIFY_CENTER);
         $printer->text("PARKING AT OWNERS RISK. MANAGEMENT IS NOT LIABLE\n");
         $printer->text("TO PAY ANY LOSS OR DAMAGE OF ANY VEHICLE OR\n");
         $printer->text("VALUABLE LEFT INSIDE IT\n");
         //$printer -> feed(1);
         //$printer -> text(date('l jS \of F Y h:i:s A') . "\n");
         /* Cut the receipt and open the cash drawer */
         $printer->cut();
         $printer->pulse();
         $printer->close();
     } catch (Exception $e) {
         echo "Couldn't print to this printer: " . $e->getMessage() . "\n";
     }
     /* A wrapper to do organise item names & prices into columns */
     /* Close printer */
 }