108 require_once DOL_DOCUMENT_ROOT.
'/includes/mike42/escpos-php/autoload.php';
109 use Mike42\Escpos\PrintConnectors\FilePrintConnector;
110 use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
111 use Mike42\Escpos\PrintConnectors\WindowsPrintConnector;
112 use Mike42\Escpos\PrintConnectors\CupsPrintConnector;
113 use Mike42\Escpos\PrintConnectors\DummyPrintConnector;
114 use Mike42\Escpos\CapabilityProfile;
115 use Mike42\Escpos\Printer;
116 use Mike42\Escpos\EscposImage;
123 const CONNECTOR_DUMMY = 1;
124 const CONNECTOR_FILE_PRINT = 2;
125 const CONNECTOR_NETWORK_PRINT = 3;
126 const CONNECTOR_WINDOWS_PRINT = 4;
127 const CONNECTOR_CUPS_PRINT = 5;
145 public $orderprinter;
155 public $errors = array();
166 'dol_line_feed' =>
'DOL_LINE_FEED',
167 'dol_line_feed_reverse' =>
'DOL_LINE_FEED_REVERSE',
168 'dol_align_left' =>
'DOL_ALIGN_LEFT',
169 'dol_align_center' =>
'DOL_ALIGN_CENTER',
170 'dol_align_right' =>
'DOL_ALIGN_RIGHT',
171 'dol_use_font_a' =>
'DOL_USE_FONT_A',
172 'dol_use_font_b' =>
'DOL_USE_FONT_B',
173 'dol_use_font_c' =>
'DOL_USE_FONT_C',
174 'dol_bold' =>
'DOL_BOLD',
175 'dol_bold_disabled' =>
'DOL_BOLD_DISABLED',
176 'dol_double_height' =>
'DOL_DOUBLE_HEIGHT',
177 'dol_double_width' =>
'DOL_DOUBLE_WIDTH',
178 'dol_default_height_width' =>
'DOL_DEFAULT_HEIGHT_WIDTH',
179 'dol_underline' =>
'DOL_UNDERLINE',
180 'dol_underline_disabled' =>
'DOL_UNDERLINE_DISABLED',
181 'dol_cut_paper_full' =>
'DOL_CUT_PAPER_FULL',
182 'dol_cut_paper_partial' =>
'DOL_CUT_PAPER_PARTIAL',
183 'dol_open_drawer' =>
'DOL_OPEN_DRAWER',
184 'dol_beep' =>
'DOL_BEEP',
185 'dol_beep_alternative' =>
'DOL_BEEP_ALTERNATIVE',
186 'dol_print_text' =>
'DOL_PRINT_TEXT',
187 'dol_print_barcode' =>
'DOL_PRINT_BARCODE',
188 'dol_value_date' =>
'DateInvoice',
189 'dol_value_date_time' =>
'DateInvoiceWithTime',
190 'dol_value_year' =>
'YearInvoice',
191 'dol_value_month_letters' =>
'DOL_VALUE_MONTH_LETTERS',
192 'dol_value_month' =>
'DOL_VALUE_MONTH',
193 'dol_value_day' =>
'DOL_VALUE_DAY',
194 'dol_value_day_letters' =>
'DOL_VALUE_DAY',
195 'dol_value_currentdate' =>
'DOL_VALUE_CURRENTDATE',
196 'dol_value_currentdate_notime' =>
'CurrentDateWithTime',
197 'dol_value_currentdate_letters' =>
'DOL_VALUE_CURRENTDATE_LETTERS',
198 'dol_value_currentyear' =>
'CurrentYear',
199 'dol_value_currentmonth_letters' =>
'DOL_VALUE_CURRENT_MONTH_LETTERS',
200 'dol_value_currentmonth' =>
'DOL_VALUE_CURRENT_MONTH',
201 'dol_value_currentday' =>
'DOL_VALUE_CURRENT_DAY',
202 'dol_value_currentday_letters' =>
'DOL_VALUE_CURRENT_DAY',
203 'dol_print_payment' =>
'DOL_PRINT_PAYMENT',
204 'dol_print_curr_date' =>
'DOL_PRINT_CURR_DATE',
205 'dol_print_logo' =>
'DOL_PRINT_LOGO',
206 'dol_print_logo_old' =>
'DOL_PRINT_LOGO_OLD',
207 'dol_print_logo_old_cf' =>
'DOL_PRINT_LOGO_OLD_CF',
208 'dol_value_object_id' =>
'InvoiceID',
209 'dol_value_object_ref' =>
'InvoiceRef',
210 'dol_print_object_lines' =>
'DOL_PRINT_OBJECT_LINES',
211 'dol_print_object_lines_with_notes' =>
'DOL_PRINT_OBJECT_LINES_WITH_NOTES',
212 'dol_print_object_tax' =>
'TotalVAT',
213 'dol_print_object_local_tax1' =>
'TotalLT1',
214 'dol_print_object_local_tax2' =>
'TotalLT2',
215 'dol_print_object_total' =>
'Total',
216 'dol_print_object_number' =>
'DOL_PRINT_OBJECT_NUMBER',
218 'dol_print_order_lines' =>
'DOL_PRINT_ORDER_LINES',
219 'dol_value_customer_firstname' =>
'DOL_VALUE_CUSTOMER_FIRSTNAME',
220 'dol_value_customer_lastname' =>
'DOL_VALUE_CUSTOMER_LASTNAME',
221 'dol_value_customer_mail' =>
'DOL_VALUE_CUSTOMER_MAIL',
222 'dol_value_customer_phone' =>
'DOL_VALUE_CUSTOMER_PHONE',
223 'dol_value_customer_skype' =>
'DOL_VALUE_CUSTOMER_SKYPE',
224 'dol_value_customer_tax_number' =>
'DOL_VALUE_CUSTOMER_TAX_NUMBER',
227 'dol_value_mysoc_name' =>
'DOL_VALUE_MYSOC_NAME',
228 'dol_value_mysoc_address' =>
'Address',
229 'dol_value_mysoc_zip' =>
'Zip',
230 'dol_value_mysoc_town' =>
'Town',
231 'dol_value_mysoc_country' =>
'Country',
232 'dol_value_mysoc_idprof1' =>
'ProfId1',
233 'dol_value_mysoc_idprof2' =>
'ProfId2',
234 'dol_value_mysoc_idprof3' =>
'ProfId3',
235 'dol_value_mysoc_idprof4' =>
'ProfId4',
236 'dol_value_mysoc_idprof5' =>
'ProfId5',
237 'dol_value_mysoc_idprof6' =>
'ProfId6',
238 'dol_value_mysoc_tva_intra' =>
'VATIntra',
239 'dol_value_mysoc_capital' =>
'Capital',
240 'dol_value_mysoc_url' =>
'Web',
241 'dol_value_vendor_lastname' =>
'VendorLastname',
242 'dol_value_vendor_firstname' =>
'VendorFirstname',
243 'dol_value_vendor_mail' =>
'VendorEmail',
244 'dol_value_place' =>
'DOL_VALUE_PLACE',
259 $sql =
"SELECT rowid, name, fk_type, fk_profile, parameter";
260 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt";
261 $sql .=
" WHERE entity = ".$conf->entity;
265 while ($line < $num) {
266 $row = $this->
db->fetch_array(
$resql);
267 switch ($row[
'fk_type']) {
269 $row[
'fk_type_name'] =
'CONNECTOR_DUMMY';
272 $row[
'fk_type_name'] =
'CONNECTOR_FILE_PRINT';
275 $row[
'fk_type_name'] =
'CONNECTOR_NETWORK_PRINT';
278 $row[
'fk_type_name'] =
'CONNECTOR_WINDOWS_PRINT';
281 $row[
'fk_type_name'] =
'CONNECTOR_CUPS_PRINT';
284 $row[
'fk_type_name'] =
'CONNECTOR_UNKNOWN';
287 switch ($row[
'fk_profile']) {
289 $row[
'fk_profile_name'] =
'PROFILE_DEFAULT';
292 $row[
'fk_profile_name'] =
'PROFILE_SIMPLE';
295 $row[
'fk_profile_name'] =
'PROFILE_EPOSTEP';
298 $row[
'fk_profile_name'] =
'PROFILE_P822D';
301 $row[
'fk_profile_name'] =
'PROFILE_STAR';
309 $this->errors[] = $this->
db->lasterror;
311 $this->listprinters = $obj;
327 $sql =
"SELECT rowid, name, template";
328 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt_template";
329 $sql .=
" WHERE entity = ".$conf->entity;
333 while ($line < $num) {
334 $obj[] = $this->
db->fetch_array(
$resql);
339 $this->errors[] = $this->
db->lasterror;
341 $this->listprinterstemplates = $obj;
358 1 => $langs->trans(
'CONNECTOR_DUMMY'),
359 2 => $langs->trans(
'CONNECTOR_FILE_PRINT'),
360 3 => $langs->trans(
'CONNECTOR_NETWORK_PRINT'),
361 4 => $langs->trans(
'CONNECTOR_WINDOWS_PRINT'),
362 5 => $langs->trans(
'CONNECTOR_CUPS_PRINT'),
383 0 => $langs->trans(
'PROFILE_DEFAULT'),
384 1 => $langs->trans(
'PROFILE_SIMPLE'),
385 2 => $langs->trans(
'PROFILE_EPOSTEP'),
386 3 => $langs->trans(
'PROFILE_P822D'),
387 4 => $langs->trans(
'PROFILE_STAR'),
404 public function addPrinter($name, $type, $profile, $parameter)
408 $sql =
"INSERT INTO ".$this->db->prefix().
"printer_receipt";
409 $sql .=
" (name, fk_type, fk_profile, parameter, entity)";
410 $sql .=
" VALUES ('".$this->db->escape($name).
"', ".((int) $type).
", ".((int) $profile).
", '".$this->
db->escape($parameter).
"', ".((int) $conf->entity).
")";
414 $this->errors[] = $this->
db->lasterror;
429 public function updatePrinter($name, $type, $profile, $parameter, $printerid)
434 $sql =
"UPDATE ".$this->db->prefix().
"printer_receipt";
435 $sql .=
" SET name='".$this->db->escape($name).
"'";
436 $sql .=
", fk_type=".((int) $type);
437 $sql .=
", fk_profile=".((int) $profile);
438 $sql .=
", parameter='".$this->db->escape($parameter).
"'";
439 $sql .=
" WHERE rowid=".((int) $printerid);
444 $this->errors[] = $this->
db->lasterror;
459 $sql =
'DELETE FROM '.$this->db->prefix().
'printer_receipt';
460 $sql .=
' WHERE rowid='.((int) $printerid);
464 $this->errors[] = $this->
db->lasterror;
480 $sql =
"INSERT INTO ".$this->db->prefix().
"printer_receipt_template";
481 $sql .=
" (name, template, entity) VALUES ('".$this->db->escape($name).
"'";
482 $sql .=
", '".$this->db->escape($template).
"', ".$conf->entity.
")";
486 $this->errors[] = $this->
db->lasterror;
501 $sql =
'DELETE FROM '.$this->db->prefix().
'printer_receipt_template';
502 $sql .=
" WHERE rowid = ".((int) $templateid);
503 $sql .=
" AND entity = ".$conf->entity;
507 $this->errors[] = $this->
db->lasterror;
525 $sql =
"UPDATE ".$this->db->prefix().
"printer_receipt_template";
526 $sql .=
" SET name='".$this->db->escape($name).
"'";
527 $sql .=
", template='".$this->db->escape($template).
"'";
528 $sql .=
" WHERE rowid=".((int) $templateid);
532 $this->errors[] = $this->
db->lasterror;
549 $img = EscposImage::load(DOL_DOCUMENT_ROOT.
'/theme/dolibarr_logo_bw.png');
556 $this->printer->bitImage($img);
557 $this->printer->text(
"Hello World!\n");
558 $testStr =
"1234567890";
559 $this->printer->barcode($testStr);
561 $this->printer->text(
"Most simple example\n");
562 $this->printer->feed();
563 $this->printer->cut();
566 if ($this->printer->connector instanceof DummyPrintConnector) {
567 $data = $this->printer->connector->getData();
570 $this->printer->close();
572 $this->errors[] = $e->getMessage();
589 global $conf, $mysoc, $langs, $user;
591 $langs->load(
'bills');
597 $this->
template = str_replace(
'{dol_value_object_id}', $object->id, $this->template);
598 $this->
template = str_replace(
'{dol_value_object_ref}', $object->ref, $this->template);
600 $this->
template = str_replace(
'{dol_value_date}',
dol_print_date($object->date,
'day'), $this->template);
601 $this->
template = str_replace(
'{dol_value_date_time}',
dol_print_date($object->date,
'dayhour'), $this->template);
602 $this->
template = str_replace(
'{dol_value_year}',
dol_print_date($object->date,
'%Y'), $this->template);
603 $this->
template = str_replace(
'{dol_value_month_letters}', $langs->trans(
"Month".dol_print_date($object->date,
'%m')), $this->template);
604 $this->
template = str_replace(
'{dol_value_month}',
dol_print_date($object->date,
'%m'), $this->template);
605 $this->
template = str_replace(
'{dol_value_day}',
dol_print_date($object->date,
'%d'), $this->template);
606 $this->
template = str_replace(
'{dol_value_day_letters}', $langs->trans(
"Day".dol_print_date($object->date,
'%m')[1]), $this->template);
608 $this->
template = str_replace(
'{dol_value_currentdate}',
dol_print_date($now,
'dayhour'), $this->
template);
609 $this->
template = str_replace(
'{dol_value_currentdate_notime}',
dol_print_date($now,
'day'), $this->
template);
610 $this->
template = str_replace(
'{dol_value_currentdate_letters}',
dol_print_date($now,
'dayhourtext'), $this->
template);
611 $this->
template = str_replace(
'{dol_value_currentyear}',
dol_print_date($now,
'%Y'), $this->
template);
612 $this->
template = str_replace(
'{dol_value_currentmonth_letters}', $langs->trans(
"Month".dol_print_date($now,
'%m')), $this->template);
613 $this->
template = str_replace(
'{dol_value_currentmonth}',
dol_print_date($now,
'%m'), $this->
template);
614 $this->
template = str_replace(
'{dol_value_currentday}',
dol_print_date($now,
'%d'), $this->
template);
615 $this->
template = str_replace(
'{dol_value_currentday_letters}', $langs->trans(
"Day".dol_print_date($now,
'%m')[1]), $this->template);
617 $this->
template = str_replace(
'{dol_value_customer_firstname}', $object->thirdparty->firstname, $this->template);
618 $this->
template = str_replace(
'{dol_value_customer_lastname}', $object->thirdparty->lastname, $this->template);
619 $this->
template = str_replace(
'{dol_value_customer_mail}', $object->thirdparty->email, $this->template);
620 $this->
template = str_replace(
'{dol_value_customer_phone}', $object->thirdparty->phone, $this->template);
622 $this->
template = str_replace(
'{dol_value_customer_tax_number}', $object->thirdparty->tva_intra, $this->template);
626 $this->
template = str_replace(
'{dol_value_mysoc_name}', $mysoc->name, $this->template);
627 $this->
template = str_replace(
'{dol_value_mysoc_address}', $mysoc->address, $this->template);
628 $this->
template = str_replace(
'{dol_value_mysoc_zip}', $mysoc->zip, $this->template);
629 $this->
template = str_replace(
'{dol_value_mysoc_town}', $mysoc->town, $this->template);
630 $this->
template = str_replace(
'{dol_value_mysoc_country}', $mysoc->country, $this->template);
631 $this->
template = str_replace(
'{dol_value_mysoc_idprof1}', $mysoc->idprof1, $this->template);
632 $this->
template = str_replace(
'{dol_value_mysoc_idprof2}', $mysoc->idprof2, $this->template);
633 $this->
template = str_replace(
'{dol_value_mysoc_idprof3}', $mysoc->idprof3, $this->template);
634 $this->
template = str_replace(
'{dol_value_mysoc_idprof4}', $mysoc->idprof4, $this->template);
635 $this->
template = str_replace(
'{dol_value_mysoc_idprof5}', $mysoc->idprof5, $this->template);
636 $this->
template = str_replace(
'{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template);
637 $this->
template = str_replace(
'{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template);
638 $this->
template = str_replace(
'{dol_value_mysoc_capital}', $mysoc->capital, $this->template);
639 $this->
template = str_replace(
'{dol_value_mysoc_url}', $mysoc->url, $this->template);
641 $this->
template = str_replace(
'{dol_value_vendor_firstname}', $user->firstname, $this->template);
642 $this->
template = str_replace(
'{dol_value_vendor_lastname}', $user->lastname, $this->template);
643 $this->
template = str_replace(
'{dol_value_vendor_mail}', $user->email, $this->template);
646 $this->
template = str_replace(
"{",
"<", $this->
template);
647 $this->
template = str_replace(
"}",
">", $this->
template);
648 $p = xml_parser_create();
649 xml_parse_into_struct($p, $this->
template, $vals, $index);
655 $nbcharactbyline = (!empty($conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE) ? $conf->global->RECEIPT_PRINTER_NB_CHARACT_BY_LINE : 48);
660 $nboflines = count($vals);
661 for ($tplline = 0; $tplline < $nboflines; $tplline++) {
663 switch ($vals[$tplline][
'tag']) {
664 case 'DOL_PRINT_TEXT':
665 $this->printer->text($vals[$tplline][
'value']);
667 case 'DOL_PRINT_OBJECT_LINES':
668 foreach ($object->lines as $line) {
669 if ($line->fk_product) {
670 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
671 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
672 $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");
673 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n \n");
675 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - strlen($line->subprice) - 10 - 1;
676 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
677 $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");
681 case 'DOL_PRINT_OBJECT_LINES_WITH_NOTES':
682 foreach ($object->lines as $line) {
683 if ($line->fk_product) {
684 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
685 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
686 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
687 $this->printer->text(strip_tags(htmlspecialchars_decode($line->product_label)).
"\n");
688 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
689 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
690 $this->printer->text($line->description.
"\n");
692 $spacestoadd = $nbcharactbyline - strlen($line->description) - strlen($line->qty) - 10 - 1;
693 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
694 $this->printer->text($line->description.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
698 case 'DOL_PRINT_OBJECT_TAX':
701 foreach ($object->lines as $line) {
702 $vatarray[$line->tva_tx] += $line->total_tva;
704 foreach ($vatarray as $vatkey => $vatvalue) {
705 $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12;
706 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
707 $this->printer->text($spaces.$vatkey.
'% '.str_pad(
price($vatvalue), 10,
' ', STR_PAD_LEFT).
"\n");
710 case 'DOL_PRINT_OBJECT_TAX1':
712 $total_localtax1 = 0;
713 foreach ($object->lines as $line) {
714 $total_localtax1 += $line->total_localtax1;
716 $this->printer->text(str_pad(
price($total_localtax1), 10,
' ', STR_PAD_LEFT).
"\n");
718 case 'DOL_PRINT_OBJECT_TAX2':
720 $total_localtax2 = 0;
721 foreach ($object->lines as $line) {
722 $total_localtax2 += $line->total_localtax2;
724 $this->printer->text(str_pad(
price($total_localtax2), 10,
' ', STR_PAD_LEFT).
"\n");
726 case 'DOL_PRINT_OBJECT_TOTAL':
727 $title = $langs->trans(
'TotalHT');
728 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
729 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
730 $this->printer->text($title.$spaces.str_pad(
price($object->total_ht), 10,
' ', STR_PAD_LEFT).
"\n");
731 $title = $langs->trans(
'TotalVAT');
732 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
733 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
734 $this->printer->text($title.$spaces.str_pad(
price($object->total_tva), 10,
' ', STR_PAD_LEFT).
"\n");
735 $title = $langs->trans(
'TotalTTC');
736 $spacestoadd = $nbcharactbyline - strlen($title) - 10;
737 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
738 $this->printer->text($title.$spaces.str_pad(
price($object->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
740 case 'DOL_PRINT_CURR_DATE':
741 if (strlen($vals[$tplline][
'value'])<2) $this->printer->text(date(
'd/m/Y H:i:s').
"\n");
742 else $this->printer->text(date($vals[$tplline][
'value']).
"\n");
744 case 'DOL_LINE_FEED':
745 $this->printer->feed();
747 case 'DOL_LINE_FEED_REVERSE':
748 $this->printer->feedReverse();
750 case 'DOL_ALIGN_CENTER':
751 $this->printer->setJustification(Printer::JUSTIFY_CENTER);
753 case 'DOL_ALIGN_RIGHT':
754 $this->printer->setJustification(Printer::JUSTIFY_RIGHT);
756 case 'DOL_ALIGN_LEFT':
757 $this->printer->setJustification(Printer::JUSTIFY_LEFT);
759 case 'DOL_OPEN_DRAWER':
760 $this->printer->pulse();
762 case 'DOL_ACTIVATE_BUZZER':
765 case 'DOL_PRINT_BARCODE':
769 $this->printer->barcode($vals[$tplline][
'value']);
771 $this->errors[] =
'Invalid Barcode value: '.$vals[$tplline][
'value'];
775 case 'DOL_PRINT_LOGO':
776 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
777 $this->printer->graphics($img);
779 case 'DOL_PRINT_LOGO_OLD':
780 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
781 $this->printer->bitImage($img);
783 case 'DOL_PRINT_LOGO_OLD_CF':
784 $img = EscposImage::load(DOL_DATA_ROOT.
'/mycompany/logos/'.$mysoc->logo);
785 $this->printer->bitImageColumnFormat($img);
787 case 'DOL_PRINT_QRCODE':
789 $this->printer->qrcode($vals[$tplline][
'value']);
791 case 'DOL_CUT_PAPER_FULL':
792 $this->printer->cut(Printer::CUT_FULL);
794 case 'DOL_CUT_PAPER_PARTIAL':
795 $this->printer->cut(Printer::CUT_PARTIAL);
797 case 'DOL_USE_FONT_A':
798 $this->printer->setFont(Printer::FONT_A);
800 case 'DOL_USE_FONT_B':
801 $this->printer->setFont(Printer::FONT_B);
803 case 'DOL_USE_FONT_C':
804 $this->printer->setFont(Printer::FONT_C);
807 $this->printer->setEmphasis(
true);
809 case 'DOL_BOLD_DISABLED':
810 $this->printer->setEmphasis(
false);
812 case 'DOL_DOUBLE_HEIGHT':
813 $this->printer->setTextSize(1, 2);
815 case 'DOL_DOUBLE_WIDTH':
816 $this->printer->setTextSize(2, 1);
818 case 'DOL_DEFAULT_HEIGHT_WIDTH':
819 $this->printer->setTextSize(1, 1);
821 case 'DOL_UNDERLINE':
822 $this->printer->setUnderline(
true);
824 case 'DOL_UNDERLINE_DISABLED':
825 $this->printer->setUnderline(
false);
828 $this->printer->getPrintConnector() -> write(
"\x1e");
830 case 'DOL_BEEP_ALTERNATIVE':
831 $this->printer->getPrintConnector() -> write(Printer::ESC .
"B" . chr(4) . chr(1));
833 case 'DOL_PRINT_ORDER_LINES':
834 foreach ($object->lines as $line) {
835 if ($line->special_code == $this->orderprinter) {
836 $spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
837 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
838 $this->printer->text($line->ref.$spaces.$line->qty.
' '.str_pad(
price($line->total_ttc), 10,
' ', STR_PAD_LEFT).
"\n");
839 $this->printer->text(strip_tags(htmlspecialchars_decode($line->desc)).
"\n");
843 case 'DOL_PRINT_PAYMENT':
844 $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,";
846 $sql .=
" FROM ".$this->db->prefix().
"paiement_facture as pf, ".$this->
db->prefix().
"paiement as p";
847 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as cp ON p.fk_paiement = cp.id";
848 $sql .=
" WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id);
849 $sql .=
" ORDER BY p.datep";
855 $row = $this->
db->fetch_object(
$resql);
856 $spacestoadd = $nbcharactbyline - strlen($langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code)) - 12;
857 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
858 $amount_payment = (
isModEnabled(
"multicurrency") && $object->multicurrency_tx != 1) ? $row->multicurrency_amount : $row->amount;
859 if ($row->code ==
"LIQ") {
860 $amount_payment = $amount_payment + $row->pos_change;
862 $this->printer->text($spaces.$langs->transnoentitiesnoconv(
"PaymentTypeShort".$row->code).
' '.str_pad(
price($amount_payment), 10,
' ', STR_PAD_LEFT).
"\n");
863 if ($row->code ==
"LIQ" && $row->pos_change > 0) {
864 $spacestoadd = $nbcharactbyline - strlen($langs->trans(
"Change")) - 12;
865 $spaces = str_repeat(
' ', $spacestoadd > 0 ? $spacestoadd : 0);
866 $this->printer->text($spaces.$langs->trans(
"Change").
' '.str_pad(
price($row->pos_change), 10,
' ', STR_PAD_LEFT).
"\n");
872 case 'DOL_VALUE_PLACE':
873 $sql =
"SELECT floor, label FROM ".$this->db->prefix().
"takepos_floor_tables where rowid=".((int) str_replace(
")",
"", str_replace(
"(PROV-POS".$_SESSION[
"takeposterminal"].
"-",
"", $object->ref)));
875 $obj = $this->
db->fetch_object(
$resql);
877 $this->printer->text($obj->label);
881 $this->printer->text($vals[$tplline][
'tag']);
882 $this->printer->text($vals[$tplline][
'value']);
883 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$tplline][
'tag']).
'>';
889 if ($this->printer->connector instanceof DummyPrintConnector || $conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
890 $data = $this->printer->connector->getData();
891 if ($conf->global->TAKEPOS_PRINT_METHOD ==
"takeposconnector") {
892 echo rtrim(strtr(base64_encode($data),
'+/',
'-_'),
'=');
897 $this->printer->close();
912 $sql =
"SELECT template";
913 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt_template";
914 $sql .=
" WHERE rowid = ".((int) $templateid);
915 $sql .=
" AND entity = ".$conf->entity;
918 $obj = $this->
db->fetch_array(
$resql);
921 $this->errors[] = $this->
db->lasterror;
925 $this->errors[] =
'TemplateDontExist';
927 $this->
template = $obj[
'0'];
944 $this->connector =
new DummyPrintConnector();
945 $this->printer =
new Printer($this->connector, $this->profile);
949 $sql =
"SELECT rowid, name, fk_type, fk_profile, parameter";
950 $sql .=
" FROM ".$this->db->prefix().
"printer_receipt";
951 $sql .=
" WHERE rowid = ".((int) $printerid);
952 $sql .=
" AND entity = ".((int) $conf->entity);
955 $obj = $this->
db->fetch_array(
$resql);
958 $this->errors[] =
'PrinterDontExist';
961 $parameter = (isset($obj[
'parameter']) ? $obj[
'parameter'] :
'');
963 $type = $obj[
'fk_type'];
966 $this->connector =
new DummyPrintConnector();
969 $this->connector =
new FilePrintConnector($parameter);
972 $parameters = explode(
':', $parameter);
973 $this->connector =
new NetworkPrintConnector($parameters[0], $parameters[1]);
979 $this->connector =
new CupsPrintConnector($parameter);
982 $this->connector =
'CONNECTOR_UNKNOWN';
985 $this->printer =
new Printer($this->connector, $this->profile);
987 $this->errors[] = $e->getMessage();
993 $this->errors[] = $this->
db->lasterror;
Class to manage Receipt Printers.
selectTypePrinter($selected='', $htmlname='printertypeid')
Form to Select type printer.
addPrinter($name, $type, $profile, $parameter)
Function to Add a printer in db.
updatePrinter($name, $type, $profile, $parameter, $printerid)
Function to Update a printer in db.
sendToPrinter($object, $templateid, $printerid)
Function to Print Receipt Ticket.
listPrinters()
list printers
__construct($db)
Constructor.
loadTemplate($templateid)
Function to load Template.
updateTemplate($name, $template, $templateid)
Function to Update a printer template in db.
sendTestToPrinter($printerid)
Function to Send Test page to Printer.
initPrinter($printerid)
Function Init Printer.
deleteTemplate($templateid)
Function to delete a printer template in db.
deletePrinter($printerid)
Function to Delete a printer from db.
selectProfilePrinter($selected='', $htmlname='printerprofileid')
Form to Select Profile printer.
addTemplate($name, $template)
Function to add a printer template in db.
listPrintersTemplates()
List printers templates.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_sanitizePathName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a path name.
if(!defined( 'CSRFCHECK_WITH_TOKEN'))
$conf db
API class for accounts.