migrate to gtea from bistbucket

This commit is contained in:
2026-03-15 17:08:23 +07:00
commit 129ca2260c
3716 changed files with 566316 additions and 0 deletions

View File

@@ -0,0 +1,242 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Carbon\Carbon;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\DB;
use Modules\HRM\Models\Attendance;
use Modules\HRM\Models\AttendanceLog;
class AttendanceRepository extends EntityRepository
{
public string $table = Attendance::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'date',
'first_clock_in',
'last_clock_out',
'hours_worked',
'status',
'breaks',
'notes',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
return array_merge([
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
], $filterData);
}
public function getAttendanceQuery(): EloquentBuilder
{
return Attendance::with(['employee', 'logs']);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getAttendanceQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* CREATE ATTENDANCE + LOGS
*/
public function create(array $data): Attendance
{
return DB::transaction(function () use ($data) {
$date = $data['date'];
$employee = $data['employee_id'];
// Always fetch today attendance or create new
$attendance = Attendance::firstOrNew([
'employee_id' => $employee,
'date' => $date,
]);
$prepared = $this->prepareForDB($data, $attendance->exists ? $attendance : null);
// Save attendance
$attendance->fill($prepared)->save();
// Insert Punch Logs
if (! empty($data['clock_in'])) {
$this->insertLog($attendance, 'in', $data['clock_in']);
}
if (! empty($data['clock_out'])) {
$this->insertLog($attendance, 'out', $data['clock_out']);
}
// Recalculate working hours after logs
$this->recalculateWorkedHours($attendance);
return $attendance;
});
}
/**
* UPDATE ATTENDANCE + REBUILD LOGS
*/
public function update(int $id, array $data): object
{
return DB::transaction(function () use ($id, $data) {
$attendance = Attendance::findOrFail($id);
$prepared = $this->prepareForDB($data, $attendance);
$attendance->update($prepared);
// Remove old logs
AttendanceLog::where('attendance_id', $id)->delete();
// Add new logs
if (! empty($data['clock_in'])) {
$this->insertLog($attendance, 'in', $data['clock_in']);
}
if (! empty($data['clock_out'])) {
$this->insertLog($attendance, 'out', $data['clock_out']);
}
$this->recalculateWorkedHours($attendance);
return $this->getById($id);
});
}
/**
* MAP REQUEST TO DB FIELDS
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (! $item) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
} else {
$data['updated_at'] = now();
}
if (isset($data['clock_in'])) {
$data['first_clock_in'] = $data['clock_in'];
unset($data['clock_in']);
}
if (isset($data['clock_out'])) {
$data['last_clock_out'] = $data['clock_out'];
unset($data['clock_out']);
}
if (isset($data['breaks']) && is_array($data['breaks'])) {
$data['breaks'] = json_encode($data['breaks']);
}
if (isset($data['notes']) && is_array($data['notes'])) {
$data['notes'] = json_encode($data['notes']);
}
return $data;
}
/**
* INSERT SINGLE PUNCH LOG ENTRY
*/
private function insertLog(Attendance $attendance, string $type, string $time)
{
if (empty($time)) {
return;
}
$dateTime = Carbon::parse($attendance->date.' '.$time)->format('Y-m-d H:i:s');
AttendanceLog::create([
'attendance_id' => $attendance->id,
'employee_id' => $attendance->employee_id,
'restaurant_id' => $attendance->restaurant_id,
'type' => $type, // in or out
'punch_time' => $dateTime,
'created_at' => now(),
]);
}
/**
* RECALCULATE TOTAL WORKED HOURS BASED ON ALL LOGS
*/
private function recalculateWorkedHours(Attendance $attendance)
{
$logs = AttendanceLog::where('attendance_id', $attendance->id)
->orderBy('punch_time')
->get();
if ($logs->count() < 2) {
return;
}
$first = Carbon::parse($logs->first()->punch_time);
$last = Carbon::parse($logs->last()->punch_time);
$hours = round($first->diffInMinutes($last) / 60, 2);
$attendance->update([
'first_clock_in' => $first,
'last_clock_out' => $last,
'hours_worked' => $hours,
]);
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Attendance does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Attendance could not be deleted.',
];
}
}

