<?php
namespace App\Controller\Admin\Afhaler;
use App\Controller\Admin\Order\Partial\OrderPartialControllerModel;
use App\Controller\Admin\OrderCrudController;
use App\Controller\Admin\Orderonderdeel\Sub\OrderonderdeelSubController;
use App\Controller\Admin\Reminder\ReminderCrudController;
use App\EasyAdmin\OrderUitgelichtField;
use App\Entity\Communicatie;
use App\Entity\Order;
use App\Entity\Ordersoort;
use App\Entity\Orderstatus;
use App\Service\AdminReferrer;
use App\Service\CreateDbEntryService;
use App\Service\DefineIndexList;
use App\Service\DefineNewOrdernummerService;
use App\Service\DefineOfferteOrderService;
use App\Service\FinanceOrderService;
use App\Service\OpenTBS;
use App\Service\TbsTemplateVars;
use App\Service\UploadedfileService;
use DateTimeImmutable;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
use Doctrine\ORM\QueryBuilder;
use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\BooleanField;
use EasyCorp\Bundle\EasyAdminBundle\Field\CollectionField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\FormField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextareaField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Security\Core\Security;
class AfhalerCrudController extends OrderCrudController
{
public function __construct(
private UploadedfileService $uploadedfileService,
private CreateDbEntryService $createDbEntryService,
private EntityManagerInterface $entityManager,
public DefineOfferteOrderService $defineOfferteOrderService,
public DefineNewOrdernummerService $defineNewOrdernummerService,
public OpenTBS $OpenTBS,
private AdminUrlGenerator $adminUrlGenerator,
public TbsTemplateVars $tbsTemplateVars,
public DefineIndexList $defineIndexList,
public Security $security,
public FinanceOrderService $financeOrderService,
) {
return parent::__construct(
$uploadedfileService,
$createDbEntryService,
$entityManager,
$defineOfferteOrderService,
$defineNewOrdernummerService,
$this->OpenTBS = $OpenTBS,
$this->adminUrlGenerator = $adminUrlGenerator,
$this->tbsTemplateVars = $tbsTemplateVars,
$this->defineIndexList = $defineIndexList,
$this->security = $security,
$this->financeOrderService = $financeOrderService,
);
}
public function configureCrud(Crud $crud): Crud
{
$crud = parent::configureCrud($crud);
return $crud->setPageTitle(CRUD::PAGE_INDEX, 'Afhalers')
->setPageTitle(CRUD::PAGE_NEW, 'Maak nieuwe afhaler')
;
}
public function createIndexQueryBuilder(SearchDto $searchDto, EntityDto $entityDto, FieldCollection $fields, FilterCollection $filters): QueryBuilder
{
return parent::createIndexQueryBuilder($searchDto, $entityDto, $fields, $filters)
->andwhere("entity.ordersoort = 3");
}
public function configureFields(string $pageName): iterable
{
//ivm redirect de referrer voor mogelijke aan te roepen controllers definieren
$adminReferrer = AdminReferrer::new($this->getContext());
$adminReferrer->setReferrer(OrderonderdeelSubController::class);
$adminReferrer->setReferrer(OrderPartialControllerModel::class);
//nu de velden definieren
//Tab Afhaler
$fields[] = FormField::addTab('Afhaler')
->hideWhenCreating();
$fields[] = FormField::addPanel('Afhaler')
->onlyWhenCreating();
$fields[] = NumberField::new('ordernummer')
->hideWhenCreating()
->onlyOnIndex()
->setNumberFormat('%s')
->setLabel('Nummer');
$fields[] = DateField::new('createdAt')
->hideOnIndex()->hideWhenCreating()
->setFormat('d-M-Y')
->setLabel('Aanmaakdatum');
$fields[] = AssociationField::new('vestiging');
$fields[] = AssociationField::new('begraafplaats')
->autocomplete();
$fields[] = TextField::new('afhaler_opdrachtgever')
->setLabel("Opdrachtgever")
->hideOnIndex();
$fields[] = TextField::new('grafnummer')
->hideOnIndex();
$fields[] = TextField::new('afhaler_naam_op_steen')
->setLabel("Naam op steen");
$fields[] = DateField::new('afhaler_overlijdensdatum_op_steen')
->setFormat('d-M-Y')
->setlabel("Overlijdensdatum op steen");
$fields[] = DateField::new('begraaf_datum')
->setFormat('d-M-Y')
->setHelp('Datum begrafenis van persoon die bijgezet wordt.')
->hideOnIndex();
$fields[] = TextareaField::new('opmerkingen')
->hideOnIndex();
$fields[] = OrderUitgelichtField::new('Uitgelicht', $this->entityManager, 'Uitgelicht')
->onlyOnDetail()
->setValue('Test');
//Tab overledene
$fields[] = FormField::addTab('Overledene')
->hideWhenCreating();;
$fields[] = FormField::addPanel('Overledene')
->onlyWhenCreating();
$fields[] = TextField::new('overledene_naam');
$fields[] = DateField::new('geb_datum')
->setFormat('d-M-Y')
->hideOnIndex();
$fields[] = DateField::new('overl_datum')
->setFormat('d-M-Y')
//->hideOnIndex()
;
$fields[] = AssociationField::new('familie')
->autocomplete()
->setLabel('Familie')
->hideOnIndex();
$fields[] = AssociationField::new('uitvaartvereniging')
->setLabel('Uitvaartvereniging')
->autocomplete()
->hideOnIndex();
//Tab Onderdelen
$fieldName = 'Onderdelen';
$fields[$fieldName] = FormField::addTab('Onderdelen')
->onlyOnDetail();
$fieldName = 'orderonderdeel';
$fields[$fieldName] = AssociationField::new('orderonderdeels')
->setLabel('Onderdelen')
->setCrudController(OrderonderdeelSubController::class)
->setTemplatePath('admin/fields/orderonderdelen.html.twig')
->hideWhenCreating()
->hideOnForm()
->onlyOnDetail();
//Tab Workflow
$fields[] = FormField::addTab('Workflow')
->hideWhenCreating();
$fields[] = AssociationField::new('orderstatus')
->setLabel('Status')
->hideWhenCreating()
->setQueryBuilder(function (QueryBuilder $queryBuilder) {
$queryBuilder->orderby('entity.volgorde, entity.id');
});
$fields[] = DateField::new('afhaal_datum')
->setFormat('d-M-Y')
->hideWhenCreating()
->hideOnIndex()
->setHelp('Datum dat het monument van de begraafplaats is gehaald.');
$fields[] = DateField::new('afhaler_contactdatum')
->setFormat('d-M-Y')
->hideWhenCreating()
->hideOnIndex()
->setHelp('Datum van contact met de familie over het afgehaalde monument.
<br><i>Als de datum is ingevuld dan verdwijnt deze afhaler uit de lijst "Afhalers > 3 weken".</i>');
$fields[] = AssociationField::new('afhaler_contactmedewerker')
->hideOnIndex()
->hideWhenCreating();
//Opslag panel
// if ($order) {
// if ($order->isOpslagNodig()) {
//$fields[] = FormField::addPanel('Opslag')->collapsible()
// ->hideWhenCreating();
// } else {
// yield FormField::addPanel('Opslag')
// ->renderCollapsed()
// ->hideWhenCreating();
// }
// }
// $fields[] = BooleanField::new('opslag_nodig')
// ->hideOnIndex()
// ->setColumns(3)
// ->setHelp('Hier geef je aan of er opslag nodig is voor het monument.
// <br><i>Bij een afhaler is dit altijd nodig. Meestal ook voor een bestaand monument dat opgeknapt moet worden.</i>');
// $fields[] = AssociationField::new('opslag_medewerker')
// ->hideOnIndex()
// ->hideWhenCreating()
// ->setColumns(3);
// $fields[] = TextField::new('opslag_locatie')
// ->setLabel('Opslaglocatie (oud)')
// ->hideOnIndex()
// ->hideWhenCreating()
// ->setColumns(3)
// ->setHelp('Locatie waar het monument is opgeslagen');
// $fields[] = TextField::new('opslaglocaties')
// ->onlyOnDetail();
$fields['Bestanden'] = FormField::addTab('Bestanden')
->hideWhenCreating()
->hideOnForm();
$fields['attachments'] = CollectionField::new('attachments')
->setFormTypeOption('by_reference', false)
//->setFormTypeOptions(['block_name'=>'custom_attachments'])
->setFormTypeOptions(['entry_type' => 'App\Form\AttachmentType'])
//->autocomplete()
//->setEntryType(AttachmentType::class)
//->onlyOnForms()
->setTemplatePath('admin/fields/attachments.html.twig')
->hideOnIndex()
->hideWhenCreating()
//->autocomplete()
//->hideOnIndex()
->hideOnForm();
$fieldName = 'Reminders';
$fields[$fieldName] = FormField::addTab('Reminders')
->onlyOnDetail()
->setLabel('Reminders/Notities');
$fieldName = 'reminders';
$fields[$fieldName] = AssociationField::new('reminders')
->setCrudController(ReminderCrudController::class)
->setTemplatePath('admin/fields/reminders.html.twig')
->hideWhenCreating()
->hideOnForm()
->onlyOnDetail();
$context = $this->getContext();
//last configuration changes
//setting the default tab
// if ($context->getRequest()->get("tab") === 'reminders') {
// $fields['Reminders']->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
// }
// // of in de referrer
// $referrer = $context->getRequest()->get('referrer');
// if (null !== $referrer) {
// if (Request::create($referrer)->get('tab') === 'reminders') {
// $fields['Reminders']->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
// }
// }
if ($tab = $context->getRequest()->get("tab")) {
$tab = ucfirst($tab);
$fields[$tab]->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
}
// of in de referrer
$referrer = $context->getRequest()->get('referrer');
if (null !== $referrer) {
if ($tab = Request::create($referrer)->get('tab')) {
$tab = ucfirst($tab);
$fields[$tab]->setCustomOptions([FormField::OPTION_TAB_IS_ACTIVE => true]);
}
}
foreach ($fields as $fieldName => $fieldObject) {
// if (!in_array($fieldName, $indexList)) {
// $fields[$fieldName]->hideOnIndex();
// }
yield $fieldObject;
}
return;
}
public function createEntity(string $entityFqcn)
{
$order = new Order();
$user = $this->security->getUser();
//aanmaakdatum
$createdAt = new DateTimeImmutable('now');
$order->setCreatedAt($createdAt);
$order->setIngevoerdDatum($createdAt);
$order->setIngevoerdDoor($user);
$order->setStep(0);
//orderstatus nieuw = 1
$orderstatus = $this->entityManager->getRepository(Orderstatus::class)->findOneBy(['id' => 1]);
$order->setOrderstatus($orderstatus);
//ordersoort afhaler = 3
$ordersoort = $this->entityManager->getRepository(Ordersoort::class)->findOneBy(['id' => 3]);
$order->setOrdersoort($ordersoort);
//recordtype
$recordType = 'Onbekend';
$order->setRecordType($recordType);
//communicatie
$communicatie = $this->entityManager->getRepository(Communicatie::class)->findOneBy(['id' => 1]);
$order->setComm($communicatie);
//ordernummer
$generatedOrdernummer = $this->defineNewOrdernummerService->getNewOrdernummer();
$order->setOrdernummer($generatedOrdernummer);
//aanpassingNodig
$aanpassing = 0;
$order->setAanpassingNodig($aanpassing);
return $order;
}
public function configureActions(Actions $actions): Actions
{
$downloadAfhaalbonAction = Action::new('Afhaalbon')
//->linkToUrl(function(){return $this->generateUrl('app_question_show',['slug'=> 'tja',]);})
->displayAsButton()
->setLabel('Genereer afhaalbon')
->setTemplatePath('admin/download_action.html.twig')
->linkToCrudAction('downloadAfhaalbon');
$actions->add(Crud::PAGE_DETAIL, $downloadAfhaalbonAction);
$actions->update(Crud::PAGE_DETAIL, 'Afhaalbon', function (Action $action) {
$action->displayIf(
static function (Order $order) {
if ($order->getOrdersoort() == 'Afhaler') {
return true;
} else {
return false;
}
}
);
return $action;
});
$actions->update(Crud::PAGE_INDEX, Action::NEW, fn (Action $action) => $action->setLabel('Nieuwe Afhaler'));
$actionEditStepOrder = Action::new('actionBewerkStep', 'Maak offerte/order')
->linkToCrudAction('actionBewerkStep')
->setCssClass('text-danger');
$actions->add(Crud::PAGE_INDEX, $actionEditStepOrder);
$actions->update(Crud::PAGE_INDEX, 'actionBewerkStep', function (Action $action) {
$action->displayIf(
static function (Order $order) {
if ($order->getStep() == 5) {
return false;
} else {
return true;
}
}
);
return $action;
});
return $actions
->disable(Action::DELETE)
->disable(Action::SAVE_AND_ADD_ANOTHER)
->add(Crud::PAGE_EDIT, Action::DETAIL)
->reorder(Crud::PAGE_INDEX,[Action::DETAIL,Action::EDIT,'actionBewerkStep'])
;
}
public function configureFilters(Filters $filters): Filters
{
return $filters
->add('vestiging')
->add('begraafplaats');
}
}