This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/invoice/classes/controller/user/invoice.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2010-11-29 22:41:08 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides User Invoice functions
*
* @package OSB
* @subpackage Invoice
* @category Controllers/User
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_User_Invoice extends Controller_TemplateDefault {
public $secure_actions = array(
2011-08-02 06:20:11 +00:00
'download'=>TRUE,
2010-11-29 22:41:08 +00:00
'list'=>TRUE,
2011-08-02 06:20:11 +00:00
'view'=>TRUE,
2010-11-29 22:41:08 +00:00
);
/**
* Show a product
*/
public function action_list() {
$id = Auth::instance()->get_user()->id;
$ao = ORM::factory('account',$id);
if (! $ao->loaded())
throw new Kohana_Exception('Account doesnt exist :account ?',array(':account'=>$id));
Block::add(array(
'title'=>sprintf('%s: %s - %s',_('Invoices For'),$ao->accnum(),$ao->name(TRUE)),
2011-08-02 06:20:11 +00:00
'body'=>View::factory('invoice/user/list')
2010-11-29 22:41:08 +00:00
->set('invoices',$ao->invoice->find_all()),
));
}
/**
* View an Invoice
*/
public function action_view($id) {
$io = ORM::factory('invoice',$id);
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account_id)) {
$this->template->content = 'Unauthorised or doesnt exist?';
return FALSE;
}
// @todo media path probably should be a config item
2011-08-02 06:20:11 +00:00
$this->template->content = View::factory('invoice/user/html')
2010-11-29 22:41:08 +00:00
->set('mediapath',Route::get('default/media'))
->set('invoice',$io);
}
2011-05-02 12:28:17 +00:00
/**
* Download an invoice
*/
public function action_download($id) {
$io = ORM::factory('invoice',$id);
2011-07-14 09:09:03 +00:00
$this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D'));
$this->response->headers(array('Content-Type' => 'application/pdf'));
$this->auto_render = FALSE;
2011-05-02 12:28:17 +00:00
}
2010-11-29 22:41:08 +00:00
}
?>