function title(Escpos $printer, $text) { $printer->selectPrintMode(Escpos::MODE_EMPHASIZED); $printer->text("\n" . $text); $printer->selectPrintMode(); // Reset }
function title(Escpos $printer, $str) { $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH); $printer->text($str); $printer->selectPrintMode(); }
$printer->text("DEF"); $printer->feedReverse(3); $printer->text("GHI"); $printer->feed(); $printer->cut(); /* Font modes */ $modes = array(Escpos::MODE_FONT_B, Escpos::MODE_EMPHASIZED, Escpos::MODE_DOUBLE_HEIGHT, Escpos::MODE_DOUBLE_WIDTH, Escpos::MODE_UNDERLINE); for ($i = 0; $i < pow(2, count($modes)); $i++) { $bits = str_pad(decbin($i), count($modes), "0", STR_PAD_LEFT); $mode = 0; for ($j = 0; $j < strlen($bits); $j++) { if (substr($bits, $j, 1) == "1") { $mode |= $modes[$j]; } } $printer->selectPrintMode($mode); $printer->text("ABCDEFGHIJabcdefghijk\n"); } $printer->selectPrintMode(); // Reset $printer->cut(); /* Underline */ for ($i = 0; $i < 3; $i++) { $printer->setUnderline($i); $printer->text("The quick brown fox jumps over the lazy dog\n"); } $printer->setUnderline(0); // Reset $printer->cut(); /* Cuts */ $printer->text("Partial cut\n(not available on all printers)\n");
<?php require_once dirname(__FILE__) . "/../Escpos.php"; $printer = new Escpos(); $printer->setBarcodeHeight(40); /* Text position */ $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH); $printer->text("Text position\n"); $printer->selectPrintMode(); $hri = array(Escpos::BARCODE_TEXT_NONE => "No text", Escpos::BARCODE_TEXT_ABOVE => "Above", Escpos::BARCODE_TEXT_BELOW => "Below", Escpos::BARCODE_TEXT_ABOVE | Escpos::BARCODE_TEXT_BELOW => "Both"); foreach ($hri as $position => $caption) { $printer->text($caption . "\n"); $printer->setBarcodeTextPosition($position); $printer->barcode("012345678901", Escpos::BARCODE_JAN13); $printer->feed(); } /* Barcode types */ $standards = array(Escpos::BARCODE_UPCA => array("title" => "UPC-A", "caption" => "Fixed-length numeric product barcodes.", "example" => array(array("caption" => "12 char numeric including (wrong) check digit.", "content" => "012345678901"), array("caption" => "Send 11 chars to add check digit automatically.", "content" => "01234567890"))), Escpos::BARCODE_UPCE => array("title" => "UPC-E", "caption" => "Fixed-length numeric compact product barcodes.", "example" => array(array("caption" => "6 char numeric - auto check digit & NSC", "content" => "123456"), array("caption" => "7 char numeric - auto check digit", "content" => "0123456"), array("caption" => "8 char numeric", "content" => "01234567"), array("caption" => "11 char numeric - auto check digit", "content" => "01234567890"), array("caption" => "12 char numeric including (wrong) check digit", "content" => "012345678901"))), Escpos::BARCODE_JAN13 => array("title" => "JAN13/EAN13", "caption" => "Fixed-length numeric barcodes.", "example" => array(array("caption" => "12 char numeric - auto check digit", "content" => "012345678901"), array("caption" => "13 char numeric including (wrong) check digit", "content" => "0123456789012"))), Escpos::BARCODE_JAN8 => array("title" => "JAN8/EAN8", "caption" => "Fixed-length numeric barcodes.", "example" => array(array("caption" => "7 char numeric - auto check digit", "content" => "0123456"), array("caption" => "8 char numeric including (wrong) check digit", "content" => "01234567"))), Escpos::BARCODE_CODE39 => array("title" => "Code39", "caption" => "Variable length alphanumeric w/ some special chars.", "example" => array(array("caption" => "Text, numbers, spaces", "content" => "ABC 012"), array("caption" => "Special characters", "content" => "\$%+-./"), array("caption" => "Extra char (*) Used as start/stop", "content" => "*TEXT*"))), Escpos::BARCODE_ITF => array("title" => "ITF", "caption" => "Variable length numeric w/even number of digits,\nas they are encoded in pairs.", "example" => array(array("caption" => "Numeric- even number of digits", "content" => "0123456789"))), Escpos::BARCODE_CODABAR => array("title" => "Codabar", "caption" => "Varaible length numeric with some allowable\nextra characters. ABCD/abcd must be used as\nstart/stop characters (one at the start, one\nat the end) to distinguish between barcode\napplications.", "example" => array(array("caption" => "Numeric w/ A A start/stop. ", "content" => "A012345A"), array("caption" => "Extra allowable characters", "content" => "A012\$+-./:A"))), Escpos::BARCODE_CODE93 => array("title" => "Code93", "caption" => "Variable length- any ASCII is available", "example" => array(array("caption" => "Text", "content" => "012abcd"))), Escpos::BARCODE_CODE128 => array("title" => "Code128", "caption" => "Variable length- any ASCII is available", "example" => array(array("caption" => "Code set A uppercase & symbols", "content" => "{A" . "012ABCD"), array("caption" => "Code set B general text", "content" => "{B" . "012ABCDabcd"), array("caption" => "Code set C compact numbers\n Sending chr(21) chr(32) chr(43)", "content" => "{C" . chr(21) . chr(32) . chr(43))))); $printer->setBarcodeTextPosition(Escpos::BARCODE_TEXT_BELOW); foreach ($standards as $type => $standard) { $printer->selectPrintMode(Escpos::MODE_DOUBLE_HEIGHT | Escpos::MODE_DOUBLE_WIDTH); $printer->text($standard["title"] . "\n"); $printer->selectPrintMode(); $printer->text($standard["caption"] . "\n\n"); foreach ($standard["example"] as $id => $barcode) { $printer->setEmphasis(true); $printer->text($barcode["caption"] . "\n"); $printer->setEmphasis(false); $printer->text("Content: " . $barcode["content"] . "\n"); $printer->barcode($barcode["content"], $type); $printer->feed();
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 */ }
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 */ }