Skip to content

A free open source IT asset/license management system

Scaffold command for cleaning accessory_checkout

Marcus Moore18c2508d2f35
diff --git a/app/Console/Commands/CleanDeclinedAccessoryCheckouts.php b/app/Console/Commands/CleanDeclinedAccessoryCheckouts.php
new file mode 100644
index 0000000000..9825d615be
--- /dev/null
+++ b/app/Console/Commands/CleanDeclinedAccessoryCheckouts.php
@@ -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;
+ }
+}
diff --git a/app/Models/CheckoutAcceptance.php b/app/Models/CheckoutAcceptance.php
index 0599286f85..876135c3f6 100644
--- a/app/Models/CheckoutAcceptance.php
+++ b/app/Models/CheckoutAcceptance.php
@@ -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');
+ }
}