This commit is contained in:
frederic34 2015-11-02 00:05:45 +01:00
parent 2f3e6958f9
commit d362d889f6
8 changed files with 828 additions and 59 deletions

View File

@ -0,0 +1,404 @@
<?php
/* Copyright (C) 2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/receiptprinter.php
* \ingroup printing
* \brief Page to setup receipt printer
*/
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/receiptprinter.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
$langs->load("admin");
$langs->load("receiptprinter");
if (! $user->admin) accessforbidden();
$action = GETPOST('action','alpha');
$mode = GETPOST('mode','alpha');
$value = GETPOST('value','alpha');
$varname = GETPOST('varname', 'alpha');
$printername = GETPOST('printername', 'alpha');
$printerid = GETPOST('printerid', 'int');
$parameter = GETPOST('parameter', 'alpha');
$printer = new dolReceiptPrinter($db);
if (!$mode) $mode='config';
if (!function_exists('gzdecode')) {
function gzdecode($data)
{
return gzinflate(substr($data,10,-8));
}
}
/*
* Action
*/
if ($action == 'addprinter' && $user->admin)
{
$error=0;
$db->begin();
if (empty($printername)) {
$error++;
setEventMessages($langs->trans("PrinterNameEmpty"), null, 'errors');
}
if (empty($parameter)) {
setEventMessages($langs->trans("PrinterParameterEmpty"), null, 'warnings');
}
if (! $error)
{
$result= $printer->AddPrinter($printername, GETPOST('printertypeid', 'int'), $parameter);
if ($result > 0) $error++;
if (! $error)
{
$db->commit();
setEventMessages($langs->trans("PrinterAdded",$printername), null);
}
else
{
$db->rollback();
dol_print_error($db);
}
}
$action = '';
}
if ($action == 'deleteprinter' && $user->admin)
{
$error=0;
$db->begin();
if (empty($printerid)) {
$error++;
setEventMessages($langs->trans("PrinterIdEmpty"), null, 'errors');
}
if (! $error)
{
$result= $printer->DeletePrinter($printerid);
if ($result > 0) $error++;
if (! $error)
{
$db->commit();
setEventMessages($langs->trans("PrinterDeleted",$printername), null);
}
else
{
$db->rollback();
dol_print_error($db);
}
}
$action = '';
}
if ($action == 'updateprinter' && $user->admin)
{
$error=0;
$db->begin();
if (empty($printerid)) {
$error++;
setEventMessages($langs->trans("PrinterIdEmpty"), null, 'errors');
}
if (! $error)
{
$result= $printer->UpdatePrinter($printername, GETPOST('printertypeid', 'int'), $parameter, $printerid);
if ($result > 0) $error++;
if (! $error)
{
$db->commit();
setEventMessages($langs->trans("PrinterUpdated",$printername), null);
}
else
{
$db->rollback();
dol_print_error($db);
}
}
$action = '';
}
if ($action == 'testprinter' && $user->admin)
{
$error=0;
if (empty($printerid)) {
$error++;
setEventMessages($langs->trans("PrinterIdEmpty"), null, 'errors');
}
if (! $error)
{
// test
$ret = $printer->SendTestToPrinter($printerid);
if ($ret == 0)
{
setEventMessages($langs->trans("TestSentToPrinter", $printername), null);
}
else
{
setEventMessages($printer->error, $printer->errors, 'errors');
}
}
$action = '';
}
/*
* View
*/
$form = new Form($db);
llxHeader('',$langs->trans("ReceiptPrinterSetup"));
$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
print load_fiche_titre($langs->trans("ReceiptPrinterSetup"),$linkback,'title_setup');
$head = receiptprinteradmin_prepare_head($mode);
if ($mode == 'config' && $user->admin)
{
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=config" autocomplete="off">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
if ($action!='editprinter') {
print '<input type="hidden" name="action" value="addprinter">';
} else {
print '<input type="hidden" name="action" value="updateprinter">';
}
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("ReceiptPrinterDesc")."<br><br>\n";
print '<table class="noborder" width="100%">'."\n";
$var=true;
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Name").'</th>';
print '<th>'.$langs->trans("Type").'</th>';
print '<th>'.$langs->trans("Parameters").'</th>';
print '<th></th>';
print '<th></th>';
print '<th></th>';
print "</tr>\n";
$ret = $printer->listprinters();
if ($ret > 0) {
setEventMessages($printer->error, $printer->errors, 'errors');
} else {
for ($line=0; $line < count($printer->listprinters); $line++) {
$var = !$var;
print '<tr '.$bc[$var].'>';
if ($action=='editprinter' && $printer->listprinters[$line]['rowid']==$printerid) {
print '<input type="hidden" name="printerid" value="'.$printer->listprinters[$line]['rowid'].'">';
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>';
print '<td><input size="60" type="text" name="parameter" value="'.$printer->listprinters[$line]['parameter'].'"></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
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;
default:
$connector = 'CONNECTOR_UNKNOWN';
break;
}
print '<td>'.$langs->trans($connector).'</td>';
print '<td>'.$printer->listprinters[$line]['parameter'].'</td>';
// edit icon
print '<td><a href="'.$_SERVER['PHP_SELF'].'?action=editprinter&amp;printerid='.$printer->listprinters[$line]['rowid'].'">';
print img_picto($langs->trans("Edit"),'edit');
print '</a></td>';
// delete icon
print '<td><a href="'.$_SERVER['PHP_SELF'].'?action=deleteprinter&amp;printerid='.$printer->listprinters[$line]['rowid'].'&amp;printername='.$printer->listprinters[$line]['name'].'">';
print img_picto($langs->trans("Delete"),'delete');
print '</a></td>';
// test icon
print '<td><a href="'.$_SERVER['PHP_SELF'].'?action=testprinter&amp;printerid='.$printer->listprinters[$line]['rowid'].'&amp;printername='.$printer->listprinters[$line]['name'].'">';
print img_picto($langs->trans("TestPrinter"),'printer');
print '</a></td>';
print '</tr>';
}
}
}
if ($action!='editprinter') {
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Name").'</th>';
print '<th>'.$langs->trans("Type").'</th>';
print '<th>'.$langs->trans("Parameters").'</th>';
print '<th></th>';
print '<th></th>';
print '<th></th>';
print "</tr>\n";
print '<tr>';
print '<td><input size="50" type="text" name="printername"></td>';
$ret = $printer->selectTypePrinter();
print '<td>'.$printer->resprint.'</td>';
print '<td><input size="60" type="text" name="parameter"></td>';
print '<td></td>';
print '<td></td>';
print '<td></td>';
print '</tr>';
}
print '</table>';
dol_fiche_end();
if ($action!='editprinter') {
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Add")).'"></div>';
} else {
print '<div class="center"><input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans("Save")).'"></div>';
}
print '</form>';
}
if ($mode == 'template' && $user->admin)
{
$tags = array(
'dol_align_left',
'dol_align_center',
'dol_align_right',
'dol_use_font_a',
'dol_use_font_b',
'dol_use_font_c',
'dol_bold',
'/dol_bold',
'dol_double_height',
'/dol_double_height',
'dol_double_width',
'/dol_double_width',
'dol_underline',
'/dol_underline',
'dol_underline_2dots',
'/dol_underline',
'dol_emphasized',
'/dol_emphasized',
'dol_switch_colors',
'/dol_switch_colors',
'dol_print_barcode',
'dol_print_barcode_customer_id',
'dol_set_print_width_57',
'dol_cut_paper_full',
'dol_cut_paper_partial',
'dol_open_drawer',
'dol_activate_buzzer',
'dol_print_qrcode',
'dol_print_date',
'dol_print_date_time',
'dol_print_year',
'dol_print_month_letters',
'dol_print_month',
'dol_print_day',
'dol_print_day_letters',
'dol_print_table',
'dol_print_cutlery',
'dol_print_payment',
'dol_print_logo',
'dol_print_logo_old',
'dol_print_order_lines',
'dol_print_order_tax',
'dol_print_order_local_tax',
'dol_print_order_total',
'dol_print_order_number',
'dol_print_order_number_unique',
'dol_print_customer_first_name',
'dol_print_customer_last_name',
'dol_print_customer_mail',
'dol_print_customer_telephone',
'dol_print_customer_mobile',
'dol_print_customer_skype',
'dol_print_customer_tax_number',
'dol_print_customer_account_balance',
'dol_print_vendor_last_name',
'dol_print_vendor_first_name',
'dol_print_vendor_mail',
'dol_print_customer_points',
'dol_print_order_points',
'dol_print_if_customer',
'dol_print_if_vendor',
'dol_print_if_happy_hour',
'dol_print_if_num_order_unique',
'dol_print_if_customer_points',
'dol_print_if_order_points',
'dol_print_if_customer_tax_number',
'dol_print_if_customer_account_balance_positive',
);
print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?mode=config" autocomplete="off">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addtemplate">';
dol_fiche_head($head, $mode, $langs->trans("ModuleSetup"), 0, 'technic');
print $langs->trans("ReceiptPrinterTemplateDesc")."<br><br>\n";
print '<table class="noborder" width="100%">'."\n";
$var=true;
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Template").'</th>';
print '<th></th>';
print "</tr>\n";
print '</table>';
print '</form>';
print '<table class="noborder" width="100%">'."\n";
$var=true;
print '<tr class="liste_titre">';
print '<th>'.$langs->trans("Tag").'</th>';
print '<th>'.$langs->trans("Description").'</th>';
print "</tr>\n";
for ($tag=0; $tag < count($tags); $tag++) {
$var = !$var;
print '<tr '.$bc[$var].'>';
print '<td>&lt;'.$tags[$tag].'&gt;</td><td>'.$langs->trans(strtoupper($tags[$tag])).'</td>';
print '</tr>';
}
print '</table>';
dol_fiche_end();
}
llxFooter();
$db->close();

