From bfd97d5226feb879a2d467e9f18c16f80352ec99 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Sun, 22 Nov 2015 11:04:27 +0100 Subject: [PATCH 1/2] Add profile escpos printer --- htdocs/admin/receiptprinter.php | 32 ++---- htdocs/core/class/dolreceiptprinter.class.php | 105 ++++++++++++++++-- .../core/modules/modReceiptPrinter.class.php | 2 +- 3 files changed, 105 insertions(+), 34 deletions(-) diff --git a/htdocs/admin/receiptprinter.php b/htdocs/admin/receiptprinter.php index 794e7c83664..7e766ee1972 100644 --- a/htdocs/admin/receiptprinter.php +++ b/htdocs/admin/receiptprinter.php @@ -76,7 +76,7 @@ if ($action == 'addprinter' && $user->admin) if (! $error) { - $result= $printer->AddPrinter($printername, GETPOST('printertypeid', 'int'), $parameter); + $result= $printer->AddPrinter($printername, GETPOST('printertypeid', 'int'), GETPOST('printerprofileid', 'int'), $parameter); if ($result > 0) $error++; if (! $error) @@ -132,7 +132,7 @@ if ($action == 'updateprinter' && $user->admin) if (! $error) { - $result= $printer->UpdatePrinter($printername, GETPOST('printertypeid', 'int'), $parameter, $printerid); + $result= $printer->UpdatePrinter($printername, GETPOST('printertypeid', 'int'), GETPOST('printerprofileid', 'int'), $parameter, $printerid); if ($result > 0) $error++; if (! $error) @@ -235,6 +235,7 @@ if ($mode == 'config' && $user->admin) print ''; print ''.$langs->trans("Name").''; print ''.$langs->trans("Type").''; + print ''.$langs->trans("Profile").''; print ''.$langs->trans("Parameters").''; print ''; print ''; @@ -252,6 +253,8 @@ if ($mode == 'config' && $user->admin) print ''; $ret = $printer->selectTypePrinter($printer->listprinters[$line]['fk_type']); print ''.$printer->resprint.''; + $ret = $printer->selectProfilePrinter($printer->listprinters[$line]['fk_profile']); + print ''.$printer->profileresprint.''; print ''; print ''; print ''; @@ -259,27 +262,8 @@ if ($mode == 'config' && $user->admin) print ''; } else { print ''.$printer->listprinters[$line]['name'].''; - switch ($printer->listprinters[$line]['fk_type']) { - case 1: - $connector = 'CONNECTOR_DUMMY'; - break; - case 2: - $connector = 'CONNECTOR_FILE_PRINT'; - break; - case 3: - $connector = 'CONNECTOR_NETWORK_PRINT'; - break; - case 4: - $connector = 'CONNECTOR_WINDOWS_PRINT'; - break; - case 5: - $connector = 'CONNECTOR_JAVA'; - break; - default: - $connector = 'CONNECTOR_UNKNOWN'; - break; - } - print ''.$langs->trans($connector).''; + print ''.$langs->trans($printer->listprinters[$line]['fk_type_name']).''; + print ''.$langs->trans($printer->listprinters[$line]['fk_profile_name']).''; print ''.$printer->listprinters[$line]['parameter'].''; // edit icon print ''; @@ -311,6 +295,8 @@ if ($mode == 'config' && $user->admin) print ''; $ret = $printer->selectTypePrinter(); print ''.$printer->resprint.''; + $ret = $printer->selectProfilePrinter(); + print ''.$printer->profileresprint.''; print ''; print ''; print ''; diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 064cf130426..78c3a1a4651 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -74,8 +74,8 @@ * Print customer skype * Print customer VAT number * Print customer account balance - * Print vendor name - * Print vendor firstname + * Print vendor name + * Print vendor firstname * Print vendor mail * Print customer points * Print number of points for this order @@ -204,14 +204,52 @@ class dolReceiptPrinter extends Escpos global $conf; $error = 0; $line = 0; - $sql = 'SELECT rowid, name, fk_type, parameter'; + $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; $sql.= ' WHERE entity = '.$conf->entity; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); while ($line < $num) { - $obj[] = $this->db->fetch_array($resql); + $row = $this->db->fetch_array($resql); + switch ($row['fk_type']) { + case 1: + $row['fk_type_name'] = 'CONNECTOR_DUMMY'; + break; + case 2: + $row['fk_type_name'] = 'CONNECTOR_FILE_PRINT'; + break; + case 3: + $row['fk_type_name'] = 'CONNECTOR_NETWORK_PRINT'; + break; + case 4: + $row['fk_type_name'] = 'CONNECTOR_WINDOWS_PRINT'; + break; + case 5: + $row['fk_type_name'] = 'CONNECTOR_JAVA'; + break; + default: + $row['fk_type_name'] = 'CONNECTOR_UNKNOWN'; + break; + } + switch ($row['fk_profile']) { + case 0: + $row['fk_profile_name'] = 'DEFAULT'; + break; + case 1: + $row['fk_profile_name'] = 'SIMPLE'; + break; + case 2: + $row['fk_profile_name'] = 'EPOSTEP'; + break; + case 3: + $row['fk_profile_name'] = 'P822D'; + break; + default: + $row['fk_profile_name'] = 'STAR'; + break; + } + $obj[] = $row; $line++; } } else { @@ -275,21 +313,47 @@ class dolReceiptPrinter extends Escpos return $error; } + + /** + * Form to Select Profile printer + * + * @param string $selected Id printer profile pre-selected + * @param string $htmlname select html name + * @return int 0 if OK; >0 if KO + */ + function selectProfilePrinter($selected='', $htmlname='printerprofileid') + { + global $langs; + $error = 0; + $html = ''; + + $this->profileresprint = $html; + return $error; + } + + /** * Function to Add a printer in db * * @param string $name Printer name * @param int $type Printer type + * @param int $profile Printer profile * @param string $parameter Printer parameter * @return int 0 if OK; >0 if KO */ - function AddPrinter($name, $type, $parameter) + function AddPrinter($name, $type, $profile, $parameter) { global $conf; $error = 0; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'printer_receipt'; - $sql.= ' (name, fk_type, parameter, entity)'; - $sql.= ' VALUES ("'.$this->db->escape($name).'", '.$type.', "'.$this->db->escape($parameter).'", '.$conf->entity.')'; + $sql.= ' (name, fk_type, fk_profile, parameter, entity)'; + $sql.= ' VALUES ("'.$this->db->escape($name).'", '.$type.', '.$profile.', "'.$this->db->escape($parameter).'", '.$conf->entity.')'; $resql = $this->db->query($sql); if (! $resql) { $error++; @@ -303,17 +367,19 @@ class dolReceiptPrinter extends Escpos * * @param string $name Printer name * @param int $type Printer type + * @param int $profile Printer profile * @param string $parameter Printer parameter * @param int $printerid Printer id * @return int 0 if OK; >0 if KO */ - function UpdatePrinter($name, $type, $parameter, $printerid) + function UpdatePrinter($name, $type, $profile, $parameter, $printerid) { global $conf; $error = 0; $sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt'; $sql.= ' SET name="'.$this->db->escape($name).'"'; $sql.= ', fk_type='.$type; + $sql.= ', fk_profile='.$profile; $sql.= ', parameter="'.$this->db->escape($parameter).'"'; $sql.= ' WHERE rowid='.$printerid; $resql = $this->db->query($sql); @@ -427,9 +493,20 @@ class dolReceiptPrinter extends Escpos $this->template = str_replace('', $object->customer_skype, $this->template); $this->template = str_replace('', $object->customer_tax_number, $this->template); $this->template = str_replace('', $object->customer_account_balance, $this->template); + $this->template = str_replace('', $object->customer_points, $this->template); + $this->template = str_replace('', $object->order_points, $this->template); $this->template = str_replace('', $object->vendor_firstname, $this->template); $this->template = str_replace('', $object->vendor_lastname, $this->template); + $this->template = str_replace('', $object->vendor_mail, $this->template); + $this->template = str_replace('', $object->date, $this->template); $this->template = str_replace('', $object->date_time, $this->template); + $this->template = str_replace('', $object->date_time, $this->template); + $this->template = str_replace('', $object->date_time, $this->template); + $this->template = str_replace('', $object->date_time, $this->template); + $this->template = str_replace('', $object->date_time, $this->template); + $this->template = str_replace('', $object->date_time, $this->template); + $this->template = str_replace('', $object->table, $this->template); + $this->template = str_replace('', $object->cutlery, $this->template); // parse template $p = xml_parser_create(); @@ -463,10 +540,18 @@ class dolReceiptPrinter extends Escpos $this->printer->pulse(); $html.= ' ϟ'.nl2br($vals[$line]['value']); break; + case 'DOL_ACTIVATE_BUZZER': + //$this->printer->buzzer(); + $html.= ' ♫'.nl2br($vals[$line]['value']); + break; case 'DOL_PRINT_BARCODE': // $vals[$line]['value'] -> barcode($content, $type) $this->printer->barcode($object->barcode); break; + case 'DOL_PRINT_BARCODE_CUSTOMER_ID': + // $vals[$line]['value'] -> barcode($content, $type) + $this->printer->barcode($object->customer_id); + break; case 'DOL_PRINT_QRCODE': // $vals[$line]['value'] -> qrCode($content, $ec, $size, $model) $this->printer->qrcode($vals[$line]['value']); @@ -553,7 +638,7 @@ class dolReceiptPrinter extends Escpos { global $conf; $error=0; - $sql = 'SELECT rowid, name, fk_type, parameter'; + $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; $sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; $sql.= ' WHERE rowid = '.$printerid; $sql.= ' AND entity = '.$conf->entity; @@ -573,7 +658,7 @@ class dolReceiptPrinter extends Escpos try { switch ($obj['fk_type']) { case 1: - require_once DOL_DOCUMENT_ROOT .'/includes/escpos/src/DummyPrintConnector.php'; + require_once DOL_DOCUMENT_ROOT .'/includes/mike42/escpos-php/src/DummyPrintConnector.php'; $this->connector = new DummyPrintConnector(); break; case 2: diff --git a/htdocs/core/modules/modReceiptPrinter.class.php b/htdocs/core/modules/modReceiptPrinter.class.php index 975226819fb..1cee882f0ec 100644 --- a/htdocs/core/modules/modReceiptPrinter.class.php +++ b/htdocs/core/modules/modReceiptPrinter.class.php @@ -136,7 +136,7 @@ class modReceiptPrinter extends DolibarrModules // Clean before activation $this->remove($options); $sql = array( - "CREATE TABLE IF NOT EXISTS llx_printer_receipt (rowid int(11) NOT NULL AUTO_INCREMENT, name varchar(128), fk_type int(11), parameter varchar(128), entity int(11), PRIMARY KEY (rowid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;", + "CREATE TABLE IF NOT EXISTS llx_printer_receipt (rowid int(11) NOT NULL AUTO_INCREMENT, name varchar(128), fk_type int(11), fk_profile int(11), parameter varchar(128), entity int(11), PRIMARY KEY (rowid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;", "CREATE TABLE IF NOT EXISTS llx_printer_receipt_template (rowid int(11) NOT NULL AUTO_INCREMENT, name varchar(128), template text, entity int(11), PRIMARY KEY (rowid)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;", ); return $this->_init($sql,$options); From 6b4b70bdbb2d3536b4c448488ef506515548cf91 Mon Sep 17 00:00:00 2001 From: frederic34 Date: Sun, 22 Nov 2015 14:11:33 +0100 Subject: [PATCH 2/2] translations and help --- htdocs/admin/receiptprinter.php | 24 ++++++++++++++----- htdocs/core/class/dolreceiptprinter.class.php | 20 ++++++++-------- htdocs/langs/en_US/receiptprinter.lang | 16 +++++++++++++ 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/htdocs/admin/receiptprinter.php b/htdocs/admin/receiptprinter.php index 7e766ee1972..5beaacc8515 100644 --- a/htdocs/admin/receiptprinter.php +++ b/htdocs/admin/receiptprinter.php @@ -286,6 +286,7 @@ if ($mode == 'config' && $user->admin) print ''; print ''.$langs->trans("Name").''; print ''.$langs->trans("Type").''; + print ''.$langs->trans("Profile").''; print ''.$langs->trans("Parameters").''; print ''; print ''; @@ -315,13 +316,24 @@ if ($mode == 'config' && $user->admin) print '

'; dol_fiche_head(); + print $langs->trans("ReceiptPrinterTypeDesc")."

\n"; print ''."\n"; - $var=true; - print ''; - print ''; - print ''; - print ''; - //print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; + print '
'.$langs->trans("CONNECTOR_DUMMY").':'.$langs->trans("CONNECTOR_DUMMY_HELP").'
'.$langs->trans("CONNECTOR_NETWORK_PRINT").':'.$langs->trans("CONNECTOR_NETWORK_PRINT_HELP").'
'.$langs->trans("CONNECTOR_FILE_PRINT").':'.$langs->trans("CONNECTOR_FILE_PRINT_HELP").'
'.$langs->trans("CONNECTOR_WINDOWS_PRINT").':'.$langs->trans("CONNECTOR_WINDOWS_PRINT_HELP").'
'.$langs->trans("CONNECTOR_JAVA").':'.$langs->trans("CONNECTOR_JAVA_HELP").'
'.$langs->trans("CONNECTOR_DUMMY").':'.$langs->trans("CONNECTOR_DUMMY_HELP").'
'.$langs->trans("CONNECTOR_NETWORK_PRINT").':'.$langs->trans("CONNECTOR_NETWORK_PRINT_HELP").'
'.$langs->trans("CONNECTOR_FILE_PRINT").':'.$langs->trans("CONNECTOR_FILE_PRINT_HELP").'
'.$langs->trans("CONNECTOR_WINDOWS_PRINT").':'.$langs->trans("CONNECTOR_WINDOWS_PRINT_HELP").'
'.$langs->trans("CONNECTOR_JAVA").':'.$langs->trans("CONNECTOR_JAVA_HELP").'
'; + dol_fiche_end(); + print '

'; + dol_fiche_head(); + print $langs->trans("ReceiptPrinterProfileDesc")."

\n"; + print ''."\n"; + print ''; + print ''; + print ''; + print ''; + print ''; print '
'.$langs->trans("PROFILE_DEFAULT").':'.$langs->trans("PROFILE_DEFAULT_HELP").'
'.$langs->trans("PROFILE_SIMPLE").':'.$langs->trans("PROFILE_SIMPLE_HELP").'
'.$langs->trans("PROFILE_EPOSTEP").':'.$langs->trans("PROFILE_EPOSTEP_HELP").'
'.$langs->trans("PROFILE_P822D").':'.$langs->trans("PROFILE_P822D_HELP").'
'.$langs->trans("PROFILE_STAR").':'.$langs->trans("PROFILE_STAR_HELP").'
'; dol_fiche_end(); } diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 78c3a1a4651..5bee14b74d4 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -234,19 +234,19 @@ class dolReceiptPrinter extends Escpos } switch ($row['fk_profile']) { case 0: - $row['fk_profile_name'] = 'DEFAULT'; + $row['fk_profile_name'] = 'PROFILE_DEFAULT'; break; case 1: - $row['fk_profile_name'] = 'SIMPLE'; + $row['fk_profile_name'] = 'PROFILE_SIMPLE'; break; case 2: - $row['fk_profile_name'] = 'EPOSTEP'; + $row['fk_profile_name'] = 'PROFILE_EPOSTEP'; break; case 3: - $row['fk_profile_name'] = 'P822D'; + $row['fk_profile_name'] = 'PROFILE_P822D'; break; default: - $row['fk_profile_name'] = 'STAR'; + $row['fk_profile_name'] = 'PROFILE_STAR'; break; } $obj[] = $row; @@ -326,11 +326,11 @@ class dolReceiptPrinter extends Escpos global $langs; $error = 0; $html = ''; $this->profileresprint = $html; diff --git a/htdocs/langs/en_US/receiptprinter.lang b/htdocs/langs/en_US/receiptprinter.lang index dc2cd392c20..28b63d7de79 100644 --- a/htdocs/langs/en_US/receiptprinter.lang +++ b/htdocs/langs/en_US/receiptprinter.lang @@ -3,6 +3,12 @@ PrinterAdded=Printer %s added PrinterUpdated=Printer %s updated PrinterDeleted=Printer %s deleted TestSentToPrinter=Test Sent To Printer %s +ReceiptPrinterDesc=Setup of printers +ReceiptPrinterTemplateDesc=Setup of Templates +ReceiptPrinterTypeDesc=Description of Receipt Printer's type +ReceiptPrinterProfileDesc=Description of Receipt Printer's Profile +ListPrinters=List of Printers +SetupReceiptTemplate=Template Setup CONNECTOR_DUMMY=Dummy Printer CONNECTOR_NETWORK_PRINT=Network Printer CONNECTOR_FILE_PRINT=Local Printer @@ -11,6 +17,16 @@ CONNECTOR_DUMMY_HELP=Fake Printer for test, does nothing CONNECTOR_NETWORK_PRINT_HELP=10.x.x.x:9100 CONNECTOR_FILE_PRINT_HELP=/dev/usb/lp0, /dev/usb/lp1 CONNECTOR_WINDOWS_PRINT_HELP=LPT1, COM1, smb://FooUser:secret@computername/workgroup/Receipt Printer +PROFILE_DEFAULT=Default Profile +PROFILE_SIMPLE=Simple Profile +PROFILE_EPOSTEP=Epos Tep Profile +PROFILE_P822D=P822D Profile +PROFILE_STAR=Star Profile +PROFILE_DEFAULT_HELP=Default Profile suitable for Epson printers +PROFILE_SIMPLE_HELP=Simple Profile No Graphics +PROFILE_EPOSTEP_HELP=Epos Tep Profile Help +PROFILE_P822D_HELP=P822D Profile No Graphics +PROFILE_STAR_HELP=Star Profile DOL_ALIGN_LEFT=Left align text DOL_ALIGN_CENTER=Center text DOL_ALIGN_RIGHT=Right align text