2 Commits
11 changed files with 107 additions and 66 deletions
+2 -31
View File
@@ -21,12 +21,6 @@ class WorkingHoursController extends AbstractController
{ {
/** /**
* @param Request $request
* @param Response $response
* @param array<string, mixed> $args
*
* @return Response
*
* @throws HttpBadRequestException * @throws HttpBadRequestException
* @throws HttpNotFoundException * @throws HttpNotFoundException
*/ */
@@ -34,7 +28,7 @@ class WorkingHoursController extends AbstractController
{ {
$body = $request->getParsedBody(); $body = $request->getParsedBody();
$repository = new WorkingHoursRepository($this->databases); $repository = new WorkingHoursRepository($this->databases);
$model = $this->buildModel($request, $args['id'], $body['workingTime'], $body['isHomeOfficeDay'] ?? false); $model = $this->buildModel($request, $args['id'], $body['workingTime'], $body['isHomeOffice'] ?? false);
try { try {
$repository->update($model); $repository->update($model);
} catch (RepositoryRecordNotFoundException $exception) { } catch (RepositoryRecordNotFoundException $exception) {
@@ -44,12 +38,6 @@ class WorkingHoursController extends AbstractController
} }
/** /**
* @param Request $request
* @param Response $response
* @param array<string, mixed> $args
*
* @return Response
*
* @throws HttpInternalServerErrorException * @throws HttpInternalServerErrorException
* @throws HttpBadRequestException * @throws HttpBadRequestException
* @noinspection PhpUnusedParameterInspection * @noinspection PhpUnusedParameterInspection
@@ -79,12 +67,6 @@ class WorkingHoursController extends AbstractController
} }
/** /**
* @param Request $request
* @param Response $response
* @param array<string, mixed> $args
*
* @return Response
*
* @throws HttpNotFoundException * @throws HttpNotFoundException
* @throws HttpInternalServerErrorException * @throws HttpInternalServerErrorException
*/ */
@@ -105,12 +87,6 @@ class WorkingHoursController extends AbstractController
} }
/** /**
* @param Request $request
* @param Response $response
* @param array<string, mixed> $args
*
* @return Response
*
* @throws HttpBadRequestException * @throws HttpBadRequestException
* @throws HttpConflictRequestException * @throws HttpConflictRequestException
* @throws HttpInternalServerErrorException * @throws HttpInternalServerErrorException
@@ -124,7 +100,7 @@ class WorkingHoursController extends AbstractController
$request, $request,
$body['workingDay'], $body['workingDay'],
$body['workingTime'], $body['workingTime'],
$body['isHomeOfficeDay'] ?? false $body['isHomeOffice'] ?? false
); );
try { try {
$repository->insert($model); $repository->insert($model);
@@ -141,11 +117,6 @@ class WorkingHoursController extends AbstractController
} }
/** /**
* @param Request $request
* @param string $date
* @param string $time
*
* @return WorkingHours
* @throws HttpBadRequestException * @throws HttpBadRequestException
*/ */
protected function buildModel(Request $request, string $date, string $time, bool $isHomeOffice): WorkingHours protected function buildModel(Request $request, string $date, string $time, bool $isHomeOffice): WorkingHours
@@ -4,6 +4,7 @@ namespace TorstenHettstedt\TimekeepingApi\Tests\Unit\Controller;
use Codeception\Attribute\DataProvider; use Codeception\Attribute\DataProvider;
use Exception; use Exception;
use PHPUnit\Framework\MockObject\Exception as MockException;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface; use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
@@ -25,16 +26,16 @@ class WorkingHoursControllerTest extends AbstractControllerTest
/** /**
* @throws Exception * @throws Exception
* @throws \PHPUnit\Framework\MockObject\Exception * @throws MockException
*/ */
protected function _before(): void protected function _before(): void
{ {
parent::_before(); parent::_before();
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::EXISTING_DATE, 'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL, 'workingTime' => self::EXISTING_INTERVAL,
'isHomeOfficeDay' => true, 'isHomeOffice' => true,
], ],
]); ]);
} }
@@ -271,8 +272,8 @@ class WorkingHoursControllerTest extends AbstractControllerTest
{ {
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::EXISTING_DATE, 'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL, 'workingTime' => self::EXISTING_INTERVAL,
], ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
@@ -316,9 +317,6 @@ class WorkingHoursControllerTest extends AbstractControllerTest
} }
/** /**
* @param string $date
* @param string $time
*
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotDatabasesException * @throws NotDatabasesException
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
@@ -329,9 +327,9 @@ class WorkingHoursControllerTest extends AbstractControllerTest
{ {
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => $date, 'workingDay' => $date,
'workingTime' => $time, 'workingTime' => $time,
'isHomeOfficeDay' => $isHomeOffice, 'isHomeOffice' => $isHomeOffice,
], ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
@@ -349,9 +347,9 @@ class WorkingHoursControllerTest extends AbstractControllerTest
{ {
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::NEW_DATE, 'workingDay' => self::NEW_DATE,
'workingTime' => self::NEW_INTERVAL, 'workingTime' => self::NEW_INTERVAL,
'isHomeOfficeDay' => true, 'isHomeOffice' => true,
], ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
@@ -370,8 +368,8 @@ class WorkingHoursControllerTest extends AbstractControllerTest
{ {
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::NEW_DATE, 'workingDay' => self::NEW_DATE,
'workingTime' => self::NEW_INTERVAL, 'workingTime' => self::NEW_INTERVAL,
], ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
@@ -390,9 +388,9 @@ class WorkingHoursControllerTest extends AbstractControllerTest
{ {
$this->request = $this->makeEmpty(Request::class, [ $this->request = $this->makeEmpty(Request::class, [
'getParsedBody' => [ 'getParsedBody' => [
'workingDay' => self::EXISTING_DATE, 'workingDay' => self::EXISTING_DATE,
'workingTime' => self::EXISTING_INTERVAL, 'workingTime' => self::EXISTING_INTERVAL,
'isHomeOfficeDay' => true, 'isHomeOffice' => true,
], ],
]); ]);
$controller = new WorkingHoursController($this->container); $controller = new WorkingHoursController($this->container);
+1 -1
View File
@@ -23,7 +23,7 @@ Arbeit;04:16;2021-07-22 07:55;2021-07-22 12:11;
Arbeit;03:11;2021-07-21 13:37;2021-07-21 16:48; Arbeit;03:11;2021-07-21 13:37;2021-07-21 16:48;
Mittagspause ;01:07;2021-07-21 12:29;2021-07-21 13:37; Mittagspause ;01:07;2021-07-21 12:29;2021-07-21 13:37;
Arbeit;04:58;2021-07-21 07:31;2021-07-21 12:29; Arbeit;04:58;2021-07-21 07:31;2021-07-21 12:29;
Arbeit;01:17;2021-07-20 18:44;2021-07-20 20:02; Verkehr;01:17;2021-07-20 18:44;2021-07-20 20:02;
Arbeit;03:50;2021-07-20 13:14;2021-07-20 17:04; Arbeit;03:50;2021-07-20 13:14;2021-07-20 17:04;
Mittagspause ;00:41;2021-07-20 12:32;2021-07-20 13:14; Mittagspause ;00:41;2021-07-20 12:32;2021-07-20 13:14;
Arbeit;04:55;2021-07-20 07:37;2021-07-20 12:32; Arbeit;04:55;2021-07-20 07:37;2021-07-20 12:32;
1 Aktivität Dauer Von Bis Kommentar
23 Arbeit 03:11 2021-07-21 13:37 2021-07-21 16:48
24 Mittagspause 01:07 2021-07-21 12:29 2021-07-21 13:37
25 Arbeit 04:58 2021-07-21 07:31 2021-07-21 12:29
26 Arbeit Verkehr 01:17 2021-07-20 18:44 2021-07-20 20:02
27 Arbeit 03:50 2021-07-20 13:14 2021-07-20 17:04
28 Mittagspause 00:41 2021-07-20 12:32 2021-07-20 13:14
29 Arbeit 04:55 2021-07-20 07:37 2021-07-20 12:32
+2 -1
View File
@@ -1,9 +1,10 @@
export class PeriodRecord { export class PeriodRecord {
/** /**
* @param {{ workingDays: Number; totalHours: any; overtime: string; period: string; }} record * @param {{ workingDays: Number; totalHours: any; overtime: string; period: string; homeOfficeDays: Number }} record
*/ */
constructor(record) { constructor(record) {
this.workingDays = Number(record.workingDays) this.workingDays = Number(record.workingDays)
this.homeOfficeDays = Number(record.homeOfficeDays)
this.totalHours = String(record.totalHours) this.totalHours = String(record.totalHours)
this.period = String(record.period) this.period = String(record.period)
this.overtime = String('##:##:##') this.overtime = String('##:##:##')
+2
View File
@@ -43,6 +43,7 @@
<tr> <tr>
<th>Zeitraum</th> <th>Zeitraum</th>
<th>Arbeitstage</th> <th>Arbeitstage</th>
<th>davon HomeOffice</th>
<th>Arbeitsstunden</th> <th>Arbeitsstunden</th>
<th>Über- / Unterstunden</th> <th>Über- / Unterstunden</th>
</tr> </tr>
@@ -52,6 +53,7 @@
<tr> <tr>
<td>{record.period}</td> <td>{record.period}</td>
<td>{record.workingDays}</td> <td>{record.workingDays}</td>
<td>{record.homeOfficeDays}</td>
<td>{record.totalHours}</td> <td>{record.totalHours}</td>
<td class="{record.isMinus ? 'absence-time' : ''}">{record.overtime}</td> <td class="{record.isMinus ? 'absence-time' : ''}">{record.overtime}</td>
</tr> </tr>
+16 -3
View File
@@ -34,6 +34,7 @@ export const actions = {
const body_data = { const body_data = {
workingDay: data.get('workingDay'), workingDay: data.get('workingDay'),
workingTime: data.get('workingTime'), workingTime: data.get('workingTime'),
isHomeOffice: data.get('isHomeOffice'),
} }
await WorkingHoursRepository.update(env.API_URL, data.get('workingDay'), body_data); await WorkingHoursRepository.update(env.API_URL, data.get('workingDay'), body_data);
}, },
@@ -42,6 +43,7 @@ export const actions = {
const body_data = { const body_data = {
workingDay: form_data.get('workingDay'), workingDay: form_data.get('workingDay'),
workingTime: form_data.get('workingTime'), workingTime: form_data.get('workingTime'),
isHomeOffice: form_data.get('isHomeOffice'),
} }
await WorkingHoursRepository.add(env.API_URL, body_data); await WorkingHoursRepository.add(env.API_URL, body_data);
}, },
@@ -56,13 +58,19 @@ export const actions = {
actualDayObject.setDate(actualDayObject.getDate() + 1) actualDayObject.setDate(actualDayObject.getDate() + 1)
}) })
for (const pair of form_data.entries()) { for (const pair of form_data.entries()) {
const working_day = day_list[pair[0]] ?? null let key = /(?<day>\w+)\[time]/.exec(pair[0])
if (working_day === null) { if (key === null) {
continue
}
let day = key?.groups?.day ?? ''
const working_day = day_list[day] ?? null
if (working_day === null || pair[1] === '00:00:00' || pair[1] === '00:00') {
continue continue
} }
const body_data = { const body_data = {
workingDay: working_day, workingDay: working_day,
workingTime: pair[1], workingTime: pair[1],
isHomeOffice: form_data.has(day + '[isHomeOffice]')
} }
await WorkingHoursRepository.addOrUpdate(env.API_URL, working_day, body_data); await WorkingHoursRepository.addOrUpdate(env.API_URL, working_day, body_data);
} }
@@ -70,10 +78,15 @@ export const actions = {
'import-csv': async ({ request }) => { 'import-csv': async ({ request }) => {
const form_data = await request.formData(); const form_data = await request.formData();
for (const pair of form_data.entries()) { for (const pair of form_data.entries()) {
const working_day = pair[0] let key = /^(?<day>\d{4}-\d{2}-\d{2})\[time]$/.exec(pair[0])
if (key === null) {
continue
}
let working_day = key?.groups?.day ?? ''
const body_data = { const body_data = {
workingDay: working_day, workingDay: working_day,
workingTime: pair[1], workingTime: pair[1],
isHomeOffice: form_data.has(working_day + '[isHomeOffice]')
} }
await WorkingHoursRepository.addOrUpdate(env.API_URL, working_day, body_data); await WorkingHoursRepository.addOrUpdate(env.API_URL, working_day, body_data);
} }
+5 -3
View File
@@ -4,11 +4,11 @@
import IconifyIcon from "@iconify/svelte"; import IconifyIcon from "@iconify/svelte";
let { data } = $props(); let { data } = $props();
const TITLE = "Bearbeitung Einträge" const TITLE = "Bearbeitung Einträge"
/** @type {{workingDay: String, workingTime: String, }[]|null} **/ /** @type {{workingDay: String, workingTime: String, isHomeOffice: Boolean, }[]|null} **/
let records = $state([]) let records = $state([])
const init = async () => await data.promise.then( const init = async () => await data.promise.then(
/** /**
* @param {{workingDay: String, workingTime: String, }[]} data * @param {{workingDay: String, workingTime: String, isHomeOffice: Boolean, }[]} data
*/ */
data => { data => {
records = data records = data
@@ -53,14 +53,16 @@
<tr> <tr>
<th>Datum</th> <th>Datum</th>
<th>Arbeitsstunden</th> <th>Arbeitsstunden</th>
<th>Zu Hause gearbeitet?</th>
<th>Aktionen</th> <th>Aktionen</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{#each records as record} {#each records as record}
<tr> <tr style="{record.isHomeOffice ? 'background: aqua' : ''}">
<td>{record.workingDay}</td> <td>{record.workingDay}</td>
<td>{record.workingTime}</td> <td>{record.workingTime}</td>
<td>{record.isHomeOffice ? 'ja' : ''}</td>
<td> <td>
<button formaction={'/working-hours/' + record.workingDay} type="submit">Bearbeiten <button formaction={'/working-hours/' + record.workingDay} type="submit">Bearbeiten
<IconifyIcon icon={wrenchIcon}/> <IconifyIcon icon={wrenchIcon}/>
@@ -4,11 +4,11 @@
import xIcon from "@iconify-icons/oi/x"; import xIcon from "@iconify-icons/oi/x";
let { data } = $props(); let { data } = $props();
const TITLE = "Bearbeitung eines Eintrags" const TITLE = "Bearbeitung eines Eintrags"
/** @type {{workingDay: String, workingTime: String, }|null} **/ /** @type {{workingDay: String, workingTime: String, isHomeOffice: Boolean, }|null} **/
let activeDate = $state(null) let activeDate = $state(null)
const init = async () => await data.promise.then( const init = async () => await data.promise.then(
/** /**
* @param {{workingDay: String, workingTime: String, }} data * @param {{workingDay: String, workingTime: String, isHomeOffice: Boolean, }} data
*/ */
data => { data => {
activeDate = data activeDate = data
@@ -42,6 +42,10 @@
value="{activeDate.workingTime}" value="{activeDate.workingTime}"
id="workingTime" required pattern="[0-5]\d:[0-5]\d:[0-5]\d"> id="workingTime" required pattern="[0-5]\d:[0-5]\d:[0-5]\d">
</div> </div>
<div>
<label for="isHomeOffice">Arbeitszeit</label>
<input name="isHomeOffice" type="checkbox" checked={activeDate.isHomeOffice} id="isHomeOffice">
</div>
</fieldset> </fieldset>
{/if} {/if}
<fieldset name="buttons"> <fieldset name="buttons">
@@ -29,6 +29,10 @@
<input name="workingTime" placeholder="Arbeitszeit" type="time" step="1" value="" <input name="workingTime" placeholder="Arbeitszeit" type="time" step="1" value=""
id="workingTime" required pattern="[0-5]\d:[0-5]\d:[0-5]\d"> id="workingTime" required pattern="[0-5]\d:[0-5]\d:[0-5]\d">
</div> </div>
<div>
<label for="isHomeOffice">Arbeitszeit</label>
<input name="isHomeOffice" type="checkbox" id="isHomeOffice">
</div>
</fieldset> </fieldset>
<fieldset name="buttons"> <fieldset name="buttons">
<button type="submit">Übernehmen und Weiter <button type="submit">Übernehmen und Weiter
@@ -14,6 +14,22 @@
tbody.weekend td input, tbody.weekend td { tbody.weekend td input, tbody.weekend td {
color: red; color: red;
} }
tbody.weekend label {
color: initial;
}
section form fieldset div input {
display: inline-block;
padding: 0.25rem;
border-style: solid;
border-width: thin;
}
section form fieldset div input[type=checkbox] {
display: inline-block;
width: auto;
margin: 0 1rem 1.0rem;
}
</style> </style>
@@ -39,10 +55,19 @@
{day} {day}
</td> </td>
<td> <td>
<input name="{day}" value="08:00:00" type="time" step="1" <input name="{day}[time]" value="08:00:00" type="time" step="1"
required pattern="[0-5]\d:[0-5]\d:[0-5]\d"> required pattern="[0-5]\d:[0-5]\d:[0-5]\d">
</td> </td>
</tr> </tr>
<tr>
<td>
</td>
<td>
<label>wurde zu Hause gearbeitet?
<input name="{day}[isHomeOffice]" type="checkbox">
</label>
</td>
</tr>
{/each} {/each}
</tbody> </tbody>
<tbody class="weekend"> <tbody class="weekend">
@@ -52,10 +77,19 @@
{day} {day}
</td> </td>
<td> <td>
<input name="{day}" value="00:00:00" type="time" step="1" <input name="{day}[time]" value="00:00:00" type="time" step="1"
required pattern="[0-5]\d:[0-5]\d:[0-5]\d"> required pattern="[0-5]\d:[0-5]\d:[0-5]\d">
</td> </td>
</tr> </tr>
<tr>
<td>
</td>
<td>
<label>wurde zu Hause gearbeitet?
<input name="{day}[isHomeOffice]" type="checkbox">
</label>
</td>
</tr>
{/each} {/each}
</tbody> </tbody>
</table> </table>
@@ -8,7 +8,7 @@
const TITLE = "Erstellung neuer Einträge für eine Woche" const TITLE = "Erstellung neuer Einträge für eine Woche"
/** @type {{ workingTime: String, workingDay: String, }[]} **/ /** @type {{ workingTime: String, workingDay: String, isHomeOffice: Boolean, }[]} **/
let imported_data = $state([]) let imported_data = $state([])
@@ -30,6 +30,8 @@
complete: results => { complete: results => {
/** @type {Object<String, Number>} **/ /** @type {Object<String, Number>} **/
let cash_work_days = {} let cash_work_days = {}
/** @type {Object<String, Boolean>} **/
let home_office_days = {}
results.data.forEach( results.data.forEach(
/** @param {Object<String, any>} item **/ /** @param {Object<String, any>} item **/
item => { item => {
@@ -42,6 +44,9 @@
let work_to = new Date(item['Bis']) let work_to = new Date(item['Bis'])
let actual_day = work_from.toISOString().substring(0, 10) let actual_day = work_from.toISOString().substring(0, 10)
let actual_work_hours = (work_to.getTime() - work_from.getTime()) / (1000 * 60 * 60) let actual_work_hours = (work_to.getTime() - work_from.getTime()) / (1000 * 60 * 60)
if (activity.trim() === 'Verkehr') {
home_office_days[actual_day] = true
}
cash_work_days[actual_day] ??= 0 cash_work_days[actual_day] ??= 0
cash_work_days[actual_day] += actual_work_hours cash_work_days[actual_day] += actual_work_hours
} }
@@ -52,7 +57,11 @@
let minutes_digits = Math.round((hours - hours_digits) * 60) let minutes_digits = Math.round((hours - hours_digits) * 60)
let working_time = String(hours_digits).padStart(2, '0') + ':' let working_time = String(hours_digits).padStart(2, '0') + ':'
+ String(minutes_digits).padStart(2, '0') + ':00' + String(minutes_digits).padStart(2, '0') + ':00'
imported_data.push({workingTime: working_time, workingDay: day}) imported_data.push({
workingTime: working_time,
workingDay: day,
isHomeOffice: home_office_days[day] ?? false,
})
} }
}, },
}) })
@@ -90,7 +99,10 @@
{item.workingDay} {item.workingDay}
</td> </td>
<td> <td>
<input type="time" readonly name="{item.workingDay}" value="{item.workingTime}"> <input type="time" readonly name="{item.workingDay}[time]" value="{item.workingTime}">
</td>
<td>
<input type="checkbox" readonly name="{item.workingDay}[isHomeOffice]" checked={item.isHomeOffice}>
</td> </td>
</tr> </tr>
{/each} {/each}