625 global $mysoc, $langs, $user;
628 $langs->load(
'bills');
635 $this->
template = str_replace(
'{dol_value_object_id}', $object->id, $this->template);
636 $this->
template = str_replace(
'{dol_value_object_ref}', $object->ref, $this->template);
638 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date($object->date,
'day'), $this->template);
639 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date($object->date,
'dayhour'), $this->template);
640 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date($object->date,
'%Y'), $this->template);
641 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date($object->date,
'%m')), $this->template);
642 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date($object->date,
'%m'), $this->template);
643 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date($object->date,
'%d'), $this->template);
644 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date($object->date,
'%m')[1]), $this->template);
646 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
647 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
648 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
649 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
650 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
651 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
652 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
653 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
655 $this->
template = str_replace(
'{dol_value_customer_firstname}', $object->thirdparty->firstname, $this->template);
656 $this->
template = str_replace(
'{dol_value_customer_lastname}', $object->thirdparty->lastname, $this->template);
657 $this->
template = str_replace(
'{dol_value_customer_mail}', $object->thirdparty->email, $this->template);
658 $this->
template = str_replace(
'{dol_value_customer_phone}', $object->thirdparty->phone, $this->template);
660 $this->
template = str_replace(
'{dol_value_customer_tax_number}', $object->thirdparty->tva_intra, $this->template);
664 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
665 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
666 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
667 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
668 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
669 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
670 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
671 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
672 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
673 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
674 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
675 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
676 $this->
template = str_replace(
'{dol_value_mysoc_capital}', $mysoc->capital, $this->template);
677 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
679 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
680 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
681 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
683 $parameters = array(
'object' => $object);
685 $reshook = $hookmanager->executeHooks(
'sendToPrinterBefore', $parameters, $this, $action);
687 $this->error =
"Error in hook dolReceiptPrinter sendToPrinterBefore ".$reshook;
688 dol_syslog(
"dolReceiptPrinter::sendToPrinter: error=".$this->error, LOG_ERR);
693 $this->
template = str_replace(
"{",
"<", $this->
template);
694 $this->
template = str_replace(
"}",
">", $this->
template);
696 if (LIBXML_VERSION < 20900) {
699 libxml_disable_entity_loader(
true);
705 $p = xml_parser_create();
706 xml_parse_into_struct($p, $this->
template, $vals, $index);
712 $nbcharactbyline =
getDolGlobalInt(
'RECEIPT_PRINTER_NB_CHARACT_BY_LINE', 48);
718 $nboflines = count($vals);
719 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
721 switch ($vals[$tplline][
'tag']) {
722 case 'DOL_PRINT_TEXT':
723 $this->printer->text($vals[$tplline][
'value']);
725 case 'DOL_PRINT_OBJECT_LINES':
726 foreach ($object->lines as $line) {
727 if ($line->fk_product) {
728 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
729 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
730 $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");
731 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
733 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
734 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
735 $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");
739 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
740 foreach ($object->lines as $line) {
741 if ($line->fk_product) {
742 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
743 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
744 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
745 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
746 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
747 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
748 $this->printer->text($line->description.
"\n");
750 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
751 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
752 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
756 case 'DOL_PRINT_OBJECT_TAX':
759 foreach ($object->lines as $line) {
760 $vatarray[$line->tva_tx] += $line->total_tva;
762 foreach ($vatarray as $vatkey => $vatvalue) {
763 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
764 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
765 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
768 case 'DOL_PRINT_OBJECT_TAX1':
770 $total_localtax1 = 0;
771 foreach ($object->lines as $line) {
772 $total_localtax1 += $line->total_localtax1;
774 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
776 case 'DOL_PRINT_OBJECT_TAX2':
778 $total_localtax2 = 0;
779 foreach ($object->lines as $line) {
780 $total_localtax2 += $line->total_localtax2;
782 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
784 case 'DOL_PRINT_OBJECT_TOTAL':
785 $title = $langs->trans(
'TotalHT');
786 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
787 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
788 $this->printer->text($title.$spaces.str_pad(
price($object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
789 $title = $langs->trans(
'TotalVAT');
790 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
791 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
792 $this->printer->text($title.$spaces.str_pad(
price($object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
793 $title = $langs->trans(
'TotalTTC');
794 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
795 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
796 $this->printer->text($title.$spaces.str_pad(
price($object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
798 case 'DOL_PRINT_CURR_DATE':
799 if (strlen($vals[$tplline][
'value'])<2) {
800 $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
802 $this->printer->text(date($vals[$tplline][
'value']).
"\n");
805 case 'DOL_LINE_FEED':
806 $this->printer->feed();
808 case 'DOL_LINE_FEED_REVERSE':
809 $this->printer->feedReverse();
811 case 'DOL_ALIGN_CENTER':
812 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
814 case 'DOL_ALIGN_RIGHT':
815 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
817 case 'DOL_ALIGN_LEFT':
818 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
820 case 'DOL_OPEN_DRAWER':
821 $this->printer->pulse();
823 case 'DOL_ACTIVATE_BUZZER':
826 case 'DOL_PRINT_BARCODE':
830 $this->printer->barcode($vals[$tplline][
'value']);
832 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
836 case 'DOL_PRINT_LOGO':
837 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
838 $this->printer->graphics($img);
840 case 'DOL_PRINT_LOGO_OLD':
841 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
842 $this->printer->bitImage($img);
844 case 'DOL_PRINT_LOGO_OLD_CF':
845 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
846 $this->printer->bitImageColumnFormat($img);
848 case 'DOL_PRINT_QRCODE':
850 $this->printer->qrcode($vals[$tplline][
'value']);
852 case 'DOL_CUT_PAPER_FULL':
853 $this->printer->cut(Printer::CUT_FULL);
855 case 'DOL_CUT_PAPER_PARTIAL':
856 $this->printer->cut(Printer::CUT_PARTIAL);
858 case 'DOL_USE_FONT_A':
859 $this->printer->setFont(Printer::FONT_A);
861 case 'DOL_USE_FONT_B':
862 $this->printer->setFont(Printer::FONT_B);
864 case 'DOL_USE_FONT_C':
865 $this->printer->setFont(Printer::FONT_C);
868 $this->printer->setEmphasis(
true);
870 case 'DOL_BOLD_DISABLED':
871 $this->printer->setEmphasis(
false);
873 case 'DOL_DOUBLE_HEIGHT':
874 $this->printer->setTextSize(1, 2);
876 case 'DOL_DOUBLE_WIDTH':
877 $this->printer->setTextSize(2, 1);
879 case 'DOL_DEFAULT_HEIGHT_WIDTH':
880 $this->printer->setTextSize(1, 1);
882 case 'DOL_UNDERLINE':
883 $this->printer->setUnderline(
true);
885 case 'DOL_UNDERLINE_DISABLED':
886 $this->printer->setUnderline(
false);
889 $this->printer->getPrintConnector() -> write(
"\x1e");
891 case 'DOL_BEEP_ALTERNATIVE':
892 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
894 case 'DOL_PRINT_ORDER_LINES':
895 foreach ($object->lines as $line) {
896 if ($line->special_code == $this->orderprinter) {
897 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
898 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
899 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
900 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
904 case 'DOL_PRINT_PAYMENT':
905 $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,";
907 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
908 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
909 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
910 $sql .=
" ORDER BY p.datep";
911 $resql = $this->db->query($sql);
913 $num = $this->db->num_rows($resql);
916 $row = $this->db->fetch_object($resql);
917 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
918 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
919 $amount_payment = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
920 if ($row->code ==
"LIQ") {
921 $amount_payment = $amount_payment + $row->pos_change;
923 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
924 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
925 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
926 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
927 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
933 case 'DOL_VALUE_PLACE':
934 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $object->ref)));
935 $resql = $this->db->query($sql);
936 $obj = $this->db->fetch_object($resql);
938 $this->printer->text($obj->label);
942 $parameters = array(
'vals' => $vals[$tplline],
'object' => $object,
'nbcharactbyline' => $nbcharactbyline);
944 $reshook = $hookmanager->executeHooks(
'sendToPrinterAfter', $parameters, $this, $action);
946 if (!$reshook || $reshook < 0) {
947 $this->printer->text($vals[$tplline][
'tag']);
948 $this->printer->text($vals[$tplline][
'value']);
949 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
956 if ($this->printer->connector instanceof DummyPrintConnector ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"takeposconnector") {
957 $data = $this->printer->connector->getData();
959 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
964 $this->printer->close();