95 require_once DOL_DOCUMENT_ROOT .
'/includes/mike42/escpos-php/Escpos.php';
103 const CONNECTOR_DUMMY = 1;
104 const CONNECTOR_FILE_PRINT = 2;
105 const CONNECTOR_NETWORK_PRINT = 3;
106 const CONNECTOR_WINDOWS_PRINT = 4;
126 public $errors = array();
148 '/dol_double_height',
153 'dol_underline_2dots',
158 '/dol_switch_colors',
160 'dol_print_barcode_customer_id',
161 'dol_set_print_width_57',
162 'dol_cut_paper_full',
163 'dol_cut_paper_partial',
165 'dol_activate_buzzer',
168 'dol_print_date_time',
170 'dol_print_month_letters',
173 'dol_print_day_letters',
178 'dol_print_logo_old',
179 'dol_print_order_lines',
180 'dol_print_order_tax',
181 'dol_print_order_local_tax',
182 'dol_print_order_total',
183 'dol_print_order_number',
184 'dol_print_order_number_unique',
185 'dol_print_customer_firstname',
186 'dol_print_customer_lastname',
187 'dol_print_customer_mail',
188 'dol_print_customer_phone',
189 'dol_print_customer_mobile',
190 'dol_print_customer_skype',
191 'dol_print_customer_tax_number',
192 'dol_print_customer_account_balance',
193 'dol_print_vendor_lastname',
194 'dol_print_vendor_firstname',
195 'dol_print_vendor_mail',
196 'dol_print_customer_points',
197 'dol_print_order_points',
198 'dol_print_if_customer',
199 'dol_print_if_vendor',
200 'dol_print_if_happy_hour',
201 'dol_print_if_num_order_unique',
202 'dol_print_if_customer_points',
203 'dol_print_if_order_points',
204 'dol_print_if_customer_tax_number',
205 'dol_print_if_customer_account_balance_positive',
220 $sql =
'SELECT rowid, name, fk_type, fk_profile, parameter';
221 $sql.=
' FROM '.MAIN_DB_PREFIX.
'printer_receipt';
222 $sql.=
' WHERE entity = '.$conf->entity;
223 $resql = $this->db->query($sql);
225 $num = $this->db->num_rows(
$resql);
226 while ($line < $num) {
227 $row = $this->db->fetch_array(
$resql);
228 switch ($row[
'fk_type']) {
230 $row[
'fk_type_name'] =
'CONNECTOR_DUMMY';
233 $row[
'fk_type_name'] =
'CONNECTOR_FILE_PRINT';
236 $row[
'fk_type_name'] =
'CONNECTOR_NETWORK_PRINT';
239 $row[
'fk_type_name'] =
'CONNECTOR_WINDOWS_PRINT';
242 $row[
'fk_type_name'] =
'CONNECTOR_JAVA';
245 $row[
'fk_type_name'] =
'CONNECTOR_UNKNOWN';
248 switch ($row[
'fk_profile']) {
250 $row[
'fk_profile_name'] =
'PROFILE_DEFAULT';
253 $row[
'fk_profile_name'] =
'PROFILE_SIMPLE';
256 $row[
'fk_profile_name'] =
'PROFILE_EPOSTEP';
259 $row[
'fk_profile_name'] =
'PROFILE_P822D';
262 $row[
'fk_profile_name'] =
'PROFILE_STAR';
270 $this->errors[] = $this->db->lasterror;
272 $this->listprinters = $obj;
288 $sql =
'SELECT rowid, name, template';
289 $sql.=
' FROM '.MAIN_DB_PREFIX.
'printer_receipt_template';
290 $sql.=
' WHERE entity = '.$conf->entity;
291 $resql = $this->db->query($sql);
293 $num = $this->db->num_rows(
$resql);
294 while ($line < $num) {
295 $obj[] = $this->db->fetch_array(
$resql);
300 $this->errors[] = $this->db->lasterror;
302 $this->listprinterstemplates = $obj;
319 1 => $langs->trans(
'CONNECTOR_DUMMY'),
320 2 => $langs->trans(
'CONNECTOR_FILE_PRINT'),
321 3 => $langs->trans(
'CONNECTOR_NETWORK_PRINT'),
322 4 => $langs->trans(
'CONNECTOR_WINDOWS_PRINT')
343 0 => $langs->trans(
'PROFILE_DEFAULT'),
344 1 => $langs->trans(
'PROFILE_SIMPLE'),
345 2 => $langs->trans(
'PROFILE_EPOSTEP'),
346 3 => $langs->trans(
'PROFILE_P822D'),
347 4 => $langs->trans(
'PROFILE_STAR')
370 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'printer_receipt';
371 $sql.=
' (name, fk_type, fk_profile, parameter, entity)';
372 $sql.=
' VALUES ("'.$this->db->escape($name).
'", '.$type.
', '.$profile.
', "'.$this->db->escape($parameter).
'", '.$conf->entity.
')';
373 $resql = $this->db->query($sql);
376 $this->errors[] = $this->db->lasterror;
397 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'printer_receipt';
398 $sql.=
' SET name="'.$this->db->escape($name).
'"';
399 $sql.=
', fk_type='.$type;
400 $sql.=
', fk_profile='.$profile;
401 $sql.=
', parameter="'.$this->db->escape($parameter).
'"';
402 $sql.=
' WHERE rowid='.$printerid;
403 $resql = $this->db->query($sql);
406 $this->errors[] = $this->db->lasterror;
423 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
'printer_receipt';
424 $sql.=
' WHERE rowid='.$printerid;
425 $resql = $this->db->query($sql);
428 $this->errors[] = $this->db->lasterror;
447 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'printer_receipt_template';
448 $sql.=
' SET name="'.$this->db->escape($name).
'"';
449 $sql.=
', template="'.$this->db->escape($template).
'"';
450 $sql.=
' WHERE rowid='.$templateid;
451 $resql = $this->db->query($sql);
454 $this->errors[] = $this->db->lasterror;
472 $img =
new EscposImage(DOL_DOCUMENT_ROOT .
'/theme/common/dolibarr_logo_bw.png');
478 $this->printer->graphics($img);
479 $this->printer->text(
"Hello World!\n");
480 $testStr =
"Testing 123";
481 $this->printer->qrCode($testStr);
482 $this->printer->text(
"Most simple example\n");
483 $this->printer->feed();
484 $this->printer->cut();
486 $this->printer->close();
488 $this->errors[] = $e->getMessage();
512 $this->
template = str_replace(
'<dol_print_num_order>', $object->id, $this->template);
513 $this->
template = str_replace(
'<dol_print_customer_firstname>', $object->customer_firstname, $this->template);
514 $this->
template = str_replace(
'<dol_print_customer_lastname>', $object->customer_lastname, $this->template);
515 $this->
template = str_replace(
'<dol_print_customer_mail>', $object->customer_mail, $this->template);
516 $this->
template = str_replace(
'<dol_print_customer_phone>', $object->customer_phone, $this->template);
517 $this->
template = str_replace(
'<dol_print_customer_mobile>', $object->customer_mobile, $this->template);
518 $this->
template = str_replace(
'<dol_print_customer_skype>', $object->customer_skype, $this->template);
519 $this->
template = str_replace(
'<dol_print_customer_tax_number>', $object->customer_tax_number, $this->template);
520 $this->
template = str_replace(
'<dol_print_customer_account_balance>', $object->customer_account_balance, $this->template);
521 $this->
template = str_replace(
'<dol_print_customer_points>', $object->customer_points, $this->template);
522 $this->
template = str_replace(
'<dol_print_order_points>', $object->order_points, $this->template);
523 $this->
template = str_replace(
'<dol_print_vendor_firstname>', $object->vendor_firstname, $this->template);
524 $this->
template = str_replace(
'<dol_print_vendor_lastname>', $object->vendor_lastname, $this->template);
525 $this->
template = str_replace(
'<dol_print_vendor_mail>', $object->vendor_mail, $this->template);
526 $this->
template = str_replace(
'<dol_print_date>', $object->date, $this->template);
527 $this->
template = str_replace(
'<dol_print_date_time>', $object->date_time, $this->template);
528 $this->
template = str_replace(
'<dol_print_year>', $object->date_time, $this->template);
529 $this->
template = str_replace(
'<dol_print_month_letters>', $object->date_time, $this->template);
530 $this->
template = str_replace(
'<dol_print_month>', $object->date_time, $this->template);
531 $this->
template = str_replace(
'<dol_print_day>', $object->date_time, $this->template);
532 $this->
template = str_replace(
'<dol_print_day_letters>', $object->date_time, $this->template);
533 $this->
template = str_replace(
'<dol_print_table>', $object->table, $this->template);
534 $this->
template = str_replace(
'<dol_print_cutlery>', $object->cutlery, $this->template);
537 $p = xml_parser_create();
538 xml_parse_into_struct($p, $this->
template, $vals, $index);
544 $html =
'<table border="1" style="width:210px"><pre>';
551 $nboflines = count($vals);
552 for ($line=0; $line < $nboflines; $line++)
554 switch ($vals[$line][
'tag']) {
555 case 'DOL_ALIGN_CENTER':
556 $this->printer->setJustification(Escpos::JUSTIFY_CENTER);
558 $this->printer->text($vals[$line][
'value']);
560 case 'DOL_ALIGN_RIGHT':
561 $this->printer->setJustification(Escpos::JUSTIFY_RIGHT);
564 case 'DOL_ALIGN_LEFT':
565 $this->printer->setJustification(Escpos::JUSTIFY_LEFT);
568 case 'DOL_OPEN_DRAWER':
569 $this->printer->pulse();
570 $html.=
' ϟ'.nl2br($vals[$line][
'value']);
572 case 'DOL_ACTIVATE_BUZZER':
574 $html.=
' ♫'.nl2br($vals[$line][
'value']);
576 case 'DOL_PRINT_BARCODE':
578 $this->printer->barcode($object->barcode);
580 case 'DOL_PRINT_BARCODE_CUSTOMER_ID':
582 $this->printer->barcode($object->customer_id);
584 case 'DOL_PRINT_QRCODE':
586 $this->printer->qrcode($vals[$line][
'value']);
587 $html.=
'QRCODE: '.$vals[$line][
'value'];
589 case 'DOL_CUT_PAPER_FULL':
590 $this->printer->cut(Escpos::CUT_FULL);
591 $html.=
' ✂'.nl2br($vals[$line][
'value']);
593 case 'DOL_CUT_PAPER_PARTIAL':
594 $this->printer->cut(Escpos::CUT_PARTIAL);
595 $html.=
' ✂'.nl2br($vals[$line][
'value']);
597 case 'DOL_USE_FONT_A':
598 $this->printer->setFont(Escpos::FONT_A);
599 $this->printer->text($vals[$line][
'value']);
601 case 'DOL_USE_FONT_B':
602 $this->printer->setFont(Escpos::FONT_B);
603 $this->printer->text($vals[$line][
'value']);
605 case 'DOL_USE_FONT_C':
606 $this->printer->setFont(Escpos::FONT_C);
607 $this->printer->text($vals[$line][
'value']);
610 $this->printer->text($vals[$line][
'value']);
611 $html.= nl2br($vals[$line][
'value']);
612 $this->errors[] =
'UnknowTag: <'.strtolower($vals[$line][
'tag']).
'>';
617 $html.=
'</pre></table>';
622 $this->printer->close();
637 $sql =
'SELECT template';
638 $sql.=
' FROM '.MAIN_DB_PREFIX.
'printer_receipt_template';
639 $sql.=
' WHERE rowid='.$templateid;
640 $sql.=
' AND entity = '.$conf->entity;
641 $resql = $this->db->query($sql);
643 $obj = $this->db->fetch_array(
$resql);
646 $this->errors[] = $this->db->lasterror;
650 $this->errors[] =
'TemplateDontExist';
652 $this->
template = $obj[
'0'];
671 $sql =
'SELECT rowid, name, fk_type, fk_profile, parameter';
672 $sql.=
' FROM '.MAIN_DB_PREFIX.
'printer_receipt';
673 $sql.=
' WHERE rowid = '.$printerid;
674 $sql.=
' AND entity = '.$conf->entity;
675 $resql = $this->db->query($sql);
677 $obj = $this->db->fetch_array(
$resql);
680 $this->errors[] = $this->db->lasterror;
684 $this->errors[] =
'PrinterDontExist';
687 $parameter = $obj[
'parameter'];
689 switch ($obj[
'fk_type']) {
691 require_once DOL_DOCUMENT_ROOT .
'/includes/mike42/escpos-php/src/DummyPrintConnector.php';
692 $this->connector =
new DummyPrintConnector();
695 $this->connector =
new FilePrintConnector($parameter);
698 $parameters = explode(
':', $parameter);
699 $this->connector =
new NetworkPrintConnector($parameters[0], $parameters[1]);
702 $this->connector =
new WindowsPrintConnector($parameter);
705 $this->connector =
'CONNECTOR_UNKNOWN';
708 $this->printer =
new Escpos($this->connector);
710 $this->errors[] = $e->getMessage();
DeletePrinter($printerid)
Function to Delete a printer from db.
UpdateTemplate($name, $template, $templateid)
Function to Update a printer template in db.
print
Draft customers invoices.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
listPrintersTemplates()
List printers templates.
selectTypePrinter($selected='', $htmlname='printertypeid')
Form to Select type printer.
listPrinters()
list printers
loadTemplate($templateid)
Function to load Template.
AddPrinter($name, $type, $profile, $parameter)
Function to Add a printer in db.
InitPrinter($printerid)
Function Init Printer.
Class to manage Receipt Printers.
SendTestToPrinter($printerid)
Function to Send Test page to Printer.
UpdatePrinter($name, $type, $profile, $parameter, $printerid)
Function to Update a printer in db.
selectProfilePrinter($selected='', $htmlname='printerprofileid')
Form to Select Profile printer.
__construct($db)
Constructor.
SendToPrinter($object, $templateid, $printerid)
Function to Print Receipt Ticket.