|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
-
- namespace Lc\CaracoleBundle\Controller\Credit;
-
- use Doctrine\ORM\EntityManagerInterface;
- use Doctrine\ORM\QueryBuilder;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
- use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
- use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
- use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
- use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
- use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
- use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
- use Lc\CaracoleBundle\Container\Credit\CreditHistoryContainer;
- use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
- use Lc\CaracoleBundle\Controller\AdminControllerTrait;
- use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
- use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
- use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
- use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
- use Lc\SovBundle\Controller\AbstractAdminController;
- use Lc\SovBundle\Translation\TranslatorAdmin;
-
- abstract class CreditHistoryAdminController extends AbstractAdminController
- {
- use AdminControllerTrait;
-
- public function overrideGlobalActions(?ActionCollection $actions): void
- {
- parent::overrideGlobalActions($actions);
- if ($actions) {
- $adminUrlGenerator = $this->get(AdminUrlGenerator::class);
-
- $creditControllerFqcn = $this->getControllerFqcnByInterface(CreditHistoryInterface::class);
-
- foreach ($actions as $action) {
- $url = $adminUrlGenerator
- ->setController($creditControllerFqcn)
- ->setAction(Action::NEW)
- ->set('userMerchantId', $this->getUserMerchant()->getId())
- ->generateUrl();
- $action->setLinkUrl($url);
- }
- }
- }
-
- public function createEntity(string $entityFqcn)
- {
- return $this->get(CreditHistoryContainer::class)->getFactory()->create();
- }
-
- public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
- {
- $entityInstance->setUserMerchant($this->getUserMerchant());
-
- parent::persistEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub
- }
-
- protected function getUserMerchant(): UserMerchantInterface
- {
- $request = $this->get(AdminContextProvider::class)->getContext()->getRequest();
- return $this->get(UserMerchantContainer::class)->getStore()->getOneById(
- $request->get('userMerchantId')
- );
- }
-
- public function configureActions(Actions $actions): Actions
- {
- $actions->disable(Action::DELETE, Action::EDIT);
-
- return parent::configureActions($actions); // TODO: Change the autogenerated stub
- }
-
- public function configureCrud(Crud $crud): Crud
- {
- $crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig');
-
- return $crud;
- }
-
- public function configureFields(string $pageName): iterable
- {
- $translatorAdmin = $this->get('translator_admin');
- return [
- IdField::new('id')->hideOnForm(),
- // @TODO : transChoices
- ChoiceField::new('type')->setChoices(
- array(
- $translatorAdmin->transField(
- 'typeOptions.' . CreditHistoryModel::TYPE_CREDIT,
- 'CreditHistory'
- ) => CreditHistoryModel::TYPE_CREDIT,
-
- $translatorAdmin->transField(
- 'typeOptions.' . CreditHistoryModel::TYPE_DEBIT,
- 'CreditHistory'
- ) => CreditHistoryModel::TYPE_DEBIT,
- )
- ),
- MoneyField::new('amount')->setCurrency('EUR'),
- DateField::new('paidAt'),
- // @TODO : transChoices
- ChoiceField::new('meanPayment')->setChoices(
- array(
- $translatorAdmin->transField(
- 'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CASH,
- 'CreditHistory'
- ) => CreditHistoryModel::MEAN_PAYMENT_CASH,
-
- $translatorAdmin->transField(
- 'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
- 'CreditHistory'
- ) => CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
-
- $translatorAdmin->transField(
- 'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CREDIT,
- 'CreditHistory'
- ) => CreditHistoryModel::MEAN_PAYMENT_CREDIT,
-
- $translatorAdmin->transField(
- 'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
- 'CreditHistory'
- ) => CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
-
- $translatorAdmin->transField(
- 'meanPaymentOptions.' . CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
- 'CreditHistory'
- ) => CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
- )
- ),
- TextField::new('reference'),
- TextField::new('comment'),
- ];
- }
-
- public function createIndexQueryBuilder(
- SearchDto $searchDto,
- EntityDto $entityDto,
- FieldCollection $fields,
- FilterCollection $filters
- ): QueryBuilder {
-
- $queryBuilder = parent::createIndexQueryBuilder(
- $searchDto,
- $entityDto,
- $fields,
- $filters
- );
-
- $queryBuilder->andWhere('entity.userMerchant = :userMerchant');
- $queryBuilder->setParameter('userMerchant', $searchDto->getRequest()->get('userMerchantId'));
-
- return $queryBuilder;
- }
- }
|