This commit is contained in:
Cüneyt Şentürk 2021-06-19 23:02:07 +03:00
parent 5c5b890942
commit 62bb74d6a0
7 changed files with 187 additions and 79 deletions

View File

@ -3,21 +3,82 @@
namespace App\Http\Livewire\Common\Notifications; namespace App\Http\Livewire\Common\Notifications;
use App\Abstracts\Livewire\Document as Component; use App\Abstracts\Livewire\Document as Component;
use App\Models\Document\Document;
use Livewire\WithPagination; use Livewire\WithPagination;
use Illuminate\Support\Collection; use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Recurring extends Component class Recurring extends Component
{ {
use WithPagination; use WithPagination;
public function markRead($notification_id)
{
$notification = DatabaseNotification::find($notification_id);
$data = $notification->getAttribute('data');
$notification->markAsRead();
$this->dispatchBrowserEvent('mark-read', [
'type' => 'recurring-' . $this->type,
'message' => trans('notifications.messages.mark_read', ['type' => $data[$this->type . '_number']]),
]);
}
public function markReadAll()
{
$notifications = $this->getNotifications();
foreach ($notifications as $notification) {
$notification->markAsRead();
}
$this->dispatchBrowserEvent('mark-read-all', [
'type' => 'recurring-' . $this->type,
'message' => trans('notifications.messages.mark_read', ['type' => trans_choice('general.' . Str::plural($this->type) , 2)]),
]);
}
public function render() public function render()
{ {
$limit = 5; $limit = 5;
$documents = user()->notifications()->unread()->where('type', 'App\Notifications\Sale\Invoice')->paginate($limit);
$documents->setCollection(Collection::make([])); $notifications = getNotifications($limit);
return view('livewire.common.notifications.recurring', compact('documents')); return view('livewire.common.notifications.recurring', compact('notifications'));
}
protected function getNotifications($limit = false)
{
$type = config('type.' . $this->type . '.notification.class');
$query = user()->notifications()->unread()
->where('type', $type)
->where('data', 'like', '%template_alias:{$this->type}_recurring_admin%');
if ($limit) {
$notifications = $query->paginate($limit);
} else {
$notifications = $query->get();
}
if ($notifications->items()) {
$items = [];
foreach ($notifications->items() as $key => $notification) {
$data = (object) $notification->getAttribute('data');
$item = Document::{$this->type}()->where('id', $data[ $this->type'_id'])->first();
$item->notification_id = $notification->getAttribute('id');
$items[] = $item;
}
$notifications->setCollection(Collection::make($items));
}
return $notifications;
} }
public function paginationView() public function paginationView()

View File

@ -21,25 +21,21 @@ class Reminder extends Component
$notification->markAsRead(); $notification->markAsRead();
$this->dispatchBrowserEvent('mark-read', [ $this->dispatchBrowserEvent('mark-read', [
'type' => $this->type, 'type' => 'reminder-' . $this->type,
'message' => trans('notifications.messages.mark_read', ['type' => $data[$this->type . '_number']]), 'message' => trans('notifications.messages.mark_read', ['type' => $data[$this->type . '_number']]),
]); ]);
} }
public function markReadAll() public function markReadAll()
{ {
$type = config('type.' . $this->type . '.notification.class'); $notifications = $this->getNotifications();
$notifications = user()->notifications()->unread()
->where('type', $type)
->get();
foreach ($notifications as $notification) { foreach ($notifications as $notification) {
$notification->markAsRead(); $notification->markAsRead();
} }
$this->dispatchBrowserEvent('mark-read-all', [ $this->dispatchBrowserEvent('mark-read-all', [
'type' => $this->type, 'type' => 'reminder-' . $this->type,
'message' => trans('notifications.messages.mark_read', ['type' => trans_choice('general.' . Str::plural($this->type) , 2)]), 'message' => trans('notifications.messages.mark_read', ['type' => trans_choice('general.' . Str::plural($this->type) , 2)]),
]); ]);
} }
@ -48,28 +44,41 @@ class Reminder extends Component
{ {
$limit = 5; $limit = 5;
$notifications = getNotifications($limit);
return view('livewire.common.notifications.reminder', compact('notifications'));
}
protected function getNotifications($limit = false)
{
$type = config('type.' . $this->type . '.notification.class'); $type = config('type.' . $this->type . '.notification.class');
$documents = user()->notifications()->unread() $query = user()->notifications()->unread()
->where('type', $type) ->where('type', $type)
->where('data', 'like', '%template_alias:{$this->type}_remind_admin%') ->where('data', 'like', '%template_alias:{$this->type}_remind_admin%');
->paginate($limit);
$items = []; if ($limit) {
$notifications = $query->paginate($limit);
foreach ($documents->items() as $key => $document) { } else {
$data = $document->getAttribute('data'); $notifications = $query->get();
$item = Document::invoice()->where('id', $data['invoice_id'])->first();
$item->notification_id = $document->getAttribute('id');
$items[] = $item;
} }
$documents->setCollection(Collection::make($items)); if ($notifications->items()) {
$items = [];
return view('livewire.common.notifications.reminder', compact('documents')); foreach ($notifications->items() as $key => $notification) {
$data = (object) $notification->getAttribute('data');
$item = Document::{$this->type}()->where('id', $data[ $this->type'_id'])->first();
$item->notification_id = $notification->getAttribute('id');
$items[] = $item;
}
$notifications->setCollection(Collection::make($items));
}
return $notifications;
} }
public function paginationView() public function paginationView()

