⚝
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 :
EmployeePayrollRepository.php
<?php namespace App\Repositories; use App\Models\Accountant; use App\Models\EmployeePayroll; use App\Models\Notification; use App\Models\User; use DateTime; use Exception; use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Collection; use Illuminate\Database\Eloquent\Model; use Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException; /** * Class EmployeePayrollRepository * * @version February 19, 2020, 8:03 am UTC */ class EmployeePayrollRepository extends BaseRepository { /** * @var array */ protected $fieldSearchable = [ 'sr_no', 'payroll_id', 'owner_id', 'owner_type', 'month', 'year', 'net_salary', 'status', 'basic_salary', 'allowance', 'deductions', ]; /** * Return searchable fields */ public function getFieldsSearchable(): array { return $this->fieldSearchable; } /** * Configure the Model **/ public function model() { return EmployeePayroll::class; } public function create($input) { $input['basic_salary'] = $input['basic_salary']; $input['allowance'] = $input['allowance']; $input['deductions'] = $input['deductions']; $input['net_salary'] = $input['net_salary']; $input['month'] = DateTime::createFromFormat('!m', $input['month'])->format('F'); $input['owner_type'] = EmployeePayroll::CLASS_TYPES[$input['type']]; $employeePayroll = EmployeePayroll::create($input); return $employeePayroll; } /** * @return bool|Builder|Builder[]|Collection|Model */ public function update($input, $id) { $input['basic_salary'] = removeCommaFromNumbers($input['basic_salary']); $input['allowance'] = removeCommaFromNumbers($input['allowance']); $input['deductions'] = removeCommaFromNumbers($input['deductions']); $input['net_salary'] = removeCommaFromNumbers($input['net_salary']); $input['month'] = DateTime::createFromFormat('!m', $input['month'])->format('F'); $input['owner_type'] = EmployeePayroll::CLASS_TYPES[$input['type']]; parent::update($input, $id); return true; } public function createNotification(array $input) { $input['owner_type'] = EmployeePayroll::CLASS_TYPES[$input['type']]; try { $employee = User::where('owner_type', $input['owner_type'])->where('owner_id', $input['owner_id'])->first(); $accountant = Accountant::pluck('user_id', 'id')->toArray(); $userIds = [ $employee->id => Notification::NOTIFICATION_FOR[EmployeePayroll::TYPES[$input['type']]], ]; foreach ($accountant as $key => $userId) { $userIds[$userId] = Notification::NOTIFICATION_FOR[Notification::ACCOUNTANT]; } $users = getAllNotificationUser($userIds); foreach ($users as $key => $notification) { if ($notification == Notification::NOTIFICATION_FOR[EmployeePayroll::TYPES[$input['type']]]) { $title = $employee->full_name.' your employee payroll has been created.'; } else { $title = $employee->full_name.' employee payroll has been created.'; } addNotification([ Notification::NOTIFICATION_TYPE['Employee Payrolls'], $key, $notification, $title, ]); } } catch (Exception $e) { throw new UnprocessableEntityHttpException($e->getMessage()); } } }