| route_name: arlista.manufacturer.list | route_name: arlista.manufacturer.list | ||||
| weight: 10 | weight: 10 | ||||
| menu_name: main | menu_name: main | ||||
| arlista.category.list: | |||||
| title: "Termékcsoportok" | |||||
| description: "Termékcsoportok szerkesztése" | |||||
| parent: main | |||||
| route_name: arlista.category.list | |||||
| weight: 30 | |||||
| menu_name: main | |||||
| arlista.component.list: | arlista.component.list: | ||||
| title: "Komponensek" | title: "Komponensek" | ||||
| description: "Komponensek szerkesztése" | description: "Komponensek szerkesztése" | ||||
| weight: 20 | weight: 20 | ||||
| menu_name: main | menu_name: main | ||||
| route_parameters: { mid: '0' } | route_parameters: { mid: '0' } | ||||
| arlista.category.list: | |||||
| title: "Termékcsoportok" | |||||
| description: "Termékcsoportok szerkesztése" | |||||
| parent: main | |||||
| route_name: arlista.category.list | |||||
| weight: 30 | |||||
| menu_name: main | |||||
| arlista.warranty.list: | arlista.warranty.list: | ||||
| title: "Garanciák" | title: "Garanciák" | ||||
| description: "Garanciák listája" | description: "Garanciák listája" | ||||
| parent: main | parent: main | ||||
| route_name: arlista.warranty.list | route_name: arlista.warranty.list | ||||
| weight: 25 | |||||
| weight: 35 | |||||
| menu_name: main | menu_name: main | ||||
| route_parameters: { filterx: 'mind' } | route_parameters: { filterx: 'mind' } | ||||
| arlista.file.list: | arlista.file.list: |
| 'manufacturers' => null, | 'manufacturers' => null, | ||||
| 'sheetSettings' => null, | 'sheetSettings' => null, | ||||
| 'listed' => null, | 'listed' => null, | ||||
| 'icons' => null, | |||||
| ], | ], | ||||
| 'template' => 'arlista-file-list', | 'template' => 'arlista-file-list', | ||||
| 'render element' => 'form', | 'render element' => 'form', |
| defaults: | defaults: | ||||
| _controller: '\Drupal\arlista\Controller\ComponentController::updateProductComponent' | _controller: '\Drupal\arlista\Controller\ComponentController::updateProductComponent' | ||||
| _title: "Komponens update" | _title: "Komponens update" | ||||
| requirements: | |||||
| _permission: "arlista manage_pricelists" | |||||
| _disable_route_normalizer: "TRUE" | |||||
| arlista.warranty.category.manufacturer.fetch: | |||||
| path: "warranty/category/manufacturer/fetch" | |||||
| defaults: | |||||
| _controller: '\Drupal\arlista\Controller\CategoryController::getAxicoIdwarranty' | |||||
| _title: "Fetch warranty for category and manufacturer" | |||||
| requirements: | requirements: | ||||
| _permission: "arlista manage_pricelists" | _permission: "arlista manage_pricelists" | ||||
| _disable_route_normalizer: "TRUE" | _disable_route_normalizer: "TRUE" |
| .arlista-green { | .arlista-green { | ||||
| color: green; | color: green; | ||||
| padding: 0.2rem 0rem; | |||||
| } | } | ||||
| .price-changed { | .price-changed { | ||||
| margin-top: 5rem; | margin-top: 5rem; | ||||
| } | } | ||||
| form.arlista-manufacturer-edit-form > a { | |||||
| form.arlista-manufacturer-edit-form > a, form > a.edit-link { | |||||
| display: block; | display: block; | ||||
| margin-bottom: 1rem; | margin-bottom: 1rem; | ||||
| } | } | ||||
| display: block; | display: block; | ||||
| margin-top: 0.5rem; | margin-top: 0.5rem; | ||||
| } | } | ||||
| tr.correct-files-uploaded-file.row-for-hiding { | |||||
| display: none; | |||||
| } | |||||
| span.hide-roller { | |||||
| display: none; | |||||
| } |
| } | } | ||||
| }); | }); | ||||
| /* | |||||
| * # Show/Hide uploaded files | |||||
| */ | |||||
| $(".show-roller").on("click",function () { | |||||
| $('.hide-roller').css('display', 'block'); | |||||
| $('.show-roller').css('display', 'none'); | |||||
| $('tr.correct-files-uploaded-file.row-for-hiding').show(); | |||||
| }); | |||||
| /* | |||||
| * # Show/Hide uploaded files | |||||
| */ | |||||
| $(".hide-roller").on("click",function () { | |||||
| $('.show-roller').css('display', 'block'); | |||||
| $('.hide-roller').css('display', 'none'); | |||||
| $('tr.correct-files-uploaded-file.row-for-hiding').hide(); | |||||
| }); | |||||
| /* | /* | ||||
| * # delete uploaded file | * # delete uploaded file | ||||
| */ | */ | ||||
| /* | /* | ||||
| * # Update listed products category on select change | * # Update listed products category on select change | ||||
| */ | */ | ||||
| $(".product-list-category-select").change(function (e) { | |||||
| $(".product-list-category-select").on("change", function (e) { | |||||
| e.preventDefault(); | e.preventDefault(); | ||||
| let selected = $(this); | let selected = $(this); | ||||
| let cid = selected.val(); | let cid = selected.val(); | ||||
| }); | }); | ||||
| }); | }); | ||||
| /* | |||||
| * # Update selected categories warranty on manufacturer select change | |||||
| */ | |||||
| $("#parent_manufacturer_id_select_warranty").on("change", function (e) { | |||||
| e.preventDefault(); | |||||
| let url = document.URL; | |||||
| let cid = $('form').find('*').filter(':input[name=cid]').attr('value'); | |||||
| let selected = $(this); | |||||
| if (selected.prop('disabled')) { | |||||
| return; | |||||
| } | |||||
| let mid = selected.val(); | |||||
| if(mid < 1){ | |||||
| return; | |||||
| } | |||||
| selected.prop('disabled', true); | |||||
| let package = { | |||||
| cid: cid, | |||||
| mid: mid, | |||||
| }; | |||||
| let fullPath = drupalSettings.arlista.host; | |||||
| let arr = fullPath.split("/"); | |||||
| url = arr[0] + "warranty/category/manufacturer/fetch"; | |||||
| $('html,body').css('cursor', 'wait'); | |||||
| $.ajax({ | |||||
| url: url, | |||||
| method: "POST", | |||||
| data: package, | |||||
| success: function (data, status, xhr) { | |||||
| $('html,body').css('cursor', 'initial'); | |||||
| selected.prop('disabled', false); | |||||
| console.log(data); | |||||
| $('#edit-axico-id-warranty-length').val(data.data) | |||||
| return; | |||||
| }, | |||||
| error: function (request, ajaxOptions, thrownError) { | |||||
| $('html,body').css('cursor', 'initial'); | |||||
| alert(request.status); | |||||
| alert(thrownError); | |||||
| } | |||||
| }); | |||||
| }); | |||||
| /* | /* | ||||
| * # Update listed products component on select change | * # Update listed products component on select change | ||||
| */ | */ | ||||
| success: function (data, status, xhr) { | success: function (data, status, xhr) { | ||||
| console.log(data); | console.log(data); | ||||
| $('html,body').css('cursor', 'initial'); | $('html,body').css('cursor', 'initial'); | ||||
| if(!data.success){ | |||||
| if(!data.success && redirect){ | |||||
| alert(data.message); | alert(data.message); | ||||
| const myTimeout = setTimeout(window.location.replace(document.URL), 5000); | const myTimeout = setTimeout(window.location.replace(document.URL), 5000); | ||||
| clearTimeout(myTimeout); | clearTimeout(myTimeout); |
| use Drupal\Core\Controller\ControllerBase; | use Drupal\Core\Controller\ControllerBase; | ||||
| use Drupal\arlista\Service\CacheService; | use Drupal\arlista\Service\CacheService; | ||||
| use Drupal\arlista\Factory\AxicoIdWarrantyFactory; | |||||
| use Drupal\arlista\Factory\CategoryFactory; | use Drupal\arlista\Factory\CategoryFactory; | ||||
| use Symfony\Component\DependencyInjection\ContainerInterface; | use Symfony\Component\DependencyInjection\ContainerInterface; | ||||
| use Drupal\arlista\Factory\FileFactory; | use Drupal\arlista\Factory\FileFactory; | ||||
| abstract class ArlistaAbstractController extends ControllerBase { | abstract class ArlistaAbstractController extends ControllerBase { | ||||
| private $axicoIdWarrantyFactory; | |||||
| private $categoryFactory; | private $categoryFactory; | ||||
| private $fileFactory; | private $fileFactory; | ||||
| private $manufacturerFactory; | private $manufacturerFactory; | ||||
| FileFactory $fileFactory, ManufacturerFactory $manufacturerFactory, | FileFactory $fileFactory, ManufacturerFactory $manufacturerFactory, | ||||
| SheetSettingFactory $SheetSettingFactory, CacheService $cacheService, | SheetSettingFactory $SheetSettingFactory, CacheService $cacheService, | ||||
| SpreadSheetFactory $spreadSheetFactory, ProductFactory $productFactory, | SpreadSheetFactory $spreadSheetFactory, ProductFactory $productFactory, | ||||
| CalculationFactory $calculationFactory) { | |||||
| CalculationFactory $calculationFactory, AxicoIdWarrantyFactory $axicoIdWarrantyFactory) { | |||||
| $this->categoryFactory = $categoryFactory; | $this->categoryFactory = $categoryFactory; | ||||
| $this->fileFactory = $fileFactory; | $this->fileFactory = $fileFactory; | ||||
| $this->manufacturerFactory = $manufacturerFactory; | $this->manufacturerFactory = $manufacturerFactory; | ||||
| $this->spreadSheetFactory = $spreadSheetFactory; | $this->spreadSheetFactory = $spreadSheetFactory; | ||||
| $this->productFactory = $productFactory; | $this->productFactory = $productFactory; | ||||
| $this->calculationFactory = $calculationFactory; | $this->calculationFactory = $calculationFactory; | ||||
| $this->axicoIdWarrantyFactory = $axicoIdWarrantyFactory; | |||||
| $this->response = new JsonResponse(); | $this->response = new JsonResponse(); | ||||
| $this->response->headers->set('Content-Type', 'application/json'); | $this->response->headers->set('Content-Type', 'application/json'); | ||||
| $this->responseBody = new ResponseBody(); | $this->responseBody = new ResponseBody(); | ||||
| $container->get('arlista.spread-sheet.factory'), | $container->get('arlista.spread-sheet.factory'), | ||||
| $container->get('arlista.product.factory'), | $container->get('arlista.product.factory'), | ||||
| $container->get('arlista.calculation.factory'), | $container->get('arlista.calculation.factory'), | ||||
| $container->get('arlista.warranty.factory'), | |||||
| ); | ); | ||||
| } | } | ||||
| public function getAxicoIdWarrantyFactory(): AxicoIdWarrantyFactory { | |||||
| return $this->axicoIdWarrantyFactory; | |||||
| } | |||||
| public function getCategoryFactory(): CategoryFactory { | public function getCategoryFactory(): CategoryFactory { | ||||
| return $this->categoryFactory; | return $this->categoryFactory; | ||||
| } | } |
| if (!$result['status']) { | if (!$result['status']) { | ||||
| $this->getResponseBody()->setMessage('Sikertelen termékcsoport frissítés'); | $this->getResponseBody()->setMessage('Sikertelen termékcsoport frissítés'); | ||||
| $this->getResponseBody()->setSuccess(0); | |||||
| $this->getResponseBody()->setData($result); | $this->getResponseBody()->setData($result); | ||||
| $this->getResponse()->setData($this->getResponseBody()->toArray()); | $this->getResponse()->setData($this->getResponseBody()->toArray()); | ||||
| return $this->getResponse(); | return $this->getResponse(); | ||||
| } | } | ||||
| unset($result['products'], $result['manufacturer'], $result['revokedProducts']); | unset($result['products'], $result['manufacturer'], $result['revokedProducts']); | ||||
| $this->getResponseBody()->setSuccess(1); | |||||
| $this->getResponseBody()->setMessage('Sikeres frissítés'); | $this->getResponseBody()->setMessage('Sikeres frissítés'); | ||||
| $this->getResponseBody()->setData($result); | $this->getResponseBody()->setData($result); | ||||
| $this->getResponse()->setData($this->getResponseBody()->toArray()); | $this->getResponse()->setData($this->getResponseBody()->toArray()); | ||||
| return $this->getResponse(); | return $this->getResponse(); | ||||
| } | } | ||||
| public function getAxicoIdwarranty(Request $request) { | |||||
| $mid = $request->request->get('mid'); | |||||
| $cid = $request->request->get('cid'); | |||||
| $category = $this->getCategoryFactory()->find($cid); | |||||
| $manufacturer = $this->getManufacturerFactory()->find($mid); | |||||
| $axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->findByAxicoIdName($manufacturer->getAxicoIdName() . $category->getAxicoIdName()); | |||||
| $this->getResponseBody()->setSuccess(1); | |||||
| $this->getResponseBody()->setMessage('Sikeres találat'); | |||||
| $this->getResponseBody()->setData($axicoIdWarranty->getDefaultWarranty()); | |||||
| $this->getResponse()->setData($this->getResponseBody()->toArray()); | |||||
| return $this->getResponse(); | |||||
| } | |||||
| } | } |
| return $result; | return $result; | ||||
| } | } | ||||
| public function findHighestSimilarCategoryWarranty($axicoIdName){ | |||||
| $result = $this->findAllLike($axicoIdName); | |||||
| $highest = 0; | |||||
| foreach($result as $axicoIdWarranty){ | |||||
| $string = substr($axicoIdWarranty->getAxicoIdName(),3,3); | |||||
| if($string == $axicoIdName){ | |||||
| $highest = $axicoIdWarranty->getDefaultWarranty() > $highest ? $axicoIdWarranty->getDefaultWarranty() : $highest; | |||||
| } | |||||
| } | |||||
| return $highest; | |||||
| } | |||||
| public function updateForManufacturer($manufacturerAxicoIdName, $categoryAxicoIdName, $warranty){ | |||||
| $axicoIdName = $manufacturerAxicoIdName . $categoryAxicoIdName; | |||||
| $axicoIdWarranty = $this->findByAxicoIdName($axicoIdName); | |||||
| $axicoIdWarranty->setDefaultWarranty($warranty); | |||||
| $this->save($axicoIdWarranty); | |||||
| } | |||||
| public function updateForAllManufacturers($categoryAxicoIdName, $warranty){ | |||||
| $result = $this->findAllLike($categoryAxicoIdName); | |||||
| $highest = 0; | |||||
| foreach($result as $axicoIdWarranty){ | |||||
| $string = substr($axicoIdWarranty->getAxicoIdName(),3,3); | |||||
| if($string == $categoryAxicoIdName){ | |||||
| $axicoIdWarranty->setDefaultWarranty($warranty); | |||||
| $this->update($axicoIdWarranty); | |||||
| $highest++; | |||||
| } | |||||
| } | |||||
| return $highest; | |||||
| } | |||||
| } | } |
| \Drupal::messenger()->addStatus('Nincsenek adatok. Konfigurálja az alapértelmezett garancia értéket a beállítások menüpontban! Ha ezt megtette, importálhatja/frissítheti a cikkszámtörzsadatokat.'); | \Drupal::messenger()->addStatus('Nincsenek adatok. Konfigurálja az alapértelmezett garancia értéket a beállítások menüpontban! Ha ezt megtette, importálhatja/frissítheti a cikkszámtörzsadatokat.'); | ||||
| } | } | ||||
| if ($data = $this->getCacheService()->getCachedDataByName([$this->getFormId(), $filterx])) { | |||||
| if ($filterx == 'mind' && $data = $this->getCacheService()->getCachedDataByName([$this->getFormId(), 'mind'])) { | |||||
| return $data; | return $data; | ||||
| } | } | ||||
| return; | return; | ||||
| } | } | ||||
| $data = $this->getAxicoIdFactory()->findAllDistinct(); | $data = $this->getAxicoIdFactory()->findAllDistinct(); | ||||
| $result = $this->getAxicoIdWarrantyFactory()->updateDatabase($data); | $result = $this->getAxicoIdWarrantyFactory()->updateDatabase($data); | ||||
| \Drupal::messenger()->addStatus('Egyedi cikkszámtörzsek száma ' . count($data) . '. Új Axico Cikkszámtörzs Garancia entitások száma ('. count($result['axicoIdWarrantyList']['inserted']) .')'); | \Drupal::messenger()->addStatus('Egyedi cikkszámtörzsek száma ' . count($data) . '. Új Axico Cikkszámtörzs Garancia entitások száma ('. count($result['axicoIdWarrantyList']['inserted']) .')'); | ||||
| $this->getCacheService()->resetCache([$this->getFormId(), 1]); | |||||
| $this->getCacheService()->resetCache([$this->getFormId(), 'mind']); | |||||
| } | } | ||||
| } | } |
| public function buildForm(array $form, FormStateInterface $form_state) { | public function buildForm(array $form, FormStateInterface $form_state) { | ||||
| $cid = $this->getQueryValue('cid'); | $cid = $this->getQueryValue('cid'); | ||||
| $category = empty($cid) ? $this->getCategoryFactory()->create() : $this->getCategoryFactory()->find($cid); | $category = empty($cid) ? $this->getCategoryFactory()->create() : $this->getCategoryFactory()->find($cid); | ||||
| if (!$category->isNew()) { | |||||
| if ($data = $this->getCacheService()->getCachedDataByName([$this->getFormId(), $category->getId()])) { | |||||
| return $data; | |||||
| } | |||||
| } | |||||
| $form['#prefix'] ='<div class="col-lg-6">'; | |||||
| $form['#prefix'] ='<div class="col-lg-4">'; | |||||
| $form['items_wrapper']['cid'] = [ | $form['items_wrapper']['cid'] = [ | ||||
| '#type' => 'hidden', | '#type' => 'hidden', | ||||
| '#value' => $cid | '#value' => $cid | ||||
| $form['items_wrapper']['axico_id_name'] = [ | $form['items_wrapper']['axico_id_name'] = [ | ||||
| '#title' => 'Termékcsoport Axico cikkszáma', | '#title' => 'Termékcsoport Axico cikkszáma', | ||||
| '#type' => 'textfield', | '#type' => 'textfield', | ||||
| '#weight' => -900, | |||||
| '#weight' => 20, | |||||
| '#default_value' => $category->getAxicoIdName(), | '#default_value' => $category->getAxicoIdName(), | ||||
| ]; | ]; | ||||
| $options = []; | |||||
| $options[100000] = 'Nincs garancia felülírás (Kérem válasszon gyártót)'; | |||||
| $options[0] = 'Minden gyártó ezen termékcsoportjának cikkszámgaranciájának felülírása'; | |||||
| $manufacturers = $this->getManufacturerFactory()->findAll(); | |||||
| foreach ($manufacturers as $selectable) { | |||||
| if ($selectable->getStatus() === 1) { | |||||
| $options[$selectable->getId()] = $selectable->getName(); | |||||
| } | |||||
| } | |||||
| $axicoId = $category->isNew() ? 'XXX' : $category->getAxicoIdName(); | |||||
| $selectSettings = [ | |||||
| 'name' => 'parent_manufacturer_id', | |||||
| 'title' => 'Gyártók hasonló cikkszámtörzseinek garanciájának felülirása [---][' . $axicoId . ']' | |||||
| ]; | |||||
| $form['items_wrapper'][$selectSettings['name']] = [ | |||||
| '#title' => $selectSettings['title'], | |||||
| '#name' => $selectSettings['name'], | |||||
| '#type' => 'select', | |||||
| '#options' => $options, | |||||
| '#id' => $selectSettings['name'] . '_select_warranty', | |||||
| '#default_value' => [$options[100000]], | |||||
| '#weight' => 40, | |||||
| ]; | |||||
| $form['items_wrapper']['axico_id_warranty_length'] = [ | |||||
| '#title' => 'Termékcsoport Axico cikkszámtörzs garancia ([---][XXX])', | |||||
| '#type' => 'textfield', | |||||
| '#default_value' => $this->getConfig()->get('default_warranty'), | |||||
| '#weight' => 30, | |||||
| ]; | |||||
| $form = $this->getSifField($form, $category, -800); | $form = $this->getSifField($form, $category, -800); | ||||
| $form['items_wrapper']['buttons'] = array( | $form['items_wrapper']['buttons'] = array( | ||||
| '#type' => 'container', | '#type' => 'container', | ||||
| '#weight' => -700, | |||||
| '#weight' => 50, | |||||
| '##attributes' => ['class' => ['col-lg-6']], | '##attributes' => ['class' => ['col-lg-6']], | ||||
| ); | ); | ||||
| $form['items_wrapper']['buttons']['arlista_category_edit_form_submit'] = [ | $form['items_wrapper']['buttons']['arlista_category_edit_form_submit'] = [ | ||||
| $form['items_wrapper']['buttons']['deleteCategory'] = $this->getDeleteButton($category); | $form['items_wrapper']['buttons']['deleteCategory'] = $this->getDeleteButton($category); | ||||
| $form['items_wrapper']['buttons']['deleteCategory']['#disabled'] = true; | $form['items_wrapper']['buttons']['deleteCategory']['#disabled'] = true; | ||||
| $form['#suffix'] ='</div>'; | $form['#suffix'] ='</div>'; | ||||
| $this->getCacheService()->setCachedDataByName([$this->getFormId(), $cid], $form); | |||||
| return $form; | return $form; | ||||
| } | } | ||||
| $manufacturers = $this->getManufacturerFactory()->findAll(); | $manufacturers = $this->getManufacturerFactory()->findAll(); | ||||
| $updated = 0; | |||||
| foreach ($manufacturers as $manufacturer) { | foreach ($manufacturers as $manufacturer) { | ||||
| /* | |||||
| * Create axico id for each existing manugacturer upon saving a new category | |||||
| */ | |||||
| if($this->getAxicoIdWarrantyFactory()->findByAxicoIdName($manufacturer->getAxicoIdName() . $category->getAxicoIdName())){ | |||||
| if($values['parent_manufacturer_id'] == $manufacturer->getId()){ | |||||
| $this->getAxicoIdWarrantyFactory()->updateForManufacturer($manufacturer->getAxicoIdName(), $category->getAxicoIdName(), $values['axico_id_warranty_length']); | |||||
| $updated++; | |||||
| } | |||||
| continue; | |||||
| } | |||||
| // Create axico id for each existing manugacturer upon saving a new category | |||||
| if (!$this->getAxicoIdFactory()->isAxicoIdPresentInGroup($manufacturer->getId(), $category->getId(), null)) { | if (!$this->getAxicoIdFactory()->isAxicoIdPresentInGroup($manufacturer->getId(), $category->getId(), null)) { | ||||
| /* @var $axicoId AxicoId */ | /* @var $axicoId AxicoId */ | ||||
| $axicoId = $this->getAxicoIdFactory()->createForCategory($manufacturer->getId(), $category->getId()); | $axicoId = $this->getAxicoIdFactory()->createForCategory($manufacturer->getId(), $category->getId()); | ||||
| $axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->create(); | $axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->create(); | ||||
| $axicoIdWarranty->setAxicoIdName($axicoId->getName()); | $axicoIdWarranty->setAxicoIdName($axicoId->getName()); | ||||
| $axicoIdWarranty->setDefaultWarranty($values['axico_id_warranty']); | |||||
| $this->getAxicoIdWarrantyFactory()->save($axicoIdWarranty); | $this->getAxicoIdWarrantyFactory()->save($axicoIdWarranty); | ||||
| } | } | ||||
| /* | |||||
| * Create calculation for each newly created category | |||||
| */ | |||||
| // Create calculation for each newly created category | |||||
| if (empty($this->getCalculationFactory()->findByManufacturerAndCategory($manufacturer, $category))) { | if (empty($this->getCalculationFactory()->findByManufacturerAndCategory($manufacturer, $category))) { | ||||
| $this->getCalculationFactory()->createFor(null, $category, $manufacturer); | $this->getCalculationFactory()->createFor(null, $category, $manufacturer); | ||||
| } | } | ||||
| } | } | ||||
| \Drupal::messenger()->addStatus($this->t('Sikeres mentés!')); | |||||
| \Drupal::messenger()->addStatus($values['parent_manufacturer_id']); | |||||
| if($values['parent_manufacturer_id'] == 0){ | |||||
| $updated = $this->getAxicoIdWarrantyFactory()->updateForAllManufacturers($category->getAxicoIdName(),$values['axico_id_warranty_length']); | |||||
| } | |||||
| \Drupal::messenger()->addStatus($this->t('Sikeres mentés! ' . $updated . ' (Cikkszámgarancia frissítve)')); | |||||
| $form_state->setRedirect('arlista.category.edit', ['cid' => $category->getId()]); | $form_state->setRedirect('arlista.category.edit', ['cid' => $category->getId()]); | ||||
| } | } |
| namespace Drupal\arlista\Form\Component; | namespace Drupal\arlista\Form\Component; | ||||
| use Drupal\Core\Form\FormStateInterface; | |||||
| use Drupal\arlista\Form\ArlistaAbstractForm; | |||||
| use Drupal\arlista\Entity\Component; | use Drupal\arlista\Entity\Component; | ||||
| use Drupal\arlista\Entity\Manufacturer; | use Drupal\arlista\Entity\Manufacturer; | ||||
| use Drupal\arlista\Entity\AxicoId; | |||||
| use Drupal\arlista\Form\ArlistaAbstractForm; | |||||
| use Drupal\Core\Form\FormStateInterface; | |||||
| use Drupal\Core\Link; | use Drupal\Core\Link; | ||||
| use Drupal\Core\Url; | use Drupal\Core\Url; | ||||
| class ComponentEdit extends ArlistaAbstractForm { | |||||
| /** | |||||
| * {@inheritdoc} | |||||
| */ | |||||
| public function getFormId() { | |||||
| return 'arlista_component_edit_form'; | |||||
| } | |||||
| /** | |||||
| * {@inheritdoc} | |||||
| */ | |||||
| public function buildForm(array $form, FormStateInterface $form_state) { | |||||
| $cmpId = $this->getQueryValue('cmpId'); | |||||
| /** @var $component Component */ | |||||
| $component = empty($cmpId) ? $this->getComponentFactory()->create() : $this->getComponentFactory()->find($cmpId); | |||||
| $form['#prefix'] = '<div class="col-lg-6">'; | |||||
| $form['cmpId'] = [ | |||||
| '#type' => 'hidden', | |||||
| '#value' => $cmpId, | |||||
| ]; | |||||
| if (!$component->isNew()) { | |||||
| $form['link'] = Link::fromTextAndUrl( | |||||
| 'Kalkulációs paraméterek', | |||||
| Url::fromRoute('arlista.manufacturer.calculation.edit', [ | |||||
| 'mid' => $component->getParentManufacturerId(), | |||||
| 'catId' => 0, | |||||
| 'cmpId' => $component->getId() | |||||
| ]) | |||||
| )->toRenderable(); | |||||
| $form['link']['#weight'] = -1100; | |||||
| $axicoId = $this->getAxicoIdFactory()->findHighestCurrentAxicoIdByComponentId($component->getId()); | |||||
| if ($axicoId) { | |||||
| $form['axico_id_count'] = [ | |||||
| '#title' => 'Utolsó kiosztott cikkszám azonosító sorszám [AAA-BBB-xxx]', | |||||
| class ComponentEdit extends ArlistaAbstractForm | |||||
| { | |||||
| /** | |||||
| * {@inheritdoc} | |||||
| */ | |||||
| public function getFormId() | |||||
| { | |||||
| return 'arlista_component_edit_form'; | |||||
| } | |||||
| private $axicoIdWarranty = null; | |||||
| /** | |||||
| * {@inheritdoc} | |||||
| */ | |||||
| public function buildForm(array $form, FormStateInterface $form_state) | |||||
| { | |||||
| $cmpId = $this->getQueryValue('cmpId'); | |||||
| /** @var $component Component */ | |||||
| $component = empty($cmpId) ? $this->getComponentFactory()->create() : $this->getComponentFactory()->find($cmpId); | |||||
| $form['#prefix'] = '<div class="col-lg-4">'; | |||||
| $form['cmpId'] = [ | |||||
| '#type' => 'hidden', | |||||
| '#value' => $cmpId, | |||||
| ]; | |||||
| if (!$component->isNew()) { | |||||
| $form['link'] = Link::fromTextAndUrl( | |||||
| 'Kalkulációs paraméterek', | |||||
| Url::fromRoute('arlista.manufacturer.calculation.edit', [ | |||||
| 'mid' => $component->getParentManufacturerId(), | |||||
| 'catId' => 0, | |||||
| 'cmpId' => $component->getId(), | |||||
| ]) | |||||
| )->toRenderable(); | |||||
| $form['link']['#weight'] = -1100; | |||||
| $axicoId = $this->getAxicoIdFactory()->findHighestCurrentAxicoIdByComponentId($component->getId()); | |||||
| if ($axicoId) { | |||||
| $form['axico_id_count'] = [ | |||||
| '#title' => 'Utolsó kiosztott cikkszám azonosító sorszám [AAA-BBB-xxx]', | |||||
| '#type' => 'textfield', | |||||
| '#default_value' => $axicoId->getCurrentCount(), | |||||
| '#disabled' => true, | |||||
| '#weight' => -975, | |||||
| ]; | |||||
| } | |||||
| } | |||||
| $form = $this->getNameField($form, $component, -1000); | |||||
| $form['axico_id_name'] = [ | |||||
| '#title' => 'Komponens Axico cikkszáma', | |||||
| '#type' => 'textfield', | |||||
| '#default_value' => $component->getAxicoIdName(), | |||||
| '#weight' => -900, | |||||
| ]; | |||||
| if ($component->getParentManufacturerId()) { | |||||
| $manufacturer = $this->getManufacturerFactory()->find($component->getParentManufacturerId()); | |||||
| $axicoIdName = $manufacturer->getAxicoIdName() . $component->getAxicoIdName(); | |||||
| $axicoIdWarranty = $component->isNew() ? $this->getAxicoIdWarrantyFactory()->create() : $this->getAxicoIdWarrantyFactory()->findByAxicoIdName($axicoIdName); | |||||
| if ($axicoIdWarranty->isNew()) { | |||||
| $axicoIdWarranty->setAxicoIdName($axicoIdName); | |||||
| } | |||||
| $this->axicoIdWarranty = $axicoIdWarranty; | |||||
| } else { | |||||
| $this->axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->create(); | |||||
| } | |||||
| $form['axico_id_warranty_length'] = [ | |||||
| '#title' => 'Komponens Axico cikkszámtörzs ' . $this->axicoIdWarranty->getAxicoIdName() . ' garancia', | |||||
| '#type' => 'textfield', | '#type' => 'textfield', | ||||
| '#default_value' => $axicoId->getCurrentCount(), | |||||
| '#disabled' => true, | |||||
| '#weight' => -975, | |||||
| '#default_value' => $this->axicoIdWarranty->getDefaultWarranty(), | |||||
| '#weight' => -900, | |||||
| ]; | |||||
| $form = $this->getSifField($form, $component, -850); | |||||
| $manufacturers = $this->getManufacturerFactory()->findAll(); | |||||
| $selectSettings = [ | |||||
| 'name' => 'parent_manufacturer_id', 'title' => 'Gyártó']; | |||||
| $form['parent_manufacturer_id'] = $this->getSelectOptions($selectSettings, | |||||
| $manufacturers, $component); | |||||
| $form['parent_manufacturer_id']['#disabled'] = $component->isNew() ? false : true; | |||||
| $form['parent_manufacturer_id']['#weight'] = -700; | |||||
| $form['buttons'] = array( | |||||
| '#type' => 'container', | |||||
| '#weight' => -500, | |||||
| ); | |||||
| $form['buttons']['arlista_component_edit_form_submit'] = [ | |||||
| '#type' => 'submit', | |||||
| '#value' => empty($component->getName()) ? 'Új komponens mentése' : $component->getName() . ' - mentés', | |||||
| '#attributes' => ['class' => ['btn-success']], | |||||
| ]; | ]; | ||||
| } | |||||
| $form['buttons']['deleteComponent'] = $this->getDeleteButton($component); | |||||
| $form['buttons']['deleteComponent']['#disabled'] = true; | |||||
| $form['#suffix'] = '</div>'; | |||||
| return $form; | |||||
| } | } | ||||
| $form = $this->getNameField($form, $component, -1000); | |||||
| $form['axico_id_name'] = [ | |||||
| '#title' => 'Komponens Axico cikkszáma', | |||||
| '#type' => 'textfield', | |||||
| '#default_value' => $component->getAxicoIdName(), | |||||
| '#weight' => -900, | |||||
| ]; | |||||
| $form = $this->getSifField($form, $component, -850); | |||||
| $manufacturers = $this->getManufacturerFactory()->findAll(); | |||||
| $selectSettings = [ | |||||
| 'name' => 'parent_manufacturer_id', 'title' => 'Gyártó']; | |||||
| $form['parent_manufacturer_id'] = $this->getSelectOptions($selectSettings, | |||||
| $manufacturers, $component); | |||||
| $form['parent_manufacturer_id']['#disabled'] = $component->isNew() ? false : true; | |||||
| $form['parent_manufacturer_id']['#weight'] = -700; | |||||
| $form['buttons'] = array( | |||||
| '#type' => 'container', | |||||
| '#weight' => -500, | |||||
| ); | |||||
| $form['buttons']['arlista_component_edit_form_submit'] = [ | |||||
| '#type' => 'submit', | |||||
| '#value' => empty($component->getName()) ? 'Új komponens mentése' : $component->getName() . ' - mentés', | |||||
| '#attributes' => ['class' => ['btn-success']] | |||||
| ]; | |||||
| $form['buttons']['deleteComponent'] = $this->getDeleteButton($component); | |||||
| $form['buttons']['deleteComponent']['#disabled'] = true; | |||||
| $form['#suffix'] = '</div>'; | |||||
| return $form; | |||||
| } | |||||
| public function validateForm(array &$form, FormStateInterface $form_state) { | |||||
| parent::validateForm($form, $form_state); | |||||
| } | |||||
| /** | |||||
| * {@inheritdoc} | |||||
| */ | |||||
| public function submitForm(array &$form, FormStateInterface $form_state) { | |||||
| $values = $form_state->getValues(); | |||||
| /* @var $component Component */ | |||||
| $component = empty($values['cmpId']) ? $this->getComponentFactory()->create() : $this->getComponentFactory()->find($values['cmpId']); | |||||
| $component->setName($values['name']); | |||||
| $component->setAxicoIdName($values['axico_id_name']); | |||||
| $component->setSif($values['sif']); | |||||
| /* @var $manufacturer Manufacturer */ | |||||
| $manufacturer = $this->getManufacturerFactory()->find($values['parent_manufacturer_id'][0]); | |||||
| if ($component->isNew()) { | |||||
| $component->setParentManufacturerId($manufacturer->getId()); | |||||
| $component = $this->getComponentFactory()->save($component); | |||||
| if (!$this->getAxicoIdFactory()->isAxicoIdPresentInGroup($manufacturer->getId(), null, $component->getId())) { | |||||
| /* @var $axicoId AxicoId */ | |||||
| $axicoId = $this->getAxicoIdFactory()->createForComponent($manufacturer->getId(), $component->getId()); | |||||
| $axicoId->setName($manufacturer->getAxicoIdName() . $component->getAxicoIdName()); | |||||
| $axicoId = $this->getAxicoIdFactory()->save($axicoId); | |||||
| $axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->create(); | |||||
| $axicoIdWarranty->setAxicoIdName($axicoId->getName()); | |||||
| $this->getAxicoIdWarrantyFactory()->save($axicoIdWarranty); | |||||
| } | |||||
| /* @var $calculation Calculation */ | |||||
| $calculation = $this->getCalculationFactory()->findByComponent($component); | |||||
| if (empty($calculation)) { | |||||
| $this->getCalculationFactory()->createFor($component, null, $manufacturer); | |||||
| } | |||||
| \Drupal::messenger()->addStatus('Új komponens sikeresen mentve!'); | |||||
| } else { | |||||
| $component = $this->getComponentFactory()->save($component); | |||||
| \Drupal::messenger()->addStatus('Sikeres mentés!'); | |||||
| public function validateForm(array &$form, FormStateInterface $form_state) | |||||
| { | |||||
| parent::validateForm($form, $form_state); | |||||
| } | } | ||||
| $this->clearCaches($manufacturer); | |||||
| /** | |||||
| * {@inheritdoc} | |||||
| */ | |||||
| public function submitForm(array &$form, FormStateInterface $form_state) | |||||
| { | |||||
| $values = $form_state->getValues(); | |||||
| /* @var $component Component */ | |||||
| $component = empty($values['cmpId']) ? $this->getComponentFactory()->create() : $this->getComponentFactory()->find($values['cmpId']); | |||||
| $component->setName($values['name']); | |||||
| $component->setAxicoIdName($values['axico_id_name']); | |||||
| $component->setSif($values['sif']); | |||||
| /* @var $manufacturer Manufacturer */ | |||||
| $manufacturer = $this->getManufacturerFactory()->find($values['parent_manufacturer_id'][0]); | |||||
| if ($component->isNew()) { | |||||
| $component->setParentManufacturerId($manufacturer->getId()); | |||||
| $component = $this->getComponentFactory()->save($component); | |||||
| if (!$this->getAxicoIdFactory()->isAxicoIdPresentInGroup($manufacturer->getId(), null, $component->getId())) { | |||||
| /* @var $axicoId AxicoId */ | |||||
| $axicoId = $this->getAxicoIdFactory()->createForComponent($manufacturer->getId(), $component->getId()); | |||||
| $axicoId->setName($manufacturer->getAxicoIdName() . $component->getAxicoIdName()); | |||||
| $axicoId = $this->getAxicoIdFactory()->save($axicoId); | |||||
| $axicoIdWarranty = $this->getAxicoIdWarrantyFactory()->create(); | |||||
| $axicoIdWarranty->setAxicoIdName($axicoId->getName()); | |||||
| $this->axicoIdWarranty = $axicoIdWarranty; | |||||
| } | |||||
| /* @var $calculation Calculation */ | |||||
| $calculation = $this->getCalculationFactory()->findByComponent($component); | |||||
| if (empty($calculation)) { | |||||
| $this->getCalculationFactory()->createFor($component, null, $manufacturer); | |||||
| } | |||||
| \Drupal::messenger()->addStatus('Új komponens sikeresen mentve!'); | |||||
| } else { | |||||
| $component = $this->getComponentFactory()->save($component); | |||||
| \Drupal::messenger()->addStatus('Sikeres mentés!'); | |||||
| } | |||||
| $axicoIdWarranty = $this->axicoIdWarranty; | |||||
| $axicoIdWarranty->setDefaultWarranty($values['axico_id_warranty_length']); | |||||
| $form_state->setRedirect('arlista.component.edit', ['cmpId' => $component->getId()]); | |||||
| } | |||||
| $this->getAxicoIdWarrantyFactory()->save($axicoIdWarranty); | |||||
| $this->clearCaches($manufacturer); | |||||
| public function deleteEntity(array &$form, FormStateInterface $form_state) { | |||||
| $form_state->setRedirect('arlista.component.delete', ['id' => $this->getQueryValue('cmpId')]); | |||||
| } | |||||
| $form_state->setRedirect('arlista.component.edit', ['cmpId' => $component->getId()]); | |||||
| } | |||||
| public function deleteEntity(array &$form, FormStateInterface $form_state) | |||||
| { | |||||
| $form_state->setRedirect('arlista.component.delete', ['id' => $this->getQueryValue('cmpId')]); | |||||
| } | |||||
| public function clearCaches(Manufacturer $manufacturer) { | |||||
| $sheetSettings = $this->getSheetSettingFactory()->findSheetSettingsByManufacturerId($manufacturer->getId()); | |||||
| foreach ($sheetSettings as $sheetSetting) { | |||||
| $this->getCacheService()->resetCache(['arlista_product_uploaded_list_form', $manufacturer->getId(), | |||||
| $sheetSetting->getId(), 'enabled_components_manufacturers_list']); | |||||
| public function clearCaches(Manufacturer $manufacturer) | |||||
| { | |||||
| $sheetSettings = $this->getSheetSettingFactory()->findSheetSettingsByManufacturerId($manufacturer->getId()); | |||||
| foreach ($sheetSettings as $sheetSetting) { | |||||
| $this->getCacheService()->resetCache(['arlista_product_uploaded_list_form', $manufacturer->getId(), | |||||
| $sheetSetting->getId(), 'enabled_components_manufacturers_list']); | |||||
| } | |||||
| $this->getCacheService()->resetCache(['arlista_component_list_form', $manufacturer->getId()]); | |||||
| $this->getCacheService()->resetCache(['arlista_axico_id_warranty_list_form', 'mind']); | |||||
| } | } | ||||
| $this->getCacheService()->resetCache(['arlista_component_list_form', $manufacturer->getId()]); | |||||
| } | |||||
| } | } |
| '#manufacturers' => $enabled, | '#manufacturers' => $enabled, | ||||
| '#sheetSettings' => $sheetSettings, | '#sheetSettings' => $sheetSettings, | ||||
| '#listed' => $this->getConfig()->get('default_listed') ?? 10, | '#listed' => $this->getConfig()->get('default_listed') ?? 10, | ||||
| '#icons' => $this->getProductFactory()->getFontAwesomeIcons(), | |||||
| '#form' => $form, | '#form' => $form, | ||||
| ]; | ]; | ||||
| $rendered_list = \Drupal::service('renderer')->render($renderable_items); | $rendered_list = \Drupal::service('renderer')->render($renderable_items); |
| $manufacturer = empty($mid) ? $this->getManufacturerFactory()->create() : $this->getManufacturerFactory()->find($mid); | $manufacturer = empty($mid) ? $this->getManufacturerFactory()->create() : $this->getManufacturerFactory()->find($mid); | ||||
| $this->mid = $mid; | $this->mid = $mid; | ||||
| $form['#prefix'] ='<div class="col-lg-6">'; | |||||
| $form['#prefix'] ='<div class="col-lg-4">'; | |||||
| $form[]['link'] = Link::fromTextAndUrl( | $form[]['link'] = Link::fromTextAndUrl( | ||||
| 'Vissza a gyártókhoz', | 'Vissza a gyártókhoz', | ||||
| Url::fromRoute('arlista.manufacturer.list') | Url::fromRoute('arlista.manufacturer.list') |
| <th>Módosítva</th> | <th>Módosítva</th> | ||||
| <th>Munkafolyamat</th> | <th>Munkafolyamat</th> | ||||
| <th>Műveletek</th> | <th>Műveletek</th> | ||||
| {% for file in files %} | |||||
| <tr class="correct-files-uploaded-file" data-field-uploaded-file-id="{{ file.id }}" data-field-request-status="ready" data-field-file-work-flow="{{ file.workFlow }}"> | |||||
| </tr> | |||||
| {% if files|length > 3 %} | |||||
| <tr class="correct-files-uploaded-file"> | |||||
| <td colspan="6"><span class="show-roller">{{icons['plus']}}</span><span class="hide-roller">{{icons['minus']}}</span></td> | |||||
| </tr> | |||||
| {% endif %} | |||||
| {% for key,file in files %} | |||||
| <tr {% if files|length > 3 and key < files|length - 2 %} class="correct-files-uploaded-file row-for-hiding" {% else %} class="correct-files-uploaded-file row-for-displaying" {% endif %} data-field-uploaded-file-id="{{ file.id }}" data-field-request-status="ready" data-field-file-work-flow="{{ file.workFlow }}"> | |||||
| <td>{{ manufacturers[file.parentManufacturerId].name }}</td> | <td>{{ manufacturers[file.parentManufacturerId].name }}</td> | ||||
| <td> | <td> | ||||
| {% if file.workFlow is not same as('UPLOADED') %} | {% if file.workFlow is not same as('UPLOADED') %} | ||||
| </td> | </td> | ||||
| </tr> | </tr> | ||||
| {% endfor %} | {% endfor %} | ||||
| </tr> | |||||
| </tbody> | </tbody> | ||||
| </table> | </table> | ||||
| <div>* A kiosztott új cikkszámok visszavonása</div> | <div>* A kiosztott új cikkszámok visszavonása</div> |