Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb
- index 7641279..842e614 100644
- --- a/app/controllers/home_controller.rb
- +++ b/app/controllers/home_controller.rb
- @@ -35,7 +35,7 @@ class HomeController < ApplicationController
- @grouped_orders = @orders_data.collect do |order|
- - { group: order, orders: Order.fetch_orders(order.ids) }
- + { group: order, orders: Order.include(SurveyQueries).fetch_orders(order.ids) }
- end
- @orders = @grouped_orders.collect{|grouped_order| grouped_order[:orders]}.flatten
- diff --git a/app/models/concerns/survey_queries.rb b/app/models/concerns/survey_queries.rb
- index 290c6a4..5c25b92 100644
- --- a/app/models/concerns/survey_queries.rb
- +++ b/app/models/concerns/survey_queries.rb
- @@ -1,5 +1,14 @@
- +require 'active_support/concern'
- +
- module SurveyQueries
- + extend ActiveSupport::Concern
- extend self
- +
- + included do
- + # Example fetch_orders('1,2,3,4,5') -> Fetches orders with ids
- + scope :fetch_orders, ->(ids) { joins("LEFT JOIN `attachments` ON attachments.order_id = orders.id LEFT JOIN `order_exceptions` ON order_exceptions.order_id = orders.id LEFT JOIN `order_notes` ON order_notes.order_id = orders.id").select("orders.*, CASE WHEN attachments.order_id IS NOT NULL THEN 'active' ELSE 'inactive' END AS attachments_exist, CASE WHEN order_exceptions.order_id IS NOT NULL THEN 'true' ELSE 'false' END AS order_exceptions_exist, CASE WHEN order_notes.order_id IS NOT NULL THEN 'true' ELSE 'false' END AS order_notes_exist").where(id: ids.split(',')).order(:ship_name) }
- + end
- +
- def self.summary_by_questions(params)
- sql = <<-SQL.squish
- SELECT
- diff --git a/app/models/order.rb b/app/models/order.rb
- index 16d5b0a..7b1922d 100644
- --- a/app/models/order.rb
- +++ b/app/models/order.rb
- @@ -106,8 +106,6 @@ class Order < ActiveRecord::Base
- scope :from_store,->(store_id){where(store_id: store_id) if store_id.present?}
- scope :payment_pending,-> { where(status: "Payment Pending") }
- scope :ordered_but_not_processed,->{ where("orders.payment_made_at <= ?", 2.days.ago) }
- - # Example fetch_orders('1,2,3,4,5') -> Fetches orders with ids
- - scope :fetch_orders, ->(ids) { joins("LEFT JOIN `attachments` ON attachments.order_id = orders.id LEFT JOIN `order_exceptions` ON order_exceptions.order_id = orders.id LEFT JOIN `order_notes` ON order_notes.order_id = orders.id").select("orders.*, CASE WHEN attachments.order_id IS NOT NULL THEN 'active' ELSE 'inactive' END AS attachments_exist, CASE WHEN order_exceptions.order_id IS NOT NULL THEN 'true' ELSE 'false' END AS order_exceptions_exist, CASE WHEN order_notes.order_id IS NOT NULL THEN 'true' ELSE 'false' END AS order_notes_exist").where(id: ids.split(',')).order(:ship_name) }
- scope :shipment_delay,->{
- joins(:order_items).
- where(
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement