Add feature for online transaction report
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\QueryBuilders;
|
||||
|
||||
use App\TransactionOnline;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TransactionOnlineBuilder extends Builder
|
||||
{
|
||||
public function filter(Request $request)
|
||||
{
|
||||
return $this->with('cawangan')
|
||||
->whereDatePaidBetween($request)
|
||||
->when($request->filled('kodcaw'), fn($query) => $query->whereCawanganCode($request->kodcaw))
|
||||
->when($request->filled('status'), fn($query) => $query->whereStatus($request->status))
|
||||
->when($request->isNotFilled('status'), fn($query) => $query->whereStatus('PAID'));
|
||||
}
|
||||
|
||||
public function whereDatePaidBetween(Request $request): self
|
||||
{
|
||||
$startDate = $request->filled('startDate') ?
|
||||
Carbon::parse($request->startDate)->startOfDay() :
|
||||
Carbon::now()->startOfDay();
|
||||
|
||||
$endDate = $request->filled('endDate') ?
|
||||
Carbon::parse($request->endDate)->startOfDay() :
|
||||
Carbon::now()->startOfDay();
|
||||
|
||||
return $this->whereBetween('paid_at', [$startDate, $endDate]);
|
||||
}
|
||||
|
||||
public function whereCawanganCode(string $kodcaw): self
|
||||
{
|
||||
return $this->where('kodcaw', $kodcaw);
|
||||
}
|
||||
|
||||
public function whereStatus(string $status): self
|
||||
{
|
||||
return $this->where('status', $status);
|
||||
}
|
||||
|
||||
public function orderBy(string $orderBy): self
|
||||
{
|
||||
return $this->orderBy($orderBy);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user