join('V_STORAGE_ONVESSEL', 'V_DASHBOARD_TRADE.vessel_id', '=', 'V_STORAGE_ONVESSEL.vessel_id') ->where('status', 'in stock') ->groupBy('commodity_name'); } /** * Get future trade statistics, ensuring current_stock is > 0 */ public static function getFutureTradeStats() { return self::select([ 'commodity_name', DB::raw('SUM(current_stock) as total_current_stock'), DB::raw('SUM(free_stock_for_sale) as total_free_stock'), DB::raw('AVG(invoice_cif) as average_invoice_cif'), DB::raw('AVG(SELFCOST) as average_selfcost') ]) ->where('status', 'future') ->where(DB::raw('ROUND(current_stock, 0)'), '>', 0) ->groupBy('commodity_name'); } }