- Updated CustomerService to simplify getAll method. - Refactored ProductService to utilize HasRoleChecks trait and improved role verification logic. - Enhanced ProductVariantService with new methods for fetching data for restocking and transactions. - Cleaned up RawMaterialService by removing unused methods and improving data retrieval. - Adjusted SupplierService to streamline getAll method. - Refactored RoleService to use Spatie's Role model and improved role filtering logic. - Updated NotificationService to handle role labels more effectively. - Improved StockMutationService by removing redundant paginated method. - Cleaned up various frontend components to directly accept necessary props instead of nested data objects. - Updated tests to reflect changes in service method names and ensure proper notification handling.
42 lines
1.1 KiB
PHP
42 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Services\Admin\Master;
|
|
|
|
use App\Models\Customer;
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
|
use Illuminate\Database\Eloquent\Collection;
|
|
|
|
class CustomerService
|
|
{
|
|
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'])
|
|
->when($search, fn ($q) => $q->where('name', 'like', "%{$search}%"))
|
|
->orderBy($sort, $direction)
|
|
->paginate($perPage);
|
|
}
|
|
|
|
public function getAll(): Collection
|
|
{
|
|
return Customer::select(['id', 'name'])->orderBy('name')->get();
|
|
}
|
|
|
|
public function store(array $data): Customer
|
|
{
|
|
return Customer::create($data);
|
|
}
|
|
|
|
public function update(Customer $customer, array $data): Customer
|
|
{
|
|
$customer->update($data);
|
|
|
|
return $customer;
|
|
}
|
|
|
|
public function destroy(Customer $customer): bool
|
|
{
|
|
return $customer->delete();
|
|
}
|
|
}
|