diff --git a/app/Http/Controllers/Admin/ManageNotificationsController.php b/app/Http/Controllers/Admin/ManageNotificationsController.php index 30baad0..51cffb8 100644 --- a/app/Http/Controllers/Admin/ManageNotificationsController.php +++ b/app/Http/Controllers/Admin/ManageNotificationsController.php @@ -86,178 +86,184 @@ class ManageNotificationsController extends Controller * Use : To add notification . */ - public function store_notificaton_data(Request $request) - { - try { - $request->validate([ - 'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048', - ]); + public function store_notificaton_data(Request $request) + { + try { + $request->validate([ + 'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048', + ]); - DB::beginTransaction(); + DB::beginTransaction(); - if (isset($request->image)) { - $image = $request->image; - $image_db = null; - } else { - $image = null; - $image_db = $request->image; - } + if (isset($request->image)) { + $image = $request->image; + $image_db = null; + } else { + $image = null; + $image_db = $request->image; + } - $tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db); - $imagePath = ListingImageUrl('notification_images', $tnormalImage); + $tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db); + $imagePath = ListingImageUrl('notification_images', $tnormalImage); - $states = $request->states; + $states = $request->states; - $dateTime = now(); - $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); - $iamPrincipals = Subscriptions::select('iam_principal_xid') - ->where('next_payment_date', '>=', $formattedDateTime) - ->get(); + $dateTime = now(); + $formattedDateTime = $dateTime->format('Y-m-d H:i:s'); + $iamPrincipals = Subscriptions::select('iam_principal_xid') + ->where('next_payment_date', '>=', $formattedDateTime) + ->get(); - $iamPrincipalIds = $iamPrincipals->pluck('iam_principal_xid'); + $iamPrincipalIds = $iamPrincipals->pluck('iam_principal_xid'); - $subscribe = IamPrincipal::whereIn('id', $iamPrincipalIds) - ->where('is_active', 1) - ->where('notification_status', 1) - ->where('principal_type_xid', 3) - ->whereIn('state_xid', $states) - ->get(); + $subscribe = IamPrincipal::whereIn('id', $iamPrincipalIds) + ->where('is_active', 1) + ->where('notification_status', 1) + ->where('principal_type_xid', 3) + ->whereIn('state_xid', $states) + ->get(); - if ($request->user_type == 1) { - $allCustomerOneSignalIds = $subscribe->pluck('id'); - $UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get(); + $scheduled = false; - foreach ($UserData as $customerIdItem) { - // user_type 1 = subscribed user - if ($request->schedule_radio1 == 1 && $request->schedule_date) { - // Scheduled Notification - NotificationDetails::create([ - 'principal_xid' => $customerIdItem->id, - 'description' => $request->description, - 'type' => $request->title, - 'image' => $imagePath, - 'date_added' => $request->schedule_date, - 'is_schedule' => 1, - 'delivery_schedule' => $request->schedule_date, - 'is_active' => 0, + if ($request->user_type == 1) { + $allCustomerOneSignalIds = $subscribe->pluck('id'); + $UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get(); - ]); - } else { - // Immediate Notification - if ($customerIdItem->one_signal_player_id) { - onesignalhelper::sendNotificationApi( - $customerIdItem->one_signal_player_id, - $request->title, - $request->description, - 'Dashboard Notification', - $imagePath, - $id = null - ); - } - onesignalhelper::StoreNotificationDetails($customerIdItem->id, 'Notification', $request->title, $imagePath); - } - } - } elseif ($request->user_type == 2) { - //user_type 2 unsubscribed users - $allPrincipalIds = IamPrincipal::where('principal_type_xid', 3) - ->pluck('id'); + foreach ($UserData as $customerIdItem) { + // user_type 1 = subscribed user + if ($request->schedule_radio1 == 1 && $request->schedule_date) { + // Scheduled Notification + NotificationDetails::create([ + 'principal_xid' => $customerIdItem->id, + 'description' => $request->description, + 'type' => $request->title, + 'image' => $imagePath, + 'date_added' => $request->schedule_date, + 'is_schedule' => 1, + 'delivery_schedule' => $request->schedule_date, + 'is_active' => 0, + ]); + $scheduled = true; + } else { + // Immediate Notification + if ($customerIdItem->one_signal_player_id) { + onesignalhelper::sendNotificationApi( + $customerIdItem->one_signal_player_id, + $request->title, + $request->description, + 'Dashboard Notification', + $imagePath, + $id = null + ); + } + onesignalhelper::StoreNotificationDetails($customerIdItem->id, 'Notification', $request->title, $imagePath); + } + } + } elseif ($request->user_type == 2) { + // user_type 2 unsubscribed users + $allPrincipalIds = IamPrincipal::where('principal_type_xid', 3) + ->pluck('id'); - $subscribedIds = Subscriptions::select('iam_principal_xid') - ->where('next_payment_date', '>=', $formattedDateTime) - ->pluck('iam_principal_xid'); + $subscribedIds = Subscriptions::select('iam_principal_xid') + ->where('next_payment_date', '>=', $formattedDateTime) + ->pluck('iam_principal_xid'); - $unsubscribedIds = $allPrincipalIds->diff($subscribedIds); + $unsubscribedIds = $allPrincipalIds->diff($subscribedIds); - $unsubscribedPrincipals = IamPrincipal::whereIn('id', $unsubscribedIds) - ->where('is_active', 1) - ->where('notification_status', 1) - ->whereIn('state_xid', $states) - ->get(); + $unsubscribedPrincipals = IamPrincipal::whereIn('id', $unsubscribedIds) + ->where('is_active', 1) + ->where('notification_status', 1) + ->whereIn('state_xid', $states) + ->get(); - $allRestaurantOneSignalIds = $unsubscribedPrincipals->pluck('id'); - $restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get(); + $allRestaurantOneSignalIds = $unsubscribedPrincipals->pluck('id'); + $restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get(); - foreach ($restaurantData as $restaurantsData) { - if ($request->schedule_radio1 == 1 && $request->schedule_date) { - // Scheduled Notification - NotificationDetails::create([ - 'principal_xid' => $restaurantsData->id, - 'description' => $request->description, - 'type' => $request->title, - 'image' => $imagePath, - 'date_added' => $request->schedule_date, - 'is_schedule' => 1, - 'delivery_schedule' => $request->schedule_date, - 'is_active' => 0, + foreach ($restaurantData as $restaurantsData) { + if ($request->schedule_radio1 == 1 && $request->schedule_date) { + // Scheduled Notification + NotificationDetails::create([ + 'principal_xid' => $restaurantsData->id, + 'description' => $request->description, + 'type' => $request->title, + 'image' => $imagePath, + 'date_added' => $request->schedule_date, + 'is_schedule' => 1, + 'delivery_schedule' => $request->schedule_date, + 'is_active' => 0, + ]); + $scheduled = true; + } else { + // Immediate Notification + if ($restaurantsData->one_signal_player_id) { + onesignalhelper::sendNotificationApi( + $restaurantsData->one_signal_player_id, + $request->title, + $request->description, + $request->title, + $imagePath, + $id = null + ); + } + onesignalhelper::StoreNotificationDetails($restaurantsData->id, 'Notification', $request->title, $imagePath); + } + } + } elseif ($request->user_type == 3) { + // user_type 3 = subscribed and unsubscribed users + $userQuery = IamPrincipal::where('is_active', 1) + ->where('notification_status', 1) + ->where('principal_type_xid', 3) + ->whereIn('state_xid', $states); + $allUserOneSignalIds = $userQuery->pluck('id'); + $UserData = IamPrincipal::whereIn('id', $allUserOneSignalIds)->get(); - ]); - } else { - // Immediate Notification - if ($restaurantsData->one_signal_player_id) { - onesignalhelper::sendNotificationApi( - $restaurantsData->one_signal_player_id, - $request->title, - $request->description, - $request->title, - $imagePath, - $id = null - ); - } - onesignalhelper::StoreNotificationDetails($restaurantsData->id, 'Notification', $request->title, $imagePath); - } - } - } elseif ($request->user_type == 3) { - // user_type 3 = subscribed and unsubscribed users - $userQuery = IamPrincipal::where('is_active', 1) - ->where('notification_status', 1) - ->where('principal_type_xid', 3) - ->whereIn('state_xid', $states); + foreach ($UserData as $CustomerData) { + if ($request->schedule_radio1 == 1 && $request->schedule_date) { + // Scheduled Notification + NotificationDetails::create([ + 'principal_xid' => $CustomerData->id, + 'description' => $request->description, + 'type' => $request->title, + 'image' => $imagePath, + 'date_added' => $request->schedule_date, + 'is_schedule' => 1, + 'delivery_schedule' => $request->schedule_date, + 'is_active' => 0, + ]); + $scheduled = true; + } else { + // Immediate Notification + if ($CustomerData->one_signal_player_id) { + onesignalhelper::sendNotificationApi( + $CustomerData->one_signal_player_id, + $request->title, + $request->description, + 'Dashboard Notification', + $imagePath, + $id = null + ); + } + onesignalhelper::StoreNotificationDetails($CustomerData->id, 'Notification', $request->title, $imagePath); + } + } + } - $allUserOneSignalIds = $userQuery->pluck('id'); - $UserData = IamPrincipal::whereIn('id', $allUserOneSignalIds)->get(); + DB::commit(); - foreach ($UserData as $CustomerData) { - if ($request->schedule_radio1 == 1 && $request->schedule_date) { - // Scheduled Notification - NotificationDetails::create([ - 'principal_xid' => $CustomerData->id, - 'description' => $request->description, - 'type' => $request->title, - 'image' => $imagePath, - 'date_added' => $request->schedule_date, - 'is_schedule' => 1, - 'delivery_schedule' => $request->schedule_date, - 'is_active' => 0, + if ($scheduled) { + return jsonResponseWithSuccessMessage(__('success.save_data_scheduled')); + } else { + return jsonResponseWithSuccessMessage(__('success.save_data_immediate')); + } + } catch (Exception $e) { + DB::rollBack(); + Log::error("Notification send Failed " . $e->getMessage()); + return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); + } + } - ]); - } else { - // Immediate Notification - if ($CustomerData->one_signal_player_id) { - onesignalhelper::sendNotificationApi( - $CustomerData->one_signal_player_id, - $request->title, - $request->description, - 'Dashboard Notification', - $imagePath, - $id = null - ); - } - onesignalhelper::StoreNotificationDetails($CustomerData->id, 'Notification', $request->title, $imagePath); - } - } - } - - DB::commit(); - return jsonResponseWithSuccessMessage(__('success.save_data')); - } catch (Exception $e) { - DB::rollBack(); - Log::error("Notification send Failed " . $e->getMessage()); - return jsonResponseWithErrorMessage(__('auth.something_went_wrong'), 500); - } - } - diff --git a/resources/lang/en/success.php b/resources/lang/en/success.php index d09ced8..122584c 100644 --- a/resources/lang/en/success.php +++ b/resources/lang/en/success.php @@ -34,5 +34,8 @@ return [ 'authentic_success' => 'Authentication Successful', 'confirmed_password' => 'please confirm your passsword', 'redeemed_successfully' => 'Referral code redeemed successfully.', + 'save_data_scheduled' => 'Notification Schedule Successfully.', + 'save_data_immediate' => 'Notification Sent Successfully.', + ]; diff --git a/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php b/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php index a389400..e251dae 100644 --- a/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php +++ b/resources/views/Admin/pages/manage_notification/manage_notifications_add.blade.php @@ -57,7 +57,10 @@
- + +
@@ -138,10 +141,12 @@
-
Delivery Schedule
+ +
-
When should this message start sending?
+
@@ -182,193 +187,212 @@
@endsection @section('section_script') - - - + + + - + @endsection diff --git a/resources/views/Admin/pages/manage_notification/manage_notifications_view.blade.php b/resources/views/Admin/pages/manage_notification/manage_notifications_view.blade.php index 8101dfb..949e8d2 100644 --- a/resources/views/Admin/pages/manage_notification/manage_notifications_view.blade.php +++ b/resources/views/Admin/pages/manage_notification/manage_notifications_view.blade.php @@ -1,83 +1,91 @@ @extends('Admin.layouts.master') @section('content') -@php -$currentPage = 'manage-notification'; -@endphp -
-
-
-
-
- + @php + $currentPage = 'manage-notification'; + @endphp +
+
+
+
+ -
-
-
-
-
-
-
-
- - - - - - - - - -
Notification content :Created Date :
{{ $notification->description }}{{ \Carbon\Carbon::parse($notification->date_added)->format('d/m/y') }}
-
-
- - - - {{-- --}} - - + +
+
+
+
+
+
+
+
+
Recipients :Last Modified Date :
+ + + + + + + + - + + - -
Message :Description :Created Date :
{{ $notification->type }}{{ $notification->description }}@if($notification->notification->principal_type_xid == '3') - Customer - @else - Resturant - @endif - {{ \Carbon\Carbon::parse($notification->date_added)->format('d/m/y') }} +
-
+ +
+
+ + + + + {{-- --}} + + + + + + + + +
Recipients :Image :Last Modified Date :
+ @if ($notification->notification->principal_type_xid == '3') + Customer + @else + Resturant + @endif + + Notification Image +
+
-
+
-
+
+
- - - +
@endsection -