Selaa lähdekoodia

Merge branch 'develop' of https://forge.laclic.fr/Laclic/CaracoleBundle into develop

packProduct
Guillaume 3 vuotta sitten
vanhempi
commit
a4e89ec642
28 muutettua tiedostoa jossa 429 lisäystä ja 316 poistoa
  1. +10
    -1
      Container/Credit/CreditHistoryContainer.php
  2. +11
    -2
      Container/User/UserMerchantContainer.php
  3. +35
    -79
      Controller/Credit/CreditHistoryAdminController.php
  4. +7
    -13
      Controller/User/UserAdminController.php
  5. +119
    -144
      Controller/User/UserMerchantAdminController.php
  6. +2
    -0
      Definition/ActionDefinition.php
  7. +80
    -0
      Definition/Field/Credit/CreditHistoryFieldDefinition.php
  8. +52
    -0
      Definition/Field/User/UserMerchantFieldDefinition.php
  9. +1
    -1
      EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php
  10. +9
    -2
      Factory/Credit/CreditHistoryFactory.php
  11. +1
    -1
      Field/Filter/ProductCategoriesFilter.php
  12. +20
    -49
      Form/User/UserMerchantActiveCreditFormType.php
  13. +1
    -4
      Model/Credit/CreditHistoryInterface.php
  14. +1
    -0
      Repository/Credit/CreditHistoryRepositoryQuery.php
  15. +2
    -8
      Repository/Order/OrderShopRepositoryQuery.php
  16. +4
    -1
      Repository/Order/OrderShopStore.php
  17. +6
    -0
      Repository/User/UserMerchantRepositoryQuery.php
  18. +1
    -0
      Resolver/MerchantResolver.php
  19. +11
    -5
      Resources/translations/admin.fr.yaml
  20. +6
    -0
      Resources/views/admin/credit/field/amount.html.twig
  21. +6
    -0
      Resources/views/admin/credit/field/comment.html.twig
  22. +6
    -0
      Resources/views/admin/credit/field/meanPayment.html.twig
  23. +6
    -0
      Resources/views/admin/credit/field/paidAt.html.twig
  24. +6
    -0
      Resources/views/admin/credit/field/reference.html.twig
  25. +9
    -2
      Resources/views/admin/credit/index_credithistory.html.twig
  26. +4
    -2
      Resources/views/admin/order/field/order_status.html.twig
  27. +12
    -1
      Solver/Credit/CreditHistorySolver.php
  28. +1
    -1
      Solver/Order/OrderPaymentSolver.php

+ 10
- 1
Container/Credit/CreditHistoryContainer.php Näytä tiedosto

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Container\Credit;

use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder;
use Lc\CaracoleBundle\Definition\Field\Credit\CreditHistoryFieldDefinition;
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepositoryQuery;
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryStore;
@@ -15,19 +16,22 @@ class CreditHistoryContainer
protected CreditHistoryStore $store;
protected CreditHistoryBuilder $builder;
protected CreditHistorySolver $solver;
protected CreditHistoryFieldDefinition $fieldDefinition;

public function __construct(
CreditHistoryFactory $factory,
CreditHistoryRepositoryQuery $repositoryQuery,
CreditHistorySolver $solver,
CreditHistoryStore $store,
CreditHistoryBuilder $builder
CreditHistoryBuilder $builder,
CreditHistoryFieldDefinition $fieldDefinition
) {
$this->factory = $factory;
$this->repositoryQuery = $repositoryQuery;
$this->solver = $solver;
$this->store = $store;
$this->builder = $builder;
$this->fieldDefinition = $fieldDefinition;
}

public function getFactory(): CreditHistoryFactory
@@ -54,4 +58,9 @@ class CreditHistoryContainer
{
return $this->builder;
}

public function getFieldDefinition(): CreditHistoryFieldDefinition
{
return $this->fieldDefinition;
}
}

+ 11
- 2
Container/User/UserMerchantContainer.php Näytä tiedosto

@@ -3,6 +3,7 @@
namespace Lc\CaracoleBundle\Container\User;

use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder;
use Lc\CaracoleBundle\Definition\Field\User\UserMerchantFieldDefinition;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Repository\User\UserMerchantRepositoryQuery;
use Lc\CaracoleBundle\Repository\User\UserMerchantStore;
@@ -15,19 +16,22 @@ class UserMerchantContainer
protected UserMerchantRepositoryQuery $repositoryQuery;
protected UserMerchantStore $store;
protected UserMerchantBuilder $builder;
protected UserMerchantFieldDefinition $fieldDefinition;

public function __construct(
UserMerchantFactory $factory,
UserMerchantSolver $solver,
UserMerchantRepositoryQuery $repositoryQuery,
UserMerchantStore $store,
UserMerchantBuilder $builder
UserMerchantBuilder $builder,
UserMerchantFieldDefinition $fieldDefinition
) {
$this->factory = $factory;
$this->solver = $solver;
$this->repositoryQuery = $repositoryQuery;
$this->store = $store;
$this->builder = $builder;
$this->fieldDefinition = $fieldDefinition;
}

