diff --git a/COPYRIGHT b/COPYRIGHT index 1af09e6fdaf..fe707c1d63d 100644 --- a/COPYRIGHT +++ b/COPYRIGHT @@ -2,7 +2,7 @@ License ------- -Dolibarr is released under the terms of the GNU General Public License as +Dolibarr is released 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 (GPL-3+). More information: https://www.gnu.org/licenses/gpl-3.0.txt @@ -15,13 +15,13 @@ PHP libraries: AdoDb-Date 0.36 Modified BSD License Yes Date convertion (not into rpm package) CKEditor 4.12.1 LGPL-2.1+ Yes Editor WYSIWYG EvalMath 1.0 BSD Yes Safe math expressions evaluation -Escpos-php ? MIT License Yes Thermal receipt printer library, for use with ESC/POS compatible printers +Escpos-php 2.2 MIT License Yes Thermal receipt printer library, for use with ESC/POS compatible printers GeoIP 1.4 LGPL-2.1+ Yes Sample code to make geoip convert (not into deb package) Mobiledetect 2.8.33 MIT License Yes Detect mobile devices browsers NuSoap 0.9.5 LGPL 2.1+ Yes Library to develop SOAP Web services (not into rpm and deb package) PEAR Mail_MIME 1.8.9 BSD Yes NuSoap dependency ParseDown 1.6 MIT License Yes Markdown parser -PHPDebugBar 1.15.0 MIT License Yes Used only by the module "debugbar" for developers +PHPDebugBar 1.15.0 MIT License Yes Used only by the module "debugbar" for developers PHPExcel 1.8.1 LGPL-2.1+ Yes Read/Write XLS files, read ODS files PHPSpreadSheet ? LGPL-2.1+ Yes Read/Write XLS files, read ODS files php-iban 1.4.7 LGPL-3+ Yes Parse and validate IBAN (and IIBAN) bank account information in PHP @@ -37,7 +37,7 @@ TCPDF 6.3.2 LGPL-3+ Yes TCPDI 1.0.0 LGPL-3+ / Apache 2.0 Yes FPDI replacement JS libraries: -Ace 1.4.6 BSD Yes JS library to get code syntaxique coloration in a textarea. +Ace 1.4.6 BSD Yes JS library to get code syntaxique coloration in a textarea. jQuery 3.4.1 MIT License Yes JS library jQuery UI 1.12.1 GPL and MIT License Yes JS library plugin UI jQuery select2 4.0.5 GPL and Apache License Yes JS library plugin for sexier multiselect diff --git a/htdocs/admin/receiptprinter.php b/htdocs/admin/receiptprinter.php index 42b0ecb9ea9..e01fc4402a8 100644 --- a/htdocs/admin/receiptprinter.php +++ b/htdocs/admin/receiptprinter.php @@ -174,14 +174,19 @@ if ($action == 'testtemplate' && $user->admin) { // } // if (! $error) { - // // test - // $ret = $printer->sendTestToPrinter($printerid); - // if ($ret == 0) { - setEventMessages($langs->trans("TestTemplateToPrinter", $printername), null); - // } else { - // setEventMessages($printer->error, $printer->errors, 'errors'); - // } - // } + // test + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + $object = new Facture($db); + //$object->initAsSpecimen(); + $object->fetch(8); + //var_dump($object->lines); + $ret = $printer->sendToPrinter($object, $templateid, 1); + if ($ret == 0) { + setEventMessages($langs->trans("TestTemplateToPrinter", $printername), null); + } else { + setEventMessages($printer->error, $printer->errors, 'errors'); + } + //} $action = ''; } @@ -310,7 +315,7 @@ if ($mode == 'config' && $user->admin) { } } - if ($action!='editprinter') { + if ($action != 'editprinter') { if ($nbofprinters > 0) { print ''; print ''.$langs->trans("Name").''; @@ -446,7 +451,7 @@ if ($mode == 'template' && $user->admin) { } print ''; print '

