Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

161 Zeilen
6.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller\Credit;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use Doctrine\ORM\QueryBuilder;
  5. use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection;
  6. use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection;
  7. use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection;
  8. use EasyCorp\Bundle\EasyAdminBundle\Config\Action;
  9. use EasyCorp\Bundle\EasyAdminBundle\Config\Actions;
  10. use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
  11. use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
  12. use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
  13. use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
  14. use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
  15. use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
  16. use EasyCorp\Bundle\EasyAdminBundle\Field\MoneyField;
  17. use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
  18. use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
  19. use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
  20. use Lc\CaracoleBundle\Controller\AdminControllerTrait;
  21. use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
  22. use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
  23. use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
  24. use Lc\SovBundle\Controller\AbstractAdminController;
  25. use Lc\SovBundle\Translation\TranslatorAdmin;
  26. abstract class CreditHistoryAdminController extends AbstractAdminController
  27. {
  28. use AdminControllerTrait;
  29. protected $em;
  30. protected $translatorAdmin;
  31. public function __construct(EntityManagerInterface $entityManager, TranslatorAdmin $translatorAdmin)
  32. {
  33. $this->em = $entityManager;
  34. $this->translatorAdmin = $translatorAdmin;
  35. }
  36. public function overrideGlobalActions(?ActionCollection $actions): void
  37. {
  38. parent::overrideGlobalActions($actions);
  39. if ($actions) {
  40. $adminUrlGenerator = $this->get(AdminUrlGenerator::class);
  41. $creditControllerFqcn = $this->getControllerFqcnByInterface(CreditHistoryInterface::class);
  42. foreach ($actions as $action) {
  43. $url = $adminUrlGenerator
  44. ->setController($creditControllerFqcn)
  45. ->setAction(Action::NEW)
  46. ->set('userMerchantId', $this->getUserMerchant()->getId())
  47. ->generateUrl();
  48. $action->setLinkUrl($url);
  49. }
  50. }
  51. }
  52. public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
  53. {
  54. $entityInstance->setUserMerchant($this->getUserMerchant());
  55. parent::persistEntity($entityManager, $entityInstance); // TODO: Change the autogenerated stub
  56. }
  57. protected function getUserMerchant(): UserMerchantInterface
  58. {
  59. $request = $this->get(AdminContextProvider::class)->getContext()->getRequest();
  60. $userMerchant = $this->get('em')->getRepository(UserMerchantInterface::class)->find(
  61. $request->get('userMerchantId')
  62. );
  63. return $userMerchant;
  64. }
  65. public function configureActions(Actions $actions): Actions
  66. {
  67. $actions->disable(Action::DELETE, Action::EDIT);
  68. return parent::configureActions($actions); // TODO: Change the autogenerated stub
  69. }
  70. public function configureCrud(Crud $crud): Crud
  71. {
  72. $crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig');
  73. return $crud;
  74. }
  75. public function configureFields(string $pageName): iterable
  76. {
  77. yield IdField::new('id')->hideOnForm();
  78. yield ChoiceField::new('type')->setChoices(
  79. array(
  80. $this->translatorAdmin->transField(
  81. 'typeOptions.'.CreditHistoryModel::TYPE_CREDIT,
  82. 'CreditHistory'
  83. ) => CreditHistoryModel::TYPE_CREDIT,
  84. $this->translatorAdmin->transField(
  85. 'typeOptions.'.CreditHistoryModel::TYPE_DEBIT,
  86. 'CreditHistory'
  87. ) => CreditHistoryModel::TYPE_DEBIT,
  88. )
  89. );
  90. yield MoneyField::new('amount')->setCurrency('EUR');
  91. yield DateField::new('paidAt');
  92. yield ChoiceField::new('meanPayment')->setChoices(
  93. array(
  94. $this->translatorAdmin->transField(
  95. 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CASH,
  96. 'CreditHistory'
  97. ) => CreditHistoryModel::MEAN_PAYMENT_CASH,
  98. $this->translatorAdmin->transField(
  99. 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
  100. 'CreditHistory'
  101. ) => CreditHistoryModel::MEAN_PAYMENT_CHEQUE,
  102. $this->translatorAdmin->transField(
  103. 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CREDIT,
  104. 'CreditHistory'
  105. ) => CreditHistoryModel::MEAN_PAYMENT_CREDIT,
  106. $this->translatorAdmin->transField(
  107. 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
  108. 'CreditHistory'
  109. ) => CreditHistoryModel::MEAN_PAYMENT_CREDIT_CARD,
  110. $this->translatorAdmin->transField(
  111. 'meanPaymentOptions.'.CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
  112. 'CreditHistory'
  113. ) => CreditHistoryModel::MEAN_PAYMENT_TRANSFER,
  114. )
  115. );;
  116. yield TextField::new('reference');
  117. yield TextField::new('comment');
  118. }
  119. public function createIndexQueryBuilder(
  120. SearchDto $searchDto,
  121. EntityDto $entityDto,
  122. FieldCollection $fields,
  123. FilterCollection $filters
  124. ): QueryBuilder {
  125. $queryBuilder = parent::createIndexQueryBuilder(
  126. $searchDto,
  127. $entityDto,
  128. $fields,
  129. $filters
  130. );
  131. $queryBuilder->andWhere('entity.userMerchant = :userMerchant');
  132. $queryBuilder->setParameter('userMerchant', $searchDto->getRequest()->get('userMerchantId'));
  133. return $queryBuilder;
  134. }
  135. }