first change
This commit is contained in:
0
Modules/Leave/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Leave/app/Http/Controllers/.gitkeep
Normal file
275
Modules/Leave/app/Http/Controllers/LeaveController.php
Normal file
275
Modules/Leave/app/Http/Controllers/LeaveController.php
Normal file
@@ -0,0 +1,275 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Auth;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Employee\Interfaces\EmployeeInterface;
|
||||
use Modules\Leave\Models\Leave;
|
||||
use Modules\Leave\Repositories\LeaveBalanceInterface;
|
||||
use Modules\Leave\Repositories\LeaveInterface;
|
||||
use Modules\Leave\Repositories\LeaveTypeInterface;
|
||||
|
||||
class LeaveController extends Controller
|
||||
{
|
||||
private $leave;
|
||||
private $employee;
|
||||
private $leaveType;
|
||||
private $leaveBalance;
|
||||
|
||||
public function __construct(
|
||||
LeaveInterface $leaveRepository,
|
||||
EmployeeInterface $employeeRepository,
|
||||
LeaveTypeInterface $leaveTypeRepository,
|
||||
LeaveBalanceInterface $leaveBalance,
|
||||
|
||||
) {
|
||||
$this->leave = $leaveRepository;
|
||||
$this->employee = $employeeRepository;
|
||||
$this->leaveType = $leaveTypeRepository;
|
||||
$this->leaveBalance = $leaveBalance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$filters = $request->all();
|
||||
$data['title'] = "Leave List";
|
||||
$data['leaves'] = $this->leave->findAll($filters);
|
||||
// dd($data['leaves']->toArray());
|
||||
$data['employeeList'] = $this->employee->pluck();
|
||||
$data['status'] = Leave::PROGRESS_STATUS;
|
||||
|
||||
return view('leave::leave.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create Leave';
|
||||
$data['editable'] = false;
|
||||
$data['employeeList'] = $this->employee->pluck();
|
||||
$data['leaveTypeList'] = $this->leaveType->pluck();
|
||||
$data['status'] = Leave::PROGRESS_STATUS;
|
||||
$data['duration'] = Leave::DURATION;
|
||||
|
||||
return view('leave::leave.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$inputData = $request->all();
|
||||
try {
|
||||
$dates = array_map('trim', explode(",", $request->start_date));
|
||||
$inputData['total_days'] = $request->duration == '2' ? count($dates) / 2 : count($dates);
|
||||
$inputData['start_date'] = ['dates' => $dates];
|
||||
$leave = $this->leave->create($inputData);
|
||||
|
||||
if ($request->status == 2) {
|
||||
$leaveBalance = $this->leaveBalance->where([
|
||||
'employee_id' => $request->employee_id,
|
||||
'leave_type_id' => $leave->leave_type_id,
|
||||
])->first();
|
||||
|
||||
$leaveBalance->remain -= $leave->total_days;
|
||||
$leaveBalance->save();
|
||||
|
||||
$leave->leave_approved_by = Auth::id();
|
||||
$leave->save();
|
||||
}
|
||||
|
||||
// $employeemodel = $this->employee->getEmployeeById($inputData['employee_id']);
|
||||
// sendNotification($employeemodel->user, [
|
||||
// 'msg' => 'Leave Created']);
|
||||
|
||||
flash()->success('Leave Created Succesfully');
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('leave.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['title'] = 'View Leave';
|
||||
$data['leave'] = $this->leave->getLeaveById($id);
|
||||
return view('leave::leave.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit Leave';
|
||||
$data['editable'] = true;
|
||||
$data['leave'] = $this->leave->getLeaveById($id);
|
||||
$data['employeeList'] = $this->employee->pluck();
|
||||
$data['leaveTypeList'] = $this->leaveType->pluck();
|
||||
$data['status'] = Leave::PROGRESS_STATUS;
|
||||
$data['duration'] = Leave::DURATION;
|
||||
return view('leave::leave.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$inputData = $request->except(['_method', "_token"]);
|
||||
try {
|
||||
$this->leave->update($id, $inputData);
|
||||
flash()->success('Leave Updated Succesfully');
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('leave.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$this->leave->delete($id);
|
||||
return response()->json(['status' => 200, 'message' => 'Leave has been deleted!'], 200);
|
||||
} catch (\Throwable $th) {
|
||||
return response()->json(['status' => 500, 'message' => 'Leave to delete!', 'error' => $th->getMessage()], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the status of the specified resource in storage.
|
||||
*/
|
||||
public function updateStatus(Request $request)
|
||||
{
|
||||
try {
|
||||
$leave = $this->leave->getLeaveById($request->leave_id);
|
||||
$request->merge([
|
||||
'leave_approved_by' => Auth::id(),
|
||||
]);
|
||||
if ($request->status == 2) {
|
||||
$leaveBalance = $this->leaveBalance->where([
|
||||
'employee_id' => $request->employee_id,
|
||||
'leave_type_id' => $leave->leave_type_id,
|
||||
])->first();
|
||||
|
||||
$leaveBalance->remain -= $leave->total_days;
|
||||
$leaveBalance->save();
|
||||
}
|
||||
$this->leave->update($request->leave_id, $request->except(['_method', "_token"]));
|
||||
// $employeemodel = $this->employee->getEmployeeById($request->employee_id);
|
||||
// sendNotification($employeemodel->user, [
|
||||
// 'msg' => 'Leave Status Changed']);
|
||||
|
||||
flash()->success('Leave Status Updated Successfully');
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('leave.index');
|
||||
}
|
||||
|
||||
public function getRemainingEmpLeave(Request $request)
|
||||
{
|
||||
try {
|
||||
$leaveBalance = $this->leaveBalance->where([
|
||||
'employee_id' => $request->employee_id,
|
||||
])->with(['leaveType:leave_type_id,name'])->get()
|
||||
->transform(function ($leaveBalance) {
|
||||
return [
|
||||
'leave_type_id' => $leaveBalance->leave_type_id,
|
||||
'leave_type' => $leaveBalance->leaveType?->name,
|
||||
'total' => $leaveBalance->total,
|
||||
'remain' => $leaveBalance->remain,
|
||||
];
|
||||
});
|
||||
return response()->json([
|
||||
'view' => view('leave::leave.partials.remaining-leave', compact('leaveBalance'))->render(),
|
||||
]);
|
||||
} catch (\Throwable $th) {
|
||||
return response()->json([
|
||||
'msg' => $th->getMessage(),
|
||||
]);
|
||||
}
|
||||
// return redirect()->route('leave.index');
|
||||
}
|
||||
|
||||
public function checkEmpLeaveDates(Request $request)
|
||||
{
|
||||
$validator = \Validator::make($request->all(), [
|
||||
'employee_id' => 'required',
|
||||
'leave_type_id' => 'required',
|
||||
'duration' => 'required',
|
||||
]);
|
||||
|
||||
if ($validator->fails()) {
|
||||
return response()->json([
|
||||
'status' => false,
|
||||
'errors' => $validator->errors(),
|
||||
]);
|
||||
}
|
||||
|
||||
try {
|
||||
$dates = array_map('trim', explode(",", $request->dates));
|
||||
$leaves = $this->leave->where([
|
||||
'employee_id' => $request->employee_id,
|
||||
])
|
||||
->when(true, function ($q) use ($dates) {
|
||||
$q->where(function ($query) use ($dates) {
|
||||
foreach ($dates as $date) {
|
||||
$query->orWhereJsonContains("start_date", ['dates' => $date]);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
->select('leave_id', 'employee_id', 'start_date', 'status')
|
||||
->get()
|
||||
->toArray();
|
||||
$mergeLeaveDates = array_map(function ($leave) {
|
||||
return $leave['start_date']['dates'];
|
||||
}, $leaves);
|
||||
|
||||
$previousLeaveDates = array_intersect($dates, array_merge(...$mergeLeaveDates));
|
||||
$html = '';
|
||||
$btnFlag = $request->filled('dates') ? true : false;
|
||||
if (!empty($previousLeaveDates)) {
|
||||
$btnFlag = false;
|
||||
$html .= '<li class="list-group-item text-danger"><i class="ri-close-fill"></i> Previous Leave Found on ' . implode(', ', $previousLeaveDates);
|
||||
}
|
||||
|
||||
$leaveBalance = $this->leaveBalance->where([
|
||||
'employee_id' => $request->employee_id,
|
||||
'leave_type_id' => $request->leave_type_id,
|
||||
])->where('remain', '<=', count($dates))
|
||||
->first();
|
||||
if ($leaveBalance) {
|
||||
$btnFlag = false;
|
||||
$html .= '<li class="list-group-item text-danger"><i class="ri-close-fill"></i> Remaining Leave Balance: ' . $leaveBalance->remain;
|
||||
}
|
||||
|
||||
if ($btnFlag == true) {
|
||||
$html .= '<li class="list-group-item text-success"><i class="ri-check-fill"></i> Leave Apply Dates: ' . $request->dates;
|
||||
}
|
||||
return response()->json(['html' => $html, 'btnFlag' => $btnFlag]);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
return response()->json([
|
||||
'msg' => $th->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
125
Modules/Leave/app/Http/Controllers/LeaveTypeController.php
Normal file
125
Modules/Leave/app/Http/Controllers/LeaveTypeController.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use DB;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Employee\Interfaces\EmployeeInterface;
|
||||
use Modules\Leave\Repositories\LeaveBalanceInterface;
|
||||
use Modules\Leave\Repositories\LeaveTypeInterface;
|
||||
|
||||
class LeaveTypeController extends Controller
|
||||
{
|
||||
private $leaveType;
|
||||
private $employee;
|
||||
private $leaveBalance;
|
||||
|
||||
public function __construct(
|
||||
LeaveTypeInterface $leaveType,
|
||||
LeaveBalanceInterface $leaveBalance,
|
||||
EmployeeInterface $employee) {
|
||||
$this->leaveType = $leaveType;
|
||||
$this->leaveBalance = $leaveBalance;
|
||||
$this->employee = $employee;
|
||||
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'LeaveType List';
|
||||
$data['leaveTypeLists'] = $this->leaveType->findAll();
|
||||
return view('leave::leave-type.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create LeaveType';
|
||||
$data['editable'] = false;
|
||||
return view('leave::leave-type.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$leaveType = $this->leaveType->create($request->all());
|
||||
$employees = $this->employee->pluck();
|
||||
|
||||
foreach ($employees as $empKey => $emp) {
|
||||
$leaveBalance = [
|
||||
'employee_id' => $empKey,
|
||||
'leave_type_id' => $leaveType->leave_type_id,
|
||||
'total' => $request->total_days,
|
||||
'remain' => $request->total_days,
|
||||
];
|
||||
|
||||
$this->leaveBalance->create($leaveBalance);
|
||||
}
|
||||
DB::commit();
|
||||
flash()->success('LeaveType created successfully');
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
DB::rollBack();
|
||||
}
|
||||
|
||||
return redirect()->route('leaveType.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['title'] = 'View Leave';
|
||||
$data['leave'] = $this->leaveType->getLeaveTypeById($id);
|
||||
|
||||
return view('leave::leave-type.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['editable'] = true;
|
||||
$data['title'] = 'Edit LeaveType';
|
||||
$data['leaveType'] = $this->leaveType->getLeaveTypeById($id);
|
||||
|
||||
return view('leave::leave-type.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$this->leaveType->update($id, $request->except(['_token', '_method']));
|
||||
flash()->success('LeaveType updated successfully');
|
||||
} catch (\Throwable $th) {
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('leaveType.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$this->leaveType->delete($id);
|
||||
flash()->success('LeaveType deleted successfully');
|
||||
return redirect()->route('leaveType.index');
|
||||
|
||||
}
|
||||
}
|
0
Modules/Leave/app/Http/Requests/.gitkeep
Normal file
0
Modules/Leave/app/Http/Requests/.gitkeep
Normal file
26
Modules/Leave/app/Http/Requests/LeaveTypeRequest.php
Normal file
26
Modules/Leave/app/Http/Requests/LeaveTypeRequest.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class LeaveTypeRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
0
Modules/Leave/app/Models/.gitkeep
Normal file
0
Modules/Leave/app/Models/.gitkeep
Normal file
83
Modules/Leave/app/Models/Leave.php
Normal file
83
Modules/Leave/app/Models/Leave.php
Normal file
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Models;
|
||||
|
||||
use App\Models\Scopes\CreatedByScope;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Attributes\ScopedBy;
|
||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\Employee\Models\Employee;
|
||||
|
||||
#[ScopedBy([CreatedByScope::class])]
|
||||
class Leave extends Model
|
||||
{
|
||||
protected $table = 'tbl_leaves';
|
||||
protected $primaryKey = 'leave_id';
|
||||
protected $guarded = [];
|
||||
|
||||
protected $appends = ['status_name'];
|
||||
|
||||
const PROGRESS_STATUS = [
|
||||
1 => 'Pending',
|
||||
2 => 'Approved',
|
||||
3 => 'Rejected',
|
||||
];
|
||||
|
||||
const DURATION = [
|
||||
1 => 'Full Day',
|
||||
2 => 'Half Day',
|
||||
3 => 'Multiple',
|
||||
];
|
||||
protected $casts = [
|
||||
'start_date' => 'json',
|
||||
];
|
||||
|
||||
protected function statusName(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
get: function (mixed $value, array $attributes) {
|
||||
switch ($attributes['status']) {
|
||||
case '1':
|
||||
$color = 'dark';
|
||||
break;
|
||||
case '2':
|
||||
$color = 'success';
|
||||
break;
|
||||
case '3':
|
||||
$color = 'danger';
|
||||
break;
|
||||
default:
|
||||
$color = 'light';
|
||||
break;
|
||||
}
|
||||
|
||||
return collect([
|
||||
'status' => self::PROGRESS_STATUS[$attributes['status']],
|
||||
'color' => $color]);
|
||||
},
|
||||
set: fn($value) => $value,
|
||||
);
|
||||
}
|
||||
|
||||
public function getDuration()
|
||||
{
|
||||
return self::DURATION[$this->duration] ?? null;
|
||||
}
|
||||
|
||||
public function employee()
|
||||
{
|
||||
return $this->belongsTo(Employee::class, 'employee_id');
|
||||
}
|
||||
|
||||
public function approveBy()
|
||||
{
|
||||
return $this->belongsTo(User::class, 'leave_approved_by');
|
||||
}
|
||||
|
||||
public function leaveType()
|
||||
{
|
||||
return $this->belongsTo(LeaveType::class, 'leave_type_id');
|
||||
}
|
||||
|
||||
}
|
25
Modules/Leave/app/Models/LeaveBalance.php
Normal file
25
Modules/Leave/app/Models/LeaveBalance.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\Employee\Models\Employee;
|
||||
|
||||
class LeaveBalance extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $table = 'tbl_leave_balances';
|
||||
protected $fillable = ['employee_id', 'leave_type_id', 'total', 'remain'];
|
||||
public $timestamps = false;
|
||||
|
||||
public function employee()
|
||||
{
|
||||
return $this->belongsTo(Employee::class, 'employee_id');
|
||||
}
|
||||
|
||||
public function leaveType()
|
||||
{
|
||||
return $this->belongsTo(LeaveType::class, 'leave_type_id');
|
||||
}
|
||||
}
|
32
Modules/Leave/app/Models/LeaveType.php
Normal file
32
Modules/Leave/app/Models/LeaveType.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Models;
|
||||
|
||||
use App\Traits\StatusTrait;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class LeaveType extends Model
|
||||
{
|
||||
use HasFactory, StatusTrait;
|
||||
|
||||
protected $table = 'tbl_leave_types';
|
||||
protected $primaryKey = 'leave_type_id';
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'total_days',
|
||||
'max_accumulated_days',
|
||||
'is_accumulated',
|
||||
'is_proportionate',
|
||||
'status',
|
||||
'description',
|
||||
'remarks',
|
||||
'createdBy',
|
||||
'updatedBy',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'is_accumulated' => 'boolean',
|
||||
'is_proportionate' => 'boolean',
|
||||
];
|
||||
}
|
0
Modules/Leave/app/Providers/.gitkeep
Normal file
0
Modules/Leave/app/Providers/.gitkeep
Normal file
123
Modules/Leave/app/Providers/LeaveServiceProvider.php
Normal file
123
Modules/Leave/app/Providers/LeaveServiceProvider.php
Normal file
@@ -0,0 +1,123 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Leave\Repositories\LeaveBalanceInterface;
|
||||
use Modules\Leave\Repositories\LeaveBalanceRepository;
|
||||
use Modules\Leave\Repositories\LeaveInterface;
|
||||
use Modules\Leave\Repositories\LeaveRepository;
|
||||
use Modules\Leave\Repositories\LeaveTypeInterface;
|
||||
use Modules\Leave\Repositories\LeaveTypeRepository;
|
||||
|
||||
class LeaveServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Leave';
|
||||
|
||||
protected string $moduleNameLower = 'leave';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->bind(LeaveInterface::class, LeaveRepository::class);
|
||||
$this->app->bind(LeaveTypeInterface::class, LeaveTypeRepository::class);
|
||||
$this->app->bind(LeaveBalanceInterface::class, LeaveBalanceRepository::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower . '.php')], 'config');
|
||||
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
|
||||
$sourcePath = module_path($this->moduleName, 'resources/views');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower . '-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
|
||||
|
||||
$componentNamespace = str_replace('/', '\\', config('modules.namespace') . '\\' . $this->moduleName . '\\' . ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
|
||||
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
|
||||
$paths[] = $path . '/modules/' . $this->moduleNameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
49
Modules/Leave/app/Providers/RouteServiceProvider.php
Normal file
49
Modules/Leave/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Leave\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')->group(module_path('Leave', '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Leave', '/routes/api.php'));
|
||||
}
|
||||
}
|
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