mirror of
				https://github.com/fspc/BikeShed-1.git
				synced 2025-10-31 00:45:35 -04:00 
			
		
		
		
	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.
This commit is contained in:
		
							parent
							
								
									a9533e6249
								
							
						
					
					
						commit
						11e738b428
					
				| @ -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? | ||||
|  | ||||
							
								
								
									
										17
									
								
								app/components/transactions.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								app/components/transactions.rb
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
| @ -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 | ||||
|  | ||||
							
								
								
									
										8
									
								
								app/models/transaction.rb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								app/models/transaction.rb
									
									
									
									
									
										Normal file
									
								
							| @ -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 | ||||
| @ -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 | ||||
| 
 | ||||
|  | ||||
| @ -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 | ||||
|  | ||||
							
								
								
									
										11
									
								
								db/schema.rb
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								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| | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user