diff --git a/app/controllers/admin/vouchers_controller.rb b/app/controllers/admin/vouchers_controller.rb new file mode 100644 index 0000000000..594c0b28da --- /dev/null +++ b/app/controllers/admin/vouchers_controller.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +module Admin + class VouchersController < ResourceController + + def new + @enterprise = Enterprise.find_by permalink: params[:enterprise_id] + end + end +end diff --git a/app/helpers/admin/enterprises_helper.rb b/app/helpers/admin/enterprises_helper.rb index e95f4589ed..42b532d56f 100644 --- a/app/helpers/admin/enterprises_helper.rb +++ b/app/helpers/admin/enterprises_helper.rb @@ -34,6 +34,7 @@ module Admin { name: 'shipping_methods', icon_class: "icon-truck", show: show_shipping_methods }, { name: 'payment_methods', icon_class: "icon-money", show: show_payment_methods }, { name: 'enterprise_fees', icon_class: "icon-tasks", show: show_enterprise_fees }, + { name: 'vouchers', icon_class: "icon-ticket", show: true }, { name: 'enterprise_permissions', icon_class: "icon-plug", show: true, href: admin_enterprise_relationships_path }, { name: 'inventory_settings', icon_class: "icon-list-ol", show: is_shop }, diff --git a/app/views/admin/enterprises/form/_vouchers.html.haml b/app/views/admin/enterprises/form/_vouchers.html.haml new file mode 100644 index 0000000000..843dc5e51a --- /dev/null +++ b/app/views/admin/enterprises/form/_vouchers.html.haml @@ -0,0 +1,33 @@ +.text-right + %a.button{ href: "#{new_admin_enterprise_voucher_path(@enterprise)}"} + = t('.add_new') +%br + +- if @enterprise.vouchers.present? + %table + %thead + %tr + %th= t('.voucher_code') + %th= t('.rate') + %th= t('.label') + %th= t('.purpose') + %th= t('.expiry') + %th= t('.use_limit') + %th= t('.customers') + %th= t('.net_value') + %tbody + - @enterprise.vouchers.each do |voucher| + %tr + %td= voucher.code + %td= voucher.rate + %td + %td + %td + %td + %td + %td + +- else + %p.text-center + = t('.no_voucher_yet') + diff --git a/app/views/admin/vouchers/new.html.haml b/app/views/admin/vouchers/new.html.haml new file mode 100644 index 0000000000..c62ed5acdc --- /dev/null +++ b/app/views/admin/vouchers/new.html.haml @@ -0,0 +1,22 @@ +.row + .sixteen.columns.alpha + .four.columns.alpha.text-right + %a.button{ href: "#{edit_admin_enterprise_path(@enterprise)}#!#vouchers_panel"} + = t('.back') + .twelve.columns.omega + .row + .eight.columns.text-center + %legend= t(".legend") + .four.columns.text-right + %input.red{ type: "button", value: t('.save') } + .row + .alpha.four.columns + = label :voucher, :code, t('.voucher_code') + .omega.eight.columns + %textarea.fullwidth{ id: 'voucher_code', name: 'voucher_code', rows: 6 } + .row + .alpha.four.columns + = label :voucher, :amount, t('.voucher_amount') + .omega.eight.columns + $ + %input{ type: 'text', id: 'voucher_amount', name: 'voucher_amount', value: 10, disabled: true } diff --git a/app/views/spree/admin/shared/_tabs.html.haml b/app/views/spree/admin/shared/_tabs.html.haml index 6613a24643..91efb77da3 100644 --- a/app/views/spree/admin/shared/_tabs.html.haml +++ b/app/views/spree/admin/shared/_tabs.html.haml @@ -4,7 +4,7 @@ = tab :orders, :subscriptions, :customer_details, :adjustments, :payments, :return_authorizations, url: admin_orders_path('q[s]' => 'completed_at desc'), icon: 'icon-shopping-cart' = tab :reports, url: main_app.admin_reports_path, icon: 'icon-file' = tab :general_settings, :mail_methods, :tax_categories, :tax_rates, :tax_settings, :zones, :countries, :states, :payment_methods, :taxonomies, :shipping_methods, :shipping_categories, :enterprise_fees, :contents, :invoice_settings, :matomo_settings, :stripe_connect_settings, label: 'configuration', icon: 'icon-wrench', url: edit_admin_general_settings_path -= tab :enterprises, :enterprise_relationships, :oidc_settings, url: main_app.admin_enterprises_path += tab :enterprises, :enterprise_relationships, :vouchers, :oidc_settings, url: main_app.admin_enterprises_path = tab :customers, url: main_app.admin_customers_path = tab :enterprise_groups, url: main_app.admin_enterprise_groups_path, label: 'groups' - if can? :admin, Spree::User diff --git a/config/locales/en.yml b/config/locales/en.yml index 5a9001e7a4..75e2de9367 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1144,6 +1144,17 @@ en: add_unregistered_user: "Add an unregistered user" email_confirmed: "Email confirmed" email_not_confirmed: "Email not confirmed" + vouchers: + legend: Vouchers + rate: Rate + label: Label + purpose: Purpose + expiry: Expiry + use_limit: Use/Limit + customers: Customer + net_value: Net Value + add_new: Add New + no_voucher_yet: No Vouchers yet actions: edit_profile: Settings properties: Properties @@ -1382,6 +1393,7 @@ en: tag_rules: "Tag Rules" shop_preferences: "Shop Preferences" users: "Users" + vouchers: Vouchers enterprise_group: primary_details: "Primary Details" users: "Users" @@ -1590,6 +1602,13 @@ en: schedules: destroy: associated_subscriptions_error: This schedule cannot be deleted because it has associated subscriptions + vouchers: + new: + legend: New Voucher + back: Back + save: Save + voucher_code: Voucher Code + voucher_amount: Amount # Admin controllers controllers: diff --git a/config/routes/admin.rb b/config/routes/admin.rb index b28f1eae57..852c7a3436 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -40,6 +40,9 @@ Openfoodnetwork::Application.routes.draw do end resources :tag_rules, only: [:destroy] + + # TODO do we need to remove more routes + resources :vouchers, only: [:new, :create] end resources :enterprise_relationships