diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 870a417..34fe9c7 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -152,9 +152,9 @@ final class ApiController extends Controller AuditMapper::create()->execute($audit); if (($validate['status'] === 0 - && $validate['vat'] === true - && $validate['name'] === true - && $validate['city'] === true) + && $validate['vat'] === 'A' + && $validate['name'] === 'A' + && $validate['city'] === 'A') || $validate['status'] !== 0 // Api out of order -> accept it -> @todo: test it during invoice creation ) { /** @var \Modules\Attribute\Models\AttributeType $type */ diff --git a/Controller/BackendController.php b/Controller/BackendController.php index 8ba826a..a7ae561 100755 --- a/Controller/BackendController.php +++ b/Controller/BackendController.php @@ -18,8 +18,11 @@ use Modules\Billing\Models\SalesBillMapper; use Modules\ClientManagement\Models\ClientAttributeTypeMapper; use Modules\ClientManagement\Models\ClientAttributeValueMapper; use Modules\ClientManagement\Models\ClientMapper; +use Modules\Media\Models\MediaMapper; +use Modules\Media\Models\MediaTypeMapper; use phpOMS\Asset\AssetType; use phpOMS\Contract\RenderableInterface; +use phpOMS\DataStorage\Database\Query\Builder; use phpOMS\DataStorage\Database\Query\OrderType; use phpOMS\Localization\ISO3166CharEnum; use phpOMS\Localization\ISO3166NameEnum; @@ -219,6 +222,33 @@ final class BackendController extends Controller $view->setData('client', $client); + // Get item profile image + // It might not be part of the 5 newest item files from above + // @todo: It would be nice to have something like this as a default method in the model e.g. + // ItemManagement::getRelations()->with('types')->where(...); + // This should return the relations and NOT the model itself + $query = new Builder($this->app->dbPool->get()); + $results = $query->selectAs(ClientMapper::HAS_MANY['files']['external'], 'file') + ->from(ClientMapper::TABLE) + ->leftJoin(ClientMapper::HAS_MANY['files']['table']) + ->on(ClientMapper::HAS_MANY['files']['table'] . '.' . ClientMapper::HAS_MANY['files']['self'], '=', ClientMapper::TABLE . '.' . ClientMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::TABLE) + ->on(ClientMapper::HAS_MANY['files']['table'] . '.' . ClientMapper::HAS_MANY['files']['external'], '=', MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD) + ->leftJoin(MediaMapper::HAS_MANY['types']['table']) + ->on(MediaMapper::TABLE . '.' . MediaMapper::PRIMARYFIELD, '=', MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['self']) + ->leftJoin(MediaTypeMapper::TABLE) + ->on(MediaMapper::HAS_MANY['types']['table'] . '.' . MediaMapper::HAS_MANY['types']['external'], '=', MediaTypeMapper::TABLE . '.' . MediaTypeMapper::PRIMARYFIELD) + ->where(ClientMapper::HAS_MANY['files']['self'], '=', $client->getId()) + ->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'client_profile_image'); + + $clientImage = MediaMapper::get() + ->with('types') + ->where('id', $results) + ->limit(1) + ->execute(); + + $view->addData('clientImage', $clientImage); + // stats if ($this->app->moduleManager->isActive('Billing')) { $ytd = SalesBillMapper::getSalesByClientId($client->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now')); diff --git a/Theme/Backend/client-profile.tpl.php b/Theme/Backend/client-profile.tpl.php index 01cc17f..74db65f 100755 --- a/Theme/Backend/client-profile.tpl.php +++ b/Theme/Backend/client-profile.tpl.php @@ -12,6 +12,7 @@ */ declare(strict_types=1); +use Modules\Media\Models\NullMedia; use Modules\Profile\Models\ContactType; use phpOMS\Uri\UriFactory; @@ -25,6 +26,8 @@ $client = $this->getData('client'); $notes = $client->getNotes(); $files = $client->getFiles(); +$clientImage = $this->getData('clientImage') ?? new NullMedia(); + $newestInvoices = $this->getData('newestInvoices') ?? []; $monthlySalesCosts = $this->getData('monthlySalesCosts') ?? []; diff --git a/tests/Controller/ApiControllerTest.php b/tests/Controller/ApiControllerTest.php index 7c3bd36..e0da714 100755 --- a/tests/Controller/ApiControllerTest.php +++ b/tests/Controller/ApiControllerTest.php @@ -25,6 +25,7 @@ use phpOMS\Application\ApplicationAbstract; use phpOMS\DataStorage\Session\HttpSession; use phpOMS\Dispatcher\Dispatcher; use phpOMS\Event\EventManager; +use phpOMS\Localization\L11nManager; use phpOMS\Module\ModuleAbstract; use phpOMS\Module\ModuleManager; use phpOMS\Router\WebRouter; @@ -63,6 +64,7 @@ final class ApiControllerTest extends \PHPUnit\Framework\TestCase $this->app->eventManager = new EventManager($this->app->dispatcher); $this->app->eventManager->importFromFile(__DIR__ . '/../../../../Web/Api/Hooks.php'); $this->app->sessionManager = new HttpSession(36000); + $this->app->l11nManager = new L11nManager(); $account = new Account(); TestUtils::setMember($account, 'id', 1); diff --git a/tests/Models/ClientAttributeTest.php b/tests/Models/ClientAttributeTest.php deleted file mode 100755 index d9b185a..0000000 --- a/tests/Models/ClientAttributeTest.php +++ /dev/null @@ -1,63 +0,0 @@ -attribute = new ClientAttribute(); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttribute - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->attribute->getId()); - self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttributeType', $this->attribute->type); - self::assertInstanceOf('\Modules\ClientManagement\Models\ClientAttributeValue', $this->attribute->value); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttribute - * @group module - */ - public function testSerialize() : void - { - $serialized = $this->attribute->jsonSerialize(); - - self::assertEquals( - [ - 'id', - 'client', - 'type', - 'value', - ], - \array_keys($serialized) - ); - } -} diff --git a/tests/Models/ClientAttributeTypeTest.php b/tests/Models/ClientAttributeTypeTest.php deleted file mode 100755 index 0d1afc8..0000000 --- a/tests/Models/ClientAttributeTypeTest.php +++ /dev/null @@ -1,82 +0,0 @@ -type = new ClientAttributeType(); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeType - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->type->getId()); - self::assertEquals('', $this->type->getL11n()); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeType - * @group module - */ - public function testL11nInputOutput() : void - { - $this->type->setL11n('Test'); - self::assertEquals('Test', $this->type->getL11n()); - - $this->type->setL11n(new BaseStringL11n('NewTest')); - self::assertEquals('NewTest', $this->type->getL11n()); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeType - * @group module - */ - public function testSerialize() : void - { - $this->type->name = 'Title'; - $this->type->fields = 2; - $this->type->custom = true; - $this->type->validationPattern = '\d*'; - $this->type->isRequired = true; - - self::assertEquals( - [ - 'id' => 0, - 'name' => 'Title', - 'fields' => 2, - 'custom' => true, - 'validationPattern' => '\d*', - 'isRequired' => true, - ], - $this->type->jsonSerialize() - ); - } -} diff --git a/tests/Models/ClientAttributeValueTest.php b/tests/Models/ClientAttributeValueTest.php deleted file mode 100755 index c999952..0000000 --- a/tests/Models/ClientAttributeValueTest.php +++ /dev/null @@ -1,107 +0,0 @@ -value = new ClientAttributeValue(); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeValue - * @group module - */ - public function testDefault() : void - { - self::assertEquals(0, $this->value->getId()); - self::assertNull($this->value->getValue()); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeValue - * @group module - */ - public function testValueIntInputOutput() : void - { - $this->value->setValue(1, AttributeValueType::_INT); - self::assertEquals(1, $this->value->getValue()); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeValue - * @group module - */ - public function testValueFloatInputOutput() : void - { - $this->value->setValue(1.1, AttributeValueType::_FLOAT); - self::assertEquals(1.1, $this->value->getValue()); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeValue - * @group module - */ - public function testValueStringInputOutput() : void - { - $this->value->setValue('test', AttributeValueType::_STRING); - self::assertEquals('test', $this->value->getValue()); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeValue - * @group module - */ - public function testValueDateInputOutput() : void - { - $dat = new \DateTime('now'); - $this->value->setValue('now', AttributeValueType::_DATETIME); - self::assertEquals($dat->format('Y-m-d'), $this->value->getValue()->format('Y-m-d')); - } - - /** - * @covers Modules\ClientManagement\Models\ClientAttributeValue - * @group module - */ - public function testSerialize() : void - { - $this->value->setValue('test', AttributeValueType::_STRING); - $this->value->isDefault = true; - - self::assertEquals( - [ - 'id' => 0, - 'valueInt' => null, - 'valueStr' => 'test', - 'valueDec' => null, - 'valueDat' => null, - 'isDefault' => true, - ], - $this->value->jsonSerialize() - ); - } -} diff --git a/tests/Models/ClientTest.php b/tests/Models/ClientTest.php index e2304d2..b423533 100755 --- a/tests/Models/ClientTest.php +++ b/tests/Models/ClientTest.php @@ -52,7 +52,7 @@ final class ClientTest extends \PHPUnit\Framework\TestCase self::assertEquals([], $this->client->getAddresses()); self::assertEquals([], $this->client->getContactElements()); self::assertEquals((new \DateTime('now'))->format('Y-m-d'), $this->client->createdAt->format('Y-m-d')); - self::assertInstanceOf('\Modules\Profile\Models\Profile', $this->client->profile); + self::assertInstanceOf('\Modules\Admin\Models\Account', $this->client->account); self::assertInstanceOf('\Modules\Admin\Models\Address', $this->client->mainAddress); self::assertInstanceOf('\Modules\Profile\Models\NullContactElement', $this->client->getMainContactElement(0)); } diff --git a/tests/Models/NullClientAttributeTest.php b/tests/Models/NullClientAttributeTest.php deleted file mode 100755 index 943a1f7..0000000 --- a/tests/Models/NullClientAttributeTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/NullClientAttributeTypeTest.php b/tests/Models/NullClientAttributeTypeTest.php deleted file mode 100755 index 3ac18b3..0000000 --- a/tests/Models/NullClientAttributeTypeTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -} diff --git a/tests/Models/NullClientAttributeValueTest.php b/tests/Models/NullClientAttributeValueTest.php deleted file mode 100755 index c2f21ea..0000000 --- a/tests/Models/NullClientAttributeValueTest.php +++ /dev/null @@ -1,42 +0,0 @@ -getId()); - } -}