|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Lc\CaracoleBundle\Repository\Order; |
|
|
namespace Lc\CaracoleBundle\Repository\Order; |
|
|
|
|
|
|
|
|
|
|
|
use App\Entity\Order\OrderStatus; |
|
|
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; |
|
|
use Lc\CaracoleBundle\Builder\File\DocumentBuilder; |
|
|
use Lc\CaracoleBundle\Factory\File\DocumentFactory; |
|
|
use Lc\CaracoleBundle\Factory\File\DocumentFactory; |
|
|
use Lc\CaracoleBundle\Model\File\DocumentModel; |
|
|
use Lc\CaracoleBundle\Model\File\DocumentModel; |
|
|
|
|
|
use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface; |
|
|
|
|
|
use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; |
|
|
use Lc\CaracoleBundle\Model\Order\OrderShopInterface; |
|
|
|
|
|
use Lc\CaracoleBundle\Repository\SectionStoreTrait; |
|
|
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; |
|
|
use Lc\CaracoleBundle\Resolver\Price\PriceResolver; |
|
|
use Lc\CaracoleBundle\Resolver\Reference\DocumentReferenceResolver; |
|
|
use Lc\CaracoleBundle\Resolver\Reference\DocumentReferenceResolver; |
|
|
|
|
|
use Lc\SovBundle\Model\User\UserInterface; |
|
|
use Lc\SovBundle\Repository\AbstractStore; |
|
|
use Lc\SovBundle\Repository\AbstractStore; |
|
|
|
|
|
|
|
|
class OrderShopStore extends AbstractStore |
|
|
class OrderShopStore extends AbstractStore |
|
|
{ |
|
|
{ |
|
|
|
|
|
use SectionStoreTrait; |
|
|
|
|
|
|
|
|
protected OrderShopRepositoryQuery $query; |
|
|
protected OrderShopRepositoryQuery $query; |
|
|
protected PriceResolver $priceResolver; |
|
|
protected PriceResolver $priceResolver; |
|
|
protected DocumentReferenceResolver $documentReferenceResolver; |
|
|
protected DocumentReferenceResolver $documentReferenceResolver; |
|
|
protected DocumentBuilder $documentBuilder; |
|
|
protected DocumentBuilder $documentBuilder; |
|
|
|
|
|
|
|
|
public function __construct( |
|
|
public function __construct( |
|
|
OrderShopRepositoryQuery $query, |
|
|
|
|
|
PriceResolver $priceResolver, |
|
|
|
|
|
DocumentReferenceResolver $documentReferenceResolver, |
|
|
|
|
|
DocumentBuilder $documentBuilder |
|
|
|
|
|
|
|
|
OrderShopRepositoryQuery $query, |
|
|
|
|
|
PriceResolver $priceResolver, |
|
|
|
|
|
DocumentReferenceResolver $documentReferenceResolver, |
|
|
|
|
|
DocumentBuilder $documentBuilder |
|
|
) { |
|
|
) { |
|
|
$this->query = $query; |
|
|
$this->query = $query; |
|
|
$this->priceResolver = $priceResolver; |
|
|
$this->priceResolver = $priceResolver; |
|
|
|
|
|
|
|
|
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct); |
|
|
$data['orderProducts'][$i]['price'] = $this->priceResolver->getPrice($orderProduct); |
|
|
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct); |
|
|
$data['orderProducts'][$i]['priceWithTax'] = $this->priceResolver->getPriceWithTax($orderProduct); |
|
|
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction( |
|
|
$data['orderProducts'][$i]['priceWithTaxAndReduction'] = $this->priceResolver->getPriceWithTaxAndReduction( |
|
|
$orderProduct |
|
|
|
|
|
|
|
|
$orderProduct |
|
|
); |
|
|
); |
|
|
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder(); |
|
|
$data['orderProducts'][$i]['quantity'] = $orderProduct->getQuantityOrder(); |
|
|
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction( |
|
|
$data['orderProducts'][$i]['totalWithTaxAndReduction'] = $this->priceResolver->getTotalOrderProductsWithTaxAndReduction( |
|
|
array($orderProduct) |
|
|
|
|
|
|
|
|
array($orderProduct) |
|
|
); |
|
|
); |
|
|
$i++; |
|
|
$i++; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
$productFamily = $orderProduct->getProduct()->getProductFamily(); |
|
|
$productFamily = $orderProduct->getProduct()->getProductFamily(); |
|
|
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) { |
|
|
if (!isset($orderProductsByProductFamily[$productFamily->getId()])) { |
|
|
$orderProductsByProductFamily[$productFamily->getId()] = [ |
|
|
$orderProductsByProductFamily[$productFamily->getId()] = [ |
|
|
'order_products' => [], |
|
|
|
|
|
'total_quantity_weight' => 0, |
|
|
|
|
|
|
|
|
'order_products' => [], |
|
|
|
|
|
'total_quantity_weight' => 0, |
|
|
]; |
|
|
]; |
|
|
} |
|
|
} |
|
|
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct; |
|
|
$orderProductsByProductFamily[$productFamily->getId()]['order_products'][] = $orderProduct; |
|
|
$orderProductsByProductFamily[$productFamily->getId( |
|
|
$orderProductsByProductFamily[$productFamily->getId( |
|
|
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit( |
|
|
)]['total_quantity_weight'] += ($orderProduct->getQuantityProduct() / $orderProduct->getUnit( |
|
|
)->getCoefficient()) * $orderProduct->getQuantityOrder(); |
|
|
|
|
|
|
|
|
)->getCoefficient()) * $orderProduct->getQuantityOrder(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop); |
|
|
$totalOrder = $this->priceResolver->getTotalWithTax($orderShop); |
|
|
|
|
|
|
|
|
if ((abs($totalOrderPayments - $totalOrder) < 0.00001 |
|
|
if ((abs($totalOrderPayments - $totalOrder) < 0.00001 |
|
|
|| $totalOrderPayments >= $totalOrder) |
|
|
|
|
|
&& $totalOrder > 0) { |
|
|
|
|
|
|
|
|
|| $totalOrderPayments >= $totalOrder) |
|
|
|
|
|
&& $totalOrder > 0) { |
|
|
return true; |
|
|
return true; |
|
|
} else { |
|
|
} else { |
|
|
return false; |
|
|
return false; |
|
|
|
|
|
|
|
|
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]); |
|
|
$newOrderShop = $this->em->getRepository(OrderShopInterface::class)->findCartCurrent(['user' => $user]); |
|
|
if ($newOrderShop === null) { |
|
|
if ($newOrderShop === null) { |
|
|
$newOrderShop = $this->createOrderShop( |
|
|
$newOrderShop = $this->createOrderShop( |
|
|
array( |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'merchant' => $this->merchantUtils->getMerchantUser() |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
array( |
|
|
|
|
|
'user' => $user, |
|
|
|
|
|
'merchant' => $this->merchantUtils->getMerchantUser() |
|
|
|
|
|
) |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return $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(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
$query |
|
|
|
|
|
->selectOrderReductionCarts() |
|
|
|
|
|
->filterByStatus(OrderStatus::$statusAliasAsValid) |
|
|
|
|
|
->filterBySection($this->section); |
|
|
|
|
|
|
|
|
|
|
|
$results = $query->find(); |
|
|
|
|
|
|
|
|
|
|
|
if ($results) { |
|
|
|
|
|
return $results[0]; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['count']) && $params['count']) { |
|
|
|
|
|
$query->selectCount(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['select'])) { |
|
|
|
|
|
$query->selectParam($params['select']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['dateStart']) || isset($params['dateEnd'])) { |
|
|
|
|
|
$params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate'; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['dateStart'])) { |
|
|
|
|
|
$query->filterByDateStart($params['dateField'], $params['dateStart']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['dateEnd'])) { |
|
|
|
|
|
$query->filterByDateEnd($params['dateField'], $params['dateEnd']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['weekNumber'])) { |
|
|
|
|
|
$query->filterByWeekNumber($params['weekNumber']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['isCart'])) { |
|
|
|
|
|
$query->filterByStatus(OrderStatus::$statusAliasAsCart); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['isValid'])) { |
|
|
|
|
|
$query->filterByStatus(OrderStatus::$statusAliasAsValid); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['isWaitingDelivery'])) { |
|
|
|
|
|
$query->filterByStatus(OrderStatus::$statusAliasWaitingDelivery); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 ($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'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['groupBy'])) { |
|
|
|
|
|
$query->groupBy($params['groupBy']); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (isset($params['count']) && $params['count']) { |
|
|
|
|
|
return $query->count(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return $query->find(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |