Compare commits
3
Commits
a09edcae25
...
7b5ce23342
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7b5ce23342 | ||
|
|
a3b123f466 | ||
|
|
d52a9d77ab |
@@ -10,24 +10,14 @@ use JetBrains\PhpStorm\ArrayShape;
|
|||||||
|
|
||||||
class WorkingHoursView implements ModelInterface
|
class WorkingHoursView implements ModelInterface
|
||||||
{
|
{
|
||||||
protected DateTimeInterface $period;
|
|
||||||
protected PeriodDesignationEnum $periodDesignation;
|
|
||||||
protected int $workingDays;
|
|
||||||
protected DateInterval $totalHours;
|
|
||||||
protected DateInterval $overtime;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
DateTimeInterface $period,
|
protected DateTimeInterface $period,
|
||||||
PeriodDesignationEnum $periodDesignation,
|
protected PeriodDesignationEnum $periodDesignation,
|
||||||
int $workingDays,
|
protected int $workingDays,
|
||||||
DateInterval $totalHours,
|
protected DateInterval $totalHours,
|
||||||
DateInterval $overtime
|
protected DateInterval $overtime
|
||||||
) {
|
) {
|
||||||
$this->period = $period;
|
|
||||||
$this->periodDesignation = $periodDesignation;
|
|
||||||
$this->workingDays = $workingDays;
|
|
||||||
$this->totalHours = $totalHours;
|
|
||||||
$this->overtime = $overtime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPeriod(): DateTimeInterface
|
public function getPeriod(): DateTimeInterface
|
||||||
@@ -66,7 +56,8 @@ class WorkingHoursView implements ModelInterface
|
|||||||
'totalHours' => "string",
|
'totalHours' => "string",
|
||||||
'workingDays' => "int",
|
'workingDays' => "int",
|
||||||
'overtime' => "string"
|
'overtime' => "string"
|
||||||
])] public function jsonSerialize(): array
|
])]
|
||||||
|
public function jsonSerialize(): array
|
||||||
{
|
{
|
||||||
$formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S';
|
$formatOvertime = (($this->getOvertime()->invert === 1) ? '-' : '') . '%H:%I:%S';
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
|
|||||||
class WorkingHoursMonthlyViewRepository extends AbstractWorkingHoursViewRepository
|
class WorkingHoursMonthlyViewRepository extends AbstractWorkingHoursViewRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
protected const SQL_SELECT = <<<SQL
|
protected const string SQL_SELECT = <<<SQL
|
||||||
select
|
select
|
||||||
"Monat" as "period",
|
"Monat" as "period",
|
||||||
"Gesamtarbeitszeit" as "totalHours",
|
"Gesamtarbeitszeit" as "totalHours",
|
||||||
@@ -20,7 +20,7 @@ class WorkingHoursMonthlyViewRepository extends AbstractWorkingHoursViewReposito
|
|||||||
"Überstunden" as "overtime"
|
"Überstunden" as "overtime"
|
||||||
from "Arbeitszeiten - Monat"
|
from "Arbeitszeiten - Monat"
|
||||||
SQL;
|
SQL;
|
||||||
protected const SQL_WHERE = ' where "Monat" = ?';
|
protected const string SQL_WHERE = ' where "Monat" = ?';
|
||||||
|
|
||||||
public function __construct(PDO $database)
|
public function __construct(PDO $database)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ use TorstenHettstedt\TimekeepingApi\Models\WorkingHours;
|
|||||||
*/
|
*/
|
||||||
class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWriterInterface
|
class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWriterInterface
|
||||||
{
|
{
|
||||||
|
protected const string SQL_SELECT = <<<'SQL'
|
||||||
|
select
|
||||||
|
"Datum" as "workingDay",
|
||||||
|
"Arbeitszeit" as "workingTime"
|
||||||
|
from public."Arbeitszeiten"
|
||||||
|
SQL;
|
||||||
|
|
||||||
|
|
||||||
public function __construct(protected PDO $database)
|
public function __construct(protected PDO $database)
|
||||||
{
|
{
|
||||||
@@ -88,7 +95,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
|||||||
|
|
||||||
protected function buildFindFilteredStatement(?string $start, ?string $end): ?PDOStatement
|
protected function buildFindFilteredStatement(?string $start, ?string $end): ?PDOStatement
|
||||||
{
|
{
|
||||||
$query = 'select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten" ';
|
$query = static::SQL_SELECT . ' ';
|
||||||
$query .= $this->buildFilterString($start, $end);
|
$query .= $this->buildFilterString($start, $end);
|
||||||
$query .= 'order by "Datum"';
|
$query .= 'order by "Datum"';
|
||||||
$stmt = $this->database->prepare($query);
|
$stmt = $this->database->prepare($query);
|
||||||
@@ -113,9 +120,7 @@ class WorkingHoursRepository implements RepositoryReaderInterface, RepositoryWri
|
|||||||
*/
|
*/
|
||||||
public function findByKey(mixed $primary_key): WorkingHours
|
public function findByKey(mixed $primary_key): WorkingHours
|
||||||
{
|
{
|
||||||
$stmt = $this->database->prepare(
|
$stmt = $this->database->prepare(static::SQL_SELECT . ' where "Datum" = ?');
|
||||||
'select "Datum" as "workingDay", "Arbeitszeit" as "workingTime" from public."Arbeitszeiten" where "Datum" = ?'
|
|
||||||
);
|
|
||||||
$stmt->bindParam(1, $primary_key);
|
$stmt->bindParam(1, $primary_key);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$row = $stmt->fetch();
|
$row = $stmt->fetch();
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
|
|||||||
class WorkingHoursWeeklyViewRepository extends AbstractWorkingHoursViewRepository
|
class WorkingHoursWeeklyViewRepository extends AbstractWorkingHoursViewRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
protected const SQL_SELECT = <<<SQL
|
protected const string SQL_SELECT = <<<SQL
|
||||||
select
|
select
|
||||||
"Woche" as "period",
|
"Woche" as "period",
|
||||||
"Gesamtarbeitszeit" as "totalHours",
|
"Gesamtarbeitszeit" as "totalHours",
|
||||||
@@ -19,7 +19,7 @@ class WorkingHoursWeeklyViewRepository extends AbstractWorkingHoursViewRepositor
|
|||||||
"Überstunden" as "overtime"
|
"Überstunden" as "overtime"
|
||||||
from "Arbeitszeiten - Woche"
|
from "Arbeitszeiten - Woche"
|
||||||
SQL;
|
SQL;
|
||||||
protected const SQL_WHERE = ' where "Woche" = ?';
|
protected const string SQL_WHERE = ' where "Woche" = ?';
|
||||||
|
|
||||||
public function __construct(PDO $database)
|
public function __construct(PDO $database)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ use TorstenHettstedt\TimekeepingApi\Models\PeriodDesignationEnum;
|
|||||||
class WorkingHoursYearlyViewRepository extends AbstractWorkingHoursViewRepository
|
class WorkingHoursYearlyViewRepository extends AbstractWorkingHoursViewRepository
|
||||||
{
|
{
|
||||||
|
|
||||||
protected const SQL_SELECT = <<<SQL
|
protected const string SQL_SELECT = <<<SQL
|
||||||
select
|
select
|
||||||
"Jahr" as "period",
|
"Jahr" as "period",
|
||||||
"Gesamtarbeitszeit" as "totalHours",
|
"Gesamtarbeitszeit" as "totalHours",
|
||||||
@@ -19,7 +19,7 @@ class WorkingHoursYearlyViewRepository extends AbstractWorkingHoursViewRepositor
|
|||||||
"Überstunden" as "overtime"
|
"Überstunden" as "overtime"
|
||||||
from "Arbeitszeiten - Jahr"
|
from "Arbeitszeiten - Jahr"
|
||||||
SQL;
|
SQL;
|
||||||
protected const SQL_WHERE = ' where "Jahr" = ?';
|
protected const string SQL_WHERE = ' where "Jahr" = ?';
|
||||||
|
|
||||||
public function __construct(PDO $database)
|
public function __construct(PDO $database)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -3,6 +3,6 @@ modules:
|
|||||||
enabled:
|
enabled:
|
||||||
- \Helper\Api
|
- \Helper\Api
|
||||||
- REST:
|
- REST:
|
||||||
url: http://localhost:8091/
|
url: http://api:80/
|
||||||
depends: PhpBrowser
|
depends: PhpBrowser
|
||||||
part: Json
|
part: Json
|
||||||
@@ -4,14 +4,12 @@ namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
|
|||||||
|
|
||||||
use Codeception\Attribute\DataProvider;
|
use Codeception\Attribute\DataProvider;
|
||||||
use Exception;
|
use Exception;
|
||||||
use PHPUnit\Framework\MockObject\MockObject;
|
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\ContainerInterface;
|
use Psr\Container\ContainerInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
use Slim\Exception\HttpBadRequestException;
|
use Slim\Exception\HttpBadRequestException;
|
||||||
use Slim\Exception\HttpNotFoundException;
|
use Slim\Exception\HttpNotFoundException;
|
||||||
use Slim\Psr7\Request;
|
use Slim\Psr7\Request;
|
||||||
use Slim\Psr7\Response;
|
|
||||||
use TorstenHettstedt\TimekeepingApi\Controller\HttpConflictRequestException;
|
use TorstenHettstedt\TimekeepingApi\Controller\HttpConflictRequestException;
|
||||||
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
|
use TorstenHettstedt\TimekeepingApi\Controller\NotDatabasesException;
|
||||||
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursController;
|
use TorstenHettstedt\TimekeepingApi\Controller\WorkingHoursController;
|
||||||
@@ -25,10 +23,6 @@ class WorkingHoursControllerTest extends AbstractControllerTest
|
|||||||
public const string NEW_DATE = '2020-04-01';
|
public const string NEW_DATE = '2020-04-01';
|
||||||
public const string NEW_INTERVAL = '07:59:00';
|
public const string NEW_INTERVAL = '07:59:00';
|
||||||
|
|
||||||
protected ContainerInterface $container;
|
|
||||||
protected Request $request;
|
|
||||||
protected Response|MockObject $response;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @throws \PHPUnit\Framework\MockObject\Exception
|
* @throws \PHPUnit\Framework\MockObject\Exception
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
create_css_files() {
|
create_css_files() {
|
||||||
cd ui/public || exit 2
|
cd ui || exit 2
|
||||||
lessc --source-map less/print.less print.css
|
lessc --source-map less/print.less static/print.css
|
||||||
lessc --source-map less/global.less global.css
|
lessc --source-map less/global.less static/global.css
|
||||||
cd ../..
|
cd ../..
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,6 +27,13 @@ build_ui() {
|
|||||||
cd ..
|
cd ..
|
||||||
}
|
}
|
||||||
|
|
||||||
|
codeception_install() {
|
||||||
|
pwd
|
||||||
|
cd api/ || exit 2
|
||||||
|
test -e ./tests/unit.suite.yml || ./vendor/bin/codecept build
|
||||||
|
cd ..
|
||||||
|
}
|
||||||
|
|
||||||
test_unit() {
|
test_unit() {
|
||||||
pwd
|
pwd
|
||||||
cd api/ || exit 2
|
cd api/ || exit 2
|
||||||
@@ -44,4 +51,4 @@ composer_run() {
|
|||||||
docker compose up -d
|
docker compose up -d
|
||||||
}
|
}
|
||||||
|
|
||||||
create_css_files && install_ui_dependence && install_api_dependence && build_ui && test_unit && composer_run && test_api
|
create_css_files && install_ui_dependence && install_api_dependence && build_ui && codeception_install && test_unit && composer_run && test_api
|
||||||
@@ -19,7 +19,7 @@ const getMonday = actualDayObject => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @type {String[]} **/
|
/** @type {String[]} **/
|
||||||
const day_list = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sontag']
|
const weekday_list = ['Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag', 'Sontag']
|
||||||
|
|
||||||
/** @param {Date} actualDayObject **/
|
/** @param {Date} actualDayObject **/
|
||||||
const getDateString = actualDayObject => {
|
const getDateString = actualDayObject => {
|
||||||
@@ -49,17 +49,23 @@ export const actions = {
|
|||||||
const form_data = await request.formData();
|
const form_data = await request.formData();
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
let actualDayObject = getMonday(new Date(form_data.get('week')))
|
let actualDayObject = getMonday(new Date(form_data.get('week')))
|
||||||
day_list.forEach(day => {
|
/** @type {Object<String,String>} **/
|
||||||
if (form_data.get(day) !== '00:00:00' && form_data.get(day) !== '00:00') {
|
let day_list = {}
|
||||||
const working_day = getDateString(actualDayObject)
|
weekday_list.forEach(day => {
|
||||||
const body_data = {
|
day_list[day] = getDateString(actualDayObject)
|
||||||
workingDay: working_day,
|
|
||||||
workingTime: form_data.get(day),
|
|
||||||
}
|
|
||||||
WorkingHoursRepository.addOrUpdate(env.API_URL, working_day, body_data);
|
|
||||||
}
|
|
||||||
actualDayObject.setDate(actualDayObject.getDate() + 1)
|
actualDayObject.setDate(actualDayObject.getDate() + 1)
|
||||||
})
|
})
|
||||||
|
for (const pair of form_data.entries()) {
|
||||||
|
const working_day = day_list[pair[0]] ?? null
|
||||||
|
if (working_day === null) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
const body_data = {
|
||||||
|
workingDay: working_day,
|
||||||
|
workingTime: pair[1],
|
||||||
|
}
|
||||||
|
await WorkingHoursRepository.addOrUpdate(env.API_URL, working_day, body_data);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
'import-csv': async ({ request }) => {
|
'import-csv': async ({ request }) => {
|
||||||
const form_data = await request.formData();
|
const form_data = await request.formData();
|
||||||
|
|||||||
Reference in New Issue
Block a user