ruckus / quickbooks-ruby

Quickbooks Online REST API V3 - Ruby
MIT License
374 stars 302 forks source link

Unable to Apply TaxRate to Quickbooks Invoice #262

Closed kashif-umair closed 9 years ago

kashif-umair commented 9 years ago

Hi, I'm using this gem to integrate quickbooks with my product. I'm able to sync invoice and it's line items to quickbooks and I've also figured out a way that how to apply tax code on invoice line items but I'm facing an issue when I try to apply tax rate to a quickbooks invoice. Can anyone please guide me to some tutorial or help me by telling me about what methods I should use to apply the tax-rate.

minimul commented 9 years ago

Is this for a U.S. invoice?

kashif-umair commented 9 years ago

Yes, I'm using to sandbox account to test out things and the quickbooks company is U.S.

minimul commented 9 years ago

I'll look like this (not tested). Tax rate goes in "header" as txn_tax_detail


module Qbo
  class Invoice

    def build
      qb_invoice = Quickbooks::Model::Invoice.new
      qb_invoice.customer_ref = set_customer
      qb_invoice.txn_tax_detail = set_transaction_tax
      qb_invoice.line_items << set_sales
      qb_invoice
    end

    def set_customer
      qb_customer = Quickbooks::Model::BaseReference.new(5)
      qb_customer.name = "Dukes Basketball Camp"
      qb_customer
    end

    def set_transaction_tax
      transaction = Quickbooks::Model::TransactionTaxDetail.new
      transaction.txn_tax_code_id = 4 # TaxRate e.g. "Sales Tax" in sandbox
      transaction
    end

    def set_sales
      sales = Quickbooks::Model::InvoiceLineItem.new
      unit_price = 55.5
      sales.amount = (unit_price.to_f * 3).round(2)
      sales.description = 'Concrete'
      sales.sales_item! do |detail|
        detail.unit_price = unit_price
        detail.quantity = 3
        detail.item_ref = 3 # Concrete in sandbox
        detail.rate_percent = 0
        detail.tax_code_id = 'TAX'
      end
      sales
    end

  end
end
kashif-umair commented 9 years ago

That's exactly what I needed. Thanks for quick response and detailed answer :+1: You can close this now.

vanboom commented 9 years ago

Could you elaborate please on how the TransactionTaxDetail works? I am struggling to get sales tax applied to my invoices also. In the above example, transaction.txn_tax_code_id = 4, where did '4' come from?

thanks!

minimul commented 9 years ago

4 is a TaxRate from the sandbox. Also, the above example is for a US invoice. The detail.tax_code_id = 'TAX' is a TaxCode. If you want to go in-depth: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/global_tax_model

markixnim commented 9 years ago

Thanks Christian for your helpful responses.

In my application, users can apply any tax rate they want to an invoice, we don't have specific tax codes. I understand while you can define different tax_codes in Quickbooks for various regions, you can also override the tax amount directly. I am wondering if it's ok to apply a generic tax code for all invoices, and override the tax_amount for each invoice. Love to hear your thoughts around this.

Thanks!

minimul commented 9 years ago

Is it for non-US? Read this for overriding: https://developer.intuit.com/docs/0100_accounting/0300_developer_guides/global_tax_model/non-us_sales_tax_integrations#/Overriding_Purchase_Tax

On Sat, Nov 7, 2015 at 3:11 AM, markixnim notifications@github.com wrote:

Thanks Christian for your helpful responses.

In my application, users can apply any tax rate they want to an invoice, we don't have specific tax codes. I understand while you can define different tax_codes in Quickbooks for various regions, you can also override the tax amount directly. I am wondering if it's ok to apply a generic tax code for all invoices, and override the tax_amount for each invoice. Love to hear your thoughts around this.

Thanks!

— Reply to this email directly or view it on GitHub https://github.com/ruckus/quickbooks-ruby/issues/262#issuecomment-154653549 .

markixnim commented 9 years ago

Thanks Christian.

We are using the US version so here is the portion of the code for overriding:

"TxnTaxDetail": { "TxnTaxCodeRef": { "value": "3", "name": "Tucson" }, "TotalTax": 9.5 },

In this case, should we create a generic TaxCode and override the tax amount for each invoice?

minimul commented 9 years ago

Yes, that is how you would override in a US invoice.

Personally, I would not create a TaxCode on your client's QBO. I would import their codes and reference them while adding the TotalTax.

If you do create a generic TaxCode make sure you name it well so they and their accountant know what it is e.g. "Killer App Generic Tax Code".

On Mon, Nov 9, 2015 at 5:41 PM, markixnim notifications@github.com wrote:

Thanks Christian.

We are using the US version so here is the portion of the code for overriding:

"TxnTaxDetail": { "TxnTaxCodeRef": { "value": "3", "name": "Tucson" }, "TotalTax": 9.5 },

In this case, should we create a generic TaxCode and override the tax amount for each invoice?

— Reply to this email directly or view it on GitHub https://github.com/ruckus/quickbooks-ruby/issues/262#issuecomment-155221936 .