642 global
$mysoc, $langs, $user;
645 $langs->load(
'bills');
652 $this->
template = str_replace(
'{dol_value_object_id}', (
string)
$object->id, $this->template);
653 $this->
template = str_replace(
'{dol_value_object_ref}',
$object->ref, $this->template);
655 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date(
$object->date,
'day'), $this->template);
656 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date(
$object->date,
'dayhour'), $this->template);
657 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date(
$object->date,
'%Y'), $this->template);
658 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date(
$object->date,
'%m')), $this->template);
659 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date(
$object->date,
'%m'), $this->template);
660 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date(
$object->date,
'%d'), $this->template);
661 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date(
$object->date,
'%m')[1]), $this->template);
663 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
664 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
665 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
666 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
667 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
668 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
669 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
670 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
672 $this->
template = str_replace(
'{dol_value_customer_firstname}',
$object->thirdparty->firstname, $this->template);
673 $this->
template = str_replace(
'{dol_value_customer_lastname}',
$object->thirdparty->lastname, $this->template);
674 $this->
template = str_replace(
'{dol_value_customer_mail}',
$object->thirdparty->email, $this->template);
675 $this->
template = str_replace(
'{dol_value_customer_phone}',
$object->thirdparty->phone, $this->template);
677 $this->
template = str_replace(
'{dol_value_customer_tax_number}',
$object->thirdparty->tva_intra, $this->template);
681 $this->
template = str_replace(
'{dol_value_mysoc_name}',
$mysoc->name, $this->template);
682 $this->
template = str_replace(
'{dol_value_mysoc_address}',
$mysoc->address, $this->template);
683 $this->
template = str_replace(
'{dol_value_mysoc_zip}',
$mysoc->zip, $this->template);
684 $this->
template = str_replace(
'{dol_value_mysoc_town}',
$mysoc->town, $this->template);
685 $this->
template = str_replace(
'{dol_value_mysoc_country}',
$mysoc->country, $this->template);
686 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}',
$mysoc->idprof1, $this->template);
687 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}',
$mysoc->idprof2, $this->template);
688 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}',
$mysoc->idprof3, $this->template);
689 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}',
$mysoc->idprof4, $this->template);
690 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}',
$mysoc->idprof5, $this->template);
691 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}',
$mysoc->idprof6, $this->template);
692 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}',
$mysoc->tva_intra, $this->template);
693 $this->
template = str_replace(
'{dol_value_mysoc_capital}', (
string)
$mysoc->capital, $this->template);
694 $this->
template = str_replace(
'{dol_value_mysoc_url}',
$mysoc->url, $this->template);
696 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
697 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
698 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
700 $parameters = array(
'object' =>
$object);
702 $reshook = $hookmanager->executeHooks(
'sendToPrinterBefore', $parameters, $this, $action);
704 $this->error =
"Error in hook dolReceiptPrinter sendToPrinterBefore ".$reshook;
705 dol_syslog(
"dolReceiptPrinter::sendToPrinter: error=".$this->error, LOG_ERR);
710 $this->
template = htmlspecialchars($this->
template, ENT_QUOTES | ENT_XML1);
713 $this->
template = str_replace(
"{",
"<", $this->
template);
714 $this->
template = str_replace(
"}",
">", $this->
template);
716 if (LIBXML_VERSION < 20900) {
720 libxml_disable_entity_loader(
true);
726 $p = xml_parser_create();
727 xml_parse_into_struct($p, $this->
template, $vals, $index);
733 $nbcharactbyline =
getDolGlobalInt(
'RECEIPT_PRINTER_NB_CHARACT_BY_LINE', 48);
743 $nboflines = count($vals);
744 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
746 switch ($vals[$tplline][
'tag']) {
747 case 'DOL_PRINT_TEXT':
748 $this->printer->text($vals[$tplline][
'value']);
750 case 'DOL_PRINT_OBJECT_LINES':
751 foreach (
$object->lines as $line) {
752 if ($line->fk_product) {
753 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
754 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
755 $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");
756 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
758 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
759 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
760 $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");
764 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
765 foreach (
$object->lines as $line) {
766 if ($line->fk_product) {
767 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
768 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
769 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
770 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
771 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
772 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
773 $this->printer->text($line->description.
"\n");
775 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - 10 - 1;
776 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
777 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
781 case 'DOL_PRINT_OBJECT_TAX':
784 foreach (
$object->lines as $line) {
785 $vat_rate = $line->tva_tx;
786 if (!array_key_exists($vat_rate, $vatarray)) {
787 $vatarray[$vat_rate] = 0;
789 $vatarray[$vat_rate] += $line->total_tva;
791 foreach ($vatarray as $vatkey => $vatvalue) {
792 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
793 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
794 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
797 case 'DOL_PRINT_OBJECT_TAX1':
799 $total_localtax1 = 0;
800 foreach (
$object->lines as $line) {
801 $total_localtax1 += $line->total_localtax1;
803 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
805 case 'DOL_PRINT_OBJECT_TAX2':
807 $total_localtax2 = 0;
808 foreach (
$object->lines as $line) {
809 $total_localtax2 += $line->total_localtax2;
811 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
813 case 'DOL_PRINT_OBJECT_TOTAL':
814 $title = $langs->trans(
'TotalHT');
815 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
816 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
817 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
818 $title = $langs->trans(
'TotalVAT');
819 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
820 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
821 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
822 $title = $langs->trans(
'TotalTTC');
823 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
824 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
825 $this->printer->text($title.$spaces.str_pad(
price(
$object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
827 case 'DOL_PRINT_CURR_DATE':
828 if (strlen($vals[$tplline][
'value']) < 2) {
829 $this->printer->text(
date(
'd/m/Y H:i:s').
"\n");
831 $this->printer->text(
date($vals[$tplline][
'value']).
"\n");
834 case 'DOL_LINE_FEED':
835 $this->printer->feed();
837 case 'DOL_LINE_FEED_REVERSE':
838 $this->printer->feedReverse();
840 case 'DOL_ALIGN_CENTER':
841 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
843 case 'DOL_ALIGN_RIGHT':
844 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
846 case 'DOL_ALIGN_LEFT':
847 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
849 case 'DOL_OPEN_DRAWER':
850 $this->printer->pulse();
852 case 'DOL_ACTIVATE_BUZZER':
855 case 'DOL_PRINT_BARCODE':
859 $this->printer->barcode($vals[$tplline][
'value']);
861 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
865 case 'DOL_PRINT_LOGO':
866 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.
$mysoc->logo);
867 $this->printer->graphics($img);
869 case 'DOL_PRINT_LOGO_OLD':
870 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.
$mysoc->logo);
871 $this->printer->bitImage($img);
873 case 'DOL_PRINT_LOGO_OLD_CF':
874 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.
$mysoc->logo);
875 $this->printer->bitImageColumnFormat($img);
877 case 'DOL_PRINT_QRCODE':
879 $this->printer->qrcode($vals[$tplline][
'value']);
881 case 'DOL_CUT_PAPER_FULL':
882 $this->printer->cut(Printer::CUT_FULL);
884 case 'DOL_CUT_PAPER_PARTIAL':
885 $this->printer->cut(Printer::CUT_PARTIAL);
887 case 'DOL_USE_FONT_A':
888 $this->printer->setFont(Printer::FONT_A);
890 case 'DOL_USE_FONT_B':
891 $this->printer->setFont(Printer::FONT_B);
893 case 'DOL_USE_FONT_C':
894 $this->printer->setFont(Printer::FONT_C);
897 $this->printer->setEmphasis(
true);
899 case 'DOL_BOLD_DISABLED':
900 $this->printer->setEmphasis(
false);
902 case 'DOL_DOUBLE_HEIGHT':
903 $this->printer->setTextSize(1, 2);
905 case 'DOL_DOUBLE_WIDTH':
906 $this->printer->setTextSize(2, 1);
908 case 'DOL_DEFAULT_HEIGHT_WIDTH':
909 $this->printer->setTextSize(1, 1);
911 case 'DOL_UNDERLINE':
912 $this->printer->setUnderline(1);
914 case 'DOL_UNDERLINE_DISABLED':
915 $this->printer->setUnderline(0);
918 $this->printer->getPrintConnector() -> write(
"\x1e");
920 case 'DOL_BEEP_ALTERNATIVE':
921 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
923 case 'DOL_PRINT_ORDER_LINES':
924 foreach (
$object->lines as $line) {
925 if ($line->special_code == $this->orderprinter) {
926 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
927 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
928 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
929 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
933 case 'DOL_PRINT_PAYMENT':
934 $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,";
936 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
937 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
938 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
939 $sql .=
" ORDER BY p.datep";
940 $resql = $this->db->query($sql);
942 $num = $this->db->num_rows($resql);
945 $row = $this->db->fetch_object($resql);
946 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
947 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
948 $amount_payment = (
isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
949 if ($row->code ==
"LIQ") {
950 $amount_payment += $row->pos_change;
952 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
953 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
954 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
955 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
956 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
962 case 'DOL_VALUE_PLACE':
963 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"",
$object->ref)));
964 $resql = $this->db->query($sql);
965 $obj = $this->db->fetch_object($resql);
967 $this->printer->text($obj->label);
971 $parameters = array(
'vals' => $vals[$tplline],
'object' =>
$object,
'nbcharactbyline' => $nbcharactbyline);
973 $reshook = $hookmanager->executeHooks(
'sendToPrinterAfter', $parameters, $this, $action);
975 if (!$reshook || $reshook < 0) {
976 $this->printer->text($vals[$tplline][
'tag']);
977 $this->printer->text($vals[$tplline][
'value']);
978 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
985 $connector = $this->printer->connector;
986 if ($connector instanceof DummyPrintConnector ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"takeposconnector") {
987 $data = $connector->getData();
989 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
994 $this->printer->close();