Scaffold command for cleaning accessory_checkout
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Accessory;
|
||||
use App\Models\AccessoryCheckout;
|
||||
use App\Models\CheckoutAcceptance;
|
||||
use App\Models\User;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
class CleanDeclinedAccessoryCheckouts extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'snipeit:clean-declined-accessory-checkouts';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Command description';
|
||||
// @todo
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
// $accessoryCheckouts = AccessoryCheckout::where('assigned_type', User::class)->get();
|
||||
//
|
||||
// dd($accessoryCheckouts);
|
||||
|
||||
$declinedCheckoutAcceptances = CheckoutAcceptance::query()
|
||||
->where([
|
||||
'checkoutable_type' => Accessory::class,
|
||||
])
|
||||
// if it was declined and the qty is null that means it potentially left
|
||||
// some entries in the `accessories_checkout` table behind.
|
||||
->whereNull('qty')
|
||||
->declined()
|
||||
->get();
|
||||
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -136,4 +136,9 @@ class CheckoutAcceptance extends Model
|
||||
{
|
||||
return $query->whereNull('accepted_at')->whereNull('declined_at');
|
||||
}
|
||||
|
||||
public function scopeDeclined(Builder $query)
|
||||
{
|
||||
return $query->whereNull('accepted_at')->whereNotNull('declined_at');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user