浏览代码

Fonction shortcut + actionDefinition et correcftif

packProduct
Fab 3 年前
父节点
当前提交
c8105ae44a
共有 10 个文件被更改,包括 216 次插入78 次删除
  1. +72
    -43
      Controller/AdminControllerTrait.php
  2. +13
    -1
      Controller/ControllerTrait.php
  3. +3
    -2
      Controller/Credit/CreditHistoryAdminController.php
  4. +5
    -4
      Controller/User/UserMerchantAdminController.php
  5. +11
    -0
      Definition/ActionDefinition.php
  6. +0
    -21
      Model/Order/OrderProductModel.php
  7. +106
    -3
      Repository/Order/OrderShopRepositoryQuery.php
  8. +4
    -1
      Repository/Order/OrderShopStore.php
  9. +1
    -0
      Repository/Product/ProductRepositoryQuery.php
  10. +1
    -3
      Resources/assets/app/admin/duplicate/duplicate.js

+ 72
- 43
Controller/AdminControllerTrait.php 查看文件

@@ -45,6 +45,7 @@ use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer;
use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
use Lc\CaracoleBundle\Container\User\UserPointSaleContainer;
use Lc\CaracoleBundle\Container\User\VisitorContainer;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMerchantInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterMultipleMerchantsInterface;
use Lc\CaracoleBundle\Doctrine\Extension\FilterSectionInterface;
@@ -55,6 +56,7 @@ 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\Solver\Setting\SettingSolver;
use Lc\SovBundle\Translation\TranslatorAdmin;
use Symfony\Component\HttpFoundation\Response;

@@ -65,43 +67,48 @@ trait AdminControllerTrait
{
return array_merge(
parent::getSubscribedServices(),
[
MerchantResolver::class => MerchantResolver::class,
SectionResolver::class => SectionResolver::class,
AddressContainer::class => AddressContainer::class,
TaxRateContainer::class => TaxRateContainer::class,
UnitContainer::class => UnitContainer::class,
CreditHistoryContainer::class => CreditHistoryContainer::class,
DocumentContainer::class => DocumentContainer::class,
MerchantContainer::class => MerchantContainer::class,
OrderPaymentContainer::class => OrderPaymentContainer::class,
OrderProductContainer::class => OrderProductContainer::class,
OrderProductReductionCatalogContainer::class => OrderProductReductionCatalogContainer::class,
OrderProductRefundContainer::class => OrderProductRefundContainer::class,
OrderReductionCartContainer::class => OrderReductionCartContainer::class,
OrderReductionCreditContainer::class => OrderReductionCreditContainer::class,
OrderRefundContainer::class => OrderRefundContainer::class,
OrderShopContainer::class => OrderShopContainer::class,
OrderStatusContainer::class => OrderStatusContainer::class,
OrderStatusHistoryContainer::class => OrderStatusHistoryContainer::class,
PointSaleContainer::class => PointSaleContainer::class,
ProductCategoryContainer::class => ProductCategoryContainer::class,
ProductContainer::class => ProductContainer::class,
ProductFamilyContainer::class => ProductFamilyContainer::class,
ReductionCartContainer::class => ReductionCartContainer::class,
ReductionCatalogContainer::class => ReductionCatalogContainer::class,
ReductionCreditContainer::class => ReductionCreditContainer::class,
OpeningContainer::class => OpeningContainer::class,
SectionContainer::class => SectionContainer::class,
MerchantSettingContainer::class => MerchantSettingContainer::class,
SectionSettingContainer::class => SectionSettingContainer::class,
UserMerchantContainer::class => UserMerchantContainer::class,
UserPointSaleContainer::class => UserPointSaleContainer::class,
VisitorContainer::class => VisitorContainer::class
]
self::getSubscribedServicesList()
);
}

