106 require_once DOL_DOCUMENT_ROOT.
'/includes/mike42/escpos-php/autoload.php';
107 use Mike42\Escpos\PrintConnectors\FilePrintConnector;
108 use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
109 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
110 use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
111 use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
112 use Mike42\Escpos\CapabilityProfile;
113 use Mike42\Escpos\Printer;
114 use Mike42\Escpos\EscposImage;
121 const CONNECTOR_DUMMY = 1;
122 const CONNECTOR_FILE_PRINT = 2;
123 const CONNECTOR_NETWORK_PRINT = 3;
124 const CONNECTOR_WINDOWS_PRINT = 4;
125 const CONNECTOR_CUPS_PRINT = 5;
143 public $orderprinter;
153 public $errors = array();
164 'dol_line_feed' =>
'DOL_LINE_FEED',
165 'dol_line_feed_reverse' =>
'DOL_LINE_FEED_REVERSE',
166 'dol_align_left' =>
'DOL_ALIGN_LEFT',
167 'dol_align_center' =>
'DOL_ALIGN_CENTER',
168 'dol_align_right' =>
'DOL_ALIGN_RIGHT',
169 'dol_use_font_a' =>
'DOL_USE_FONT_A',
170 'dol_use_font_b' =>
'DOL_USE_FONT_B',
171 'dol_use_font_c' =>
'DOL_USE_FONT_C',
172 'dol_bold' =>
'DOL_BOLD',
173 'dol_bold_disabled' =>
'DOL_BOLD_DISABLED',
174 'dol_double_height' =>
'DOL_DOUBLE_HEIGHT',
175 'dol_double_width' =>
'DOL_DOUBLE_WIDTH',
176 'dol_default_height_width' =>
'DOL_DEFAULT_HEIGHT_WIDTH',
177 'dol_underline' =>
'DOL_UNDERLINE',
178 'dol_underline_disabled' =>
'DOL_UNDERLINE_DISABLED',
179 'dol_cut_paper_full' =>
'DOL_CUT_PAPER_FULL',
180 'dol_cut_paper_partial' =>
'DOL_CUT_PAPER_PARTIAL',
181 'dol_open_drawer' =>
'DOL_OPEN_DRAWER',
182 'dol_beep' =>
'DOL_BEEP',
183 'dol_beep_alternative' =>
'DOL_BEEP_ALTERNATIVE',
184 'dol_print_text' =>
'DOL_PRINT_TEXT',
185 'dol_print_barcode' =>
'DOL_PRINT_BARCODE',
186 'dol_value_date' =>
'DateInvoice',
187 'dol_value_date_time' =>
'DateInvoiceWithTime',
188 'dol_value_year' =>
'YearInvoice',
189 'dol_value_month_letters' =>
'DOL_VALUE_MONTH_LETTERS',
190 'dol_value_month' =>
'DOL_VALUE_MONTH',
191 'dol_value_day' =>
'DOL_VALUE_DAY',
192 'dol_value_day_letters' =>
'DOL_VALUE_DAY',
193 'dol_value_currentdate' =>
'DOL_VALUE_CURRENTDATE',
194 'dol_print_payment' =>
'DOL_PRINT_PAYMENT',
195 'dol_print_curr_date' =>
'DOL_PRINT_CURR_DATE',
196 'dol_print_logo' =>
'DOL_PRINT_LOGO',
197 'dol_print_logo_old' =>
'DOL_PRINT_LOGO_OLD',
198 'dol_value_object_id' =>
'InvoiceID',
199 'dol_value_object_ref' =>
'InvoiceRef',
200 'dol_print_object_lines' =>
'DOL_PRINT_OBJECT_LINES',
201 'dol_print_object_lines_with_notes' =>
'DOL_PRINT_OBJECT_LINES_WITH_NOTES',
202 'dol_print_object_tax' =>
'TotalVAT',
203 'dol_print_object_local_tax1' =>
'TotalLT1',
204 'dol_print_object_local_tax2' =>
'TotalLT2',
205 'dol_print_object_total' =>
'Total',
206 'dol_print_object_number' =>
'DOL_PRINT_OBJECT_NUMBER',
208 'dol_print_order_lines' =>
'DOL_PRINT_ORDER_LINES',
209 'dol_value_customer_firstname' =>
'DOL_VALUE_CUSTOMER_FIRSTNAME',
210 'dol_value_customer_lastname' =>
'DOL_VALUE_CUSTOMER_LASTNAME',
211 'dol_value_customer_mail' =>
'DOL_VALUE_CUSTOMER_MAIL',
212 'dol_value_customer_phone' =>
'DOL_VALUE_CUSTOMER_PHONE',
213 'dol_value_customer_skype' =>
'DOL_VALUE_CUSTOMER_SKYPE',
214 'dol_value_customer_tax_number' =>
'DOL_VALUE_CUSTOMER_TAX_NUMBER',
217 'dol_value_mysoc_name' =>
'DOL_VALUE_MYSOC_NAME',
218 'dol_value_mysoc_address' =>
'Address',
219 'dol_value_mysoc_zip' =>
'Zip',
220 'dol_value_mysoc_town' =>
'Town',
221 'dol_value_mysoc_country' =>
'Country',
222 'dol_value_mysoc_idprof1' =>
'ProfId1',
223 'dol_value_mysoc_idprof2' =>
'ProfId2',
224 'dol_value_mysoc_idprof3' =>
'ProfId3',
225 'dol_value_mysoc_idprof4' =>
'ProfId4',
226 'dol_value_mysoc_idprof5' =>
'ProfId5',
227 'dol_value_mysoc_idprof6' =>
'ProfId6',
228 'dol_value_mysoc_tva_intra' =>
'VATIntra',
229 'dol_value_mysoc_capital' =>
'Capital',
230 'dol_value_mysoc_url' =>
'Web',
231 'dol_value_vendor_lastname' =>
'VendorLastname',
232 'dol_value_vendor_firstname' =>
'VendorFirstname',
233 'dol_value_vendor_mail' =>
'VendorEmail',
234 'dol_value_place' =>
'DOL_VALUE_PLACE',
249 $sql =
"SELECT rowid, name, fk_type, fk_profile, parameter";
250 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt";
251 $sql .=
" WHERE entity = ".$conf->entity;
255 while ($line < $num) {
256 $row = $this->
db->fetch_array(
$resql);
257 switch ($row[
'fk_type']) {
259 $row[
'fk_type_name'] =
'CONNECTOR_DUMMY';
262 $row[
'fk_type_name'] =
'CONNECTOR_FILE_PRINT';
265 $row[
'fk_type_name'] =
'CONNECTOR_NETWORK_PRINT';
268 $row[
'fk_type_name'] =
'CONNECTOR_WINDOWS_PRINT';
271 $row[
'fk_type_name'] =
'CONNECTOR_CUPS_PRINT';
274 $row[
'fk_type_name'] =
'CONNECTOR_UNKNOWN';
277 switch ($row[
'fk_profile']) {
279 $row[
'fk_profile_name'] =
'PROFILE_DEFAULT';
282 $row[
'fk_profile_name'] =
'PROFILE_SIMPLE';
285 $row[
'fk_profile_name'] =
'PROFILE_EPOSTEP';
288 $row[
'fk_profile_name'] =
'PROFILE_P822D';
291 $row[
'fk_profile_name'] =
'PROFILE_STAR';
299 $this->errors[] = $this->
db->lasterror;
301 $this->listprinters = $obj;
317 $sql =
"SELECT rowid, name, template";
318 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt_template";
319 $sql .=
" WHERE entity = ".$conf->entity;
323 while ($line < $num) {
324 $obj[] = $this->
db->fetch_array(
$resql);
329 $this->errors[] = $this->
db->lasterror;
331 $this->listprinterstemplates = $obj;
348 1 => $langs->trans(
'CONNECTOR_DUMMY'),
349 2 => $langs->trans(
'CONNECTOR_FILE_PRINT'),
350 3 => $langs->trans(
'CONNECTOR_NETWORK_PRINT'),
351 4 => $langs->trans(
'CONNECTOR_WINDOWS_PRINT'),
352 5 => $langs->trans(
'CONNECTOR_CUPS_PRINT'),
373 0 => $langs->trans(
'PROFILE_DEFAULT'),
374 1 => $langs->trans(
'PROFILE_SIMPLE'),
375 2 => $langs->trans(
'PROFILE_EPOSTEP'),
376 3 => $langs->trans(
'PROFILE_P822D'),
377 4 => $langs->trans(
'PROFILE_STAR'),
394 public function addPrinter($name, $type, $profile, $parameter)
398 $sql =
"INSERT INTO ".$this->db->prefix().
"printer_receipt";
399 $sql .=
" (name, fk_type, fk_profile, parameter, entity)";
400 $sql .=
" VALUES ('".$this->db->escape($name).
"', ".((int) $type).
", ".((int) $profile).
", '".$this->
db->escape($parameter).
"', ".((int) $conf->entity).
")";
404 $this->errors[] = $this->
db->lasterror;
419 public function updatePrinter($name, $type, $profile, $parameter, $printerid)
424 $sql =
"UPDATE ".$this->db->prefix().
"printer_receipt";
425 $sql .=
" SET name='".$this->db->escape($name).
"'";
426 $sql .=
", fk_type=".((int) $type);
427 $sql .=
", fk_profile=".((int) $profile);
428 $sql .=
", parameter='".$this->db->escape($parameter).
"'";
429 $sql .=
" WHERE rowid=".((int) $printerid);
434 $this->errors[] = $this->
db->lasterror;
449 $sql =
'DELETE FROM '.$this->db->prefix().
'printer_receipt';
450 $sql .=
' WHERE rowid='.((int) $printerid);
454 $this->errors[] = $this->
db->lasterror;
470 $sql =
"INSERT INTO ".$this->db->prefix().
"printer_receipt_template";
471 $sql .=
" (name, template, entity) VALUES ('".$this->db->escape($name).
"'";
472 $sql .=
", '".$this->db->escape($template).
"', ".$conf->entity.
")";
476 $this->errors[] = $this->
db->lasterror;
491 $sql =
'DELETE FROM '.$this->db->prefix().
'printer_receipt_template';
492 $sql .=
" WHERE rowid = ".((int) $templateid);
493 $sql .=
" AND entity = ".$conf->entity;
497 $this->errors[] = $this->
db->lasterror;
515 $sql =
"UPDATE ".$this->db->prefix().
"printer_receipt_template";
516 $sql .=
" SET name='".$this->db->escape($name).
"'";
517 $sql .=
", template='".$this->db->escape($template).
"'";
518 $sql .=
" WHERE rowid=".((int) $templateid);
522 $this->errors[] = $this->
db->lasterror;
539 $img = EscposImage::load(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo_bw.png');
546 $this->printer->bitImage($img);
547 $this->printer->text(
"Hello World!\n");
548 $testStr =
"1234567890";
549 $this->printer->barcode($testStr);
551 $this->printer->text(
"Most simple example\n");
552 $this->printer->feed();
553 $this->printer->cut();
556 if ($this->printer->connector instanceof DummyPrintConnector) {
557 $data = $this->printer->connector->getData();
560 $this->printer->close();
562 $this->errors[] = $e->getMessage();
579 global $conf, $mysoc, $langs, $user;
584 $this->
template = str_replace(
'{dol_value_object_id}', $object->id, $this->template);
585 $this->
template = str_replace(
'{dol_value_object_ref}', $object->ref, $this->template);
587 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date($object->date,
'day'), $this->template);
588 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date($object->date,
'dayhour'), $this->template);
589 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date($object->date,
'%Y'), $this->template);
590 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date($object->date,
'%m')), $this->template);
591 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date($object->date,
'%m'), $this->template);
592 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date($object->date,
'%d'), $this->template);
593 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date($object->date,
'%m')[1]), $this->template);
594 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date(
dol_now(),
'dayhour'), $this->
template);
596 $this->
template = str_replace(
'{dol_value_customer_firstname}', $object->thirdparty->firstname, $this->template);
597 $this->
template = str_replace(
'{dol_value_customer_lastname}', $object->thirdparty->lastname, $this->template);
598 $this->
template = str_replace(
'{dol_value_customer_mail}', $object->thirdparty->email, $this->template);
599 $this->
template = str_replace(
'{dol_value_customer_phone}', $object->thirdparty->phone, $this->template);
601 $this->
template = str_replace(
'{dol_value_customer_tax_number}', $object->thirdparty->tva_intra, $this->template);
605 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
606 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
607 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
608 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
609 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
610 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
611 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
612 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
613 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
614 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
615 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
616 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
617 $this->
template = str_replace(
'{dol_value_mysoc_capital}', $mysoc->capital, $this->template);
618 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
620 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
621 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
622 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
625 $this->
template = str_replace(
"{",
"<", $this->
template);
626 $this->
template = str_replace(
"}",
">", $this->
template);
627 $p = xml_parser_create();
628 xml_parse_into_struct($p, $this->
template, $vals, $index);
634 $nbcharactbyline = (!empty($conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE) ? $conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE : 48);
639 $nboflines = count($vals);
640 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
642 switch ($vals[$tplline][
'tag']) {
643 case 'DOL_PRINT_TEXT':
644 $this->printer->text($vals[$tplline][
'value']);
646 case 'DOL_PRINT_OBJECT_LINES':
647 foreach ($object->lines as $line) {
648 if ($line->fk_product) {
649 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
650 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
651 $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");
652 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
654 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
655 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
656 $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");
660 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
661 foreach ($object->lines as $line) {
662 if ($line->fk_product) {
663 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
664 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
665 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
666 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
667 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
668 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
669 $this->printer->text($line->description.
"\n");
671 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
672 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
673 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
677 case 'DOL_PRINT_OBJECT_TAX':
680 foreach ($object->lines as $line) {
681 $vatarray[$line->tva_tx] += $line->total_tva;
683 foreach ($vatarray as $vatkey => $vatvalue) {
684 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
685 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
686 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
689 case 'DOL_PRINT_OBJECT_TAX1':
691 $total_localtax1 = 0;
692 foreach ($object->lines as $line) {
693 $total_localtax1 += $line->total_localtax1;
695 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
697 case 'DOL_PRINT_OBJECT_TAX2':
699 $total_localtax2 = 0;
700 foreach ($object->lines as $line) {
701 $total_localtax2 += $line->total_localtax2;
703 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
705 case 'DOL_PRINT_OBJECT_TOTAL':
706 $title = $langs->trans(
'TotalHT');
707 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
708 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
709 $this->printer->text($title.$spaces.str_pad(
price($object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
710 $title = $langs->trans(
'TotalVAT');
711 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
712 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
713 $this->printer->text($title.$spaces.str_pad(
price($object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
714 $title = $langs->trans(
'TotalTTC');
715 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
716 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
717 $this->printer->text($title.$spaces.str_pad(
price($object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
719 case 'DOL_PRINT_CURR_DATE':
720 if (strlen($vals[$tplline][
'value'])<2) $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
721 else $this->printer->text(date($vals[$tplline][
'value']).
"\n");
723 case 'DOL_LINE_FEED':
724 $this->printer->feed();
726 case 'DOL_LINE_FEED_REVERSE':
727 $this->printer->feedReverse();
729 case 'DOL_ALIGN_CENTER':
730 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
732 case 'DOL_ALIGN_RIGHT':
733 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
735 case 'DOL_ALIGN_LEFT':
736 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
738 case 'DOL_OPEN_DRAWER':
739 $this->printer->pulse();
741 case 'DOL_ACTIVATE_BUZZER':
744 case 'DOL_PRINT_BARCODE':
748 $this->printer->barcode($vals[$tplline][
'value']);
750 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
754 case 'DOL_PRINT_LOGO':
755 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
756 $this->printer->graphics($img);
758 case 'DOL_PRINT_LOGO_OLD':
759 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
760 $this->printer->bitImage($img);
762 case 'DOL_PRINT_QRCODE':
764 $this->printer->qrcode($vals[$tplline][
'value']);
766 case 'DOL_CUT_PAPER_FULL':
767 $this->printer->cut(Printer::CUT_FULL);
769 case 'DOL_CUT_PAPER_PARTIAL':
770 $this->printer->cut(Printer::CUT_PARTIAL);
772 case 'DOL_USE_FONT_A':
773 $this->printer->setFont(Printer::FONT_A);
775 case 'DOL_USE_FONT_B':
776 $this->printer->setFont(Printer::FONT_B);
778 case 'DOL_USE_FONT_C':
779 $this->printer->setFont(Printer::FONT_C);
782 $this->printer->setEmphasis(
true);
784 case 'DOL_BOLD_DISABLED':
785 $this->printer->setEmphasis(
false);
787 case 'DOL_DOUBLE_HEIGHT':
788 $this->printer->setTextSize(1, 2);
790 case 'DOL_DOUBLE_WIDTH':
791 $this->printer->setTextSize(2, 1);
793 case 'DOL_DEFAULT_HEIGHT_WIDTH':
794 $this->printer->setTextSize(1, 1);
796 case 'DOL_UNDERLINE':
797 $this->printer->setUnderline(
true);
799 case 'DOL_UNDERLINE_DISABLED':
800 $this->printer->setUnderline(
false);
803 $this->printer->getPrintConnector() -> write(
"\x1e");
805 case 'DOL_BEEP_ALTERNATIVE':
806 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
808 case 'DOL_PRINT_ORDER_LINES':
809 foreach ($object->lines as $line) {
810 if ($line->special_code == $this->orderprinter) {
811 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
812 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
813 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
814 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
818 case 'DOL_PRINT_PAYMENT':
819 $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,";
821 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->
db->prefix().
"paiement as p";
822 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
823 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
824 $sql .=
" ORDER BY p.datep";
830 $row = $this->
db->fetch_object(
$resql);
831 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
832 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
833 $amount_payment = (!empty($conf->multicurrency->enabled) && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
834 if ($row->code ==
"LIQ") {
835 $amount_payment = $amount_payment + $row->pos_change;
837 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
838 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
839 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
840 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
841 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
847 case 'DOL_VALUE_PLACE':
848 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $object->ref)));
850 $obj = $this->
db->fetch_object(
$resql);
852 $this->printer->text($obj->label);
856 $this->printer->text($vals[$tplline][
'tag']);
857 $this->printer->text($vals[$tplline][
'value']);
858 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
864 if ($this->printer->connector instanceof DummyPrintConnector || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
865 $data = $this->printer->connector->getData();
866 if ($conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
867 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
872 $this->printer->close();
887 $sql =
"SELECT template";
888 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt_template";
889 $sql .=
" WHERE rowid = ".((int) $templateid);
890 $sql .=
" AND entity = ".$conf->entity;
893 $obj = $this->
db->fetch_array(
$resql);
896 $this->errors[] = $this->
db->lasterror;
900 $this->errors[] =
'TemplateDontExist';
902 $this->
template = $obj[
'0'];
919 $this->connector =
new DummyPrintConnector();
920 $this->printer =
new Printer($this->connector, $this->profile);
924 $sql =
"SELECT rowid, name, fk_type, fk_profile, parameter";
925 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt";
926 $sql .=
" WHERE rowid = ".((int) $printerid);
927 $sql .=
" AND entity = ".((int) $conf->entity);
930 $obj = $this->
db->fetch_array(
$resql);
933 $this->errors[] =
'PrinterDontExist';
936 $parameter = (isset($obj[
'parameter']) ? $obj[
'parameter'] :
'');
938 $type = $obj[
'fk_type'];
941 $this->connector =
new DummyPrintConnector();
944 $this->connector =
new FilePrintConnector($parameter);
947 $parameters = explode(
':', $parameter);
948 $this->connector =
new NetworkPrintConnector($parameters[0], $parameters[1]);
954 $this->connector =
new CupsPrintConnector($parameter);
957 $this->connector =
'CONNECTOR_UNKNOWN';
960 $this->printer =
new Printer($this->connector, $this->profile);
962 $this->errors[] = $e->getMessage();
968 $this->errors[] = $this->
db->lasterror;