2013-10-10 02:44:53 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides User Invoice functions
|
|
|
|
*
|
|
|
|
* @package Invoice
|
|
|
|
* @category Controllers/User
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_User_Invoice extends Controller_Invoice {
|
2013-06-11 04:30:13 +00:00
|
|
|
protected $secure_actions = array(
|
|
|
|
'download'=>TRUE,
|
2013-12-19 23:00:32 +00:00
|
|
|
'email'=>TRUE,
|
2013-06-11 04:30:13 +00:00
|
|
|
'list'=>TRUE,
|
|
|
|
'view'=>TRUE,
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download an invoice
|
|
|
|
*/
|
|
|
|
public function action_download() {
|
|
|
|
$io = ORM::factory('Invoice',$this->request->param('id'));
|
|
|
|
|
2013-11-22 04:36:50 +00:00
|
|
|
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account))
|
|
|
|
throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
|
|
|
|
|
2013-10-11 02:08:50 +00:00
|
|
|
// Log the download
|
|
|
|
$imo = $io->invoice_memo;
|
|
|
|
$imo->invoice_id = $io->id;
|
|
|
|
$imo->account_id = $this->ao->id;
|
2013-11-15 05:25:45 +00:00
|
|
|
$imo->type = 'download';
|
2013-10-11 02:08:50 +00:00
|
|
|
$imo->memo = 'Invoice Downloaded.';
|
|
|
|
$imo->save();
|
|
|
|
|
2013-12-19 23:00:32 +00:00
|
|
|
$this->response->body(Invoice::instance($io)->render('pdf','all',array('download'=>sprintf('%s.pdf',$io->refnum()))));
|
2013-06-11 04:30:13 +00:00
|
|
|
$this->response->headers(array('Content-Type' => 'application/pdf'));
|
|
|
|
$this->auto_render = FALSE;
|
|
|
|
}
|
|
|
|
|
2013-12-19 23:00:32 +00:00
|
|
|
/**
|
|
|
|
* Email an invoice
|
|
|
|
*/
|
|
|
|
public function action_email() {
|
|
|
|
$io = ORM::factory('Invoice',$this->request->param('id'));
|
|
|
|
|
|
|
|
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account))
|
|
|
|
throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
|
|
|
|
|
|
|
|
if ($x=Invoice::instance($io)->render('email','all')) {
|
|
|
|
// Log the emailling
|
|
|
|
$imo = $io->invoice_memo;
|
|
|
|
$imo->invoice_id = $io->id;
|
|
|
|
$imo->account_id = $this->ao->id;
|
|
|
|
$imo->type = 'email';
|
|
|
|
$imo->memo = 'Invoice Emailed.';
|
|
|
|
$imo->save();
|
|
|
|
|
|
|
|
SystemMessage::factory()
|
|
|
|
->title('Invoice')
|
|
|
|
->type('success')
|
|
|
|
->body(sprintf('Invoice :%s sent via email',$io->refnum()));
|
|
|
|
|
|
|
|
HTTP::redirect(URL::link('user','email/view/'.$x));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
HTTP::redirect(URL::link('user','invoice/view/'.$io->id));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-11 04:30:13 +00:00
|
|
|
/**
|
|
|
|
* Show a list of invoices
|
|
|
|
*/
|
|
|
|
public function action_list() {
|
2016-07-29 01:19:30 +00:00
|
|
|
$this->meta->title = 'Invoice List';
|
|
|
|
|
2013-06-11 04:30:13 +00:00
|
|
|
Block::factory()
|
2016-07-29 13:04:34 +00:00
|
|
|
->title(sprintf('Invoices for Account: %s',$this->ao->refnum()))
|
|
|
|
->title_icon($this->icon)
|
|
|
|
->body(View::factory('invoice/user/list')->set('o',$this->ao->invoice->find_all()));
|
2013-06-11 04:30:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View an Invoice
|
|
|
|
*/
|
|
|
|
public function action_view() {
|
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
|
|
|
|
|
|
|
$io = ORM::factory('Invoice',$id);
|
|
|
|
|
|
|
|
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account))
|
|
|
|
throw HTTP_Exception::factory(403,'Service either doesnt exist, or you are not authorised to see it');
|
|
|
|
|
2013-12-19 23:00:32 +00:00
|
|
|
$output .= Invoice::instance($io)->render('html','all');
|
|
|
|
|
|
|
|
|
2016-07-24 14:44:17 +00:00
|
|
|
$this->template->content = View::factory('invoice/user/view')->set('o',$io)->set('output',$output);
|
2013-06-11 04:30:13 +00:00
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
?>
|