From 3159289ac03ec1eb64e8a014991007ffeedf249a Mon Sep 17 00:00:00 2001 From: Ricky Barrette Date: Sun, 6 Mar 2022 17:26:57 -0500 Subject: [PATCH] Removed unused code, only need to bill time removed line items, payments, drop used db tables --- app/controllers/line_items_controler.rb | 94 ------------------- app/controllers/payments_controller.rb | 57 ----------- app/models/payment.rb | 37 -------- app/models/qbo_item.rb | 47 ---------- app/models/qbo_purchase.rb | 47 ---------- app/views/payments/_form.html.erb | 42 --------- app/views/payments/new.html.erb | 3 - .../migrate/034_remove_qbo_items.rb | 27 +----- 8 files changed, 5 insertions(+), 349 deletions(-) delete mode 100644 app/controllers/line_items_controler.rb delete mode 100644 app/controllers/payments_controller.rb delete mode 100644 app/models/payment.rb delete mode 100644 app/models/qbo_item.rb delete mode 100644 app/models/qbo_purchase.rb delete mode 100644 app/views/payments/_form.html.erb delete mode 100644 app/views/payments/new.html.erb rename app/models/line_item.rb => db/migrate/034_remove_qbo_items.rb (63%) diff --git a/app/controllers/line_items_controler.rb b/app/controllers/line_items_controler.rb deleted file mode 100644 index 5300f32..0000000 --- a/app/controllers/line_items_controler.rb +++ /dev/null @@ -1,94 +0,0 @@ -#The MIT License (MIT) -# -#Copyright (c) 2022 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. - -# This controller class will handle map management -class LineItemsController < ApplicationController - unloadable - - include AuthHelper - - before_action :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 diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb deleted file mode 100644 index 3ee14cc..0000000 --- a/app/controllers/payments_controller.rb +++ /dev/null @@ -1,57 +0,0 @@ -#The MIT License (MIT) -# -#Copyright (c) 2022 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. -class PaymentsController < ApplicationController - unloadable - - include AuthHelper - - before_action :check_permissions - - def new - @payment = Payment.new - - @customers = Customer.all.sort_by &:name - - @accounts = Qbo.get_base(:account).query("SELECT Id, Name FROM Account WHERE AccountType = 'Bank' Order By Name") - - @payment_methods = Qbo.get_base(:payment_method).all - end - - def create - @payment = Payment.new(params[:payment]) - if @payment.save - flash[:notice] = "Payment Saved" - redirect_to Customer.find_by_id(@payment.customer_id) - else - flash[:error] = @payment.errors.full_messages.to_sentence - redirect_to new_customer_path - end - end - - private - - def check_permissions - if !allowed_to?(:add_payments) - render :file => "public/401.html.erb", :status => :unauthorized, :layout =>true - end - end - - def only_one_non_zero?( array ) - found_non_zero = false - array.each do |val| - if val!=0 - return false if found_non_zero - found_non_zero = true - end - end - found_non_zero - end - -end diff --git a/app/models/payment.rb b/app/models/payment.rb deleted file mode 100644 index b401b2f..0000000 --- a/app/models/payment.rb +++ /dev/null @@ -1,37 +0,0 @@ -#The MIT License (MIT) -# -#Copyright (c) 2020 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. - -class Payment - unloadable - - include ActiveModel::Model - - attr_accessor :errors, :customer_id, :account_id, :payment_method_id, :total_amount - validates_presence_of :customer_id, :account_id, :payment_method_id, :total_amount - validates :total_amount, numericality: true - - def save - payment = Quickbooks::Model::Payment.new - payment.customer_id = @customer_id.to_i - payment.deposit_to_account_id = @account_id.to_i - payment.payment_method_id = @payment_method_id.to_i - payment.total = @total_amount - Qbo.get_base(:payment).update(payment) - end - - def save! - save - end - - # Dummy stub to make validtions happy. - def update_attribute - end - -end diff --git a/app/models/qbo_item.rb b/app/models/qbo_item.rb deleted file mode 100644 index 123ca0f..0000000 --- a/app/models/qbo_item.rb +++ /dev/null @@ -1,47 +0,0 @@ -#The MIT License (MIT) -# -#Copyright (c) 2022 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. - -class QboItem < ActiveRecord::Base - unloadable - has_many :issues - #attr_accessible :name - validates_presence_of :id, :name - - self.primary_key = :id - - def self.get_base - Qbo.get_base(:item) - end - - def self.sync - last = Qbo.first.last_sync - - query = "SELECT Id, Name FROM Item WHERE Type = 'Service' " - query << " AND Metadata.LastUpdatedTime >= '#{last.iso8601}' " if last - - if count == 0 - items = get_base.all - else - items = get_base.query(query) - end - - unless items.count = 0 - items.find_by(:type, "Service").each { |i| - qbo_item = QboItem.find_or_create_by(id: i.id) - qbo_item.name = i.name - qbo_item.id = i.id - qbo_item.save - } - end - -# QboItem.where.not(items.map(&:id)).destroy_all - end - -end diff --git a/app/models/qbo_purchase.rb b/app/models/qbo_purchase.rb deleted file mode 100644 index aee8ede..0000000 --- a/app/models/qbo_purchase.rb +++ /dev/null @@ -1,47 +0,0 @@ -#The MIT License (MIT) -# -#Copyright (c) 2022 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. - -class QboPurchase < ActiveRecord::Base - unloadable - belongs_to :issues - belongs_to :qbo_customer - #attr_accessible :description - validates_presence_of :id, :line_id, :description, :qbo_customer_id - - def self.get_base - Qbo.get_base(:purchase) - end - - def get_purchase(id) - get_base.find_by_id(id) - end - - def self.sync - QboPurchase.get_base.all.each { |purchase| - - purchase.line_items.all? { |line_item| - - detail = line_item.account_based_expense_line_detail ? line_item.account_based_expense_line_detail : line_item.item_based_expense_line_detail - - if detail.billable_status = "Billable" - qbo_purchase = find_or_create_by(id: purchase.id) - qbo_purchase.line_id = line_item.id - qbo_purchase.description = line_item.description - qbo_purchase.qbo_customer_id = detail.customer_ref - - #TODO attach to issues - #qbo_purchase.issue_id = Issue.find_by_invoice() - - qbo_purchase.save - end - } - } - end -end diff --git a/app/views/payments/_form.html.erb b/app/views/payments/_form.html.erb deleted file mode 100644 index b229889..0000000 --- a/app/views/payments/_form.html.erb +++ /dev/null @@ -1,42 +0,0 @@ -
-
-
- - <%= form_for @payment do |f| %> - -
- <%=t(:field_customer)%>: -
- <%= f.collection_select :customer_id, @customers, :id, :name, include_blank: true, :selected => @customer, :required => true%> -
-
- -
- <%=t(:label_deposit_into)%>: -
- <%= f.collection_select :account_id, @accounts, :id, :name, include_blank: true, :selected => @account, :required => true%> -
-
- -
- <%=t(:label_payment_method)%>: -
- <%= f.collection_select :payment_method_id, @payment_methods, :id, :name, include_blank: true, :selected => @payment_method, :required => true%> -
-
- -
- <%=t(:label_amount)%>: -
- <%= f.number_field :total_amount %> -
-
- -
- <%= f.submit %> -
- <% end %> - -
-
-
diff --git a/app/views/payments/new.html.erb b/app/views/payments/new.html.erb deleted file mode 100644 index 1745d20..0000000 --- a/app/views/payments/new.html.erb +++ /dev/null @@ -1,3 +0,0 @@ -

<%=t(:label_new_payment)%>

-
-<%= render :partial => 'payments/form' %> diff --git a/app/models/line_item.rb b/db/migrate/034_remove_qbo_items.rb similarity index 63% rename from app/models/line_item.rb rename to db/migrate/034_remove_qbo_items.rb index 5eaed60..ac8ea7e 100644 --- a/app/models/line_item.rb +++ b/db/migrate/034_remove_qbo_items.rb @@ -8,27 +8,10 @@ # #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. -class LineItem < ActiveRecord::Base - - unloadable - - belongs_to :issue - - #attr_accessible :amount, :description, :unit_price, :quantity, :item_id - validates_presence_of :amount, :description, :unit_price, :quantity - - def add_to_invoice(invoice) - line_item = Quickbooks::Model::InvoiceLineItem.new - line_item.amount = amount - line_item.description = description - line_item.sales_item! do |detail| - detail.unit_price = unit_price - detail.quantity = quantity - detail.item_id = item_id # Item ID here... Where do i get this??? - end - - invoice.line_items << line_item - - return invoice +class RemoveQboItems < ActiveRecord::Migration[5.1] + def change + drop_table :qbo_items + drop_table :qbo_purchases + drop_table :line_items end end