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

Commit ffbafeb

Browse files
author
Mario Basic
committed
Services are now displayed by month. Added upcoming month to overview.
1 parent ffbe7f8 commit ffbafeb

File tree

11 files changed

+140
-48
lines changed

11 files changed

+140
-48
lines changed

app/Http/Controllers/HomeController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,22 @@ public function index()
2727
$query->where('active', 1);
2828
})->with(['service.client'])->get();
2929

30-
return view('home')->with(compact('occurrences'));
30+
if($currentMonth + 1 <= 12){
31+
$upcomingOccurrences = Occurrence::orderBy('occurs_at')
32+
// Where occurs_at month and year is the same as current month and year
33+
->where(function($query) use($currentMonth, $currentYear) {
34+
$query->where('occurs_at', 'like', $currentYear . '-' . ++$currentMonth . '-%');
35+
})
36+
// Return only occurrences that belong to services that are active
37+
->whereHas('service', function($query) {
38+
$query->where('active', 1);
39+
})->with(['service.client'])->get();
40+
}
41+
else {
42+
$upcomingOccurrences = [];
43+
}
44+
45+
46+
return view('home')->with(compact('occurrences', 'upcomingOccurrences'));
3147
}
3248
}

app/Http/Controllers/ServiceController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function store(Request $request)
5555
'day' => 'required|integer|min:1|max:31',
5656
'cost' => 'required|regex:/([0-9],)+[0-9]{2,}/|min:0',
5757
'currency' => 'required|in:hrk,usd,eur',
58-
'exchange_rate' => 'required|regex:/([0-9],)+[0-9]{2,}/|min:0',
58+
'exchange_rate' => 'required|numeric|min:0',
5959
'active' => 'boolean',
6060
'client_id' => 'required|exists:clients,id'
6161
]);
@@ -69,7 +69,7 @@ public function store(Request $request)
6969
$service->day = $request->get('day');
7070
$service->cost = convert_integer($request->get('cost'));
7171
$service->currency = $request->get('currency');
72-
$service->exchange_rate = str_replace(',', '.', $request->get('exchange_rate'));
72+
$service->exchange_rate = $request->get('exchange_rate');
7373
$service->active = $request->get('active', false);
7474
$service->client()->associate($client);
7575
$service->save();
@@ -118,7 +118,7 @@ public function update(Request $request, $id)
118118
'day' => 'required|integer|min:1|max:31',
119119
'cost' => 'required|regex:/([0-9],)+[0-9]{2,}/|min:0',
120120
'currency' => 'required|in:hrk,usd,eur',
121-
'exchange_rate' => 'required|regex:/([0-9],)+[0-9]{2,}/|min:0',
121+
'exchange_rate' => 'required|numeric|min:0',
122122
'active' => 'boolean',
123123
'client_id' => 'required|exists:clients,id'
124124
]);
@@ -130,7 +130,7 @@ public function update(Request $request, $id)
130130
'day' => $request->get('day'),
131131
'cost' => convert_integer($request->get('cost')),
132132
'currency' => $request->get('currency'),
133-
'exchange_rate' => str_replace(',', '.', $request->get('exchange_rate')),
133+
'exchange_rate' => $request->get('exchange_rate'),
134134
'active' => $request->get('active', false),
135135
]);
136136

public/build/js/all.js.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/js/app-6a274cc27f.js renamed to public/build/js/app-953d76804f.js

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/js/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/rev-manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"css/app.css": "css/app-b139bf95a1.css",
3-
"js/app.js": "js/app-6a274cc27f.js"
3+
"js/app.js": "js/app-953d76804f.js"
44
}

public/js/app.js

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/js/app.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/assets/js/app.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ $('#currency').on('change', function() {
2828
},
2929
method: 'GET',
3030
success: function (data) {
31-
data = data.replace('.', ',');
3231
$('#exchange_rate').val(data);
3332
}
3433
});

