diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb index db22345..f9a9009 100644 --- a/app/controllers/accounts_controller.rb +++ b/app/controllers/accounts_controller.rb @@ -19,4 +19,9 @@ class AccountsController < ApplicationController account.update(default: true) redirect_to accounts_path, notice: "Default account updated." end + + def sync + Account.sync + redirect_to :home, flash: { notice: I18n.t(:label_syncing) } + end end \ No newline at end of file diff --git a/app/models/account.rb b/app/models/account.rb index 15b613b..1aef2a5 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -28,6 +28,10 @@ class Account < QboBaseModel return r end + def to_s + name + end + private def clear_other_defaults diff --git a/app/views/accounts/index.html.erb b/app/views/accounts/index.html.erb index 90750b5..c476dd5 100644 --- a/app/views/accounts/index.html.erb +++ b/app/views/accounts/index.html.erb @@ -1,39 +1,37 @@ -
| Default | -Name | -Description | -Classification | -Active | -|||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| - <%= radio_button_tag "default_account_id", account.id, account.default %> - | -<%= account.name %> | -<%= account.description %> | -<%= account.classification %> | -- <%= account.active ? "Yes" : "No" %> - | +<%= form_tag set_default_accounts_path, method: :patch do %> +|||||||||||||||
| <%= l(:label_default) %> | +<%= l(:field_name) %> | +<%= l(:field_description) %> | +<%= l(:field_classification) %> | +<%= l(:field_active) %> |
|---|---|---|---|---|
| - <%= submit_tag "Save Default Account", style: "padding: 6px 12px; font-weight: bold;" %> - | -||||
+ <%= f.text_field :name, required: true, size: 60 %> +
-| <%= f.label :name %> | -<%= f.text_field :name, required: true, style: "width: 100%;" %> | -
| <%= f.label :sku %> | -<%= f.text_field :sku, style: "width: 100%;" %> | -
| <%= f.label :description %> | -<%= f.text_area :description, rows: 3, style: "width: 100%;" %> | -
| <%= f.label :unit_price %> | -<%= f.number_field :unit_price, step: 0.01, style: "width: 100%;" %> | -
| <%= f.label :taxable %> | -- <%= f.check_box :taxable %> - | -
| <%= f.label :account %> | -- <%= f.collection_select :account_id, - Account.where(classification: 'Revenue').order(:name), - :id, - :name, - { selected: @item.account_id || Account.get_default&.id }, - { include_blank: true, style: "width: 100%;" } %> - | -
| <%= f.label :type %> | -- <%= f.select :type, - Quickbooks::Model::Item::ITEM_TYPES.map { |t| [t, t] }, - { selected: @item.type || Quickbooks::Model::Item::NON_INVENTORY_TYPE }, - { style: "width: 100%;" } %> - | -
| <%= f.label :active %> | -<%= f.check_box :active %> | -
- <%= f.submit "Save Item", style: "padding: 6px 12px; font-weight: bold;" %> -
++ <%= f.check_box :active %> +
+| Name | -SKU | -Description | -Price | -Active | -- |
|---|---|---|---|---|---|
| <%= link_to item.name, item_path(item) %> | -<%= item.sku %> | -<%= item.description %> | -<%= number_to_currency(item.unit_price) %> | -<%= item.active ? "Yes" : "No" %> | -- <%= link_to "Edit", edit_item_path(item), class: "icon icon-edit" %> - <%= link_to "Delete", item_path(item), - method: :delete, - data: { confirm: "Are you sure?" }, - class: "icon icon-del" %> - | -
| <%= l(:field_name) %> | +<%= l(:field_sku) %> | +<%= l(:field_description) %> | +<%= l(:field_unit_price) %> | +<%= l(:field_taxable) %> | +<%= l(:field_active) %> | ++ |
|---|---|---|---|---|---|---|
| <%= link_to item.name, item_path(item) %> | +<%= item.sku %> | +<%= truncate(item.description, length: 60) %> | +<%= number_to_currency(item.unit_price) %> | ++ <%= item.taxable ? content_tag(:span, '', class: 'icon icon-ok') : "" %> + | ++ <%= checked_image item.active %> + | ++ <%= link_to l(:button_edit), edit_item_path(item), class: 'icon icon-edit' %> + <%= link_to l(:button_delete), item_path(item), + method: :delete, + data: { confirm: l(:text_are_you_sure) }, + class: 'icon icon-del' %> + | +
<%= l(:label_no_data) %>
+<% end %> \ No newline at end of file diff --git a/app/views/items/show.html.erb b/app/views/items/show.html.erb index 61f559b..be2015a 100644 --- a/app/views/items/show.html.erb +++ b/app/views/items/show.html.erb @@ -1,35 +1,44 @@ -| SKU: | -<%= @item.sku.presence || "-" %> | -
| Description: | -<%= @item.description.presence || "-" %> | -
| Unit Price: | -<%= number_to_currency(@item.unit_price) %> | -
| Type: | -<%= @item.type.presence || "-" %> | -
| Account: | -<%= @item.account&.name || "-" %> | -
| Active: | -<%= @item.active ? "Yes" : "No" %> | -
SKU: <%= @item.sku.presence || "-" %>
+Type: <%= @item.type.presence || "-" %>
+Unit Price: <%= number_to_currency(@item.unit_price) %>
+Account: <%= @item.account&.name || "-" %>
++ Taxable: + <% if @item.taxable %> + Yes + <% else %> + No + <% end %> +
++ Active: + <% if @item.active %> + Yes + <% else %> + No + <% end %> +
+Description:
++ + <%= Item.count %> + + (@ <%= Item.last_sync %>) + +
++ + <%= Account.count %> + + (@ <%= Account.last_sync %>) + +
++ + <%= Qbo.exists? ? Qbo.last_sync : 'Never synced' %> +
++ + <%= Account.get_default %> +