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

@ -118,7 +118,7 @@ final class BroadbandTraffic implements ShouldQueue
// If we have no records
if (! $oo) {
Log::error(sprintf('%s:Too many services return for [%s]',self::LOGKEY,$row[$o->getColumnKey('Login')]),['date'=>$date,'count'=>$oo->count()]);
Log::error(sprintf('%s:None or too many services return for [%s]',self::LOGKEY,$row[$o->getColumnKey('Login')]),['date'=>$date]);
$to->service = $row[$o->getColumnKey('Login')];
$to->site_id = 1; // @todo This needs to be worked out a better way

View File

@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use App\Models\Service;
@ -35,6 +36,8 @@ class CancelRequest extends Mailable
*/
public function build()
{
Config::set('site',$this->service->site);
switch (get_class($this->service->type)) {
case 'App\Models\Service\Broadband':
$subject = sprintf('Cancel BROADBAND: %s',$this->service->type->service_address);

View File

@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use App\Models\Service;
@ -35,6 +36,8 @@ class ChangeRequest extends Mailable
*/
public function build()
{
Config::set('site',$this->service->site);
switch (get_class($this->service->type)) {
case 'App\Models\Service\Broadband':
$subject = sprintf('Change BROADBAND: %s',$this->service->type->service_address);

View File

@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use App\Models\Invoice;
@ -32,6 +33,8 @@ class InvoiceEmail extends Mailable
*/
public function build()
{
Config::set('site',$this->invoice->site);
return $this
->markdown('email.user.invoice')
->subject(sprintf( 'Invoice: %s - Total: $%s - Due: %s',

View File

@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use App\Models\Service;
@ -35,6 +36,8 @@ class OrderRequest extends Mailable
*/
public function build()
{
Config::set('site',$this->service->site);
switch (get_class($this->service->type)) {
case 'App\Models\Service\Broadband':
$subject = sprintf('Order BROADBAND: %s',$this->service->type->service_address);

View File

@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Config;
use App\Models\Service;
@ -35,6 +36,8 @@ class OrderRequestApprove extends Mailable
*/
public function build()
{
Config::set('site',$this->service->site);
// @todo This is not consistent with Cancel/Change Request
switch ($this->service->category) {
case 'BROADBAND': $subject = sprintf('%s: %s',$this->service->category,$this->service->type->service_address);

View File

@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Support\Facades\Config;
use App\Models\Service;
@ -34,6 +35,8 @@ class OrderRequestReject extends Mailable
*/
public function build()
{
Config::set('site',$this->service->site);
return $this
->markdown('email.admin.order.reject')
->subject(sprintf('Your order: #%s was rejected',$this->service->id))

View File

@ -5,6 +5,7 @@ namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use App\Models\{Site,User,UserOauth};
@ -35,6 +36,8 @@ class SocialLink extends Mailable
*/
public function build()
{
Config::set('site',$this->site);
return $this
->markdown('email.system.social_link')
->subject('Link your Account')

View File

@ -6,6 +6,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use App\Models\User;
@ -32,6 +33,8 @@ class TestEmail extends Mailable
*/
public function build()
{
Config::set('site',$this->user->site);
return $this
->markdown('email.system.test_email')
->subject('Just a test...')

View File

@ -7,6 +7,7 @@ use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Config;
use App\Models\{Supplier,Site};
@ -35,11 +36,13 @@ class TrafficMismatch extends Mailable
*/
public function build()
{
Config::set('site',$x=Site::find(1)); // @todo To auto determine;
return $this
->markdown('email.system.broadband_traffic_mismatch')
->subject('Traffic Mismatch for '.$this->date)
->with([
'site'=>Site::find(1), // @todo To auto determine
'site'=>$x,
'date'=>$this->date,
'aso'=>$this->aso,
]);

View File

@ -17,6 +17,7 @@ class SiteScope implements Scope
*/
public function apply(Builder $builder, Model $model)
{
// @todo Need to only do this, if the original query doesnt already have a where condition with a site_id
$builder->where($model->getTable().'.site_id',config('site')->site_id);
}
}

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 */

View File

@ -4,15 +4,15 @@ Please cancel the following...
@component('mail::table')
| Service | Details |
| :---------- | :---------------- |
| Logged User | {{ Auth::user()->id }} |
| Logged User | {{ Auth::user()->id ?? 'System' }} |
| Account | {{ $service->account->name }} |
| Service ID | {{ $service->sid }} |
| Product | {{ $service->product->name }} |
@switch($service->category)
@case('Broadband')
@case('broadband')
| Address | {{ $service->type->service_address }} |
@break;
@case('Phone')
@case('phone')
| Number | {{ $service->type->service_number }} |
| Supplier Details | {{ $service->order_info->join(':') }} |
@break;