2013-10-10 02:44:53 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides charge item capabilities.
|
|
|
|
*
|
|
|
|
* @package Charge
|
|
|
|
* @category Models
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
|
|
|
*/
|
2013-12-19 23:00:32 +00:00
|
|
|
class Model_Charge extends ORM_OSB implements Invoicable {
|
2013-09-06 05:39:56 +00:00
|
|
|
protected $_belongs_to = array(
|
|
|
|
'account'=>array(),
|
2013-12-31 06:18:49 +00:00
|
|
|
'product'=>array(),
|
2013-11-15 05:25:45 +00:00
|
|
|
'service'=>array(),
|
2013-09-06 05:39:56 +00:00
|
|
|
);
|
2013-06-04 11:50:41 +00:00
|
|
|
|
2015-09-29 01:54:45 +00:00
|
|
|
protected $_compress_column = array(
|
|
|
|
'attributes',
|
|
|
|
);
|
|
|
|
|
2013-09-06 05:39:56 +00:00
|
|
|
protected $_nullifempty = array(
|
2013-10-10 02:44:53 +00:00
|
|
|
'attributes',
|
|
|
|
);
|
|
|
|
|
2013-09-06 05:39:56 +00:00
|
|
|
protected $_serialize_column = array(
|
|
|
|
'attributes',
|
2013-10-10 02:44:53 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
protected $_display_filters = array(
|
2013-10-09 05:43:41 +00:00
|
|
|
'amount'=>array(
|
|
|
|
array('Currency::display',array(':value')),
|
|
|
|
),
|
2013-10-10 02:44:53 +00:00
|
|
|
'date_orig'=>array(
|
2014-08-25 04:41:07 +00:00
|
|
|
array('Site::Date',array(':value')),
|
2013-10-10 02:44:53 +00:00
|
|
|
),
|
2013-09-06 05:39:56 +00:00
|
|
|
'date_charge'=>array(
|
2014-08-25 04:41:07 +00:00
|
|
|
array('Site::Date',array(':value')),
|
2013-09-06 05:39:56 +00:00
|
|
|
),
|
2013-10-09 05:43:41 +00:00
|
|
|
'processed'=>array(
|
2013-11-08 11:02:32 +00:00
|
|
|
array('StaticList_YesNo::get',array(':value',TRUE)),
|
2013-10-09 05:43:41 +00:00
|
|
|
),
|
|
|
|
'sweep_type'=>array(
|
|
|
|
array('StaticList_SweepType::get',array(':value')),
|
|
|
|
),
|
|
|
|
'void'=>array(
|
2013-11-14 11:50:35 +00:00
|
|
|
array('StaticList_YesNo::get',array(':value',TRUE)),
|
2013-10-10 02:44:53 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2013-11-15 05:25:45 +00:00
|
|
|
/**
|
|
|
|
* Temporarily override our parent call to reformat old data
|
|
|
|
*/
|
|
|
|
public function __get($column) {
|
|
|
|
switch ($column) {
|
|
|
|
case 'attributes':
|
|
|
|
$x = parent::__get($column);
|
|
|
|
|
|
|
|
if (is_string($this->_object[$column]) AND preg_match('/==/',$this->_object[$column])) {
|
|
|
|
$x = explode("\n",$this->_object[$column]);
|
|
|
|
|
|
|
|
foreach ($x as $k=>$v) {
|
|
|
|
if (preg_match('/==/',$x[$k]))
|
|
|
|
$x[$k] = preg_replace('/==\s*/',':',$v);
|
|
|
|
|
|
|
|
if (preg_replace('/^ADSL Service:/',"",$x[$k]) == $this->service->plugin()->service_number)
|
|
|
|
unset($x[$k]);
|
|
|
|
}
|
|
|
|
|
|
|
|
sort($x);
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->{$column} = $x;
|
|
|
|
|
|
|
|
return $x;
|
|
|
|
|
|
|
|
default: return parent::__get($column);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-03 04:00:51 +00:00
|
|
|
/** REQUIRED ABSTRACT METHODS **/
|
|
|
|
public function namesub($variable=NULL) {
|
|
|
|
return sprintf('%d@%2.2f - %s (%s)',$this->quantity,$this->amount,($this->description ? ' '.$this->description : '').($this->attributes ? ' ['.join('|',$this->attributes).']' : ''),$this->display('date_charge'));
|
|
|
|
}
|
|
|
|
|
|
|
|
/** LOCAL METHODS **/
|
|
|
|
|
2016-07-29 13:04:34 +00:00
|
|
|
/**
|
|
|
|
* Return the Invoice Item object for this charge
|
|
|
|
*/
|
|
|
|
public function iio() {
|
|
|
|
$iio = ORM::factory('Invoice_Item');
|
|
|
|
if ($this->processed) {
|
|
|
|
$iio->where('module_id','=',$this->mid())
|
|
|
|
->where('module_ref','=',$this->id)
|
|
|
|
->find();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $iio;
|
|
|
|
}
|
|
|
|
|
2013-12-19 23:00:32 +00:00
|
|
|
public function invoice_item($item_type) {
|
2014-01-08 04:48:42 +00:00
|
|
|
switch ($item_type) {
|
|
|
|
case 5:
|
|
|
|
return sprintf('%s (%s x %s%s%s) %s',
|
|
|
|
StaticList_ItemType::get($item_type),
|
|
|
|
$this->quantity,
|
|
|
|
$this->display('amount'),
|
|
|
|
($this->description ? ' '.$this->description : ''),
|
|
|
|
($this->attributes ? ' ['.join('|',$this->attributes).']' : ''),
|
|
|
|
$this->display('date_charge'));
|
|
|
|
|
|
|
|
default:
|
|
|
|
return sprintf('%s %s',StaticList_ItemType::get($item_type),$this->display('date_charge')).($this->description ? ' ('.$this->description.')' : '');
|
|
|
|
}
|
2013-12-19 23:00:32 +00:00
|
|
|
}
|
|
|
|
|
2016-07-29 01:19:30 +00:00
|
|
|
public function xtitle() {
|
|
|
|
return $this->invoice_item(5);
|
|
|
|
}
|
|
|
|
|
2013-06-04 11:50:41 +00:00
|
|
|
public function total($format=FALSE) {
|
|
|
|
$result = $this->quantity * $this->amount;
|
|
|
|
|
|
|
|
if ($this->taxable)
|
|
|
|
$result = Tax::add($result);
|
|
|
|
|
|
|
|
return $format ? Currency::display($result) : $result;
|
|
|
|
}
|
2013-10-10 02:44:53 +00:00
|
|
|
}
|
|
|
|
?>
|