@@ -162,9 +162,13 @@ class AdminController extends EasyAdminController | |||
$this->commonQueryFilter($entityClass, $queryBuilder); | |||
$listFields = $this->entity['list']['fields']; | |||
$this->filtersForm = $this->createForm(ListFilterType::class, null, array( | |||
'fields' => $listFields, | |||
'method' => 'get' | |||
'method' => 'get', | |||
'entity_name' => $this->entity['name'], | |||
//'entityClass' => $this->entity['class'], | |||
'entity_class' => $this->entity['class'] | |||
)); | |||
$this->filtersForm->handleRequest($this->request); | |||
@@ -172,6 +176,7 @@ class AdminController extends EasyAdminController | |||
foreach ($listFields as $field) { | |||
if ($this->filtersForm->has($field['property'])) { | |||
switch ($field['dataType']) { | |||
case 'option': | |||
case 'integer': | |||
case 'text': | |||
case 'string': |
@@ -39,8 +39,11 @@ class CitiesController extends AbstractController | |||
$return = [] ; | |||
foreach($result as $city) { | |||
$codesPostaux = $city->codesPostaux ; | |||
$return[] = [ | |||
'label' => $city->nom, | |||
'label' => '<span class="city">'.$city->nom.'</span> <span class="zip">'.$codesPostaux[0].'</span>', | |||
'value' => $city->code | |||
] ; | |||
} |
@@ -4,6 +4,7 @@ namespace Lc\ShopBundle\Form\Backend\Filters; | |||
use Doctrine\ORM\EntityManagerInterface; | |||
use Doctrine\ORM\EntityRepository; | |||
use Lc\ShopBundle\Services\Utils; | |||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | |||
use Symfony\Component\Form\AbstractType; | |||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | |||
@@ -14,23 +15,49 @@ use Symfony\Component\Form\Extension\Core\Type\IntegerType; | |||
use Symfony\Component\Form\Extension\Core\Type\TextType; | |||
use Symfony\Component\Form\FormBuilderInterface; | |||
use Symfony\Component\OptionsResolver\OptionsResolver; | |||
use Symfony\Contracts\Translation\TranslatorInterface; | |||
class ListFilterType extends AbstractType | |||
{ | |||
protected $em; | |||
protected $translator; | |||
protected $utils; | |||
public function __construct(EntityManagerInterface $entityManager) | |||
public function __construct(EntityManagerInterface $entityManager, TranslatorInterface $translator, Utils $utils) | |||
{ | |||
$this->em = $entityManager; | |||
$this->translator = $translator; | |||
$this->utils = $utils; | |||
} | |||
public function buildForm(FormBuilderInterface $builder, array $options) | |||
{ | |||
foreach ($options['fields'] as $field) { | |||
switch ($field['dataType']) { | |||
case 'option': | |||
$refl = new \ReflectionClass($options['entity_class']); | |||
$choiceOptions= array(); | |||
foreach ($refl->getConstants() as $key => $value) { | |||
if (stripos($key, $this->utils->snakeCase($field['property'])) !== false) { | |||
$choiceOptions[$this->translator->trans('field.'.$options['entity_name'].'.'.$field['property'].'Options.'.$value)] = $value; | |||
} | |||
} | |||
$builder->add($field['property'], ChoiceType::class, array( | |||
'required' => false, | |||
'choices'=> $choiceOptions, | |||
'attr'=>array( | |||
'class'=> 'select2 input-sm', | |||
'form'=> 'filters-form' | |||
) | |||
)); | |||
break; | |||
case 'integer': | |||
$builder->add($field['property'], TextType::class, array( | |||
'required' => false, | |||
@@ -131,7 +158,10 @@ class ListFilterType extends AbstractType | |||
'label' => false, | |||
'csrf_protection'=> false, | |||
'translation_domain' => 'lcshop', | |||
'fields' => false | |||
'fields' => false, | |||
'entity_name' => false, | |||
'entity_class' => false, | |||
//'entityClass' => false | |||
]); | |||
} | |||
} |
@@ -243,13 +243,26 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
$query->andWhere('e.weekNumber = :weekNumber'); | |||
$query->andWhere('e.mainOrderShop = false OR e.mainOrderShop IS NULL'); | |||
$query->setParameter('weekNumber', $weekNumber); | |||
$query->orderBy('e.validationDate', 'DESC'); | |||
$query->orderBy('e.weekId', 'DESC'); | |||
$query->setMaxResults(1); | |||
return $query->getQuery()->getOneOrNullResult(); | |||
} | |||
public function findLastOrderValid() | |||
{ | |||
$query = $this->findByMerchantQuery(); | |||
$query = $this->filterOrderValid($query); | |||
$query->andWhere('e.mainOrderShop = false OR e.mainOrderShop IS NULL'); | |||
$query->orderBy('e.idValidOrder', 'DESC'); | |||
$query->setMaxResults(1); | |||
return $query->getQuery()->getOneOrNullResult(); | |||
} | |||
public function countValidOrderProductsOfWeekByProduct($weekNumber, $productId) | |||
{ | |||
$query = $this->findByMerchantQuery(); |
@@ -381,6 +381,7 @@ field: | |||
quantityProduct: Quantité (en rapport à l'unité) | |||
unit: Unité | |||
OrderShop: | |||
createdAt: Date de création | |||
save: Sauvegarder | |||
reference: Référence | |||
mainInfo: Information principal |
@@ -0,0 +1,9 @@ | |||
{% set lastMessage = item.ticketMessages.last %} | |||
{% if lastMessage.answerByAdmin != true %} | |||
<span class="badge badge-danger"> | |||
New | |||
</span> | |||
{% endif %} | |||
{{ lastMessage.createdAt|date('d/m/Y H:i') }} par {{ lastMessage.createdBy }} |
@@ -46,7 +46,7 @@ | |||
<div class="direct-chat-msg {{ message.answerByAdmin ? 'right' }}"> | |||
<div class="direct-chat-infos clearfix"> | |||
<span class="direct-chat-name {{ message.answerByAdmin ? 'float-right' : 'float-left' }}"> | |||
{{ entity.username }} | |||
{{ message.createdBy }} | |||
</span> | |||
<span class="direct-chat-timestamp {{ message.answerByAdmin ? 'float-left' : 'float-right' }}"> | |||
{{ message.createdAt|date('d/m/Y H:i') }} |
@@ -102,10 +102,11 @@ class OrderUtils | |||
$return = false; | |||
$user = $this->security->getUser(); | |||
$visitor = $this->userUtils->getVisitorCurrent(); | |||
if (!$orderShop) { | |||
$user = $this->security->getUser(); | |||
$visitor = $this->userUtils->getVisitorCurrent(); | |||
$orderShop = $this->createOrderShop([ | |||
'user' => $user, | |||
'visitor' => $visitor, | |||
@@ -125,15 +126,17 @@ class OrderUtils | |||
$orderProductAdd->setQuantityProduct($orderProductAdd->getProduct()->getQuantityInherited()); | |||
$productFamily = $this->productFamilyUtils->getProductFamilyBySlug($orderProductAdd->getProduct()->getProductFamily()->getSlug()); | |||
$reductionCatalog = $productFamily->getReductionCatalog(); | |||
if ($reductionCatalog) { | |||
$orderProductReductionCatalog = new OrderProductReductionCatalog(); | |||
$orderProductReductionCatalog->setTitle($reductionCatalog->getTitle()); | |||
$orderProductReductionCatalog->setValue($reductionCatalog->getValue()); | |||
$orderProductReductionCatalog->setUnit($reductionCatalog->getUnit()); | |||
$orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate()); | |||
$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog); | |||
if($productFamily) { | |||
$reductionCatalog = $productFamily->getReductionCatalog(); | |||
if ($reductionCatalog) { | |||
$orderProductReductionCatalog = new OrderProductReductionCatalog(); | |||
$orderProductReductionCatalog->setTitle($reductionCatalog->getTitle()); | |||
$orderProductReductionCatalog->setValue($reductionCatalog->getValue()); | |||
$orderProductReductionCatalog->setUnit($reductionCatalog->getUnit()); | |||
$orderProductReductionCatalog->setBehaviorTaxRate($reductionCatalog->getBehaviorTaxRate()); | |||
$orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog); | |||
} | |||
} | |||
foreach ($orderShop->getOrderProducts() as $orderProduct) { |
@@ -21,9 +21,9 @@ trait OrderUtilsStockTrait | |||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||
$newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient())); | |||
$productFamily = $orderProduct->getProduct()->getProductFamily() ; | |||
$productFamily = $orderProduct->getProduct()->getProductFamily(); | |||
$productFamily->setAvailableQuantity($newAvailability); | |||
$productFamily->setUpdatedBy($orderShop->getUser()) ; | |||
$productFamily->setUpdatedBy($orderShop->getUser()); | |||
$this->em->persist($productFamily); | |||
@@ -33,9 +33,9 @@ trait OrderUtilsStockTrait | |||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); | |||
$productFamily = $orderProduct->getProduct()->getProductFamily() ; | |||
$productFamily = $orderProduct->getProduct()->getProductFamily(); | |||
$productFamily->setAvailableQuantity($newAvailability); | |||
$productFamily->setUpdatedBy($orderShop->getUser()) ; | |||
$productFamily->setUpdatedBy($orderShop->getUser()); | |||
$this->em->persist($productFamily); | |||
@@ -44,9 +44,9 @@ trait OrderUtilsStockTrait | |||
$oldAvailability = $orderProduct->getProduct()->getAvailableQuantityInherited(); | |||
$newAvailability = $oldAvailability - $orderProduct->getQuantityOrder(); | |||
$product = $orderProduct->getProduct() ; | |||
$product = $orderProduct->getProduct(); | |||
$product->setAvailableQuantity($newAvailability); | |||
$product->setUpdatedBy($orderShop->getUser()) ; | |||
$product->setUpdatedBy($orderShop->getUser()); | |||
$this->em->persist($product); | |||
@@ -59,119 +59,116 @@ trait OrderUtilsStockTrait | |||
public function isProductAvailable(Product $product, $quantityOrder = 0, $checkCart = false, $orderShop = null) | |||
{ | |||
if($product->getStatus() != 1) { | |||
return false ; | |||
if ($product->getStatus() != 1 || $product->getProductFamily()->getStatus() != 1) { | |||
return false; | |||
} | |||
if(!$orderShop) { | |||
$orderShop = $this->getCartCurrent() ; | |||
if (!$orderShop) { | |||
$orderShop = $this->getCartCurrent(); | |||
} | |||
$productFamily = $product->getProductFamily() ; | |||
$productFamily = $product->getProductFamily(); | |||
$quantityAsked = $quantityOrder; | |||
if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
if(!$quantityOrder) { | |||
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true) ; | |||
} | |||
else { | |||
if ($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
if (!$quantityOrder) { | |||
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product, true); | |||
} else { | |||
$quantityAsked = ($product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient()) * $quantityOrder; | |||
} | |||
if($checkCart) { | |||
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product, true) ; | |||
if ($checkCart) { | |||
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product, true); | |||
} | |||
} | |||
if(($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY | |||
if (($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY | |||
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT)) { | |||
if(!$quantityOrder) { | |||
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product) ; | |||
if (!$quantityOrder) { | |||
$quantityAsked = $this->getQuantityOrderByProduct($orderShop, $product); | |||
} | |||
if($checkCart) { | |||
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product) ; | |||
if ($checkCart) { | |||
$quantityAsked += $this->getQuantityOrderByProduct($orderShop, $product); | |||
} | |||
} | |||
if ($product->getAvailableQuantityInherited() >= $quantityAsked | |||
|| $productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_UNLIMITED) { | |||
return true; | |||
} | |||
else { | |||
} else { | |||
return false; | |||
} | |||
} | |||
public function isOneProductAvailableAddCart($products): bool | |||
{ | |||
foreach($products as $product) { | |||
if($this->isProductAvailable($product, 1, true)) { | |||
return true ; | |||
foreach ($products as $product) { | |||
if ($this->isProductAvailable($product, 1, true)) { | |||
return true; | |||
} | |||
} | |||
return false ; | |||
return false; | |||
} | |||
public function isOrderProductAvailable(OrderProductInterface $orderProduct) | |||
{ | |||
return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder()) ; | |||
return $this->isProductAvailable($orderProduct->getProduct(), $orderProduct->getQuantityOrder()); | |||
} | |||
public function isOrderProductAvailableAddCart(OrderProductInterface $orderProduct, $orderShop = null) | |||
{ | |||
$product = $orderProduct->getProduct() ; | |||
$product = $orderProduct->getProduct(); | |||
return $this->isProductAvailable($product, $orderProduct->getQuantityOrder(), true, $orderShop); | |||
} | |||
public function getQuantityOrderByProduct($orderShop, $product, $byWeight = false) | |||
{ | |||
$quantity = 0 ; | |||
$productFamily = $product->getProductFamily() ; | |||
$behaviorCountStock = $productFamily->getBehaviorCountStock() ; | |||
if($orderShop) { | |||
foreach($orderShop->getOrderProducts() as $orderProduct) { | |||
if($orderProduct->getProduct()->getId() == $product->getId() | |||
|| ( ($behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) | |||
$quantity = 0; | |||
$productFamily = $product->getProductFamily(); | |||
$behaviorCountStock = $productFamily->getBehaviorCountStock(); | |||
if ($orderShop) { | |||
foreach ($orderShop->getOrderProducts() as $orderProduct) { | |||
if ($orderProduct->getProduct()->getId() == $product->getId() | |||
|| (($behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY || $behaviorCountStock == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) | |||
&& $orderProduct->getProduct()->getProductFamily()->getId() == $productFamily->getId())) { | |||
if($byWeight) { | |||
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getProduct()->getUnitInherited()->getCoefficient()) ; | |||
} | |||
else { | |||
$quantity += $orderProduct->getQuantityOrder() ; | |||
if ($byWeight) { | |||
$quantity += $orderProduct->getQuantityOrder() * ($orderProduct->getQuantityProduct() / $orderProduct->getProduct()->getUnitInherited()->getCoefficient()); | |||
} else { | |||
$quantity += $orderProduct->getQuantityOrder(); | |||
} | |||
} | |||
} | |||
} | |||
return $quantity ; | |||
return $quantity; | |||
} | |||
public function getProductQuantityMaxAddCart($product) | |||
{ | |||
$orderShop = $this->getCartCurrent() ; | |||
$productFamily = $product->getProductFamily() ; | |||
$orderShop = $this->getCartCurrent(); | |||
$productFamily = $product->getProductFamily(); | |||
$byWeight = false ; | |||
if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
$byWeight = true ; | |||
$byWeight = false; | |||
if ($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
$byWeight = true; | |||
} | |||
return $product->getAvailableQuantityInherited() - $this->getQuantityOrderByProduct($orderShop, $product, $byWeight) ; | |||
return $product->getAvailableQuantityInherited() - $this->getQuantityOrderByProduct($orderShop, $product, $byWeight); | |||
} | |||
public function getProductQuantity($product) { | |||
public function getProductQuantity($product) | |||
{ | |||
$productFamily = $product->getProductFamily() ; | |||
$productFamily = $product->getProductFamily(); | |||
if($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
return $product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient() ; | |||
} | |||
else { | |||
return 1 ; | |||
if ($productFamily->getBehaviorCountStock() == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) { | |||
return $product->getQuantityInherited() / $product->getUnitInherited()->getCoefficient(); | |||
} else { | |||
return 1; | |||
} | |||
} | |||
} |
@@ -252,10 +252,20 @@ class Utils | |||
return $result; | |||
} | |||
public function getZipByCity($city) | |||
public function getZipByCity($city, $code = null) | |||
{ | |||
$zip = null ; | |||
$returnCitiesSearchZip = json_decode($this->callCitiesApi('get', 'communes', ['nom' => $city, 'fields' => 'nom,codesPostaux'])) ; | |||
$paramsSearch = [ | |||
'nom' => $city, | |||
'fields' => 'nom,codesPostaux' | |||
] ; | |||
if($code != null && $code != 0) { | |||
$paramsSearch['code'] = $code ; | |||
} | |||
$returnCitiesSearchZip = json_decode($this->callCitiesApi('get', 'communes', $paramsSearch)) ; | |||
if($returnCitiesSearchZip) { | |||
foreach($returnCitiesSearchZip as $citySearchZip) { | |||
@@ -334,6 +344,21 @@ class Utils | |||
return $this->session->getFlashBag()->all(); | |||
} | |||
function camelCase($str) { | |||
$i = array("-","_"); | |||
$str = preg_replace('/([a-z])([A-Z])/', "\\1 \\2", $str); | |||
$str = preg_replace('@[^a-zA-Z0-9\-_ ]+@', '', $str); | |||
$str = str_replace($i, ' ', $str); | |||
$str = str_replace(' ', '', ucwords(strtolower($str))); | |||
$str = strtolower(substr($str,0,1)).substr($str,1); | |||
return $str; | |||
} | |||
function snakeCase($str) { | |||
$str = preg_replace('/([a-z])([A-Z])/', "\\1_\\2", $str); | |||
$str = strtolower($str); | |||
return $str; | |||
} | |||
public function getRemindersByUser($user) | |||
{ |