public function getFactory(): UserMerchantFactory
@@ -55,4 +59,9 @@ class UserMerchantContainer
return $this->builder;
}

}
public function getFieldDefinition(): UserMerchantFieldDefinition
{
return $this->fieldDefinition;
}

}

+ 35
- 79
Controller/Credit/CreditHistoryAdminController.php Näytä tiedosto

@@ -3,40 +3,36 @@
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\Config\KeyValueStore;
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\NumberField;
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\Controller\AbstractAdminController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
use Lc\CaracoleBundle\Model\Order\OrderPaymentModel;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\CaracoleBundle\Solver\Credit\CreditHistorySolver;
use Lc\CaracoleBundle\Solver\Order\OrderPaymentSolver;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;

abstract class CreditHistoryAdminController extends AbstractAdminController
{
use AdminControllerTrait;

public function getRepositoryQuery() :RepositoryQueryInterface
public function getRepositoryQuery(): RepositoryQueryInterface
{
return $this->get(CreditHistoryContainer::class)->getRepositoryQuery();
}
@@ -62,14 +58,7 @@ abstract class CreditHistoryAdminController extends AbstractAdminController

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
return $this->get(CreditHistoryContainer::class)->getFactory()->createBase($this->getUserMerchant());
}

protected function getUserMerchant(): UserMerchantInterface
@@ -82,11 +71,22 @@ abstract class CreditHistoryAdminController extends AbstractAdminController

public function configureActions(Actions $actions): Actions
{
$actions->disable(ActionDefinition::DELETE, ActionDefinition::EDIT);
$actions = parent::configureActions($actions);
$actions->disable(ActionDefinition::DELETE, ActionDefinition::EDIT, ActionDefinition::DUPLICATE);

return parent::configureActions($actions); // TODO: Change the autogenerated stub
return $actions;
}

public function persistEntity(EntityManagerInterface $entityManager, $entityInstance): void
{
if ($this->get(CreditHistoryContainer::class)->getBuilder()->save($entityInstance)) {
$this->addFlashTranslator('success', 'saveCreditHistory');
} else {
$this->addFlashTranslator('error', 'saveCreditHistory');
}
}


public function configureCrud(Crud $crud): Crud
{
$crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig');
@@ -94,78 +94,34 @@ abstract class CreditHistoryAdminController extends AbstractAdminController
return $crud;
}

public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
{
$responseParameters = parent::configureResponseParameters($responseParameters);

$responseParameters->set('user_merchant', $this->getUserMerchant());
return $responseParameters;
}

public function configureFields(string $pageName): iterable
{
$translatorAdmin = $this->get(TranslatorAdmin::class);
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.' . OrderPaymentModel::MEAN_PAYMENT_CASH,
'CreditHistory'
) => OrderPaymentModel::MEAN_PAYMENT_CASH,

$translatorAdmin->transField(
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CHEQUE,
'CreditHistory'
) => OrderPaymentModel::MEAN_PAYMENT_CHEQUE,

$translatorAdmin->transField(
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT,
'CreditHistory'
) => OrderPaymentModel::MEAN_PAYMENT_CREDIT,

$translatorAdmin->transField(
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD,
'CreditHistory'
) => OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD,

$translatorAdmin->transField(
'meanPaymentOptions.' . OrderPaymentModel::MEAN_PAYMENT_TRANSFER,
'CreditHistory'
) => OrderPaymentModel::MEAN_PAYMENT_TRANSFER,
)
),
TextField::new('reference'),
TextField::new('comment'),
];
return $this->getCreditHistoryContainer()->getFieldDefinition()->getFields($pageName);

}