public static function getSubscribedServicesList()
{
return [
MerchantResolver::class => MerchantResolver::class,
SectionResolver::class => SectionResolver::class,
AddressContainer::class => AddressContainer::class,
TaxRateContainer::class => TaxRateContainer::class,
UnitContainer::class => UnitContainer::class,
CreditHistoryContainer::class => CreditHistoryContainer::class,
DocumentContainer::class => DocumentContainer::class,
MerchantContainer::class => MerchantContainer::class,
OrderPaymentContainer::class => OrderPaymentContainer::class,
OrderProductContainer::class => OrderProductContainer::class,
OrderProductReductionCatalogContainer::class => OrderProductReductionCatalogContainer::class,
OrderProductRefundContainer::class => OrderProductRefundContainer::class,
OrderReductionCartContainer::class => OrderReductionCartContainer::class,
OrderReductionCreditContainer::class => OrderReductionCreditContainer::class,
OrderRefundContainer::class => OrderRefundContainer::class,
OrderShopContainer::class => OrderShopContainer::class,
OrderStatusContainer::class => OrderStatusContainer::class,
OrderStatusHistoryContainer::class => OrderStatusHistoryContainer::class,
PointSaleContainer::class => PointSaleContainer::class,
ProductCategoryContainer::class => ProductCategoryContainer::class,
ProductContainer::class => ProductContainer::class,
ProductFamilyContainer::class => ProductFamilyContainer::class,
ReductionCartContainer::class => ReductionCartContainer::class,
ReductionCatalogContainer::class => ReductionCatalogContainer::class,
ReductionCreditContainer::class => ReductionCreditContainer::class,
OpeningContainer::class => OpeningContainer::class,
SectionContainer::class => SectionContainer::class,
MerchantSettingContainer::class => MerchantSettingContainer::class,
SectionSettingContainer::class => SectionSettingContainer::class,
UserMerchantContainer::class => UserMerchantContainer::class,
UserPointSaleContainer::class => UserPointSaleContainer::class,
VisitorContainer::class => VisitorContainer::class
];
}

