⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.19
Server IP:
178.33.27.10
Server:
Linux cpanel.dev-unit.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
Server Software:
Apache/2.4.57 (Unix) OpenSSL/1.0.2k-fips
PHP Version:
8.2.11
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
id
/
hospital.dev-unit.com
/
app
/
Repositories
/
View File Name :
ExpenseRepository.php
<?php namespace App\Repositories; use App\Models\Accountant; use App\Models\Expense; use App\Models\Notification; use App\Models\User; use Exception; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class ExpenseRepository */ class ExpenseRepository extends BaseRepository { /** * @var string[] */ protected $fieldSearchable = [ 'expense_head', 'name', 'invoice_number', 'date', 'amount', 'description', ]; /** * @return array|string[] */ public function getFieldsSearchable() { return $this->fieldSearchable; } public function model(): string { return Expense::class; } public function store($input): bool { try { /** @var Expense $expense */ $expense = $this->create($input); if (! empty($input['attachment'])) { $expense->addMedia($input['attachment'])->toMediaCollection(Expense::PATH, config('app.media_disc')); } return true; } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } public function updateExpense(array $input, int $expenseId) { try { /** @var Expense $expense */ $input['amount'] = removeCommaFromNumbers($input['amount']); $expense = $this->update($input, $expenseId); if (! empty($input['attachment'])) { $expense->clearMediaCollection(Expense::PATH); $expense->addMedia($input['attachment'])->toMediaCollection(Expense::PATH, config('app.media_disc')); } if ($input['avatar_remove'] == 1 && isset($input['avatar_remove']) && ! empty($input['avatar_remove'])) { removeFile($expense, Expense::PATH); } } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } public function deleteDocument(int $expenseId) { try { /** @var Expense $expense */ $expense = $this->find($expenseId); $expense->clearMediaCollection(Expense::PATH); $this->delete($expenseId); } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } public function createNotification(array $input) { try { $userIds = []; $accountant = Accountant::pluck('user_id', 'id')->toArray(); foreach ($accountant as $key => $userId) { $userIds[$userId] = Notification::NOTIFICATION_FOR[Notification::ACCOUNTANT]; } $adminUser = User::role('Admin')->first(); $allUsers = $userIds + [$adminUser->id => Notification::NOTIFICATION_FOR[Notification::ADMIN]]; $users = getAllNotificationUser($allUsers); foreach ($users as $key => $notification) { addNotification([ Notification::NOTIFICATION_TYPE['Expense'], $key, $notification, Expense::EXPENSE_HEAD[$input['expense_head']].' expense added.', ]); } } catch (Exception $e) { Notification::make() ->danger() ->title($e->getMessage()) ->error(); } } }