diff --git a/app/components/transactions.rb b/app/components/transactions.rb index 040230b..f202646 100644 --- a/app/components/transactions.rb +++ b/app/components/transactions.rb @@ -13,5 +13,55 @@ class Transactions < Netzke::Basepack::Grid } } ] + + end + + def default_fields_for_forms + bike_store = Bike.all.map { |b| [b.id, b.serial_number] } + user_store = User.all.map { |u| [u.id, u.to_s] } + [ + :amount, + :item, + { :name => :for_bike, :checkboxName => :bike_item, :inputValue => true, :title => "Selling a bike?", + :xtype => 'fieldset', :checkboxToggle => true, :collapsed => true, :items => [ + {:xtype => 'combo', :no_binding => true, :name => :bike_id, :title => 'Bike', :fieldLabel => 'Bike', :store => bike_store} + ] + }, + { + xtype: 'fieldcontainer', + fieldLabel: 'Customer Type', + defaultType: 'radiofield', + defaults: { + flex: 1 + }, + layout: 'hbox', + items: [ + { + no_binding: true, + boxLabel: 'Customer', + name: 'customer_type', + inputValue: 'Customer', + id: 'customer_radio' + }, + { + no_binding: true, + boxLabel: 'User', + name: 'customer_type', + inputValue: 'User', + id: 'user_radio' + } + ] + }, + { :name => :for_user, :checkboxName => :customer_type, :inputValue => true, :title => "Customer a User?", + :xtype => 'fieldset', :collapsible => true, :collapsed => true, :items => [ + {:xtype => 'combo', :no_binding => true, :name => :customer_id, :title => 'User', :fieldLabel => 'User', :store => user_store} + ] + }, + { :name => :for_customer, :checkboxName => :customer_type, :inputValue => true, :title => "New Customer?", + :xtype => 'fieldset', :collapsible => true, :collapsed => true, :items => [ + { :xtype => 'textfield', :no_binding => true, :name => 'customer[first_name]'}, + ] + } + ] end end diff --git a/app/models/transaction.rb b/app/models/transaction.rb index 484e8f9..0afc26a 100644 --- a/app/models/transaction.rb +++ b/app/models/transaction.rb @@ -1,8 +1,24 @@ class Transaction < ActiveRecord::Base acts_as_loggable - attr_accessible :vendor_id, :customer_id, :customer_type, :bike_id, :amount, :item + + attr_accessible :vendor_id, :customer_id, :customer_type, :bike_id, :amount, :item, + :customer_attributes belongs_to :vendor, :class_name => 'User', :foreign_key => 'vendor_id' belongs_to :bike + belongs_to :customer + + accepts_nested_attributes_for :customer, allow_destroy: false + + before_save :check_customer_type + + def check_customer_type + puts "_________------------_________------------_________------------" + puts self.inspect + puts "_________------------_________------------_________------------" + end + def to_s + "#{amount} #{item} #{bike_id}" + end end