Scaffold command for cleaning accessory_checkout

This commit is contained in:
Marcus Moore
2025-08-20 13:49:19 -07:00
parent 4dcfd8b353
commit 18c2508d2f
2 changed files with 56 additions and 0 deletions
@@ -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;
}
}
+5
View File
@@ -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');
}
}