View File

@ -58,6 +58,7 @@ if (GETPOST('action','alpha') == 'set')
$res = dolibarr_set_const($db,"CASHDESK_ID_WAREHOUSE",(GETPOST('CASHDESK_ID_WAREHOUSE','alpha') > 0 ? GETPOST('CASHDESK_ID_WAREHOUSE','alpha') : ''),'chaine',0,'',$conf->entity);
$res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",GETPOST('CASHDESK_NO_DECREASE_STOCK','alpha'),'chaine',0,'',$conf->entity);
$res = dolibarr_set_const($db,"CASHDESK_SERVICES", GETPOST('CASHDESK_SERVICES','alpha'),'chaine',0,'',$conf->entity);
$res = dolibarr_set_const($db,"CASHDESK_DOLIBAR_RECEIPT_PRINTER", GETPOST('CASHDESK_DOLIBAR_RECEIPT_PRINTER','alpha'),'chaine',0,'',$conf->entity);
dol_syslog("admin/cashdesk: level ".GETPOST('level','alpha'));
@ -169,6 +170,17 @@ if (! empty($conf->service->enabled))
print "</td></tr>\n";
}
// Use Dolibarr Receipt Printer
if (! empty($conf->receiptprinter->enabled))
{
$var=! $var;
print '<tr '.$bc[$var].'><td>';
print $langs->trans("DolibarrReceiptPrinter");
print '<td colspan="2">';
print $form->selectyesno("CASHDESK_DOLIBAR_RECEIPT_PRINTER",$conf->global->CASHDESK_DOLIBAR_RECEIPT_PRINTER,1);
print "</td></tr>\n";
}
print '</table>';
print '<br>';

