Class: PaymentTermsTranslationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/payment_terms_translations_controller.rb

Instance Method Summary collapse

Methods included from AuthentificationHelper

#accessible_company_ids_from_tenant_and_user, #application_mode_from_hostname, #current_company_id_from_accessible_company_ids, #current_tenant_from_user, #current_user_and_locale_from_token

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/payment_terms_translations_controller.rb', line 6

def index
  EdiPartner.find(params[:edi_partner_id])
  limit = params[:limit].to_i || 10
  offset = params[:offset].to_i || 0
  @records = EdiPaymentTermsTranslation.table_data(
    edi_partner_id: params[:edi_partner_id],
    limit: limit,
    offset: offset
  )
  @total = PaymentTerm.count

  render json: {
    data: @records,
    metadata: {
      total: @total,
      limit: limit,
      offset: offset
    }
  }
end

#update_from_table_editsObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/controllers/payment_terms_translations_controller.rb', line 27

def update_from_table_edits
  update_from_table_edits_params[:rows_edits].each do |row_edits|
    row_hash = row_edits[:rowHash]
    edits = row_edits[:edits]

    edits.each do |field, value|
      next unless field == 'edi_payment_term_code'

      uom_translation = EdiPaymentTermsTranslation.find_or_initialize_by(
        edi_partner_id: params[:edi_partner_id],
        payment_term_id: row_hash[:payment_term_id],
        head_office_id: row_hash[:head_office_id]
      )
      uom_translation.update(
        edi_payment_term_code: value,
        active: value.present?
      )
    end
  end
end