Parcourir la source

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

packProduct
Guillaume il y a 3 ans
Parent
révision
55c9740b20
42 fichiers modifiés avec 2002 ajouts et 380 suppressions
  1. +210
    -7
      Controller/AdminControllerTrait.php
  2. +1
    -0
      Controller/Dashboard/DashboardAdminAdminController.php
  3. +1
    -3
      Controller/User/UserMerchantAdminController.php
  4. +0
    -17
      Doctrine/Extension/ReductionPropertyTrait.php
  5. +56
    -0
      EventSubscriber/Address/DuplicateAddressEventSubscriber.php
  6. +64
    -0
      EventSubscriber/Product/DuplicateProductfamilyEventSubscriber.php
  7. +144
    -0
      EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php
  8. +72
    -0
      Form/Merchant/DuplicateToOtherMerchantFormType.php
  9. +73
    -0
      Form/Section/DuplicateToOtherSectionFormType.php
  10. +1
    -1
      Model/Credit/CreditHistoryModel.php
  11. +10
    -7
      Model/Reduction/ReductionCartModel.php
  12. +13
    -11
      Model/Reduction/ReductionCatalogModel.php
  13. +9
    -8
      Model/Reduction/ReductionCreditModel.php
  14. +46
    -0
      Repository/Credit/CreditHistoryRepositoryQuery.php
  15. +31
    -0
      Repository/Credit/CreditHistoryStore.php
  16. +12
    -0
      Repository/File/DocumentStore.php
  17. +9
    -0
      Repository/Merchant/MerchantStore.php
  18. +337
    -1
      Repository/Order/OrderShopRepositoryQuery.php
  19. +514
    -237
      Repository/Order/OrderShopStore.php
  20. +2
    -0
      Repository/PointSale/PointSaleRepositoryQuery.php
  21. +3
    -0
      Repository/PointSale/PointSaleStore.php
  22. +2
    -0
      Repository/Product/ProductFamilyRepositoryQuery.php
  23. +3
    -0
      Repository/Product/ProductFamilyStore.php
  24. +34
    -5
      Repository/Reminder/ReminderStore.php
  25. +0
    -27
      Repository/Reminder/TicketStore.php
  26. +25
    -0
      Repository/Site/NewsStore.php
  27. +9
    -0
      Repository/Site/PageRepositoryQuery.php
  28. +59
    -0
      Repository/Site/PageStore.php
  29. +51
    -0
      Repository/Ticket/TicketStore.php
  30. +0
    -15
      Repository/User/GroupUserRepository.php
  31. +2
    -8
      Repository/User/GroupUserRepositoryQuery.php
  32. +2
    -7
      Repository/User/GroupUserStore.php
  33. +40
    -0
      Repository/User/UserRepositoryQuery.php
  34. +27
    -0
      Repository/User/UserStore.php
  35. +6
    -0
      Resources/assets/app/admin/duplicate/app.duplicate.js
  36. +36
    -0
      Resources/assets/app/admin/duplicate/duplicate.js
  37. +37
    -0
      Resources/assets/app/admin/duplicate/duplicate.scss
  38. +6
    -0
      Resources/translations/admin.fr.yaml
  39. +14
    -0
      Resources/views/admin/merchant/modal/duplicate_entity_to_other_merchant.html.twig
  40. +14
    -0
      Resources/views/admin/merchant/modal/duplicate_entity_to_other_section.html.twig
  41. +26
    -0
      Resources/views/admin/merchant/modal/switch_merchant.html.twig
  42. +1
    -26
      Resources/views/adminlte/layout.html.twig

+ 210
- 7
Controller/AdminControllerTrait.php Voir le fichier

@@ -2,19 +2,34 @@

namespace Lc\CaracoleBundle\Controller;

use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
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\Context\AdminContext;
use EasyCorp\Bundle\EasyAdminBundle\Exception\ForbiddenActionException;
use EasyCorp\Bundle\EasyAdminBundle\Exception\InsufficientEntityPermissionException;
use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Form\Merchant\DuplicateToOtherMerchantFormType;
use Lc\CaracoleBundle\Form\Section\DuplicateToOtherSectionFormType;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCatalogStore;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
use Lc\CaracoleBundle\Resolver\SectionResolver;
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
use EasyCorp\Bundle\EasyAdminBundle\Dto\SearchDto;
use Lc\SovBundle\Component\EntityComponent;
use Lc\SovBundle\Factory\User\UserFactory;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\Response;


trait AdminControllerTrait
@@ -22,12 +37,16 @@ trait AdminControllerTrait

public static function getSubscribedServices()
{
return array_merge(parent::getSubscribedServices(), [
'merchant_resolver' => MerchantResolver::class,
'section_resolver' => SectionResolver::class,
'user_factory' => UserFactory::class,
'user_merchant_factory' => UserMerchantFactory::class,
]);
return array_merge(
parent::getSubscribedServices(),
[
'merchant_resolver' => MerchantResolver::class,
'section_resolver' => SectionResolver::class,
'user_factory' => UserFactory::class,
'user_merchant_factory' => UserMerchantFactory::class,
ReductionCatalogStore::class => ReductionCatalogStore::class,
]
);
}

public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
@@ -35,7 +54,7 @@ trait AdminControllerTrait
$responseParameters = parent::configureResponseParameters($responseParameters);

// affichage du filtre sur section
if($this->isInstanceOf(FilterSectionInterface::class)) {
if ($this->isInstanceOf(FilterSectionInterface::class)) {
$responseParameters->set('display_switch_section', true);
}

@@ -74,6 +93,190 @@ trait AdminControllerTrait
}


public function duplicateToOtherMerchant(
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
EntityManagerInterface $em
) {
if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => "duplicate", 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}

if (!$context->getEntity()->isAccessible()) {
throw new InsufficientEntityPermissionException($context);
}

if (!$this->isInstanceOf(FilterMerchantInterface::class)) {
throw new \ErrorException('L\entité n\'est pas lié à un merchant.');
}
$duplicateOtherMerchantForm = $this->createForm(
DuplicateToOtherMerchantFormType::class,
null,
array(
'entityClass' => $context->getEntity()->getFqcn(),
'entityId' => $context->getEntity()->getInstance()->getId(),
'action' => $context->getRequest()->getUri(),
'attr' => ['id'=> 'duplicate-other-merchant-form'],

)
);

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

if ($duplicateOtherMerchantForm->isSubmitted() && $duplicateOtherMerchantForm->isValid()) {
$newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance());
$em->create($newEntity);
$merchant = $duplicateOtherMerchantForm->get('merchants')->getData();
$newEntity->setMerchant($merchant);
$em->update($newEntity);
$em->flush();

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();
$this->addFlash(
'success',
$translatorAdmin->transFlashMessage(
'duplicateToOtherMerchant',
['%merchant%' => $merchant->getTitle()]
),
array()
);

//TODO switch merchant route
return $this->redirect($url);
}


if ($context->getRequest()->isXmlHttpRequest()) {
$response['data'] = $this->renderView(
'@LcCaracole/admin/merchant/modal/duplicate_entity_to_other_merchant.html.twig',
array(
'form_duplicate_entity_to_other_merchant' => $duplicateOtherMerchantForm->createView(),
)
);

return new Response(json_encode($response));
}else{
throw new \ErrorException('La requête doit être effectué en ajax');
}
}

public function duplicateToOtherSection(
AdminContext $context,
EntityComponent $entityComponent,
TranslatorAdmin $translatorAdmin,
EntityManagerInterface $em
) {
if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => "duplicate", 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}

if (!$context->getEntity()->isAccessible()) {
throw new InsufficientEntityPermissionException($context);
}

if (!$this->isInstanceOf(FilterSectionInterface::class)) {
throw new \ErrorException('L\entité n\'est pas lié à un merchant.');
}
$duplicateOtherSectionForm = $this->createForm(
DuplicateToOtherSectionFormType::class,
null,
array(
'entityClass' => $context->getEntity()->getFqcn(),
'entityId' => $context->getEntity()->getInstance()->getId(),
'action' => $context->getRequest()->getUri(),
'attr' => ['id'=> 'duplicate-other-section-form'],
)
);

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

if ($duplicateOtherSectionForm->isSubmitted() && $duplicateOtherSectionForm->isValid()) {
$newEntity = $entityComponent->duplicateEntity($context->getEntity()->getInstance());
$em->create($newEntity);
$section = $duplicateOtherSectionForm->get('sections')->getData();
$newEntity->setSection($section);
$em->update($newEntity);
$em->flush();

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();
$this->addFlash(
'success',
$translatorAdmin->transFlashMessage(
'duplicateToOtherSection',
['%section%' => $section->getTitle()]
),
array()
);

//TODO switch merchant route
return $this->redirect($url);
}


if ($context->getRequest()->isXmlHttpRequest()) {
$response['data'] = $this->renderView(
'@LcCaracole/admin/merchant/modal/duplicate_entity_to_other_section.html.twig',
array(
'form_duplicate_entity_to_other_section' => $duplicateOtherSectionForm->createView(),
)
);

return new Response(json_encode($response));
}else{
throw new \ErrorException('La requête doit être effectué en ajax');
}
}


public function buildIndexActions(Actions $actions): void
{
parent::buildIndexActions($actions);
if ($this->isInstanceOf(FilterMerchantInterface::class)) {
$actions->add(Crud::PAGE_INDEX, $this->getDuplicateToOhterMerchantAction());
}

if ($this->isInstanceOf(FilterSectionInterface::class)) {
$actions->add(Crud::PAGE_INDEX, $this->getDuplicateToOhterSectionAction());
}
}

