diff --git a/app/controllers/invoice_controller.rb b/app/controllers/invoice_controller.rb index 6bf1e4b..d5a93b8 100644 --- a/app/controllers/invoice_controller.rb +++ b/app/controllers/invoice_controller.rb @@ -21,10 +21,10 @@ class InvoiceController < ApplicationController def show begin qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + @pdf = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) invoice = service.fetch_by_id(params[:id]) - @pdf = service.pdf(invoice) + service.pdf(invoice) end return unless @pdf diff --git a/app/models/customer.rb b/app/models/customer.rb index 04dc6fe..4ce883c 100644 --- a/app/models/customer.rb +++ b/app/models/customer.rb @@ -144,9 +144,9 @@ class Customer < ActiveRecord::Base def self.sync # Sync ALL customers if the database is empty qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + customers = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) - customers = service.all + service.all end return unless customers @@ -178,9 +178,9 @@ class Customer < ActiveRecord::Base # This needs to be simplified def self.sync_by_id(id) qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + customer = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) - customer = service.fetch_by_id(id) + service.fetch_by_id(id) end return unless customer @@ -203,9 +203,9 @@ class Customer < ActiveRecord::Base def save_with_push begin qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + @details = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) - @details = serivce.update(@details) + serivce.update(@details) end #raise "QBO Fault" if @details.fault? self.id = @details.id @@ -225,9 +225,9 @@ class Customer < ActiveRecord::Base begin raise Exception unless self.id qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + @details = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Customer.new(:company_id => qbo.realm_id, :access_token => access_token) - @details = bservice.ase.fetch_by_id(self.id) + bservice.ase.fetch_by_id(self.id) end rescue Exception => e @details = Quickbooks::Model::Customer.new diff --git a/app/models/employee.rb b/app/models/employee.rb index 54c23ea..acf6702 100644 --- a/app/models/employee.rb +++ b/app/models/employee.rb @@ -15,9 +15,9 @@ class Employee < ActiveRecord::Base def self.sync qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + employees = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token) - employees = service.all + service.all end return unless employees @@ -36,9 +36,9 @@ class Employee < ActiveRecord::Base def self.sync_by_id(id) qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + employee = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Employee.new(:company_id => qbo.realm_id, :access_token => access_token) - employee = service.fetch_by_id(id) + service.fetch_by_id(id) end return unless employee diff --git a/app/models/estimate.rb b/app/models/estimate.rb index 641ff39..00410d7 100644 --- a/app/models/estimate.rb +++ b/app/models/estimate.rb @@ -20,9 +20,9 @@ class Estimate < ActiveRecord::Base def self.sync logger.debug "Syncing ALL estimates" qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + estimates = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) - estimates = service.all + service.all end return unless estimates @@ -79,7 +79,7 @@ class Estimate < ActiveRecord::Base qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) estimate = service.fetch_by_id(id) - return service.pdf(estimate) + service.pdf(estimate) end end @@ -108,9 +108,9 @@ class Estimate < ActiveRecord::Base begin raise Exception unless self.id qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + @details = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Estimate.new(:company_id => qbo.realm_id, :access_token => access_token) - @details = service(:estimate).fetch_by_id(self.id) + service(:estimate).fetch_by_id(self.id) end rescue Exception => e @details = Quickbooks::Model::Estimate.new diff --git a/app/models/invoice.rb b/app/models/invoice.rb index 4b6d570..f66d1e8 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -26,13 +26,9 @@ class Invoice < ActiveRecord::Base # TODO actually do something with the above query # .all() is never called since count is never initialized qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + invoices = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) - if count == 0 - invoices = service.all - else - invoices = service.query() - end + service.all end return unless invoices @@ -197,9 +193,9 @@ class Invoice < ActiveRecord::Base begin raise Exception unless self.id qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + @details = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) - @details = service.fetch_by_id(self.id) + service.fetch_by_id(self.id) end rescue Exception => e @details = Quickbooks::Model::Invoice.new diff --git a/db/migrate/032_add_txn_dates.rb b/db/migrate/032_add_txn_dates.rb index 5e1a68d..8379d79 100644 --- a/db/migrate/032_add_txn_dates.rb +++ b/db/migrate/032_add_txn_dates.rb @@ -27,9 +27,9 @@ class AddTxnDates < ActiveRecord::Migration[5.1] say "Sync Invoices" qbo = Qbo.first - qbo.perform_authenticated_request do |access_token| + invoices = qbo.perform_authenticated_request do |access_token| service = Quickbooks::Service::Invoice.new(:company_id => qbo.realm_id, :access_token => access_token) - invoices = service.all + service.all end return unless invoices