Removed redundant functions, some Standardisation work
This commit is contained in:
@@ -17,11 +17,11 @@ class Controller_Task_Invoice extends Controller_Task {
|
||||
|
||||
foreach (ORM::factory('Invoice_Item')->find_all() as $iio) {
|
||||
if ($iio->product_name AND $iio->product_id) {
|
||||
if (md5(strtoupper($iio->product_name)) == md5(strtoupper($iio->product->title()))) {
|
||||
if (md5(strtoupper($iio->product_name)) == md5(strtoupper($iio->product->name(Site::language())))) {
|
||||
$iio->product_name = NULL;
|
||||
$iio->save();
|
||||
} else {
|
||||
print_r(array("DIFF",'id'=>$iio->id,'pn'=>serialize($iio->product_name),'ppn'=>serialize($iio->product->title()),'pid'=>$iio->product_id,'test'=>strcasecmp($iio->product_name,$iio->product->title())));
|
||||
print_r(array("DIFF",'id'=>$iio->id,'pn'=>serialize($iio->product_name),'ppn'=>serialize($iio->product->name(Site::language())),'pid'=>$iio->product_id,'test'=>strcasecmp($iio->product_name,$iio->product->name(Site::language()))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,16 +0,0 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This interface ensures that all items have the required invoice methods
|
||||
*
|
||||
* @package Invoice
|
||||
* @category Interface
|
||||
* @author Deon George
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
interface Invoicable {
|
||||
// Render an invoice line item.
|
||||
public function invoice_item($item_type);
|
||||
}
|
||||
?>
|
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
class Model_Invoice extends ORM implements Cartable {
|
||||
protected $_belongs_to = array(
|
||||
'account'=>array()
|
||||
);
|
||||
@@ -54,14 +54,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
|
||||
/** REQUIRED ABSTRACT METHODS **/
|
||||
|
||||
/**
|
||||
* Display the Invoice Reference Number
|
||||
*/
|
||||
public function refnum($short=FALSE) {
|
||||
return ($short ? '' : $this->account->refnum(FALSE).'-').sprintf('%06s',$this->id);
|
||||
}
|
||||
|
||||
|
||||
/** REQUIRED INTERFACE METHODS **/
|
||||
|
||||
public function cart_item() {
|
||||
@@ -127,7 +119,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
$c = 0;
|
||||
if (! $this->_loaded)
|
||||
foreach ($this->_sub_items as $iio)
|
||||
$iio->id = 'FAKE:'.$c++;
|
||||
$iio->id = '****:'.$c++;
|
||||
|
||||
// First work through our recurring schedule items
|
||||
$result['s'] = array();
|
||||
@@ -191,14 +183,15 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
*/
|
||||
public function items_summary() {
|
||||
$result = array();
|
||||
$lo = $this->account->language;
|
||||
|
||||
foreach ($this->subitems() as $iio) {
|
||||
// We only summarise item_type=0
|
||||
if (! $iio->item_type == 0)
|
||||
continue;
|
||||
|
||||
if ($iio->module() instanceof Model_Product) {
|
||||
$p = $iio->module()->title();
|
||||
if ($iio->product) {
|
||||
$p = $iio->product->name($lo);
|
||||
|
||||
if (! isset($result[$p])) {
|
||||
$result[$p]['quantity'] = 0;
|
||||
@@ -258,6 +251,13 @@ class Model_Invoice extends ORM_OSB implements Cartable {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Invoice Reference Number
|
||||
*/
|
||||
public function refnum($short=FALSE) {
|
||||
return ($short ? '' : $this->account->refnum(FALSE).'-').sprintf('%06s',$this->id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the reminder value
|
||||
*/
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Invoice_Item extends ORM_OSB {
|
||||
class Model_Invoice_Item extends ORM {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'invoice'=>array(),
|
||||
@@ -66,51 +66,6 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
|
||||
/** REQUIRED ABSTRACT METHODS **/
|
||||
|
||||
public function name($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return sprintf('%s: %s',$this->product->name($variable),$this->service->namesub($variable));
|
||||
case 124:
|
||||
return StaticList_ItemType::get($this->item_type);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function namesub($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->period());
|
||||
case 2:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->_module() ? $this->_module()->display('date_charge') : $this->period());
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),($this->_module()->attributes ? $this->_module()->namesub($variable) : $this->_module()->display('date_charge')));
|
||||
case 5:
|
||||
return $this->_module()->namesub($variable);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Invoice Item Reference Number
|
||||
*/
|
||||
public function refnum($short=FALSE) {
|
||||
return $short ? '' : sprintf('%03s-',$this->item_type).sprintf('%06s',$this->id);
|
||||
}
|
||||
|
||||
/** LOCAL METHODS **/
|
||||
|
||||
/**
|
||||
@@ -185,6 +140,7 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
break;
|
||||
case 3:
|
||||
case 4:
|
||||
case 7:
|
||||
if (! $this->service_id OR ! $this->product_id OR ! $this->module_id OR ! $this->module_ref OR $this->product_name OR ! is_null($this->recurring_schedule))
|
||||
return FALSE;
|
||||
break;
|
||||
@@ -210,11 +166,57 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
return $this->_module();
|
||||
}
|
||||
|
||||
public function name($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
return sprintf('%s: %s',$this->product->name($variable),$this->service->namesub($variable));
|
||||
case 124:
|
||||
return StaticList_ItemType::get($this->item_type);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function namesub($variable=NULL) {
|
||||
if (! $this->isValid())
|
||||
return sprintf('Record Error [%s-%s]',$this->item_type,$this->id);
|
||||
|
||||
switch ($this->item_type) {
|
||||
case 0:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->period());
|
||||
case 2:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),$this->_module() ? $this->_module()->display('date_charge') : $this->period());
|
||||
case 3:
|
||||
case 4:
|
||||
case 6:
|
||||
return sprintf('%s: %s',StaticList_ItemType::get($this->item_type),($this->_module()->attributes ? $this->_module()->namesub($variable) : $this->_module()->display('date_charge')));
|
||||
case 5:
|
||||
case 7:
|
||||
return $this->_module()->namesub($variable);
|
||||
default:
|
||||
return sprintf('Unknown [%s-%s]',$this->item_type,$this->id);
|
||||
}
|
||||
}
|
||||
|
||||
// Display the period that a transaction applies
|
||||
public function period() {
|
||||
return ($this->date_start == $this->date_stop) ? Site::Date($this->date_start) : sprintf('%s -> %s',Site::Date($this->date_start),Site::Date($this->date_stop));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the Invoice Item Reference Number
|
||||
*/
|
||||
public function refnum($short=FALSE) {
|
||||
return $short ? '' : sprintf('%03s-',$this->item_type).sprintf('%06s',$this->id);
|
||||
}
|
||||
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Our items will be clobbered once we save the object, so we need to save it here.
|
||||
$subitems = $this->subitems();
|
||||
@@ -276,20 +278,6 @@ class Model_Invoice_Item extends ORM_OSB {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* The title for invoice items
|
||||
*/
|
||||
public function title() {
|
||||
if ($this->service_id AND $this->module_id AND method_exists($this->module(),'invoice_title'))
|
||||
return $this->service->name(); #$this->module_ref ? sprintf('%s: %s',$this->module()->invoice_title(),$this->service->name()) : $this->service->name();
|
||||
elseif ($x=$this->module() AND ($x instanceof Model_Charge) AND $x->product_id)
|
||||
return $x->product->title().' '.$this->service->name();
|
||||
elseif ($this->product_id)
|
||||
return sprintf('* %s: %s',$this->product->invoice_title(),$this->service->name());
|
||||
else
|
||||
return 'Unknown Item';
|
||||
}
|
||||
|
||||
public function total($format=FALSE) {
|
||||
$result = $this->void ? 0 : $this->subtotal()+$this->tax()-$this->discount();
|
||||
|
||||
|
@@ -9,7 +9,7 @@
|
||||
* @copyright (c) 2009-2013 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Invoice_Memo extends ORM_OSB {
|
||||
class Model_Invoice_Memo extends ORM {
|
||||
// Relationships
|
||||
protected $_belongs_to = array(
|
||||
'invoice'=>array(),
|
||||
|
Reference in New Issue
Block a user