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 = [];
$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']); ItemAttributeTypeMapper::create()->execute($itemAttrType['color']);
ItemAttributeTypeL11nMapper::create()->execute(new ItemAttributeTypeL11n($itemAttrType['color']->getId(), 'Color', ISO639x1Enum::_EN)); ItemAttributeTypeL11nMapper::create()->execute(new ItemAttributeTypeL11n($itemAttrType['color']->getId(), 'Color', ISO639x1Enum::_EN));
ItemAttributeTypeL11nMapper::create()->execute(new ItemAttributeTypeL11n($itemAttrType['color']->getId(), 'Farbe', ISO639x1Enum::_DE)); 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 Model\SettingsEnum;
use Modules\Admin\Models\LocalizationMapper; use Modules\Admin\Models\LocalizationMapper;
use Modules\Billing\Models\BillTypeL11n; use Modules\Billing\Models\BillTransferType;
use Modules\Billing\Models\SalesBillMapper; use Modules\Billing\Models\SalesBillMapper;
use Modules\ItemManagement\Models\ItemAttributeMapper;
use Modules\ItemManagement\Models\ItemAttributeTypeMapper; use Modules\ItemManagement\Models\ItemAttributeTypeMapper;
use Modules\ItemManagement\Models\ItemAttributeValueMapper; use Modules\ItemManagement\Models\ItemAttributeValueMapper;
use Modules\ItemManagement\Models\ItemL11nMapper;
use Modules\ItemManagement\Models\ItemL11nType;
use Modules\ItemManagement\Models\ItemMapper; use Modules\ItemManagement\Models\ItemMapper;
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;
@ -64,8 +61,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-type-list'); $view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-type-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attributes = ItemAttributeTypeMapper::with('language', $response->getLanguage()) $attributes = ItemAttributeTypeMapper::getAll()->with('l11n')->where('l11n/language', $response->getLanguage())->execute();
::getAll();
$view->addData('attributes', $attributes); $view->addData('attributes', $attributes);
@ -90,8 +86,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-value-list'); $view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-value-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attributes = ItemAttributeValueMapper::with('language', $response->getLanguage()) $attributes = ItemAttributeValueMapper::getAll()->with('l11n')->where('l11n/language', $response->getLanguage())->execute();
::getAll();
$view->addData('attributes', $attributes); $view->addData('attributes', $attributes);
@ -116,8 +111,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-type'); $view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-type');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attribute = ItemAttributeTypeMapper::with('language', $response->getLanguage()) $attribute = ItemAttributeTypeMapper::get()->with('l11n')->where('id', (int) $request->getData('id'))->where('l11n/language', $response->getLanguage())->execute();
::get((int) $request->getData('id'));
$view->addData('attribute', $attribute); $view->addData('attribute', $attribute);
@ -142,8 +136,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-value'); $view->setTemplate('/Modules/ItemManagement/Theme/Backend/attribute-value');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004801001, $request, $response));
$attribute = ItemAttributeValueMapper::with('language', $response->getLanguage()) $attribute = ItemAttributeValueMapper::get()->with('l11n')->where('id', (int) $request->getData('id'))->where('l11n/language', $response->getLanguage())->execute();
::get((int) $request->getData('id'));
$view->addData('attribute', $attribute); $view->addData('attribute', $attribute);
@ -172,19 +165,10 @@ final class BackendController extends Controller
->with('l11n') ->with('l11n')
->with('l11n/type') ->with('l11n/type')
->where('l11n/language', $response->getLanguage()) ->where('l11n/language', $response->getLanguage())
->where('l11n/type', ['name1', 'name2', 'name3'], 'IN') ->where('l11n/type/title', ['name1', 'name2', 'name3'], 'IN')
->limit(25) ->limit(25)
->execute(); ->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); $view->addData('items', $items);
return $view; return $view;
@ -208,7 +192,14 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/purchase-item-list'); $view->setTemplate('/Modules/ItemManagement/Theme/Backend/purchase-item-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004806001, $request, $response)); $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); $view->addData('items', $items);
return $view; return $view;
@ -324,25 +315,25 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/ItemManagement/Theme/Backend/sales-item-profile'); $view->setTemplate('/Modules/ItemManagement/Theme/Backend/sales-item-profile');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004805001, $request, $response)); $view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1004805001, $request, $response));
$item = ItemMapper::with('language', $response->getLanguage()) $item = ItemMapper::get()
::with('files', limit: 5)::orderBy('createdAt', 'ASC') ->with('l11n')
::with('notes', limit: 5)::orderBy('id', 'ASC') ->with('l11n/type')
::get((int) $request->getData('id')); ->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); $view->addData('item', $item);
$settings = $this->app->appSettings->get(null, [ $settings = $this->app->appSettings->get(null, [
SettingsEnum::DEFAULT_LOCALIZATION, SettingsEnum::DEFAULT_LOCALIZATION,
]); ]);
$view->setData('defaultlocalization', LocalizationMapper::get()->where('id', (int) $settings['id']))->execute(); $view->setData('defaultlocalization', LocalizationMapper::get()->where('id', (int) $settings->getId())->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);
// stats // stats
if ($this->app->moduleManager->isActive('Billing')) { 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')); $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')); $avg = SalesBillMapper::getAvgSalesPriceByItemId($item->getId(), (new SmartDateTime('now'))->smartModify(-1), new SmartDateTime('now'));
$lastOrder = SalesBillMapper::getLastOrderDateByItemId($item->getId()); $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::getAll()
$newestInvoices = SalesBillMapper::with('language', $response->getLanguage(), [BillTypeL11n::class])::getNewestItemInvoices($item->getId(), 5); ->with('type')
$topCustomers = SalesBillMapper::getItemTopCustomers($item->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'), 5); ->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')); $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')); $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); $countrySales = SalesBillMapper::getItemCountrySales($item->getId(), new SmartDateTime('Y-01-01'), new SmartDateTime('now'), 5);

View File

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

View File

@ -38,10 +38,10 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
/** /**
* Item ID. * Item ID.
* *
* @var ItemAttributeType * @var int
* @since 1.0.0 * @since 1.0.0
*/ */
public ItemAttributeType $type; public int $type;
/** /**
* Language. * Language.
@ -62,15 +62,15 @@ class ItemAttributeTypeL11n implements \JsonSerializable, ArrayableInterface
/** /**
* Constructor. * Constructor.
* *
* @param ItemAttributeType $type Attribute type * @param int $type Attribute type
* @param string $title Localized title * @param string $title Localized title
* @param string $language Language * @param string $language Language
* *
* @since 1.0.0 * @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->title = $title;
$this->language = $language; $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'], 'itemmgmt_item_purchaseprice' => ['name' => 'itemmgmt_item_purchaseprice', 'type' => 'Serializable', 'internal' => 'purchasePrice'],
]; ];
protected static array $conditionals = [
];
/** /**
* Primary table. * Primary table.
* *

View File

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