Merge pull request #175 from WDI-Ideas/sayli

Sayli
This commit is contained in:
Sayli Raut
2024-06-19 16:21:02 +05:30
committed by GitHub
4 changed files with 215 additions and 159 deletions

View File

@@ -34,7 +34,7 @@ class RulesControllerAPI extends Controller
return jsonResponseWithErrorMessageApi(__('auth.user_deleted'), 409);
}
} catch (\Exception $e) {
Log::error('FAW get data controller function failed: ' . $e->getMessage());
Log::error('Voucher rules get data controller function failed: ' . $e->getMessage());
return jsonResponseWithErrorMessageApi(__('auth.something_went_wrong'), 500);
}
}

View File

@@ -81,90 +81,79 @@ class ManageNotificationsController extends Controller
* Use : To add notification .
*/
public function store_notificaton_data(Request $request)
{
// dd($request);
try {
$request->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048',
]);
{
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;
}
$tnormalImage = saveSingleImageWithoutCrop($image, 'notification_images', $image_db);
$imagePath = ListingImageUrl('notification_images', $tnormalImage);
$allCustomerOneSignalIds = IamPrincipal::where('is_active', 1)
->where('notification_status', 1)
->where('principal_type_xid', 3)
->where('state_xid', $request->state)
->pluck('id');
$allRestaurantOneSignalIds = IamPrincipal::where('is_active', 1)
->where('notification_status', 1)
->where('principal_type_xid', 3)
->where('state_xid', $request->state)
->pluck('id');
// Find the remaining user data
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
$title = $request->title;
$message = $request->description;
$content_type = 'Notification';
$imageUrl = $imagePath;
// FOR all customer
if ($request->user_type == 1) {
foreach ($UserData as $customerIdItem) {
if ($customerIdItem->one_signal_player_id) {
onesignalhelper::sendNotificationApi(
$customerIdItem->one_signal_player_id,
$title,
$message,
$content_type,
$imageUrl,
$id = null
);
}
onesignalhelper::StoreNotificationDetails($customerIdItem->id, $content_type, $title, $imagePath);
}
} elseif ($request->user_type == 2) {
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
foreach ($restaurantData as $restIdItem) {
if ($restIdItem->one_signal_player_id) {
onesignalhelper::sendNotificationApi(
$restIdItem->one_signal_player_id,
$title,
$message,
$content_type,
$imageUrl,
$id = null
);
}
onesignalhelper::StoreNotificationDetails($restIdItem->id, $content_type, $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);
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);
// Fetch OneSignal IDs based on the selected states and user type
$states = $request->states;
$userQuery = IamPrincipal::where('is_active', 1)
->where('notification_status', 1)
->where('principal_type_xid', 3)
->whereIn('state_xid', $states);
if ($request->user_type == 1) {
$allCustomerOneSignalIds = $userQuery->pluck('id');
$UserData = IamPrincipal::whereIn('id', $allCustomerOneSignalIds)->get();
foreach ($UserData as $customerIdItem) {
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) {
$allRestaurantOneSignalIds = $userQuery->pluck('id');
$restaurantData = IamPrincipal::whereIn('id', $allRestaurantOneSignalIds)->get();
foreach ($restaurantData as $restIdItem) {
if ($restIdItem->one_signal_player_id) {
onesignalhelper::sendNotificationApi(
$restIdItem->one_signal_player_id,
$request->title,
$request->description,
'Dashboard Notification',
$imagePath,
$id = null
);
}
onesignalhelper::StoreNotificationDetails($restIdItem->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);
}
}
/**

View File

@@ -8,36 +8,36 @@
<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 Notification</h6>
</div>
<div class="col-md-8">
</div>
<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 Notification</h6>
</div>
<div class="col-md-8">
</div>
</div>
<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing">
<div class="widget-content widget-content-area br-8 position-btn">
<table id="zero-config" class="table dt-table-hover" style="width:100%">
<thead class="text-center">
<tr>
<th class="text-start">Sr No.</th>
<th class="text-start">Notification content</th>
<th class="text-start">Email</th>
<th class="text-start">Created Date</th>
<th class="text-start">Recipients</th>
<th class="text-start">Date sent</th>
<th class="no-content">Status</th>
</tr>
</thead>
<tbody class="text-center">
@foreach ($notifications as $notification)
</div>
<div class="col-xl-12 col-lg-12 col-sm-12 layout-spacing">
<div class="widget-content widget-content-area br-8 position-btn">
<table id="zero-config" class="table dt-table-hover" style="width:100%">
<thead class="text-center">
<tr>
<th class="text-start">Sr No.</th>
<th class="text-start">Notification content</th>
<th class="text-start">Email</th>
<th class="text-start">Created Date</th>
<th class="text-start">Recipients</th>
<th class="text-start">Date sent</th>
<th class="no-content">Status</th>
</tr>
</thead>
<tbody class="text-center">
@foreach ($notifications as $notification)
<tr>
<td class="text-start">{{ $loop->iteration }}</td>
<td class="text-start">{{ $notification->type }}</td>
@@ -86,40 +86,101 @@
</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</tbody>
</table>
</div>
</div>
</div>
</div>
@endsection
@section('section_script')
<script src="../src/plugins/src/table/datatable/datatables.js"></script>
<script>
$('#zero-config').DataTable({
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'l><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center mt-sm-0 mt-3'f>>>" +
"<'table-responsive'tr>" +
"<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
"oLanguage": {
"oPaginate": { "sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>', "sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>' },
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"stripeClasses": [],
"lengthMenu": [7, 10, 20, 50],
"pageLength": 10
});
</script>
<script>
$(document).ready(function () {
$('<button><a class="extra-btn width-max-content" href="{{ route('manage_add_notifications') }}">Add</a></button><button><ul class="navbar-item flex-row ms-lg-auto ms-0"><li class="nav-item dropdown action-dropdown order-lg-0 order-1"><a href="javascript:void(0);"class="nav-link dropdown-toggle user extra-btn" id="actionDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><div class="avatar-container"><div class="avatar avatar-sm avatar-indicators avatar-online"><h3>Filter</h3></div></div></a><div class="dropdown-menu position-absolute" aria-labelledby="actionDropdown"><div class="dropdown-item"><a href="#"><span>All</span></a></div><div class="dropdown-item"><a href="#"><span>Customer</span></a></div><div class="dropdown-item"><a href="#"> <span>Restaurant</span></a></div></div></li></ul></button>').insertBefore("#zero-config_filter label");
});
</script>
</div>
@endsection
@section('section_script')
<script src="../src/plugins/src/table/datatable/datatables.js"></script>
<script>
$('#zero-config').DataTable({
"dom": "<'dt--top-section'<'row'<'col-12 col-sm-6 d-flex justify-content-sm-start justify-content-center'l><'col-12 col-sm-6 d-flex justify-content-sm-end justify-content-center mt-sm-0 mt-3'f>>>" +
"<'table-responsive'tr>" +
"<'dt--bottom-section d-sm-flex justify-content-sm-between text-center'<'dt--pages-count mb-sm-0 mb-3'i><'dt--pagination'p>>",
"oLanguage": {
"oPaginate": {
"sPrevious": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-left"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>',
"sNext": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-arrow-right"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>'
},
"sInfo": "Showing page _PAGE_ of _PAGES_",
"sSearch": '<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-search"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>',
"sSearchPlaceholder": "Search...",
"sLengthMenu": "Results : _MENU_",
},
"stripeClasses": [],
"lengthMenu": [7, 10, 20, 50],
"pageLength": 10
});
</script>
<script>
$(document).ready(function() {
$('<button><a class="extra-btn width-max-content" href="{{ route('manage_add_notifications') }}">Add</a></button><button><ul class="navbar-item flex-row ms-lg-auto ms-0"><li class="nav-item dropdown action-dropdown order-lg-0 order-1"><a href="javascript:void(0);"class="nav-link dropdown-toggle user extra-btn" id="actionDropdown" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><div class="avatar-container"><div class="avatar avatar-sm avatar-indicators avatar-online"><h3>Filter</h3></div></div></a><div class="dropdown-menu position-absolute" aria-labelledby="actionDropdown"><div class="dropdown-item"><a href="{{ route('manage.notification') }}" id="allFilter"><span>All</span></a></div><div class="dropdown-item"><a href="{{ route('manage.notification', ['active' => 4]) }}" id="activeFilter"><span>Customer</span></a></div><div class="dropdown-item"><a href="{{ route('manage.notification', ['active' => 3]) }}" id="expiredFilter"> <span>Restaurant</span></a></div></div></li></ul></button>')
.insertBefore("#zero-config_filter label");
// Retrieve the selected filter from local storage
var selectedFilter = localStorage.getItem('selectedFilter');
// If a selected filter exists, set its color
if (selectedFilter) {
handleChange(selectedFilter);
} else {
// If no selected filter is found, simulate a click event on the default filter button
$('#allFilter').trigger('click');
}
// Add event listeners to filter links
$('#activeFilter').on('click', function() {
// Prevent the default anchor behavior
handleChange('active');
// Store selected filter in local storage
localStorage.setItem('selectedFilter', 'active');
});
$('#expiredFilter').on('click', function() {
// Prevent the default anchor behavior
handleChange('expired');
// Store selected filter in local storage
localStorage.setItem('selectedFilter', 'expired');
});
$('#allFilter').on('click', function() {
// Prevent the default anchor behavior
handleChange('all');
// Store selected filter in local storage
localStorage.setItem('selectedFilter', 'all');
});
});
// Define handleChange function
function handleChange(filterType) {
// Reset background color of all filters
$('#activeFilter, #expiredFilter, #allFilter').css('background-color', '');
// Set background color based on filter type
if (filterType === 'active') {
$('#activeFilter').css({
'padding': '4px 8px',
'background-color': 'rgb(233, 233, 234)',
'color': 'rgb(191, 191, 196)'
}); // Set color for active filter
} else if (filterType === 'expired') {
$('#expiredFilter').css({
'padding': '4px 8px',
'background-color': 'rgb(233, 233, 234)',
'color': 'rgb(191, 191, 196)'
}); // Set color for expired filter
} else if (filterType === 'all') {
$('#allFilter').css({
'padding': '4px 8px',
'background-color': 'rgb(233, 233, 234)',
'color': 'rgb(191, 191, 196)'
});
}
}
</script>
@endsection

View File

@@ -69,33 +69,39 @@
value="1" id="select-all-ids" />
<label class="form-check-label" for="select-all-ids">Send to unsubscribed
users who are in their respective states</label><br>
<div id="dropdown-1" style="display: none;">
<select class="form-select" aria-label="Default select example"
id="single" name="state">
<option value="">Select State</option>
@foreach ($state as $states)
<option value="{{ $states['id'] }}">{{ $states['name'] }}
</option>
@endforeach
</select>
<div id="dropdown-1"
style="display: none; max-height: 200px; overflow-y: auto;">
@foreach ($state as $states)
<div class="form-check">
<input class="form-check-input" type="checkbox" name="states[]"
value="{{ $states['id'] }}"
id="state-{{ $states['id'] }}" />
<label class="form-check-label"
for="state-{{ $states['id'] }}">{{ $states['name'] }}</label>
</div>
@endforeach
</div>
<input class="form-check-input" type="radio" name="user_type"
id="select-popular-ids" value="2" /><br>
<label class="form-check-label" for="select-popular-ids">Send to subscribed
users who are in their respective states</label><br>
<div id="dropdown-2" style="display: none;">
<select class="form-select" aria-label="Default select example"
id="single" name="state">
<option value="">Select State</option>
@foreach ($state as $states)
<option value="{{ $states['id'] }}">{{ $states['name'] }}
</option>
@endforeach
</select>
<div id="dropdown-2"
style="display: none; max-height: 200px; overflow-y: auto;">
@foreach ($state as $states)
<div class="form-check">
<input class="form-check-input" type="checkbox" name="states[]"
value="{{ $states['id'] }}"
id="state-{{ $states['id'] }}" />
<label class="form-check-label"
for="state-{{ $states['id'] }}">{{ $states['name'] }}</label>
</div>
@endforeach
</div>
</div>
</div>
</div>
<div class="col-md-12">
<button class="download-btn-custom mt-3 custom-width-10" type="submit"
id="store_notification_btn">