Fixes to emailing cancel requests. Changes to email jobs with no site_id

This commit is contained in:
Deon George
2022-09-29 12:16:08 +10:00
parent 1667b8c1df
commit 2a19f14adb
13 changed files with 68 additions and 12 deletions

View File

@@ -5,7 +5,6 @@ namespace App\Models;
use Carbon\Carbon;
use Exception;
use Illuminate\Database\Eloquent\Casts\AsCollection;
use Illuminate\Database\Eloquent\Collection as DatabaseCollection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@@ -18,6 +17,7 @@ use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpKernel\Exception\HttpException;
use Leenooks\Carbon as LeenooksCarbon;
use App\Models\Scopes\SiteScope;
use App\Interfaces\IDs;
use App\Traits\ScopeServiceUserAuthorised;
use App\Traits\SiteID;
@@ -325,7 +325,11 @@ class Service extends Model implements IDs
*/
public function account()
{
return $this->belongsTo(Account::class);
return $this->belongsTo(Account::class)
->when($this->site_id,function($q) {
return $q->where('site_id', $this->site_id)
->withoutGlobalScope(SiteScope::class);
});
}
/**
@@ -346,6 +350,10 @@ class Service extends Model implements IDs
public function charges()
{
return $this->hasMany(Charge::class)
->when($this->site_id,function($q) {
return $q->where('site_id', $this->site_id)
->withoutGlobalScope(SiteScope::class);
})
->where('active','=',TRUE)
->orderBy('created_at');
}
@@ -354,6 +362,10 @@ class Service extends Model implements IDs
public function invoice_items($active=TRUE)
{
$query = $this->hasMany(InvoiceItem::class)
->when($this->site_id,function($q) {
return $q->where('site_id', $this->site_id)
->withoutGlobalScope(SiteScope::class);
})
->where('item_type','=',0)
->orderBy('start_at');
@@ -370,6 +382,10 @@ class Service extends Model implements IDs
public function invoices($active=TRUE)
{
$query = $this->hasManyThrough(Invoice::class,InvoiceItem::class,NULL,'id',NULL,'invoice_id')
->when($this->site_id,function($q) {
return $q->where('site_id', $this->site_id)
->withoutGlobalScope(SiteScope::class);
})
->distinct('id')
->where('invoices.site_id','=',$this->site_id)
->where('invoice_items.site_id','=',$this->site_id)
@@ -390,7 +406,11 @@ class Service extends Model implements IDs
*/
public function orderedby()
{
return $this->belongsTo(Account::class);
return $this->belongsTo(Account::class)
->when($this->site_id,function($q) {
return $q->where('site_id', $this->site_id)
->withoutGlobalScope(SiteScope::class);
});
}
/**
@@ -400,7 +420,11 @@ class Service extends Model implements IDs
*/
public function product()
{
return $this->belongsTo(Product::class);
return $this->belongsTo(Product::class)
->when($this->site_id,function($q) {
return $q->where('site_id', $this->site_id)
->withoutGlobalScope(SiteScope::class);
});
}
/**
@@ -410,7 +434,11 @@ class Service extends Model implements IDs
*/
public function type()
{
return $this->morphTo(null,'model','id','service_id');
return $this->morphTo(null,'model','id','service_id')
->when($this->site_id,function($q) {
return $q->where('site_id', $this->site_id)
->withoutGlobalScope(SiteScope::class);
});
}
/* SCOPES */