View File

@@ -0,0 +1,177 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Award;
use Symfony\Component\HttpFoundation\Response;
class AwardRepository extends EntityRepository
{
public string $table = Award::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'title',
'description',
'date_awarded',
'amount',
'award_type',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getAwardQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.employee_id",
'users.first_name',
'users.last_name',
'departments.name as department_name',
'designations.title as designation_title',
"{$this->table}.title",
"{$this->table}.description",
"{$this->table}.date_awarded",
"{$this->table}.amount",
"{$this->table}.award_type",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('users', "{$this->table}.employee_id", '=', 'users.id')
->leftJoin('departments', 'users.department_id', '=', 'departments.id')
->leftJoin('designations', 'users.designation_id', '=', 'designations.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.title", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getAwardQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getAwardQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Award::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Award::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Award does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Award could not be deleted.',
];
}
}

View File

@@ -0,0 +1,176 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Candidate;
use Symfony\Component\HttpFoundation\Response;
class CandidateRepository extends EntityRepository
{
public string $table = Candidate::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'recruitment_id',
'first_name',
'last_name',
'email',
'phone',
'resume',
'cover_letter',
'status',
'notes',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getCandidateQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.recruitment_id",
'recruitments.title as recruitment_title',
"{$this->table}.first_name",
"{$this->table}.last_name",
"{$this->table}.email",
"{$this->table}.phone",
"{$this->table}.resume",
"{$this->table}.cover_letter",
"{$this->table}.status",
"{$this->table}.notes",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('recruitments', "{$this->table}.recruitment_id", '=', 'recruitments.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.first_name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getCandidateQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getCandidateQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Candidate::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Candidate::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Candidate does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Candidate could not be deleted.',
];
}
}

View File

@@ -0,0 +1,166 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Department;
use Symfony\Component\HttpFoundation\Response;
class DepartmentRepository extends EntityRepository
{
public string $table = Department::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'parent_id',
'name',
'description',
'status',
'meta',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getDepartmentQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.parent_id",
"{$this->table}.name",
"{$this->table}.description",
"{$this->table}.status",
"{$this->table}.meta",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getDepartmentQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getDepartmentQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Department::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Department::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Department does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Department could not be deleted.',
];
}
}

View File

@@ -0,0 +1,168 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Designation;
use Symfony\Component\HttpFoundation\Response;
class DesignationRepository extends EntityRepository
{
public string $table = Designation::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'department_id',
'title',
'description',
'status',
'meta',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getDesignationQuery(): Builder
{
return $this->getQuery()
->leftJoin('departments', "{$this->table}.department_id", '=', 'departments.id')
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.department_id",
'departments.name as department_name', // joined department name
"{$this->table}.title",
"{$this->table}.description",
"{$this->table}.status",
"{$this->table}.meta",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.title", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getDesignationQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getDesignationQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Designation::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Designation::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Designation does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Designation could not be deleted.',
];
}
}

View File

