Updated charge, Invoice improvements and other minor fixes
This commit is contained in:
@@ -13,8 +13,26 @@ class Invoice {
|
||||
// This invoice Object
|
||||
private $io;
|
||||
|
||||
private $_methods = array(
|
||||
'min_due',
|
||||
'save',
|
||||
'saved',
|
||||
);
|
||||
|
||||
// Enable passing calls to ORM::Invoice()
|
||||
public function __call($method,array $args) {
|
||||
if (in_array($method,$this->_methods))
|
||||
return call_user_func_array(array($this->io,$method),$args);
|
||||
else
|
||||
throw HTTP_Exception::factory(501,'Unknown/unauthorised method :method',array(':method'=>$method));
|
||||
}
|
||||
|
||||
public function __construct(Model_Invoice $io=NULL) {
|
||||
$this->io = is_null($io) ? ORM::factory('Invoice') : $io;
|
||||
|
||||
// Set our invoice as valid
|
||||
if (is_null($io))
|
||||
$this->io->status = 1;
|
||||
}
|
||||
|
||||
public static function instance(Model_Invoice $io=NULL) {
|
||||
@@ -27,6 +45,19 @@ class Invoice {
|
||||
* @param $so Model_Servie
|
||||
*/
|
||||
public function add_service(Model_Service $so) {
|
||||
if ($this->io->loaded())
|
||||
throw HTTP_Exception::factory(501,'Cannot use add service :service to an existing invoice :invoice ',array(':service'=>$so->id,':invoice'=>$this->io->id));
|
||||
|
||||
if (! $this->io->account_id)
|
||||
$this->io->account_id = $so->account_id;
|
||||
|
||||
else if ($this->io->account_id != $so->account_id)
|
||||
throw HTTP_Exception::factory(501,'Cannot add service :service to invoice - it is for a different account',array(':service'=>$so->id));
|
||||
|
||||
// Set the invoice due date
|
||||
if (! $this->io->due_date OR $this->io->due_date > $this->io->min_due($so->date_next_invoice))
|
||||
$this->io->due_date = $this->io->min_due($so->date_next_invoice);
|
||||
|
||||
$pdata = Period::details($so->recur_schedule,$so->product->price_recurr_day,$so->invoiced_to()+86400,FALSE,$so->product->price_recurr_strict);
|
||||
|
||||
$iio = ORM::factory('Invoice_Item');
|
||||
@@ -39,13 +70,14 @@ class Invoice {
|
||||
$iio->date_stop = $pdata['end_time'];
|
||||
|
||||
// Service Billing
|
||||
$iio->item_type = StaticList_ItemType::index('MAIN');
|
||||
$iio->item_type = 0;
|
||||
|
||||
$this->io->add_item($iio);
|
||||
|
||||
// Check if there are any charges
|
||||
$c = ORM::factory('Charge')
|
||||
->where('service_id','=',$so->id)
|
||||
->where('void','is',NULL)
|
||||
->where('processed','is',NULL);
|
||||
|
||||
foreach ($c->find_all() as $co) {
|
||||
@@ -57,9 +89,7 @@ class Invoice {
|
||||
$iio->price_base = $co->amount;
|
||||
$iio->date_start = $co->date_orig;
|
||||
$iio->date_stop = $co->date_orig;
|
||||
|
||||
// @todo This should be $co->item_type;
|
||||
$iio->item_type = StaticList_ItemType::index('EXCESS');
|
||||
$iio->item_type = $co->type;
|
||||
|
||||
$this->io->add_item($iio);
|
||||
}
|
||||
@@ -67,12 +97,13 @@ class Invoice {
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render($type,$section) {
|
||||
public function render($type,$section,$args=array()) {
|
||||
switch ($type) {
|
||||
case 'html':
|
||||
switch ($section) {
|
||||
case 'body':
|
||||
return View::factory('invoice/user/view/body')
|
||||
->set('show_id',(isset($args['noid']) AND $args['noid']) ? FALSE : TRUE)
|
||||
->set('o',$this->io);
|
||||
break;
|
||||
|
||||
|
Reference in New Issue
Block a user