View File

@ -1,5 +1,5 @@
@if ($notifications->total()) @if ($notifications->total())
<div class="card" id="export"> <div class="card" id="exports">
<div class="card-header"> <div class="card-header">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-8"> <div class="col-8">

View File

@ -1,5 +1,5 @@
@if ($notifications->total()) @if ($notifications->total())
<div class="card" id="import"> <div class="card" id="imports">
<div class="card-header"> <div class="card-header">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-8"> <div class="col-8">
@ -31,7 +31,9 @@
'count' => $notification->total_rows 'count' => $notification->total_rows
]) !!} ]) !!}
@else @else
{!! $notification->message !!} @foreach ($notification->errors as $error)
{!! $error !!}
@endforeach
@endif @endif
</td> </td>

View File

@ -1,103 +1,110 @@
@if ($documents->count()) @if ($notifications->count())
<div class="card"> <div class="card" id="recurring-{{$type}}">
<div class="card-header"> <div class="card-header">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-8"> <div class="col-8">
<h5 class="h3 mb-0">Card title</h5> <h5 class="h3 mb-0">{{ trans($textTitle) }}</h5>
</div> </div>
<div class="col-4 text-right"> <div class="col-4 text-right">
<a href="#!" class="btn btn-sm btn-neutral">Action</a> <button type="button" class="btn btn-outline-success rounded-circle btn-icon-only btn-sm mr-2"
data-toggle="tooltip"
data-placement="right"
title="{{ trans('notifications.mark_read_all') }}"
wire:click="markReadAll()"
>
<span class="btn-inner--icon"><i class="fas fa-check-double"></i></span>
</button>
</div> </div>
</div> </div>
</div> </div>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-flush table-hover" id="tbl-reminder-invoices"> <table class="table table-flush table-hover" id="tbl-recurring-{{ $type }}">
<thead class="thead-light"> <thead class="thead-light">
<tr class="row table-head-line"> <tr class="row table-head-line">
@stack('document_number_th_start') @stack('document_number_th_start')
@if (!$hideDocumentNumber) @if (!$hideDocumentNumber)
<th class="{{ $classDocumentNumber }}"> <th class="{{ $classDocumentNumber }}">
@stack('document_number_th_inside_start') @stack('document_number_th_inside_start')
{{ trans_choice($textDocumentNumber, 1) }} {{ trans_choice($textDocumentNumber, 1) }}
@stack('document_number_th_inside_end') @stack('document_number_th_inside_end')
</th> </th>
@endif @endif
@stack('document_number_th_end') @stack('document_number_th_end')
@stack('contact_name_th_start') @stack('contact_name_th_start')
@if (!$hideContactName) @if (!$hideContactName)
<th class="{{ $classContactName }}"> <th class="{{ $classContactName }}">
@stack('contact_name_th_inside_start') @stack('contact_name_th_inside_start')
{{ trans_choice($textContactName, 1) }} {{ trans_choice($textContactName, 1) }}
@stack('contact_name_th_inside_end') @stack('contact_name_th_inside_end')
</th> </th>
@endif @endif
@stack('contact_name_th_end') @stack('contact_name_th_end')
@stack('amount_th_start') @stack('amount_th_start')
@if (!$hideAmount) @if (!$hideAmount)
<th class="{{ $classAmount }}"> <th class="{{ $classAmount }}">
@stack('amount_th_inside_start') @stack('amount_th_inside_start')
{{ trans('general.amount') }} {{ trans('general.amount') }}
@stack('amount_th_inside_end') @stack('amount_th_inside_end')
</th> </th>
@endif @endif
@stack('amount_th_end') @stack('amount_th_end')
@stack('issued_at_th_start') @stack('issued_at_th_start')
@if (!$hideIssuedAt) @if (!$hideIssuedAt)
<th class="{{ $classIssuedAt }}"> <th class="{{ $classIssuedAt }}">
@stack('issued_at_th_inside_start') @stack('issued_at_th_inside_start')
{{ trans($textIssuedAt) }} {{ trans($textIssuedAt) }}
@stack('issued_at_th_inside_end') @stack('issued_at_th_inside_end')
</th> </th>
@endif @endif
@stack('issued_at_th_end') @stack('issued_at_th_end')
@stack('due_at_th_start') @stack('due_at_th_start')
@if (!$hideDueAt) @if (!$hideDueAt)
<th class="{{ $classDueAt }}"> <th class="{{ $classDueAt }}">
@stack('due_at_th_inside_start') @stack('due_at_th_inside_start')
{{ trans($textDueAt) }} {{ trans($textDueAt) }}
@stack('due_at_th_inside_end') @stack('due_at_th_inside_end')
</th> </th>
@endif @endif
@stack('due_at_th_end') @stack('due_at_th_end')
@stack('status_th_start') @stack('status_th_start')
@if (!$hideStatus) @if (!$hideStatus)
<th class="{{ $classStatus }}"> <th class="{{ $classStatus }}">
@stack('status_th_inside_start') @stack('status_th_inside_start')
{{ trans_choice('general.statuses', 1) }} {{ trans_choice('general.statuses', 1) }}
@stack('status_th_inside_end') @stack('status_th_inside_end')
</th> </th>
@endif @endif
@stack('status_th_end') @stack('status_th_end')
@if (!$hideActions) @if (!$hideActions)
<th class="{{ $classActions }}"> <th class="{{ $classActions }}">
<a>{{ trans('general.actions') }}</a> <a>{{ trans_choice('notifications.reads', 1) }}</a>
</th> </th>
@endif @endif
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@foreach($documents as $item) @foreach($notifications as $item)
<tr class="row align-items-center border-top-1"> <tr class="row align-items-center border-top-1">
@stack('document_number_td_start') @stack('document_number_td_start')
@if (!$hideDocumentNumber) @if (!$hideDocumentNumber)
@ -146,34 +153,39 @@
</td> </td>
@endif @endif
@stack('issued_at_td_end') @stack('issued_at_td_end')
@stack('due_at_td_start') @stack('due_at_td_start')
@if (!$hideDueAt) @if (!$hideDueAt)
<td class="{{ $classDueAt }}"> <td class="{{ $classDueAt }}">
@stack('due_at_td_inside_start') @stack('due_at_td_inside_start')
@date($item->due_at) @date($item->due_at)
@stack('due_at_td_inside_end') @stack('due_at_td_inside_end')
</td> </td>
@endif @endif
@stack('due_at_td_end') @stack('due_at_td_end')
@stack('status_td_start') @stack('status_td_start')
@if (!$hideStatus) @if (!$hideStatus)
<td class="{{ $classStatus }}"> <td class="{{ $classStatus }}">
@stack('status_td_inside_start') @stack('status_td_inside_start')
<span class="badge badge-pill badge-{{ $item->status_label }}">{{ trans($textDocumentStatus . $item->status) }}</span> <span class="badge badge-pill badge-{{ $item->status_label }}">{{ trans($textDocumentStatus . $item->status) }}</span>
@stack('status_td_inside_end') @stack('status_td_inside_end')
</td> </td>
@endif @endif
@stack('status_td_end') @stack('status_td_end')
@if (!$hideActions) @if (!$hideActions)
<td class="{{ $classActions }}"> <td class="{{ $classActions }}">
<button type="button" class="btn btn-outline-success rounded-circle btn-icon-only btn-sm"> <button type="button" class="btn btn-outline-success rounded-circle btn-icon-only btn-sm"
data-toggle="tooltip"
data-placement="right"
title="{{ trans('notifications.mark_read') }}"
wire:click="markRead('{{ $item->notification_id }}')"
>
<span class="btn-inner--icon"><i class="fa fa-check"></i></span> <span class="btn-inner--icon"><i class="fa fa-check"></i></span>
</button> </button>
</td> </td>
@ -184,21 +196,21 @@
</table> </table>
</div> </div>
@if ($documents->total() > 5) @if ($notifications->total() > 5)
<div class="card-footer table-action"> <div class="card-footer table-action">
<div class="row"> <div class="row">
@if ($documents->count()) @if ($notifications->count())
<div class="col-xs-12 col-sm-5 d-flex align-items-center"> <div class="col-xs-12 col-sm-5 d-flex align-items-center">
{!! Form::select('limit', ['5' => '5'], request('limit', setting('default.list_limit', '25')), ['class' => 'disabled form-control form-control-sm d-inline-block w-auto d-none d-md-block', 'disabled' => 'disabled']) !!} {!! Form::select('limit', ['5' => '5'], request('limit', 5), ['class' => 'disabled form-control form-control-sm d-inline-block w-auto d-none d-md-block', 'disabled' => 'disabled']) !!}
<span class="table-text d-none d-lg-block ml-2"> <span class="table-text d-none d-lg-block ml-2">
{{ trans('pagination.page') }} {{ trans('pagination.page') }}
{{ trans('pagination.showing', ['first' => $documents->firstItem(), 'last' => $documents->lastItem(), 'total' => $documents->total()]) }} {{ trans('pagination.showing', ['first' => $notifications->firstItem(), 'last' => $notifications->lastItem(), 'total' => $notifications->total()]) }}
</span> </span>
</div> </div>
<div class="col-xs-12 col-sm-7 pagination-xs"> <div class="col-xs-12 col-sm-7 pagination-xs">
<nav class="float-right"> <nav class="float-right">
{!! $documents->withPath(request()->url())->withQueryString()->links() !!} {!! $notifications->withPath(request()->url())->withQueryString()->links() !!}
</nav> </nav>
</div> </div>
@else @else
@ -210,4 +222,28 @@
</div> </div>
@endif @endif
</div> </div>
@endif @endif
@push('scripts_start')
<script src="{{ asset('public/vendor/bootstrap-notify/bootstrap-notify.min.js') }}"></script>
@endpush
@push('body_js')
<script type="text/javascript">
window.addEventListener('mark-read', event => {
if (event.detail.type == 'recurring-{{ $type }}') {
$.notify(event.detail.message, {
type: 'success',
});
}
});
window.addEventListener('mark-read-all', event => {
if (event.detail.type == 'recurring-{{ $type }}') {
$.notify(event.detail.message, {
type: 'success',
});
}
});
</script>
@endpush

