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 '