report可過濾client
This commit is contained in:
parent
4c29eb106e
commit
851ad32aaf
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Client;
|
||||
use App\Models\Payment;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
@ -25,6 +26,7 @@ private function groupAndSumPaymentsByYear($payments)
|
||||
|
||||
public function reports(Request $request)
|
||||
{
|
||||
$clients = Client::all();
|
||||
$clientId = $request->get('client_id');
|
||||
$today = Carbon::today();
|
||||
$paymentQuery = Payment::whereBetween(
|
||||
@ -32,10 +34,12 @@ public function reports(Request $request)
|
||||
[$today->startOfYear()->toDateTimeString(), $today->endOfYear()->toDateTimeString()]
|
||||
);
|
||||
|
||||
$client = null;
|
||||
if($clientId) {
|
||||
$paymentQuery->whereHas('project', function($query) use ($clientId) {
|
||||
return $query->where('client_id', '=', $clientId);
|
||||
});
|
||||
$client = Client::find($clientId);
|
||||
}
|
||||
$paymentsInThisYear = $paymentQuery->get();
|
||||
$thisYearPaymentGroup = $this->groupAndSumPaymentsByYear($paymentsInThisYear);
|
||||
@ -59,6 +63,6 @@ public function reports(Request $request)
|
||||
'sum' => $lastYearPaymentGroup->sum(),
|
||||
],
|
||||
];
|
||||
return view('reports', ['data' => $data]);
|
||||
return view('reports', ['data' => $data, 'client' => $client, 'clients' => $clients]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,6 +4,25 @@
|
||||
<div class="container">
|
||||
<div class="row justify-content-center">
|
||||
<div class="col-6">
|
||||
<div>
|
||||
<form>
|
||||
<div class="col">
|
||||
<select name="client_id" class="form-control">
|
||||
@foreach($clients as $client)
|
||||
<option value="{{ $client->id }}">{{ $client->name }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
<div class="col">
|
||||
<button>搜尋</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
</div>
|
||||
@if($client)
|
||||
<div>客戶: {{ $client->name }}</div>
|
||||
@endif
|
||||
|
||||
今年 ({{ $data['thisYearPaymentGroup']['year'] }}) 總收入 : {{ $data['thisYearPaymentGroup']['sum'] }}
|
||||
<canvas id="myChart" width="400" height="400"></canvas>
|
||||
<script>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user