Add account next invoice

This commit is contained in:
2024-07-31 22:36:28 +10:00
parent 0b5bc9e012
commit f43748e20a
9 changed files with 109 additions and 96 deletions

View File

@@ -5,8 +5,6 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Collection;
use Illuminate\Database\Eloquent\Collection as DatabaseCollection;
use Illuminate\Support\Facades\Log;
use Laravel\Passport\HasApiTokens;
use Leenooks\Traits\ScopeActive;
@@ -272,41 +270,6 @@ class User extends Authenticatable implements IDs
return in_array($this->role(),['wholesaler']);
}
/**
* Get all the items for the next invoice
*
* @param bool $future
* @return DatabaseCollection
* @deprecated This should be done in accounts
*/
public function next_invoice_items(bool $future=FALSE): Collection
{
return collect();
$result = new DatabaseCollection;
$this->services->load(['invoice_items.taxes']);
foreach ($this->services as $o) {
if ($future) {
if ($o->invoice_next->subDays(config('app.invoice_inadvance'))->isPast())
continue;
} else {
if ($o->invoice_next->subDays(config('app.invoice_inadvance'))->isFuture())
continue;
}
foreach ($o->next_invoice_items($future) as $oo)
$result->push($oo);
}
$result->load([
'product.translate',
'service.type',
]);
return $result;
}
/**
* Determine what the logged in user's role is
* + Wholesaler - aka Super User