108 require_once DOL_DOCUMENT_ROOT.
'/includes/mike42/escpos-php/autoload.php';
109 use Mike42\Escpos\PrintConnectors\FilePrintConnector;
110 use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
111 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
112 use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
113 use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
114 use Mike42\Escpos\CapabilityProfile;
115 use Mike42\Escpos\Printer;
116 use Mike42\Escpos\EscposImage;
123 const CONNECTOR_DUMMY = 1;
124 const CONNECTOR_FILE_PRINT = 2;
125 const CONNECTOR_NETWORK_PRINT = 3;
126 const CONNECTOR_WINDOWS_PRINT = 4;
127 const CONNECTOR_CUPS_PRINT = 5;
145 public $orderprinter;
151 public $listprinters;
157 public $listprinterstemplates;
167 public $errors = array();
178 'dol_line_feed' =>
'DOL_LINE_FEED',
179 'dol_line_feed_reverse' =>
'DOL_LINE_FEED_REVERSE',
180 'dol_align_left' =>
'DOL_ALIGN_LEFT',
181 'dol_align_center' =>
'DOL_ALIGN_CENTER',
182 'dol_align_right' =>
'DOL_ALIGN_RIGHT',
183 'dol_use_font_a' =>
'DOL_USE_FONT_A',
184 'dol_use_font_b' =>
'DOL_USE_FONT_B',
185 'dol_use_font_c' =>
'DOL_USE_FONT_C',
186 'dol_bold' =>
'DOL_BOLD',
187 'dol_bold_disabled' =>
'DOL_BOLD_DISABLED',
188 'dol_double_height' =>
'DOL_DOUBLE_HEIGHT',
189 'dol_double_width' =>
'DOL_DOUBLE_WIDTH',
190 'dol_default_height_width' =>
'DOL_DEFAULT_HEIGHT_WIDTH',
191 'dol_underline' =>
'DOL_UNDERLINE',
192 'dol_underline_disabled' =>
'DOL_UNDERLINE_DISABLED',
193 'dol_cut_paper_full' =>
'DOL_CUT_PAPER_FULL',
194 'dol_cut_paper_partial' =>
'DOL_CUT_PAPER_PARTIAL',
195 'dol_open_drawer' =>
'DOL_OPEN_DRAWER',
196 'dol_beep' =>
'DOL_BEEP',
197 'dol_beep_alternative' =>
'DOL_BEEP_ALTERNATIVE',
198 'dol_print_text' =>
'DOL_PRINT_TEXT',
199 'dol_print_barcode' =>
'DOL_PRINT_BARCODE',
200 'dol_value_date' =>
'DateInvoice',
201 'dol_value_date_time' =>
'DateInvoiceWithTime',
202 'dol_value_year' =>
'YearInvoice',
203 'dol_value_month_letters' =>
'DOL_VALUE_MONTH_LETTERS',
204 'dol_value_month' =>
'DOL_VALUE_MONTH',
205 'dol_value_day' =>
'DOL_VALUE_DAY',
206 'dol_value_day_letters' =>
'DOL_VALUE_DAY',
207 'dol_value_currentdate' =>
'DOL_VALUE_CURRENTDATE',
208 'dol_value_currentdate_notime' =>
'CurrentDateWithTime',
209 'dol_value_currentdate_letters' =>
'DOL_VALUE_CURRENTDATE_LETTERS',
210 'dol_value_currentyear' =>
'CurrentYear',
211 'dol_value_currentmonth_letters' =>
'DOL_VALUE_CURRENT_MONTH_LETTERS',
212 'dol_value_currentmonth' =>
'DOL_VALUE_CURRENT_MONTH',
213 'dol_value_currentday' =>
'DOL_VALUE_CURRENT_DAY',
214 'dol_value_currentday_letters' =>
'DOL_VALUE_CURRENT_DAY',
215 'dol_print_payment' =>
'DOL_PRINT_PAYMENT',
216 'dol_print_curr_date' =>
'DOL_PRINT_CURR_DATE',
217 'dol_print_logo' =>
'DOL_PRINT_LOGO',
218 'dol_print_logo_old' =>
'DOL_PRINT_LOGO_OLD',
219 'dol_print_logo_old_cf' =>
'DOL_PRINT_LOGO_OLD_CF',
220 'dol_value_object_id' =>
'InvoiceID',
221 'dol_value_object_ref' =>
'InvoiceRef',
222 'dol_print_object_lines' =>
'DOL_PRINT_OBJECT_LINES',
223 'dol_print_object_lines_with_notes' =>
'DOL_PRINT_OBJECT_LINES_WITH_NOTES',
224 'dol_print_object_tax' =>
'TotalVAT',
225 'dol_print_object_local_tax1' =>
'TotalLT1',
226 'dol_print_object_local_tax2' =>
'TotalLT2',
227 'dol_print_object_total' =>
'Total',
228 'dol_print_object_number' =>
'DOL_PRINT_OBJECT_NUMBER',
230 'dol_print_order_lines' =>
'DOL_PRINT_ORDER_LINES',
231 'dol_value_customer_firstname' =>
'DOL_VALUE_CUSTOMER_FIRSTNAME',
232 'dol_value_customer_lastname' =>
'DOL_VALUE_CUSTOMER_LASTNAME',
233 'dol_value_customer_mail' =>
'DOL_VALUE_CUSTOMER_MAIL',
234 'dol_value_customer_phone' =>
'DOL_VALUE_CUSTOMER_PHONE',
235 'dol_value_customer_skype' =>
'DOL_VALUE_CUSTOMER_SKYPE',
236 'dol_value_customer_tax_number' =>
'DOL_VALUE_CUSTOMER_TAX_NUMBER',
239 'dol_value_mysoc_name' =>
'DOL_VALUE_MYSOC_NAME',
240 'dol_value_mysoc_address' =>
'Address',
241 'dol_value_mysoc_zip' =>
'Zip',
242 'dol_value_mysoc_town' =>
'Town',
243 'dol_value_mysoc_country' =>
'Country',
244 'dol_value_mysoc_idprof1' =>
'ProfId1',
245 'dol_value_mysoc_idprof2' =>
'ProfId2',
246 'dol_value_mysoc_idprof3' =>
'ProfId3',
247 'dol_value_mysoc_idprof4' =>
'ProfId4',
248 'dol_value_mysoc_idprof5' =>
'ProfId5',
249 'dol_value_mysoc_idprof6' =>
'ProfId6',
250 'dol_value_mysoc_tva_intra' =>
'VATIntra',
251 'dol_value_mysoc_capital' =>
'Capital',
252 'dol_value_mysoc_url' =>
'Web',
253 'dol_value_vendor_lastname' =>
'VendorLastname',
254 'dol_value_vendor_firstname' =>
'VendorFirstname',
255 'dol_value_vendor_mail' =>
'VendorEmail',
256 'dol_value_place' =>
'DOL_VALUE_PLACE',
273 $sql =
"SELECT rowid, name, fk_type, fk_profile, parameter";
274 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt";
275 $sql .=
" WHERE entity = ".((int) $conf->entity);
277 $resql = $this->db->query(
$sql);
280 $num = $this->db->num_rows($resql);
281 while ($line < $num) {
282 $row = $this->db->fetch_array($resql);
283 switch ($row[
'fk_type']) {
285 $row[
'fk_type_name'] =
'CONNECTOR_DUMMY';
288 $row[
'fk_type_name'] =
'CONNECTOR_FILE_PRINT';
291 $row[
'fk_type_name'] =
'CONNECTOR_NETWORK_PRINT';
294 $row[
'fk_type_name'] =
'CONNECTOR_WINDOWS_PRINT';
297 $row[
'fk_type_name'] =
'CONNECTOR_CUPS_PRINT';
300 $row[
'fk_type_name'] =
'CONNECTOR_UNKNOWN';
303 switch ($row[
'fk_profile']) {
305 $row[
'fk_profile_name'] =
'PROFILE_DEFAULT';
308 $row[
'fk_profile_name'] =
'PROFILE_SIMPLE';
311 $row[
'fk_profile_name'] =
'PROFILE_EPOSTEP';
314 $row[
'fk_profile_name'] =
'PROFILE_P822D';
317 $row[
'fk_profile_name'] =
'PROFILE_STAR';
325 $this->errors[] = $this->db->lasterror;
328 $this->listprinters = $obj;
347 $sql =
"SELECT rowid, name, template";
348 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt_template";
349 $sql .=
" WHERE entity = ".$conf->entity;
351 $resql = $this->db->query(
$sql);
354 $num = $this->db->num_rows($resql);
355 while ($line < $num) {
356 $obj[] = $this->db->fetch_array($resql);
361 $this->errors[] = $this->db->lasterror;
364 $this->listprinterstemplates = $obj;
382 1 => $langs->trans(
'CONNECTOR_DUMMY'),
383 2 => $langs->trans(
'CONNECTOR_FILE_PRINT'),
384 3 => $langs->trans(
'CONNECTOR_NETWORK_PRINT'),
385 4 => $langs->trans(
'CONNECTOR_WINDOWS_PRINT'),
386 5 => $langs->trans(
'CONNECTOR_CUPS_PRINT'),
407 0 => $langs->trans(
'PROFILE_DEFAULT'),
408 1 => $langs->trans(
'PROFILE_SIMPLE'),
409 2 => $langs->trans(
'PROFILE_EPOSTEP'),
410 3 => $langs->trans(
'PROFILE_P822D'),
411 4 => $langs->trans(
'PROFILE_STAR'),
428 public function addPrinter($name, $type, $profile, $parameter)
432 $sql =
"INSERT INTO ".$this->db->prefix().
"printer_receipt";
433 $sql .=
" (name, fk_type, fk_profile, parameter, entity)";
434 $sql .=
" VALUES ('".$this->db->escape($name).
"', ".((int) $type).
", ".((int) $profile).
", '".$this->db->escape($parameter).
"', ".((int) $conf->entity).
")";
435 $resql = $this->db->query(
$sql);
438 $this->errors[] = $this->db->lasterror;
453 public function updatePrinter($name, $type, $profile, $parameter, $printerid)
458 $sql =
"UPDATE ".$this->db->prefix().
"printer_receipt";
459 $sql .=
" SET name='".$this->db->escape($name).
"'";
460 $sql .=
", fk_type=".((int) $type);
461 $sql .=
", fk_profile=".((int) $profile);
462 $sql .=
", parameter='".$this->db->escape($parameter).
"'";
463 $sql .=
" WHERE rowid=".((int) $printerid);
465 $resql = $this->db->query(
$sql);
468 $this->errors[] = $this->db->lasterror;
483 $sql =
'DELETE FROM '.$this->db->prefix().
'printer_receipt';
484 $sql .=
' WHERE rowid='.((int) $printerid);
485 $resql = $this->db->query(
$sql);
488 $this->errors[] = $this->db->lasterror;
504 $sql =
"INSERT INTO ".$this->db->prefix().
"printer_receipt_template";
505 $sql .=
" (name, template, entity) VALUES ('".$this->db->escape($name).
"'";
506 $sql .=
", '".$this->db->escape($template).
"', ".$conf->entity.
")";
507 $resql = $this->db->query(
$sql);
510 $this->errors[] = $this->db->lasterror;
525 $sql =
'DELETE FROM '.$this->db->prefix().
'printer_receipt_template';
526 $sql .=
" WHERE rowid = ".((int) $templateid);
527 $sql .=
" AND entity = ".$conf->entity;
528 $resql = $this->db->query(
$sql);
531 $this->errors[] = $this->db->lasterror;
549 $sql =
"UPDATE ".$this->db->prefix().
"printer_receipt_template";
550 $sql .=
" SET name='".$this->db->escape($name).
"'";
551 $sql .=
", template='".$this->db->escape($template).
"'";
552 $sql .=
" WHERE rowid=".((int) $templateid);
553 $resql = $this->db->query(
$sql);
556 $this->errors[] = $this->db->lasterror;
573 $img = EscposImage::load(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo_bw.png');
580 $this->printer->bitImage($img);
581 $this->printer->text(
"Hello World!\n");
582 $testStr =
"1234567890";
583 $this->printer->barcode($testStr);
585 $this->printer->text(
"Most simple example\n");
586 $this->printer->feed();
587 $this->printer->cut();
590 if ($this->printer->connector instanceof DummyPrintConnector) {
591 $data = $this->printer->connector->getData();
594 $this->printer->close();
596 $this->errors[] = $e->getMessage();
613 global $conf, $mysoc, $langs, $user;
615 $langs->load(
'bills');
621 $this->
template = str_replace(
'{dol_value_object_id}', $object->id, $this->template);
622 $this->
template = str_replace(
'{dol_value_object_ref}', $object->ref, $this->template);
624 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date($object->date,
'day'), $this->template);
625 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date($object->date,
'dayhour'), $this->template);
626 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date($object->date,
'%Y'), $this->template);
627 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date($object->date,
'%m')), $this->template);
628 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date($object->date,
'%m'), $this->template);
629 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date($object->date,
'%d'), $this->template);
630 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date($object->date,
'%m')[1]), $this->template);
632 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
633 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
634 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
635 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
636 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
637 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
638 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
639 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
641 $this->
template = str_replace(
'{dol_value_customer_firstname}', $object->thirdparty->firstname, $this->template);
642 $this->
template = str_replace(
'{dol_value_customer_lastname}', $object->thirdparty->lastname, $this->template);
643 $this->
template = str_replace(
'{dol_value_customer_mail}', $object->thirdparty->email, $this->template);
644 $this->
template = str_replace(
'{dol_value_customer_phone}', $object->thirdparty->phone, $this->template);
646 $this->
template = str_replace(
'{dol_value_customer_tax_number}', $object->thirdparty->tva_intra, $this->template);
650 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
651 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
652 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
653 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
654 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
655 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
656 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
657 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
658 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
659 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
660 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
661 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
662 $this->
template = str_replace(
'{dol_value_mysoc_capital}', $mysoc->capital, $this->template);
663 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
665 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
666 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
667 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
670 $this->
template = str_replace(
"{",
"<", $this->
template);
671 $this->
template = str_replace(
"}",
">", $this->
template);
672 $p = xml_parser_create();
673 xml_parse_into_struct($p, $this->
template, $vals, $index);
679 $nbcharactbyline = (!empty($conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE) ? $conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE : 48);
684 $nboflines = count($vals);
685 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
687 switch ($vals[$tplline][
'tag']) {
688 case 'DOL_PRINT_TEXT':
689 $this->printer->text($vals[$tplline][
'value']);
691 case 'DOL_PRINT_OBJECT_LINES':
692 foreach ($object->lines as $line) {
693 if ($line->fk_product) {
694 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
695 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
696 $this->printer->text($line->ref . $spaces . $line->qty . str_pad(
price($line->subprice), 10,
' ', STR_PAD_LEFT) .
' ' . str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT) .
"\n");
697 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
699 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
700 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
701 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->subprice), 10,
' ', STR_PAD_LEFT).
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
705 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
706 foreach ($object->lines as $line) {
707 if ($line->fk_product) {
708 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
709 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
710 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
711 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
712 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
713 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
714 $this->printer->text($line->description.
"\n");
716 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
717 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
718 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
722 case 'DOL_PRINT_OBJECT_TAX':
725 foreach ($object->lines as $line) {
726 $vatarray[$line->tva_tx] += $line->total_tva;
728 foreach ($vatarray as $vatkey => $vatvalue) {
729 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
730 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
731 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
734 case 'DOL_PRINT_OBJECT_TAX1':
736 $total_localtax1 = 0;
737 foreach ($object->lines as $line) {
738 $total_localtax1 += $line->total_localtax1;
740 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
742 case 'DOL_PRINT_OBJECT_TAX2':
744 $total_localtax2 = 0;
745 foreach ($object->lines as $line) {
746 $total_localtax2 += $line->total_localtax2;
748 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
750 case 'DOL_PRINT_OBJECT_TOTAL':
751 $title = $langs->trans(
'TotalHT');
752 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
753 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
754 $this->printer->text($title.$spaces.str_pad(
price($object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
755 $title = $langs->trans(
'TotalVAT');
756 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
757 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
758 $this->printer->text($title.$spaces.str_pad(
price($object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
759 $title = $langs->trans(
'TotalTTC');
760 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
761 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
762 $this->printer->text($title.$spaces.str_pad(
price($object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
764 case 'DOL_PRINT_CURR_DATE':
765 if (strlen($vals[$tplline][
'value'])<2) $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
766 else $this->printer->text(date($vals[$tplline][
'value']).
"\n");
768 case 'DOL_LINE_FEED':
769 $this->printer->feed();
771 case 'DOL_LINE_FEED_REVERSE':
772 $this->printer->feedReverse();
774 case 'DOL_ALIGN_CENTER':
775 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
777 case 'DOL_ALIGN_RIGHT':
778 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
780 case 'DOL_ALIGN_LEFT':
781 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
783 case 'DOL_OPEN_DRAWER':
784 $this->printer->pulse();
786 case 'DOL_ACTIVATE_BUZZER':
789 case 'DOL_PRINT_BARCODE':
793 $this->printer->barcode($vals[$tplline][
'value']);
795 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
799 case 'DOL_PRINT_LOGO':
800 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
801 $this->printer->graphics($img);
803 case 'DOL_PRINT_LOGO_OLD':
804 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
805 $this->printer->bitImage($img);
807 case 'DOL_PRINT_LOGO_OLD_CF':
808 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
809 $this->printer->bitImageColumnFormat($img);
811 case 'DOL_PRINT_QRCODE':
813 $this->printer->qrcode($vals[$tplline][
'value']);
815 case 'DOL_CUT_PAPER_FULL':
816 $this->printer->cut(Printer::CUT_FULL);
818 case 'DOL_CUT_PAPER_PARTIAL':
819 $this->printer->cut(Printer::CUT_PARTIAL);
821 case 'DOL_USE_FONT_A':
822 $this->printer->setFont(Printer::FONT_A);
824 case 'DOL_USE_FONT_B':
825 $this->printer->setFont(Printer::FONT_B);
827 case 'DOL_USE_FONT_C':
828 $this->printer->setFont(Printer::FONT_C);
831 $this->printer->setEmphasis(
true);
833 case 'DOL_BOLD_DISABLED':
834 $this->printer->setEmphasis(
false);
836 case 'DOL_DOUBLE_HEIGHT':
837 $this->printer->setTextSize(1, 2);
839 case 'DOL_DOUBLE_WIDTH':
840 $this->printer->setTextSize(2, 1);
842 case 'DOL_DEFAULT_HEIGHT_WIDTH':
843 $this->printer->setTextSize(1, 1);
845 case 'DOL_UNDERLINE':
846 $this->printer->setUnderline(
true);
848 case 'DOL_UNDERLINE_DISABLED':
849 $this->printer->setUnderline(
false);
852 $this->printer->getPrintConnector() -> write(
"\x1e");
854 case 'DOL_BEEP_ALTERNATIVE':
855 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
857 case 'DOL_PRINT_ORDER_LINES':
858 foreach ($object->lines as $line) {
859 if ($line->special_code == $this->orderprinter) {
860 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
861 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
862 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
863 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
867 case 'DOL_PRINT_PAYMENT':
868 $sql =
"SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,";
870 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
871 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
872 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
873 $sql .=
" ORDER BY p.datep";
874 $resql = $this->db->query(
$sql);
876 $num = $this->db->num_rows($resql);
879 $row = $this->db->fetch_object($resql);
880 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
881 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
882 $amount_payment = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
883 if ($row->code ==
"LIQ") {
884 $amount_payment = $amount_payment + $row->pos_change;
886 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
887 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
888 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
889 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
890 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
896 case 'DOL_VALUE_PLACE':
897 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $object->ref)));
898 $resql = $this->db->query(
$sql);
899 $obj = $this->db->fetch_object($resql);
901 $this->printer->text($obj->label);
905 $this->printer->text($vals[$tplline][
'tag']);
906 $this->printer->text($vals[$tplline][
'value']);
907 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
913 if ($this->printer->connector instanceof DummyPrintConnector || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
914 $data = $this->printer->connector->getData();
915 if ($conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
916 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
921 $this->printer->close();
936 $sql =
"SELECT template";
937 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt_template";
938 $sql .=
" WHERE rowid = ".((int) $templateid);
939 $sql .=
" AND entity = ".$conf->entity;
940 $resql = $this->db->query(
$sql);
942 $obj = $this->db->fetch_array($resql);
945 $this->errors[] = $this->db->lasterror;
949 $this->errors[] =
'TemplateDontExist';
951 $this->
template = $obj[
'0'];
968 $this->connector =
new DummyPrintConnector();
969 $this->printer =
new Printer($this->connector, $this->profile);
973 $sql =
"SELECT rowid, name, fk_type, fk_profile, parameter";
974 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt";
975 $sql .=
" WHERE rowid = ".((int) $printerid);
976 $sql .=
" AND entity = ".((int) $conf->entity);
977 $resql = $this->db->query(
$sql);
979 $obj = $this->db->fetch_array($resql);
982 $this->errors[] =
'PrinterDontExist';
985 $parameter = (isset($obj[
'parameter']) ? $obj[
'parameter'] :
'');
987 $type = $obj[
'fk_type'];
990 $this->connector =
new DummyPrintConnector();
993 $this->connector =
new FilePrintConnector($parameter);
996 $parameters = explode(
':', $parameter);
997 $this->connector =
new NetworkPrintConnector($parameters[0], $parameters[1]);
1003 $this->connector =
new CupsPrintConnector($parameter);
1006 $this->connector =
'CONNECTOR_UNKNOWN';
1009 $this->printer =
new Printer($this->connector, $this->profile);
1011 $this->errors[] = $e->getMessage();
1017 $this->errors[] = $this->db->lasterror;