Skip to content

Commit

Permalink
Add area column to vacation report.
Browse files Browse the repository at this point in the history
Merge pull request #559 from Igalia/add-area-vacation-report
  • Loading branch information
jaragunde authored Feb 9, 2022
2 parents 8d43ec9 + 040b922 commit fbe35ce
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 60 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/runtests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ jobs:
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
- name: Generate autoload files
run: composer dump-autoload -o
- name: Run tests
run: ./vendor/bin/phpunit --testdox tests

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"autoload": {
"psr-4": {
"Phpreport\\Model\\": "model/",
"Phpreport\\Util\\": "util/",
"Phpreport\\Web\\": "web/"
}
},
Expand Down
15 changes: 7 additions & 8 deletions model/dao/AreaHistoryDAO/PostgreSQLAreaHistoryDAO.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,18 @@ function __construct() {
*/
protected function setValues($row)
{

$areaHistoryVO = new AreaHistoryVO();
$areaHistoryVO = new AreaHistoryVO();

$areaHistoryVO->setId($row['id']);
$areaHistoryVO->setInitDate(date_create($row['init_date']));
$areaHistoryVO->setUserId($row['usrid']);
if (is_null($row['end_date']))
$areaHistoryVO->setUserId($row['usrid']);
if (is_null($row['end_date']))
$areaHistoryVO->setEndDate(NULL);
else
$areaHistoryVO->setEndDate(date_create($row['end_date']));
$areaHistoryVO->setAreaId($row['areaid']);
else
$areaHistoryVO->setEndDate(date_create($row['end_date']));
$areaHistoryVO->setAreaId($row['areaid']);

return $areaHistoryVO;
return $areaHistoryVO;
}

/** Area History retriever by id for PostgreSQL.
Expand Down
5 changes: 5 additions & 0 deletions model/facade/AdminFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
include_once(PHPREPORT_ROOT . '/model/facade/action/CreateAreaAction.php');
include_once(PHPREPORT_ROOT . '/model/facade/action/DeleteAreaAction.php');
include_once(PHPREPORT_ROOT . '/model/facade/action/UpdateAreaAction.php');
include_once(PHPREPORT_ROOT . '/model/facade/action/GetAreaByIdAction.php');
include_once(PHPREPORT_ROOT . '/model/dao/DAOFactory.php');
include_once(PHPREPORT_ROOT . '/model/vo/CommonEventVO.php');
include_once(PHPREPORT_ROOT . '/model/vo/CityVO.php');
Expand Down Expand Up @@ -263,4 +264,8 @@ static function UpdateArea(AreaVO $area) {

}

static function GetAreaById(int $areaId) {
$action = new GetAreaByIdAction($areaId);
return $action->execute();
}
}
38 changes: 38 additions & 0 deletions model/facade/action/GetAreaByIdAction.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
/*
* Copyright (C) 2022 Igalia, S.L. <info@igalia.com>
*
* This file is part of PhpReport.
*
* PhpReport is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PhpReport is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhpReport. If not, see <http://www.gnu.org/licenses/>.
*/

include_once(PHPREPORT_ROOT . '/model/facade/action/Action.php');
include_once(PHPREPORT_ROOT . '/model/dao/DAOFactory.php');

class GetAreaByIdAction extends Action
{
public function __construct($areaId)
{
$this->preActionParameter = "GET_AREA_BY_ID_PREACTION";
$this->postActionParameter = "GET_AREA_BY_ID_POSTACTION";
$this->areaId = $areaId;
}

protected function doExecute()
{
$dao = DAOFactory::getAreaDAO();
return $dao->getById($this->areaId);
}
}
16 changes: 15 additions & 1 deletion model/facade/action/GetHolidaySummaryReportAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
*/

include_once(PHPREPORT_ROOT . '/model/facade/action/GetHolidayHoursBaseAction.php');
include_once(PHPREPORT_ROOT . '/model/facade/AdminFacade.php');
include_once(PHPREPORT_ROOT . '/model/dao/DAOFactory.php');

use Phpreport\Web\services\HolidayService;
use Phpreport\Util\DateOperations;

class GetHolidaySummaryReportAction extends GetHolidayHoursBaseAction
{
Expand Down Expand Up @@ -53,16 +56,27 @@ protected function doExecute()
);
$validJourney = array_filter(
$journeyHistories,
fn ($history) => $history->dateBelongsToJourney(date_create())
fn ($history) => $history->dateBelongsToHistory(date_create())
);
$validJourney = array_pop($validJourney);
$validJourney = $validJourney ? $validJourney->getJourney() : 0;
$leaves = HolidayService::groupByWeeks($leaves, $this->weeks);
if (count($leaves) == 0) {
$leaves = $this->weeks;
}
$areas = \UsersFacade::GetUserAreaHistories($this->user->getLogin());
$currentArea = array_filter(
$areas,
fn ($area) => $area->dateBelongsToHistory(date_create())
);
$currentArea = array_pop($currentArea);
if ($currentArea) {
$currentArea = AdminFacade::GetAreaById($currentArea->getAreaId());
$currentArea = $currentArea->getName();
}
return [
'user' => $this->user->getLogin(),
'area' => $currentArea ?? '',
'availableHours' => round($summary['availableHours'][$this->user->getLogin()], 2),
'availableDays' => HolidayService::formatHours($summary['availableHours'][$this->user->getLogin()], $validJourney, 1),
'pendingHours' => round($summary['pendingHours'][$this->user->getLogin()], 2),
Expand Down
17 changes: 6 additions & 11 deletions model/vo/AreaHistoryVO.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,18 @@
*/
class AreaHistoryVO extends BaseHistoryVO
{

/**#@+
* @ignore
*/
protected $areaId = NULL;

public function setAreaId($areaId) {
public function setAreaId($areaId)
{
if (is_null($areaId))
$this->areaId = $areaId;
else
$this->areaId = $areaId;
else
$this->areaId = (int) $areaId;
}

public function getAreaId() {
public function getAreaId()
{
return $this->areaId;
}

/**#@-*/

}
41 changes: 24 additions & 17 deletions model/vo/BaseHistoryVO.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,52 +40,59 @@
*/
abstract class BaseHistoryVO
{
/**#@+
* @ignore
*/
protected $id = NULL;
protected $userId = NULL;
protected $initDate = NULL;
protected $endDate = NULL;

public function setId($id) {
public function setId($id)
{
if (is_null($id))
$this->id = $id;
else
$this->id = $id;
else
$this->id = (int) $id;
}

public function getId() {
public function getId()
{
return $this->id;
}

public function setUserId($userId) {
public function setUserId($userId)
{
if (is_null($userId))
$this->userId = $userId;
else
$this->userId = $userId;
else
$this->userId = (int) $userId;
}

public function getUserId() {
public function getUserId()
{
return $this->userId;
}

public function setInitDate(DateTime $initDate = NULL) {
public function setInitDate(DateTime $initDate = NULL)
{
$this->initDate = $initDate;
}

public function getInitDate() {
public function getInitDate()
{
return $this->initDate;
}

public function setEndDate(DateTime $endDate = NULL) {
public function setEndDate(DateTime $endDate = NULL)
{
$this->endDate = $endDate;
}

public function getEndDate() {
public function getEndDate()
{
return $this->endDate;
}

/**#@-*/

public function dateBelongsToHistory(DateTime $date): bool
{
return $date >= $this->getInitDate() && $date <= $this->getEndDate();
}
}
5 changes: 0 additions & 5 deletions model/vo/JourneyHistoryVO.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,4 @@ public function getJourney() {
}

/**#@-*/


public function dateBelongsToJourney(DateTime $date): bool{
return $date >= $this->getInitDate() && $date <= $this->getEndDate();
}
}
10 changes: 5 additions & 5 deletions tests/model/vo/JourneyHistoryVOTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testReturnFalseIfDateIsBeforeJourney(): void
$date = date_create("2020-01-01");
$this->assertEquals(
false,
$this->instance->dateBelongsToJourney($date)
$this->instance->dateBelongsToHistory($date)
);
}

Expand All @@ -33,7 +33,7 @@ public function testReturnTrueIfDateBelongsToJourney(): void
$date = date_create("2021-05-01");
$this->assertEquals(
true,
$this->instance->dateBelongsToJourney($date)
$this->instance->dateBelongsToHistory($date)
);
}

Expand All @@ -42,7 +42,7 @@ public function testReturnTrueIfDateEqualsInitOfJourney(): void
$date = date_create("2021-01-01");
$this->assertEquals(
true,
$this->instance->dateBelongsToJourney($date)
$this->instance->dateBelongsToHistory($date)
);
}

Expand All @@ -51,7 +51,7 @@ public function testReturnTrueIfDateEqualsEndOfJourney(): void
$date = date_create("2021-06-01");
$this->assertEquals(
true,
$this->instance->dateBelongsToJourney($date)
$this->instance->dateBelongsToHistory($date)
);
}

Expand All @@ -60,7 +60,7 @@ public function testReturnFalseIfDateIsAfterJourney(): void
$date = date_create("2021-07-01");
$this->assertEquals(
false,
$this->instance->dateBelongsToJourney($date)
$this->instance->dateBelongsToHistory($date)
);
}
}
19 changes: 12 additions & 7 deletions web/holidaySummary.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
<script src="vuejs/v-calendar.2.3.2.min.js"></script>

<div id="holidaySummaryReport">
<table class="report">
<div v-if="isLoading" class="loaderContainer">
<div class="loader"></div>
</div>
<table v-if="!isLoading" class="report">
<thead slot="head">
<th>User</th>
<th>Area</th>
<th>Hours/day</th>
<th>Available (days)</th>
<th>Available (hours)</th>
Expand All @@ -50,17 +54,18 @@
<tbody>
<tr v-for="row in displayData" :key="row.id">
<td>{{ row.user }}</td>
<td>{{row.hoursDay}}</td>
<td>{{row.availableDays}}</td>
<td>{{row.availableHours}}</td>
<td>{{row.pendingHours}}</td>
<td>{{row.usedHours}}</td>
<td>{{ row.area }}</td>
<td>{{ row.hoursDay }}</td>
<td>{{ row.availableDays }}</td>
<td>{{ row.availableHours }}</td>
<td>{{ row.pendingHours }}</td>
<td>{{ row.usedHours }}</td>
<td :class="{ 'alert': row.percentage < 50}">{{row.percentage}}</td>
<td v-for="userWeek in row.holidays" :key="userWeek" :class="{ 'highlight': userWeek > 0}">{{userWeek}}</td>
</tr>
</tbody>
</table>
<p class="text-center">
<p v-if="!isLoading" class="text-center">
<a href="services/getHolidaySummary.php?format=csv" class="btn">Download Report</a>
</p>
</div>
Expand Down
30 changes: 30 additions & 0 deletions web/include/phpreport.css
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,33 @@ div#tasks textarea {
.autocompleteItemBtn.active {
background-color: #f0f0f0;
}

.loaderContainer {
text-align: center;
padding: 50px;
}

.loader {
display: inline-block;
width: 20px;
height: 20px;
}
.loader:after {
content: " ";
display: block;
width: 20px;
height: 20px;
margin: 8px;
border-radius: 50%;
border: 4px solid #ccc;
border-color: #ccc transparent #ccc transparent;
animation: loader 1.2s linear infinite;
}
@keyframes loader {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
4 changes: 3 additions & 1 deletion web/js/holidaySummary.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ var app = new Vue({
data() {
return {
weeks: {},
displayData: {}
displayData: {},
isLoading: true,
};
},
created() {
Expand All @@ -43,6 +44,7 @@ var app = new Vue({
referrerPolicy: 'no-referrer',
});
const body = await res.json();
this.isLoading = false;
this.weeks = Object.keys(body.weeks);
this.displayData = body.holidays;
}
Expand Down
Loading

0 comments on commit fbe35ce

Please sign in to comment.