total_amount = 0 json.data do json.array! @money_plans do |d| json.id d.id json.business_name d.business.name json.date_at (d&.date_at&.to_s(:date) || "") json.amount d.amount json.clazz d.clazz json.business d.business.name json.business_id d.business.id json.school d.business.school&.name json.school_id d.business.school_id json.staff d.staff&.user&.real_name json.staff_id d.staff_id json.number d.business.number json.category d.category || '' json.payment_clause d.payment_clause json.stage d.business&.last_follow_up&.stage&.name || '' json.return_period d.return_period json.signed_date d.business&.last_follow_up&.signed_date json.actual_amount d.business&.last_follow_up&.actual_amount json.rate d.business&.last_follow_up&.actual_amount ? (d.amount / d.business.last_follow_up.actual_amount * 100.0).round(2) : '' json.staff_manages d.business&.last_follow_up&.assign_follow_ups.present? ? (d.business.last_follow_up.assign_follow_ups.map{ |d| d.staff.user.real_name}.join("、")) : d.business.staff&.user&.real_name if d['claim_num'] > 0 if d['return_money'].to_f >= d.amount json.state '已回款' else json.state '部分回款' end elsif d['claim_num'] == 0 && d.date_at > Time.now json.state '正常' else json.state '已逾期' end json.claim_num d['claim_num'] if d.business.department&.school json.property d.business.department.school.school_tags.where(for_missions: true).pluck(:name).join("、") else json.property '' end json.return_money (d['return_money'] || 0).round(6) json.residue_money ((d.amount - d['return_money'].to_f) > 0 ? d.amount - d['return_money'].to_f : 0).round(6) if d['claim_num'] > 0 json.accounts_state '' else case d.business&.last_follow_up&.stage&.name when '已中标' json.accounts_state '中标应收款' when '已签单' json.accounts_state '合同应收款' when '已部署' json.accounts_state '部署应收款' when '已验收' json.accounts_state '验收应收款' when '已回款' json.accounts_state '质保金' when '已开票' json.accounts_state '开票应收款' end end json.created_at d.created_at.to_s end end json.code 0 json.count @money_plans.total_count