From 2acb3efe5a3700b8587ea327944731f928de6dfd Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sat, 31 Mar 2018 08:00:56 -0400 Subject: [PATCH 1/2] Create line_items_controler.rb --- app/controllers/line_items_controler.rb | 96 +++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 app/controllers/line_items_controler.rb diff --git a/app/controllers/line_items_controler.rb b/app/controllers/line_items_controler.rb new file mode 100644 index 0000000..6f54778 --- /dev/null +++ b/app/controllers/line_items_controler.rb @@ -0,0 +1,96 @@ +#The License +# +#Copyright (c) 2018 Rick Barrette - All Rights Reserved +# +#Unauthorized copying of this software and associated documentation files (the "Software"), via any medium is strictly prohibited. +# +#Proprietary and confidential +# +#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. + +# This controller class will handle map management +class LineItemsController < ApplicationController + unloadable + + include AuthHelper + + before_filter :require_user + + # display all line items for an issue + def index + if params[:issue_id] + begin + @line_items = Issue.find_by_id(params[:issue_id]).line_items + rescue ActiveRecord::RecordNotFound + render_404 + end + end + end + + # return an HTML form for creating a new line item + def new + @line_item = LineItem.new + end + + # create a new line item + def create + @line_item = LineItem.new(params[:line_item]) + if @line_item.save + flash[:notice] = "New Line Item Created" + redirect_to @line_item.issue + else + flash[:error] = @line_item.errors.full_messages.to_sentence + redirect_to new_line_item_path + end + end + + # display a specific line item + def show + begin + @line_item = LineItem.find_by_id(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + end + + # return an HTML form for editing a line item + def edit + begin + @line_item = LineItem.find_by_id(params[:id]) + rescue ActiveRecord::RecordNotFound + render_404 + end + end + + # update a specific line item + def update + begin + @line_item = LineItem.find_by_id(params[:id]) + if @line_item.update_attributes(params[:line_item]) + flash[:notice] = "Line Item updated" + redirect_to @line_item + else + flash[:error] = @line_item.errors.full_messages.to_sentence if @line_item.errors + redirect_to edit_line_item_path + end + rescue ActiveRecord::RecordNotFound + render_404 + end + end + + # delete a specific line item + def destroy + begin + line_item = LineItem.find_by_id(params[:id]) + issue = line_item.issue + line_item.destroy + flash[:notice] = "Line Item deleted successfully" + redirect_to issue + rescue ActiveRecord::RecordNotFound + render_404 + end + end + +end From 7412ac4f91217a7c3e8d209074965fa070f460c0 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Sat, 31 Mar 2018 08:03:26 -0400 Subject: [PATCH 2/2] Added boolean billed --- db/migrate/026_create_line_items.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/db/migrate/026_create_line_items.rb b/db/migrate/026_create_line_items.rb index 51b40e1..b3132a3 100644 --- a/db/migrate/026_create_line_items.rb +++ b/db/migrate/026_create_line_items.rb @@ -17,7 +17,8 @@ class CreateLineItems < ActiveRecord::Migration t.float :amount t.string :description t.float :unit_price - t.float :quantity + t.float :quantity + t.boolean :billed end add_reference :line_items, :issues, index: true