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