feat: optimize data retrieval in services by selecting specific fields for EmployeeAdvance, User, LeaveRequest, Category, Customer, and Supplier
This commit is contained in:
parent
d08f394d5b
commit
dded6058dc
@ -13,7 +13,7 @@ class CashAccountService
|
||||
{
|
||||
public function get(): ?CashAccount
|
||||
{
|
||||
return CashAccount::first();
|
||||
return CashAccount::select('id', 'name', 'balance')->first();
|
||||
}
|
||||
|
||||
public function getAllTransactions(): Collection
|
||||
@ -25,6 +25,7 @@ public function getAllTransactions(): Collection
|
||||
}
|
||||
|
||||
return $cashAccount->cashTransactions()
|
||||
->select('id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at')
|
||||
->with('createdBy.userProfile')
|
||||
->latest()
|
||||
->get();
|
||||
|
||||
@ -15,7 +15,8 @@ class EmployeeAdvanceService
|
||||
{
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return EmployeeAdvance::with(['employee.user.userProfile'])
|
||||
return EmployeeAdvance::select('id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at')
|
||||
->with(['employee.user.userProfile'])
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
|
||||
@ -10,8 +10,12 @@ class EmployeeService
|
||||
{
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return User::whereHas('employee')
|
||||
->with(['userProfile', 'employee'])
|
||||
return User::select('id', 'email', 'username', 'is_active')
|
||||
->whereHas('employee')
|
||||
->with([
|
||||
'userProfile' => fn ($q) => $q->select('id', 'user_id', 'full_name', 'phone_number'),
|
||||
'employee' => fn ($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
|
||||
])
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
|
||||
@ -12,7 +12,8 @@ class LeaveRequestService
|
||||
{
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return LeaveRequest::with(['employee.user.userProfile', 'verifiedBy'])
|
||||
return LeaveRequest::select('id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at')
|
||||
->with(['employee.user.userProfile'])
|
||||
->latest()
|
||||
->get();
|
||||
}
|
||||
|
||||
@ -9,7 +9,7 @@ class CategoryService
|
||||
{
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return Category::latest()->get();
|
||||
return Category::select('id', 'name')->latest()->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Category
|
||||
|
||||
@ -9,7 +9,7 @@ class CustomerService
|
||||
{
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return Customer::latest()->get();
|
||||
return Customer::select('id', 'name', 'phone_number', 'address')->latest()->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Customer
|
||||
|
||||
@ -9,7 +9,7 @@ class SupplierService
|
||||
{
|
||||
public function getAll(): Collection
|
||||
{
|
||||
return Supplier::latest()->get();
|
||||
return Supplier::select('id', 'name', 'phone_number', 'address')->latest()->get();
|
||||
}
|
||||
|
||||
public function create(array $data): Supplier
|
||||
|
||||
Loading…
Reference in New Issue
Block a user