Fixed payment updates, admin update and minor SSL items

This commit is contained in:
Deon George 2011-12-29 13:52:24 +11:00
parent 50fe0583a3
commit 4a68621fc7
8 changed files with 90 additions and 49 deletions

View File

@ -30,8 +30,9 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
);
// Required abstract functions
public function service_view() {
return View::factory('service/user/plugin/adsl/view')
public function admin_update() {
return View::factory('service/admin/adsl/update')
->set('mediapath',Route::get('default/media'))
->set('so',$this);
}
@ -46,6 +47,11 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
return $this->service->product->plugin();
}
public function service_view() {
return View::factory('service/user/plugin/adsl/view')
->set('so',$this);
}
/**
* Return the IP Address for the service
*/
@ -337,12 +343,6 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
}
}
protected function _admin_update() {
return View::factory($this->viewpath(strtolower($this->service->prod_plugin_name)))
->set('mediapath',Route::get('default/media'))
->set('so',$this);
}
/**
* Render a google chart of traffic
*/

View File

@ -40,9 +40,8 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
);
// Required abstract functions
public function service_view() {
return View::factory('service/user/plugin/domain/view')
->set('so',$this);
public function admin_update() {
return '';
}
public function name() {
@ -53,7 +52,9 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
return sprintf('%s - %s',_('Domain Name License'),$this->name());
}
protected function _admin_update() {
public function service_view() {
return View::factory('service/user/plugin/domain/view')
->set('so',$this);
}
/**

View File

@ -34,16 +34,17 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
);
// Required abstract functions
public function service_view() {
return View::factory('service/user/plugin/host/view')
->set('so',$this);
public function admin_update() {
return '';
}
public function name() {
return sprintf('%s.%s',$this->display('domain_name'),$this->domain_tld->display('name'));
}
protected function _admin_update() {
public function service_view() {
return View::factory('service/user/plugin/host/view')
->set('so',$this);
}
/**

View File

@ -45,14 +45,21 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
$this->auto_render = FALSE;
$i = 0;
$list = array();
if (isset($_REQUEST['pid']))
foreach (ORM::factory('payment_item')->where('payment_id','=',$_REQUEST['pid'])->find_all() as $pio)
foreach (ORM::factory('payment',$_REQUEST['pid'])->items() as $pio) {
$output .= View::factory($this->viewpath().'/body')
->set('trc',$i++%2 ? 'odd' : 'even')
->set('pio',$pio)
->set('io',$pio->invoice);
// Remember the invoices we have listed
array_push($list,$pio->invoice_id);
}
foreach (ORM::factory('account',$_REQUEST['key'])->invoices_due() as $io)
// Only list invoices not yet listed
if (! in_array($io->id,$list))
$output .= View::factory($this->viewpath().'/body')
->set('trc',$i++%2 ? 'odd' : 'even')
->set('pio',ORM::factory('payment_item'))
@ -96,20 +103,13 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
$po = ORM::factory('payment',$id);
if ($_POST) {
if (isset($_POST['payment_item']) AND count($_POST['payment_item'])) {
foreach ($_POST['payment_item'] as $k=>$v) {
if ($v) {
$pio = $po->add_item();
$pio->invoice_id = $k;
$pio->alloc_amt = $v;
}
}
}
// Update our invoice payment items
if (isset($_POST['payment_item']) AND count($_POST['payment_item']))
foreach ($_POST['payment_item'] as $k=>$v)
$po->add_item($k)->alloc_amt = is_numeric($v) ? $v : 0;
// Entry updated
if (! $po->values($_POST)->check() OR ! $po->save())
throw new Kohana_Exception('Unable to save payment');
else
if ($po->values($_POST)->check() AND $po->save())
SystemMessage::add(array(
'title'=>'Payment Recorded',
'type'=>'info',

View File

@ -37,27 +37,35 @@ class Model_Payment extends ORMOSB {
// Items belonging to an invoice
private $payment_items = array();
public function __construct($id = NULL) {
// Load our model.
parent::__construct($id);
// Load our sub items
if ($this->loaded())
$this->payment_items = $this->payment_item->find_all()->as_array();
}
/**
* Return a list of invoice items for this payment.
*/
public function items() {
// If we havent been changed, we'll load the records from the DB.
if ($this->loaded() AND ! $this->_changed)
return $this->payment_item->order_by('invoice_id')->find_all()->as_array();
else
return $this->payment_items;
}
/**
* Add an item to an invoice
*/
public function add_item() {
if ($this->loaded() and ! $this->payment_items)
throw new Kohana_Exception('Need to load payment_items?');
public function add_item($iid) {
// Find our id, if it exists
foreach ($this->payment_items as $pio)
if ($pio->invoice_id == $iid)
return $pio;
// New Item
$c = count($this->payment_items);
$this->payment_items[$c] = ORM::factory('payment_item');
$this->payment_items[$c]->invoice_id = $iid;
return $this->payment_items[$c];
}
@ -151,7 +159,33 @@ class Model_Payment extends ORMOSB {
$this->source_id = Auth::instance()->get_user()->id;
$this->ip = Request::$client_ip;
// @todo Need validation, if there is an overbalance in payment_items or if an invoice is overpaid.
// Make sure we dont over allocate
$t = 0;
$msg = '';
foreach ($items as $pio) {
// Only need to check items that ave actually changed.
if ($pio->changed()) {
$old_pio = ORM::factory('payment_item',$pio->id);
if ($it = $pio->invoice->due()+ORM::factory('payment_item',$pio->id)->alloc_amt-$pio->alloc_amt < 0)
$msg .= ($msg ? ' ' : '').sprintf('Invoice %s over allocated by %3.2f.',$pio->invoice_id,$it);
}
$t += $pio->alloc_amt;
}
if ($t > (float)$this->total_amt)
$msg .= ($msg ? ' ' : '').sprintf('Payment over allocated by %3.2f.',$t-$this->total_amt);
if ($msg) {
SystemMessage::add(array(
'title'=>'Payment NOT Recorded',
'type'=>'warning',
'body'=>$msg,
));
return FALSE;
}
// Save the payment
parent::save($validation);

View File

@ -15,9 +15,9 @@ abstract class Model_Service_Plugin extends ORMOSB {
protected $_sorting = array();
/**
* View details of the service
* Form info for admins to update
*/
abstract public function service_view();
abstract public function admin_update();
/**
* Our service name as defined in the DB
@ -31,6 +31,11 @@ abstract class Model_Service_Plugin extends ORMOSB {
return sprintf('%s - %s',$this->service->product->name(),$this->name());
}
/**
* View details of the service
*/
abstract public function service_view();
/**
* Get specific service details for use in other modules
* For Example: Invoice

View File

@ -19,7 +19,7 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
public function action_list() {
Block::add(array(
'title'=>_('SSL Services'),
'title'=>_('SSL CA Certificates'),
'body'=>Table::display(
ORM::factory('ssl_ca')->find_all(),
25,
@ -27,7 +27,7 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
'id'=>array('label'=>'ID','url'=>'admin/ssl/view/'),
'sign_cert'=>array('label'=>'Cert'),
'issuer()'=>array('label'=>'Issuer'),
'expires()'=>array('label'=>'Expires'),
'expires(TRUE)'=>array('label'=>'Expires'),
),
array(
'page'=>TRUE,

View File

@ -26,8 +26,8 @@ class Model_SSL_CA extends ORMOSB {
),
);
public function expires() {
return SSL::expire($this->sign_cert);
public function expires($format=FALSE) {
return SSL::expire($this->sign_cert,$format);
}
public function issuer() {