639 global $mysoc, $langs, $user;
642 $langs->load(
'bills');
649 $this->
template = str_replace(
'{dol_value_object_id}', (
string)
$object->id, $this->template);
650 $this->
template = str_replace(
'{dol_value_object_ref}',
$object->ref, $this->template);
652 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date(
$object->date,
'day'), $this->template);
653 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date(
$object->date,
'dayhour'), $this->template);
654 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date(
$object->date,
'%Y'), $this->template);
655 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date(
$object->date,
'%m')), $this->template);
656 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date(
$object->date,
'%m'), $this->template);
657 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date(
$object->date,
'%d'), $this->template);
658 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date(
$object->date,
'%m')[1]), $this->template);
660 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
661 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
662 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
663 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
664 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
665 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
666 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
667 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
669 $this->
template = str_replace(
'{dol_value_customer_firstname}',
$object->thirdparty->firstname, $this->template);
670 $this->
template = str_replace(
'{dol_value_customer_lastname}',
$object->thirdparty->lastname, $this->template);
671 $this->
template = str_replace(
'{dol_value_customer_mail}',
$object->thirdparty->email, $this->template);
672 $this->
template = str_replace(
'{dol_value_customer_phone}',
$object->thirdparty->phone, $this->template);
674 $this->
template = str_replace(
'{dol_value_customer_tax_number}',
$object->thirdparty->tva_intra, $this->template);
678 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
679 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
680 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
681 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
682 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
683 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
684 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
685 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
686 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
687 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
688 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
689 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
690 $this->
template = str_replace(
'{dol_value_mysoc_capital}', (
string) $mysoc->capital, $this->template);
691 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
693 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
694 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
695 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
697 $parameters = array(
'object' =>
$object);
699 $reshook = $hookmanager->executeHooks(
'sendToPrinterBefore', $parameters, $this, $action);
701 $this->error =
"Error in hook dolReceiptPrinter sendToPrinterBefore ".$reshook;
702 dol_syslog(
"dolReceiptPrinter::sendToPrinter: error=".$this->error, LOG_ERR);
707 $this->
template = htmlspecialchars($this->
template, ENT_QUOTES | ENT_XML1);
710 $this->
template = str_replace(
"{",
"<", $this->
template);
711 $this->
template = str_replace(
"}",
">", $this->
template);
713 if (LIBXML_VERSION < 20900) {
717 libxml_disable_entity_loader(
true);
723 $p = xml_parser_create();
724 xml_parse_into_struct($p, $this->
template, $vals, $index);
730 $nbcharactbyline =
getDolGlobalInt(
'RECEIPT_PRINTER_NB_CHARACT_BY_LINE', 48);
736 $nboflines = count($vals);
737 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
739 switch ($vals[$tplline][
'tag']) {
740 case 'DOL_PRINT_TEXT':
741 $this->printer->text($vals[$tplline][
'value']);
743 case 'DOL_PRINT_OBJECT_LINES':
744 foreach (
$object->lines as $line) {
745 if ($line->fk_product) {
746 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
747 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
748 $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");
749 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
751 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
752 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
753 $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");
757 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
758 foreach (
$object->lines as $line) {
759 if ($line->fk_product) {
760 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
761 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
762 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
763 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
764 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
765 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
766 $this->printer->text($line->description.
"\n");
768 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
769 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
770 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
774 case 'DOL_PRINT_OBJECT_TAX':
777 foreach (
$object->lines as $line) {
778 $vat_rate = $line->tva_tx;
779 if (!array_key_exists($vat_rate, $vatarray)) {
780 $vatarray[$vat_rate] = 0;
782 $vatarray[$vat_rate] += $line->total_tva;
784 foreach ($vatarray as $vatkey => $vatvalue) {
785 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
786 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
787 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
790 case 'DOL_PRINT_OBJECT_TAX1':
792 $total_localtax1 = 0;
793 foreach (
$object->lines as $line) {
794 $total_localtax1 += $line->total_localtax1;
796 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
798 case 'DOL_PRINT_OBJECT_TAX2':
800 $total_localtax2 = 0;
801 foreach (
$object->lines as $line) {
802 $total_localtax2 += $line->total_localtax2;
804 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
806 case 'DOL_PRINT_OBJECT_TOTAL':
807 $title = $langs->trans(
'TotalHT');
808 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
809 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
810 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
811 $title = $langs->trans(
'TotalVAT');
812 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
813 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
814 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
815 $title = $langs->trans(
'TotalTTC');
816 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
817 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
818 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
820 case 'DOL_PRINT_CURR_DATE':
821 if (strlen($vals[$tplline][
'value']) < 2) {
822 $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
824 $this->printer->text(date($vals[$tplline][
'value']).
"\n");
827 case 'DOL_LINE_FEED':
828 $this->printer->feed();
830 case 'DOL_LINE_FEED_REVERSE':
831 $this->printer->feedReverse();
833 case 'DOL_ALIGN_CENTER':
834 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
836 case 'DOL_ALIGN_RIGHT':
837 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
839 case 'DOL_ALIGN_LEFT':
840 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
842 case 'DOL_OPEN_DRAWER':
843 $this->printer->pulse();
845 case 'DOL_ACTIVATE_BUZZER':
848 case 'DOL_PRINT_BARCODE':
852 $this->printer->barcode($vals[$tplline][
'value']);
854 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
858 case 'DOL_PRINT_LOGO':
859 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
860 $this->printer->graphics($img);
862 case 'DOL_PRINT_LOGO_OLD':
863 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
864 $this->printer->bitImage($img);
866 case 'DOL_PRINT_LOGO_OLD_CF':
867 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
868 $this->printer->bitImageColumnFormat($img);
870 case 'DOL_PRINT_QRCODE':
872 $this->printer->qrcode($vals[$tplline][
'value']);
874 case 'DOL_CUT_PAPER_FULL':
875 $this->printer->cut(Printer::CUT_FULL);
877 case 'DOL_CUT_PAPER_PARTIAL':
878 $this->printer->cut(Printer::CUT_PARTIAL);
880 case 'DOL_USE_FONT_A':
881 $this->printer->setFont(Printer::FONT_A);
883 case 'DOL_USE_FONT_B':
884 $this->printer->setFont(Printer::FONT_B);
886 case 'DOL_USE_FONT_C':
887 $this->printer->setFont(Printer::FONT_C);
890 $this->printer->setEmphasis(
true);
892 case 'DOL_BOLD_DISABLED':
893 $this->printer->setEmphasis(
false);
895 case 'DOL_DOUBLE_HEIGHT':
896 $this->printer->setTextSize(1, 2);
898 case 'DOL_DOUBLE_WIDTH':
899 $this->printer->setTextSize(2, 1);
901 case 'DOL_DEFAULT_HEIGHT_WIDTH':
902 $this->printer->setTextSize(1, 1);
904 case 'DOL_UNDERLINE':
905 $this->printer->setUnderline(
true);
907 case 'DOL_UNDERLINE_DISABLED':
908 $this->printer->setUnderline(
false);
911 $this->printer->getPrintConnector() -> write(
"\x1e");
913 case 'DOL_BEEP_ALTERNATIVE':
914 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
916 case 'DOL_PRINT_ORDER_LINES':
917 foreach (
$object->lines as $line) {
918 if ($line->special_code == $this->orderprinter) {
919 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
920 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
921 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
922 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
926 case 'DOL_PRINT_PAYMENT':
927 $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,";
929 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
930 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
931 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
932 $sql .=
" ORDER BY p.datep";
933 $resql = $this->db->query($sql);
935 $num = $this->db->num_rows($resql);
938 $row = $this->db->fetch_object($resql);
939 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
940 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
941 $amount_payment = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
942 if ($row->code ==
"LIQ") {
943 $amount_payment += $row->pos_change;
945 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
946 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
947 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
948 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
949 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
955 case 'DOL_VALUE_PLACE':
956 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"",
$object->ref)));
957 $resql = $this->db->query($sql);
958 $obj = $this->db->fetch_object($resql);
960 $this->printer->text($obj->label);
964 $parameters = array(
'vals' => $vals[$tplline],
'object' =>
$object,
'nbcharactbyline' => $nbcharactbyline);
966 $reshook = $hookmanager->executeHooks(
'sendToPrinterAfter', $parameters, $this, $action);
968 if (!$reshook || $reshook < 0) {
969 $this->printer->text($vals[$tplline][
'tag']);
970 $this->printer->text($vals[$tplline][
'value']);
971 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
978 $connector = $this->printer->connector;
979 if ($connector instanceof DummyPrintConnector ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"takeposconnector") {
980 $data = $connector->getData();
982 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
987 $this->printer->close();