Example #1
0
 /**
  * Displays an invoice in a theme
  * @param Invoice $invoice
  * @return Template 
  */
 protected function viewToHtml($invoice)
 {
     $theme = Configuration::get('default_invoice_theme');
     if (!$theme) {
         throw new Exception('No default theme set', 400);
     }
     $file = Configuration::get('base_dir') . DS . 'themes' . DS . $theme . '.html';
     if (!is_file($file)) {
         throw new Exception('Could not find theme: ' . $file, 400);
     }
     $invoice_file = Configuration::get('base_dir') . DS . 'templates' . DS . 'invoice-table-view.php';
     $payment_file = Configuration::get('base_dir') . DS . 'templates' . DS . 'payment-table-view.php';
     // make template
     $template = new Template($file);
     $template->token_begin = '[[';
     $template->token_end = ']]';
     $INVOICE = Set::flatten($invoice, 'invoice');
     $INVOICE['invoice.url'] = Configuration::get('base_url') . '/xhtml.php/invoices/' . $invoice->id . '/view';
     $INVOICE['invoice.pdf'] = Configuration::get('base_url') . '/pdf.php/invoices/' . $invoice->id . '/view';
     $INVOICE['entry_table'] = $template->getPHPFile($invoice_file, array('invoice' => $invoice));
     $INVOICE['payment_table'] = $template->getPHPFile($payment_file, array('invoice' => $invoice));
     foreach ($template->findTokens() as $token) {
         if (array_key_exists($token, $INVOICE)) {
             $template->replace($token, $INVOICE[$token]);
         }
     }
     // return
     return $template;
 }