1 | <?php |
||
18 | class TimeCalculatorService |
||
19 | { |
||
20 | |||
21 | /** |
||
22 | * @var \JhFlexiTime\Repository\BookingRepositoryInterface |
||
23 | */ |
||
24 | protected $bookingRepository; |
||
25 | |||
26 | /** |
||
27 | * @var BalanceRepositoryInterface |
||
28 | */ |
||
29 | protected $balanceRepository; |
||
30 | |||
31 | /** |
||
32 | * @var \JhFlexiTime\Service\PeriodServiceInterface |
||
33 | */ |
||
34 | protected $periodService; |
||
35 | |||
36 | /** |
||
37 | * @var \JhFlexiTime\Options\ModuleOptions |
||
38 | */ |
||
39 | protected $options; |
||
40 | |||
41 | /** |
||
42 | * @var DateTime |
||
43 | */ |
||
44 | protected $today; |
||
45 | |||
46 | /** |
||
47 | * @param ModuleOptions $options |
||
48 | * @param BookingRepositoryInterface $bookingRepository |
||
49 | * @param BalanceRepositoryInterface $balanceRepository |
||
50 | * @param PeriodServiceInterface $periodService |
||
51 | * @param DateTime $date |
||
52 | */ |
||
53 | public function __construct( |
||
66 | |||
67 | /** |
||
68 | * @param UserInterface $user |
||
69 | * @param DateTime $period |
||
70 | * @return array |
||
71 | */ |
||
72 | public function getWeekTotals(UserInterface $user, DateTime $period) |
||
84 | |||
85 | /** |
||
86 | * |
||
87 | * @param UserInterface $user |
||
88 | * @param DateTime $userStartDate |
||
89 | * @param DateTime $period |
||
90 | * @return array |
||
91 | */ |
||
92 | public function getTotals(UserInterface $user, DateTime $userStartDate, DateTime $period) |
||
123 | |||
124 | /** |
||
125 | * This gets the balance of the CURRENT month, regardless of which month you are viewing. |
||
126 | * Viewing the running balance and balance forward of a particular month is not supported. |
||
127 | * |
||
128 | * @param UserInterface $user |
||
129 | * @param float $balanceForward |
||
130 | * |
||
131 | * @return float |
||
132 | */ |
||
133 | private function getRunningBalance(UserInterface $user, $balanceForward) |
||
145 | |||
146 | /*** |
||
147 | * @param UserInterface $user |
||
148 | * @return float |
||
149 | */ |
||
150 | private function getBalanceForward(UserInterface $user) |
||
155 | |||
156 | /** |
||
157 | * @param DateTime $period |
||
158 | * @param DateTime $today |
||
159 | * @return float |
||
160 | */ |
||
161 | private function getRemainingHours(DateTime $period, DateTime $today) |
||
176 | |||
177 | /** |
||
178 | * Get the total hours worked for the given period |
||
179 | * |
||
180 | * @param UserInterface $user |
||
181 | * @param DateTime $startDate |
||
182 | * @param DateTime $endDate |
||
183 | * @param DateTime $today |
||
184 | * @return float|int |
||
185 | */ |
||
186 | public function getTotalWorkedHours(UserInterface $user, DateTime $startDate, DateTime $endDate, DateTime $today) |
||
195 | |||
196 | /** |
||
197 | * Get the month balance. How much has been worked out of how many hours have passed. |
||
198 | * If we are looking at a future date, no hours have passed |
||
199 | * |
||
200 | * @param DateTime $startDate |
||
201 | * @param DateTime $endDate |
||
202 | * @param DateTime $today |
||
203 | * @param float $monthTotalWorked |
||
204 | * @return float |
||
205 | */ |
||
206 | private function getMonthBalance(DateTime $startDate, DateTime $endDate, DateTime $today, $monthTotalWorked) |
||
218 | |||
219 | /** |
||
220 | * Compute the start date to base total calculation on |
||
221 | * If the user joined started in the month passed in, then the start date |
||
222 | * should be the user's start date. |
||
223 | * |
||
224 | * If not, the start date should be the first day of the passed in month. |
||
225 | * This is because we don't want base calculations on a date which was before the |
||
226 | * user started |
||
227 | * |
||
228 | * @param DateTime $userStartDate |
||
229 | * @param DateTime $period |
||
230 | * @return DateTime |
||
231 | */ |
||
232 | private function getStartDate(DateTime $userStartDate, DateTime $period) |
||
239 | |||
240 | /** |
||
241 | * Compute the end date to base total calculation on |
||
242 | * If the passed in month is the current month, then the end date should be the current day |
||
243 | * - we don't want to include days which haven't gone by yet |
||
244 | * |
||
245 | * Other wise the end date should just be the last day in the period we are querying |
||
246 | * |
||
247 | * @param DateTime $period |
||
248 | * @param DateTime $today |
||
249 | * @return DateTime |
||
250 | */ |
||
251 | private function getEndDate(DateTime $period, DateTime $today) |
||
259 | |||
260 | /** |
||
261 | * Did the user start in the given month? |
||
262 | * |
||
263 | * @param DateTime $userStartDate |
||
264 | * @param DateTime $today |
||
265 | * @return bool |
||
266 | */ |
||
267 | private function userStartedInMonth(DateTime $userStartDate, DateTime $today) |
||
271 | } |
||
272 |