Next/Future invoices for users

This commit is contained in:
Deon George
2020-02-08 22:51:50 +11:00
parent b61e00d80f
commit eb316f65fc
18 changed files with 277 additions and 96 deletions

View File

@@ -2,8 +2,10 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Leenooks\Carbon;
class InvoiceItem extends Model
@@ -11,7 +13,6 @@ class InvoiceItem extends Model
protected $dates = ['date_start','date_stop'];
public $dateFormat = 'U';
protected $table = 'ab_invoice_item';
protected $with = ['taxes'];
private $_tax = 0;
@@ -20,6 +21,11 @@ class InvoiceItem extends Model
return $this->belongsTo(Invoice::class);
}
/**
* Product for this item
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function product()
{
return $this->belongsTo(Product::class);
@@ -131,13 +137,13 @@ class InvoiceItem extends Model
/**
* Add taxes to this record
*/
public function addTaxes()
public function addTaxes(Collection $taxes)
{
// Refuse to change an existing record
if ($this->exists)
throw new \Exception('Refusing to add Taxes to existing record');
foreach($this->service->account->country->taxes as $to)
foreach($taxes as $to)
{
$iit = new InvoiceItemTax;
$iit->tax_id = $to->id;