@@ -0,0 +1,283 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Facades\Hash;
use Modules\HRM\Models\Employee;
use Symfony\Component\HttpFoundation\Response;
class EmployeeRepository extends EntityRepository
{
public string $table = Employee::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'first_name',
'last_name',
'username',
'email',
'phone',
'password',
'otp_code',
'isVerified',
'email_verified_at',
'address',
'avatar',
'role_id',
'user_type',
'facebook',
'twitter',
'linkedin',
'google_plus',
'nid',
'platform',
'device_info',
'last_active_time',
'status',
'department_id',
'designation_id',
'salary_type_id',
'address',
'gender',
'date_of_birth',
'joining_date',
'basic_salary',
'created_by',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getUserQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (isset($filter['search']) && strlen($filter['search']) > 0) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getUserQuery(): Builder
{
return $this->getQuery()
->leftJoin('departments', "{$this->table}.department_id", '=', 'departments.id')
->leftJoin('designations', "{$this->table}.designation_id", '=', 'designations.id')
->select(
'users.id',
'users.restaurant_id',
"{$this->table}.department_id",
'departments.name as department_name', // join department
"{$this->table}.designation_id",
'designations.title as designation_title', // join designation
'users.first_name',
'users.last_name',
'users.username',
'users.email',
'users.phone',
'users.isVerified',
'users.email_verified_at',
'users.address',
'users.avatar',
'users.role_id',
'users.user_type',
'users.facebook',
'users.twitter',
'users.linkedin',
'users.google_plus',
'users.nid',
'users.platform',
'users.device_info',
'users.last_active_time',
'users.status',
'users.department_id',
'users.designation_id',
'users.salary_type_id',
'users.address',
'users.gender',
'users.date_of_birth',
'users.joining_date',
'users.basic_salary',
'users.created_by',
'users.deleted_at'
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where('users.first_name', 'LIKE', $searchable)
->orWhere('users.last_name', 'LIKE', $searchable)
->orWhere('users.email', 'LIKE', $searchable)
->orWhere('users.phone', 'LIKE', $searchable)
->orWhere('users.status', 'LIKE', $searchable);
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$user = $this->getUserQuery()
->where($columnName, $columnValue)
->first();
if (empty($user)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $user;
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function create(array $data): object
{
try {
$data['password'] = empty($data['password']) ? '123456' : $data['password'];
$data = $this->prepareForDB($data);
$userId = $this->getQuery()->insertGetId($data);
$user = Employee::find($userId);
return $user;
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['created_by'] = $this->getCurrentUserId();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['avatar']) && $data['avatar'] instanceof \Illuminate\Http\UploadedFile) {
$data['avatar'] = fileUploader('users/', 'png', $data['avatar']);
}
} else {
if (! empty($data['avatar']) && $data['avatar'] instanceof \Illuminate\Http\UploadedFile) {
$data['avatar'] = fileUploader('users/', 'png', $data['avatar'], $item->avatar);
}
$data['updated_at'] = now();
}
if (! empty($data['password'])) {
$data['password'] = Hash::make($data['password']);
} else {
unset($data['password']);
}
return $data;
}
/**
* @throws Exception
*/
public function update(int $id, array $data): ?object
{
try {
$user = Employee::find($id);
$data = $this->prepareForDB($data, $user);
parent::update($id, $data);
return $this->getById($user->id);
} catch (Exception $exception) {
throw new Exception($exception->getMessage(), Response::HTTP_INTERNAL_SERVER_ERROR);
}
}
/**
* @throws Exception
*/
public function getDropdown(): array
{
$dropdowns = parent::getDropdown();
$dropdownsData = [];
foreach ($dropdowns as $dropdownItem) {
$dropdownItem->name = $dropdownItem->first_name.' '.$dropdownItem->last_name.' #'.$dropdownItem->id;
unset($dropdownItem->first_name, $dropdownItem->last_name, $dropdownItem->phone);
$dropdownsData[] = $dropdownItem;
}
return $dropdownsData;
}
protected function getExceptionMessages(): array
{
$exceptionMessages = parent::getExceptionMessages();
$userExceptionMessages = [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Employee does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Employee could not be deleted.',
];
return array_merge($exceptionMessages, $userExceptionMessages);
}
protected function getDropdownSelectableColumns(): array
{
return [
'first_name',
'last_name',
];
}
protected function getOrderByColumnWithOrders(): array
{
return [
'first_name' => 'asc',
];
}
}

View File

@@ -0,0 +1,189 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\EmployeeSalary;
use Symfony\Component\HttpFoundation\Response;
class EmployeeSalaryRepository extends EntityRepository
{
public string $table = EmployeeSalary::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'salary_month',
'basic_salary',
'allowances',
'deductions',
'overtime_hours',
'overtime_rate',
'bonus',
'net_salary',
'payment_date',
'remarks',
'status',
'salary_breakdown',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getEmployeeSalaryQuery(): Builder
{
return $this->getQuery()
->leftJoin('users', "{$this->table}.employee_id", '=', 'users.id')
->leftJoin('departments', 'users.department_id', '=', 'departments.id')
->leftJoin('designations', 'users.designation_id', '=', 'designations.id')
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.employee_id",
'users.first_name',
'users.last_name',
'departments.name as department_name',
'designations.title as designation_title',
"{$this->table}.salary_month",
"{$this->table}.basic_salary",
"{$this->table}.allowances",
"{$this->table}.deductions",
"{$this->table}.overtime_hours",
"{$this->table}.overtime_rate",
"{$this->table}.bonus",
"{$this->table}.net_salary",
"{$this->table}.payment_date",
"{$this->table}.remarks",
"{$this->table}.status",
"{$this->table}.salary_breakdown",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getEmployeeSalaryQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getEmployeeSalaryQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return EmployeeSalary::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = EmployeeSalary::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['salary_breakdown'] = json_encode($data['salary_breakdown']);
} else {
$data['salary_breakdown'] = json_encode($data['salary_breakdown']);
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'EmployeeSalary does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'EmployeeSalary could not be deleted.',
];
}
}

View File

@@ -0,0 +1,177 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\EmployeeShiftAssignment;
use Symfony\Component\HttpFoundation\Response;
class EmployeeShiftAssignmentRepository extends EntityRepository
{
public string $table = EmployeeShiftAssignment::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'shift_id',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getEmployeeShiftAssignmentQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.employee_id",
'users.first_name',
'users.last_name',
"{$this->table}.shift_id",
'shifts.name as shift_name',
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('users', 'users.id', '=', "{$this->table}.employee_id")
->leftJoin('shifts', 'shifts.id', '=', "{$this->table}.shift_id");
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.employee_id", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getEmployeeShiftAssignmentQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getEmployeeShiftAssignmentQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return EmployeeShiftAssignment::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = EmployeeShiftAssignment::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('HRM/', 'png', $data['image']);
}
} else {
if (! empty($data['image']) && $data['image'] instanceof \Illuminate\Http\UploadedFile) {
$data['image'] = fileUploader('HRM/', 'png', $data['image'], $item->image);
}
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'EmployeeShiftAssignment does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'EmployeeShiftAssignment could not be deleted.',
];
}
}

View File

@@ -0,0 +1,176 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Interview;
use Symfony\Component\HttpFoundation\Response;
class InterviewRepository extends EntityRepository
{
public string $table = Interview::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'candidate_id',
'department_id',
'interview_date',
'interviewer_name',
'feedback',
'rating',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getInterviewQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.candidate_id",
'candidates.first_name as candidate_first_name',
'candidates.last_name as candidate_last_name',
'recruitments.title as recruitment_title',
"{$this->table}.department_id",
'departments.name as department_name',
"{$this->table}.interview_date",
"{$this->table}.interviewer_name",
"{$this->table}.feedback",
"{$this->table}.rating",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('candidates', "{$this->table}.candidate_id", '=', 'candidates.id')
->leftJoin('recruitments', 'candidates.recruitment_id', '=', 'recruitments.id')
->leftJoin('departments', "{$this->table}.department_id", '=', 'departments.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getInterviewQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getInterviewQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Interview::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Interview::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Interview does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Interview could not be deleted.',
];
}
}

View File

@@ -0,0 +1,187 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\LeaveApplication;
use Symfony\Component\HttpFoundation\Response;
class LeaveApplicationRepository extends EntityRepository
{
public string $table = LeaveApplication::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'leave_type_id',
'start_date',
'end_date',
'reason',
'admin_note',
'status',
'approved_by',
'leave_duration_type',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getLeaveApplicationQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
'restaurants.name as restaurant_name',
"{$this->table}.employee_id",
'users.first_name',
'users.last_name',
'departments.name as department_name',
'designations.title as designation_title',
"{$this->table}.leave_type_id",
'leave_types.name as leave_type_name',
"{$this->table}.start_date",
"{$this->table}.end_date",
"{$this->table}.reason",
"{$this->table}.admin_note",
"{$this->table}.approved_by",
'approvers.first_name as approved_by_name',
"{$this->table}.leave_duration_type",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('users', "{$this->table}.employee_id", '=', 'users.id')
->leftJoin('departments', 'users.department_id', '=', 'departments.id')
->leftJoin('designations', 'users.designation_id', '=', 'designations.id')
->leftJoin('leave_types', "{$this->table}.leave_type_id", '=', 'leave_types.id')
->leftJoin('users as approvers', "{$this->table}.approved_by", '=', 'approvers.id')
->leftJoin('restaurants', "{$this->table}.restaurant_id", '=', 'restaurants.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getLeaveApplicationQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getLeaveApplicationQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return LeaveApplication::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = LeaveApplication::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'LeaveApplication does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'LeaveApplication could not be deleted.',
];
}
}

