DONE: layout letter with letterhead and footer, notification for newly...

This commit is contained in:
ISMAIL MASSERAN
2026-06-28 02:16:49 +00:00
parent 94ecbe5887
commit 034ecf947f
400 changed files with 29802 additions and 5446 deletions
@@ -0,0 +1,89 @@
<?php
namespace Modules\User\Repositories;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Address;
use Modules\User\Repositories\Contracts\AddressRepositoryInterface;
class AddressRepository implements AddressRepositoryInterface
{
protected function baseQuery()
{
return Address::query()
->where('user_id', auth()->id())
->orderBy('address_type');
}
public function getAllPaginated(int $perPage = 10, string $search = '')
{
$query = $this->baseQuery();
return $query->paginate($perPage);
}
public function getAllWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $sortBy = 'address_type',
string $sortOrder = 'asc'
) {
$allowedSortColumns = [
'id',
'address_type',
'address_line_1',
'city',
'state',
'postcode',
'country',
'created_at',
];
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'address_type';
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
$query = Address::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->orderBy($sortBy, $sortOrder);
return $query->paginate($perPage);
}
public function getAllWithRelations(string $search = ''): Collection
{
$query = Address::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->orderBy('address_type');
return $query->get();
}
public function create(array $data): Address
{
return Address::create($data);
}
public function findById(string $id): ?Address
{
return Address::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->find($id);
}
public function delete(string $id): bool
{
$address = $this->findById($id);
if ($address) {
return $address->delete();
}
return false;
}
public function all(string $search = ''): Collection
{
return $this->baseQuery()->get();
}
}
@@ -0,0 +1,59 @@
<?php
namespace Modules\User\Repositories;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\BankDetail;
use Modules\User\Repositories\Contracts\BankDetailRepositoryInterface;
class BankDetailRepository implements BankDetailRepositoryInterface
{
protected function baseQuery()
{
return BankDetail::query()->where('user_id', auth()->id());
}
public function getAllPaginated(int $perPage = 10, string $search = '')
{
$query = $this->baseQuery();
return $query->paginate($perPage);
}
public function getAllWithRelations(string $search = ''): Collection
{
$query = BankDetail::query()
->where('user_id', auth()->id())
->with(['user:id,name,email', 'bank:id,name'])
->orderBy('account_number');
return $query->get();
}
public function create(array $data): BankDetail
{
return BankDetail::create($data);
}
public function findById(string $id): ?BankDetail
{
return BankDetail::query()
->where('user_id', auth()->id())
->find($id);
}
public function delete(string $id): bool
{
$bankDetail = $this->findById($id);
if ($bankDetail) {
return $bankDetail->delete();
}
return false;
}
public function all(string $search = ''): Collection
{
return $this->baseQuery()->get();
}
}
@@ -0,0 +1,81 @@
<?php
namespace Modules\User\Repositories;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Bank;
use Modules\User\Repositories\Contracts\BankRepositoryInterface;
class BankRepository implements BankRepositoryInterface
{
protected function baseQuery()
{
return Bank::query()->orderBy('name');
}
public function getAllPaginated(int $perPage = 10, string $search = '')
{
$query = $this->baseQuery();
return $query->paginate($perPage);
}
public function getAllWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $sortBy = 'name',
string $sortOrder = 'asc'
) {
$allowedSortColumns = [
'name',
'code',
'swift_code',
'is_active',
'created_at',
];
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'name';
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
$query = Bank::query()->orderBy($sortBy, $sortOrder);
return $query->paginate($perPage);
}
public function getAllWithRelations(string $search = ''): Collection
{
$query = Bank::query()->orderBy('name');
return $query->get();
}
public function create(array $data): Bank
{
return Bank::create($data);
}
public function findById(string $id): ?Bank
{
return Bank::query()
->find($id);
}
// public function delete(string $id): bool
// {
// $bank = $this->findById($id);
// if ($bank) {
// return $bank->delete();
// }
// return false;
// }
public function all(string $search = ''): Collection
{
return $this->baseQuery()->get();
}
public function active(): Collection
{
return Bank::query()->where('is_active', true)->get();
}
}
@@ -0,0 +1,28 @@
<?php
namespace Modules\User\Repositories\Contracts;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Address;
interface AddressRepositoryInterface
{
public function getAllPaginated(int $perPage = 10, string $search = '');
public function getAllWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $sortBy = 'address_type',
string $sortOrder = 'asc'
);
public function getAllWithRelations(string $search = ''): Collection;
public function create(array $data): Address;
public function findById(string $id): ?Address;
public function delete(string $id): bool;
public function all(string $search = ''): Collection;
}
@@ -0,0 +1,21 @@
<?php
namespace Modules\User\Repositories\Contracts;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\BankDetail;
interface BankDetailRepositoryInterface
{
public function getAllPaginated(int $perPage = 10, string $search = '');
public function getAllWithRelations(string $search = ''): Collection;
public function create(array $data): BankDetail;
public function findById(string $id): ?BankDetail;
public function delete(string $id): bool;
public function all(string $search = ''): Collection;
}
@@ -0,0 +1,30 @@
<?php
namespace Modules\User\Repositories\Contracts;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Bank;
interface BankRepositoryInterface
{
public function getAllPaginated(int $perPage = 10, string $search = '');
public function getAllWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $sortBy = 'name',
string $sortOrder = 'asc'
);
public function getAllWithRelations(string $search = ''): Collection;
public function create(array $data): Bank;
public function findById(string $id): ?Bank;
// public function delete(string $id): bool;
public function all(string $search = ''): Collection;
public function active(): Collection;
}
@@ -0,0 +1,28 @@
<?php
namespace Modules\User\Repositories\Contracts;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Employment;
interface EmploymentRepositoryInterface
{
public function getAllPaginated(int $perPage = 10, string $search = '');
public function getAllWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $sortBy = 'company_name',
string $sortOrder = 'asc'
);
public function getAllWithRelations(string $search = ''): Collection;
public function create(array $data): Employment;
public function findById(string $id): ?Employment;
public function delete(string $id): bool;
public function all(string $search = ''): Collection;
}
@@ -0,0 +1,28 @@
<?php
namespace Modules\User\Repositories\Contracts;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Heir;
interface HeirRepositoryInterface
{
public function getAllPaginated(int $perPage = 10, string $search = '');
// public function getAllWithRelationsPaginated(
// int $perPage = 10,
// string $search = '',
// string $sortBy = 'name',
// string $sortOrder = 'asc'
// );
public function getAllWithRelations(string $search = ''): Collection;
public function create(array $data): Heir;
public function findById(string $id): ?Heir;
public function delete(string $id): bool;
public function all(string $search = ''): Collection;
}
@@ -43,6 +43,27 @@ interface UserRepositoryInterface
*/
public function delete(string $id): bool;
/**
* Get soft-deleted Users with their relationships and pagination
*/
public function getDeletedWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $status = '',
string $sortBy = 'deleted_at',
string $sortOrder = 'desc'
);
/**
* Find soft-deleted User by ID
*/
public function findTrashedById(string $id): ?User;
/**
* Restore a soft-deleted User
*/
public function restore(string $id): bool;
/**
* Get all Users
*/
@@ -0,0 +1,90 @@
<?php
namespace Modules\User\Repositories;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Employment;
use Modules\User\Repositories\Contracts\EmploymentRepositoryInterface;
class EmploymentRepository implements EmploymentRepositoryInterface
{
protected function baseQuery()
{
return Employment::query()
->where('user_id', auth()->id())
->orderBy('company_name');
}
public function getAllPaginated(int $perPage = 10, string $search = '')
{
$query = $this->baseQuery();
return $query->paginate($perPage);
}
public function getAllWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $sortBy = 'company_name',
string $sortOrder = 'asc'
) {
$allowedSortColumns = [
'id',
'company_name',
'job_title',
'employment_type',
'salary',
'start_date',
'end_date',
'is_current',
'created_at',
];
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'company_name';
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
$query = Employment::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->orderBy($sortBy, $sortOrder);
return $query->paginate($perPage);
}
public function getAllWithRelations(string $search = ''): Collection
{
$query = Employment::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->orderBy('company_name');
return $query->get();
}
public function create(array $data): Employment
{
return Employment::create($data);
}
public function findById(string $id): ?Employment
{
return Employment::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->find($id);
}
public function delete(string $id): bool
{
$employement = $this->findById($id);
if ($employement) {
return $employement->delete();
}
return false;
}
public function all(string $search = ''): Collection
{
return $this->baseQuery()->get();
}
}
@@ -0,0 +1,89 @@
<?php
namespace Modules\User\Repositories;
use Illuminate\Database\Eloquent\Collection;
use Modules\User\Entities\Heir;
use Modules\User\Repositories\Contracts\HeirRepositoryInterface;
class HeirRepository implements HeirRepositoryInterface
{
protected function baseQuery()
{
return Heir::query()
->where('user_id', auth()->id())
->orderBy('name');
}
public function getAllPaginated(int $perPage = 10, string $search = '')
{
$query = $this->baseQuery();
return $query->paginate($perPage);
}
// public function getAllWithRelationsPaginated(
// int $perPage = 10,
// string $search = '',
// string $sortBy = 'name',
// string $sortOrder = 'asc'
// ) {
// $allowedSortColumns = [
// 'id',
// 'name',
// 'job_title',
// 'relationship',
// 'phone_number',
// 'address',
// 'is_primary',
// 'created_at',
// ];
// $sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'company_name';
// $sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
// $query = Employment::query()
// ->where('user_id', auth()->id())
// ->with(['user:id,name,email'])
// ->orderBy($sortBy, $sortOrder);
// return $query->paginate($perPage);
// }
public function getAllWithRelations(string $search = ''): Collection
{
$query = Heir::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->orderBy('name');
return $query->get();
}
public function create(array $data): Heir
{
return Heir::create($data);
}
public function findById(string $id): ?Heir
{
return Heir::query()
->where('user_id', auth()->id())
->with(['user:id,name,email'])
->find($id);
}
public function delete(string $id): bool
{
$heir = $this->findById($id);
if ($heir) {
return $heir->delete();
}
return false;
}
public function all(string $search = ''): Collection
{
return $this->baseQuery()->get();
}
}
+88 -56
View File
@@ -8,24 +8,32 @@ use Modules\User\Repositories\Contracts\UserRepositoryInterface;
class UserRepository implements UserRepositoryInterface
{
private function applySearch($query, string $search): void
{
if (empty($search)) {
return;
}
$query->where(function ($q) use ($search) {
$q->where('name', 'ILIKE', "%{$search}%")
->orWhere('ic_number', 'ILIKE', "%{$search}%")
->orWhere('email', 'ILIKE', "%{$search}%")
->orWhere('phone_number', 'ILIKE', "%{$search}%")
->orWhere('member_number', 'ILIKE', "%{$search}%")
->orWhereHas('roles', function ($roleQuery) use ($search) {
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
});
});
}
/**
* Get all Users with pagination and search
*/
public function getAllPaginated(int $perPage = 10, string $search = '')
{
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
if (! empty($search)) {
$query->where(function ($q) use ($search) {
$q->where('name', 'ILIKE', "%{$search}%");
$q->orWhere('ic_number', 'ILIKE', "%{$search}%");
$q->orWhere('email', 'ILIKE', "%{$search}%");
$q->orWhere('phone_number', 'ILIKE', "%{$search}%");
$q->orWhereHas('roles', function ($roleQuery) use ($search) {
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
});
});
}
$this->applySearch($query, $search);
return $query->paginate($perPage);
}
@@ -46,38 +54,60 @@ class UserRepository implements UserRepositoryInterface
'email',
'position',
'status',
'ic_number',
'phone_number',
'member_number',
'created_at',
'deleted_at',
];
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'name';
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()
$query = User::excludeDevelopersUnlessDeveloper()
->with([
'roles:id,name,guard_name'
])
->orderBy($sortBy, $sortOrder);
if (! empty($search)) {
$query->where(function ($q) use ($search) {
$q->where('name', 'ILIKE', "%{$search}%")
->orWhere('ic_number', 'ILIKE', "%{$search}%")
->orWhere('email', 'ILIKE', "%{$search}%")
->orWhere('phone_number', 'ILIKE', "%{$search}%")
->orWhereHas('roles', function ($roleQuery) use ($search) {
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
});
$q->orWhere('ic_number', 'ILIKE', "%{$search}%");
$q->orWhere('email', 'ILIKE', "%{$search}%");
$q->orWhere('phone_number', 'ILIKE', "%{$search}%");
$q->orWhereHas('roles', function ($roleQuery) use ($search) {
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
});
});
$this->applySearch($query, $search);
if (! empty($status)) {
$query->where('status', $status);
}
// Add status filter
return $query->paginate($perPage);
}
/**
* Get soft-deleted Users with their relationships and pagination
*/
public function getDeletedWithRelationsPaginated(
int $perPage = 10,
string $search = '',
string $status = '',
string $sortBy = 'deleted_at',
string $sortOrder = 'desc'
) {
$allowedSortColumns = [
'id',
'name',
'email',
'position',
'status',
'member_number',
'created_at',
'deleted_at',
];
$sortBy = in_array($sortBy, $allowedSortColumns, true) ? $sortBy : 'deleted_at';
$sortOrder = strtolower($sortOrder) === 'desc' ? 'desc' : 'asc';
$query = User::onlyTrashed()
->excludeDevelopersUnlessDeveloper()
->with([
'roles:id,name,guard_name',
])
->orderBy($sortBy, $sortOrder);
$this->applySearch($query, $search);
if (! empty($status)) {
$query->where('status', $status);
}
@@ -90,19 +120,9 @@ class UserRepository implements UserRepositoryInterface
*/
public function getAllWithRelations(string $search = ''): Collection
{
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
if (! empty($search)) {
$query->where(function ($q) use ($search) {
$q->where('name', 'ILIKE', "%{$search}%")
->orWhere('ic_number', 'ILIKE', "%{$search}%")
->orWhere('email', 'ILIKE', "%{$search}%")
->orWhere('phone_number', 'ILIKE', "%{$search}%")
->orWhereHas('roles', function ($roleQuery) use ($search) {
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
});
});
}
$this->applySearch($query, $search);
return $query->get();
}
@@ -136,24 +156,36 @@ class UserRepository implements UserRepositoryInterface
return false;
}
/**
* Find soft-deleted User by ID
*/
public function findTrashedById(string $id): ?User
{
return User::onlyTrashed()->with(['roles'])->find($id);
}
/**
* Restore a soft-deleted User
*/
public function restore(string $id): bool
{
$user = User::onlyTrashed()->find($id);
if ($user) {
return (bool) $user->restore();
}
return false;
}
/**
* Get all Ranks
*/
public function all(string $search = ''): Collection
{
$query = User::visibleTo(auth()->user())->excludeDevelopersUnlessDeveloper()->orderBy('name');
$query = User::excludeDevelopersUnlessDeveloper()->orderBy('name');
if (! empty($search)) {
$query->where(function ($q) use ($search) {
$q->where('name', 'ILIKE', "%{$search}%")
->orWhere('ic_number', 'ILIKE', "%{$search}%")
->orWhere('email', 'ILIKE', "%{$search}%")
->orWhere('phone_number', 'ILIKE', "%{$search}%")
->orWhereHas('roles', function ($roleQuery) use ($search) {
$roleQuery->whereRaw('LOWER(name) ILIKE ?', ['%' . strtolower($search) . '%']);
});
});
}
$this->applySearch($query, $search);
return $query->get();
}