<?php
namespace App\Smarty\Functions; class InvoiceLabel { static public function create($params, $smarty) { $defaultOutput = ''; if ($params['default']) { $defaultOutput=$params['default']; } if (is_object($params['ref']) and get_class($params['ref'])=='Entity\Invoice') { $invoice = $params['ref']; } elseif ( is_numeric($params['ref']) and $params['ref']>0 ) { $invoice = \Entity\Invoice::select($params['ref']); if (!$invoice->recordExists()) { return $defaultOutput; } } else { return $defaultOutput; } if ($params['assign']) { $smarty->assign($params['assign'], $invoice); return ''; } if (!$params['format']) { if ($params['hideLink']) return ($invoice->getId()?sprintf("#%s", $invoice->getId()):$defaultOutput); else { return sprintf("<span class=\"remoteLoadLink\" onclick=\"RemoteLoad.loadEntity(this, '%s', '%s');\">%s</span>", 'invoice', $invoice->getId(), ($invoice->getId()?sprintf("#%s", $invoice->getId()):$defaultOutput)); } } else { $replaceArray = []; $replaceArray['%id%']=$invoice->getId(); $replaceArray['%invoiceNumber%']=$invoice->invoiceNumber; $replaceArray['%invoiceDateStd%']=\Engine\DateTime::isoToStd($invoice->invoiceDate); if ($params['hideLink']) return str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); else { $defaultOutput = str_replace(array_keys($replaceArray), array_values($replaceArray), $params['format']); return sprintf("<span class=\"remoteLoadLink\" onclick=\"RemoteLoad.loadEntity(this, '%s', '%s');\">%s</span>", 'invoice', $invoice->getId(), $defaultOutput); } } } }