public function getDuplicateToOhterMerchantAction(): Action
{
$duplicateAction = Action::new(
'duplicateToOtherMerchant',
$this->get('translator_admin')->transAction('duplicateToOtherMerchant'),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicateToOtherMerchant')
->setCssClass('text-info in-dropdown duplicate-to-other-merchant duplicate-modal-action');

return $duplicateAction;
}

public function getDuplicateToOhterSectionAction(): Action
{
$duplicateAction = Action::new(
'duplicateToOtherSection',
$this->get('translator_admin')->transAction('duplicateToOtherSection'),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicateToOtherSection')
->setCssClass('text-info in-dropdown duplicate-to-other-section duplicate-modal-action');

return $duplicateAction;
}
}


+ 1
- 0
Controller/Dashboard/DashboardAdminAdminController.php Voir le fichier

@@ -27,6 +27,7 @@ class DashboardAdminAdminController extends SovDashboardController

$assets->addWebpackEncoreEntry('carac-common');
$assets->addWebpackEncoreEntry('carac-switch-merchant');
$assets->addWebpackEncoreEntry('carac-duplicate');

return $assets;
}

+ 1
- 3
Controller/User/UserMerchantAdminController.php Voir le fichier

@@ -209,7 +209,7 @@ abstract class UserMerchantAdminController extends AbstractAdminController
}

return $this->render(
'@LcCaracole/admin/user/usermerchant_edit.html.twig',
'@LcCaracole/admin/user/edit_usermerchant.html.twig',
[
'form' => $form->createView(),
]
@@ -233,8 +233,6 @@ abstract class UserMerchantAdminController extends AbstractAdminController
if (!$context->getEntity()->isAccessible()) {
throw new InsufficientEntityPermissionException($context);
}
dump($context->getCrud()->getControllerFqcn());


$options['action'] = $adminUrlGenerator
->setController($context->getCrud()->getControllerFqcn())

+ 0
- 17
Doctrine/Extension/ReductionPropertyTrait.php Voir le fichier

@@ -22,11 +22,6 @@ trait ReductionPropertyTrait
*/
protected $groupUsers;

/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface", inversedBy="productFamilies")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;

/**
* @ORM\Column(type="datetime", nullable=true)
@@ -50,18 +45,6 @@ trait ReductionPropertyTrait
$this->groupUsers = new ArrayCollection();
}

public function getMerchant(): ?MerchantInterface
{
return $this->merchant;
}

public function setMerchant(?MerchantInterface $merchant): self
{
$this->merchant = $merchant;

return $this;
}

/**
* @return Collection|UserInterface[]
*/

+ 56
- 0
EventSubscriber/Address/DuplicateAddressEventSubscriber.php Voir le fichier

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

namespace Lc\CaracoleBundle\EventSubscriber\Address;

use Doctrine\ORM\EntityManagerInterface;

use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Lc\SovBundle\Event\EntityComponentEvent;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Repository\AbstractRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DuplicateAddressEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $adminUrlGenerator;

public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}

public static function getSubscribedEvents()
{
return [
EntityComponentEvent::DUPLICATE_EVENT => ['duplicateAddressOnDuplicateEvent'],
];
}

public function duplicateAddressOnDuplicateEvent(EntityComponentEvent $event)
{
$entity = $event->getEntity();

$classMetadata = $this->em->getClassMetadata(get_class($entity));

foreach ($classMetadata->getAssociationMappings() as $associationMapping){
if(in_array(AddressInterface::class, class_implements($associationMapping['targetEntity']))){
$methodGet = 'get'.ucfirst($associationMapping['fieldName']);
$methodSet = 'set'.ucfirst($associationMapping['fieldName']);
if(method_exists($entity, $methodGet) && method_exists($entity, $methodSet)){
$newAddress = clone $entity->$methodGet();
$entity->$methodSet($newAddress);
$this->em->persist($newAddress);
}
}

}
}


}

+ 64
- 0
EventSubscriber/Product/DuplicateProductfamilyEventSubscriber.php Voir le fichier

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

namespace Lc\CaracoleBundle\EventSubscriber\Product;

use Doctrine\ORM\EntityManagerInterface;

use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\SovBundle\Doctrine\EntityInterface;
use Lc\SovBundle\Doctrine\Extension\SluggableInterface;
use Lc\SovBundle\Doctrine\Extension\SortableInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\TreeInterface;
use Lc\SovBundle\Event\EntityComponentEvent;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Lc\SovBundle\Repository\AbstractRepositoryInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class DuplicateProductfamilyEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $adminUrlGenerator;

public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}

public static function getSubscribedEvents()
{
return [
EntityComponentEvent::DUPLICATE_EVENT => ['duplicateProductOnDuplicateEvent'],
];
}

public function duplicateProductOnDuplicateEvent(EntityComponentEvent $event)
{
$entity = $event->getEntity();

$classMetadata = $this->em->getClassMetadata(get_class($entity));

/*foreach ($classMetadata->getAssociationMappings() as $associationMapping){
if(in_array(ProductInterface::class, class_implements($associationMapping['targetEntity']))){

/*foreach ($productFamily->getProducts() as $i => $product) {
$newProduct = clone $product;
$newProduct->setProductFamily($productFamily);
$this->em->persist($newProduct);
$productFamily->addProduct($newProduct);
}

$methodGet = 'get'.ucfirst($associationMapping['fieldName']);
$methodSet = 'set'.ucfirst($associationMapping['fieldName']);
if(method_exists($entity, $methodGet) && method_exists($entity, $methodSet)){
$newAddress = clone $entity->$methodGet();
$entity->$methodSet($newAddress);
$this->em->persist($newAddress);
}
}

}*/
}

}

+ 144
- 0
EventSubscriber/Product/UpdateProductfamilyEventSubscriber.php Voir le fichier

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

namespace Lc\CaracoleBundle\EventSubscriber\Product;

use Doctrine\ORM\EntityManagerInterface;

use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductInterface;
use Lc\CaracoleBundle\Model\Reduction\ReductionCatalogInterface;
use Lc\SovBundle\Event\EntityManager\EntityManagerEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

class UpdateProductfamilyEventSubscriber implements EventSubscriberInterface
{
protected $em;
protected $adminUrlGenerator;

public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}

public static function getSubscribedEvents()
{
return [
EntityManagerEvent::PRE_UPDATE_EVENT => ['processBeforePersistProductFamily'],
EntityManagerEvent::PRE_CREATE_EVENT => ['processBeforePersistProductFamily'],
];
}

public function processBeforePersistProductFamily(EntityManagerEvent $event)
{
$entity = $event->getEntity();
if($entity instanceof ProductFamilyInterface) {
$this->processProducts($entity);
$this->processPrice($entity);
$this->processReductionCatalog($entity);
}
//TODO updatePriceByProductFamily
}


protected function processReductionCatalog($entity)
{
$reductionCatalog = $entity->getReductionCatalog();

if ($reductionCatalog instanceof ReductionCatalogInterface) {
if ($reductionCatalog->getValue() && $reductionCatalog->getBehaviorTaxRate() && $reductionCatalog->getUnit()) {
//$reductionCatalog->setSection($entity->getSection());
$reductionCatalog->setProductFamily($entity);
if(is_null($reductionCatalog->getId())) {
$this->em->create($reductionCatalog);
}else {
$this->em->update($reductionCatalog);
}
}
}
}

protected function processPrice($entity)
{
if ($entity->getBehaviorPrice() == 'by-piece') {
$entity->setPriceByRefUnit(null);
$entity->setBuyingPriceByRefUnit(null);
} else {
if ($entity->getBehaviorPrice() == 'by-reference-unit') {
$entity->setPrice(null);
$entity->setBuyingPrice(null);
}
}
}

protected function processProducts($entity)
{

//Récupère le product origin
$originProducts = $this->em->getRepository(ProductInterface::class)
->findBy(
array(
'productFamily' => $entity->getId(),
'originProduct' => true,
)
);

if (count($originProducts) > 1) {
throw new \ErrorException('Plusieurs OriginProduct pour un même produit... Contacter fab');
// Case Nouveau product family
} else {
if (count($originProducts) == 0) {
$entityClassName = $this->em->getEntityName(ProductInterface::class);
$originProduct = new $entityClassName();
$originProduct->setProductFamily($entity);
$originProduct->setOriginProduct(true);
$entity->addProduct($originProduct);
} else {
$originProduct = $originProducts[0];
}
}

if ($entity->getActiveProducts()) {
$originProduct->setStatus(-1);
} else {
$originProduct->setStatus(1);
}

//Enregistrement
$entity->addProduct($originProduct);

foreach ($entity->getProducts() as $product) {
$product->setProductFamily($entity);

if ($entity->getProductsQuantityAsTitle() && $product->getStatus() >= 1) {
$product->setTitle(
str_replace('.', ',', $product->getQuantityInherited()).$product->getUnitInherited(
)->getWording()
);
}

$this->em->persist($product);
$entity->addProduct($product);
}
}

/* protected function processCategories(ProductFamilyInterface $entity)
{
$productCategoryRepository = $this->em->getRepository(ProductCategoryInterface::class);
$productCategories = $entity->getProductCategories();

$entity->initProductCategories();

foreach ($productCategories as $key => $bool) {
if (is_bool($bool) && $bool) {
if (strpos($key, 'category_children_') !== false) {
$idCategory = (int)str_replace('category_children_', '', $key);
} else {
$idCategory = (int)str_replace('category_', '', $key);
}

$category = $productCategoryRepository->find($idCategory);
$entity->addProductCategory($category);
}
}
}*/
}

+ 72
- 0
Form/Merchant/DuplicateToOtherMerchantFormType.php Voir le fichier

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

