app/views/educode_sales/sales/index.json.jbuilder in educode_sales-0.6.1 vs app/views/educode_sales/sales/index.json.jbuilder in educode_sales-0.6.2

- old
+ new

@@ -3,10 +3,12 @@ businesses_c_count = 0 businesses_d_count = 0 businesses_e_count = 0 businesses_o_count = 0 school_counts = 0 +follow_school_rates = 0 +follow_department_rates = 0 area_ids = EducodeSales::Common.where(clazz: 'area').ids.sort.to_s json.data do json.array! @staffs do |d| part_a_ids = EducodeSales::Business.where("educode_sales_businesses.last_follow_up_id is null AND staff_id = ?",d.id).ids part_b_ids = EducodeSales::Business.where("educode_sales_businesses.last_follow_up_id is not null").joins(" @@ -36,15 +38,17 @@ business_o = @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id = ?", @o_clazz&.id).count school_count = EducodeSales::CustomerExtension.where(customer_staff_id: d.id).size json.goal @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.stage_id in (?)", @x, @step_ids).sum(:total_amount).round(2) json.return_money @businesses.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", @x).where.not("educode_sales_money_plans.clazz!= ?", 1).sum(:amount).round(2) json.school_count school_count - follow_school_count = EducodeSales::CustomerFollow.where(staff_id: d.id).pluck(:school_id).uniq.size + follow_school_count = (EducodeSales::CustomerFollow.where(staff_id: d.id).pluck(:school_id) + EducodeSales::Business.where(id: EducodeSales::FollowUp.where(staff_id: d.id).pluck(:business_id).uniq).pluck(:school_id)).uniq.size json.follow_school_count follow_school_count json.follow_school_counts EducodeSales::CustomerFollow.where(staff_id: d.id).size + EducodeSales::FollowUp.where(staff_id: d.id).size - json.follow_school_rate follow_school_count!=0 ? school_count.to_f * 100 / follow_school_count : 0 - json.follow_department_rate follow_school_count!=0 ? school_count.to_f * 100 / follow_school_count : 0 + follow_school_rate = (follow_school_count!=0 ? school_count.to_f * 100 / follow_school_count : 0).round(2) + json.follow_school_rate follow_school_rate.to_s + '%' + follow_department_rate = (follow_school_count!=0 ? school_count.to_f * 110 / follow_school_count : 0).round(2) + json.follow_department_rate follow_department_rate.to_s + '%' else business_a = @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id = ?", @a_clazz&.id).where("educode_sales_follow_ups.year = ?", @year).count business_b = @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id = ?", @b_clazz&.id).where("educode_sales_follow_ups.year = ?", @year).count business_c = @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id = ?", @c_clazz&.id).where("educode_sales_follow_ups.year = ?", @year).count business_d = @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id = ?", @d_clazz&.id).where("educode_sales_follow_ups.year = ?", @year).count @@ -52,15 +56,17 @@ business_o = @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id = ?", @o_clazz&.id).where("educode_sales_follow_ups.year = ?", @year).count school_count = EducodeSales::CustomerExtension.where(customer_staff_id: d.id).size json.goal @businesses.joins("JOIN educode_sales_follow_ups on educode_sales_follow_ups.id = educode_sales_businesses.last_follow_up_id").where("educode_sales_follow_ups.clazz_id != ? AND educode_sales_follow_ups.stage_id in (?)", @x, @step_ids).where("educode_sales_follow_ups.bidded_date >= ? AND educode_sales_follow_ups.bidded_date <= ?", "#{@year}-01-01", "#{@year}-12-31").sum(:total_amount).round(2) json.return_money @businesses.joins(last_follow_up: :money_plans).where("educode_sales_follow_ups.clazz_id != ?", @x).where.not("educode_sales_money_plans.clazz!= ?", 1).where("educode_sales_money_plans.date_at >= ? AND educode_sales_money_plans.date_at <= ? ", "#{@year}-01-01 00:00:00", "#{@year}-12-31 23:59:59").sum(:amount).round(2) json.school_count school_count - follow_school_count = EducodeSales::CustomerFollow.where(staff_id: d.id).where("created_at >= ? AND created_at <= ?", "#{@year}-01-01", "#{@year}-12-31").pluck(:school_id).uniq.size || 0 + follow_school_count = (EducodeSales::CustomerFollow.where(staff_id: d.id).where("created_at >= ? AND created_at <= ?", "#{@year}-01-01", "#{@year}-12-31").pluck(:school_id) + EducodeSales::Business.where(id: EducodeSales::FollowUp.where("created_at >= ? AND created_at <= ?", "#{@year}-01-01", "#{@year}-12-31").where(staff_id: d.id).pluck(:business_id).uniq).pluck(:school_id)).uniq.size json.follow_school_count follow_school_count json.follow_school_counts EducodeSales::CustomerFollow.where(staff_id: d.id).where("created_at >= ? AND created_at <= ?", "#{@year}-01-01", "#{@year}-12-31").size + EducodeSales::FollowUp.where(staff_id: d.id).where("created_at >= ? AND created_at <= ?", "#{@year}-01-01", "#{@year}-12-31").size - json.follow_school_rate follow_school_count!=0 ? school_count.to_f * 100 / follow_school_count : 0 - json.follow_department_rate follow_school_count!=0 ? school_count.to_f * 100 / follow_school_count : 0 + follow_school_rate = (follow_school_count!=0 ? school_count.to_f * 100 / follow_school_count : 0).round(2) + json.follow_school_rate follow_school_rate.to_s + '%' + follow_department_rate = (follow_school_count!=0 ? school_count.to_f * 110 / follow_school_count : 0).round(2) + json.follow_department_rate follow_department_rate.to_s + '%' end json.business_a business_a json.business_b business_b json.business_c business_c @@ -79,10 +85,12 @@ businesses_c_count += business_c businesses_d_count += business_d businesses_e_count += business_e businesses_o_count += business_o school_counts += school_count + follow_school_rates += follow_school_rate + follow_department_rates += follow_department_rate end end json.totalRow do json.business_a businesses_a_count.to_s @@ -90,8 +98,10 @@ json.business_c businesses_c_count.to_s json.business_d businesses_d_count.to_s json.business_e businesses_e_count.to_s json.business_o businesses_o_count.to_s json.school_count school_counts.to_s + json.follow_school_rate (follow_school_rates.to_f / @staffs.size).to_s + '%' + json.follow_department_rate (follow_department_rates.to_f / @staffs.size).to_s + '%' end json.code 0 json.count @staffs.total_count \ No newline at end of file