Class: SuppliersController
- Inherits:
-
CrmController
- Object
- ActionController::Base
- ApplicationController
- CrmController
- SuppliersController
- Includes:
- Controllers::RequireTurboFrame
- Defined in:
- app/controllers/suppliers_controller.rb
Overview
Controller: suppliers.
Constant Summary collapse
- TAB_ACTIONS =
Tab fragments never render standalone — non-frame hits redirect to show ?tab=.
%i[tab_main tab_addresses tab_contacts tab_payments tab_orders tab_receipts].freeze
- ALLOWED_PER_PAGE =
Allowed per page.
[100, 200, 500, 1000, 5000].freeze
Constants included from Controllers::ReferenceFindable
Controllers::ReferenceFindable::ID_EMBEDDED_PATTERNS
Constants included from Controllers::AnalyticsEvents
Controllers::AnalyticsEvents::MAX_QUEUED_EVENTS, Controllers::AnalyticsEvents::SESSION_KEY
Constants included from Controllers::ErrorRendering
Controllers::ErrorRendering::NON_CONTENT_PATH_PREFIXES
Instance Method Summary collapse
-
#create ⇒ Object
POST /suppliers POST /suppliers.xml.
-
#destroy ⇒ void
Deletes a supplier.
-
#edit ⇒ Object
GET /suppliers/1/edit.
-
#edit_default_address ⇒ void
Redirects to add an address when the supplier has none, otherwise falls through to editing the default address.
-
#index ⇒ Object
GET /suppliers GET /suppliers.xml.
-
#lookup ⇒ void
Returns supplier (or party, when
include_customers) autocomplete results as JSON. -
#new ⇒ Object
GET /suppliers/new GET /suppliers/new.xml.
-
#show ⇒ Object
GET /suppliers/1 GET /suppliers/1.xml.
-
#tab_addresses ⇒ void
Renders the addresses tab fragment.
-
#tab_contacts ⇒ void
Renders the contacts tab fragment.
-
#tab_main ⇒ Object
Tab actions for turbo-tabs lazy loading.
-
#tab_orders ⇒ void
Renders the purchase orders tab fragment.
-
#tab_payments ⇒ void
Renders the payments tab fragment.
-
#tab_receipts ⇒ void
Renders the receipts tab fragment.
-
#update ⇒ Object
PUT /suppliers/1 PUT /suppliers/1.xml.
-
#update_default_address ⇒ void
Updates the supplier's default address from submitted params.
Methods included from Controllers::RequireTurboFrame
require_in_pane_tab_frames, require_turbo_frame
Methods inherited from CrmController
#access_denied, #context_id, #context_object, #crm_home_path, #current_ability, #default_url_options, #download_temp, #get_tempfile_path_for_download, #init_status_job_collector, #initialize_crm_lazy_chunks, #persist_enqueued_status_jobs, #record_not_found, #redirect_to_job_or_fallback, #render_edit_action, #set_context, #set_download_path, #stash_file_for_temp_download, #sync_admin_presence_cookie, #touch_employee_last_seen
Methods inherited from ApplicationController
#account_impersonated?, #add_to_flash, #after_sign_in_path_for, #bypass_forgery_protection?, #chat_enabled?, #cloudflare_cleared?, #default_catalog, #default_url_options, #enable_turbo_frames, #find_publication, #fix_invalid_accept_header, #init_js_utils, #is_globals_call?, #layout_by_resource, #locale_store, #redirect_to, #require_employee_for_crm, #set_base_host, #set_real_ip, #set_report_errors_for, #should_render_layout?, #skip_layout_for_turbo_frame?, #stamp_impersonation_context, #tab_frame_breakout_request?, #warmlyyours_canada_ip?, #warmlyyours_ip?, #y
Methods included from Controllers::ReturnPathHandling
#check_for_return_path, #redirect_to_return_path_or_default
Methods included from Controllers::AnalyticsEvents
#consume_queued_analytics_events, #registration_lead_type, #track_event
Methods included from Controllers::DeviceDetection
Methods included from Controllers::SubdomainDetection
#is_crm_request?, #is_www_request?, #json_request?
Methods included from Controllers::TurboSafeRedirect
Methods included from Controllers::TrackingDetection
#bot_request?, #gdpr_country?, #gdpr_country_data, #prevent_bots, #set_tracking_cookie, #track_visitor?
Methods included from Controllers::AcceleratedFileSending
#send_file_accelerated, #send_upload_accelerated
Methods included from Controllers::ErrorRendering
#excp_string, #mail_to_for_error_reporting, #render_400, #render_404, #render_406, #render_410, #render_500, #render_invalid_authenticity_token, #render_ip_spoof_error, #render_unpermitted_parameters, #safe_referer_or_fallback
Methods included from Controllers::TurnstileVerification
#load_turnstile_script_tag, #turnstile_lazy_widget, #turnstile_script_tag, #turnstile_widget, #validate_turnstile!
Methods included from Controllers::CloudflareCaching
edge_cached, #edge_cached_action?, #reset_cloudflare_cache, #set_cloudflare_cache, #skip_edge_cache!, #skip_session
Methods included from Controllers::Webpackable
#preload_webpack_fonts, #webpack_css_include, #webpack_css_url, #webpack_js_include, #wpd_is_running?
Methods included from Controllers::Localizable
#cloudflare_country_locale, #determine_request_locale, #geocoder_locale, #guest_user_locale_check, #locale_optional_www_auth_path?, #param_locale, #set_locale, #set_request_locale, #skip_localization?, #warmlyyours_ip_locale
Methods included from Controllers::Authenticable
#access_denied, #authenticate_account, #authenticate_account!, #authenticate_account_from_login_token!, #check_is_a_manager, #check_is_a_sales_manager, #check_is_an_admin, #check_is_an_employee, #check_party, #clear_mismatched_guest_user, #create_guest_user, #credentials?, #current_or_guest_user, #current_or_guest_user_id_read_only, #current_user, #devise_mapping, #fully_logged_in?, #generate_bot_id, #guest_user, #identifiable?, #init_current_user, #initialize_guest, #load_context_user, #logging_in, #resource, #resource_name, #restrict_access_for_non_employees, #scrubbed_request_path, #user_object, #warn_on_session_guest_id_leak
Methods included from UrlsHelper
#catalog_breadcrumb_links, #catalog_link, #catalog_link_for_product_line, #catalog_link_for_sku, #cms_link, #delocalized_path, #path_to_sales_product_sku, #path_to_sales_product_sku_for_product_line, #path_to_sales_product_sku_for_product_line_slug, #product_line_from_catalog_link, #protocol_neutral_url, #sanitize_external_url, #valid_external_url?
Instance Method Details
#create ⇒ Object
POST /suppliers
POST /suppliers.xml
87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/controllers/suppliers_controller.rb', line 87 def create (:create, Supplier) @supplier = Supplier.new(params[:supplier]) respond_to do |format| if @supplier.save format.html { redirect_to(new_supplier_address_path(@supplier, return_path: supplier_path(@supplier)), info: 'Supplier was successfully created. Enter an address') } else format.html { render action: 'new', status: :unprocessable_content } end end end |
#destroy ⇒ void
This method returns an undefined value.
Deletes a supplier.
118 119 120 121 122 123 124 |
# File 'app/controllers/suppliers_controller.rb', line 118 def destroy (:destroy, Supplier) @supplier = Supplier.find(params[:id]) @supplier.destroy flash[:info] = 'Supplier was successfully destroyed.' redirect_to_return_path_or_default suppliers_path end |
#edit ⇒ Object
GET /suppliers/1/edit
79 80 81 82 83 |
# File 'app/controllers/suppliers_controller.rb', line 79 def edit (:update, Supplier) @supplier = Supplier.find(params[:id]) render_edit_action end |
#edit_default_address ⇒ void
This method returns an undefined value.
Redirects to add an address when the supplier has none, otherwise falls
through to editing the default address.
130 131 132 133 134 135 136 137 138 |
# File 'app/controllers/suppliers_controller.rb', line 130 def edit_default_address (:update, Supplier) @supplier = Supplier.find(params[:id]) (:update, @supplier) return if @supplier.addresses.present? flash[:warning] = 'No addresses exists for supplier' redirect_to_return_path_or_default supplier_path(@supplier, tab: "addresses") && return end |
#index ⇒ Object
GET /suppliers
GET /suppliers.xml
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/controllers/suppliers_controller.rb', line 15 def index (:read, Supplier) params[:q] ||= { state_eq: 'active' } @q = Supplier.ransack(params[:q]) @q.sorts = 'full_name ASC' if @q.sorts.blank? per_page = validated_per_page suppliers_scope = @q.result .select(:id, :full_name, :banner, :terms, :currency, :state, :estimated_landed_cost_ptg, :business_unit_id, :gl_offset_account_id) .includes(:business_unit, :gl_offset_account, :view_estimated_landed_cost) @pagy, @suppliers = pagy(suppliers_scope, limit: per_page) end |
#lookup ⇒ void
This method returns an undefined value.
Returns supplier (or party, when include_customers) autocomplete results as JSON.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/controllers/suppliers_controller.rb', line 32 def lookup (:read, Supplier) respond_to do |format| format.json do party_id = params[:party_id] if party_id s = Party.find(party_id) render json: { results: { label: s.id_and_name, value: s.id, terms: s.terms, full_name: s.full_name, business_unit_id: s.business_unit_id, gl_offset_account_id: s.gl_offset_account_id, stripe_key: s.try(:catalog).try(:stripe_key) || Catalog.find(1).stripe_key } } else queryable = params[:include_customers].to_b ? Party : Supplier @suppliers = queryable.order(:full_name).where('parties.id = ? or full_name ilike ?', params[:term].to_i, "%#{params[:term]}%").limit(10) @suppliers = @suppliers.where(type: params[:party_type]) if params[:party_type].present? render json: @suppliers.map { |s| { label: s.id_and_name, value: s.id, terms: s.terms, full_name: s.full_name, business_unit_id: s.business_unit_id, gl_offset_account_id: s.gl_offset_account_id, stripe_key: s.try(:catalog).try(:stripe_key) || Catalog.find(1).stripe_key } } end end end end |
#new ⇒ Object
GET /suppliers/new
GET /suppliers/new.xml
70 71 72 73 74 75 76 |
# File 'app/controllers/suppliers_controller.rb', line 70 def new (:create, Supplier) @supplier = Supplier.new respond_to do |format| format.html # new.html.erb end end |
#show ⇒ Object
GET /suppliers/1
GET /suppliers/1.xml
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'app/controllers/suppliers_controller.rb', line 55 def show (:read, Supplier) @supplier = Supplier.find(params[:id]) @pagy_vouchers, @vouchers = pagy(@supplier.vouchers.includes(:company, :supplier, :business_unit).order(reference_number: :desc), page: params[:voucher_page]) @pagy_payments, @payments = pagy(@supplier.outgoing_payments.includes(:company, :supplier).order(payment_date: :desc), page: params[:payment_page]) @pagy_purchase_orders, @purchase_orders = pagy(@supplier.purchase_orders.order(Arel.sql("case state when 'cancelled' then 4 when 'landed_costs' then 3 when 'fully_receipted' then 2 else 1 end,order_date DESC ")), page: params[:purchase_order_page]) respond_to do |format| format.html # show.html.erb end end |
#tab_addresses ⇒ void
This method returns an undefined value.
Renders the addresses tab fragment.
169 170 171 172 173 174 175 176 |
# File 'app/controllers/suppliers_controller.rb', line 169 def tab_addresses @supplier = Supplier.find(params[:id]) (:read, @supplier) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_contacts ⇒ void
This method returns an undefined value.
Renders the contacts tab fragment.
181 182 183 184 185 186 187 188 |
# File 'app/controllers/suppliers_controller.rb', line 181 def tab_contacts @supplier = Supplier.find(params[:id]) (:read, @supplier) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_main ⇒ Object
Tab actions for turbo-tabs lazy loading. Streamed pattern (PR #903) —
every tab serves both formats so in-pane interactions can target
tab_frame_id via turbo_stream.update.
157 158 159 160 161 162 163 164 |
# File 'app/controllers/suppliers_controller.rb', line 157 def tab_main @supplier = Supplier.find(params[:id]) (:read, @supplier) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_orders ⇒ void
This method returns an undefined value.
Renders the purchase orders tab fragment.
206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'app/controllers/suppliers_controller.rb', line 206 def tab_orders @supplier = Supplier.find(params[:id]) (:read, @supplier) @pagy_purchase_orders, @purchase_orders = pagy( @supplier.purchase_orders.order(Arel.sql("case state when 'cancelled' then 4 when 'landed_costs' then 3 when 'fully_receipted' then 2 else 1 end, order_date DESC")), page: params[:purchase_order_page] ) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_payments ⇒ void
This method returns an undefined value.
Renders the payments tab fragment.
193 194 195 196 197 198 199 200 201 |
# File 'app/controllers/suppliers_controller.rb', line 193 def tab_payments @supplier = Supplier.find(params[:id]) (:read, @supplier) @pagy_payments, @payments = pagy(@supplier.outgoing_payments.includes(:company, :supplier).order(payment_date: :desc), page: params[:payment_page]) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#tab_receipts ⇒ void
This method returns an undefined value.
Renders the receipts tab fragment.
222 223 224 225 226 227 228 229 |
# File 'app/controllers/suppliers_controller.rb', line 222 def tab_receipts @supplier = Supplier.find(params[:id]) (:read, @supplier) respond_to do |format| format.html { render layout: should_render_layout? } format.turbo_stream end end |
#update ⇒ Object
PUT /suppliers/1
PUT /suppliers/1.xml
102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/controllers/suppliers_controller.rb', line 102 def update (:update, Supplier) @supplier = Supplier.find(params[:id]) respond_to do |format| if @supplier.update(params[:supplier]) format.html { redirect_to(supplier_url(@supplier), info: 'Supplier was successfully updated.') } else format.html { render_edit_action(status: :unprocessable_content) } end end end |
#update_default_address ⇒ void
This method returns an undefined value.
Updates the supplier's default address from submitted params.
143 144 145 146 147 148 149 150 151 152 |
# File 'app/controllers/suppliers_controller.rb', line 143 def update_default_address (:update, Supplier) @supplier = Supplier.find(params[:id]) (:update, @supplier) if @supplier.update(params[:supplier]) redirect_to_return_path_or_default supplier_path(@supplier, tab: "addresses") else render :edit_default_address, status: :unprocessable_content end end |