View File

@ -19,78 +19,92 @@
/**
* \file htdocs/core/class/dolreceiptprinter.class.php
* \brief Print receipt ticket on various printer
* \brief Print receipt ticket on various ESC/POS printer
*/
/*
* codes for ticket template
* Tags for ticket template
*
* <align_left> Left align text
* <align_center> Center text
* <align_right> Right align text
* <use_font_a> Use font A of printer
* <use_font_b> Use font B of printer
* <use_font_c> Use font C of printer
* <bold> </bold> Text Bold
* <double_height> </double_height> Text double height
* <double_width> </double_width> Text double width
* <underline> </underline> Underline text
* <underline_2dots> </underline> Underline with double line
* <emphasized> </emphasized> Emphasized text
* <switch_colors> </switch_colors> Print in white on black
* <print_barcode> Print barcode
* <print_barcode_customer_id> Print barcode customer id
* <set_print_width_57> Ticket print width of 57mm
* <cut_paper_full> Cut ticket completely
* <cut_paper_partial> Cut ticket partially
* <open_drawer> Open cash drawer
* <activate_buzzer> Activate buzzer
* <dol_align_left> Left align text
* <dol_align_center> Center text
* <dol_align_right> Right align text
* <dol_use_font_a> Use font A of printer
* <dol_use_font_b> Use font B of printer
* <dol_use_font_c> Use font C of printer
* <dol_bold> </dol_bold> Text Bold
* <dol_double_height> </dol_double_height> Text double height
* <dol_double_width> </dol_double_width> Text double width
* <dol_underline> </dol_underline> Underline text
* <dol_underline_2dots> </dol_underline_2dots> Underline with double line
* <dol_emphasized> </dol_emphasized> Emphasized text
* <dol_switch_colors> </dol_switch_colors> Print in white on black
* <dol_print_barcode> Print barcode
* <dol_print_barcode_customer_id> Print barcode customer id
* <dol_set_print_width_57> Ticket print width of 57mm
* <dol_cut_paper_full> Cut ticket completely
* <dol_cut_paper_partial> Cut ticket partially
* <dol_open_drawer> Open cash drawer
* <dol_activate_buzzer> Activate buzzer
*
* Code which can be placed everywhere
* <print_qrcode> Print QR Code
* <print_date> Print date (format : AAAA-MM-DD)
* <print_date_time> Print date and time (format AAAA-MM-DD HH:MM:SS)
* <print_year> Print Year
* <print_month_letters> Print month in letters (example : november)
* <print_month> Print month number
* <print_day> Print day number
* <print_table> Print table number
* <print_cutlery> Print cutlery number
* <print_payment> Print payment method
* <print_logo> Print logo stored on printer. Example : <print_logo>32|32
* <print_logo_deprecated> Print logo stored on printer. Must be followed by logo code. For old printers.
* <print_num_order> Print order number
* <print_num_order_unique> Print order number after validation
* <print_customer_first_name> Print customer firstname
* <print_customer_last_name> Print customer name
* <print_customer_mail> Print customer mail
* <print_customer_telephone> Print customer phone
* <print_customer_mobile> Print customer mobile
* <print_customer_skype> Print customer skype
* <print_customer_tax_number> Print customer VAT number
* <print_customer_account_balance> Print customer account balance
* <print_vendor_last_name> Print vendor name
* <print_vendor_first_name> Print vendor firstname
* <print_customer_points> Print customer points
* <print_order_points> Print number of points for this order
* <dol_print_qrcode> Print QR Code
* <dol_print_date> Print date AAAA-MM-DD
* <dol_print_date_time> Print date and time AAAA-MM-DD HH:MM:SS
* <dol_print_year> Print Year
* <dol_print_month_letters> Print month in letters (example : november)
* <dol_print_month> Print month number
* <dol_print_day> Print day number
* <dol_print_day_letters> Print day number
* <dol_print_table> Print table number (for restaurant, bar...)
* <dol_print_cutlery> Print number of cutlery (for restaurant)
* <dol_print_payment> Print payment method
* <dol_print_logo> Print logo stored on printer. Example : <print_logo>32|32
* <dol_print_logo_old> Print logo stored on printer. Must be followed by logo code. For old printers.
* <dol_print_order_lines> Print order lines
* <dol_print_order_tax> Print order total tax
* <dol_print_order_local_tax> Print order local tax
* <dol_print_order_total> Print order total
* <dol_print_order_number> Print order number
* <dol_print_order_number_unique> Print order number after validation
* <dol_print_customer_first_name> Print customer firstname
* <dol_print_customer_last_name> Print customer name
* <dol_print_customer_mail> Print customer mail
* <dol_print_customer_telephone> Print customer phone
* <dol_print_customer_mobile> Print customer mobile
* <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_mail> Print vendor mail
* <dol_print_customer_points> Print customer points
* <dol_print_order_points> Print number of points for this order
*
* Conditional code at line start (if…then Print)
* <print_if_customer> Print the line IF a customer is affected to the order
* <print_if_vendor> Print the line IF a vendor is affected to the order
* <print_if_happy_hour> Print the line IF Happy Hour
* <print_if_num_order_unique> Print the line IF order is validated
* <print_if_customer_points> Print the line IF customer points > 0
* <print_if_order_points> Print the line IF points of the order > 0
* <print_if_customer_tax_number> Print the line IF customer has vat number
* <print_if_customer_account_balance_positive> Print the line IF customer balance > 0
* <dol_print_if_customer> Print the line IF a customer is affected to the order
* <dol_print_if_vendor> Print the line IF a vendor is affected to the order
* <dol_print_if_happy_hour> Print the line IF Happy Hour
* <dol_print_if_num_order_unique> Print the line IF order is validated
* <dol_print_if_customer_points> Print the line IF customer points > 0
* <dol_print_if_order_points> Print the line IF points of the order > 0
* <dol_print_if_customer_tax_number> Print the line IF customer has vat number
* <dol_print_if_customer_account_balance_positive> Print the line IF customer balance > 0
*
*/
require_once DOL_DOCUMENT_ROOT .'/includes/escpos/Escpos.php';
/**
* Class to manage Receipt Printers
*/
class dolReceiptPrinter
class dolReceiptPrinter extends Escpos
{
const CONNECTOR_DUMMY = 1;
const CONNECTOR_FILE_PRINT = 2;
const CONNECTOR_NETWORK_PRINT = 3;
const CONNECTOR_WINDOWS_PRINT = 4;
//const CONNECTOR_JAVA = 6;
var $db;
var $error;
var $errors;
@ -107,5 +121,191 @@ class dolReceiptPrinter
$this->db=$db;
}
/**
* Constructor
*
* @return int 0 if OK; >0 if KO
*/
function listPrinters()
{
global $conf;
$error = 0;
$line = 0;
$sql = 'SELECT rowid, name, fk_type, 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);
$line++;
}
} else {
$error++;
$this->errors[] = $this->db->lasterror;
}
$this->listprinters = $obj;
return $error;
}
/**
* Form to Select type printer
*
* @param string $selected Id printer type pre-selected
* @param string $htmlname select html name
* @return int 0 if OK; >0 if KO
*/
function selectTypePrinter($selected='', $htmlname='printertypeid')
{
global $langs;
$error = 0;
$html = '<select class="flat" name="'.$htmlname.'">';
$html.= '<option value="1" '.($selected==1?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_DUMMY').'</option>';
$html.= '<option value="2" '.($selected==2?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_FILE_PRINT').'</option>';
$html.= '<option value="3" '.($selected==3?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_NETWORK_PRINT').'</option>';
$html.= '<option value="4" '.($selected==4?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_WINDOWS_PRINT').'</option>';
//$html.= '<option value="5" '.($selected==5?'selected="selected"':'').'>'.$langs->trans('CONNECTOR_JAVA').'</option>';
$html.= '</select>';
$this->resprint = $html;
return $error;
}
/**
* Function to Add a printer in db
*
* @param string $name Printer name
* @param int $type Printer type
* @param string $parameter Printer parameter
* @return int 0 if OK; >0 if KO
*/
function AddPrinter($name, $type, $parameter)
{
global $conf;
$error = 0;
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'printer_receipt';
$sql.= ' (name, fk_type, parameter, entity)';
$sql.= ' VALUES ("'.$name.'", '.$type.', "'.$parameter.'", '.$conf->entity.')';
$resql = $this->db->query($sql);
if (! $resql) {
$error++;
$this->errors[] = $this->db->lasterror;
}
return $error;
}
/**
* Function to Update a printer in db
*
* @param string $name Printer name
* @param int $type Printer type
* @param string $parameter Printer parameter
* @param int $printerid Printer id
* @return int 0 if OK; >0 if KO
*/
function UpdatePrinter($name, $type, $parameter, $printerid)
{
global $conf;
$error = 0;
$sql = 'UPDATE '.MAIN_DB_PREFIX.'printer_receipt';
$sql.= ' SET name="'.$name.'"';
$sql.= ', fk_type='.$type;
$sql.= ', parameter="'.$parameter.'"';
$sql.= ' WHERE rowid='.$printerid;
$resql = $this->db->query($sql);
if (! $resql) {
$error++;
$this->errors[] = $this->db->lasterror;
}
return $error;
}
/**
* Function to Delete a printer from db
*
* @param int $printerid Printer id
* @return int 0 if OK; >0 if KO
*/
function DeletePrinter($printerid)
{
global $conf;
$error = 0;
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt';
$sql.= ' WHERE rowid='.$printerid;
$resql = $this->db->query($sql);
if (! $resql) {
$error++;
$this->errors[] = $this->db->lasterror;
}
return $error;
}
/**
* Function to Send Test äge to Printer
*
* @param int $printerid Printer id
* @return int 0 if OK; >0 if KO
*/
function SendTestToPrinter($printerid)
{
global $conf;
$error = 0;
$sql = 'SELECT rowid, name, fk_type, parameter';
$sql.= ' FROM '.MAIN_DB_PREFIX.'printer_receipt';
$sql.= ' WHERE rowid = '.$printerid;
$sql.= ' AND entity = '.$conf->entity;
$resql = $this->db->query($sql);
if ($resql) {
$obj = $this->db->fetch_array($resql);
} else {
$error++;
$this->errors[] = $this->db->lasterror;
}
//print '<pre>'.print_r($obj, true).'</pre>';
if (! $error) {
$parameter = $obj['parameter'];
try {
switch ($obj['fk_type']) {
case 1:
require_once DOL_DOCUMENT_ROOT .'/includes/escpos/src/DummyPrintConnector.php';
$connector = new DummyPrintConnector();
break;
case 2:
$connector = new FilePrintConnector($parameter);
break;
case 3:
$parameters = explode(':', $parameter);
$connector = new NetworkPrintConnector($parameters[0], $parameters[1]);
break;
case 4:
$connector = new WindowsPrintConnector($parameter);
break;
default:
$connector = 'CONNECTOR_UNKNOWN';
break;
}
$testprinter = new Escpos($connector);
$img = new EscposImage(DOL_DOCUMENT_ROOT .'/theme/common/dolibarr_logo_bw.png');
$testprinter -> graphics($img);
$testprinter -> text("Hello World!\n");
$testStr = "Testing 123";
$testprinter -> qrCode($testStr);
$testprinter -> text("Most simple example\n");
$testprinter -> feed();
$testprinter -> cut();
//print '<pre>'.print_r($connector, true).'</pre>';
$testprinter -> close();
//print '<pre>'.print_r($connector, true).'</pre>';
//print '<pre>'.print_r($testprinter, true).'</pre>';
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
$error++;
}
}
return $error;
}
}

View File

@ -0,0 +1,72 @@
<?php
/* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2015 Frederic France <frederic.france@free.fr>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/core/lib/receiptprinter.lib.php
* \ingroup printing
* \brief Library for receipt printer functions
*/
/**
* Define head array for tabs of receipt printer setup pages
*
* @param string $mode Mode
* @return Array of head
*/
function receiptprinteradmin_prepare_head($mode)
{
global $langs, $conf;
$h = 0;
$head = array();
$head[$h][0] = DOL_URL_ROOT."/admin/receiptprinter.php?mode=config";
$head[$h][1] = $langs->trans("ListPrinters");
$head[$h][2] = 'config';
$h++;
$head[$h][0] = DOL_URL_ROOT."/admin/receiptprinter.php?mode=template";
$head[$h][1] = $langs->trans("SetupReceiptTemplate");
$head[$h][2] = 'template';
$h++;
if ($mode == 'test')
{
$head[$h][0] = DOL_URL_ROOT."/admin/receiptprinter.php?mode=test";
$head[$h][1] = $langs->trans("TargetedPrinter");
$head[$h][2] = 'test';
$h++;
}
//$object=new stdClass();
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
// $this->tabs = array('entity:-tabname); to remove a tab
//complete_head_from_modules($conf,$langs,$object,$head,$h,'printingadmin');
//complete_head_from_modules($conf,$langs,$object,$head,$h,'printing','remove');
return $head;
}

View File

@ -50,7 +50,7 @@ class modReceiptPrinter extends DolibarrModules
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
$this->name = preg_replace('/^mod/i','',get_class($this));
// Module description, used if translation string 'ModuleXXXDesc' not found (where XXX is value of numeric property 'numero' of module)
$this->description = "Receipt Printer.";
$this->description = "ReceiptPrinterDesc";
$this->version = 'dolibarr'; // 'development' or 'experimental' or 'dolibarr' or version
$this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
// Where to store the module in setup page (0=common,1=interface,2=others,3=very specific)
@ -70,7 +70,7 @@ class modReceiptPrinter extends DolibarrModules
$this->depends = array();
$this->requiredby = array();
$this->phpmin = array(5,1); // Minimum version of PHP required by module
$this->need_dolibarr_version = array(3,7,-2); // Minimum version of Dolibarr required by module
$this->need_dolibarr_version = array(3,9,-2); // Minimum version of Dolibarr required by module
$this->conflictwith = array();
$this->langfiles = array("receiptprinter");

View File

@ -38,3 +38,4 @@ ShowStock=Show warehouse
DeleteArticle=Click to remove this article
FilterRefOrLabelOrBC=Search (Ref/Label)
UserNeedPermissionToEditStockToUsePos=You ask to decrease stock on invoice creation, so user that use POS need to have permission to edit stock.
DolibarrReceiptPrinter=Dolibarr Receipt Printer

View File

@ -0,0 +1,80 @@
# Dolibarr language file - Source file is en_US - receiptprinter
PrinterAdded=Printer %s added
PrinterUpdated=Printer %s updated
PrinterDeleted=Printer %s deleted
TestSentToPrinter=Test Sent To Printer %s
CONNECTOR_DUMMY=Dummy Printer
CONNECTOR_NETWORK_PRINT=Network Printer
CONNECTOR_FILE_PRINT=Local Printer
CONNECTOR_WINDOWS_PRINT=Local Windows Printer
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
DOL_ALIGN_LEFT=Left align text
DOL_ALIGN_CENTER=Center text
DOL_ALIGN_RIGHT=Right align text
DOL_USE_FONT_A=Use font A of printer
DOL_USE_FONT_B=Use font B of printer
DOL_USE_FONT_C=Use font C of printer
DOL_BOLD=Text Bold
/DOL_BOLD=End of Text Bold
DOL_DOUBLE_HEIGHT=Text double height
/DOL_DOUBLE_HEIGHT=End of Text double height
DOL_DOUBLE_WIDTH=Text double width
/DOL_DOUBLE_WIDTH=End of Text double width
DOL_UNDERLINE=Underline text
/DOL_UNDERLINE=End of Underline text
DOL_UNDERLINE_2DOTS=Underline with double line
/DOL_UNDERLINE_2DOTS=End of Underline with double line
DOL_EMPHASIZED=Emphasized text
/DOL_EMPHASIZED=End of Emphasized text
DOL_SWITCH_COLORS=Print in white on black
/DOL_SWITCH_COLORS=End of Print in white on black
DOL_PRINT_BARCODE=Print barcode
DOL_PRINT_BARCODE_CUSTOMER_ID=Print barcode customer id
DOL_SET_PRINT_WIDTH_57=Ticket print width of 57mm
DOL_CUT_PAPER_FULL=Cut ticket completely
DOL_CUT_PAPER_PARTIAL=Cut ticket partially
DOL_OPEN_DRAWER=Open cash drawer
DOL_ACTIVATE_BUZZER=Activate buzzer
DOL_PRINT_QRCODE=Print QR Code
DOL_PRINT_DATE=Print date AAAA-MM-DD
DOL_PRINT_DATE_TIME=Print date and time AAAA-MM-DD HH:MM:SS
DOL_PRINT_YEAR=Print Year
DOL_PRINT_MONTH_LETTERS=Print month in letters (example : november)
DOL_PRINT_MONTH=Print month number
DOL_PRINT_DAY=Print day number
DOL_PRINT_DAY_LETTERS=Print day number
DOL_PRINT_TABLE=Print table number (for restaurant, bar...)
DOL_PRINT_CUTLERY=Print number of cutlery (for restaurant)
DOL_PRINT_PAYMENT=Print payment method
DOL_PRINT_LOGO=Print logo stored on printer. Example : 32|32
DOL_PRINT_LOGO_OLD=Print logo stored on printer. Must be followed by logo code. For old printers.
DOL_PRINT_ORDER_LINES=Print order lines
DOL_PRINT_ORDER_TAX=Print order total tax
DOL_PRINT_ORDER_LOCAL_TAX=Print order local tax
DOL_PRINT_ORDER_TOTAL=Print order total
DOL_PRINT_ORDER_NUMBER=Print order number
DOL_PRINT_ORDER_NUMBER_UNIQUE=Print order number after validation
DOL_PRINT_CUSTOMER_FIRST_NAME=Print customer firstname
DOL_PRINT_CUSTOMER_LAST_NAME=Print customer name
DOL_PRINT_CUSTOMER_MAIL=Print customer mail
DOL_PRINT_CUSTOMER_TELEPHONE=Print customer phone
DOL_PRINT_CUSTOMER_MOBILE=Print customer mobile
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_MAIL=Print vendor mail
DOL_PRINT_CUSTOMER_POINTS=Print customer points
DOL_PRINT_ORDER_POINTS=Print number of points for this order
DOL_PRINT_IF_CUSTOMER=Print the line IF a customer is affected to the order
DOL_PRINT_IF_VENDOR=Print the line IF a vendor is affected to the order
DOL_PRINT_IF_HAPPY_HOUR=Print the line IF Happy Hour
DOL_PRINT_IF_NUM_ORDER_UNIQUE=Print the line IF order is validated
DOL_PRINT_IF_CUSTOMER_POINTS=Print the line IF customer points > 0
DOL_PRINT_IF_ORDER_POINTS=Print the line IF points of the order > 0
DOL_PRINT_IF_CUSTOMER_TAX_NUMBER=Print the line IF customer has vat number
DOL_PRINT_IF_CUSTOMER_ACCOUNT_BALANCE_POSITIVE=Print the line IF customer balance > 0

Binary file not shown.

After

Width:  |  Height:  |  Size: 791 B