Skip to content
Snippets Groups Projects
Commit 3aa25cd2 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #4064 from frederic34/escpos

Add profile escpos printer
parents 91f1acd1 6b4b70bd
Branches
No related tags found
No related merge requests found
......@@ -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 '<tr class="liste_titre">';
print '<th>'.$langs->trans("Name").'</th>';
print '<th>'.$langs->trans("Type").'</th>';
print '<th>'.$langs->trans("Profile").'</th>';
print '<th>'.$langs->trans("Parameters").'</th>';
print '<th></th>';
print '<th></th>';
......@@ -252,6 +253,8 @@ if ($mode == 'config' && $user->admin)
print '<td><input size="50" type="text" name="printername" value="'.$printer->listprinters[$line]['name'].'"></td>';
$ret = $printer->selectTypePrinter($printer->listprinters[$line]['fk_type']);
print '<td>'.$printer->resprint.'</td>';
$ret = $printer->selectProfilePrinter($printer->listprinters[$line]['fk_profile']);
print '<td>'.$printer->profileresprint.'</td>';
print '<td><input size="60" type="text" name="parameter" value="'.$printer->listprinters[$line]['parameter'].'"></td>';
print '<td></td>';
print '<td></td>';
......@@ -259,27 +262,8 @@ if ($mode == 'config' && $user->admin)
print '</tr>';
} else {
print '<td>'.$printer->listprinters[$line]['name'].'</td>';
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 '<td>'.$langs->trans($connector).'</td>';
print '<td>'.$langs->trans($printer->listprinters[$line]['fk_type_name']).'</td>';
print '<td>'.$langs->trans($printer->listprinters[$line]['fk_profile_name']).'</td>';
print '<td>'.$printer->listprinters[$line]['parameter'].'</td>';
// edit icon
print '<td><a href="'.$_SERVER['PHP_SELF'].'?mode=config&amp;action=editprinter&amp;printerid='.$printer->listprinters[$line]['rowid'].'">';
......@@ -302,6 +286,7 @@ if ($mode == 'config' && $user->admin)
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Name").'</th>';
print '<th>'.$langs->trans("Type").'</th>';
print '<th>'.$langs->trans("Profile").'</th>';
print '<th>'.$langs->trans("Parameters").'</th>';
print '<th></th>';
print '<th></th>';
......@@ -311,6 +296,8 @@ if ($mode == 'config' && $user->admin)
print '<td><input size="50" type="text" name="printername"></td>';
$ret = $printer->selectTypePrinter();
print '<td>'.$printer->resprint.'</td>';
$ret = $printer->selectProfilePrinter();
print '<td>'.$printer->profileresprint.'</td>';
print '<td><input size="60" type="text" name="parameter"></td>';
print '<td></td>';
print '<td></td>';
......@@ -329,13 +316,24 @@ if ($mode == 'config' && $user->admin)
print '<div><p></div>';
dol_fiche_head();
print $langs->trans("ReceiptPrinterTypeDesc")."<br><br>\n";
print '<table class="noborder" width="100%">'."\n";
$var=true;
print '<tr><td>'.$langs->trans("CONNECTOR_DUMMY").':</td><td>'.$langs->trans("CONNECTOR_DUMMY_HELP").'</td></tr>';
print '<td>'.$langs->trans("CONNECTOR_NETWORK_PRINT").':</td><td>'.$langs->trans("CONNECTOR_NETWORK_PRINT_HELP").'</td></tr>';
print '<td>'.$langs->trans("CONNECTOR_FILE_PRINT").':</td><td>'.$langs->trans("CONNECTOR_FILE_PRINT_HELP").'</td></tr>';
print '<td>'.$langs->trans("CONNECTOR_WINDOWS_PRINT").':</td><td>'.$langs->trans("CONNECTOR_WINDOWS_PRINT_HELP").'</td></tr>';
//print '<td>'.$langs->trans("CONNECTOR_JAVA").':</td><td>'.$langs->trans("CONNECTOR_JAVA_HELP").'</td></tr>';
print '<tr '.$bc[1].'><td>'.$langs->trans("CONNECTOR_DUMMY").':</td><td>'.$langs->trans("CONNECTOR_DUMMY_HELP").'</td></tr>';
print '<tr '.$bc[0].'><td>'.$langs->trans("CONNECTOR_NETWORK_PRINT").':</td><td>'.$langs->trans("CONNECTOR_NETWORK_PRINT_HELP").'</td></tr>';
print '<tr '.$bc[1].'><td>'.$langs->trans("CONNECTOR_FILE_PRINT").':</td><td>'.$langs->trans("CONNECTOR_FILE_PRINT_HELP").'</td></tr>';
print '<tr '.$bc[0].'><td>'.$langs->trans("CONNECTOR_WINDOWS_PRINT").':</td><td>'.$langs->trans("CONNECTOR_WINDOWS_PRINT_HELP").'</td></tr>';
//print '<tr '.$bc[1].'><td>'.$langs->trans("CONNECTOR_JAVA").':</td><td>'.$langs->trans("CONNECTOR_JAVA_HELP").'</td></tr>';
print '</table>';
dol_fiche_end();
print '<div><p></div>';
dol_fiche_head();
print $langs->trans("ReceiptPrinterProfileDesc")."<br><br>\n";
print '<table class="noborder" width="100%">'."\n";
print '<tr '.$bc[1].'><td>'.$langs->trans("PROFILE_DEFAULT").':</td><td>'.$langs->trans("PROFILE_DEFAULT_HELP").'</td></tr>';
print '<tr '.$bc[0].'><td>'.$langs->trans("PROFILE_SIMPLE").':</td><td>'.$langs->trans("PROFILE_SIMPLE_HELP").'</td></tr>';
print '<tr '.$bc[1].'><td>'.$langs->trans("PROFILE_EPOSTEP").':</td><td>'.$langs->trans("PROFILE_EPOSTEP_HELP").'</td></tr>';
print '<tr '.$bc[0].'><td>'.$langs->trans("PROFILE_P822D").':</td><td>'.$langs->trans("PROFILE_P822D_HELP").'</td></tr>';
print '<tr '.$bc[1].'><td>'.$langs->trans("PROFILE_STAR").':</td><td>'.$langs->trans("PROFILE_STAR_HELP").'</td></tr>';
print '</table>';
dol_fiche_end();
}
......
......@@ -74,8 +74,8 @@
* <dol_print_customer_skype> Print customer skype
* <dol_print_customer_tax_number> Print customer VAT number
* <dol_print_customer_account_balance> Print customer account balance
* <dol_print_vendor_last_name> Print vendor name
* <dol_print_vendor_first_name> Print vendor firstname
* <dol_print_vendor_lastname> Print vendor name
* <dol_print_vendor_firstname> Print vendor firstname
* <dol_print_vendor_mail> Print vendor mail
* <dol_print_customer_points> Print customer points
* <dol_print_order_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'] = 'PROFILE_DEFAULT';
break;
case 1:
$row['fk_profile_name'] = 'PROFILE_SIMPLE';
break;
case 2:
$row['fk_profile_name'] = 'PROFILE_EPOSTEP';
break;
case 3:
$row['fk_profile_name'] = 'PROFILE_P822D';
break;
default:
$row['fk_profile_name'] = 'PROFILE_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 = '<select class="flat" name="'.$htmlname.'">';
$html.= '<option value="0" '.($selected==0?'selected="selected"':'').'>'.$langs->trans('PROFILE_DEFAULT').'</option>';
$html.= '<option value="1" '.($selected==1?'selected="selected"':'').'>'.$langs->trans('PROFILE_SIMPLE').'</option>';
$html.= '<option value="2" '.($selected==2?'selected="selected"':'').'>'.$langs->trans('PROFILE_EPOSTEP').'</option>';
$html.= '<option value="3" '.($selected==3?'selected="selected"':'').'>'.$langs->trans('PROFILE_P822D').'</option>';
$html.= '<option value="4" '.($selected==4?'selected="selected"':'').'>'.$langs->trans('PROFILE_STAR').'</option>';
$html.= '</select>';
$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('<dol_print_customer_skype>', $object->customer_skype, $this->template);
$this->template = str_replace('<dol_print_customer_tax_number>', $object->customer_tax_number, $this->template);
$this->template = str_replace('<dol_print_customer_account_balance>', $object->customer_account_balance, $this->template);
$this->template = str_replace('<dol_print_customer_points>', $object->customer_points, $this->template);
$this->template = str_replace('<dol_print_order_points>', $object->order_points, $this->template);
$this->template = str_replace('<dol_print_vendor_firstname>', $object->vendor_firstname, $this->template);
$this->template = str_replace('<dol_print_vendor_lastname>', $object->vendor_lastname, $this->template);
$this->template = str_replace('<dol_print_vendor_mail>', $object->vendor_mail, $this->template);
$this->template = str_replace('<dol_print_date>', $object->date, $this->template);
$this->template = str_replace('<dol_print_date_time>', $object->date_time, $this->template);
$this->template = str_replace('<dol_print_year>', $object->date_time, $this->template);
$this->template = str_replace('<dol_print_month_letters>', $object->date_time, $this->template);
$this->template = str_replace('<dol_print_month>', $object->date_time, $this->template);
$this->template = str_replace('<dol_print_day>', $object->date_time, $this->template);
$this->template = str_replace('<dol_print_day_letters>', $object->date_time, $this->template);
$this->template = str_replace('<dol_print_table>', $object->table, $this->template);
$this->template = str_replace('<dol_print_cutlery>', $object->cutlery, $this->template);
// parse template
$p = xml_parser_create();
......@@ -463,10 +540,18 @@ class dolReceiptPrinter extends Escpos
$this->printer->pulse();
$html.= ' &#991;'.nl2br($vals[$line]['value']);
break;
case 'DOL_ACTIVATE_BUZZER':
//$this->printer->buzzer();
$html.= ' &#x266b;'.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:
......
......@@ -137,7 +137,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);
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment