client id reports

This commit is contained in:
kroutony 2022-07-09 22:12:58 +08:00
parent 44cfb2b170
commit 4c29eb106e

View File

@ -23,13 +23,21 @@ private function groupAndSumPaymentsByYear($payments)
});
}
public function reports()
public function reports(Request $request)
{
$clientId = $request->get('client_id');
$today = Carbon::today();
$paymentsInThisYear = Payment::whereBetween(
$paymentQuery = Payment::whereBetween(
'created_at',
[$today->startOfYear()->toDateTimeString(), $today->endOfYear()->toDateTimeString()]
)->get();
);
if($clientId) {
$paymentQuery->whereHas('project', function($query) use ($clientId) {
return $query->where('client_id', '=', $clientId);
});
}
$paymentsInThisYear = $paymentQuery->get();
$thisYearPaymentGroup = $this->groupAndSumPaymentsByYear($paymentsInThisYear);
$lastYearToday = $today->clone()->modify('-1 year');