Skip to content

Commit

Permalink
Add orders to Receipt Printers module
Browse files Browse the repository at this point in the history
  • Loading branch information
javierybar committed Feb 22, 2020
1 parent 18533b6 commit fddcc84
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 4 deletions.
26 changes: 26 additions & 0 deletions htdocs/core/class/dolreceiptprinter.class.php
Expand Up @@ -49,6 +49,8 @@
* <dol_print_object_tax> Print object total tax
* <dol_print_object_local_tax> Print object local tax
* <dol_print_object_total> Print object total
* <dol_print_order_lines_printer1> Print order lines for Printer1
* <dol_print_order_lines_printer2> Print order lines for Printer2
* <dol_print_payment> Print payment method
*
* Code which can be placed everywhere
Expand Down Expand Up @@ -188,6 +190,8 @@ public function __construct($db)
'dol_print_object_local_tax',
'dol_print_object_total',
'dol_print_object_number',
'dol_print_order_lines_printer1',
'dol_print_order_lines_printer2',
'dol_value_customer_firstname',
'dol_value_customer_lastname',
'dol_value_customer_mail',
Expand Down Expand Up @@ -720,6 +724,28 @@ public function sendToPrinter($object, $templateid, $printerid)
case 'DOL_BEEP':
$this->printer->getPrintConnector() -> write("\x1e");
break;
case 'DOL_PRINT_ORDER_LINES_PRINTER1':
foreach ($object->lines as $line) {
if ($line->special_code==1)
{
$spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
$spaces = str_repeat(' ', $spacestoadd);
$this->printer->text($line->ref.$spaces.$line->qty.' '.str_pad(price($line->total_ttc), 10, ' ', STR_PAD_LEFT)."\n");
$this->printer->text(strip_tags(htmlspecialchars_decode($line->desc))."\n");
}
}
break;
case 'DOL_PRINT_ORDER_LINES_PRINTER2':
foreach ($object->lines as $line) {
if ($line->special_code==2)
{
$spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
$spaces = str_repeat(' ', $spacestoadd);
$this->printer->text($line->ref.$spaces.$line->qty.' '.str_pad(price($line->total_ttc), 10, ' ', STR_PAD_LEFT)."\n");

This comment has been minimized.

Copy link
@FlorentinGarnier

FlorentinGarnier Apr 23, 2021

Is it possible to change this to have only One line with product->desc in place of line ref? It improve ticket reading.

$this->printer->text(strip_tags(htmlspecialchars_decode($line->desc))."\n");
}
}
break;
default:
$this->printer->text($vals[$tplline]['tag']);
$this->printer->text($vals[$tplline]['value']);
Expand Down
24 changes: 20 additions & 4 deletions htdocs/takepos/invoice.php
Expand Up @@ -441,6 +441,10 @@ function fail($message)
if ($action == "order" and $placeid != 0)
{
include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter"){
require_once DOL_DOCUMENT_ROOT.'/core/class/dolreceiptprinter.class.php';
$printer = new dolReceiptPrinter($db);
}

$headerorder = '<html><br><b>'.$langs->trans('Place').' '.$place.'<br><table width="65%"><thead><tr><th class="left">'.$langs->trans("Label").'</th><th class="right">'.$langs->trans("Qty").'</th></tr></thead><tbody>';
$footerorder = '</tbody></table>'.dol_print_date(dol_now(), 'dayhour').'<br></html>';
Expand All @@ -458,13 +462,20 @@ function fail($message)
$result = array_intersect($catsprinter1, $existing);
$count = count($result);
if ($count > 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=".$line->id;
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='1' where rowid=".$line->id; //Set to print on printer 1
$db->query($sql);
$order_receipt_printer1 .= '<tr>'.$line->product_label.'<td class="right">'.$line->qty;
if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer1 .= "<br>(".$line->array_options['options_order_notes'].")";
$order_receipt_printer1 .= '</td></tr>';
}
}
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter"){
$invoice->fetch($placeid); //Reload object before send to printer
$ret = $printer->sendToPrinter($invoice, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION["takeposterminal"]}, $conf->global->{'TAKEPOS_PRINTER_TO_USE'.$_SESSION["takeposterminal"]}); // PRINT TO PRINTER 1
}
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='1' and fk_facture=".$invoice->id; // Set as printed
$db->query($sql);
$invoice->fetch($placeid); //Reload object after set lines as printed

foreach ($invoice->lines as $line)
{
Expand All @@ -476,15 +487,20 @@ function fail($message)
$result = array_intersect($catsprinter2, $existing);
$count = count($result);
if ($count > 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where rowid=".$line->id;
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='2' where rowid=".$line->id; //Set to print on printer 2
$db->query($sql);
$order_receipt_printer2 .= '<tr>'.$line->product_label.'<td class="right">'.$line->qty;
if (!empty($line->array_options['options_order_notes'])) $order_receipt_printer2 .= "<br>(".$line->array_options['options_order_notes'].")";
$order_receipt_printer2 .= '</td></tr>';
}
}

$invoice->fetch($placeid);
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter"){
$invoice->fetch($placeid); //Reload object before send to printer
$ret = $printer->sendToPrinter($invoice, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION["takeposterminal"]}, $conf->global->{'TAKEPOS_PRINTER_TO_USE'.$_SESSION["takeposterminal"]}); // PRINT TO PRINTER 2
}
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet set special_code='4' where special_code='2' and fk_facture=".$invoice->id; // Set as printed
$db->query($sql);
$invoice->fetch($placeid); //Reload object after set lines as printed
}

$sectionwithinvoicelink = '';
Expand Down

0 comments on commit fddcc84

Please sign in to comment.