date format changes

This commit is contained in:
sayliraut
2024-07-29 15:05:11 +05:30
parent 27719f3c99
commit 74c77f6b0f
10 changed files with 173 additions and 175 deletions

View File

@@ -6,6 +6,8 @@ use Maatwebsite\Excel\Concerns\FromCollection;
use App\Models\Subscriptions;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Illuminate\Support\Collection;
use Carbon\Carbon;
class DashboardSelectedExportUser implements FromCollection, WithHeadings
{
@@ -34,9 +36,9 @@ class DashboardSelectedExportUser implements FromCollection, WithHeadings
'Amount' => $transaction['amount'],
'Payment Details' => $transaction['stripe_customer_id'],
'Subscription status' => $transaction['subscription_status'],
'Subscription Start Date' => $transaction['current_period_start'],
'Subscription End Date' => $transaction['current_period_end'],
'Next Payment Date' => $transaction['next_payment_date']
'Subscription Start Date' => Carbon::parse($transaction['current_period_start'])->format('m/d/Y h:i A'),
'Subscription End Date' => Carbon::parse($transaction['current_period_end'])->format('m/d/Y h:i A'),
'Next Payment Date' => Carbon::parse($transaction['next_payment_date'])->format('m/d/Y h:i A')
];
});

View File

@@ -24,7 +24,7 @@ class FeedbakExport implements FromCollection, WithHeadings
'Last Name' => $feedback->principal ? $feedback->principal->last_name : 'N/A',
'Feedback Reaction' => $feedback->feedbackReaction ? $feedback->feedbackReaction->feedback_reaction_title : 'N/A',
'Comment' => $feedback->comment,
'Date Received' => $feedback->created_at,
'Date Received' => \Carbon\Carbon::parse($feedback->created_at)->format('m/d/Y'),
'Feedback Type' => $feedbackType,
'Restaurant Name' => $feedback->restaurant ? $feedback->restaurant->name : 'N/A',
];

View File

@@ -59,7 +59,7 @@ use Illuminate\Support\Collection;
// }
// }
//
//
class restaurant_export implements FromCollection, WithHeadings
{
public function collection()
@@ -78,11 +78,11 @@ class restaurant_export implements FromCollection, WithHeadings
'First Name' => $restaurant_user->first_name,
'Last Name' => $restaurant_user->last_name,
'Email Address' => $restaurant_user->email_address,
'Date of Birth' => optional($restaurant_user->date_of_birth)->format('m/d/Y'),
'State Name' => optional($restaurant_user->state)->name ?? '',
'Date of Birth' => \Carbon\Carbon::parse($restaurant_user->date_of_birth)->format('m/d/Y'),
// 'State Name' => $restaurant_user->state->name ?? '',
'Phone Number' => $restaurant_user->phone_number,
'Restaurant Name' => optional($role->restaurant)->name ?? '',
'Restaurant Address' => optional($role->restaurant)->address ?? '',
'Restaurant Name' => $role->restaurant->name ?? '',
'Restaurant Address' => $role->restaurant->address ?? '',
];
});
});
@@ -97,10 +97,10 @@ class restaurant_export implements FromCollection, WithHeadings
'Last Name',
'Email Address',
'Date of Birth',
'State Name',
// 'State Name',
'Phone Number',
'Restaurant Name',
'Restaurant Address',
];
}
}
}

View File

@@ -1,4 +1,4 @@
<?php
<?php
namespace App\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
@@ -111,7 +111,7 @@ class restaurant_export_selected implements FromCollection, WithHeadings
'Last Name' => $customer->last_name,
'Email Address' => $customer->email_address,
'Date of Birth' => \Carbon\Carbon::parse($customer->date_of_birth)->format('m/d/Y'),
'State Name' => optional($customer->state)->name ?? 'NA',
// 'State Name' => optional($customer->state)->name ?? 'NA',
'Phone Number' => $customer->phone_number,
'Restaurant Name' => optional($role->restaurant)->name ?? 'NA',
'Restaurant Address' => optional($role->restaurant)->address ?? 'NA',
@@ -133,10 +133,10 @@ class restaurant_export_selected implements FromCollection, WithHeadings
'Last Name',
'Email Address',
'Date of Birth',
'State Name',
// 'State Name',
'Phone Number',
'Restaurant Name',
'Restaurant Address'
];
}
}
}

