Class: ManifestationCheckoutStatsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/manifestation_checkout_stats_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /manifestation_checkout_stats POST /manifestation_checkout_stats.json



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'app/controllers/manifestation_checkout_stats_controller.rb', line 79

def create
  @manifestation_checkout_stat = ManifestationCheckoutStat.new(manifestation_checkout_stat_params)
  @manifestation_checkout_stat.user = current_user

  respond_to do |format|
    if @manifestation_checkout_stat.save
      ManifestationCheckoutStatJob.perform_later(@manifestation_checkout_stat)
      format.html { redirect_to @manifestation_checkout_stat, notice: t('controller.successfully_created', model: t('activerecord.models.manifestation_checkout_stat')) }
      format.json { render json: @manifestation_checkout_stat, status: :created, location: @manifestation_checkout_stat }
    else
      format.html { render action: "new" }
      format.json { render json: @manifestation_checkout_stat.errors, status: :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /manifestation_checkout_stats/1 DELETE /manifestation_checkout_stats/1.json



114
115
116
117
118
119
120
121
# File 'app/controllers/manifestation_checkout_stats_controller.rb', line 114

def destroy
  @manifestation_checkout_stat.destroy

  respond_to do |format|
    format.html { redirect_to manifestation_checkout_stats_url }
    format.json { head :no_content }
  end
end

#editObject

GET /manifestation_checkout_stats/1/edit



74
75
# File 'app/controllers/manifestation_checkout_stats_controller.rb', line 74

def edit
end

#indexObject

GET /manifestation_checkout_stats GET /manifestation_checkout_stats.json



8
9
10
11
12
13
14
15
# File 'app/controllers/manifestation_checkout_stats_controller.rb', line 8

def index
  @manifestation_checkout_stats = ManifestationCheckoutStat.page(params[:page])

  respond_to do |format|
    format.html # index.html.erb
    format.json { render json: @manifestation_checkout_stats }
  end
end

#newObject

GET /manifestation_checkout_stats/new GET /manifestation_checkout_stats/new.json



62
63
64
65
66
67
68
69
70
71
# File 'app/controllers/manifestation_checkout_stats_controller.rb', line 62

def new
  @manifestation_checkout_stat = ManifestationCheckoutStat.new
  @manifestation_checkout_stat.start_date = Time.zone.now.beginning_of_day
  @manifestation_checkout_stat.end_date = Time.zone.now.beginning_of_day

  respond_to do |format|
    format.html # new.html.erb
    format.json { render json: @manifestation_checkout_stat }
  end
end

#showObject

GET /manifestation_checkout_stats/1 GET /manifestation_checkout_stats/1.json



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/manifestation_checkout_stats_controller.rb', line 19

def show
  if params[:format] == 'txt'
    per_page = 65534
  else
    per_page = CheckoutStatHasManifestation.default_per_page
  end

  @carrier_type_results = Checkout.where(
    Checkout.arel_table[:created_at].gteq @manifestation_checkout_stat.start_date
  ).where(
    Checkout.arel_table[:created_at].lt @manifestation_checkout_stat.end_date
  ).joins(item: :manifestation).group(
    'checkouts.shelf_id', :carrier_type_id
  ).merge(
    Manifestation.where(carrier_type_id: CarrierType.pluck(:id))
  ).count(:id)

  @checkout_type_results = Checkout.where(
    Checkout.arel_table[:created_at].gteq @manifestation_checkout_stat.start_date
  ).where(
    Checkout.arel_table[:created_at].lt @manifestation_checkout_stat.end_date
  ).joins(item: :manifestation).group(
    'checkouts.shelf_id', :checkout_type_id
  ).count(:id)

  @stats = Checkout.where(
    Checkout.arel_table[:created_at].gteq @manifestation_checkout_stat.start_date
  ).where(
    Checkout.arel_table[:created_at].lt @manifestation_checkout_stat.end_date
  ).joins(item: :manifestation).group(:manifestation_id).merge(
    Manifestation.where(carrier_type_id: CarrierType.pluck(:id))
  ).order('count_id DESC').page(params[:page]).per(per_page)

  respond_to do |format|
    format.html # show.html.erb
    format.json { render json: @manifestation_checkout_stat }
    format.txt
    format.js
  end
end

#updateObject

PUT /manifestation_checkout_stats/1 PUT /manifestation_checkout_stats/1.json



97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'app/controllers/manifestation_checkout_stats_controller.rb', line 97

def update
  respond_to do |format|
    if @manifestation_checkout_stat.update(manifestation_checkout_stat_params)
      if @manifestation_checkout_stat.mode == 'import'
        ManifestationCheckoutStatJob.perform_later(@manifestation_checkout_stat)
      end
      format.html { redirect_to @manifestation_checkout_stat, notice: t('controller.successfully_updated', model: t('activerecord.models.manifestation_checkout_stat')) }
      format.json { head :no_content }
    else
      format.html { render action: "edit" }
      format.json { render json: @manifestation_checkout_stat.errors, status: :unprocessable_entity }
    end
  end
end