View File

@@ -0,0 +1,168 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\LeaveType;
use Symfony\Component\HttpFoundation\Response;
class LeaveTypeRepository extends EntityRepository
{
public string $table = LeaveType::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'max_days',
'carry_forward',
'is_paid',
'status',
'description',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getLeaveTypeQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.max_days",
"{$this->table}.carry_forward",
"{$this->table}.is_paid",
"{$this->table}.status",
"{$this->table}.description",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getLeaveTypeQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getLeaveTypeQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return LeaveType::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = LeaveType::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'LeaveType does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'LeaveType could not be deleted.',
];
}
}

View File

@@ -0,0 +1,185 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\LoanInstallment;
use Symfony\Component\HttpFoundation\Response;
class LoanInstallmentRepository extends EntityRepository
{
public string $table = LoanInstallment::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'loan_id',
'amount',
'due_date',
'paid_date',
'is_paid',
'is_overdue',
'fine_amount',
'total_due',
'status',
'remarks',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getLoanInstallmentQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.loan_id",
'loans.employee_id',
'users.first_name',
'users.last_name',
'departments.name as department_name',
'designations.title as designation_title',
"{$this->table}.amount",
"{$this->table}.due_date",
"{$this->table}.paid_date",
"{$this->table}.is_paid",
"{$this->table}.is_overdue",
"{$this->table}.fine_amount",
"{$this->table}.total_due",
"{$this->table}.remarks",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('loans', "{$this->table}.loan_id", '=', 'loans.id')
->leftJoin('users', 'loans.employee_id', '=', 'users.id')
->leftJoin('departments', 'users.department_id', '=', 'departments.id')
->leftJoin('designations', 'users.designation_id', '=', 'designations.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.loan_id", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getLoanInstallmentQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getLoanInstallmentQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return LoanInstallment::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = LoanInstallment::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'LoanInstallment does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'LoanInstallment could not be deleted.',
];
}
}

View File

@@ -0,0 +1,187 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Loan;
use Symfony\Component\HttpFoundation\Response;
class LoanRepository extends EntityRepository
{
public string $table = Loan::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'amount',
'schedule_type',
'fine_rate',
'installments',
'paid_amount',
'remaining_amount',
'status',
'loan_type',
'remarks',
'start_date',
'end_date',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getLoanQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.employee_id",
'users.first_name',
'users.last_name',
'departments.name as department_name',
'designations.title as designation_title',
"{$this->table}.amount",
"{$this->table}.schedule_type",
"{$this->table}.fine_rate",
"{$this->table}.installments",
"{$this->table}.paid_amount",
"{$this->table}.remaining_amount",
"{$this->table}.loan_type",
"{$this->table}.remarks",
"{$this->table}.start_date",
"{$this->table}.end_date",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('users', "{$this->table}.employee_id", '=', 'users.id')
->leftJoin('departments', 'users.department_id', '=', 'departments.id')
->leftJoin('designations', 'users.designation_id', '=', 'designations.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.employee_id", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getLoanQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getLoanQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Loan::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Loan::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Loan does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Loan could not be deleted.',
];
}
}

View File

@@ -0,0 +1,185 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Recruitment;
use Symfony\Component\HttpFoundation\Response;
class RecruitmentRepository extends EntityRepository
{
public string $table = Recruitment::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'title',
'description',
'requirements',
'vacancy_count',
'department_id',
'designation_id',
'start_date',
'end_date',
'job_type',
'recruiter_id',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getRecruitmentQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.title",
"{$this->table}.description",
"{$this->table}.requirements",
"{$this->table}.vacancy_count",
"{$this->table}.department_id",
'departments.name as department_name',
"{$this->table}.designation_id",
'designations.title as designation_title',
"{$this->table}.start_date",
"{$this->table}.end_date",
"{$this->table}.job_type",
"{$this->table}.recruiter_id",
'recruiters.first_name as recruiter_first_name',
'recruiters.last_name as recruiter_last_name',
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('departments', "{$this->table}.department_id", '=', 'departments.id')
->leftJoin('designations', "{$this->table}.designation_id", '=', 'designations.id')
->leftJoin('users as recruiters', "{$this->table}.recruiter_id", '=', 'recruiters.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getRecruitmentQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getRecruitmentQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Recruitment::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Recruitment::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Recruitment does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Recruitment could not be deleted.',
];
}
}