'; - print ''."\n"; + print '
'."\n"; print ''; print ''; print ''; @@ -462,18 +467,6 @@ if ($mode == 'template' && $user->admin) { dol_fiche_end(); } -// to remove after test -// $object=new stdClass(); -// $object->date_time = '2015-11-02 22:30:25'; -// $object->id = 1234; -// $object->customer_firstname = 'John'; -// $object->customer_lastname = 'Deuf'; -// $object->vendor_firstname = 'Jim'; -// $object->vendor_lastname = 'Big'; -// $object->barcode = '3700123862396'; -//$printer->sendToPrinter($object, 1, 16); -//setEventMessages($printer->error, $printer->errors, 'errors'); - // End of page llxFooter(); $db->close(); diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 1f9ea78bf95..c18c6e0be9b 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -59,12 +59,12 @@ * Print payment method * Print logo stored on printer. Example : 32|32 * Print logo stored on printer. Must be followed by logo code. For old printers. - * Print order lines - * Print order total tax - * Print order local tax - * Print order total - * Print order number - * Print order number after validation + * Print object lines + * Print object total tax + * Print object local tax + * Print object total + * Print object number + * Print object number after validation * Print customer firstname * Print customer name * Print customer mail @@ -77,15 +77,15 @@ * Print vendor firstname * Print vendor mail * Print customer points - * Print number of points for this order + * Print number of points for this object * * Conditional code at line start (if�then Print) - * Print the line IF a customer is affected to the order - * Print the line IF a vendor is affected to the order + * Print the line IF a customer is affected to the object + * Print the line IF a vendor is affected to the object * Print the line IF Happy Hour - * Print the line IF order is validated + * Print the line IF object is validated * Print the line IF customer points > 0 - * Print the line IF points of the order > 0 + * Print the line IF points of the object > 0 * Print the line IF customer has vat number * Print the line IF customer balance > 0 * @@ -141,6 +141,7 @@ class dolReceiptPrinter extends Printer { $this->db=$db; $this->tags = array( + 'dol_line_feed', 'dol_align_left', 'dol_align_center', 'dol_align_right', @@ -167,7 +168,8 @@ class dolReceiptPrinter extends Printer 'dol_cut_paper_full', 'dol_cut_paper_partial', 'dol_open_drawer', - 'dol_activate_buzzer', + //'dol_activate_buzzer', + 'dol_print_text', 'dol_print_qrcode', 'dol_print_date', 'dol_print_date_time', @@ -181,12 +183,14 @@ class dolReceiptPrinter extends Printer '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_object_id', + 'dol_print_object_ref', + 'dol_print_object_lines', + 'dol_print_object_tax', + 'dol_print_object_local_tax', + 'dol_print_object_total', + 'dol_print_object_number', + 'dol_print_object_number_unique', 'dol_print_customer_firstname', 'dol_print_customer_lastname', 'dol_print_customer_mail', @@ -199,13 +203,13 @@ class dolReceiptPrinter extends Printer 'dol_print_vendor_firstname', 'dol_print_vendor_mail', 'dol_print_customer_points', - 'dol_print_order_points', + 'dol_print_object_points', 'dol_print_if_customer', 'dol_print_if_vendor', 'dol_print_if_happy_hour', - 'dol_print_if_num_order_unique', + 'dol_print_if_num_object_unique', 'dol_print_if_customer_points', - 'dol_print_if_order_points', + 'dol_print_if_object_points', 'dol_print_if_customer_tax_number', 'dol_print_if_customer_account_balance_positive', ); @@ -521,12 +525,13 @@ class dolReceiptPrinter extends Printer */ public function sendToPrinter($object, $templateid, $printerid) { - global $conf; + global $conf, $mysoc; $error = 0; $ret = $this->loadTemplate($templateid); // tags a remplacer par leur valeur avant de parser - $this->template = str_replace('', $object->id, $this->template); + $this->template = str_replace('', $object->id, $this->template); + $this->template = str_replace('', $object->ref, $this->template); $this->template = str_replace('', $object->customer_firstname, $this->template); $this->template = str_replace('', $object->customer_lastname, $this->template); $this->template = str_replace('', $object->customer_mail, $this->template); @@ -536,7 +541,7 @@ class dolReceiptPrinter extends Printer $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->object_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); @@ -558,78 +563,92 @@ class dolReceiptPrinter extends Printer //print '
'.print_r($vals, true).'
'; // print ticket $level = 0; - $html = '
'.$langs->trans("Tag").''.$langs->trans("Description").'
';
+        $nbcaractbyline = 47;
         $ret = $this->initPrinter($printerid);
         if ($ret>0) {
             setEventMessages($this->error, $this->errors, 'errors');
         } else {
             $nboflines = count($vals);
-            for ($line=0; $line < $nboflines; $line++) {
-                switch ($vals[$line]['tag']) {
+            for ($tplline=0; $tplline < $nboflines; $tplline++) {
+                //var_dump($vals[$tplline]['value']);
+                switch ($vals[$tplline]['tag']) {
+                    case 'DOL_PRINT_TEXT':
+                        $this->printer->text($vals[$tplline]['value']);
+                        break;
+                    case 'DOL_PRINT_OBJECT_LINES':
+                        foreach ($object->lines as $line) {
+                            $spacestoadd = $nbcaractbyline - strlen($line->ref) - strlen(price($line->total_ttc, 'MT'));
+                            $spaces = str_repeat(' ', $spacestoadd);
+                            $this->printer->text($line->ref.$spaces.price($line->total_ttc, 'MT')."\n");
+                            //var_dump($line->ref);
+                        }
+                        break;
+                    case 'DOL_LINE_FEED':
+                        $this->printer->feed();
+                        break;
                     case 'DOL_ALIGN_CENTER':
-                        $this->printer->setJustification(Escpos::JUSTIFY_CENTER);
-                        $html.='
'; - $this->printer->text($vals[$line]['value']); + $this->printer->setJustification(Printer::JUSTIFY_CENTER); break; case 'DOL_ALIGN_RIGHT': - $this->printer->setJustification(Escpos::JUSTIFY_RIGHT); - $html.=''; + $this->printer->setJustification(Printer::JUSTIFY_RIGHT); break; case 'DOL_ALIGN_LEFT': - $this->printer->setJustification(Escpos::JUSTIFY_LEFT); - $html.=''; + $this->printer->setJustification(Printer::JUSTIFY_LEFT); break; case 'DOL_OPEN_DRAWER': $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) + // $vals[$tplline]['value'] -> barcode($content, $type) $this->printer->barcode($object->barcode); break; + case 'DOL_PRINT_LOGO': + // $vals[$tplline]['value'] -> barcode($content, $type) + $img = EscposImage::load(DOL_DATA_ROOT .'/mycompany/logos/'.$mysoc->logo); + $this->printer->graphics($img); + break; + case 'DOL_PRINT_LOGO_OLD': + // $vals[$tplline]['value'] -> barcode($content, $type) + $img = EscposImage::load(DOL_DATA_ROOT .'/mycompany/logos/'.$mysoc->logo); + $this->printer->bitImage($img); + break; case 'DOL_PRINT_BARCODE_CUSTOMER_ID': - // $vals[$line]['value'] -> barcode($content, $type) + // $vals[$tplline]['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']); - $html.='QRCODE: '.$vals[$line]['value']; + // $vals[$tplline]['value'] -> qrCode($content, $ec, $size, $model) + $this->printer->qrcode($vals[$tplline]['value']); break; case 'DOL_CUT_PAPER_FULL': - $this->printer->cut(Escpos::CUT_FULL); - $html.= ' ✂'.nl2br($vals[$line]['value']); + $this->printer->cut(Printer::CUT_FULL); break; case 'DOL_CUT_PAPER_PARTIAL': - $this->printer->cut(Escpos::CUT_PARTIAL); - $html.= ' ✂'.nl2br($vals[$line]['value']); + $this->printer->cut(Printer::CUT_PARTIAL); break; case 'DOL_USE_FONT_A': - $this->printer->setFont(Escpos::FONT_A); - $this->printer->text($vals[$line]['value']); + $this->printer->setFont(Printer::FONT_A); + $this->printer->text($vals[$tplline]['value']); break; case 'DOL_USE_FONT_B': - $this->printer->setFont(Escpos::FONT_B); - $this->printer->text($vals[$line]['value']); + $this->printer->setFont(Printer::FONT_B); + $this->printer->text($vals[$tplline]['value']); break; case 'DOL_USE_FONT_C': - $this->printer->setFont(Escpos::FONT_C); - $this->printer->text($vals[$line]['value']); + $this->printer->setFont(Printer::FONT_C); + $this->printer->text($vals[$tplline]['value']); break; default: - $this->printer->text($vals[$line]['value']); - $html.= nl2br($vals[$line]['value']); - $this->errors[] = 'UnknowTag: <'.strtolower($vals[$line]['tag']).'>'; + $this->printer->text($vals[$tplline]['value']); + $html.= nl2br($vals[$tplline]['value']); + $this->errors[] = 'UnknowTag: <'.strtolower($vals[$tplline]['tag']).'>'; $error++; break; } } - $html.= '
'; - print $html; // Close and print // uncomment next line to see content sent to printer //print '
'.print_r($this->connector, true).'
'; diff --git a/htdocs/langs/en_US/receiptprinter.lang b/htdocs/langs/en_US/receiptprinter.lang index aa61848fc9d..5714ba78151 100644 --- a/htdocs/langs/en_US/receiptprinter.lang +++ b/htdocs/langs/en_US/receiptprinter.lang @@ -29,6 +29,7 @@ PROFILE_SIMPLE_HELP=Simple Profile No Graphics PROFILE_EPOSTEP_HELP=Epos Tep Profile PROFILE_P822D_HELP=P822D Profile No Graphics PROFILE_STAR_HELP=Star Profile +DOL_LINE_FEED=Skip line DOL_ALIGN_LEFT=Left align text DOL_ALIGN_CENTER=Center text DOL_ALIGN_RIGHT=Right align text @@ -42,3 +43,5 @@ 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_LOGO=Print logo of my company +DOL_PRINT_LOGO_OLD=Print logo of my company (old printers) diff --git a/htdocs/takepos/admin/setup.php b/htdocs/takepos/admin/setup.php index a1f07f4f7ad..2c9cc3cb495 100644 --- a/htdocs/takepos/admin/setup.php +++ b/htdocs/takepos/admin/setup.php @@ -68,6 +68,7 @@ if (GETPOST('action', 'alpha') == 'set') $res = dolibarr_set_const($db, "TAKEPOS_ROOT_CATEGORY_ID", GETPOST('TAKEPOS_ROOT_CATEGORY_ID', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOSCONNECTOR", GETPOST('TAKEPOSCONNECTOR', 'alpha'), 'chaine', 0, '', $conf->entity); + $res = dolibarr_set_const($db, "TAKEPOS_DOLIBARR_PRINTER", GETPOST('TAKEPOS_DOLIBARR_PRINTER', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_BAR_RESTAURANT", GETPOST('TAKEPOS_BAR_RESTAURANT', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_TICKET_VAT_GROUPPED", GETPOST('TAKEPOS_TICKET_VAT_GROUPPED', 'alpha'), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "TAKEPOS_PRINT_SERVER", GETPOST('TAKEPOS_PRINT_SERVER', 'alpha'), 'chaine', 0, '', $conf->entity); @@ -163,6 +164,15 @@ print $form->select_all_categories(Categorie::TYPE_PRODUCT, $conf->global->TAKEP print ajax_combobox('TAKEPOS_ROOT_CATEGORY_ID'); print "\n"; +if ($conf->receiptprinter->enabled) { + // Use Dolibarr printing + print ''; + print $langs->trans("DolibarrReceiptPrinterModule"); + print ''; + print $form->selectyesno("TAKEPOS_DOLIBARR_PRINTER", $conf->global->TAKEPOS_DOLIBARR_PRINTER, 1); + print "\n"; +} + // Use Takepos printing print ''; print $langs->trans("DolibarrReceiptPrinter").' ('.$langs->trans("TakeposConnectorNecesary").')'; diff --git a/htdocs/takepos/admin/terminal.php b/htdocs/takepos/admin/terminal.php index 167735e901d..1bbe339c852 100644 --- a/htdocs/takepos/admin/terminal.php +++ b/htdocs/takepos/admin/terminal.php @@ -81,6 +81,7 @@ if (GETPOST('action', 'alpha') == 'set') } $res = dolibarr_set_const($db, "CASHDESK_ID_WAREHOUSE".$terminaltouse, (GETPOST('CASHDESK_ID_WAREHOUSE'.$terminaltouse, 'alpha') > 0 ? GETPOST('CASHDESK_ID_WAREHOUSE'.$terminaltouse, 'alpha') : ''), 'chaine', 0, '', $conf->entity); $res = dolibarr_set_const($db, "CASHDESK_NO_DECREASE_STOCK".$terminaltouse, GETPOST('CASHDESK_NO_DECREASE_STOCK'.$terminaltouse, 'alpha'), 'chaine', 0, '', $conf->entity); + $res = dolibarr_set_const($db, "TAKEPOS_PRINTER_TO_USE".$terminaltouse, GETPOST('TAKEPOS_PRINTER_TO_USE'.$terminaltouse, 'alpha'), 'chaine', 0, '', $conf->entity); dol_syslog("admin/cashdesk: level ".GETPOST('level', 'alpha')); @@ -193,6 +194,20 @@ if (! empty($conf->stock->enabled)) print ''.$langs->trans("StockDecreaseForPointOfSaleDisabled").''; } print ''; + if ($conf->receiptprinter->enabled) { + // Select printer to use with terminal + require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php'; + $printer = new dolReceiptPrinter($db); + $printer->listprinters(); + $printers = array(); + foreach ($printer->listprinters as $key => $value) { + $printers[$key] = $value['name']; + } + print ''.$langs->trans("TakeposTerminalPrinterToUse").''; + print ''; + print $form->selectarray('TAKEPOS_PRINTER_TO_USE'.$terminal, $printers, (empty($conf->global->{'TAKEPOS_PRINTER_TO_USE'.$terminal})?'0':$conf->global->{'TAKEPOS_PRINTER_TO_USE'.$terminal}), 1); + print ''; + } } print ''; diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 126fea907a9..df2a839fb0e 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -444,8 +444,13 @@ if ($action=="valid" || $action=="history") else $sectionwithinvoicelink.=$langs->trans('BillShortStatusValidated'); } $sectionwithinvoicelink.=''; - if ($conf->global->TAKEPOSCONNECTOR) $sectionwithinvoicelink.=' '; - else $sectionwithinvoicelink.=' '; + if ($conf->global->TAKEPOSCONNECTOR) { + $sectionwithinvoicelink.=' '; + } elseif ($conf->global->TAKEPOS_DOLIBARR_PRINTER) { + $sectionwithinvoicelink.=' '; + } else { + $sectionwithinvoicelink.=' '; + } if ($conf->global->TAKEPOS_AUTO_PRINT_TICKETS) $sectionwithinvoicelink.=''; } @@ -548,6 +553,18 @@ function TakeposPrinting(id){ }); }); } +function DolibarrTakeposPrinting(id) { + console.log('Printing ticket ' + id) + var receipt; + // $.get("receipt.php?facid="+id, function(data, status) { + // receipt=data.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, ''); + // $.ajax({ + // type: "POST", + // url: 'http://global->TAKEPOS_PRINT_SERVER; ?>:8111/print', + // data: receipt + // }); + // }); +} global->TAKEPOS_BAR_RESTAURANT) //add temp ticket button if ($conf->global->TAKEPOS_BAR_RESTAURANT) { - if ($conf->global->TAKEPOSCONNECTOR) $menus[$r++]=array('title'=>'
'.$langs->trans("Receipt").'
','action'=>'TakeposPrinting(placeid);'); - else $menus[$r++]=array('title'=>'
'.$langs->trans("Receipt").'
','action'=>'Print(placeid);'); + if ($conf->global->TAKEPOSCONNECTOR) { + $menus[$r++]=array('title'=>'
'.$langs->trans("Receipt").'
','action'=>'TakeposPrinting(placeid);'); + } else { + $menus[$r++]=array('title'=>'
'.$langs->trans("Receipt").'
','action'=>'Print(placeid);'); + } } if ($conf->global->TAKEPOSCONNECTOR && $conf->global->TAKEPOS_ORDER_NOTES==1) { @@ -713,6 +725,12 @@ if ($conf->global->TAKEPOS_BAR_RESTAURANT) if ($conf->global->TAKEPOSCONNECTOR) { $menus[$r++]=array('title'=>'
'.$langs->trans("DOL_OPEN_DRAWER").'
', 'action'=>'OpenDrawer();'); } +if ($conf->global->TAKEPOS_DOLIBARR_PRINTER) { + $menus[$r++] = array( + 'title' => '
'.$langs->trans("DOL_OPEN_DRAWER").'
', + 'action' => 'DolibarrOpenDrawer();', + ); +} $hookmanager->initHooks(array('takeposfrontend')); $reshook=$hookmanager->executeHooks('ActionButtons');