app/models/caboose/order_reporter.rb in caboose-cms-0.7.22 vs app/models/caboose/order_reporter.rb in caboose-cms-0.7.23
- old
+ new
@@ -1,13 +1,17 @@
-
module Caboose
class OrderReporter
def OrderReporter.summary_report(site_id, d1, d2)
q = ["select
concat(date_part('year', date_authorized), '-', date_part('month', date_authorized), '-', date_part('day', date_authorized)),
- count(*),
+ count(*),
+ sum(subtotal),
+ sum(tax),
+ sum(shipping),
+ sum(handling),
+ sum(discount),
sum(total)
from store_orders
where site_id = ?
and (financial_status = ? or financial_status = ?)
and date_authorized >= ?
@@ -19,39 +23,44 @@
days = []
rows.each do |row|
arr = row[0].split('-')
days << Caboose::StdClass.new(
- :date => Date.new(arr[0].to_i, arr[1].to_i, arr[2].to_i),
- :count => row[1],
- :total => row[2]
+ :date => Date.new(arr[0].to_i, arr[1].to_i, arr[2].to_i),
+ :count => row[1].to_i,
+ :subtotal => row[2].to_f,
+ :tax => row[3].to_f,
+ :shipping => row[4].to_f,
+ :handling => row[5].to_f,
+ :discount => row[6].to_f,
+ :total => row[7].to_f
)
end
days.sort_by!{ |h| h.date }
last_day = d1 - 1.day
days2 = []
days.each do |h|
while (h.date - last_day) > 1
- days2 << Caboose::StdClass.new(:date => last_day + 1.day, :count => 0, :total => 0.0)
+ days2 << Caboose::StdClass.new(
+ :date => last_day + 1.day,
+ :count => 0,
+ :subtotal => 0.0,
+ :tax => 0.0,
+ :shipping => 0.0,
+ :handling => 0.0,
+ :discount => 0.0,
+ :total => 0.0
+ )
last_day = last_day + 1.day
end
days2 << h
last_day = h.date
end
- days2.each do |h|
- puts "#{h.date} #{h.count} #{h.total}"
- end
- return days2
-
- #return rows.collect { |row|
- # arr = row[0].split('-')
- # Caboose::StdClass.new(
- # :date => Date.new(arr[0].to_i, arr[1].to_i, arr[2].to_i),
- # :count => row[1],
- # :total => row[2]
- # )
- #}
+ #days2.each do |h|
+ # puts "#{h.date} #{h.count} #{h.total}"
+ #end
+ return days2
end
end
-end
+end
\ No newline at end of file