def products_sold_totals_in_timeframe(start_date, end_date)
@products_sold_totals_in_timeframe = Salon.find_by_sql ["SELECT Count(transaction_items.saleable_item_id) AS sold_quantity, saleable_items.price AS price, Sum(transaction_items.quantity*transaction_items.price) AS product_revenue, Sum(transaction_items.quantity*transaction_items.price)-(Sum((transaction_items.quantity*transaction_items.price)/(1+transactions.sales_tax/100))) AS sales_tax, Sum(transaction_items.quantity*transaction_items.cost) AS product_cost, Sum(transaction_items.quantity*transaction_items.price*(1-(transactions.stylist_product_percentage/100))) AS paid_commission, IFNULL(Sum(transaction_items.quantity*transaction_items.price*(transactions.stylist_product_percentage/100))-(Sum(transaction_items.quantity*transaction_items.cost)+Sum(transaction_items.quantity*transaction_items.price)-(Sum((transaction_items.quantity*transaction_items.price)/(1+transactions.sales_tax/100)))),0) AS product_profit FROM salons Inner Join transactions ON salons.id = transactions.salon_id Inner Join transaction_items ON transactions.id = transaction_items.transaction_id Inner Join saleable_items ON transaction_items.saleable_item_id = saleable_items.id Inner Join inventories ON saleable_items.id = inventories.saleable_item_id AND salons.id = inventories.salon_id WHERE (transactions.created_at BETWEEN ? AND ?) AND (transactions.product_total > '0') AND (transaction_items.item_type = 'standard') AND (transactions.salon_id = ?) GROUP BY salons.id", start_date.utc, end_date.utc, self.id]
return @products_sold_totals_in_timeframe
end