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
*/
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
$uo = parent::get_user($default);

View File

@ -148,7 +148,7 @@ $(document).ready(function() {
->title_icon('icon-th-list')
->body(Table::factory()
->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(
'id'=>'ID',
'date_charge'=>'Date',

View File

@ -9,7 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing
* @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(
'list'=>TRUE,
'templateadd'=>TRUE,

View File

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

View File

@ -20,7 +20,7 @@ class Controller_Reseller_Invoice extends Controller_Invoice {
->title_icon('icon-th-list')
->body(Table::factory()
->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)
->columns(array(
'id'=>'ID',

View File

@ -22,6 +22,13 @@ class Controller_User_Invoice extends Controller_Invoice {
public function action_download() {
$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->headers(array('Content-Type' => 'application/pdf'));
$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_icon('icon-list-alt')
->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(
'invoice_item'=>array('far_key'=>'id'),
'invoice_item_tax'=>array('through'=>'invoice_item'),
'invoice_memo'=>array('far_key'=>'id'),
'service'=>array('through'=>'invoice_item'),
'payment'=>array('through'=>'payment_item'),
'payment_item'=>array('far_key'=>'id'),
@ -190,6 +191,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
return $format ? Currency::display($result) : $result;
}
//ZZ
/**
* 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
*/
public function list_overdue_billing($time=NULL,$billing=FALSE) {
public function list_overdue_billing($time=NULL,$billing=FALSE,$authorised=TRUE) {
$result = array();
foreach ($this->list_overdue($time) as $io) {
foreach ($this->list_overdue($time,$authorised) as $io) {
$i = FALSE;
foreach ($io->service->find_all() as $so)
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';
$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
// If we have already sent a reminder, we'll skip to the next one.
if ($io->remind($key) OR ($io->account->invoice_delivery != 1))

View File

@ -27,7 +27,7 @@ class Task_Invoice_Remindoverdue1 extends Minion_Task {
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 ($io->remind($key) OR ($io->account->invoice_delivery != 1))
continue;

View File

@ -22,6 +22,7 @@ class Model_Service extends ORM_OSB {
'invoice_item'=>array('far_key'=>'id'),
'invoice'=>array('through'=>'invoice_item'),
'service_change'=>array('far_key'=>'id'),
'service_memo'=>array('far_key'=>'id'),
);
protected $_belongs_to = array(
'product'=>array(),
@ -292,8 +293,8 @@ class Model_Service extends ORM_OSB {
public function list_byplugin($plugin) {
return $this
->join('product')
->on($this->table_name().'.site_id','=','product.site_id') // @todo This should be automatic
->on($this->table_name().'.product_id','=','product.id')
->on($this->table_name().'.site_id','=','product.site_id') // @todo This should be automatic
->on($this->table_name().'.product_id','=','product.id')
->where('prod_plugin_file','=',$plugin)
->and_where('service.status','=',TRUE)
->find_all();

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

@ -40,7 +40,7 @@
echo $o->product->feature_summary();
endif ?>
</div> <!-- /row -->
</div> <!-- /row -->
<div class="row">
<?php echo $o->details('service_view'); ?>
@ -93,3 +93,19 @@
<?php echo Invoice::instance()->add_service($o)->render('html','body',array('noid'=>TRUE)); ?>
</fieldset>
</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
* @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(
'download'=>FALSE,
);
@ -37,6 +37,13 @@ class Controller_User_SSL extends Controller_TemplateDefault_User {
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());
openssl_pkcs12_export_to_file($so->plugin()->cert,$file,$so->plugin()->pk,$passwd,array('extracerts'=>$so->plugin()->cacerts()));
$x = file_get_contents($file);