Updated charge, Invoice improvements and other minor fixes

This commit is contained in:
Deon George
2013-09-06 15:39:56 +10:00
parent 2322a802de
commit ab3735914b
52 changed files with 748 additions and 560 deletions

View File

@@ -46,6 +46,8 @@ class Model_Service extends ORM_OSB {
),
);
protected $_form = array('id'=>'id','value'=>'service_name()');
/**
* Get the additional charges associated with this service
*/
@@ -63,11 +65,11 @@ class Model_Service extends ORM_OSB {
if ($unprocessed)
$x->where_open()
->where('processed','IS',NULL)
->or_where('processed','=',FALSE)
->where_close();
->where('processed','IS',NULL)
->or_where('processed','=',FALSE)
->where_close();
return $x->find_all();
return $x->and_where('void','IS',NULL)->find_all();
}
/**
@@ -132,9 +134,24 @@ class Model_Service extends ORM_OSB {
* Show the date we are invoiced to
*/
public function invoiced_to($format=FALSE) {
$x = $this->invoice_item->order_by('date_stop','DESC')->limit(1)->find();
$iio = $this->last_invoice_item()
->limit(1);
return $format ? $x->display('date_stop') : $x->date_stop;
$iio->find();
$x = (! $iio->loaded() AND $this->date_next_invoice) ? $this->date_next_invoice-86400 : $iio->date_stop;
return $format ? Config::date($x) : $x;
}
private function last_invoice_item() {
return ORM::factory('Invoice_Item')->join('invoice')
->on('invoice.id','=','invoice_item.invoice_id')
->on('invoice.status','=',1)
->on('invoice_item.service_id','=',$this)
->on('invoice_item.item_type','=',0)
->on('invoice_item.void','is','null')
->order_by('date_stop','DESC');
}
/**
@@ -150,7 +167,7 @@ class Model_Service extends ORM_OSB {
public function paid_to($format=FALSE) {
$x = NULL;
foreach ($this->invoice_item->order_by('date_stop','DESC')->order_by('date_orig','DESC')->find_all() as $iio)
foreach ($this->last_invoice_item()->order_by('date_orig','DESC')->find_all() as $iio)
if ($iio->invoice->due() == 0) {
$x = $iio;
break;
@@ -203,7 +220,7 @@ class Model_Service extends ORM_OSB {
$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'];
$p = ! is_null($this->price) ? $this->price : $x[$this->price_group]['price_base'];
if ($tax)
$p = Tax::add($p);
@@ -250,7 +267,7 @@ class Model_Service extends ORM_OSB {
*/
public function list_autocomplete($term,$index,$value,array $label,array $limit=array(),array $options=NULL) {
// We only show service numbers.
if (! is_numeric($term))
if (! is_numeric($term) AND (! $limit))
return array();
$ao = Auth::instance()->get_user();