Open Source Billing

This commit is contained in:
Deon George
2013-10-10 13:44:53 +11:00
commit b02d70adf0
2344 changed files with 392978 additions and 0 deletions

View File

@@ -0,0 +1,93 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders responses and forms based on the values from a module.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class StaticList_Module extends StaticList {
protected static $record = array();
/**
* Display a static name for a value
*/
public static function display($id) {
// Override our argument list as defined in parent
list($table,$key,$skey,$value) = func_get_args();
$db = DB::select($key)->from($table)->where($skey,'=',$value)->execute();
if ($db->count() !== 1)
return sprintf('No Value (%s)',$value);
else
return $db->get($key);
}
/**
* This function is to return the cached value of the current active record
* This is so that a follow up call to get an attribute of a value retrieved
* can reuse the active record values.
* This gets over a limitation where the query to form() to get a default
* no longer exists (or is invalid) and you want other attributes of the
* remaining active record, which may not be the default record.
*/
public static function record($table,$attribute,$skey,$value) {
if (empty(static::$record[$table]))
return static::display($table,$attribute,$skey,$value);
else
return static::$record[$table][$attribute];
}
/**
* Renders form input
*/
public static function form($name,$default='',$addblank=FALSE) {
// Override our argument list as defined in parent
list($name,$table,$default,$key,$value,$where,$addblank,$attributes) = func_get_args();
$db = DB::select()->from($table);
foreach ($where as $k=>$v) {
list ($op,$v) = explode(':',$v);
$db->where($k,$op,$v);
}
$db = $db->execute();
// If we only have one record, dont make a select list
if ($db->count() == 1) {
static::$record[$table] = $db->as_array();
static::$record[$table] = array_shift(static::$record[$table]);
return Form::hidden($name,$db->get($key)).$db->get($value);
}
// Else we return a select list
$x = array();
if ($addblank)
$x[] = '';
foreach ($db as $record) {
$x[$record[$key]] = $record[$value];
// Save our static record, in case we reference this item again.
if ($record[$key] == $default)
static::$record[$table] = $record;
}
return Form::select($name,$x,$default,$attributes);
}
protected function table($module=NULL) {
if (is_null($module))
throw new Kohana_Exception('Module is a required attribute.');
}
public static function factory() {
return new StaticList_Module;
}
}
?>

View File

@@ -0,0 +1,29 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders Price Type responses and forms.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class StaticList_PriceType extends StaticList {
protected function table() {
return array(
0=>_('One-time Charge'),
1=>_('Recurring Membership/Subscription'),
2=>_('Trial for Membership/Subscription')
);
}
public static function factory() {
return new StaticList_PriceType;
}
public static function display($value) {
return static::_display($value);
}
}
?>

View File

@@ -0,0 +1,55 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders Recurring Schedule Times on responses and forms.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class StaticList_RecurSchedule extends StaticList {
protected function table() {
return array(
0=>_('Weekly'),
1=>_('Monthly'),
2=>_('Quarterly'),
3=>_('Semi-Annually'),
4=>_('Annually'),
5=>_('Two years'),
6=>_('Three Years')
);
}
public static function factory() {
return new StaticList_RecurSchedule;
}
public static function display($value) {
return static::_display($value);
}
/**
* Renders the price display for a product
*
* @uses product
*/
public static function form($name,$product='',$default='',$addblank=FALSE) {
if (empty($product))
throw new Kohana_Exception('Product is a required field for :method',array(':method'=>__METHOD__));
$x = '';
$table = static::factory()->table();
foreach ($product->get_price_array() as $term => $price) {
$x[$term] = sprintf('%s %s',Currency::display(Tax::add($price['price_base'])),$table[$term]);
if ($price['price_setup'] > 0)
$x[$term] .= sprintf(' + %s %s',Currency::display(Tax::add($price['price_setup'])),_('Setup'));
}
return Form::select($name,$x,$default);
}
}
?>

View File

@@ -0,0 +1,28 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders Recurring Schedule Types on responses and forms.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class StaticList_RecurType extends StaticList {
protected function table() {
return array(
0=>_('Bill on Aniversary Date of Subscription'),
1=>_('Bill on Fixed Schedule'),
);
}
public static function factory() {
return new StaticList_RecurType;
}
public static function display($value) {
return static::_display($value);
}
}
?>

View File

@@ -0,0 +1,33 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders Charge Sweep Types on responses and forms.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class StaticList_SweepType extends StaticList {
protected function table() {
return array(
0=>_('Daily'),
1=>_('Weekly'),
2=>_('Monthly'),
3=>_('Quarterly'),
4=>_('Semi-Annually'),
5=>_('Annually'),
6=>_('Service Rebill'),
);
}
public static function factory() {
return new StaticList_SweepType;
}
public static function display($value) {
return static::_display($value);
}
}
?>

View File

@@ -0,0 +1,28 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders Person Title responses and forms.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class StaticList_Title extends StaticList {
protected function table() {
return array(
'mr'=>_('Mr'),
'ms'=>_('Ms'),
'mrs'=>_('Mrs'),
'miss'=>_('Miss'),
'dr'=>_('Dr'),
'prof'=>_('Prof')
);
}
public static function factory() {
return new StaticList_Title;
}
}
?>

View File

@@ -0,0 +1,28 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This is class renders Yes/No responses and forms.
*
* @package OSB
* @category Helpers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class StaticList_YesNo extends StaticList {
protected function table() {
return array(
0=>_('No'),
1=>_('Yes'),
);
}
public static function factory() {
return new StaticList_YesNo;
}
public static function display($value) {
return static::_display($value);
}
}
?>