diff --git a/app/controllers/vehicles_controller.rb b/app/controllers/vehicles_controller.rb index f497b60..ada5947 100644 --- a/app/controllers/vehicles_controller.rb +++ b/app/controllers/vehicles_controller.rb @@ -28,26 +28,30 @@ class VehiclesController < ApplicationController # create a new vehicle def create - Vehicle.new(params).save + @vehicle = Vehicle.new(params) + @vehicle.save! + redirect_to @vehicle end # display a specific vehicle def show - + @vehicle = Vehicle.find_by_id(params[:id]) end # return an HTML form for editing a vehicle def edit - + @vehicle = Vehicle.find_by_id(params[:id]) + @selected_customer = @vehicle.qbo_customer.name if @vehicle.qbo_customer end # update a specific vehicle def update - v = Vehicle.find_by_id(params[:id]) - if v != nil - #TODO something + @vehicle = Vehicle.find_by_id(params[:id]) + if @vehicle.update_attributes(params) + flash[:success] = "Vehicle updated" + redirect_to @vehicle else - flash.now[:error] = "No Vehicle Found" + render :edit end end diff --git a/app/models/qbo_customer.rb b/app/models/qbo_customer.rb index d0fa1cd..e73cba6 100644 --- a/app/models/qbo_customer.rb +++ b/app/models/qbo_customer.rb @@ -16,7 +16,11 @@ class QboCustomer < ActiveRecord::Base attr_accessible :name validates_presence_of :id, :name - def to_s; name end + self.primary_key = "id" + + def to_s + name + end def get_base Qbo.get_base(:customer) diff --git a/app/views/vehicles/_form.html.erb b/app/views/vehicles/_form.html.erb new file mode 100644 index 0000000..802e201 --- /dev/null +++ b/app/views/vehicles/_form.html.erb @@ -0,0 +1,48 @@ +
+
+
+ + <%= form_for @vehicle do |f| %> +
+ Customer: +
+ <%= f.select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, include_blank: true, :selected => @selected_customer, :required => true%> +
+
+ +
+ Year: +
+ <%= f.text_field :year, :required => true %> +
+
+ +
+ Make: +
+ <%= f.text_field :make, :required => true %> +
+
+ +
+ Model: +
+ <%= f.text_field :model, :required => true %> +
+
+ +
+ Notes: +
+ <%= f.text_area :notes, :rows => 6%> +
+
+ +
+ <%= f.submit %> +
+ <% end %> + +
+
+
\ No newline at end of file diff --git a/app/views/vehicles/edit.html.erb b/app/views/vehicles/edit.html.erb new file mode 100644 index 0000000..624eda8 --- /dev/null +++ b/app/views/vehicles/edit.html.erb @@ -0,0 +1,3 @@ +

Edit Customer Vehicle

+
+<%= render :partial => 'vehicles/form' %> diff --git a/app/views/vehicles/index.html.erb b/app/views/vehicles/index.html.erb index 15a0f37..55efa7c 100644 --- a/app/views/vehicles/index.html.erb +++ b/app/views/vehicles/index.html.erb @@ -1,22 +1,10 @@ - -

Customer Vehicles



<% Vehicle.all.each do |vehicle| %>
- <%= vehicle.qbo_customer.name if vehicle.qbo_customer %> <%= vehicle.to_s %> <%= button_to "Edit", vehicle, method: :edit %> <%= button_to "Delete", vehicle, method: :delete, data: {confirm: "You sure?"} %> + <%= vehicle.qbo_customer.name if vehicle.qbo_customer %> <%= vehicle.to_s %> <%= button_to "Edit", edit_vehicle_path(vehicle), method: :get%> <%= button_to "Delete", vehicle, method: :delete, data: {confirm: "You sure?"} %>
<% end %> diff --git a/app/views/vehicles/new.html.erb b/app/views/vehicles/new.html.erb index 86be779..38f2bcb 100644 --- a/app/views/vehicles/new.html.erb +++ b/app/views/vehicles/new.html.erb @@ -1,10 +1,3 @@ -

Customer Vehicles

+

New Customer Vehicle


-<%= form_for @vehicle do |f| %> - Customer: <%= f.select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, include_blank: true, :required => true%>
- Year: <%= f.text_field :year, :required => true %>
- Make: <%= f.text_field :make, :required => true %>
- Model: <%= f.text_area :model, :required => true %>
- Notes: <%= f.text_area :notes, :rows => 3%>
- <%= f.submit %> -<% end %> +<%= render :partial => 'vehicles/form' %> diff --git a/app/views/vehicles/show.html.erb b/app/views/vehicles/show.html.erb new file mode 100644 index 0000000..22edd03 --- /dev/null +++ b/app/views/vehicles/show.html.erb @@ -0,0 +1,9 @@ +

Customer Vehicle

+
+<%= @vehicle.qbo_customer.name if @vehicle.qbo_customer %> +
+<%= @vehicle.to_s %> +
+<%= button_to "Edit", edit_vehicle_path(@vehicle), method: :get%> +
+<%= button_to "Delete", @vehicle, method: :delete, data: {confirm: "You sure?"} %> diff --git a/init.rb b/init.rb index 6f8c9df..e0ee8d9 100644 --- a/init.rb +++ b/init.rb @@ -42,6 +42,7 @@ Redmine::Plugin.register :redmine_qbo do #Quickbooks.sandbox_mode = true # Register QBO top menu item - menu :top_menu, :qbo, { :controller => 'qbo', :action => 'index' }, :caption => 'Quickbooks', :if => Proc.new { User.current.admin? } + menu :top_menu, :qbo, { :controller => :qbo, :action => :index }, :caption => 'Quickbooks', :if => Proc.new { User.current.admin? } + menu :top_menu, :vehicles, { :controller => :vehicles, :action => :index }, :caption => 'Vehicles', :if => Proc.new { User.current.logged? } end diff --git a/lib/issues_form_hook_listener.rb b/lib/issues_form_hook_listener.rb index ae134d3..18b7d78 100644 --- a/lib/issues_form_hook_listener.rb +++ b/lib/issues_form_hook_listener.rb @@ -13,11 +13,6 @@ class IssuesFormHookListener < Redmine::Hook::ViewListener # Edit Issue Form # Show a dropdown for quickbooks contacts def view_issues_form_details_bottom(context={}) - # Update the customer and item database - QboCustomer.update_all - #QboItem.update_all - QboInvoice.update_all - #QboEstimate.update_all # Check to see if there is a quickbooks user attached to the issue selected_customer = context[:issue].qbo_customer ? context[:issue].qbo_customer.id : nil