From 18c2508d2f35ed50ad6e7723ea008d4bf5666e1b Mon Sep 17 00:00:00 2001 From: Marcus Moore Date: Wed, 20 Aug 2025 13:49:19 -0700 Subject: [PATCH] Scaffold command for cleaning accessory_checkout --- .../CleanDeclinedAccessoryCheckouts.php | 51 +++++++++++++++++++ app/Models/CheckoutAcceptance.php | 5 ++ 2 files changed, 56 insertions(+) create mode 100644 app/Console/Commands/CleanDeclinedAccessoryCheckouts.php 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 @@ +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'); + } }