From 6bf5575f9c7b272d1b5069c9352af8f3d75f1222 Mon Sep 17 00:00:00 2001 From: Rick Barrette Date: Tue, 17 Mar 2026 19:18:03 -0400 Subject: [PATCH] Updated views for items and accounts --- app/controllers/accounts_controller.rb | 5 ++ app/models/account.rb | 4 + app/views/accounts/index.html.erb | 68 ++++++++-------- app/views/items/_form.html.erb | 103 +++++++++--------------- app/views/items/index.html.erb | 77 ++++++++++-------- app/views/items/show.html.erb | 73 +++++++++-------- app/views/line_items/_settings.html.erb | 43 ++++++++-- config/locales/en.yml | 13 +++ config/routes.rb | 1 + 9 files changed, 216 insertions(+), 171 deletions(-) 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 @@ -

Accounts

+

<%= l(:label_accounts) %>

-<%= form_with url: set_default_accounts_path, method: :patch, local: true do %> - - - - - - - - - - - - - <% @accounts.each_with_index do |account, index| %> - - - - - - +<%= form_tag set_default_accounts_path, method: :patch do %> +
+
DefaultNameDescriptionClassificationActive
- <%= radio_button_tag "default_account_id", account.id, account.default %> - <%= account.name %><%= account.description %><%= account.classification %> - <%= account.active ? "Yes" : "No" %> -
+ + + + + + + - <% end %> - + - - - - - -
<%= 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;" %> -
+ + <% @accounts.each do |account| %> + "> + + <%= radio_button_tag "default_account_id", account.id, account.default %> + + <%= account.name %> + <%= truncate(account.description, length: 80) %> + <%= account.classification %> + + <%= checked_image account.active %> + + + <% end %> + + + + +

+ <%= submit_tag l(:button_save), class: 'button-small' %> +

<% end %> \ No newline at end of file diff --git a/app/views/items/_form.html.erb b/app/views/items/_form.html.erb index 7bb3e90..2f82b56 100644 --- a/app/views/items/_form.html.erb +++ b/app/views/items/_form.html.erb @@ -1,76 +1,47 @@ -<%= form_with model: @item, local: true do |f| %> +<%= labelled_form_for @item do |f| %> + <%= error_messages_for 'item' %> - <% if @item.errors.any? %> -
-

<%= pluralize(@item.errors.count, "error") %> prohibited this item from being saved:

- -
- <% end %> +
+

+ <%= f.text_field :name, required: true, size: 60 %> +

- - - - - - +

+ <%= f.text_field :sku, size: 30 %> +

- - - - +

+ <%= f.text_area :description, rows: 4, class: 'wiki-edit' %> +

- - - - +

+ <%= f.number_field :unit_price, step: 0.01, size: 10 %> +

- - - - +

+ <%= f.check_box :taxable %> +

- - - - +

+ <%= f.label :account_id, l(: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 } %> +

- - - - +

+ <%= f.select :type, + Quickbooks::Model::Item::ITEM_TYPES.map { |t| [t, t] }, + { selected: @item.type || Quickbooks::Model::Item::NON_INVENTORY_TYPE } %> +

- - - - - - - - - - -
<%= 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 %> +

+
+ <%= submit_tag l(:button_save) %> + <%= link_to l(:button_cancel), items_path if controller.action_name == 'edit' %> <% end %> \ No newline at end of file diff --git a/app/views/items/index.html.erb b/app/views/items/index.html.erb index 0b884a8..d35186e 100644 --- a/app/views/items/index.html.erb +++ b/app/views/items/index.html.erb @@ -1,37 +1,48 @@ -

Items

-
- <%= link_to "New Item", new_item_path, class: "icon icon-add" %> + <%= link_to l(:label_item_new), new_item_path, class: 'icon icon-add' %>
- - - - - - - - - - - +

<%= l(:label_items) %>

- - <% @items.each do |item| %> - - - - - - - - - <% end %> - -
NameSKUDescriptionPriceActive
<%= 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" %> -
\ No newline at end of file +<% if @items.any? %> +
+ + + + + + + + + + + + + + <% @items.each do |item| %> + "> + + + + + + + + + <% end %> + +
<%= 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' %> +
+
+<% else %> +

<%= 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 @@ -

<%= @item.name %>

+
+ <%= link_to l(:button_edit), edit_item_path(@item), class: 'icon icon-edit' %> + <%= link_to l(:button_back), items_path, class: 'icon icon-list' %> +
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
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" %>
+

<%= t(:item) %># <%= @item.id %> <%= @item.name %>

-
- <%= link_to "Edit", edit_item_path(@item), class: "btn btn-primary", style: "margin-right: 8px;" %> - <%= link_to "Back", items_path, class: "btn btn-secondary" %> +
+
+
+

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.description.presence || "No description provided".html_safe %> +
+
\ No newline at end of file diff --git a/app/views/line_items/_settings.html.erb b/app/views/line_items/_settings.html.erb index 45c7220..c68479f 100644 --- a/app/views/line_items/_settings.html.erb +++ b/app/views/line_items/_settings.html.erb @@ -1,6 +1,39 @@ -
- <%=t(:label_item_count)%> <%= Item.count %> @ <%= Item.last_sync %> -
- <%=t(:label_last_sync)%> <%= Qbo.last_sync if Qbo.exists? %> +
+

+ + <%= Item.count %> + + (@ <%= Item.last_sync %>) + +

+

+ + <%= Account.count %> + + (@ <%= Account.last_sync %>) + +

+

+ + <%= Qbo.exists? ? Qbo.last_sync : 'Never synced' %> +

+

+ + <%= Account.get_default %> +

-<%= link_to t(:label_sync_now), sync_items_path %> \ No newline at end of file + +
+ Management & Synchronization + +
+ <%= link_to t(:label_sync_now_items), sync_items_path, class: 'button icon icon-reload' %> + <%= link_to t(:label_sync_now_accounts), sync_accounts_path, class: 'button icon icon-reload' %> +
+ +
+ <%= link_to t(:label_items), items_path, class: 'icon icon-list' %> + | + <%= link_to t(:label_accounts), accounts_path, class: 'icon icon-list' %> +
+
\ No newline at end of file diff --git a/config/locales/en.yml b/config/locales/en.yml index 90bf982..30f9fc7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -11,13 +11,26 @@ # English strings go here for Rails i18n # Usage I18n.t(:label) en: + field_classification: "Classification" + field_sku: "SKU" + field_taxable: "Taxable" + field_unit_price: "Unit Price" + + label_account: "Account" + label_accounts: "Accounts" + label_account_count: "Number of Accounts:" + label_default_account: "Default Item Income Account" label_description: "Description" label_item: "Item" label_item_count: "Item Count:" + label_items: "Items" label_line_items: "Line Items" label_price: "Unit Price" label_qty: "Quantity" label_remove: "Remove" + label_sync_now_accounts: "Sync Accounts" + label_sync_now_items: "Sync Items" label_total: "Total" + notice_added_from: "Added from issue #" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 2a02a82..7174538 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,5 +18,6 @@ end resources :accounts do collection do patch :set_default + get :sync end end \ No newline at end of file