namespace Lc\CaracoleBundle\Form\Merchant;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
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\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DuplicateToOtherMerchantFormType extends AbstractType
{
protected $em;
protected $translatorAdmin;
protected $merchantResolver;

public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin, MerchantResolver $merchantResolver)
{
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
$this->merchantResolver = $merchantResolver;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
//TODO tester si l'utilisateur à les droits sur ce merchant
$builder->add(
'merchants',
EntityType::class,
[
'class' => $this->em->getEntityName(MerchantInterface::class),
'choice_label' => 'title'
]
);

$builder->add(
'EntityId',
HiddenType::class,
[
'data' => $options['entityId']
]
);

$builder->add(
'EntityClass',
HiddenType::class,
[
'data' => $options['entityClass']
]
);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'entityId' => null,
'entityClass' => null,
]
);
}

}

+ 73
- 0
Form/Section/DuplicateToOtherSectionFormType.php Voir le fichier

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

namespace Lc\CaracoleBundle\Form\Section;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Resolver\MerchantResolver;
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\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

class DuplicateToOtherSectionFormType extends AbstractType
{
protected $em;
protected $translatorAdmin;
protected $merchantResolver;

public function __construct(EntityManager $em, TranslatorAdmin $translatorAdmin, MerchantResolver $merchantResolver)
{
$this->em = $em;
$this->translatorAdmin = $translatorAdmin;
$this->merchantResolver = $merchantResolver;
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
//TODO tester si l'utilisateur à les droits sur ce merchant
$builder->add(
'sections',
EntityType::class,
[
'class' => $this->em->getEntityName(SectionInterface::class),
'choice_label' => 'title'
]
);

$builder->add(
'EntityId',
HiddenType::class,
[
'data' => $options['entityId']
]
);

$builder->add(
'EntityClass',
HiddenType::class,
[
'data' => $options['entityClass']
]
);
}

/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(
[
'entityId' => null,
'entityClass' => null,
]
);
}

}

+ 1
- 1
Model/Credit/CreditHistoryModel.php Voir le fichier

@@ -29,7 +29,7 @@ abstract class CreditHistoryModel extends AbstractLightEntity implements PayoffI
const MEAN_PAYMENT_CASH = 'cash';


/**
/**$merchant
* @ORM\Column(type="float", nullable=true)
*/
protected $amount;

+ 10
- 7
Model/Reduction/ReductionCartModel.php Voir le fichier