View File

@ -1,5 +1,5 @@
@if ($documents->count()) @if ($notifications->count())
<div class="card"> <div class="card" id="reminder-{{$type}}">
<div class="card-header"> <div class="card-header">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-8"> <div class="col-8">
@ -104,7 +104,7 @@
</thead> </thead>
<tbody> <tbody>
@foreach($documents as $item) @foreach($notifications as $item)
<tr class="row align-items-center border-top-1"> <tr class="row align-items-center border-top-1">
@stack('document_number_td_start') @stack('document_number_td_start')
@if (!$hideDocumentNumber) @if (!$hideDocumentNumber)
@ -196,21 +196,21 @@
</table> </table>
</div> </div>
@if ($documents->total() > 5) @if ($notifications->total() > 5)
<div class="card-footer table-action"> <div class="card-footer table-action">
<div class="row"> <div class="row">
@if ($documents->count()) @if ($notifications->count())
<div class="col-xs-12 col-sm-5 d-flex align-items-center"> <div class="col-xs-12 col-sm-5 d-flex align-items-center">
{!! Form::select('limit', ['5' => '5'], request('limit', 5), ['class' => 'disabled form-control form-control-sm d-inline-block w-auto d-none d-md-block', 'disabled' => 'disabled']) !!} {!! Form::select('limit', ['5' => '5'], request('limit', 5), ['class' => 'disabled form-control form-control-sm d-inline-block w-auto d-none d-md-block', 'disabled' => 'disabled']) !!}
<span class="table-text d-none d-lg-block ml-2"> <span class="table-text d-none d-lg-block ml-2">
{{ trans('pagination.page') }} {{ trans('pagination.page') }}
{{ trans('pagination.showing', ['first' => $documents->firstItem(), 'last' => $documents->lastItem(), 'total' => $documents->total()]) }} {{ trans('pagination.showing', ['first' => $notifications->firstItem(), 'last' => $notifications->lastItem(), 'total' => $notifications->total()]) }}
</span> </span>
</div> </div>
<div class="col-xs-12 col-sm-7 pagination-xs"> <div class="col-xs-12 col-sm-7 pagination-xs">
<nav class="float-right"> <nav class="float-right">
{!! $documents->withPath(request()->url())->withQueryString()->links() !!} {!! $notifications->withPath(request()->url())->withQueryString()->links() !!}
</nav> </nav>
</div> </div>
@else @else
@ -231,7 +231,7 @@
@push('body_js') @push('body_js')
<script type="text/javascript"> <script type="text/javascript">
window.addEventListener('mark-read', event => { window.addEventListener('mark-read', event => {
if (event.detail.type == '{{ $type }}') { if (event.detail.type == 'reminder-{{ $type }}') {
$.notify(event.detail.message, { $.notify(event.detail.message, {
type: 'success', type: 'success',
}); });
@ -239,7 +239,7 @@
}); });
window.addEventListener('mark-read-all', event => { window.addEventListener('mark-read-all', event => {
if (event.detail.type == '{{ $type }}') { if (event.detail.type == 'reminder-{{ $type }}') {
$.notify(event.detail.message, { $.notify(event.detail.message, {
type: 'success', type: 'success',
}); });

View File

@ -226,7 +226,7 @@
@can('read-purchases-bills') @can('read-purchases-bills')
@if (count($bills)) @if (count($bills))
<a href="{{ route('notifications.index') . '#reminder-bills' }}" class="list-group-item list-group-item-action"> <a href="{{ route('notifications.index') . '#reminder-bill' }}" class="list-group-item list-group-item-action">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-auto"> <div class="col-auto">
<i class="fa fa-shopping-cart"></i> <i class="fa fa-shopping-cart"></i>
@ -247,7 +247,7 @@
@can('read-sales-invoices') @can('read-sales-invoices')
@if (count($invoices)) @if (count($invoices))
<a href="{{ route('notifications.index') . '#reminder-invoices' }}" class="list-group-item list-group-item-action"> <a href="{{ route('notifications.index') . '#reminder-invoice' }}" class="list-group-item list-group-item-action">
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-auto"> <div class="col-auto">
<i class="fa fa-money-bill"></i> <i class="fa fa-money-bill"></i>