-
-
Save samholst/5fa3b16a89c39b2934c970c40ebcb69d to your computer and use it in GitHub Desktop.
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
= form_for(@tank_configuration) do |f| | |
- if @tank_configuration.errors.any? | |
#error_explanation | |
h2 | |
= pluralize(@tank_configuration.errors.count, "error") | |
| prohibited this tank_configuration from being saved: | |
ul | |
- @tank_configuration.errors.full_messages.each do |msg| | |
li | |
= msg | |
.field | |
= f.label :model_number | |
= f.text_field :model_number | |
.field | |
= f.label :category | |
= f.select :category, TankConfiguration::Categories | |
.field | |
= f.label :capacity | |
= f.text_field :capacity | |
.field | |
= f.label :tank_size | |
= f.text_field :tank_size | |
.field | |
= f.label :number_of_tanks | |
= f.number_field :number_of_tanks | |
.field | |
= f.label :mount_type | |
= f.text_field :mount_type | |
.field | |
= f.label :tank_weight | |
= f.text_field :tank_weight | |
.field | |
= f.label :empty_system_weight | |
= f.text_field :empty_system_weight | |
.field | |
= f.label :enclosure_dimensions | |
= f.text_field :enclosure_dimensions | |
.field | |
= f.label :clearance_needed | |
= f.text_field :clearance_needed | |
.field | |
= f.label :display_publicly | |
= f.check_box :display_publicly | |
.field | |
= f.label :description | |
= f.text_area :description | |
.field | |
= f.file_field :images, :multiple => true | |
.actions | |
= f.submit |
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
# == Schema Information | |
# | |
# Table name: images | |
# | |
# id :integer not null, primary key | |
# file :string(255) | |
# category :string(255) | |
# tank_configuration_id :integer | |
# created_at :datetime | |
# updated_at :datetime | |
# | |
class Image < ActiveRecord::Base | |
belongs_to :tank_configuration | |
mount_uploader :file, ImageUploader | |
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
class ImagesController < CustomerController | |
before_action :set_image, only: [:show, :edit, :update, :destroy] | |
def access | |
permissions([:weak_admin, :weak_admin_plus] => AllRest) | |
end | |
# GET /images | |
# GET /images.json | |
def index | |
@images = Image.all | |
end | |
# GET /images/1 | |
# GET /images/1.json | |
def show | |
end | |
# GET /images/new | |
def new | |
@image = Image.new | |
end | |
# GET /images/1/edit | |
def edit | |
end | |
# POST /images | |
# POST /images.json | |
def create | |
images = image_params[:file].to_a.map do |file| | |
Image.create(image_params.merge(:file => file)) | |
end | |
redirect_to images_path, notice: 'Image was successfully created.' | |
end | |
# PATCH/PUT /images/1 | |
# PATCH/PUT /images/1.json | |
def update | |
respond_to do |format| | |
if @image.update(image_params) | |
format.html { redirect_to images_path, notice: 'Image was successfully updated.' } | |
format.json { head :no_content } | |
else | |
format.html { render action: 'edit' } | |
format.json { render json: @image.errors, status: :unprocessable_entity } | |
end | |
end | |
end | |
# DELETE /images/1 | |
# DELETE /images/1.json | |
def destroy | |
@image.destroy | |
respond_to do |format| | |
format.html { redirect_to images_path } | |
format.json { head :no_content } | |
end | |
end | |
private | |
# Use callbacks to share common setup or constraints between actions. | |
def set_image | |
@image = Image.find(params[:id]) | |
end | |
# Never trust parameters from the scary internet, only allow the white list through. | |
def image_params | |
params.require(:image).permit({:file => []}, :category, :tank_configuration_id) | |
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
# == Schema Information | |
# | |
# Table name: tank_configurations | |
# | |
# id :integer not null, primary key | |
# capacity :string(255) | |
# tank_size :string(255) | |
# number_of_tanks :integer | |
# mount_type :string(255) | |
# tank_weight :string(255) | |
# empty_system_weight :string(255) | |
# enclosure_dimensions :string(255) | |
# clearance_needed :string(255) | |
# created_at :datetime | |
# updated_at :datetime | |
# category :string(255) | |
# model_number :string(255) | |
# description :text | |
# display_publicly :boolean default(TRUE) | |
# | |
class TankConfiguration < ActiveRecord::Base | |
Categories = ["BACK OF CAB", "TOP OF BODY", "BUSES", "SIDE RAIL", "COMBO", "CANOPY"] | |
has_many :images | |
has_many :warranty_documents, as: :product | |
has_many :customer_builds, class_name: "::Customer::Build" | |
has_many :customer_orders, -> { uniq }, class_name: "::Customer::Order", through: :customer_builds, source: :order | |
has_many :customer_invoices, -> { uniq }, class_name: "::Customer::Invoice", through: :customer_builds, source: :invoice | |
def customer_invoice_builds | |
@order_builds ||= customer_builds.where(invoice_id: customer_invoices.map(&:id)).to_a | |
end | |
def build_count | |
customer_invoice_builds.size | |
end | |
def order_gross | |
@order_gross ||= begin | |
gross = 0 | |
grouped_invoices = customer_invoices.group_by{|o| o.tank_configurations.count > 1 ? :build : :order } | |
grouped_invoices.each_pair do |k, v| | |
case k | |
when :order | |
gross += v.sum(&:total) | |
when :build | |
gross += v.sum{|o| o.total_for_tank_configuration(id)} | |
end | |
end | |
gross | |
end | |
end | |
def builds_in_process | |
customer_invoice_builds.to_a.select{|b| (b[:status].keys & [:shipped, :installed]).empty?} | |
end | |
def builds_shipped | |
customer_invoice_builds.to_a.select{|b| b[:status].keys.include?(:shipped)} | |
end | |
def builds_completed | |
customer_invoice_builds.to_a.select{|b| b.status == :installed} | |
end | |
def builds_in_process_count | |
builds_in_process.size | |
end | |
def builds_shipped_count | |
builds_shipped.size | |
end | |
def builds_completed_count | |
builds_completed.size | |
end | |
def images=(attrs) | |
attrs.to_a.each { |attr| self.images.build(:file => attr) } | |
end | |
def title | |
"DH#: #{model_number} - #{category} - #{tank_size} - #{capacity}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment