%PDF- %PDF-
Direktori : /var/www/html/hr/api/app/Models/ |
Current File : /var/www/html/hr/api/app/Models/Holiday.php |
<?php namespace App\Models; use Carbon\Carbon; use Illuminate\Support\Facades\DB; use Throwable; /** * @property integer id * @property string name * @property mixed date */ class Holiday extends BaseModel { /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'date', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'id' => 'integer', 'name' => 'string', 'date' => 'date', ]; /** * @param $data * @return Holiday * @throws Throwable */ public static function createItem($data) { try { DB::beginTransaction(); /** @var Holiday $day */ $day = self::query() ->create([ 'name' => $data['name'], 'date' => $data['date'], ]); DB::commit(); return $day; } catch (Throwable $e) { DB::rollBack(); throw $e; } } public static function getByYear($year = null) { if (!$year) { $year = Carbon::now()->year; } $start = Carbon::now() ->setYear($year) ->startOfYear(); $end = Carbon::now() ->setYear($year) ->endOfYear(); return Holiday::query() ->where('date', '>=', $start) ->where('date', '<=', $end) ->orderBy('date') ->get(); } public static function getHolidaysInDates($start, $end, $select = ['*']) { $holidays = self::query() ->where('date', '>=', $start) ->where('date', '<=', $end) ->orderBy('date') ->select($select) ->get(); $configurations = Configuration::getCurrent(); if ($configurations && $configurations->should_postpone_holidays) { foreach ($holidays as $holiday) { if (!Day::isWorkingDay($holiday->date)) { $holidays->push([ 'name' => "*$holiday->name", 'date' => Day::getNextWorkingDay($holiday->date), ]); } } } return $holidays; } }