public function createIndexQueryBuilder(
public function createIndexRepositoryQuery(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): QueryBuilder {

$queryBuilder = parent::createIndexQueryBuilder(
): RepositoryQueryInterface {
$repositoryQuery = parent::createIndexRepositoryQuery(
$searchDto,
$entityDto,
$fields,
$filters
);
$repositoryQuery->filterByUserMerchant($this->getUserMerchant());

$queryBuilder->andWhere('entity.userMerchant = :userMerchant');
$queryBuilder->setParameter('userMerchant', $searchDto->getRequest()->get('userMerchantId'));

return $queryBuilder;
return $repositoryQuery;
}
}

+ 7
- 13
Controller/User/UserAdminController.php Näytä tiedosto

@@ -2,18 +2,12 @@

namespace Lc\CaracoleBundle\Controller\User;

use App\Entity\Address;
use App\Form\Backend\Common\AddressType;

use EasyCorp\Bundle\EasyAdminBundle\Config\Crud;
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter;
use Lc\CaracoleBundle\Container\Address\AddressContainer;
use Lc\CaracoleBundle\Controller\ControllerTrait;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\CaracoleBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Symfony\Component\HttpFoundation\Response;

abstract class UserAdminController extends AbstractAdminController
{
@@ -31,13 +25,12 @@ abstract class UserAdminController extends AbstractAdminController

public function configureFields(string $pageName): iterable
{

$fields = $this->get(UserContainer::class)
->getFieldDefinition()
->setMerchant($this->getMerchantCurrent())
->getAllFields();

if($pageName == Crud::PAGE_INDEX){
if ($pageName == Crud::PAGE_INDEX) {
return [
$fields['id'],
$fields['gender'],
@@ -50,8 +43,8 @@ abstract class UserAdminController extends AbstractAdminController
$fields['isSaleAlwaysOpen'],
$fields['newsletters']
];
}elseif($pageName == Crud::PAGE_EDIT || $pageName == Crud::PAGE_NEW){
$fieldToReturn = [
} elseif ($pageName == Crud::PAGE_EDIT || $pageName == Crud::PAGE_NEW) {
$fieldToReturn = [
$fields['id'],
$fields['gender'],
$fields['lastname'],
@@ -64,13 +57,14 @@ abstract class UserAdminController extends AbstractAdminController
$fields['newsletters']
];

if($this->isGranted('ROLE_SUPER_ADMIN')){
if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$fieldToReturn[] = $fields['roles'];
}
return $fieldToReturn;
} elseif ($pageName == Crud::PAGE_DETAIL) {
return [$fields['id']];
}
}



}

+ 119
- 144
Controller/User/UserMerchantAdminController.php Näytä tiedosto

@@ -2,42 +2,34 @@

namespace Lc\CaracoleBundle\Controller\User;

use App\Controller\Credit\CreditHistoryAdminController;
use Doctrine\ORM\EntityManagerInterface;
use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection;
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\Config\Filters;
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Event\BeforeCrudActionEvent;
use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException;
use EasyCorp\Bundle\EasyAdminBundle\Field\ArrayField;
use EasyCorp\Bundle\EasyAdminBundle\Field\AssociationField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use EasyCorp\Bundle\EasyAdminBundle\Filter\BooleanFilter;
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
use Lc\CaracoleBundle\Controller\ControllerTrait;
use Lc\CaracoleBundle\Controller\AbstractAdminController;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Factory\User\UserFactory;
use Lc\CaracoleBundle\Form\Credit\CreditHistoryFormType;
use Lc\CaracoleBundle\Form\User\UserMerchantFormType;
use Lc\CaracoleBundle\Form\User\UserMerchantActiveCreditFormType;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\SovBundle\Container\User\UserContainer;
use Lc\SovBundle\Controller\AbstractAdminController;
use Lc\SovBundle\Field\BooleanField;
use Lc\SovBundle\Repository\RepositoryQueryInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\Response;

abstract class UserMerchantAdminController extends AbstractAdminController
{
use ControllerTrait;

public function getRepositoryQuery(): RepositoryQueryInterface
{
@@ -49,6 +41,17 @@ abstract class UserMerchantAdminController extends AbstractAdminController
return $this->getUserMerchantContainer()->getFactory()->createBase($this->getMerchantCurrent());
}

public function createIndexRepositoryQuery(
SearchDto $searchDto,
EntityDto $entityDto,
FieldCollection $fields,
FilterCollection $filters
): RepositoryQueryInterface {
$repositoryQuery = parent::createIndexRepositoryQuery($searchDto, $entityDto, $fields, $filters);
$repositoryQuery->filterIsCreditActive();
return $repositoryQuery;
}

public function overrideEntitiesActions(?EntityCollection $entities): void
{
$context = $this->get(AdminContextProvider::class)->getContext();
@@ -87,27 +90,19 @@ abstract class UserMerchantAdminController extends AbstractAdminController
)
->setCssClass('btn btn-sm btn-success');
$actions->add(Crud::PAGE_INDEX, $creditAction);
$actions->disable(
ActionDefinition::EDIT,
ActionDefinition::DUPLICATE,
ActionDefinition::DELETE,
ActionDefinition::DUPLICATE_TO_OTHER_MERCHANT
);

return $actions;
}

public function configureFields(string $pageName): iterable
{
$fields = [
IntegerField::new('id')->onlyOnIndex()->setSortable(true),
TextField::new('user.lastname')->setSortable(true),
TextField::new('user.firstname')->setSortable(true),
TextField::new('user.email')->setSortable(true),
BooleanField::new('active')->setSortable(true),
BooleanField::new('creditActive')->hideOnIndex(),
AssociationField::new('user'),
];

if ($this->isGranted('ROLE_SUPER_ADMIN')) {
$fields[] = ArrayField::new('roles');
}

return $fields;
return $this->getUserMerchantContainer()->getFieldDefinition()->getFields($pageName);
}

public function configureFilters(Filters $filters): Filters
@@ -125,137 +120,117 @@ abstract class UserMerchantAdminController extends AbstractAdminController
->getFactory()
->create($merchantResolver->getCurrent());

$form = $this->createForm(UserMerchantFormType::class, $userMerchant);

$form->handleRequest($context->getRequest());

if ($form->isSubmitted() && $form->isValid()) {
$userMerchant = $form->getData();

$existingUser = $this->get(UserContainer::class)->getStore()->getOneByEmail($form->get('email')->getData());
//Le user n'existe pas, on le créer
if ($existingUser == null) {
$param['email'] = $form->get('email')->getData();
$param['lastname'] = $form->get('lastname')->getData();
$param['lastname'] = $form->get('firstname')->getData();
$param['roles'] = array();

// @TODO : à adapter l'array de valeur passer au factory
$userFactory = new UserFactory();
$user = $userFactory->create($param);

$entityManager->create($user);
$userMerchant->setUser($user);
$entityManager->create($userMerchant);
$entityManager->flush();
$this->addFlashTranslator('success', 'created');
$url = $this->get(AdminUrlGenerator::class)->setAction(ActionDefinition::INDEX)->generateUrl();

return $this->redirect($url);
} else {
//Le user existe, on vérifie si le usemerchant existe aussi
$existingUserMerchant = $merchantResolver->getUserMerchant($existingUser);
if ($existingUserMerchant == null) {
$userMerchant->setUser($existingUser);
$entityManager->create($userMerchant);
$entityManager->flush();

$this->addFlashTranslator('success', 'linked');
$url = $this->get(AdminUrlGenerator::class)->setAction(ActionDefinition::INDEX)->generateUrl();

return $this->redirect($url);
} else {
$this->addFlashTranslator('error', 'already_exist');
}
}
}

return $this->render(
'@LcCaracole/admin/user/new_usermerchant.html.twig',
[
'form' => $form->createView(),
]
$form = $this->createForm(
UserMerchantActiveCreditFormType::class,
$userMerchant,
array(
'merchant' => $this->getMerchantCurrent()
)
);
}


public function edit(AdminContext $context): Response
{
$entityManager = $this->get(EntityManagerInterface::class);

$userMerchant = $context->getEntity()->getInstance();

$form = $this->createForm(UserMerchantFormType::class, $userMerchant);

$form->handleRequest($context->getRequest());

if ($form->isSubmitted() && $form->isValid()) {
$userMerchant = $form->getData();

$userMerchant->getUser()->setEmail($form->get('email')->getData());
$userMerchant->getUser()->setLastName($form->get('lastname')->getData());
$userMerchant->getUser()->setFirstname($form->get('firstname')->getData());

$user = $form->get('user')->getData();
$userMerchant = $merchantResolver->getUserMerchant($user);
$userMerchant->setCreditActive(true);
$entityManager->update($userMerchant);
$entityManager->update($userMerchant->getUser());
$entityManager->flush();
$this->addFlashTranslator('success', 'updated');
$url = $this->get(AdminUrlGenerator::class)->setAction(ActionDefinition::INDEX)->generateUrl();

return $this->redirect($url);
} else {
$form->get('email')->setData($userMerchant->getUser()->getEmail());
$form->get('lastname')->setData($userMerchant->getUser()->getLastname());
$form->get('firstname')->setData($userMerchant->getUser()->getFirstname());
$this->addFlashTranslator('success', 'creditActive');

return $this->redirect($this->generateEaUrl(CreditHistoryAdminController::class, ActionDefinition::INDEX, null, array(
'userMerchantId'=> $userMerchant->getId()
)));
}

return $this->render(
'@LcCaracole/admin/user/edit_usermerchant.html.twig',
'@LcCaracole/admin/user/new_usermerchant.html.twig',
[
'form' => $form->createView(),
]
);
}

public function credit(AdminContext $context, AdminUrlGenerator $adminUrlGenerator): Response
{
$event = new BeforeCrudActionEvent($context);
$this->get('event_dispatcher')->dispatch($event);
if ($event->isPropagationStopped()) {
return $event->getResponse();
}

if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => ActionDefinition::DETAIL, 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}
if (!$context->getEntity()->isAccessible()) {
throw new InsufficientEntityPermissionException($context);
}

$options['action'] = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())
->setAction('add_credit')
->setEntityId($context->getEntity()->getInstance()->getId())
->set('userMerchant', 'niche')
->generateUrl();
$addCreditHistoryForm = $this->createForm(CreditHistoryFormType::class, null, $options)->createView();


return $this->render(
'@LcCaracole/admin/credit/credit_detail.html.twig',
[
'pageName' => Crud::PAGE_DETAIL,
'entity' => $context->getEntity(),
'batch_actions' => array(),
'entities' => array(),
'filters' => array(),
'paginator' => array(),
'add_credit_history_form' => $addCreditHistoryForm,
]
);
}
// public function edit(AdminContext $context): Response
// {
// $entityManager = $this->get(EntityManagerInterface::class);
//
// $userMerchant = $context->getEntity()->getInstance();
//
// $form = $this->createForm(UserMerchantFormType::class, $userMerchant);
//
// $form->handleRequest($context->getRequest());
//
// if ($form->isSubmitted() && $form->isValid()) {
// $userMerchant = $form->getData();
//
// $userMerchant->getUser()->setEmail($form->get('email')->getData());
// $userMerchant->getUser()->setLastName($form->get('lastname')->getData());
// $userMerchant->getUser()->setFirstname($form->get('firstname')->getData());
//
// $entityManager->update($userMerchant);
// $entityManager->update($userMerchant->getUser());
// $entityManager->flush();
// $this->addFlashTranslator('success', 'updated');
// $url = $this->get(AdminUrlGenerator::class)->setAction(ActionDefinition::INDEX)->generateUrl();
//
// return $this->redirect($url);
// } else {
// $form->get('email')->setData($userMerchant->getUser()->getEmail());
// $form->get('lastname')->setData($userMerchant->getUser()->getLastname());
// $form->get('firstname')->setData($userMerchant->getUser()->getFirstname());
// }
//
// return $this->render(
// '@LcCaracole/admin/user/edit_usermerchant.html.twig',
// [
// 'form' => $form->createView(),
// ]
// );
// }

// public function credit(AdminContext $context, AdminUrlGenerator $adminUrlGenerator): Response
// {
// $event = new BeforeCrudActionEvent($context);
// $this->get('event_dispatcher')->dispatch($event);
// if ($event->isPropagationStopped()) {
// return $event->getResponse();
// }
//
// if (!$this->isGranted(
// Permission::EA_EXECUTE_ACTION,
// ['action' => ActionDefinition::DETAIL, 'entity' => $context->getEntity()]
// )) {
// throw new ForbiddenActionException($context);
// }
// if (!$context->getEntity()->isAccessible()) {
// throw new InsufficientEntityPermissionException($context);
// }
//
// $options['action'] = $adminUrlGenerator
// ->setController($context->getCrud()->getControllerFqcn())
// ->setAction('add_credit')
// ->setEntityId($context->getEntity()->getInstance()->getId())
// ->set('userMerchant', 'niche')
// ->generateUrl();
// $addCreditHistoryForm = $this->createForm(CreditHistoryFormType::class, null, $options)->createView();
//
//
// return $this->render(
// '@LcCaracole/admin/credit/credit_detail.html.twig',
// [
// 'pageName' => Crud::PAGE_DETAIL,
// 'entity' => $context->getEntity(),
// 'batch_actions' => array(),
// 'entities' => array(),
// 'filters' => array(),
// 'paginator' => array(),
// 'add_credit_history_form' => $addCreditHistoryForm,
// ]
// );
// }

}

