new datamapper mostly implemented

This commit is contained in:
Dennis Eichhorn 2021-12-11 11:54:16 +01:00
parent 9b1cf99422
commit fa7e92a8b5
12 changed files with 84 additions and 54 deletions

View File

@ -20,6 +20,7 @@ use Modules\ClientManagement\Models\ClientMapper;
use Modules\Media\Models\Media; use Modules\Media\Models\Media;
use phpOMS\Asset\AssetType; use phpOMS\Asset\AssetType;
use phpOMS\Contract\RenderableInterface; use phpOMS\Contract\RenderableInterface;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Localization\ISO3166CharEnum; use phpOMS\Localization\ISO3166CharEnum;
use phpOMS\Localization\ISO3166NameEnum; use phpOMS\Localization\ISO3166NameEnum;
use phpOMS\Localization\Money; use phpOMS\Localization\Money;
@ -57,10 +58,13 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-list'); $view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response));
$client = ClientMapper::with('notes', models: null) $client = ClientMapper::getAll()
::with('contactElements', models: null) ->with('profile')
//::with('type', 'backend_image', models: [Media::class]) // @todo: it would be nicer if I coult say files:type or files/type and remove the models parameter? @todo: uncommented for now because the type is also part of client and therefore bug. that's the problem with a mix of black/whitelisting in the datamapper with the "with" feature. make it whitelist only for belongsTo, ownsMany, hasOne, .... ->with('profile/account')
::getAfterPivot(0, null, 25); ->with('profile/image')
->with('mainAddress')
->limit(25)
->execute();
$view->addData('client', $client); $view->addData('client', $client);
@ -111,10 +115,15 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-profile'); $view->setTemplate('/Modules/ClientManagement/Theme/Backend/client-profile');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003102001, $request, $response));
$client = ClientMapper $client = ClientMapper::get()
::with('files', limit: 5)::orderBy('createdAt', 'ASC') ->with('profile')
::with('notes', limit: 5)::orderBy('id', 'ASC') ->with('profile/account')
::get((int) $request->getData('id')); ->with('contactElements')
->with('mainAddress')
->with('files')->limit(5, 'files')->sort('files', OrderType::DESC)
->with('notes')->limit(5, 'files')->sort('notes', OrderType::DESC)
->where('id', (int) $request->getData('id'))
->execute();
$view->setData('client', $client); $view->setData('client', $client);
@ -123,9 +132,7 @@ final class BackendController extends Controller
$ytd = SalesBillMapper::getSalesByClientId($client->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now')); $ytd = SalesBillMapper::getSalesByClientId($client->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'));
$mtd = SalesBillMapper::getSalesByClientId($client->getId(), new SmartDateTime('Y-m-01'), new SmartDateTime('now')); $mtd = SalesBillMapper::getSalesByClientId($client->getId(), new SmartDateTime('Y-m-01'), new SmartDateTime('now'));
$lastOrder = SalesBillMapper::getLastOrderDateByClientId($client->getId()); $lastOrder = SalesBillMapper::getLastOrderDateByClientId($client->getId());
$newestInvoices = SalesBillMapper $newestInvoices = SalesBillMapper::getAll()->with('client')->where('client', $client->getId())->sort('id', OrderType::DESC)->limit(5)->execute();
::with('language', $response->getLanguage(), [BillTypeL11n::class])
::getNewestClientInvoices($client->getId(), 5);
$monthlySalesCosts = SalesBillMapper::getClientMonthlySalesCosts($client->getId(), (new SmartDateTime('now'))->createModify(-1), new SmartDateTime('now')); $monthlySalesCosts = SalesBillMapper::getClientMonthlySalesCosts($client->getId(), (new SmartDateTime('now'))->createModify(-1), new SmartDateTime('now'));
$items = SalesBillMapper::getClientItem($client->getId(), (new SmartDateTime('now'))->createModify(-1), new SmartDateTime('now')); $items = SalesBillMapper::getClientItem($client->getId(), (new SmartDateTime('now'))->createModify(-1), new SmartDateTime('now'));
} else { } else {

View File

@ -18,6 +18,7 @@ use Modules\Admin\Models\Address;
use Modules\Admin\Models\NullAddress; use Modules\Admin\Models\NullAddress;
use Modules\Editor\Models\EditorDoc; use Modules\Editor\Models\EditorDoc;
use Modules\Media\Models\Media; use Modules\Media\Models\Media;
use Modules\Media\Models\NullMedia;
use Modules\Profile\Models\ContactElement; use Modules\Profile\Models\ContactElement;
use Modules\Profile\Models\NullContactElement; use Modules\Profile\Models\NullContactElement;
use Modules\Profile\Models\Profile; use Modules\Profile\Models\Profile;
@ -308,6 +309,26 @@ class Client
return $files; return $files;
} }
/**
* Get all media files by type
*
* @param int $type Media type
*
* @return Media
*
* @since 1.0.0
*/
public function getFileByType(int $type) : Media
{
foreach ($this->files as $file) {
if ($file->type === $type) {
return $file;
}
}
return new NullMedia();
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\ClientManagement\Models; namespace Modules\ClientManagement\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* Client mapper class. * Client mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class ClientAttributeMapper extends DataMapperAbstract final class ClientAttributeMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -32,7 +32,7 @@ final class ClientAttributeMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ public const COLUMNS = [
'clientmgmt_client_attr_id' => ['name' => 'clientmgmt_client_attr_id', 'type' => 'int', 'internal' => 'id'], 'clientmgmt_client_attr_id' => ['name' => 'clientmgmt_client_attr_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_client_attr_client' => ['name' => 'clientmgmt_client_attr_client', 'type' => 'int', 'internal' => 'client'], 'clientmgmt_client_attr_client' => ['name' => 'clientmgmt_client_attr_client', 'type' => 'int', 'internal' => 'client'],
'clientmgmt_client_attr_type' => ['name' => 'clientmgmt_client_attr_type', 'type' => 'int', 'internal' => 'type'], 'clientmgmt_client_attr_type' => ['name' => 'clientmgmt_client_attr_type', 'type' => 'int', 'internal' => 'type'],
@ -45,7 +45,7 @@ final class ClientAttributeMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}> * @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $ownsOne = [ public const OWNS_ONE = [
'type' => [ 'type' => [
'mapper' => ClientAttributeTypeMapper::class, 'mapper' => ClientAttributeTypeMapper::class,
'external' => 'clientmgmt_client_attr_type', 'external' => 'clientmgmt_client_attr_type',
@ -62,7 +62,7 @@ final class ClientAttributeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'clientmgmt_client_attr'; public const TABLE = 'clientmgmt_client_attr';
/** /**
* Primary field name. * Primary field name.
@ -70,5 +70,5 @@ final class ClientAttributeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'clientmgmt_client_attr_id'; public const PRIMARYFIELD ='clientmgmt_client_attr_id';
} }

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\ClientManagement\Models; namespace Modules\ClientManagement\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* Client mapper class. * Client mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class ClientAttributeTypeL11nMapper extends DataMapperAbstract final class ClientAttributeTypeL11nMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -32,7 +32,7 @@ final class ClientAttributeTypeL11nMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ public const COLUMNS = [
'clientmgmt_attr_type_l11n_id' => ['name' => 'clientmgmt_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'], 'clientmgmt_attr_type_l11n_id' => ['name' => 'clientmgmt_attr_type_l11n_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_attr_type_l11n_title' => ['name' => 'clientmgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true], 'clientmgmt_attr_type_l11n_title' => ['name' => 'clientmgmt_attr_type_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
'clientmgmt_attr_type_l11n_type' => ['name' => 'clientmgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'], 'clientmgmt_attr_type_l11n_type' => ['name' => 'clientmgmt_attr_type_l11n_type', 'type' => 'int', 'internal' => 'type'],
@ -45,7 +45,7 @@ final class ClientAttributeTypeL11nMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'clientmgmt_attr_type_l11n'; public const TABLE = 'clientmgmt_attr_type_l11n';
/** /**
* Primary field name. * Primary field name.
@ -53,5 +53,5 @@ final class ClientAttributeTypeL11nMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'clientmgmt_attr_type_l11n_id'; public const PRIMARYFIELD ='clientmgmt_attr_type_l11n_id';
} }

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\ClientManagement\Models; namespace Modules\ClientManagement\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* Client mapper class. * Client mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class ClientAttributeTypeMapper extends DataMapperAbstract final class ClientAttributeTypeMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -32,7 +32,7 @@ final class ClientAttributeTypeMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ public const COLUMNS = [
'clientmgmt_attr_type_id' => ['name' => 'clientmgmt_attr_type_id', 'type' => 'int', 'internal' => 'id'], 'clientmgmt_attr_type_id' => ['name' => 'clientmgmt_attr_type_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_attr_type_name' => ['name' => 'clientmgmt_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true], 'clientmgmt_attr_type_name' => ['name' => 'clientmgmt_attr_type_name', 'type' => 'string', 'internal' => 'name', 'autocomplete' => true],
'clientmgmt_attr_type_fields' => ['name' => 'clientmgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'], 'clientmgmt_attr_type_fields' => ['name' => 'clientmgmt_attr_type_fields', 'type' => 'int', 'internal' => 'fields'],
@ -47,21 +47,19 @@ final class ClientAttributeTypeMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $hasMany = [ public const HAS_MANY = [
'l11n' => [ 'l11n' => [
'mapper' => ClientAttributeTypeL11nMapper::class, 'mapper' => ClientAttributeTypeL11nMapper::class,
'table' => 'clientmgmt_attr_type_l11n', 'table' => 'clientmgmt_attr_type_l11n',
'self' => 'clientmgmt_attr_type_l11n_type', 'self' => 'clientmgmt_attr_type_l11n_type',
'column' => 'title', 'column' => 'title',
'conditional' => true,
'external' => null, 'external' => null,
], ],
'defaults' => [ 'defaults' => [
'mapper' => ClientAttributeValueMapper::class, 'mapper' => ClientAttributeValueMapper::class,
'table' => 'clientmgmt_client_attr_default', 'table' => 'clientmgmt_client_attr_default',
'self' => 'clientmgmt_client_attr_default_type', 'self' => 'clientmgmt_client_attr_default_type',
'external' => 'clientmgmt_client_attr_default_value', 'external' => 'clientmgmt_client_attr_default_value'
'conditional' => false,
], ],
]; ];
@ -71,7 +69,7 @@ final class ClientAttributeTypeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'clientmgmt_attr_type'; public const TABLE = 'clientmgmt_attr_type';
/** /**
* Primary field name. * Primary field name.
@ -79,5 +77,5 @@ final class ClientAttributeTypeMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'clientmgmt_attr_type_id'; public const PRIMARYFIELD ='clientmgmt_attr_type_id';
} }

View File

@ -14,7 +14,7 @@ declare(strict_types=1);
namespace Modules\ClientManagement\Models; namespace Modules\ClientManagement\Models;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* Client mapper class. * Client mapper class.
@ -24,7 +24,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https: //orange-management.org * @link https: //orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class ClientAttributeValueMapper extends DataMapperAbstract final class ClientAttributeValueMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -32,7 +32,7 @@ final class ClientAttributeValueMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ public const COLUMNS = [
'clientmgmt_attr_value_id' => ['name' => 'clientmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'], 'clientmgmt_attr_value_id' => ['name' => 'clientmgmt_attr_value_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_attr_value_default' => ['name' => 'clientmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'], 'clientmgmt_attr_value_default' => ['name' => 'clientmgmt_attr_value_default', 'type' => 'bool', 'internal' => 'isDefault'],
'clientmgmt_attr_value_type' => ['name' => 'clientmgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'], 'clientmgmt_attr_value_type' => ['name' => 'clientmgmt_attr_value_type', 'type' => 'int', 'internal' => 'type'],
@ -50,7 +50,7 @@ final class ClientAttributeValueMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'clientmgmt_attr_value'; public const TABLE = 'clientmgmt_attr_value';
/** /**
* Primary field name. * Primary field name.
@ -58,5 +58,5 @@ final class ClientAttributeValueMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'clientmgmt_attr_value_id'; public const PRIMARYFIELD ='clientmgmt_attr_value_id';
} }

View File

@ -19,7 +19,7 @@ use Modules\Editor\Models\EditorDocMapper;
use Modules\Media\Models\MediaMapper; use Modules\Media\Models\MediaMapper;
use Modules\Profile\Models\ContactElementMapper; use Modules\Profile\Models\ContactElementMapper;
use Modules\Profile\Models\ProfileMapper; use Modules\Profile\Models\ProfileMapper;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
/** /**
* Client mapper class. * Client mapper class.
@ -29,7 +29,7 @@ use phpOMS\DataStorage\Database\DataMapperAbstract;
* @link https://orange-management.org * @link https://orange-management.org
* @since 1.0.0 * @since 1.0.0
*/ */
final class ClientMapper extends DataMapperAbstract final class ClientMapper extends DataMapperFactory
{ {
/** /**
* Columns. * Columns.
@ -37,7 +37,7 @@ final class ClientMapper extends DataMapperAbstract
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}> * @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $columns = [ public const COLUMNS = [
'clientmgmt_client_id' => ['name' => 'clientmgmt_client_id', 'type' => 'int', 'internal' => 'id'], 'clientmgmt_client_id' => ['name' => 'clientmgmt_client_id', 'type' => 'int', 'internal' => 'id'],
'clientmgmt_client_no' => ['name' => 'clientmgmt_client_no', 'type' => 'string', 'internal' => 'number'], 'clientmgmt_client_no' => ['name' => 'clientmgmt_client_no', 'type' => 'string', 'internal' => 'number'],
'clientmgmt_client_no_reverse' => ['name' => 'clientmgmt_client_no_reverse', 'type' => 'string', 'internal' => 'numberReverse'], 'clientmgmt_client_no_reverse' => ['name' => 'clientmgmt_client_no_reverse', 'type' => 'string', 'internal' => 'numberReverse'],
@ -55,7 +55,7 @@ final class ClientMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $table = 'clientmgmt_client'; public const TABLE = 'clientmgmt_client';
/** /**
* Primary field name. * Primary field name.
@ -63,7 +63,7 @@ final class ClientMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $primaryField = 'clientmgmt_client_id'; public const PRIMARYFIELD ='clientmgmt_client_id';
/** /**
* Created at column * Created at column
@ -71,7 +71,7 @@ final class ClientMapper extends DataMapperAbstract
* @var string * @var string
* @since 1.0.0 * @since 1.0.0
*/ */
protected static string $createdAt = 'clientmgmt_client_created_at'; public const CREATED_AT = 'clientmgmt_client_created_at';
/** /**
* Has one relation. * Has one relation.
@ -79,7 +79,7 @@ final class ClientMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}> * @var array<string, array{mapper:string, external:string, by?:string, column?:string, conditional?:bool}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $ownsOne = [ public const OWNS_ONE = [
'profile' => [ 'profile' => [
'mapper' => ProfileMapper::class, 'mapper' => ProfileMapper::class,
'external' => 'clientmgmt_client_profile', 'external' => 'clientmgmt_client_profile',
@ -96,7 +96,7 @@ final class ClientMapper extends DataMapperAbstract
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}> * @var array<string, array{mapper:string, table:string, self?:?string, external?:?string, column?:string}>
* @since 1.0.0 * @since 1.0.0
*/ */
protected static array $hasMany = [ public const HAS_MANY = [
'files' => [ 'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */ 'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'clientmgmt_client_media', /* table of the related object, null if no relation table is used (many->1) */ 'table' => 'clientmgmt_client_media', /* table of the related object, null if no relation table is used (many->1) */

View File

@ -104,7 +104,7 @@ echo $this->getData('nav')->render(); ?>
<tbody> <tbody>
<?php $count = 0; foreach ($clients as $key => $value) : ++$count; <?php $count = 0; foreach ($clients as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId()); $url = UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $value->getId());
$image = $value->getFileByType('backend_image'); $image = $value->getFileByType(0);
?> ?>
<tr data-href="<?= $url; ?>"> <tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><img width="30" loading="lazy" class="item-image" <td><a href="<?= $url; ?>"><img width="30" loading="lazy" class="item-image"

View File

@ -162,7 +162,9 @@ $bills = $this->getData('newestInvoices') ?? [];
<i class="filter fa fa-filter"></i> <i class="filter fa fa-filter"></i>
</label> </label>
<tbody> <tbody>
<?php $count = 0; foreach ($bills as $key => $value) : <?php $count = 0;
/** @var \Modules\Billing\Models\Bill $value */
foreach ($bills as $key => $value) :
++$count; ++$count;
$url = UriFactory::build('{/prefix}sales/bill?{?}&id=' . $value->getId()); $url = UriFactory::build('{/prefix}sales/bill?{?}&id=' . $value->getId());
?> ?>
@ -179,8 +181,8 @@ $bills = $this->getData('newestInvoices') ?? [];
<td><a href="<?= $url; ?>"><?= $value->billZip; ?></a> <td><a href="<?= $url; ?>"><?= $value->billZip; ?></a>
<td><a href="<?= $url; ?>"><?= $value->billCity; ?></a> <td><a href="<?= $url; ?>"><?= $value->billCity; ?></a>
<td><a href="<?= $url; ?>"><?= $value->billCountry; ?></a> <td><a href="<?= $url; ?>"><?= $value->billCountry; ?></a>
<td><a href="<?= $url; ?>"><?= $value->net->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $value->netSales->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->profit->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $value->netProfit->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $value->createdAt->format('Y-m-d'); ?></a> <td><a href="<?= $url; ?>"><?= $value->createdAt->format('Y-m-d'); ?></a>
<?php endforeach; ?> <?php endforeach; ?>
<?php if ($count === 0) : ?> <?php if ($count === 0) : ?>

View File

@ -262,14 +262,16 @@ echo $this->getData('nav')->render();
<td><?= $this->getHtml('Net'); ?> <td><?= $this->getHtml('Net'); ?>
<td><?= $this->getHtml('Date'); ?> <td><?= $this->getHtml('Date'); ?>
<tbody> <tbody>
<?php foreach ($newestInvoices as $invoice) : <?php
/** @var \Modules\Billing\Models\Bill $invoice */
foreach ($newestInvoices as $invoice) :
$url = UriFactory::build('{/prefix}sales/bill?{?}&id=' . $invoice->getId()); $url = UriFactory::build('{/prefix}sales/bill?{?}&id=' . $invoice->getId());
?> ?>
<tr data-href="<?= $url; ?>"> <tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $invoice->getNumber(); ?></a> <td><a href="<?= $url; ?>"><?= $invoice->getNumber(); ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->type->getL11n(); ?></a> <td><a href="<?= $url; ?>"><?= $invoice->type->getL11n(); ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->billTo; ?></a> <td><a href="<?= $url; ?>"><?= $invoice->billTo; ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->net->getCurrency(); ?></a> <td><a href="<?= $url; ?>"><?= $invoice->netSales->getCurrency(); ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->createdAt->format('Y-m-d'); ?></a> <td><a href="<?= $url; ?>"><?= $invoice->createdAt->format('Y-m-d'); ?></a>
<?php endforeach; ?> <?php endforeach; ?>
</table> </table>

View File

@ -12,7 +12,7 @@ require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/Autoloader.php'; require_once __DIR__ . '/Autoloader.php';
use phpOMS\DataStorage\Database\DatabasePool; use phpOMS\DataStorage\Database\DatabasePool;
use phpOMS\DataStorage\Database\DataMapperAbstract; use phpOMS\DataStorage\Database\Mapper\DataMapperFactory;
use phpOMS\DataStorage\Session\HttpSession; use phpOMS\DataStorage\Session\HttpSession;
$CONFIG = [ $CONFIG = [
@ -329,7 +329,7 @@ $GLOBALS['dbpool']->create('delete', $CONFIG['db']['core']['masters']['delete'])
$GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']); $GLOBALS['dbpool']->create('insert', $CONFIG['db']['core']['masters']['insert']);
$GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']); $GLOBALS['dbpool']->create('schema', $CONFIG['db']['core']['masters']['schema']);
DataMapperAbstract::setConnection($GLOBALS['dbpool']->get()); DataMapperFactory::db($GLOBALS['dbpool']->get());
$GLOBALS['frameworkpath'] = '/phpOMS/'; $GLOBALS['frameworkpath'] = '/phpOMS/';

View File

@ -37,7 +37,7 @@ final class ClientMapperTest extends \PHPUnit\Framework\TestCase
// This is required because by default a NullAccount without an ID is created in the Profile model // 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. // but NullModels without ids are handled like "null" values which are not allowed for Accounts.
$profile = ProfileMapper::getFor(1, 'account'); $profile = ProfileMapper::get()->where('account', 1)->execute();
$profile = $profile instanceof NullProfile ? new Profile() : $profile; $profile = $profile instanceof NullProfile ? new Profile() : $profile;
if ($profile->account->getId() === 0) { if ($profile->account->getId() === 0) {
$profile->account = new NullAccount(1); $profile->account = new NullAccount(1);
@ -45,7 +45,7 @@ final class ClientMapperTest extends \PHPUnit\Framework\TestCase
$client->profile = $profile; $client->profile = $profile;
$id = ClientMapper::create($client); $id = ClientMapper::create()->execute($client);
self::assertGreaterThan(0, $client->getId()); self::assertGreaterThan(0, $client->getId());
self::assertEquals($id, $client->getId()); self::assertEquals($id, $client->getId());
} }