Improvements to taxing

This commit is contained in:
Deon George
2013-12-05 16:22:23 +11:00
parent 8ba487a4a6
commit 778eada7f0
13 changed files with 253 additions and 212 deletions

View File

@@ -11,28 +11,30 @@
*/
class Invoice {
// This invoice Object
private $io;
private $_io;
private $_methods = array(
'dump',
'min_due',
'save',
'saved',
'total',
);
// 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);
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;
$this->_io = is_null($io) ? ORM::factory('Invoice') : $io;
// Set our invoice as valid
if (is_null($io))
$this->io->status = 1;
$this->_io->status = 1;
}
public static function instance(Model_Invoice $io=NULL) {
@@ -45,18 +47,18 @@ 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->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;
if (! $this->_io->account_id)
$this->_io->account_id = $so->account_id;
else if ($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);
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);
@@ -72,7 +74,7 @@ class Invoice {
// Service Billing
$iio->item_type = 0;
$this->io->add_item($iio);
$this->_io->subitem_add($iio,$this->_io->account->country);
// Check if there are any charges
$c = ORM::factory('Charge')
@@ -91,7 +93,7 @@ class Invoice {
$iio->date_stop = $co->date_orig;
$iio->item_type = $co->type;
$this->io->add_item($iio);
$this->_io->subitem_add($iio,$this->_io->account->country);
}
return $this;
@@ -104,7 +106,7 @@ class Invoice {
case 'body':
return View::factory('invoice/user/view/body')
->set('show_id',(isset($args['noid']) AND $args['noid']) ? FALSE : TRUE)
->set('o',$this->io);
->set('o',$this->_io);
break;
default:
@@ -124,7 +126,7 @@ class Invoice {
public function pdf() {
$invoice_class = Kohana::classname('Invoice_TCPDF_'.Kohana::$config->load('invoice')->driver);
$pdf = new $invoice_class($this->io);
$pdf = new $invoice_class($this->_io);
if ($pdf->getTemplate()) {
$pagecount = $pdf->setSourceFile($pdf->getTemplate());
@@ -153,12 +155,12 @@ class Invoice {
$pdf->drawRemittenceStub();
$pdf->drawPaymentMethods();
if ($this->io->billing_status !=1 && $this->io->due_date <= time())
if ($this->_io->billing_status !=1 && $this->_io->due_date <= time())
$pdf->drawInvoiceDueNotice();
elseif($this->io->billing_status == 1)
elseif($this->_io->billing_status == 1)
$pdf->drawInvoicePaidNotice();
if ($this->io->account->invoices_due_total())
if ($this->_io->account->invoices_due_total())
$pdf->drawSummaryInvoicesDue();
$pdf->drawSummaryLineItems();