+ 2
- 0
Definition/ActionDefinition.php Näytä tiedosto

@@ -7,5 +7,7 @@ class ActionDefinition extends SovActionDefinition{

public const DUPLICATE_TO_OTHER_MERCHANT = 'duplicateToOtherMerchant';
public const DUPLICATE_TO_OTHER_SECTION = 'duplicateToOtherSection';
public const EDIT_ADDRESS_USER = 'editAddressUser';


}

+ 80
- 0
Definition/Field/Credit/CreditHistoryFieldDefinition.php Näytä tiedosto

@@ -0,0 +1,80 @@
<?php

namespace Lc\CaracoleBundle\Definition\Field\Credit;

use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField;
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField;
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Context\MerchantContextTrait;
use Lc\CaracoleBundle\Solver\Credit\CreditHistorySolver;
use Lc\CaracoleBundle\Solver\Order\OrderPaymentSolver;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;

class CreditHistoryFieldDefinition extends AbstractFieldDefinition
{
use MerchantContextTrait;

public function configureIndex(): array
{
return [
'id',
'type',
'amount',
'paidAt',
'meanPayment',
'reference',
'comment',
];
}

public function configureForm(): array
{
return [
'type',
'amount',
'paidAt',
'meanPayment',
'reference',
'comment',
];
}

public function configureFields(): array
{
return [
'id' => IdField::new('id')->hideOnForm(),
'type' => ChoiceField::new('type')
->setChoices(
$this->translatorAdmin->transChoices(
CreditHistorySolver::getTypeChoices(),
'CreditHistory',
'type'
)
),
'amount' => NumberField::new('amount')
->setTemplatePath('@LcCaracole/admin/credit/field/amount.html.twig')
->setCustomOption('appendHtml', '&euro;'),
'paidAt' => DateField::new('paidAt')->setFormTypeOption('required', true)
->setTemplatePath('@LcCaracole/admin/credit/field/paidAt.html.twig'),
'meanPayment' => ChoiceField::new('meanPayment')
->setChoices(
$this->translatorAdmin->transChoices(
OrderPaymentSolver::getMeanPaymentChoices(),
'OrderPayment',
'meanPayment'
)
)->setFormTypeOption('required', true)
->setTemplatePath('@LcCaracole/admin/credit/field/meanPayment.html.twig'),
'reference' => TextField::new('reference')
->setTemplatePath('@LcCaracole/admin/credit/field/reference.html.twig'),
'comment' => TextField::new('comment')
->setTemplatePath('@LcCaracole/admin/credit/field/comment.html.twig'),

];
}

}



