diff --git a/Admin/Install/db.json b/Admin/Install/db.json
index 5e5bc1f..54b34d1 100644
--- a/Admin/Install/db.json
+++ b/Admin/Install/db.json
@@ -12,7 +12,8 @@
"clientmgmt_client_no": {
"name": "clientmgmt_client_no",
"type": "VARCHAR(255)",
- "null": false
+ "null": false,
+ "unique": true
},
"clientmgmt_client_no_reverse": {
"name": "clientmgmt_client_no_reverse",
@@ -39,8 +40,8 @@
"type": "DATETIME",
"null": false
},
- "clientmgmt_client_account": {
- "name": "clientmgmt_client_account",
+ "clientmgmt_client_profile": {
+ "name": "clientmgmt_client_profile",
"type": "INT",
"null": false,
"foreignTable": "profile_account",
diff --git a/Controller/BackendController.php b/Controller/BackendController.php
index 91b852f..439e677 100644
--- a/Controller/BackendController.php
+++ b/Controller/BackendController.php
@@ -49,7 +49,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ClientManagement/Theme/Backend/clients-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response));
- $client = ClientMapper::getNewest(50);
+ $client = ClientMapper::getAll();
$view->addData('client', $client);
return $view;
diff --git a/Models/Client.php b/Models/Client.php
index 090b35d..c0568a3 100644
--- a/Models/Client.php
+++ b/Models/Client.php
@@ -43,7 +43,7 @@ class Client
private \DateTime $createdAt;
- private $profile = null;
+ private Profile $profile;
private array $files = [];
diff --git a/Models/ClientMapper.php b/Models/ClientMapper.php
index 124f500..e329b1f 100644
--- a/Models/ClientMapper.php
+++ b/Models/ClientMapper.php
@@ -43,7 +43,7 @@ final class ClientMapper extends DataMapperAbstract
'clientmgmt_client_type' => ['name' => 'clientmgmt_client_type', 'type' => 'int', 'internal' => 'type'],
'clientmgmt_client_info' => ['name' => 'clientmgmt_client_info', 'type' => 'string', 'internal' => 'info'],
'clientmgmt_client_created_at' => ['name' => 'clientmgmt_client_created_at', 'type' => 'DateTime', 'internal' => 'createdAt', 'readonly' => true],
- 'clientmgmt_client_account' => ['name' => 'clientmgmt_client_account', 'type' => 'int', 'internal' => 'profile'],
+ 'clientmgmt_client_profile' => ['name' => 'clientmgmt_client_profile', 'type' => 'int', 'internal' => 'profile'],
];
/**
@@ -79,7 +79,7 @@ final class ClientMapper extends DataMapperAbstract
protected static array $ownsOne = [
'profile' => [
'mapper' => ProfileMapper::class,
- 'self' => 'clientmgmt_client_account',
+ 'self' => 'clientmgmt_client_profile',
],
];
diff --git a/Theme/Backend/clients-profile.tpl.php b/Theme/Backend/clients-profile.tpl.php
index 2bbbc22..aabb893 100644
--- a/Theme/Backend/clients-profile.tpl.php
+++ b/Theme/Backend/clients-profile.tpl.php
@@ -75,7 +75,9 @@ echo $this->getData('nav')->render();
diff --git a/tests/Models/ClientMapperTest.php b/tests/Models/ClientMapperTest.php
index e69de29..c73805e 100644
--- a/tests/Models/ClientMapperTest.php
+++ b/tests/Models/ClientMapperTest.php
@@ -0,0 +1,70 @@
+setNumber('123456789');
+
+ // This is required because by default a NullAccount without an ID is created in the Profile model
+ // but NullModels without ids are handled like "null" values which are not allowed for Accounts.
+ $profile = ProfileMapper::getFor(1, 'account');
+ $profile = $profile instanceof NullProfile ? new Profile() : $profile;
+ if ($profile->getAccount()->getId() === 0) {
+ $profile->setAccount(new NullAccount(1));
+ }
+
+ $client->setProfile($profile);
+
+ $id = ClientMapper::create($client);
+ self::assertGreaterThan(0, $client->getId());
+ self::assertEquals($id, $client->getId());
+ }
+
+ /**
+ * @group volume
+ * @group module
+ * @coversNothing
+ */
+ public function testClientVolume() : void
+ {
+ $profile = ProfileMapper::getFor(1, 'account');
+ $profile = $profile instanceof NullProfile ? new Profile() : $profile;
+ if ($profile->getAccount()->getId() === 0) {
+ $profile->setAccount(new NullAccount(1));
+ }
+
+ for ($i = 0; $i < 100; ++$i) {
+ $client = new Client();
+ $client->setNumber((string) \mt_rand(100000, 999999));
+
+ $client->setProfile($profile);
+ ClientMapper::create($client);
+ }
+ }
+}