src/Controller/Admin/Afhaler/AfhalerCrudController.php line 94

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin\Afhaler;
  3. use App\Controller\Admin\Order\Partial\OrderPartialControllerModel;
  4. use App\Controller\Admin\OrderCrudController;
  5. use App\Controller\Admin\Orderonderdeel\Sub\OrderonderdeelSubController;
  6. use App\Controller\Admin\Reminder\ReminderCrudController;
  7. use App\EasyAdmin\OrderUitgelichtField;
  8. use App\Entity\Communicatie;
  9. use App\Entity\Order;
  10. use App\Entity\Ordersoort;
  11. use App\Entity\Orderstatus;
  12. use App\Service\AdminReferrer;
  13. use App\Service\CreateDbEntryService;
  14. use App\Service\DefineIndexList;
  15. use App\Service\DefineNewOrdernummerService;
  16. use App\Service\DefineOfferteOrderService;
  17. use App\Service\FinanceOrderService;
  18. use App\Service\OpenTBS;
  19. use App\Service\TbsTemplateVars;
  20. use App\Service\UploadedfileService;
  21. use DateTimeImmutable;
  22. use Doctrine\ORM\EntityManagerInterface;
  23. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  24. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  25. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  26. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  27. use Doctrine\ORM\QueryBuilder;
  28. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  29. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  30. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  31. use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
  32. use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
  33. use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
  34. use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
  35. use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
  36. use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
  37. use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
  38. use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
  39. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  40. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  41. use Symfony\Component\HttpFoundation\Request;
  42. use Symfony\Component\Security\Core\Security;
  43. class AfhalerCrudController extends OrderCrudController
  44. {
  45.     public function __construct(
  46.         private UploadedfileService $uploadedfileService,
  47.         private CreateDbEntryService $createDbEntryService,
  48.         private EntityManagerInterface $entityManager,
  49.         public DefineOfferteOrderService $defineOfferteOrderService,
  50.         public DefineNewOrdernummerService $defineNewOrdernummerService,
  51.         public OpenTBS $OpenTBS,
  52.         private AdminUrlGenerator $adminUrlGenerator,
  53.         public TbsTemplateVars $tbsTemplateVars,
  54.         public DefineIndexList $defineIndexList,
  55.         public Security $security,
  56.         public FinanceOrderService $financeOrderService,
  57.     ) {
  58.         return parent::__construct(
  59.             $uploadedfileService,
  60.             $createDbEntryService,
  61.             $entityManager,
  62.             $defineOfferteOrderService,
  63.             $defineNewOrdernummerService,
  64.             $this->OpenTBS $OpenTBS,
  65.             $this->adminUrlGenerator =  $adminUrlGenerator,
  66.             $this->tbsTemplateVars $tbsTemplateVars,
  67.             $this->defineIndexList $defineIndexList,
  68.             $this->security $security,
  69.             $this->financeOrderService $financeOrderService,
  70.         );
  71.     }
  72.     public function configureCrud(Crud $crud): Crud
  73.     {
  74.         $crud parent::configureCrud($crud);
  75.         return $crud->setPageTitle(CRUD::PAGE_INDEX'Afhalers')
  76.                     ->setPageTitle(CRUD::PAGE_NEW'Maak nieuwe afhaler')            
  77.         ;
  78.     }
  79.     public function createIndexQueryBuilder(SearchDto $searchDtoEntityDto $entityDtoFieldCollection $fieldsFilterCollection $filters): QueryBuilder
  80.     {
  81.         return parent::createIndexQueryBuilder($searchDto$entityDto$fields$filters)
  82.             ->andwhere("entity.ordersoort = 3");
  83.     }
  84.     public function configureFields(string $pageName): iterable
  85.     {
  86.         //ivm redirect de referrer voor mogelijke aan te roepen controllers definieren
  87.         $adminReferrer AdminReferrer::new($this->getContext());
  88.         $adminReferrer->setReferrer(OrderonderdeelSubController::class);
  89.         $adminReferrer->setReferrer(OrderPartialControllerModel::class);
  90.         
  91.         
  92.         //nu de velden definieren
  93.         //Tab Afhaler
  94.         $fields[] = FormField::addTab('Afhaler')
  95.             ->hideWhenCreating();
  96.         $fields[] = FormField::addPanel('Afhaler')
  97.             ->onlyWhenCreating();
  98.         $fields[] = NumberField::new('ordernummer')
  99.             ->hideWhenCreating()
  100.             ->onlyOnIndex()
  101.             ->setNumberFormat('%s')
  102.             ->setLabel('Nummer');
  103.         $fields[] = DateField::new('createdAt')
  104.             ->hideOnIndex()->hideWhenCreating()
  105.             ->setFormat('d-M-Y')
  106.             ->setLabel('Aanmaakdatum');
  107.         $fields[] = AssociationField::new('vestiging');
  108.         $fields[] = AssociationField::new('begraafplaats')
  109.             ->autocomplete();
  110.         $fields[] = TextField::new('afhaler_opdrachtgever')
  111.             ->setLabel("Opdrachtgever")
  112.             ->hideOnIndex();
  113.         $fields[] = TextField::new('grafnummer')
  114.             ->hideOnIndex();
  115.         $fields[] = TextField::new('afhaler_naam_op_steen')
  116.             ->setLabel("Naam op steen");
  117.         $fields[] = DateField::new('afhaler_overlijdensdatum_op_steen')
  118.             ->setFormat('d-M-Y')
  119.             ->setlabel("Overlijdensdatum op steen");
  120.         $fields[] = DateField::new('begraaf_datum')
  121.             ->setFormat('d-M-Y')
  122.             ->setHelp('Datum begrafenis van persoon die bijgezet wordt.')
  123.             ->hideOnIndex();
  124.         $fields[] = TextareaField::new('opmerkingen')
  125.             ->hideOnIndex();
  126.         $fields[] = OrderUitgelichtField::new('Uitgelicht'$this->entityManager'Uitgelicht')
  127.             ->onlyOnDetail()
  128.             ->setValue('Test');
  129.         //Tab overledene
  130.         $fields[] = FormField::addTab('Overledene')
  131.             ->hideWhenCreating();;
  132.         $fields[] = FormField::addPanel('Overledene')
  133.             ->onlyWhenCreating();
  134.         $fields[] = TextField::new('overledene_naam');
  135.         $fields[] = DateField::new('geb_datum')
  136.             ->setFormat('d-M-Y')
  137.             ->hideOnIndex();
  138.         $fields[] = DateField::new('overl_datum')
  139.             ->setFormat('d-M-Y')
  140.             //->hideOnIndex()
  141.         ;
  142.         $fields[] = AssociationField::new('familie')
  143.             ->autocomplete()
  144.             ->setLabel('Familie')
  145.             ->hideOnIndex();
  146.         $fields[] = AssociationField::new('uitvaartvereniging')
  147.             ->setLabel('Uitvaartvereniging')
  148.             ->autocomplete()
  149.             ->hideOnIndex();
  150.         //Tab Onderdelen
  151.         $fieldName 'Onderdelen';
  152.         $fields[$fieldName] = FormField::addTab('Onderdelen')
  153.             ->onlyOnDetail();
  154.         $fieldName 'orderonderdeel';
  155.         $fields[$fieldName] = AssociationField::new('orderonderdeels')
  156.             ->setLabel('Onderdelen')
  157.             ->setCrudController(OrderonderdeelSubController::class)
  158.             ->setTemplatePath('admin/fields/orderonderdelen.html.twig')
  159.             ->hideWhenCreating()
  160.             ->hideOnForm()
  161.             ->onlyOnDetail();
  162.         //Tab Workflow
  163.         $fields[] = FormField::addTab('Workflow')
  164.             ->hideWhenCreating();
  165.         $fields[] = AssociationField::new('orderstatus')
  166.             ->setLabel('Status')
  167.             ->hideWhenCreating()
  168.             ->setQueryBuilder(function (QueryBuilder $queryBuilder) {
  169.                 $queryBuilder->orderby('entity.volgorde, entity.id');
  170.             });
  171.         $fields[] = DateField::new('afhaal_datum')
  172.             ->setFormat('d-M-Y')
  173.             ->hideWhenCreating()
  174.             ->hideOnIndex()
  175.             ->setHelp('Datum dat het monument van de begraafplaats is gehaald.');
  176.         $fields[] = DateField::new('afhaler_contactdatum')
  177.             ->setFormat('d-M-Y')
  178.             ->hideWhenCreating()
  179.             ->hideOnIndex()
  180.             ->setHelp('Datum van contact met de familie over het afgehaalde monument.
  181.             <br><i>Als de datum is ingevuld dan verdwijnt deze afhaler uit de lijst "Afhalers > 3 weken".</i>');
  182.         $fields[] = AssociationField::new('afhaler_contactmedewerker')
  183.             ->hideOnIndex()
  184.             ->hideWhenCreating();
  185.         //Opslag panel
  186.         // if ($order) {
  187.         //     if ($order->isOpslagNodig()) {
  188.         //$fields[] = FormField::addPanel('Opslag')->collapsible()
  189.          //   ->hideWhenCreating();
  190.         //     } else {
  191.         //         yield FormField::addPanel('Opslag')
  192.         //             ->renderCollapsed()
  193.         //             ->hideWhenCreating();
  194.         //     }
  195.         // }
  196.         // $fields[] = BooleanField::new('opslag_nodig')
  197.         //     ->hideOnIndex()
  198.         //     ->setColumns(3)
  199.         //     ->setHelp('Hier geef je aan of er opslag nodig is voor het monument.
  200.         //     <br><i>Bij een afhaler is dit altijd nodig. Meestal ook voor een bestaand monument dat opgeknapt moet worden.</i>');
  201.         // $fields[] = AssociationField::new('opslag_medewerker')
  202.         //     ->hideOnIndex()
  203.         //     ->hideWhenCreating()
  204.         //     ->setColumns(3);
  205.         // $fields[] = TextField::new('opslag_locatie')
  206.         //     ->setLabel('Opslaglocatie (oud)')
  207.         //     ->hideOnIndex()
  208.         //     ->hideWhenCreating()
  209.         //     ->setColumns(3)
  210.         //     ->setHelp('Locatie waar het monument is opgeslagen');
  211.         // $fields[] = TextField::new('opslaglocaties')
  212.         //     ->onlyOnDetail();
  213.         $fields['Bestanden'] = FormField::addTab('Bestanden')
  214.             ->hideWhenCreating()
  215.             ->hideOnForm();
  216.         $fields['attachments'] = CollectionField::new('attachments')
  217.             ->setFormTypeOption('by_reference'false)
  218.             //->setFormTypeOptions(['block_name'=>'custom_attachments'])
  219.             ->setFormTypeOptions(['entry_type' => 'App\Form\AttachmentType'])
  220.             //->autocomplete()
  221.             //->setEntryType(AttachmentType::class)
  222.             //->onlyOnForms()
  223.             ->setTemplatePath('admin/fields/attachments.html.twig')
  224.             ->hideOnIndex()
  225.             ->hideWhenCreating()
  226.             //->autocomplete()
  227.             //->hideOnIndex()
  228.             ->hideOnForm();
  229.         $fieldName 'Reminders';
  230.         $fields[$fieldName] = FormField::addTab('Reminders')
  231.             ->onlyOnDetail()
  232.             ->setLabel('Reminders/Notities');
  233.         $fieldName 'reminders';
  234.         $fields[$fieldName] = AssociationField::new('reminders')
  235.             ->setCrudController(ReminderCrudController::class)
  236.             ->setTemplatePath('admin/fields/reminders.html.twig')
  237.             ->hideWhenCreating()
  238.             ->hideOnForm()
  239.             ->onlyOnDetail();
  240.         $context $this->getContext();
  241.         //last configuration changes
  242.         //setting the default tab
  243.         // if ($context->getRequest()->get("tab") === 'reminders') {
  244.         //     $fields['Reminders']->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
  245.         // }
  246.         // // of in de referrer
  247.         // $referrer = $context->getRequest()->get('referrer');
  248.         // if (null !== $referrer) {
  249.         //     if (Request::create($referrer)->get('tab') === 'reminders') {
  250.         //         $fields['Reminders']->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
  251.         //     }
  252.         // }
  253.         if ($tab $context->getRequest()->get("tab")) {
  254.             $tab ucfirst($tab);
  255.             $fields[$tab]->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
  256.         }
  257.         // of in de referrer
  258.         $referrer $context->getRequest()->get('referrer');
  259.         if (null !== $referrer) {
  260.             if ($tab Request::create($referrer)->get('tab')) {
  261.                 $tab ucfirst($tab);
  262.                 $fields[$tab]->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
  263.             }
  264.         }
  265.         foreach ($fields as $fieldName => $fieldObject) {
  266.             // if (!in_array($fieldName, $indexList)) {
  267.             //     $fields[$fieldName]->hideOnIndex();
  268.             // }
  269.             yield $fieldObject;
  270.         }
  271.         return;
  272.     }
  273.     public function createEntity(string $entityFqcn)
  274.     {
  275.         $order = new Order();
  276.         $user $this->security->getUser();
  277.         //aanmaakdatum
  278.         $createdAt =  new DateTimeImmutable('now');
  279.         $order->setCreatedAt($createdAt);
  280.         $order->setIngevoerdDatum($createdAt);
  281.         $order->setIngevoerdDoor($user);
  282.         $order->setStep(0);
  283.         //orderstatus nieuw = 1
  284.         $orderstatus $this->entityManager->getRepository(Orderstatus::class)->findOneBy(['id' => 1]);
  285.         $order->setOrderstatus($orderstatus);
  286.         //ordersoort afhaler = 3
  287.         $ordersoort $this->entityManager->getRepository(Ordersoort::class)->findOneBy(['id' => 3]);
  288.         $order->setOrdersoort($ordersoort);
  289.         //recordtype
  290.         $recordType 'Onbekend';
  291.         $order->setRecordType($recordType);
  292.         //communicatie
  293.         $communicatie $this->entityManager->getRepository(Communicatie::class)->findOneBy(['id' => 1]);
  294.         $order->setComm($communicatie);
  295.         //ordernummer
  296.         $generatedOrdernummer $this->defineNewOrdernummerService->getNewOrdernummer();
  297.         $order->setOrdernummer($generatedOrdernummer);
  298.         //aanpassingNodig
  299.         $aanpassing 0;
  300.         $order->setAanpassingNodig($aanpassing);
  301.         return $order;
  302.     }
  303.     public function configureActions(Actions $actions): Actions
  304.     {
  305.         $downloadAfhaalbonAction Action::new('Afhaalbon')
  306.             //->linkToUrl(function(){return $this->generateUrl('app_question_show',['slug'=> 'tja',]);})
  307.             ->displayAsButton()
  308.             ->setLabel('Genereer afhaalbon')
  309.             ->setTemplatePath('admin/download_action.html.twig')
  310.             ->linkToCrudAction('downloadAfhaalbon');
  311.         $actions->add(Crud::PAGE_DETAIL$downloadAfhaalbonAction);
  312.         $actions->update(Crud::PAGE_DETAIL'Afhaalbon', function (Action $action) {
  313.             $action->displayIf(
  314.                 static function (Order $order) {
  315.                     if ($order->getOrdersoort() == 'Afhaler') {
  316.                         return  true;
  317.                     } else {
  318.                         return false;
  319.                     }
  320.                 }
  321.             );
  322.             return $action;
  323.         });
  324.         
  325.         $actions->update(Crud::PAGE_INDEXAction::NEW, fn (Action $action) => $action->setLabel('Nieuwe Afhaler'));
  326.         $actionEditStepOrder Action::new('actionBewerkStep''Maak offerte/order')
  327.             ->linkToCrudAction('actionBewerkStep')
  328.             ->setCssClass('text-danger');
  329.         $actions->add(Crud::PAGE_INDEX$actionEditStepOrder);
  330.         $actions->update(Crud::PAGE_INDEX'actionBewerkStep', function (Action $action) {
  331.             $action->displayIf(
  332.                 static function (Order $order) {
  333.                     if ($order->getStep() == 5) {
  334.                         return  false;
  335.                     } else {
  336.                         return true;
  337.                     }
  338.                 }
  339.             );
  340.             return $action;
  341.         });
  342.         
  343.         return $actions
  344.             ->disable(Action::DELETE)
  345.             ->disable(Action::SAVE_AND_ADD_ANOTHER)
  346.             ->add(Crud::PAGE_EDITAction::DETAIL)
  347.             ->reorder(Crud::PAGE_INDEX,[Action::DETAIL,Action::EDIT,'actionBewerkStep'])
  348.             ;
  349.     }
  350.     public function configureFilters(Filters $filters): Filters
  351.     {
  352.         return $filters
  353.             ->add('vestiging')
  354.             ->add('begraafplaats');
  355.     }
  356. }