migrate to gtea from bistbucket
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Restaurant\Repositories;
|
||||
|
||||
use Modules\Restaurant\Models\Purchase;
|
||||
|
||||
class PurchaseRepository
|
||||
{
|
||||
public function getAll($filters)
|
||||
{
|
||||
$restaurantId = getUserRestaurantId();
|
||||
|
||||
$query = Purchase::with([
|
||||
'supplier:id,name,phone',
|
||||
'creator:id,first_name',
|
||||
'items.ingredient:id,name,unit_id',
|
||||
])
|
||||
->where('restaurant_id', $restaurantId);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 🔍 Search Filters
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
if (! empty($filters['search'])) {
|
||||
$search = $filters['search'];
|
||||
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('invoice_no', 'like', "%{$search}%")
|
||||
->orWhereHas('supplier', function ($sq) use ($search) {
|
||||
$sq->where('name', 'like', "%{$search}%")
|
||||
->orWhere('phone', 'like', "%{$search}%");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 🔎 Filter: Supplier
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
if (! empty($filters['supplier_id'])) {
|
||||
$query->where('supplier_id', $filters['supplier_id']);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 📅 Filter: Purchase Date Range
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
if (! empty($filters['start_date']) && ! empty($filters['end_date'])) {
|
||||
$query->whereBetween('purchase_date', [
|
||||
$filters['start_date'],
|
||||
$filters['end_date'],
|
||||
]);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 🧾 Filter: Payment Status
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
if (! empty($filters['payment_status'])) {
|
||||
$query->where('payment_status', $filters['payment_status']);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 🧰 Filter: Purchase Type
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
if (! empty($filters['purchase_type'])) {
|
||||
$query->where('purchase_type', $filters['purchase_type']);
|
||||
}
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 🔽 Sorting
|
||||
|--------------------------------------------------------------------------
|
||||
| sort_by = any column (id, invoice_no, purchase_date)
|
||||
| sort_order = asc / desc
|
||||
*/
|
||||
$sortBy = $filters['sort_by'] ?? 'id';
|
||||
$sortOrder = $filters['sort_order'] ?? 'desc';
|
||||
|
||||
$query->orderBy($sortBy, $sortOrder);
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 📄 Pagination
|
||||
|--------------------------------------------------------------------------
|
||||
*/
|
||||
$perPage = $filters['per_page'] ?? 15;
|
||||
|
||||
return $query->paginate($perPage);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user