Skip to content
This repository was archived by the owner on Jan 5, 2019. It is now read-only.

Commit 51afd5c

Browse files
author
Mario Basic
committed
Added previous unpaid occurrences to overview. Added a partial for occurrences table.
1 parent 36f856b commit 51afd5c

File tree

3 files changed

+142
-141
lines changed

3 files changed

+142
-141
lines changed

app/Http/Controllers/HomeController.php

Lines changed: 76 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -12,57 +12,94 @@
1212

1313
class HomeController extends Controller
1414
{
15-
/**
16-
* Show the application dashboard.
17-
*
18-
* @return \Illuminate\Http\Response
19-
*/
20-
public function index()
15+
protected $occurrences;
16+
17+
public function __construct(Occurrence $occurrences)
18+
{
19+
$this->occurrences = $occurrences;
20+
}
21+
22+
public function getOccurrencesForMonth(int $month)
2123
{
22-
$currentMonth = date('m');
23-
$currentYear = date('Y');
24-
$occurrences = Occurrence::orderBy('occurs_at')
25-
// Where occurs_at month and year is the same as current month and year
26-
->where(function($query) use($currentMonth, $currentYear) {
27-
$query->where('occurs_at', 'like', $currentYear . '-' . $currentMonth . '-%');
28-
})
29-
// Return only occurrences that belong to services that are active
30-
->whereHas('service', function($query) {
31-
$query->where('active', 1);
32-
})->with(['service.client'])->get();
33-
34-
if($currentMonth + 1 <= 12){
35-
$upcomingMonth = ++$currentMonth;
36-
if($upcomingMonth < 10) {
37-
$upcomingMonth = '0' . $upcomingMonth;
38-
}
39-
$upcomingOccurrences = Occurrence::orderBy('occurs_at')
40-
// Where occurs_at month and year is the same as upcoming month and current year
41-
->where(function($query) use($upcomingMonth, $currentYear) {
42-
$query->where('occurs_at', 'like', $currentYear . '-' . $upcomingMonth . '-%');
24+
// Change (int 9) to (string '09')
25+
if($month < 10) {
26+
$month = '0' . $month;
27+
}
28+
29+
$year = Carbon::now()->year;
30+
31+
return $this->occurrences->orderBy('occurs_at')
32+
// Where occurs_at month and year is
33+
// the same as current month and year
34+
->where(function($query) use($month, $year) {
35+
// $date = 2016-07-%
36+
$date = $year . '-' . $month . '-%';
37+
38+
$query->where('occurs_at', 'like', $date);
4339
})
44-
// Return only occurrences that belong to services that are active
40+
// Return only occurrences that belong
41+
// to services that are active
4542
->whereHas('service', function($query) {
4643
$query->where('active', 1);
47-
})->with(['service.client'])->get();
48-
}
49-
else {
50-
$upcomingOccurrences = [];
44+
})
45+
->with(['service.client'])
46+
->get();
47+
}
48+
public function getOccurrencesForCurrentMonth()
49+
{
50+
$month = Carbon::now()->month;
51+
52+
return $this->getOccurrencesForMonth($month);
53+
}
54+
55+
public function getOccurrencesForNextMonth()
56+
{
57+
$month = Carbon::now()->month;
58+
$occurrences = [];
59+
60+
if(++$month <= 12){
61+
$occurrences = $this->getOccurrencesForMonth($month);
5162
}
5263

53-
$previousUnpaidOccurrences = Occurrence::orderBy('occurs_at')
54-
// Where occurs_at month and year is the same as upcoming month and current year
55-
->where(function($query) use($currentYear, $currentMonth) {
56-
$query->where('occurs_at', '<', Carbon::create($currentYear, $currentMonth, 1));
64+
return $occurrences;
65+
}
66+
67+
public function getPreviousUnpaidOccurrences()
68+
{
69+
$date = Carbon::now();
70+
$date->day = 1;
71+
$date->hour = 0;
72+
$date->minute = 0;
73+
$date->second = 0;
74+
75+
return $this->occurrences->orderBy('occurs_at')
76+
->where(function($query) use ($date) {
77+
$query->where('occurs_at', '<', $date);
5778
})
5879
->where('payment_received', 0)
59-
// Return only occurrences that belong to services that are active
80+
// Return only occurrences that belong
81+
// to services that are active
6082
->whereHas('service', function($query) {
6183
$query->where('active', 1);
62-
})->with(['service.client'])->get();
84+
})
85+
->with(['service.client'])
86+
->get();
87+
}
88+
89+
/**
90+
* Show the application dashboard.
91+
*
92+
* @return \Illuminate\Http\Response
93+
*/
94+
public function index()
95+
{
96+
$occurrencesThisMonth = $this->getOccurrencesForCurrentMonth();
97+
98+
$occurrencesNextMonth = $this->getOccurrencesForNextMonth();
6399

100+
$previousUnpaidOccurrences = $this->getPreviousUnpaidOccurrences();
64101

65-
return view('home')->with(compact('occurrences', 'upcomingOccurrences', 'previousUnpaidOccurrences'));
102+
return view('home')->with(compact('occurrencesThisMonth', 'occurrencesNextMonth', 'previousUnpaidOccurrences'));
66103
}
67104

68105
public function report()

resources/views/home.blade.php

Lines changed: 16 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -15,107 +15,21 @@
1515
])
1616
</div>
1717
</div>
18-
@if(count($occurrences) > 0)
19-
<div class="row">
20-
<div class="col-md-12">
21-
<h3>
22-
This month
23-
<small class="pull-right" style="margin-top: 15px;">
24-
TOTAL {{ $Service->getSumForMonth(date('n'), true) }}
25-
</small>
26-
</h3>
27-
<div class="table-responsive">
28-
<table class="table">
29-
<tr>
30-
<th>Date</th>
31-
<th>Service</th>
32-
<th>Client</th>
33-
<th>Category</th>
34-
<th>Cost</th>
35-
<th>Offer sent</th>
36-
<th>Payment received</th>
37-
<th>Receipt sent</th>
38-
</tr>
39-
@foreach($occurrences as $occurrence)
40-
<tr>
41-
<td>{{ $occurrence->occurs_at->format('d.m.Y') }}</td>
42-
<td>{{ $occurrence->service->title }}</td>
43-
<td>{{ $occurrence->service->client->name }}</td>
44-
<td>{{ $occurrence->service->category->name or 'n/a' }}</td>
45-
<td>{{ $occurrence->service->formatted_cost }}</td>
46-
<td class="kyle-change-boolean"
47-
data-url="/api/v1/occurrences/{{ $occurrence->id }}/offer"
48-
data-state="{{ $occurrence->getFutureOfferState() }}">
49-
{{ $occurrence->offer_sent }}
50-
</td>
51-
<td class="kyle-change-boolean"
52-
data-url="/api/v1/occurrences/{{ $occurrence->id }}/payment"
53-
data-state="{{ $occurrence->getFuturePaymentState() }}">
54-
{{ $occurrence->payment_received }}
55-
</td>
56-
<td class="kyle-change-boolean"
57-
data-url="/api/v1/occurrences/{{ $occurrence->id }}/receipt"
58-
data-state="{{ $occurrence->getFutureReceiptState() }}">
59-
{{ $occurrence->receipt_sent }}
60-
</td>
61-
</tr>
62-
@endforeach
63-
</table>
64-
</div>
65-
</div>
66-
</div>
67-
@else
68-
<p class="lead">Nothing to bill this month :/</p>
69-
@endif
70-
@if(count($upcomingOccurrences) > 0)
71-
<div class="row">
72-
<div class="col-md-12">
73-
<h3>
74-
Upcoming month
75-
<small class="pull-right" style="margin-top: 15px;">
76-
TOTAL {{ $Service->getSumForMonth(date('n') + 1, true) }}
77-
</small>
78-
</h3>
79-
<div class="table-responsive">
80-
<table class="table">
81-
<tr>
82-
<th>Date</th>
83-
<th>Service</th>
84-
<th>Client</th>
85-
<th>Category</th>
86-
<th>Cost</th>
87-
<th>Offer sent</th>
88-
<th>Payment received</th>
89-
<th>Receipt sent</th>
90-
</tr>
91-
@foreach($upcomingOccurrences as $occurrence)
92-
<tr>
93-
<td>{{ $occurrence->occurs_at->format('d.m.Y') }}</td>
94-
<td>{{ $occurrence->service->title }}</td>
95-
<td>{{ $occurrence->service->client->name }}</td>
96-
<td>{{ $occurrence->service->category->name or 'n/a' }}</td>
97-
<td>{{ $occurrence->service->formatted_cost }}</td>
98-
<td class="kyle-change-boolean"
99-
data-url="/api/v1/occurrences/{{ $occurrence->id }}/offer"
100-
data-state="{{ $occurrence->getFutureOfferState() }}">
101-
{{ $occurrence->offer_sent }}
102-
</td>
103-
<td class="kyle-change-boolean"
104-
data-url="/api/v1/occurrences/{{ $occurrence->id }}/payment"
105-
data-state="{{ $occurrence->getFuturePaymentState() }}">
106-
{{ $occurrence->payment_received }}
107-
</td>
108-
<td class="kyle-change-boolean"
109-
data-url="/api/v1/occurrences/{{ $occurrence->id }}/receipt"
110-
data-state="{{ $occurrence->getFutureReceiptState() }}">
111-
{{ $occurrence->receipt_sent }}
112-
</td>
113-
</tr>
114-
@endforeach
115-
</table>
116-
</div>
117-
</div>
118-
</div>
119-
@endif
18+
19+
@include('partials._occurrences_table', [
20+
'title' => 'This Month',
21+
'occurrences' => $occurrencesThisMonth
22+
])
23+
24+
@include('partials._occurrences_table', [
25+
'title' => 'Upcoming Month',
26+
'occurrences' => $occurrencesNextMonth
27+
])
28+
29+
@include('partials._occurrences_table', [
30+
'title' => 'Have not received payment for',
31+
'occurrences' => $previousUnpaidOccurrences
32+
])
33+
12034
</div>
12135
@endsection
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
@if(count($occurrences) > 0)
2+
<div class="row">
3+
<div class="col-md-12">
4+
<h3>
5+
{{ $title or 'Upcoming month' }}
6+
<small class="pull-right" style="margin-top: 15px;">
7+
TOTAL {{ $Service->getSumForMonth(date('n') + 1, true) }}
8+
</small>
9+
</h3>
10+
<div class="table-responsive">
11+
<table class="table">
12+
<tr>
13+
<th>Date</th>
14+
<th>Service</th>
15+
<th>Client</th>
16+
<th>Category</th>
17+
<th>Cost</th>
18+
<th>Offer sent</th>
19+
<th>Payment received</th>
20+
<th>Receipt sent</th>
21+
</tr>
22+
@foreach($occurrences as $occurrence)
23+
<tr>
24+
<td>{{ $occurrence->occurs_at->format('d.m.Y') }}</td>
25+
<td>{{ $occurrence->service->title }}</td>
26+
<td>{{ $occurrence->service->client->name }}</td>
27+
<td>{{ $occurrence->service->category->name or 'n/a' }}</td>
28+
<td>{{ $occurrence->service->formatted_cost }}</td>
29+
<td class="kyle-change-boolean"
30+
data-url="/api/v1/occurrences/{{ $occurrence->id }}/offer"
31+
data-state="{{ $occurrence->getFutureOfferState() }}">
32+
{{ $occurrence->offer_sent }}
33+
</td>
34+
<td class="kyle-change-boolean"
35+
data-url="/api/v1/occurrences/{{ $occurrence->id }}/payment"
36+
data-state="{{ $occurrence->getFuturePaymentState() }}">
37+
{{ $occurrence->payment_received }}
38+
</td>
39+
<td class="kyle-change-boolean"
40+
data-url="/api/v1/occurrences/{{ $occurrence->id }}/receipt"
41+
data-state="{{ $occurrence->getFutureReceiptState() }}">
42+
{{ $occurrence->receipt_sent }}
43+
</td>
44+
</tr>
45+
@endforeach
46+
</table>
47+
</div>
48+
</div>
49+
</div>
50+
@endif

0 commit comments

Comments
 (0)