diff --git a/app/Exports/ReportExport.php b/app/Exports/ReportExport.php new file mode 100644 index 0000000..bdf3889 --- /dev/null +++ b/app/Exports/ReportExport.php @@ -0,0 +1,77 @@ +reportType = $reportType; + $this->states = $states; + $this->startDate = $startDate; + $this->endDate = $endDate; + } + + public function view(): View + { + if ($this->reportType === 'Total Users') { + $query = IamPrincipal::query(); + + if (!empty($this->states)) { + $query->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(); + return view('exports.report', [ + 'data' => $data, + 'reportType' => $this->reportType + ]); + } elseif ($this->reportType === 'Redemptions') { + $query = RedeemRestaurant::with(['restaurant', 'customer'])->where('is_redeem', 0); + + if (!empty($this->states)) { + $query->whereHas('customer', function ($q) { + $q->whereIn('state_xid', $this->states); + }); + } + + if ($this->startDate) { + $query->whereDate('redeem_date', '>=', $this->startDate); + } + + if ($this->endDate) { + $query->whereDate('redeem_date', '<=', $this->endDate); + } + + $data = $query->get(); + return view('exports.report', [ + 'data' => $data, + 'reportType' => $this->reportType + ]); + } + + // Default empty data if no matching report type + return view('exports.report', [ + 'data' => collect(), + 'reportType' => $this->reportType + ]); + } +} diff --git a/app/Http/Controllers/APIs/Customer_API/SubscriptionController.php b/app/Http/Controllers/APIs/Customer_API/SubscriptionController.php index e62aa68..7fa8959 100644 --- a/app/Http/Controllers/APIs/Customer_API/SubscriptionController.php +++ b/app/Http/Controllers/APIs/Customer_API/SubscriptionController.php @@ -6,6 +6,8 @@ use App\Http\Controllers\Controller; use App\Services\APIs\CustomerAPIs\RulesApiServices; use Illuminate\Support\Facades\Log; use Illuminate\Http\Request; +use App\Models\Faq; + class SubscriptionController extends Controller { @@ -14,19 +16,20 @@ class SubscriptionController extends Controller //created by; Hritik //On - 28th June ,2024 //use - to get Data of User in Webview and show list of product + public function mySubscription(Request $request) - { - try { +{ + try { + $faqs = Faq::with('faqCategory')->where('faq_category_id', 3)->get(); + return view('Admin.pages.subscriptions.my-subscription', compact('faqs')); - - return view('Admin.pages.subscriptions.my-subscription'); - - } catch (\Exception $e) { - Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); - return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); - } + } catch (\Exception $e) { + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } +} + //created by; Hritik @@ -37,11 +40,10 @@ class SubscriptionController extends Controller public function listOfProduct(Request $request) { try { - - - - return view('Admin.pages.subscriptions.list-of-products'); - + $faqs = Faq::with('faqCategory')->where('faq_category_id', 3)->get(); + + return view('Admin.pages.subscriptions.list-of-products', compact('faqs')); + } catch (\Exception $e) { Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); diff --git a/app/Http/Controllers/Admin/ManageReportsController.php b/app/Http/Controllers/Admin/ManageReportsController.php index 39d29a3..558be19 100644 --- a/app/Http/Controllers/Admin/ManageReportsController.php +++ b/app/Http/Controllers/Admin/ManageReportsController.php @@ -4,12 +4,46 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use Illuminate\Http\Request; +use App\Models\ManageState; +use Illuminate\Support\Facades\Log; +use Maatwebsite\Excel\Facades\Excel; +use App\Exports\ReportExport; + + class ManageReportsController extends Controller { - public function index(){ - - return view('Admin.pages.manage_reports.manage_reports'); - + + public function index() +{ + try { + $states = ManageState::all(); + return view('Admin.pages.manage_reports.manage_reports', compact('states')); + } catch (\Exception $e) { + Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); } } + +// public function exportReports(Request $request) +// { +// $reportType = $request->input('reportType'); +// $states = $request->input('states'); +// $startDate = $request->input('startDate'); +// $endDate = $request->input('endDate'); + +// return Excel::download(new ReportExport($reportType, $states, $startDate, $endDate), 'report.xlsx'); +// } + + +public function exportReports(Request $request) +{ + $reportType = $request->input('reportType'); + $states = $request->input('states'); + $startDate = $request->input('startDate'); + $endDate = $request->input('endDate'); + + return Excel::download(new ReportExport($reportType, $states, $startDate, $endDate), 'report.xlsx'); +} + +} 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 498d390..d6f1629 100644 --- a/resources/views/Admin/pages/manage_reports/manage_reports.blade.php +++ b/resources/views/Admin/pages/manage_reports/manage_reports.blade.php @@ -5,54 +5,89 @@ $currentPage = 'manage-reports'; @endphp +