+ 52
- 0
Definition/Field/User/UserMerchantFieldDefinition.php Näytä tiedosto

@@ -0,0 +1,52 @@
<?php

namespace Lc\CaracoleBundle\Definition\Field\User;

use EasyCorp\Bundle\EasyAdminBundle\Field\IntegerField;
use EasyCorp\Bundle\EasyAdminBundle\Field\NumberField;
use EasyCorp\Bundle\EasyAdminBundle\Field\TextField;
use Lc\CaracoleBundle\Context\MerchantContextTrait;
use Lc\CaracoleBundle\Field\AssociationField;
use Lc\SovBundle\Definition\Field\AbstractFieldDefinition;



class UserMerchantFieldDefinition extends AbstractFieldDefinition
{
use MerchantContextTrait;

public function configureIndex(): array
{
return [
'id',
'lastname',
'firstname',
'email',
'credit',
];
}

public function configureForm(): array
{
return [
'user',
];
}

public function configureFields(): array
{

return [
'id'=> IntegerField::new('id')->onlyOnIndex()->setSortable(true),
'lastname'=> TextField::new('user.lastname')->setSortable(true),
'firstname'=> TextField::new('user.firstname')->setSortable(true),
'email'=> TextField::new('user.email')->setSortable(true),
'credit'=> NumberField::new('credit')->setSortable(true)
->setTemplatePath('@LcSov/adminlte/crud/field/amount.html.twig')
->setCustomOption('appendHtml', '&euro;'),
'user'=> AssociationField::new('user'),

];
}

}

