613 global $conf, $mysoc, $langs, $user;
615 $langs->load(
'bills');
621 $this->
template = str_replace(
'{dol_value_object_id}', $object->id, $this->template);
622 $this->
template = str_replace(
'{dol_value_object_ref}', $object->ref, $this->template);
624 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date($object->date,
'day'), $this->template);
625 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date($object->date,
'dayhour'), $this->template);
626 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date($object->date,
'%Y'), $this->template);
627 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date($object->date,
'%m')), $this->template);
628 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date($object->date,
'%m'), $this->template);
629 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date($object->date,
'%d'), $this->template);
630 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date($object->date,
'%m')[1]), $this->template);
632 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
633 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
634 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
635 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
636 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
637 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
638 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
639 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
641 $this->
template = str_replace(
'{dol_value_customer_firstname}', $object->thirdparty->firstname, $this->template);
642 $this->
template = str_replace(
'{dol_value_customer_lastname}', $object->thirdparty->lastname, $this->template);
643 $this->
template = str_replace(
'{dol_value_customer_mail}', $object->thirdparty->email, $this->template);
644 $this->
template = str_replace(
'{dol_value_customer_phone}', $object->thirdparty->phone, $this->template);
646 $this->
template = str_replace(
'{dol_value_customer_tax_number}', $object->thirdparty->tva_intra, $this->template);
650 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
651 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
652 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
653 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
654 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
655 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
656 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
657 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
658 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
659 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
660 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
661 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
662 $this->
template = str_replace(
'{dol_value_mysoc_capital}', $mysoc->capital, $this->template);
663 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
665 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
666 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
667 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
670 $this->
template = str_replace(
"{",
"<", $this->
template);
671 $this->
template = str_replace(
"}",
">", $this->
template);
672 $p = xml_parser_create();
673 xml_parse_into_struct($p, $this->
template, $vals, $index);
679 $nbcharactbyline = (!empty($conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE) ? $conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE : 48);
684 $nboflines = count($vals);
685 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
687 switch ($vals[$tplline][
'tag']) {
688 case 'DOL_PRINT_TEXT':
689 $this->printer->text($vals[$tplline][
'value']);
691 case 'DOL_PRINT_OBJECT_LINES':
692 foreach ($object->lines as $line) {
693 if ($line->fk_product) {
694 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
695 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
696 $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");
697 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
699 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
700 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
701 $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");
705 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
706 foreach ($object->lines as $line) {
707 if ($line->fk_product) {
708 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
709 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
710 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
711 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
712 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
713 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
714 $this->printer->text($line->description.
"\n");
716 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
717 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
718 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
722 case 'DOL_PRINT_OBJECT_TAX':
725 foreach ($object->lines as $line) {
726 $vatarray[$line->tva_tx] += $line->total_tva;
728 foreach ($vatarray as $vatkey => $vatvalue) {
729 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
730 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
731 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
734 case 'DOL_PRINT_OBJECT_TAX1':
736 $total_localtax1 = 0;
737 foreach ($object->lines as $line) {
738 $total_localtax1 += $line->total_localtax1;
740 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
742 case 'DOL_PRINT_OBJECT_TAX2':
744 $total_localtax2 = 0;
745 foreach ($object->lines as $line) {
746 $total_localtax2 += $line->total_localtax2;
748 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
750 case 'DOL_PRINT_OBJECT_TOTAL':
751 $title = $langs->trans(
'TotalHT');
752 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
753 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
754 $this->printer->text($title.$spaces.str_pad(
price($object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
755 $title = $langs->trans(
'TotalVAT');
756 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
757 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
758 $this->printer->text($title.$spaces.str_pad(
price($object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
759 $title = $langs->trans(
'TotalTTC');
760 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
761 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
762 $this->printer->text($title.$spaces.str_pad(
price($object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
764 case 'DOL_PRINT_CURR_DATE':
765 if (strlen($vals[$tplline][
'value'])<2) $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
766 else $this->printer->text(date($vals[$tplline][
'value']).
"\n");
768 case 'DOL_LINE_FEED':
769 $this->printer->feed();
771 case 'DOL_LINE_FEED_REVERSE':
772 $this->printer->feedReverse();
774 case 'DOL_ALIGN_CENTER':
775 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
777 case 'DOL_ALIGN_RIGHT':
778 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
780 case 'DOL_ALIGN_LEFT':
781 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
783 case 'DOL_OPEN_DRAWER':
784 $this->printer->pulse();
786 case 'DOL_ACTIVATE_BUZZER':
789 case 'DOL_PRINT_BARCODE':
793 $this->printer->barcode($vals[$tplline][
'value']);
795 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
799 case 'DOL_PRINT_LOGO':
800 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
801 $this->printer->graphics($img);
803 case 'DOL_PRINT_LOGO_OLD':
804 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
805 $this->printer->bitImage($img);
807 case 'DOL_PRINT_LOGO_OLD_CF':
808 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
809 $this->printer->bitImageColumnFormat($img);
811 case 'DOL_PRINT_QRCODE':
813 $this->printer->qrcode($vals[$tplline][
'value']);
815 case 'DOL_CUT_PAPER_FULL':
816 $this->printer->cut(Printer::CUT_FULL);
818 case 'DOL_CUT_PAPER_PARTIAL':
819 $this->printer->cut(Printer::CUT_PARTIAL);
821 case 'DOL_USE_FONT_A':
822 $this->printer->setFont(Printer::FONT_A);
824 case 'DOL_USE_FONT_B':
825 $this->printer->setFont(Printer::FONT_B);
827 case 'DOL_USE_FONT_C':
828 $this->printer->setFont(Printer::FONT_C);
831 $this->printer->setEmphasis(
true);
833 case 'DOL_BOLD_DISABLED':
834 $this->printer->setEmphasis(
false);
836 case 'DOL_DOUBLE_HEIGHT':
837 $this->printer->setTextSize(1, 2);
839 case 'DOL_DOUBLE_WIDTH':
840 $this->printer->setTextSize(2, 1);
842 case 'DOL_DEFAULT_HEIGHT_WIDTH':
843 $this->printer->setTextSize(1, 1);
845 case 'DOL_UNDERLINE':
846 $this->printer->setUnderline(
true);
848 case 'DOL_UNDERLINE_DISABLED':
849 $this->printer->setUnderline(
false);
852 $this->printer->getPrintConnector() -> write(
"\x1e");
854 case 'DOL_BEEP_ALTERNATIVE':
855 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
857 case 'DOL_PRINT_ORDER_LINES':
858 foreach ($object->lines as $line) {
859 if ($line->special_code == $this->orderprinter) {
860 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
861 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
862 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
863 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
867 case 'DOL_PRINT_PAYMENT':
868 $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,";
870 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->db->prefix().
"paiement as p";
871 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
872 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
873 $sql .=
" ORDER BY p.datep";
874 $resql = $this->db->query($sql);
876 $num = $this->db->num_rows($resql);
879 $row = $this->db->fetch_object($resql);
880 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
881 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
882 $amount_payment = (isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
883 if ($row->code ==
"LIQ") {
884 $amount_payment = $amount_payment + $row->pos_change;
886 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
887 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
888 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
889 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
890 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
896 case 'DOL_VALUE_PLACE':
897 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $object->ref)));
898 $resql = $this->db->query($sql);
899 $obj = $this->db->fetch_object($resql);
901 $this->printer->text($obj->label);
905 $this->printer->text($vals[$tplline][
'tag']);
906 $this->printer->text($vals[$tplline][
'value']);
907 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
913 if ($this->printer->connector instanceof DummyPrintConnector || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
914 $data = $this->printer->connector->getData();
915 if ($conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
916 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
921 $this->printer->close();