mirror of
https://github.com/Karaka-Management/oms-SupplierManagement.git
synced 2026-01-10 17:08:41 +00:00
update
This commit is contained in:
parent
6139d8d336
commit
c2ee6165ed
43
Admin/Install/Search.php
Normal file
43
Admin/Install/Search.php
Normal file
|
|
@ -0,0 +1,43 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Jingga
|
||||||
|
*
|
||||||
|
* PHP Version 8.1
|
||||||
|
*
|
||||||
|
* @package Modules\SupplierManagement\Admin\Install
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\SupplierManagement\Admin\Install;
|
||||||
|
|
||||||
|
use phpOMS\Application\ApplicationAbstract;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search class.
|
||||||
|
*
|
||||||
|
* @package Modules\SupplierManagement\Admin\Install
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
final class Search
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Install navigation providing
|
||||||
|
*
|
||||||
|
* @param ApplicationAbstract $app Application
|
||||||
|
* @param string $path Module path
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function install(ApplicationAbstract $app, string $path) : void
|
||||||
|
{
|
||||||
|
\Modules\Search\Admin\Installer::installExternal($app, ['path' => __DIR__ . '/SearchCommands.php']);
|
||||||
|
}
|
||||||
|
}
|
||||||
32
Admin/Install/SearchCommands.php
Normal file
32
Admin/Install/SearchCommands.php
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Jingga
|
||||||
|
*
|
||||||
|
* PHP Version 8.1
|
||||||
|
*
|
||||||
|
* @package Modules\SupplierManagement
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use Modules\SupplierManagement\Controller\SearchController;
|
||||||
|
use Modules\SupplierManagement\Models\PermissionCategory;
|
||||||
|
use phpOMS\Account\PermissionType;
|
||||||
|
use phpOMS\Router\RouteVerb;
|
||||||
|
|
||||||
|
return [
|
||||||
|
'^(?!:).+.*?' => [
|
||||||
|
[
|
||||||
|
'dest' => '\Modules\SupplierManagement\Controller\SearchController:searchGeneral',
|
||||||
|
'verb' => RouteVerb::ANY,
|
||||||
|
'permission' => [
|
||||||
|
'module' => SearchController::NAME,
|
||||||
|
'type' => PermissionType::READ,
|
||||||
|
'state' => PermissionCategory::SUPPLIER,
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
"de": "Bewertung"
|
"de": "Bewertung"
|
||||||
},
|
},
|
||||||
"value_type": 2,
|
"value_type": 2,
|
||||||
"is_custom_allowed": true,
|
"is_custom_allowed": false,
|
||||||
"validation_pattern": "",
|
"validation_pattern": "",
|
||||||
"is_required": false,
|
"is_required": false,
|
||||||
"default_value": "",
|
"default_value": "",
|
||||||
|
|
@ -55,6 +55,89 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "supplier_area",
|
||||||
|
"l11n": {
|
||||||
|
"en": "Supplier area",
|
||||||
|
"de": "Lieferantenebiet"
|
||||||
|
},
|
||||||
|
"value_type": 2,
|
||||||
|
"is_custom_allowed": false,
|
||||||
|
"validation_pattern": "",
|
||||||
|
"is_required": false,
|
||||||
|
"default_value": "01",
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"value": "01"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "bill_emails",
|
||||||
|
"l11n": {
|
||||||
|
"en": "Send bills as emails",
|
||||||
|
"de": "Sende Rechnungen als Email"
|
||||||
|
},
|
||||||
|
"value_type": 5,
|
||||||
|
"is_custom_allowed": false,
|
||||||
|
"validation_pattern": "",
|
||||||
|
"is_required": false,
|
||||||
|
"default_value": true,
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "bill_email_address",
|
||||||
|
"l11n": {
|
||||||
|
"en": "Email address for billing",
|
||||||
|
"de": "Emailadresse für Rechnungen"
|
||||||
|
},
|
||||||
|
"value_type": 2,
|
||||||
|
"is_custom_allowed": true,
|
||||||
|
"validation_pattern": "",
|
||||||
|
"is_required": false,
|
||||||
|
"default_value": "",
|
||||||
|
"values": []
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "support_emails",
|
||||||
|
"l11n": {
|
||||||
|
"en": "Send ticket as emails",
|
||||||
|
"de": "Sende Ticket als Email"
|
||||||
|
},
|
||||||
|
"value_type": 5,
|
||||||
|
"is_custom_allowed": false,
|
||||||
|
"validation_pattern": "",
|
||||||
|
"is_required": false,
|
||||||
|
"default_value": 1,
|
||||||
|
"values": [
|
||||||
|
{
|
||||||
|
"value": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"value": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "support_email_address",
|
||||||
|
"l11n": {
|
||||||
|
"en": "Email address for tickets",
|
||||||
|
"de": "Emailadresse für Tickets"
|
||||||
|
},
|
||||||
|
"value_type": 2,
|
||||||
|
"is_custom_allowed": true,
|
||||||
|
"validation_pattern": "",
|
||||||
|
"is_required": false,
|
||||||
|
"default_value": "",
|
||||||
|
"values": []
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "segment",
|
"name": "segment",
|
||||||
"l11n": {
|
"l11n": {
|
||||||
|
|
|
||||||
|
|
@ -323,7 +323,7 @@ final class ApiController extends Controller
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
|
$uploaded = $this->app->moduleManager->get('Media', 'Api')->uploadFiles(
|
||||||
names: $request->getDataList('names'),
|
names: $request->getDataList('names'),
|
||||||
fileNames: $request->getDataList('filenames'),
|
fileNames: $request->getDataList('filenames'),
|
||||||
files: $uploadedFiles,
|
files: $uploadedFiles,
|
||||||
|
|
|
||||||
|
|
@ -224,10 +224,8 @@ final class BackendController extends Controller
|
||||||
$view->data['supplier'] = $supplier;
|
$view->data['supplier'] = $supplier;
|
||||||
|
|
||||||
// Get item profile image
|
// Get item profile image
|
||||||
// It might not be part of the 5 newest item files from above
|
// @feature Create a new read mapper function that returns relation models instead of its own model
|
||||||
// @todo It would be nice to have something like this as a default method in the model e.g.
|
// https://github.com/Karaka-Management/phpOMS/issues/320
|
||||||
// ItemManagement::getRelations()->with('types')->where(...);
|
|
||||||
// This should return the relations and NOT the model itself
|
|
||||||
$query = new Builder($this->app->dbPool->get());
|
$query = new Builder($this->app->dbPool->get());
|
||||||
$results = $query->selectAs(SupplierMapper::HAS_MANY['files']['external'], 'file')
|
$results = $query->selectAs(SupplierMapper::HAS_MANY['files']['external'], 'file')
|
||||||
->from(SupplierMapper::TABLE)
|
->from(SupplierMapper::TABLE)
|
||||||
|
|
@ -243,7 +241,6 @@ final class BackendController extends Controller
|
||||||
->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'supplier_profile_image');
|
->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'supplier_profile_image');
|
||||||
|
|
||||||
$clientImage = MediaMapper::get()
|
$clientImage = MediaMapper::get()
|
||||||
->with('types')
|
|
||||||
->where('id', $results)
|
->where('id', $results)
|
||||||
->limit(1)
|
->limit(1)
|
||||||
->execute();
|
->execute();
|
||||||
|
|
|
||||||
112
Controller/SearchController.php
Normal file
112
Controller/SearchController.php
Normal file
|
|
@ -0,0 +1,112 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Jingga
|
||||||
|
*
|
||||||
|
* PHP Version 8.1
|
||||||
|
*
|
||||||
|
* @package Modules\SupplierManagement
|
||||||
|
* @copyright Dennis Eichhorn
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @version 1.0.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
*/
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Modules\SupplierManagement\Controller;
|
||||||
|
|
||||||
|
use Modules\Admin\Models\ContactType;
|
||||||
|
use Modules\Media\Models\MediaMapper;
|
||||||
|
use Modules\Media\Models\MediaTypeMapper;
|
||||||
|
use Modules\SupplierManagement\Models\SupplierMapper;
|
||||||
|
use phpOMS\DataStorage\Database\Query\Builder;
|
||||||
|
use phpOMS\Message\RequestAbstract;
|
||||||
|
use phpOMS\Message\ResponseAbstract;
|
||||||
|
use phpOMS\System\MimeType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Search class.
|
||||||
|
*
|
||||||
|
* @package Modules\SupplierManagement
|
||||||
|
* @license OMS License 2.0
|
||||||
|
* @link https://jingga.app
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
final class SearchController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Api method to search for tags
|
||||||
|
*
|
||||||
|
* @param RequestAbstract $request Request
|
||||||
|
* @param ResponseAbstract $response Response
|
||||||
|
* @param array $data Generic data
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function searchGeneral(RequestAbstract $request, ResponseAbstract $response, array $data = []) : void
|
||||||
|
{
|
||||||
|
$names = \explode(' ', ($request->getDataString('search') ?? ''));
|
||||||
|
$names[] = ($request->getDataString('search') ?? '');
|
||||||
|
|
||||||
|
$mapper = SupplierMapper::getAll()
|
||||||
|
->with('account')
|
||||||
|
->with('mainAddress')
|
||||||
|
->with('account/contacts')
|
||||||
|
->limit(8);
|
||||||
|
|
||||||
|
foreach ($names as $name) {
|
||||||
|
$mapper->where('account/login', '%' . $name . '%', 'LIKE', 'OR')
|
||||||
|
->where('account/name1', '%' . $name . '%', 'LIKE', 'OR')
|
||||||
|
->where('account/name2', '%' . $name . '%', 'LIKE', 'OR')
|
||||||
|
->where('account/name3', '%' . $name . '%', 'LIKE', 'OR');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \Modules\SupplierManagement\Models\Supplier[] $accounts */
|
||||||
|
$accounts = $mapper->execute();
|
||||||
|
|
||||||
|
$results = [];
|
||||||
|
foreach ($accounts as $account) {
|
||||||
|
// Get item profile image
|
||||||
|
// @feature Create a new read mapper function that returns relation models instead of its own model
|
||||||
|
// https://github.com/Karaka-Management/phpOMS/issues/320
|
||||||
|
$query = new Builder($this->app->dbPool->get());
|
||||||
|
$iResults = $query->selectAs(SupplierMapper::HAS_MANY['files']['external'], 'file')
|
||||||
|
->from(SupplierMapper::TABLE)
|
||||||
|
->leftJoin(SupplierMapper::HAS_MANY['files']['table'])
|
||||||
|
->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::HAS_MANY['files']['self'], '=', SupplierMapper::TABLE . '.' . SupplierMapper::PRIMARYFIELD)
|
||||||
|
->leftJoin(MediaMapper::TABLE)
|
||||||
|
->on(SupplierMapper::HAS_MANY['files']['table'] . '.' . SupplierMapper::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(SupplierMapper::HAS_MANY['files']['self'], '=', $account->id)
|
||||||
|
->where(MediaTypeMapper::TABLE . '.' . MediaTypeMapper::getColumnByMember('name'), '=', 'supplier_profile_image');
|
||||||
|
|
||||||
|
$image = MediaMapper::get()
|
||||||
|
->where('id', $iResults)
|
||||||
|
->limit(1)
|
||||||
|
->execute();
|
||||||
|
|
||||||
|
$results[] = [
|
||||||
|
'title' => $account->account->name1 . ' ' . $account->account->name2,
|
||||||
|
'link' => '{/base}/purchase/supplier/view?id=' . $account->id,
|
||||||
|
'email' => $account->account->getContactByType(ContactType::EMAIL)->content,
|
||||||
|
'phone' => $account->account->getContactByType(ContactType::PHONE)->content,
|
||||||
|
'city' => $account->mainAddress?->city,
|
||||||
|
'image' => $image->id === 0
|
||||||
|
? 'Web/Backend/img/logo_grey.png'
|
||||||
|
: $image->getPath(),
|
||||||
|
'tags' => [],
|
||||||
|
'type' => 'list_accounts',
|
||||||
|
'module' => 'Supplier Management',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
$response->header->set('Content-Type', MimeType::M_JSON . '; charset=utf-8', true);
|
||||||
|
$response->add($request->uri->__toString(), $results);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user