Fixed payment updates, admin update and minor SSL items
This commit is contained in:
parent
50fe0583a3
commit
4a68621fc7
@ -30,8 +30,9 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Required abstract functions
|
// Required abstract functions
|
||||||
public function service_view() {
|
public function admin_update() {
|
||||||
return View::factory('service/user/plugin/adsl/view')
|
return View::factory('service/admin/adsl/update')
|
||||||
|
->set('mediapath',Route::get('default/media'))
|
||||||
->set('so',$this);
|
->set('so',$this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,6 +47,11 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
|
|||||||
return $this->service->product->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
|
* 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
|
* Render a google chart of traffic
|
||||||
*/
|
*/
|
||||||
|
@ -40,9 +40,8 @@ class Model_Service_Plugin_Domain extends Model_Service_Plugin {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Required abstract functions
|
// Required abstract functions
|
||||||
public function service_view() {
|
public function admin_update() {
|
||||||
return View::factory('service/user/plugin/domain/view')
|
return '';
|
||||||
->set('so',$this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function name() {
|
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());
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -34,16 +34,17 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Required abstract functions
|
// Required abstract functions
|
||||||
public function service_view() {
|
public function admin_update() {
|
||||||
return View::factory('service/user/plugin/host/view')
|
return '';
|
||||||
->set('so',$this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function name() {
|
public function name() {
|
||||||
return sprintf('%s.%s',$this->display('domain_name'),$this->domain_tld->display('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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -45,14 +45,21 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
|
|||||||
$this->auto_render = FALSE;
|
$this->auto_render = FALSE;
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
|
$list = array();
|
||||||
if (isset($_REQUEST['pid']))
|
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')
|
$output .= View::factory($this->viewpath().'/body')
|
||||||
->set('trc',$i++%2 ? 'odd' : 'even')
|
->set('trc',$i++%2 ? 'odd' : 'even')
|
||||||
->set('pio',$pio)
|
->set('pio',$pio)
|
||||||
->set('io',$pio->invoice);
|
->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)
|
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')
|
$output .= View::factory($this->viewpath().'/body')
|
||||||
->set('trc',$i++%2 ? 'odd' : 'even')
|
->set('trc',$i++%2 ? 'odd' : 'even')
|
||||||
->set('pio',ORM::factory('payment_item'))
|
->set('pio',ORM::factory('payment_item'))
|
||||||
@ -96,20 +103,13 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
|
|||||||
$po = ORM::factory('payment',$id);
|
$po = ORM::factory('payment',$id);
|
||||||
|
|
||||||
if ($_POST) {
|
if ($_POST) {
|
||||||
if (isset($_POST['payment_item']) AND count($_POST['payment_item'])) {
|
// Update our invoice payment items
|
||||||
foreach ($_POST['payment_item'] as $k=>$v) {
|
if (isset($_POST['payment_item']) AND count($_POST['payment_item']))
|
||||||
if ($v) {
|
foreach ($_POST['payment_item'] as $k=>$v)
|
||||||
$pio = $po->add_item();
|
$po->add_item($k)->alloc_amt = is_numeric($v) ? $v : 0;
|
||||||
$pio->invoice_id = $k;
|
|
||||||
$pio->alloc_amt = $v;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entry updated
|
// Entry updated
|
||||||
if (! $po->values($_POST)->check() OR ! $po->save())
|
if ($po->values($_POST)->check() AND $po->save())
|
||||||
throw new Kohana_Exception('Unable to save payment');
|
|
||||||
else
|
|
||||||
SystemMessage::add(array(
|
SystemMessage::add(array(
|
||||||
'title'=>'Payment Recorded',
|
'title'=>'Payment Recorded',
|
||||||
'type'=>'info',
|
'type'=>'info',
|
||||||
|
@ -37,27 +37,35 @@ class Model_Payment extends ORMOSB {
|
|||||||
// Items belonging to an invoice
|
// Items belonging to an invoice
|
||||||
private $payment_items = array();
|
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.
|
* Return a list of invoice items for this payment.
|
||||||
*/
|
*/
|
||||||
public function items() {
|
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;
|
return $this->payment_items;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an item to an invoice
|
* Add an item to an invoice
|
||||||
*/
|
*/
|
||||||
public function add_item() {
|
public function add_item($iid) {
|
||||||
if ($this->loaded() and ! $this->payment_items)
|
// Find our id, if it exists
|
||||||
throw new Kohana_Exception('Need to load payment_items?');
|
foreach ($this->payment_items as $pio)
|
||||||
|
if ($pio->invoice_id == $iid)
|
||||||
|
return $pio;
|
||||||
|
|
||||||
|
// New Item
|
||||||
$c = count($this->payment_items);
|
$c = count($this->payment_items);
|
||||||
|
|
||||||
$this->payment_items[$c] = ORM::factory('payment_item');
|
$this->payment_items[$c] = ORM::factory('payment_item');
|
||||||
|
$this->payment_items[$c]->invoice_id = $iid;
|
||||||
|
|
||||||
return $this->payment_items[$c];
|
return $this->payment_items[$c];
|
||||||
}
|
}
|
||||||
@ -151,7 +159,33 @@ class Model_Payment extends ORMOSB {
|
|||||||
$this->source_id = Auth::instance()->get_user()->id;
|
$this->source_id = Auth::instance()->get_user()->id;
|
||||||
$this->ip = Request::$client_ip;
|
$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
|
// Save the payment
|
||||||
parent::save($validation);
|
parent::save($validation);
|
||||||
|
@ -15,9 +15,9 @@ abstract class Model_Service_Plugin extends ORMOSB {
|
|||||||
protected $_sorting = array();
|
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
|
* 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());
|
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
|
* Get specific service details for use in other modules
|
||||||
* For Example: Invoice
|
* For Example: Invoice
|
||||||
|
@ -19,7 +19,7 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
|
|||||||
|
|
||||||
public function action_list() {
|
public function action_list() {
|
||||||
Block::add(array(
|
Block::add(array(
|
||||||
'title'=>_('SSL Services'),
|
'title'=>_('SSL CA Certificates'),
|
||||||
'body'=>Table::display(
|
'body'=>Table::display(
|
||||||
ORM::factory('ssl_ca')->find_all(),
|
ORM::factory('ssl_ca')->find_all(),
|
||||||
25,
|
25,
|
||||||
@ -27,7 +27,7 @@ class Controller_Admin_SSL extends Controller_TemplateDefault_Admin {
|
|||||||
'id'=>array('label'=>'ID','url'=>'admin/ssl/view/'),
|
'id'=>array('label'=>'ID','url'=>'admin/ssl/view/'),
|
||||||
'sign_cert'=>array('label'=>'Cert'),
|
'sign_cert'=>array('label'=>'Cert'),
|
||||||
'issuer()'=>array('label'=>'Issuer'),
|
'issuer()'=>array('label'=>'Issuer'),
|
||||||
'expires()'=>array('label'=>'Expires'),
|
'expires(TRUE)'=>array('label'=>'Expires'),
|
||||||
),
|
),
|
||||||
array(
|
array(
|
||||||
'page'=>TRUE,
|
'page'=>TRUE,
|
||||||
|
@ -26,8 +26,8 @@ class Model_SSL_CA extends ORMOSB {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
public function expires() {
|
public function expires($format=FALSE) {
|
||||||
return SSL::expire($this->sign_cert);
|
return SSL::expire($this->sign_cert,$format);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function issuer() {
|
public function issuer() {
|
||||||
|
Reference in New Issue
Block a user