Merge pull request 'womtfix/negative-werte' (#12) from womtfix/negative-werte into master

Reviewed-on: #12
This commit was merged in pull request #12.
This commit is contained in:
2021-04-15 12:25:33 +02:00
6 changed files with 76 additions and 18 deletions
+2 -1
View File
@@ -91,12 +91,13 @@ class WorkingHoursView implements ModelInterface
'overtime' => "string" 'overtime' => "string"
])] public function jsonSerialize(): array ])] public function jsonSerialize(): array
{ {
$formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S';
return [ return [
'period' => $this->getPeriod()->format($this->getPeriodDesignation()->getValue()), 'period' => $this->getPeriod()->format($this->getPeriodDesignation()->getValue()),
'periodDesignation' => strtolower($this->getPeriodDesignation()->getKey()), 'periodDesignation' => strtolower($this->getPeriodDesignation()->getKey()),
'workingDays' => $this->getWorkingDays(), 'workingDays' => $this->getWorkingDays(),
'totalHours' => $this->getTotalHours()->format('%H:%I:%S'), 'totalHours' => $this->getTotalHours()->format('%H:%I:%S'),
'overtime' => $this->getOvertime()->format('%H:%I:%S') 'overtime' => $this->getOvertime()->format($formatOvertime)
]; ];
} }
} }
+20 -1
View File
@@ -12,6 +12,9 @@ use Psr\Http\Message\StreamInterface;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
use Slim\App; use Slim\App;
use Slim\Exception\HttpException; use Slim\Exception\HttpException;
use Slim\Interfaces\RouteParserInterface;
use Slim\Routing\RouteContext;
use Slim\Routing\RoutingResults;
use TorstenHettstedt\TimekeepingApi\Middleware\ErrorHandler; use TorstenHettstedt\TimekeepingApi\Middleware\ErrorHandler;
class ErrorHandlerTest extends Unit class ErrorHandlerTest extends Unit
@@ -28,6 +31,7 @@ class ErrorHandlerTest extends Unit
protected function _before(): void protected function _before(): void
{ {
parent::_before(); parent::_before();
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->app = $this->makeEmpty(App::class, [ $this->app = $this->makeEmpty(App::class, [
'getResponseFactory' => $this->makeEmpty(ResponseFactoryInterface::class, [ 'getResponseFactory' => $this->makeEmpty(ResponseFactoryInterface::class, [
'createResponse' => $this->makeEmpty(ResponseInterface::class, [ 'createResponse' => $this->makeEmpty(ResponseInterface::class, [
@@ -40,7 +44,16 @@ class ErrorHandlerTest extends Unit
]), ]),
]), ]),
]); ]);
$this->request = $this->makeEmpty(ServerRequestInterface::class); /** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->request = $this->makeEmpty(ServerRequestInterface::class, [
'getAttribute' => function($name) {
return match ($name) {
RouteContext::ROUTE_PARSER => $this->makeEmpty(RouteParserInterface::class),
RouteContext::ROUTING_RESULTS => $this->makeEmpty(RoutingResults::class),
default => null,
};
}
]);
} }
/** /**
@@ -48,11 +61,13 @@ class ErrorHandlerTest extends Unit
*/ */
public function testUseWithLogger(): void public function testUseWithLogger(): void
{ {
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->exception = $this->make(Exception::class, [ $this->exception = $this->make(Exception::class, [
'message' => '', 'message' => '',
'code' => 400, 'code' => 400,
'file' => '/path(to/file', 'file' => '/path(to/file',
]); ]);
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->logger = $this->makeEmpty(LoggerInterface::class, [ $this->logger = $this->makeEmpty(LoggerInterface::class, [
'error' => Expected::once(), 'error' => Expected::once(),
]); ]);
@@ -66,12 +81,14 @@ class ErrorHandlerTest extends Unit
*/ */
public function testUseWithHttpException(): void public function testUseWithHttpException(): void
{ {
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->exception = $this->make(HttpException::class, [ $this->exception = $this->make(HttpException::class, [
'message' => '', 'message' => '',
'code' => 400, 'code' => 400,
'file' => '/path(to/file', 'file' => '/path(to/file',
'getTitle' => Expected::once('The Title'), 'getTitle' => Expected::once('The Title'),
]); ]);
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->logger = $this->makeEmpty(LoggerInterface::class, []); $this->logger = $this->makeEmpty(LoggerInterface::class, []);
$middleWare = new ErrorHandler($this->app); $middleWare = new ErrorHandler($this->app);
@@ -84,11 +101,13 @@ class ErrorHandlerTest extends Unit
*/ */
public function testUseWithGeneralException(): void public function testUseWithGeneralException(): void
{ {
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->exception = $this->make(Exception::class, [ $this->exception = $this->make(Exception::class, [
'message' => '', 'message' => '',
'code' => 400, 'code' => 400,
'file' => '/path(to/file', 'file' => '/path(to/file',
]); ]);
/** @noinspection PhpFieldAssignmentTypeMismatchInspection */
$this->logger = $this->makeEmpty(LoggerInterface::class, []); $this->logger = $this->makeEmpty(LoggerInterface::class, []);
$middleWare = new ErrorHandler($this->app); $middleWare = new ErrorHandler($this->app);
+37 -15
View File
@@ -17,13 +17,15 @@ class WorkingHoursViewTest extends Unit
*/ */
public function workingHoursProvider(): array public function workingHoursProvider(): array
{ {
$date = new DateTime('2020-11-30');
$work_days = 15;
$total_hours = new DateInterval("PT32H22M");
$overtime = new DateInterval("PT22M");
$absence_time = clone $overtime;
$absence_time->invert = 1;
return [ return [
[ [
new DateTime('2020-11-30'), $date, PeriodDesignationEnum::WEEKLY(), $work_days, $total_hours, $overtime,
PeriodDesignationEnum::WEEKLY(),
15,
new DateInterval("PT32H22M"),
new DateInterval("PT22M"),
[ [
'period' => '2020#49', 'period' => '2020#49',
'periodDesignation' => 'weekly', 'periodDesignation' => 'weekly',
@@ -33,11 +35,17 @@ class WorkingHoursViewTest extends Unit
], ],
], ],
[ [
new DateTime('2020-11-30'), $date, PeriodDesignationEnum::WEEKLY(), $work_days, $total_hours, $absence_time,
PeriodDesignationEnum::MONTHLY(), [
15, 'period' => '2020#49',
new DateInterval("PT32H22M"), 'periodDesignation' => 'weekly',
new DateInterval("PT22M"), 'workingDays' => 15,
'totalHours' => '32:22:00',
'overtime' => '-00:22:00'
],
],
[
$date, PeriodDesignationEnum::MONTHLY(), $work_days, $total_hours, $overtime,
[ [
'period' => '2020-11', 'period' => '2020-11',
'periodDesignation' => 'monthly', 'periodDesignation' => 'monthly',
@@ -47,12 +55,17 @@ class WorkingHoursViewTest extends Unit
], ],
], ],
[ [
new DateTime('2020-11-30'), $date, PeriodDesignationEnum::MONTHLY(), $work_days, $total_hours, $absence_time,
PeriodDesignationEnum::YEARLY(),
15,
new DateInterval("PT32H22M"),
new DateInterval("PT22M"),
[ [
'period' => '2020-11',
'periodDesignation' => 'monthly',
'workingDays' => 15,
'totalHours' => '32:22:00',
'overtime' => '-00:22:00'
],
],
[
$date, PeriodDesignationEnum::YEARLY(), $work_days, $total_hours, $overtime, [
'period' => '2020', 'period' => '2020',
'periodDesignation' => 'yearly', 'periodDesignation' => 'yearly',
'workingDays' => 15, 'workingDays' => 15,
@@ -60,6 +73,15 @@ class WorkingHoursViewTest extends Unit
'overtime' => '00:22:00' 'overtime' => '00:22:00'
], ],
], ],
[
$date, PeriodDesignationEnum::YEARLY(), $work_days, $total_hours, $absence_time, [
'period' => '2020',
'periodDesignation' => 'yearly',
'workingDays' => 15,
'totalHours' => '32:22:00',
'overtime' => '-00:22:00'
],
],
]; ];
} }
+1
View File
@@ -6,6 +6,7 @@ Definition der Farben
@hueSub: 215; @hueSub: 215;
@mainColor: hsl(@hueMain, 90%, 29%); @mainColor: hsl(@hueMain, 90%, 29%);
@redColor: hsl(0, 90%, 29%);
@mainColorDark: darken(@mainColor,66%,relativ); @mainColorDark: darken(@mainColor,66%,relativ);
@mainColorLight: lighten(@mainColor,66%,relativ); @mainColorLight: lighten(@mainColor,66%,relativ);
@subColor: hsl(@hueSub, 90%, 29%); @subColor: hsl(@hueSub, 90%, 29%);
+7
View File
@@ -79,6 +79,13 @@ main {
border-bottom: @mainColor solid thin; border-bottom: @mainColor solid thin;
} }
} }
};
tbody {
td.absence-time {
color: @redColor;
text-decoration-line: underline;
text-decoration-style: dashed;
}
} }
} }
form { form {
+9 -1
View File
@@ -1,6 +1,14 @@
<script> <script>
export let params; export let params;
console.log(params) console.log(params)
if (!String.prototype.startsWith) {
String.prototype.startsWith = function(searchString, position) {
position = position || 0;
return this.indexOf(searchString, position) === position;
};
}
$: isNegative = time => time.startsWith('-') ? 'absence-time' : '';
$: cutMinusChar = time => time.startsWith('-') ? time.substr(1) : time;
</script> </script>
<svelte:head> <svelte:head>
@@ -36,7 +44,7 @@
<td>{record.period}</td> <td>{record.period}</td>
<td>{record.workingDays}</td> <td>{record.workingDays}</td>
<td>{record.totalHours}</td> <td>{record.totalHours}</td>
<td>{record.overtime}</td> <td class="{ isNegative(record.overtime) }">{cutMinusChar(record.overtime)}</td>
</tr> </tr>
{/each} {/each}
</tbody> </tbody>