@@ 71-88 (lines=18) @@ | ||
68 | * @param AclHelper $aclHelper |
|
69 | * @return int |
|
70 | */ |
|
71 | public function getAOVValueByPeriod(\DateTime $start, \DateTime $end, AclHelper $aclHelper) |
|
72 | { |
|
73 | $select = 'SUM( |
|
74 | CASE WHEN o.subtotalAmount IS NOT NULL THEN o.subtotalAmount ELSE 0 END - |
|
75 | CASE WHEN o.discountAmount IS NOT NULL THEN ABS(o.discountAmount) ELSE 0 END |
|
76 | ) as revenue, |
|
77 | count(o.id) as ordersCount'; |
|
78 | $qb = $this->createQueryBuilder('o'); |
|
79 | $qb->select($select) |
|
80 | ->andWhere($qb->expr()->between('o.createdAt', ':dateStart', ':dateEnd')) |
|
81 | ->setParameter('dateStart', $start) |
|
82 | ->setParameter('dateEnd', $end); |
|
83 | $this->applyActiveChannelLimitation($qb); |
|
84 | ||
85 | $value = $aclHelper->apply($qb)->getOneOrNullResult(); |
|
86 | ||
87 | return $value['revenue'] ? $value['revenue'] / $value['ordersCount'] : 0; |
|
88 | } |
|
89 | ||
90 | /** |
|
91 | * @param \DateTime $start |
|
@@ 97-114 (lines=18) @@ | ||
94 | * @return float|int |
|
95 | * @throws \Doctrine\ORM\NonUniqueResultException |
|
96 | */ |
|
97 | public function getDiscountedOrdersPercentByDatePeriod( |
|
98 | \DateTime $start, |
|
99 | \DateTime $end, |
|
100 | AclHelper $aclHelper |
|
101 | ) { |
|
102 | $qb = $this->createQueryBuilder('o'); |
|
103 | $qb->select( |
|
104 | 'COUNT(o.id) as allOrders', |
|
105 | 'SUM(CASE WHEN (o.discountAmount IS NOT NULL AND o.discountAmount <> 0) THEN 1 ELSE 0 END) as discounted' |
|
106 | ); |
|
107 | $qb->andWhere($qb->expr()->between('o.createdAt', ':dateStart', ':dateEnd')); |
|
108 | $qb->setParameter('dateStart', $start); |
|
109 | $qb->setParameter('dateEnd', $end); |
|
110 | $this->applyActiveChannelLimitation($qb); |
|
111 | ||
112 | $value = $aclHelper->apply($qb)->getOneOrNullResult(); |
|
113 | return $value['allOrders'] ? $value['discounted'] / $value['allOrders'] : 0; |
|
114 | } |
|
115 | ||
116 | /** |
|
117 | * @param Cart|Customer $item |