%h2.effective-qb-sync-page-title= @page_title

%h3 1. Create a Quickbooks user for sync

%p The Quickbooks web connector requires a user be created for synchronization.

%ul
  %li
    Open the Quickbooks Pro company file that will be synchronized with the website
  %li
    Click Company -> Set up Users and Passwords -> Set Up Users...
    - if EffectiveQbSync.quickbooks_username.present? && EffectiveQbSync.quickbooks_password.present?
      %li
        Add a Quickbooks user with username:
        %strong= Array(EffectiveQbSync.quickbooks_username).join('</strong> or <strong>').html_safe
        and password:
        %strong= Array(EffectiveQbSync.quickbooks_password).join('</strong> or <strong>').html_safe
    - elsif EffectiveQbSync.quickbooks_username.blank? && EffectiveQbSync.quickbooks_password.present?
      %li
        Add a Quickbooks user any username, and password:
        %strong= Array(EffectiveQbSync.quickbooks_password).join('</strong> or <strong>').html_safe
    - else
      %li
        (developer) Add a quickbooks_username and quickbooks_password to the config/initializers/effective_qb_sync.rb file
        %ul
          %li Add a Quickbooks user with that same username and password

    %li Access for user: "Selected areas of Quickbooks"
    %li Sales and Accounts Receivable "Selective Access - Create transactions only"
    %li Purchases and Accounts Payable "No Access"
    %li Chequing and Credit Cards "No Access"
    %li Time Tracking "No Access"
    %li Payroll and Employees "No Access"
    %li Sales Tax "No Access"
    %li Sensitive Accounting Activities "No Access"
    %li Sensitive Financial Reporting "No Access"
    %li Changing or Deleting Transactions "Yes" and "No"
    %li Finished

%h3 2. Create all Quickbooks items

%p
  Each acts_as_purchasable object on the website has a qb_item_name that must match an existing Quickbooks Item.
  %br
  The website's price will override any Quickbooks default item prices.

%p Make sure a Quickbooks Item exists for each of the following:
= render partial: '/admin/qb_syncs/qb_item_names'

%p To add an Item in Quickbooks:

%ul
  %li Click the menu bar Lists -> Item List
  %li In the bottom left, Item -> New
  %li Make sure the "Item Name/Number" matches with above.

%h3 3. Configure the Quickbooks Sales Tax Behaviour

%p Quickbooks sales tax can be configured in one of two ways:

%ul
  %li
    Sales tax should be added by Quickbooks
    %ul
      %li Click Edit -> Preferences -> Sales Tax -> Company Preferences
      %li Do you charge sales tax? Yes
      %li Add sales tax item...
      %li Set the config/initializers/effective_qb_sync.rb "quickbooks_tax_name" to an empty string
      %li When synchronizing, the website will not add in the tax amount
      %li Quickbooks will consider the order subtotal and add the appropriate tax amount

  %li
    Sales tax should be added by the website
    %ul
      %li Click Edit -> Preferences -> Sales Tax -> Company Preferences
      %li Do you charge sales tax? No
      %li Add a regular Quickbooks Item (as per 2. Create all Quickbooks items instructions, above)
      %li
        - if EffectiveQbSync.quickbooks_tax_name.present?
          Ensure that the Item Name in Quickbooks is
          %strong #{EffectiveQbSync.quickbooks_tax_name}
        - else
          (developer) Add a quickbooks_tax_name to the config/initializers/effective_qb_sync.rb file
      %li The website will add an additional line item with the tax amount.

%p
  Currently, the website is configured such that:
  %strong
    - if EffectiveQbSync.quickbooks_tax_name.present?
      Sales tax should be added by the website
    - else
      Sales tax should be added by Quickbooks


%h3 4. Configure the Quickbooks Web Connector

%p Now that the Quickbooks company file has been configured, it is time to set up the Quickbooks Web Connector program.

%ul
  %li
    Download the #{link_to 'quickbooks web connector .qwc file', (effective_qb_sync.qwc_admin_qb_syncs_path)} and put it somewhere safe
  %li
    Open the Quickbooks Web Connector program from the Start menu
    %ul
      %li Click Add an application
      %li Select the .qwc file just downloaded
      %li Click OK to add the new web service
      %li Select any of the 'Yes' options (Yes, always; allow access even if Quickbooks is not running is prefered) and Continue...
      %li Done
      %li
        If the .qwc file doesn't add properly, you can edit the .qwc file with wordpad, and check the following:
        %ul
          %li The AppID must be unique between all other .qwc files
          %li
            The AppURL must be an
            %strong https://
            url that ends with
            %strong= effective_qb_sync.qb_sync_path
            such as
            %strong https://myapp.herokuapp.com#{effective_qb_sync.qb_sync_path}
          %li The AppSupport url doesn't matter
          %li The UserName must be present and match an existing user
          %li The OwnerID and FileID values must also be unique between all other .qwc files
      %li Enter the password as above and Save it


%h3 5. Start the Synchronization

%p Everything is ready to go. Good luck with the first synchronization!

%ul
  %li Open the Quickbooks Web Connector
  %li Check the far left checkbox next to the new application
  %li Click Update Selected to do the sync
  %li (optional) or enable Auto-Run
  %li
    If any synchronization errors occur,
    %strong= EffectiveQbSync.error_email || EffectiveOrders.mailer[:admin_email]
    will receive an email with instructions on how to fix the error

%h3 6. Troubleshooting

%p
  Don't actually use this, but click below to skip all unsynced orders.

%ul
  %li This action will create a finished QbTicket containing all orders.
  %li All orders will be considered already synced, and will not be sent to QuickBooks again.
  %li You might need a developer's help to undo this.
  - unsynced = Effective::QbRequest.new_requests_for_unsynced_items.length
  %li= link_to "Mark all #{unsynced} unsynced orders as already synchronized", effective_qb_sync.set_all_orders_finished_admin_qb_syncs_path, 'data-method': :post, 'data-confirm': 'Are you sure?'