Merge pull request #13561 from andreubisquerra/master

Up to 2 orders printers in TakePOS with Receipt printers module
This commit is contained in:
Laurent Destailleur
2020-04-10 20:06:35 +02:00
committed by GitHub
3 changed files with 28 additions and 25 deletions

View File

@@ -49,8 +49,7 @@
* <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_order_lines> Print order lines for Printer
* <dol_print_payment> Print payment method
*
* Code which can be placed everywhere
@@ -134,6 +133,12 @@ class dolReceiptPrinter extends Printer
public $printer;
public $template;
/**
* Number of order printer
* @var int
*/
public $orderprinter;
/**
* @var string Error code (or message)
*/
@@ -191,8 +196,7 @@ class dolReceiptPrinter extends Printer
'dol_print_object_local_tax',
'dol_print_object_total',
'dol_print_object_number',
'dol_print_order_lines_printer1',
'dol_print_order_lines_printer2',
'dol_print_order_lines',
'dol_value_customer_firstname',
'dol_value_customer_lastname',
'dol_value_customer_mail',
@@ -726,20 +730,9 @@ class dolReceiptPrinter extends Printer
case 'DOL_BEEP':
$this->printer->getPrintConnector() -> write("\x1e");
break;
case 'DOL_PRINT_ORDER_LINES_PRINTER1':
case 'DOL_PRINT_ORDER_LINES':
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)
if ($line->special_code==$this->orderprinter)
{
$spacestoadd = $nbcharactbyline - strlen($line->ref) - strlen($line->qty) - 10 - 1;
$spaces = str_repeat(' ', $spacestoadd);

View File

@@ -41,7 +41,7 @@ if (!empty($_REQUEST['CASHDESK_ID_THIRDPARTY'.$terminal.'_id']))
// Security check
if (!$user->admin) accessforbidden();
$langs->loadLangs(array("admin", "cashdesk"));
$langs->loadLangs(array("admin", "cashdesk", "printing"));
global $db;
@@ -85,6 +85,8 @@ 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);
$res = dolibarr_set_const($db, "TAKEPOS_ORDER_PRINTER1_TO_USE".$terminaltouse, GETPOST('TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminaltouse, 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_ORDER_PRINTER2_TO_USE".$terminaltouse, GETPOST('TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminaltouse, 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES".$terminaltouse, GETPOST('TAKEPOS_TEMPLATE_TO_USE_FOR_INVOICES'.$terminaltouse, 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS".$terminaltouse, GETPOST('TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$terminaltouse, 'alpha'), 'chaine', 0, '', $conf->entity);
@@ -234,9 +236,13 @@ if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter") {
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 '</td></tr>';
if ($conf->global->TAKEPOS_ORDER_PRINTERS) {
print '<tr class="oddeven"><td>'.$langs->trans("OrderPrinterToUse").'</td>';
print '<tr class="oddeven"><td>'.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 1</td>';
print '<td>';
print $form->selectarray('TAKEPOS_ORDER_PRINTER_TO_USE'.$terminal, $printers, (empty($conf->global->{'TAKEPOS_ORDER_PRINTER_TO_USE'.$terminal}) ? '0' : $conf->global->{'TAKEPOS_ORDER_PRINTER_TO_USE'.$terminal}), 1);
print $form->selectarray('TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminal, $printers, (empty($conf->global->{'TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminal}) ? '0' : $conf->global->{'TAKEPOS_ORDER_PRINTER1_TO_USE'.$terminal}), 1);
print '</td></tr>';
print '<tr class="oddeven"><td>'.$langs->trans("OrderPrinterToUse").' - '.$langs->trans("Printer").' 2</td>';
print '<td>';
print $form->selectarray('TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminal, $printers, (empty($conf->global->{'TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminal}) ? '0' : $conf->global->{'TAKEPOS_ORDER_PRINTER2_TO_USE'.$terminal}), 1);
print '</td></tr>';
}
$printer->listPrintersTemplates();

View File

@@ -526,6 +526,7 @@ if ($action == "order" and $placeid != 0)
$result = array_intersect($catsprinter1, $existing);
$count = count($result);
if ($count > 0) {
$linestoprint++;
$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;
@@ -533,17 +534,18 @@ if ($action == "order" and $placeid != 0)
$order_receipt_printer1 .= '</td></tr>';
}
}
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" && $count > 0) {
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" && $linestoprint > 0) {
$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
$printer->orderprinter=1;
$ret = $printer->sendToPrinter($invoice, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION["takeposterminal"]}, $conf->global->{'TAKEPOS_ORDER_PRINTER1_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
$linestoprint=0;
foreach ($invoice->lines as $line)
{
$count=0;
if ($line->special_code == "4") {
continue;
}
@@ -552,6 +554,7 @@ if ($action == "order" and $placeid != 0)
$result = array_intersect($catsprinter2, $existing);
$count = count($result);
if ($count > 0) {
$linestoprint++;
$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;
@@ -559,9 +562,10 @@ if ($action == "order" and $placeid != 0)
$order_receipt_printer2 .= '</td></tr>';
}
}
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" && $count > 0) {
if ($conf->global->TAKEPOS_PRINT_METHOD == "receiptprinter" && $linestoprint > 0) {
$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
$printer->orderprinter=2;
$ret = $printer->sendToPrinter($invoice, $conf->global->{'TAKEPOS_TEMPLATE_TO_USE_FOR_ORDERS'.$_SESSION["takeposterminal"]}, $conf->global->{'TAKEPOS_ORDER_PRINTER2_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);