diff --git a/app/Exports/ReportExport.php b/app/Exports/ReportExport.php index 07bed6a..50f417f 100644 --- a/app/Exports/ReportExport.php +++ b/app/Exports/ReportExport.php @@ -4,6 +4,7 @@ namespace App\Exports; use App\Models\IamPrincipal; use App\Models\RedeemRestaurant; +use App\Models\Subscriptions; use Illuminate\Contracts\View\View; use Maatwebsite\Excel\Concerns\FromView; @@ -28,7 +29,25 @@ class ReportExport implements FromView { $data = collect(); - if ($this->reportType === 'Total Users') { + if ($this->reportType === 'Total Subscribed') { + $query = Subscriptions::with(['iamPrincipal.state']); + + if (!empty($this->states)) { + $query->whereHas('iamPrincipal', function ($q) { + $q->whereIn('state_xid', $this->states); + }); + } + + if ($this->startDate) { + $query->whereDate('created_at', '>=', $this->startDate); + } + + if ($this->endDate) { + $query->whereDate('created_at', '<=', $this->endDate); + } + + $data = $query->get(); + } elseif ($this->reportType === 'Total Users') { $query = IamPrincipal::query(); if (!empty($this->states)) { diff --git a/app/Models/Subscriptions.php b/app/Models/Subscriptions.php index e5c15fb..8f59c18 100644 --- a/app/Models/Subscriptions.php +++ b/app/Models/Subscriptions.php @@ -11,9 +11,36 @@ class Subscriptions extends Model protected $table = 'subscriptions'; protected $guarded = []; + protected $fillable = [ + 'id', + 'subscription_product_xid', + 'iam_principal_xid', + 'amount', + 'stripe_customer_id', + 'payment_intent_id', + 'payment_intent_client_secret', + 'subscription_id', + 'subscription_status', + 'current_period_start', + 'current_period_end', + 'status', + 'next_payment_date', + 'is_cancelled_subscription', + 'cancelled_at', + 'is_active', + 'deleted_at', + 'created_by', + 'modified_by', + 'created_at', + 'updated_at' + ]; - +public function iamPrincipal() +{ + return $this->belongsTo(IamPrincipal::class, 'iam_principal_xid', 'id'); +} + } diff --git a/resources/views/Admin/pages/manage_reports/manage_reports.blade.php b/resources/views/Admin/pages/manage_reports/manage_reports.blade.php index ddba1e3..76a628e 100644 --- a/resources/views/Admin/pages/manage_reports/manage_reports.blade.php +++ b/resources/views/Admin/pages/manage_reports/manage_reports.blade.php @@ -119,10 +119,16 @@ $currentPage = 'manage-reports'; radio.addEventListener('change', function() { document.querySelectorAll('.state-checkboxes').forEach(function(checkboxDiv) { checkboxDiv.classList.remove('show'); + checkboxDiv.querySelectorAll('.state-checkbox').forEach(function(checkbox) { + checkbox.disabled = true; + }); }); var selectedPoint = this.value; document.querySelectorAll('.state-checkboxes[data-point="' + selectedPoint + '"]').forEach(function(checkboxDiv) { checkboxDiv.classList.add('show'); + checkboxDiv.querySelectorAll('.state-checkbox').forEach(function(checkbox) { + checkbox.disabled = false; + }); }); }); }); @@ -147,7 +153,8 @@ $currentPage = 'manage-reports';