diff --git a/app/Http/Controllers/APIs/Customer_API/StripeWebhookController.php b/app/Http/Controllers/APIs/Customer_API/StripeWebhookController.php index ce05ea0..6d0fd47 100644 --- a/app/Http/Controllers/APIs/Customer_API/StripeWebhookController.php +++ b/app/Http/Controllers/APIs/Customer_API/StripeWebhookController.php @@ -92,7 +92,14 @@ class StripeWebhookController extends Controller Log::info("Referral User Subscription Updating Function Starts"); $referralUserSubscriptionData = Subscriptions::where('iam_principal_xid', $referralUserId)->where('subscription_status', '=', 'active')->first(); + + $stripe->subscriptions->update( + $referralUserSubscriptionData->subscription_id, + ['proration_behavior' => 'none'] + ); if ($referralUserSubscriptionData && $referralUserSubscriptionData->is_cancelled_subscription == 0) { + + //update subscription add 30 days trial period to this subscription $nextPaymentDate = $referralUserSubscriptionData->next_payment_date; $date = new DateTime($nextPaymentDate); @@ -129,6 +136,14 @@ class StripeWebhookController extends Controller //checkout store in db $subscriptionData = $stripe->checkout->sessions->retrieve($session->id, []); $SubscriptionObject = $stripe->subscriptions->retrieve($subscriptionData->subscription, []); + //update proration behavior + $stripe->subscriptions->update( + $subscriptionData->subscription, + ['proration_behavior' => 'none'] + ); + + //update proration behavior + $priceObject = $stripe->prices->retrieve($SubscriptionObject->plan->id, []); $amountSubtotalDollars = $subscriptionData->amount_total / 100; diff --git a/app/Http/Controllers/Admin/DashboardController.php b/app/Http/Controllers/Admin/DashboardController.php index 99808a3..6bc7793 100644 --- a/app/Http/Controllers/Admin/DashboardController.php +++ b/app/Http/Controllers/Admin/DashboardController.php @@ -21,14 +21,64 @@ class DashboardController extends Controller * Use : To show the dashboard. */ - // public function showDashboard(){ - - - // return view('Admin.dashboard'); - // } public function showDashboard() { - // Monthly data + + $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(); + } + + + $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(); + + $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(); + + // Ensure that $quarterlyData contains zeros for quarters with no data + for ($i = 1; $i <= 4; $i++) { + if (!isset($quarterlyData[$i])) { + $quarterlyData[$i] = 0; + } + } + + // Sort the array by quarter keys + ksort($quarterlyData); + + // 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(); + + $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')) @@ -82,7 +132,9 @@ class DashboardController extends Controller $customerCount = IamPrincipal::where('principal_type_xid', '=', 3)->count(); $restaurantCount = Subscriptions::where('is_active', 1)->count(); - $recent_transaction = Subscriptions::with('subscription')->get()->toArray(); + $dateTime = now(); + $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); + $recent_transaction = Subscriptions::where('next_payment_date', '>=', $formattedDateTime)->with('subscription')->get()->toArray(); return view('Admin.dashboard', compact( @@ -94,7 +146,13 @@ class DashboardController extends Controller 'dataQuarterlyWithType4', 'dataYearlyWithType3', 'dataYearlyWithType4', - 'recent_transaction' + 'recent_transaction', + 'dailyData', + 'formattedDailyData', + 'defaultData', + 'formattedDefaultData', + 'quarterlyData', + 'yearlyData' )); } diff --git a/app/Http/Controllers/Admin/ManageNotificationsController.php b/app/Http/Controllers/Admin/ManageNotificationsController.php index f60bcfe..c470b3a 100644 --- a/app/Http/Controllers/Admin/ManageNotificationsController.php +++ b/app/Http/Controllers/Admin/ManageNotificationsController.php @@ -10,6 +10,7 @@ use Exception; use Illuminate\Support\Facades\Log; use App\Helpers\onesignalhelper; use App\Models\ManageState; +use App\Models\Subscriptions; use Illuminate\Support\Facades\DB; class ManageNotificationsController extends Controller @@ -83,6 +84,7 @@ class ManageNotificationsController extends Controller public function store_notificaton_data(Request $request) { try { + $request->validate([ 'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048', ]); @@ -102,6 +104,10 @@ class ManageNotificationsController extends Controller $states = $request->states; + // $dateTime = now(); + // $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); + // $unsubscribe = Subscriptions::select('iam_principal_xid')->where('next_payment_date', '>=', $formattedDateTime)->get(); + $userQuery = IamPrincipal::where('is_active', 1) ->where('notification_status', 1) ->where('principal_type_xid', 3) diff --git a/app/Http/Helpers/onesignalhelper.php b/app/Http/Helpers/onesignalhelper.php index 278f80f..7fa88db 100644 --- a/app/Http/Helpers/onesignalhelper.php +++ b/app/Http/Helpers/onesignalhelper.php @@ -66,13 +66,6 @@ class onesignalhelper try { $currentUtcTime = Carbon::now(); - // $data = new NotificationDetails(); - // $data->principal_xid = $customerId; - // $data->type = $type; - // $data->date_added = $currentUtcTime; - // $data->description = $description; - // $data->save(); - $newRecord = NotificationDetails::create([ 'principal_xid' => $customerId, 'type' => $type, diff --git a/app/Models/NotificationDetails.php b/app/Models/NotificationDetails.php index 331938e..a82a486 100644 --- a/app/Models/NotificationDetails.php +++ b/app/Models/NotificationDetails.php @@ -11,7 +11,7 @@ class NotificationDetails extends Model protected $table = "notification_details"; protected $fillable = [ 'id', - 'principal_xid', 'type', 'description', 'image', 'date_added' + 'principal_xid', 'type', 'description', 'image', 'date_added','is_schedule','delivery_schedule' ]; protected $guarded = []; diff --git a/app/Services/APIs/RestaurantService/RestaurantApi_Service.php b/app/Services/APIs/RestaurantService/RestaurantApi_Service.php index fdb4624..08405b4 100644 --- a/app/Services/APIs/RestaurantService/RestaurantApi_Service.php +++ b/app/Services/APIs/RestaurantService/RestaurantApi_Service.php @@ -40,28 +40,40 @@ class RestaurantApi_Service ->where('principal_xid', $userDetail->id) ->get(); - // $restaurantDetails = []; + $restaurantDetails = []; + $isActive = true; + $inactiveMessage = ""; foreach ($restaurantRoles as $restaurantRole) { $restaurant = ManageRestaurant::select('id', 'name', 'description', 'restaurant_id', 'address', 'image', 'bio', 'try_on_1', 'phone_number', 'try_on_2', 'try_on_3', 'try_on_4', 'exclusion', 'latitude', 'longtitude', 'is_active', 'created_by', 'modified_by', 'deleted_at', 'created_at', 'updated_at') ->where('id', $restaurantRole->restaurant_xid) - ->where('is_active', 1) ->first(); if ($restaurant) { $restaurant->image = ListingImageUrl('restaurant_images', $restaurant->image); $restaurant->description = strip_tags($restaurant->description); - // $restaurantDetails[] = $restaurant; + if ($restaurant->is_active == 0) { + $isActive = false; + $inactiveMessage = "Your restaurant is currently not participating in Cheers to the Season. Please reach out to contact@cheerstotheseason.com to re-enroll."; + } + + // Add restaurant details to the array + $restaurantDetails[] = $restaurant; } } // Construct response $response = [ 'user_detail' => $userDetail, - 'restaurant_details' => $restaurant, + 'restaurant_details' => $restaurantDetails, + 'is_active' => $isActive, ]; + if (!$isActive) { + $response['message'] = $inactiveMessage; + } + // Return JSON response with success message return jsonResponseWithSuccessMessageApi(__('auth.User_details_fetch'), $response, 200); } catch (Exception $ex) { @@ -74,6 +86,7 @@ class RestaurantApi_Service + public function updateRestaurantDetail($restIamId, $request) { try { diff --git a/resources/views/Admin/dashboard.blade.php b/resources/views/Admin/dashboard.blade.php index 56a9fdf..019dbf6 100644 --- a/resources/views/Admin/dashboard.blade.php +++ b/resources/views/Admin/dashboard.blade.php @@ -52,37 +52,37 @@ $currentPage = 'dashboard'; --}} -