Add supplier files

This commit is contained in:
Dennis Eichhorn 2020-12-19 20:26:08 +01:00
parent 63b8016d65
commit d99a251a16
7 changed files with 115 additions and 16 deletions

View File

@ -105,11 +105,6 @@
"null": false,
"foreignTable": "suppliermgmt_supplier",
"foreignKey": "suppliermgmt_supplier_id"
},
"suppliermgmt_supplier_media_type": {
"name": "suppliermgmt_supplier_media_type",
"type": "TINYINT",
"null": false
}
}
}

View File

@ -20,6 +20,7 @@ use Modules\Profile\Models\ContactElementMapper;
use Modules\Profile\Models\Profile;
use Modules\SupplierManagement\Models\Supplier;
use Modules\SupplierManagement\Models\SupplierMapper;
use Modules\Media\Models\PathSettings;
use phpOMS\Message\Http\RequestStatusCode;
use phpOMS\Message\NotificationLevel;
use phpOMS\Message\RequestAbstract;
@ -150,4 +151,50 @@ final class ApiController extends Controller
SupplierMapper::class, 'contactElements', '', $request->getOrigin());
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Contact Element', 'Contact element successfully created', $contactElement);
}
/**
* Api method to create item files
*
* @param RequestAbstract $request Request
* @param ResponseAbstract $response Response
* @param mixed $data Generic data
*
* @return void
*
* @api
*
* @since 1.0.0
*/
public function apiFileCreate(RequestAbstract $request, ResponseAbstract $response, $data = null) : void
{
$uploadedFiles = $request->getFiles() ?? [];
if (empty($uploadedFiles)) {
$this->fillJsonResponse($request, $response, NotificationLevel::ERROR, 'Item', 'Invalid supplier image', $uploadedFiles);
$response->header->status = RequestStatusCode::R_400;
return;
}
$uploaded = $this->app->moduleManager->get('Media')->uploadFiles(
$request->getData('name') ?? '',
$uploadedFiles,
$request->header->account,
'Modules/Media/Files/Modules/SupplierManagement/' . ($request->getData('supplier') ?? '0'),
'/Modules/SupplierManagement/' . ($request->getData('supplier') ?? '0'),
$request->getData('type') ?? '',
'',
'',
PathSettings::FILE_PATH
);
$this->createModelRelation(
$request->header->account,
(int) $request->getData('supplier'),
\reset($uploaded)->getId(),
SupplierMapper::class, 'files', '', $request->getOrigin()
);
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Image', 'Image successfully updated', $uploaded);
}
}

View File

@ -48,7 +48,7 @@ final class BackendController extends Controller
$view->setTemplate('/Modules/SupplierManagement/Theme/Backend/supplier-list');
$view->addData('nav', $this->app->moduleManager->get('Navigation')->createNavigationMid(1003202001, $request, $response));
$supplier = SupplierMapper::getAll();
$supplier = SupplierMapper::getAfterPivot(0, null, 25);
$view->addData('supplier', $supplier);
return $view;

View File

@ -293,4 +293,45 @@ class Supplier
{
$this->contactElements[] = $element;
}
/**
* Get media file by type
*
* @param string $type Media type
*
* @return Media
*
* @since 1.0.0
*/
public function getFileByType(string $type) : Media
{
foreach ($this->files as $file) {
if ($file->type === $type) {
return $file;
}
}
return new NullMedia();
}
/**
* Get all media files by type
*
* @param string $type Media type
*
* @return Media[]
*
* @since 1.0.0
*/
public function getFilesByType(string $type) : array
{
$files = [];
foreach ($this->files as $file) {
if ($file->type === $type) {
$files[] = $file;
}
}
return $files;
}
}

View File

