namespace Lc\CaracoleBundle\Container\Credit; | namespace Lc\CaracoleBundle\Container\Credit; | ||||
use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder; | use Lc\CaracoleBundle\Builder\Credit\CreditHistoryBuilder; | ||||
use Lc\CaracoleBundle\Definition\Field\Credit\CreditHistoryFieldDefinition; | |||||
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory; | use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory; | ||||
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepositoryQuery; | use Lc\CaracoleBundle\Repository\Credit\CreditHistoryRepositoryQuery; | ||||
use Lc\CaracoleBundle\Repository\Credit\CreditHistoryStore; | use Lc\CaracoleBundle\Repository\Credit\CreditHistoryStore; | ||||
protected CreditHistoryStore $store; | protected CreditHistoryStore $store; | ||||
protected CreditHistoryBuilder $builder; | protected CreditHistoryBuilder $builder; | ||||
protected CreditHistorySolver $solver; | protected CreditHistorySolver $solver; | ||||
protected CreditHistoryFieldDefinition $fieldDefinition; | |||||
public function __construct( | public function __construct( | ||||
CreditHistoryFactory $factory, | CreditHistoryFactory $factory, | ||||
CreditHistoryRepositoryQuery $repositoryQuery, | CreditHistoryRepositoryQuery $repositoryQuery, | ||||
CreditHistorySolver $solver, | CreditHistorySolver $solver, | ||||
CreditHistoryStore $store, | CreditHistoryStore $store, | ||||
CreditHistoryBuilder $builder | |||||
CreditHistoryBuilder $builder, | |||||
CreditHistoryFieldDefinition $fieldDefinition | |||||
) { | ) { | ||||
$this->factory = $factory; | $this->factory = $factory; | ||||
$this->repositoryQuery = $repositoryQuery; | $this->repositoryQuery = $repositoryQuery; | ||||
$this->solver = $solver; | $this->solver = $solver; | ||||
$this->store = $store; | $this->store = $store; | ||||
$this->builder = $builder; | $this->builder = $builder; | ||||
$this->fieldDefinition = $fieldDefinition; | |||||
} | } | ||||
public function getFactory(): CreditHistoryFactory | public function getFactory(): CreditHistoryFactory | ||||
{ | { | ||||
return $this->builder; | return $this->builder; | ||||
} | } | ||||
public function getFieldDefinition(): CreditHistoryFieldDefinition | |||||
{ | |||||
return $this->fieldDefinition; | |||||
} | |||||
} | } |
namespace Lc\CaracoleBundle\Container\User; | namespace Lc\CaracoleBundle\Container\User; | ||||
use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder; | use Lc\CaracoleBundle\Builder\User\UserMerchantBuilder; | ||||
use Lc\CaracoleBundle\Definition\Field\User\UserMerchantFieldDefinition; | |||||
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory; | use Lc\CaracoleBundle\Factory\User\UserMerchantFactory; | ||||
use Lc\CaracoleBundle\Repository\User\UserMerchantRepositoryQuery; | use Lc\CaracoleBundle\Repository\User\UserMerchantRepositoryQuery; | ||||
use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | use Lc\CaracoleBundle\Repository\User\UserMerchantStore; | ||||
protected UserMerchantRepositoryQuery $repositoryQuery; | protected UserMerchantRepositoryQuery $repositoryQuery; | ||||
protected UserMerchantStore $store; | protected UserMerchantStore $store; | ||||
protected UserMerchantBuilder $builder; | protected UserMerchantBuilder $builder; | ||||
protected UserMerchantFieldDefinition $fieldDefinition; | |||||
public function __construct( | public function __construct( | ||||
UserMerchantFactory $factory, | UserMerchantFactory $factory, | ||||
UserMerchantSolver $solver, | UserMerchantSolver $solver, | ||||
UserMerchantRepositoryQuery $repositoryQuery, | UserMerchantRepositoryQuery $repositoryQuery, | ||||
UserMerchantStore $store, | UserMerchantStore $store, | ||||
UserMerchantBuilder $builder | |||||
UserMerchantBuilder $builder, | |||||
UserMerchantFieldDefinition $fieldDefinition | |||||
) { | ) { | ||||
$this->factory = $factory; | $this->factory = $factory; | ||||
$this->solver = $solver; | $this->solver = $solver; | ||||
$this->repositoryQuery = $repositoryQuery; | $this->repositoryQuery = $repositoryQuery; | ||||
$this->store = $store; | $this->store = $store; | ||||
$this->builder = $builder; | $this->builder = $builder; | ||||
$this->fieldDefinition = $fieldDefinition; | |||||
} | } | ||||
public function getFactory(): UserMerchantFactory | public function getFactory(): UserMerchantFactory | ||||
return $this->builder; | return $this->builder; | ||||
} | } | ||||
} | |||||
public function getFieldDefinition(): UserMerchantFieldDefinition | |||||
{ | |||||
return $this->fieldDefinition; | |||||
} | |||||
} |
namespace Lc\CaracoleBundle\Controller\Credit; | namespace Lc\CaracoleBundle\Controller\Credit; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Doctrine\ORM\QueryBuilder; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection; | use EasyCorp\Bundle\EasyAdminBundle\Collection\ActionCollection; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; | use EasyCorp\Bundle\EasyAdminBundle\Collection\FieldCollection; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; | use EasyCorp\Bundle\EasyAdminBundle\Collection\FilterCollection; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Action; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; | use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\KeyValueStore; | |||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto; | use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; | use EasyCorp\Bundle\EasyAdminBundle\Field\ChoiceField; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Field\DateField; | use EasyCorp\Bundle\EasyAdminBundle\Field\DateField; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Field\IdField; | 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\Field\TextField; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; | use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; | use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; | ||||
use Lc\CaracoleBundle\Container\Credit\CreditHistoryContainer; | use Lc\CaracoleBundle\Container\Credit\CreditHistoryContainer; | ||||
use Lc\CaracoleBundle\Container\User\UserMerchantContainer; | use Lc\CaracoleBundle\Container\User\UserMerchantContainer; | ||||
use Lc\CaracoleBundle\Controller\AdminControllerTrait; | |||||
use Lc\CaracoleBundle\Controller\AbstractAdminController; | |||||
use Lc\CaracoleBundle\Definition\ActionDefinition; | use Lc\CaracoleBundle\Definition\ActionDefinition; | ||||
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory; | |||||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | 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\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\Repository\RepositoryQueryInterface; | ||||
use Lc\SovBundle\Translation\TranslatorAdmin; | use Lc\SovBundle\Translation\TranslatorAdmin; | ||||
abstract class CreditHistoryAdminController extends AbstractAdminController | abstract class CreditHistoryAdminController extends AbstractAdminController | ||||
{ | { | ||||
use AdminControllerTrait; | |||||
public function getRepositoryQuery() :RepositoryQueryInterface | |||||
public function getRepositoryQuery(): RepositoryQueryInterface | |||||
{ | { | ||||
return $this->get(CreditHistoryContainer::class)->getRepositoryQuery(); | return $this->get(CreditHistoryContainer::class)->getRepositoryQuery(); | ||||
} | } | ||||
public function createEntity(string $entityFqcn) | 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 | protected function getUserMerchant(): UserMerchantInterface | ||||
public function configureActions(Actions $actions): Actions | 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 | public function configureCrud(Crud $crud): Crud | ||||
{ | { | ||||
$crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig'); | $crud->overrideTemplate('crud/index', '@LcCaracole/admin/credit/index_credithistory.html.twig'); | ||||
return $crud; | 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 | 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, | SearchDto $searchDto, | ||||
EntityDto $entityDto, | EntityDto $entityDto, | ||||
FieldCollection $fields, | FieldCollection $fields, | ||||
FilterCollection $filters | FilterCollection $filters | ||||
): QueryBuilder { | |||||
$queryBuilder = parent::createIndexQueryBuilder( | |||||
): RepositoryQueryInterface { | |||||
$repositoryQuery = parent::createIndexRepositoryQuery( | |||||
$searchDto, | $searchDto, | ||||
$entityDto, | $entityDto, | ||||
$fields, | $fields, | ||||
$filters | $filters | ||||
); | ); | ||||
$repositoryQuery->filterByUserMerchant($this->getUserMerchant()); | |||||
$queryBuilder->andWhere('entity.userMerchant = :userMerchant'); | |||||
$queryBuilder->setParameter('userMerchant', $searchDto->getRequest()->get('userMerchantId')); | |||||
return $queryBuilder; | |||||
return $repositoryQuery; | |||||
} | } | ||||
} | } |
namespace Lc\CaracoleBundle\Controller\User; | 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\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\CaracoleBundle\Controller\ControllerTrait; | ||||
use Lc\SovBundle\Container\User\UserContainer; | use Lc\SovBundle\Container\User\UserContainer; | ||||
use Lc\CaracoleBundle\Controller\AbstractAdminController; | use Lc\CaracoleBundle\Controller\AbstractAdminController; | ||||
use Lc\SovBundle\Repository\RepositoryQueryInterface; | use Lc\SovBundle\Repository\RepositoryQueryInterface; | ||||
use Symfony\Component\HttpFoundation\Response; | |||||
abstract class UserAdminController extends AbstractAdminController | abstract class UserAdminController extends AbstractAdminController | ||||
{ | { | ||||
public function configureFields(string $pageName): iterable | public function configureFields(string $pageName): iterable | ||||
{ | { | ||||
$fields = $this->get(UserContainer::class) | $fields = $this->get(UserContainer::class) | ||||
->getFieldDefinition() | ->getFieldDefinition() | ||||
->setMerchant($this->getMerchantCurrent()) | ->setMerchant($this->getMerchantCurrent()) | ||||
->getAllFields(); | ->getAllFields(); | ||||
if($pageName == Crud::PAGE_INDEX){ | |||||
if ($pageName == Crud::PAGE_INDEX) { | |||||
return [ | return [ | ||||
$fields['id'], | $fields['id'], | ||||
$fields['gender'], | $fields['gender'], | ||||
$fields['isSaleAlwaysOpen'], | $fields['isSaleAlwaysOpen'], | ||||
$fields['newsletters'] | $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['id'], | ||||
$fields['gender'], | $fields['gender'], | ||||
$fields['lastname'], | $fields['lastname'], | ||||
$fields['newsletters'] | $fields['newsletters'] | ||||
]; | ]; | ||||
if($this->isGranted('ROLE_SUPER_ADMIN')){ | |||||
if ($this->isGranted('ROLE_SUPER_ADMIN')) { | |||||
$fieldToReturn[] = $fields['roles']; | $fieldToReturn[] = $fields['roles']; | ||||
} | } | ||||
return $fieldToReturn; | return $fieldToReturn; | ||||
} elseif ($pageName == Crud::PAGE_DETAIL) { | |||||
return [$fields['id']]; | |||||
} | } | ||||
} | } | ||||
} | } |
namespace Lc\CaracoleBundle\Controller\User; | namespace Lc\CaracoleBundle\Controller\User; | ||||
use App\Controller\Credit\CreditHistoryAdminController; | |||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Collection\EntityCollection; | 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\Action; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; | use EasyCorp\Bundle\EasyAdminBundle\Config\Actions; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | use EasyCorp\Bundle\EasyAdminBundle\Config\Crud; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Config\Filters; | use EasyCorp\Bundle\EasyAdminBundle\Config\Filters; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Context\AdminContext; | 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\Filter\BooleanFilter; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; | use EasyCorp\Bundle\EasyAdminBundle\Provider\AdminContextProvider; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; | use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator; | ||||
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission; | |||||
use Lc\CaracoleBundle\Container\User\UserMerchantContainer; | use Lc\CaracoleBundle\Container\User\UserMerchantContainer; | ||||
use Lc\CaracoleBundle\Controller\ControllerTrait; | |||||
use Lc\CaracoleBundle\Controller\AbstractAdminController; | |||||
use Lc\CaracoleBundle\Definition\ActionDefinition; | 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\Model\Credit\CreditHistoryInterface; | ||||
use Lc\CaracoleBundle\Resolver\MerchantResolver; | 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\Repository\RepositoryQueryInterface; | ||||
use Lc\SovBundle\Translation\TranslatorAdmin; | use Lc\SovBundle\Translation\TranslatorAdmin; | ||||
use Symfony\Component\HttpFoundation\Response; | use Symfony\Component\HttpFoundation\Response; | ||||
abstract class UserMerchantAdminController extends AbstractAdminController | abstract class UserMerchantAdminController extends AbstractAdminController | ||||
{ | { | ||||
use ControllerTrait; | |||||
public function getRepositoryQuery(): RepositoryQueryInterface | public function getRepositoryQuery(): RepositoryQueryInterface | ||||
{ | { | ||||
return $this->getUserMerchantContainer()->getFactory()->createBase($this->getMerchantCurrent()); | 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 | public function overrideEntitiesActions(?EntityCollection $entities): void | ||||
{ | { | ||||
$context = $this->get(AdminContextProvider::class)->getContext(); | $context = $this->get(AdminContextProvider::class)->getContext(); | ||||
) | ) | ||||
->setCssClass('btn btn-sm btn-success'); | ->setCssClass('btn btn-sm btn-success'); | ||||
$actions->add(Crud::PAGE_INDEX, $creditAction); | $actions->add(Crud::PAGE_INDEX, $creditAction); | ||||
$actions->disable( | |||||
ActionDefinition::EDIT, | |||||
ActionDefinition::DUPLICATE, | |||||
ActionDefinition::DELETE, | |||||
ActionDefinition::DUPLICATE_TO_OTHER_MERCHANT | |||||
); | |||||
return $actions; | return $actions; | ||||
} | } | ||||
public function configureFields(string $pageName): iterable | 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 | public function configureFilters(Filters $filters): Filters | ||||
->getFactory() | ->getFactory() | ||||
->create($merchantResolver->getCurrent()); | ->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()); | $form->handleRequest($context->getRequest()); | ||||
if ($form->isSubmitted() && $form->isValid()) { | 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); | ||||
$entityManager->update($userMerchant->getUser()); | |||||
$entityManager->flush(); | $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( | return $this->render( | ||||
'@LcCaracole/admin/user/edit_usermerchant.html.twig', | |||||
'@LcCaracole/admin/user/new_usermerchant.html.twig', | |||||
[ | [ | ||||
'form' => $form->createView(), | '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, | |||||
// ] | |||||
// ); | |||||
// } | |||||
} | } |
public const DUPLICATE_TO_OTHER_MERCHANT = 'duplicateToOtherMerchant'; | public const DUPLICATE_TO_OTHER_MERCHANT = 'duplicateToOtherMerchant'; | ||||
public const DUPLICATE_TO_OTHER_SECTION = 'duplicateToOtherSection'; | public const DUPLICATE_TO_OTHER_SECTION = 'duplicateToOtherSection'; | ||||
public const EDIT_ADDRESS_USER = 'editAddressUser'; | |||||
} | } |
<?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', '€'), | |||||
'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'), | |||||
]; | |||||
} | |||||
} | |||||
<?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', '€'), | |||||
'user'=> AssociationField::new('user'), | |||||
]; | |||||
} | |||||
} |
} | } | ||||
} | } | ||||
}*/ | }*/ | ||||
} | |||||
} |
class CreditHistoryFactory extends AbstractFactory | class CreditHistoryFactory extends AbstractFactory | ||||
{ | { | ||||
// createCreditHistory | // 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) ; | $creditHistory->setType($type) ; | ||||
return $creditHistory; | |||||
} | |||||
public function createBase(UserMerchantInterface $userMerchant): CreditHistoryInterface | |||||
{ | |||||
$creditHistory = new CreditHistory(); | |||||
$creditHistory->setUserMerchant($userMerchant) ; | $creditHistory->setUserMerchant($userMerchant) ; | ||||
return $creditHistory; | return $creditHistory; |
} | } | ||||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, string $fieldProperty, $filteredValue = null) | |||||
public function applyFilter(RepositoryQueryInterface $repositoryQuery, FieldDto $fieldDto, string $fieldProperty, $filteredValue = null) | |||||
{ | { | ||||
if ($filteredValue !== null) { | if ($filteredValue !== null) { | ||||
$repositoryQuery->filterByProductCategory($filteredValue); | $repositoryQuery->filterByProductCategory($filteredValue); |
namespace Lc\CaracoleBundle\Form\User; | namespace Lc\CaracoleBundle\Form\User; | ||||
use App\Entity\User\User; | |||||
use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | use Lc\CaracoleBundle\Model\User\UserMerchantInterface; | ||||
use Lc\CaracoleBundle\Repository\User\UserStore; | |||||
use Lc\SovBundle\Definition\RolesDefinitionInterface; | use Lc\SovBundle\Definition\RolesDefinitionInterface; | ||||
use Lc\SovBundle\Doctrine\EntityManager; | use Lc\SovBundle\Doctrine\EntityManager; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
use Lc\SovBundle\Translation\TranslatorAdmin; | use Lc\SovBundle\Translation\TranslatorAdmin; | ||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||||
use Symfony\Component\Form\AbstractType; | use Symfony\Component\Form\AbstractType; | ||||
use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | use Symfony\Component\Form\Extension\Core\Type\CheckboxType; | ||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
use Symfony\Component\OptionsResolver\OptionsResolver; | use Symfony\Component\OptionsResolver\OptionsResolver; | ||||
use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; | 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( | public function __construct( | ||||
EntityManager $em, | |||||
EntityManager $entityManager, | |||||
TranslatorAdmin $translatorAdmin, | TranslatorAdmin $translatorAdmin, | ||||
RolesDefinitionInterface $rolesDefinition, | |||||
AuthorizationCheckerInterface $authorizationChecker | |||||
UserStore $userStore | |||||
) { | ) { | ||||
$this->em = $em; | |||||
$this->rolesDefinition = $rolesDefinition; | |||||
$this->entityManager = $entityManager; | |||||
$this->translatorAdmin = $translatorAdmin; | $this->translatorAdmin = $translatorAdmin; | ||||
$this->authorizationChecker = $authorizationChecker; | |||||
$this->userStore = $userStore; | |||||
} | } | ||||
public function buildForm(FormBuilderInterface $builder, array $options) | 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( | $builder->add( | ||||
'roles', | |||||
ChoiceType::class, | |||||
'user', | |||||
EntityType::class, | |||||
array( | array( | ||||
'choices' => $this->rolesDefinition->getRolesList(), | |||||
'multiple' => true, | |||||
'class'=> $this->entityManager->getEntityName(UserInterface::class), | |||||
'choices'=> $this->userStore->setMerchant($options['merchant'])->get() | |||||
) | ) | ||||
); | ); | ||||
{ | { | ||||
$resolver->setDefaults( | $resolver->setDefaults( | ||||
[ | [ | ||||
'data_class' => $this->em->getEntityName(UserMerchantInterface::class), | |||||
'data_class' => $this->entityManager->getEntityName(UserMerchantInterface::class), | |||||
'merchant' => null, | |||||
] | ] | ||||
); | ); | ||||
} | } |
use Lc\SovBundle\Doctrine\Extension\TimestampableTrait; | use Lc\SovBundle\Doctrine\Extension\TimestampableTrait; | ||||
use Lc\SovBundle\Model\User\UserInterface; | use Lc\SovBundle\Model\User\UserInterface; | ||||
/** | |||||
* @ORM\MappedSuperclass() | |||||
*/ | |||||
interface CreditHistoryInterface | interface CreditHistoryInterface | ||||
{ | { | ||||
} | |||||
} |
->andWhere('.createdAt <= :dateEnd') | ->andWhere('.createdAt <= :dateEnd') | ||||
->setParameter(':dateEnd', $dateEnd); | ->setParameter(':dateEnd', $dateEnd); | ||||
} | } | ||||
} | } |
namespace Lc\CaracoleBundle\Repository\Order; | 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 Knp\Component\Pager\PaginatorInterface; | ||||
use Lc\CaracoleBundle\Model\Address\AddressInterface; | use Lc\CaracoleBundle\Model\Address\AddressInterface; | ||||
use Lc\CaracoleBundle\Model\Distribution\DistributionInterface; | 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\ReductionCartInterface; | ||||
use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface; | ||||
use Lc\CaracoleBundle\Model\User\VisitorInterface; | use Lc\CaracoleBundle\Model\User\VisitorInterface; | ||||
{ | { | ||||
return $this | return $this | ||||
->select( | ->select( | ||||
'SUM(r.statTotalWithTax) as total' | |||||
'SUM(DISTINCT(r.statTotalWithTax)) as total' | |||||
); | ); | ||||
} | } | ||||
public function selectCount(): self | public function selectCount(): self | ||||
{ | { | ||||
return $this | return $this | ||||
->select('count(r.id) as total'); | |||||
->select('count(DISTINCT(r.id)) as total'); | |||||
} | } | ||||
public function filterByUser(UserInterface $user): self | public function filterByUser(UserInterface $user): self |
UserInterface $user = null, | UserInterface $user = null, | ||||
$query = null | $query = null | ||||
): int { | ): int { | ||||
$query = $this->createDefaultQuery($query); | |||||
//TODO vérifier que ne pas utiliser createDefaultQuery est pertinent | |||||
$query = $this->createQuery($query); | |||||
if ($user) { | if ($user) { | ||||
$query->filterByUser($user); | $query->filterByUser($user); | ||||
} | } | ||||
{ | { | ||||
$query = $this->createDefaultQuery($query); | $query = $this->createDefaultQuery($query); | ||||
$query->selectCount(); | $query->selectCount(); | ||||
$this->applyGetByFilters($params, $query); | $this->applyGetByFilters($params, $query); | ||||
return $query->count(); | return $query->count(); | ||||
} | } | ||||
->andWhere('.user = :user') | ->andWhere('.user = :user') | ||||
->setParameter('user', $user); | ->setParameter('user', $user); | ||||
} | } | ||||
public function filterIsCreditActive() | |||||
{ | |||||
return $this | |||||
->andWhere('.creditActive = 1'); | |||||
} | |||||
} | } |
$merchant = $this->getCurrent(); | $merchant = $this->getCurrent(); | ||||
} | } | ||||
//TODO Pas de REPO !!!!! | |||||
return $this->userMerchantRepository->findOneBy( | return $this->userMerchantRepository->findOneBy( | ||||
[ | [ | ||||
'user' => $user, | 'user' => $user, |
admin_section: Sections | admin_section: Sections | ||||
admin_tva: TVA | admin_tva: TVA | ||||
admin_unit: Unités | admin_unit: Unités | ||||
user_merchant_index: Utilisateurs | |||||
user_merchant_index: Comptes prépayés | |||||
group_user_index: Groupes d'utilisateurs | group_user_index: Groupes d'utilisateurs | ||||
duplicateToOtherSection: Dupliquer sur une autre section | duplicateToOtherSection: Dupliquer sur une autre section | ||||
editProductFamily: Éditer le produit | editProductFamily: Éditer le produit | ||||
history: Historique | history: Historique | ||||
credit: Voir l'historique de crédit | |||||
setting_definition: | setting_definition: | ||||
merchant: | merchant: | ||||
label: Règle de taxe | label: Règle de taxe | ||||
label_plurial: Règles de taxes | label_plurial: Règles de taxes | ||||
UserMerchant: | UserMerchant: | ||||
label: Utilisateur | |||||
label_plurial: Utilisateurs | |||||
label: Utilisateur avec compte prépayé actif | |||||
label_plurial: Utilisateurs avec comptes prépayés actifs | |||||
fields: | fields: | ||||
user: | user: | ||||
email: Email | email: Email | ||||
lastname: Nom | lastname: Nom | ||||
firstname: Prénom | firstname: Prénom | ||||
creditActive: Crédit activer | creditActive: Crédit activer | ||||
credit: Montant du compte prépayé | |||||
User: | User: | ||||
fields: | fields: | ||||
isSaleAlwaysOpen: Vente toujours ouverte | isSaleAlwaysOpen: Vente toujours ouverte | ||||
label_plurial: Historiques de compte prépayé | label_plurial: Historiques de compte prépayé | ||||
fields: | fields: | ||||
type: Type | type: Type | ||||
typeOptions: | |||||
typeChoices: | |||||
credit: Crédit | credit: Crédit | ||||
debit: Débit | debit: Débit | ||||
amount: Montant | amount: Montant | ||||
paidAt: Date de transaction | paidAt: Date de transaction | ||||
reference: Référence | reference: Référence | ||||
comment: Commentaire | 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: | OrderShop: | ||||
fields: | fields: | ||||
deliveryInfos: | | deliveryInfos: | |
{% 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 %} |
{% set item = entity.instance %} | |||||
{% if item.orderPayment is not null %} | |||||
{{ item.orderPayment.comment }} | |||||
{% else %} | |||||
{{ item.comment }} | |||||
{% endif %} |
{% 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 %} |
{% 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 %} |
{% set item = entity.instance %} | |||||
{% if item.orderPayment is not null %} | |||||
{{ item.orderPayment.reference }} | |||||
{% else %} | |||||
{{ item.reference }} | |||||
{% endif %} |
{% block content_title %} | {% block content_title %} | ||||
{{ 'index'|sov_trans_admin_title(ea.getEntity().getFqcn()) }} | {{ '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 %} |
{% 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> |
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface; | ||||
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel; | |||||
use function Clue\StreamFilter\remove; | |||||
class CreditHistorySolver | class CreditHistorySolver | ||||
{ | { | ||||
public static function getTypeChoices() :array | |||||
{ | |||||
return[ | |||||
CreditHistoryModel::TYPE_CREDIT, | |||||
CreditHistoryModel::TYPE_DEBIT, | |||||
]; | |||||
} | |||||
public function getMeanPaymentInheritedLabel(CreditHistoryInterface $creditHistory): string | public function getMeanPaymentInheritedLabel(CreditHistoryInterface $creditHistory): string | ||||
{ | { | ||||
return 'entity.CreditHistory.fields.meanPaymentOptions.' . $this->getMeanPaymentInherited($creditHistory); | return 'entity.CreditHistory.fields.meanPaymentOptions.' . $this->getMeanPaymentInherited($creditHistory); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | |||||
} |
class OrderPaymentSolver | class OrderPaymentSolver | ||||
{ | { | ||||
public function getMeanPaymentChoices() | |||||
public static function getMeanPaymentChoices() | |||||
{ | { | ||||
return [ | return [ | ||||
OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD, | OrderPaymentModel::MEAN_PAYMENT_CREDIT_CARD, |