app/views/educode_sales/sales/index.json.jbuilder in educode_sales-0.4.4 vs app/views/educode_sales/sales/index.json.jbuilder in educode_sales-0.4.5
- old
+ new
@@ -1,17 +1,33 @@
+businesses_a_count = 0
+businesses_b_count = 0
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("
+ JOIN educode_sales_follow_ups ON educode_sales_businesses.last_follow_up_id = educode_sales_follow_ups.id
+ ").where("educode_sales_follow_ups.staff_id = ?", d.id).pluck(:business_id)
+ business_ids = part_a_ids + part_b_ids
+ @businesses = EducodeSales::Business.where(id:business_ids)
json.id d.id
json.name d.user.real_name
json.role d.role&.name
json.area d.areas.present? ? d.areas.pluck(:name).join("、") : ''
- json.business_a 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 = ?", @a_clazz&.id).count
- json.business_b 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 = ?", @b_clazz&.id).count
- json.goal 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 != ? AND educode_sales_follow_ups.stage_id in (?)", @x, @step_ids).sum(:total_amount).round(2)
- json.return_money 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 != ?", @x).sum("educode_sales_businesses.return_money").round(2)
+ 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).count
+ businesses_a_count += business_a
+ json.business_a business_a
+ 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).count
+ businesses_b_count += business_b
+ json.business_b business_b
+ 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("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 != ?", @x).sum("educode_sales_businesses.return_money").round(2)
json.a_clazz_id @a_clazz&.id
json.b_clazz_id @b_clazz&.id
end
end
+json.totalRow do
+ json.business_a businesses_a_count.to_s
+ json.business_b businesses_b_count.to_s
+end
json.code 0
json.count @staffs.total_count
\ No newline at end of file