Compare commits

...
4 Commits
8 changed files with 309 additions and 234 deletions

No files matched your search

Generated
+204 -203
View File
File diff suppressed because it is too large. Load diff
@@ -4,20 +4,24 @@ namespace App\Controller\Admin\System\StaffingRule;
use App\Service\Assignment\StaffingConfigurationException;
use App\Service\Export\StaffingPreviewExporter;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Attribute\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class PreviewController extends AbstractController
{
public function __construct(private readonly StaffingPreviewExporter $previewExporter)
{
public function __construct(
private readonly StaffingPreviewExporter $previewExporter,
private readonly PaginatorInterface $paginator,
) {
}
#[Route('/admin/system/staffing-rule/preview', name: 'app_admin_system_staffing_rule_preview')]
#[IsGranted('ROLE_TEAM_ADMIN')]
public function index(): Response
public function index(Request $request): Response
{
try {
$rows = $this->previewExporter->rows();
@@ -27,8 +31,16 @@ class PreviewController extends AbstractController
return $this->redirectToRoute('app_admin_system_staffing_rule_index');
}
// The candidates are a computed list, not a query: page the finished rows. The Excel
// export stays the full list.
$pagination = $this->paginator->paginate(
$rows,
$request->query->getInt('page', 1),
$request->query->getInt('limit', 50),
);
return $this->render('admin/system/staffing_rule/preview.html.twig', [
'rows' => $rows,
'pagination' => $pagination,
]);
}
}
+19 -13
View File
@@ -17,11 +17,13 @@ use App\Service\Common\PickupOptions;
* - without split, each ski level is a Kursleitung of its own, one place;
* - with split, a Reiseleitung takes over each level through the combined profile, one place
* per level, and the plain Reiseleitung keeps the remaining places;
* - Guiding is the guiding fee on every guide-type assignment, not an assignment of its own;
* - a date with bus travel (boarding points) gets its first boarding point pre-selected as
* Busbegleitung on exactly one assignment, the first guide-type one - the plain Reiseleitung
* where there is one. Taken from the date, not the matrix: bus travel varies between the
* dates of one product.
* dates of one product;
* - Guiding is the guiding fee on exactly one guide place, not an assignment of its own: the
* bus escort's. Where that assignment has more places, one place is split off to carry
* fee and pickup, so the others are neither guiding nor escorting the bus.
*/
final class AssignmentPlanner
{
@@ -64,6 +66,7 @@ final class AssignmentPlanner
}
$pickup = $this->firstPickup($destination);
$guiding = $rule->isGuiding();
$planned = [];
foreach ($roles as [$role, $places]) {
@@ -71,26 +74,29 @@ final class AssignmentPlanner
continue;
}
$fees = [];
$fees = true === $role->isCourse() ? [StaffingFee::COURSE] : [];
if (true === $role->isGuide() && true === $rule->isGuiding()) {
$fees[] = StaffingFee::GUIDING;
if (false === $role->isGuide()) {
$planned[] = new PlannedAssignment($role, $places, null, $fees);
continue;
}
if (true === $role->isCourse()) {
$fees[] = StaffingFee::COURSE;
}
$first = true === $guiding ? 1 : $places;
$planned[] = new PlannedAssignment(
$role,
$places,
true === $role->isGuide() ? $pickup : null,
$fees,
$first,
$pickup,
true === $guiding ? [StaffingFee::GUIDING, ...$fees] : $fees,
);
if (true === $role->isGuide()) {
$pickup = null;
if ($first < $places) {
$planned[] = new PlannedAssignment($role, $places - $first, null, $fees);
}
$guiding = false;
$pickup = null;
}
return $planned;
@@ -33,7 +33,7 @@
</tr>
</thead>
<tbody>
{% for row in rows %}
{% for row in pagination %}
<tr>
<td>{{ row.productCode }}</td>
<td>
@@ -72,6 +72,7 @@
{% endfor %}
</tbody>
</table>
{{ knp_pagination_render(pagination) }}
</div>
</div>
{% endblock %}
@@ -47,18 +47,23 @@ class AssignmentGenerateCommandTest extends KernelTestCase
$assignments = $this->assignments();
$this->assertCount(2, $assignments);
$this->assertCount(3, $assignments);
[$guide, $course] = $assignments;
[$guide, $secondGuide, $course] = $assignments;
$this->assertSame($destination->getId(), $guide->getDestination()->getId());
$this->assertSame('Reiseleitung', $guide->getJobProfile()->getName());
$this->assertSame(2, $guide->getAvailableDispositions());
$this->assertSame(1, $guide->getAvailableDispositions());
$this->assertSame(5, $guide->getPickup());
$this->assertSame(['Skigebietsguiding (pro Einheit)'], $guide->getFees()->map(static fn ($fee) => $fee->getName())->toArray());
$this->assertSame(Assignment::STATUS_DRAFT, $guide->getStatus());
$this->assertSame('system', $guide->getCreatedBy());
$this->assertSame('Reiseleitung', $secondGuide->getJobProfile()->getName());
$this->assertSame(1, $secondGuide->getAvailableDispositions());
$this->assertSame(0, $secondGuide->getPickup());
$this->assertCount(0, $secondGuide->getFees());
$this->assertSame('Kursleitung Ski Anfänger:innen', $course->getJobProfile()->getName());
$this->assertSame(0, $course->getPickup());
}
@@ -79,7 +84,7 @@ class AssignmentGenerateCommandTest extends KernelTestCase
$this->tester->execute([]);
$this->assertStringContainsString('davon 1 schon mit Einsätzen', $this->tester->getDisplay());
$this->assertCount(2, $this->assignments());
$this->assertCount(3, $this->assignments());
}
public function testADryRunWritesNothing(): void
@@ -90,7 +95,7 @@ class AssignmentGenerateCommandTest extends KernelTestCase
$this->assertSame(Command::SUCCESS, $this->tester->execute(['--dry-run' => true]));
$this->assertStringContainsString('2× Reiseleitung (Busbegleitung)', $this->tester->getDisplay());
$this->assertStringContainsString('1× Reiseleitung (Busbegleitung)', $this->tester->getDisplay());
$this->assertCount(0, $this->assignments());
}
@@ -93,12 +93,31 @@ class StaffingRuleControllerTest extends WebTestCase
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
$this->assertStringContainsString('DKIMP110127', $content);
$this->assertStringContainsString('Zeile inaktiv', $content);
$this->assertStringContainsString('2× Reiseleitung', $content);
$this->assertSame(2, substr_count($content, '1× Reiseleitung'));
$this->assertSame(1, substr_count($content, 'Skigebietsguiding (pro Einheit)'));
$this->assertStringContainsString('Busbegleitung ab Göttingen, 22:00 Uhr', $content);
$this->assertStringContainsString('1× Kursleitung Ski Anfänger:innen', $content);
$this->assertStringContainsString('Ski-/Snowboardkurs (pro Stunde)', $content);
}
public function testThePreviewIsPaginated(): void
{
$this->staffingRule($this->entityManager, 'DKIMP');
$this->staffingRule($this->entityManager, 'DGSMP');
$this->staffingDestination($this->entityManager, 'DKIMP110127', 'DKIMP');
$this->staffingDestination($this->entityManager, 'DGSMP110127', 'DGSMP');
$this->entityManager->flush();
// same date: ordered by product code
$this->client->request('GET', '/admin/system/staffing-rule/preview?limit=1&page=2');
$content = (string) $this->client->getResponse()->getContent();
$this->assertSame(Response::HTTP_OK, $this->client->getResponse()->getStatusCode());
$this->assertStringContainsString('DKIMP110127', $content);
$this->assertStringNotContainsString('DGSMP110127', $content);
}
public function testThePreviewDownloadsAsXlsx(): void
{
$this->staffingRule($this->entityManager, 'DKIMP');
@@ -274,13 +274,9 @@ class ApplicationFormControllerTest extends WebTestCase
* An empty string is the shape a form posts for a field the visitor left blank, and it is as
* unusable as an absent key - except for eu, where "" is a lawful no and has its own case.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('requiredFields')]
#[\PHPUnit\Framework\Attributes\DataProvider('nonBlankFields')]
public function testAPayloadWithAnEmptyRequiredFieldIsRejected(string $field): void
{
if ('eu' === $field) {
$this->markTestSkipped('An empty eu is a no, not a missing answer - see its own test');
}
$this->post([$field => ''] + $this->payload());
$this->assertSame(Response::HTTP_BAD_REQUEST, $this->client->getResponse()->getStatusCode());
@@ -306,6 +302,21 @@ class ApplicationFormControllerTest extends WebTestCase
yield 'city' => ['city'];
}
/**
* The required fields that are NotBlank as well: all but eu, which is only NotNull because ""
* is a lawful no (testAnEmptyEuFlagIsNotAYes).
*
* @return iterable<string, array{string}>
*/
public static function nonBlankFields(): iterable
{
foreach (self::requiredFields() as $name => $arguments) {
if ('eu' !== $name) {
yield $name => $arguments;
}
}
}
/**
* The one field whose format is nailed down: provisioning parses it as a date, so the day the
* TYPO3 side switches a form back to a free-text birthday has to be a 400 here rather than a
@@ -56,14 +56,34 @@ class AssignmentPlannerTest extends TestCase
], self::summarize($planned));
}
public function testGuidingIsAFeeOnEveryGuideTypeAssignment(): void
public function testGuidingIsAFeeOnTheFirstGuideTypeAssignmentOnly(): void
{
$planned = $this->plan(self::rule(guides: 3, beginner: true, advanced: true, split: true, guiding: true));
$this->assertSame([
[StaffingRole::GUIDE, 1, null, [StaffingFee::GUIDING]],
[StaffingRole::GUIDE_SKI_BEGINNER, 1, null, [StaffingFee::COURSE]],
[StaffingRole::GUIDE_SKI_ADVANCED, 1, null, [StaffingFee::COURSE]],
], self::summarize($planned));
}
public function testGuidingSplitsOffOnePlaceWhichAlsoEscortsTheBus(): void
{
$planned = $this->plan(self::rule(guides: 3, guiding: true), self::busTravel());
$this->assertSame([
[StaffingRole::GUIDE, 1, 5, [StaffingFee::GUIDING]],
[StaffingRole::GUIDE, 2, null, []],
], self::summarize($planned));
}
public function testWithoutAPlainReiseleitungTheFirstCombinedOneGuides(): void
{
$planned = $this->plan(self::rule(guides: 2, beginner: true, advanced: true, split: true, guiding: true));
$this->assertSame([
[StaffingRole::GUIDE_SKI_BEGINNER, 1, null, [StaffingFee::GUIDING, StaffingFee::COURSE]],
[StaffingRole::GUIDE_SKI_ADVANCED, 1, null, [StaffingFee::GUIDING, StaffingFee::COURSE]],
[StaffingRole::GUIDE_SKI_ADVANCED, 1, null, [StaffingFee::COURSE]],
], self::summarize($planned));
}