2013-11-26 13:45:07 +01:00
|
|
|
<?php
|
|
|
|
|
2013-12-04 17:20:14 +01:00
|
|
|
class Invoice extends EntityModel
|
2013-11-26 13:45:07 +01:00
|
|
|
{
|
2013-12-05 16:23:24 +01:00
|
|
|
protected $hidden = array('id', 'account_id', 'client_id', 'created_at', 'updated_at', 'deleted_at', 'viewed_date');
|
2013-12-03 18:32:33 +01:00
|
|
|
|
2013-12-01 21:58:25 +01:00
|
|
|
public function account()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Account');
|
|
|
|
}
|
2013-11-26 13:45:07 +01:00
|
|
|
|
|
|
|
public function client()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('Client');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function invoice_items()
|
|
|
|
{
|
|
|
|
return $this->hasMany('InvoiceItem');
|
|
|
|
}
|
|
|
|
|
2013-12-01 08:33:17 +01:00
|
|
|
public function invoice_status()
|
|
|
|
{
|
|
|
|
return $this->belongsTo('InvoiceStatus');
|
|
|
|
}
|
|
|
|
|
2013-12-01 21:58:25 +01:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->invoice_number;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEntityType()
|
|
|
|
{
|
|
|
|
return ENTITY_INVOICE;
|
|
|
|
}
|
|
|
|
|
2013-12-05 16:23:24 +01:00
|
|
|
/*
|
2013-11-26 13:45:07 +01:00
|
|
|
public function getTotal()
|
|
|
|
{
|
|
|
|
$total = 0;
|
|
|
|
|
|
|
|
foreach ($this->invoice_items as $invoiceItem)
|
|
|
|
{
|
|
|
|
$total += $invoiceItem->qty * $invoiceItem->cost;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $total;
|
|
|
|
}
|
2013-12-05 16:23:24 +01:00
|
|
|
*/
|
2013-11-26 22:45:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Invoice::created(function($invoice)
|
|
|
|
{
|
|
|
|
Activity::createInvoice($invoice);
|
|
|
|
});
|