Revamping invoice PDF rendering and standardisation work

This commit is contained in:
Deon George
2016-08-10 16:07:00 +10:00
parent a560c5f4fa
commit 24bb4a701b
27 changed files with 229 additions and 475 deletions

View File

@@ -53,6 +53,7 @@ class Model_Invoice extends ORM_OSB implements Cartable {
private $_render = array();
/** REQUIRED ABSTRACT METHODS **/
/**
* Display the Invoice Reference Number
*/
@@ -116,29 +117,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
->where('module_data','=',$this);
}
/**
* Display the Invoice Number
*/
public function id() {
return sprintf('%06s',$this->id);
}
/**
* Return the recurring schedules that are on an invoice
*
* @param $period Return an Array of items for that period
*/
public function items_periods($period=FALSE) {
if (is_null($period))
return isset($this->_render['OTHER']) ? $this->_render['OTHER'] : array();
elseif ($period)
return isset($this->_render['SCHED'][$period]) ? $this->_render['SCHED'][$period] : array();
else
return array_keys($this->_render['SCHED']);
}
/**
* Return an array of items to render, in appropriate order
*/
@@ -184,10 +162,19 @@ class Model_Invoice extends ORM_OSB implements Cartable {
}
}
// Get service items that dont have a recurring schedule
foreach ($this->_sub_items as $iio)
if (! $iio->void AND ! in_array($iio->id,$track) AND $iio->service_id) {
// Ensure we dont process this item again
array_push($track,$iio->id);
array_push($result['s'],$iio);
}
// Next get the items we havent already got
$result['other'] = array();
foreach ($this->_sub_items as $iio)
if (! in_array($iio->id,$track))
if (! $iio->void AND ! in_array($iio->id,$track))
array_push($result['other'],$iio);
// Debug
@@ -226,29 +213,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
return $result;
}
/**
* Return the item titles that are on an invoice
*
* @param $title Return an Array of items for that title
*/
public function items_titles($title=NULL,$period=NULL) {
$result = array();
foreach ($this->subitems() as $ito) {
if ($ito->service_id) {
if (is_null($title) AND ! in_array($ito->title(),$result) AND (is_null($period) OR ($period == $ito->recurring_schedule)))
array_push($result,$ito->title());
elseif (($ito->title() == $title AND (is_null($period) OR ($period == $ito->recurring_schedule))) OR is_null($ito->recurring_schedule))
array_push($result,$ito);
} else {
throw HTTP_Exception::factory(501,'Not handled non-services');
}
}
return $result;
}
public function payments() {
return $this->payment_item->find_all();
}
@@ -262,37 +226,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
return $format ? Currency::display($result) : $result;
}
/**
* This function takes care of all the invoice items so that they are rendered only once
*
* We organise items by
* + recurring_schedule for service items item_type=0
* + recurring_schedule for service items for item_type!=0 (that have an item_type=0 previously selected)
* + Other Items
*/
public function pre_render() {
$this->_render = array();
$this->_render['SCHED'] = array();
$processed = array();
foreach ($this->subitems() as $iio) {
if ($iio->id AND in_array($iio->id,$processed))
continue;
if ($iio->recurring_schedule) {
$this->_render['SCHED'][$iio->recurring_schedule][] = $iio;
} elseif (Object::in_array('service_id',$iio->service_id,$this->_render['SCHED'],TRUE)) {
// Do nothing
} else {
$this->_render['OTHER'][] = $iio;
}
array_push($processed,$iio->id);
}
}
/**
* For a particular recurring schedule, get al lthe services
*/
@@ -418,72 +351,6 @@ class Model_Invoice extends ORM_OSB implements Cartable {
return $this;
}
/**
* Return the service items on an invoice relating to an invoice_item
* IE: item_type == 0
*/
public function service_items(Model_Invoice_Item $o) {
$result = array();
// At the moment, we only return items pertaining to a service
if (! $o->service_id)
return $result;
foreach ($this->subitems() as $iio)
if ($iio->item_type == 0 AND $iio->service_id == $o->service_id)
array_push($result,$iio);
return $result;
}
/**
* Return the extra items on an invoice relating to an invoice_item
* IE: item_type != 0
*/
public function service_items_extra(Model_Invoice_Item $o) {
$result = array();
foreach ($this->subitems() as $iio)
if ($iio->item_type != 0 AND (! $o->service_id OR ($iio->service_id == $o->service_id)))
array_push($result,$iio);
return $result;
}
/**
* Return the total of all items relating to a service
*/
public function service_items_tax(Model_Invoice_Item $o,$format=FALSE) {
$result = 0;
// At the moment, we only return extra items pertaining to a service
if (! $o->service_id)
return $result;
foreach ($this->subitems() as $iio)
if ($iio->service_id == $o->service_id)
$result += $iio->tax();
return $format ? Currency::display($result) : $result;
}
/**
* Return the total of all items relating to a service
*/
public function service_items_total(Model_Invoice_Item $o,$format=FALSE) {
$result = 0;
// At the moment, we only return extra items pertaining to a service
if (! $o->service_id)
return $result;
foreach ($this->subitems() as $iio)
if ($iio->service_id == $o->service_id)
$result += $iio->total();
return $format ? Currency::display($result) : $result;
}
/**
* For a particular service, get all the products
*/