Class: StoreTranslationsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/store_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
26
# File 'app/controllers/store_translations_controller.rb', line 6

def index
  limit = params[:limit].to_i || 10
  offset = params[:offset].to_i || 0

  edi_partner = EdiPartner.find(params[:edi_partner_id])
  edi_partner.partner_class
  records = edi_partner.partner_class.store_translations_table_data(
    head_office_key: edi_partner.head_office_id,
    limit: limit,
    offset: offset
  )
  total = edi_partner.partners_count
  render json: {
    data: records,
    metadata: {
      total: total,
      limit: limit,
      offset: offset
    }
  }
end

#update_from_table_editsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/store_translations_controller.rb', line 28

def update_from_table_edits
  edi_partner = EdiPartner.find(params[:edi_partner_id])
  update_from_table_edits_params[:rows_edits].each do |row_edits|
    row_hash = row_edits[:rowHash]
    edits = row_edits[:edits]

    partner = edi_partner.partner_class.find(row_hash[:partner_id])

    new_edi_store_code = edits[:edi_store_code] || row_hash[:edi_store_code]
    if partner.is_a?(Supplier)
      partner.update!(
        edi_store_code: new_edi_store_code,
        active: new_edi_store_code.present?,
        MODIFICATION_DATE: Time.now,
        MODIFIED_BY: current_user.email.last(20)
      )
    elsif partner.is_a?(Customer)
      partner.update!(
        edi_store_code: new_edi_store_code,
        active: new_edi_store_code.present?,
        last_modification_date: Time.now,
        last_modified_by: current_user.email.last(20)
      )
    end
  end
end