|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the HRis Software package. |
|
5
|
|
|
* |
|
6
|
|
|
* HRis - Human Resource and Payroll System |
|
7
|
|
|
* |
|
8
|
|
|
* @link http://github.com/HB-Co/HRis |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace HRis\Api\Repositories\Time; |
|
11
|
|
|
|
|
12
|
|
|
use HRis\Api\Eloquent\Employee; |
|
13
|
|
|
use HRis\Api\Eloquent\Timelog; |
|
14
|
|
|
use HRis\Api\Repositories\Repository; |
|
15
|
|
|
|
|
16
|
|
|
class TimelogRepository extends Repository |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* TimelogRepository constructor. |
|
20
|
|
|
* |
|
21
|
|
|
* @author Harlequin Doyon |
|
22
|
|
|
*/ |
|
23
|
|
|
public function __construct() |
|
24
|
|
|
{ |
|
25
|
|
|
parent::__construct(new Timelog()); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Pagination. |
|
30
|
|
|
* |
|
31
|
|
|
* @param int $id |
|
32
|
|
|
* @param string $sort |
|
33
|
|
|
* @param string $direction |
|
34
|
|
|
* |
|
35
|
|
|
* @return \Illuminate\Database\Eloquent\Collection|static[] |
|
36
|
|
|
* |
|
37
|
|
|
* @author Harlequin Doyon |
|
38
|
|
|
*/ |
|
39
|
|
|
public function paginate($id = null, $sort = 'id', $direction = 'asc') |
|
40
|
|
|
{ |
|
41
|
|
|
if (is_null($id)) { |
|
42
|
|
|
return $this->model->paginate(ROWS_PER_PAGE); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
return $this->model->whereEmployeeId($id) |
|
46
|
|
|
->orderBy($sort, $direction) |
|
47
|
|
|
->paginate(ROWS_PER_PAGE); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Check the latest timelog if user has no time in. |
|
52
|
|
|
* |
|
53
|
|
|
* @param Employee $employee |
|
54
|
|
|
* |
|
55
|
|
|
* @return \Illuminate\Database\Eloquent\Model |
|
56
|
|
|
* |
|
57
|
|
|
* @author Harlequin Doyon |
|
58
|
|
|
*/ |
|
59
|
|
|
public function hasNoLatestTimein(Employee $employee) |
|
60
|
|
|
{ |
|
61
|
|
|
$timelog = $this->latest($employee); |
|
62
|
|
|
|
|
63
|
|
|
if (!isset($timelog) || (!empty($timelog->in) && !empty($timelog->out))) { |
|
64
|
|
|
return true; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
/** |
|
71
|
|
|
* Fetch the latest record of the table. |
|
72
|
|
|
* |
|
73
|
|
|
* @param Employee $employee |
|
74
|
|
|
* |
|
75
|
|
|
* @return \Illuminate\Database\Eloquent\Model |
|
76
|
|
|
* |
|
77
|
|
|
* @author Harlequin Doyon |
|
78
|
|
|
*/ |
|
79
|
|
|
public function latest(Employee $employee) |
|
80
|
|
|
{ |
|
81
|
|
|
return $this->model->where('employee_id', $employee->id)->orderBy('created_at', 'desc')->first(); |
|
|
|
|
|
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Check the latest timelog if user has no time out. |
|
86
|
|
|
* |
|
87
|
|
|
* @param Employee $employee |
|
88
|
|
|
* |
|
89
|
|
|
* @return bool |
|
90
|
|
|
* |
|
91
|
|
|
* @author Harlequin Doyon |
|
92
|
|
|
*/ |
|
93
|
|
|
public function hasNoLatestTimeout(Employee $employee) |
|
94
|
|
|
{ |
|
95
|
|
|
$timelog = $this->latest($employee); |
|
96
|
|
|
|
|
97
|
|
|
if (isset($timelog) && is_null($timelog->out)) { |
|
98
|
|
|
return true; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
return false; |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
/** |
|
105
|
|
|
* Returns timelog in a given range. |
|
106
|
|
|
* |
|
107
|
|
|
* @param $start |
|
108
|
|
|
* @param $end |
|
109
|
|
|
* @param $employee_id |
|
110
|
|
|
* @param $rows_per_page |
|
111
|
|
|
* |
|
112
|
|
|
* @return mixed |
|
113
|
|
|
*/ |
|
114
|
|
|
public function range($start, $end, $employee_id, $rows_per_page) |
|
115
|
|
|
{ |
|
116
|
|
|
return $this->model |
|
117
|
|
|
->whereBetween('in', [$start, $end]) |
|
118
|
|
|
->where('employee_id', $employee_id) |
|
119
|
|
|
->select('id', 'employee_id', 'in', 'out', 'rendered_hours', 'created_at') |
|
120
|
|
|
->orderBy('id', 'desc') |
|
121
|
|
|
->paginate($rows_per_page); |
|
122
|
|
|
} |
|
123
|
|
|
} |
|
124
|
|
|
|
Since your code implements the magic getter
_get, this function will be called for any read access on an undefined variable. You can add the@propertyannotation to your class or interface to document the existence of this variable.If the property has read access only, you can use the @property-read annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.