Multi enhancements, including auto serialization, product editing

This commit is contained in:
Deon George 2012-03-30 15:13:01 +11:00
parent d9c3394b0f
commit 6807b6ab52
30 changed files with 445 additions and 115 deletions

View File

@ -16,7 +16,7 @@ class lnApp_Table {
if (is_array($d) AND isset($d[$key]))
$x = $d[$key];
// If the key is a method, we need to eval it
elseif (preg_match('/\(/',$key))
elseif (preg_match('/\(/',$key) OR preg_match('/-\>/',$key))
eval("\$x = \$d->$key;");
elseif (preg_match('/^__VALUE__$/',$key))
$x = $d;

View File

@ -19,6 +19,9 @@ abstract class ORMOSB extends ORM {
protected $_created_column = array('column'=>'date_orig','format'=>TRUE);
protected $_updated_column = array('column'=>'date_last','format'=>TRUE);
// Our attribute values that need to be stored as serialized
protected $_serialize_column = array();
public function rules() {
return array(
'id'=>array(
@ -93,6 +96,7 @@ abstract class ORMOSB extends ORM {
return TRUE;
}
// @todo Change this to be called by array_blob functions
public static function serialize_array(ORM $model,$field,$value) {
if (is_null($value))
return TRUE;
@ -105,8 +109,10 @@ abstract class ORMOSB extends ORM {
}
public function __get($column) {
if (array_key_exists($column,$this->_table_columns)) {
// If the column is a blob, we'll decode it automatically
if (array_key_exists($column,$this->_table_columns) AND $this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
if ($this->_table_columns[$column]['data_type'] == 'blob' AND (! isset($this->_table_columns[$column]['auto_convert']) OR ! $this->_table_columns[$column]['auto_convert'])) {
// In case our blob hasnt been saved as one.
try {
@ -121,9 +127,33 @@ abstract class ORMOSB extends ORM {
$this->_table_columns[$column]['auto_convert'] = TRUE;
}
// If the column is a serialized object, we'll unserialize it.
if (in_array($column,$this->_serialize_column) AND (! isset($this->_table_columns[$column]['unserialized']) OR ! $this->_table_columns[$column]['unserialized'])) {
// In case our object hasnt been saved as serialized.
try {
$this->_object[$column] = unserialize($this->_object[$column]);
}
catch(Exception $e) {
// @todo Log this exception
echo Kohana_Exception::text($e), "\n";
echo debug_print_backtrace();
}
$this->_table_columns[$column]['unserialized'] = TRUE;
}
}
return parent::__get($column);
}
public function keyget($column,$key=NULL) {
if (is_null($key) OR ! is_array($this->$column))
return $this->$column;
else
return array_key_exists($key,$this->$column) ? $this->{$column}[$key] : NULL;
}
public function save(Validation $validation = NULL) {
// Find any fields that have changed, and that are blobs, and encode them.
if ($this->_changed)

View File

@ -47,6 +47,13 @@ abstract class StaticList {
return $table[$id];
}
/**
* Lists our available keys
*/
public static function keys() {
return array_keys(static::factory()->table());
}
/**
* Renders form input
*

View File

@ -51,7 +51,7 @@
<ul>
<li id="current"><?php echo HTML::anchor('','Home'); ?></li>
<li><?php echo HTML::anchor('product/categorys','Products'); ?></li>
<li><?php echo HTML::anchor('staticpage_category/list','FAQ'); ?></li>
<li><?php echo HTML::anchor('http://helpdesk.graytech.net.au/otrs/faq.pl','FAQ'); ?></li>
</ul>
</div>
<div id="nav_main2">

View File

@ -28,6 +28,10 @@ class Model_Product_Plugin_ADSL extends Model_Product_Plugin {
),
);
public function admin_update() {
return '';
}
// Our required abstract methods
public function feature_summary() {
// @todo This view should render based on the the results of this::allowance();

View File

@ -67,6 +67,10 @@ class Model_Service_Plugin_ADSL extends Model_Service_Plugin {
return Config::date(strtotime(sprintf('+%s months',$this->contract_term),$this->service_connect_date));
}
public function hasOffpeak() {
return ((is_null($this->product()->base_down_offpeak) OR $this->product()->base_down_offpeak) AND (is_null($this->product()->base_up_offpeak) OR $this->product()->base_up_offpeak)) ? TRUE : FALSE;
}
/**
* This function will return the months that have traffic data.
* This array can be used in a select list to display the traffic for that month

View File

@ -1,12 +0,0 @@
<tr class="<?php echo $i ? 'odd' : 'even'; ?>">
<td><?php echo $service->plugin()->display('service_number'); ?></td>
<td><?php echo $service->plugin()->ipaddress(); ?></td>
<td><?php printf('%s (%s)',$service->product->name(),$service->id); ?></td>
<td><?php echo $service->product->prod_plugin_file ? $service->product->plugin()->allowance() : 'No Details'; ?></td>
<td><?php echo $service->plugin()->traffic_thismonth(); ?></td>
<td><?php echo $service->plugin()->traffic_lastmonth(); ?></td>
<td><?php echo $service->display('price'); ?></td>
<td><?php echo $service->display('recur_schedule'); ?></td>
<td><?php echo $service->display('date_next_invoice'); ?></td>
<td><input type="checkbox"/></td>
</tr>

View File

@ -1,23 +0,0 @@
<!-- Print out the heading for the first record -->
<!-- // @todo This needs to be translated -->
<tr class="title">
<td colspan="10" style="padding: 0px;">
<table width="100%">
<tr>
<td style="border: 0px;"><?php printf('%s %s',$service->account->accnum(),$service->account->name()); ?></td>
<td style="border: 0px; text-align: right;"><?php printf('(%s: %s)',_('Invoices Due'),Currency::display($service->account->invoices_due_total())); ?></td>
</tr>
</table>
</td>
</tr>
<tr class="head">
<td>Service</td>
<td>IP Address</td>
<td>Plan</td>
<td>Plan Allowance</td>
<td>This Month</td>
<td>Last Month</td>
<td>Amount</td>
<td>Freq</td>
<td>Next Invoice Date</td>
</tr>

View File

@ -35,12 +35,18 @@
</tr>
<tr>
<td>Service Password</td>
<td class="data"><?php #echo $so->display('service_password'); ?></td>
<td class="data"><?php # @todo Enable the ability to hide this value echo $so->display('service_password'); ?></td>
</tr>
<tr>
<td>Service IP</td>
<td class="data"><?php echo $so->ipaddress(); ?></td>
</tr>
<?php if ($so->hasOffPeak() AND $so->offpeak_start AND $so->offpeak_end) { ?>
<tr>
<td>Offpeak Period</td>
<td class="data"><?php printf('%s-%s',$so->offpeak_start,$so->offpeak_end); ?></td>
</tr>
<?php } ?>
</table>
</td>
<td style="vertical-align: top;" colspan="2">

View File

@ -16,6 +16,7 @@ class Model_Product_Plugin_Domain extends Model_Product_Plugin {
}
// Our required abstract methods
public function admin_update() {}
public function feature_summary() {}
// @todo This is not used, but should be.

View File

@ -50,6 +50,9 @@ class Quicken extends OSBExport {
# Payments
foreach ($inv->_payments as $payitem) {
if (! $payitem->AMOUNT)
continue;
$export .= "!TRNS\t";
$export .= implode("\t",$payitem->keys())."\n";
$export .= "TRNS\t";

View File

@ -62,8 +62,9 @@ class Controller_Task_Invoice extends Controller_Task {
$days = ORM::factory('invoice')->config('REMIND_DUE');
foreach (ORM::factory('invoice')->list_due(time()+86400*$days) 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) AND (is_null($x=$this->request->param('id')) OR $x != 'again'))
if (($io->remind($key) AND (is_null($x=$this->request->param('id')) OR $x != 'again')) OR ($io->account->invoice_delivery != 1))
continue;
// Send our email
@ -115,8 +116,9 @@ class Controller_Task_Invoice extends Controller_Task {
$key = 'remind_overdue_'.$notice;
foreach (ORM::factory('invoice')->list_overdue_billing(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) AND (is_null($x) OR $x != 'again'))
if (($io->remind($key) AND (is_null($x=$this->request->param('id')) OR $x != 'again')) OR ($io->account->invoice_delivery != 1))
continue;
// Send our email
@ -148,16 +150,17 @@ class Controller_Task_Invoice extends Controller_Task {
/**
* Generate our services invoices, based on the service next invoice date
*
* @param int ID Service ID to generate invoice for (optional)
* @param int ID Service ID to generate invoice for (optional) - multiple services colon separated
*/
public function action_services() {
// Used to only process X invoices in a row.
$max = ORM::factory('invoice')->config('GEN_INV_MAX');
$action = array();
$snd = array(); // Our service next billing dates that need to be updated if this is successful.
// Our service next billing dates that need to be updated if this is successful.
$snd = array();
// Our charges that need to be updated if this is successful.
$chgs = array();
// If we are invoicing a specific service
$sid = is_null($this->request->param('id')) ? NULL : explode(':',$this->request->param('id'));
// Sort our service by account_id, then we can generate 1 invoice.
$svs = ORM::factory('service')->list_invoicesoon()->as_array();
Sort::MAsort($svs,'account_id,date_next_invoice');
@ -189,22 +192,19 @@ class Controller_Task_Invoice extends Controller_Task {
$io->status = TRUE;
}
$ppa = $so->product->get_price_array();
// @todo Need to check our recurr_weekday configuration for items that need to be pro-rated and items that are billed on absolute dates.
$pdata = Period::details($so->recur_schedule,$so->product->price_recurr_weekday,$so->date_next_invoice,TRUE);
$iio = $io->add_item();
$iio = $io->add_item();
$iio->service_id = $so->id;
$iio->product_id = $so->product_id;
$iio->quantity = $pdata['prorata'];
$iio->item_type = 0;
$iio->item_type = 0; // Service Billing
$iio->discount_amt = null; // @todo
$iio->price_type = $so->product->price_type; // @todo Do we need this?
// @todo Might be a better way to do this
$iio->price_base = $so->price ? $so->price : (isset($ppa[$so->recur_schedule]['price_base']) ? $ppa[$so->recur_schedule]['price_base'] : 0);
$iio->price_type = $so->product->price_type;
$iio->price_base = $so->price();
$iio->recurring_schedule = $so->recur_schedule;
$iio->date_start = $pdata['start_time']; // @todo
$iio->date_stop = $pdata['end_time']; // @todo
$iio->date_start = $pdata['start_time'];
$iio->date_stop = $pdata['end_time'];
// Our service next billing date, if this invoice generation is successful.
$snd[$so->id] = $pdata['end_time']+86400;
@ -217,7 +217,6 @@ class Controller_Task_Invoice extends Controller_Task {
foreach ($c->find_all() as $co) {
$iio = $io->add_item();
$iio->service_id = $co->service_id;
$iio->product_id = $co->product_id;
$iio->charge_id = $co->id;
@ -229,11 +228,11 @@ class Controller_Task_Invoice extends Controller_Task {
$iio->date_stop = $co->date_orig; // @todo
// @todo Temp
// We'll mark any charges as temporarily processed, although they should be set to status=1 later.
$co->status=2;
$co->save();
array_push($chgs,$co->id);
}
array_push($action,(string)$so->id);
}
// Save our invoice.
@ -243,13 +242,22 @@ class Controller_Task_Invoice extends Controller_Task {
}
// Update our service next billing dates.
// @todo Catch any update errors
foreach ($snd as $sid=>$date) {
$so = ORM::factory('service',$sid);
$so->date_next_invoice = $date;
$so->save();
}
$this->response->body(_('Services Invoiced: ').join('|',$action));
// Update any processed charges as such
// @todo Catch any update errors
foreach ($chgs as $cid) {
$co = ORM::factory('charge',$cid);
$co->status=1;
$co->save();
}
$this->response->body(_('Services Invoiced: ').join('|',array_keys($snd)));
}
public function action_send() {
@ -270,8 +278,8 @@ class Controller_Task_Invoice extends Controller_Task {
$max_count = 0;
foreach ($i->find_all() as $io) {
// If we have already sent a reminder, we'll skip to the next one.
if ($io->remind($key) AND (is_null($x) OR $x != 'again'))
// If we have already sent a reminder or we dont email invoices we'll skip to the next one.
if (($io->remind($key) AND (is_null($x) OR $x != 'again')) OR ($io->account->invoice_delivery != 1))
continue;
// If we have issued the max number of invoices this round, finish.
@ -303,7 +311,7 @@ class Controller_Task_Invoice extends Controller_Task {
// @todo Record email log id if possible.
if ($et->send()) {
$io->print_status = 1;
$io->set_remind($key,time());
$io->set_remind($key,time(),($x=='again' ? TRUE : FALSE));
array_push($action,(string)$io);
}
}

View File

@ -445,9 +445,13 @@ class Model_Invoice extends ORMOSB {
// If our value is null, we'll remove it.
if (is_null($value) AND isset($remind[$key]))
unset($remind[$key]);
elseif ($add)
elseif ($add) {
if (! is_array($a=$remind[$key]))
$remind[$key] = array($a);
$remind[$key][] = $value;
else
} else
$remind[$key] = $value;
$this->reminders = serialize($remind);

View File

@ -206,6 +206,7 @@ class Controller_Admin_Payment extends Controller_TemplateDefault_Admin {
}
public function action_addbulk() {
// @todo This needs to come from the DB.
$supported = array(
'ezypay'=>'Ezypay',
);

View File

@ -12,17 +12,41 @@
*/
class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
protected $secure_actions = array(
'ajaxtranslateform'=>TRUE,
'list'=>TRUE,
'update'=>TRUE,
'view'=>TRUE,
);
public function action_ajaxtranslateform() {
$this->auto_render = FALSE;
$po = ORM::factory('product',$this->request->param('id'));
if (! $this->request->is_ajax() OR ! $po->loaded() OR ! isset($_REQUEST['key']))
$this->response->body(_('Unable to find translate data'));
else {
$pto = $po->product_translate->where('language_id','=',$_REQUEST['key'])->find();
$this->response->body(View::factory($this->viewpath())->set('pto',$pto));
}
}
/**
* Show a list of products
*/
public function action_list() {
if ($this->request->param('id'))
$prods = ORM::factory('product')->list_category($this->request->param('id'),FALSE);
else
$prods = ORM::factory('product')->order_by('active DESC,prod_plugin_file')->find_all();
Block::add(array(
'title'=>_('Customer Products'),
'body'=>Table::display(
ORM::factory('product')->order_by('active DESC,prod_plugin_file')->find_all(),
$prods,
25,
array(
'id'=>array('label'=>'ID','url'=>'product/view/'),
@ -43,5 +67,78 @@ class Controller_Admin_Product extends Controller_TemplateDefault_Admin {
)),
));
}
/**
* Edit a product configuration
*/
public function action_update() {
$po = ORM::factory('product',$this->request->param('id'));
if (! $po->loaded())
Request::current()->redirect('welcome/index');
if ($_POST) {
if (isset($_POST['product_translate']['id']) AND ($pto=ORM::factory('product_translate',$_POST['product_translate']['id'])) AND $pto->loaded())
if (! $pto->values($_POST['product_translate'])->update()->saved())
throw new Kohana_Exception('Failed to save updates to product_translate data for record :record',array(':record'=>$po->id()));
if (! $po->values($_POST)->update()->saved())
throw new Kohana_Exception('Failed to save updates to product data for record :record',array(':record'=>$so->id()));
}
Block::add(array(
'title'=>sprintf('%s %s:%s',_('Update Product'),$po->id,$po->name()),
'body'=>View::factory($this->viewpath())
->set('po',$po)
->set('mediapath',Route::get('default/media'))
->set('plugin_form',$po->admin_update()),
));
Script::add(array('type'=>'stdin','data'=>'
$(document).ready(function() {
$("select[name=language_id]").change(function() {
// Send the request and update sub category dropdown
$.ajax({
type: "GET",
data: "key="+$(this).val(),
dataType: "html",
cache: false,
url: "'.URL::site('admin/product/ajaxtranslateform/'.$po->id).'",
timeout: 2000,
error: function(x) {
alert("Failed to submit");
},
success: function(data) {
$("div[id=translate]").replaceWith(data);
}
});
});
});
'));
}
public function action_view() {
$po = ORM::factory('product',$this->request->param('id'));
Block::add(array(
'title'=>sprintf('%s: %s',_('Current Services Using this Product'),$po->name()),
'body'=>Table::display(
ORM::factory('service')->where('product_id','=',$po->id)->find_all(),
25,
array(
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'account->accnum()'=>array(),
'account->name()'=>array('label'=>'Account'),
'name()'=>array('label'=>'Details'),
'active'=>array('label'=>'Active'),
'price(TRUE,TRUE)'=>array('label'=>'Price','align'=>'right'),
),
array(
'page'=>TRUE,
'type'=>'select',
'form'=>'user/service/view',
)),
));
}
}
?>

View File

@ -42,6 +42,8 @@ class Controller_Product extends Controller_TemplateDefault {
Request::current()->redirect('welcome/index');
Breadcrumb::name($this->request->uri(),$cat->name);
Breadcrumb::url('product','product/categorys');
Breadcrumb::url('product/category','product/categorys');
Block::add(array(
'title'=>sprintf('%s: %s',_('Category'),$cat->name),
@ -68,6 +70,7 @@ class Controller_Product extends Controller_TemplateDefault {
Request::current()->redirect('product_category/index');
Breadcrumb::name($this->request->uri(),$po->product_translate->find()->name);
Breadcrumb::url('product','product/categorys');
// Work out our category id for the control line
if (! empty($_GET['cid'])) {
@ -78,6 +81,7 @@ class Controller_Product extends Controller_TemplateDefault {
Request::current()->redirect('product_category/index');
Breadcrumb::name('product/view',$co->name);
Breadcrumb::url('product/view','product/category/'.$co->id);
}
Block::add(array(

View File

@ -41,6 +41,19 @@ class Model_Product extends ORMOSB {
),
);
// Our attributes that are arrays, we'll convert/unconvert them
protected $_serialize_column = array(
'price_group',
);
public function rules() {
return array_merge(parent::rules(),array(
'price_group'=>array(
array('ORMOSB::serialize_array',array(':model',':field',':value')),
),
));
}
/**
* Return the object of the product plugin
*/
@ -81,14 +94,14 @@ class Model_Product extends ORMOSB {
// @todo Need to work out our default groups elsewhere, not in product
// All users are members of the all user group "0"
$groups = array(0);
$pg = unserialize($this->price_group);
if (Auth::instance()->logged_in())
foreach (Auth::instance()->get_user()->group->find_all() as $go)
array_push($groups,$go->id);
// Work out the best price for the user
$price = array();
foreach (unserialize($this->price_group) as $bill_freq => $pg) {
if (is_array($this->price_group))
foreach ($this->price_group as $bill_freq => $pg) {
if (isset($pg['show']) AND $pg['show'])
foreach ($groups as $gid) {
if (! empty($pg[$gid])) {
@ -133,6 +146,50 @@ class Model_Product extends ORMOSB {
echo '';
}
/**
* Enable the plugin to store data
*/
public function admin_update() {
if (is_null($plugin = $this->plugin()))
return NULL;
else
return $plugin->admin_update();
}
/**
* Is price shown for a specific period
*/
public function isPriceShown($p) {
$x = $this->keyget('price_group',$p);
return (isset($x['show']) AND $x['show']) ? TRUE : FALSE;
}
/**
* Return the configured price groups for this product
*/
public function availPriceGroups() {
// @todo This needs to be worked out dynamically
return array(0,2);
}
/**
* Return the available pricing options
*/
public function availPriceOptions() {
// @todo This needs to be worked out dynamically
return array('price_base','price_setup');
}
/**
* Return the price for the particle group and price option for the period
*/
public function price($grp,$period,$option) {
$x = $this->keyget('price_group',$period);
return isset($x[$grp][$option]) ? $x[$grp][$option] : NULL;
}
/**
* List the number of services using this product
*/
@ -151,14 +208,20 @@ class Model_Product extends ORMOSB {
* Return the products for a given category
* @todo This shouldnt be here.
*/
public function list_category($cat) {
public function list_category($cat,$active=TRUE) {
$results = array();
foreach ($this->where('active','=',TRUE)->find_all() as $po) {
if ($active)
$cats = $this->where('active','=',TRUE);
else
$cats = $this;
foreach ($cats->find_all() as $po) {
if ($c = unserialize($po->avail_category) AND in_array($cat,$c))
array_push($results,$po);
}
Sort::MAsort($results,'position,price_base');
return $results;
}
}

View File

@ -0,0 +1,20 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class product access to product category translation.
*
* @package OSB
* @subpackage Product
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Product_Category_Translate extends ORMOSB {
protected $_table_name = 'product_cat_translate';
protected $_belongs_to = array(
'product_category'=>array(),
);
}
?>

View File

@ -14,6 +14,12 @@ abstract class Model_Product_Plugin extends ORMOSB {
// Reset any sorting that may be defined in our parent
protected $_sorting = array();
/**
* The admin_update should be implemented in plugins.
* It is used to update the plugin specific product information
*/
abstract public function admin_update();
/**
* The feature summary should be implemented in plugins.
* It is displayed on the product overview page, as a summary of the products features.

View File

@ -11,6 +11,8 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Product_Translate extends ORMOSB {
protected $_updated_column = FALSE;
protected $_belongs_to = array(
'product'=>array(),
);

View File

@ -0,0 +1,15 @@
<?php echo Form::hidden('product_translate[id]',$pto->id); ?>
<table>
<tr>
<td style="width: 40%;">Product Name</td>
<td style="width: 60%;" style="data"><?php echo Form::input('product_translate[name]',$pto->name); ?></td>
</tr>
<tr>
<td>Product Short Description</td>
<td style="data"><?php echo Form::input('product_translate[description_short]',$pto->description_short); ?></td>
</tr>
<tr>
<td>Product Long Description</td>
<td style="data"><?php echo Form::textarea('product_translate[description_full]',$pto->description_full); ?></td>
</tr>
</table>

View File

@ -0,0 +1,63 @@
<!-- @todo NEEDS TO BE TRANSLATED -->
<?php echo Form::open(); ?>
<table width="100%">
<tr>
<td style="width: 50%; vertical-align: top;">
<table width="100%">
<tr>
<td style="width: 40%;">Product Active</td>
<td style="width: 5%;">&nbsp;</td>
<td style="width: 60%;" class="data"><?php echo StaticList_YesNo::form('active',$po->active); ?></td>
</tr>
<tr>
<td colspan="2">Base Price</td>
<td class="data"><?php echo Form::input('price_base',$po->price_base); ?></td>
</tr>
<tr>
<td colspan="2">Price</td>
<td class="data">
<table>
<tr>
<td colspan="2">&nbsp;</td>
<?php foreach (StaticList_RecurSchedule::keys() as $k) { ?>
<td class="head"><?php echo StaticList_RecurSchedule::display($k); ?></td>
<td><?php echo Form::checkbox("price_group[$k][show]",1,$po->isPriceShown($k)); ?>
<?php } ?>
</tr>
<?php foreach ($po->availPriceGroups() as $g) { ?>
<?php foreach ($po->availPriceOptions() as $o) { ?>
<tr>
<td><?php echo ORM::factory('group',$g)->name; ?></td>
<td><?php echo $o; ?></td>
<?php foreach (StaticList_RecurSchedule::keys() as $k) { ?>
<td colspan="2"><?php echo Form::input("price_group[$k][$g][$o]",$po->price($g,$k,$o),array('size'=>5)); ?></td>
<?php } ?>
</tr>
<?php } ?>
<?php } ?>
</table>
</td>
</tr>
<tr>
<td colspan="2">Default Period</td>
<td class="data"><?php echo StaticList_RecurSchedule::form('price_recurr_default',$po,$po->price_recurr_default); ?></td>
</tr>
<tr>
<td colspan="2">Order</td>
<td class="data"><?php echo Form::input('position',$po->position); ?></td>
</tr>
<tr>
<td>Product Descriptions</td>
<td><?php echo Form::select('language_id',array('','EN'=>'EN')); ?></td>
</tr>
<tr>
<td>&nbsp;</td>
<td class="data" colspan="2"><div id="translate"></div></td>
</tr>
</table>
<?php if ($plugin_form) { echo '<br/>'.$plugin_form; } ?>
</td>
</tr>
</table>
<?php echo Form::submit('submit',_('Update'),array('class'=>'form_button')); ?>
<?php echo Form::close(); ?>

View File

@ -27,7 +27,7 @@ echo Form::open('cart/add');
<td style="background-color: #FFFFFF;">
<table width="100%" border="0" cellpadding="4">
<tr>
<td class="body" rowspan="3"><?php echo $translate->description_full; ?></td>
<td class="body" rowspan="4"><?php echo $translate->description_full; ?></td>
<td style="text-align: right;"><?php if ($a=$record->show_thumb()) echo $a; ?></td>
</tr>
<tr>
@ -43,10 +43,8 @@ echo Form::open('cart/add');
} ?>
</tr>
<tr>
<?php if ($record->prod_plugin_file && method_exists($record->prod_plugin_file,'feature_summary')) {
// @todo This doesnt work, it needs to be product_plugin_xx class
$pio = new $record->prod_plugin_file;
echo '<td style="vertical-align: top;">'.$pio->feature_summary().'</td>';
<?php if ($record->prod_plugin_file && method_exists($record->plugin(),'feature_summary')) {
echo '<td style="vertical-align: top;">'.$record->plugin()->feature_summary().'</td>';
} ?>
</tr>
<tr>
@ -57,7 +55,7 @@ echo Form::open('cart/add');
<td class="body" style="width: 50%;"><b>Currency</b></td>
</tr>
<tr>
<td class="body"><?php echo StaticList_RecurSchedule::form('recurr_schedule',$record);?> </td>
<td class="body"><?php echo StaticList_RecurSchedule::form('recurr_schedule',$record,$record->price_recurr_default);?> </td>
<!-- @todo The default currency should be system configurable and displayed by default -->
<!-- @todo If CURRENCY's value is not active in the DB, then the wrong flag is shown, as StaticList_Module::form() only returns active values -->
<!-- @todo Currency is not used in the cart? -->

View File

@ -59,7 +59,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
@ -96,7 +96,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
@ -128,7 +128,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
@ -201,10 +201,11 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'plugin()->traffic_thismonth()'=>array('label'=>'This Month'),
'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'date_next_invoice'=>array('label'=>'Next Invoice'),
'product->display("active")'=>array('label'=>'Current'),
),
array(
'type'=>'select',
@ -238,7 +239,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'plugin()->traffic_thismonth()'=>array('label'=>'This Month'),
'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'date_next_invoice'=>array('label'=>'Next Invoice'),
@ -264,7 +265,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'service_name()'=>array('label'=>'Details'),
'plugin()->display("domain_expire")'=>array('label'=>'Expire'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
@ -297,7 +298,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'service_name()'=>array('label'=>'Details'),
'plugin()->display("domain_expire")'=>array('label'=>'Expire'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
@ -324,7 +325,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'service_name()'=>array('label'=>'Details'),
'plugin()->display("host_expire")'=>array('label'=>'Expire'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
@ -350,7 +351,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
@ -533,7 +534,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'date_next_invoice'=>array('label'=>'Next Invoice'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'charges_new()'=>array('label'=>'Charges','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
@ -560,7 +561,7 @@ class Controller_Admin_Service extends Controller_TemplateDefault_Admin {
throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id()));
if (! $so->values($_POST)->update()->saved())
throw new Kohana_Exception('Failed to save updates to plugin data for record :record',array(':record'=>$so->id()));
throw new Kohana_Exception('Failed to save updates to service data for record :record',array(':record'=>$so->id()));
}
Block::add(array(

View File

@ -33,7 +33,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
@ -70,7 +70,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
@ -107,7 +107,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
@ -180,7 +180,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
'plugin()->traffic_thismonth()'=>array('label'=>'This Month'),
'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'date_next_invoice'=>array('label'=>'Next Invoice'),
@ -217,7 +217,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
'plugin()->traffic_thismonth()'=>array('label'=>'This Month'),
'plugin()->traffic_lastmonth()'=>array('label'=>'Last Month'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'date_next_invoice'=>array('label'=>'Next Invoice'),
@ -240,7 +240,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
'service_name()'=>array('label'=>'Details'),
'plugin()->display("domain_expire")'=>array('label'=>'Expire'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),
@ -264,7 +264,7 @@ class Controller_Affiliate_Service extends Controller_TemplateDefault_Affiliate
'service_name()'=>array('label'=>'Details'),
'plugin()->display("host_expire")'=>array('label'=>'Expire'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'account->accnum()'=>array('label'=>'Cust ID'),
'account->name()'=>array('label'=>'Customer'),
'display("date_next_invoice")'=>array('label'=>'Next Invoice'),

View File

@ -29,7 +29,7 @@ class Controller_User_Service extends Controller_TemplateDefault_User {
'id'=>array('label'=>'ID','url'=>'user/service/view/'),
'service_name()'=>array('label'=>'Details'),
'recur_schedule'=>array('label'=>'Billing'),
'price'=>array('label'=>'Price','class'=>'right'),
'price(TRUE,TRUE)'=>array('label'=>'Price','class'=>'right'),
'active'=>array('label'=>'Active'),
),
array(

View File

@ -44,10 +44,6 @@ class Model_Service extends ORMOSB {
'recur_schedule'=>array(
array('StaticList_RecurSchedule::display',array(':value')),
),
'price'=>array(
array('Tax::add',array(':value')),
array('Currency::display',array(':value')),
),
);
/**
@ -77,6 +73,21 @@ class Model_Service extends ORMOSB {
return is_null($plugin=$this->plugin()) ? $this->product->name() : $plugin->name();
}
/**
* Return the service charge
*/
public function price($tax=FALSE,$format=FALSE) {
$x = $this->product->keyget('price_group',$this->recur_schedule);
// @todo This index shouldnt be hard coded.
$p = $this->price ? $this->price : $x[$this->price_group]['price_base'];
if ($tax)
$p = Tax::add($p);
return $format ? Currency::display($p) : $p;
}
public function service_name() {
return is_null($plugin=$this->plugin()) ? $this->name() : $plugin->service_name();
}

View File

@ -12,5 +12,10 @@
*/
class Model_Service_Billing extends ORMOSB {
protected $_table_name = 'account_billing';
// Relationships
protected $_has_one = array(
'checkout'=>array('far_key'=>'checkout_plugin_id','foreign_key'=>'id'),
);
}
?>

View File

@ -38,10 +38,6 @@
<td>Type</td>
<td class="data"><?php echo StaticList_RecurType::display($so->recur_type); ?></td>
</tr>
<tr>
<td>Recur on Weekday</td>
<td class="data"><?php echo Form::input('recur_weekday',$so->recur_weekday,array('size'=>4)); ?></td>
</tr>
<tr>
<td>User Can Change Schedule</td>
<td class="data"><?php echo StaticList_YesNo::form('recur_schedule_change',$so->recur_schedule_change); ?></td>

View File

@ -5,8 +5,12 @@
<!-- Service Information -->
<table class="box-full">
<tr>
<td style="width: 40%;">Service Active</td>
<td style="width: 60%;" class="data"><?php echo $so->display('active'); ?></td>
<td style="width: 40%;">Account</td>
<td style="width: 60%;" class="data"><?php printf('%s (%s)',$so->account->name(),$so->account->accnum()); ?></td>
</tr>
<tr>
<td>Service Active</td>
<td class="data"><?php echo $so->display('active'); ?></td>
</tr>
<tr>
<td>Billing Period</td>
@ -14,8 +18,14 @@
</tr>
<tr>
<td>Cost</td>
<td class="data"><?php echo $so->display('price'); ?></td>
<td class="data"><?php echo $so->price(TRUE,TRUE); ?></td>
</tr>
<?php if (is_null($so->price) OR ($so->price<=$so->product->price($so->price_group,$so->recur_schedule,'price_base'))) { ?>
<tr>
<td>Service</td>
<td class="data"><?php echo HTML::anchor('product/view/'.$so->product_id,$so->product->name()); ?></td>
</tr>
<?php } ?>
<tr>
<td>Date Next Invoice</td>
<td class="data"><?php echo $so->display('date_next_invoice'); ?></td>
@ -24,6 +34,12 @@
<td>Current Invoices Due</td>
<td class="data"><?php echo Currency::display($so->account->invoices_due_total()); ?></td>
</tr>
<?php if ($so->service_billing->loaded()) { ?>
<tr>
<td>Direct Debit</td>
<td class="data"><?php echo $so->service_billing->checkout->name; ?></td>
</tr>
<?php } ?>
</table>
<!-- END Service Information -->
</td>