diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 50018bdd07b..ebca25d8464 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -460,7 +460,6 @@ class dolReceiptPrinter extends Printer */ public function updatePrinter($name, $type, $profile, $parameter, $printerid) { - global $conf; $error = 0; $sql = "UPDATE ".$this->db->prefix()."printer_receipt"; @@ -625,6 +624,7 @@ class dolReceiptPrinter extends Printer $error = 0; $ret = $this->loadTemplate($templateid); + $now = dol_now('tzuser'); // tags a remplacer par leur valeur avant de parser (dol_value_xxx) $this->template = str_replace('{dol_value_object_id}', $object->id, $this->template); @@ -706,6 +706,7 @@ class dolReceiptPrinter extends Printer // print ticket $nbcharactbyline = getDolGlobalInt('RECEIPT_PRINTER_NB_CHARACT_BY_LINE', 48); $ret = $this->initPrinter($printerid); + if ($ret > 0) { setEventMessages($this->error, $this->errors, 'errors'); } else { @@ -961,22 +962,23 @@ class dolReceiptPrinter extends Printer } /** - * Function to load Template + * Function to load Template into $this->template * * @param int $templateid Template id * @return int 0 if OK; >0 if KO */ public function loadTemplate($templateid) { - global $conf; $error = 0; + $sql = "SELECT template"; $sql .= " FROM ".$this->db->prefix()."printer_receipt_template"; $sql .= " WHERE rowid = ".((int) $templateid); - $sql .= " AND entity = ".$conf->entity; + $sql .= " AND entity IN (".getEntity('printer_receipt_template').")"; + $resql = $this->db->query($sql); if ($resql) { - $obj = $this->db->fetch_array($resql); + $obj = $this->db->fetch_object($resql); } else { $error++; $this->errors[] = $this->db->lasterror; @@ -985,7 +987,7 @@ class dolReceiptPrinter extends Printer $error++; $this->errors[] = 'TemplateDontExist'; } else { - $this->template = $obj['0']; + $this->template = $obj->template; } return $error; @@ -993,24 +995,25 @@ class dolReceiptPrinter extends Printer /** - * Function Init Printer + * Function Init Printer into $this->printer * * @param int $printerid Printer id - * @return void|int 0 if OK; >0 if KO + * @return void|int 0 if OK; >0 if KO */ public function initPrinter($printerid) { - global $conf; if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") { $this->connector = new DummyPrintConnector(); $this->printer = new Printer($this->connector, $this->profile); return; } + $error = 0; $sql = "SELECT rowid, name, fk_type, fk_profile, parameter"; $sql .= " FROM ".$this->db->prefix()."printer_receipt"; $sql .= " WHERE rowid = ".((int) $printerid); - $sql .= " AND entity = ".((int) $conf->entity); + $sql .= " AND entity IN (".getEntity('printer_receipt').")"; + $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_array($resql); diff --git a/htdocs/core/modules/modReceiptPrinter.class.php b/htdocs/core/modules/modReceiptPrinter.class.php index ae755358000..baf71c682e8 100644 --- a/htdocs/core/modules/modReceiptPrinter.class.php +++ b/htdocs/core/modules/modReceiptPrinter.class.php @@ -131,11 +131,17 @@ class modReceiptPrinter extends DolibarrModules */ public function init($options = '') { - global $conf, $langs; + global $langs; + + $result = $this->_load_tables('/install/mysql/', 'receiptprinter'); + if ($result < 0) { + return -1; // Do not activate module if error 'not allowed' returned when loading module SQL queries (the _load_table run sql with run_sql with the error allowed parameter set to 'default') + } // Clean before activation $this->remove($options); + // @TODO Move create/delete into sql file and insert into data file $templateexample = '{dol_align_center}\r\n{dol_print_text}{dol_value_mysoc_name}\r\n{dol_print_text}{dol_value_mysoc_address}\r\n{dol_print_text}{dol_value_mysoc_zip}{dol_value_mysoc_town}\r\n{dol_line_feed}\r\n{dol_print_text}Facture {dol_value_object_ref}\r\n{dol_line_feed}\r\n{dol_align_left}\r\n{dol_print_object_lines}\r\n{dol_line_feed}\r\n{dol_print_object_tax}\r\n{dol_line_feed}\r\n{dol_print_object_total}\r\n{dol_line_feed}\r\n{dol_cut_paper_full}'; $sql = array( "CREATE TABLE IF NOT EXISTS ".MAIN_DB_PREFIX."printer_receipt (rowid integer AUTO_INCREMENT PRIMARY KEY, name varchar(128), fk_type integer, fk_profile integer, parameter varchar(128), entity integer) ENGINE=innodb;", @@ -143,6 +149,7 @@ class modReceiptPrinter extends DolibarrModules "DELETE FROM ".MAIN_DB_PREFIX."printer_receipt_template WHERE name = '".$this->db->escape($langs->trans('Example'))."';", "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template (name,template,entity) VALUES ('".$this->db->escape($langs->trans('Example'))."', '".$this->db->escape($templateexample)."', 1);", ); + return $this->_init($sql, $options); } } diff --git a/htdocs/langs/en_US/cashdesk.lang b/htdocs/langs/en_US/cashdesk.lang index fd5d558bb28..0c629b2dd01 100644 --- a/htdocs/langs/en_US/cashdesk.lang +++ b/htdocs/langs/en_US/cashdesk.lang @@ -106,8 +106,10 @@ ControlCashOpening=Open the "Control cash box" popup when opening the POS CloseCashFence=Close cash box control CashReport=Cash report MainPrinterToUse=Main printer to use +MainPrinterToUseMore=empty means the browser printer system OrderPrinterToUse=Order printer to use MainTemplateToUse=Main template to use +MainTemplateToUseMore=when not using browser printing system OrderTemplateToUse=Order template to use BarRestaurant=Bar Restaurant AutoOrder=Order by the customer himself diff --git a/htdocs/takepos/admin/bar.php b/htdocs/takepos/admin/bar.php index 653ef6acf9d..0c8f41fb237 100644 --- a/htdocs/takepos/admin/bar.php +++ b/htdocs/takepos/admin/bar.php @@ -126,15 +126,16 @@ if (getDolGlobalInt('TAKEPOS_BAR_RESTAURANT')) { print ''.$langs->trans("Parameters").''.$langs->trans("Value").''; print "\n"; - if (getDolGlobalString('TAKEPOS_PRINT_METHOD') != "browser") { // Why this ? - print ''; - print $langs->trans("OrderPrinters").' ('.$langs->trans("Setup").')'; - print ''; - print ''; - print ajax_constantonoff("TAKEPOS_ORDER_PRINTERS", array(), $conf->entity, 0, 0, 1, 0); - //print $form->selectyesno("TAKEPOS_ORDER_PRINTERS", $conf->global->TAKEPOS_ORDER_PRINTERS, 1); - print ''; + //if (getDolGlobalString('TAKEPOS_PRINT_METHOD') != "browser") { // Why this ? + print ''; + print $langs->trans("OrderPrinters").' ('.$langs->trans("Setup").')'; + print ''; + print ''; + print ajax_constantonoff("TAKEPOS_ORDER_PRINTERS", array(), $conf->entity, 0, 0, 1, 0); + //print $form->selectyesno("TAKEPOS_ORDER_PRINTERS", $conf->global->TAKEPOS_ORDER_PRINTERS, 1); + print ''; + if (getDolGlobalString('TAKEPOS_ORDER_PRINTERS')) { print ''; print $langs->trans("OrderNotes"); print ''; @@ -142,7 +143,8 @@ if (getDolGlobalInt('TAKEPOS_BAR_RESTAURANT')) { print ajax_constantonoff("TAKEPOS_ORDER_NOTES", array(), $conf->entity, 0, 0, 1, 0); //print $form->selectyesno("TAKEPOS_ORDER_NOTES", $conf->global->TAKEPOS_ORDER_NOTES, 1); print ''; - } else { + } + /*else { print ''; print $langs->trans("OrderPrinters"); print ''; @@ -156,7 +158,7 @@ if (getDolGlobalInt('TAKEPOS_BAR_RESTAURANT')) { print ''; print ''.$langs->trans("NotAvailableWithBrowserPrinter").''; print ''; - } + }*/ print ''; print $langs->trans("BasicPhoneLayout"); diff --git a/htdocs/takepos/admin/terminal.php b/htdocs/takepos/admin/terminal.php index e2768929be2..b8ef9803187 100644 --- a/htdocs/takepos/admin/terminal.php +++ b/htdocs/takepos/admin/terminal.php @@ -302,41 +302,50 @@ if (isModEnabled('stock')) { } } -if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") { +if (isModEnabled('receiptprinter')) { // Select printer to use with terminal require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; $printer = new dolReceiptPrinter($db); - if (getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter") { - $printer->listprinters(); - $printers = array(); - foreach ($printer->listprinters as $key => $value) { - $printers[$value['rowid']] = $value['name']; - } - print ''.$langs->trans("MainPrinterToUse").''; - print ''; - print $form->selectarray('TAKEPOS_PRINTER_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$terminal), 1); - print ''; - if (getDolGlobalInt('TAKEPOS_ORDER_PRINTERS')) { - print ''.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 1'; - print ''; - print $form->selectarray('TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminal), 1); - print ''; - print ''.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 2'; - print ''; - print $form->selectarray('TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminal), 1); - print ''; - print ''.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 3'; - print ''; - print $form->selectarray('TAKEPOS_ORDER_PRINTER3_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_ORDER_PRINTER3_TO_USE'.$terminal), 1); - print ''; - } + + $printer->listprinters(); + $printers = array(); + foreach ($printer->listprinters as $key => $value) { + $printers[$value['rowid']] = $value['name']; } + print ''.$langs->trans("MainPrinterToUse"); + print ' ('.$langs->trans("MainPrinterToUseMore").')'; + print ''; + print ''; + print $form->selectarray('TAKEPOS_PRINTER_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_PRINTER_TO_USE'.$terminal), 1); + print ''; + if (getDolGlobalString('TAKEPOS_BAR_RESTAURANT') && getDolGlobalInt('TAKEPOS_ORDER_PRINTERS')) { + print ''.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 1'; + print ''; + print $form->selectarray('TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminal), 1); + print ''; + print ''.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 2'; + print ''; + print $form->selectarray('TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminal), 1); + print ''; + print ''.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 3'; + print ''; + print $form->selectarray('TAKEPOS_ORDER_PRINTER3_TO_USE'.$terminal, $printers, getDolGlobalInt('TAKEPOS_ORDER_PRINTER3_TO_USE'.$terminal), 1); + print ''; + } +} + +if (isModEnabled('receiptprinter') || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "receiptprinter" || getDolGlobalString('TAKEPOS_PRINT_METHOD') == "takeposconnector") { + // Select printer to use with terminal + require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; + $printer = new dolReceiptPrinter($db); $printer->listPrintersTemplates(); $templates = array(); foreach ($printer->listprinterstemplates as $key => $value) { $templates[$value['rowid']] = $value['name']; } - print ''.$langs->trans("MainTemplateToUse").' ('.$langs->trans("SetupReceiptTemplate").')'; + print ''.$langs->trans("MainTemplateToUse"); + print ' ('.$langs->trans("MainTemplateToUseMore").')'; + print ' ('.$langs->trans("SetupReceiptTemplate").')'; print ''; print $form->selectarray('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$terminal, $templates, getDolGlobalInt('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$terminal), 1); print '';