resources/views/home.blade.php

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,22 @@
1313
])
1414
</div>
1515
</div>
16+
@if(count($occurrences) > 0)
1617
<div class="row">
1718
<div class="col-md-12">
18-
<h2>This month</h2>
19+
<?php
20+
$usd_sum = 0;
21+
foreach($occurrences as $occurrence) {
22+
$usd_sum+= ($occurrence->service->cost / 100) * $occurrence->service->exchange_rate;
23+
}
24+
$usd_sum = ceil($usd_sum);
25+
?>
26+
<h2>
27+
This month
28+
<small class="pull-right" style="margin-top: 15px;">
29+
TOTAL {{ number_format($usd_sum, 2, ',', '.') }} USD
30+
</small>
31+
</h2>
1932
<div class="table-responsive">
2033
<table class="table">
2134
<tr>
@@ -40,10 +53,53 @@
4053
@endforeach
4154
</table>
4255
</div>
43-
@if(count($occurrences) == 0)
44-
<p class="lead">Nothing to bill this month :/</p>
45-
@endif
4656
</div>
4757
</div>
58+
@else
59+
<p class="lead">Nothing to bill this month :/</p>
60+
@endif
61+
@if(count($upcomingOccurrences) > 0)
62+
<div class="row">
63+
<div class="col-md-12">
64+
<?php
65+
$usd_sum = 0;
66+
foreach($upcomingOccurrences as $occurrence) {
67+
$usd_sum+= ($occurrence->service->cost / 100) * $occurrence->service->exchange_rate;
68+
}
69+
$usd_sum = ceil($usd_sum);
70+
?>
71+
<h2>
72+
Upcoming month
73+
<small class="pull-right" style="margin-top: 15px;">
74+
TOTAL {{ number_format($usd_sum, 2, ',', '.') }} USD
75+
</small>
76+
</h2>
77+
<div class="table-responsive">
78+
<table class="table">
79+
<tr>
80+
<th>Date</th>
81+
<th>Service</th>
82+
<th>Client</th>
83+
<th>Cost</th>
84+
<th>Offer sent</th>
85+
<th>Payment received</th>
86+
<th>Receipt sent</th>
87+
</tr>
88+
@foreach($upcomingOccurrences as $occurrence)
89+
<tr>
90+
<td>{{ $occurrence->occurs_at->format('d.m.Y') }}</td>
91+
<td>{{ $occurrence->service->title }}</td>
92+
<td>{{ $occurrence->service->client->name }}</td>
93+
<td>{{ $occurrence->service->formatted_cost }}</td>
94+
<td>{{ $occurrence->offer_sent }}</td>
95+
<td>{{ $occurrence->payment_received }}</td>
96+
<td>{{ $occurrence->receipt_sent }}</td>
97+
</tr>
98+
@endforeach
99+
</table>
100+
</div>
101+
</div>
102+
</div>
103+
@endif
48104
</div>
49105
@endsection

resources/views/services/index.blade.php

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,40 +18,62 @@
1818
<a href="{{ route('services.create') }}" class="btn btn-primary btn-lg">Add Service</a>
1919
</p>
2020
<br />
21-
<div class="table-responsive">
22-
<table class="table">
23-
<tr>
24-
<th>Repeats on</th>
25-
<th>Title</th>
26-
<th>Client</th>
27-
<th>Active</th>
28-
<th>Note</th>
29-
<th>Cost</th>
30-
<th></th>
31-
</tr>
3221

33-
@foreach($services as $service)
34-
<tr>
35-
<td>{{ $service->day }}.{{ $service->month }}</td>
36-
<td>{{ $service->title }}</td>
37-
<td>{{ $service->client->name }}</td>
38-
<td>{{ $service->active }}</td>
39-
<td>{{ $service->note }}</td>
40-
<td>{{ $service->formatted_cost }}</td>
41-
<td>
42-
{{ Form::open(['route' => ['services.destroy', $service->id], 'method' => 'DELETE', 'class' => 'confirm']) }}
43-
<a href="{{ route('services.edit', $service->id) }}" class="btn btn-xs btn-default">
44-
<i class="fa fa-fw fa-edit"></i> Edit
45-
</a>
46-
<button name="service_{{ $service->id }}" type="submit" class="btn btn-xs btn-danger">
47-
<i class="fa fa-fw fa-trash"></i> Delete
48-
</button>
49-
{{ Form::close() }}
50-
</td>
51-
</tr>
52-
@endforeach
53-
</table>
54-
</div>
22+
@for($i = 1; $i <= 12; $i++)
23+
@if($services->where('month', $i)->count() > 0)
24+
25+
<?php
26+
$usd_sum = 0;
27+
foreach($services->where('month', $i) as $service) {
28+
$usd_sum+= ($service->cost / 100) * $service->exchange_rate;
29+
}
30+
$usd_sum = ceil($usd_sum);
31+
?>
32+
33+
<h2>
34+
{{ date('F', mktime(0, 0, 0, $i)) }}
35+
<small>{{ $i }}</small>
36+
<small class="pull-right" style="margin-top: 15px;">
37+
TOTAL {{ number_format($usd_sum, 2, ',', '.') }} USD
38+
</small>
39+
</h2>
40+
41+
<div class="table-responsive">
42+
<table class="table">
43+
<tr>
44+
<th>Repeats on</th>
45+
<th>Title</th>
46+
<th>Client</th>
47+
<th>Active</th>
48+
<th>Note</th>
49+
<th>Cost</th>
50+
<th></th>
51+
</tr>
52+
53+
@foreach($services->where('month', $i) as $service)
54+
<tr>
55+
<td>{{ $service->day }}.{{ $service->month }}</td>
56+
<td>{{ $service->title }}</td>
57+
<td>{{ $service->client->name }}</td>
58+
<td>{{ $service->active }}</td>
59+
<td>{{ $service->note }}</td>
60+
<td>{{ $service->formatted_cost }}</td>
61+
<td>
62+
{{ Form::open(['route' => ['services.destroy', $service->id], 'method' => 'DELETE', 'class' => 'confirm']) }}
63+
<a href="{{ route('services.edit', $service->id) }}" class="btn btn-xs btn-default">
64+
<i class="fa fa-fw fa-edit"></i> Edit
65+
</a>
66+
<button name="service_{{ $service->id }}" type="submit" class="btn btn-xs btn-danger">
67+
<i class="fa fa-fw fa-trash"></i> Delete
68+
</button>
69+
{{ Form::close() }}
70+
</td>
71+
</tr>
72+
@endforeach
73+
</table>
74+
</div>
75+
@endif
76+
@endfor
5577
</div>
5678
</div>
5779
</div>

0 commit comments

Comments
 (0)