@@ -6,6 +6,7 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinInterface;
use Lc\CaracoleBundle\Doctrine\Extension\OrderAmountMinTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionCartPropertyInterface;
@@ -16,6 +17,7 @@ use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\PointSale\PointSaleInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
@@ -26,7 +28,7 @@ use Lc\SovBundle\Model\User\UserInterface;
*/
abstract class ReductionCartModel extends AbstractLightEntity implements ReductionPropertyInterface, ReductionInterface,
ReductionCartPropertyInterface,
FilterMerchantInterface,
FilterSectionInterface,
OrderAmountMinInterface, StatusInterface
{

@@ -47,11 +49,12 @@ abstract class ReductionCartModel extends AbstractLightEntity implements Reducti
*/
protected $title;


/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;
protected $section;

/**
* @ORM\Column(type="array", nullable=true)
@@ -148,14 +151,14 @@ abstract class ReductionCartModel extends AbstractLightEntity implements Reducti
return $this;
}

public function getMerchant(): ?MerchantInterface
public function getSection(): SectionInterface
{
return $this->merchant;
return $this->section;
}

public function setMerchant(?MerchantInterface $merchant): self
public function setSection(SectionInterface $section): self
{
$this->merchant = $merchant;
$this->section = $section;

return $this;
}

+ 13
- 11
Model/Reduction/ReductionCatalogModel.php Voir le fichier

@@ -5,13 +5,14 @@ namespace Lc\CaracoleBundle\Model\Reduction;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionPropertyInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
@@ -21,7 +22,7 @@ use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
*/
abstract class ReductionCatalogModel extends AbstractLightEntity implements ReductionCatalogInterface,
ReductionPropertyInterface,
FilterMerchantInterface, StatusInterface
FilterSectionInterface, StatusInterface
{
use StatusTrait;
use ReductionTrait;
@@ -34,11 +35,12 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
*/
protected $title;


/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;
protected $section;

/**
* @ORM\ManyToMany(targetEntity="Lc\CaracoleBundle\Model\Product\ProductFamilyInterface")
@@ -76,14 +78,14 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
}


public function getMerchant(): ?MerchantInterface
public function getSection(): SectionInterface
{
return $this->merchant;
return $this->section;
}

public function setMerchant(?MerchantInterface $merchant): self
public function setSection(SectionInterface $section): self
{
$this->merchant = $merchant;
$this->section = $section;

return $this;
}
@@ -116,12 +118,12 @@ abstract class ReductionCatalogModel extends AbstractLightEntity implements Redu
}


public function getProductFamily(): ?ProductFamily
public function getProductFamily(): ?ProductFamilyModel
{
return $this->productFamily;
}

public function setProductFamily(?ProductFamily $productFamily): self
public function setProductFamily(?ProductFamilyModel $productFamily): self
{
$this->productFamily = $productFamily;


+ 9
- 8
Model/Reduction/ReductionCreditModel.php Voir le fichier

@@ -6,9 +6,11 @@ use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionInterface;
use Lc\CaracoleBundle\Doctrine\Extension\ReductionTrait;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\SovBundle\Doctrine\Extension\StatusInterface;
use Lc\SovBundle\Doctrine\Extension\StatusTrait;
use Lc\SovBundle\Doctrine\Pattern\AbstractLightEntity;
@@ -17,7 +19,7 @@ use Lc\SovBundle\Model\User\UserInterface;
/**
* @ORM\MappedSuperclass()
*/
abstract class ReductionCreditModel extends AbstractLightEntity implements ReductionInterface, FilterMerchantInterface,
abstract class ReductionCreditModel extends AbstractLightEntity implements ReductionInterface, FilterSectionInterface,
StatusInterface
{
const TYPE_CREDIT = 'credit';
@@ -38,12 +40,11 @@ abstract class ReductionCreditModel extends AbstractLightEntity implements Reduc
*/
protected $users;


/**
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Merchant\MerchantInterface")
* @ORM\ManyToOne(targetEntity="Lc\CaracoleBundle\Model\Section\SectionInterface")
* @ORM\JoinColumn(nullable=false)
*/
protected $merchant;
protected $section;

/**
* @ORM\Column(type="string", length=255)
@@ -84,14 +85,14 @@ abstract class ReductionCreditModel extends AbstractLightEntity implements Reduc
}


public function getMerchant(): ?MerchantInterface
public function getSection(): SectionInterface
{
return $this->merchant;
return $this->section;
}

public function setMerchant(?MerchantInterface $merchant): self
public function setSection(SectionInterface $section): self
{
$this->merchant = $merchant;
$this->section = $section;

return $this;
}

+ 46
- 0
Repository/Credit/CreditHistoryRepositoryQuery.php Voir le fichier

@@ -2,13 +2,59 @@

namespace Lc\CaracoleBundle\Repository\Credit;

use App\Entity\Merchant\Merchant;
use App\Entity\User\UserMerchant;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;
use DateTime;

class CreditHistoryRepositoryQuery extends AbstractRepositoryQuery
{
protected $isJoinUserMerchants = false;

public function __construct(CreditHistoryRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'r', $paginator);
}

public function joinUserMerchant(): self
{
if (!$this->isJoinUserMerchants) {
$this->isJoinUserMerchants = true;

return $this
->innerJoin('.userMerchant', 'um');
}
return $this;
}

public function filterByJoinUserMerchant(Merchant $merchant): self
{
$this->joinUserMerchant();
return $this
->andWhere('um.merchant = :merchant')
->setParameter('merchant', $merchant);
}

public function filterByUserMerchant(UserMerchant $userMerchant): self
{
return $this
->andWhere('.userMerchant = :userMerchant')
->setParameter('userMerchant', $userMerchant);
}

public function filterByDateStart(DateTime $dateStart): self
{
return $this
->andWhere('.createdAt >= :dateStart')
->setParameter(':dateStart', $dateStart);
}

public function filterByDateEnd(DateTime $dateEnd): self
{
return $this
->andWhere('.createdAt <= :dateEnd')
->setParameter(':dateEnd', $dateEnd);
}
}

+ 31
- 0
Repository/Credit/CreditHistoryStore.php Voir le fichier

@@ -2,14 +2,45 @@

namespace Lc\CaracoleBundle\Repository\Credit;

use App\Entity\User\UserMerchant;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\SovBundle\Repository\AbstractStore;
use DateTime;

class CreditHistoryStore extends AbstractStore
{
use MerchantStoreTrait;

protected CreditHistoryRepositoryQuery $query;

public function __construct(CreditHistoryRepositoryQuery $query)
{
$this->query = $query;
}

//findAllByDateStartEnd
public function getByDateStartEnd(DateTime $dateStart, DateTime $dateEnd): array
{
$query = $this->query->create();

$query
->filterByJoinUserMerchant($this->merchant)
->filterByDateStart($dateStart)
->filterByDateEnd($dateEnd)
->orderBy('.createdAt');

return $query->find();
}

//findAllByUserMerchant
public function getByUserMerchant(UserMerchant $userMerchant): array
{
$query = $this->query->create();

$query
->filterByUserMerchant($userMerchant)
->orderBy('.createdAt', 'DESC');

return $query->find();
}
}

+ 12
- 0
Repository/File/DocumentStore.php Voir le fichier

@@ -20,4 +20,16 @@ class DocumentStore extends AbstractStore
{
// @TODO : à écrire
}

//findLastInvoice
public function getOneLastInvoice()
{
$query = $this->query->create();

$query
->filterByMerchant($this->merchant)
->orderBy('.createdAt', 'DESC');

return $query->findOne();
}
}

+ 9
- 0
Repository/Merchant/MerchantStore.php Voir le fichier

@@ -23,4 +23,13 @@ class MerchantStore extends AbstractStore
return $query->findOne();
}

//TODO pas de merchant_configs

// public function findAllWithConfigs()
// {
// $qb = $this->createQueryBuilder('hub');
// $qb->innerJoin('hub.merchantConfigs', 'merchant_configs');
// return $qb->getQuery()->getResult();
// }

}

+ 337
- 1
Repository/Order/OrderShopRepositoryQuery.php Voir le fichier

@@ -2,17 +2,353 @@

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\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Model\Address\AddressInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\User\VisitorInterface;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;
use DateTime;

class OrderShopRepositoryQuery extends AbstractRepositoryQuery
{
use SectionRepositoryQueryTrait;

protected $isJoinOrderReductionCredits = false;
protected $isJoinOrderReductionCarts = false;
protected $isJoinOrderStatus = false;
protected $isJoinComplementaryOrderShops = false;
protected $isJoinDeliveryPointSale = false;
protected $isJoinDeliveryAvailabilityZone = false;
protected $isJoinDeliverySlotZone = false;
protected $isJoinDeliveryAvailabilityPointSale = false;
protected $isJoinDeliverySlotPointSale = false;
protected $isHorsTournee = false;
protected $isGiftVoucher = false;

public function __construct(OrderShopRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'r', $paginator);
}

public function selectParam($select): self
{
return $this
->addSelect($select);
}

public function selectCount(): self
{
return $this
->addSelect('count(r.id) as total');
}

public function filterByUser(UserInterface $user): self
{
return $this
->andWhere('.user = :user')
->setParameter('user', $user);
}

public function filterByDateStart(string $dateField, DateTime $dateStart): self
{
return $this
->andWhere('.' . $dateField . ' >= :dateStart')
->setParameter('dateStart', $dateStart);
}

public function filterByDateEnd(string $dateField, DateTime $dateEnd): self
{
return $this
->andWhere('.' . $dateField . ' <= :dateEnd')
->setParameter('dateEnd', $dateEnd);
}

public function filterByEstimatedDeliveryDateStart(DateTime $dateStart): self
{
return $this
->andWhere('.estimatedDeliveryDateTime >= :deliveryDateStart')
->setParameter('deliveryDateStart', $dateStart);
}

public function filterByEstimatedDeliveryDateEnd(DateTime $dateEnd): self
{
return $this
->andWhere('.estimatedDeliveryDateTime < :deliveryDateEnd')
->setParameter('deliveryDateEnd', $dateEnd);
}

public function filterByDeliveryDateStart(DateTime $dateStart): self
{
return $this
->andWhere('.deliveryDate >= :deliveryDateStart')
->setParameter('deliveryDateStart', $dateStart);
}

public function filterByDeliveryDateEnd(DateTime $dateEnd): self
{
return $this
->andWhere('.deliveryDate < :deliveryDateEnd')
->setParameter('deliveryDateEnd', $dateEnd);
}

public function filterByVisitor(VisitorInterface $visitor): self
{
return $this
->andWhere('.visitor = :visitor')
->setParameter('visitor', $visitor);
}

public function filterByAddress(AddressInterface $address): self
{
return $this
->andWhere('.deliveryAddress = :address OR .invoiceAddress = :address')
->setParameter('address', $address);
}

public function filterByWeekDeliveryTruck(string $weekDeliveryTrucks): self
{
return $this
->andWhere('.weekDeliveryTruck IN (:weekDeliveryTrucks)')
->setParameter('weekDeliveryTrucks', $weekDeliveryTrucks);
}

public function filterByStatus(array $statusArray): self
{
$this->joinOrderStatus();

return $this
->andWhere('os.alias IN (:alias)')
->setParameter('alias', $statusArray);
}

public function filterByReductionCredit(OrderReductionCreditInterface $reductionCredit): self
{
$this->joinOrderReductionCredits();

return $this
->andWhere('orc.reductionCredit = :reductionCredit')
->setParameter('reductionCredit', $reductionCredit);
}

public function filterByReductionCart(OrderReductionCartInterface $reductionCart): self
{
$this->joinOrderReductionCarts();

return $this
->andWhere('orcart.reductionCart = :reductionCart')
->setParameter('reductionCart', $reductionCart);
}

public function filterByAvailabilityPointZone(DeliveryAvailabilityZone $deliveryAvailabilityZone): self
{
return $this
->andWhere('.deliveryAvailabilityZone = :deliveryAvailabilityZone')
->setParameter('deliveryAvailabilityZone', $deliveryAvailabilityZone);
}

public function filterByAvailabilityPointSale(DeliveryAvailabilityPointSale $deliveryAvailabilityPointSale): self
{
return $this
->andWhere('.deliveryAvailabilityPointSale = :deliveryAvailabilityPointSale')
->setParameter('deliveryAvailabilityPointSale', $deliveryAvailabilityPointSale);
}

public function filterByWeekNumber(int $weekNumber): self
{
return $this
->andWhere('.weekNumber = :weekNumber')
->setParameter('weekNumber', $weekNumber);
}

public function filterIsNotMainOrderShop(): self
{
return $this
->andWhere('.mainOrderShop = false OR .mainOrderShop IS NULL');
}

public function filterIsNullMainOrderShop(): self
{
return $this
->andWhere('.mainOrderShop IS NULL');
}

public function filterIsNullDeliveryPointSale(): self
{
$this
->joinDeliveryPointSale()
->andWhere(
'.deliveryPointSale IS NULL OR (pointSale.isDepository = 0 AND (pointSale.devAlias IS NULL OR (pointSale.devAlias != :devAliasHorsTournee AND pointSale.devAlias != :devAliasGiftVoucher)))'
)
->setParameterGiftVoucher()
->setParameterHorsTournee();

return $this;
}

public function filterIsNotNullDeliveryPointSale(): self
{
$this
->joinDeliveryPointSale()
->andWhere(
'pointSale IS NOT NULL AND pointSale.isDepository = 1 AND (pointSale.devAlias IS NULL OR (pointSale.devAlias != :devAliasHorsTournee AND pointSale.devAlias != :devAliasGiftVoucher))'
)
->setParameterGiftVoucher()
->setParameterHorsTournee();

return $this;
}


public function filterIsPointSale(string $devAlias = 'devAliasHorsTournee'): self
{
$this
->joinDeliveryPointSale()
->andWhere('pointSale IS NOT NULL AND pointSale.devAlias = :' . $devAlias);

if($devAlias == 'devAliasHorsTournee'){
$this->setParameterHorsTournee();
} elseif($devAlias == 'devAliasGiftVoucher') {
$this->setParameterGiftVoucher();
}

return $this;
}

public function selectOrderReductionCarts(): self
{
$this->joinOrderReductionCarts();

return $this->addSelect('orcart');
}

public function setParameterGiftVoucher(): self
{
if (!$this->isGiftVoucher) {
$this->isGiftVoucher = true;

return $this
->setParameter('devAliasGiftVoucher', PointSale::DEV_ALIAS_GIFT_VOUCHER);
}
return $this;
}

public function setParameterHorsTournee(): self
{
if (!$this->isHorsTournee) {
$this->isHorsTournee = true;

return $this
->setParameter('devAliasHorsTournee', PointSale::DEV_ALIAS_OFF_CIRCUIT);
}
return $this;
}

public function joinOrderReductionCredits(): self
{
if (!$this->isJoinOrderReductionCredits) {
$this->isJoinOrderReductionCredits = true;

return $this
->innerJoin('.orderReductionCredits', 'orc');
}
return $this;
}

public function joinDeliveryAvailabilityZone(): self
{
if (!$this->isJoinDeliveryAvailabilityZone) {
$this->isJoinDeliveryAvailabilityZone = true;

return $this
->leftJoin('.deliveryAvailabilityZone', 'deliveryAvailabilityZone');
}
return $this;
}

public function joinDeliverySlotZone(): self
{
$this->joinDeliveryAvailabilityZone();

if (!$this->isJoinDeliverySlotZone) {
$this->isJoinDeliverySlotZone = true;

return $this
->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone');
}
return $this;
}

public function joinDeliveryAvailabilityPointSale(): self
{
if (!$this->isJoinDeliveryAvailabilityPointSale) {
$this->isJoinDeliveryAvailabilityPointSale = true;

return $this
->leftJoin('.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale');
}
return $this;
}

public function joinDeliverySlotPointSale(): self
{
$this->joinDeliveryAvailabilityZone();

if (!$this->isJoinDeliverySlotPointSale) {
$this->isJoinDeliverySlotPointSale = true;

return $this
->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale');
}
return $this;
}

public function joinOrderStatus(): self
{
if (!$this->isJoinOrderStatus) {
$this->isJoinOrderStatus = true;

return $this
->leftJoin('.orderStatus', 'os');
}
return $this;
}

public function joinOrderReductionCarts(): self
{
if (!$this->isJoinOrderReductionCarts) {
$this->isJoinOrderReductionCarts = true;

return $this
->leftJoin('.orderReductionCarts', 'orcart');
}
return $this;
}

public function joinComplementaryOrderShops(): self
{
if (!$this->isJoinComplementaryOrderShops) {
$this->isJoinComplementaryOrderShops = true;

return $this
->leftJoin('.complementaryOrderShops', 'complementaryOrderShops');
}
return $this;
}

public function joinDeliveryPointSale(): self
{
if (!$this->isJoinDeliveryPointSale) {
$this->isJoinDeliveryPointSale = true;

return $this
->leftJoin('.deliveryPointSale', 'pointSale');
}
return $this;
}
}

+ 514
- 237
Repository/Order/OrderShopStore.php Voir le fichier

@@ -2,17 +2,20 @@

namespace Lc\CaracoleBundle\Repository\Order;

use App\Entity\Order\OrderProduct;
use App\Entity\Order\OrderStatus;
use App\Entity\Section\Section;
use Doctrine\ORM\EntityManagerInterface;
use Lc\CaracoleBundle\Builder\File\DocumentBuilder;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
use Lc\CaracoleBundle\Repository\Section\SectionStore;
use Lc\CaracoleBundle\Resolver\OpeningResolver;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\AbstractStore;
@@ -22,6 +25,8 @@ use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

class OrderShopStore extends AbstractStore
{
use SectionStoreTrait;

protected OrderShopRepositoryQuery $query;
protected EntityManagerInterface $entityManager;
protected PriceResolver $priceResolver;
@@ -63,44 +68,58 @@ class OrderShopStore extends AbstractStore
$this->router = $router;
}

// getOrderShopsOfWeek
public function getByCycle(SectionInterface $section, $params = [])
{
$orderShops = $this->getBy(
array_merge(
[
'section' => $section,
'cycleNumber' => $this->getCycleNumberCurrentOrder($section),
'isValid' => true,
],
$params
)
);

return $orderShops;
}
// getOrderShopsOfWeek
public
function getByCycle(SectionInterface $section, $params = [])
{
$orderShops = $this->getBy(
array_merge(
[
'section' => $section,
'cycleNumber' => $this->getCycleNumberCurrentOrder($section),
'isValid' => true,
],
$params
)
);

return $orderShops;
}

// getOrderShopsOfWeekByUser
public function getByCycleAndUser(SectionInterface $section, UserInterface $user, array $params = [])
{
return $this->getByCycle(
$section,
array_merge(
[
'user' => $user,
'weekNumber' => $this->getCycleNumberCurrentOrder($section),
'excludeComplementaryOrderShops' => true
],
$params
)
);
}
// getOrderShopsOfWeekByUser
public
function getByCycleAndUser(SectionInterface $section, UserInterface $user, array $params = [])
{
return $this->getByCycle(
$section,
array_merge(
[
'user' => $user,
'weekNumber' => $this->getCycleNumberCurrentOrder($section),
'excludeComplementaryOrderShops' => true
],
$params
)
);
}

//public $countOrderShopsOfWeek = null;
//public $countOrderShopsOfWeek = null;

public function countByCycle(SectionInterface $section, bool $excludeComplementaryOrderShops = true)
{
return $this->getByCycle(
public
function countByCycle(SectionInterface $section, bool $excludeComplementaryOrderShops = true)
{
return $this->getByCycle(
$section,
[
'count' => true,
'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops

]
);

// @TODO : optimisation à remettre en place
/*if (is_null($this->countOrderShopsOfWeek)) {
$this->countOrderShopsOfWeek = $this->getByCycle(
$section,
[
'count' => true,
@@ -108,258 +127,516 @@ class OrderShopStore extends AbstractStore

]
);
}
return $this->countOrderShopsOfWeek;*/
}

// @TODO : optimisation à remettre en place
/*if (is_null($this->countOrderShopsOfWeek)) {
$this->countOrderShopsOfWeek = $this->getByCycle(
$section,
[
'count' => true,
'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops
// getNextWeekId
public
function getNextCycleId(SectionInterface $section, int $cycleNumber): int
{
$lastOrder = $this->getOneLastOrderValidOfCycle($section, $cycleNumber);
if ($lastOrder) {
return intval($lastOrder->getCycleId() + 1);
} else {
return 1;
}
}

]
);
}
return $this->countOrderShopsOfWeek;*/
public
function getNextIdValidOrder(Section $section)
{
$lastOrder = $this->getOneLastOrderValid($section);

if ($lastOrder) {
return intval($lastOrder->getIdValidOrder() + 1);
} else {
return 1;
}
}

// getNextWeekId
public function getNextCycleId(SectionInterface $section, int $cycleNumber): int
{
$lastOrder = $this->getOneLastOrderValidOfCycle($section, $cycleNumber);
if ($lastOrder) {
return intval($lastOrder->getCycleId() + 1);
} else {
return 1;
// getOrderDatas
public
function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
{
$data = [];

$data['order'] = $orderShop;

if ($orderShop) {
$data['count'] = $orderShop->countQuantities();
$data['total_with_tax'] = $this->priceResolver->getTotalWithTax($orderShop);
$data['order_products_by_category'] = $orderShop->getOrderProductsByParentCategory();
$data['total_remaining_to_be_paid'] = $this->getTotalRemainingToBePaid($orderShop);
}
return $data;
}

public
function getAsJsonObject(OrderShopInterface $orderShop): array
{
$data['id'] = $orderShop->getId();
$data['user'] = $orderShop->getUser()->getSummary();
$data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
$data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
$data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
$data['total'] = $this->priceResolver->getTotal($orderShop);
$data['totalWithTax'] = $this->priceResolver->getTotalWithTax($orderShop);
$data['totalWithTaxAndReduction'] = $this->priceResolver->getTotalWithTax($orderShop);
$i = 0;

foreach ($orderShop->getOrderProductsByParentCategory() as $labelCategory => $orderProducts) {
foreach ($orderProducts as $orderProduct) {
$data['orderProducts'][$i]['id'] = $orderProduct->getId();
$data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
$data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['labelCategory'] = $labelCategory;
$data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct);
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct);
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction(
$orderProduct
);
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction(
array($orderProduct)
);
$i++;
}
}

public function getNextIdValidOrder(Section $section)
{
$lastOrder = $this->getOneLastOrderValid($section);
return $data;
}

if ($lastOrder) {
return intval($lastOrder->getIdValidOrder() + 1);
} else {
return 1;
public
function groupOrderProductsByProductFamily(array $orderProducts): array
{
$orderProductsByProductFamily = [];
foreach ($orderProducts as $orderProduct) {
if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
$productFamily = $orderProduct->getProduct()->getProductFamily();
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
$orderProductsByProductFamily[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
];
}
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
$orderProductsByProductFamily[$productFamily->getId(
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
)->getCoefficient()) * $orderProduct->getQuantityOrder();
}
}

// getOrderDatas
public function getDatas(OrderShopInterface $orderShop, UserInterface $user = null): array
{
$data = [];
return $orderProductsByProductFamily;
}

$data['order'] = $orderShop;
// isOrderShopPositiveAmount
public
function isPositiveAmount(OrderShopInterface $orderShop)
{
return $this->priceResolver->getTotalWithTax($orderShop) >= 0;
}

if ($orderShop) {
$data['count'] = $orderShop->countQuantities();
$data['total_with_tax'] = $this->priceResolver->getTotalWithTax($orderShop);
$data['order_products_by_category'] = $orderShop->getOrderProductsByParentCategory();
$data['total_remaining_to_be_paid'] = $this->getTotalRemainingToBePaid($orderShop);
}
return $data;
}

public function getAsJsonObject(OrderShopInterface $orderShop): array
{
$data['id'] = $orderShop->getId();
$data['user'] = $orderShop->getUser()->getSummary();
$data['orderStatus'] = $orderShop->getOrderStatus()->__toString();
$data['deliveryAddress'] = $orderShop->getDeliveryAddress()->getSummary();
$data['invoiceAddress'] = $orderShop->getInvoiceAddress()->getSummary();
$data['total'] = $this->priceResolver->getTotal($orderShop);
$data['totalWithTax'] = $this->priceResolver->getTotalWithTax($orderShop);
$data['totalWithTaxAndReduction'] = $this->priceResolver->getTotalWithTax($orderShop);
$i = 0;

foreach ($orderShop->getOrderProductsByParentCategory() as $labelCategory => $orderProducts) {
foreach ($orderProducts as $orderProduct) {
$data['orderProducts'][$i]['id'] = $orderProduct->getId();
$data['orderProducts'][$i]['product'] = $orderProduct->getProduct()->getId();
$data['orderProducts'][$i]['quantityOrder'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['labelCategory'] = $labelCategory;
$data['orderProducts'][$i]['title'] = $orderProduct->getTitle();
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct);
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct);
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction(
$orderProduct
);
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder();
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction(
array($orderProduct)
);
$i++;
}
}
public
function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false)
{
$totalOrderPayments = $this->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop);

return $data;
if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true;
} else {
return false;
}
}

