635 global $mysoc, $langs, $user;
638 $langs->load(
'bills');
645 $this->
template = str_replace(
'{dol_value_object_id}', (
string)
$object->id, $this->template);
646 $this->
template = str_replace(
'{dol_value_object_ref}',
$object->ref, $this->template);
648 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date(
$object->date,
'day'), $this->template);
649 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date(
$object->date,
'dayhour'), $this->template);
650 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date(
$object->date,
'%Y'), $this->template);
651 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date(
$object->date,
'%m')), $this->template);
652 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date(
$object->date,
'%m'), $this->template);
653 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date(
$object->date,
'%d'), $this->template);
654 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date(
$object->date,
'%m')[1]), $this->template);
656 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
657 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
658 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
659 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
660 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
661 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
662 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
663 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
665 $this->
template = str_replace(
'{dol_value_customer_firstname}',
$object->thirdparty->firstname, $this->template);
666 $this->
template = str_replace(
'{dol_value_customer_lastname}',
$object->thirdparty->lastname, $this->template);
667 $this->
template = str_replace(
'{dol_value_customer_mail}',
$object->thirdparty->email, $this->template);
668 $this->
template = str_replace(
'{dol_value_customer_phone}',
$object->thirdparty->phone, $this->template);
670 $this->
template = str_replace(
'{dol_value_customer_tax_number}',
$object->thirdparty->tva_intra, $this->template);
674 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
675 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
676 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
677 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
678 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
679 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
680 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
681 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
682 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
683 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
684 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
685 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
686 $this->
template = str_replace(
'{dol_value_mysoc_capital}', (
string) $mysoc->capital, $this->template);
687 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
689 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
690 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
691 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
693 $parameters = array(
'object' =>
$object);
695 $reshook = $hookmanager->executeHooks(
'sendToPrinterBefore', $parameters, $this, $action);
697 $this->error =
"Error in hook dolReceiptPrinter sendToPrinterBefore ".$reshook;
698 dol_syslog(
"dolReceiptPrinter::sendToPrinter: error=".$this->error, LOG_ERR);
703 $this->
template = htmlspecialchars($this->
template, ENT_QUOTES | ENT_XML1);
706 $this->
template = str_replace(
"{",
"<", $this->
template);
707 $this->
template = str_replace(
"}",
">", $this->
template);
709 if (LIBXML_VERSION < 20900) {
713 libxml_disable_entity_loader(
true);
719 $p = xml_parser_create();
720 xml_parse_into_struct($p, $this->
template, $vals, $index);
726 $nbcharactbyline =
getDolGlobalInt(
'RECEIPT_PRINTER_NB_CHARACT_BY_LINE', 48);
732 $nboflines = count($vals);
733 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
735 switch ($vals[$tplline][
'tag']) {
736 case 'DOL_PRINT_TEXT':
737 $this->printer->text($vals[$tplline][
'value']);
739 case 'DOL_PRINT_OBJECT_LINES':
740 foreach (
$object->lines as $line) {
741 if ($line->fk_product) {
742 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
743 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
744 $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");
745 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
747 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen((
string) $line->qty) - strlen(
price($line->subprice)) - 10 - 1;
748 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
749 $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");
753 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
754 foreach (
$object->lines as $line) {
755 if ($line->fk_product) {
756 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
757 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
758 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
759 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\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.
"\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.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
770 case 'DOL_PRINT_OBJECT_TAX':
773 foreach (
$object->lines as $line) {
774 $vatarray[$line->tva_tx] += $line->total_tva;
776 foreach ($vatarray as $vatkey => $vatvalue) {
777 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
778 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
779 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
782 case 'DOL_PRINT_OBJECT_TAX1':
784 $total_localtax1 = 0;
785 foreach (
$object->lines as $line) {
786 $total_localtax1 += $line->total_localtax1;
788 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
790 case 'DOL_PRINT_OBJECT_TAX2':
792 $total_localtax2 = 0;
793 foreach (
$object->lines as $line) {
794 $total_localtax2 += $line->total_localtax2;
796 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
798 case 'DOL_PRINT_OBJECT_TOTAL':
799 $title = $langs->trans(
'TotalHT');
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_ht), 10,
' ', STR_PAD_LEFT).
"\n");
803 $title = $langs->trans(
'TotalVAT');
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_tva), 10,
' ', STR_PAD_LEFT).
"\n");
807 $title = $langs->trans(
'TotalTTC');
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_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
812 case 'DOL_PRINT_CURR_DATE':
813 if (strlen($vals[$tplline][
'value']) < 2) {
814 $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
816 $this->printer->text(date($vals[$tplline][
'value']).
"\n");
819 case 'DOL_LINE_FEED':
820 $this->printer->feed();
822 case 'DOL_LINE_FEED_REVERSE':
823 $this->printer->feedReverse();
825 case 'DOL_ALIGN_CENTER':
826 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
828 case 'DOL_ALIGN_RIGHT':
829 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
831 case 'DOL_ALIGN_LEFT':
832 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
834 case 'DOL_OPEN_DRAWER':
835 $this->printer->pulse();
837 case 'DOL_ACTIVATE_BUZZER':
840 case 'DOL_PRINT_BARCODE':
844 $this->printer->barcode($vals[$tplline][
'value']);
846 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
850 case 'DOL_PRINT_LOGO':
851 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
852 $this->printer->graphics($img);
854 case 'DOL_PRINT_LOGO_OLD':
855 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
856 $this->printer->bitImage($img);
858 case 'DOL_PRINT_LOGO_OLD_CF':
859 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
860 $this->printer->bitImageColumnFormat($img);
862 case 'DOL_PRINT_QRCODE':
864 $this->printer->qrcode($vals[$tplline][
'value']);
866 case 'DOL_CUT_PAPER_FULL':
867 $this->printer->cut(Printer::CUT_FULL);
869 case 'DOL_CUT_PAPER_PARTIAL':
870 $this->printer->cut(Printer::CUT_PARTIAL);
872 case 'DOL_USE_FONT_A':
873 $this->printer->setFont(Printer::FONT_A);
875 case 'DOL_USE_FONT_B':
876 $this->printer->setFont(Printer::FONT_B);
878 case 'DOL_USE_FONT_C':
879 $this->printer->setFont(Printer::FONT_C);
882 $this->printer->setEmphasis(
true);
884 case 'DOL_BOLD_DISABLED':
885 $this->printer->setEmphasis(
false);
887 case 'DOL_DOUBLE_HEIGHT':
888 $this->printer->setTextSize(1, 2);
890 case 'DOL_DOUBLE_WIDTH':
891 $this->printer->setTextSize(2, 1);
893 case 'DOL_DEFAULT_HEIGHT_WIDTH':
894 $this->printer->setTextSize(1, 1);
896 case 'DOL_UNDERLINE':
897 $this->printer->setUnderline(
true);
899 case 'DOL_UNDERLINE_DISABLED':
900 $this->printer->setUnderline(
false);
903 $this->printer->getPrintConnector() -> write(
"\x1e");
905 case 'DOL_BEEP_ALTERNATIVE':
906 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
908 case 'DOL_PRINT_ORDER_LINES':
909 foreach (
$object->lines as $line) {
910 if ($line->special_code == $this->orderprinter) {
911 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen((
string) $line->qty) - 10 - 1;
912 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
913 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
914 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
918 case 'DOL_PRINT_PAYMENT':
919 $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,";
921 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
922 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
923 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int)
$object->id);
924 $sql .=
" ORDER BY p.datep";
925 $resql = $this->db->query($sql);
927 $num = $this->db->num_rows($resql);
930 $row = $this->db->fetch_object($resql);
931 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
932 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
933 $amount_payment = (isModEnabled(
"multicurrency") &&
$object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
934 if ($row->code ==
"LIQ") {
935 $amount_payment = $amount_payment + $row->pos_change;
937 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
938 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
939 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
940 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
941 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
947 case 'DOL_VALUE_PLACE':
948 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"",
$object->ref)));
949 $resql = $this->db->query($sql);
950 $obj = $this->db->fetch_object($resql);
952 $this->printer->text($obj->label);
956 $parameters = array(
'vals' => $vals[$tplline],
'object' =>
$object,
'nbcharactbyline' => $nbcharactbyline);
958 $reshook = $hookmanager->executeHooks(
'sendToPrinterAfter', $parameters, $this, $action);
960 if (!$reshook || $reshook < 0) {
961 $this->printer->text($vals[$tplline][
'tag']);
962 $this->printer->text($vals[$tplline][
'value']);
963 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
970 if ($this->printer->connector instanceof DummyPrintConnector ||
getDolGlobalString(
'TAKEPOS_PRINT_METHOD') ==
"takeposconnector") {
971 $data = $this->printer->connector->getData();
973 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
978 $this->printer->close();