Merge branch 'main' of https://github.com/WDI-Ideas/cheerstothe_season_laravel11 into HritikCheers
This commit is contained in:
77
app/Exports/ReportExport.php
Normal file
77
app/Exports/ReportExport.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Exports;
|
||||
|
||||
use App\Models\IamPrincipal;
|
||||
use App\Models\RedeemRestaurant;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
|
||||
class ReportExport implements FromView
|
||||
{
|
||||
protected $reportType;
|
||||
protected $states;
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($reportType, $states, $startDate, $endDate)
|
||||
{
|
||||
$this->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
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -23,6 +23,7 @@ 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 {
|
||||
@@ -46,6 +47,7 @@ class SubscriptionController extends Controller
|
||||
|
||||
// $request['iam_principal_id'] = $user_id;
|
||||
|
||||
return view('Admin.pages.subscriptions.my-subscription', compact('faqs'));
|
||||
|
||||
$products = SubscriptionProducts::where('is_active', '1')->get();
|
||||
|
||||
@@ -67,6 +69,8 @@ class SubscriptionController extends Controller
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//created by; Hritik
|
||||
//On - 28th June ,2024
|
||||
//use - to get Data of User in Webview and show list of product
|
||||
|
||||
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,54 +5,89 @@
|
||||
$currentPage = 'manage-reports';
|
||||
@endphp
|
||||
|
||||
<div class="layout-px-spacing">
|
||||
<div class="middle-content container-xxl p-0">
|
||||
<div class="row layout-top-spacing">
|
||||
<div class="top-tabel">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h6 class="card-title">Manage Reports & Analysis</h6>
|
||||
</div>
|
||||
<div class="col-md-8"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<form id="reportForm" action="{{ route('export.reports') }}" method="POST">
|
||||
@csrf
|
||||
<div class="row widget-content widget-content-area br-8 position-btn m-auto py-3" style="overflow: auto;">
|
||||
<!-- <div class="col-md-6">
|
||||
<label for="">Select Modules</label>
|
||||
<select class="form-control">
|
||||
<option value="">dummy</option>
|
||||
<option value="">dummy</option>
|
||||
<option value="">dummy</option>
|
||||
</select>
|
||||
</div> -->
|
||||
<div class="col-6">
|
||||
<label for="startDate">Start Date:</label>
|
||||
<input class="form-control" placeholder="Select start date" type="text" id="startDate" name="startDate">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="endDate">End Date:</label>
|
||||
<input class="form-control" placeholder="Select end date" type="text" id="endDate" name="endDate">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row widget-content widget-content-area br-8 position-btn m-auto py-3" style="overflow: auto;">
|
||||
@php
|
||||
$points = [
|
||||
'Total Subscribed',
|
||||
'Total Users',
|
||||
'New Subscribed',
|
||||
'Redemptions',
|
||||
'Redemptions for Specific Restaurants',
|
||||
'Referrals Made',
|
||||
'Referees Joined',
|
||||
'Subscriptions Cancelled'
|
||||
];
|
||||
@endphp
|
||||
|
||||
|
||||
<div class="layout-px-spacing">
|
||||
<div class="middle-content container-xxl p-0">
|
||||
<div class="row layout-top-spacing ">
|
||||
<div class="top-tabel">
|
||||
<div class="row">
|
||||
<div class="col-md-4">
|
||||
<h6 class="card-title">Manage Reports & Analysis</h6>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
|
||||
@foreach($points as $point)
|
||||
<div class="col-md-12">
|
||||
<div class="card mb-3">
|
||||
<div class="card-header">
|
||||
<label>
|
||||
<input type="radio" name="reportType" value="{{ $point }}" class="report-type-radio"> {{ $point }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="card-body state-checkboxes" style="display: none;" data-point="{{ $point }}">
|
||||
<label>
|
||||
<input type="checkbox" class="check-all"> Check All
|
||||
</label>
|
||||
<div class="state-checkboxes-container">
|
||||
@foreach($states as $state)
|
||||
<label class="state-checkbox-label">
|
||||
<input type="checkbox" name="states[]" value="{{ $state->id }}" class="state-checkbox"> {{ $state->name }}
|
||||
</label>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row widget-content widget-content-area br-8 position-btn m-auto py-3" style="overflow: auto;">
|
||||
<div class="col-md-6">
|
||||
<label for="">Select Modules</label>
|
||||
<select class="form-control">
|
||||
<option value="">dummny</option>
|
||||
<option value="">dummny</option>
|
||||
<option value="">dummny</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="col-6">
|
||||
<label for="startDate">Start Date:</label>
|
||||
<input class="form-control" placeholder="Select start date" type="text" id="startDate">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="endDate">End Date:</label>
|
||||
<input class="form-control" placeholder="Select end date" type="text" id="endDate">
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<a class="download-btn-custom mt-3 custom-width-10" href="">
|
||||
<span>Download</span>
|
||||
</a>
|
||||
</div>
|
||||
|
||||
@endforeach
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-12 text-center">
|
||||
<button type="submit" class="download-btn-custom mt-3 custom-width-10">
|
||||
<span>Download</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
|
||||
|
||||
@section('section_script')
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
@section('section_script')
|
||||
<script>
|
||||
// Select the start and end date inputs
|
||||
var startDateInput = document.getElementById("startDate");
|
||||
@@ -70,5 +105,70 @@ $currentPage = 'manage-reports';
|
||||
var endDatePicker = flatpickr(endDateInput, {
|
||||
dateFormat: "Y-m-d",
|
||||
});
|
||||
|
||||
// Show/hide checkboxes based on selected radio button
|
||||
document.querySelectorAll('input[name="reportType"]').forEach(function(radio) {
|
||||
radio.addEventListener('change', function() {
|
||||
document.querySelectorAll('.state-checkboxes').forEach(function(checkboxDiv) {
|
||||
checkboxDiv.style.display = 'none';
|
||||
});
|
||||
var selectedPoint = this.value;
|
||||
document.querySelectorAll('.state-checkboxes[data-point="' + selectedPoint + '"]').forEach(function(checkboxDiv) {
|
||||
checkboxDiv.style.display = 'block';
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Handle "Check All" functionality
|
||||
document.querySelectorAll('.check-all').forEach(function(checkAllBox) {
|
||||
checkAllBox.addEventListener('change', function() {
|
||||
var checkboxes = this.closest('.state-checkboxes').querySelectorAll('.state-checkbox');
|
||||
checkboxes.forEach(function(checkbox) {
|
||||
checkbox.checked = checkAllBox.checked;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// Refresh page after download
|
||||
document.getElementById('reportForm').addEventListener('submit', function() {
|
||||
// Add a timeout to ensure the form data is sent before refreshing
|
||||
setTimeout(function() {
|
||||
location.reload();
|
||||
}, 1000); // Adjust the timeout as needed (milliseconds)
|
||||
});
|
||||
</script>
|
||||
|
||||
<style>
|
||||
.state-checkboxes-container {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.state-checkbox-label {
|
||||
margin-right: 10px;
|
||||
display: inline-block;
|
||||
}
|
||||
.card {
|
||||
border: 1px solid #ccc;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
.card-header {
|
||||
background-color: #f8f9fa;
|
||||
padding: 10px;
|
||||
border-bottom: 1px solid #ddd;
|
||||
}
|
||||
.card-body {
|
||||
padding: 10px;
|
||||
}
|
||||
.download-btn-custom {
|
||||
display: inline-block;
|
||||
background-color: #007bff;
|
||||
color: #fff;
|
||||
padding: 10px 20px;
|
||||
text-decoration: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@endsection
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section class="mt-3 mb-5">
|
||||
<!-- <section class="mt-3 mb-5">
|
||||
<div class="container">
|
||||
<h3 class=" head my-4">Subscription FAQs</h3>
|
||||
<div data-ui-tablist class="ui-accordion ui-accordion--outlined" data-ui-transition="collapse-fade">
|
||||
@@ -76,7 +76,24 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</section> -->
|
||||
<section class="mt-3 mb-5">
|
||||
<div class="container">
|
||||
<h3 class="head my-4">Subscription FAQs</h3>
|
||||
<div data-ui-tablist class="ui-accordion ui-accordion--outlined" data-ui-transition="collapse-fade">
|
||||
@foreach($faqs as $faq)
|
||||
<div class="ui-accordion-item">
|
||||
<button data-ui-tablist-tab class="ui-accordion-header">{{ $faq->question }}</button>
|
||||
<div data-ui-tablist-tabpanel {{ $loop->first ? '' : 'hidden' }}>
|
||||
<div class="ui-accordion-body">
|
||||
{{ $faq->answers }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- Modal start -->
|
||||
<div class="modal fade" id="exampleModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
|
||||
|
||||
66
resources/views/exports/report.blade.php
Normal file
66
resources/views/exports/report.blade.php
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Report</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>{{ $reportType }} Report</h1>
|
||||
@if ($reportType === 'Total Users')
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sr No.</th>
|
||||
<th>ID</th>
|
||||
<th>First Name</th>
|
||||
<th>Last Name</th>
|
||||
<th>Email</th>
|
||||
<th>State</th>
|
||||
<th>Created At</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($data as $user)
|
||||
<tr>
|
||||
<td>{{$loop->iteration}}
|
||||
<td>{{ $user->id }}</td>
|
||||
<td>{{ $user->first_name }}</td>
|
||||
<td>{{ $user->last_name }}</td>
|
||||
<td>{{ $user->email_address}}</td>
|
||||
<td>{{ $user->state->name ?? 'N/A' }}</td>
|
||||
<td>{{ $user->created_at }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@elseif ($reportType === 'Redemptions')
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Sr No. </th>
|
||||
<th>ID</th>
|
||||
<th>Customer First Name</th>
|
||||
<th>Customer Last Name</th>
|
||||
<th>Restaurant Name</th>
|
||||
<th>Redeem Date</th>
|
||||
<th>State</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach($data as $redemption)
|
||||
<tr>
|
||||
<td>{{$loop->iteration}}</td>
|
||||
<td>{{ $redemption->id }}</td>
|
||||
<td>{{ $redemption->customer->first_name ?? 'N/A' }}</td>
|
||||
<td>{{ $redemption->customer->last_name ?? 'N/A' }}</td>
|
||||
<td>{{ $redemption->restaurant->name ?? 'N/A' }}</td>
|
||||
|
||||
<td>{{ $redemption->redeem_date }}</td>
|
||||
<td>{{ $redemption->customer->state->name ?? 'N/A' }}</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
@endif
|
||||
</body>
|
||||
</html>
|
||||
@@ -172,6 +172,8 @@ Route::group(['middleware' => ['checkStatus']], function () {
|
||||
|
||||
//*******************************************************manage reports********************************************************
|
||||
Route::get('/manage-reports', [ManageReportsController::class, 'index'])->name('manage.reports');
|
||||
Route::post('/export-reports', [ManageReportsController::class, 'exportReports'])->name('export.reports');
|
||||
|
||||
//*******************************************************manage feedback********************************************************
|
||||
Route::get('/manage-feedback', [ManageFeedbackController::class, 'index'])->name('manage.feedback');
|
||||
Route::post('/delete_feedback/{id}', [ManageFeedbackController::class, 'delete_feedback'])->name('delete.feedback');
|
||||
|
||||
Reference in New Issue
Block a user