mirror of https://github.com/fspc/BikeShed-1.git
Jason Denney
12 years ago
26 changed files with 441 additions and 16 deletions
@ -0,0 +1,21 @@ |
|||||
|
class Customers < Netzke::Basepack::Grid |
||||
|
def configure(c) |
||||
|
c.model = "Customer" |
||||
|
end |
||||
|
|
||||
|
#override with nil to remove actions |
||||
|
def default_bbar |
||||
|
[ :apply, :add_in_form, :search ] |
||||
|
end |
||||
|
|
||||
|
#needed for transactions customer selection |
||||
|
js_configure do |c| |
||||
|
c.mixin :init_component |
||||
|
end |
||||
|
|
||||
|
#needed for transactions customer selection |
||||
|
endpoint :select_customer do |params, this| |
||||
|
session[:selected_customer_id] = params[:customer_id] |
||||
|
session[:selected_customer_type] = params[:customer_type] |
||||
|
end |
||||
|
end |
@ -0,0 +1,11 @@ |
|||||
|
{ |
||||
|
initComponent: function(){ |
||||
|
// calling superclass's initComponent
|
||||
|
this.callParent(); |
||||
|
this.getView().on('itemclick', function(view, record){ |
||||
|
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
|
||||
|
console.log("user: " + record.get('id') ); |
||||
|
this.selectCustomer({customer_id: record.get('id'), customer_type: 'Customer'}); |
||||
|
}, this); |
||||
|
} |
||||
|
} |
@ -0,0 +1,67 @@ |
|||||
|
class TransactionLogs < Netzke::Basepack::Grid |
||||
|
|
||||
|
def configure(c) |
||||
|
super |
||||
|
|
||||
|
c.model = "ActsAsLoggable::Log" |
||||
|
c.title = "Transaction Payments" |
||||
|
c.data_store = {auto_load: false} |
||||
|
c.scope = lambda { |rel| rel.where(:loggable_type => 'Transaction',:loggable_id => session[:selected_transaction_id]);} |
||||
|
c.strong_default_attrs = { |
||||
|
:loggable_type => 'Transaction', |
||||
|
:loggable_id => session[:selected_transaction_id], |
||||
|
:log_action_type => 'ActsAsLoggable::TransactionAction', |
||||
|
:logger_type => 'User', |
||||
|
:logger_id => controller.current_user.id, |
||||
|
:start_date => Time.now.to_formatted_s(:db), |
||||
|
:end_date => Time.now.to_formatted_s(:db) |
||||
|
} |
||||
|
|
||||
|
c.columns = [ |
||||
|
{ :name => :start_date, :format => "g:ia - D, M j - Y", :width => 165, :default_value => Time.now.to_formatted_s(:db), :text => 'Date' }, |
||||
|
{ :name => :description, :text => "Amount"} , |
||||
|
{ :name => :transaction_action__action, :text => 'Method'}, |
||||
|
{ :name => :logged_by, :getter => lambda{ |rec| |
||||
|
user = User.find_by_id(rec.logger_id) |
||||
|
user.nil? ? "" : "#{user.first_name} #{user.last_name}" |
||||
|
}, |
||||
|
:text => "Processed by" |
||||
|
} |
||||
|
] |
||||
|
|
||||
|
if controller.current_user.user? |
||||
|
c.prohibit_update = true |
||||
|
c.prohibit_create = true |
||||
|
c.prohibit_delete = true |
||||
|
end |
||||
|
|
||||
|
end |
||||
|
|
||||
|
def default_fields_for_forms |
||||
|
customer = nil |
||||
|
item = nil |
||||
|
if session[:selected_transaction_id] |
||||
|
trans = Transaction.find_by_id(session[:selected_transaction_id]) |
||||
|
customer = trans.customer |
||||
|
item = trans.item |
||||
|
end |
||||
|
customer = "No Customer Selected" if customer.nil? |
||||
|
item = "No Item Selected" if item.nil? |
||||
|
[ |
||||
|
{ :no_binding => true, :xtype => 'displayfield', :fieldLabel => "Payment from:", :value => "#{customer.to_s}"}, |
||||
|
{ :no_binding => true, :xtype => 'displayfield', :fieldLabel => "Payment for:", :value => "#{item.to_s}"}, |
||||
|
{ :name => :description, :xtype => 'numberfield', :field_label => 'Amount'}, |
||||
|
#had to hack acts_as_loggable/log.rb to get this to work |
||||
|
{ :name => :transaction_action__action, :field_label => 'Payment Method'} |
||||
|
] |
||||
|
end |
||||
|
|
||||
|
|
||||
|
#override with nil to remove actions |
||||
|
def default_bbar |
||||
|
bbar = [ :search ] |
||||
|
bbar.concat [ :apply, :add_in_form ] if not controller.current_user.user? |
||||
|
bbar |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,62 @@ |
|||||
|
class Transactions < Netzke::Basepack::Grid |
||||
|
def configure(c) |
||||
|
super |
||||
|
c.model = "Transaction" |
||||
|
c.strong_default_attrs = { |
||||
|
:vendor_id => controller.current_user.id, |
||||
|
:customer_id => session[:selected_customer_id], |
||||
|
:customer_type => session[:selected_customer_type] |
||||
|
} |
||||
|
c.columns = [ |
||||
|
:amount, |
||||
|
:item, |
||||
|
{ :name => :bike__serial_number}, |
||||
|
{ :name => :vendor, :getter => lambda { |rec| |
||||
|
user = rec.vendor |
||||
|
user.nil? ? "" : "#{user.first_name} #{user.last_name}" |
||||
|
} |
||||
|
}, |
||||
|
{ :name => :customer, :getter => lambda { |rec| |
||||
|
user = rec.customer |
||||
|
user.nil? ? "" : "#{user.first_name} #{user.last_name}" |
||||
|
} |
||||
|
}, |
||||
|
:created_at |
||||
|
] |
||||
|
|
||||
|
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] } |
||||
|
customer = nil |
||||
|
if session[:selected_customer_type] == "User" |
||||
|
customer = User.find_by_id(session[:selected_customer_id]) |
||||
|
elsif session[:selected_customer_type] == "Customer" |
||||
|
customer = Customer.find_by_id(session[:selected_customer_id]) |
||||
|
end |
||||
|
|
||||
|
customer = "No User Selected" if customer.nil? |
||||
|
[ |
||||
|
{ :no_binding => true, :xtype => 'displayfield', :fieldLabel => "Creating Transaction for:", :value => "#{customer.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} |
||||
|
] |
||||
|
} |
||||
|
] |
||||
|
end |
||||
|
|
||||
|
#override with nil to remove actions |
||||
|
def default_bbar |
||||
|
[ :apply, :add_in_form, :search ] |
||||
|
end |
||||
|
=begin |
||||
|
#needed for transaction selection |
||||
|
js_configure do |c| |
||||
|
c.mixin :init_component |
||||
|
end |
||||
|
=end |
||||
|
end |
@ -0,0 +1,30 @@ |
|||||
|
class TransactionsBorder < Netzke::Base |
||||
|
# Remember regions collapse state and size |
||||
|
include Netzke::Basepack::ItemPersistence |
||||
|
component :transactions |
||||
|
component :transaction_logs |
||||
|
#users and customers components are required for the transactions form |
||||
|
component :users_and_customers_accordian |
||||
|
|
||||
|
def configure(c) |
||||
|
super |
||||
|
c.header = false |
||||
|
c.title = "Transactions" |
||||
|
c.items = [ |
||||
|
{ netzke_component: :transactions, region: :center, height: 300, split: true }, |
||||
|
{ netzke_component: :transaction_logs, region: :east, width: 300, split: true }, |
||||
|
{ netzke_component: :users_and_customers_accordian, region: :south, height: 300, split: true } |
||||
|
] |
||||
|
end |
||||
|
|
||||
|
js_configure do |c| |
||||
|
c.layout = :border |
||||
|
c.border = false |
||||
|
c.mixin :init_component |
||||
|
end |
||||
|
|
||||
|
endpoint :select_transaction do |params, this| |
||||
|
session[:selected_transaction_id] = params[:transaction_id] |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
initComponent: function(){ |
||||
|
// calling superclass's initComponent
|
||||
|
this.callParent(); |
||||
|
|
||||
|
// setting the 'rowclick' event
|
||||
|
var view = this.getComponent('transactions').getView(); |
||||
|
view.on('itemclick', function(view, record){ |
||||
|
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
|
||||
|
this.selectTransaction({transaction_id: record.get('id')}); |
||||
|
this.getComponent('transaction_logs').getStore().load(); |
||||
|
}, this); |
||||
|
} |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
class UserTransactions < Netzke::Basepack::Grid |
||||
|
|
||||
|
def configure(c) |
||||
|
super |
||||
|
|
||||
|
c.model = "Transaction" |
||||
|
c.title = "Transactions" |
||||
|
c.scope = lambda { |rel| rel.where(:customer_id => controller.current_user.id, :customer_type => 'User');} |
||||
|
c.data_store = { auto_load: true } |
||||
|
c.columns = [ |
||||
|
:amount, |
||||
|
:item, |
||||
|
{ :name => :bike__serial_number}, |
||||
|
{ :name => :vendor, :getter => lambda { |rec| |
||||
|
user = rec.vendor |
||||
|
user.nil? ? "" : "#{user.first_name} #{user.last_name}" |
||||
|
} |
||||
|
}, |
||||
|
{ :name => :customer, :getter => lambda { |rec| |
||||
|
user = rec.customer |
||||
|
user.nil? ? "" : "#{user.first_name} #{user.last_name}" |
||||
|
} |
||||
|
}, |
||||
|
:created_at |
||||
|
] |
||||
|
|
||||
|
if controller.current_user.user? |
||||
|
c.prohibit_update = true |
||||
|
c.prohibit_create = true |
||||
|
c.prohibit_delete = true |
||||
|
end |
||||
|
end |
||||
|
|
||||
|
#override with nil to remove actions |
||||
|
def default_bbar |
||||
|
bbar = [ :search ] |
||||
|
bbar.concat [ :apply, :add_in_form ] if not controller.current_user.user? |
||||
|
bbar |
||||
|
end |
||||
|
end |
@ -0,0 +1,27 @@ |
|||||
|
class UserTransactionsBorder < Netzke::Base |
||||
|
# Remember regions collapse state and size |
||||
|
include Netzke::Basepack::ItemPersistence |
||||
|
component :user_transactions |
||||
|
component :transaction_logs |
||||
|
|
||||
|
def configure(c) |
||||
|
super |
||||
|
c.header = false |
||||
|
c.title = "Transactions" |
||||
|
c.items = [ |
||||
|
{ netzke_component: :user_transactions, region: :center, height: 300, split: true }, |
||||
|
{ netzke_component: :transaction_logs, region: :south, height: 300, split: true } |
||||
|
] |
||||
|
end |
||||
|
|
||||
|
js_configure do |c| |
||||
|
c.layout = :border |
||||
|
c.border = false |
||||
|
c.mixin :init_component |
||||
|
end |
||||
|
|
||||
|
endpoint :select_transaction do |params, this| |
||||
|
session[:selected_transaction_id] = params[:transaction_id] |
||||
|
end |
||||
|
|
||||
|
end |
@ -0,0 +1,14 @@ |
|||||
|
{ |
||||
|
initComponent: function(){ |
||||
|
// calling superclass's initComponent
|
||||
|
this.callParent(); |
||||
|
|
||||
|
// setting the 'rowclick' event
|
||||
|
var view = this.getComponent('user_transactions').getView(); |
||||
|
view.on('itemclick', function(view, record){ |
||||
|
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
|
||||
|
this.selectTransaction({transaction_id: record.get('id')}); |
||||
|
this.getComponent('transaction_logs').getStore().load(); |
||||
|
}, this); |
||||
|
} |
||||
|
} |
@ -0,0 +1,11 @@ |
|||||
|
{ |
||||
|
initComponent: function(){ |
||||
|
// calling superclass's initComponent
|
||||
|
this.callParent(); |
||||
|
this.getView().on('itemclick', function(view, record){ |
||||
|
// The beauty of using Ext.Direct: calling 3 endpoints in a row, which results in a single call to the server!
|
||||
|
console.log("user: " + record.get('id') ); |
||||
|
this.selectCustomer({customer_id: record.get('id'), customer_type: 'User'}); |
||||
|
}, this); |
||||
|
} |
||||
|
} |
@ -0,0 +1,10 @@ |
|||||
|
class UsersAndCustomersAccordian < Netzke::Basepack::Accordion |
||||
|
component :customers |
||||
|
component :users |
||||
|
|
||||
|
def configure(c) |
||||
|
c.prevent_header = true |
||||
|
c.items = [ :customers, :users ] |
||||
|
super |
||||
|
end |
||||
|
end |
@ -0,0 +1,22 @@ |
|||||
|
class Customer < ActiveRecord::Base |
||||
|
attr_accessible :first_name, :last_name, :addrStreet1, |
||||
|
:addrStreet2, :addrCity, :addrState, :addrZip, :phone, :email |
||||
|
|
||||
|
has_many :transactions, :as => :customer |
||||
|
|
||||
|
validates :first_name, :presence => true |
||||
|
validates :last_name, :presence => true |
||||
|
#validates :addrStreet1, :presence => true |
||||
|
#validates :addrStreet2, :presence => true |
||||
|
#validates :addrCity, :presence => true |
||||
|
#validates :addrState, :presence => true |
||||
|
#validates :addrZip, :presence => true |
||||
|
#validates :phone, :presence => true |
||||
|
#validates :email, :presence => true |
||||
|
|
||||
|
self.per_page = 15 |
||||
|
|
||||
|
def to_s |
||||
|
"#{first_name} #{last_name}" |
||||
|
end |
||||
|
end |
@ -0,0 +1,19 @@ |
|||||
|
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 |
||||
|
belongs_to :customer, :polymorphic => true |
||||
|
|
||||
|
validates :vendor_id, :presence => true |
||||
|
validates :customer_id, :presence => { :message => "Choose a User or Customer"} |
||||
|
validates :customer_type, :presence => { :message => "Choose a User or Customer"} |
||||
|
validates :amount, :presence => true |
||||
|
validates :item, :presence => true |
||||
|
|
||||
|
def to_s |
||||
|
"#{amount} #{item} #{bike_id}" |
||||
|
end |
||||
|
end |
@ -0,0 +1,19 @@ |
|||||
|
class CreateCustomers < ActiveRecord::Migration |
||||
|
def change |
||||
|
create_table :customers do |t| |
||||
|
t.string "first_name", :null => false |
||||
|
t.string "last_name", :null => false |
||||
|
t.string "addrStreet1" |
||||
|
t.string "addrStreet2" |
||||
|
t.string "addrCity" |
||||
|
t.string "addrState" |
||||
|
t.string "addrZip" |
||||
|
t.string "phone" |
||||
|
t.string "email" |
||||
|
end |
||||
|
|
||||
|
add_index :customers, :phone, :unique => true |
||||
|
add_index :customers, :email, :unique => true |
||||
|
end |
||||
|
|
||||
|
end |
Loading…
Reference in new issue