exportSpecific

This commit is contained in:
sayaliparab
2024-07-03 19:30:35 +05:30
parent 9721378c66
commit cd77a330d9
5 changed files with 92 additions and 52 deletions

View File

@@ -13,17 +13,21 @@ class ReportExport implements FromView
protected $states;
protected $startDate;
protected $endDate;
protected $restaurants;
public function __construct($reportType, $states, $startDate, $endDate)
public function __construct($reportType, $states, $startDate, $endDate, $restaurants = [])
{
$this->reportType = $reportType;
$this->states = $states;
$this->startDate = $startDate;
$this->endDate = $endDate;
$this->restaurants = $restaurants;
}
public function view(): View
{
$data = collect();
if ($this->reportType === 'Total Users') {
$query = IamPrincipal::query();
@@ -40,10 +44,6 @@ class ReportExport implements FromView
}
$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);
@@ -54,23 +54,34 @@ class ReportExport implements FromView
}
if ($this->startDate) {
$query->whereDate('redeem_date', '>=', $this->startDate);
$query->whereDate('created_at', '>=', $this->startDate);
}
if ($this->endDate) {
$query->whereDate('redeem_date', '<=', $this->endDate);
$query->whereDate('created_at', '<=', $this->endDate);
}
$data = $query->get();
} elseif ($this->reportType === 'Redemptions for Specific Restaurants') {
$query = RedeemRestaurant::with('restaurant', 'customer');
if (!empty($this->restaurants)) {
$query->whereIn('manage_restaurants_xid', $this->restaurants);
}
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
]);
}
// Default empty data if no matching report type
return view('exports.report', [
'data' => collect(),
'data' => $data,
'reportType' => $this->reportType
]);
}

View File

@@ -23,7 +23,6 @@ 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 {
@@ -47,7 +46,6 @@ 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();
@@ -63,14 +61,12 @@ class SubscriptionController extends Controller
}
} catch (\Exception $e) {
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
Log::error("An error occurred in " . _METHOD_ . ": " . $e->getMessage(), ['exception' => $e]);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'));
}
}
//created by; Hritik
//On - 28th June ,2024
//use - to get Data of User in Webview and show list of product
@@ -84,7 +80,7 @@ class SubscriptionController extends Controller
return view('Admin.pages.subscriptions.list-of-products', compact('productList'));
} catch (\Exception $e) {
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
Log::error("An error occurred in " . _METHOD_ . ": " . $e->getMessage(), ['exception' => $e]);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
}
@@ -236,7 +232,7 @@ class SubscriptionController extends Controller
} catch (\Exception $e) {
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
Log::error("An error occurred in " . _METHOD_ . ": " . $e->getMessage(), ['exception' => $e]);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'));
// return redirect()->back()->with(['error' => "Something went wrong while subscription!" . $e->getMessage()]);
@@ -303,7 +299,7 @@ class SubscriptionController extends Controller
} catch (Exception $e) {
DB::rollBack();
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
Log::error("An error occurred in " . _METHOD_ . ": " . $e->getMessage(), ['exception' => $e]);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
}
}

View File

@@ -8,8 +8,7 @@ use App\Models\ManageState;
use Illuminate\Support\Facades\Log;
use Maatwebsite\Excel\Facades\Excel;
use App\Exports\ReportExport;
use App\Models\ManageRestaurant;
class ManageReportsController extends Controller
{
@@ -18,7 +17,8 @@ class ManageReportsController extends Controller
{
try {
$states = ManageState::all();
return view('Admin.pages.manage_reports.manage_reports', compact('states'));
$restaurants = ManageRestaurant::all();
return view('Admin.pages.manage_reports.manage_reports', compact('states','restaurants'));
} catch (\Exception $e) {
Log::error("An error occurred in " . __METHOD__ . ": " . $e->getMessage(), ['exception' => $e]);
return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500);
@@ -40,10 +40,12 @@ public function exportReports(Request $request)
{
$reportType = $request->input('reportType');
$states = $request->input('states');
$restaurants = $request->input('restaurants', []);
$startDate = $request->input('startDate');
$endDate = $request->input('endDate');
return Excel::download(new ReportExport($reportType, $states, $startDate, $endDate), 'report.xlsx');
return Excel::download(new ReportExport($reportType, $states, $startDate, $endDate, $restaurants), 'report.xlsx');
}
}

View File

@@ -20,14 +20,6 @@ $currentPage = 'manage-reports';
<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">
@@ -60,16 +52,29 @@ $currentPage = 'manage-reports';
</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 }}
@if($point === 'Redemptions for Specific Restaurants')
<label>
<input type="checkbox" class="check-all"> Check All
</label>
@endforeach
</div>
<div class="state-checkboxes-container">
@foreach($restaurants as $restaurant)
<label class="state-checkbox-label">
<input type="checkbox" name="restaurants[]" value="{{ $restaurant->id }}" class="state-checkbox"> {{ $restaurant->name }}
</label>
@endforeach
</div>
@else
<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>
@endif
</div>
</div>
</div>

View File

@@ -1,4 +1,3 @@
<!DOCTYPE html>
<html>
<head>
@@ -16,17 +15,17 @@
<th>Last Name</th>
<th>Email</th>
<th>State</th>
<th>Created At</th>
<th>Date</th>
</tr>
</thead>
<tbody>
@foreach($data as $user)
<tr>
<td>{{$loop->iteration}}
<td>{{ $loop->iteration }}</td>
<td>{{ $user->id }}</td>
<td>{{ $user->first_name }}</td>
<td>{{ $user->last_name }}</td>
<td>{{ $user->email_address}}</td>
<td>{{ $user->email_address }}</td>
<td>{{ $user->state->name ?? 'N/A' }}</td>
<td>{{ $user->created_at }}</td>
</tr>
@@ -37,26 +36,53 @@
<table>
<thead>
<tr>
<th>Sr No. </th>
<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>
<th>Date</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>
<td>{{$redemption->created_at ?? 'N/A'}}</td>
</tr>
@endforeach
</tbody>
</table>
@elseif ($reportType === 'Redemptions for Specific Restaurants')
<table>
<thead>
<tr>
<th>Sr No. </th>
<th>Customer First Name</th>
<th>Customer Last Name</th>
<th>Restaurant Name</th>
<th>Redeem Date</th>
<th> Date </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->customer->first_name }}</td>
<td>{{ $redemption->customer->last_name }}</td>
<td>{{ $redemption->restaurant->name }}</td>
<td>{{ $redemption->redeem_date }}</td>
<td>{{ $redemption->customer->state->name ?? 'N/A' }}</td>
<td>{{$redemption->created_at}}</td>
</tr>
@endforeach
</tbody>