akaunting 3.0 (the last dance)

This commit is contained in:
Burak Civan
2022-06-01 10:15:55 +03:00
parent cead09f6d4
commit d9c0764572
3812 changed files with 126831 additions and 102949 deletions

View File

@ -1,91 +0,0 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Exports extends Component
{
use WithPagination;
protected $listeners = [
'refreshParent' => '$notifications',
];
public function markRead($notification_id)
{
$notification = DatabaseNotification::find($notification_id);
$data = $notification->getAttribute('data');
$notification->markAsRead();
$type = isset($data['file_name']) ?: trans('general.export');
$this->dispatchBrowserEvent('mark-read', [
'type' => 'export',
'message' => trans('notifications.messages.mark_read', ['type' => $type]),
]);
}
public function markReadAll()
{
$notifications = $this->getNotifications();
foreach ($notifications as $notification) {
$notification->markAsRead();
}
$this->dispatchBrowserEvent('mark-read-all', [
'type' => 'export',
'message' => trans('notifications.messages.mark_read_all', ['type' => trans('general.export')]),
]);
}
public function render()
{
$limit = 5;
$notifications = $this->getNotifications($limit);
return view('livewire.common.notifications.exports', compact('notifications'));
}
protected function getNotifications($limit = false)
{
$query = user()->notifications()->unread()
->where(function ($query) {
$query->where('type', 'App\Notifications\Common\ExportCompleted')
->orWhere('type', 'App\Notifications\Common\ExportFailed');
});
if ($limit) {
$notifications = $query->paginate($limit);
} else {
$notifications = $query->get();
}
if ($notifications) {
$items = [];
foreach ($notifications as $key => $notification) {
$data = (object) $notification->getAttribute('data');
$data->notification_id = $notification->getAttribute('id');
$items[] = $data;
}
$notifications->setCollection(Collection::make($items));
}
return $notifications;
}
public function paginationView()
{
return 'vendor.livewire.default';
}
}

View File

@ -1,91 +0,0 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Imports extends Component
{
use WithPagination;
protected $listeners = [
'refreshParent' => '$notifications',
];
public function markRead($notification_id)
{
$notification = DatabaseNotification::find($notification_id);
$data = $notification->getAttribute('data');
$notification->markAsRead();
$type = isset($data['translation']) ?: trans('import.import');
$this->dispatchBrowserEvent('mark-read', [
'type' => 'import',
'message' => trans('notifications.messages.mark_read', ['type' => $type]),
]);
}
public function markReadAll()
{
$notifications = $this->getNotifications();
foreach ($notifications as $notification) {
$notification->markAsRead();
}
$this->dispatchBrowserEvent('mark-read-all', [
'type' => 'import',
'message' => trans('notifications.messages.mark_read_all', ['type' => trans('import.import')]),
]);
}
public function render()
{
$limit = 5;
$notifications = $this->getNotifications($limit);
return view('livewire.common.notifications.imports', compact('notifications'));
}
protected function getNotifications($limit = false)
{
$query = user()->notifications()->unread()
->where(function ($query) {
$query->where('type', 'App\Notifications\Common\ImportCompleted')
->orWhere('type', 'App\Notifications\Common\ImportFailed');
});
if ($limit) {
$notifications = $query->paginate($limit);
} else {
$notifications = $query->get();
}
if ($notifications) {
$items = [];
foreach ($notifications as $key => $notification) {
$data = (object) $notification->getAttribute('data');
$data->notification_id = $notification->getAttribute('id');
$items[] = $data;
}
$notifications->setCollection(Collection::make($items));
}
return $notifications;
}
public function paginationView()
{
return 'vendor.livewire.default';
}
}

View File

@ -1,107 +0,0 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use App\Traits\Modules;
use App\Utilities\Date;
use Livewire\Component;
class NewApps extends Component
{
use Modules;
public function markRead($alias)
{
$notifications = $this->getNotifications('new-apps');
foreach ($notifications as $notification) {
if ($notification->alias != $alias) {
continue;
}
$read = $notification;
}
$prefix = 'notifications.' . user()->id . '.' . $alias;
setting()->set([
$prefix . '.name' => $read->name,
$prefix . '.message' => $read->alias,
$prefix . '.date' => Date::now(),
$prefix . '.status' => '0',
]);
setting()->save();
$this->dispatchBrowserEvent('mark-read', [
'type' => 'new-apps',
'message' => trans('notifications.messages.mark_read', ['type' => $read->name]),
]);
}
public function markReadAll()
{
$notifications = $this->getNotifications('new-apps');
foreach ($notifications as $notification) {
$prefix = 'notifications.' . user()->id . '.' . $notification->alias;
setting()->set([
$prefix . '.name' => $notification->name,
$prefix . '.message' => $notification->alias,
$prefix . '.date' => Date::now(),
$prefix . '.status' => '0',
]);
}
setting()->save();
$this->dispatchBrowserEvent('mark-read-all', [
'type' => 'new-apps',
'message' => trans('notifications.messages.mark_read_all', ['type' => trans_choice('notifications.new_apps', 2)]),
]);
}
public function render()
{
$notifications = $this->getNotifications('new-apps');
$this->clearReadNotifications($notifications);
return view('livewire.common.notifications.new-apps', compact('notifications'));
}
protected function clearReadNotifications(&$notifications)
{
$hide_notifications = setting('notifications.' . user()->id);
if (!$hide_notifications) {
return;
}
if (!$notifications) {
return;
}
$aliases = [];
// MarkRead app notification
foreach ($notifications as $index => $notification) {
$aliases[] = $notification->alias;
if (setting('notifications.' . user()->id . '.' . $notification->alias)) {
unset($notifications[$index]);
}
}
// Clear setting table missing notification
foreach ($hide_notifications as $alias => $hide_notification) {
if (in_array($alias, $aliases)) {
continue;
}
setting()->forget('notifications.' . user()->id . '.' . $alias);
setting()->save();
}
}
}

View File

@ -1,88 +0,0 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use App\Abstracts\Livewire\Document as Component;
use App\Models\Document\Document;
use Livewire\WithPagination;
use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Recurring extends Component
{
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()
{
$limit = 5;
$notifications = $this->getNotifications($limit);
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 = [];
foreach ($notifications 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()
{
return 'vendor.livewire.default';
}
}

View File

@ -1,88 +0,0 @@
<?php
namespace App\Http\Livewire\Common\Notifications;
use App\Abstracts\Livewire\Document as Component;
use App\Models\Document\Document;
use Livewire\WithPagination;
use Illuminate\Support\Collection;
use Illuminate\Notifications\DatabaseNotification;
use Illuminate\Support\Str;
class Reminder extends Component
{
use WithPagination;
public function markRead($notification_id)
{
$notification = DatabaseNotification::find($notification_id);
$data = $notification->getAttribute('data');
$notification->markAsRead();
$this->dispatchBrowserEvent('mark-read', [
'type' => 'reminder-' . $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' => 'reminder-' . $this->type,
'message' => trans('notifications.messages.mark_read', ['type' => trans_choice('general.' . Str::plural($this->type) , 2)]),
]);
}
public function render()
{
$limit = 5;
$notifications = $this->getNotifications($limit);
return view('livewire.common.notifications.reminder', 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}_remind_admin%');
if ($limit) {
$notifications = $query->paginate($limit);
} else {
$notifications = $query->get();
}
if ($notifications) {
$items = [];
foreach ($notifications 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()
{
return 'vendor.livewire.default';
}
}