View File

@@ -0,0 +1,190 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\SalaryGenerate;
use Symfony\Component\HttpFoundation\Response;
class SalaryGenerateRepository extends EntityRepository
{
public string $table = SalaryGenerate::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'month',
'basic_salary',
'total_earnings',
'total_deductions',
'overtime_hours',
'overtime_amount',
'net_salary',
'generated_date',
'generated_by',
'status',
'salary_breakdown',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getSalaryGenerateQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
'restaurants.name as restaurant_name',
"{$this->table}.employee_id",
'users.first_name',
'users.last_name',
'departments.name as department_name',
'designations.title as designation_title',
"{$this->table}.month",
"{$this->table}.basic_salary",
"{$this->table}.total_earnings",
"{$this->table}.total_deductions",
"{$this->table}.overtime_hours",
"{$this->table}.overtime_amount",
"{$this->table}.net_salary",
"{$this->table}.generated_date",
"{$this->table}.generated_by",
"{$this->table}.status",
"{$this->table}.salary_breakdown",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('users', "{$this->table}.employee_id", '=', 'users.id')
->leftJoin('departments', 'users.department_id', '=', 'departments.id')
->leftJoin('designations', 'users.designation_id', '=', 'designations.id')
->leftJoin('restaurants', "{$this->table}.restaurant_id", '=', 'restaurants.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.month", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getSalaryGenerateQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getSalaryGenerateQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return SalaryGenerate::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = SalaryGenerate::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
$data['salary_breakdown'] = json_encode($data['salary_breakdown']);
} else {
$data['salary_breakdown'] = json_encode($data['salary_breakdown']);
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'SalaryGenerate does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'SalaryGenerate could not be deleted.',
];
}
}

View File

@@ -0,0 +1,177 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\SalarySetup;
use Symfony\Component\HttpFoundation\Response;
class SalarySetupRepository extends EntityRepository
{
public string $table = SalarySetup::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'employee_id',
'salary_type_id',
'amount',
'calculation_type',
'notes',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getSalarySetupQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.employee_id",
'users.first_name',
'users.last_name',
'departments.name as department_name',
'designations.title as designation_title',
"{$this->table}.salary_type_id",
'salary_types.name as salary_type_name',
"{$this->table}.amount",
"{$this->table}.calculation_type",
"{$this->table}.notes",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
)
->leftJoin('users', "{$this->table}.employee_id", '=', 'users.id')
->leftJoin('departments', 'users.department_id', '=', 'departments.id')
->leftJoin('designations', 'users.designation_id', '=', 'designations.id')
->leftJoin('salary_types', "{$this->table}.salary_type_id", '=', 'salary_types.id');
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getSalarySetupQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getSalarySetupQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return SalarySetup::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = SalarySetup::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'SalarySetup does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'SalarySetup could not be deleted.',
];
}
}

View File

@@ -0,0 +1,170 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\SalaryType;
use Symfony\Component\HttpFoundation\Response;
class SalaryTypeRepository extends EntityRepository
{
public string $table = SalaryType::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'type',
'default_amount',
'calculation_method',
'is_taxable',
'is_visible_in_payslip',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getSalaryTypeQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.type",
"{$this->table}.default_amount",
"{$this->table}.calculation_method",
"{$this->table}.is_taxable",
"{$this->table}.is_visible_in_payslip",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getSalaryTypeQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getSalaryTypeQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return SalaryType::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = SalaryType::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'SalaryType does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'SalaryType could not be deleted.',
];
}
}

View File

