From 11e738b42827669add6e81b7a5dbef0a21fcc4c0 Mon Sep 17 00:00:00 2001 From: Jason Denney Date: Sat, 19 Jan 2013 15:59:47 -0500 Subject: [PATCH] Adding transactions -Need to create a customers table to store contact information of customers who are not a user. -Need to scope "User Transactions" for users, staff, and admin. Need to have a "All Shop Transactions" tab. -Need to add conditional UX to form. --- app/components/app_tab_panel.rb | 2 +- app/components/transactions.rb | 17 +++++++++++++++++ app/models/bike.rb | 2 ++ app/models/transaction.rb | 8 ++++++++ app/models/user.rb | 1 + .../20121205043759_create_transactions.rb | 6 +++++- db/schema.rb | 11 ++++++++--- 7 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 app/components/transactions.rb create mode 100644 app/models/transaction.rb diff --git a/app/components/app_tab_panel.rb b/app/components/app_tab_panel.rb index 7442c27..d881e54 100644 --- a/app/components/app_tab_panel.rb +++ b/app/components/app_tab_panel.rb @@ -10,7 +10,7 @@ class AppTabPanel < Netzke::Basepack::TabPanel #all users # (had to use hash for borders to get the title to display properly) - @@app_tab_panel_items = [ :bikes_border, {layout: :fit, wrappedComponent: :brands_and_models_border, title: "Brands/Models"}] + @@app_tab_panel_items = [ :transactions, :bikes_border, {layout: :fit, wrappedComponent: :brands_and_models_border, title: "Brands/Models"}] #for users if controller.current_user.user? diff --git a/app/components/transactions.rb b/app/components/transactions.rb new file mode 100644 index 0000000..040230b --- /dev/null +++ b/app/components/transactions.rb @@ -0,0 +1,17 @@ +class Transactions < Netzke::Basepack::Grid + def configure(c) + super + c.model = "Transaction" + c.strong_default_attrs = { :vendor_id => controller.current_user.id } + c.columns = [ + :amount, + :item, + { :name => :bike__serial_number}, + { :name => :vendor, :getter => lambda { |rec| + user = rec.vendor + user.nil? ? "" : "#{user.first_name} #{user.last_name}" + } + } + ] + end +end diff --git a/app/models/bike.rb b/app/models/bike.rb index b57b59f..4389ffb 100644 --- a/app/models/bike.rb +++ b/app/models/bike.rb @@ -2,6 +2,8 @@ class Bike < ActiveRecord::Base acts_as_loggable attr_accessible :serial_number, :bike_brand_id, :bike_model_id, :color, :bike_style_id, :seat_tube_height, :top_tube_length, :wheel_size, :value, :bike_condition_id, :bike_status_id + + has_many :transactions has_one :owner, :class_name => 'User' belongs_to :bike_brand diff --git a/app/models/transaction.rb b/app/models/transaction.rb new file mode 100644 index 0000000..484e8f9 --- /dev/null +++ b/app/models/transaction.rb @@ -0,0 +1,8 @@ +class Transaction < ActiveRecord::Base + acts_as_loggable + attr_accessible :vendor_id, :customer_id, :customer_type, :bike_id, :amount, :item + + belongs_to :vendor, :class_name => 'User', :foreign_key => 'vendor_id' + belongs_to :bike + +end diff --git a/app/models/user.rb b/app/models/user.rb index a656337..c51f98a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -10,6 +10,7 @@ class User < ActiveRecord::Base :first_name, :last_name, :nickname, :user_role_id, :bike_id, :user_profiles_attributes + has_many :transactions has_many :user_profiles accepts_nested_attributes_for :user_profiles, allow_destroy: false diff --git a/db/migrate/20121205043759_create_transactions.rb b/db/migrate/20121205043759_create_transactions.rb index 86f5222..827e7a8 100644 --- a/db/migrate/20121205043759_create_transactions.rb +++ b/db/migrate/20121205043759_create_transactions.rb @@ -1,9 +1,12 @@ class CreateTransactions < ActiveRecord::Migration def change create_table :transactions do |t| - t.integer "user_id", :null => false + t.integer "vendor_id", :null => false + t.integer "customer_id" + t.integer "customer_type" t.integer "bike_id" t.integer "amount", :null => false + t.string "item", :null => false #Adding whether or not a user sold or purchased the bike #could be used to help keep track of external sales. #aka, a collective member (user) sold a bike to @@ -11,6 +14,7 @@ class CreateTransactions < ActiveRecord::Migration #Currently this model automatically assumes that the user is #purchasing a bike, or a part for a bike from the collective #t.boolean "user_sold_flag", :default => false + t.timestamps end end end diff --git a/db/schema.rb b/db/schema.rb index 0b8e94a..62957cf 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -88,9 +88,14 @@ ActiveRecord::Schema.define(:version => 20121229160809) do end create_table "transactions", :force => true do |t| - t.integer "user_id", :null => false - t.integer "bike_id" - t.integer "amount", :null => false + t.integer "vendor_id", :null => false + t.integer "customer_id" + t.integer "customer_type" + t.integer "bike_id" + t.integer "amount", :null => false + t.string "item", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false end create_table "user_actions", :force => true do |t|