$builder->
select([ 'customer',
'IDENTITY(customer.defaultBillingAddress) as default_billing_address_id',
'IDENTITY(customer.defaultShippingAddress) as default_shipping_address_id',
'billing',
'shipping',
'paymentData',
'locale.language',
'shop.name as shopName',
$builder->
expr()->
count('doneOrders.id'
) . ' as orderCount',
'SUM(doneOrders.invoiceAmount) as amount',
'(' .
$subQueryBuilder->
getDQL() . ') as canceledOrderAmount',
]);
// Join s_orders second time to display the count of canceled orders and the count and total amount of done orders
$builder->
from($this->
getEntityName(), 'customer'
) ->
leftJoin('customer.defaultBillingAddress', 'billing'
) ->
leftJoin('customer.defaultShippingAddress', 'shipping'
) ->
leftJoin('customer.shop', 'shop'
) ->
leftJoin('customer.languageSubShop', 'subShop'
) ->
leftJoin('subShop.locale', 'locale'
) ->
leftJoin('customer.paymentData', 'paymentData', Join::WITH, 'paymentData.paymentMean = customer.paymentId'
) ->
leftJoin('customer.orders', 'doneOrders', Join::WITH, 'doneOrders.status <> -1 AND doneOrders.status <> 4'
) ->
where('customer.id = :customerId'
)