Added Invoice/SSL download recording, other misc fixes

This commit is contained in:
Deon George 2013-10-11 13:08:50 +11:00
parent 6f855fb32d
commit 6e95184b0c
15 changed files with 137 additions and 12 deletions

View File

@ -174,6 +174,10 @@ class Auth_OSB extends Auth_ORM {
* @return mixed * @return mixed
*/ */
public function get_user($default=NULL,$tokenuser=TRUE) { public function get_user($default=NULL,$tokenuser=TRUE) {
// If we are a CLI, we are not logged in
if (PHP_SAPI === 'cli')
throw new Kohana_Exception('Calling :method from the CLI is not allowed!',array(':method'=>__METHOD__));
// Get the current user // Get the current user
$uo = parent::get_user($default); $uo = parent::get_user($default);

View File

@ -148,7 +148,7 @@ $(document).ready(function() {
->title_icon('icon-th-list') ->title_icon('icon-th-list')
->body(Table::factory() ->body(Table::factory()
->page_items(50) ->page_items(50)
->data(ORM::factory('Charge')->where_authorised('account_id',$this->ao)->where('void','is',NULL)->order_by('id DESC')->find_all()) ->data(ORM::factory('Charge')->where_authorised($this->ao)->where('void','is',NULL)->order_by('id DESC')->find_all())
->columns(array( ->columns(array(
'id'=>'ID', 'id'=>'ID',
'date_charge'=>'Date', 'date_charge'=>'Date',

View File

@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing * @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_Admin_Email extends Controller_TemplateDefault_Admin { class Controller_Admin_Email extends Controller_Email {
protected $secure_actions = array( protected $secure_actions = array(
'list'=>TRUE, 'list'=>TRUE,
'templateadd'=>TRUE, 'templateadd'=>TRUE,

View File

@ -1,7 +1,7 @@
<?php defined('SYSPATH') or die('No direct access allowed.'); <?php defined('SYSPATH') or die('No direct access allowed.');
/** /**
* This class provides email management * This class provides EMAIL management
* *
* @package Email * @package Email
* @category Controllers * @category Controllers

View File

@ -20,7 +20,7 @@ class Controller_Reseller_Invoice extends Controller_Invoice {
->title_icon('icon-th-list') ->title_icon('icon-th-list')
->body(Table::factory() ->body(Table::factory()
->jssort('invoices') ->jssort('invoices')
->data(ORM::factory('Invoice')->where_authorised('account_id',$this->ao)->where_active()->find_all()) ->data(ORM::factory('Invoice')->where_authorised($this->ao)->where_active()->find_all())
->page_items(25) ->page_items(25)
->columns(array( ->columns(array(
'id'=>'ID', 'id'=>'ID',

View File

@ -22,6 +22,13 @@ class Controller_User_Invoice extends Controller_Invoice {
public function action_download() { public function action_download() {
$io = ORM::factory('Invoice',$this->request->param('id')); $io = ORM::factory('Invoice',$this->request->param('id'));
// Log the download
$imo = $io->invoice_memo;
$imo->invoice_id = $io->id;
$imo->account_id = $this->ao->id;
$imo->memo = 'Invoice Downloaded.';
$imo->save();
$this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D')); $this->response->body(Invoice::instance($io)->pdf()->Output(sprintf('%s.pdf',$io->refnum()),'D'));
$this->response->headers(array('Content-Type' => 'application/pdf')); $this->response->headers(array('Content-Type' => 'application/pdf'));
$this->auto_render = FALSE; $this->auto_render = FALSE;
@ -83,6 +90,20 @@ class Controller_User_Invoice extends Controller_Invoice {
->title(sprintf('%s: %s - %s',_('Invoice'),$io->refnum(),$io->account->name())) ->title(sprintf('%s: %s - %s',_('Invoice'),$io->refnum(),$io->account->name()))
->title_icon('icon-list-alt') ->title_icon('icon-list-alt')
->body($output); ->body($output);
$x = $io->invoice_memo->find_all();
if ($x->count())
Block::factory()
->title('Invoice Memos')
->title_icon('icon-list-alt')
->body(Table::factory()
->data($x)
->columns(array(
'id'=>'ID',
'date_orig'=>'Date',
'account->name()'=>'Account',
'memo'=>'Memo',
)));
} }
} }
?> ?>

View File

@ -16,6 +16,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
protected $_has_many = array( protected $_has_many = array(
'invoice_item'=>array('far_key'=>'id'), 'invoice_item'=>array('far_key'=>'id'),
'invoice_item_tax'=>array('through'=>'invoice_item'), 'invoice_item_tax'=>array('through'=>'invoice_item'),
'invoice_memo'=>array('far_key'=>'id'),
'service'=>array('through'=>'invoice_item'), 'service'=>array('through'=>'invoice_item'),
'payment'=>array('through'=>'payment_item'), 'payment'=>array('through'=>'payment_item'),
'payment_item'=>array('far_key'=>'id'), 'payment_item'=>array('far_key'=>'id'),
@ -190,6 +191,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
return $format ? Currency::display($result) : $result; return $format ? Currency::display($result) : $result;
} }
//ZZ
/** /**
* Return a list of valid checkout options for this invoice * Return a list of valid checkout options for this invoice
*/ */
@ -698,10 +700,10 @@ class Model_Invoice extends ORM_OSB implements Cartable {
/** /**
* Return a list of invoices that are over their due date with/without auto billing * Return a list of invoices that are over their due date with/without auto billing
*/ */
public function list_overdue_billing($time=NULL,$billing=FALSE) { public function list_overdue_billing($time=NULL,$billing=FALSE,$authorised=TRUE) {
$result = array(); $result = array();
foreach ($this->list_overdue($time) as $io) { foreach ($this->list_overdue($time,$authorised) as $io) {
$i = FALSE; $i = FALSE;
foreach ($io->service->find_all() as $so) foreach ($io->service->find_all() as $so)
if (($billing AND $so->account_billing_id) OR (! $billing AND ! $so->account_billing_id)) { if (($billing AND $so->account_billing_id) OR (! $billing AND ! $so->account_billing_id)) {

View File

@ -0,0 +1,30 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Invoice Memos.
*
* @package Invoice
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Invoice_Memo extends ORM_OSB {
// Relationships
protected $_belongs_to = array(
'invoice'=>array(),
);
protected $_has_one = array(
'account'=>array('foreign_key'=>'id'),
);
/**
* Filters used to format the display of values into friendlier values
*/
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
}
?>

View File

@ -15,7 +15,7 @@ class Task_Invoice_Reminddue extends Minion_Task {
$key = 'remind_due'; $key = 'remind_due';
$days = ORM::factory('Invoice')->config(strtoupper($key)); $days = ORM::factory('Invoice')->config(strtoupper($key));
foreach (ORM::factory('Invoice')->list_due(time()+86400*$days) as $io) { foreach (ORM::factory('Invoice')->list_overdue(time()+86400*$days,FALSE) as $io) {
// @todo Use another option to supress reminders // @todo Use another option to supress reminders
// If we have already sent a reminder, we'll skip to the next one. // If we have already sent a reminder, we'll skip to the next one.
if ($io->remind($key) OR ($io->account->invoice_delivery != 1)) if ($io->remind($key) OR ($io->account->invoice_delivery != 1))

View File

@ -27,7 +27,7 @@ class Task_Invoice_Remindoverdue1 extends Minion_Task {
return; return;
} }
foreach (ORM::factory('Invoice')->list_overdue_billing(time()-86400*$days,FALSE) as $io) { foreach (ORM::factory('Invoice')->list_overdue_billing(time()-86400*$days,FALSE,FALSE) as $io) {
// If we have already sent a reminder, we'll skip to the next one. // If we have already sent a reminder, we'll skip to the next one.
if ($io->remind($key) OR ($io->account->invoice_delivery != 1)) if ($io->remind($key) OR ($io->account->invoice_delivery != 1))
continue; continue;

View File

@ -22,6 +22,7 @@ class Model_Service extends ORM_OSB {
'invoice_item'=>array('far_key'=>'id'), 'invoice_item'=>array('far_key'=>'id'),
'invoice'=>array('through'=>'invoice_item'), 'invoice'=>array('through'=>'invoice_item'),
'service_change'=>array('far_key'=>'id'), 'service_change'=>array('far_key'=>'id'),
'service_memo'=>array('far_key'=>'id'),
); );
protected $_belongs_to = array( protected $_belongs_to = array(
'product'=>array(), 'product'=>array(),

View File

@ -0,0 +1,30 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Service Memos.
*
* @package Service
* @category Models
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Service_Memo extends ORM_OSB {
// Relationships
protected $_belongs_to = array(
'service'=>array(),
);
protected $_has_one = array(
'account'=>array('foreign_key'=>'id'),
);
/**
* Filters used to format the display of values into friendlier values
*/
protected $_display_filters = array(
'date_orig'=>array(
array('Config::datetime',array(':value')),
),
);
}
?>

View File

@ -93,3 +93,19 @@
<?php echo Invoice::instance()->add_service($o)->render('html','body',array('noid'=>TRUE)); ?> <?php echo Invoice::instance()->add_service($o)->render('html','body',array('noid'=>TRUE)); ?>
</fieldset> </fieldset>
</div> <!-- /row --> </div> <!-- /row -->
<?php $x=$o->service_memo->find_all(); if ($x->count()) : ?>
<div class="row">
<fieldset class="span5">
<legend>Service Memos</legend>
<?php echo Table::factory()
->data($x)
->columns(array(
'id'=>'ID',
'date_orig'=>'Date',
'account->name()'=>'Account',
'memo'=>'Memo',
)); ?>
</fieldset>
</div> <!-- /row -->
<?php endif ?>

View File

@ -0,0 +1,14 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides SSL management
*
* @package SSL
* @category Controllers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_SSL extends Controller_TemplateDefault {
}
?>

View File

@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing * @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class Controller_User_SSL extends Controller_TemplateDefault_User { class Controller_User_SSL extends Controller_SSL {
protected $secure_actions = array( protected $secure_actions = array(
'download'=>FALSE, 'download'=>FALSE,
); );
@ -37,6 +37,13 @@ class Controller_User_SSL extends Controller_TemplateDefault_User {
return FALSE; return FALSE;
} }
// Log the download
$smo = $so->service_memo;
$smo->service_id = $so->id;
$smo->account_id = $this->ao->id;
$smo->memo = sprintf('SSL Certificate %s Downloaded.',$so->plugin()->serial());
$smo->save();
$file = sprintf('%s/%s.pkcs12',Kohana::$config->load('config')->tmpdir,$so->name()); $file = sprintf('%s/%s.pkcs12',Kohana::$config->load('config')->tmpdir,$so->name());
openssl_pkcs12_export_to_file($so->plugin()->cert,$file,$so->plugin()->pk,$passwd,array('extracerts'=>$so->plugin()->cacerts())); openssl_pkcs12_export_to_file($so->plugin()->cert,$file,$so->plugin()->pk,$passwd,array('extracerts'=>$so->plugin()->cacerts()));
$x = file_get_contents($file); $x = file_get_contents($file);