-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
152 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Place all the behaviors and hooks related to the matching controller here. | ||
# All this logic will automatically be available in application.js. | ||
# You can use CoffeeScript in this file: http://coffeescript.org/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the admin::consumptions controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: http://sass-lang.com/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
class Admin::ConsumptionsController < ApplicationController | ||
before_action :should_be_admin | ||
|
||
def index | ||
@consumptions = Consumption.all | ||
end | ||
|
||
def recalculate | ||
begin | ||
Consumption.transaction do | ||
Consumption.where(id: params[:ids]).each(&:recalculate) | ||
end | ||
|
||
redirect_to action: :index | ||
rescue | ||
flash[:recalculate_error] = true | ||
|
||
redirect_to action: :index | ||
end | ||
end | ||
|
||
def new | ||
end | ||
|
||
def create | ||
start_at = Time.zone.parse(params[:start_date]) | ||
end_at = Time.zone.parse(params[:end_date]).change(hour: 23, min: 59, sec: 59) | ||
|
||
Consumption.transaction do | ||
Car.all.select do |car| | ||
car.fuels.in(start_at, end_at).exists? | ||
end.each do |car| | ||
Consumption.create( | ||
car: car, | ||
start_at: start_at, | ||
end_at: end_at, | ||
price: 0 | ||
) | ||
end | ||
end | ||
|
||
redirect_to action: :index | ||
end | ||
|
||
def destroy_multiple | ||
Consumption.where(id: params[:ids]).destroy_all | ||
|
||
redirect_to action: :index | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Admin::ConsumptionsHelper | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<div class="row"> | ||
<% if flash[:recalculate_error] %> | ||
<div class="col s12"> | ||
<div class='card-panel red lighten-2' style='text-align: center;'> | ||
<span class='white-text'> | ||
燃費の算出に失敗しました。期間中の乗車記録に不備があります。 | ||
</span> | ||
</div> | ||
</div> | ||
<% end %> | ||
<%= link_to new_admin_consumption_path, method: :GET do %> | ||
<div class="col s12"> | ||
<div class='card-panel blue lighten-2' style='text-align: center; font-size: large;'> | ||
<span class='white-text'> | ||
集計期間を登録する | ||
</span> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% @consumptions.group_by { |c| [c.start_at.to_date, c.end_at.to_date] }.sort.reverse.each do |dates, consumptions| %> | ||
<div class="col s12"> | ||
<div class="Card"> | ||
<div class="Card--Content"> | ||
<p class="Card--Content--Title"> | ||
<%= dates[0] %> 〜 <%= dates[1] %> | ||
</p> | ||
<p style='text-align: right;'> | ||
<ul> | ||
<% consumptions.each do |consumption| %> | ||
<li><%= consumption.car.name %>:<%= consumption.price.round(1) %> 円/km</li> | ||
<% end %> | ||
</ul> | ||
</p> | ||
<div class="Card--Action"> | ||
<%= link_to recalculate_admin_consumptions_path(ids: consumptions.map(&:id)), method: :POST, class: 'Card--Action--FAB green' do %> | ||
<i class='Card--Action--FAB--Icon'>autorenew</i> | ||
<% end %> | ||
<%= link_to destroy_multiple_admin_consumptions_path(ids: consumptions.map(&:id)), method: :DELETE, class: 'Card--Action--FAB red' do %> | ||
<i class='Card--Action--FAB--Icon'>delete</i> | ||
<% end %> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<% end %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div class="Card"> | ||
<div class="Card--Content"> | ||
<span class="Card--Content--Title">集計期間の登録</span> | ||
<%= form_tag admin_consumptions_path, html: { class: 'Form' } do |f| %> | ||
<div class='Form--InputSet--Field s6'> | ||
<%= label_tag '開始日' %> | ||
<%= date_field_tag :start_date, class: 'datepicker' %> | ||
</div> | ||
|
||
<div class='Form--InputSet--Field s6'> | ||
<%= label_tag '終了日' %> | ||
<%= date_field_tag :end_date, class: 'datepicker' %> | ||
</div> | ||
|
||
<%= submit_tag "登録", class: "Form--SubmitBtn" %> | ||
<% end %> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require 'test_helper' | ||
|
||
class Admin::ConsumptionsControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |