634 global $mysoc, $langs, $user;
637 $langs->load(
'bills');
644 $this->
template = str_replace(
'{dol_value_object_id}', (
string)
$object->id, $this->template);
645 $this->
template = str_replace(
'{dol_value_object_ref}',
$object->ref, $this->template);
647 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date(
$object->date,
'day'), $this->template);
648 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date(
$object->date,
'dayhour'), $this->template);
649 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date(
$object->date,
'%Y'), $this->template);
650 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date(
$object->date,
'%m')), $this->template);
651 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date(
$object->date,
'%m'), $this->template);
652 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date(
$object->date,
'%d'), $this->template);
653 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date(
$object->date,
'%m')[1]), $this->template);
655 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
656 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
657 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
658 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
659 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
660 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
661 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
662 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
664 $this->
template = str_replace(
'{dol_value_customer_firstname}',
$object->thirdparty->firstname, $this->template);
665 $this->
template = str_replace(
'{dol_value_customer_lastname}',
$object->thirdparty->lastname, $this->template);
666 $this->
template = str_replace(
'{dol_value_customer_mail}',
$object->thirdparty->email, $this->template);
667 $this->
template = str_replace(
'{dol_value_customer_phone}',
$object->thirdparty->phone, $this->template);
669 $this->
template = str_replace(
'{dol_value_customer_tax_number}',
$object->thirdparty->tva_intra, $this->template);
673 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
674 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
675 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
676 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
677 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
678 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
679 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
680 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
681 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
682 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
683 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
684 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
685 $this->
template = str_replace(
'{dol_value_mysoc_capital}', (
string) $mysoc->capital, $this->template);
686 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
688 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
689 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
690 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
692 $parameters = array(
'object' =>
$object);
694 $reshook = $hookmanager->executeHooks(
'sendToPrinterBefore', $parameters, $this, $action);
696 $this->error =
"Error in hook dolReceiptPrinter sendToPrinterBefore ".$reshook;
697 dol_syslog(
"dolReceiptPrinter::sendToPrinter: error=".$this->error, LOG_ERR);
702 $this->
template = str_replace(
"{",
"<", $this->
template);
703 $this->
template = str_replace(
"}",
">", $this->
template);
705 if (LIBXML_VERSION < 20900) {
709 libxml_disable_entity_loader(
true);
715 $p = xml_parser_create();
716 xml_parse_into_struct($p, $this->
template, $vals, $index);
722 $nbcharactbyline =
getDolGlobalInt(
'RECEIPT_PRINTER_NB_CHARACT_BY_LINE', 48);
728 $nboflines = count($vals);
729 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
731 switch ($vals[$tplline][
'tag']) {
732 case 'DOL_PRINT_TEXT':
733 $this->printer->text($vals[$tplline][
'value']);
735 case 'DOL_PRINT_OBJECT_LINES':
736 foreach (
$object->lines as $line) {
737 if ($line->fk_product) {
738 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
739 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
740 $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");
741 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
743 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
744 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
745 $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");
749 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
750 foreach (
$object->lines as $line) {
751 if ($line->fk_product) {
752 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
753 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
754 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
755 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
756 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
757 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
758 $this->printer->text($line->description.
"\n");
760 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
761 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
762 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
766 case 'DOL_PRINT_OBJECT_TAX':
769 foreach (
$object->lines as $line) {
770 $vatarray[$line->tva_tx] += $line->total_tva;
772 foreach ($vatarray as $vatkey => $vatvalue) {
773 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
774 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
775 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
778 case 'DOL_PRINT_OBJECT_TAX1':
780 $total_localtax1 = 0;
781 foreach (
$object->lines as $line) {
782 $total_localtax1 += $line->total_localtax1;
784 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
786 case 'DOL_PRINT_OBJECT_TAX2':
788 $total_localtax2 = 0;
789 foreach (
$object->lines as $line) {
790 $total_localtax2 += $line->total_localtax2;
792 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
794 case 'DOL_PRINT_OBJECT_TOTAL':
795 $title = $langs->trans(
'TotalHT');
796 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
797 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
798 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
799 $title = $langs->trans(
'TotalVAT');
800 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
801 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
802 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
803 $title = $langs->trans(
'TotalTTC');
804 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
805 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
806 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
808 case 'DOL_PRINT_CURR_DATE':
809 if (strlen($vals[$tplline][
'value']) < 2) {
810 $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
812 $this->printer->text(date($vals[$tplline][
'value']).
"\n");
815 case 'DOL_LINE_FEED':
816 $this->printer->feed();
818 case 'DOL_LINE_FEED_REVERSE':
819 $this->printer->feedReverse();
821 case 'DOL_ALIGN_CENTER':
822 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
824 case 'DOL_ALIGN_RIGHT':
825 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
827 case 'DOL_ALIGN_LEFT':
828 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
830 case 'DOL_OPEN_DRAWER':
831 $this->printer->pulse();
833 case 'DOL_ACTIVATE_BUZZER':
836 case 'DOL_PRINT_BARCODE':
840 $this->printer->barcode($vals[$tplline][
'value']);
842 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
846 case 'DOL_PRINT_LOGO':
847 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
848 $this->printer->graphics($img);
850 case 'DOL_PRINT_LOGO_OLD':
851 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
852 $this->printer->bitImage($img);
854 case 'DOL_PRINT_LOGO_OLD_CF':
855 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
856 $this->printer->bitImageColumnFormat($img);
858 case 'DOL_PRINT_QRCODE':
860 $this->printer->qrcode($vals[$tplline][
'value']);
862 case 'DOL_CUT_PAPER_FULL':
863 $this->printer->cut(Printer::CUT_FULL);
865 case 'DOL_CUT_PAPER_PARTIAL':
866 $this->printer->cut(Printer::CUT_PARTIAL);
868 case 'DOL_USE_FONT_A':
869 $this->printer->setFont(Printer::FONT_A);
871 case 'DOL_USE_FONT_B':
872 $this->printer->setFont(Printer::FONT_B);
874 case 'DOL_USE_FONT_C':
875 $this->printer->setFont(Printer::FONT_C);
878 $this->printer->setEmphasis(
true);
880 case 'DOL_BOLD_DISABLED':
881 $this->printer->setEmphasis(
false);
883 case 'DOL_DOUBLE_HEIGHT':
884 $this->printer->setTextSize(1, 2);
886 case 'DOL_DOUBLE_WIDTH':
887 $this->printer->setTextSize(2, 1);
889 case 'DOL_DEFAULT_HEIGHT_WIDTH':
890 $this->printer->setTextSize(1, 1);
892 case 'DOL_UNDERLINE':
893 $this->printer->setUnderline(
true);
895 case 'DOL_UNDERLINE_DISABLED':
896 $this->printer->setUnderline(
false);
899 $this->printer->getPrintConnector() -> write(
"\x1e");
901 case 'DOL_BEEP_ALTERNATIVE':
902 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
904 case 'DOL_PRINT_ORDER_LINES':
905 foreach (
$object->lines as $line) {
906 if ($line->special_code == $this->orderprinter) {
907 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
908 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
909 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
910 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
914 case 'DOL_PRINT_PAYMENT':
915 $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,";
917 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
918 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
919 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
920 $sql .=
" ORDER BY p.datep";
921 $resql = $this->db->query($sql);
923 $num = $this->db->num_rows($resql);
926 $row = $this->db->fetch_object($resql);
927 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
928 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
929 $amount_payment = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
930 if ($row->code ==
"LIQ") {
931 $amount_payment = $amount_payment + $row->pos_change;
933 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
934 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
935 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
936 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
937 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
943 case 'DOL_VALUE_PLACE':
944 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"",
$object->ref)));
945 $resql = $this->db->query($sql);
946 $obj = $this->db->fetch_object($resql);
948 $this->printer->text($obj->label);
952 $parameters = array(
'vals' => $vals[$tplline],
'object' =>
$object,
'nbcharactbyline' => $nbcharactbyline);
954 $reshook = $hookmanager->executeHooks(
'sendToPrinterAfter', $parameters, $this, $action);
956 if (!$reshook || $reshook < 0) {
957 $this->printer->text($vals[$tplline][
'tag']);
958 $this->printer->text($vals[$tplline][
'value']);
959 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
966 if ($this->printer->connector instanceof DummyPrintConnector ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"takeposconnector") {
967 $data = $this->printer->connector->getData();
969 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
974 $this->printer->close();