@@ -0,0 +1,168 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\Shift;
use Symfony\Component\HttpFoundation\Response;
class ShiftRepository extends EntityRepository
{
public string $table = Shift::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'name',
'start_time',
'end_time',
'description',
'status',
'created_at',
'updated_at',
'deleted_at',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getShiftQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.name",
"{$this->table}.start_time",
"{$this->table}.end_time",
"{$this->table}.description",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.name", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getShiftQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getShiftQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return Shift::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = Shift::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'Shift does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'Shift could not be deleted.',
];
}
}

View File

@@ -0,0 +1,162 @@
<?php
namespace Modules\HRM\Repositories;
use App\Abstracts\EntityRepository;
use Exception;
use Illuminate\Contracts\Pagination\Paginator;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Database\Query\Builder;
use Modules\HRM\Models\WeeklyHoliday;
use Symfony\Component\HttpFoundation\Response;
class WeeklyHolidayRepository extends EntityRepository
{
public string $table = WeeklyHoliday::TABLE_NAME;
protected array $fillableColumns = [
'restaurant_id',
'day',
'description',
'status',
];
protected function getQuery(): Builder
{
return parent::getQuery();
}
protected function getFilterData(array $filterData = []): array
{
$defaultArgs = [
'perPage' => 10,
'search' => '',
'orderBy' => 'id',
'order' => 'desc',
'with_deleted' => false,
];
return array_merge($defaultArgs, $filterData);
}
private function getWeeklyHolidayQuery(): Builder
{
return $this->getQuery()
->select(
"{$this->table}.id",
"{$this->table}.restaurant_id",
"{$this->table}.day",
"{$this->table}.description",
"{$this->table}.status",
"{$this->table}.created_at",
"{$this->table}.deleted_at"
);
}
protected function filterSearchQuery(Builder|EloquentBuilder $query, string $searchedText): Builder
{
$searchable = "%$searchedText%";
return $query->where("{$this->table}.day", 'LIKE', $searchable)
->orWhere("{$this->table}.status", 'LIKE', $searchable);
}
public function getAll(array $filterData = []): Paginator
{
$filter = $this->getFilterData($filterData);
$query = $this->getWeeklyHolidayQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
if (! empty($filter['search'])) {
$query = $this->filterSearchQuery($query, $filter['search']);
}
return $query
->orderBy($filter['orderBy'], $filter['order'])
->paginate($filter['perPage']);
}
public function getCount(array $filterData = []): int
{
$filter = $this->getFilterData($filterData);
$query = $this->getQuery();
if (! $filter['with_deleted']) {
$query->whereNull("{$this->table}.deleted_at");
}
return $query->count();
}
/**
* @throws Exception
*/
public function getByColumn(string $columnName, $columnValue, array $selects = ['*']): ?object
{
$item = $this->getWeeklyHolidayQuery()
->where($columnName, $columnValue)
->first($selects);
if (empty($item)) {
throw new Exception(
$this->getExceptionMessage(static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE),
Response::HTTP_NOT_FOUND
);
}
return $item;
}
/**
* @throws Exception
*/
public function create(array $data): object
{
$data = $this->prepareForDB($data);
$id = $this->getQuery()->insertGetId($data);
return WeeklyHoliday::find($id);
}
/**
* @throws Exception
*/
public function update(int $id, array $data): object
{
$item = WeeklyHoliday::findOrFail($id);
$data = $this->prepareForDB($data, $item);
parent::update($id, $data);
return $this->getById($id);
}
/**
* @throws Exception
*/
public function prepareForDB(array $data, ?object $item = null): array
{
$data = parent::prepareForDB($data, $item);
if (empty($item)) {
$data['created_at'] = now();
$data['restaurant_id'] = $this->getCurrentRestaurantId();
$data['status'] = 1;
} else {
$data['updated_at'] = now();
}
return $data;
}
protected function getExceptionMessages(): array
{
return [
static::MESSAGE_ITEM_DOES_NOT_EXIST_MESSAGE => 'WeeklyHoliday does not exist.',
static::MESSAGE_ITEM_COULD_NOT_BE_DELETED => 'WeeklyHoliday could not be deleted.',
];
}
}