Sha256: ce3d5d5de28435e60fc92953b821805891be578cb8873a8859d2913d4ce08382

Contents?: true

Size: 1.03 KB

Versions: 2

Compression:

Stored size: 1.03 KB

Contents

json.data do
  json.array! @customers do |d|
    department_ids = d.departments.ids
    business_ids = EducodeSales::Business.where(department_id: department_ids).ids
    follow_ups = EducodeSales::FollowUp.where(business_id: business_ids)
    customer_follows = EducodeSales::CustomerFollow.where(school_id: d.id)
    a_last_follow_time = follow_ups.last&.created_at&.to_s
    b_last_follow_time = customer_follows.last&.created_at&.to_s
    if a_last_follow_time.present? && b_last_follow_time.present?
      json.last_follow_time a_last_follow_time < b_last_follow_time ? b_last_follow_time : a_last_follow_time
    else
      json.last_follow_time a_last_follow_time || b_last_follow_time
    end
    json.id d.id
    json.name d.name
    json.area d.province
    json.department d.departments.size
    json.business business_ids.size
    json.follow follow_ups.size + customer_follows.size
    json.staff EducodeSales::CustomerExtension.find_by(school_id: d.id)&.customer_staff&.user&.real_name
  end
end

json.code 0
json.count @customers.total_count

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
educode_sales-0.6.1 app/views/educode_sales/customers/index.json.jbuilder
educode_sales-0.6.0 app/views/educode_sales/customers/index.json.jbuilder