Minor fixes to statement, services and internal things
Many misc updates
This commit is contained in:
@@ -148,7 +148,7 @@ class Model_Invoice extends ORMOSB {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of services on an invoice
|
||||
* Get a list of invoice_items for a service_id on an invoice
|
||||
*
|
||||
* We use this to list details by service on an invoice.
|
||||
*/
|
||||
@@ -158,15 +158,15 @@ class Model_Invoice extends ORMOSB {
|
||||
$items = $this->items();
|
||||
|
||||
foreach ($items as $ito)
|
||||
if ($ito->service_id AND empty($result[$ito->service_id]))
|
||||
$result[$ito->service_id] = $ito->service;
|
||||
if ($ito->service_id AND empty($result[$ito->service_id]))
|
||||
$result[$ito->service_id] = $ito;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all invoice items for a service optionally by recurring schedule
|
||||
*/
|
||||
*/
|
||||
public function items_service($sid,$rs=NULL) {
|
||||
$result = array();
|
||||
$items = $this->items();
|
||||
@@ -211,11 +211,11 @@ class Model_Invoice extends ORMOSB {
|
||||
$result = array();
|
||||
|
||||
foreach ($this->items() as $ito) {
|
||||
// We conly summaries item_type=0
|
||||
// We only summarise item_type=0
|
||||
if (! $ito->item_type == 0)
|
||||
continue;
|
||||
|
||||
$t = $ito->product_id;
|
||||
$t = $ito->product->name();
|
||||
|
||||
if (! isset($result[$t])) {
|
||||
$result[$t]['quantity'] = 0;
|
||||
@@ -303,14 +303,17 @@ class Model_Invoice extends ORMOSB {
|
||||
}
|
||||
|
||||
public function min_due($date) {
|
||||
// @todo This should be configurable;
|
||||
return ($date < time()) ? time() : $date;
|
||||
return ($date < time()) ? time()+Kohana::config('config.invoice.min_due_days')*86400 : $date;
|
||||
}
|
||||
|
||||
public function save(Validation $validation = NULL) {
|
||||
// Our items will be clobbered once we save the object, so we need to save it here.
|
||||
$items = $this->items();
|
||||
|
||||
// @todo This is added here so we can do payments
|
||||
$this->total_amt = $this->total();
|
||||
$this->billed_amt = 0;
|
||||
|
||||
// Save the invoice
|
||||
parent::save($validation);
|
||||
|
||||
@@ -331,12 +334,14 @@ class Model_Invoice extends ORMOSB {
|
||||
throw new Kohana_Exception('Problem saving invoice_item for invoice :invoice - Failed save()',array(':invoice'=>$invoice->id));
|
||||
}
|
||||
|
||||
// @todo Need to save tax information
|
||||
// @todo Need to save discount information
|
||||
}
|
||||
|
||||
|
||||
} else
|
||||
throw new Kohana_Exception('Couldnt save invoice for some reason?');
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -387,13 +392,29 @@ class Model_Invoice extends ORMOSB {
|
||||
return $this->saved();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of affiliates associated with this invoice (via the service)
|
||||
*/
|
||||
public function service_affiliates() {
|
||||
$return = array();
|
||||
|
||||
foreach ($this->items() as $io)
|
||||
array_push($return,$io->service->affiliate_id);
|
||||
|
||||
return $return;
|
||||
}
|
||||
|
||||
/** LIST FUNCTIONS **/
|
||||
|
||||
private function _list_active() {
|
||||
return ORM::factory('invoice')->where('status','=',1);
|
||||
}
|
||||
|
||||
private function _list_due() {
|
||||
static $result = array();
|
||||
|
||||
if (! $result)
|
||||
foreach (ORM::factory('invoice')->where('status','=',1)->find_all() as $io)
|
||||
foreach ($this->_list_active()->find_all() as $io)
|
||||
if ($io->due())
|
||||
array_push($result,$io);
|
||||
|
||||
@@ -445,12 +466,20 @@ class Model_Invoice extends ORMOSB {
|
||||
if ($io->due_date > time())
|
||||
if (is_null($time))
|
||||
array_push($result,$io);
|
||||
elseif ($this->due_date <= $time)
|
||||
elseif ($io->due_date <= $time)
|
||||
array_push($result,$io);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a list of invoices that need to be sent.
|
||||
* @todo This should be optimised a little to return only invoices to send, instead of looking for them.
|
||||
*/
|
||||
public function list_tosend() {
|
||||
return ORM::factory('invoice')->where('status','=',1)->where_open()->where('print_status','is',NULL)->or_where('print_status','!=',1)->where_close();
|
||||
}
|
||||
|
||||
public function html() {
|
||||
// @todo This should be in a config file.
|
||||
$css = '<style type="text/css">';
|
||||
|
Reference in New Issue
Block a user