move into sonardesk
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Contracts\View\View;
|
||||
use Illuminate\Routing\Controller;
|
||||
use Modules\Licensing\Models\License;
|
||||
use Modules\Licensing\Models\LicenseProduct;
|
||||
use Modules\Licensing\Models\LicenseWebhookEvent;
|
||||
|
||||
final class LicensingDashboardController extends Controller
|
||||
{
|
||||
@@ -53,4 +54,45 @@ final class LicensingDashboardController extends Controller
|
||||
return view('licensing::admin.subscriptions', compact('subscriptions', 'total', 'active', 'cancelScheduled'));
|
||||
}
|
||||
|
||||
/** Local-only billing integrity audit. Does not contact Paddle or mutate records. */
|
||||
public function billingAudit(): View
|
||||
{
|
||||
$linked = License::query()->whereNotNull('external_subscription_id');
|
||||
|
||||
$duplicateSubscriptions = License::query()
|
||||
->select('payment_provider', 'external_subscription_id')
|
||||
->selectRaw('COUNT(*) AS license_count')
|
||||
->whereNotNull('external_subscription_id')
|
||||
->groupBy('payment_provider', 'external_subscription_id')
|
||||
->havingRaw('COUNT(*) > 1')
|
||||
->orderByDesc('license_count')
|
||||
->limit(25)
|
||||
->get();
|
||||
|
||||
$duplicateEvents = LicenseWebhookEvent::query()
|
||||
->select('provider', 'external_event_id')
|
||||
->selectRaw('COUNT(*) AS event_count')
|
||||
->whereNotNull('external_event_id')
|
||||
->groupBy('provider', 'external_event_id')
|
||||
->havingRaw('COUNT(*) > 1')
|
||||
->orderByDesc('event_count')
|
||||
->limit(25)
|
||||
->get();
|
||||
|
||||
return view('licensing::admin.billing-audit', [
|
||||
'linkedCount' => (clone $linked)->count(),
|
||||
'missingProvider' => (clone $linked)->whereNull('payment_provider')->count(),
|
||||
'missingCustomer' => (clone $linked)->whereNull('external_customer_id')->count(),
|
||||
'missingStatus' => (clone $linked)->whereNull('subscription_status')->count(),
|
||||
'eventCount' => LicenseWebhookEvent::query()->count(),
|
||||
'unprocessedEvents' => LicenseWebhookEvent::query()->whereNull('processed_at')->count(),
|
||||
'failedEvents' => LicenseWebhookEvent::query()->whereNotNull('processing_error')->count(),
|
||||
'duplicateSubscriptions' => $duplicateSubscriptions,
|
||||
'duplicateEvents' => $duplicateEvents,
|
||||
'recentFailures' => LicenseWebhookEvent::query()
|
||||
->whereNotNull('processing_error')->latest()->limit(15)
|
||||
->get(['id', 'provider', 'external_event_id', 'event_type', 'processing_error', 'created_at']),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user