Class: Report::CouponSalesReport::CouponSalesReportCommand
- Inherits:
-
BaseCommand
- Object
- BaseCommand
- Report::CouponSalesReport::CouponSalesReportCommand
- Defined in:
- app/services/report/coupon_sales_report/coupon_sales_report_command.rb
Overview
Service object: coupon sales report command.
Instance Method Summary collapse
-
#execute ⇒ Object
Run the report with the given filters and store the result.
-
#success? ⇒ Boolean
Whether the command validated and ran successfully.
-
#to_by_coupons_csv ⇒ Object
To by coupons csv.
-
#to_by_items_csv ⇒ Object
To by items csv.
-
#to_coupons_items_csv ⇒ Object
To coupons items csv.
Instance Method Details
#execute ⇒ Object
Run the report with the given filters and store the result.
16 17 18 19 20 |
# File 'app/services/report/coupon_sales_report/coupon_sales_report_command.rb', line 16 def execute return unless valid? @result = Report::CouponSalesReport::CouponSalesReport.result_report(attributes) end |
#success? ⇒ Boolean
Whether the command validated and ran successfully.
75 76 77 |
# File 'app/services/report/coupon_sales_report/coupon_sales_report_command.rb', line 75 def success? valid? && @result.success? end |
#to_by_coupons_csv ⇒ Object
To by coupons csv.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/services/report/coupon_sales_report/coupon_sales_report_command.rb', line 24 def to_by_coupons_csv return unless valid? @result = Report::CouponSalesReport::CouponSalesReport.result_report(attributes) return if @result.coupons_by_month.blank? attributes = @result.coupons_by_month.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.coupons_by_month.each do |r| csv << r end end end |
#to_by_items_csv ⇒ Object
To by items csv.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/services/report/coupon_sales_report/coupon_sales_report_command.rb', line 41 def to_by_items_csv return unless valid? @result = Report::CouponSalesReport::CouponSalesReport.result_report(attributes) return if @result.items_by_month.blank? attributes = @result.items_by_month.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.items_by_month.each do |r| csv << r end end end |
#to_coupons_items_csv ⇒ Object
To coupons items csv.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/services/report/coupon_sales_report/coupon_sales_report_command.rb', line 58 def to_coupons_items_csv return unless valid? @result = Report::CouponSalesReport::CouponSalesReport.result_report(attributes) return if @result.coupons_items.blank? attributes = @result.coupons_items.first.keys CSV.generate(headers: true) do |csv| csv << attributes @result.coupons_items.each do |r| csv << r end end end |