Issue Fixed

This commit is contained in:
Devansh 2020-08-13 13:33:03 +05:30
parent 8514421cf0
commit 90b4a223a7
1 changed files with 5 additions and 3 deletions

View File

@ -211,7 +211,7 @@ class DashboardController extends Controller
/**
* Returns top selling products
*
*
* @return \Illuminate\Support\Collection
*/
public function getTopSellingProducts()
@ -235,10 +235,12 @@ class DashboardController extends Controller
*/
public function getCustomerWithMostSales()
{
$dbPrefix = DB::getTablePrefix();
return $this->orderRepository->getModel()
->leftJoin('refunds', 'orders.id', 'refunds.order_id')
->select(DB::raw('(SUM(orders.base_grand_total) - SUM(IFNULL(refunds.base_grand_total, 0))) as total_base_grand_total'))
->addSelect(DB::raw('COUNT(orders.id) as total_orders'))
->select(DB::raw("(SUM({$dbPrefix}orders.base_grand_total) - SUM(IFNULL({$dbPrefix}refunds.base_grand_total, 0))) as total_base_grand_total"))
->addSelect(DB::raw("COUNT({$dbPrefix}orders.id) as total_orders"))
->addSelect('orders.id', 'customer_id', 'customer_email', 'customer_first_name', 'customer_last_name')
->where('orders.created_at', '>=', $this->startDate)
->where('orders.created_at', '<=', $this->endDate)