ultimatepos/app/Services/Api/SellService.php

44 lines
1.3 KiB
PHP

<?php
namespace App\Services\Api;
use App\Transaction;
use Illuminate\Http\Request;
class SellService
{
public function list(Request $request, int $business_id)
{
$query = Transaction::where('business_id', $business_id)
->where('type', 'sell')
->with(['contact', 'location', 'sell_lines']);
if ($request->filled('location_id')) {
$query->where('location_id', $request->input('location_id'));
}
if ($request->filled('status')) {
$query->where('status', $request->input('status'));
}
if ($request->filled('search')) {
$search = $request->input('search');
$query->where(function ($q) use ($search) {
$q->where('invoice_no', 'like', "%{$search}%")
->orWhere('ref_no', 'like', "%{$search}%");
});
}
return $query->orderBy('transaction_date', 'desc')
->paginate($request->input('per_page', 25));
}
public function find(int $business_id, int $id): Transaction
{
return Transaction::where('business_id', $business_id)
->where('type', 'sell')
->with(['contact', 'location', 'sell_lines.product', 'payment_lines'])
->findOrFail($id);
}
}