View File

@@ -8,6 +8,7 @@ use App\Models\IamPrincipal;
use Illuminate\Support\Facades\DB;
use App\Models\ManageRestaurant;
use App\Models\Subscriptions;
use Carbon\Carbon;
use App\Exports\DashboardExportUser;
use App\Exports\DashboardSelectedExportUser;
use Maatwebsite\Excel\Facades\Excel;
@@ -21,143 +22,152 @@ class DashboardController extends Controller
* Use : To show the dashboard.
*/
public function showDashboard()
{
$dailyData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("DATE(created_at) as date"))
->whereBetween('created_at', [now()->subDays(7), now()]) // Fetch data for the last 7 days
->groupBy(DB::raw("DATE(created_at)"))
->orderBy(DB::raw("DATE(created_at)"))
->pluck('count', 'date')
->toArray();
$start_date = now()->subDays(7)->startOfDay();
$end_date = now()->endOfDay();
$formattedDailyData = [];
while ($start_date <= $end_date) {
$formattedDailyData[$start_date->format('Y-m-d')] = isset($dailyData[$start_date->format('Y-m-d')]) ? $dailyData[$start_date->format('Y-m-d')] : 0;
$start_date->addDay();
}
public function showDashboard()
{
$defaultData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
$dailyData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("DATE(created_at) as date"))
->whereBetween('created_at', [now()->subDays(7), now()]) // Fetch data for the last 7 days
->groupBy(DB::raw("DATE(created_at)"))
->orderBy(DB::raw("DATE(created_at)"))
->pluck('count', 'date')
->toArray();
$months = range(1, 12);
$formattedDefaultData = [];
foreach ($months as $month) {
$formattedDefaultData[$month] = isset($defaultData[$month]) ? $defaultData[$month] : 0;
}
$quarterlyData = Subscriptions::select(
DB::raw("COUNT(*) as count"),
DB::raw("QUARTER(created_at) as quarter")
)
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
$start_date = now()->subDays(7)->startOfDay();
$end_date = now()->endOfDay();
$formattedDailyData = [];
while ($start_date <= $end_date) {
$formattedDailyData[$start_date->format('Y-m-d')] = $dailyData[$start_date->format('Y-m-d')] ?? 0;
$start_date->addDay();
}
// Ensure that $quarterlyData contains zeros for quarters with no data
for ($i = 1; $i <= 4; $i++) {
if (!isset($quarterlyData[$i])) {
$quarterlyData[$i] = 0;
}
}
$defaultData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
// Sort the array by quarter keys
ksort($quarterlyData);
$months = range(1, 12);
$formattedDefaultData = [];
foreach ($months as $month) {
$formattedDefaultData[$month] = $defaultData[$month] ?? 0;
}
// Fetching data for yearly option
$yearlyData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
$quarterlyData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
for ($i = 1; $i <= 4; $i++) {
$quarterlyData[$i] = $quarterlyData[$i] ?? 0;
}
$dataMonthlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
->where('principal_type_xid', 3)
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
ksort($quarterlyData);
$dataMonthlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
$yearlyData = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
// Fill missing months with zeros
$months = range(1, 12);
$dataMonthlyWithType3 = array_replace(array_fill_keys($months, 0), $dataMonthlyWithType3);
$dataMonthlyWithType4 = array_replace(array_fill_keys($months, 0), $dataMonthlyWithType4);
$dataMonthlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
->where('principal_type_xid', 3)
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
// Quarterly data
$dataQuarterlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
->where('principal_type_xid', 3)
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
$dataMonthlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("MONTH(created_at) as month"))
->whereYear('created_at', date('Y'))
->groupBy(DB::raw("MONTH(created_at)"))
->orderBy(DB::raw("MONTH(created_at)"))
->pluck('count', 'month')
->toArray();
$dataQuarterlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
$dataMonthlyWithType3 = array_replace(array_fill_keys($months, 0), $dataMonthlyWithType3);
$dataMonthlyWithType4 = array_replace(array_fill_keys($months, 0), $dataMonthlyWithType4);
$dataQuarterlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
->where('principal_type_xid', 3)
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
$dataQuarterlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("QUARTER(created_at) as quarter"))
->groupBy(DB::raw("QUARTER(created_at)"))
->orderBy(DB::raw("QUARTER(created_at)"))
->pluck('count', 'quarter')
->toArray();
// Fill missing quarters with zeros
$quarters = range(1, 4);
$dataQuarterlyWithType3 = array_replace(array_fill_keys($quarters, 0), $dataQuarterlyWithType3);
$dataQuarterlyWithType4 = array_replace(array_fill_keys($quarters, 0), $dataQuarterlyWithType4);
// Yearly data
$dataYearlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
->where('principal_type_xid', 3)
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
$dataYearlyWithType3 = IamPrincipal::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
->where('principal_type_xid', 3)
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
$dataYearlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
$dataYearlyWithType4 = Subscriptions::select(DB::raw("COUNT(*) as count"), DB::raw("YEAR(created_at) as year"))
->groupBy(DB::raw("YEAR(created_at)"))
->pluck('count', 'year')
->toArray();
$customerCount = IamPrincipal::where('principal_type_xid', '=', 3)->count();
$restaurantCount = Subscriptions::where('is_active', 1)->count();
$dateTime = now();
$formattedDateTime = $dateTime->format('Y-m-d H:i:s');
$recent_transaction = Subscriptions::where('next_payment_date', '>=', $formattedDateTime)->with('subscription')->orderBy('id', 'desc')->get()->toArray();
$customerCount = IamPrincipal::where('principal_type_xid', 3)->count();
$restaurantCount = Subscriptions::where('is_active', 1)->count();
$formattedDateTime = now()->format('Y-m-d H:i:s');
$recent_transactions = Subscriptions::where('next_payment_date', '>=', $formattedDateTime)
->with('subscription')
->orderBy('id', 'desc')
->get();
$formatted_transactions = $recent_transactions->map(function ($transaction) {
return [
'id' => $transaction->id,
'subscription' => [
'first_name' => $transaction->subscription->first_name,
'last_name' => $transaction->subscription->last_name,
'id' => $transaction->subscription->id,
],
'amount' => $transaction->amount,
'subscription_id' => $transaction->subscription_id,
'stripe_customer_id' => $transaction->stripe_customer_id,
'subscription_status' => $transaction->subscription_status,
'current_period_start' => Carbon::parse($transaction->current_period_start)->format('m/d/y'),
'current_period_end' => Carbon::parse($transaction->current_period_end)->format('m/d/y'),
'next_payment_date' => Carbon::parse($transaction->next_payment_date)->format('m/d/y'),
];
})->toArray();
return view('Admin.dashboard', compact(
'customerCount',
'restaurantCount',
'dataMonthlyWithType3',
'dataMonthlyWithType4',
'dataQuarterlyWithType3',
'dataQuarterlyWithType4',
'dataYearlyWithType3',
'dataYearlyWithType4',
'formatted_transactions',
'dailyData',
'formattedDailyData',
'defaultData',
'formattedDefaultData',
'quarterlyData',
'yearlyData'
));
}
return view('Admin.dashboard', compact(
'customerCount',
'restaurantCount',
'dataMonthlyWithType3',
'dataMonthlyWithType4',
'dataQuarterlyWithType3',
'dataQuarterlyWithType4',
'dataYearlyWithType3',
'dataYearlyWithType4',
'recent_transaction',
'dailyData',
'formattedDailyData',
'defaultData',
'formattedDefaultData',
'quarterlyData',
'yearlyData'
));
}
/*
/*
Created By : Sayali Parab
Created at : 08 July 2024
Use : To Get Excel.
@@ -188,7 +198,7 @@ class DashboardController extends Controller
$recentTransaction = Subscriptions::with(['iamPrincipal', 'subscriptionProduct'])->get()->toArray();
return Excel::download(new DashboardExportUser($recentTransaction), 'recent_transactions.xlsx');
}
$ids = $request->input('selected_id');
if (!is_array($ids)) {
$ids = explode(',', $ids);
@@ -199,7 +209,4 @@ class DashboardController extends Controller
return response()->json(['error' => 'Export failed. Something went wrong.'], 500);
}
}
}

View File

@@ -127,40 +127,40 @@
</tr>
</thead>
<tbody class="text-center">
@foreach ($recent_transaction as $recent_transactions)
@foreach ($formatted_transactions as $transaction)
<tr>
<td>
<div
class="form-check form-check-sm form-check-custom form-check-solid">
<input class="form-check-input" type="checkbox"
id="customer_checkbox_ids" name="customer_ids"
value="{{ $recent_transactions['id'] }}" />
value="{{ $transaction['id'] }}" />
</div>
</td>
<td class="text-start">{{ $loop->iteration }}</td>
<td class="text-start">
{{ $recent_transactions['subscription']['first_name'] }}
{{ $recent_transactions['subscription']['last_name'] }}
{{ $transaction['subscription']['first_name'] }}
{{ $transaction['subscription']['last_name'] }}
</td>
<td class="text-start">
{{ $recent_transactions['subscription']['id'] }}</td>
<td class="text-start">$ {{ $recent_transactions['amount'] }}</td>
<td class="text-start">{{ $transaction['subscription']['id'] }}</td>
<td class="text-start">$ {{ $transaction['amount'] }}</td>
<td class="text-start">
<a class="view-btn m-0 pointer sub_admin_permission"
data-toggle="modal" data-target="#payment-details-modal"
data-id="{{ $recent_transactions['id'] }}"
data-name="{{ $recent_transactions['subscription']['first_name'] }}"
data-price="{{ $recent_transactions['amount'] }}"
data-subscription-id="{{ $recent_transactions['subscription_id'] }}"
data-customer-id="{{ $recent_transactions['stripe_customer_id'] }}"
data-subscription-status="{{ $recent_transactions['subscription_status'] }}"
data-start-date="{{ $recent_transactions['current_period_start'] }}"
data-end-date="{{ $recent_transactions['current_period_end'] }}"
data-next-date="{{ $recent_transactions['next_payment_date'] }}">View</a>
data-id="{{ $transaction['id'] }}"
data-name="{{ $transaction['subscription']['first_name'] }}"
data-price="{{ $transaction['amount'] }}"
data-subscription-id="{{ $transaction['subscription_id'] }}"
data-customer-id="{{ $transaction['stripe_customer_id'] }}"
data-subscription-status="{{ $transaction['subscription_status'] }}"
data-start-date="{{ $transaction['current_period_start'] }}"
data-end-date="{{ $transaction['current_period_end'] }}"
data-next-date="{{ $transaction['next_payment_date'] }}">View</a>
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</form>

View File

@@ -98,7 +98,7 @@ $currentPage = 'manage-reports';
<script>
// Initialize Flatpickr for the date range with placeholders and set maxDate to today
flatpickr("#startDate", {
dateFormat: "Y-m-d",
dateFormat: "m/d/Y",
maxDate: "today",
onChange: function (selectedDates, dateStr) {
// Set the minimum date for the end date input
@@ -107,7 +107,7 @@ $currentPage = 'manage-reports';
});
flatpickr("#endDate", {
dateFormat: "Y-m-d",
dateFormat: "m/d/Y",
maxDate: "today",
});

View File

@@ -55,24 +55,20 @@
<td>Restaurant Name :</td>
<td>Restaurant ID :</td>
<td>Bio :</td>
<td>Monday :</td>
<td>Tuesday :</td>
<td>Wednesday :</td>
<td>Thursday :</td>
<td>Friday :</td>
<td>Saturday :</td>
<td>Sunday :</td>
<td>Try on 1 :</td>
<td>Try on 2 :</td>
<td>Try on 3 :</td>
<td>Try on 4 :</td>
<td>Image :</td>
</tr>
<tr class="w-100">
<td>{{ $restaurantItem->name }}</td>
<td>{{ $restaurantItem->restaurant_id }}</td>
<td class="text-scrollable">{{ $restaurantItem->bio }}</td>
@foreach (['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] as $day)
<td>
{{ isset($operating_hours[$day]) ? $operating_hours[$day]->start_time . ' - ' . $operating_hours[$day]->end_time : 'N/A' }}
</td>
@endforeach
<td class="text-scrollable">{{ $restaurantItem->try_on_1 }}</td>
<td class="text-scrollable">{{ $restaurantItem->try_on_2 }}</td>
<td class="text-scrollable">{{ $restaurantItem->try_on_3 }}</td>
<td class="text-scrollable">{{ $restaurantItem->try_on_4 }}</td>
<td>
<div id="imageInputPreviewNormal" style="width: 30%;">
<img src="{{ $restaurantItem->image }}" alt="Image Preview"
@@ -88,10 +84,6 @@
{{-- <td>Description :</td> --}}
<td>Status :</td>
<td>Address :</td>
<td>Try on 1 :</td>
<td>Try on 2 :</td>
<td>Try on 3 :</td>
<td>Try on 4 :</td>
<td>Exclusion :</td>
<td>Latitude :</td>
<td>Longitude :</td>
@@ -101,10 +93,7 @@
<td>{{ $restaurantItem->is_active == 1 ? 'Active' : 'Expired' }}
</td>
<td>{{ $restaurantItem->address }}</td>
<td class="text-scrollable">{{ $restaurantItem->try_on_1 }}</td>
<td class="text-scrollable">{{ $restaurantItem->try_on_2 }}</td>
<td class="text-scrollable">{{ $restaurantItem->try_on_3 }}</td>
<td class="text-scrollable">{{ $restaurantItem->try_on_4 }}</td>
<td class="text-scrollable">{{ $restaurantItem->exclusion }}</td>
<td>{{ $restaurantItem->latitude }}</td>
<td>{{ $restaurantItem->longtitude }}</td>

View File

@@ -154,11 +154,11 @@
</td>
<td>{{ $subscribe->subscription_status }}
</td>
<td>{{ \Carbon\Carbon::parse($subscribe->current_period_start)->format('m-d-y') }}
<td>{{ \Carbon\Carbon::parse($subscribe->current_period_start)->format('m/d/y') }}
</td>
<td>{{ \Carbon\Carbon::parse($subscribe->current_period_end)->format('m-d-y') }}
<td>{{ \Carbon\Carbon::parse($subscribe->current_period_end)->format('m/d/y') }}
</td>
<td>{{ \Carbon\Carbon::parse($subscribe->next_payment_date)->format('m-d-y') }}
<td>{{ \Carbon\Carbon::parse($subscribe->next_payment_date)->format('m/d/y') }}
</td>
</tr>
@endforeach

View File

@@ -49,7 +49,7 @@
</div>
<div class="info" style="display: flex;">
<span>Date of Birth:</span>
<span>{{ \Carbon\Carbon::parse($customers_data->date_of_birth)->format('m-d-Y') }}</span>
<span>{{ \Carbon\Carbon::parse($customers_data->date_of_birth)->format('m/d/Y') }}</span>
</div>
<div class="info">
<span>Phone Number:</span>