+ 1
- 1
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php Näytä tiedosto

@@ -145,4 +145,4 @@ class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface
}
}
}*/
}
}

+ 9
- 2
Factory/Credit/CreditHistoryFactory.php Näytä tiedosto

@@ -11,11 +11,18 @@ use Lc\SovBundle\Model\User\UserInterface;
class CreditHistoryFactory extends AbstractFactory
{
// createCreditHistory
public function create(string $type, UserMerchantInterface $userMerchant): CreditHistoryInterface
public function create(string $type,UserMerchantInterface $userMerchant ): CreditHistoryInterface
{
$creditHistory = new CreditHistory();
$creditHistory = $this->createBase($userMerchant);

$creditHistory->setType($type) ;

return $creditHistory;
}

public function createBase(UserMerchantInterface $userMerchant): CreditHistoryInterface
{
$creditHistory = new CreditHistory();
$creditHistory->setUserMerchant($userMerchant) ;

return $creditHistory;

+ 1
- 1
Field/Filter/ProductCategoriesFilter.php Näytä tiedosto

@@ -39,7 +39,7 @@ class ProductCategoriesFilter extends AssociationFilter
}


public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, $filteredValue = null)
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, string $fieldProperty, $filteredValue = null)
{
if ($filteredValue !== null) {
$repositoryQuery->filterByProductCategory($filteredValue);

Form/User/UserMerchantFormType.php → Form/User/UserMerchantActiveCreditFormType.php Näytä tiedosto

@@ -2,11 +2,14 @@

namespace Lc\CaracoleBundle\Form\User;

use App\Entity\User\User;
use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
use Lc\CaracoleBundle\Repository\User\UserStore;
use Lc\SovBundle\Definition\RolesDefinitionInterface;
use Lc\SovBundle\Doctrine\EntityManager;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
@@ -17,67 +20,34 @@ use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface;

class UserMerchantFormType extends AbstractType
use function Symfony\Component\Translation\t;

class UserMerchantActiveCreditFormType extends AbstractType
{
protected $em;
protected $rolesDefinition;
protected $translatorAdmin;
protected $authorizationChecker;
protected EntityManager $entityManager;
protected UserStore $userStore;
protected TranslatorAdmin $translatorAdmin;

public function __construct(
EntityManager $em,
EntityManager $entityManager,
TranslatorAdmin $translatorAdmin,
RolesDefinitionInterface $rolesDefinition,
AuthorizationCheckerInterface $authorizationChecker
UserStore $userStore
) {
$this->em = $em;
$this->rolesDefinition = $rolesDefinition;
$this->entityManager = $entityManager;
$this->translatorAdmin = $translatorAdmin;
$this->authorizationChecker = $authorizationChecker;
$this->userStore = $userStore;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$entityName = $this->em->getEntityName(UserInterface::class);

$builder->add(
'firstname',
TextType::class,
array(
'mapped' => false,
)
);

$builder->add(
'lastname',
TextType::class,
array(
'mapped' => false,
)
);

$builder->add(
'email',
EmailType::class,
array(
'mapped' => false,
)
);

$builder->add(
'creditActive',
CheckboxType::class,
array(
'required' => false,
)
);

$builder->add(
'roles',
ChoiceType::class,
'user',
EntityType::class,
array(
'choices' => $this->rolesDefinition->getRolesList(),
'multiple' => true,
'class'=> $this->entityManager->getEntityName(UserInterface::class),
'choices'=> $this->userStore->setMerchant($options['merchant'])->get()
)

);
@@ -99,7 +69,8 @@ class UserMerchantFormType extends AbstractType
{
$resolver->setDefaults(
[
'data_class' => $this->em->getEntityName(UserMerchantInterface::class),
'data_class' => $this->entityManager->getEntityName(UserMerchantInterface::class),
'merchant' => null,
]
);
}

+ 1
- 4
Model/Credit/CreditHistoryInterface.php Näytä tiedosto

@@ -15,10 +15,7 @@ use Lc\SovBundle\Doctrine\Extension\DevAliasTrait;
use Lc\SovBundle\Doctrine\Extension\TimestampableTrait;
use Lc\SovBundle\Model\User\UserInterface;

/**
* @ORM\MappedSuperclass()
*/
interface CreditHistoryInterface
{

}
}

+ 1
- 0
Repository/Credit/CreditHistoryRepositoryQuery.php Näytä tiedosto

@@ -57,4 +57,5 @@ class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery
->andWhere('.createdAt <= :dateEnd')
->setParameter(':dateEnd', $dateEnd);
}

}

+ 2
- 8
Repository/Order/OrderShopRepositoryQuery.php Näytä tiedosto

@@ -2,15 +2,9 @@

namespace Lc\CaracoleBundle\Repository\Order;

use App\Entity\Delivery\DeliveryAvailabilityPointSale;
use App\Entity\Delivery\DeliveryAvailabilityZone;
use App\Entity\PointSale\PointSale;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
use Lc\CaracoleBundle\Model\User\VisitorInterface;
@@ -44,7 +38,7 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
{
return $this
->select(
'SUM(r.statTotalWithTax) as total'
'SUM(DISTINCT(r.statTotalWithTax)) as total'
);
}

@@ -86,7 +80,7 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
public function selectCount(): self
{
return $this
->select('count(r.id) as total');
->select('count(DISTINCT(r.id)) as total');
}

public function filterByUser(UserInterface $user): self

+ 4
- 1
Repository/Order/OrderShopStore.php Näytä tiedosto

@@ -237,8 +237,9 @@ class OrderShopStore extends AbstractStore
UserInterface $user = null,
$query = null
): int {
$query = $this->createDefaultQuery($query);

//TODO vérifier que ne pas utiliser createDefaultQuery est pertinent
$query = $this->createQuery($query);
if ($user) {
$query->filterByUser($user);
}
@@ -340,7 +341,9 @@ class OrderShopStore extends AbstractStore
{
$query = $this->createDefaultQuery($query);
$query->selectCount();

$this->applyGetByFilters($params, $query);

return $query->count();
}


+ 6
- 0
Repository/User/UserMerchantRepositoryQuery.php Näytä tiedosto

@@ -22,4 +22,10 @@ class UserMerchantRepositoryQuery extends AbstractRepositoryQuery
->andWhere('.user = :user')
->setParameter('user', $user);
}

