642 global
$mysoc, $langs, $user;
645 $langs->load(
'bills');
649 include_once DOL_DOCUMENT_ROOT.
'/blockedlog/lib/blockedlog.lib.php';
665 if (empty($templateid) || $islneverion) {
667 $this->
template =
"{dol_align_center}\r\n";
668 $this->
template .=
"{dol_print_text}{dol_value_mysoc_name}\r\n";
669 $this->
template .=
"{dol_print_text}{dol_value_mysoc_address}\r\n";
670 $this->
template .=
"{dol_print_text}{dol_value_mysoc_zip}{dol_value_mysoc_town}\r\n";
671 $this->
template .=
"{dol_print_text}{dol_value_mysoc_idprof1}\r\n";
672 $this->
template .=
"{dol_print_text}{dol_value_mysoc_vatnumber}\r\n";
673 $this->
template .=
"{dol_line_feed}\r\n";
674 $this->
template .=
"{dol_print_text}".$langs->transnoentitiesnoconv(
"Invoice").
" {dol_value_object_ref}\r\n";
676 $this->
template .=
"{dol_print_text}*** ".$langs->transnoentities(
"TemporaryReceipt").
" ***\r\n";
678 if (
$object->pos_print_counter > 1) {
679 $this->
template .=
"{dol_print_text}*** ".$langs->transnoentities(
"DUPLICATA");
681 $this->
template .=
' (no '.($object->pos_print_counter - 1).
') ***';
683 $this->
template .=
"\r\n";
686 $this->
template .=
"{dol_value_date}\r\n";
687 $this->
template .=
"{dol_value_currentdate}\r\n";
688 $this->
template .=
"{dol_value_signaturehashstart}\r\n";
689 $this->
template .=
"{dol_line_feed}\r\n";
690 $this->
template .=
"{dol_align_left}\r\n";
691 $this->
template .=
"{dol_print_object_lines}\r\n";
692 $this->
template .=
"{dol_line_feed}\r\n";
693 $this->
template .=
"{dol_print_object_tax}\r\n";
694 $this->
template .=
"{dol_line_feed}\r\n";
695 $this->
template .=
"{dol_print_object_total}\r\n";
696 $this->
template .=
"{dol_line_feed}\r\n";
698 $this->
template .=
"{dol_value_lnemention}\r\n";
699 $this->
template .=
"{dol_line_feed}\r\n";
701 $this->
template .=
"{dol_cut_paper_full}";
706 $this->
template = str_replace(
'{dol_value_object_id}', (
string)
$object->id, $this->template);
707 $this->
template = str_replace(
'{dol_value_object_ref}',
$object->ref, $this->template);
709 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date(
$object->date,
'day'), $this->template);
710 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date(
$object->date,
'dayhour'), $this->template);
711 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date(
$object->date,
'%Y'), $this->template);
712 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date(
$object->date,
'%m')), $this->template);
713 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date(
$object->date,
'%m'), $this->template);
714 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date(
$object->date,
'%d'), $this->template);
715 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date(
$object->date,
'%m')[1]), $this->template);
717 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
718 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
719 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
720 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
721 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
722 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
723 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
724 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
726 $this->
template = str_replace(
'{dol_value_customer_firstname}',
$object->thirdparty->firstname, $this->template);
727 $this->
template = str_replace(
'{dol_value_customer_lastname}',
$object->thirdparty->lastname, $this->template);
728 $this->
template = str_replace(
'{dol_value_customer_mail}',
$object->thirdparty->email, $this->template);
729 $this->
template = str_replace(
'{dol_value_customer_phone}',
$object->thirdparty->phone, $this->template);
731 $this->
template = str_replace(
'{dol_value_customer_tax_number}',
$object->thirdparty->tva_intra, $this->template);
735 $this->
template = str_replace(
'{dol_value_mysoc_name}',
$mysoc->name, $this->template);
736 $this->
template = str_replace(
'{dol_value_mysoc_address}',
$mysoc->address, $this->template);
737 $this->
template = str_replace(
'{dol_value_mysoc_zip}',
$mysoc->zip, $this->template);
738 $this->
template = str_replace(
'{dol_value_mysoc_town}',
$mysoc->town, $this->template);
739 $this->
template = str_replace(
'{dol_value_mysoc_country}',
$mysoc->country, $this->template);
740 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}',
$mysoc->idprof1, $this->template);
741 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}',
$mysoc->idprof2, $this->template);
742 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}',
$mysoc->idprof3, $this->template);
743 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}',
$mysoc->idprof4, $this->template);
744 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}',
$mysoc->idprof5, $this->template);
745 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}',
$mysoc->idprof6, $this->template);
746 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}',
$mysoc->tva_intra, $this->template);
747 $this->
template = str_replace(
'{dol_value_mysoc_capital}', (
string)
$mysoc->capital, $this->template);
748 $this->
template = str_replace(
'{dol_value_mysoc_url}',
$mysoc->url, $this->template);
750 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
751 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
752 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
754 $parameters = array(
'object' =>
$object);
756 $reshook = $hookmanager->executeHooks(
'sendToPrinterBefore', $parameters, $this, $action);
758 $this->error =
"Error in hook dolReceiptPrinter sendToPrinterBefore ".$reshook;
759 dol_syslog(
"dolReceiptPrinter::sendToPrinter: error=".$this->error, LOG_ERR);
764 $this->
template = htmlspecialchars($this->
template, ENT_QUOTES | ENT_XML1);
767 $this->
template = str_replace(
"{",
"<", $this->
template);
768 $this->
template = str_replace(
"}",
">", $this->
template);
770 if (LIBXML_VERSION < 20900) {
774 libxml_disable_entity_loader(
true);
780 $p = xml_parser_create();
781 xml_parse_into_struct($p, $this->
template, $vals, $index);
787 $nbcharactbyline =
getDolGlobalInt(
'RECEIPT_PRINTER_NB_CHARACT_BY_LINE', 48);
797 $nboflines = count($vals);
798 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
800 switch ($vals[$tplline][
'tag']) {
801 case 'DOL_PRINT_TEXT':
802 $this->printer->text($vals[$tplline][
'value']);
804 case 'DOL_PRINT_OBJECT_LINES':
805 foreach (
$object->lines as $line) {
806 if ($line->fk_product) {
807 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
808 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
809 $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");
810 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
812 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
813 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
814 $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");
818 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
819 foreach (
$object->lines as $line) {
820 if ($line->fk_product) {
821 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
822 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
823 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
824 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
825 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
826 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
827 $this->printer->text($line->description.
"\n");
829 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
830 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
831 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
835 case 'DOL_PRINT_OBJECT_TAX':
838 foreach (
$object->lines as $line) {
839 $vat_rate = $line->tva_tx;
840 if (!array_key_exists($vat_rate, $vatarray)) {
841 $vatarray[$vat_rate] = 0;
843 $vatarray[$vat_rate] += $line->total_tva;
845 foreach ($vatarray as $vatkey => $vatvalue) {
846 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
847 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
848 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
851 case 'DOL_PRINT_OBJECT_TAX1':
853 $total_localtax1 = 0;
854 foreach (
$object->lines as $line) {
855 $total_localtax1 += $line->total_localtax1;
857 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
859 case 'DOL_PRINT_OBJECT_TAX2':
861 $total_localtax2 = 0;
862 foreach (
$object->lines as $line) {
863 $total_localtax2 += $line->total_localtax2;
865 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
867 case 'DOL_PRINT_OBJECT_TOTAL':
868 $title = $langs->trans(
'TotalHT');
869 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
870 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
871 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
872 $title = $langs->trans(
'TotalVAT');
873 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
874 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
875 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
876 $title = $langs->trans(
'TotalTTC');
877 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
878 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
879 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
881 case 'DOL_PRINT_CURR_DATE':
882 if (strlen($vals[$tplline][
'value']) < 2) {
883 $this->printer->text(
date(
'd/m/Y H:i:s').
"\n");
885 $this->printer->text(
date($vals[$tplline][
'value']).
"\n");
888 case 'DOL_LINE_FEED':
889 $this->printer->feed();
891 case 'DOL_LINE_FEED_REVERSE':
892 $this->printer->feedReverse();
894 case 'DOL_ALIGN_CENTER':
895 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
897 case 'DOL_ALIGN_RIGHT':
898 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
900 case 'DOL_ALIGN_LEFT':
901 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
903 case 'DOL_OPEN_DRAWER':
904 $this->printer->pulse();
906 case 'DOL_ACTIVATE_BUZZER':
909 case 'DOL_PRINT_BARCODE':
913 $this->printer->barcode($vals[$tplline][
'value']);
915 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
919 case 'DOL_PRINT_LOGO':
920 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.
$mysoc->logo);
921 $this->printer->graphics($img);
923 case 'DOL_PRINT_LOGO_OLD':
924 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.
$mysoc->logo);
925 $this->printer->bitImage($img);
927 case 'DOL_PRINT_LOGO_OLD_CF':
928 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.
$mysoc->logo);
929 $this->printer->bitImageColumnFormat($img);
931 case 'DOL_PRINT_QRCODE':
933 $this->printer->qrcode($vals[$tplline][
'value']);
935 case 'DOL_CUT_PAPER_FULL':
936 $this->printer->cut(Printer::CUT_FULL);
938 case 'DOL_CUT_PAPER_PARTIAL':
939 $this->printer->cut(Printer::CUT_PARTIAL);
941 case 'DOL_USE_FONT_A':
942 $this->printer->setFont(Printer::FONT_A);
944 case 'DOL_USE_FONT_B':
945 $this->printer->setFont(Printer::FONT_B);
947 case 'DOL_USE_FONT_C':
948 $this->printer->setFont(Printer::FONT_C);
951 $this->printer->setEmphasis(
true);
953 case 'DOL_BOLD_DISABLED':
954 $this->printer->setEmphasis(
false);
956 case 'DOL_DOUBLE_HEIGHT':
957 $this->printer->setTextSize(1, 2);
959 case 'DOL_DOUBLE_WIDTH':
960 $this->printer->setTextSize(2, 1);
962 case 'DOL_DEFAULT_HEIGHT_WIDTH':
963 $this->printer->setTextSize(1, 1);
965 case 'DOL_UNDERLINE':
966 $this->printer->setUnderline(1);
968 case 'DOL_UNDERLINE_DISABLED':
969 $this->printer->setUnderline(0);
972 $this->printer->getPrintConnector() -> write(
"\x1e");
974 case 'DOL_BEEP_ALTERNATIVE':
975 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
977 case 'DOL_PRINT_ORDER_LINES':
978 foreach (
$object->lines as $line) {
979 if ($line->special_code == $this->orderprinter) {
980 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
981 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
982 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
983 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
987 case 'DOL_PRINT_PAYMENT':
988 $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,";
990 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
991 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
992 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
993 $sql .=
" ORDER BY p.datep";
994 $resql = $this->db->query($sql);
996 $num = $this->db->num_rows($resql);
999 $row = $this->db->fetch_object($resql);
1000 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
1001 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
1002 $amount_payment = (
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
1003 if ($row->code ==
"LIQ") {
1004 $amount_payment += $row->pos_change;
1006 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
1007 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
1008 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
1009 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
1010 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
1016 case 'DOL_VALUE_PLACE':
1017 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"",
$object->ref)));
1018 $resql = $this->db->query($sql);
1019 $obj = $this->db->fetch_object($resql);
1021 $this->printer->text($obj->label);
1025 $parameters = array(
'vals' => $vals[$tplline],
'object' =>
$object,
'nbcharactbyline' => $nbcharactbyline);
1027 $reshook = $hookmanager->executeHooks(
'sendToPrinterAfter', $parameters, $this, $action);
1029 if (!$reshook || $reshook < 0) {
1030 $this->printer->text($vals[$tplline][
'tag']);
1031 $this->printer->text($vals[$tplline][
'value']);
1032 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
1039 $connector = $this->printer->connector;
1040 if ($connector instanceof DummyPrintConnector ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"takeposconnector") {
1041 $data = $connector->getData();
1043 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
1048 $this->printer->close();