first change
This commit is contained in:
0
Modules/Leave/app/Repositories/.gitkeep
Normal file
0
Modules/Leave/app/Repositories/.gitkeep
Normal file
14
Modules/Leave/app/Repositories/LeaveBalanceInterface.php
Normal file
14
Modules/Leave/app/Repositories/LeaveBalanceInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Repositories;
|
||||
|
||||
interface LeaveBalanceInterface
|
||||
{
|
||||
public function pluck();
|
||||
public function findAll();
|
||||
public function delete($leaveTypeId);
|
||||
public function create(array $LeaveTypeDetails);
|
||||
|
||||
public function where(array $filter);
|
||||
public function update($leaveTypeId, array $newDetails);
|
||||
}
|
38
Modules/Leave/app/Repositories/LeaveBalanceRepository.php
Normal file
38
Modules/Leave/app/Repositories/LeaveBalanceRepository.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Repositories;
|
||||
|
||||
use Modules\Leave\Models\LeaveBalance;
|
||||
|
||||
class LeaveBalanceRepository implements LeaveBalanceInterface
|
||||
{
|
||||
public function pluck()
|
||||
{
|
||||
return LeaveBalance::pluck('name', 'id');
|
||||
}
|
||||
public function findAll()
|
||||
{
|
||||
return LeaveBalance::get();
|
||||
}
|
||||
|
||||
public function create(array $LeaveBalanceDetails)
|
||||
{
|
||||
return LeaveBalance::create($LeaveBalanceDetails);
|
||||
}
|
||||
|
||||
public function update($LeaveBalanceId, array $newDetails)
|
||||
{
|
||||
return LeaveBalance::where('id', $LeaveBalanceId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function where(array $filter)
|
||||
{
|
||||
return LeaveBalance::where($filter);
|
||||
}
|
||||
|
||||
public function delete($LeaveBalanceId)
|
||||
{
|
||||
LeaveBalance::destroy($LeaveBalanceId);
|
||||
}
|
||||
|
||||
}
|
14
Modules/Leave/app/Repositories/LeaveInterface.php
Normal file
14
Modules/Leave/app/Repositories/LeaveInterface.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Repositories;
|
||||
|
||||
interface LeaveInterface
|
||||
{
|
||||
public function findAll($filters = [], $limit = null, $offset = null);
|
||||
public function getLeaveById($leaveId);
|
||||
public function where(array $filter);
|
||||
public function delete($leaveId);
|
||||
public function create(array $LeaveDetails);
|
||||
public function update($leaveId, array $newDetails);
|
||||
public function getLeaveByEmployeeId(int $id);
|
||||
}
|
80
Modules/Leave/app/Repositories/LeaveRepository.php
Normal file
80
Modules/Leave/app/Repositories/LeaveRepository.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Repositories;
|
||||
|
||||
use Illuminate\Contracts\Database\Eloquent\Builder;
|
||||
use Modules\Leave\Models\Leave;
|
||||
|
||||
class LeaveRepository implements LeaveInterface
|
||||
{
|
||||
public function findAll($filters = [], $limit = null, $offset = null)
|
||||
{
|
||||
return Leave::with(['leaveType', 'employee'])->when($filters, function ($query) use ($filters) {
|
||||
|
||||
if (isset($filters["employee_id"])) {
|
||||
$query->whereHas('employee', function (Builder $query) use ($filters) {
|
||||
$query->where('id', '=', $filters["employee_id"]);
|
||||
});
|
||||
}
|
||||
|
||||
if (isset($filters["status"])) {
|
||||
$query->where("status", $filters["status"]);
|
||||
}
|
||||
|
||||
if (!empty($filters['date'])) {
|
||||
$dateFilter = explode("to", $filters['date']);
|
||||
$startDate = trim($dateFilter[0]);
|
||||
$endDate = trim($dateFilter[1]);
|
||||
if ($startDate === $endDate) {
|
||||
$query->where("created_at", '=', $startDate);
|
||||
} else {
|
||||
$query->where("created_at", '>=', $startDate);
|
||||
$query->where("created_at", '<=', $endDate);
|
||||
}
|
||||
}
|
||||
|
||||
// if (isset($filters["date"])) {
|
||||
// $explodeDate = explode("to", $filters['date']);
|
||||
// dd($explodeDate);
|
||||
// $query->whereBetween("start_date", [$explodeDate[0], preg_replace('/\s+/', '', $explodeDate[1])]);
|
||||
// }
|
||||
|
||||
})->latest()
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getLeaveById($leaveId)
|
||||
{
|
||||
return Leave::findOrFail($leaveId);
|
||||
}
|
||||
|
||||
public function where(array $filter)
|
||||
{
|
||||
return Leave::where($filter);
|
||||
}
|
||||
|
||||
public function delete($leaveId)
|
||||
{
|
||||
Leave::destroy($leaveId);
|
||||
}
|
||||
|
||||
public function create(array $leaveDetails)
|
||||
{
|
||||
return Leave::create($leaveDetails);
|
||||
}
|
||||
|
||||
public function update($leaveId, array $newDetails)
|
||||
{
|
||||
return Leave::where('leave_id', $leaveId)->update($newDetails);
|
||||
}
|
||||
|
||||
|
||||
public function getLeaveByEmployeeId(int $id)
|
||||
{
|
||||
return Leave::where([
|
||||
['employee_id', $id],
|
||||
])
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
}
|
13
Modules/Leave/app/Repositories/LeaveTypeInterface.php
Normal file
13
Modules/Leave/app/Repositories/LeaveTypeInterface.php
Normal file
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Repositories;
|
||||
|
||||
interface LeaveTypeInterface
|
||||
{
|
||||
public function pluck();
|
||||
public function findAll();
|
||||
public function getLeaveTypeById($leaveTypeId);
|
||||
public function delete($leaveTypeId);
|
||||
public function create(array $LeaveTypeDetails);
|
||||
public function update($leaveTypeId, array $newDetails);
|
||||
}
|
38
Modules/Leave/app/Repositories/LeaveTypeRepository.php
Normal file
38
Modules/Leave/app/Repositories/LeaveTypeRepository.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Repositories;
|
||||
|
||||
use Modules\Leave\Models\LeaveType;
|
||||
|
||||
class LeaveTypeRepository implements LeaveTypeInterface
|
||||
{
|
||||
public function pluck()
|
||||
{
|
||||
return LeaveType::pluck('name', 'leave_type_id');
|
||||
}
|
||||
public function findAll()
|
||||
{
|
||||
return LeaveType::get();
|
||||
}
|
||||
|
||||
public function getLeaveTypeById($leaveTypeId)
|
||||
{
|
||||
return LeaveType::findOrFail($leaveTypeId);
|
||||
}
|
||||
|
||||
public function create(array $leaveTypeDetails)
|
||||
{
|
||||
return LeaveType::create($leaveTypeDetails);
|
||||
}
|
||||
|
||||
public function update($leaveTypeId, array $newDetails)
|
||||
{
|
||||
return LeaveType::where('leave_type_id', $leaveTypeId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function delete($leaveTypeId)
|
||||
{
|
||||
LeaveType::destroy($leaveTypeId);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user