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

Commit 36f856b

Browse files
author
Mario Basic
committed
New feature in works.
1 parent 1c9d07f commit 36f856b

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

app/Http/Controllers/HomeController.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
namespace App\Http\Controllers;
44

5+
use App\Client;
6+
use App\Service;
7+
use App\Category;
8+
use Carbon\Carbon;
59
use App\Occurrence;
610
use App\Http\Requests;
711
use Illuminate\Http\Request;
8-
use App\Service;
9-
use App\Client;
10-
use App\Category;
1112

1213
class HomeController extends Controller
1314
{
@@ -49,8 +50,19 @@ public function index()
4950
$upcomingOccurrences = [];
5051
}
5152

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));
57+
})
58+
->where('payment_received', 0)
59+
// Return only occurrences that belong to services that are active
60+
->whereHas('service', function($query) {
61+
$query->where('active', 1);
62+
})->with(['service.client'])->get();
63+
5264

53-
return view('home')->with(compact('occurrences', 'upcomingOccurrences'));
65+
return view('home')->with(compact('occurrences', 'upcomingOccurrences', 'previousUnpaidOccurrences'));
5466
}
5567

5668
public function report()

app/Occurrence.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,15 @@ public function getFutureReceiptState()
6363
{
6464
return $this->receipt_sent ? 0 : 1;
6565
}
66+
67+
/**
68+
* Check if the occurrence is paid.
69+
* "Has the payment been received."
70+
*
71+
* @return boolean
72+
*/
73+
public function isPaid()
74+
{
75+
return (bool) $this->payment_received;
76+
}
6677
}

0 commit comments

Comments
 (0)