@ -99,8 +99,8 @@ final class SupplierMapper extends DataMapperAbstract
'files' => [
'mapper' => MediaMapper::class, /* mapper of the related object */
'table' => 'suppliermgmt_supplier_media', /* table of the related object, null if no relation table is used (many->1) */
'external' => 'suppliermgmt_supplier_media_src',
'self' => 'suppliermgmt_supplier_media_dst',
'external' => 'suppliermgmt_supplier_media_dst',
'self' => 'suppliermgmt_supplier_media_src',
],
'contactElements' => [
'mapper' => ContactElementMapper::class,

View File

@ -23,23 +23,39 @@ echo $this->getData('nav')->render(); ?>
<div class="col-xs-12">
<section class="portlet">
<div class="portlet-head"><?= $this->getHtml('Suppliers'); ?><i class="fa fa-download floatRight download btn"></i></div>
<table class="default">
<table id="iPurchaseSupplierList" class="default">
<thead>
<tr>
<td>
<td><?= $this->getHtml('ID', '0', '0'); ?>
<td><?= $this->getHtml('Name1'); ?>
<td class="wf-100"><?= $this->getHtml('Name2'); ?>
<input id="clientList-r1-asc" name="supplierList-sort" type="radio"><label for="supplierList-r1-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="supplierList-r1-desc" name="supplierList-sort" type="radio"><label for="supplierList-r1-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td class="wf-100"><?= $this->getHtml('Name'); ?>
<input id="supplierList-r2-asc" name="supplierList-sort" type="radio"><label for="supplierList-r2-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="supplierList-r2-desc" name="supplierList-sort" type="radio"><label for="supplierList-r2-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('City'); ?>
<input id="supplierList-r5-asc" name="supplierList-sort" type="radio"><label for="supplierList-r5-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="supplierList-r5-desc" name="supplierList-sort" type="radio"><label for="supplierList-r5-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('Zip'); ?>
<input id="supplierList-r6-asc" name="supplierList-sort" type="radio"><label for="supplierList-r6-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="supplierList-r6-desc" name="supplierList-sort" type="radio"><label for="supplierList-r6-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('Address'); ?>
<input id="supplierList-r7-asc" name="supplierList-sort" type="radio"><label for="supplierList-r7-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="supplierList-r7-desc" name="supplierList-sort" type="radio"><label for="supplierList-r7-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<td><?= $this->getHtml('Country'); ?>
<input id="supplierList-r8-asc" name="supplierList-sort" type="radio"><label for="supplierList-r8-asc"><i class="sort-asc fa fa-chevron-up"></i></label>
<input id="supplierList-r8-desc" name="supplierList-sort" type="radio"><label for="supplierList-r8-desc"><i class="sort-desc fa fa-chevron-down"></i></label>
<tbody>
<?php $count = 0; foreach ($suppliers as $key => $value) : ++$count;
$url = UriFactory::build('{/prefix}purchase/supplier/profile?{?}&id=' . $value->getId()); ?>
$url = UriFactory::build('{/prefix}purchase/supplier/profile?{?}&id=' . $value->getId());
$image = $value->getFileByType('backend_image'); ?>
<tr data-href="<?= $url; ?>">
<td><a href="<?= $url; ?>"><img width="30" loading="lazy" class="item-image"
src="<?= $image instanceof NullMedia ?
UriFactory::build('Web/Backend/img/user_default_' . \mt_rand(1, 6) .'.png') :
UriFactory::build('{/prefix}' . $image->getPath()); ?>"></a>
<td data-label="<?= $this->getHtml('ID', '0', '0'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->number); ?></a>
<td data-label="<?= $this->getHtml('Name1'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->profile->account->name1); ?></a>
<td data-label="<?= $this->getHtml('Name2'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->profile->account->name2); ?></a>
<td data-label="<?= $this->getHtml('Name'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->profile->account->name1); ?> <?= $this->printHtml($value->profile->account->name2); ?></a>
<td data-label="<?= $this->getHtml('City'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->mainAddress->city); ?></a>
<td data-label="<?= $this->getHtml('Zip'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->mainAddress->postal); ?></a>
<td data-label="<?= $this->getHtml('Address'); ?>"><a href="<?= $url; ?>"><?= $this->printHtml($value->mainAddress->address); ?></a>

View File

@ -434,8 +434,8 @@ echo $this->getData('nav')->render();
<tbody>
<tr>
<td><?= $this->printHtml($this->request->getOrigin()); ?>
<td><?= $this->printHtml($this->request->header->account); ?>
<td><?= $this->printHtml($this->request->header->account); ?>
<td><?= $this->printHtml((string) $this->request->header->account); ?>
<td><?= $this->printHtml((string) $this->request->header->account); ?>
<td>Creating customer
<td><?= $this->printHtml((new \DateTime('now'))->format('Y-m-d H:i:s')); ?>
</table>