["column" => "payment_status", "operator" => "in", "value" => Status::getTransactionSuccessStatuses()], "created_at" => ["column" => "created_at", "operator" => "between", "value" => [$fromDate, $toDate]] ]; $currentOrders = Order::search(Arr::only($params, ['created_at']))->count(); $stat = Order::search($params) ->selectRaw('count(*) as paid_orders') ->selectRaw('sum(total_amount) as paid_amounts') ->get()->first(); $paidOrders = $stat->paid_orders; $paidOrderItems = $stat->paid_orders; $paidAmounts = $stat->paid_amounts; if ($withCompare) { $dayDiff = strtotime($toDate) - strtotime($fromDate); $fromDate = gmdate('Y-m-d 00:00:00', strtotime($fromDate) - $dayDiff); $toDate = gmdate('Y-m-d 23:59:59', strtotime($toDate) - $dayDiff); Arr::set($params, 'created_at.value', [$fromDate, $toDate]); $prevCurrentOrders = Order::search(Arr::only($params, ['created_at']))->count(); $prevPaidOrders = Order::search($params)->count(); $prevPaidOrderItems = Order::search($params)->count(); $prevPaidAmounts = Order::search($params)->sum('total_amount'); } return [ 'total_orders' => [ 'title' => __('All Orders', 'fluent-cart'), 'current_count' => $currentOrders, 'compare_count' => ($withCompare) ? $prevCurrentOrders : null ], 'paid_orders' => [ 'title' => __('Paid Orders', 'fluent-cart'), 'current_count' => $paidOrders, 'compare_count' => ($withCompare) ? $prevPaidOrders : null ], 'total_paid_order_items' => [ 'title' => __('Paid Order Items', 'fluent-cart'), 'current_count' => $paidOrderItems, 'compare_count' => ($withCompare) ? $prevPaidOrderItems : null ], 'total_paid_amounts' => [ 'title' => __('Order Value (Paid)', 'fluent-cart'), 'current_count' => $paidAmounts, 'compare_count' => ($withCompare) ? $prevPaidAmounts : null, 'is_cents' => true ] ]; } }