diff --git a/app/controllers/charges_controller.rb b/app/controllers/charges_controller.rb index e87c2e17..e3aade09 100644 --- a/app/controllers/charges_controller.rb +++ b/app/controllers/charges_controller.rb @@ -32,13 +32,16 @@ class ChargesController < ApplicationController # GET /charges # GET /charges.json def index - unless ( params[:organization_id].blank? ) - @organization = Organization.find(params[:organization_id]) - @charges = @organization.charges - else + if (current_user.has_role? :admin) + @charges = Charge.all + elsif (current_user.participant.is_scc?) @charges = Charge.all + else + @orgs = current_user.participant.memberships.map {|mem| mem.organization.id} + unless @orgs.nil? + @charges = Charge.for_organizations(@orgs) + end end - @charges = @charges.paginate(:page => params[:page]).per_page(20) end @@ -59,6 +62,7 @@ def new # GET /charges/1/edit def edit + @current_receiving_participant = @charge.receiving_participant.nil? ? "" : @charge.receiving_participant.formatted_name end # POST /charges @@ -76,7 +80,7 @@ def create # PUT /charges/1.json def update @charge.is_approved = false - @charge.update(charge_params) + @charge.update_attributes(charge_params) respond_with(@charge) end @@ -96,7 +100,8 @@ def destroy def approve @charge.is_approved = !@charge.is_approved @charge.save - respond_with @charge, location: -> {charges_path} + + respond_with(@charge, location: @charge.organization) end private diff --git a/app/models/charge.rb b/app/models/charge.rb index fd208350..89362d41 100644 --- a/app/models/charge.rb +++ b/app/models/charge.rb @@ -39,5 +39,13 @@ class Charge < ActiveRecord::Base default_scope { order('charged_at DESC') } scope :approved, -> { where(is_approved: true) } scope :pending, -> { where(is_approved: false) } + + def self.for_organizations(organizations) + if (organizations.nil?) + all + else + where("organization_id IN (?)", organizations) + end + end end diff --git a/app/views/charges/_form.html.erb b/app/views/charges/_form.html.erb index 374d0e3d..2b7648d1 100644 --- a/app/views/charges/_form.html.erb +++ b/app/views/charges/_form.html.erb @@ -20,11 +20,14 @@ When adding a charge, please ensure that you add a detailed description. This al <%= f.input_field :amount, :as => :string %> <% end %> + <%= f.input :description, :as => :text, textarea: "{ font-size:16px; }" %> + <%= f.association :issuing_participant, :collection => Participant.scc %> + <%= f.input :receiving_participant do %> <%= f.input_field :receiving_participant_id, as: :hidden %> - <%= text_field_tag 'card-number-input', nil, class: 'form-control' %> + <%= text_field_tag 'card-number-input', nil, placeholder: @current_receiving_participant, class: 'form-control'%>
<% end %> diff --git a/test/unit/event_type_test.rb b/test/unit/event_type_test.rb index 7c3a828c..2d2877ab 100644 --- a/test/unit/event_type_test.rb +++ b/test/unit/event_type_test.rb @@ -9,6 +9,7 @@ # **`display`** | `boolean` | # **`id`** | `integer` | `not null, primary key` # **`name`** | `string(255)` | +# **`priority`** | `integer` | # class EventTypeTest < ActiveSupport::TestCase @@ -16,4 +17,4 @@ class EventTypeTest < ActiveSupport::TestCase should have_many(:events) -end \ No newline at end of file +end