From 3e86d5fdab53085031c9fc481f89720b300e78e9 Mon Sep 17 00:00:00 2001 From: Tung Le Date: Thu, 11 Dec 2025 21:49:28 +0700 Subject: [PATCH 1/7] Fix bug download title and invoice download --- app/controllers/kaui/invoices_controller.rb | 9 +++++++++ .../kaui/account_timelines/_multi_functions_bar.html.erb | 2 +- app/views/kaui/audit_logs/_multi_functions_bar.html.erb | 2 +- app/views/kaui/invoices/_multi_functions_bar.html.erb | 2 +- app/views/kaui/payments/_multi_functions_bar.html.erb | 2 +- 5 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/controllers/kaui/invoices_controller.rb b/app/controllers/kaui/invoices_controller.rb index 64068f71..9eedcf5c 100644 --- a/app/controllers/kaui/invoices_controller.rb +++ b/app/controllers/kaui/invoices_controller.rb @@ -35,6 +35,15 @@ def download else Kaui::Invoice.list_or_search(query_string, 0, MAXIMUM_NUMBER_OF_RECORDS_DOWNLOAD, options_for_klient.merge(params: kb_params)) end + + if start_date && end_date + invoices = invoices.select do |invoice| + start_date_parsed = Date.parse(start_date) + end_date_parsed = Date.parse(end_date) + invoice_date = Date.parse(invoice.invoice_date) + invoice_date >= start_date_parsed && invoice_date <= end_date_parsed + end + end csv_string = CSV.generate(headers: true) do |csv| csv << columns diff --git a/app/views/kaui/account_timelines/_multi_functions_bar.html.erb b/app/views/kaui/account_timelines/_multi_functions_bar.html.erb index 84a84851..8a8aa327 100644 --- a/app/views/kaui/account_timelines/_multi_functions_bar.html.erb +++ b/app/views/kaui/account_timelines/_multi_functions_bar.html.erb @@ -43,7 +43,7 @@ - +
diff --git a/app/views/kaui/audit_logs/_multi_functions_bar.html.erb b/app/views/kaui/audit_logs/_multi_functions_bar.html.erb index b3ec6c2d..787fdee2 100644 --- a/app/views/kaui/audit_logs/_multi_functions_bar.html.erb +++ b/app/views/kaui/audit_logs/_multi_functions_bar.html.erb @@ -43,7 +43,7 @@ - +
diff --git a/app/views/kaui/invoices/_multi_functions_bar.html.erb b/app/views/kaui/invoices/_multi_functions_bar.html.erb index 9a6601b4..67a20a73 100644 --- a/app/views/kaui/invoices/_multi_functions_bar.html.erb +++ b/app/views/kaui/invoices/_multi_functions_bar.html.erb @@ -91,7 +91,7 @@ - +
diff --git a/app/views/kaui/payments/_multi_functions_bar.html.erb b/app/views/kaui/payments/_multi_functions_bar.html.erb index 3bf24c5b..dda23a2c 100644 --- a/app/views/kaui/payments/_multi_functions_bar.html.erb +++ b/app/views/kaui/payments/_multi_functions_bar.html.erb @@ -90,7 +90,7 @@ - +
From efbff930f7fde8697fbdf762c684aeb1a1b95583 Mon Sep 17 00:00:00 2001 From: Tung Le Date: Sat, 13 Dec 2025 09:27:14 +0700 Subject: [PATCH 2/7] Fix bug cannot delete user --- .../kaui/admin_allowed_users/index.html.erb | 23 ++++++------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/app/views/kaui/admin_allowed_users/index.html.erb b/app/views/kaui/admin_allowed_users/index.html.erb index ca227208..024adc82 100644 --- a/app/views/kaui/admin_allowed_users/index.html.erb +++ b/app/views/kaui/admin_allowed_users/index.html.erb @@ -60,22 +60,11 @@ <%= link_to u.kb_username, admin_allowed_user_path(u.id) %> <%= u.description %> - - - <%= render "kaui/components/button/button", { - label: 'Delete', - variant: "outline-secondary d-inline-flex align-items-center gap-1", - type: "button", - html_class: "kaui-button delete-button custom-hover", - html_options: { - data: { - confirm: "Are you sure?", - method: "delete", - turbo: false, - "url": kaui_engine.admin_allowed_user_path(u.id) - } - } - } %> + <%= form_tag kaui_engine.admin_allowed_user_path(u.id), method: :delete, style: 'display: inline;', onsubmit: "return confirm('Are you sure?');" do %> + <%= button_tag type: 'submit', class: 'btn btn-outline-secondary d-inline-flex align-items-center gap-1 kaui-button delete-button custom-hover', style: 'border: none; background: none; padding: 0;' do %> + Delete + <% end %> + <% end %> <%= link_to kaui_engine.edit_admin_allowed_user_path(u.id), :class => '' do %> <%= render "kaui/components/button/button", { label: "Edit", @@ -154,6 +143,8 @@ $header.find('.sort-' + direction).addClass('active'); } + } catch (e) { + console.error('Error initializing DataTable:', e); } }, 100); }); From bbf839388d36031833d04e27b03c01d39950f123 Mon Sep 17 00:00:00 2001 From: Tung Le Date: Sat, 13 Dec 2025 20:17:31 +0700 Subject: [PATCH 3/7] Validate catalog --- .../kaui/admin_tenants/new_catalog.html.erb | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/app/views/kaui/admin_tenants/new_catalog.html.erb b/app/views/kaui/admin_tenants/new_catalog.html.erb index 2a0a4081..3e4487ff 100644 --- a/app/views/kaui/admin_tenants/new_catalog.html.erb +++ b/app/views/kaui/admin_tenants/new_catalog.html.erb @@ -246,6 +246,8 @@ function switch_basic_config() { $(document).ready(function() { switch_basic_config(); + // jQuery UI autocomplete interferes with HTML5 validation + // So we keep the custom JS validation $('#simple_plan_product_name').autocomplete({ source: function(query, process) { process(known_products()); @@ -261,8 +263,72 @@ $(document).ready(function() { $('#simple_plan_product_name').on('mouseleave', function() { recompute_available_base_products_for_ao(); }); + + // Custom validation since HTML5 validation is not working + // (possibly due to jQuery autocomplete or other JavaScript interference) + $('#catalog_simple form').on('submit', function(e) { + var isValid = true; + var pattern = /^[a-zA-Z_][\w\.-]*$/; + + // Validate Product Name + var productName = $('#simple_plan_product_name').val().trim(); + var productNameField = $('#simple_plan_product_name'); + + if (productName === '') { + showError(productNameField, 'Product Name is required'); + isValid = false; + } else if (!pattern.test(productName)) { + showError(productNameField, 'Product Name must start with a letter or underscore, and can only contain letters, digits, underscores, hyphens, and periods'); + isValid = false; + } else { + clearError(productNameField); + } + + // Validate Plan Name + var planName = $('#simple_plan_plan_id').val().trim(); + var planNameField = $('#simple_plan_plan_id'); + + if (planName === '') { + showError(planNameField, 'Plan Name is required'); + isValid = false; + } else if (!pattern.test(planName)) { + showError(planNameField, 'Plan Name must start with a letter or underscore, and can only contain letters, digits, underscores, hyphens, and periods'); + isValid = false; + } else { + clearError(planNameField); + } + + if (!isValid) { + e.preventDefault(); + e.stopPropagation(); + // Scroll to first error + $('.error-message:first').get(0)?.scrollIntoView({ behavior: 'smooth', block: 'center' }); + return false; + } + + return true; + }); + + // Clear errors on input + $('#simple_plan_product_name, #simple_plan_plan_id').on('input', function() { + clearError($(this)); + }); }); +function showError(field, message) { + clearError(field); + field.addClass('error-field'); + field.css('border-color', '#dc3545'); + var errorDiv = $('
').text(message); + field.parent().append(errorDiv); +} + +function clearError(field) { + field.removeClass('error-field'); + field.css('border-color', ''); + field.parent().find('.error-message').remove(); +} + document.querySelectorAll('.toggle-option').forEach(el => { el.addEventListener('click', () => { document.querySelectorAll('.toggle-option').forEach(opt => opt.classList.remove('active-btn')); From 22c450d05ad7290f5ba8d37683188e7f1d0fc4d3 Mon Sep 17 00:00:00 2001 From: Tung Le Date: Sun, 14 Dec 2025 20:08:32 +0700 Subject: [PATCH 4/7] Handle count number too large --- app/controllers/kaui/home_controller.rb | 2 +- app/views/kaui/components/dashboard/_card.html.erb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/kaui/home_controller.rb b/app/controllers/kaui/home_controller.rb index 7960454c..66090764 100644 --- a/app/controllers/kaui/home_controller.rb +++ b/app/controllers/kaui/home_controller.rb @@ -14,7 +14,7 @@ def index @max_records = {} %w[account payment invoice].each do |type| model = "Kaui::#{type.capitalize}".constantize - @max_records[type.to_sym] = model.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records || 0 + @max_records[type.to_sym] = model.list_or_search(nil, 0, 0, options_for_klient).pagination_max_nb_records end end diff --git a/app/views/kaui/components/dashboard/_card.html.erb b/app/views/kaui/components/dashboard/_card.html.erb index 18c0ff1b..a4bc816d 100644 --- a/app/views/kaui/components/dashboard/_card.html.erb +++ b/app/views/kaui/components/dashboard/_card.html.erb @@ -1,3 +1,4 @@ +<% count_text = count.nil? ? "20k+" : count.to_i %>
@@ -6,7 +7,7 @@
<%= title %>
-

<%= count %>

+

<%= count_text %>

From 7b20d982814edda98071512bdbe6da09d108bebf Mon Sep 17 00:00:00 2001 From: Tung Le Date: Sun, 14 Dec 2025 23:26:21 +0700 Subject: [PATCH 5/7] Handle non-official aviate versions --- app/helpers/kaui/plugin_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/helpers/kaui/plugin_helper.rb b/app/helpers/kaui/plugin_helper.rb index 9ba28384..b742699d 100644 --- a/app/helpers/kaui/plugin_helper.rb +++ b/app/helpers/kaui/plugin_helper.rb @@ -24,6 +24,8 @@ def installed_plugin_names '/kenui' when /payment-test/ '/payment_test' + when /aviate/ + '/aviate' else "/#{plugin_key}" end From 113be91a52793ca4791a065e5ffd6894843af907 Mon Sep 17 00:00:00 2001 From: Tung Le Date: Sun, 14 Dec 2025 23:31:04 +0700 Subject: [PATCH 6/7] Show Next invoice date --- app/views/kaui/accounts/_billing_details.html.erb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/views/kaui/accounts/_billing_details.html.erb b/app/views/kaui/accounts/_billing_details.html.erb index b3dd3a9f..e9c8d684 100644 --- a/app/views/kaui/accounts/_billing_details.html.erb +++ b/app/views/kaui/accounts/_billing_details.html.erb @@ -117,12 +117,10 @@ <% end %>
- <% if can? :trigger, Kaui::Invoice %> -
- Next invoice date -

N/A

-
- <% end %> +
+ Next invoice date +

N/A

+
From 8afa545df1ced3d05a013d7dd56afc438a985e48 Mon Sep 17 00:00:00 2001 From: Tung Le Date: Sun, 14 Dec 2025 23:34:13 +0700 Subject: [PATCH 7/7] Code refactor --- app/controllers/kaui/invoices_controller.rb | 16 ++++++++-------- .../kaui/admin_allowed_users/index.html.erb | 6 +++--- test/dummy/config/initializers/money.rb | 1 + 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/controllers/kaui/invoices_controller.rb b/app/controllers/kaui/invoices_controller.rb index 9eedcf5c..4172ceb4 100644 --- a/app/controllers/kaui/invoices_controller.rb +++ b/app/controllers/kaui/invoices_controller.rb @@ -35,15 +35,15 @@ def download else Kaui::Invoice.list_or_search(query_string, 0, MAXIMUM_NUMBER_OF_RECORDS_DOWNLOAD, options_for_klient.merge(params: kb_params)) end - - if start_date && end_date - invoices = invoices.select do |invoice| - start_date_parsed = Date.parse(start_date) - end_date_parsed = Date.parse(end_date) - invoice_date = Date.parse(invoice.invoice_date) - invoice_date >= start_date_parsed && invoice_date <= end_date_parsed - end + + if start_date && end_date + invoices = invoices.select do |invoice| + start_date_parsed = Date.parse(start_date) + end_date_parsed = Date.parse(end_date) + invoice_date = Date.parse(invoice.invoice_date) + invoice_date.between?(start_date_parsed, end_date_parsed) end + end csv_string = CSV.generate(headers: true) do |csv| csv << columns diff --git a/app/views/kaui/admin_allowed_users/index.html.erb b/app/views/kaui/admin_allowed_users/index.html.erb index 024adc82..85de7f78 100644 --- a/app/views/kaui/admin_allowed_users/index.html.erb +++ b/app/views/kaui/admin_allowed_users/index.html.erb @@ -60,12 +60,12 @@ <%= link_to u.kb_username, admin_allowed_user_path(u.id) %> <%= u.description %> - <%= form_tag kaui_engine.admin_allowed_user_path(u.id), method: :delete, style: 'display: inline;', onsubmit: "return confirm('Are you sure?');" do %> - <%= button_tag type: 'submit', class: 'btn btn-outline-secondary d-inline-flex align-items-center gap-1 kaui-button delete-button custom-hover', style: 'border: none; background: none; padding: 0;' do %> + <%= form_tag kaui_engine.admin_allowed_user_path(u.id), method: :delete, class: 'd-inline', onsubmit: "return confirm('Are you sure?');" do %> + <%= button_tag type: 'submit', class: 'btn btn-outline-secondary d-inline-flex align-items-center gap-1 kaui-button delete-button custom-hover' do %> Delete <% end %> <% end %> - <%= link_to kaui_engine.edit_admin_allowed_user_path(u.id), :class => '' do %> + <%= link_to kaui_engine.edit_admin_allowed_user_path(u.id), class: 'text-decoration-none' do %> <%= render "kaui/components/button/button", { label: "Edit", variant: "outline-secondary d-inline-flex align-items-center gap-1", diff --git a/test/dummy/config/initializers/money.rb b/test/dummy/config/initializers/money.rb index 9b0921fb..d727180f 100644 --- a/test/dummy/config/initializers/money.rb +++ b/test/dummy/config/initializers/money.rb @@ -1,2 +1,3 @@ Money.locale_backend = :currency Money.rounding_mode = BigDecimal::ROUND_HALF_UP +Money.default_currency = 'USD'