bug fixes / dbmapper fixes

This commit is contained in:
Dennis Eichhorn 2021-12-19 20:20:39 +01:00
parent 75340bbe28
commit 50f94855c9
13 changed files with 128 additions and 123 deletions

View File

@ -67,7 +67,7 @@ final class Installer extends InstallerAbstract
{
$itemAttrType = [];
$itemAttrType['color'] = new ItemAttributeType('color'); // @todo: I think 'color' in this case is a ItemAttributeTypeL11n, this is wrong?!
$itemAttrType['color'] = new ItemAttributeType('color');
ItemAttributeTypeMapper::create()->execute($itemAttrType['color']);
ItemAttributeTypeL11nMapper::create()->execute(new ItemAttributeTypeL11n($itemAttrType['color']->getId(), 'Color', ISO639x1Enum::_EN));
ItemAttributeTypeL11nMapper::create()->execute(new ItemAttributeTypeL11n($itemAttrType['color']->getId(), 'Farbe', ISO639x1Enum::_DE));

View File

@ -16,17 +16,14 @@ namespace Modules\ItemManagement\Controller;
use Model\SettingsEnum;
use Modules\Admin\Models\LocalizationMapper;
use Modules\Billing\Models\BillTypeL11n;
use Modules\Billing\Models\BillTransferType;
use Modules\Billing\Models\SalesBillMapper;
use Modules\ItemManagement\Models\ItemAttributeMapper;
use Modules\ItemManagement\Models\ItemAttributeTypeMapper;
use Modules\ItemManagement\Models\ItemAttributeValueMapper;
use Modules\ItemManagement\Models\ItemL11nMapper;
use Modules\ItemManagement\Models\ItemL11nType;
use Modules\ItemManagement\Models\ItemMapper;
use Modules\Media\Models\Media;
use phpOMS\Asset\AssetType;
use phpOMS\Contract\RenderableInterface;
use phpOMS\DataStorage\Database\Query\OrderType;
use phpOMS\Localization\ISO3166CharEnum;
use phpOMS\Localization\ISO3166NameEnum;
use phpOMS\Localization\Money;
@ -64,8 +61,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-type-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attributes = ItemAttributeTypeMapper::with('language', $response->getLanguage())
::getAll();
$attributes = ItemAttributeTypeMapper::getAll()->with('l11n')->where('l11n/language', $response->getLanguage())->execute();
$view->addData('attributes', $attributes);
@ -90,8 +86,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-value-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attributes = ItemAttributeValueMapper::with('language', $response->getLanguage())
::getAll();
$attributes = ItemAttributeValueMapper::getAll()->with('l11n')->where('l11n/language', $response->getLanguage())->execute();
$view->addData('attributes', $attributes);
@ -116,8 +111,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-type');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attribute = ItemAttributeTypeMapper::with('language', $response->getLanguage())
::get((int) $request->getData('id'));
$attribute = ItemAttributeTypeMapper::get()->with('l11n')->where('id', (int) $request->getData('id'))->where('l11n/language', $response->getLanguage())->execute();
$view->addData('attribute', $attribute);
@ -142,8 +136,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-value');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attribute = ItemAttributeValueMapper::with('language', $response->getLanguage())
::get((int) $request->getData('id'));
$attribute = ItemAttributeValueMapper::get()->with('l11n')->where('id', (int) $request->getData('id'))->where('l11n/language', $response->getLanguage())->execute();
$view->addData('attribute', $attribute);
@ -172,19 +165,10 @@ final class BackendController extends Controller
->with('l11n')
->with('l11n/type')
->where('l11n/language', $response->getLanguage())
->where('l11n/type', ['name1', 'name2', 'name3'], 'IN')
->where('l11n/type/title', ['name1', 'name2', 'name3'], 'IN')
->limit(25)
->execute();
/*
$items = ItemMapper::with('language', $response->getLanguage())
::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?
::with('notes', models: null)
::with('attributes', models: null)
::with('title', ['name1', 'name2', 'name3'], comparison: 'in', models: [ItemL11nType::class]) // @todo: profile, why does this have almost no impact on the sql performance?
::getAfterPivot(0, null, 25);
*/
$view->addData('items', $items);
return $view;
@ -208,7 +192,14 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/purchase-item-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004806001, $request, $response));
$items = ItemMapper::with('language', $response->getLanguage())::getAfterPivot(0, null, 25);
$items = ItemMapper::getAll()
->with('l11n')
->with('l11n/type')
->where('l11n/language', $response->getLanguage())
->where('l11n/type/title', ['name1', 'name2', 'name3'], 'IN')
->limit(25)
->execute();
$view->addData('items', $items);
return $view;
@ -324,25 +315,25 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/sales-item-profile');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004805001, $request, $response));
$item = ItemMapper::with('language', $response->getLanguage())
::with('files', limit: 5)::orderBy('createdAt', 'ASC')
::with('notes', limit: 5)::orderBy('id', 'ASC')
::get((int) $request->getData('id'));
$item = ItemMapper::get()
->with('l11n')
->with('l11n/type')
->with('files')
->with('notes')
->where('id', (int) $request->getData('id'))
->where('l11n/language', $response->getLanguage())
->where('l11n/type/title', ['name1', 'name2', 'name3'], 'IN')
->limit(5, 'files')->sort('files/id', OrderType::DESC) // @todo: limit not working!!!
->limit(5, 'notes')->sort('notes/id', OrderType::DESC)
->execute();
$view->addData('item', $item);
$settings = $this->app->appSettings->get(null, [
SettingsEnum::DEFAULT_LOCALIZATION,
]);
$view->setData('defaultlocalization', LocalizationMapper::get()->where('id', (int) $settings['id']))->execute();
$itemL11n = ItemL11nMapper::with('language', $response->getLanguage())
::with('item', $item->getId())::getAll();
$view->addData('itemL11n', $itemL11n);
$itemAttribute = ItemAttributeMapper::with('language', $response->getLanguage())
::with('item', $item->getId())::getAll();
$view->addData('itemAttribute', $itemAttribute);
$view->setData('defaultlocalization', LocalizationMapper::get()->where('id', (int) $settings->getId())->execute());
// stats
if ($this->app->moduleManager->isActive('Billing')) {
@ -350,9 +341,14 @@ final class BackendController extends Controller
$mtd = SalesBillMapper::getSalesByItemId($item->getId(), new SmartDateTime('Y-m-01'), new SmartDateTime('now'));
$avg = SalesBillMapper::getAvgSalesPriceByItemId($item->getId(), (new SmartDateTime('now'))->smartModify(-1), new SmartDateTime('now'));
$lastOrder = SalesBillMapper::getLastOrderDateByItemId($item->getId());
// @todo: why is the conditional array necessary, shouldn't the mapper realize when it mustn't use the conditional (when the field doesn't exist in the mapper)
$newestInvoices = SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])::getNewestItemInvoices($item->getId(), 5);
$topCustomers = SalesBillMapper::getItemTopCustomers($item->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'), 5);
$newestInvoices = SalesBillMapper::getAll()
->with('type')
->where('type/transferType', BillTransferType::SALES)
->sort('id', OrderType::DESC)
->limit(5)
->execute();
$topCustomers = [];
$allInvoices = SalesBillMapper::getItemBills($item->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'));
$regionSales = SalesBillMapper::getItemRegionSales($item->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'));
$countrySales = SalesBillMapper::getItemCountrySales($item->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'), 5);

View File

@ -80,7 +80,7 @@ class Item
/**
* Attributes.
*
* @var int[]|ItemAttribute[]
* @var ItemAttribute[]
* @since 1.0.0
*/
private array $attributes = [];
@ -142,13 +142,13 @@ class Item
/**
* Get l11n
*
* @param string $type Localization type
* @param null|string $type Localization type
*
* @return ItemL11n
*
* @since 1.0.0
*/
public function getL11n(string $type) : ItemL11n
public function getL11n(string $type = null) : ItemL11n
{
foreach ($this->l11n as $l11n) {
if ($l11n->type->title === $type) {
@ -159,6 +159,18 @@ class Item
return new NullItemL11n();
}
/**
* Get localizations
*
* @return ItemL11n[]
*
* @since 1.0.0
*/
public function getL11ns() : array
{
return $this->l11n;
}
/**
* Get status.
*
@ -216,7 +228,7 @@ class Item
/**
* Get attributes
*
* @return int[]|ItemAttribute[]
* @return ItemAttribute[]
*
* @since 1.0.0
*/

View File

@ -38,10 +38,10 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
/**
* Item ID.
*
* @var ItemAttributeType
* @var int
* @since 1.0.0
*/
public ItemAttributeType $type;
public int $type;
/**
* Language.
@ -62,15 +62,15 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
/**
* Constructor.
*
* @param ItemAttributeType $type Attribute type
* @param int $type Attribute type
* @param string $title Localized title
* @param string $language Language
*
* @since 1.0.0
*/
public function __construct(ItemAttributeType $type = null, string $title = '', string $language = ISO639x1Enum::_EN)
public function __construct(int $type = 0, string $title = '', string $language = ISO639x1Enum::_EN)
{
$this->type = $type ?? new ItemAttributeType();;
$this->type = $type;
$this->title = $title;
$this->language = $language;
}

View File

@ -43,10 +43,6 @@ final class ItemMapper extends DataMapperFactory
'itemmgmt_item_purchaseprice' => ['name' => 'itemmgmt_item_purchaseprice', 'type' => 'Serializable', 'internal' => 'purchasePrice'],
];
protected static array $conditionals = [
];
/**
* Primary table.
*

View File

@ -21,11 +21,8 @@ use phpOMS\Uri\UriFactory;
/** @var \Modules\ItemManagement\Models\Item $item */
$item = $this->getData('item');
/** @var \Modules\ItemManagement\Models\ItemL11n $itemL11n */
$itemL11n = $this->getData('itemL11n');
/** @var \Modules\ItemManagement\Models\ItemAttribute $itemAttribute */
$itemAttribute = $this->getData('itemAttribute');
$itemL11n = $item->getL11ns();
$itemAttribute = $item->getAttributes();
$notes = $item->getNotes();
$files = $item->getFiles();
@ -90,7 +87,7 @@ echo $this->getData('nav')->render();
</form>
</section>
<?php $image = $item->getFileByType('backend_image');
<?php $image = $item->getFileByType(0);
if (!($image instanceof NullMedia)) : ?>
<section class="portlet">
<div class="portlet-body">
@ -217,14 +214,16 @@ echo $this->getData('nav')->render();
<td><?= $this->getHtml('Net'); ?>
<td><?= $this->getHtml('Date'); ?>
<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());
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $this->printHtml($invoice->getNumber()); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($invoice->type->getL11n()); ?></a>
<td><a class="content" href="<?= UriFactory::build('{/prefix}sales/client/profile?{?}&id=' . $invoice->client->getId()); ?>"><?= $this->printHtml($invoice->billTo); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($invoice->net->getCurrency()); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($invoice->netSales->getCurrency()); ?></a>
<td><a href="<?= $url; ?>"><?= $this->printHtml($invoice->createdAt->format('Y-m-d')); ?></a>
<?php endforeach; ?>
</table>
@ -244,7 +243,7 @@ echo $this->getData('nav')->render();
<td><?= $this->getHtml('Country'); ?>
<td><?= $this->getHtml('Net'); ?>
<tbody>
<?php $i = -1; foreach ($topCustomers[0] as $client) : ++$i;
<?php $i = -1; foreach ($topCustomers as $client) : ++$i;
$url = UriFactory::build('{/prefix}sales/client/profile?id=' . $client->getId());
?>
<tr data-href="<?= $url; ?>">
@ -922,14 +921,16 @@ echo $this->getData('nav')->render();
<td><?= $this->getHtml('Net'); ?>
<td><?= $this->getHtml('Date'); ?>
<tbody>
<?php foreach ($allInvoices as $invoice) :
<?php
/** @var \Modules\Billing\Models\Bill $invoice */
foreach ($allInvoices as $invoice) :
$url = UriFactory::build('{/prefix}sales/bill?{?}&id=' . $invoice->getId());
?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><?= $invoice->getNumber(); ?></a>
<td><a href="<?= $url; ?>"><?= $invoice->type->getL11n(); ?></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>
<?php endforeach; ?>
</table>