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
|
|
|
|
*/
|
2011-08-26 01:16:48 +00:00
|
|
|
class Controller_User_Invoice extends Controller_TemplateDefault_User {
|
|
|
|
protected $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
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
2011-08-27 06:33:46 +00:00
|
|
|
* Show a list of invoices
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
|
|
|
public function action_list() {
|
|
|
|
Block::add(array(
|
2011-08-26 01:16:48 +00:00
|
|
|
'title'=>sprintf('%s: %s - %s',_('Invoices For'),$this->ao->accnum(),$this->ao->name(TRUE)),
|
2011-08-27 06:33:46 +00:00
|
|
|
'body'=>Table::display(
|
|
|
|
$this->ao->invoice->find_all(),
|
|
|
|
25,
|
|
|
|
array(
|
|
|
|
'id'=>array('label'=>'ID','url'=>'user/invoice/view/'),
|
|
|
|
'date_orig'=>array('label'=>'Date'),
|
|
|
|
'total_amt'=>array('label'=>'Total','class'=>'right'),
|
|
|
|
'credit_amt'=>array('label'=>'Credits','class'=>'right'),
|
|
|
|
'billed_amt'=>array('label'=>'Payments','class'=>'right'),
|
|
|
|
'due(TRUE)'=>array('label'=>'Still Due','class'=>'right'),
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'page'=>TRUE,
|
|
|
|
'type'=>'select',
|
|
|
|
'form'=>'user/invoice/view',
|
|
|
|
)),
|
2010-11-29 22:41:08 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* View an Invoice
|
|
|
|
*/
|
2011-08-27 06:33:46 +00:00
|
|
|
public function action_view() {
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
if (! $id = $this->request->param('id')) {
|
|
|
|
if (isset($_POST['id']) AND is_array($_POST['id']))
|
|
|
|
Table::post('invoice_view','id');
|
|
|
|
|
|
|
|
list($id,$output) = Table::page('invoice_view');
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$id = $this->request->param('id');
|
|
|
|
}
|
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
$io = ORM::factory('invoice',$id);
|
|
|
|
|
2011-09-26 10:12:54 +00:00
|
|
|
if (! $io->loaded() OR ! Auth::instance()->authorised($io->account_id,$io->affiliate_id)) {
|
2010-11-29 22:41:08 +00:00
|
|
|
$this->template->content = 'Unauthorised or doesnt exist?';
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-08-27 06:33:46 +00:00
|
|
|
$output .= View::factory('invoice/user/view')
|
2010-11-29 22:41:08 +00:00
|
|
|
->set('mediapath',Route::get('default/media'))
|
2011-08-27 06:33:46 +00:00
|
|
|
->set('io',$io);
|
|
|
|
|
|
|
|
Block::add(array(
|
|
|
|
'title'=>sprintf('%s: %s',_('Invoice'),$io->refnum()),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
?>
|