More Progress!

This commit is contained in:
2016-04-21 20:44:18 -04:00
parent fa3322d530
commit 0c2d57c826
9 changed files with 81 additions and 36 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -0,0 +1,48 @@
<div class="row">
<div class="span6 columns">
<fieldset>
<%= form_for @vehicle do |f| %>
<div class="clearfix">
Customer:
<div class="input">
<%= f.select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, include_blank: true, :selected => @selected_customer, :required => true%>
</div>
</div>
<div class="clearfix">
Year:
<div class="input">
<%= f.text_field :year, :required => true %>
</div>
</div>
<div class="clearfix">
Make:
<div class="input">
<%= f.text_field :make, :required => true %>
</div>
</div>
<div class="clearfix">
Model:
<div class="input">
<%= f.text_field :model, :required => true %>
</div>
</div>
<div class="clearfix">
Notes:
<div class="input">
<%= f.text_area :notes, :rows => 6%>
</div>
</div>
<div class="actions">
<%= f.submit %>
</div>
<% end %>
</fieldset>
</div>
</div>

View File

@@ -0,0 +1,3 @@
<h1>Edit Customer Vehicle</h1>
<br/>
<%= render :partial => 'vehicles/form' %>

View File

@@ -1,22 +1,10 @@
<!--
#The MIT License (MIT)
#
#Copyright (c) 2016 rick barrette
#
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
#
#The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-->
<h1>Customer Vehicles</h1>
<br/>
<br/>
<% Vehicle.all.each do |vehicle| %>
<br/>
<div>
<%= 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?"} %>
</div>
<% end %>

View File

@@ -1,10 +1,3 @@
<h1>Customer Vehicles</h1>
<h1>New Customer Vehicle</h1>
<br/>
<%= form_for @vehicle do |f| %>
Customer: <%= f.select :qbo_customer_id, QboCustomer.all.pluck(:name, :id).sort, include_blank: true, :required => true%><br />
Year: <%= f.text_field :year, :required => true %><br />
Make: <%= f.text_field :make, :required => true %><br />
Model: <%= f.text_area :model, :required => true %><br />
Notes: <%= f.text_area :notes, :rows => 3%><br />
<%= f.submit %>
<% end %>
<%= render :partial => 'vehicles/form' %>

View File

@@ -0,0 +1,9 @@
<h1>Customer Vehicle</h1>
<br/>
<%= @vehicle.qbo_customer.name if @vehicle.qbo_customer %>
<br/>
<%= @vehicle.to_s %>
<br/>
<%= button_to "Edit", edit_vehicle_path(@vehicle), method: :get%>
<br/>
<%= button_to "Delete", @vehicle, method: :delete, data: {confirm: "You sure?"} %>

View File

@@ -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

View File

@@ -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