feat: additional receipts as attachments to teamer invoices

addresses #869dv97u9
This commit is contained in:
2026-09-09 11:10:57 +02:00
parent 16d847137d
commit 52926ec6cc
29 changed files with 682 additions and 23 deletions
+39
View File
@@ -146,6 +146,45 @@ class DispositionTest extends TestCase
$this->assertFalse($disposition->isContractRejected());
}
/**
* getDocumentByType() answers with the first match and is right for the Honorarvertrag and the
* Honorarnote, of which there is one each. Belege are the first type a disposition can hold
* several of, so they need the collection-returning sibling.
*/
public function testTheReceiptsOfADispositionAreReturnedAsACollection(): void
{
$disposition = $this->createDisposition(createdAt: 'today', assignmentEndsIn: '-1 day');
$disposition
->addDocument((new Upload())->setType(Upload::TYPE_INVOICE))
->addDocument((new Upload())->setType(Upload::TYPE_RECEIPT)->setOriginalFilename('bahn.pdf'))
->addDocument((new Upload())->setType(Upload::TYPE_CONTRACT))
->addDocument((new Upload())->setType(Upload::TYPE_RECEIPT)->setOriginalFilename('taxi.jpg'))
;
$receipts = $disposition->getDocumentsByType(Upload::TYPE_RECEIPT);
$this->assertCount(2, $receipts);
$this->assertSame(
['bahn.pdf', 'taxi.jpg'],
array_values(array_map(
fn (Upload $upload): string => $upload->getOriginalFilename(),
$receipts->toArray()
))
);
// The single-result sibling keeps working for the types that only ever have one.
$this->assertSame(Upload::TYPE_INVOICE, $disposition->getDocumentByType(Upload::TYPE_INVOICE)?->getType());
}
public function testADispositionWithoutReceiptsReturnsAnEmptyCollection(): void
{
$disposition = $this->createDisposition(createdAt: 'today', assignmentEndsIn: '-1 day');
$disposition->addDocument((new Upload())->setType(Upload::TYPE_INVOICE));
$this->assertCount(0, $disposition->getDocumentsByType(Upload::TYPE_RECEIPT));
}
private function createDisposition(
string $createdAt,
string $assignmentEndsIn,
+92
View File
@@ -0,0 +1,92 @@
<?php
declare(strict_types=1);
namespace App\Tests\Model;
use App\Entity\Upload;
use App\Model\UploadDto;
use App\Model\UploadSessionDto;
use PHPUnit\Framework\TestCase;
/**
* The upload session is one flat list shared by every dropzone on a page, and the teamer's
* disposition detail page has two of them at once: the Honorarnote and its Belege. Before the
* uploads carried their mapping, a consumer could only take getUploads()->first() - so submitting
* the invoice form could persist a receipt as the Honorarnote. That is what these pin down.
*/
class UploadSessionDtoTest extends TestCase
{
public function testUploadsAreSelectedByTheMappingTheyCameFrom(): void
{
$session = $this->createSession();
$this->assertSame(
['honorarnote.pdf'],
$this->filenames($session->getUploadsByType(Upload::TYPE_INVOICE))
);
$this->assertSame(
['bahn.pdf', 'taxi.jpg'],
$this->filenames($session->getUploadsByType(Upload::TYPE_RECEIPT))
);
}
public function testRemovingOneMappingLeavesTheOtherAlone(): void
{
$session = $this->createSession();
$session->removeUploadsByType(Upload::TYPE_RECEIPT);
$this->assertCount(0, $session->getUploadsByType(Upload::TYPE_RECEIPT));
$this->assertSame(['honorarnote.pdf'], $this->filenames($session->getUploadsByType(Upload::TYPE_INVOICE)));
}
/**
* A session written before UploadDto carried a type deserializes with a null one. Such an
* entry must match no mapping at all rather than being claimed by the first consumer to ask -
* that would be the very ambiguity the type removes.
*/
public function testAnUploadWithoutAMappingMatchesNothing(): void
{
$session = new UploadSessionDto();
$session->addUpload(new UploadDto('uuid-legacy', 'legacy.pdf', 'legacy.pdf', 'application/pdf', 1));
$this->assertCount(0, $session->getUploadsByType(Upload::TYPE_INVOICE));
$this->assertCount(0, $session->getUploadsByType(Upload::TYPE_RECEIPT));
$this->assertCount(1, $session->getUploads());
}
private function createSession(): UploadSessionDto
{
$session = new UploadSessionDto();
$session
->addUpload($this->createUpload('uuid-1', 'honorarnote.pdf', Upload::TYPE_INVOICE))
->addUpload($this->createUpload('uuid-2', 'bahn.pdf', Upload::TYPE_RECEIPT))
->addUpload($this->createUpload('uuid-3', 'taxi.jpg', Upload::TYPE_RECEIPT))
;
return $session;
}
private function createUpload(string $uuid, string $filename, string $type): UploadDto
{
return new UploadDto($uuid, $filename, $filename, 'application/pdf', 1024, $type);
}
/**
* @param \Doctrine\Common\Collections\Collection<int, UploadDto> $uploads
*
* @return array<int, string>
*/
private function filenames(iterable $uploads): array
{
$filenames = [];
foreach ($uploads as $upload) {
$filenames[] = $upload->getFilename();
}
return $filenames;
}
}
@@ -8,6 +8,7 @@ use App\Entity\Application;
use App\Entity\Assignment;
use App\Entity\Disposition;
use App\Entity\Teamer;
use App\Entity\User;
use App\Security\Voter\DispositionVoter;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
@@ -85,6 +86,98 @@ class DispositionVoterTest extends TestCase
$this->assertSame(VoterInterface::ACCESS_GRANTED, $this->vote(DispositionVoter::CALL_OFF, $disposition));
}
/**
* The receipt window is the one permission in this voter that is not derived from a workflow
* transition, because there is none to derive it from: while the Honorarnote is being checked
* the state machine offers nothing at all, and that is exactly when receipts must stay
* manageable.
*
* @dataProvider receiptWindowStatuses
*/
public function testTheReceiptWindowIsTheTwoInvoiceStates(string $status, bool $expected): void
{
$this->security->method('isGranted')->willReturn(true);
$disposition = $this->createDisposition(skipFormalities: false)->setStatus($status);
$this->assertSame(
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
$this->vote(DispositionVoter::MANAGE_RECEIPTS, $disposition),
);
}
/**
* @return array<string, array{string, bool}>
*/
public static function receiptWindowStatuses(): array
{
return [
'invoice may still be uploaded' => [Disposition::STATUS_ENDED, true],
'invoice is being checked' => [Disposition::STATUS_CHECKING_INVOICE, true],
'nothing has happened yet' => [Disposition::STATUS_NEW, false],
'contract is being checked' => [Disposition::STATUS_CHECKING_CONTRACT, false],
'assignment is still ahead' => [Disposition::STATUS_CONFIRMED, false],
'invoice was accepted' => [Disposition::STATUS_COMPLETED, false],
'placement was cancelled' => [Disposition::STATUS_CALLED_OFF, false],
];
}
public function testReceiptsAreDeniedOnASkipFormalitiesAssignment(): void
{
$this->security->method('isGranted')->willReturn(true);
$disposition = $this
->createDisposition(skipFormalities: true)
->setStatus(Disposition::STATUS_CHECKING_INVOICE)
;
$this->assertSame(
VoterInterface::ACCESS_DENIED,
$this->vote(DispositionVoter::MANAGE_RECEIPTS, $disposition),
);
}
/**
* The owning teamer gets in without being administrative; anyone else's teamer does not.
*
* @dataProvider receiptOwnership
*/
public function testOnlyTheOwningTeamerMayManageTheirReceipts(bool $owning, bool $expected): void
{
$this->security
->method('isGranted')
->willReturnCallback(fn (string $role): bool => 'ROLE_TEAMER' === $role)
;
$teamer = new Teamer();
$assignment = (new Assignment())->setSkipFormalities(false);
$disposition = (new Disposition(new Application($assignment, $teamer)))
->setStatus(Disposition::STATUS_CHECKING_INVOICE)
;
$user = (new User())->setTeamer($owning ? $teamer : new Teamer());
$token = $this->createMock(TokenInterface::class);
$token->method('getUser')->willReturn($user);
$this->assertSame(
$expected ? VoterInterface::ACCESS_GRANTED : VoterInterface::ACCESS_DENIED,
(new DispositionVoter($this->security))->vote($token, $disposition, [DispositionVoter::MANAGE_RECEIPTS]),
);
}
/**
* @return array<string, array{bool, bool}>
*/
public static function receiptOwnership(): array
{
return [
'their own placement' => [true, true],
'somebody else\'s placement' => [false, false],
];
}
private function vote(string $attribute, Disposition $disposition): int
{
return (new DispositionVoter($this->security))->vote(