Skip to content

Commit

Permalink
NEW #19501 Add two hooks in dolreceiptprinter.php (#26439)
Browse files Browse the repository at this point in the history
* Add two hooks in dolreceiptprinter.php

* fix PHPCS error

* fix PHPCS errors
  • Loading branch information
Daoud-mohamed authored Nov 9, 2023
1 parent a9f8b1d commit 6db7c48
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions htdocs/core/class/dolreceiptprinter.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,7 @@ public function sendTestToPrinter($printerid)
public function sendToPrinter($object, $templateid, $printerid)
{
global $conf, $mysoc, $langs, $user;
global $hookmanager;

$langs->load('bills');

Expand Down Expand Up @@ -674,6 +675,15 @@ public function sendToPrinter($object, $templateid, $printerid)
$this->template = str_replace('{dol_value_vendor_lastname}', $user->lastname, $this->template);
$this->template = str_replace('{dol_value_vendor_mail}', $user->email, $this->template);

$parameters = array('object'=>$object);
$action = '';
$reshook = $hookmanager->executeHooks('sendToPrinterBefore', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook < 0) {
$this->error = "Error in hook dolReceiptPrinter sendToPrinterBefore ".$reshook;
dol_syslog("dolReceiptPrinter::sendToPrinter: error=".$this->error, LOG_ERR);
return $reshook;
}

// parse template
$this->template = str_replace("{", "<", $this->template);
$this->template = str_replace("}", ">", $this->template);
Expand Down Expand Up @@ -910,10 +920,16 @@ public function sendToPrinter($object, $templateid, $printerid)
}
break;
default:
$this->printer->text($vals[$tplline]['tag']);
$this->printer->text($vals[$tplline]['value']);
$this->errors[] = 'UnknowTag: &lt;'.strtolower($vals[$tplline]['tag']).'&gt;';
$error++;
$parameters = array('vals' => $vals[$tplline],'object' => $object,'nbcharactbyline' => $nbcharactbyline);
$action = '';
$reshook = $hookmanager->executeHooks('sendToPrinterAfter', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks

if (!$reshook || $reshook < 0 ) {
$this->printer->text($vals[$tplline]['tag']);
$this->printer->text($vals[$tplline]['value']);
$this->errors[] = 'UnknowTag: &lt;'.strtolower($vals[$tplline]['tag']).'&gt;';
$error++;
}
break;
}
}
Expand Down

0 comments on commit 6db7c48

Please sign in to comment.