refactor: update select statements to use array syntax for improved readability
This commit is contained in:
parent
d853e742ed
commit
705f0d3efa
@ -25,7 +25,7 @@ public function __construct(
|
||||
|
||||
public function get(): ?CashAccount
|
||||
{
|
||||
return CashAccount::select('id', 'name', 'balance')->first();
|
||||
return CashAccount::select(['id', 'name', 'balance'])->first();
|
||||
}
|
||||
|
||||
public function getAllTransactions(array $filters = []): Collection
|
||||
@ -37,7 +37,7 @@ public function getAllTransactions(array $filters = []): Collection
|
||||
}
|
||||
|
||||
return $cashAccount->cashTransactions()
|
||||
->select('id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at')
|
||||
->select(['id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at'])
|
||||
->with('createdBy.userProfile', 'media')
|
||||
->when($filters['type'] ?? null, function ($query, $type) {
|
||||
$query->where('type', $type);
|
||||
@ -56,7 +56,7 @@ public function paginatedTransactions(int $perPage = 25, string $search = '', st
|
||||
}
|
||||
|
||||
$paginator = $cashAccount->cashTransactions()
|
||||
->select('id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at')
|
||||
->select(['id', 'created_by_id', 'reference_type', 'reference_id', 'amount', 'balance_after', 'type', 'description', 'created_at'])
|
||||
->with('createdBy.userProfile', 'media')
|
||||
->when($search, fn ($q) => $q->where('description', 'like', "%{$search}%"))
|
||||
->when($filters['type'] ?? null, function ($query, $type) {
|
||||
|
||||
@ -18,7 +18,7 @@ class EmployeeAdvanceService
|
||||
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return EmployeeAdvance::select('id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at')
|
||||
return EmployeeAdvance::select(['id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at'])
|
||||
->with(['employee.user.userProfile'])
|
||||
->latest()
|
||||
->get();
|
||||
@ -27,7 +27,7 @@ public function getAll(array $filters = []): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
return EmployeeAdvance::query()
|
||||
->select('id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at')
|
||||
->select(['id', 'employee_id', 'amount', 'paid_amount', 'description', 'due_date', 'status', 'created_at'])
|
||||
->with(['employee.user.userProfile'])
|
||||
->when($search, fn ($q) => $q->where('description', 'like', "%{$search}%"))
|
||||
->orderBy($sort, $direction)
|
||||
|
||||
@ -24,7 +24,7 @@ public function __construct(
|
||||
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return Expense::select('id', 'created_by_id', 'amount', 'description', 'created_at')
|
||||
return Expense::select(['id', 'created_by_id', 'amount', 'description', 'created_at'])
|
||||
->with('createdBy.userProfile', 'media')
|
||||
->latest()
|
||||
->get()
|
||||
@ -34,7 +34,7 @@ public function getAll(array $filters = []): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
$paginator = Expense::query()
|
||||
->select('id', 'created_by_id', 'amount', 'description', 'created_at')
|
||||
->select(['id', 'created_by_id', 'amount', 'description', 'created_at'])
|
||||
->with('createdBy.userProfile', 'media')
|
||||
->when($search, fn ($q) => $q->where('description', 'like', "%{$search}%"))
|
||||
->orderBy($sort, $direction)
|
||||
|
||||
@ -19,7 +19,7 @@ class PayrollPeriodService
|
||||
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return PayrollPeriod::select('id', 'year', 'month', 'status', 'closed_at', 'created_at')
|
||||
return PayrollPeriod::select(['id', 'year', 'month', 'status', 'closed_at', 'created_at'])
|
||||
->withCount('payrolls')
|
||||
->withSum('payrolls', 'total_amount')
|
||||
->withSum('payrolls', 'bonus_amount')
|
||||
@ -38,7 +38,7 @@ public function getAll(array $filters = []): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
return PayrollPeriod::query()
|
||||
->select('id', 'year', 'month', 'status', 'closed_at', 'created_at')
|
||||
->select(['id', 'year', 'month', 'status', 'closed_at', 'created_at'])
|
||||
->withCount('payrolls')
|
||||
->withSum('payrolls', 'total_amount')
|
||||
->withSum('payrolls', 'bonus_amount')
|
||||
|
||||
@ -14,9 +14,9 @@ public function getAll(array $filters = []): Collection
|
||||
return User::select(['id', 'email', 'username', 'is_active'])
|
||||
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
|
||||
->with([
|
||||
'userProfile' => fn ($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
|
||||
'employee' => fn ($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
|
||||
'roles' => fn ($q) => $q->select('id', 'name'),
|
||||
'userProfile' => fn ($q) => $q->select(['id', 'user_id', 'full_name', 'phone_number', 'gender']),
|
||||
'employee' => fn ($q) => $q->select(['id', 'user_id', 'join_date', 'employment_status', 'base_salary']),
|
||||
'roles' => fn ($q) => $q->select(['id', 'name']),
|
||||
])
|
||||
->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status)))
|
||||
->when(isset($filters['is_active']) && $filters['is_active'] !== '', fn ($q) => $q->where('is_active', filter_var($filters['is_active'], FILTER_VALIDATE_BOOLEAN)))
|
||||
@ -31,9 +31,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
->select(['id', 'email', 'username', 'is_active'])
|
||||
->where(fn ($q) => $q->whereHas('employee')->orWhereHas('roles', fn ($rq) => $rq->where('name', 'Owner')))
|
||||
->with([
|
||||
'userProfile' => fn ($q) => $q->select('id', 'user_id', 'full_name', 'phone_number', 'gender'),
|
||||
'employee' => fn ($q) => $q->select('id', 'user_id', 'join_date', 'employment_status', 'base_salary'),
|
||||
'roles' => fn ($q) => $q->select('id', 'name'),
|
||||
'userProfile' => fn ($q) => $q->select(['id', 'user_id', 'full_name', 'phone_number', 'gender']),
|
||||
'employee' => fn ($q) => $q->select(['id', 'user_id', 'join_date', 'employment_status', 'base_salary']),
|
||||
'roles' => fn ($q) => $q->select(['id', 'name']),
|
||||
])
|
||||
->when($search, fn ($q) => $q->whereHas('userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%")))
|
||||
->when($filters['employment_status'] ?? null, fn ($q, $status) => $q->whereHas('employee', fn ($eq) => $eq->where('employment_status', $status)))
|
||||
|
||||
@ -14,7 +14,7 @@ class LeaveRequestService
|
||||
{
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return LeaveRequest::select('id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at')
|
||||
return LeaveRequest::select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at'])
|
||||
->with(['employee.user.userProfile'])
|
||||
->when($filters['status'] ?? null, function ($query, $status) {
|
||||
$query->where('status', $status);
|
||||
@ -26,7 +26,7 @@ public function getAll(array $filters = []): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
return LeaveRequest::query()
|
||||
->select('id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at')
|
||||
->select(['id', 'employee_id', 'start_date', 'end_date', 'total_days', 'status', 'created_at'])
|
||||
->with(['employee.user.userProfile'])
|
||||
->when($search, fn ($q) => $q->whereHas('employee.user.userProfile', fn ($uq) => $uq->where('full_name', 'like', "%{$search}%")))
|
||||
->when($filters['status'] ?? null, function ($query, $status) {
|
||||
|
||||
@ -25,7 +25,7 @@ public function __construct(
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator
|
||||
{
|
||||
$paginator = Cutting::query()
|
||||
->select('id', 'created_by_id', 'status', 'description', 'total_material_cost', 'cost_per_unit', 'created_at')
|
||||
->select(['id', 'created_by_id', 'status', 'description', 'total_material_cost', 'cost_per_unit', 'created_at'])
|
||||
->with([
|
||||
'createdBy:id',
|
||||
'createdBy.userProfile:id,user_id,full_name',
|
||||
@ -65,7 +65,7 @@ public function getForCreate(): array
|
||||
{
|
||||
return [
|
||||
'rawMaterials' => RawMaterial::query()
|
||||
->select('id', 'name', 'unit', 'is_active')
|
||||
->select(['id', 'name', 'unit', 'is_active'])
|
||||
->with([
|
||||
'rawMaterialPrices:id,raw_material_id,variant,price,stock',
|
||||
])
|
||||
|
||||
@ -24,13 +24,13 @@ public function __construct(
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator
|
||||
{
|
||||
$paginator = Purchase::query()
|
||||
->select('id', 'supplier_id', 'created_by_id', 'subtotal', 'discount', 'shipping_cost', 'total', 'notes', 'created_at')
|
||||
->select(['id', 'supplier_id', 'created_by_id', 'subtotal', 'discount', 'shipping_cost', 'total', 'notes', 'created_at'])
|
||||
->with([
|
||||
'supplier:id,name',
|
||||
'createdBy:id',
|
||||
'createdBy.userProfile:id,user_id,full_name',
|
||||
'purchaseItems' => fn ($q) => $q
|
||||
->select('id', 'purchase_id', 'raw_material_price_id', 'quantity', 'unit_price', 'subtotal')
|
||||
->select(['id', 'purchase_id', 'raw_material_price_id', 'quantity', 'unit_price', 'subtotal'])
|
||||
->orderByRaw('(SELECT variant FROM raw_material_prices WHERE raw_material_prices.id = purchase_items.raw_material_price_id)'),
|
||||
'purchaseItems.rawMaterialPrice:id,raw_material_id,variant,price,stock',
|
||||
'purchaseItems.rawMaterialPrice.rawMaterial:id,name,unit',
|
||||
@ -66,9 +66,9 @@ public function paginated(int $perPage = 25, string $search = '', string $sort =
|
||||
public function getForCreate(): array
|
||||
{
|
||||
return [
|
||||
'suppliers' => Supplier::select('id', 'name')->latest()->get(),
|
||||
'suppliers' => Supplier::select(['id', 'name'])->latest()->get(),
|
||||
'rawMaterials' => RawMaterial::query()
|
||||
->select('id', 'name', 'unit', 'is_active')
|
||||
->select(['id', 'name', 'unit', 'is_active'])
|
||||
->with([
|
||||
'rawMaterialPrices:id,raw_material_id,variant,price,stock',
|
||||
])
|
||||
|
||||
@ -26,12 +26,12 @@ public function __construct(
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc'): LengthAwarePaginator
|
||||
{
|
||||
$paginator = Restock::query()
|
||||
->select('id', 'created_by_id', 'subtotal', 'total', 'notes', 'stock_type', 'created_at')
|
||||
->select(['id', 'created_by_id', 'subtotal', 'total', 'notes', 'stock_type', 'created_at'])
|
||||
->with([
|
||||
'createdBy:id',
|
||||
'createdBy.userProfile:id,user_id,full_name',
|
||||
'restockItems' => fn ($q) => $q
|
||||
->select('id', 'restock_id', 'product_variant_id', 'quantity', 'unit_price', 'subtotal')
|
||||
->select(['id', 'restock_id', 'product_variant_id', 'quantity', 'unit_price', 'subtotal'])
|
||||
->orderByRaw('(SELECT name FROM product_variants WHERE product_variants.id = restock_items.product_variant_id)'),
|
||||
'restockItems.productVariant:id,product_id,name,stock,reject_stock,retail_stock',
|
||||
'restockItems.productVariant.product:id,name',
|
||||
@ -63,7 +63,7 @@ public function getForCreate(): array
|
||||
{
|
||||
return [
|
||||
'products' => Product::query()
|
||||
->select('id', 'name', 'status')
|
||||
->select(['id', 'name', 'status'])
|
||||
->with([
|
||||
'productVariants:id,product_id,name,stock,reject_stock',
|
||||
'productVariants.productPrices:id,variant_id,type,price',
|
||||
|
||||
@ -41,7 +41,7 @@ public function __construct(
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
$paginator = Order::query()
|
||||
->select('id', 'created_by_id', 'customer_id', 'marketing_id', 'order_number', 'channel', 'price_type', 'status', 'payment_type', 'subtotal', 'discount', 'nego_price', 'total_amount', 'cogs', 'notes', 'created_at')
|
||||
->select(['id', 'created_by_id', 'customer_id', 'marketing_id', 'order_number', 'channel', 'price_type', 'status', 'payment_type', 'subtotal', 'discount', 'nego_price', 'total_amount', 'cogs', 'notes', 'created_at'])
|
||||
->with([
|
||||
'createdBy:id',
|
||||
'createdBy.userProfile:id,user_id,full_name',
|
||||
@ -96,7 +96,7 @@ public function getFilterOptions(): array
|
||||
'channelOptions' => OrderChannel::toSelect(),
|
||||
'paymentTypeOptions' => PaymentType::toSelect(),
|
||||
'customers' => Customer::query()
|
||||
->select('id', 'name')
|
||||
->select(['id', 'name'])
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
'employees' => User::query()
|
||||
@ -118,7 +118,7 @@ public function getForCreate(): array
|
||||
{
|
||||
return [
|
||||
'products' => Product::query()
|
||||
->select('id', 'name', 'status')
|
||||
->select(['id', 'name', 'status'])
|
||||
->with([
|
||||
'productVariants:id,product_id,name,stock,reject_stock',
|
||||
'productVariants.productPrices:id,variant_id,type,price',
|
||||
@ -137,7 +137,7 @@ public function getForCreate(): array
|
||||
});
|
||||
}),
|
||||
'customers' => Customer::query()
|
||||
->select('id', 'name')
|
||||
->select(['id', 'name'])
|
||||
->orderBy('name')
|
||||
->get(),
|
||||
'employees' => User::query()
|
||||
|
||||
@ -10,13 +10,13 @@ class CategoryService
|
||||
{
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return Category::select('id', 'name')->latest()->get();
|
||||
return Category::select(['id', 'name'])->latest()->get();
|
||||
}
|
||||
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
return Category::query()
|
||||
->select('id', 'name')
|
||||
->select(['id', 'name'])
|
||||
->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%"))
|
||||
->orderBy($sort, $direction)
|
||||
->paginate($perPage);
|
||||
|
||||
@ -10,13 +10,13 @@ class CustomerService
|
||||
{
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return Customer::select('id', 'name', 'phone_number', 'address')->latest()->get();
|
||||
return Customer::select(['id', 'name', 'phone_number', 'address'])->latest()->get();
|
||||
}
|
||||
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
return Customer::query()
|
||||
->select('id', 'name', 'phone_number', 'address')
|
||||
->select(['id', 'name', 'phone_number', 'address'])
|
||||
->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%"))
|
||||
->orderBy($sort, $direction)
|
||||
->paginate($perPage);
|
||||
|
||||
@ -21,7 +21,7 @@ public function __construct(
|
||||
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
$products = Product::select('id', 'name', 'slug', 'description', 'status')
|
||||
$products = Product::select(['id', 'name', 'slug', 'description', 'status'])
|
||||
->with([
|
||||
'categories:id,name',
|
||||
'productVariants:id,product_id,name,stock,reject_stock,retail_stock',
|
||||
@ -46,7 +46,7 @@ public function getAll(array $filters = []): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
$paginator = Product::query()
|
||||
->select('id', 'name', 'slug', 'description', 'status')
|
||||
->select(['id', 'name', 'slug', 'description', 'status'])
|
||||
->with([
|
||||
'categories:id,name',
|
||||
'productVariants:id,product_id,name,stock,reject_stock,retail_stock',
|
||||
|
||||
@ -20,7 +20,7 @@ public function __construct(
|
||||
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return RawMaterial::select('id', 'name', 'unit', 'is_active')
|
||||
return RawMaterial::select(['id', 'name', 'unit', 'is_active'])
|
||||
->with([
|
||||
'rawMaterialPrices:id,raw_material_id,variant,price,stock',
|
||||
'rawMaterialPrices.media',
|
||||
@ -42,7 +42,7 @@ public function getAll(array $filters = []): Collection
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
$paginator = RawMaterial::query()
|
||||
->select('id', 'name', 'unit', 'is_active')
|
||||
->select(['id', 'name', 'unit', 'is_active'])
|
||||
->with([
|
||||
'rawMaterialPrices:id,raw_material_id,variant,price,stock',
|
||||
])
|
||||
|
||||
@ -10,13 +10,13 @@ class SupplierService
|
||||
{
|
||||
public function getAll(array $filters = []): Collection
|
||||
{
|
||||
return Supplier::select('id', 'name', 'phone_number', 'address')->latest()->get();
|
||||
return Supplier::select(['id', 'name', 'phone_number', 'address'])->latest()->get();
|
||||
}
|
||||
|
||||
public function paginated(int $perPage = 25, string $search = '', string $sort = 'created_at', string $direction = 'desc', array $filters = []): LengthAwarePaginator
|
||||
{
|
||||
return Supplier::query()
|
||||
->select('id', 'name', 'phone_number', 'address')
|
||||
->select(['id', 'name', 'phone_number', 'address'])
|
||||
->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%"))
|
||||
->orderBy($sort, $direction)
|
||||
->paginate($perPage);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user