public function groupOrderProductsByProductFamily(array $orderProducts): array
{
$orderProductsByProductFamily = [];
foreach ($orderProducts as $orderProduct) {
if ($orderProduct->getProduct() && $orderProduct->getProduct()->getProductFamily()) {
$productFamily = $orderProduct->getProduct()->getProductFamily();
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) {
$orderProductsByProductFamily[$productFamily->getId()] = [
'order_products' => [],
'total_quantity_weight' => 0,
];
}
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct;
$orderProductsByProductFamily[$productFamily->getId(
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit(
)->getCoefficient()) * $orderProduct->getQuantityOrder();
public
function getTotalOrderPayments(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): float
{
$totalAmount = floatval(0);
foreach ($orderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
}
if ($mergeComplementaryOrderShop) {
foreach ($orderShop->getComplementaryOrderShops() as $complementaryOrderShop) {
foreach ($complementaryOrderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
}
}
}
return $totalAmount;
}

return $orderProductsByProductFamily;
public
function getTotalRemainingToBePaid(OrderShopInterface $orderShop): float
{
return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop);
}

// isOrderShopPositiveAmountRemainingToBePaid
public
function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
{
return $this->getTotalRemainingToBePaid($orderShop) > 0;
}

public
function getCartByUserOrCreateIt($user)
{
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
if ($newOrderShop === null) {
$newOrderShop = $this->createOrderShop(
array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
)
);
}

// isOrderShopPositiveAmount
public function isPositiveAmount(OrderShopInterface $orderShop)
{
return $this->priceResolver->getTotalWithTax($orderShop) >= 0;
return $newOrderShop;
}

public
function isCartAllowToBeOrder(OrderShopInterface $orderShop)
{
return true;
}

// countValidOrderShopByUserAllMerchant
public
function countValidByUserAllMerchant($user)
{
$totalOrder = 0;

foreach ($this->merchantStore->getRepositoryQuery()->findAll() as $merchant) {
$totalOrder += $this->countValidByUser($user, $merchant);
}

public function isPaid(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false)
{
$totalOrderPayments = $this->getTotalOrderPayments($orderShop, $mergeComplementaryOrderShop);
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop);
return $totalOrder;
}

if ((abs($totalOrderPayments - $totalOrder) < 0.00001
|| $totalOrderPayments >= $totalOrder)
&& $totalOrder > 0) {
return true;
} else {
return false;
}
public
function countValidByUser(UserInterface $user, MerchantInterface $merchant = null)
{
return $this->getBy(
[
'user' => $user,
'isValid' => true,
'merchant' => $merchant,
'excludeComplementaryOrderShops' => true,
'count' => true
]
);
}

/*
public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null)
{
$paramsSearchOrderShop = [];

$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();

$orderShop = null;
$orderShopUser = null;
$orderShopVisitor = null;

if ($user) {
$orderShopUser = $this->orderShopRepo->findCartCurrent(
[
'user' => $user
]
);
}

public function getTotalOrderPayments(OrderShopInterface $orderShop, $mergeComplementaryOrderShop = false): float
{
$totalAmount = floatval(0);
foreach ($orderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
if ($visitor) {
$orderShopVisitor = $this->orderShopRepo->findCartCurrent(
[
'visitor' => $visitor
]
);
}

if ($orderShopUser || $orderShopVisitor) {
// merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->utils->addFlash(
'success',
"Votre panier visiteur vient d'être fusionné avec votre panier client."
);
} else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
}
if ($mergeComplementaryOrderShop) {
foreach ($orderShop->getComplementaryOrderShops() as $complementaryOrderShop) {
foreach ($complementaryOrderShop->getOrderPayments() as $orderPayment) {
$totalAmount = $orderPayment->getAmount() + $totalAmount;
}
}
// set user
if ($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user);
$orderShop->setVisitor(null);
$this->em->persist($orderShop);
$this->em->flush();
}
return $totalAmount;
}

public function getTotalRemainingToBePaid(OrderShopInterface $orderShop): float
{
return $this->priceResolver->getTotalWithTax($orderShop) - $this->getTotalOrderPayments($orderShop);
return $orderShop;
}*/


public
function countValidOrderWithReductionCredit(
OrderReductionCreditInterface $reductionCredit,
UserInterface $user = null
): string {
$query = $this->query->create();

if ($user) {
$query->filterByUser($user);
}
$query
->selectCount()
->filterByReductionCredit($reductionCredit)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

return $query->count();
}

public
function countValidOrderWithReductionCart(OrderReductionCartInterface $reductionCart): string
{
$query = $this->query->create();

$query
->selectCount()
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

return $query->count();
}

// isOrderShopPositiveAmountRemainingToBePaid
public function isPositiveAmountRemainingToBePaid(OrderShopInterface $orderShop): bool
{
return $this->getTotalRemainingToBePaid($orderShop) > 0;
public
function countValidOrderWithReductionCartPerUser(
OrderReductionCartInterface $reductionCart,
UserInterface $user
): string {
$query = $this->query->create();

$query
->selectCount()
->filterByUser($user)
->filterByReductionCart($reductionCart)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

return $query->count();
}

//findCartCurrent
public
function getCartCurrent(array $params): ?OrderShopInterface
{
$query = $this->query->create();

if (isset($params['user'])) {
$query
->filterByUser($params['user']);
}
if (isset($params['visitor'])) {
$query
->filterByVisitor($params['visitor']);
}

public function getCartByUserOrCreateIt($user)
{
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]);
if ($newOrderShop === null) {
$newOrderShop = $this->createOrderShop(
array(
'user' => $user,
'merchant' => $this->merchantUtils->getMerchantUser()
)
);
}
$query
->selectOrderReductionCarts()
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterBySection($this->section);

$results = $query->find();

return $newOrderShop;
if ($results) {
return $results[0];
}

public function isCartAllowToBeOrder(OrderShopInterface $orderShop, bool $forceByAdmin = false)
{
return true;
return null;
}

//findLastOrderValidOfWeek
public
function getOneLastOrderValidOfWeek(int $weekNumber): ?OrderShopInterface
{
$query = $this->query->create();

$query
->filterByWeekNumber($weekNumber)
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.weekId', 'DESC')
->filterBySection($this->section);

return $query->findOne();
}

//findLastOrderValid
public
function getOneLastOrderValid(): ?OrderShopInterface
{
$query = $this->query->create();

$query
->filterByStatus(OrderStatus::$statusAliasAsValid)
->filterIsNotMainOrderShop()
->orderBy('.idValidOrder', 'DESC')
->filterBySection($this->section);

return $query->findOne();
}

//TODO Fonction à tester

// findAllBy
public
function getAllBy(array $params = [])
{
$query = $this->query->create();

if (isset($params['section'])) {
$query->filterBySection($params['section']);
} else {
$query->filterBySection($this->section);
}

// countValidOrderShopByUserAllMerchant
public function countValidByUserAllMerchant($user)
{
$totalOrder = 0;
if (isset($params['count']) && $params['count']) {
$query->selectCount();
}

foreach ($this->merchantStore->getRepositoryQuery()->findAll() as $merchant) {
$totalOrder += $this->countValidByUser($user, $merchant);
}
if (isset($params['select'])) {
$query->selectParam($params['select']);
}

return $totalOrder;
if (isset($params['dateStart']) || isset($params['dateEnd'])) {
$params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate';
}

public function countValidByUser(UserInterface $user, MerchantInterface $merchant = null)
{
return $this->getBy(
[
'user' => $user,
'isValid' => true,
'merchant' => $merchant,
'excludeComplementaryOrderShops' => true,
'count' => true
]
);
if (isset($params['dateStart'])) {
$query->filterByDateStart($params['dateField'], $params['dateStart']);
}

if (isset($params['dateEnd'])) {
$query->filterByDateEnd($params['dateField'], $params['dateEnd']);
}

/*
public function getCartCurrent(SectionInterface $section, UserInterface $user = null, VisitorInterface $visitor = null)
{
$paramsSearchOrderShop = [];
if (isset($params['weekNumber'])) {
$query->filterByWeekNumber($params['weekNumber']);
}

$user = $this->security->getUser();
$visitor = $this->userUtils->getVisitorCurrent();
if (isset($params['isCart'])) {
$query->filterByStatus(OrderStatus::$statusAliasAsCart);
}

$orderShop = null;
$orderShopUser = null;
$orderShopVisitor = null;
if (isset($params['isValid'])) {
$query->filterByStatus(OrderStatus::$statusAliasAsValid);
}

if ($user) {
$orderShopUser = $this->orderShopRepo->findCartCurrent(
[
'user' => $user
]
);
}
if (isset($params['isWaitingDelivery'])) {
$query->filterByStatus(OrderStatus::$statusAliasWaitingDelivery);
}

if ($visitor) {
$orderShopVisitor = $this->orderShopRepo->findCartCurrent(
[
'visitor' => $visitor
]
);
if (isset($params['orderStatus'])) {
$query->filterByStatus($params['orderStatus']);
}

if (isset($params['user'])) {
$query->filterByUser($params['user']);
}

if (isset($params['address'])) {
$query->filterByAddress($params['address']);
}

if (isset($params['weekDeliveryTrucks'])) {
$query->filterByWeekDeliveryTruck($params['weekDeliveryTrucks']);
}

if (isset($params['estimatedDeliveryDateTime'])) {
$date = clone $params['estimatedDeliveryDateTime'];
$query
->filterByEstimatedDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByEstimatedDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
}


if (isset($params['deliveryDate'])) {
$date = clone $params['deliveryDate'];
$query
->filterByDeliveryDateStart($date->format('Y-m-d 00:00:00'))
->filterByDeliveryDateEnd($date->modify('+1 day')->format('Y-m-d 00:00:00'));
}

if (isset($params['mergeComplementaryOrderShops'])) {
//TODO jointure peut être pas utile
$query
->joinComplementaryOrderShops();
}

if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) {
$query->filterIsNullMainOrderShop();
}

if (isset($params['isCircuit'])) {
$query->filterIsNullDeliveryPointSale();
}

if (isset($params['isDepository'])) {
$query->filterIsNotNullDeliveryPointSale();
}

if (isset($params['isOffCircuit'])) {
$query->filterIsPointSale('devAliasHorsTournee');
}

if (isset($params['isGiftVoucher'])) {
$query->filterIsPointSale('devAliasGiftVoucher');
}

if (isset($params['deliveryAvailability'])) {
$deliveryAvailability = $params['deliveryAvailability'];
$deliveryAvailabilityZone = ($deliveryAvailability instanceof DeliveryAvailabilityZone) ? $deliveryAvailability : false;
$deliveryAvailabilityPointSale = ($deliveryAvailability instanceof DeliveryAvailabilityPointSale) ? $deliveryAvailability : false;

if ($deliveryAvailabilityZone) {
$query->filterByAvailabilityPointZone($deliveryAvailabilityZone);
}

if ($orderShopUser || $orderShopVisitor) {
// merge
if ($orderShopUser && $orderShopVisitor && $orderShopUser != $orderShopVisitor
&& $orderShopVisitor->getOrderProducts() && count($orderShopVisitor->getOrderProducts())
&& $orderShopUser->getOrderStatus()->getAlias() == OrderStatus::ALIAS_CART) {
$orderShop = $this->mergeOrderShops($orderShopUser, $orderShopVisitor);
$this->utils->addFlash(
'success',
"Votre panier visiteur vient d'être fusionné avec votre panier client."
);
} else {
$orderShop = ($orderShopUser) ? $orderShopUser : $orderShopVisitor;
}
// set user
if ($orderShop && $user && !$orderShop->getUser()) {
$orderShop->setUser($user);
$orderShop->setVisitor(null);
$this->em->persist($orderShop);
$this->em->flush();
}
if ($deliveryAvailabilityPointSale) {
$query->filterByAvailabilityPointZone($deliveryAvailabilityPointSale);
}
} else {
$query->joinDeliverySlotZone();
$query->joinDeliverySlotPointSale();
}

if (isset($params['orderBy'])) {
$query->orderBy(
$params['orderBy'],
isset($params['orderByDirection']) ? $params['orderByDirection'] : 'DESC'
);
} else {
$query->orderBy('.id', 'DESC');
}

return $orderShop;
}*/
if (isset($params['groupBy'])) {
$query->groupBy($params['groupBy']);
}

if (isset($params['count']) && $params['count']) {
return $query->count();
}

return $query->find();
}
}

+ 2
- 0
Repository/PointSale/PointSaleRepositoryQuery.php Voir le fichier

@@ -5,10 +5,12 @@ namespace Lc\CaracoleBundle\Repository\PointSale;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\StatusRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class PointSaleRepositoryQuery extends AbstractRepositoryQuery
{
use StatusRepositoryQueryTrait;

public function __construct(PointSaleRepository $repository, PaginatorInterface $paginator)
{

+ 3
- 0
Repository/PointSale/PointSaleStore.php Voir le fichier

@@ -2,10 +2,13 @@

namespace Lc\CaracoleBundle\Repository\PointSale;

use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\SovBundle\Repository\AbstractStore;

class PointSaleStore extends AbstractStore
{
use MerchantStoreTrait;

protected PointSaleRepositoryQuery $query;

public function __construct(PointSaleRepositoryQuery $query)

+ 2
- 0
Repository/Product/ProductFamilyRepositoryQuery.php Voir le fichier

@@ -5,11 +5,13 @@ namespace Lc\CaracoleBundle\Repository\Product;
use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\StatusRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;

class ProductFamilyRepositoryQuery extends AbstractRepositoryQuery
{
use SectionRepositoryQueryTrait;
use StatusRepositoryQueryTrait;

public function __construct(ProductFamilyRepository $repository, PaginatorInterface $paginator)
{

+ 3
- 0
Repository/Product/ProductFamilyStore.php Voir le fichier

@@ -4,11 +4,14 @@ namespace Lc\CaracoleBundle\Repository\Product;

use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\CaracoleBundle\Resolver\Price\PriceResolver;
use Lc\SovBundle\Repository\AbstractStore;

class ProductFamilyStore extends AbstractStore
{
use SectionStoreTrait;

protected ProductFamilyRepositoryQuery $query;
protected PriceResolver $priceResolver;


+ 34
- 5
Repository/Reminder/ReminderStore.php Voir le fichier

@@ -2,10 +2,9 @@

namespace Lc\CaracoleBundle\Repository\Reminder;

use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Repository\Reminder\ReminderStore as SovReminderStore;

class ReminderStore extends SovReminderStore
@@ -15,19 +14,49 @@ class ReminderStore extends SovReminderStore

public function get($params = [], $query = null)
{
if(is_null($query)) {
if (is_null($query)) {
$query = $this->query->create();
}

if($this->merchant) {
if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

if($this->section) {
if ($this->section) {
$query->filterBySection($this->section);
}

return parent::get($params, $query);
}

public function getByUser(UserInterface $user, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::getByUser($user, $query);
}

public function getByEasyAdminConfigAndUser(
string $crudAction,
string $crudControllerFqcn,
UserInterface $user,
int $entityId = null,
$query = null
): array {
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::getByEasyAdminConfigAndUser($crudAction, $crudControllerFqcn, $user, $entityId, $query);
}
}

+ 0
- 27
Repository/Reminder/TicketStore.php Voir le fichier

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

namespace Lc\CaracoleBundle\Repository\Reminder;

use Lc\SovBundle\Repository\Reminder\ReminderStore as SovReminderStore;
use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;

class TicketStore extends SovReminderStore
{
protected MerchantInterface $merchant;

public function setMerchant(MerchantInterface $merchant)
{
$this->merchant = $merchant;
}

public function getFoo($query = null)
{
$query = $this->query->create();

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::getFoo($query);
}
}

+ 25
- 0
Repository/Site/NewsStore.php Voir le fichier

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

namespace Lc\CaracoleBundle\Repository\Site;

use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\SovBundle\Repository\Site\NewsStore as SovNewsStore;

class NewsStore extends SovNewsStore
{
use MerchantStoreTrait;

public function getLatests(int $maxResults = 0, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::getLatests($maxResults, $query);
}

}

+ 9
- 0
Repository/Site/PageRepositoryQuery.php Voir le fichier

@@ -4,10 +4,19 @@ namespace Lc\CaracoleBundle\Repository\Site;

use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\SectionRepositoryQueryTrait;
use Lc\CaracoleBundle\Repository\StatusRepositoryQueryTrait;
use Lc\SovBundle\Repository\Site\PageRepositoryQuery as SovPageRepositoryQuery;

class PageRepositoryQuery extends SovPageRepositoryQuery
{
use SectionRepositoryQueryTrait;
use StatusRepositoryQueryTrait;

public function filterByDevAlias(string $devAlias): self
{
return $this
->andWhere('.devAlias = :devAlias')
->setParameter('devAlias', $devAlias);
}

}

+ 59
- 0
Repository/Site/PageStore.php Voir le fichier

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

namespace Lc\CaracoleBundle\Repository\Site;

use Lc\CaracoleBundle\Model\Section\SectionInterface;
use Lc\CaracoleBundle\Repository\SectionStoreTrait;
use Lc\SovBundle\Model\Site\PageInterface;
use Lc\SovBundle\Repository\Site\PageStore as SovPageStore;

class PageStore extends SovPageStore
{
use SectionStoreTrait;

public function __construct(PageRepositoryQuery $query)
{
parent::__construct($query);
}

// TODO Vérifier si c'est good avec la section
// findPage
public function getOnePage(string $devAlias, SectionInterface $section = null): ?PageInterface
{
$query = $this->query->create();

if ($section == null) {
$section = $this->section;
}
$query
->filterIsOnline()
->filterByDevAlias($devAlias)
->filterBySection($section);

return $query->findOne();
}

// public function findPage($devAlias, $devAliasMerchant = false)
// {
// $merchant = false;
//
// if ($devAliasMerchant) {
// $merchant = $this->merchantUtils->getMerchantByDevAlias($devAliasMerchant);
// }
//
// if ($devAliasMerchant && $merchant) {
// $query = $this->createQueryBuilder('e')
// ->where('e.merchant = :merchant')
// ->setParameter('merchant', $merchant->getId());
// } else {
// $query = $this->findByMerchantQuery();
// }
//
// return $query->andWhere('e.status = 1')
// ->andWhere('e.devAlias = :devAlias')
// ->setParameter('devAlias', $devAlias)
// ->getQuery()
// ->getOneOrNullResult();
// }

}

+ 51
- 0
Repository/Ticket/TicketStore.php Voir le fichier

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

namespace Lc\CaracoleBundle\Repository\Ticket;

use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\SovBundle\Repository\Ticket\TicketStore as SovTicketStore;

class TicketStore extends SovTicketStore
{
use MerchantStoreTrait;

public function getByUser($user, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::getByUser($user, $query);
}

public function getAllOpen(int $limit = 0, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::getAllOpen($limit, $query);
}

public function countAllOpen($query = null): string
{
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query->filterByMerchant($this->merchant);
}

return parent::countAllOpen($query);
}

}

+ 0
- 15
Repository/User/GroupUserRepository.php Voir le fichier

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

namespace Lc\CaracoleBundle\Repository\User;

use App\Entity\User\GroupUser;
use Doctrine\Persistence\ManagerRegistry;
use Lc\SovBundle\Repository\AbstractRepository;

class GroupUserRepository extends AbstractRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, GroupUser::class);
}
}

+ 2
- 8
Repository/User/GroupUserRepositoryQuery.php Voir le fichier

@@ -2,16 +2,10 @@

namespace Lc\CaracoleBundle\Repository\User;

use Knp\Component\Pager\PaginatorInterface;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\SovBundle\Repository\AbstractRepositoryQuery;
use Lc\SovBundle\Repository\User\GroupUserRepositoryQuery as SovAbstractRepositoryQuery;

class GroupUserRepositoryQuery extends AbstractRepositoryQuery
class GroupUserRepositoryQuery extends SovAbstractRepositoryQuery
{
use MerchantRepositoryQueryTrait;

public function __construct(GroupUserRepository $repository, PaginatorInterface $paginator)
{
parent::__construct($repository, 'r', $paginator);
}
}

+ 2
- 7
Repository/User/GroupUserStore.php Voir le fichier

@@ -2,14 +2,9 @@

namespace Lc\CaracoleBundle\Repository\User;

use Lc\SovBundle\Repository\AbstractStore;
use Lc\SovBundle\Repository\User\GroupUserStore as SovGroupUserStore;

class GroupUserStore extends AbstractStore
class GroupUserStore extends SovGroupUserStore
{
protected GroupUserRepositoryQuery $query;

public function __construct(GroupUserRepositoryQuery $query)
{
$this->query = $query;
}
}

+ 40
- 0
Repository/User/UserRepositoryQuery.php Voir le fichier

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

namespace Lc\CaracoleBundle\Repository\User;

use App\Entity\Merchant\Merchant;
use Lc\CaracoleBundle\Repository\MerchantRepositoryQueryTrait;
use Lc\SovBundle\Repository\User\UserRepositoryQuery as SovUserRepositoryQuery;

class UserRepositoryQuery extends SovUserRepositoryQuery
{
use MerchantRepositoryQueryTrait;

protected $isJoinUserMerchants = false;

public function joinUserMerchants(): self
{
if (!$this->isJoinUserMerchants) {
$this->isJoinUserMerchants = true;

return $this
->innerJoin('.userMerchants', 'um');
}
return $this;
}

public function filterMerchantIsActive(): self
{
$this->joinUserMerchants();
return $this
->andWhere('um.active = 1');
}

public function filterByJoinUserMerchant(Merchant $merchant): self
{
$this->joinUserMerchants();
return $this
->andWhere('um.merchant = :merchant')
->setParameter('merchant', $merchant);
}
}

+ 27
- 0
Repository/User/UserStore.php Voir le fichier

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

namespace Lc\CaracoleBundle\Repository\User;

use App\Entity\Newsletter\Newsletter;
use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
use Lc\SovBundle\Repository\User\UserStore as SovUserStore;

class UserStore extends SovUserStore
{
use MerchantStoreTrait;

public function getByNewsletter(Newsletter $newsletter, $query = null): array
{
if (is_null($query)) {
$query = $this->query->create();
}

if ($this->merchant) {
$query
->filterByJoinUserMerchant($this->merchant)
->filterMerchantIsActive();
}

return parent::getByNewsletter($newsletter, $query);
}
}

+ 6
- 0
Resources/assets/app/admin/duplicate/app.duplicate.js Voir le fichier

@@ -0,0 +1,6 @@

import './duplicate.js' ;
import './duplicate.scss' ;




+ 36
- 0
Resources/assets/app/admin/duplicate/duplicate.js Voir le fichier

@@ -0,0 +1,36 @@
$(document).ready(function () {
initDuplicateOtherToOtherMerchant();
});

function initDuplicateOtherToOtherMerchant() {
$('.duplicate-modal-action').on('click', function (e) {
$btn = $(this);
e.preventDefault();
$.ajax({
url: $btn.prop('href'),
method: "POST",
dataType: "json",
success: function (response) {
$('body').append(response.data);
SovTools.log($('#carac-modal-duplicate'));
$('#carac-modal-duplicate').modal('show');
//initDuplicateModal();

}
});
});
}

function initDuplicateModal(){
$('#carac-button-visit-merchant').on('click', function (e){
SovTools.log($('form[name="duplicate_to_other_merchant_form"]'));
$.ajax({
url: $btn.prop('href'),
data: $('form[name="duplicate_to_other_merchant_form"]').serialize(),
method: "POST",
dataType: "json",
success: function (response) {
}
});
});
}

+ 37
- 0
Resources/assets/app/admin/duplicate/duplicate.scss Voir le fichier

@@ -0,0 +1,37 @@

// switch dans la navbar
.nav-switch-merchant {
width: 220px ;
text-align: right ;

.fa {
position: relative;
top: 3px;
right: 7px;
}

form.switch-merchant {
display: inline-block ;
width: 180px ;
position: relative ;
top: 7px ;
text-align: left ;

label, .select2-selection__clear {
display: none ;
}

button {
display: none ;
}
}
}

// modal
#carac-modal-switch-merchant {
form.switch-merchant {
.form-group:first-child {
display: none ;
}
}
}

+ 6
- 0
Resources/translations/admin.fr.yaml Voir le fichier

@@ -17,9 +17,13 @@ menu:

flash_message:
settings_saved: Paramètres mis à jour
duplicateToOtherMerchant: "Le document a bien été dupliqué sur le marchand : %merchant%"
duplicateToOtherSection: "Le document a bien été dupliqué sur la section : %section%"

action:
favorite: Définir comme favoris
duplicateToOtherMerchant: Dupliquer sur un autre marchand
duplicateToOtherSection: Dupliquer sur une autre section

setting_definition:
merchant:
@@ -49,6 +53,8 @@ entity:
address: Adresse
merchant: Marchand
taxRate: Règle de taxe
merchants: Marchands
sections: Sections
behaviorTaxRate: Avec ou sans TVA
behaviorTaxRateChoices:
tax-excluded: TVA exclue

+ 14
- 0
Resources/views/admin/merchant/modal/duplicate_entity_to_other_merchant.html.twig Voir le fichier

@@ -0,0 +1,14 @@
{% embed '@LcSov/adminlte/embed/modal.twig' %}
{% block id %}carac-modal-duplicate{% endblock %}
{% block title %}
Dupliquer l'entité sur un autre marchand
{% endblock %}
{% block body %}
{% form_theme form_duplicate_entity_to_other_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form(form_duplicate_entity_to_other_merchant) }}
{% endblock %}
{% block footer %}
<button type="submit" class="btn btn-default" data-dismiss="modal">{{ "cancel"|sov_trans_admin_action }}</button>
<button type="submit" class="btn btn-primary" form="{{ form_duplicate_entity_to_other_merchant.vars.attr.id }}">{{ "duplicate"|sov_trans_admin_action }}</button>
{% endblock %}
{% endembed %}

+ 14
- 0
Resources/views/admin/merchant/modal/duplicate_entity_to_other_section.html.twig Voir le fichier

@@ -0,0 +1,14 @@
{% embed '@LcSov/adminlte/embed/modal.twig' %}
{% block id %}carac-modal-duplicate{% endblock %}
{% block title %}
Dupliquer l'entité sur une autre section
{% endblock %}
{% block body %}
{% form_theme form_duplicate_entity_to_other_section '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form(form_duplicate_entity_to_other_section) }}
{% endblock %}
{% block footer %}
<button class="btn btn-default" data-dismiss="modal">{{ "cancel"|sov_trans_admin_action }}</button>
<button type="submit" class="btn btn-primary" form="{{ form_duplicate_entity_to_other_section.vars.attr.id }}">{{ "duplicate"|sov_trans_admin_action }}</button>
{% endblock %}
{% endembed %}

+ 26
- 0
Resources/views/admin/merchant/modal/switch_merchant.html.twig Voir le fichier

@@ -0,0 +1,26 @@
{% embed '@LcSov/adminlte/embed/modal.twig' %}
{% block id %}carac-modal-switch-merchant{% endblock %}
{% block size %}modal-lg{% endblock %}
{% block title %}
Bienvenue sur le marchand <i>{{ merchant_current.getTitle() }}</i>
{% endblock %}
{% block body %}
{% if not user.favoriteMerchant %}
<p>Vous n'avez pas de marchand favoris.</p>
{% endif %}
{% if user.favoriteMerchant and user.favoriteMerchant != merchant_current %}
<p>Vous n'êtes pas sur votre marchand par favoris.</p>
{% endif %}
<p>Vous pouvez soit définir le marchand <strong>{{ merchant_current.getTitle() }}</strong>
comme marchand favoris ou simplement indiquer que vous visitez ce marchand pour aujourd'hui.</p>
{% endblock %}
{% block footer %}
{% set form_switch_merchant = carac_form_switch_merchant('admin', 'carac_merchant_favorite') %}
{% form_theme form_switch_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_merchant) }}
{{ form(form_switch_merchant) }}
{{ form_end(form_switch_merchant) }}
<button id="carac-button-visit-merchant" type="button" class="btn btn-default"
data-dismiss="modal">Visiter</button>
{% endblock %}
{% endembed %}

+ 1
- 26
Resources/views/adminlte/layout.html.twig Voir le fichier

@@ -47,31 +47,6 @@

{% if(user.favoriteMerchant != merchant_current) %}
{# modal affichée uniquement si la sessionStorage.visit_merchant n'est pas défini (js) #}
{% embed '@LcSov/adminlte/embed/modal.twig' %}
{% block id %}carac-modal-switch-merchant{% endblock %}
{% block size %}modal-lg{% endblock %}
{% block title %}
Bienvenue sur le marchand <i>{{ merchant_current.getTitle() }}</i>
{% endblock %}
{% block body %}
{% if not user.favoriteMerchant %}
<p>Vous n'avez pas de marchand favoris.</p>
{% endif %}
{% if user.favoriteMerchant and user.favoriteMerchant != merchant_current %}
<p>Vous n'êtes pas sur votre marchand par favoris.</p>
{% endif %}
<p>Vous pouvez soit définir le marchand <strong>{{ merchant_current.getTitle() }}</strong>
comme marchand favoris ou simplement indiquer que vous visitez ce marchand pour aujourd'hui.</p>
{% endblock %}
{% block footer %}
{% set form_switch_merchant = carac_form_switch_merchant('admin', 'carac_merchant_favorite') %}
{% form_theme form_switch_merchant '@LcSov/adminlte/crud/form_theme.html.twig' %}
{{ form_start(form_switch_merchant) }}
{{ form(form_switch_merchant) }}
{{ form_end(form_switch_merchant) }}
<button id="carac-button-visit-merchant" type="button" class="btn btn-default"
data-dismiss="modal">Visiter</button>
{% endblock %}
{% endembed %}
{% include '@LcCaracole/admin/merchant/modal/switch_merchant.html.twig' %}
{% endif %}
{% endblock %}

Chargement…
Annuler
Enregistrer