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/'),
|
2011-12-09 04:10:53 +00:00
|
|
|
'date_orig'=>array('label'=>'Date Issued'),
|
|
|
|
'due_date'=>array('label'=>'Date Due'),
|
|
|
|
'total(TRUE)'=>array('label'=>'Total','class'=>'right'),
|
2011-08-27 06:33:46 +00:00
|
|
|
'credit_amt'=>array('label'=>'Credits','class'=>'right'),
|
2011-12-09 04:10:53 +00:00
|
|
|
'payments_total(TRUE)'=>array('label'=>'Payments','class'=>'right'),
|
2011-08-27 06:33:46 +00:00
|
|
|
'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() {
|
2011-12-21 01:39:21 +00:00
|
|
|
list($id,$output) = Table::page(__METHOD__);
|
2011-08-27 06:33:46 +00:00
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$io = ORM::factory('Invoice',$id);
|
2010-11-29 22:41:08 +00:00
|
|
|
|
2011-10-14 05:44:12 +00:00
|
|
|
if (! $io->loaded() OR (! Auth::instance()->authorised($io->account_id,$io->affiliate_id) AND ! in_array($this->ao->affiliate->id,$io->service_affiliates()))) {
|
2010-11-29 22:41:08 +00:00
|
|
|
$this->template->content = 'Unauthorised or doesnt exist?';
|
2012-01-09 01:35:24 +00:00
|
|
|
|
2010-11-29 22:41:08 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-12-21 01:39:21 +00:00
|
|
|
$output .= View::factory($this->viewpath())
|
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);
|
|
|
|
|
2013-01-15 06:07:54 +00:00
|
|
|
if ($io->due() AND ! $io->cart_exists()) {
|
|
|
|
$output .= View::factory($this->viewpath().'/pay')
|
|
|
|
->set('mid',$io->mid())
|
|
|
|
->set('o',$io);
|
|
|
|
}
|
|
|
|
|
2012-01-09 01:35:24 +00:00
|
|
|
if (! $io->status) {
|
|
|
|
// Add a gribber popup
|
|
|
|
// @todo Make a gribber popup a class on its own.
|
|
|
|
Style::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'css/jquery.gritter.css',
|
|
|
|
'media'=>'screen',
|
|
|
|
));
|
|
|
|
Script::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'js/jquery.gritter-1.5.js',
|
|
|
|
));
|
|
|
|
Script::add(array(
|
|
|
|
'type'=>'stdin',
|
|
|
|
'data'=>sprintf(
|
|
|
|
'$(document).ready(function() {
|
|
|
|
$.extend($.gritter.options, {
|
|
|
|
fade_in_speed: "medium",
|
|
|
|
fade_out_speed: 2000,
|
|
|
|
time: "3000",
|
|
|
|
sticky: false,
|
|
|
|
});
|
|
|
|
$.gritter.add({
|
|
|
|
title: "%s",
|
|
|
|
text: "%s",
|
|
|
|
image: "%s",
|
|
|
|
});});',
|
|
|
|
'Cancelled','Invoice CANCELLED',URL::site().SystemMessage::image('info',true)
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
|
|
|
Style::add(array(
|
|
|
|
'type'=>'stdin',
|
|
|
|
'data'=>'
|
|
|
|
#watermark {
|
|
|
|
color: #800000;
|
|
|
|
font-size: 4em;
|
|
|
|
-webkit-transform: rotate(-45deg);
|
|
|
|
-moz-transform: rotate(-45deg);
|
|
|
|
position: absolute;
|
|
|
|
width: 100%;
|
|
|
|
height: 100%;
|
|
|
|
margin: 0;
|
|
|
|
z-index: 1;
|
2013-01-04 04:13:48 +00:00
|
|
|
left:250px;
|
|
|
|
top:-20px;
|
2012-01-09 01:35:24 +00:00
|
|
|
}
|
|
|
|
'));
|
|
|
|
|
|
|
|
$output .= '<div id="watermark"><p>Invoice CANCELLED.</p></div>';
|
|
|
|
}
|
|
|
|
|
2011-08-27 06:33:46 +00:00
|
|
|
Block::add(array(
|
2011-12-20 05:46:10 +00:00
|
|
|
'title'=>sprintf('%s: %s - %s',_('Invoice'),$io->refnum(),$io->account->name()),
|
2011-08-27 06:33:46 +00:00
|
|
|
'body'=>$output,
|
|
|
|
));
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
2011-05-02 12:28:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Download an invoice
|
|
|
|
*/
|
2012-01-01 09:41:42 +00:00
|
|
|
public function action_download() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$io = ORM::factory('Invoice',$this->request->param('id'));
|
2011-05-02 12:28:17 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
?>
|