public function configureResponseParameters(KeyValueStore $responseParameters): KeyValueStore
{
$responseParameters = parent::configureResponseParameters($responseParameters);
@@ -189,7 +196,7 @@ trait AdminControllerTrait
$em->flush();

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::EDIT)
->setAction(ActionDefinition::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();
$this->addFlashTranslator(
@@ -226,7 +233,7 @@ trait AdminControllerTrait
) {
if (!$this->isGranted(
Permission::EA_EXECUTE_ACTION,
['action' => "duplicate", 'entity' => $context->getEntity()]
['action' => ActionDefinition::DUPLICATE, 'entity' => $context->getEntity()]
)) {
throw new ForbiddenActionException($context);
}
@@ -260,7 +267,7 @@ trait AdminControllerTrait
$em->flush();

$url = $this->get(AdminUrlGenerator::class)
->setAction(Action::EDIT)
->setAction(ActionDefinition::EDIT)
->setEntityId($newEntity->getId())
->generateUrl();
$this->addFlashTranslator(
@@ -304,11 +311,11 @@ trait AdminControllerTrait
public function getDuplicateToOhterMerchantAction(): Action
{
$duplicateAction = Action::new(
'duplicateToOtherMerchant',
$this->get(TranslatorAdmin::class)->transAction('duplicateToOtherMerchant'),
ActionDefinition::DUPLICATE_TO_OTHER_MERCHANT,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE_TO_OTHER_MERCHANT),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicateToOtherMerchant')
->linkToCrudAction(ActionDefinition::DUPLICATE_TO_OTHER_MERCHANT)
->setCssClass('text-info in-dropdown duplicate-to-other-merchant duplicate-modal-action');

return $duplicateAction;
@@ -317,11 +324,11 @@ trait AdminControllerTrait
public function getDuplicateToOhterSectionAction(): Action
{
$duplicateAction = Action::new(
'duplicateToOtherSection',
$this->get(TranslatorAdmin::class)->transAction('duplicateToOtherSection'),
ActionDefinition::DUPLICATE_TO_OTHER_SECTION,
$this->get(TranslatorAdmin::class)->transAction(ActionDefinition::DUPLICATE_TO_OTHER_SECTION),
'fa fa-fw fa-copy'
)
->linkToCrudAction('duplicateToOtherSection')
->linkToCrudAction(ActionDefinition::DUPLICATE_TO_OTHER_SECTION)
->setCssClass('text-info in-dropdown duplicate-to-other-section duplicate-modal-action');

return $duplicateAction;
@@ -336,5 +343,27 @@ trait AdminControllerTrait
{
return $this->get(MerchantResolver::class)->getCurrent();
}

public function getMerchantSettingCurrent(string $settingName)
{
return $this->getSettingValue($this->getCurrentMerchant(), $settingName);
}

public function getSectionSettingCurrent(string $settingName)
{
return $this->getSettingValue($this->getCurrentSection(), $settingName);
}

public function getSettingSolver(): SettingSolver
{
return $this->get(SettingSolver::class);
}

public function getSettingValue($entity, $settingName)
{
return $this->getSettingSolver()->getSettingValue($entity, $settingName);
}


}


+ 13
- 1
Controller/ControllerTrait.php 查看文件

@@ -42,6 +42,7 @@ use Lc\CaracoleBundle\Resolver\SectionResolver;
use Lc\CaracoleBundle\Resolver\VisitorResolver;
use Lc\CaracoleBundle\Solver\Price\PriceSolver;
use Lc\SovBundle\Model\User\UserInterface;
use Lc\SovBundle\Solver\Setting\SettingSolver;
use Symfony\Component\Security\Core\Security;

trait ControllerTrait
@@ -98,6 +99,17 @@ trait ControllerTrait
return $this->getSettingValue($this->getCurrentSection(), $settingName);
}

public function getSettingSolver(): SettingSolver
{
return $this->get(SettingSolver::class);
}

public function getSettingValue($entity, $settingName)
{
return $this->getSettingSolver()->getSettingValue($entity, $settingName);
}


public function getUserCurrent(): ?UserInterface
{
return $this->get(Security::class)->getUser();
@@ -294,4 +306,4 @@ trait ControllerTrait
{
return $this->get(VisitorContainer::class);
}
}
}

+ 3
- 2
Controller/Credit/CreditHistoryAdminController.php 查看文件

@@ -22,6 +22,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use Lc\CaracoleBundle\Container\Credit\CreditHistoryContainer;
use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Factory\Credit\CreditHistoryFactory;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryInterface;
use Lc\CaracoleBundle\Model\Credit\CreditHistoryModel;
@@ -45,7 +46,7 @@ abstract class CreditHistoryAdminController extends AbstractAdminController
foreach ($actions as $action) {
$url = $adminUrlGenerator
->setController($creditControllerFqcn)
->setAction(Action::NEW)
->setAction(ActionDefinition::NEW)
->set('userMerchantId', $this->getUserMerchant()->getId())
->generateUrl();
$action->setLinkUrl($url);
@@ -75,7 +76,7 @@ abstract class CreditHistoryAdminController extends AbstractAdminController

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

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

+ 5
- 4
Controller/User/UserMerchantAdminController.php 查看文件

@@ -26,6 +26,7 @@ use EasyCorp\Bundle\EasyAdminBundle\Router\AdminUrlGenerator;
use EasyCorp\Bundle\EasyAdminBundle\Security\Permission;
use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
use Lc\CaracoleBundle\Controller\AdminControllerTrait;
use Lc\CaracoleBundle\Definition\ActionDefinition;
use Lc\CaracoleBundle\Factory\User\UserFactory;
use Lc\CaracoleBundle\Factory\User\UserMerchantFactory;
use Lc\CaracoleBundle\Form\Credit\CreditHistoryFormType;
@@ -145,7 +146,7 @@ abstract class UserMerchantAdminController extends AbstractAdminController
$entityManager->create($userMerchant);
$entityManager->flush();
$this->addFlashTranslator('success','created');
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl();
$url = $this->get(AdminUrlGenerator::class)->setAction(ActionDefinition::INDEX)->generateUrl();

return $this->redirect($url);
} else {
@@ -157,7 +158,7 @@ abstract class UserMerchantAdminController extends AbstractAdminController
$entityManager->flush();

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

return $this->redirect($url);
} else {
@@ -196,7 +197,7 @@ abstract class UserMerchantAdminController extends AbstractAdminController
$entityManager->update($userMerchant->getUser());
$entityManager->flush();
$this->addFlashTranslator('success', 'updated');
$url = $this->get(AdminUrlGenerator::class)->setAction(Action::INDEX)->generateUrl();
$url = $this->get(AdminUrlGenerator::class)->setAction(ActionDefinition::INDEX)->generateUrl();

return $this->redirect($url);
} else {
@@ -223,7 +224,7 @@ abstract class UserMerchantAdminController extends AbstractAdminController

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

+ 11
- 0
Definition/ActionDefinition.php 查看文件

@@ -0,0 +1,11 @@
<?php
namespace Lc\CaracoleBundle\Definition;

use Lc\SovBundle\Definition\ActionDefinition as SovActionDefinition;

class ActionDefinition extends SovActionDefinition{

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

}

+ 0
- 21
Model/Order/OrderProductModel.php 查看文件

@@ -46,11 +46,6 @@ abstract class OrderProductModel implements PriceInterface, EntityInterface
*/
protected $orderProductReductionCatalog;

/**
* @ORM\OneToOne(targetEntity="Lc\CaracoleBundle\Model\Order\OrderProductRefundInterface", mappedBy="orderProduct", cascade={"persist", "remove"})
*/
protected $orderProductRefund;

public function __toString()
{
if ($this->getTitle()) {
@@ -146,21 +141,5 @@ abstract class OrderProductModel implements PriceInterface, EntityInterface
return $this;
}

public function getOrderProductRefund(): ?OrderProductRefundInterface
{
return $this->orderProductRefund;
}

public function setOrderProductRefund(OrderProductRefundInterface $orderProductRefund): self
{
$this->orderProductRefund = $orderProductRefund;

// set the owning side of the relation if necessary
if ($orderProductRefund->getOrderProduct() !== $this) {
$orderProductRefund->setOrderProduct($this);
}

return $this;
}

}

+ 106
- 3
Repository/Order/OrderShopRepositoryQuery.php 查看文件

@@ -23,6 +23,7 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
use SectionRepositoryQueryTrait;

protected bool $isJoinProduct = false;
protected bool $isJoinProductFamily = false;
protected bool $isJoinOrderProduct = false;
protected bool $isJoinOrderReductionCredits = false;
protected bool $isJoinOrderReductionCarts = false;
@@ -36,6 +37,42 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
parent::__construct($repository, 'r', $paginator);
}


public function selectSumStatTotalWithTax(): self
{
return $this
->select(
'SUM(r.statTotalWithTax) as total'
);
}

public function selectSumQuantityOrder(): self
{
$this->joinOrderProduct();
return $this
->select(
'SUM(orderProduct.quantityOrder) as quantity'
);
}


public function selectSum(): self
{
$this->joinProduct();
return $this
->select(
'SUM(orderProduct.quantityOrder) as quantity, .cycleNumber as cycleNumber, product.id as productId'
);
}


public function selectCountUser(): self
{
return $this
->select('count(DISTINCT(r.user)) as total');
}


// @TODO : nécessaire ?
public function selectParam($select): self
{
@@ -56,6 +93,40 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
->setParameter('user', $user);
}

public function filterByAlias(array $status): self
{
$this->joinOrderStatus();

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

public function filterByCycleNumbers(array $cycleNumbers): self
{
return $this
->andWhere('.cycleNumber IN(:cycleNumbers)')
->setParameter('cycleNumbers', $cycleNumbers);
}

public function filterByProducts(array $products): self
{
$this->joinOrderProduct();

return $this
->andWhere('product.id IN(:products)')
->setParameter('products', $products);
}

public function filterByProduct(int $productId): self
{
$this->joinProduct();

return $this
->andWhere('orderProduct.product = :product')
->setParameter('product', $productId);
}

public function filterIsMerchantOnline(): self
{
$this->joinMerchant();
@@ -145,13 +216,45 @@ class OrderShopRepositoryQuery extends AbstractRepositoryQuery
return $this->addSelect('orcart');
}

public function joinOrderProduct(): self

public function joinOrderProduct(bool $addSelect = false): self
{
if (!$this->isJoinOrderProduct) {
$this->isJoinOrderProduct = true;

return $this
->innerJoin('.orderProducts', 'op');
$this->innerJoin('.orderProducts', 'orderProduct');
if ($addSelect) {
$this->addSelect('orderProduct');
}
}
return $this;
}

public function joinProduct(bool $addSelect = false): self
{
$this->joinOrderProduct($addSelect);
if (!$this->isJoinProduct) {
$this->isJoinProduct = true;

$this->leftJoin('orderProduct.product', 'product');

if ($addSelect) {
$this->addSelect('product');
}
}
return $this;
}

public function joinProductFamily(bool $addSelect = false): self
{
$this->joinProduct($addSelect);
if (!$this->isJoinProductFamily) {
$this->isJoinProductFamily = true;

$this->leftJoin('product.productFamily', 'productFamily');
if ($addSelect) {
$this->addSelect('productFamily');
}
}
return $this;
}

+ 4
- 1
Repository/Order/OrderShopStore.php 查看文件

@@ -97,7 +97,7 @@ class OrderShopStore extends AbstractStore

public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
{
$query->joinOrderProduct();
$query->joinOrderProduct(true);
return $query;
}

@@ -406,6 +406,9 @@ class OrderShopStore extends AbstractStore
if (isset($params['excludeComplementaryOrderShops']) || isset($params['mergeComplementaryOrderShops'])) {
$query->filterIsNullMainOrderShop();
}
if (isset($params['joinProductFamily'])) {
$query->joinProductFamily(true);
}

if (isset($params['orderBy'])) {
$sort = isset($params['orderByDirection']) ? $params['orderByDirection'] : 'DESC';

+ 1
- 0
Repository/Product/ProductRepositoryQuery.php 查看文件

@@ -45,6 +45,7 @@ class ProductRepositoryQuery extends AbstractRepositoryQuery
{
$this->joinProductFamily();
$this->andWhereStatus('pf', 1);
$this->andWhereStatus($this->id, 1);
return $this;
}


+ 1
- 3
Resources/assets/app/admin/duplicate/duplicate.js 查看文件

@@ -12,7 +12,6 @@ function initDuplicateOtherToOtherMerchant() {
dataType: "json",
success: function (response) {
$('body').append(response.data);
SovTools.log($('#carac-modal-duplicate'));
$('#carac-modal-duplicate').modal('show');
//initDuplicateModal();

@@ -23,7 +22,6 @@ function initDuplicateOtherToOtherMerchant() {

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(),
@@ -33,4 +31,4 @@ function initDuplicateModal(){
}
});
});
}
}

正在加载...
取消
保存