This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/service/classes/model/service.php

102 lines
2.1 KiB
PHP
Raw Normal View History

2010-11-29 22:41:08 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports Services
*
* @package OSB
* @subpackage Service
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Service extends ORMOSB {
// Relationships
protected $_has_many = array(
'invoice'=>array('through'=>'invoice_item'),
'adsl_plan'=>array('through'=>'service__adsl'),
);
protected $_has_one = array(
'service_adsl'=>array(),
);
protected $_belongs_to = array(
'product'=>array(),
'account'=>array(),
);
protected $_formats = array(
'active'=>array('StaticList_YesNo::display'=>array()),
'date_next_invoice'=>array('Config::date'=>array()),
'recur_schedule'=>array('StaticList_RecurSchedule::display'=>array()),
'price'=>array(
'Tax::add'=>array(),
'Currency::display'=>array(),
),
);
/**
* Display the service number
*/
public function svcnum() {
return sprintf('%05s',$this->id);
}
// Nothing to directly display on invoices for this module.
public function invoice_display() {
if ($this->sku)
return sprintf('%s: %s',_('Service'),$this->sku);
else
return '';
}
public function name() {
return $this->product->product_translate->find()->name;
}
/**
* Find invoices associated with this service
*/
public function invoices() {
$return = array();
foreach ($this->invoice->distinct('id')->find_all() as $invoice) {
$return[$invoice->id]['due'] = $invoice->due();
}
return $return;
}
/**
* Find invoices currently outstanding associated with this service
*/
public function invoices_due() {
$return = array();
foreach ($this->invoices() as $id => $invoice)
if ($invoice['due'])
array_push($return,$invoice);
return $return;
}
/**
* Calculate the total of invoices due for this service
*/
public function invoices_due_total() {
$total = 0;
foreach ($this->invoices_due() as $invoice)
$total += $invoice['due'];
return $total;
}
// @todo To implement
/**
* Calculate the tax for this item
*/
public function tax() {
return $this->price * .1;
}
}
?>