public function filterIsCreditActive()
{
return $this
->andWhere('.creditActive = 1');
}
}

+ 1
- 0
Resolver/MerchantResolver.php Näytä tiedosto

@@ -112,6 +112,7 @@ class MerchantResolver
$merchant = $this->getCurrent();
}

//TODO Pas de REPO !!!!!
return $this->userMerchantRepository->findOneBy(
[
'user' => $user,

+ 11
- 5
Resources/translations/admin.fr.yaml Näytä tiedosto

@@ -11,7 +11,7 @@ menu:
admin_section: Sections
admin_tva: TVA
admin_unit: Unités
user_merchant_index: Utilisateurs
user_merchant_index: Comptes prépayés
group_user_index: Groupes d'utilisateurs


@@ -28,6 +28,7 @@ action:
duplicateToOtherSection: Dupliquer sur une autre section
editProductFamily: Éditer le produit
history: Historique
credit: Voir l'historique de crédit

setting_definition:
merchant:
@@ -110,14 +111,15 @@ entity:
label: Règle de taxe
label_plurial: Règles de taxes
UserMerchant:
label: Utilisateur
label_plurial: Utilisateurs
label: Utilisateur avec compte prépayé actif
label_plurial: Utilisateurs avec comptes prépayés actifs
fields:
user:
email: Email
lastname: Nom
firstname: Prénom
creditActive: Crédit activer
credit: Montant du compte prépayé
User:
fields:
isSaleAlwaysOpen: Vente toujours ouverte
@@ -127,7 +129,7 @@ entity:
label_plurial: Historiques de compte prépayé
fields:
type: Type
typeOptions:
typeChoices:
credit: Crédit
debit: Débit
amount: Montant
@@ -141,7 +143,11 @@ entity:
paidAt: Date de transaction
reference: Référence
comment: Commentaire

flashes:
success:
saveCreditHistory: La ligne de crédit/débit a bien été ajouté
error:
saveCreditHistory: Une erreur est survenue à l'ajout de crédit/débit
OrderShop:
fields:
deliveryInfos: |

+ 6
- 0
Resources/views/admin/credit/field/amount.html.twig Näytä tiedosto

@@ -0,0 +1,6 @@
{% set item = entity.instance %}
{% if item.orderPayment is not null %}
{% include '@LcSov/adminlte/crud/field/amount.html.twig' with {value : item.orderPayment.amount} %}
{% else %}
{% include '@LcSov/adminlte/crud/field/amount.html.twig' with {value : item.amount} %}
{% endif %}

+ 6
- 0
Resources/views/admin/credit/field/comment.html.twig Näytä tiedosto

@@ -0,0 +1,6 @@
{% set item = entity.instance %}
{% if item.orderPayment is not null %}
{{ item.orderPayment.comment }}
{% else %}
{{ item.comment }}
{% endif %}

+ 6
- 0
Resources/views/admin/credit/field/meanPayment.html.twig Näytä tiedosto

@@ -0,0 +1,6 @@
{% set item = entity.instance %}
{% if item.orderPayment is not null %}
{{ item.orderPayment.meanPayment|sov_trans_admin_choice('meanPayment', 'OrderPayment') }}
{% else %}
{{ item.meanPayment|sov_trans_admin_choice('meanPayment', 'OrderPayment') }}
{% endif %}

+ 6
- 0
Resources/views/admin/credit/field/paidAt.html.twig Näytä tiedosto

@@ -0,0 +1,6 @@
{% set item = entity.instance %}
{% if item.orderPayment is not null %}
{{ item.orderPayment.paidAt|date('Y/m/d h:i') }}
{% else %}
{{ item.paidAt|date('Y/m/d h:i') }}
{% endif %}

+ 6
- 0
Resources/views/admin/credit/field/reference.html.twig Näytä tiedosto

@@ -0,0 +1,6 @@
{% set item = entity.instance %}
{% if item.orderPayment is not null %}
{{ item.orderPayment.reference }}
{% else %}
{{ item.reference }}
{% endif %}

+ 9
- 2
Resources/views/admin/credit/index_credithistory.html.twig Näytä tiedosto

@@ -2,5 +2,12 @@

{% block content_title %}
{{ 'index'|sov_trans_admin_title(ea.getEntity().getFqcn()) }}
Info de Fab
{% endblock %}
<br />
{{ user_merchant.user }}

{% endblock %}

{% block page_actions %}
{{ parent() }}
<h4>Créduit actuel : {{ user_merchant.credit|format_price|raw }}</h4>
{% endblock %}

+ 4
- 2
Resources/views/admin/order/field/order_status.html.twig Näytä tiedosto

@@ -1,2 +1,4 @@
{% set value = field.value %}
<span class="badge badge-{{ value.color is defined ? value.color : entity.instance.orderStatus.color }}">{{ value }}</span>
{% if value is not defined %}
{% set value = field.value %}
{% endif %}
<span class="badge badge-{{ value.color is defined ? value.color : value.color }}">{{ value }}</span>

+ 12
- 1
Solver/Credit/CreditHistorySolver.php Näytä tiedosto

@@ -4,8 +4,19 @@ namespace Lc\CaracoleBundle\Solver\Credit;

use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;

use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;

use function Clue\StreamFilter\remove;

class CreditHistorySolver
{
public static function getTypeChoices() :array
{
return[
CreditHistoryModel::TYPE_CREDIT,
CreditHistoryModel::TYPE_DEBIT,
];
}
public function getMeanPaymentInheritedLabel(CreditHistoryInterface $creditHistory): string
{
return 'entity.CreditHistory.fields.meanPaymentOptions.' . $this->getMeanPaymentInherited($creditHistory);
@@ -75,4 +86,4 @@ class CreditHistorySolver
}
}
}
}
}

+ 1
- 1
Solver/Order/OrderPaymentSolver.php Näytä tiedosto

@@ -7,7 +7,7 @@ use Lc\CaracoleBundle\Model\Order\OrderPaymentModel;
class OrderPaymentSolver
{

public function getMeanPaymentChoices()
public static function getMeanPaymentChoices()
{
return [
OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD,

Loading…
Peruuta
Tallenna